// jquery.dynatree.js build 0.4.2 // Revision: 216, date: 2009-04-19 08:08:47 // Copyright (c) 2008-09 Martin Wendt (http://dynatree.googlecode.com/) // Licensed under the MIT License. var _canLog=true;function _log(mode,msg){if(!_canLog) return;var args=Array.prototype.slice.apply(arguments,[1]);var dt=new Date();var tag=dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds()+"."+dt.getMilliseconds();args[0]=tag+" - "+args[0];try{switch(mode){case"info":window.console.info.apply(window.console,args);break;case"warn":window.console.warn.apply(window.console,args);break;default:window.console.log.apply(window.console,args);}}catch(e){if(!window.console) _canLog=false;}} function logMsg(msg){Array.prototype.unshift.apply(arguments,["debug"]);_log.apply(this,arguments);} var DTNodeStatus_Error=-1;var DTNodeStatus_Loading=1;var DTNodeStatus_Ok=0;;(function($){var Class={create:function(){return function(){this.initialize.apply(this,arguments);}}} var DynaTreeNode=Class.create();DynaTreeNode.prototype={initialize:function(parent,tree,data){this.parent=parent;this.tree=tree;if(typeof data=="string") data={title:data};if(data.key==undefined) data.key="_"+tree._nodeCount++;this.data=$.extend({},$.ui.dynatree.nodedatadefaults,data);this.div=null;this.span=null;this.childList=null;this.isRead=false;this.hasSubSel=false;if(tree.initMode=="cookie"){if(tree.initActiveKey==this.data.key) tree.activeNode=this;if(tree.initFocusKey==this.data.key) tree.focusNode=this;this.bExpanded=($.inArray(this.data.key,tree.initExpandedKeys)>=0);this.bSelected=($.inArray(this.data.key,tree.initSelectedKeys)>=0);}else{if(data.activate) tree.activeNode=this;if(data.focus) tree.focusNode=this;this.bExpanded=(data.expand==true);this.bSelected=(data.select==true);} if(this.bExpanded) tree.expandedNodes.push(this);if(this.bSelected) tree.selectedNodes.push(this);},toString:function(){return"dtnode<"+this.data.key+">: '"+this.data.title+"'";},toDict:function(recursive,callback){var dict=$.extend({},this.data);dict.activate=(this.tree.activeNode===this);dict.focus=(this.tree.focusNode===this);dict.expand=this.bExpanded;dict.select=this.bSelected;if(callback) callback(dict);if(recursive&&this.childList){dict.children=[];for(var i=0;i0)||opts.minExpandLevel>1;var bHideFirstConnector=opts.rootVisible||opts.minExpandLevel>0;var res="";var p=this.parent;while(p){if(bHideFirstConnector&&(p==rootParent)) break;res=(p.isLastSibling()?cache.tagEmpty:cache.tagVline)+res;p=p.parent;} if(bHideFirstExpander&&this.parent==rootParent){}else if(this.childList||this.data.isLazy){res+=cache.tagExpander;}else{res+=cache.tagConnector;} if(opts.checkbox&&this.data.hideCheckbox!=true&&!this.data.isStatusNode){res+=cache.tagCheckbox;} if(this.data.icon){res+="";}else if(this.data.icon==false){}else{res+=cache.tagNodeIcon;} var tooltip=(this.data&&typeof this.data.tooltip=="string")?" title='"+this.data.tooltip+"'":"";res+=""+this.data.title+"";return res;},render:function(bDeep,bHidden){if(!this.div){this.span=document.createElement("span");this.span.dtnode=this;if(this.data.key) this.span.id=this.tree.options.idPrefix+this.data.key;this.div=document.createElement("div");this.div.appendChild(this.span);if(this.parent) this.parent.div.appendChild(this.div);if(this.parent==null&&!this.tree.options.rootVisible) this.span.style.display="none";} this.span.innerHTML=this._getInnerHtml();this.div.style.display=(this.parent==null||this.parent.bExpanded?"":"none");var opts=this.tree.options;var cn=opts.classNames;var isLastSib=this.isLastSibling();var cnList=[];cnList.push((this.data.isFolder)?cn.folder:cn.document);if(this.bExpanded) cnList.push(cn.expanded);if(this.data.isLazy&&!this.isRead) cnList.push(cn.lazy);if(isLastSib) cnList.push(cn.lastsib);if(this.bSelected) cnList.push(cn.selected);if(this.hasSubSel) cnList.push(cn.partsel);if(this.tree.activeNode===this) cnList.push(cn.active);if(this.data.addClass) cnList.push(this.data.addClass);cnList.push(cn.combinedExpanderPrefix +(this.bExpanded?"e":"c") +(this.data.isLazy&&!this.isRead?"d":"") +(isLastSib?"l":""));cnList.push(cn.combinedIconPrefix +(this.bExpanded?"e":"c") +(this.data.isFolder?"f":""));this.span.className=cnList.join(" ");if(bDeep&&this.childList&&(bHidden||this.bExpanded)){for(var i=0;ia").focus();}catch(e){}},isActive:function(){return(this.tree.activeNode===this);},activate:function(){var opts=this.tree.options;if(this.data.isStatusNode) return;if(opts.onQueryActivate&&opts.onQueryActivate.call(this.span,true,this)==false) return;if(this.tree.activeNode){if(this.tree.activeNode===this) return;this.tree.activeNode.deactivate();} if(opts.activeVisible) this.makeVisible();this.tree.activeNode=this;if(opts.persist) $.cookie(opts.cookieId+"-active",this.data.key,opts.cookie);$(this.span).addClass(opts.classNames.active);if(opts.onActivate) opts.onActivate.call(this.span,this);},deactivate:function(){if(this.tree.activeNode===this){var opts=this.tree.options;if(opts.onQueryActivate&&opts.onQueryActivate.call(this.span,false,this)==false) return;$(this.span).removeClass(opts.classNames.active);if(opts.persist){$.cookie(opts.cookieId+"-active","",opts.cookie);} this.tree.activeNode=null;if(opts.onDeactivate) opts.onDeactivate.call(this.span,this);}},_userActivate:function(){var activate=true;var expand=false;if(this.data.isFolder){switch(this.tree.options.clickFolderMode){case 2:activate=false;expand=true;break;case 3:activate=expand=true;break;}} if(this.parent==null&&this.tree.options.minExpandLevel>0){expand=false;} if(expand){this.toggleExpand();this.focus();} if(activate){this.activate();}},_setSubSel:function(hasSubSel){if(hasSubSel){this.hasSubSel=true;$(this.span).addClass(this.tree.options.classNames.partsel);}else{this.hasSubSel=false;$(this.span).removeClass(this.tree.options.classNames.partsel);}},_fixSelectionState:function(){if(this.bSelected){this.visit(function(dtnode){dtnode.parent._setSubSel(true);dtnode._select(true,false,false);});var p=this.parent;while(p){p._setSubSel(true);var allChildsSelected=true;for(var i=0;iDIV",this.div).animate(opts.fx,duration);}else{var $d=$(">DIV",this.div);$d.toggle();} if(opts.onExpand) opts.onExpand.call(this.span,bExpand,this);},expand:function(flag){if(!this.childList&&!this.data.isLazy&&flag) return;if(this.parent==null&&this.tree.options.minExpandLevel>0&&!flag) return;this._expand(flag);},toggleExpand:function(){this.expand(!this.bExpanded);},collapseSiblings:function(){if(this.parent==null) return;var ac=this.parent.childList;for(var i=0;i=0;i--){sib=parents[i].nextSibling();if(sib)break;}} if(sib)sib.focus();break;default:handled=false;} return!handled;},onKeypress:function(event){},onFocus:function(event){var opts=this.tree.options;if(event.type=="blur"||event.type=="focusout"){if(opts.onBlur) opts.onBlur.call(this.span,this);if(this.tree.tnFocused) $(this.tree.tnFocused.span).removeClass(opts.classNames.focused);this.tree.tnFocused=null;if(opts.persist){$.cookie(opts.cookieId+"-focus",null,$.extend({},opts.cookie));}}else if(event.type=="focus"||event.type=="focusin"){if(this.tree.tnFocused&&this.tree.tnFocused!==this){this.tree.logDebug("dtnode.onFocus: out of sync: curFocus: %o",this.tree.tnFocused);$(this.tree.tnFocused.span).removeClass(opts.classNames.focused);} this.tree.tnFocused=this;if(opts.onFocus) opts.onFocus.call(this.span,this);$(this.tree.tnFocused.span).addClass(opts.classNames.focused);if(opts.persist) $.cookie(opts.cookieId+"-focus",this.data.key,opts.cookie);}},_postInit:function(){if(opts.onPostInit) opts.onPostInit.call(this.span,this);},visit:function(fn,data,includeSelf){var n=0;if(includeSelf==true){if(fn(this,data)==false) return 1;n++;} if(this.childList) for(var i=0;i=dtnode.getLevel()) this.bExpanded=true;if(!dtnode.data.isStatusNode&&opts.selectMode==3&&!tree.isInitializing()) dtnode._fixSelectionState();if(tree.bEnableUpdate) this.render(true,true);return dtnode;},_addNode:function(data){return this._addChildNode(new DynaTreeNode(this,this.tree,data));},append:function(obj){if(!obj||obj.length==0) return;if(!obj.length) obj=[obj];var prevFlag=this.tree.enableUpdate(false);var tnFirst=null;for(var i=0;i",tagVline:"",tagExpander:"",tagConnector:"",tagNodeIcon:"",tagCheckbox:"",lastentry:undefined};this.divTree=divContainer;this.tnRoot=new DynaTreeNode(null,this,{title:this.options.title,key:"root"});this.tnRoot.data.isFolder=true;this.tnRoot.render(false,false);this.divRoot=this.tnRoot.div;this.divRoot.className=this.options.classNames.container;this.divTree.appendChild(this.divRoot);},toString:function(){return"DynaTree '"+this.options.title+"'";},toDict:function(){return this.tnRoot.toDict(true);},logDebug:function(msg){if(this.options.debugLevel>=2){Array.prototype.unshift.apply(arguments,["debug"]);_log.apply(this,arguments);}},logInfo:function(msg){if(this.options.debugLevel>=1){Array.prototype.unshift.apply(arguments,["info"]);_log.apply(this,arguments);}},logWarning:function(msg){Array.prototype.unshift.apply(arguments,["warn"]);_log.apply(this,arguments);},isInitializing:function(){return(this.initMode=="data"||this.initMode=="cookie"||this.initMode=="postInit");},_changeNodeList:function(mode,node,bAdd){if(!node) return false;var cookieName=this.options.cookieId+"-"+mode;var nodeList=(mode=="expand")?this.expandedNodes:this.selectedNodes;var idx=$.inArray(node,nodeList);if(bAdd){if(idx>=0) return false;nodeList.push(node);}else{if(idx<0) return false;nodeList.splice(idx,1);} if(this.options.persist){var keyList=$.map(nodeList,function(e,i){return e.data.key});$.cookie(cookieName,keyList.join(","),this.options.cookie);}else{}},redraw:function(){this.logDebug("dynatree.redraw()...");this.tnRoot.render(true,true);this.logDebug("dynatree.redraw() done.");},getRoot:function(){return this.tnRoot;},getNodeByKey:function(key){var el=document.getElementById(this.options.idPrefix+key);return(el&&el.dtnode)?el.dtnode:null;},getActiveNode:function(){return this.activeNode;},getSelectedNodes:function(stopOnParents){if(stopOnParents==true){var nodeList=[];this.tnRoot.visit(function(dtnode){if(dtnode.bSelected){nodeList.push(dtnode);return false;}});return nodeList;}else{return this.selectedNodes;}},activateKey:function(key){var dtnode=this.getNodeByKey(key);if(!dtnode){this.activeNode=null;return null;} dtnode.focus();dtnode.activate();return dtnode;},selectKey:function(key,select){var dtnode=this.getNodeByKey(key);if(!dtnode) return null;dtnode.select(select);return dtnode;},enableUpdate:function(bEnable){if(this.bEnableUpdate==bEnable) return bEnable;this.bEnableUpdate=bEnable;if(bEnable) this.redraw();return!bEnable;},visit:function(fn,data,includeRoot){return this.tnRoot.visit(fn,data,includeRoot);},_createFromTag:function(parentTreeNode,$ulParent){var self=this;$ulParent.find(">li").each(function(){var $li=$(this);var $liSpan=$li.find(">span:first");var title;if($liSpan.length){title=$liSpan.html();}else{title=$li.html();var iPos=title.search(/
    =0) title=$.trim(title.substring(0,iPos));else title=$.trim(title);} var data={title:title,isFolder:$li.hasClass("folder"),isLazy:$li.hasClass("lazy"),expand:$li.hasClass("expanded"),select:$li.hasClass("selected"),activate:$li.hasClass("active"),focus:$li.hasClass("focused")};if($li.attr("title")) data.tooltip=$li.attr("title");if($li.attr("id")) data.key=$li.attr("id");if($li.attr("data")){var dataAttr=$.trim($li.attr("data"));if(dataAttr){if(dataAttr.charAt(0)!="{") dataAttr="{"+dataAttr+"}" try{$.extend(data,eval("("+dataAttr+")"));}catch(e){throw("Error parsing node data: "+e+"\ndata:\n'"+dataAttr+"'");}}} childNode=parentTreeNode._addNode(data);var $ul=$li.find(">ul:first");if($ul.length){self._createFromTag(childNode,$ul);}});},lastentry:undefined};$.widget("ui.dynatree",{init:function(){return this._init();},_init:function(){logMsg("Dynatree._init(): version='%s', debugLevel=%o.",DynaTree.version,this.options.debugLevel);this.options.event+=".dynatree";var $this=this.element;var opts=this.options;if(!opts.imagePath){$("script").each(function(){if(this.src.search(/.*dynatree[^/]*\.js$/i)>=0){if(this.src.indexOf("/")>=0) opts.imagePath=this.src.slice(0,this.src.lastIndexOf("/"))+"/skin/";else opts.imagePath="skin/";logMsg("Guessing imagePath from '%s': '%s'",this.src,opts.imagePath);return false;}});} var divContainer=$this.get(0);if(opts.children||(opts.initAjax&&opts.initAjax.url)||opts.initId) $(divContainer).empty();this.tree=new DynaTree(divContainer,opts);var root=this.tree.getRoot();var prevFlag=this.tree.enableUpdate(false);this.tree.logDebug("Start init tree structure...");if(opts.children){root.append(opts.children);}else if(opts.initAjax&&opts.initAjax.url){root.appendAjax(opts.initAjax);}else if(opts.initId){this.tree._createFromTag(root,$("#"+opts.initId));}else{var $ul=$this.find(">ul").hide();this.tree._createFromTag(root,$ul);$ul.remove();} this.tree.enableUpdate(prevFlag);this.tree.logDebug("Init tree structure... done.");this.bind();this.tree.initMode="postInit";nodeList=this.tree.selectedNodes.slice();this.tree.selectedNodes=[];for(var i=0;i