forked from kylepaulsen/NanoModal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
186 lines (173 loc) · 6.53 KB
/
index.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
<head>
<title>NanoModal Example Page</title>
<style>
.redText {
color: red;
}
.nanoModal.nanoModalOverride, .nanoModalOverlay.nanoModalOverride {
opacity: 0;
-webkit-transition: opacity 0.5s ease;
-moz-transition: opacity 0.5s ease;
-o-transition: opacity 0.5s ease;
transition: opacity 0.5s ease;
}
</style>
</head>
<body>
<button onclick="openModal1()">Open Modal 1</button>
<button onclick="openModal2()">Open Modal 2</button>
<button onclick="openModal3()">Open Modal 3</button>
<button onclick="openModal4()">Open Modal 4</button>
<div id="hiddenModals" style="display: none;">
<div id="modal3">
<h3>This is the ULTIMATE modal!</h3>
<p>This is some info about this modal</p>
<br>
Enter your name: <input id="name" type="text">
</div>
</div>
<script type="text/javascript" src="nanomodal.js"></script>
<script type="text/javascript">
nanoModal.customShow = function(defaultShow, modalAPI) {
defaultShow();
modalAPI.overlay.el.style.opacity = 0.5;
modalAPI.modal.el.style.opacity = 1;
};
nanoModal.customHide = function(defaultHide, modalAPI) {
modalAPI.overlay.el.style.opacity = 0;
// this is only needed if you have modals that open other modals on the onHide event.
modalAPI.modal.onHideEvent.fire();
modalAPI.modal.el.style.opacity = 0;
if (document.body.style.transition !== undefined) {
setTimeout(defaultHide, 500);
} else {
defaultHide();
}
};
var modal1 = nanoModal("Test Content");
var numShown = 0;
var modal2 = nanoModal("", {
buttons: []
}).onShow(function(modal) {
modal.setContent("Click outside the modal to close or press escape.<br>" +
"This Modal has been shown " + (++numShown) + " times.");
});
var modal3 = nanoModal("This is super test content.", {
overlayClose: false,
buttons: [{
text: "OK",
handler: "hide",
primary: true
}, {
text: "Cancel",
handler: function(modal) {
modal.hide();
nanoModal("Can't Cancel!!! >:(", {
autoRemove: true,
classes: "redText", buttons: [{
text: "Close",
handler: function(modalObj) {
modalObj.hide();
modal3.show();
},
primary: true
}]
}).show();
},
classes: "whatever"
}]
});
var modal4 = nanoModal(document.getElementById("modal3"), {
overlayClose: false,
buttons: [{
text: "WHOA DUDE!",
handler: function() {
var name = document.getElementById("name").value;
modal4.hide();
if (name.length < 1) {
nanoModal("NO! Enter your name NOW!", {autoRemove: true}).show().onHide(modal4.show);
} else {
nanoModal("Well hello there, " + name, {autoRemove: true}).show();
}
},
primary: true
}]
});
function openModal1() {
modal1.show();
}
function openModal2() {
modal2.show();
}
function openModal3() {
modal3.show();
}
function openModal4() {
modal4.show();
}
var memTestModal1 = nanoModal("HELLO!!!");
function memLeakTest1() {
var iter = 0;
var loop = function() {
if (iter % 2 === 0) {
memTestModal1.show();
} else {
memTestModal1.hide();
}
++iter;
setTimeout(loop, 10);
};
loop();
}
//memLeakTest1();
function memLeakTest2() {
var iter = 0;
var loop = function() {
if (iter % 2 === 0) {
memTestModal1 = nanoModal("Hello!! " + iter);
} else {
memTestModal1.remove();
}
++iter;
setTimeout(loop, 10);
};
loop();
}
//memLeakTest2();
function memLeakTest3() {
var iter = 0;
var div = document.createElement("div");
var b = document.createElement("b");
b.innerHTML = "Mem Test 3!!!";
div.appendChild(b);
document.body.appendChild(div);
var loop = function() {
if (iter % 2 === 0) {
memTestModal1 = nanoModal(div, {
buttons: [{
text: "OK",
handler: "hide",
primary: true
}, {
text: "Cancel",
handler: function() {
console.log("ASDFSAFD");
}
}]
});
memTestModal1.show();
} else {
memTestModal1.remove();
}
++iter;
setTimeout(loop, 10);
};
loop();
}
//memLeakTest3();
</script>
<div style="width: 200px; height: 3000px; border: 1px solid #000"></div>
</body>
</html>