-
Notifications
You must be signed in to change notification settings - Fork 0
/
prodo-popup.js
182 lines (175 loc) · 6.46 KB
/
prodo-popup.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
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
//Data Storage
var arrowPopupCreated = 'NO';
var arrowPopupoStatus = 0;
var arrowPopupContentHeight = 0;
var arrowPopupContentHeightDouble = 0;
var prodoContent = document.getElementById('prodoContent').innerHTML;
//Popup Templates
var arrowPopupTemplate = '<div id="arrowSlide" class="arrowSlide"><div id="arrowPopup" class="arrowPopup"><div id="popupLeftArrow" class="popupLeftArrow"></div><div id="popupRightArrow" class="popupRightArrow"></div><div id="arrowPopupContent" class="arrowPopupContent"></div></div></div>';
//Create popup from template
function createProdoPopup(prodoPopupType){
if(prodoPopupType == 'ARROW'){
try{
document.getElementById('prodoBase').innerHTML = arrowPopupTemplate;
}
catch(err){}
finally{
document.getElementById('arrowPopupContent').innerHTML = prodoContent;
}
arrowPopupCreated = 'YES';
return;
}
if(prodoPopupType == 'ALERT'){
//Alert Type Popup
}
}
//Cookie Management
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
} else {
expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
//Open Popups
function prodoTimedTrigger(){
if(arrowPopupoStatus == 0 && arrowPopupCreated == 'YES' ){
showPopup();
arrowPopupoStatus++;
}
}function prodoTimed(triggerDelay){
setTimeout(prodoTimedTrigger, triggerDelay*1000);
}
function prodoMouseoutTrigger(container){
addEvent(document, "mouseout", function(e) {
e = e ? e : window.event;
var from = e.relatedTarget || e.toElement;
if (!from || from.nodeName == container) {
if(arrowPopupoStatus == 0 && arrowPopupCreated == 'YES' ){
showPopup();
arrowPopupoStatus++;
}else{
return null;
}
}
});
}
function prodoScrollTrigger(){
window.onscroll = function(ev) {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
if(arrowPopupoStatus == 0 && arrowPopupCreated == 'YES' ){
showPopup();
arrowPopupoStatus++;
}else{
return null;
}
}
};
}
//Close Popups - always manual
function closeProdoPopup(name, lifetime, delay){
setTimeout(closeProdoPopupFinally, delay);
createCookie(name, 'SHOWN', lifetime);
}
function hideProdoPopup(delay){
setTimeout(closeProdoPopupFinally, delay);
}
function closeProdoPopupFinally(){
hidePopup();
}
function prodoPopupInitiate(prodoPopupType){
var name = document.getElementsByTagName('prodo')[0].getAttribute('name');
var onetime = document.getElementsByTagName('prodo')[0].getAttribute('onetime');
var lifetime = document.getElementsByTagName('prodo')[0].getAttribute('lifetime');
var container = document.getElementsByTagName('prodo')[0].getAttribute('triggeringContainer');
var triggerDelay = document.getElementsByTagName('prodo')[0].getAttribute('triggerDelay');
var popUpState = getCookie(name);
if( popUpState == "" && onetime == "YES"){
createCookie(name, 'FRESH', lifetime);
}
else if( popUpState == "SHOWN" && onetime == "YES"){
return null;
}
if(arrowPopupCreated == 'NO'){
createProdoPopup(prodoPopupType);
}
bindTrigger(container, triggerDelay);
}
function bindTrigger(container, triggerDelay){
prodoTimed(triggerDelay);
prodoMouseoutTrigger(container);
prodoScrollTrigger();
}
//---------------------SHOW_popup---------------------------------//
function showPopup(){
arrowPopupContentHeight = $('#arrowPopupContent').height();
arrowPopupContentHeightDouble = arrowPopupContentHeight + arrowPopupContentHeight;
document.getElementById('prodoBase').style.zIndex = '9999999';
document.getElementById('prodoBase').style.visibility = 'visible';
document.getElementById('popupLeftArrow').style.height = arrowPopupContentHeightDouble + 'px';
document.getElementById('popupRightArrow').style.height = arrowPopupContentHeightDouble + 'px';
setTimeout(showPopupStag1, 9);
setTimeout(showPopupStag4, 400);
}
function showPopupStag1(){
document.getElementById('prodoBase').className = "prodoBase stable";
document.getElementById('arrowSlide').className = "arrowSlide stable";
setTimeout(showPopupStag2, 10);
}
function showPopupStag2(){
document.getElementById('blurFilter').className = "blurFilter poped";
setTimeout(showPopupStag3, 300);
}
function showPopupStag3(){
document.getElementById('popupLeftArrow').className = "popupLeftArrow stable";
document.getElementById('popupRightArrow').className = "popupRightArrow stable";
document.getElementById('popupLeftArrow').style.height = arrowPopupContentHeight + 'px';
document.getElementById('popupRightArrow').style.height = arrowPopupContentHeight + 'px';
}
function showPopupStag4(){
document.getElementById('arrowPopupContent').className = "arrowPopupContent stable";
alertSound.playclip();
}
//---------------------HIDE_popup---------------------------------//
function hidePopup(){
document.getElementById('arrowPopupContent').className = "arrowPopupContent";
setTimeout(hidePopupStage1, 400);
}
function hidePopupStage1(){
document.getElementById('popupLeftArrow').className = "popupLeftArrow arrowFade";
document.getElementById('popupRightArrow').className = "popupRightArrow arrowFade";
document.getElementById('popupLeftArrow').style.height = arrowPopupContentHeightDouble + 'px';
document.getElementById('popupRightArrow').style.height = arrowPopupContentHeightDouble + 'px';
setTimeout(hidePopupStage2, 150);
}
function hidePopupStage2(){
document.getElementById('arrowSlide').className = "arrowSlide gone";
setTimeout(hidePopupStage3, 150);
}
function hidePopupStage3(){
document.getElementById('prodoBase').className = "prodoBase";
document.getElementById('blurFilter').className = "blurFilter";
setTimeout(hidePopupStage4, 200);
}
function hidePopupStage4(){
document.getElementById('prodoBase').style.visibility = 'hidden';
document.getElementById('prodoBase').style.zIndex = '-9';
}