From 4abde895a5b579fb798e062806c8fef2289f0d8f Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Wed, 19 Apr 2017 17:21:15 +0200 Subject: Use JavaScript to collapse long comments Instead of using CSS to limit the height of package comments as implemented in 7b13203 (Limit comment height to 15 lines, 2016-03-12), use JavaScript to collapse long comments and add a link to expand them. Clicking the same link twice results in the corresponding comment being collapsed again. If JavaScript is disabled, the full comments are shown (without any possibility to collapse or expand). Signed-off-by: Lukas Fleischer --- web/html/packages.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'web/html/packages.php') diff --git a/web/html/packages.php b/web/html/packages.php index 113a1145..8d76c76d 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -72,10 +72,45 @@ function collapseDependsList(list) { }); } +function collapseComment(div) { + var linkid = div.attr('id') + 'link', + par = div.find('p'), + height = par.height(), + maxheight = 200; + + if (height <= maxheight) + return; + + par.css({ 'overflow': 'hidden', 'height': maxheight + 'px' }); + par.addClass('collapsed'); + par.after('

Show More…

'); + + $('#' + linkid).click(function(event) { + var newheight; + + if (par.hasClass('collapsed')) { + par.css({ 'height': 'auto' }); + newheight = par.height(); + par.css({ 'height': maxheight }); + $(this).text('Collapse'); + } else { + newheight = maxheight; + $(this).text('Show More…'); + } + + par.animate({ 'height': newheight }); + par.toggleClass('collapsed'); + event.preventDefault(); + }); +} + $(document).ready(function() { collapseDependsList("#pkgdepslist"); collapseDependsList("#pkgreqslist"); collapseDependsList("#pkgsrcslist"); + $(".article-content").each(function() { + collapseComment($(this)); + }); }); -- cgit v1.2.3-24-g4f1b