Advertisement
SSYT

script.js

May 10th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function() {
  2.     var update_likes = function() {
  3.         $('.post').each(function() {
  4.             var post = $(this);
  5.             $('div#likeBar:not("a")', this).hide();
  6.             var pID = post.attr('id').match(/\d+/g);
  7.             $.ajax({
  8.                 type: "GET",
  9.                 url: "http://forumotion.96.lt/get_like.php/?post_id="+pID,
  10.                 beforeSend: function(xml) {
  11.                     $('#likeBar', post).html("Loading...").show();
  12.                 },
  13.                 complete: function(xml) {
  14.                     xmlDoc = xml.responseText;
  15.                     $('#likeBar', post).html(xmlDoc);
  16.                     var user = "/u"+_userdata.user_id;
  17.                     var liked = $('#likeBar a[href="'+ user +'"]', post);
  18.                     if(liked.length == 1)
  19.                     {
  20.                         $('a[id*="like-post"]', post).remove();
  21.                     }
  22.  
  23.                     $('#likeBar', post).each(function() {
  24.                         var d = $('strong', this).text().match(/\d+/g);
  25.                         $('p', this).html($('p a:lt(3)', this));
  26.                         $('p', this).prepend("People like's this: ");
  27.                         if($('p a', this).length > 3) {
  28.                             $('p', this).append(''+ parseInt(d) - 3 +' other people');
  29.                         }
  30.                     });
  31.                 }, error: function(xml) {
  32.                     console.log("Failed loading data...");
  33.                 }
  34.             });
  35.         });
  36.     };
  37.  
  38.     setTimeout(function() { update_likes(); }, 50);
  39.  
  40.     $('.post').each(function() {
  41.         var post = $(this);
  42.         var people = _userdata.username;
  43.         var author = $('.postprofile dt a[href*="/u"]', post);
  44.         if(author.text() === people || _userdata.session_logged_in == 0) {
  45.             $('a[id*="like-post"]', post).remove();
  46.         }
  47.  
  48.         $('a[id*="like-post"]', this).on('click', function(e) {
  49.             e.preventDefault();
  50.             var id = $(this).attr('post-id').match(/\d+/);
  51.             var people = _userdata.username;
  52.             var author = $('.postprofile dt a[href*="/u"]', post);
  53.             var avatar = $(_userdata.avatar).attr('src');
  54.             var string = "user="+ people +"&post_id="+ id +"&like_count=1&avatars="+ avatar  +"&user_id_people="+ _userdata.user_id +"&user_id="+author.attr('href').match(/\d+/g)+"&post_author="+author.text();
  55.             if(author.text() === people) {
  56.                 alert("Nu iti poti da like singur la post !");
  57.             } else {
  58.                 $.ajax({
  59.                     type: "post",
  60.                     url: "http://forumotion.96.lt/like.php/?query=post_id="+ id +"&people="+_userdata.username,
  61.                     data: string,
  62.                     beforeSend: function() {
  63.                         $(this).html('Loading...');
  64.                     },
  65.                     complete: function(response) {
  66.                         $('body').after('<div id="ipsGlobalNotification"><div class="popupWrapper"><div class="popupInner"><div class="ipsPad">You have like this </div></div></div></div>');
  67.                         console.log("[Like System] "+response.responseText);
  68.                         update_likes();
  69.                     }
  70.                 });
  71.             }
  72.         });
  73.     });
  74. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement