| 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 |
|
| 16 |
|
| 17 |
|
| 18 |
var SimpleDialog = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiSimpleDialog" : "dojox.mobile.SimpleDialog", Pane, { |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
top: "auto", |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
left: "auto", |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
modal: true, |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
closeButton: false, |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
closeButtonClass: "mblDomButtonSilverCircleRedCross", |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
tabIndex: "0", |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
_setTabIndexAttr: "", |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
baseClass: "mblSimpleDialog", |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
_cover: [], |
| 81 |
|
| 82 |
buildRendering: function(){ |
| 83 |
this.containerNode = domConstruct.create("div", {className:"mblSimpleDialogContainer"}); |
| 84 |
if(this.srcNodeRef){ |
| 85 |
|
| 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){ |
| 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"); |
| 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 |
|
| 126 |
|
| 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 |
|
| 137 |
this.own(on(this._cover[0], touch.press, function() {})); |
| 138 |
} |
| 139 |
}, |
| 140 |
|
| 141 |
removeCover: function(){ |
| 142 |
|
| 143 |
|
| 144 |
this._cover[0].style.display = "none"; |
| 145 |
}, |
| 146 |
|
| 147 |
_onCloseButtonClick: function(e){ |
| 148 |
|
| 149 |
|
| 150 |
if(this.onCloseButtonClick(e) === false){ return; } |
| 151 |
this.hide(); |
| 152 |
}, |
| 153 |
|
| 154 |
onCloseButtonClick: function( ){ |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
}, |
| 160 |
|
| 161 |
_onKeyDown: function(e){ |
| 162 |
|
| 163 |
|
| 164 |
if(e.keyCode == 27){ |
| 165 |
this.hide(); |
| 166 |
} |
| 167 |
}, |
| 168 |
|
| 169 |
refresh: function(){ |
| 170 |
|
| 171 |
|
| 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 |
|
| 196 |
|
| 197 |
if(this.domNode.style.display === ""){ return; } |
| 198 |
if(this.modal){ |
| 199 |
this.addCover(); |
| 200 |
} |
| 201 |
this.domNode.style.display = ""; |
| 202 |
this.resize(); |
| 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; |
| 209 |
|
| 210 |
this.defer(function(){ focusNode.focus();}, 1000); |
| 211 |
}, |
| 212 |
|
| 213 |
hide: function(){ |
| 214 |
|
| 215 |
|
| 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 |
}); |