Debian Codegraph @

dojox/mobile/Opener.js

raw symbols SCIP
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 // summary:
19 // A non-templated popup widget that will use either Tooltip or
20 // Overlay depending on screen size.
21
22 // lazy: String
23 // If true, the content of the widget, which includes dojo markup,
24 // is instantiated lazily. That is, only when the widget is opened
25 // by the user, the required modules are loaded and the content
26 // widgets are instantiated.
27 lazy: false,
28
29 // requires: String
30 // Comma-separated required module names to be lazily loaded. This
31 // is effective only when lazy=true. All the modules specified with
32 // dojoType and their depending modules are automatically loaded
33 // when the widget is opened. However, if you need other extra
34 // modules to be loaded, use this parameter.
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(/*DomNode*/node){},
46 onHide: function(/*DomNode*/node, /*Anything*/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' }); // move cover temporarily to calculate domNode vertical position correctly
59 this._resizeCover(domGeometry.position(this.domNode, false)); // must be before this.inherited(arguments) for Tooltip sizing
60 return this.inherited(arguments);
61 },
62
63 hide: function(/*Anything*/ val){
64 this.inherited(arguments);
65 this.onHide(this.node, val);
66 },
67
68 _reposition: function(){
69 // tags:
70 // private
71 var popupPos = this.inherited(arguments);
72 this._resizeCover(popupPos);
73 return popupPos;
74 },
75
76 _resizeCover: function(popupPos){
77 // tags:
78 // private
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); // correct onorientationchange values
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 // tags:
94 // private
95 var ret = this.onBlur(e);
96 if(ret !== false){ // only exactly false prevents hide()
97 this.hide(e);
98 }
99 return ret;
100 }
101 });
102 cls.prototype.baseClass += " mblOpener"; // add to either mblOverlay or mblTooltip
103 return cls;
104 });