1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
|
/* This file is a part of CanDyDOC fileset.
File is written by Victor Nakoryakov and placed into the public domain.
This file is javascript with classes that represents explorer window.
And things related to navigation. */
var explorer = new Explorer();
///////////////////////////////////////////////////////////////////////////////
// Current symbol marker class constructor
///////////////////////////////////////////////////////////////////////////////
function Marker()
{
this.top = document.createElement("div");
this.middle = document.createElement("div");
this.bottom = document.createElement("div");
this.container = document.createElement("div");
this.setTo = function(term)
{
// find definition related to `term`
var def = term.nextSibling;
while (def && def.nodeName != "DD")
def = def.nextSibling;
var defHeight = 0;
var childrenHeight = 0; // children of current declaration
if (def)
{
defHeight = def.offsetHeight;
var child = def.firstChild;
// traverse until DL tag, until children definition
while (child && child.nodeName != "DL")
child = child.nextSibling;
if (child)
childrenHeight = child.offsetHeight;
}
this.top.style.height = term.offsetHeight;
this.middle.style.height = defHeight - childrenHeight;
this.bottom.style.height = childrenHeight;
if (childrenHeight == 0)
this.bottom.style.display = "none";
else
this.bottom.style.display = "";
this.container.style.left = getLeft(term) - 8;
this.container.style.top = getTop(term);
this.container.style.display = "";
}
///////////////////////////////////////////////////////////////////////////
this.container.style.position = "absolute";
this.container.style.display = "none";
this.top.className = "markertop";
this.middle.className = "markermiddle";
this.bottom.className = "markerbottom";
this.container.appendChild(this.top);
this.container.appendChild(this.middle);
this.container.appendChild(this.bottom);
//document.body.appendChild( this.container );
// Workaround bug in IE 5/6. We can not append anything to document body until
// full page load.
window.marker = this;
if (window.addEventListener)
window.addEventListener("load", new Function("document.body.appendChild( window.marker.container );"), false);
else if (window.attachEvent)
window.attachEvent("onload", new Function("document.body.appendChild( window.marker.container );"));
}
///////////////////////////////////////////////////////////////////////////////
// Outline class constructor
///////////////////////////////////////////////////////////////////////////////
function Outline()
{
this.tree = new TreeView();
this.mountPoint = null;
this.writeEnabled = false;
this.marker = new Marker();
this.classRegExp = new RegExp;
this.structRegExp = new RegExp;
this.enumRegExp = new RegExp;
this.templateRegExp = new RegExp;
this.aliasRegExp = new RegExp;
this.funcRegExp = new RegExp;
this.incSymbolLevel = function()
{
if (this.mountPoint == null)
this.mountPoint = this.tree.children[ 0 ];
else
this.mountPoint = this.mountPoint.lastChild();
}
this.decSymbolLevel = function()
{
// place icons near items according to extracted below type
for (var i = 0; i < this.mountPoint.children.length; ++i)
{
child = this.mountPoint.children[i];
var term = child.termRef;
// find first span node
var n = term.firstChild;
while (n && n.nodeName != "SPAN")
n = n.nextSibling;
if (!n) // shouldn't happen
continue;
var iconSrc;
if (n.firstChild.nodeName == "#text")
{
var text = n.firstChild.data; // text before declaration
if ( this.classRegExp.test(text) )
iconSrc = "candydoc/img/outline/class.gif";
else if ( this.structRegExp.test(text) )
iconSrc = "candydoc/img/outline/struct.gif";
else if ( this.enumRegExp.test(text) )
iconSrc = "candydoc/img/outline/enum.gif";
else if ( this.templateRegExp.test(text) )
iconSrc = "candydoc/img/outline/template.gif";
else if ( this.aliasRegExp.test(text) )
iconSrc = "candydoc/img/outline/alias.gif";
else // function or variable? check whether '(' ')' exists on the right
{
var np = n.firstChild;
while (np && np.nodeName != "SCRIPT") // find our script "onDecl"
np = np.nextSibling;
if (np && np.nextSibling && np.nextSibling.nodeName == "#text" &&
this.funcRegExp.test(np.nextSibling.data))
{
iconSrc = "candydoc/img/outline/func.gif";
}
else
iconSrc = "candydoc/img/outline/var.gif";
}
}
else // enum member ?
iconSrc = "candydoc/img/outline/var.gif";
child.icon.src = iconSrc;
child.icon.width = 16;
child.icon.height = 16;
}
this.mountPoint = this.mountPoint.parentNode;
}
this.addDecl = function(decl)
{
function getLastLeaf(elem)
{
if (elem.childNodes.length > 0)
return getLastLeaf(elem.lastChild);
else
return elem;
}
function getCurrentTerm()
{
var ret = getLastLeaf( document.getElementById("content") );
while (ret && ret.nodeName != "DT")
ret = ret.parentNode;
return ret;
}
if (this.writeEnabled)
{
var node = this.mountPoint.createChild(decl);
node.termRef = getCurrentTerm();
node.setOnclick( new Function("explorer.outline.mark(this.termRef);") );
}
}
this.mark = function(term)
{
this.marker.setTo(term);
window.scrollTo(0, getTop(term) - getWindowHeight() / 6);
}
this.classRegExp.compile("(.*\b)?class(\b.*)?");
this.structRegExp.compile("(.*\b)?struct(\b.*)?");
this.enumRegExp.compile("(.*\b)?enum(\b.*)?");
this.templateRegExp.compile("(.*\b)?template(\b.*)?");
this.aliasRegExp.compile("(.*\b)?alias(\b.*)?");
this.funcRegExp.compile(/.*\(.*/);
}
///////////////////////////////////////////////////////////////////////////////
// Package explorer class constructor
///////////////////////////////////////////////////////////////////////////////
function PackageExplorer()
{
this.tree = new TreeView(true);
this.addModule = function(mod)
{
var moduleIco = "candydoc/img/outline/module.gif";
var packageIco = "candydoc/img/outline/package.gif";
var path = mod.split("\.");
var node = this.tree.branch(path[0]);
if ( !node )
node = this.tree.createBranch(path[0], (path.length == 1) ? moduleIco : packageIco);
for (var i = 1; i < path.length; ++i)
{
var prev = node;
node = node.child(path[i]);
if (!node)
node = prev.createChild(path[i], (path.length == i + 1) ? moduleIco : packageIco);
if (path.length == i + 1)
node.setRef(path[i] + ".html");
}
}
}
///////////////////////////////////////////////////////////////////////////////
// Explorer class constructor
///////////////////////////////////////////////////////////////////////////////
function Explorer()
{
this.outline = new Outline();
this.packageExplorer = new PackageExplorer();
this.tabs = new Array();
this.tabCount = 0;
this.initialize = function(moduleName)
{
this.tabArea = document.getElementById("tabarea");
this.clientArea = document.getElementById("explorerclient");
// prevent text selection
this.tabArea.onmousedown = new Function("return false;");
this.tabArea.onclick = new Function("return true;");
this.tabArea.onselectstart = new Function("return false;");
this.clientArea.onmousedown = new Function("return false;");
this.clientArea.onclick = new Function("return true;");
this.clientArea.onselectstart = new Function("return false;");
this.outline.tree.createBranch( moduleName, "candydoc/img/outline/module.gif" );
// create tabs
this.createTab("Outline", this.outline.tree.domEntry);
this.createTab("Package", this.packageExplorer.tree.domEntry);
}
this.createTab = function(name, domEntry)
{
var tab = new Object();
this.tabs[name] = tab;
this.tabCount++;
tab.domEntry = domEntry;
tab.labelSpan = document.createElement("span");
if (this.tabCount > 1)
{
tab.labelSpan.className = "inactivetab";
tab.domEntry.style.display = "none";
}
else
{
tab.labelSpan.className = "activetab";
tab.domEntry.style.display = "";
}
tab.labelSpan.appendChild( document.createTextNode(name) );
tab.labelSpan.owner = this;
tab.labelSpan.onclick = new Function("this.owner.setSelection('" + name + "');");
this.tabArea.appendChild( tab.labelSpan );
this.clientArea.appendChild( domEntry );
}
this.setSelection = function(tabName)
{
for (name in this.tabs)
{
this.tabs[name].labelSpan.className = "inactivetab";
this.tabs[name].domEntry.style.display = "none";
}
this.tabs[tabName].labelSpan.className = "activetab";
this.tabs[tabName].domEntry.style.display = "";
}
}
|