Fossil

Artifact [273d05ebd5]
Login

Artifact 273d05ebd552370468c435e7c60a036d082c2eb36d2ba0729d04c622f6d25b8c:


(function(F/*the fossil object*/){
  "use strict";
  /* JS code for /forumpage and friends. Requires fossil.dom. */
  const P = fossil.page, D = fossil.dom;
 
  F.onPageLoad(function(){
    const scrollbarIsVisible = (e)=>e.scrollHeight > e.clientHeight;
    const getButtonHandler = function(contentElem){
      return function(ev){
        const btn = ev.target;
        const isExpanded = D.hasClass(contentElem,'expanded');
        btn.innerText = isExpanded ? 'Expand...' : 'Collapse';
        contentElem.classList.toggle('expanded');
      };
    };
    const doCollapser = function(forumPostWrapper){
      const content = forumPostWrapper.querySelector('div.forumPostBody');
      if(!scrollbarIsVisible(content)) return;
      const button = D.button('Expand...');
      button.classList.add('forum-post-collapser');
      button.addEventListener('click', getButtonHandler(content), false);
      forumPostWrapper.insertBefore(button, content.nextSibling);
    };
    document.querySelectorAll(
      'div.forumHier, div.forumTime, div.forumHierRoot'
    ).forEach(doCollapser)
  });
  
})(window.fossil);