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>.
8 * @type {HTMLButtonElement}
13 * The cancel <button>.
14 * @type {HTMLButtonElement}
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=} okTitle The title of the OK button. If undefined or empty,
47 * @param {string=} cancelTitle The title of the cancel button. If undefined
48 * or empty, no button is shown.
49 * @param {function=} okCallback A function to be called when the user presses
50 * the ok button. Can be undefined if |okTitle| is falsey.
51 * @param {function=} cancelCallback A function to be called when the user
52 * presses the cancel button. Can be undefined if |cancelTitle| is falsey.
55 title, message, okTitle, cancelTitle, okCallback, cancelCallback) {
56 if (typeof title != 'undefined')
57 $('alertOverlayTitle').textContent = title;
58 $('alertOverlayTitle').hidden = typeof title == 'undefined';
60 if (typeof message != 'undefined')
61 $('alertOverlayMessage').textContent = message;
62 $('alertOverlayMessage').hidden = typeof message == 'undefined';
65 okButton.textContent = okTitle;
66 okButton.hidden = !okTitle;
67 okButton.clickCallback = okCallback;
70 cancelButton.textContent = cancelTitle;
71 cancelButton.hidden = !cancelTitle;
72 cancelButton.clickCallback = cancelCallback;
77 initialize: initialize,
82 document.addEventListener('DOMContentLoaded', alertOverlay.initialize);