| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/Deferred", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/_base/window", |
| 6 |
"dojo/dom-class", |
| 7 |
"dojo/dom-construct", |
| 8 |
"dojo/dom-style", |
| 9 |
"dojo/dom-geometry", |
| 10 |
"./Tooltip", |
| 11 |
"./Overlay", |
| 12 |
"./lazyLoadUtils" |
| 13 |
], function(declare, Deferred, lang, win, domClass, domConstruct, domStyle, domGeometry, Tooltip, Overlay, lazyLoadUtils){ |
| 14 |
|
| 15 |
var isOverlay = domClass.contains(win.doc.documentElement, "dj_phone"); |
| 16 |
|
| 17 |
var cls = declare("dojox.mobile.Opener", isOverlay ? Overlay : Tooltip, { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
lazy: false, |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
requires: "", |
| 36 |
|
| 37 |
buildRendering: function(){ |
| 38 |
this.inherited(arguments); |
| 39 |
this.cover = domConstruct.create('div', { |
| 40 |
onclick: lang.hitch(this, '_onBlur'), 'class': 'mblOpenerUnderlay', |
| 41 |
style: { position: isOverlay ? 'absolute' : 'fixed', backgroundColor:'transparent', overflow:'hidden', zIndex:'-1' } |
| 42 |
}, this.domNode, 'first'); |
| 43 |
}, |
| 44 |
|
| 45 |
onShow: function(node){}, |
| 46 |
onHide: function(node, v){}, |
| 47 |
|
| 48 |
show: function(node, positions){ |
| 49 |
if(this.lazy){ |
| 50 |
this.lazy = false; |
| 51 |
var _this = this; |
| 52 |
return Deferred.when(lazyLoadUtils.instantiateLazyWidgets(this.domNode, this.requires), function(){ |
| 53 |
return _this.show(node, positions); |
| 54 |
}); |
| 55 |
} |
| 56 |
this.node = node; |
| 57 |
this.onShow(node); |
| 58 |
domStyle.set(this.cover, { top:'0px', left:'0px', width:'0px', height:'0px' }); |
| 59 |
this._resizeCover(domGeometry.position(this.domNode, false)); |
| 60 |
return this.inherited(arguments); |
| 61 |
}, |
| 62 |
|
| 63 |
hide: function( val){ |
| 64 |
this.inherited(arguments); |
| 65 |
this.onHide(this.node, val); |
| 66 |
}, |
| 67 |
|
| 68 |
_reposition: function(){ |
| 69 |
|
| 70 |
|
| 71 |
var popupPos = this.inherited(arguments); |
| 72 |
this._resizeCover(popupPos); |
| 73 |
return popupPos; |
| 74 |
}, |
| 75 |
|
| 76 |
_resizeCover: function(popupPos){ |
| 77 |
|
| 78 |
|
| 79 |
if(isOverlay){ |
| 80 |
if(parseInt(domStyle.get(this.cover, 'top')) != -popupPos.y || parseInt(domStyle.get(this.cover, 'height')) != popupPos.y){ |
| 81 |
var x = Math.max(popupPos.x, 0); |
| 82 |
domStyle.set(this.cover, { top:-popupPos.y+'px', left:-x+'px', width:popupPos.w+x+'px', height:popupPos.y+'px' }); |
| 83 |
} |
| 84 |
}else{ |
| 85 |
domStyle.set(this.cover, { |
| 86 |
width:Math.max(win.doc.documentElement.scrollWidth || win.body().scrollWidth || win.doc.documentElement.clientWidth)+'px', |
| 87 |
height:Math.max(win.doc.documentElement.scrollHeight || win.body().scrollHeight || win.doc.documentElement.clientHeight)+'px' |
| 88 |
}); |
| 89 |
} |
| 90 |
}, |
| 91 |
|
| 92 |
_onBlur: function(e){ |
| 93 |
|
| 94 |
|
| 95 |
var ret = this.onBlur(e); |
| 96 |
if(ret !== false){ |
| 97 |
this.hide(e); |
| 98 |
} |
| 99 |
return ret; |
| 100 |
} |
| 101 |
}); |
| 102 |
cls.prototype.baseClass += " mblOpener"; |
| 103 |
return cls; |
| 104 |
}); |