TreeEventModel.js
上传用户:shuoshiled
上传日期:2018-01-28
资源大小:10124k
文件大小:5k
源码类别:

中间件编程

开发平台:

JavaScript

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