3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.tree.TreeNodeUI"></div>/**
\r
10 * @class Ext.tree.TreeNodeUI
\r
11 * This class provides the default UI implementation for Ext TreeNodes.
\r
12 * The TreeNode UI implementation is separate from the
\r
13 * tree implementation, and allows customizing of the appearance of
\r
16 * If you are customizing the Tree's user interface, you
\r
17 * may need to extend this class, but you should never need to instantiate this class.<br>
\r
19 * This class provides access to the user interface components of an Ext TreeNode, through
\r
20 * {@link Ext.tree.TreeNode#getUI}
\r
22 Ext.tree.TreeNodeUI = function(node){
\r
24 this.rendered = false;
\r
25 this.animating = false;
\r
26 this.wasLeaf = true;
\r
27 this.ecc = 'x-tree-ec-icon x-tree-elbow';
\r
28 this.emptyIcon = Ext.BLANK_IMAGE_URL;
\r
31 Ext.tree.TreeNodeUI.prototype = {
\r
33 removeChild : function(node){
\r
35 this.ctNode.removeChild(node.ui.getEl());
\r
40 beforeLoad : function(){
\r
41 this.addClass("x-tree-node-loading");
\r
45 afterLoad : function(){
\r
46 this.removeClass("x-tree-node-loading");
\r
50 onTextChange : function(node, text, oldText){
\r
52 this.textNode.innerHTML = text;
\r
57 onDisableChange : function(node, state){
\r
58 this.disabled = state;
\r
59 if (this.checkbox) {
\r
60 this.checkbox.disabled = state;
\r
63 this.addClass("x-tree-node-disabled");
\r
65 this.removeClass("x-tree-node-disabled");
\r
70 onSelectedChange : function(state){
\r
73 this.addClass("x-tree-selected");
\r
76 this.removeClass("x-tree-selected");
\r
81 onMove : function(tree, node, oldParent, newParent, index, refNode){
\r
82 this.childIndent = null;
\r
84 var targetNode = newParent.ui.getContainer();
\r
85 if(!targetNode){//target not rendered
\r
86 this.holder = document.createElement("div");
\r
87 this.holder.appendChild(this.wrap);
\r
90 var insertBefore = refNode ? refNode.ui.getEl() : null;
\r
92 targetNode.insertBefore(this.wrap, insertBefore);
\r
94 targetNode.appendChild(this.wrap);
\r
96 this.node.renderIndent(true, oldParent != newParent);
\r
100 <div id="method-Ext.tree.TreeNodeUI-addClass"></div>/**
\r
101 * Adds one or more CSS classes to the node's UI element.
\r
102 * Duplicate classes are automatically filtered out.
\r
103 * @param {String/Array} className The CSS class to add, or an array of classes
\r
105 addClass : function(cls){
\r
107 Ext.fly(this.elNode).addClass(cls);
\r
111 <div id="method-Ext.tree.TreeNodeUI-removeClass"></div>/**
\r
112 * Removes one or more CSS classes from the node's UI element.
\r
113 * @param {String/Array} className The CSS class to remove, or an array of classes
\r
115 removeClass : function(cls){
\r
117 Ext.fly(this.elNode).removeClass(cls);
\r
122 remove : function(){
\r
124 this.holder = document.createElement("div");
\r
125 this.holder.appendChild(this.wrap);
\r
130 fireEvent : function(){
\r
131 return this.node.fireEvent.apply(this.node, arguments);
\r
135 initEvents : function(){
\r
136 this.node.on("move", this.onMove, this);
\r
138 if(this.node.disabled){
\r
139 this.onDisableChange(this.node, true);
\r
141 if(this.node.hidden){
\r
144 var ot = this.node.getOwnerTree();
\r
145 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
\r
146 if(dd && (!this.node.isRoot || ot.rootVisible)){
\r
147 Ext.dd.Registry.register(this.elNode, {
\r
149 handles: this.getDDHandles(),
\r
156 getDDHandles : function(){
\r
157 return [this.iconNode, this.textNode, this.elNode];
\r
160 <div id="method-Ext.tree.TreeNodeUI-hide"></div>/**
\r
164 this.node.hidden = true;
\r
166 this.wrap.style.display = "none";
\r
170 <div id="method-Ext.tree.TreeNodeUI-show"></div>/**
\r
174 this.node.hidden = false;
\r
176 this.wrap.style.display = "";
\r
181 onContextMenu : function(e){
\r
182 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
\r
183 e.preventDefault();
\r
185 this.fireEvent("contextmenu", this.node, e);
\r
190 onClick : function(e){
\r
195 if(this.fireEvent("beforeclick", this.node, e) !== false){
\r
196 var a = e.getTarget('a');
\r
197 if(!this.disabled && this.node.attributes.href && a){
\r
198 this.fireEvent("click", this.node, e);
\r
200 }else if(a && e.ctrlKey){
\r
203 e.preventDefault();
\r
208 if(this.node.attributes.singleClickExpand && !this.animating && this.node.isExpandable()){
\r
209 this.node.toggle();
\r
212 this.fireEvent("click", this.node, e);
\r
219 onDblClick : function(e){
\r
220 e.preventDefault();
\r
224 if(this.fireEvent("beforedblclick", this.node, e) !== false){
\r
226 this.toggleCheck();
\r
228 if(!this.animating && this.node.isExpandable()){
\r
229 this.node.toggle();
\r
231 this.fireEvent("dblclick", this.node, e);
\r
235 onOver : function(e){
\r
236 this.addClass('x-tree-node-over');
\r
239 onOut : function(e){
\r
240 this.removeClass('x-tree-node-over');
\r
244 onCheckChange : function(){
\r
245 var checked = this.checkbox.checked;
\r
247 this.checkbox.defaultChecked = checked;
\r
248 this.node.attributes.checked = checked;
\r
249 this.fireEvent('checkchange', this.node, checked);
\r
253 ecClick : function(e){
\r
254 if(!this.animating && this.node.isExpandable()){
\r
255 this.node.toggle();
\r
260 startDrop : function(){
\r
261 this.dropping = true;
\r
264 // delayed drop so the click event doesn't get fired on a drop
\r
265 endDrop : function(){
\r
266 setTimeout(function(){
\r
267 this.dropping = false;
\r
268 }.createDelegate(this), 50);
\r
272 expand : function(){
\r
273 this.updateExpandIcon();
\r
274 this.ctNode.style.display = "";
\r
278 focus : function(){
\r
279 if(!this.node.preventHScroll){
\r
280 try{this.anchor.focus();
\r
284 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
\r
285 var l = noscroll.scrollLeft;
\r
286 this.anchor.focus();
\r
287 noscroll.scrollLeft = l;
\r
292 <div id="method-Ext.tree.TreeNodeUI-toggleCheck"></div>/**
\r
293 * Sets the checked status of the tree node to the passed value, or, if no value was passed,
\r
294 * toggles the checked status. If the node was rendered with no checkbox, this has no effect.
\r
295 * @param {Boolean} (optional) The new checked status.
\r
297 toggleCheck : function(value){
\r
298 var cb = this.checkbox;
\r
300 cb.checked = (value === undefined ? !cb.checked : value);
\r
301 this.onCheckChange();
\r
308 this.anchor.blur();
\r
313 animExpand : function(callback){
\r
314 var ct = Ext.get(this.ctNode);
\r
316 if(!this.node.isExpandable()){
\r
317 this.updateExpandIcon();
\r
318 this.ctNode.style.display = "";
\r
319 Ext.callback(callback);
\r
322 this.animating = true;
\r
323 this.updateExpandIcon();
\r
326 callback : function(){
\r
327 this.animating = false;
\r
328 Ext.callback(callback);
\r
331 duration: this.node.ownerTree.duration || .25
\r
336 highlight : function(){
\r
337 var tree = this.node.getOwnerTree();
\r
338 Ext.fly(this.wrap).highlight(
\r
339 tree.hlColor || "C3DAF9",
\r
340 {endColor: tree.hlBaseColor}
\r
345 collapse : function(){
\r
346 this.updateExpandIcon();
\r
347 this.ctNode.style.display = "none";
\r
351 animCollapse : function(callback){
\r
352 var ct = Ext.get(this.ctNode);
\r
353 ct.enableDisplayMode('block');
\r
356 this.animating = true;
\r
357 this.updateExpandIcon();
\r
360 callback : function(){
\r
361 this.animating = false;
\r
362 Ext.callback(callback);
\r
365 duration: this.node.ownerTree.duration || .25
\r
370 getContainer : function(){
\r
371 return this.ctNode;
\r
374 <div id="method-Ext.tree.TreeNodeUI-getEl"></div>/**
\r
375 * Returns the element which encapsulates this node.
\r
376 * @return {HtmlElement} The DOM element. The default implementation uses a <code><li></code>.
\r
378 getEl : function(){
\r
383 appendDDGhost : function(ghostNode){
\r
384 ghostNode.appendChild(this.elNode.cloneNode(true));
\r
388 getDDRepairXY : function(){
\r
389 return Ext.lib.Dom.getXY(this.iconNode);
\r
393 onRender : function(){
\r
398 render : function(bulkRender){
\r
399 var n = this.node, a = n.attributes;
\r
400 var targetNode = n.parentNode ?
\r
401 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
\r
403 if(!this.rendered){
\r
404 this.rendered = true;
\r
406 this.renderElements(n, a, targetNode, bulkRender);
\r
409 if(this.textNode.setAttributeNS){
\r
410 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
\r
412 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
\r
415 this.textNode.setAttribute("ext:qtip", a.qtip);
\r
417 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
\r
420 }else if(a.qtipCfg){
\r
421 a.qtipCfg.target = Ext.id(this.textNode);
\r
422 Ext.QuickTips.register(a.qtipCfg);
\r
425 if(!this.node.expanded){
\r
426 this.updateExpandIcon(true);
\r
429 if(bulkRender === true) {
\r
430 targetNode.appendChild(this.wrap);
\r
436 renderElements : function(n, a, targetNode, bulkRender){
\r
437 // add some indent caching, this helps performance when rendering a large tree
\r
438 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
\r
440 var cb = Ext.isBoolean(a.checked),
\r
442 href = a.href ? a.href : Ext.isGecko ? "" : "#",
\r
443 buf = ['<li class="x-tree-node"><div ext:tree-node-id="',n.id,'" class="x-tree-node-el x-tree-node-leaf x-unselectable ', a.cls,'" unselectable="on">',
\r
444 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
\r
445 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />',
\r
446 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
\r
447 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',
\r
448 '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ',
\r
449 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>",
\r
450 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
\r
453 if(bulkRender !== true && n.nextSibling && (nel = n.nextSibling.ui.getEl())){
\r
454 this.wrap = Ext.DomHelper.insertHtml("beforeBegin", nel, buf);
\r
456 this.wrap = Ext.DomHelper.insertHtml("beforeEnd", targetNode, buf);
\r
459 this.elNode = this.wrap.childNodes[0];
\r
460 this.ctNode = this.wrap.childNodes[1];
\r
461 var cs = this.elNode.childNodes;
\r
462 this.indentNode = cs[0];
\r
463 this.ecNode = cs[1];
\r
464 this.iconNode = cs[2];
\r
467 this.checkbox = cs[3];
\r
469 this.checkbox.defaultChecked = this.checkbox.checked;
\r
472 this.anchor = cs[index];
\r
473 this.textNode = cs[index].firstChild;
\r
476 <div id="method-Ext.tree.TreeNodeUI-getAnchor"></div>/**
\r
477 * Returns the <a> element that provides focus for the node's UI.
\r
478 * @return {HtmlElement} The DOM anchor element.
\r
480 getAnchor : function(){
\r
481 return this.anchor;
\r
484 <div id="method-Ext.tree.TreeNodeUI-getTextEl"></div>/**
\r
485 * Returns the text node.
\r
486 * @return {HtmlNode} The DOM text node.
\r
488 getTextEl : function(){
\r
489 return this.textNode;
\r
492 <div id="method-Ext.tree.TreeNodeUI-getIconEl"></div>/**
\r
493 * Returns the icon <img> element.
\r
494 * @return {HtmlElement} The DOM image element.
\r
496 getIconEl : function(){
\r
497 return this.iconNode;
\r
500 <div id="method-Ext.tree.TreeNodeUI-isChecked"></div>/**
\r
501 * Returns the checked status of the node. If the node was rendered with no
\r
502 * checkbox, it returns false.
\r
503 * @return {Boolean} The checked flag.
\r
505 isChecked : function(){
\r
506 return this.checkbox ? this.checkbox.checked : false;
\r
510 updateExpandIcon : function(){
\r
512 var n = this.node,
\r
515 cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow",
\r
516 hasChild = n.hasChildNodes();
\r
517 if(hasChild || n.attributes.expandable){
\r
520 c1 = "x-tree-node-collapsed";
\r
521 c2 = "x-tree-node-expanded";
\r
524 c1 = "x-tree-node-expanded";
\r
525 c2 = "x-tree-node-collapsed";
\r
528 this.removeClass("x-tree-node-leaf");
\r
529 this.wasLeaf = false;
\r
531 if(this.c1 != c1 || this.c2 != c2){
\r
532 Ext.fly(this.elNode).replaceClass(c1, c2);
\r
533 this.c1 = c1; this.c2 = c2;
\r
537 Ext.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
\r
540 this.wasLeaf = true;
\r
543 var ecc = "x-tree-ec-icon "+cls;
\r
544 if(this.ecc != ecc){
\r
545 this.ecNode.className = ecc;
\r
552 onIdChange: function(id){
\r
554 this.elNode.setAttribute('ext:tree-node-id', id);
\r
559 getChildIndent : function(){
\r
560 if(!this.childIndent){
\r
564 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
\r
566 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
\r
568 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
\r
573 this.childIndent = buf.join("");
\r
575 return this.childIndent;
\r
579 renderIndent : function(){
\r
582 p = this.node.parentNode;
\r
584 indent = p.ui.getChildIndent();
\r
586 if(this.indentMarkup != indent){ // don't rerender if not required
\r
587 this.indentNode.innerHTML = indent;
\r
588 this.indentMarkup = indent;
\r
590 this.updateExpandIcon();
\r
594 destroy : function(){
\r
596 Ext.dd.Registry.unregister(this.elNode.id);
\r
599 Ext.each(['textnode', 'anchor', 'checkbox', 'indentNode', 'ecNode', 'iconNode', 'elNode', 'ctNode', 'wrap', 'holder'], function(el){
\r
601 Ext.fly(this[el]).remove();
\r
609 <div id="cls-Ext.tree.RootTreeNodeUI"></div>/**
\r
610 * @class Ext.tree.RootTreeNodeUI
\r
611 * This class provides the default UI implementation for <b>root</b> Ext TreeNodes.
\r
612 * The RootTreeNode UI implementation allows customizing the appearance of the root tree node.<br>
\r
614 * If you are customizing the Tree's user interface, you
\r
615 * may need to extend this class, but you should never need to instantiate this class.<br>
\r
617 Ext.tree.RootTreeNodeUI = Ext.extend(Ext.tree.TreeNodeUI, {
\r
619 render : function(){
\r
620 if(!this.rendered){
\r
621 var targetNode = this.node.ownerTree.innerCt.dom;
\r
622 this.node.expanded = true;
\r
623 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
\r
624 this.wrap = this.ctNode = targetNode.firstChild;
\r
627 collapse : Ext.emptyFn,
\r
628 expand : Ext.emptyFn
\r