forked from rmurphey/jqfundamentals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal.js
62 lines (52 loc) · 1.05 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
var modal = {
initialized : false,
init : function() {
if (modal.initalized) { return; }
modal.$m = $('<div id="modal"/>')
.appendTo('body')
.hide();
modal.$c = $('<div id="modal_content"/>')
.appendTo(modal.$m);
modal.$o = $('<div id="overlay"/>')
.appendTo('body')
.hide()
.css({opacity:0.8})
.click(modal.hide);
modal.$h = $('<p class="closer">Close</p>')
.insertBefore(modal.$c)
.click(modal.hide);
modal.initialized = true;
},
show : function() {
modal.init();
modal.$m.fadeIn(300);
modal.$o.show();
},
populate : function(html) {
modal.init();
modal.$c.html(html);
modal.show();
},
hide : function() {
modal.init();
modal.$m.fadeOut(300);
modal.$o.hide();
}
};
$(document).ready(function() {
var $links = $('#menus a');
if ($links.length) {
$links.click(function(e) {
e.preventDefault();
var href = $(this).attr('href');
$.ajax({
url : href,
dataType : 'html',
type : 'GET',
success : function(html) {
modal.populate(html);
}
});
});
}
});