-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
112 lines (96 loc) · 2.15 KB
/
index.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
/**
* Module dependencies.
*/
var Notification = require('notification').Notification
, Progress = require('progress')
, inherit = require('inherit')
, o = require('jquery');
/**
* Expose `notify`.
*/
exports = module.exports = notify;
/**
* Return a new `ProgressNotification` with the given
* (optional) `title` and `msg`. Either combination
* may pass a callback.
*
* @param {String} title or msg
* @param {Function} msg
* @return {Dialog}
* @api public
*/
function notify(title, msg){
if (2 == arguments.length) {
return new ProgressNotification({ title: title, message: msg })
.show();
} else {
return new ProgressNotification({ message: title })
.show();
}
}
/**
* Initialize a new `ProgressNotification`.
*
* Options:
*
* - `title` dialog title
* - `message` a message to display
*
* @param {Object} options
* @api public
*/
function ProgressNotification(options) {
options = options || {};
var self = this;
var msg = options.message;
this.progress = new Progress;
this.size(40);
this.content = o(require('./template'));
options.message = this.content;
options.classname = 'progress-notification';
Notification.call(this, options);
this.content.find('.progress-notification-canvas').append(this.progress.el);
this.message(msg);
};
/**
* Inherit from `Notification.prototype`.
*/
inherit(ProgressNotification, Notification);
/**
* Set progress indicator size to `n`.
*
* @param {Number} n
* @return {ProgressNotification}
* @api public
*/
ProgressNotification.prototype.size = function(n){
this.progress.size(n);
return this;
};
/**
* Set progress `msg`.
*
* @param {String|Element} msg
* @return {ProgressNotification}
* @api public
*/
ProgressNotification.prototype.message = function(msg){
var el = this.content.find('.progress-notification-message');
if ('string' == typeof msg) {
el.text(msg);
} else {
el.empty().append(msg);
}
return this;
};
/**
* Set progress percentage to `n`.
*
* @param {Number} n
* @return {ProgressNotification}
* @api public
*/
ProgressNotification.prototype.update = function(n){
this.progress.update(n);
return this;
};