-
Notifications
You must be signed in to change notification settings - Fork 0
/
ok.dialog.js
58 lines (53 loc) · 2.47 KB
/
ok.dialog.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
OkDialog = {
closeAnOpenedDialog: function () {
try {
document.querySelector("input[id^='quit_r']").click();
} catch (e) { }
},
close: function (id) {
OkDialog.removeHandler(document, "keyup", OkDialog.keydown)
var myEl = document.querySelector(id);
myEl.parentNode.removeChild(myEl);
},
generateUniq: function () {
return "r" + Math.random().toString(22).replace(/0./g, '');
},
keydown: function (evt) {
evt = evt || window.event;
if (evt.keyCode == 27) {
OkDialog.closeAnOpenedDialog();
}
},
removeHandler: function (elem, eventType, handler)
{
if (elem.removeEventListener)
elem.removeEventListener(eventType, handler, false);
if (elem.detachEvent)
elem.detachEvent('on' + eventType, handler);
},
open: function (selector, fullsizeobj) {
if (selector != undefined) {
var myElementContent = document.querySelector(selector).innerHTML;
var tempID = this.generateUniq();
var customElStyle = "", position = "";
if (fullsizeobj != undefined) {
fullsizeobj.height = fullsizeobj.height || "auto";
customElStyle = " style='width:" + fullsizeobj.width + "px; height:" + fullsizeobj.height + "px;padding:0;margin:0 auto;padding-top: 20px; margin-top:" + Number(window.pageYOffset + 50) + "px;' ";
position = " style='position:absolute;' ";
}
var gemeratedHTML = '<div id="' + tempID + '" class="SlidingPlanningClass" ' + position + '><div class="stickyPanel" ' + customElStyle + '><div class="closePanelClass">';
gemeratedHTML += '<input type="button" onclick="OkDialog.close(\'#' + tempID + '\')" id="quit_' + tempID + '" class="cancelButtonForSticky"/></div>';
gemeratedHTML += '<div class="topData"></div><div class="bottomData">';
gemeratedHTML += myElementContent;
gemeratedHTML += '</div></div></div>';
document.body.insertBefore(gemeratedHTML.toDOM(), null);
var myElement = document.getElementById(tempID);
myElement.style.display = "block";
document.onkeyup = OkDialog.keydown.bind(this);
try {
myElement.querySelector("input[type='text']").focus();
} catch (err) { }
return tempID;
}
}
};