forked from FinelySliced/leanModal.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.leanModal.js
More file actions
77 lines (48 loc) · 2.03 KB
/
jquery.leanModal.js
File metadata and controls
77 lines (48 loc) · 2.03 KB
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
(function($){
$.fn.extend({
leanModal: function(options) {
function closeModal(modalId){
$('#lean_overlay').fadeOut(200);
$(modalId).css({ 'display' : 'none' });
}
var defaults = {
top: null,
overlay: 0.5,
closeButton: null
};
if(!$('#lean_overlay')[0]){
var overlay = $('<div id="lean_overlay"></div>');
$('body').append(overlay);
}
options = $.extend(defaults, options);
return this.each(function() {
var o = options;
$(this).click(function(e) {
var modalId = $(this).attr('href');
$('#lean_overlay').click(function() {
closeModal(modalId);
});
$(o.closeButton).click(function() {
closeModal(modalId);
});
var modalHeight= $(modalId).outerHeight();
var modalWidth = $(modalId).outerWidth();
$('#lean_overlay').css({ 'display' : 'block', opacity : 0 });
$('#lean_overlay').fadeTo(200, o.overlay);
$(modalId).css({
'display' : 'block',
'position' : 'fixed',
'opacity' : 0,
'z-index': 11000,
'left' : 50 + '%',
'margin-left' : -(modalWidth/2) + 'px',
'top' : o.top ? o.top + 'px' : '50%',
'margin-top' : o.top ? 0 : -(modalHeight/2) + 'px'
});
$(modalId).fadeTo(200,1);
e.preventDefault();
});
});
}
});
})(jQuery);