The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

LIKE button without refreshing page

View previous topic View next topic Go down

Solved LIKE button without refreshing page

Post by troyeccles on July 3rd 2015, 9:52 am

Hello,

I have the script below running to create a LIKE button linked to reputation. It works really well except....when you click LIKE it refreshes the page in order to update the reputation.

Is it possible to code a LIKE button that instantly adds a Like Count without having to refresh the page - a bit like Facebook or Twitter? Even if it updates the reputation at a later time when the screen IS refreshed?

I'm just finding my members don't use the LIKE button much because it involves a page refresh.

Current Code:

$(function() {
var voteImage = 'https://i39.servimg.com/u/f39/18/78/19/68/tbar_v10.png';

$('.vote').each(function() {
if ($(this).find('.vote-bar').length) { var VCount = $(this).find('.vote-bar').attr('title').replace(/.*\((\d+).*\)/,'$1') }
if (VCount == '1') { var vote = ' vote' }
else { var vote = ' votes' }
var VPlus = $(this).find('.vote-button:first a').addClass('VPlus').attr('title', 'Vote up').html('<img src="'+voteImage+'" alt="+"/>');

$(this).closest('.postbody').find('.profile-icons').append(VPlus);
$(this).closest('.postbody:has(.vote-bar)').find('.profile-icons').append('<span class="VCount" title="'+VCount+vote+'">'+VCount+'</span>');
$(this).remove();
});

$('.VPlus').click(function(){
$.get($(this).attr('href'), function() {
location.reload();
});
return false
});
});

troyeccles
Forumember

Posts : 296
Reputation : 5
Language : English

Back to top Go down

Solved Re: LIKE button without refreshing page

Post by Ange Tuteur on July 3rd 2015, 12:58 pm

Hi @troyeccles,

Replace your script with this :
Code:
$(function() {
    var voteImage = 'http://i39.servimg.com/u/f39/18/78/19/68/tbar_v10.png';
 
    $('.vote').each(function() {
      if ($(this).find('.vote-bar').length) { var VCount = $(this).find('.vote-bar').attr('title').replace(/.*\((\d+).*\)/,'$1') }
      if (VCount == '1') { var vote = ' vote' }
      else { var vote = ' votes' }
      var VPlus = $(this).find('.vote-button:first a').addClass('VPlus').attr('title', 'Vote up').html('<img src="'+voteImage+'" alt="+"/>');
     
      $(this).closest('.postbody').find('.profile-icons').append(VPlus);
      $(this).closest('.postbody:has(.vote-bar)').find('.profile-icons').append('<span class="VCount" title="'+VCount+vote+'">'+VCount+'</span>');
      $(this).remove();
    });
   
    $('.VPlus').click(function(){
      var t = this, n = this.nextSibling;
      $.get($(this).attr('href'), function() {
          t.style.opacity = '0.3';
          if (n) {
            n.innerHTML = +n.innerHTML + 1;
            n.title = n.innerHTML + ' votes';
          } else {
            $(t.parentNode).append('<span class="VCount" title="1 vote">1</span>');
          }
      });
      return false
    });
});

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: LIKE button without refreshing page

Post by Michael_vx on July 3rd 2015, 8:44 pm

sorry for entering here first
blackeye
what version of forums that Script is should be for its not working in my test forum phpbb2
totally hide the vote buttons

Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: LIKE button without refreshing page

Post by troyeccles on July 7th 2015, 12:20 pm

Ange, you are nothing short of a genius!

Thank you!!!

This is solved for my version although it looks like it may not be solved for the other versions.

Thank you again.

Troy.

troyeccles
Forumember

Posts : 296
Reputation : 5
Language : English

Back to top Go down

Solved Re: LIKE button without refreshing page

Post by Ange Tuteur on July 7th 2015, 12:27 pm

@Michael_vx wrote:sorry for entering here first
blackeye
what version of forums that Script is should be for its not working in my test forum phpbb2
totally hide the vote buttons
The script is meant for version phpBB3. Wink

@troyeccles wrote:Ange, you are nothing short of a genius!

Thank you!!!

This is solved for my version although it looks like it may not be solved for the other versions.

Thank you again.

Troy.
You're welcome ^^

Topic archived

Have a great day. Smile

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum