reddit-pizzagate-archive/static/js/comments-toggle.js

1 line
No EOL
1.2 KiB
JavaScript

if(typeof jQuery==='undefined'){console.error("jQuery is required for comments-toggle.js.")}jQuery(document).ready(function($){function setCommentDepths(){$('.comment').filter(function(){return $(this).parents('.comment').length===0}).each(function(){traverseComment($(this),0)})}function traverseComment($comment,depth){$comment.attr('data-depth',depth);if($comment.find(".comment-toggle-arrow").length===0){var $arrow=$('<span class="comment-toggle-arrow" style="cursor:pointer; font-size:18px; margin-right:12px;">&#x25BC;</span>');$comment.find('.userinfo').first().prepend($arrow)}$comment.children('.comment').each(function(){traverseComment($(this),depth+1)})}function toggleComment($comment){var depth=parseInt($comment.attr('data-depth'),10)||0;$comment.toggleClass('collapsed');$comment.nextAll().each(function(){var $next=$(this);var nextDepth=parseInt($next.attr('data-depth'),10);if(isNaN(nextDepth)){return true;}if(nextDepth<=depth){return false;}$next.toggleClass('hidden')})}setCommentDepths();$('body').on('click','.comment-toggle-arrow',function(e){e.preventDefault();var $comment=$(this).closest('.comment');toggleComment($comment);if($comment.hasClass('collapsed')){$(this).html('&#x25B2;')}else{$(this).html('&#x25BC;')}})});