From fda8427000640072eef6584988e1be5887db3c48 Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Fri, 23 Aug 2013 14:35:09 +0200 Subject: Made a couple of minor performance tweeks to navtree.js --- src/navtree.js | 40 ++++++++++++++++++++++++++++++---------- src/navtree_js.h | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/navtree.js b/src/navtree.js index 1a46df4..ed2565a 100644 --- a/src/navtree.js +++ b/src/navtree.js @@ -1,3 +1,5 @@ +var SYNCONMSG = 'click to disable panel synchronisation'; +var SYNCOFFMSG = 'click to enable panel synchronisation'; var navTreeSubIndices = new Array(); function getData(varName) @@ -78,12 +80,12 @@ function createIndent(o,domNode,node,level) var level=-1; var n = node; while (n.parentNode) { level++; n=n.parentNode; } - var imgNode = document.createElement("img"); - imgNode.style.paddingLeft=(16*level).toString()+'px'; - imgNode.width = 16; - imgNode.height = 22; - imgNode.border = 0; if (node.childrenData) { + var imgNode = document.createElement("img"); + imgNode.style.paddingLeft=(16*level).toString()+'px'; + imgNode.width = 16; + imgNode.height = 22; + imgNode.border = 0; node.plus_img = imgNode; node.expandToggle = document.createElement("a"); node.expandToggle.href = "javascript:void(0)"; @@ -100,8 +102,12 @@ function createIndent(o,domNode,node,level) domNode.appendChild(node.expandToggle); imgNode.src = node.relpath+"ftv2pnode.png"; } else { - imgNode.src = node.relpath+"ftv2node.png"; - domNode.appendChild(imgNode); + var span = document.createElement("span"); + span.style.display = 'inline-block'; + span.style.width = 16*(level+1)+'px'; + span.style.height = '22px'; + span.innerHTML = ' '; + domNode.appendChild(span); } } @@ -320,7 +326,7 @@ function showNode(o, node, index, hash) if (!node.childrenVisited) { getNode(o, node); } - $(node.getChildrenUL()).show(); + $(node.getChildrenUL()).css({'display':'block'}); if (node.isLast) { node.plus_img.src = node.relpath+"ftv2mlastnode.png"; } else { @@ -352,8 +358,22 @@ function showNode(o, node, index, hash) } } +function removeToInsertLater(element) { + var parentNode = element.parentNode; + var nextSibling = element.nextSibling; + parentNode.removeChild(element); + return function() { + if (nextSibling) { + parentNode.insertBefore(element, nextSibling); + } else { + parentNode.appendChild(element); + } + }; +} + function getNode(o, po) { + var insertFunction = removeToInsertLater(po.li); po.childrenVisited = true; var l = po.childrenData.length-1; for (var i in po.childrenData) { @@ -361,6 +381,7 @@ function getNode(o, po) po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2], i==l); } + insertFunction(); } function gotoNode(o,subIndex,root,hash,relpath) @@ -466,6 +487,7 @@ function initNavTree(toroot,relpath) $(window).load(function(){ navTo(o,toroot,window.location.hash,relpath); + showRoot(); }); $(window).bind('hashchange', function(){ @@ -489,7 +511,5 @@ function initNavTree(toroot,relpath) navTo(o,toroot,window.location.hash,relpath); } }) - - $(window).load(showRoot); } diff --git a/src/navtree_js.h b/src/navtree_js.h index 1ad83d3..bd03629 100644 --- a/src/navtree_js.h +++ b/src/navtree_js.h @@ -1,3 +1,5 @@ +"var SYNCONMSG = 'click to disable panel synchronisation';\n" +"var SYNCOFFMSG = 'click to enable panel synchronisation';\n" "var navTreeSubIndices = new Array();\n" "\n" "function getData(varName)\n" @@ -78,12 +80,12 @@ " var level=-1;\n" " var n = node;\n" " while (n.parentNode) { level++; n=n.parentNode; }\n" -" var imgNode = document.createElement(\"img\");\n" -" imgNode.style.paddingLeft=(16*level).toString()+'px';\n" -" imgNode.width = 16;\n" -" imgNode.height = 22;\n" -" imgNode.border = 0;\n" " if (node.childrenData) {\n" +" var imgNode = document.createElement(\"img\");\n" +" imgNode.style.paddingLeft=(16*level).toString()+'px';\n" +" imgNode.width = 16;\n" +" imgNode.height = 22;\n" +" imgNode.border = 0;\n" " node.plus_img = imgNode;\n" " node.expandToggle = document.createElement(\"a\");\n" " node.expandToggle.href = \"javascript:void(0)\";\n" @@ -100,8 +102,12 @@ " domNode.appendChild(node.expandToggle);\n" " imgNode.src = node.relpath+\"ftv2pnode.png\";\n" " } else {\n" -" imgNode.src = node.relpath+\"ftv2node.png\";\n" -" domNode.appendChild(imgNode);\n" +" var span = document.createElement(\"span\");\n" +" span.style.display = 'inline-block';\n" +" span.style.width = 16*(level+1)+'px';\n" +" span.style.height = '22px';\n" +" span.innerHTML = ' ';\n" +" domNode.appendChild(span);\n" " } \n" "}\n" "\n" @@ -320,7 +326,7 @@ " if (!node.childrenVisited) {\n" " getNode(o, node);\n" " }\n" -" $(node.getChildrenUL()).show();\n" +" $(node.getChildrenUL()).css({'display':'block'});\n" " if (node.isLast) {\n" " node.plus_img.src = node.relpath+\"ftv2mlastnode.png\";\n" " } else {\n" @@ -352,8 +358,22 @@ " }\n" "}\n" "\n" +"function removeToInsertLater(element) {\n" +" var parentNode = element.parentNode;\n" +" var nextSibling = element.nextSibling;\n" +" parentNode.removeChild(element);\n" +" return function() {\n" +" if (nextSibling) {\n" +" parentNode.insertBefore(element, nextSibling);\n" +" } else {\n" +" parentNode.appendChild(element);\n" +" }\n" +" };\n" +"}\n" +"\n" "function getNode(o, po)\n" "{\n" +" var insertFunction = removeToInsertLater(po.li);\n" " po.childrenVisited = true;\n" " var l = po.childrenData.length-1;\n" " for (var i in po.childrenData) {\n" @@ -361,6 +381,7 @@ " po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2],\n" " i==l);\n" " }\n" +" insertFunction();\n" "}\n" "\n" "function gotoNode(o,subIndex,root,hash,relpath)\n" @@ -466,6 +487,7 @@ "\n" " $(window).load(function(){\n" " navTo(o,toroot,window.location.hash,relpath);\n" +" showRoot();\n" " });\n" "\n" " $(window).bind('hashchange', function(){\n" @@ -489,7 +511,5 @@ " navTo(o,toroot,window.location.hash,relpath);\n" " }\n" " })\n" -"\n" -" $(window).load(showRoot);\n" "}\n" "\n" -- cgit v0.12