123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- define("dijit/_HasDropDown", [
- "dojo/_base/declare",
- "dojo/_base/Deferred",
- "dojo/_base/event",
- "dojo/dom",
- "dojo/dom-attr",
- "dojo/dom-class",
- "dojo/dom-geometry",
- "dojo/dom-style",
- "dojo/has",
- "dojo/keys",
- "dojo/_base/lang",
- "dojo/touch",
- "dojo/_base/window",
- "./registry",
- "./focus",
- "./popup",
- "./_FocusMixin",
- "./Viewport"
- ], function(declare, Deferred, event,dom, domAttr, domClass, domGeometry, domStyle, has, keys, lang, touch,
- win, registry, focus, popup, _FocusMixin, Viewport){
-
-
-
-
- return declare("dijit._HasDropDown", _FocusMixin, {
-
-
-
-
-
-
- _buttonNode: null,
-
-
-
-
-
- _arrowWrapperNode: null,
-
-
-
-
- _popupStateNode: null,
-
-
-
-
- _aroundNode: null,
-
-
-
- dropDown: null,
-
-
-
-
- autoWidth: true,
-
-
-
- forceWidth: false,
-
-
-
-
- maxHeight: 0,
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- dropDownPosition: ["below","above"],
-
-
-
- _stopClickEvents: true,
- _onDropDownMouseDown: function(/*Event*/ e){
-
-
- if(this.disabled || this.readOnly){ return; }
-
-
-
-
-
-
-
- if(e.type != "MSPointerDown" && e.type != "pointerdown"){
- e.preventDefault();
- }
- this._docHandler = this.connect(win.doc, touch.release, "_onDropDownMouseUp");
- this.toggleDropDown();
- },
- _onDropDownMouseUp: function(/*Event?*/ e){
-
-
-
-
-
-
-
-
-
-
-
- if(e && this._docHandler){
- this.disconnect(this._docHandler);
- }
- var dropDown = this.dropDown, overMenu = false;
- if(e && this._opened){
-
-
-
-
- var c = domGeometry.position(this._buttonNode, true);
- if(!(e.pageX >= c.x && e.pageX <= c.x + c.w) ||
- !(e.pageY >= c.y && e.pageY <= c.y + c.h)){
- var t = e.target;
- while(t && !overMenu){
- if(domClass.contains(t, "dijitPopup")){
- overMenu = true;
- }else{
- t = t.parentNode;
- }
- }
- if(overMenu){
- t = e.target;
- if(dropDown.onItemClick){
- var menuItem;
- while(t && !(menuItem = registry.byNode(t))){
- t = t.parentNode;
- }
- if(menuItem && menuItem.onClick && menuItem.getParent){
- menuItem.getParent().onItemClick(menuItem, e);
- }
- }
- return;
- }
- }
- }
- if(this._opened){
- if(dropDown.focus && dropDown.autoFocus !== false){
-
-
- window.setTimeout(lang.hitch(dropDown, "focus"), 1);
- }
- }else{
-
-
- setTimeout(lang.hitch(this, "focus"), 0);
- }
- if(has("ios")){
- this._justGotMouseUp = true;
- setTimeout(lang.hitch(this, function(){
- this._justGotMouseUp = false;
- }), 0);
- }
- },
- _onDropDownClick: function(/*Event*/ e){
- if(has("ios") && !this._justGotMouseUp){
-
-
-
-
-
- this._onDropDownMouseDown(e);
- this._onDropDownMouseUp(e);
- }
-
- if(this._stopClickEvents){
- event.stop(e);
- }
- },
- buildRendering: function(){
- this.inherited(arguments);
- this._buttonNode = this._buttonNode || this.focusNode || this.domNode;
- this._popupStateNode = this._popupStateNode || this.focusNode || this._buttonNode;
-
-
- var defaultPos = {
- "after" : this.isLeftToRight() ? "Right" : "Left",
- "before" : this.isLeftToRight() ? "Left" : "Right",
- "above" : "Up",
- "below" : "Down",
- "left" : "Left",
- "right" : "Right"
- }[this.dropDownPosition[0]] || this.dropDownPosition[0] || "Down";
- domClass.add(this._arrowWrapperNode || this._buttonNode, "dijit" + defaultPos + "ArrowButton");
- },
- postCreate: function(){
-
-
- this.inherited(arguments);
- this.connect(this._buttonNode, touch.press, "_onDropDownMouseDown");
- this.connect(this._buttonNode, "onclick", "_onDropDownClick");
- this.connect(this.focusNode, "onkeydown", "_onKey");
- this.connect(this.focusNode, "onkeyup", "_onKeyUp");
- },
- destroy: function(){
- if(this.dropDown){
-
-
- if(!this.dropDown._destroyed){
- this.dropDown.destroyRecursive();
- }
- delete this.dropDown;
- }
- this.inherited(arguments);
- },
- _onKey: function(/*Event*/ e){
-
-
- if(this.disabled || this.readOnly){ return; }
- var d = this.dropDown, target = e.target;
- if(d && this._opened && d.handleKey){
- if(d.handleKey(e) === false){
-
- event.stop(e);
- return;
- }
- }
- if(d && this._opened && e.keyCode == keys.ESCAPE){
- this.closeDropDown();
- event.stop(e);
- }else if(!this._opened &&
- (e.keyCode == keys.DOWN_ARROW ||
- ( (e.keyCode == keys.ENTER || e.keyCode == dojo.keys.SPACE) &&
-
- ((target.tagName || "").toLowerCase() !== 'input' ||
- (target.type && target.type.toLowerCase() !== 'text'))))){
-
-
-
- this._toggleOnKeyUp = true;
- event.stop(e);
- }
- },
- _onKeyUp: function(){
- if(this._toggleOnKeyUp){
- delete this._toggleOnKeyUp;
- this.toggleDropDown();
- var d = this.dropDown;
- if(d && d.focus){
- setTimeout(lang.hitch(d, "focus"), 1);
- }
- }
- },
- _onBlur: function(){
-
-
-
-
-
-
- var focusMe = focus.curNode && this.dropDown && dom.isDescendant(focus.curNode, this.dropDown.domNode);
- this.closeDropDown(focusMe);
- this.inherited(arguments);
- },
- isLoaded: function(){
-
-
-
-
-
- return true;
- },
- loadDropDown: function(/*Function*/ loadCallback){
-
-
-
-
-
-
-
- loadCallback();
- },
- loadAndOpenDropDown: function(){
-
-
-
-
-
-
-
-
-
-
- var d = new Deferred(),
- afterLoad = lang.hitch(this, function(){
- this.openDropDown();
- d.resolve(this.dropDown);
- });
- if(!this.isLoaded()){
- this.loadDropDown(afterLoad);
- }else{
- afterLoad();
- }
- return d;
- },
- toggleDropDown: function(){
-
-
-
-
-
-
- if(this.disabled || this.readOnly){ return; }
- if(!this._opened){
- this.loadAndOpenDropDown();
- }else{
- this.closeDropDown();
- }
- },
- openDropDown: function(){
-
-
-
-
-
-
-
- var dropDown = this.dropDown,
- ddNode = dropDown.domNode,
- aroundNode = this._aroundNode || this.domNode,
- self = this;
-
-
-
- if(!this._preparedNode){
- this._preparedNode = true;
-
- if(ddNode.style.width){
- this._explicitDDWidth = true;
- }
- if(ddNode.style.height){
- this._explicitDDHeight = true;
- }
- }
-
- if(this.maxHeight || this.forceWidth || this.autoWidth){
- var myStyle = {
- display: "",
- visibility: "hidden"
- };
- if(!this._explicitDDWidth){
- myStyle.width = "";
- }
- if(!this._explicitDDHeight){
- myStyle.height = "";
- }
- domStyle.set(ddNode, myStyle);
-
- var maxHeight = this.maxHeight;
- if(maxHeight == -1){
-
-
- var viewport = Viewport.getEffectiveBox(this.ownerDocument),
- position = domGeometry.position(aroundNode, false);
- maxHeight = Math.floor(Math.max(position.y, viewport.h - (position.y + position.h)));
- }
-
-
- popup.moveOffScreen(dropDown);
- if(dropDown.startup && !dropDown._started){
- dropDown.startup();
- }
-
- var mb = domGeometry.getMarginSize(ddNode);
- var overHeight = (maxHeight && mb.h > maxHeight);
- domStyle.set(ddNode, {
- overflow: overHeight ? "auto" : "visible"
- });
- if(overHeight){
- mb.h = maxHeight;
- if("w" in mb){
- mb.w += 16;
- }
- }else{
- delete mb.h;
- }
-
- if(this.forceWidth){
- mb.w = aroundNode.offsetWidth;
- }else if(this.autoWidth){
- mb.w = Math.max(mb.w, aroundNode.offsetWidth);
- }else{
- delete mb.w;
- }
-
- if(lang.isFunction(dropDown.resize)){
- dropDown.resize(mb);
- }else{
- domGeometry.setMarginBox(ddNode, mb);
- }
- }
- var retVal = popup.open({
- parent: this,
- popup: dropDown,
- around: aroundNode,
- orient: this.dropDownPosition,
- onExecute: function(){
- self.closeDropDown(true);
- },
- onCancel: function(){
- self.closeDropDown(true);
- },
- onClose: function(){
- domAttr.set(self._popupStateNode, "popupActive", false);
- domClass.remove(self._popupStateNode, "dijitHasDropDownOpen");
- self._opened = false;
- }
- });
- domAttr.set(this._popupStateNode, "popupActive", "true");
- domClass.add(self._popupStateNode, "dijitHasDropDownOpen");
- this._opened=true;
-
- return retVal;
- },
- closeDropDown: function(/*Boolean*/ focus){
-
-
-
-
-
-
- if(this._opened){
- if(focus){ this.focus(); }
- popup.close(this.dropDown);
- this._opened = false;
- }
- }
- });
- });
|