root / trunk / web / dojo / dijit / _CssStateMixin.js @ 10
History | View | Annotate | Download (2.93 KB)
| 1 | 9 | andrej.cim | /*
|
|---|---|---|---|
| 2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
| 3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
| 4 | see: http://dojotoolkit.org/license for details
|
||
| 5 | */
|
||
| 6 | |||
| 7 | |||
| 8 | if(!dojo._hasResource["dijit._CssStateMixin"]){ |
||
| 9 | dojo._hasResource["dijit._CssStateMixin"]=true; |
||
| 10 | dojo.provide("dijit._CssStateMixin");
|
||
| 11 | dojo.declare("dijit._CssStateMixin",[],{cssStateNodes:{},postCreate:function(){ |
||
| 12 | this.inherited(arguments); |
||
| 13 | dojo.forEach(["onmouseenter","onmouseleave","onmousedown"],function(e){ |
||
| 14 | this.connect(this.domNode,e,"_cssMouseEvent"); |
||
| 15 | },this);
|
||
| 16 | this.connect(this,"set",function(_1,_2){ |
||
| 17 | if(arguments.length>=2&&{disabled:true,readOnly:true,checked:true,selected:true}[_1]){ |
||
| 18 | this._setStateClass();
|
||
| 19 | } |
||
| 20 | }); |
||
| 21 | dojo.forEach(["_onFocus","_onBlur"],function(ap){ |
||
| 22 | this.connect(this,ap,"_setStateClass"); |
||
| 23 | },this);
|
||
| 24 | for(var ap in this.cssStateNodes){ |
||
| 25 | this._trackMouseState(this[ap],this.cssStateNodes[ap]); |
||
| 26 | } |
||
| 27 | this._setStateClass();
|
||
| 28 | },_cssMouseEvent:function(_3){ |
||
| 29 | if(!this.disabled){ |
||
| 30 | switch(_3.type){
|
||
| 31 | case "mouseenter": |
||
| 32 | case "mouseover": |
||
| 33 | this._hovering=true; |
||
| 34 | this._active=this._mouseDown; |
||
| 35 | break;
|
||
| 36 | case "mouseleave": |
||
| 37 | case "mouseout": |
||
| 38 | this._hovering=false; |
||
| 39 | this._active=false; |
||
| 40 | break;
|
||
| 41 | case "mousedown": |
||
| 42 | this._active=true; |
||
| 43 | this._mouseDown=true; |
||
| 44 | var _4=this.connect(dojo.body(),"onmouseup",function(){ |
||
| 45 | this._active=false; |
||
| 46 | this._mouseDown=false; |
||
| 47 | this._setStateClass();
|
||
| 48 | this.disconnect(_4);
|
||
| 49 | }); |
||
| 50 | break;
|
||
| 51 | } |
||
| 52 | this._setStateClass();
|
||
| 53 | } |
||
| 54 | },_setStateClass:function(){ |
||
| 55 | var _5=this.baseClass.split(" "); |
||
| 56 | function _6(_7){ |
||
| 57 | _5=_5.concat(dojo.map(_5,function(c){
|
||
| 58 | return c+_7;
|
||
| 59 | }),"dijit"+_7);
|
||
| 60 | }; |
||
| 61 | if(!this.isLeftToRight()){ |
||
| 62 | _6("Rtl");
|
||
| 63 | } |
||
| 64 | if(this.checked){ |
||
| 65 | _6("Checked");
|
||
| 66 | } |
||
| 67 | if(this.state){ |
||
| 68 | _6(this.state);
|
||
| 69 | } |
||
| 70 | if(this.selected){ |
||
| 71 | _6("Selected");
|
||
| 72 | } |
||
| 73 | if(this.disabled){ |
||
| 74 | _6("Disabled");
|
||
| 75 | }else{
|
||
| 76 | if(this.readOnly){ |
||
| 77 | _6("ReadOnly");
|
||
| 78 | }else{
|
||
| 79 | if(this._active){ |
||
| 80 | _6("Active");
|
||
| 81 | }else{
|
||
| 82 | if(this._hovering){ |
||
| 83 | _6("Hover");
|
||
| 84 | } |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | if(this._focused){ |
||
| 89 | _6("Focused");
|
||
| 90 | } |
||
| 91 | var tn=this.stateNode||this.domNode,_8={}; |
||
| 92 | dojo.forEach(tn.className.split(" "),function(c){ |
||
| 93 | _8[c]=true;
|
||
| 94 | }); |
||
| 95 | if("_stateClasses" in this){ |
||
| 96 | dojo.forEach(this._stateClasses,function(c){ |
||
| 97 | delete _8[c];
|
||
| 98 | }); |
||
| 99 | } |
||
| 100 | dojo.forEach(_5,function(c){
|
||
| 101 | _8[c]=true;
|
||
| 102 | }); |
||
| 103 | var _9=[];
|
||
| 104 | for(var c in _8){ |
||
| 105 | _9.push(c); |
||
| 106 | } |
||
| 107 | tn.className=_9.join(" ");
|
||
| 108 | this._stateClasses=_5;
|
||
| 109 | },_trackMouseState:function(_a,_b){ |
||
| 110 | var _c=false,_d=false,_e=false; |
||
| 111 | var _f=this,cn=dojo.hitch(this,"connect",_a); |
||
| 112 | function _10(){ |
||
| 113 | var _11=("disabled" in _f&&_f.disabled)||("readonly" in _f&&_f.readonly); |
||
| 114 | dojo.toggleClass(_a,_b+"Hover",_c&&!_d&&!_11);
|
||
| 115 | dojo.toggleClass(_a,_b+"Active",_d&&!_11);
|
||
| 116 | dojo.toggleClass(_a,_b+"Focused",_e&&!_11);
|
||
| 117 | }; |
||
| 118 | cn("onmouseenter",function(){ |
||
| 119 | _c=true;
|
||
| 120 | _10(); |
||
| 121 | }); |
||
| 122 | cn("onmouseleave",function(){ |
||
| 123 | _c=false;
|
||
| 124 | _d=false;
|
||
| 125 | _10(); |
||
| 126 | }); |
||
| 127 | cn("onmousedown",function(){ |
||
| 128 | _d=true;
|
||
| 129 | _10(); |
||
| 130 | }); |
||
| 131 | cn("onmouseup",function(){ |
||
| 132 | _d=false;
|
||
| 133 | _10(); |
||
| 134 | }); |
||
| 135 | cn("onfocus",function(){ |
||
| 136 | _e=true;
|
||
| 137 | _10(); |
||
| 138 | }); |
||
| 139 | cn("onblur",function(){ |
||
| 140 | _e=false;
|
||
| 141 | _10(); |
||
| 142 | }); |
||
| 143 | this.connect(this,"set",function(_12,_13){ |
||
| 144 | if(_12=="disabled"||_12=="readOnly"){ |
||
| 145 | _10(); |
||
| 146 | } |
||
| 147 | }); |
||
| 148 | }}); |
||
| 149 | } |