forked from ibm-js/delite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpener.js
126 lines (111 loc) · 3.75 KB
/
Opener.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copy of dojox/mobile/Opener, not refactored to work with delite [yet]
define([
"dojo/_base/declare",
"dojo/Deferred",
"dojo/_base/lang",
"dojo/_base/window",
"dojo/dom-class",
"dojo/dom-construct",
"dojo/dom-style",
"dojo/dom-geometry",
"./Tooltip",
"./Overlay",
"./lazyLoadUtils"
], function (declare, Deferred, lang, win, domClass, domConstruct, domStyle, domGeometry, Tooltip, Overlay,
lazyLoadUtils) {
var isOverlay = domClass.contains(win.doc.documentElement, "dj_phone");
var cls = declare("dui.mobile.Opener", isOverlay ? Overlay : Tooltip, {
// summary:
// A non-templated popup widget that will use either Tooltip or
// Overlay depending on screen size.
// lazy: String
// If true, the content of the widget, which includes dojo markup,
// is instantiated lazily. That is, only when the widget is opened
// by the user, the required modules are loaded and the content
// widgets are instantiated.
lazy: false,
// requires: String
// Comma-separated required module names to be lazily loaded. This
// is effective only when lazy=true. All the modules specified with
// dojoType and their depending modules are automatically loaded
// when the widget is opened. However, if you need other extra
// modules to be loaded, use this parameter.
requires: "",
buildRendering: function () {
this.inherited(arguments);
this.cover = domConstruct.create("div", {
onclick: lang.hitch(this, "_onBlur"),
"class": "duiOpenerUnderlay",
style: {
position: isOverlay ? "absolute" : "fixed",
backgroundColor: "transparent",
overflow: "hidden",
zIndex: "-1"
}
}, this.domNode, "first");
},
/*jshint unused:false */
onShow: function ( /*DomNode*/node) {
},
/*jshint unused:false */
onHide: function ( /*DomNode*/node, /*Anything*/v) {
},
show: function (node, positions) {
if (this.lazy) {
this.lazy = false;
var _this = this;
return lazyLoadUtils.instantiateLazyWidgets(this.domNode, this.requires).then(function () {
return _this.show(node, positions);
});
}
this.node = node;
this.onShow(node);
// move cover temporarily to calculate domNode vertical position correctly
domStyle.set(this.cover, { top: "0px", left: "0px", width: "0px", height: "0px" });
// must be before this.inherited(arguments) for Tooltip sizing
this._resizeCover(domGeometry.position(this.domNode, false));
return this.inherited(arguments);
},
hide: function (/*Anything*/ val) {
this.inherited(arguments);
this.onHide(this.node, val);
},
_reposition: function () {
// tags:
// private
var popupPos = this.inherited(arguments);
this._resizeCover(popupPos);
return popupPos;
},
_resizeCover: function (popupPos) {
// tags:
// private
if (isOverlay) {
if (parseInt(domStyle.get(this.cover, "top"), 10) !== -popupPos.y ||
parseInt(domStyle.get(this.cover, "height"), 10) !== popupPos.y) {
var x = Math.max(popupPos.x, 0); // correct onorientationchange values
domStyle.set(this.cover, { top: -popupPos.y + "px", left: -x + "px", width: popupPos.w + x + "px",
height: popupPos.y + "px" });
}
} else {
domStyle.set(this.cover, {
width: Math.max(win.doc.documentElement.scrollWidth || win.body().scrollWidth
|| win.doc.documentElement.clientWidth) + "px",
height: Math.max(win.doc.documentElement.scrollHeight || win.body().scrollHeight
|| win.doc.documentElement.clientHeight) + "px"
});
}
},
_onBlur: function (e) {
// tags:
// private
var ret = this.onBlur(e);
if (ret !== false) { // only exactly false prevents hide()
this.hide(e);
}
return ret;
}
});
cls.prototype.baseClass += " duiOpener"; // add to either duiOverlay or duiTooltip
return cls;
});