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
86 lines (60 loc) · 2.44 KB
/
jquery.leanModal.js
File metadata and controls
86 lines (60 loc) · 2.44 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
78
79
80
81
82
83
84
85
86
(function($){
var modal_no = 0;
$.fn.extend({
leanModal: function(options) {
var defaults = {
top: 100,
overlay: 0.5
}
options = $.extend(defaults, options);
return this.each(function() {
var o = options;
$(this).click(function(e) {
$("body").append("<div id='lean_overlay'></div>");
$this = $(this);
var href = $this.attr("href");
if(href.substr(0,1) == '#')
{
show_modal(href, o);
}
else
{
(function(){
id = "modal-dialog-"+(modal_no++);
$(document.createElement('div'))
.appendTo('body')
.css({'display': 'none'})
.attr('id',id)
.load(href,function(){show_modal("#"+id, o);});
$this.attr('href',"#"+id);
})();
}
e.preventDefault();
});
});
function show_modal(modal_id, options){
$("#lean_overlay").click(function() {
close_modal(modal_id);
});
var modal_height = $(modal_id).outerHeight();
var modal_width = $(modal_id).outerWidth();
$('#lean_overlay').css({ 'display' : 'block', opacity : 0 });
$('#lean_overlay').fadeTo(200,options.overlay);
$(modal_id).css({
'display' : 'block',
'position' : 'fixed',
'opacity' : 0,
'z-index': 9999,
'left' : 50 + '%',
'margin-left' : -(modal_width/2) + "px",
'top' : options.top + "px"
});
$(modal_id).fadeTo(200,1);
}
function close_modal(modal_id){
$("#lean_overlay").fadeOut(200);
$(modal_id).css({ 'display' : 'none' });
}
}
});
})(jQuery);