Upgrade to ExtJS 3.3.1 - Released 11/30/2010
[extjs.git] / docs / source / TreeEventModel.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.3.1
11  * Copyright(c) 2006-2010 Sencha Inc.
12  * licensing@sencha.com
13  * http://www.sencha.com/license
14  */
15 Ext.tree.TreeEventModel = function(tree){
16     this.tree = tree;
17     this.tree.on('render', this.initEvents, this);
18 };
19
20 Ext.tree.TreeEventModel.prototype = {
21     initEvents : function(){
22         var t = this.tree;
23
24         if(t.trackMouseOver !== false){
25             t.mon(t.innerCt, {
26                 scope: this,
27                 mouseover: this.delegateOver,
28                 mouseout: this.delegateOut
29             });
30         }
31         t.mon(t.getTreeEl(), {
32             scope: this,
33             click: this.delegateClick,
34             dblclick: this.delegateDblClick,
35             contextmenu: this.delegateContextMenu
36         });
37     },
38
39     getNode : function(e){
40         var t;
41         if(t = e.getTarget('.x-tree-node-el', 10)){
42             var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
43             if(id){
44                 return this.tree.getNodeById(id);
45             }
46         }
47         return null;
48     },
49
50     getNodeTarget : function(e){
51         var t = e.getTarget('.x-tree-node-icon', 1);
52         if(!t){
53             t = e.getTarget('.x-tree-node-el', 6);
54         }
55         return t;
56     },
57
58     delegateOut : function(e, t){
59         if(!this.beforeEvent(e)){
60             return;
61         }
62         if(e.getTarget('.x-tree-ec-icon', 1)){
63             var n = this.getNode(e);
64             this.onIconOut(e, n);
65             if(n == this.lastEcOver){
66                 delete this.lastEcOver;
67             }
68         }
69         if((t = this.getNodeTarget(e)) && !e.within(t, true)){
70             this.onNodeOut(e, this.getNode(e));
71         }
72     },
73
74     delegateOver : function(e, t){
75         if(!this.beforeEvent(e)){
76             return;
77         }
78         if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
79             Ext.getBody().on('mouseover', this.trackExit, this);
80             this.trackingDoc = true;
81         }
82         if(this.lastEcOver){ // prevent hung highlight
83             this.onIconOut(e, this.lastEcOver);
84             delete this.lastEcOver;
85         }
86         if(e.getTarget('.x-tree-ec-icon', 1)){
87             this.lastEcOver = this.getNode(e);
88             this.onIconOver(e, this.lastEcOver);
89         }
90         if(t = this.getNodeTarget(e)){
91             this.onNodeOver(e, this.getNode(e));
92         }
93     },
94
95     trackExit : function(e){
96         if(this.lastOverNode){
97             if(this.lastOverNode.ui && !e.within(this.lastOverNode.ui.getEl())){
98                 this.onNodeOut(e, this.lastOverNode);
99             }
100             delete this.lastOverNode;
101             Ext.getBody().un('mouseover', this.trackExit, this);
102             this.trackingDoc = false;
103         }
104
105     },
106
107     delegateClick : function(e, t){
108         if(this.beforeEvent(e)){
109             if(e.getTarget('input[type=checkbox]', 1)){
110                 this.onCheckboxClick(e, this.getNode(e));
111             }else if(e.getTarget('.x-tree-ec-icon', 1)){
112                 this.onIconClick(e, this.getNode(e));
113             }else if(this.getNodeTarget(e)){
114                 this.onNodeClick(e, this.getNode(e));
115             }
116         }else{
117             this.checkContainerEvent(e, 'click');
118         }
119     },
120
121     delegateDblClick : function(e, t){
122         if(this.beforeEvent(e)){
123             if(this.getNodeTarget(e)){
124                 this.onNodeDblClick(e, this.getNode(e));
125             }
126         }else{
127             this.checkContainerEvent(e, 'dblclick');
128         }
129     },
130
131     delegateContextMenu : function(e, t){
132         if(this.beforeEvent(e)){
133             if(this.getNodeTarget(e)){
134                 this.onNodeContextMenu(e, this.getNode(e));
135             }
136         }else{
137             this.checkContainerEvent(e, 'contextmenu');
138         }
139     },
140     
141     checkContainerEvent: function(e, type){
142         if(this.disabled){
143             e.stopEvent();
144             return false;
145         }
146         this.onContainerEvent(e, type);    
147     },
148
149     onContainerEvent: function(e, type){
150         this.tree.fireEvent('container' + type, this.tree, e);
151     },
152
153     onNodeClick : function(e, node){
154         node.ui.onClick(e);
155     },
156
157     onNodeOver : function(e, node){
158         this.lastOverNode = node;
159         node.ui.onOver(e);
160     },
161
162     onNodeOut : function(e, node){
163         node.ui.onOut(e);
164     },
165
166     onIconOver : function(e, node){
167         node.ui.addClass('x-tree-ec-over');
168     },
169
170     onIconOut : function(e, node){
171         node.ui.removeClass('x-tree-ec-over');
172     },
173
174     onIconClick : function(e, node){
175         node.ui.ecClick(e);
176     },
177
178     onCheckboxClick : function(e, node){
179         node.ui.onCheckChange(e);
180     },
181
182     onNodeDblClick : function(e, node){
183         node.ui.onDblClick(e);
184     },
185
186     onNodeContextMenu : function(e, node){
187         node.ui.onContextMenu(e);
188     },
189
190     beforeEvent : function(e){
191         var node = this.getNode(e);
192         if(this.disabled || !node || !node.ui){
193             e.stopEvent();
194             return false;
195         }
196         return true;
197     },
198
199     disable: function(){
200         this.disabled = true;
201     },
202
203     enable: function(){
204         this.disabled = false;
205     }
206 };</pre>    
207 </body>
208 </html>