123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- define("dijit/_MenuBase", [
- "./popup",
- "dojo/window",
- "./_Widget",
- "./_KeyNavContainer",
- "./_TemplatedMixin",
- "dojo/_base/declare",
- "dojo/dom",
- "dojo/dom-attr",
- "dojo/dom-class",
- "dojo/_base/lang",
- "dojo/_base/array"
- ], function(pm, winUtils, _Widget, _KeyNavContainer, _TemplatedMixin,
- declare, dom, domAttr, domClass, lang, array){
- return declare("dijit._MenuBase",
- [_Widget, _TemplatedMixin, _KeyNavContainer],
- {
-
-
-
-
- parentMenu: null,
-
-
- popupDelay: 500,
- onExecute: function(){
-
-
-
-
-
-
-
- },
- onCancel: function(/*Boolean*/ /*===== closeAll =====*/){
-
-
-
-
-
-
- },
- _moveToPopup: function(/*Event*/ evt){
-
-
-
-
-
-
- if(this.focusedChild && this.focusedChild.popup && !this.focusedChild.disabled){
- this.focusedChild._onClick(evt);
- }else{
- var topMenu = this._getTopMenu();
- if(topMenu && topMenu._isMenuBar){
- topMenu.focusNext();
- }
- }
- },
- _onPopupHover: function(/*Event*/ /*===== evt =====*/){
-
-
-
-
-
-
-
- if(this.currentPopup && this.currentPopup._pendingClose_timer){
- var parentMenu = this.currentPopup.parentMenu;
-
- if(parentMenu.focusedChild){
- parentMenu.focusedChild._setSelected(false);
- }
- parentMenu.focusedChild = this.currentPopup.from_item;
- parentMenu.focusedChild._setSelected(true);
-
- this._stopPendingCloseTimer(this.currentPopup);
- }
- },
- onItemHover: function(/*MenuItem*/ item){
-
-
-
-
-
-
-
- if(this.isActive){
- this.focusChild(item);
- if(this.focusedChild.popup && !this.focusedChild.disabled && !this.hover_timer){
- this.hover_timer = setTimeout(lang.hitch(this, "_openPopup"), this.popupDelay);
- }
- }
-
-
-
-
- if(this.focusedChild){
- this.focusChild(item);
- }
- this._hoveredChild = item;
- },
- _onChildBlur: function(item){
-
-
-
-
-
- this._stopPopupTimer();
- item._setSelected(false);
-
- var itemPopup = item.popup;
- if(itemPopup){
- this._stopPendingCloseTimer(itemPopup);
- itemPopup._pendingClose_timer = setTimeout(function(){
- itemPopup._pendingClose_timer = null;
- if(itemPopup.parentMenu){
- itemPopup.parentMenu.currentPopup = null;
- }
- pm.close(itemPopup);
- }, this.popupDelay);
- }
- },
- onItemUnhover: function(/*MenuItem*/ item){
-
-
-
-
- if(this.isActive){
- this._stopPopupTimer();
- }
- if(this._hoveredChild == item){ this._hoveredChild = null; }
- },
- _stopPopupTimer: function(){
-
-
-
-
-
- if(this.hover_timer){
- clearTimeout(this.hover_timer);
- this.hover_timer = null;
- }
- },
- _stopPendingCloseTimer: function(/*dijit._Widget*/ popup){
-
-
-
-
- if(popup._pendingClose_timer){
- clearTimeout(popup._pendingClose_timer);
- popup._pendingClose_timer = null;
- }
- },
- _stopFocusTimer: function(){
-
-
-
-
- if(this._focus_timer){
- clearTimeout(this._focus_timer);
- this._focus_timer = null;
- }
- },
- _getTopMenu: function(){
-
-
-
-
- for(var top=this; top.parentMenu; top=top.parentMenu);
- return top;
- },
- onItemClick: function(/*dijit._Widget*/ item, /*Event*/ evt){
-
-
-
-
-
- if(typeof this.isShowingNow == 'undefined'){
- this._markActive();
- }
- this.focusChild(item);
- if(item.disabled){ return false; }
- if(item.popup){
- this._openPopup();
- }else{
-
-
- this.onExecute();
-
- item.onClick(evt);
- }
- },
- _openPopup: function(){
-
-
-
-
- this._stopPopupTimer();
- var from_item = this.focusedChild;
- if(!from_item){ return; }
- var popup = from_item.popup;
- if(popup.isShowingNow){ return; }
- if(this.currentPopup){
- this._stopPendingCloseTimer(this.currentPopup);
- pm.close(this.currentPopup);
- }
- popup.parentMenu = this;
- popup.from_item = from_item;
- var self = this;
- pm.open({
- parent: this,
- popup: popup,
- around: from_item.domNode,
- orient: this._orient || ["after", "before"],
- onCancel: function(){
-
-
- self.focusChild(from_item);
- self._cleanUp();
- from_item._setSelected(true);
- self.focusedChild = from_item;
- },
- onExecute: lang.hitch(this, "_cleanUp")
- });
- this.currentPopup = popup;
-
- if(this.popupHoverHandle){
- this.disconnect(this.popupHoverHandle);
- }
- this.popupHoverHandle = this.connect(popup.domNode, "onmouseenter", "_onPopupHover");
- if(popup.focus){
-
-
-
-
- popup._focus_timer = setTimeout(lang.hitch(popup, function(){
- this._focus_timer = null;
- this.focus();
- }), 0);
- }
- },
- _markActive: function(){
-
-
-
-
-
-
-
-
-
-
-
- this.isActive = true;
- domClass.replace(this.domNode, "dijitMenuActive", "dijitMenuPassive");
- },
- onOpen: function(/*Event*/ /*===== e =====*/){
-
-
-
-
-
-
- this.isShowingNow = true;
- this._markActive();
- },
- _markInactive: function(){
-
-
- this.isActive = false;
- domClass.replace(this.domNode, "dijitMenuPassive", "dijitMenuActive");
- },
- onClose: function(){
-
-
-
-
-
-
- this._stopFocusTimer();
- this._markInactive();
- this.isShowingNow = false;
- this.parentMenu = null;
- },
- _closeChild: function(){
-
-
-
-
- this._stopPopupTimer();
- if(this.currentPopup){
-
-
-
-
-
- if(array.indexOf(this._focusManager.activeStack, this.id) >= 0){
- domAttr.set(this.focusedChild.focusNode, "tabIndex", this.tabIndex);
- this.focusedChild.focusNode.focus();
- }
-
- pm.close(this.currentPopup);
- this.currentPopup = null;
- }
- if(this.focusedChild){
- this.focusedChild._setSelected(false);
- this.focusedChild._onUnhover();
- this.focusedChild = null;
- }
- },
- _onItemFocus: function(/*MenuItem*/ item){
-
-
-
-
-
-
- if(this._hoveredChild && this._hoveredChild != item){
- this._hoveredChild._onUnhover();
- }
- },
- _onBlur: function(){
-
-
-
-
- this._cleanUp();
- this.inherited(arguments);
- },
- _cleanUp: function(){
-
-
-
-
- this._closeChild();
- if(typeof this.isShowingNow == 'undefined'){
- this._markInactive();
- }
- }
- });
- });
|