autodoc.git / modref / site.js

version» Context lines:

autodoc.git/modref/site.js:4:      var PikeDoc = null;      if (!window.console) {    window.console = {log:function(){},error:function(){}};   }      /*    Encapsulate so we don't clutter the global scope   */ - (function(window, document, console) { + (function(window, document) {   'use strict';      // The scroll position at which the navbar sticks. This actually gets   // calculated dynamically upon page load.   var stickyScrollBreak = 70, -  +  // Window width when we go to mobile mode    mobileBreakPoint = 800,    // The navbar to the left, HTMLElement    navbar, innerNavbar,    // Content wrapper, HTMLElement    content,    // The height of the navbar    navbarHeight,    // The height of the window    windowHeight,    // The height of the header    headerHeight, - // The heaigh of the footer +  // The height of the footer    footerHeight,    // The menu hamburger when in mobile mode    burger,    // Optimization┬« - objectKeys = Object.keys; +  objectKeys = Object.keys, +  // Functions to run when DOM is ready +  onDOMReadyQueue = [];      // Hide the navbox when on the start page where the prev and next links   // doesn't lead anywhere   function maybeHideNavbox() {    var navbox = document.getElementsByClassName('navbox')[0];    var prev = navbox.getElementsByClassName('prev')[0];    var next = navbox.getElementsByClassName('next')[0];    prev = prev.getAttribute('href');    next = next.getAttribute('href');   
autodoc.git/modref/site.js:51:   }      // And if on the start page hide the Top link in the side navbar   function hideTopLink() {    var top = document.getElementsByClassName('top head');    top[0].style.display = 'none';   }      // Called when DOM is ready   function onPageLoad() { +  var versionElems, dateElems, i, tmp; +     maybeHideNavbox();    navbar = document.getElementsByClassName('navbar')[0];    content = document.getElementsByClassName('content')[0];    footerHeight = document.getElementsByTagName('footer')[0].offsetHeight;    windowHeight = window.outerHeight;    headerHeight = document.getElementsByTagName('header')[0].offsetHeight;    navbarHeight = windowHeight - content.offsetTop - footerHeight;    innerNavbar = document.getElementById('navbar');    burger = document.getElementById('burger');    -  +  // When the doc is compiled with FLAG_NO_DYNAMIC the version and publish date +  // will not be written to the pages but inserted with JS. If the VERSION +  // symbol exists we need to put the version and pubdate in the elements with +  // attributes data-id="version" and data-id="date". +  if (PikeDoc.VERSION) { +  versionElems = document.querySelectorAll('[data-id="version"]'); +  dateElems = document.querySelectorAll('[data-id="date"]'); +  +  for (i = 0; i < versionElems.length; i++) { +  versionElems[i].innerHTML = PikeDoc.VERSION; +  } +  +  for (i = 0; i < dateElems.length; i++) { +  dateElems[i].innerHTML = PikeDoc.PUBDATE; +  } +  } +  else { +  tmp = document.querySelector('[data-id="version"]'); +  PikeDoc.VERSION = tmp.textContent; +  tmp = document.querySelector('[data-id="date"]'); +  PikeDoc.PUBDATE = tmp.textContent; +  } +     stickyScrollBreak = headerHeight;   }      var iAmSticky; - // Invoked when DOM is ready + // Invoked when DOM is ready, and use as callback for onscroll.   function onPageScroll() {    // If scrollY is larger than the sticky position ...    if (window.scrollY > stickyScrollBreak) {    // ... see if we're already sticky and return if so ...    if (iAmSticky) {    return;    }    // ... or else set to sticky.    iAmSticky = true;    content.style.minHeight = (windowHeight - headerHeight - -  footerHeight + 20) + 'px'; +  footerHeight + 5) + 'px';    navbar.classList.add('sticky');    }    // If scrollY is less than the sticky position ...    else {    // ... see if we're explicitly non-sticky and return if so ...    if (iAmSticky === false) {    return;    }    // ... else set to explicitly non-sticky    iAmSticky = false;
autodoc.git/modref/site.js:117:    }   }      function onBurgerClick() {    document.body.classList.toggle('menu-open');    return false;   }      function setMobileMode() {    document.removeEventListener('scroll', onPageScroll); -  document.addEventListener('scroll', onMobilePageScroll); +  document.addEventListener('scroll', onMobilePageScroll, false);    burger.removeEventListener('click', onBurgerClick); -  burger.addEventListener('click', onBurgerClick); +  burger.addEventListener('click', onBurgerClick, false);    navbar.classList.remove('sticky');    iAmSticky = false;   }      function setDesktopMode() {    document.removeEventListener('scroll', onMobilePageScroll); -  document.addEventListener('scroll', onPageScroll); +  document.addEventListener('scroll', onPageScroll, false);    burger.removeEventListener('click', onBurgerClick);    document.body.classList.remove('menu-open');   }      var iAmMobile = false;   function onWindowResize() {    if (document.body.offsetWidth < mobileBreakPoint) {    if (iAmMobile) {    return;    }
autodoc.git/modref/site.js:154:    }    iAmMobile = false;    document.body.classList.remove('mobile');    setDesktopMode();    }   }      // We only care about fairly modern browsers   if (document.addEventListener) {    // Fire when the DOM is ready -  document.addEventListener("DOMContentLoaded", function() { +  document.addEventListener('DOMContentLoaded', function() {    onPageLoad();    cacheFactory.setMenu();    PikeDoc.domReady(true);    onWindowResize(); -  window.addEventListener('resize', onWindowResize); -  document.addEventListener('scroll', iAmMobile ? onMobilePageScroll : -  onPageScroll); -  }); +  window.addEventListener('resize', onWindowResize, false); +  document.addEventListener('scroll', iAmMobile ? onMobilePageScroll +  : onPageScroll, +  false); +  }, false);   }      // During a session each generated menu is cached locally in a sessionStorage   // (if available). This one handles that.   var cacheFactory = (function() {    var cache = window.sessionStorage;    var m, isChecked = false; -  +     function init() { -  if (m || PikeDoc.current.link === 'index.html') return true; -  if (isChecked && !m) return false; +  if (m || PikeDoc.current.link === 'index.html') { +  return true; +  } +  +  if (isChecked && !m) { +  return false; +  } +     if (cache) {    m = cache.getItem(PikeDoc.current.link);    isChecked = true; -  return !!m; +  if (m) { +  m = JSON.parse(m); +  return validateDate(m.time);    } -  +  return false; +  } +     isChecked = true; -  +     return false;    }    -  +  function validateDate(time) { +  var t = PikeDoc.PUBDATE; +  if (!t) { +  t = new Date(); +  t.setTime(t.getTime() - (3600*1000)*48); +  return t < new Date(time); +  } +  +  return getPubDate() < new Date(time); +  } +  +  function getPubDate() { +  if (PikeDoc.PUBDATE) { +  return new Date(Date.parse(PikeDoc.PUBDATE)); +  } +  return new Date(); +  } +     function store() {    if (cache) { -  cache.setItem(PikeDoc.current.link||'root', innerNavbar.innerHTML); +  var obj = { +  time: new Date().getTime(), +  value: innerNavbar.innerHTML +  }; +  +  cache.setItem(PikeDoc.current.link||'root', JSON.stringify(obj));    }    }       function setMenu() {    if (m) { -  innerNavbar.innerHTML = m; +  innerNavbar.innerHTML = m.value;    }    }       return {    hasCache: init,    store: store,    setMenu: setMenu    };   }());   
autodoc.git/modref/site.js:277:    }       return {    basedir: basedir,    hasPrefix: hasPrefix,    adjustLink: adjustLink,    mergeChildren: mergeChildren    };   }());    - // Main function/ for generating the navigation + // Main object for generating the navigation   PikeDoc = (function() {    var symbols = [],    symbolsMap = {},    endInherits = [],    inheritList = [],    isDomReady = false,    isAllLoaded = false,    isInline = true,    current;   
autodoc.git/modref/site.js:302:    }       Symbol.prototype = {    addChildren: function(type, children) {    this._children[type] = children;    return this;    },    finish: function() {    var my = this;    +  // window.console.log('### Symbol.finish(', this.name, ')'); +     objectKeys(this._children).forEach(function(k) {    my.children = my.children.concat(my._children[k]);    });       lowSetInherit();    },    setInherited: function() {    this.children.forEach(function(c) {    c.inherited = 1;    });
autodoc.git/modref/site.js:345:    */    function registerSymbol(name, isInline) {    // Only the parent namespace/module/class is loaded inline, and we don't    // care about that one. Also, when on the TOP page the navigation is    // written to the page, so we don't care for that either.    if (isInline || !name) {    return new Symbol(name);    }    var s = new Symbol(name);    symbols.push(s); -  //console.log('+ Register symbol: ', name); +  // console.log(' + Register symbol: ', name);    symbolsMap[name] = s;    return s;    }       function endInherit(which) { endInherits.push(which); }    function addInherit(which) { inheritList = inheritList.concat(which); }       var types = {};    function finish() { -  +  // window.console.log('finish(', endInherits.length, ')');    if (endInherits.length === 0) {    var merge = helpers.mergeChildren;    objectKeys(symbolsMap).forEach(function(k) {    var ch = symbolsMap[k]._children;    objectKeys(ch).forEach(function(sk) {    types[sk] = merge(types[sk]||[], ch[sk]);    });    });       isAllLoaded = true;    maybeRenderNavbar();    }    }       var jsMap = {}; -  +  var scriptQueue = 0;    function loadScript(link, namespace, inherits) {    if (cacheFactory.hasCache()) {    return;    }       link = helpers.adjustLink(link);       // Already loaded    if (jsMap[link]) {    return;    }    -  +  // window.console.log('+++ Load:', link); +     jsMap[link] = true;       if (inherits) {    addInherit(inherits);    }    -  +  scriptQueue += 1; +     var s = createElem('script', { src: link }); -  +  //s.async = false;    document.head.appendChild(s);       (function(scr, ns) {    scr.addEventListener('load', function() { -  +  scriptQueue -= 1; +     if (ns) {    if (ns === true) { finish(); }    else { endInherit(ns); }    } -  }); +  else { +  finish(); +  } +  }, false);    }(s, namespace));    }       function domReady() {    isDomReady = true; -  +  onDOMReadyQueue.forEach(function(f) { +  if (typeof f === 'function') { +  f(); +  } +  });    maybeRenderNavbar();    }       function lowNavbar(container, heading, nodes, suffix) {    if (!nodes || !nodes.length)    return;    -  +  var curlnk = PikeDoc.current.link;    var adjlnk = helpers.adjustLink; -  var c = container; -  var div = createElem('div', { style: 'margin-left:0.5em' }); +  var c = container; +  var div = createElem('div', { style: 'margin-left:0.5em' });       nodes.forEach(function(n) {    var name, tnode, tmp;    name = n.name + suffix;    tnode = document.createTextNode(name);       if (!n.inherited) {    tnode = createElem('b', name);    }    -  if (n.link !== PikeDoc.current.link) { +  if (n.link !== curlnk) {    tmp = createElem('a', { href: adjlnk(n.link) });    tmp.appendChild(tnode);    tnode = tmp;    }       div.appendChild(tnode);    });       c.appendChild(createElem('b', { class: 'heading' }, heading));    c.appendChild(div);
autodoc.git/modref/site.js:455:    lowNavbar(s, 'Methods', types.method, '()');    lowNavbar(s, 'Operators', types.operator, '()');    lowNavbar(s, 'Members', types.member, '()');    lowNavbar(s, 'Namespaces', types.namespace, '::');    lowNavbar(s, 'Appendices', types.appendix, '');       cacheFactory.store();    }       function maybeRenderNavbar() { -  if (isAllLoaded && isDomReady) { +  // window.console.log('maybeRenderNavbar(', isAllLoaded, isDomReady, scriptQueue, ')'); +  if (isAllLoaded && isDomReady && scriptQueue === 0) {    navbar();    }    }    -  +  (function() { +  // If the refdoc lives in pike.lysator.liu.se we add some custom Google +  // searchability. +  if (document.location.hostname === 'pike.lysator.liu.se' || +  document.location.hostname === 'pike.local') // for dev purposes +  { +  onDOMReadyQueue.push(function() { +  // When this is run on pike.lysator.liu.se the script below will replace +  // the content of #version with a search field. Since the script below +  // is loaded async there might be the case where the version is +  // briefly shown before it's replaced, which will produce an unpleasant +  // flicker. This hack will minimize that "unpleasantry". +  var v = document.getElementById('version'); +  if (!v.classList.contains('search')) { +  v.innerHTML = ''; +  } +  }); +  +  var s = document.getElementsByTagName('script')[0]; +  var el = createElem('script', { +  src: '/assets/js/local/refdoc-search.min.js', +  async: true +  }); +  +  s.parentNode.insertBefore(el, s); +  +  var f = createElem('link', { +  href: '/assets/img/favicon.png?v=2', +  rel: 'shortcut icon' +  }); +  +  document.head.appendChild(f); +  } +  }()); +     return {    registerSymbol: registerSymbol,    endInherit: endInherit,    loadScript: loadScript,    domReady: domReady,    isInline: isInline,    current: current,    finish: finish,    };      }());    - }(window, document, window.console)); + }(window, document));