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
3 // found in the LICENSE file.
5 cr.define('alertOverlay', function() {
7 * The confirm <button>.
13 * The cancel <button>.
18 function initialize(e) {
19 okButton = $('alertOverlayOk');
20 cancelButton = $('alertOverlayCancel');
22 // The callbacks are set to the callbacks provided in show(). Clear them
23 // out when either is clicked.
24 okButton.addEventListener('click', function(e) {
25 assert(okButton.clickCallback);
27 okButton.clickCallback(e);
28 okButton.clickCallback = null;
29 cancelButton.clickCallback = null;
31 cancelButton.addEventListener('click', function(e) {
32 assert(cancelButton.clickCallback);
34 cancelButton.clickCallback(e);
35 okButton.clickCallback = null;
36 cancelButton.clickCallback = null;
41 * Updates the alert overlay with the given message, button titles, and
43 * @param {string} title The alert title to display to the user.
44 * @param {string} message The alert message to display to the user.
45 * @param {string=} opt_okTitle The title of the OK button. If undefined or
46 * empty, no button is shown.
47 * @param {string=} opt_cancelTitle The title of the cancel button. If
48 * undefined or empty, no button is shown.
49 * @param {function()=} opt_okCallback A function to be called when the user
50 * presses the ok button. Can be undefined if |opt_okTitle| is falsey.
51 * @param {function()=} opt_cancelCallback A function to be called when the
52 * user presses the cancel button. Can be undefined if |opt_cancelTitle|
55 function setValues(title, message, opt_okTitle, opt_cancelTitle,
56 opt_okCallback, opt_cancelCallback) {
57 if (typeof title != 'undefined')
58 $('alertOverlayTitle').textContent = title;
59 $('alertOverlayTitle').hidden = typeof title == 'undefined';
61 if (typeof message != 'undefined')
62 $('alertOverlayMessage').textContent = message;
63 $('alertOverlayMessage').hidden = typeof message == 'undefined';
66 okButton.textContent = opt_okTitle;
67 okButton.hidden = !opt_okTitle;
68 okButton.clickCallback = opt_okCallback;
71 cancelButton.textContent = opt_cancelTitle;
72 cancelButton.hidden = !opt_cancelTitle;
73 cancelButton.clickCallback = opt_cancelCallback;
78 initialize: initialize,
83 document.addEventListener('DOMContentLoaded', alertOverlay.initialize);