OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('cr.ui.dialogs', function() { | 5 cr.define('cr.ui.dialogs', function() { |
6 /** | 6 /** |
7 * @constructor | 7 * @constructor |
8 */ | 8 */ |
9 function BaseDialog(parentNode) { | 9 function BaseDialog(parentNode) { |
10 this.parentNode_ = parentNode; | 10 this.parentNode_ = parentNode; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 * @param {Function=} opt_onShow | 164 * @param {Function=} opt_onShow |
165 */ | 165 */ |
166 BaseDialog.prototype.showHtml = function( | 166 BaseDialog.prototype.showHtml = function( |
167 title, message, opt_onOk, opt_onCancel, opt_onShow) { | 167 title, message, opt_onOk, opt_onCancel, opt_onShow) { |
168 this.text_.innerHTML = message; | 168 this.text_.innerHTML = message; |
169 this.show_(title, opt_onOk, opt_onCancel, opt_onShow); | 169 this.show_(title, opt_onOk, opt_onCancel, opt_onShow); |
170 }; | 170 }; |
171 | 171 |
172 /** @private */ | 172 /** @private */ |
173 BaseDialog.prototype.findFocusableElements_ = function(doc) { | 173 BaseDialog.prototype.findFocusableElements_ = function(doc) { |
174 var elements = Array.prototype.filter.call( | 174 var elements = |
175 doc.querySelectorAll('*'), function(n) { return n.tabIndex >= 0; }); | 175 Array.prototype.filter.call(doc.querySelectorAll('*'), function(n) { |
| 176 return n.tabIndex >= 0; |
| 177 }); |
176 | 178 |
177 var iframes = doc.querySelectorAll('iframe'); | 179 var iframes = doc.querySelectorAll('iframe'); |
178 for (var i = 0; i < iframes.length; i++) { | 180 for (var i = 0; i < iframes.length; i++) { |
179 // Some iframes have an undefined contentDocument for security reasons, | 181 // Some iframes have an undefined contentDocument for security reasons, |
180 // such as chrome://terms (which is used in the chromeos OOBE screens). | 182 // such as chrome://terms (which is used in the chromeos OOBE screens). |
181 var iframe = iframes[i]; | 183 var iframe = iframes[i]; |
182 var contentDoc; | 184 var contentDoc; |
183 try { | 185 try { |
184 contentDoc = iframe.contentDocument; | 186 contentDoc = iframe.contentDocument; |
185 } catch (e) { | 187 } catch (e) { |
(...skipping 24 matching lines...) Expand all Loading... |
210 * @param {Function=} opt_onShow | 212 * @param {Function=} opt_onShow |
211 * @private | 213 * @private |
212 */ | 214 */ |
213 BaseDialog.prototype.show_ = function( | 215 BaseDialog.prototype.show_ = function( |
214 title, opt_onOk, opt_onCancel, opt_onShow) { | 216 title, opt_onOk, opt_onCancel, opt_onShow) { |
215 // Make all outside nodes unfocusable while the dialog is active. | 217 // Make all outside nodes unfocusable while the dialog is active. |
216 this.deactivatedNodes_ = this.findFocusableElements_(this.document_); | 218 this.deactivatedNodes_ = this.findFocusableElements_(this.document_); |
217 this.tabIndexes_ = this.deactivatedNodes_.map(function(n) { | 219 this.tabIndexes_ = this.deactivatedNodes_.map(function(n) { |
218 return n.getAttribute('tabindex'); | 220 return n.getAttribute('tabindex'); |
219 }); | 221 }); |
220 this.deactivatedNodes_.forEach(function(n) { n.tabIndex = -1; }); | 222 this.deactivatedNodes_.forEach(function(n) { |
| 223 n.tabIndex = -1; |
| 224 }); |
221 | 225 |
222 this.previousActiveElement_ = this.document_.activeElement; | 226 this.previousActiveElement_ = this.document_.activeElement; |
223 this.parentNode_.appendChild(this.container_); | 227 this.parentNode_.appendChild(this.container_); |
224 | 228 |
225 this.onOk_ = opt_onOk; | 229 this.onOk_ = opt_onOk; |
226 this.onCancel_ = opt_onCancel; | 230 this.onCancel_ = opt_onCancel; |
227 | 231 |
228 if (title) { | 232 if (title) { |
229 this.title_.textContent = title; | 233 this.title_.textContent = title; |
230 this.title_.hidden = false; | 234 this.title_.hidden = false; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 AlertDialog.prototype.show = function(message, opt_onOk, opt_onShow) { | 303 AlertDialog.prototype.show = function(message, opt_onOk, opt_onShow) { |
300 return BaseDialog.prototype.show.call( | 304 return BaseDialog.prototype.show.call( |
301 this, message, opt_onOk, opt_onOk, opt_onShow); | 305 this, message, opt_onOk, opt_onOk, opt_onShow); |
302 }; | 306 }; |
303 | 307 |
304 /** | 308 /** |
305 * ConfirmDialog contains a message, an ok button, and a cancel button. | 309 * ConfirmDialog contains a message, an ok button, and a cancel button. |
306 * @constructor | 310 * @constructor |
307 * @extends {cr.ui.dialogs.BaseDialog} | 311 * @extends {cr.ui.dialogs.BaseDialog} |
308 */ | 312 */ |
309 function ConfirmDialog(parentNode) { BaseDialog.call(this, parentNode); } | 313 function ConfirmDialog(parentNode) { |
| 314 BaseDialog.call(this, parentNode); |
| 315 } |
310 | 316 |
311 ConfirmDialog.prototype = {__proto__: BaseDialog.prototype}; | 317 ConfirmDialog.prototype = {__proto__: BaseDialog.prototype}; |
312 | 318 |
313 /** | 319 /** |
314 * PromptDialog contains a message, a text input, an ok button, and a | 320 * PromptDialog contains a message, a text input, an ok button, and a |
315 * cancel button. | 321 * cancel button. |
316 * @constructor | 322 * @constructor |
317 * @extends {cr.ui.dialogs.BaseDialog} | 323 * @extends {cr.ui.dialogs.BaseDialog} |
318 */ | 324 */ |
319 function PromptDialog(parentNode) { | 325 function PromptDialog(parentNode) { |
(...skipping 30 matching lines...) Expand all Loading... |
350 * TODO(fukino): remove suppression if there is a better way to avoid warning | 356 * TODO(fukino): remove suppression if there is a better way to avoid warning |
351 * about overriding method with different signature. | 357 * about overriding method with different signature. |
352 */ | 358 */ |
353 PromptDialog.prototype.show = function( | 359 PromptDialog.prototype.show = function( |
354 message, defaultValue, opt_onOk, opt_onCancel, opt_onShow) { | 360 message, defaultValue, opt_onOk, opt_onCancel, opt_onShow) { |
355 this.input_.value = defaultValue || ''; | 361 this.input_.value = defaultValue || ''; |
356 return BaseDialog.prototype.show.call( | 362 return BaseDialog.prototype.show.call( |
357 this, message, opt_onOk, opt_onCancel, opt_onShow); | 363 this, message, opt_onOk, opt_onCancel, opt_onShow); |
358 }; | 364 }; |
359 | 365 |
360 PromptDialog.prototype.getValue = function() { return this.input_.value; }; | 366 PromptDialog.prototype.getValue = function() { |
| 367 return this.input_.value; |
| 368 }; |
361 | 369 |
362 /** @private */ | 370 /** @private */ |
363 PromptDialog.prototype.onOkClick_ = function(event) { | 371 PromptDialog.prototype.onOkClick_ = function(event) { |
364 this.hide(); | 372 this.hide(); |
365 if (this.onOk_) | 373 if (this.onOk_) |
366 this.onOk_(this.getValue()); | 374 this.onOk_(this.getValue()); |
367 }; | 375 }; |
368 | 376 |
369 return { | 377 return { |
370 BaseDialog: BaseDialog, | 378 BaseDialog: BaseDialog, |
371 AlertDialog: AlertDialog, | 379 AlertDialog: AlertDialog, |
372 ConfirmDialog: ConfirmDialog, | 380 ConfirmDialog: ConfirmDialog, |
373 PromptDialog: PromptDialog | 381 PromptDialog: PromptDialog |
374 }; | 382 }; |
375 }); | 383 }); |
OLD | NEW |