Created
October 4, 2021 05:04
-
-
Save genesis16/2ee8b7bdbb7e91e3d494b0826ec2db63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function( $ ) { | |
'use strict'; | |
$(document).on('click', '.sl-button', function() { | |
var button = $(this); | |
var post_id = button.attr('data-post-id'); | |
var security = button.attr('data-nonce'); | |
var iscomment = button.attr('data-iscomment'); | |
var allbuttons; | |
if ( iscomment === '1' ) { /* Comments can have same id */ | |
allbuttons = $('.sl-comment-button-'+post_id); | |
} else { | |
allbuttons = $('.sl-button-'+post_id); | |
} | |
var loader = allbuttons.next('#sl-loader'); | |
if (post_id !== '') { | |
$.ajax({ | |
type: 'POST', | |
url: simpleLikes.ajaxurl, | |
data : { | |
action : 'process_simple_like', | |
post_id : post_id, | |
nonce : security, | |
is_comment : iscomment, | |
}, | |
beforeSend:function(){ | |
loader.html(' <div class="loader">Loading...</div>'); | |
}, | |
success: function(response){ | |
var icon = response.icon; | |
var count = response.count; | |
allbuttons.html(icon+count); | |
if(response.status === 'unliked') { | |
var like_text = simpleLikes.like; | |
allbuttons.prop('title', like_text); | |
allbuttons.removeClass('liked'); | |
} else { | |
var unlike_text = simpleLikes.unlike; | |
allbuttons.prop('title', unlike_text); | |
allbuttons.addClass('liked'); | |
} | |
loader.empty(); | |
} | |
}); | |
} | |
return false; | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment