-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathapprise-1.5.full.js
128 lines (111 loc) · 4.33 KB
/
apprise-1.5.full.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Apprise 1.5 by Daniel Raftery
// http://thrivingkings.com/apprise
//
// Button text added by Adam Bezulski
//
// Cached jQuery variables, position center added by Josiah Ruddell
function apprise(string, args, callback) {
var default_args =
{
'confirm': false, // Ok and Cancel buttons
'verify': false, // Yes and No buttons
'input': false, // Text input (can be true or string for default text)
'animate': false, // Groovy animation (can true or number, default is 400)
'textOk': 'Ok', // Ok button default text
'textCancel': 'Cancel', // Cancel button default text
'textYes': 'Yes', // Yes button default text
'textNo': 'No', // No button default text
'position': 'center'// position center (y-axis) any other option will default to 100 top
}
if (args) {
for (var index in default_args)
{ if (typeof args[index] == "undefined") args[index] = default_args[index]; }
}
var aHeight = $(window).height(),
aWidth = $(window).width(),
apprise = $('<div class="appriseOuter"></div>'),
overlay = $('<div class="appriseOverlay" id="aOverlay"></div>'),
inner = $('<div class="appriseInner"></div>'),
buttons = $('<div class="aButtons"></div>'),
posTop = 100;
overlay.css({ height: aHeight, width: aWidth })
.appendTo('body')
.fadeIn(100,function(){$(this).css('filter','alpha(opacity=70)');});
apprise.appendTo('body');
inner.append(string)
.appendTo(apprise);
if (args) {
if (args['input']) {
if (typeof (args['input']) == 'string') {
inner.append('<div class="aInput"><input type="text" class="aTextbox" t="aTextbox" value="' + args['input'] + '" /></div>');
}
if (typeof (args['input']) == 'object') {
inner.append($('<div class="aInput"></div>').append(args['input']));
}
else {
inner.append('<div class="aInput"><input type="text" class="aTextbox" t="aTextbox" /></div>');
}
$('.aTextbox').focus();
}
}
inner.append(buttons);
if (args) {
if (args['confirm'] || args['input']) {
buttons.append('<button value="ok">' + args['textOk'] + '</button>');
buttons.append('<button value="cancel">' + args['textCancel'] + '</button>');
}
else if (args['verify']) {
buttons.append('<button value="ok">' + args['textYes'] + '</button>');
buttons.append('<button value="cancel">' + args['textNo'] + '</button>');
}
else { buttons.append('<button value="ok">' + args['textOk'] + '</button>'); }
}
else { buttons.append('<button value="ok">Ok</button>'); }
// position after adding buttons
apprise.css("left", ($(window).width() - $('.appriseOuter').width()) / 2 + $(window).scrollLeft() + "px");
// get center
if (args) {
if (args['position'] && args['position'] === 'center') {
posTop = (aHeight - apprise.height()) / 2;
}
if (args['animate']) {
var aniSpeed = args['animate'];
if (isNaN(aniSpeed)) { aniSpeed = 400; }
apprise.css('top', '-200px').show().animate({ top: posTop }, aniSpeed);
}
else { apprise.css('top', posTop).fadeIn(200); }
}
else { apprise.css('top', posTop).fadeIn(200); }
$(document).keydown(function (e) {
if (overlay.is(':visible')) {
if (e.keyCode == 13)
{ $('.aButtons > button[value="ok"]').click(); }
if (e.keyCode == 27)
{ $('.aButtons > button[value="cancel"]').click(); }
}
});
var aText = $('.aTextbox').val();
if (!aText) { aText = false; }
$('.aTextbox').keyup(function ()
{ aText = $(this).val(); });
$('.aButtons > button').click(function () {
overlay.remove();
apprise.remove();
if (callback) {
$(this).text("");
var wButton = $(this).attr("value");
if (wButton == 'ok') {
if (args) {
if (args['input']) { callback(aText); }
else { callback(true); }
}
else {
callback(true);
}
}
else if (wButton == 'cancel') {
callback(false);
}
}
});
}