sclass HDivWithVerticalExpandButton { int initialHeight; S expandButtonText = "MORE"; O contents; S btnID = aGlobalID(); *(int *initialHeight, O *contents) {} *(int *initialHeight, O *contents, S *expandButtonText) {} S html() { ret hjs(expandVars("var pressed_$btnID = false;")) + div(contents, class := "expandable", style := "max-height: " + initialHeight + "px; overflow: hidden;") + "\n" + hbuttonOnClick_noSubmit(expandButtonText, expandVars([[ pressed_$btnID = true; $(this).prev('.expandable').css('max-height', 'none'); $(this).hide(); ]]), style := "display: none", id := btnID) + "\n" + hjs(expandVars([[ { let btn = $('#$btnID'); window.check_$btnID = function() { if (pressed_$btnID) return; $(btn).toggle($(btn).prev('.expandable').outerHeight() >= $initialHeight); setTimeout(check_$btnID, 5000); }; check_$btnID(); setTimeout(check_$btnID, 1000); } ]])); } S expandVars(S js) { ret replaceDollarVars(js, +btnID, +initialHeight); } bool needsJQuery() { true; } }