git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

docs/api/navtree.js

      1 /*
      2  @licstart  The following is the entire license notice for the JavaScript code in this file.
      3 
      4  The MIT License (MIT)
      5 
      6  Copyright (C) 1997-2020 by Dimitri van Heesch
      7 
      8  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
      9  and associated documentation files (the "Software"), to deal in the Software without restriction,
     10  including without limitation the rights to use, copy, modify, merge, publish, distribute,
     11  sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
     12  furnished to do so, subject to the following conditions:
     13 
     14  The above copyright notice and this permission notice shall be included in all copies or
     15  substantial portions of the Software.
     16 
     17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
     18  BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
     20  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     22 
     23  @licend  The above is the entire license notice for the JavaScript code in this file
     24  */
     25 var navTreeSubIndices = new Array();
     26 var arrowDown = '▼';
     27 var arrowRight = '►';
     28 
     29 function getData(varName)
     30 {
     31   var i = varName.lastIndexOf('/');
     32   var n = i>=0 ? varName.substring(i+1) : varName;
     33   return eval(n.replace(/\-/g,'_'));
     34 }
     35 
     36 function stripPath(uri)
     37 {
     38   return uri.substring(uri.lastIndexOf('/')+1);
     39 }
     40 
     41 function stripPath2(uri)
     42 {
     43   var i = uri.lastIndexOf('/');
     44   var s = uri.substring(i+1);
     45   var m = uri.substring(0,i+1).match(/\/d\w\/d\w\w\/$/);
     46   return m ? uri.substring(i-6) : s;
     47 }
     48 
     49 function hashValue()
     50 {
     51   return $(location).attr('hash').substring(1).replace(/[^\w\-]/g,'');
     52 }
     53 
     54 function hashUrl()
     55 {
     56   return '#'+hashValue();
     57 }
     58 
     59 function pathName()
     60 {
     61   return $(location).attr('pathname').replace(/[^-A-Za-z0-9+&@#/%?=~_|!:,.;\(\)]/g, '');
     62 }
     63 
     64 function localStorageSupported()
     65 {
     66   try {
     67     return 'localStorage' in window && window['localStorage'] !== null && window.localStorage.getItem;
     68   }
     69   catch(e) {
     70     return false;
     71   }
     72 }
     73 
     74 function storeLink(link)
     75 {
     76   if (!$("#nav-sync").hasClass('sync') && localStorageSupported()) {
     77       window.localStorage.setItem('navpath',link);
     78   }
     79 }
     80 
     81 function deleteLink()
     82 {
     83   if (localStorageSupported()) {
     84     window.localStorage.setItem('navpath','');
     85   }
     86 }
     87 
     88 function cachedLink()
     89 {
     90   if (localStorageSupported()) {
     91     return window.localStorage.getItem('navpath');
     92   } else {
     93     return '';
     94   }
     95 }
     96 
     97 function getScript(scriptName,func,show)
     98 {
     99   var head = document.getElementsByTagName("head")[0];
    100   var script = document.createElement('script');
    101   script.id = scriptName;
    102   script.type = 'text/javascript';
    103   script.onload = func;
    104   script.src = scriptName+'.js';
    105   head.appendChild(script);
    106 }
    107 
    108 function createIndent(o,domNode,node,level)
    109 {
    110   var level=-1;
    111   var n = node;
    112   while (n.parentNode) { level++; n=n.parentNode; }
    113   if (node.childrenData) {
    114     var imgNode = document.createElement("span");
    115     imgNode.className = 'arrow';
    116     imgNode.style.paddingLeft=(16*level).toString()+'px';
    117     imgNode.innerHTML=arrowRight;
    118     node.plus_img = imgNode;
    119     node.expandToggle = document.createElement("a");
    120     node.expandToggle.href = "javascript:void(0)";
    121     node.expandToggle.onclick = function() {
    122       if (node.expanded) {
    123         $(node.getChildrenUL()).slideUp("fast");
    124         node.plus_img.innerHTML=arrowRight;
    125         node.expanded = false;
    126       } else {
    127         expandNode(o, node, false, false);
    128       }
    129     }
    130     node.expandToggle.appendChild(imgNode);
    131     domNode.appendChild(node.expandToggle);
    132   } else {
    133     var span = document.createElement("span");
    134     span.className = 'arrow';
    135     span.style.width   = 16*(level+1)+'px';
    136     span.innerHTML = ' ';
    137     domNode.appendChild(span);
    138   }
    139 }
    140 
    141 var animationInProgress = false;
    142 
    143 function gotoAnchor(anchor,aname,updateLocation)
    144 {
    145   var pos, docContent = $('#doc-content');
    146   var ancParent = $(anchor.parent());
    147   if (ancParent.hasClass('memItemLeft') ||
    148       ancParent.hasClass('memtitle') ||
    149       ancParent.hasClass('fieldname') ||
    150       ancParent.hasClass('fieldtype') ||
    151       ancParent.is(':header'))
    152   {
    153     pos = ancParent.position().top;
    154   } else if (anchor.position()) {
    155     pos = anchor.position().top;
    156   }
    157   if (pos) {
    158     var dist = Math.abs(Math.min(
    159                pos-docContent.offset().top,
    160                docContent[0].scrollHeight-
    161                docContent.height()-docContent.scrollTop()));
    162     animationInProgress=true;
    163     docContent.animate({
    164       scrollTop: pos + docContent.scrollTop() - docContent.offset().top
    165     },Math.max(50,Math.min(500,dist)),function(){
    166       if (updateLocation) window.location.href=aname;
    167       animationInProgress=false;
    168     });
    169   }
    170 }
    171 
    172 function newNode(o, po, text, link, childrenData, lastNode)
    173 {
    174   var node = new Object();
    175   node.children = Array();
    176   node.childrenData = childrenData;
    177   node.depth = po.depth + 1;
    178   node.relpath = po.relpath;
    179   node.isLast = lastNode;
    180 
    181   node.li = document.createElement("li");
    182   po.getChildrenUL().appendChild(node.li);
    183   node.parentNode = po;
    184 
    185   node.itemDiv = document.createElement("div");
    186   node.itemDiv.className = "item";
    187 
    188   node.labelSpan = document.createElement("span");
    189   node.labelSpan.className = "label";
    190 
    191   createIndent(o,node.itemDiv,node,0);
    192   node.itemDiv.appendChild(node.labelSpan);
    193   node.li.appendChild(node.itemDiv);
    194 
    195   var a = document.createElement("a");
    196   node.labelSpan.appendChild(a);
    197   node.label = document.createTextNode(text);
    198   node.expanded = false;
    199   a.appendChild(node.label);
    200   if (link) {
    201     var url;
    202     if (link.substring(0,1)=='^') {
    203       url = link.substring(1);
    204       link = url;
    205     } else {
    206       url = node.relpath+link;
    207     }
    208     a.className = stripPath(link.replace('#',':'));
    209     if (link.indexOf('#')!=-1) {
    210       var aname = '#'+link.split('#')[1];
    211       var srcPage = stripPath(pathName());
    212       var targetPage = stripPath(link.split('#')[0]);
    213       a.href = srcPage!=targetPage ? url : "javascript:void(0)";
    214       a.onclick = function(){
    215         storeLink(link);
    216         if (!$(a).parent().parent().hasClass('selected'))
    217         {
    218           $('.item').removeClass('selected');
    219           $('.item').removeAttr('id');
    220           $(a).parent().parent().addClass('selected');
    221           $(a).parent().parent().attr('id','selected');
    222         }
    223         var anchor = $(aname);
    224         gotoAnchor(anchor,aname,true);
    225       };
    226     } else {
    227       a.href = url;
    228       a.onclick = function() { storeLink(link); }
    229     }
    230   } else {
    231     if (childrenData != null)
    232     {
    233       a.className = "nolink";
    234       a.href = "javascript:void(0)";
    235       a.onclick = node.expandToggle.onclick;
    236     }
    237   }
    238 
    239   node.childrenUL = null;
    240   node.getChildrenUL = function() {
    241     if (!node.childrenUL) {
    242       node.childrenUL = document.createElement("ul");
    243       node.childrenUL.className = "children_ul";
    244       node.childrenUL.style.display = "none";
    245       node.li.appendChild(node.childrenUL);
    246     }
    247     return node.childrenUL;
    248   };
    249 
    250   return node;
    251 }
    252 
    253 function showRoot()
    254 {
    255   var headerHeight = $("#top").height();
    256   var footerHeight = $("#nav-path").height();
    257   var windowHeight = $(window).height() - headerHeight - footerHeight;
    258   (function (){ // retry until we can scroll to the selected item
    259     try {
    260       var navtree=$('#nav-tree');
    261       navtree.scrollTo('#selected',100,{offset:-windowHeight/2});
    262     } catch (err) {
    263       setTimeout(arguments.callee, 0);
    264     }
    265   })();
    266 }
    267 
    268 function expandNode(o, node, imm, showRoot)
    269 {
    270   if (node.childrenData && !node.expanded) {
    271     if (typeof(node.childrenData)==='string') {
    272       var varName    = node.childrenData;
    273       getScript(node.relpath+varName,function(){
    274         node.childrenData = getData(varName);
    275         expandNode(o, node, imm, showRoot);
    276       }, showRoot);
    277     } else {
    278       if (!node.childrenVisited) {
    279         getNode(o, node);
    280       }
    281       $(node.getChildrenUL()).slideDown("fast");
    282       node.plus_img.innerHTML = arrowDown;
    283       node.expanded = true;
    284     }
    285   }
    286 }
    287 
    288 function glowEffect(n,duration)
    289 {
    290   n.addClass('glow').delay(duration).queue(function(next){
    291     $(this).removeClass('glow');next();
    292   });
    293 }
    294 
    295 function highlightAnchor()
    296 {
    297   var aname = hashUrl();
    298   var anchor = $(aname);
    299   if (anchor.parent().attr('class')=='memItemLeft'){
    300     var rows = $('.memberdecls tr[class$="'+hashValue()+'"]');
    301     glowEffect(rows.children(),300); // member without details
    302   } else if (anchor.parent().attr('class')=='fieldname'){
    303     glowEffect(anchor.parent().parent(),1000); // enum value
    304   } else if (anchor.parent().attr('class')=='fieldtype'){
    305     glowEffect(anchor.parent().parent(),1000); // struct field
    306   } else if (anchor.parent().is(":header")) {
    307     glowEffect(anchor.parent(),1000); // section header
    308   } else {
    309     glowEffect(anchor.next(),1000); // normal member
    310   }
    311 }
    312 
    313 function selectAndHighlight(hash,n)
    314 {
    315   var a;
    316   if (hash) {
    317     var link=stripPath(pathName())+':'+hash.substring(1);
    318     a=$('.item a[class$="'+link+'"]');
    319   }
    320   if (a && a.length) {
    321     a.parent().parent().addClass('selected');
    322     a.parent().parent().attr('id','selected');
    323     highlightAnchor();
    324   } else if (n) {
    325     $(n.itemDiv).addClass('selected');
    326     $(n.itemDiv).attr('id','selected');
    327   }
    328   var topOffset=5;
    329   if (typeof page_layout!=='undefined' && page_layout==1) {
    330     topOffset+=$('#top').outerHeight();
    331   }
    332   if ($('#nav-tree-contents .item:first').hasClass('selected')) {
    333     topOffset+=25;
    334   }
    335   $('#nav-sync').css('top',topOffset+'px');
    336   showRoot();
    337 }
    338 
    339 function showNode(o, node, index, hash)
    340 {
    341   if (node && node.childrenData) {
    342     if (typeof(node.childrenData)==='string') {
    343       var varName    = node.childrenData;
    344       getScript(node.relpath+varName,function(){
    345         node.childrenData = getData(varName);
    346         showNode(o,node,index,hash);
    347       },true);
    348     } else {
    349       if (!node.childrenVisited) {
    350         getNode(o, node);
    351       }
    352       $(node.getChildrenUL()).css({'display':'block'});
    353       node.plus_img.innerHTML = arrowDown;
    354       node.expanded = true;
    355       var n = node.children[o.breadcrumbs[index]];
    356       if (index+1<o.breadcrumbs.length) {
    357         showNode(o,n,index+1,hash);
    358       } else {
    359         if (typeof(n.childrenData)==='string') {
    360           var varName = n.childrenData;
    361           getScript(n.relpath+varName,function(){
    362             n.childrenData = getData(varName);
    363             node.expanded=false;
    364             showNode(o,node,index,hash); // retry with child node expanded
    365           },true);
    366         } else {
    367           var rootBase = stripPath(o.toroot.replace(/\..+$/, ''));
    368           if (rootBase=="index" || rootBase=="pages" || rootBase=="search") {
    369             expandNode(o, n, true, true);
    370           }
    371           selectAndHighlight(hash,n);
    372         }
    373       }
    374     }
    375   } else {
    376     selectAndHighlight(hash);
    377   }
    378 }
    379 
    380 function removeToInsertLater(element) {
    381   var parentNode = element.parentNode;
    382   var nextSibling = element.nextSibling;
    383   parentNode.removeChild(element);
    384   return function() {
    385     if (nextSibling) {
    386       parentNode.insertBefore(element, nextSibling);
    387     } else {
    388       parentNode.appendChild(element);
    389     }
    390   };
    391 }
    392 
    393 function getNode(o, po)
    394 {
    395   var insertFunction = removeToInsertLater(po.li);
    396   po.childrenVisited = true;
    397   var l = po.childrenData.length-1;
    398   for (var i in po.childrenData) {
    399     var nodeData = po.childrenData[i];
    400     po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2],
    401       i==l);
    402   }
    403   insertFunction();
    404 }
    405 
    406 function gotoNode(o,subIndex,root,hash,relpath)
    407 {
    408   var nti = navTreeSubIndices[subIndex][root+hash];
    409   o.breadcrumbs = $.extend(true, [], nti ? nti : navTreeSubIndices[subIndex][root]);
    410   if (!o.breadcrumbs && root!=NAVTREE[0][1]) { // fallback: show index
    411     navTo(o,NAVTREE[0][1],"",relpath);
    412     $('.item').removeClass('selected');
    413     $('.item').removeAttr('id');
    414   }
    415   if (o.breadcrumbs) {
    416     o.breadcrumbs.unshift(0); // add 0 for root node
    417     showNode(o, o.node, 0, hash);
    418   }
    419 }
    420 
    421 function navTo(o,root,hash,relpath)
    422 {
    423   var link = cachedLink();
    424   if (link) {
    425     var parts = link.split('#');
    426     root = parts[0];
    427     if (parts.length>1) hash = '#'+parts[1].replace(/[^\w\-]/g,'');
    428     else hash='';
    429   }
    430   if (hash.match(/^#l\d+$/)) {
    431     var anchor=$('a[name='+hash.substring(1)+']');
    432     glowEffect(anchor.parent(),1000); // line number
    433     hash=''; // strip line number anchors
    434   }
    435   var url=root+hash;
    436   var i=-1;
    437   while (NAVTREEINDEX[i+1]<=url) i++;
    438   if (i==-1) { i=0; root=NAVTREE[0][1]; } // fallback: show index
    439   if (navTreeSubIndices[i]) {
    440     gotoNode(o,i,root,hash,relpath)
    441   } else {
    442     getScript(relpath+'navtreeindex'+i,function(){
    443       navTreeSubIndices[i] = eval('NAVTREEINDEX'+i);
    444       if (navTreeSubIndices[i]) {
    445         gotoNode(o,i,root,hash,relpath);
    446       }
    447     },true);
    448   }
    449 }
    450 
    451 function showSyncOff(n,relpath)
    452 {
    453     n.html('<img src="'+relpath+'sync_off.png" title="'+SYNCOFFMSG+'"/>');
    454 }
    455 
    456 function showSyncOn(n,relpath)
    457 {
    458     n.html('<img src="'+relpath+'sync_on.png" title="'+SYNCONMSG+'"/>');
    459 }
    460 
    461 function toggleSyncButton(relpath)
    462 {
    463   var navSync = $('#nav-sync');
    464   if (navSync.hasClass('sync')) {
    465     navSync.removeClass('sync');
    466     showSyncOff(navSync,relpath);
    467     storeLink(stripPath2(pathName())+hashUrl());
    468   } else {
    469     navSync.addClass('sync');
    470     showSyncOn(navSync,relpath);
    471     deleteLink();
    472   }
    473 }
    474 
    475 var loadTriggered = false;
    476 var readyTriggered = false;
    477 var loadObject,loadToRoot,loadUrl,loadRelPath;
    478 
    479 $(window).on('load',function(){
    480   if (readyTriggered) { // ready first
    481     navTo(loadObject,loadToRoot,loadUrl,loadRelPath);
    482     showRoot();
    483   }
    484   loadTriggered=true;
    485 });
    486 
    487 function initNavTree(toroot,relpath)
    488 {
    489   var o = new Object();
    490   o.toroot = toroot;
    491   o.node = new Object();
    492   o.node.li = document.getElementById("nav-tree-contents");
    493   o.node.childrenData = NAVTREE;
    494   o.node.children = new Array();
    495   o.node.childrenUL = document.createElement("ul");
    496   o.node.getChildrenUL = function() { return o.node.childrenUL; };
    497   o.node.li.appendChild(o.node.childrenUL);
    498   o.node.depth = 0;
    499   o.node.relpath = relpath;
    500   o.node.expanded = false;
    501   o.node.isLast = true;
    502   o.node.plus_img = document.createElement("span");
    503   o.node.plus_img.className = 'arrow';
    504   o.node.plus_img.innerHTML = arrowRight;
    505 
    506   if (localStorageSupported()) {
    507     var navSync = $('#nav-sync');
    508     if (cachedLink()) {
    509       showSyncOff(navSync,relpath);
    510       navSync.removeClass('sync');
    511     } else {
    512       showSyncOn(navSync,relpath);
    513     }
    514     navSync.click(function(){ toggleSyncButton(relpath); });
    515   }
    516 
    517   if (loadTriggered) { // load before ready
    518     navTo(o,toroot,hashUrl(),relpath);
    519     showRoot();
    520   } else { // ready before load
    521     loadObject  = o;
    522     loadToRoot  = toroot;
    523     loadUrl     = hashUrl();
    524     loadRelPath = relpath;
    525     readyTriggered=true;
    526   }
    527 
    528   $(window).bind('hashchange', function(){
    529      if (window.location.hash && window.location.hash.length>1){
    530        var a;
    531        if ($(location).attr('hash')){
    532          var clslink=stripPath(pathName())+':'+hashValue();
    533          a=$('.item a[class$="'+clslink.replace(/</g,'\\3c ')+'"]');
    534        }
    535        if (a==null || !$(a).parent().parent().hasClass('selected')){
    536          $('.item').removeClass('selected');
    537          $('.item').removeAttr('id');
    538        }
    539        var link=stripPath2(pathName());
    540        navTo(o,link,hashUrl(),relpath);
    541      } else if (!animationInProgress) {
    542        $('#doc-content').scrollTop(0);
    543        $('.item').removeClass('selected');
    544        $('.item').removeAttr('id');
    545        navTo(o,toroot,hashUrl(),relpath);
    546      }
    547   })
    548 }
    549 /* @license-end */

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.