Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* append "toggle" button to post
- * which on click executes togglePost(id)*/
- function addButton() {
- jQuery('.entry').each(function () {
- var entry = jQuery(this);
- /* don't add buttons twice*/
- if (!entry.hasClass('gotButton')) {
- entry.addClass('gotButton');
- var id = entry.find('.wblock').data('id');
- var button = '<button onclick="togglePost(' + id + ');">-</button>';
- jQuery(this).append(button);
- }
- });
- }
- /* toggle post which @param id == id */
- function togglePost(id) {
- jQuery('.wblock').each(function () {
- var $this = jQuery(this);
- if ($this.attr('data-id') == id) {
- $this.slideToggle(300, function () {
- if ($this.is(":visible")) {
- $this.parent().find('button').text('-');
- } else {
- $this.parent().find('button').text('+');
- }
- });
- /* hide children comments also */
- $this.parent().find('.sub').slideToggle();
- }
- });
- }
- jQuery(document).ready(function () {
- addButton();
- /* add buttons after loading posts with ajax*/
- jQuery(this).ajaxSuccess(function () {
- addButton();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement