You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
5.6 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js">Ext.tree.TreeEventModel = function(tree){
  19. this.tree = tree;
  20. this.tree.on('render', this.initEvents, this);
  21. };
  22. Ext.tree.TreeEventModel.prototype = {
  23. initEvents : function(){
  24. var t = this.tree;
  25. if(t.trackMouseOver !== false){
  26. t.mon(t.innerCt, {
  27. scope: this,
  28. mouseover: this.delegateOver,
  29. mouseout: this.delegateOut
  30. });
  31. }
  32. t.mon(t.getTreeEl(), {
  33. scope: this,
  34. click: this.delegateClick,
  35. dblclick: this.delegateDblClick,
  36. contextmenu: this.delegateContextMenu
  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. getNodeTarget : function(e){
  50. var t = e.getTarget('.x-tree-node-icon', 1);
  51. if(!t){
  52. t = e.getTarget('.x-tree-node-el', 6);
  53. }
  54. return t;
  55. },
  56. delegateOut : function(e, t){
  57. if(!this.beforeEvent(e)){
  58. return;
  59. }
  60. if(e.getTarget('.x-tree-ec-icon', 1)){
  61. var n = this.getNode(e);
  62. this.onIconOut(e, n);
  63. if(n == this.lastEcOver){
  64. delete this.lastEcOver;
  65. }
  66. }
  67. if((t = this.getNodeTarget(e)) &amp;&amp; !e.within(t, true)){
  68. this.onNodeOut(e, this.getNode(e));
  69. }
  70. },
  71. delegateOver : function(e, t){
  72. if(!this.beforeEvent(e)){
  73. return;
  74. }
  75. if(Ext.isGecko &amp;&amp; !this.trackingDoc){ // prevent hanging in FF
  76. Ext.getBody().on('mouseover', this.trackExit, this);
  77. this.trackingDoc = true;
  78. }
  79. if(this.lastEcOver){ // prevent hung highlight
  80. this.onIconOut(e, this.lastEcOver);
  81. delete this.lastEcOver;
  82. }
  83. if(e.getTarget('.x-tree-ec-icon', 1)){
  84. this.lastEcOver = this.getNode(e);
  85. this.onIconOver(e, this.lastEcOver);
  86. }
  87. if(t = this.getNodeTarget(e)){
  88. this.onNodeOver(e, this.getNode(e));
  89. }
  90. },
  91. trackExit : function(e){
  92. if(this.lastOverNode){
  93. if(this.lastOverNode.ui &amp;&amp; !e.within(this.lastOverNode.ui.getEl())){
  94. this.onNodeOut(e, this.lastOverNode);
  95. }
  96. delete this.lastOverNode;
  97. Ext.getBody().un('mouseover', this.trackExit, this);
  98. this.trackingDoc = false;
  99. }
  100. },
  101. delegateClick : function(e, t){
  102. if(this.beforeEvent(e)){
  103. if(e.getTarget('input[type=checkbox]', 1)){
  104. this.onCheckboxClick(e, this.getNode(e));
  105. }else if(e.getTarget('.x-tree-ec-icon', 1)){
  106. this.onIconClick(e, this.getNode(e));
  107. }else if(this.getNodeTarget(e)){
  108. this.onNodeClick(e, this.getNode(e));
  109. }
  110. }else{
  111. this.checkContainerEvent(e, 'click');
  112. }
  113. },
  114. delegateDblClick : function(e, t){
  115. if(this.beforeEvent(e)){
  116. if(this.getNodeTarget(e)){
  117. this.onNodeDblClick(e, this.getNode(e));
  118. }
  119. }else{
  120. this.checkContainerEvent(e, 'dblclick');
  121. }
  122. },
  123. delegateContextMenu : function(e, t){
  124. if(this.beforeEvent(e)){
  125. if(this.getNodeTarget(e)){
  126. this.onNodeContextMenu(e, this.getNode(e));
  127. }
  128. }else{
  129. this.checkContainerEvent(e, 'contextmenu');
  130. }
  131. },
  132. checkContainerEvent: function(e, type){
  133. if(this.disabled){
  134. e.stopEvent();
  135. return false;
  136. }
  137. this.onContainerEvent(e, type);
  138. },
  139. onContainerEvent: function(e, type){
  140. this.tree.fireEvent('container' + type, this.tree, e);
  141. },
  142. onNodeClick : function(e, node){
  143. node.ui.onClick(e);
  144. },
  145. onNodeOver : function(e, node){
  146. this.lastOverNode = node;
  147. node.ui.onOver(e);
  148. },
  149. onNodeOut : function(e, node){
  150. node.ui.onOut(e);
  151. },
  152. onIconOver : function(e, node){
  153. node.ui.addClass('x-tree-ec-over');
  154. },
  155. onIconOut : function(e, node){
  156. node.ui.removeClass('x-tree-ec-over');
  157. },
  158. onIconClick : function(e, node){
  159. node.ui.ecClick(e);
  160. },
  161. onCheckboxClick : function(e, node){
  162. node.ui.onCheckChange(e);
  163. },
  164. onNodeDblClick : function(e, node){
  165. node.ui.onDblClick(e);
  166. },
  167. onNodeContextMenu : function(e, node){
  168. node.ui.onContextMenu(e);
  169. },
  170. beforeEvent : function(e){
  171. var node = this.getNode(e);
  172. if(this.disabled || !node || !node.ui){
  173. e.stopEvent();
  174. return false;
  175. }
  176. return true;
  177. },
  178. disable: function(){
  179. this.disabled = true;
  180. },
  181. enable: function(){
  182. this.disabled = false;
  183. }
  184. };</pre>
  185. </body>
  186. </html>