_CssStateMixin.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //>>built
  2. define("dijit/_CssStateMixin",["dojo/_base/array","dojo/_base/declare","dojo/dom","dojo/dom-class","dojo/has","dojo/_base/lang","dojo/on","dojo/domReady","dojo/touch","dojo/_base/window","./a11yclick","./registry"],function(_1,_2,_3,_4,_5,_6,on,_7,_8,_9,_a,_b){
  3. var _c=_2("dijit._CssStateMixin",[],{hovering:false,active:false,_applyAttributes:function(){
  4. this.inherited(arguments);
  5. _1.forEach(["disabled","readOnly","checked","selected","focused","state","hovering","active","_opened"],function(_d){
  6. this.watch(_d,_6.hitch(this,"_setStateClass"));
  7. },this);
  8. for(var ap in this.cssStateNodes||{}){
  9. this._trackMouseState(this[ap],this.cssStateNodes[ap]);
  10. }
  11. this._trackMouseState(this.domNode,this.baseClass);
  12. this._setStateClass();
  13. },_cssMouseEvent:function(_e){
  14. if(!this.disabled){
  15. switch(_e.type){
  16. case "mouseover":
  17. case "MSPointerOver":
  18. this._set("hovering",true);
  19. this._set("active",this._mouseDown);
  20. break;
  21. case "mouseout":
  22. case "MSPointerOut":
  23. this._set("hovering",false);
  24. this._set("active",false);
  25. break;
  26. case "mousedown":
  27. case "touchstart":
  28. case "MSPointerDown":
  29. case "keydown":
  30. this._set("active",true);
  31. break;
  32. case "mouseup":
  33. case "dojotouchend":
  34. case "keyup":
  35. this._set("active",false);
  36. break;
  37. }
  38. }
  39. },_setStateClass:function(){
  40. var _f=this.baseClass.split(" ");
  41. function _10(_11){
  42. _f=_f.concat(_1.map(_f,function(c){
  43. return c+_11;
  44. }),"dijit"+_11);
  45. };
  46. if(!this.isLeftToRight()){
  47. _10("Rtl");
  48. }
  49. var _12=this.checked=="mixed"?"Mixed":(this.checked?"Checked":"");
  50. if(this.checked){
  51. _10(_12);
  52. }
  53. if(this.state){
  54. _10(this.state);
  55. }
  56. if(this.selected){
  57. _10("Selected");
  58. }
  59. if(this._opened){
  60. _10("Opened");
  61. }
  62. if(this.disabled){
  63. _10("Disabled");
  64. }else{
  65. if(this.readOnly){
  66. _10("ReadOnly");
  67. }else{
  68. if(this.active){
  69. _10("Active");
  70. }else{
  71. if(this.hovering){
  72. _10("Hover");
  73. }
  74. }
  75. }
  76. }
  77. if(this.focused){
  78. _10("Focused");
  79. }
  80. var tn=this.stateNode||this.domNode,_13={};
  81. _1.forEach(tn.className.split(" "),function(c){
  82. _13[c]=true;
  83. });
  84. if("_stateClasses" in this){
  85. _1.forEach(this._stateClasses,function(c){
  86. delete _13[c];
  87. });
  88. }
  89. _1.forEach(_f,function(c){
  90. _13[c]=true;
  91. });
  92. var _14=[];
  93. for(var c in _13){
  94. _14.push(c);
  95. }
  96. tn.className=_14.join(" ");
  97. this._stateClasses=_f;
  98. },_subnodeCssMouseEvent:function(_15,_16,evt){
  99. if(this.disabled||this.readOnly){
  100. return;
  101. }
  102. function _17(_18){
  103. _4.toggle(_15,_16+"Hover",_18);
  104. };
  105. function _19(_1a){
  106. _4.toggle(_15,_16+"Active",_1a);
  107. };
  108. function _1b(_1c){
  109. _4.toggle(_15,_16+"Focused",_1c);
  110. };
  111. switch(evt.type){
  112. case "mouseover":
  113. case "MSPointerOver":
  114. _17(true);
  115. break;
  116. case "mouseout":
  117. case "MSPointerOut":
  118. _17(false);
  119. _19(false);
  120. break;
  121. case "mousedown":
  122. case "touchstart":
  123. case "MSPointerDown":
  124. case "keydown":
  125. _19(true);
  126. break;
  127. case "mouseup":
  128. case "MSPointerUp":
  129. case "dojotouchend":
  130. case "keyup":
  131. _19(false);
  132. break;
  133. case "focus":
  134. case "focusin":
  135. _1b(true);
  136. break;
  137. case "blur":
  138. case "focusout":
  139. _1b(false);
  140. break;
  141. }
  142. },_trackMouseState:function(_1d,_1e){
  143. _1d._cssState=_1e;
  144. }});
  145. _7(function(){
  146. function _1f(evt,_20,_21){
  147. if(_21&&_3.isDescendant(_21,_20)){
  148. return;
  149. }
  150. for(var _22=_20;_22&&_22!=_21;_22=_22.parentNode){
  151. if(_22._cssState){
  152. var _23=_b.getEnclosingWidget(_22);
  153. if(_23){
  154. if(_22==_23.domNode){
  155. _23._cssMouseEvent(evt);
  156. }else{
  157. _23._subnodeCssMouseEvent(_22,_22._cssState,evt);
  158. }
  159. }
  160. }
  161. }
  162. };
  163. var _24=_9.body(),_25;
  164. on(_24,_8.over,function(evt){
  165. _1f(evt,evt.target,evt.relatedTarget);
  166. });
  167. on(_24,_8.out,function(evt){
  168. _1f(evt,evt.target,evt.relatedTarget);
  169. });
  170. on(_24,_a.press,function(evt){
  171. _25=evt.target;
  172. _1f(evt,_25);
  173. });
  174. on(_24,_a.release,function(evt){
  175. _1f(evt,_25);
  176. _25=null;
  177. });
  178. on(_24,"focusin, focusout",function(evt){
  179. var _26=evt.target;
  180. if(_26._cssState&&!_26.getAttribute("widgetId")){
  181. var _27=_b.getEnclosingWidget(_26);
  182. if(_27){
  183. _27._subnodeCssMouseEvent(_26,_26._cssState,evt);
  184. }
  185. }
  186. });
  187. });
  188. return _c;
  189. });