TreeEventModel.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:5k
源码类别:

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ Ext.tree.TreeEventModel = function(tree){
  2.     this.tree = tree;
  3.     this.tree.on('render', this.initEvents, this);
  4. }
  5. Ext.tree.TreeEventModel.prototype = {
  6.     initEvents : function(){
  7.         var t = this.tree;
  8.             
  9.         if(t.trackMouseOver !== false){
  10.             t.mon(t.innerCt, {
  11.                 scope: this,
  12.                 mouseover: this.delegateOver,
  13.                 mouseout: this.delegateOut
  14.             });
  15.         }
  16.         t.mon(t.getTreeEl(), {
  17.             scope: this,
  18.             click: this.delegateClick,
  19.             dblclick: this.delegateDblClick,
  20.             contextmenu: this.delegateContextMenu
  21.         });
  22.     },
  23.     getNode : function(e){
  24.         var t;
  25.         if(t = e.getTarget('.x-tree-node-el', 10)){
  26.             var id = Ext.fly(t, '_treeEvents').getAttribute('tree-node-id', 'ext');
  27.             if(id){
  28.                 return this.tree.getNodeById(id);
  29.             }
  30.         }
  31.         return null;
  32.     },
  33.     getNodeTarget : function(e){
  34.         var t = e.getTarget('.x-tree-node-icon', 1);
  35.         if(!t){
  36.             t = e.getTarget('.x-tree-node-el', 6);
  37.         }
  38.         return t;
  39.     },
  40.     delegateOut : function(e, t){
  41.         if(!this.beforeEvent(e)){
  42.             return;
  43.         }
  44.         if(e.getTarget('.x-tree-ec-icon', 1)){
  45.             var n = this.getNode(e);
  46.             this.onIconOut(e, n);
  47.             if(n == this.lastEcOver){
  48.                 delete this.lastEcOver;
  49.             }
  50.         }
  51.         if((t = this.getNodeTarget(e)) && !e.within(t, true)){
  52.             this.onNodeOut(e, this.getNode(e));
  53.         }
  54.     },
  55.     delegateOver : function(e, t){
  56.         if(!this.beforeEvent(e)){
  57.             return;
  58.         }
  59.         if(Ext.isGecko && !this.trackingDoc){ // prevent hanging in FF
  60.             Ext.getBody().on('mouseover', this.trackExit, this);
  61.             this.trackingDoc = true;
  62.         }
  63.         if(this.lastEcOver){ // prevent hung highlight
  64.             this.onIconOut(e, this.lastEcOver);
  65.             delete this.lastEcOver;
  66.         }
  67.         if(e.getTarget('.x-tree-ec-icon', 1)){
  68.             this.lastEcOver = this.getNode(e);
  69.             this.onIconOver(e, this.lastEcOver);
  70.         }
  71.         if(t = this.getNodeTarget(e)){
  72.             this.onNodeOver(e, this.getNode(e));
  73.         }
  74.     },
  75.     trackExit : function(e){
  76.         if(this.lastOverNode && !e.within(this.lastOverNode.ui.getEl())){
  77.             this.onNodeOut(e, this.lastOverNode);
  78.             delete this.lastOverNode;
  79.             Ext.getBody().un('mouseover', this.trackExit, this);
  80.             this.trackingDoc = false;
  81.         }
  82.     },
  83.     delegateClick : function(e, t){
  84.         if(this.beforeEvent(e)){
  85.             if(e.getTarget('input[type=checkbox]', 1)){
  86.                 this.onCheckboxClick(e, this.getNode(e));
  87.             }else if(e.getTarget('.x-tree-ec-icon', 1)){
  88.                 this.onIconClick(e, this.getNode(e));
  89.             }else if(this.getNodeTarget(e)){
  90.                 this.onNodeClick(e, this.getNode(e));
  91.             }else{
  92.                 this.onContainerEvent(e, 'click');
  93.             }
  94.         }
  95.     },
  96.     delegateDblClick : function(e, t){
  97.         if(this.beforeEvent(e)){
  98.             if(this.getNodeTarget(e)){
  99.                 this.onNodeDblClick(e, this.getNode(e));
  100.             }else{
  101.                 this.onContainerEvent(e, 'dblclick');    
  102.             }
  103.         }
  104.     },
  105.     delegateContextMenu : function(e, t){
  106.         if(this.beforeEvent(e)){
  107.             if(this.getNodeTarget(e)){
  108.                 this.onNodeContextMenu(e, this.getNode(e));
  109.             }else{
  110.                 this.onContainerEvent(e, 'contextmenu');    
  111.             }
  112.         }
  113.     },
  114.     
  115.     onContainerEvent: function(e, type){
  116.         this.tree.fireEvent('container' + type, this.tree, e); 
  117.     },
  118.     onNodeClick : function(e, node){
  119.         node.ui.onClick(e);
  120.     },
  121.     onNodeOver : function(e, node){
  122.         this.lastOverNode = node;
  123.         node.ui.onOver(e);
  124.     },
  125.     onNodeOut : function(e, node){
  126.         node.ui.onOut(e);
  127.     },
  128.     onIconOver : function(e, node){
  129.         node.ui.addClass('x-tree-ec-over');
  130.     },
  131.     onIconOut : function(e, node){
  132.         node.ui.removeClass('x-tree-ec-over');
  133.     },
  134.     onIconClick : function(e, node){
  135.         node.ui.ecClick(e);
  136.     },
  137.     onCheckboxClick : function(e, node){
  138.         node.ui.onCheckChange(e);
  139.     },
  140.     onNodeDblClick : function(e, node){
  141.         node.ui.onDblClick(e);
  142.     },
  143.     onNodeContextMenu : function(e, node){
  144.         node.ui.onContextMenu(e);
  145.     },
  146.     beforeEvent : function(e){
  147.         if(this.disabled){
  148.             e.stopEvent();
  149.             return false;
  150.         }
  151.         return true;
  152.     },
  153.     disable: function(){
  154.         this.disabled = true;
  155.     },
  156.     enable: function(){
  157.         this.disabled = false;
  158.     }
  159. };