-
Notifications
You must be signed in to change notification settings - Fork 1
/
alertview.js
50 lines (38 loc) · 1.53 KB
/
alertview.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
$(function() {
var $alertViewBackdrop = $('<div class="alert-view-backdrop"/>');
$(document.body).append($alertViewBackdrop);
/**
Shows the AlertView modal.
@param {Object} Optional properties: title, message, buttons, and callback.
*/
window.AlertView = {
show: function(settings) {
var title = settings.title;
var message = settings.message;
var buttons = settings.buttons;
var callback = settings.callback;
var $alertViewElement = $('<div class="alert-view animated bounceIn"/>');
if (title) $('<h1>' + title + '</h1>').appendTo($alertViewElement);
if (message) $('<p>' + message + '</p>').appendTo($alertViewElement);
if (buttons) {
var numberOfButtons = buttons.length;
if (numberOfButtons > 0) {
$alertViewElement.addClass('button-count-' + numberOfButtons);
for (var i = 0; i < numberOfButtons; i++) {
$('<a ' + (i === 0 ? 'class="alert-button-primary" ' : '') + 'data-button-index="' + i + '" href="#">' + buttons[i] + '</a>').appendTo($alertViewElement);
}
}
}
$alertViewElement.delegate('a', 'click', function(evt) {
evt.preventDefault();
if (callback && typeof callback === 'function') {
callback(parseInt($(this).attr('data-button-index'), 10));
}
$alertViewElement.remove();
});
// Add the alertViewElement just before the backdrop
$alertViewBackdrop.before($alertViewElement);
}
};
});