Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Ajax add-on to the Fluxbb Like plugin
- Copyright (C) 2012 soyuka
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- (function($){
- $.fn.wsLiker = function(id, pseudo, likeString, unlikeString, likeThisPostString) {
- $(this).live('click', function(event) {
- //Pas de lien
- event.preventDefault();
- //Url à envoyer
- var url = $(this).attr("href");
- //Ajax envoi
- $.get(url, function(data) {
- //Data(+data+)
- });
- //J'aime ou J'aime pas ?
- var value = $(this).text();
- var like = 0;
- //On change le texte, l'url et on récupère la valeur du j'aime
- if(value == "J'aime") {
- $(this).text(unlikeString);
- $(this).attr('href', url + '&dislike=1')
- like = 0;
- } else {
- $(this).text(likeString);
- $(this).attr('href', url.slice(0, - 10) ); //fait à l'arrache je l'avoue
- like = 1;
- }
- var pseudoHtml = '<span title="'+pseudo+'">, <a href="profile.php?id='+id+'">'+pseudo+'</a></span>';
- //Si on aime, on regarde si le block d'aimer existe, on le créé, on ajoute le pseudo
- if(like == 0) {
- //La div "Like"
- var liker = $(this).parents(".blockpost").next();
- if(liker.hasClass('liker')) {
- //Bloc existe, on ajoute le pseudo...
- var parent = liker.find(".postmsg p");
- //Je clone pour l'apparence
- tpl = $(pseudoHtml).clone();
- //On cache
- tpl.hide();
- tpl.appendTo(parent).fadeIn().css('display', 'inline');
- } else {
- //Template etc.
- var template = '<div class="blockpost rowodd liker">'+
- '<div class="box">'+
- '<div class="inbox">'+
- '<div class="postbody">'+
- '<div class="postleft">'+
- '<dl>'+
- '<dd class="usertitle"><strong>'+likeThisPostString+'</strong></dd>'+
- '</dl>'+
- '</div>'+
- '<div class="postright">'+
- '<div class="postmsg">'+
- '<p><span title="'+pseudo+'"><a href="profile.php?id='+id+'">'+pseudo+'</a></span></p>'+
- '</div>'+
- '</div>'+
- '</div>'+
- '</div>'+
- '</div>'+
- '</div>';
- //Bloc n'existe pas faut le créer...
- var parent = $(this).parents(".blockpost");
- //Création du clone pour les effets
- tpl = $(template).clone();
- //On le cache
- tpl.hide();
- //On l'insère
- tpl.insertAfter(parent).delay(100).fadeIn();
- }
- //Sinon on trouve le pseudo et on le jarte
- } else {
- //La div "like" qui existe forcément
- var liker = $(this).parents(".blockpost").next('.liker');
- //Le lien du pseudo à chercher
- //var linkPseudo = $('a[href="profile.php?id='+id+'"]');
- var linkPseudo = $("span[title="+pseudo+"]");
- //On enlève le pseudo
- liker.find(linkPseudo).fadeOut('fast', function () {
- $(this).remove();
- });
- /*
- Compter le nb de a si 0 => liker disparait
- */
- var nb = liker.find('a').length;
- if(nb == 0 || nb == 1)
- liker.fadeOut('fast').fadeOut('fast', function () {
- $(this).empty().remove();
- });
- //Apparement .empty().remove() = gain de 2% en vitesse
- }
- });
- };
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement