_MenuBase.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //>>built
  2. define("dijit/_MenuBase",["dojo/_base/array","dojo/_base/declare","dojo/dom","dojo/dom-attr","dojo/dom-class","dojo/_base/lang","dojo/mouse","dojo/on","dojo/window","./a11yclick","./registry","./_Widget","./_CssStateMixin","./_KeyNavContainer","./_TemplatedMixin"],function(_1,_2,_3,_4,_5,_6,_7,on,_8,_9,_a,_b,_c,_d,_e){
  3. return _2("dijit._MenuBase",[_b,_e,_d,_c],{selected:null,_setSelectedAttr:function(_f){
  4. if(this.selected!=_f){
  5. if(this.selected){
  6. this.selected._setSelected(false);
  7. this._onChildDeselect(this.selected);
  8. }
  9. if(_f){
  10. _f._setSelected(true);
  11. }
  12. this._set("selected",_f);
  13. }
  14. },activated:false,_setActivatedAttr:function(val){
  15. _5.toggle(this.domNode,"dijitMenuActive",val);
  16. _5.toggle(this.domNode,"dijitMenuPassive",!val);
  17. this._set("activated",val);
  18. },parentMenu:null,popupDelay:500,passivePopupDelay:Infinity,autoFocus:false,childSelector:function(_10){
  19. var _11=_a.byNode(_10);
  20. return _10.parentNode==this.containerNode&&_11&&_11.focus;
  21. },postCreate:function(){
  22. var _12=this,_13=typeof this.childSelector=="string"?this.childSelector:_6.hitch(this,"childSelector");
  23. this.own(on(this.containerNode,on.selector(_13,_7.enter),function(){
  24. _12.onItemHover(_a.byNode(this));
  25. }),on(this.containerNode,on.selector(_13,_7.leave),function(){
  26. _12.onItemUnhover(_a.byNode(this));
  27. }),on(this.containerNode,on.selector(_13,_9),function(evt){
  28. _12.onItemClick(_a.byNode(this),evt);
  29. evt.stopPropagation();
  30. evt.preventDefault();
  31. }));
  32. this.inherited(arguments);
  33. },onKeyboardSearch:function(_14,evt,_15,_16){
  34. this.inherited(arguments);
  35. if(!!_14&&(_16==-1||(!!_14.popup&&_16==1))){
  36. this.onItemClick(_14,evt);
  37. }
  38. },_keyboardSearchCompare:function(_17,_18){
  39. if(!!_17.shortcutKey){
  40. return _18==_17.shortcutKey.toLowerCase()?-1:0;
  41. }
  42. return this.inherited(arguments)?1:0;
  43. },onExecute:function(){
  44. },onCancel:function(){
  45. },_moveToPopup:function(evt){
  46. if(this.focusedChild&&this.focusedChild.popup&&!this.focusedChild.disabled){
  47. this.onItemClick(this.focusedChild,evt);
  48. }else{
  49. var _19=this._getTopMenu();
  50. if(_19&&_19._isMenuBar){
  51. _19.focusNext();
  52. }
  53. }
  54. },_onPopupHover:function(){
  55. this.set("selected",this.currentPopupItem);
  56. this._stopPendingCloseTimer();
  57. },onItemHover:function(_1a){
  58. if(this.activated){
  59. this.set("selected",_1a);
  60. if(_1a.popup&&!_1a.disabled&&!this.hover_timer){
  61. this.hover_timer=this.defer(function(){
  62. this._openItemPopup(_1a);
  63. },this.popupDelay);
  64. }
  65. }else{
  66. if(this.passivePopupDelay<Infinity){
  67. if(this.passive_hover_timer){
  68. this.passive_hover_timer.remove();
  69. }
  70. this.passive_hover_timer=this.defer(function(){
  71. this.onItemClick(_1a,{type:"click"});
  72. },this.passivePopupDelay);
  73. }
  74. }
  75. this._hoveredChild=_1a;
  76. _1a._set("hovering",true);
  77. },_onChildDeselect:function(_1b){
  78. this._stopPopupTimer();
  79. if(this.currentPopupItem==_1b){
  80. this._stopPendingCloseTimer();
  81. this._pendingClose_timer=this.defer(function(){
  82. this._pendingClose_timer=null;
  83. this.currentPopupItem=null;
  84. _1b._closePopup();
  85. },this.popupDelay);
  86. }
  87. },onItemUnhover:function(_1c){
  88. if(this._hoveredChild==_1c){
  89. this._hoveredChild=null;
  90. }
  91. if(this.passive_hover_timer){
  92. this.passive_hover_timer.remove();
  93. this.passive_hover_timer=null;
  94. }
  95. _1c._set("hovering",false);
  96. },_stopPopupTimer:function(){
  97. if(this.hover_timer){
  98. this.hover_timer=this.hover_timer.remove();
  99. }
  100. },_stopPendingCloseTimer:function(){
  101. if(this._pendingClose_timer){
  102. this._pendingClose_timer=this._pendingClose_timer.remove();
  103. }
  104. },_getTopMenu:function(){
  105. for(var top=this;top.parentMenu;top=top.parentMenu){
  106. }
  107. return top;
  108. },onItemClick:function(_1d,evt){
  109. if(this.passive_hover_timer){
  110. this.passive_hover_timer.remove();
  111. }
  112. this.focusChild(_1d);
  113. if(_1d.disabled){
  114. return false;
  115. }
  116. if(_1d.popup){
  117. this.set("selected",_1d);
  118. this.set("activated",true);
  119. var _1e=/^key/.test(evt._origType||evt.type)||(evt.clientX==0&&evt.clientY==0);
  120. this._openItemPopup(_1d,_1e);
  121. }else{
  122. this.onExecute();
  123. _1d._onClick?_1d._onClick(evt):_1d.onClick(evt);
  124. }
  125. },_openItemPopup:function(_1f,_20){
  126. if(_1f==this.currentPopupItem){
  127. return;
  128. }
  129. if(this.currentPopupItem){
  130. this._stopPendingCloseTimer();
  131. this.currentPopupItem._closePopup();
  132. }
  133. this._stopPopupTimer();
  134. var _21=_1f.popup;
  135. _21.parentMenu=this;
  136. this.own(this._mouseoverHandle=on.once(_21.domNode,"mouseover",_6.hitch(this,"_onPopupHover")));
  137. var _22=this;
  138. _1f._openPopup({parent:this,orient:this._orient||["after","before"],onCancel:function(){
  139. if(_20){
  140. _22.focusChild(_1f);
  141. }
  142. _22._cleanUp();
  143. },onExecute:_6.hitch(this,"_cleanUp",true),onClose:function(){
  144. if(_22._mouseoverHandle){
  145. _22._mouseoverHandle.remove();
  146. delete _22._mouseoverHandle;
  147. }
  148. }},_20);
  149. this.currentPopupItem=_1f;
  150. },onOpen:function(){
  151. this.isShowingNow=true;
  152. this.set("activated",true);
  153. },onClose:function(){
  154. this.set("activated",false);
  155. this.set("selected",null);
  156. this.isShowingNow=false;
  157. this.parentMenu=null;
  158. },_closeChild:function(){
  159. this._stopPopupTimer();
  160. if(this.currentPopupItem){
  161. if(this.focused){
  162. _4.set(this.selected.focusNode,"tabIndex",this.tabIndex);
  163. this.selected.focusNode.focus();
  164. }
  165. this.currentPopupItem._closePopup();
  166. this.currentPopupItem=null;
  167. }
  168. },_onItemFocus:function(_23){
  169. if(this._hoveredChild&&this._hoveredChild!=_23){
  170. this.onItemUnhover(this._hoveredChild);
  171. }
  172. this.set("selected",_23);
  173. },_onBlur:function(){
  174. this._cleanUp(true);
  175. this.inherited(arguments);
  176. },_cleanUp:function(_24){
  177. this._closeChild();
  178. if(typeof this.isShowingNow=="undefined"){
  179. this.set("activated",false);
  180. }
  181. if(_24){
  182. this.set("selected",null);
  183. }
  184. }});
  185. });