464 lines
No EOL
17 KiB
HTML
464 lines
No EOL
17 KiB
HTML
<html><head><title>TreeNodeUI.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>TreeNodeUI.js</h1><pre class="highlighted"><code><i>/**
|
|
* The TreeNode UI implementation is separate from the
|
|
* tree implementation. Unless you are customizing the tree UI,
|
|
* you should never have to use <b>this</b> directly.
|
|
*/</i>
|
|
Ext.tree.TreeNodeUI = <b>function</b>(node){
|
|
<b>this</b>.node = node;
|
|
<b>this</b>.rendered = false;
|
|
<b>this</b>.animating = false;
|
|
<b>this</b>.emptyIcon = Ext.BLANK_IMAGE_URL;
|
|
};
|
|
|
|
Ext.tree.TreeNodeUI.prototype = {
|
|
removeChild : <b>function</b>(node){
|
|
<b>if</b>(this.rendered){
|
|
<b>this</b>.ctNode.removeChild(node.ui.getEl());
|
|
}
|
|
},
|
|
|
|
beforeLoad : <b>function</b>(){
|
|
<b>this</b>.addClass("x-tree-node-loading");
|
|
},
|
|
|
|
afterLoad : <b>function</b>(){
|
|
<b>this</b>.removeClass("x-tree-node-loading");
|
|
},
|
|
|
|
onTextChange : <b>function</b>(node, text, oldText){
|
|
<b>if</b>(this.rendered){
|
|
<b>this</b>.textNode.innerHTML = text;
|
|
}
|
|
},
|
|
|
|
onDisableChange : <b>function</b>(node, state){
|
|
<b>this</b>.disabled = state;
|
|
<b>if</b>(state){
|
|
<b>this</b>.addClass("x-tree-node-disabled");
|
|
}<b>else</b>{
|
|
<b>this</b>.removeClass("x-tree-node-disabled");
|
|
}
|
|
},
|
|
|
|
onSelectedChange : <b>function</b>(state){
|
|
<b>if</b>(state){
|
|
<b>this</b>.focus();
|
|
<b>this</b>.addClass("x-tree-selected");
|
|
}<b>else</b>{
|
|
<i>//<b>this</b>.blur();</i>
|
|
<b>this</b>.removeClass("x-tree-selected");
|
|
}
|
|
},
|
|
|
|
onMove : <b>function</b>(tree, node, oldParent, newParent, index, refNode){
|
|
<b>this</b>.childIndent = null;
|
|
<b>if</b>(this.rendered){
|
|
<b>var</b> targetNode = newParent.ui.getContainer();
|
|
<b>if</b>(!targetNode){<i>//target not rendered</i>
|
|
<b>this</b>.holder = document.createElement("div");
|
|
<b>this</b>.holder.appendChild(<b>this</b>.wrap);
|
|
<b>return</b>;
|
|
}
|
|
<b>var</b> insertBefore = refNode ? refNode.ui.getEl() : null;
|
|
<b>if</b>(insertBefore){
|
|
targetNode.insertBefore(<b>this</b>.wrap, insertBefore);
|
|
}<b>else</b>{
|
|
targetNode.appendChild(<b>this</b>.wrap);
|
|
}
|
|
<b>this</b>.node.renderIndent(true);
|
|
}
|
|
},
|
|
|
|
addClass : <b>function</b>(cls){
|
|
<b>if</b>(this.elNode){
|
|
Ext.fly(<b>this</b>.elNode).addClass(cls);
|
|
}
|
|
},
|
|
|
|
removeClass : <b>function</b>(cls){
|
|
<b>if</b>(this.elNode){
|
|
Ext.fly(<b>this</b>.elNode).removeClass(cls);
|
|
}
|
|
},
|
|
|
|
remove : <b>function</b>(){
|
|
<b>if</b>(this.rendered){
|
|
<b>this</b>.holder = document.createElement("div");
|
|
<b>this</b>.holder.appendChild(<b>this</b>.wrap);
|
|
}
|
|
},
|
|
|
|
fireEvent : <b>function</b>(){
|
|
<b>return</b> this.node.fireEvent.apply(<b>this</b>.node, arguments);
|
|
},
|
|
|
|
initEvents : <b>function</b>(){
|
|
<b>this</b>.node.on("move", <b>this</b>.onMove, <b>this</b>);
|
|
<b>var</b> E = Ext.EventManager;
|
|
<b>var</b> a = <b>this</b>.anchor;
|
|
|
|
<b>var</b> el = Ext.fly(a);
|
|
|
|
<b>if</b>(Ext.isOpera){ <i>// opera render bug ignores the CSS</i>
|
|
el.setStyle("text-decoration", "none");
|
|
}
|
|
|
|
el.on("click", <b>this</b>.onClick, <b>this</b>);
|
|
el.on("dblclick", <b>this</b>.onDblClick, <b>this</b>);
|
|
el.on("contextmenu", <b>this</b>.onContextMenu, <b>this</b>);
|
|
|
|
<b>var</b> icon = Ext.fly(<b>this</b>.iconNode);
|
|
icon.on("click", <b>this</b>.onClick, <b>this</b>);
|
|
icon.on("dblclick", <b>this</b>.onDblClick, <b>this</b>);
|
|
icon.on("contextmenu", <b>this</b>.onContextMenu, <b>this</b>);
|
|
E.on(<b>this</b>.ecNode, "click", <b>this</b>.ecClick, <b>this</b>, true);
|
|
|
|
<b>if</b>(this.node.disabled){
|
|
<b>this</b>.addClass("x-tree-node-disabled");
|
|
}
|
|
<b>if</b>(this.node.hidden){
|
|
<b>this</b>.addClass("x-tree-node-disabled");
|
|
}
|
|
<b>var</b> ot = <b>this</b>.node.getOwnerTree();
|
|
<b>var</b> dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
|
|
<b>if</b>(dd && (!<b>this</b>.node.isRoot || ot.rootVisible)){
|
|
Ext.dd.Registry.register(<b>this</b>.elNode, {
|
|
node: <b>this</b>.node,
|
|
handles: [<b>this</b>.iconNode, <b>this</b>.textNode],
|
|
isHandle: false
|
|
});
|
|
}
|
|
},
|
|
|
|
hide : <b>function</b>(){
|
|
<b>if</b>(this.rendered){
|
|
<b>this</b>.wrap.style.display = "none";
|
|
}
|
|
},
|
|
|
|
show : <b>function</b>(){
|
|
<b>if</b>(this.rendered){
|
|
<b>this</b>.wrap.style.display = "";
|
|
}
|
|
},
|
|
|
|
onContextMenu : <b>function</b>(e){
|
|
e.preventDefault();
|
|
<b>this</b>.focus();
|
|
<b>this</b>.fireEvent("contextmenu", <b>this</b>.node, e);
|
|
},
|
|
|
|
onClick : <b>function</b>(e){
|
|
<b>if</b>(this.dropping){
|
|
<b>return</b>;
|
|
}
|
|
<b>if</b>(this.fireEvent("beforeclick", <b>this</b>.node, e) !== false){
|
|
<b>if</b>(!<b>this</b>.disabled && <b>this</b>.node.attributes.href){
|
|
<b>this</b>.fireEvent("click", <b>this</b>.node, e);
|
|
<b>return</b>;
|
|
}
|
|
e.preventDefault();
|
|
<b>if</b>(this.disabled){
|
|
<b>return</b>;
|
|
}
|
|
|
|
<b>if</b>(this.node.attributes.singleClickExpand && !<b>this</b>.animating && <b>this</b>.node.hasChildNodes()){
|
|
<b>this</b>.node.toggle();
|
|
}
|
|
|
|
<b>this</b>.fireEvent("click", <b>this</b>.node, e);
|
|
}<b>else</b>{
|
|
e.stopEvent();
|
|
}
|
|
},
|
|
|
|
onDblClick : <b>function</b>(e){
|
|
e.preventDefault();
|
|
<b>if</b>(this.disabled){
|
|
<b>return</b>;
|
|
}
|
|
<b>if</b>(!<b>this</b>.animating && <b>this</b>.node.hasChildNodes()){
|
|
<b>this</b>.node.toggle();
|
|
}
|
|
<b>this</b>.fireEvent("dblclick", <b>this</b>.node, e);
|
|
},
|
|
|
|
ecClick : <b>function</b>(e){
|
|
<b>if</b>(!<b>this</b>.animating && <b>this</b>.node.hasChildNodes()){
|
|
<b>this</b>.node.toggle();
|
|
}
|
|
},
|
|
|
|
startDrop : <b>function</b>(){
|
|
<b>this</b>.dropping = true;
|
|
},
|
|
|
|
<i>// delayed drop so the click event doesn't get fired on a drop</i>
|
|
endDrop : <b>function</b>(){
|
|
setTimeout(<b>function</b>(){
|
|
<b>this</b>.dropping = false;
|
|
}.createDelegate(<b>this</b>), 50);
|
|
},
|
|
|
|
expand : <b>function</b>(){
|
|
<b>this</b>.updateExpandIcon();
|
|
<b>this</b>.ctNode.style.display = "";
|
|
},
|
|
|
|
focus : <b>function</b>(){
|
|
<b>if</b>(!<b>this</b>.node.preventHScroll){
|
|
try{<b>this</b>.anchor.focus();
|
|
}catch(e){}
|
|
}<b>else</b> if(!Ext.isIE){
|
|
try{
|
|
<b>var</b> noscroll = <b>this</b>.node.getOwnerTree().el.dom;
|
|
<b>var</b> l = noscroll.scrollLeft;
|
|
<b>this</b>.anchor.focus();
|
|
noscroll.scrollLeft = l;
|
|
}catch(e){}
|
|
}
|
|
},
|
|
|
|
blur : <b>function</b>(){
|
|
try{
|
|
<b>this</b>.anchor.blur();
|
|
}catch(e){}
|
|
},
|
|
|
|
animExpand : <b>function</b>(callback){
|
|
<b>var</b> ct = Ext.get(<b>this</b>.ctNode);
|
|
ct.stopFx();
|
|
<b>if</b>(!<b>this</b>.node.hasChildNodes()){
|
|
<b>this</b>.updateExpandIcon();
|
|
<b>this</b>.ctNode.style.display = "";
|
|
Ext.callback(callback);
|
|
<b>return</b>;
|
|
}
|
|
<b>this</b>.animating = true;
|
|
<b>this</b>.updateExpandIcon();
|
|
|
|
ct.slideIn('t', {
|
|
callback : <b>function</b>(){
|
|
<b>this</b>.animating = false;
|
|
Ext.callback(callback);
|
|
},
|
|
scope: <b>this</b>,
|
|
duration: <b>this</b>.node.ownerTree.duration || .25
|
|
});
|
|
},
|
|
|
|
highlight : <b>function</b>(){
|
|
<b>var</b> tree = <b>this</b>.node.getOwnerTree();
|
|
Ext.fly(<b>this</b>.wrap).highlight(
|
|
tree.hlColor || "C3DAF9",
|
|
{endColor: tree.hlBaseColor}
|
|
);
|
|
},
|
|
|
|
collapse : <b>function</b>(){
|
|
<b>this</b>.updateExpandIcon();
|
|
<b>this</b>.ctNode.style.display = "none";
|
|
},
|
|
|
|
animCollapse : <b>function</b>(callback){
|
|
<b>var</b> ct = Ext.get(<b>this</b>.ctNode);
|
|
ct.enableDisplayMode('block');
|
|
ct.stopFx();
|
|
|
|
<b>this</b>.animating = true;
|
|
<b>this</b>.updateExpandIcon();
|
|
|
|
ct.slideOut('t', {
|
|
callback : <b>function</b>(){
|
|
<b>this</b>.animating = false;
|
|
Ext.callback(callback);
|
|
},
|
|
scope: <b>this</b>,
|
|
duration: <b>this</b>.node.ownerTree.duration || .25
|
|
});
|
|
},
|
|
|
|
getContainer : <b>function</b>(){
|
|
<b>return</b> this.ctNode;
|
|
},
|
|
|
|
getEl : <b>function</b>(){
|
|
<b>return</b> this.wrap;
|
|
},
|
|
|
|
appendDDGhost : <b>function</b>(ghostNode){
|
|
ghostNode.appendChild(<b>this</b>.elNode.cloneNode(true));
|
|
},
|
|
|
|
getDDRepairXY : <b>function</b>(){
|
|
<b>return</b> Ext.lib.Dom.getXY(<b>this</b>.iconNode);
|
|
},
|
|
|
|
onRender : <b>function</b>(){
|
|
<b>this</b>.render();
|
|
},
|
|
|
|
render : <b>function</b>(bulkRender){
|
|
<b>var</b> n = <b>this</b>.node;
|
|
<b>var</b> targetNode = n.parentNode ?
|
|
n.parentNode.ui.getContainer() : n.ownerTree.container.dom;
|
|
<b>if</b>(!<b>this</b>.rendered){
|
|
<b>this</b>.rendered = true;
|
|
<b>var</b> a = n.attributes;
|
|
|
|
<i>// add some indent caching, <b>this</b> helps performance when rendering a large tree</i>
|
|
<b>this</b>.indentMarkup = "";
|
|
<b>if</b>(n.parentNode){
|
|
<b>this</b>.indentMarkup = n.parentNode.ui.getChildIndent();
|
|
}
|
|
|
|
<b>var</b> buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', n.attributes.cls,'">',
|
|
'<span class="x-tree-node-indent">',<b>this</b>.indentMarkup,"</span>",
|
|
'<img src="', <b>this</b>.emptyIcon, '" class="x-tree-ec-icon">',
|
|
'<img src="', a.icon || <b>this</b>.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on">',
|
|
'<a hidefocus="on" href="',a.href ? a.href : "#",'" tabIndex="1" ',
|
|
a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
|
|
'<ul class="x-tree-node-ct" style="display:none;"></ul>',
|
|
"</li>"];
|
|
|
|
<b>if</b>(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
|
|
<b>this</b>.wrap = Ext.DomHelper.insertHtml("beforeBegin",
|
|
n.nextSibling.ui.getEl(), buf.join(""));
|
|
}<b>else</b>{
|
|
<b>this</b>.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
|
|
}
|
|
<b>this</b>.elNode = <b>this</b>.wrap.childNodes[0];
|
|
<b>this</b>.ctNode = <b>this</b>.wrap.childNodes[1];
|
|
<b>var</b> cs = <b>this</b>.elNode.childNodes;
|
|
<b>this</b>.indentNode = cs[0];
|
|
<b>this</b>.ecNode = cs[1];
|
|
<b>this</b>.iconNode = cs[2];
|
|
<b>this</b>.anchor = cs[3];
|
|
<b>this</b>.textNode = cs[3].firstChild;
|
|
<b>if</b>(a.qtip){
|
|
<b>if</b>(this.textNode.setAttributeNS){
|
|
<b>this</b>.textNode.setAttributeNS("ext", "qtip", a.qtip);
|
|
<b>if</b>(a.qtipTitle){
|
|
<b>this</b>.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
|
|
}
|
|
}<b>else</b>{
|
|
<b>this</b>.textNode.setAttribute("ext:qtip", a.qtip);
|
|
<b>if</b>(a.qtipTitle){
|
|
<b>this</b>.textNode.setAttribute("ext:qtitle", a.qtipTitle);
|
|
}
|
|
}
|
|
}
|
|
<b>this</b>.initEvents();
|
|
<b>if</b>(!<b>this</b>.node.expanded){
|
|
<b>this</b>.updateExpandIcon();
|
|
}
|
|
}<b>else</b>{
|
|
<b>if</b>(bulkRender === true) {
|
|
targetNode.appendChild(<b>this</b>.wrap);
|
|
}
|
|
}
|
|
},
|
|
|
|
getAnchor : <b>function</b>(){
|
|
<b>return</b> this.anchor;
|
|
},
|
|
|
|
getTextEl : <b>function</b>(){
|
|
<b>return</b> this.textNode;
|
|
},
|
|
|
|
getIconEl : <b>function</b>(){
|
|
<b>return</b> this.iconNode;
|
|
},
|
|
|
|
updateExpandIcon : <b>function</b>(){
|
|
<b>if</b>(this.rendered){
|
|
<b>var</b> n = <b>this</b>.node, c1, c2;
|
|
<i>//console.log(n.id)</i>
|
|
<b>var</b> cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
|
|
<b>var</b> hasChild = n.hasChildNodes();
|
|
<b>if</b>(hasChild){
|
|
<b>if</b>(n.expanded){
|
|
cls += "-minus";
|
|
c1 = "x-tree-node-collapsed";
|
|
c2 = "x-tree-node-expanded";
|
|
}<b>else</b>{
|
|
cls += "-plus";
|
|
c1 = "x-tree-node-expanded";
|
|
c2 = "x-tree-node-collapsed";
|
|
}
|
|
<b>if</b>(this.wasLeaf){
|
|
<b>this</b>.removeClass("x-tree-node-leaf");
|
|
<b>this</b>.wasLeaf = false;
|
|
}
|
|
<b>if</b>(this.c1 != c1 || <b>this</b>.c2 != c2){
|
|
Ext.fly(<b>this</b>.elNode).replaceClass(c1, c2);
|
|
<b>this</b>.c1 = c1; <b>this</b>.c2 = c2;
|
|
}
|
|
}<b>else</b>{
|
|
<b>if</b>(!<b>this</b>.wasLeaf){
|
|
Ext.fly(<b>this</b>.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
|
|
<b>this</b>.wasLeaf = true;
|
|
}
|
|
}
|
|
<b>var</b> ecc = "x-tree-ec-icon "+cls;
|
|
<b>if</b>(this.ecc != ecc){
|
|
<b>this</b>.ecNode.className = ecc;
|
|
<b>this</b>.ecc = ecc;
|
|
}
|
|
}
|
|
},
|
|
|
|
getChildIndent : <b>function</b>(){
|
|
<b>if</b>(!<b>this</b>.childIndent){
|
|
<b>var</b> buf = [];
|
|
<b>var</b> p = <b>this</b>.node;
|
|
<b>while</b>(p){
|
|
<b>if</b>(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
|
|
<b>if</b>(!p.isLast()) {
|
|
buf.unshift('<img src="'+<b>this</b>.emptyIcon+'" class="x-tree-elbow-line">');
|
|
} <b>else</b> {
|
|
buf.unshift('<img src="'+<b>this</b>.emptyIcon+'" class="x-tree-icon">');
|
|
}
|
|
}
|
|
p = p.parentNode;
|
|
}
|
|
<b>this</b>.childIndent = buf.join("");
|
|
}
|
|
<b>return</b> this.childIndent;
|
|
},
|
|
|
|
renderIndent : <b>function</b>(){
|
|
<b>if</b>(this.rendered){
|
|
<b>var</b> indent = "";
|
|
<b>var</b> p = <b>this</b>.node.parentNode;
|
|
<b>if</b>(p){
|
|
indent = p.ui.getChildIndent();
|
|
}
|
|
<b>if</b>(this.indentMarkup != indent){ <i>// don't rerender <b>if</b> not required</i>
|
|
<b>this</b>.indentNode.innerHTML = indent;
|
|
<b>this</b>.indentMarkup = indent;
|
|
}
|
|
<b>this</b>.updateExpandIcon();
|
|
}
|
|
}
|
|
};
|
|
|
|
Ext.tree.RootTreeNodeUI = <b>function</b>(){
|
|
Ext.tree.RootTreeNodeUI.superclass.constructor.apply(<b>this</b>, arguments);
|
|
};
|
|
Ext.extend(Ext.tree.RootTreeNodeUI, Ext.tree.TreeNodeUI, {
|
|
render : <b>function</b>(){
|
|
<b>if</b>(!<b>this</b>.rendered){
|
|
<b>var</b> targetNode = <b>this</b>.node.ownerTree.container.dom;
|
|
<b>this</b>.node.expanded = true;
|
|
targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
|
|
<b>this</b>.wrap = <b>this</b>.ctNode = targetNode.firstChild;
|
|
}
|
|
},
|
|
collapse : <b>function</b>(){
|
|
},
|
|
expand : <b>function</b>(){
|
|
}
|
|
});</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
|
|
</body></html> |