-
Notifications
You must be signed in to change notification settings - Fork 0
/
micro-modal.js
50 lines (44 loc) · 1004 Bytes
/
micro-modal.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
(function() {
var $, close, initialize, open;
$ = jQuery;
$.fn.modal = function(options) {
if (typeof options === 'string') {
switch (options) {
case 'open':
open.apply(this);
break;
case 'close':
close.apply(this);
}
} else {
initialize.apply(this, [options]);
}
return this;
};
initialize = function(options) {
var $modal;
options = $.extend({
backdrop: true,
keyboard: true,
vertical: true
}, options);
$modal = $(this);
if (options.backdrop) {
$modal.addClass('modal-backdrop');
}
if (options.vertical) {
$modal.addClass('modal-vertical');
}
return $modal.on('click', function(e) {
if (e.target === e.currentTarget) {
return close.apply(this);
}
});
};
open = function() {
return $(this).addClass('modal-open');
};
close = function() {
return $(this).removeClass('modal-open');
};
}).call(this);