forked from bogenpirat/remote-torrent-adder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal.js
46 lines (40 loc) · 1.42 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
// Original JavaScript code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
var rta_modal_init = function() {
var openModal = function()
{
var modalWrapper = document.getElementById("rta_modal_wrapper");
var modalWindow = document.getElementById("rta_modal_window");
modalWrapper.className = "overlay_rta";
var overflow = modalWindow.offsetHeight - document.documentElement.clientHeight;
if(overflow > 0) {
modalWindow.style.maxHeight = (parseInt(window.getComputedStyle(modalWindow).height) - overflow) + "px";
}
modalWindow.style.marginTop = (-modalWindow.offsetHeight)/2 + "px";
modalWindow.style.marginLeft = (-modalWindow.offsetWidth)/2 + "px";
};
var closeModal = function()
{
var modalWrapper = document.getElementById("rta_modal_wrapper");
if(modalWrapper) {
modalWrapper.remove();
}
};
var clickHandler = function(e) {
if(!e.target) e.target = e.srcElement;
if(e.target.tagName == "DIV") {
if(e.target.id != "rta_modal_window") closeModal(e);
}
};
var keyHandler = function(e) {
if(e.keyCode == 27) closeModal(e);
};
if(document.addEventListener) {
document.addEventListener("click", clickHandler, false);
document.addEventListener("keydown", keyHandler, false);
} else {
document.attachEvent("onclick", clickHandler);
document.attachEvent("onkeydown", keyHandler);
}
return [openModal, closeModal];
};