This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblitz.js
132 lines (114 loc) · 3.66 KB
/
blitz.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
129
130
131
132
(function() {
window.Blitz = (function() {
Blitz.VERSION = '0.7.1';
Blitz.prototype.blitzTemplate = "<div class=\"blitz hide\">\n <div class=\"blitz-inner-wrapper\">\n <span class=\"blitz-message\"></span>\n <span class=\"blitz-spinner hide\"></span>\n <a href=\"#\" class=\"blitz-close\">×</a>\n </div>\n</div>";
Blitz.prototype.defaults = {
delay: 0,
replace: false,
spinner: false
};
function Blitz(container, options) {
if (options == null) {
options = {};
}
this.container = container;
this.options = this._defaults(options, this.defaults);
}
Blitz.prototype.setOptions = function(options) {
var key, value, _results;
_results = [];
for (key in options) {
value = options[key];
_results.push(this.options[key] = value);
}
return _results;
};
Blitz.prototype.notice = function(message, options) {
if (options == null) {
options = {};
}
return this._display(message, 'notice', options);
};
Blitz.prototype.alert = function(message, options) {
if (options == null) {
options = {};
}
return this._display(message, 'alert', options);
};
Blitz.prototype.success = function(message, options) {
if (options == null) {
options = {};
}
return this._display(message, 'success', options);
};
Blitz.prototype.hide = function() {
if ((this.$wrapper != null) && (this.$spinner != null)) {
this.$wrapper.addClass('hide');
return this.$spinner.addClass('hide');
}
};
Blitz.prototype._display = function(message, kind, options) {
options = this._defaults(options, this.options);
this._render(options.replace);
this._bindDomEvents();
this._startAutoHide(options.delay);
this._toggleSpinner(options.spinner);
this.$message.html(message);
return this.$wrapper.removeClass('hide notice alert success').addClass(kind);
};
Blitz.prototype._render = function() {
if (!this._rendered) {
this._rendered = true;
this.$wrapper = $(this.blitzTemplate);
this.$message = $('.blitz-message', this.$wrapper);
this.$spinner = $('.blitz-spinner', this.$wrapper);
this.$close = $('.blitz-close', this.$wrapper);
if (this.options.replace) {
return $(this.container).replaceWith(this.$wrapper);
} else {
return $(this.container).append(this.$wrapper);
}
}
};
Blitz.prototype._bindDomEvents = function() {
var self;
if (!this._domEventsBound) {
self = this;
return this.$wrapper.on('click.blitz', '.blitz-close', function(event) {
self.hide();
return false;
});
}
};
Blitz.prototype._startAutoHide = function(delay) {
var callback, self;
this._clearTimeout();
if (delay > 0) {
self = this;
callback = function() {
return self.hide();
};
return this.autoHideTimeout = setTimeout(callback, delay);
}
};
Blitz.prototype._clearTimeout = function() {
if (this.autoHideTimeout != null) {
return clearTimeout(this.autoHideTimeout);
}
};
Blitz.prototype._toggleSpinner = function(show) {
return this.$spinner.toggleClass('hide', !show);
};
Blitz.prototype._defaults = function(options, defaults) {
var key, value;
for (key in defaults) {
value = defaults[key];
if (options[key] == null) {
options[key] = defaults[key];
}
}
return options;
};
return Blitz;
})();
}).call(this);