forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
43 lines (34 loc) · 1.37 KB
/
utils.js
File metadata and controls
43 lines (34 loc) · 1.37 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
function showModalBox(content, callback) {
content = $(content);
// make sure previous one is gone
$("#modal-overlay").remove();
// the url(data:...) part is backwards compatibility for non-rgba
// supporting browsers (IE 8) - it's a 2 pixel black PNG with
// opacity 50%
var overlay = $('<div id="modal-overlay" style="position:fixed;z-index:100;top:0;left:0;height:100%;width:100%;background:transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAABCAQAAABeK7cBAAAACXBIWXMAAAsTAAALEwEAmpwYAAAADUlEQVQIHWNgqGeoBwACAQD/+EjsGgAAAABJRU5ErkJggg==);background:rgba(0,0,0,0.5);"></div>');
var box = $('<div id="modal-box" style="position:absolute;left:50%;top:50%"></div>');
box.append(content);
overlay.append(box);
box.click(function (e) {
e.stopPropagation();
});
overlay.click(closeModalBox);
box.find(".button.close").click(function (e) {
e.preventDefault();
closeModalBox();
});
overlay.keydown(function (e) {
if (e.which == 27)
closeModalBox();
});
$("body").append(overlay);
var w = content.outerWidth() || 400;
var h = content.outerHeight() || 300;
box.css({ "margin-left": -parseInt(w/2), "margin-top": -parseInt(h/2) });
content.focus();
if (callback)
callback();
}
function closeModalBox() {
$("#modal-overlay").remove();
}