-
Notifications
You must be signed in to change notification settings - Fork 1
/
learn.html
209 lines (175 loc) · 5.24 KB
/
learn.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html>
<head>
<title>Popup/Modal Library Cookie Example</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="popup.css">
<style>
/* Custom styles for all popups including the `basic` example */
body.interstitial .popup > .content {
border: 1px solid #e8e8e8;
background-color: #fdfdfe;
}
body.interstitial .popup > .content h1 {
color: #009fdf;
}
body.interstitial .popup > .content p {
color: #4e4e4e;
}
body.interstitial .popup > .content li {
margin-bottom: 10px;
}
@media only screen and (max-width: 767px) {
body.interstitial .popup > .content {
width: 90vw;
padding: 4.6875vw;
margin: 15vh auto;
box-sizing: border-box;
}
body.interstitial .popup > .content h1 {
font-size: 7.5vw;
line-height: 9.375vw;
margin-bottom: 4.6875vw;
}
body.interstitial .popup > .content p {
font-size: 5vw;
line-height: 6.5625vw;
margin-bottom: 3.125vw;
}
body.interstitial .popup > .content .close {
font-size: 7.5vw;
padding: 0 1.5625vw;
}
}
@media only screen and (min-width: 768px) {
body.interstitial .popup > .content {
width: 45vw;
padding: 2.3333vw;
margin: 15vh 0;
}
body.interstitial .popup > .content > h1 {
margin-bottom: 1.04166667vw;
}
body.interstitial .popup > .content > p {
font-size: 1.11111111vw;
line-height: 1.38888889vw;
margin-bottom: 0.69444444vw;
}
body.interstitial .popup > .content .close {
font-size: 2.08333333vw;
line-height: 2.08333333vw;
}
}
/* Demo page styles */
body {
font-family: Verdana, Geneva, Tahoma, sans-serif;
margin: 0;
}
header {
background-color: dodgerblue;
border-bottom: 1px solid #cccccc;
padding: 20px;
}
header > h1 {
font-size: 18px;
font-weight: normal;
color: white;
text-align: center;
margin: 0;
}
a {
cursor: pointer;
color: blue;
text-decoration: underline;
}
p {
max-width: 800px;
}
code {
padding: 2px 4px;
color: #bd4147;
background-color: #f7f7f9;
border-radius: 3px;
}
main {
padding: 30px;
}
</style>
</head>
<body>
<header>
<h1>a Popup Library for designers & developers</h1>
</header>
<main>
<h1>Learn more about the Cookie Popup Example</h1>
<p><a href="/popupjs">Go back</a></p>
<p>This library isn't doing anything special to make a popup open based on a cookie's value. However, this library does allow you to write your own logic to open/close popups however you would like.</p>
<p>Please take a look at the <code>source</code> to see how this works.</p>
<p>Note: if this page is loaded and the <code>learn</code> cookie has a value not equal to <code>true</code>, the popup would be shown on this page. A click on "yes" would set the proper cookie to prevent this popup from opening on future refreshes. A click on "no" would return the visitor to <code>/</code>.</p>
</main>
<!-- cookie -->
<div class="popup cookie">
<div class="content">
<p>The following page is for those who want to learn about how to read/write cookies using this popup library.</p>
<p>Would you like to learn more?</p>
<a>Yes</a>
<a>No</a>
</div>
</div>
<script src="popup.js"></script>
<script>
/* cookie */
(function() {
var popup = window.popup.register("cookie", {
triggers: [],
preventCloseOnOutsideClick: true
});
var triggers = document.querySelectorAll('[href="learn.html"]');
triggers.forEach(trigger => {
trigger.addEventListener("click", event => {
if (!getCookie("learn")) {
event.preventDefault();
event.stopPropagation();
window.popup.open(popup);
}
});
});
var buttons = {
learn: document.querySelector(".popup.cookie a:first-of-type"),
general: document.querySelector(".popup.cookie a:last-of-type")
};
var urls = {
general: "/popupjs",
learn: "/popupjs/learn.html"
};
if (window.location.pathname.indexOf(urls.learn) !== -1 && !getCookie("learn")) {
window.popup.open(popup);
}
buttons.general.addEventListener("click", function(event) {
if (window.location.pathname.indexOf(urls.learn) !== -1) {
window.location.href = urls.general;
}
window.popup.close(popup);
});
buttons.learn.addEventListener("click", function(event) {
document.cookie = "learn=true;path=/";
if (window.location.pathname.indexOf(urls.learn) === -1) {
window.location.href = urls.learn;
}
window.popup.close(popup);
});
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2)
return parts
.pop()
.split(";")
.shift();
}
})();
</script>
</body>
</html>