38fcc662be 2010-11-10 kinaba: /* This file is a part of CanDyDOC fileset. 38fcc662be 2010-11-10 kinaba: File is written by Victor Nakoryakov and placed into the public domain. 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: This file is javascript with classes that represents explorer window. 38fcc662be 2010-11-10 kinaba: And things related to navigation. */ 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: var explorer = new Explorer(); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: // Current symbol marker class constructor 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: function Marker() 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: this.top = document.createElement("div"); 38fcc662be 2010-11-10 kinaba: this.middle = document.createElement("div"); 38fcc662be 2010-11-10 kinaba: this.bottom = document.createElement("div"); 38fcc662be 2010-11-10 kinaba: this.container = document.createElement("div"); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.setTo = function(term) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: // find definition related to `term` 38fcc662be 2010-11-10 kinaba: var def = term.nextSibling; 38fcc662be 2010-11-10 kinaba: while (def && def.nodeName != "DD") 38fcc662be 2010-11-10 kinaba: def = def.nextSibling; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: var defHeight = 0; 38fcc662be 2010-11-10 kinaba: var childrenHeight = 0; // children of current declaration 38fcc662be 2010-11-10 kinaba: if (def) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: defHeight = def.offsetHeight; 38fcc662be 2010-11-10 kinaba: var child = def.firstChild; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: // traverse until DL tag, until children definition 38fcc662be 2010-11-10 kinaba: while (child && child.nodeName != "DL") 38fcc662be 2010-11-10 kinaba: child = child.nextSibling; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: if (child) 38fcc662be 2010-11-10 kinaba: childrenHeight = child.offsetHeight; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.top.style.height = term.offsetHeight; 38fcc662be 2010-11-10 kinaba: this.middle.style.height = defHeight - childrenHeight; 38fcc662be 2010-11-10 kinaba: this.bottom.style.height = childrenHeight; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: if (childrenHeight == 0) 38fcc662be 2010-11-10 kinaba: this.bottom.style.display = "none"; 38fcc662be 2010-11-10 kinaba: else 38fcc662be 2010-11-10 kinaba: this.bottom.style.display = ""; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.container.style.left = getLeft(term) - 8; 38fcc662be 2010-11-10 kinaba: this.container.style.top = getTop(term); 38fcc662be 2010-11-10 kinaba: this.container.style.display = ""; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: this.container.style.position = "absolute"; 38fcc662be 2010-11-10 kinaba: this.container.style.display = "none"; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.top.className = "markertop"; 38fcc662be 2010-11-10 kinaba: this.middle.className = "markermiddle"; 38fcc662be 2010-11-10 kinaba: this.bottom.className = "markerbottom"; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.container.appendChild(this.top); 38fcc662be 2010-11-10 kinaba: this.container.appendChild(this.middle); 38fcc662be 2010-11-10 kinaba: this.container.appendChild(this.bottom); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: //document.body.appendChild( this.container ); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: // Workaround bug in IE 5/6. We can not append anything to document body until 38fcc662be 2010-11-10 kinaba: // full page load. 38fcc662be 2010-11-10 kinaba: window.marker = this; 38fcc662be 2010-11-10 kinaba: if (window.addEventListener) 38fcc662be 2010-11-10 kinaba: window.addEventListener("load", new Function("document.body.appendChild( window.marker.container );"), false); 38fcc662be 2010-11-10 kinaba: else if (window.attachEvent) 38fcc662be 2010-11-10 kinaba: window.attachEvent("onload", new Function("document.body.appendChild( window.marker.container );")); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: // Outline class constructor 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: function Outline() 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: this.tree = new TreeView(); 38fcc662be 2010-11-10 kinaba: this.mountPoint = null; 38fcc662be 2010-11-10 kinaba: this.writeEnabled = false; 38fcc662be 2010-11-10 kinaba: this.marker = new Marker(); 38fcc662be 2010-11-10 kinaba: this.classRegExp = new RegExp; 38fcc662be 2010-11-10 kinaba: this.structRegExp = new RegExp; 38fcc662be 2010-11-10 kinaba: this.enumRegExp = new RegExp; 38fcc662be 2010-11-10 kinaba: this.templateRegExp = new RegExp; 38fcc662be 2010-11-10 kinaba: this.aliasRegExp = new RegExp; 38fcc662be 2010-11-10 kinaba: this.funcRegExp = new RegExp; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.incSymbolLevel = function() 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: if (this.mountPoint == null) 38fcc662be 2010-11-10 kinaba: this.mountPoint = this.tree.children[ 0 ]; 38fcc662be 2010-11-10 kinaba: else 38fcc662be 2010-11-10 kinaba: this.mountPoint = this.mountPoint.lastChild(); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.decSymbolLevel = function() 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: // place icons near items according to extracted below type 38fcc662be 2010-11-10 kinaba: for (var i = 0; i < this.mountPoint.children.length; ++i) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: child = this.mountPoint.children[i]; 38fcc662be 2010-11-10 kinaba: var term = child.termRef; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: // find first span node 38fcc662be 2010-11-10 kinaba: var n = term.firstChild; 38fcc662be 2010-11-10 kinaba: while (n && n.nodeName != "SPAN") 38fcc662be 2010-11-10 kinaba: n = n.nextSibling; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: if (!n) // shouldn't happen 38fcc662be 2010-11-10 kinaba: continue; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: var iconSrc; 38fcc662be 2010-11-10 kinaba: if (n.firstChild.nodeName == "#text") 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: var text = n.firstChild.data; // text before declaration 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: if ( this.classRegExp.test(text) ) 38fcc662be 2010-11-10 kinaba: iconSrc = "candydoc/img/outline/class.gif"; 38fcc662be 2010-11-10 kinaba: else if ( this.structRegExp.test(text) ) 38fcc662be 2010-11-10 kinaba: iconSrc = "candydoc/img/outline/struct.gif"; 38fcc662be 2010-11-10 kinaba: else if ( this.enumRegExp.test(text) ) 38fcc662be 2010-11-10 kinaba: iconSrc = "candydoc/img/outline/enum.gif"; 38fcc662be 2010-11-10 kinaba: else if ( this.templateRegExp.test(text) ) 38fcc662be 2010-11-10 kinaba: iconSrc = "candydoc/img/outline/template.gif"; 38fcc662be 2010-11-10 kinaba: else if ( this.aliasRegExp.test(text) ) 38fcc662be 2010-11-10 kinaba: iconSrc = "candydoc/img/outline/alias.gif"; 38fcc662be 2010-11-10 kinaba: else // function or variable? check whether '(' ')' exists on the right 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: var np = n.firstChild; 38fcc662be 2010-11-10 kinaba: while (np && np.nodeName != "SCRIPT") // find our script "onDecl" 38fcc662be 2010-11-10 kinaba: np = np.nextSibling; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: if (np && np.nextSibling && np.nextSibling.nodeName == "#text" && 38fcc662be 2010-11-10 kinaba: this.funcRegExp.test(np.nextSibling.data)) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: iconSrc = "candydoc/img/outline/func.gif"; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: else 38fcc662be 2010-11-10 kinaba: iconSrc = "candydoc/img/outline/var.gif"; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: else // enum member ? 38fcc662be 2010-11-10 kinaba: iconSrc = "candydoc/img/outline/var.gif"; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: child.icon.src = iconSrc; 38fcc662be 2010-11-10 kinaba: child.icon.width = 16; 38fcc662be 2010-11-10 kinaba: child.icon.height = 16; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.mountPoint = this.mountPoint.parentNode; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.addDecl = function(decl) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: function getLastLeaf(elem) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: if (elem.childNodes.length > 0) 38fcc662be 2010-11-10 kinaba: return getLastLeaf(elem.lastChild); 38fcc662be 2010-11-10 kinaba: else 38fcc662be 2010-11-10 kinaba: return elem; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: function getCurrentTerm() 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: var ret = getLastLeaf( document.getElementById("content") ); 38fcc662be 2010-11-10 kinaba: while (ret && ret.nodeName != "DT") 38fcc662be 2010-11-10 kinaba: ret = ret.parentNode; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: return ret; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: if (this.writeEnabled) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: var node = this.mountPoint.createChild(decl); 38fcc662be 2010-11-10 kinaba: node.termRef = getCurrentTerm(); 38fcc662be 2010-11-10 kinaba: node.setOnclick( new Function("explorer.outline.mark(this.termRef);") ); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.mark = function(term) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: this.marker.setTo(term); 38fcc662be 2010-11-10 kinaba: window.scrollTo(0, getTop(term) - getWindowHeight() / 6); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.classRegExp.compile("(.*\b)?class(\b.*)?"); 38fcc662be 2010-11-10 kinaba: this.structRegExp.compile("(.*\b)?struct(\b.*)?"); 38fcc662be 2010-11-10 kinaba: this.enumRegExp.compile("(.*\b)?enum(\b.*)?"); 38fcc662be 2010-11-10 kinaba: this.templateRegExp.compile("(.*\b)?template(\b.*)?"); 38fcc662be 2010-11-10 kinaba: this.aliasRegExp.compile("(.*\b)?alias(\b.*)?"); 38fcc662be 2010-11-10 kinaba: this.funcRegExp.compile(/.*\(.*/); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: // Package explorer class constructor 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: function PackageExplorer() 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: this.tree = new TreeView(true); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.addModule = function(mod) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: var moduleIco = "candydoc/img/outline/module.gif"; 38fcc662be 2010-11-10 kinaba: var packageIco = "candydoc/img/outline/package.gif"; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: var path = mod.split("\."); 38fcc662be 2010-11-10 kinaba: var node = this.tree.branch(path[0]); 38fcc662be 2010-11-10 kinaba: if ( !node ) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: node = this.tree.createBranch(path[0], (path.length == 1) ? moduleIco : packageIco); 38fcc662be 2010-11-10 kinaba: // modified by k.inaba : link for toplevel module 38fcc662be 2010-11-10 kinaba: if (path.length == 1) 38fcc662be 2010-11-10 kinaba: node.setRef(path[0] + ".html"); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: for (var i = 1; i < path.length; ++i) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: var prev = node; 38fcc662be 2010-11-10 kinaba: node = node.child(path[i]); 38fcc662be 2010-11-10 kinaba: if (!node) 38fcc662be 2010-11-10 kinaba: node = prev.createChild(path[i], (path.length == i + 1) ? moduleIco : packageIco); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: if (path.length == i + 1) 38fcc662be 2010-11-10 kinaba: node.setRef(path[i] + ".html"); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: // Explorer class constructor 38fcc662be 2010-11-10 kinaba: /////////////////////////////////////////////////////////////////////////////// 38fcc662be 2010-11-10 kinaba: function Explorer() 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: this.outline = new Outline(); 38fcc662be 2010-11-10 kinaba: this.packageExplorer = new PackageExplorer(); 38fcc662be 2010-11-10 kinaba: this.tabs = new Array(); 38fcc662be 2010-11-10 kinaba: this.tabCount = 0; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.initialize = function(moduleName) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: this.tabArea = document.getElementById("tabarea"); 38fcc662be 2010-11-10 kinaba: this.clientArea = document.getElementById("explorerclient"); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: // prevent text selection 38fcc662be 2010-11-10 kinaba: this.tabArea.onmousedown = new Function("return false;"); 38fcc662be 2010-11-10 kinaba: this.tabArea.onclick = new Function("return true;"); 38fcc662be 2010-11-10 kinaba: this.tabArea.onselectstart = new Function("return false;"); 38fcc662be 2010-11-10 kinaba: this.clientArea.onmousedown = new Function("return false;"); 38fcc662be 2010-11-10 kinaba: this.clientArea.onclick = new Function("return true;"); 38fcc662be 2010-11-10 kinaba: this.clientArea.onselectstart = new Function("return false;"); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.outline.tree.createBranch( moduleName, "candydoc/img/outline/module.gif" ); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: // create tabs 38fcc662be 2010-11-10 kinaba: this.createTab("Outline", this.outline.tree.domEntry); 38fcc662be 2010-11-10 kinaba: this.createTab("Package", this.packageExplorer.tree.domEntry); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.createTab = function(name, domEntry) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: var tab = new Object(); 38fcc662be 2010-11-10 kinaba: this.tabs[name] = tab; 38fcc662be 2010-11-10 kinaba: this.tabCount++; 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: tab.domEntry = domEntry; 38fcc662be 2010-11-10 kinaba: tab.labelSpan = document.createElement("span"); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: if (this.tabCount > 1) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: tab.labelSpan.className = "inactivetab"; 38fcc662be 2010-11-10 kinaba: tab.domEntry.style.display = "none"; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: else 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: tab.labelSpan.className = "activetab"; 38fcc662be 2010-11-10 kinaba: tab.domEntry.style.display = ""; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: tab.labelSpan.appendChild( document.createTextNode(name) ); 38fcc662be 2010-11-10 kinaba: tab.labelSpan.owner = this; 38fcc662be 2010-11-10 kinaba: tab.labelSpan.onclick = new Function("this.owner.setSelection('" + name + "');"); 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.tabArea.appendChild( tab.labelSpan ); 38fcc662be 2010-11-10 kinaba: this.clientArea.appendChild( domEntry ); 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.setSelection = function(tabName) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: for (name in this.tabs) 38fcc662be 2010-11-10 kinaba: { 38fcc662be 2010-11-10 kinaba: this.tabs[name].labelSpan.className = "inactivetab"; 38fcc662be 2010-11-10 kinaba: this.tabs[name].domEntry.style.display = "none"; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: 38fcc662be 2010-11-10 kinaba: this.tabs[tabName].labelSpan.className = "activetab"; 38fcc662be 2010-11-10 kinaba: this.tabs[tabName].domEntry.style.display = ""; 38fcc662be 2010-11-10 kinaba: } 38fcc662be 2010-11-10 kinaba: }