summaryrefslogtreecommitdiff
path: root/lib/dijit/_CssStateMixin.js
blob: 53144804f9848df863eca04babddc9cbc2bdf557 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
	Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


if(!dojo._hasResource["dijit._CssStateMixin"]){
dojo._hasResource["dijit._CssStateMixin"]=true;
dojo.provide("dijit._CssStateMixin");
dojo.declare("dijit._CssStateMixin",[],{cssStateNodes:{},postCreate:function(){
this.inherited(arguments);
dojo.forEach(["onmouseenter","onmouseleave","onmousedown"],function(e){
this.connect(this.domNode,e,"_cssMouseEvent");
},this);
this.connect(this,"set",function(_1,_2){
if(arguments.length>=2&&{disabled:true,readOnly:true,checked:true,selected:true}[_1]){
this._setStateClass();
}
});
dojo.forEach(["_onFocus","_onBlur"],function(ap){
this.connect(this,ap,"_setStateClass");
},this);
for(var ap in this.cssStateNodes){
this._trackMouseState(this[ap],this.cssStateNodes[ap]);
}
this._setStateClass();
},_cssMouseEvent:function(_3){
if(!this.disabled){
switch(_3.type){
case "mouseenter":
case "mouseover":
this._hovering=true;
this._active=this._mouseDown;
break;
case "mouseleave":
case "mouseout":
this._hovering=false;
this._active=false;
break;
case "mousedown":
this._active=true;
this._mouseDown=true;
var _4=this.connect(dojo.body(),"onmouseup",function(){
this._active=false;
this._mouseDown=false;
this._setStateClass();
this.disconnect(_4);
});
break;
}
this._setStateClass();
}
},_setStateClass:function(){
var _5=this.baseClass.split(" ");
function _6(_7){
_5=_5.concat(dojo.map(_5,function(c){
return c+_7;
}),"dijit"+_7);
};
if(!this.isLeftToRight()){
_6("Rtl");
}
if(this.checked){
_6("Checked");
}
if(this.state){
_6(this.state);
}
if(this.selected){
_6("Selected");
}
if(this.disabled){
_6("Disabled");
}else{
if(this.readOnly){
_6("ReadOnly");
}else{
if(this._active){
_6("Active");
}else{
if(this._hovering){
_6("Hover");
}
}
}
}
if(this._focused){
_6("Focused");
}
var tn=this.stateNode||this.domNode,_8={};
dojo.forEach(tn.className.split(" "),function(c){
_8[c]=true;
});
if("_stateClasses" in this){
dojo.forEach(this._stateClasses,function(c){
delete _8[c];
});
}
dojo.forEach(_5,function(c){
_8[c]=true;
});
var _9=[];
for(var c in _8){
_9.push(c);
}
tn.className=_9.join(" ");
this._stateClasses=_5;
},_trackMouseState:function(_a,_b){
var _c=false,_d=false,_e=false;
var _f=this,cn=dojo.hitch(this,"connect",_a);
function _10(){
var _11=("disabled" in _f&&_f.disabled)||("readonly" in _f&&_f.readonly);
dojo.toggleClass(_a,_b+"Hover",_c&&!_d&&!_11);
dojo.toggleClass(_a,_b+"Active",_d&&!_11);
dojo.toggleClass(_a,_b+"Focused",_e&&!_11);
};
cn("onmouseenter",function(){
_c=true;
_10();
});
cn("onmouseleave",function(){
_c=false;
_d=false;
_10();
});
cn("onmousedown",function(){
_d=true;
_10();
});
cn("onmouseup",function(){
_d=false;
_10();
});
cn("onfocus",function(){
_e=true;
_10();
});
cn("onblur",function(){
_e=false;
_10();
});
this.connect(this,"set",function(_12,_13){
if(_12=="disabled"||_12=="readOnly"){
_10();
}
});
}});
}