Debian Codegraph @

dojox/mobile/SimpleDialog.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare",
3 "dojo/_base/window",
4 "dojo/dom-class",
5 "dojo/dom-attr",
6 "dojo/dom-construct",
7 "dojo/on",
8 "dojo/touch",
9 "dijit/registry",
10 "./Pane",
11 "./iconUtils",
12 "dojo/has",
13 "dojo/has!dojo-bidi?dojox/mobile/bidi/SimpleDialog"
14 ], function(declare, win, domClass, domAttr, domConstruct, on, touch, registry, Pane, iconUtils, has, BidiSimpleDialog){
15 // module:
16 // dojox/mobile/SimpleDialog
17
18 var SimpleDialog = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiSimpleDialog" : "dojox.mobile.SimpleDialog", Pane, {
19 // summary:
20 // A dialog box for mobile.
21 // description:
22 // SimpleDialog is a dialog box for mobile.
23 // When a SimpleDialog is created, it is initially hidden
24 // (display="none"). To show the dialog box, you need to
25 // get a reference to the widget and to call its show() method.
26 //
27 // The contents can be arbitrary HTML, text, or widgets. Note,
28 // however, that the widget is initially hidden. You need to be
29 // careful when you place in a SimpleDialog elements that cannot
30 // be initialized in hidden state.
31 //
32 // This widget has much less functionalities than dijit/Dialog,
33 // but it has the advantage of a much smaller code size.
34
35 // top: String
36 // The top edge position of the widget. If "auto", the widget is
37 // placed at the middle of the screen. Otherwise, the value
38 // (ex. "20px") is used as the top style of widget's domNode.
39 top: "auto",
40
41 // left: String
42 // The left edge position of the widget. If "auto", the widget is
43 // placed at the center of the screen. Otherwise, the value
44 // (ex. "20px") is used as the left style of widget's domNode.
45 left: "auto",
46
47 // modal: Boolean
48 // If true, a translucent cover is added over the entire page to
49 // prevent the user from interacting with elements on the page.
50 modal: true,
51
52 // closeButton: [const] Boolean
53 // If true, a button to close the dialog box is displayed at the
54 // top-right corner.
55 // Note that changing the value of the property after the widget
56 // creation has no effect.
57 closeButton: false,
58
59 // closeButtonClass: String
60 // A class name of a DOM button to be used as a close button.
61 closeButtonClass: "mblDomButtonSilverCircleRedCross",
62
63 // tabIndex: String
64 // Tabindex setting for the item so users can hit the tab key to
65 // focus on it.
66 tabIndex: "0",
67
68 // _setTabIndexAttr: [private] String
69 // Sets tabIndex to domNode.
70 _setTabIndexAttr: "",
71
72 /* internal properties */
73
74 // baseClass: String
75 // The name of the CSS class of this widget.
76 baseClass: "mblSimpleDialog",
77
78 // _cover: [private] Array
79 // Array for sharing the cover instances.
80 _cover: [],
81
82 buildRendering: function(){
83 this.containerNode = domConstruct.create("div", {className:"mblSimpleDialogContainer"});
84 if(this.srcNodeRef){
85 // reparent
86 for(var i = 0, len = this.srcNodeRef.childNodes.length; i < len; i++){
87 this.containerNode.appendChild(this.srcNodeRef.removeChild(this.srcNodeRef.firstChild));
88 }
89 }
90 this.inherited(arguments);
91 domAttr.set(this.domNode, "role", "dialog");
92
93 if(this.containerNode.getElementsByClassName){ //TODO: Do we need to support IE8 a11y?
94 var titleNode = this.containerNode.getElementsByClassName("mblSimpleDialogTitle")[0];
95 if (titleNode){
96 titleNode.id = titleNode.id || registry.getUniqueId("dojo_mobile_mblSimpleDialogTitle");
97 domAttr.set(this.domNode, "aria-labelledby", titleNode.id);
98 }
99 var textNode = this.containerNode.getElementsByClassName("mblSimpleDialogText")[0];
100 if (textNode){
101 textNode.id = textNode.id || registry.getUniqueId("dojo_mobile_mblSimpleDialogText");
102 domAttr.set(this.domNode, "aria-describedby", textNode.id);
103 }
104 }
105 domClass.add(this.domNode, "mblSimpleDialogDecoration");
106 this.domNode.style.display = "none";
107 this.domNode.appendChild(this.containerNode);
108 if(this.closeButton){
109 this.closeButtonNode = domConstruct.create("div", {
110 className: "mblSimpleDialogCloseBtn "+this.closeButtonClass
111 }, this.domNode);
112 iconUtils.createDomButton(this.closeButtonNode);
113 this.connect(this.closeButtonNode, "onclick", "_onCloseButtonClick");
114 }
115 this.connect(this.domNode, "onkeydown", "_onKeyDown"); // for desktop browsers
116 },
117
118 startup: function(){
119 if(this._started){ return; }
120 this.inherited(arguments);
121 win.body().appendChild(this.domNode);
122 },
123
124 addCover: function(){
125 // summary:
126 // Adds the transparent DIV cover.
127 if(!this._cover[0]){
128 this._cover[0] = domConstruct.create("div", {
129 className: "mblSimpleDialogCover"
130 }, win.body());
131 }else{
132 this._cover[0].style.display = "";
133 }
134
135 if(has("windows-theme")) {
136 // Hack to prevent interaction with elements placed under cover div.
137 this.own(on(this._cover[0], touch.press, function() {}));
138 }
139 },
140
141 removeCover: function(){
142 // summary:
143 // Removes the transparent DIV cover.
144 this._cover[0].style.display = "none";
145 },
146
147 _onCloseButtonClick: function(e){
148 // tags:
149 // private
150 if(this.onCloseButtonClick(e) === false){ return; } // user's click action
151 this.hide();
152 },
153
154 onCloseButtonClick: function(/*Event*/ /*===== e =====*/){
155 // summary:
156 // User-defined function to handle clicks.
157 // tags:
158 // callback
159 },
160
161 _onKeyDown: function(e){
162 // tags:
163 // private
164 if(e.keyCode == 27){ // ESC
165 this.hide();
166 }
167 },
168
169 refresh: function(){ // TODO: should we call refresh on resize?
170 // summary:
171 // Refreshes the layout of the dialog.
172 var n = this.domNode;
173 var h;
174 if(this.closeButton){
175 var b = this.closeButtonNode;
176 var s = Math.round(b.offsetHeight / 2);
177 b.style.top = -s + "px";
178 b.style.left = n.offsetWidth - s + "px";
179 }
180 if(this.top === "auto"){
181 h = win.global.innerHeight || win.doc.documentElement.clientHeight;
182 n.style.top = Math.round((h - n.offsetHeight) / 2) + "px";
183 }else{
184 n.style.top = this.top;
185 }
186 if(this.left === "auto"){
187 h = win.global.innerWidth || win.doc.documentElement.clientWidth;
188 n.style.left = Math.round((h - n.offsetWidth) / 2) + "px";
189 }else{
190 n.style.left = this.left;
191 }
192 },
193
194 show: function(){
195 // summary:
196 // Shows the dialog.
197 if(this.domNode.style.display === ""){ return; }
198 if(this.modal){
199 this.addCover();
200 }
201 this.domNode.style.display = "";
202 this.resize(); // #15628
203 this.refresh();
204 var diaglogButton;
205 if(this.domNode.getElementsByClassName){
206 diaglogButton = this.domNode.getElementsByClassName("mblSimpleDialogButton")[0];
207 }
208 var focusNode = diaglogButton || this.closeButtonNode || this.domNode; // Focus preference is: user supplied button, close button, entire dialog
209 /// on Safari iOS the focus is not taken without a timeout
210 this.defer(function(){ focusNode.focus();}, 1000);
211 },
212
213 hide: function(){
214 // summary:
215 // Hides the dialog.
216 if(this.domNode.style.display === "none"){ return; }
217 this.domNode.style.display = "none";
218 if(this.modal){
219 this.removeCover();
220 }
221 }
222 });
223 return has("dojo-bidi") ? declare("dojox.mobile.SimpleDialog", [SimpleDialog, BidiSimpleDialog]) : SimpleDialog;
224 });