Guest User

wypokpeel

a guest
Sep 17th, 2015
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* append "toggle" button to post
  2.  * which on click executes togglePost(id)*/
  3. function addButton() {
  4.     jQuery('.entry').each(function () {
  5.         var entry = jQuery(this);
  6.         /* don't add buttons twice*/
  7.         if (!entry.hasClass('gotButton')) {
  8.             entry.addClass('gotButton');
  9.             var id = entry.find('.wblock').data('id');
  10.             var button = '<button onclick="togglePost(' + id + ');">-</button>';
  11.             jQuery(this).append(button);
  12.         }
  13.  
  14.     });
  15. }
  16. /* toggle post which @param id == id */
  17. function togglePost(id) {
  18.     jQuery('.wblock').each(function () {
  19.         var $this = jQuery(this);
  20.         if ($this.attr('data-id') == id) {
  21.             $this.slideToggle(300, function () {
  22.                 if ($this.is(":visible")) {
  23.                     $this.parent().find('button').text('-');
  24.                 } else {
  25.                     $this.parent().find('button').text('+');
  26.                 }
  27.             });
  28.             /* hide children comments also */
  29.             $this.parent().find('.sub').slideToggle();
  30.         }
  31.  
  32.     });
  33.  
  34.  
  35. }
  36.  
  37.  
  38. jQuery(document).ready(function () {
  39.     addButton();
  40.     /* add buttons after loading posts with ajax*/
  41.     jQuery(this).ajaxSuccess(function () {
  42.         addButton();
  43.     });
  44. });
RAW Paste Data