PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 1.6.9.1
JetBackup – Backup, Restore & Migrate v1.6.9.1
3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / public / js / popup.js
backup / public / js Last commit date
Chart.bundle.min.js 8 years ago bootstrap-switch.min.js 10 years ago bootstrap.min.js 5 years ago deactivationSurvey.js 5 years ago jquery-ui.js 9 years ago jquery.fileupload.js 8 years ago jquery.iframe-transport.js 8 years ago jquery.rateyo.js 6 years ago jquery.validate.min.js 5 years ago jstree.checkbox.js 8 years ago jstree.min.js 8 years ago jstree.types.js 8 years ago jstree.wholerow.js 8 years ago less.min.js 10 years ago main.js 4 years ago popup.js 5 years ago sgNoticeDismiss.js 6 years ago sgbackup.js 3 years ago sgcloud.js 3 years ago sglicense.js 6 years ago sglogin.js 6 years ago sgrequesthandler.js 10 years ago sgrequesthandler.wordpress.js 10 years ago sgschedule.js 3 years ago sgsettings.js 3 years ago
popup.js
1532 lines
1 function PopupConfig() {
2 this.prefix = 'sgpb';
3 this.popupId;
4 this.popupData;
5 this.openDelay = 0;
6 this.currentObj = {};
7 this.allowed = true;
8 this.showButton = true;
9 this.buttonPosition = 'topRight';
10 this.buttonInside = true;
11 this.autoclose = false;
12 this.overlayShouldClose = true;
13 this.contentShouldClose = false;
14 this.escShouldClose = true;
15 this.closeButtonImage = 'img/close.png';
16 this.popupTheme = 1;
17 this.popupType = 'html';
18 this.closeButtonWidth = 21;
19 this.closeButtonHeight = 21;
20 this.closeButtonWidthType = 'px';
21 this.closeButtonHeightType = 'px';
22 this.closeButtonType = 'IMG';
23 this.closeButtonText = 'Close';
24 this.closeButtonDelay = 0;
25 this.overlayVisible = true;
26 this.overlayColor = 'black';
27 this.overlayOpacity = 80;
28 this.overlayAddClass = 'sgpb-popup-overlay sg-popup-overlay';
29 this.contentPadding = 8;
30 this.zIndex = 9999;
31 this.contentShowBackground = true;
32 this.contentBackgroundColor = '#ffffff';
33 this.contentBackgroundImage = '';
34 this.contentBackgroundMode = 'none';
35 this.contentBackgroundPosition = '';
36 this.contentBorderStyle = 'solid';
37 this.contentBorderRadius = 0;
38 this.contentBorderRadiusType = '%';
39 this.contentBorderColor = '#f00';
40 this.contentBorderWidth = 0;
41 this.boxBorderWidth = 0;
42 this.contentShadowColor = '#ccc';
43 this.contentShadowBlur = 0;
44 this.scrollingEnabled = false;
45 this.shadowSpread = 0;
46 this.contentAddClass = 'class2';
47 this.contents = false;
48 this.positionRight = false;
49 this.positionTop = false;
50 this.positionBottom = false;
51 this.positionLeft = false;
52 this.width = '-1';
53 this.height = '-1';
54 this.maxWidth = '-1';
55 this.maxHeight = '-1';
56 this.minWidth = '-1';
57 this.minHeight = '-1';
58 this.srcElement = '';
59 this.openAnimationEffect = '';
60 this.openAnimationSpeed = 0;
61 this.openAnimationStatus = false;
62 this.closeAnimationEffect = '';
63 this.closeAnimationSpeed = 0;
64 this.closeAnimationStatus = false;
65 this.customShouldOpen = false;
66 this.customShouldClose = false;
67 }
68 String.prototype.firstToLowerCase = function() {
69 return this.charAt(0).toLowerCase() + this.slice(1);
70 };
71 String.prototype.firstToUpperCase = function() {
72 return this.charAt(0).toUpperCase() + this.slice(1);
73 };
74 PopupConfig.prototype.magicCall = function(functionName, arrgname) {
75 if (functionName.indexOf('get') != -1) {
76 var param = functionName.replace(/^get/g, "").firstToLowerCase();
77 return this[param];
78 } else {
79 var param = functionName.replace(/^set/g, "").firstToLowerCase();
80 this[param] = arrgname;
81 }
82 };
83 PopupConfig.prototype.addCustomEvent = function(eventName, args) {
84 var event = document.createEvent('CustomEvent');
85 event.initCustomEvent(eventName, true, true, args);
86 window.dispatchEvent(event);
87 };
88 PopupConfig.prototype.combineConfigObj = function() {
89 var that = this;
90 var eventSendArgs = {
91 'popupId': that.popupId,
92 'popupData': that.popupData,
93 'currentObj': that.currentObj
94 };
95 window.sgWindowOldWidth = window.innerWidth;
96 window.sgWindowOldHeight = window.innerHeight;
97 var config = {
98 popupId: that.popupId,
99 openDelay: this.openDelay,
100 popupTheme: this.popupTheme,
101 popupType: this.popupType,
102 closeBehavior: {
103 allowed: this.allowed,
104 showButton: this.showButton,
105 buttonPosition: this.buttonPosition,
106 buttonInside: this.buttonInside,
107 autoclose: this.autoclose,
108 overlayShouldClose: this.overlayShouldClose,
109 contentShouldClose: this.contentShouldClose,
110 escShouldClose: this.escShouldClose,
111 right: this.closeButtonPositionRight,
112 top: this.closeButtonPositionTop,
113 bottom: this.closeButtonPositionBottom,
114 left: this.closeButtonPositionLeft
115 },
116 openAnimation: {
117 type: this.openAnimationEffect,
118 speed: this.openAnimationSpeed,
119 status: this.openAnimationStatus
120 },
121 closeAnimation: {
122 type: this.closeAnimationEffect,
123 speed: this.closeAnimationSpeed,
124 status: this.closeAnimationStatus
125 },
126 closeButton: {
127 data: this.buttonImage,
128 width: this.closeButtonWidth,
129 height: this.closeButtonHeight,
130 widthType: this.closeButtonWidthType,
131 heightType: this.closeButtonHeightType,
132 type: this.closeButtonType,
133 text: this.closeButtonText
134 },
135 overlay: {
136 visible: this.overlayVisible,
137 color: this.overlayColor,
138 opacity: this.overlayOpacity,
139 addClass: this.overlayAddClass
140 },
141 contentBox: {
142 padding: this.contentPadding,
143 zIndex: this.zIndex,
144 showBackground: this.contentShowBackground,
145 backgroundColor: this.contentBackgroundColor,
146 backgroundImage: this.contentBackgroundImage,
147 backgroundMode: this.contentBackgroundMode,
148 backgroundPosition: this.contentBackgroundPosition,
149 borderStyle: this.contentBorderStyle,
150 borderRadius: this.contentBorderRadius,
151 borderRadiusType: this.contentBorderRadiusType,
152 borderColor: this.contentBorderColor,
153 borderWidth: this.contentBorderWidth,
154 boxBorderWidth: this.boxBorderWidth,
155 shadowColor: this.contentShadowColor,
156 shadowBlur: this.contentShadowBlur,
157 scrollingEnabled: this.scrollingEnabled,
158 shadowSpread: this.shadowSpread,
159 addClass: this.contentAddClass
160 },
161 contents: this.contents,
162 inline: this.srcElement,
163 iframe: false,
164 position: {
165 right: this.positionRight,
166 top: this.positionTop,
167 bottom: this.positionBottom,
168 left: this.positionLeft
169 },
170 sizingRanges: [{
171 screenFrom: {
172 width: 0,
173 height: 0
174 },
175 screenTo: {
176 width: 300,
177 height: 3000
178 },
179 width: '100%',
180 height: this.height,
181 maxWidth: this.maxWidth,
182 maxHeight: this.maxHeight,
183 minWidth: this.minWidth,
184 minHeight: this.minHeight
185 }, {
186 screenFrom: {
187 width: 300,
188 height: 0
189 },
190 screenTo: {
191 width: 3000,
192 height: 3000
193 },
194 width: this.width,
195 height: this.height,
196 maxWidth: this.maxWidth,
197 maxHeight: this.maxHeight,
198 minWidth: this.minWidth,
199 minHeight: this.minHeight
200 }],
201 shouldOpen: function() {
202 return true;
203 },
204 willOpen: function() {
205 that.addCustomEvent('sgpbWillOpen', eventSendArgs);
206 },
207 didOpen: function(args) {
208 var finalArgs = Object.assign(args, eventSendArgs);
209 that.addCustomEvent('sgpbDidOpen', finalArgs);
210 },
211 shouldClose: function() {
212 return true;
213 },
214 willClose: function() {
215 that.addCustomEvent('sgpbWillClose', eventSendArgs);
216 },
217 didClose: function() {
218 that.addCustomEvent('sgpbDidClose', eventSendArgs);
219 }
220 };
221 if (this.customShouldOpen) {
222 config.shouldOpen = this.customShouldOpen;
223 }
224 if (this.customShouldClose) {
225 config.shouldClose = this.customShouldClose;
226 }
227 return config;
228 };
229 var obj = new PopupConfig();
230
231 function SGPopup(config) {
232 var integrations = config.integrations;
233 var popupName = config.popupName;
234 var initialConfig = config;
235 var prefix = config.prefix || 'sgpb';
236 var isInited = false;
237 var mainDiv = null;
238 var contentDiv = null;
239 var DIV = null;
240 var opened = false;
241 var resizeTimeout = null;
242 var overlayDiv = null;
243 var defaultZIndex = 9999;
244 var defaultWidth = "640px";
245 var defaultHeight = config.autoHeight;
246 var closeButtonImage = null;
247 var popupId = config.id;
248 var showOnce = config.showOnce || false;
249 var events = config.events || [];
250 var openDelay = config.openDelay || 0;
251 var popupTheme = config.popupTheme;
252 var popupType = config.popupType;
253 var fitBackgroundImg = null;
254 var parentThis = this;
255 var openAnimation = config.openAnimation || {
256 type: "none",
257 speed: 0
258 };
259 var closeAnimation = config.closeAnimation || {
260 type: "none",
261 speed: 0
262 };
263 var closeBehavior = config.closeBehavior || {
264 allowed: true,
265 showButton: true,
266 buttonPosition: 'topLeft',
267 buttonInside: true,
268 autoclose: false,
269 overlayShouldClose: true,
270 contentShouldClose: false,
271 escShouldClose: true
272 };
273 var closeButton = config.closeButton || {
274 data: 'img/close.png',
275 width: 16,
276 height: 16,
277 widthType: 'px',
278 heightType: 'px',
279 closeButtonType: 'IMG',
280 closeButtonText: 'Close'
281 };
282 var overlay = config.overlay || {
283 visible: true,
284 color: "#000",
285 opacity: 0.7
286 };
287 var contentBox = config.contentBox || {
288 padding: 8,
289 showBackground: true,
290 backgroundColor: "#fff",
291 borderStyle: "solid",
292 borderColor: "#ccc",
293 borderRadius: 4,
294 borderRadiusType: 'px',
295 borderWidth: 1,
296 shadowColor: "#ccc",
297 shadowSpread: 0,
298 shadowBlur: 10,
299 scrollingEnabled: true,
300 backgroundPosition: ''
301 };
302 var contents = config.contents || "";
303 var inline = config.inline || false;
304 var href = config.href || false;
305 var position = config.position || {
306 left: "center",
307 top: "center"
308 };
309 if ((typeof position.left == "undefined" || (isNaN(parseInt(position.left)) && position.left != "center")) && (typeof position.right == "undefined" || (isNaN(parseInt(position.right)) && position.right != "center"))) {
310 position.left = "center";
311 }
312 if ((typeof position.top == "undefined" || (isNaN(parseInt(position.top)) && position.top != "center")) && (typeof position.bottom == "undefined" || (isNaN(parseInt(position.bottom)) && position.bottom != "center"))) {
313 position.top = "center";
314 }
315 var sizingRanges = config.sizingRanges || [{
316 screenFrom: {
317 width: -1,
318 height: -1
319 },
320 screenTo: {
321 width: -1,
322 height: -1
323 },
324 width: defaultWidth,
325 height: defaultHeight,
326 maxWidth: -1,
327 maxHeight: -1,
328 minWidth: -1,
329 minHeight: -1
330 }];
331 var shouldOpen = config.shouldOpen || function() {
332 return true;
333 };
334 var willOpen = config.willOpen || function() {};
335 var didOpen = config.didOpen || function() {};
336 var shouldClose = config.shouldClose || function() {
337 return true;
338 };
339 var willClose = config.willClose || function() {};
340 var didClose = config.didClose || function() {};
341 SGPopup.inlinePrevTarget = SGPopup.inlinePrevTarget || {};
342
343 function resetInlineContent() {
344 if (inline) {
345 var htmlElement = document.getElementById(inline);
346 if (SGPopup.inlinePrevTarget.hasPreviousElement) {
347 if (typeof SGPopup.inlinePrevTarget.parentNode != 'undefined') {
348 SGPopup.inlinePrevTarget.parentNode.insertBefore(htmlElement, SGPopup.inlinePrevTarget.node.nextSibling);
349 }
350 } else {
351 SGPopup.inlinePrevTarget.node.appendChild(htmlElement);
352 }
353 }
354 }
355 var OPEN_ANIMATION_POP = "@-webkit-keyframes popin{from{-webkit-transform:scale(.8);opacity:0}to{-webkit-transform:scale(1);opacity:1}}@-moz-keyframes popin{from{-moz-transform:scale(.8);opacity:0}to{-moz-transform:scale(1);opacity:1}}@keyframes popin{from{transform:scale(.8);opacity:0}to{transform:scale(1);opacity:1}}";
356 var OPEN_ANIMATION_FADE = "@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@-moz-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes fadein{from{opacity:0}to{opacity:1}}";
357 var OPEN_ANIMATION_FLIP = "@-webkit-keyframes flipintoright{from{-webkit-transform:rotateY(90deg) scale(.9)}to{-webkit-transform:rotateY(0)}}@-moz-keyframes flipintoright{from{-moz-transform:rotateY(90deg) scale(.9)}to{-moz-transform:rotateY(0)}}@keyframes flipintoright{from{transform:rotateY(90deg) scale(.9)}to{transform:rotateY(0)}}";
358 var OPEN_ANIMATION_SLIDELEFT = "@-webkit-keyframes slideinfromright{from{-webkit-transform:translate3d({start},0,0)}to{-webkit-transform:translate3d(0,0,0)}}@-moz-keyframes slideinfromright{from{-moz-transform:translateX({start})}to{-moz-transform:translateX(0)}}@keyframes slideinfromright{from{transform:translateX({start})}to{transform:translateX(0)}}";
359 var OPEN_ANIMATION_SLIDERIGHT = "@-webkit-keyframes slideinfromleft{from{-webkit-transform:translate3d({start},0,0)}to{-webkit-transform:translate3d(0,0,0)}}@-moz-keyframes slideinfromleft{from{-moz-transform:translateX({start})}to{-moz-transform:translateX(0)}}@keyframes slideinfromleft{from{transform:translateX({start})}to{transform:translateX(0)}}";
360 var OPEN_ANIMATION_FLOW = "@-webkit-keyframes flowinfromright{0%{-webkit-transform:translateX(100%) scale(.7)}30%,40%{-webkit-transform:translateX(0) scale(.7)}100%{-webkit-transform:translateX(0) scale(1)}}@-moz-keyframes flowinfromright{0%{-moz-transform:translateX(100%) scale(.7)}30%,40%{-moz-transform:translateX(0) scale(.7)}100%{-moz-transform:translateX(0) scale(1)}}@keyframes flowinfromright{0%{transform:translateX(100%) scale(.7)}30%,40%{transform:translateX(0) scale(.7)}100%{transform:translateX(0) scale(1)}}";
361 var OPEN_ANIMATION_SLIDEUP = "@-webkit-keyframes slideinfrombottom{from{-webkit-transform:translateY({start})}to{-webkit-transform:translateY(0)}}@-moz-keyframes slideinfrombottom{from{-moz-transform:translateY({start})}to{-moz-transform:translateY(0)}}@keyframes slideinfrombottom{from{transform:translateY({start})}to{transform:translateY(0)}}";
362 var OPEN_ANIMATION_SLIDEDOWN = "@-webkit-keyframes slideinfromtop{from{-webkit-transform:translateY({start})}to{-webkit-transform:translateY(0)}}@-moz-keyframes slideinfromtop{from{-moz-transform:translateY({start})}to{-moz-transform:translateY(0)}}@keyframes slideinfromtop{from{transform:translateY({start})}to{transform:translateY(0)}}";
363 var CLOSE_ANIMATION_SLIDELEFT = "@-webkit-keyframes slideouttoleft{from{-webkit-transform:translate3d(0,0,0)}to{-webkit-transform:translate3d({end},0,0)}}@-moz-keyframes slideouttoleft{from{-moz-transform:translateX(0)}to{-moz-transform:translateX({end})}}@keyframes slideouttoleft{from{transform:translateX(0)}to{transform:translateX({end})}}";
364 var CLOSE_ANIMATION_SLIDERIGHT = "@-webkit-keyframes slideouttoright{from{-webkit-transform:translate3d(0,0,0)}to{-webkit-transform:translate3d({end},0,0)}}@-moz-keyframes slideouttoright{from{-moz-transform:translateX(0)}to{-moz-transform:translateX({end})}}@keyframes slideouttoright{from{transform:translateX(0)}to{transform:translateX({end})}}";
365 var CLOSE_ANIMATION_POP = "@-webkit-keyframes popout{from{-webkit-transform:scale(1);opacity:1}to{-webkit-transform:scale(.8);opacity:0}}@-moz-keyframes popout{from{-moz-transform:scale(1);opacity:1}to{-moz-transform:scale(.8);opacity:0}}@keyframes popout{from{transform:scale(1);opacity:1}to{transform:scale(.8);opacity:0}}";
366 var CLOSE_ANIMATION_FADE = "@-webkit-keyframes fadeout{from{opacity:1}to{opacity:0}}@-moz-keyframes fadeout{from{opacity:1}to{opacity:0}}@keyframes fadeout{from{opacity:1}to{opacity:0}}";
367 var CLOSE_ANIMATION_FLIP = "@-webkit-keyframes flipouttoright{from{-webkit-transform:rotateY(0)}to{-webkit-transform:rotateY(90deg) scale(.9)}}@-moz-keyframes flipouttoright{from{-moz-transform:rotateY(0)}to{-moz-transform:rotateY(90deg) scale(.9)}}@keyframes flipouttoright{from{transform:rotateY(0)}to{transform:rotateY(90deg) scale(.9)}}";
368 var CLOSE_ANIMATION_FLOW = "@-webkit-keyframes flowouttoright{0%{-webkit-transform:translateX(0) scale(1)}60%,70%{-webkit-transform:translateX(0) scale(.7)}100%{-webkit-transform:translateX(100%) scale(.7)}}@-moz-keyframes flowouttoright{0%{-moz-transform:translateX(0) scale(1)}60%,70%{-moz-transform:translateX(0) scale(.7)}100%{-moz-transform:translateX(100%) scale(.7)}}@keyframes flowouttoright{0%{transform:translateX(0) scale(1)}60%,70%{transform:translateX(0) scale(.7)}100%{transform:translateX(100%) scale(.7)}}";
369 var CLOSE_ANIMATION_SLIDEUP = "@-webkit-keyframes slideouttotop{from{-webkit-transform:translateY(0)}to{-webkit-transform:translateY({end})}}@-moz-keyframes slideouttotop{from{-moz-transform:translateY(0)}to{-moz-transform:translateY({end})}}@keyframes slideouttotop{from{transform:translateY(0)}to{transform:translateY({end})}}";
370 var CLOSE_ANIMATION_SLIDEDOWN = "@-webkit-keyframes slideouttobottom{from{-webkit-transform:translateY(0)}to{-webkit-transform:translateY({end})}}@-moz-keyframes slideouttobottom{from{-moz-transform:translateY(0)}to{-moz-transform:translateY({end})}}@keyframes slideouttobottom{from{transform:translateY(0)}to{transform:translateY({end})}}";
371
372 function addAnimationClass(classString) {
373 var style = document.createElement('style');
374 style.type = 'text/css';
375 style.innerHTML = classString;
376 style.id = prefix + "-effect-custom-style";
377 document.getElementsByTagName('head')[0].appendChild(style);
378 }
379
380 function setMainDivStyles(sizeConfig) {
381 jQuery(window).trigger('sgpbPopupBuilderAdditionalDimensionSettings');
382 contentDiv.style.zIndex = defaultZIndex + 10;
383 mainDiv.style.boxSizing = 'content-box';
384 if (sizeConfig.minHeight != -1) {
385 var minHeight = sizeConfig.minHeight;
386 var popupMinHeight = window.innerHeight;
387 if (typeof minHeight == 'string' && minHeight.indexOf('%') != -1) {
388 var popupMinhHeight = (popupMinhHeight / 100) * parseInt(minHeight);
389 mainDiv.style.minHeight = popupMinhHeight + 'px';
390 } else {
391 mainDiv.style.minHeight = parseInt(minHeight) + 'px';
392 }
393 }
394 if (sizeConfig.minWidth != -1) {
395 var popupMinhWidth = window.innerWidth;
396 var minWidth = sizeConfig.minWidth;
397 if (typeof minWidth == 'string' && minWidth.indexOf('%') != -1) {
398 var popupMinhWidth = (popupMinhWidth / 100) * parseInt(minWidth);
399 mainDiv.style.minWidth = popupMinhWidth + 'px';
400 } else {
401 mainDiv.style.minWidth = parseInt(minWidth) + 'px';
402 }
403 }
404 if (sizeConfig.maxHeight != -1 && sizeConfig.maxHeight) {
405 var maxHeight = sizeConfig.maxHeight;
406 var popupMaxHeight = window.innerHeight;
407 if (maxHeight.indexOf('%') != -1) {
408 var popupMaxHeight = (popupMaxHeight / 100) * parseInt(maxHeight);
409 this.calculatedMaxHeight = calculateMaxHeight(popupMaxHeight);
410 mainDiv.style.maxHeight = this.calculatedMaxHeight;
411 } else {
412 this.calculatedMaxHeight = calculateMaxHeight(parseInt(maxHeight));
413 mainDiv.style.maxHeight = this.calculatedMaxHeight;
414 }
415 } else {
416 var popupMaxHeight = window.innerHeight;
417 mainDiv.style.maxHeight = calculateMaxHeight(popupMaxHeight);
418 }
419 if (sizeConfig.maxWidth != -1 && sizeConfig.maxWidth) {
420 var maxWidth = sizeConfig.maxWidth;
421 var popupMaxWidth = window.innerWidth;
422 if (maxWidth.indexOf('%') != -1) {
423 var popupMaxWidth = (popupMaxWidth / 100) * parseInt(maxWidth);
424 this.calculatedMaxWidth = calculateMaxWidth(popupMaxWidth);
425 mainDiv.style.maxWidth = this.calculatedMaxWidth;
426 } else {
427 this.calculatedMaxWidth = calculateMaxWidth(parseInt(maxWidth));
428 mainDiv.style.maxWidth = this.calculatedMaxWidth;
429 }
430 } else {
431 var popupMaxWidth = window.innerWidth;
432 mainDiv.style.maxWidth = calculateMaxWidth(popupMaxWidth);
433 }
434 if (contentBox.borderStyle) {
435 mainDiv.style.borderStyle = contentBox.borderStyle;
436 }
437 if (contentBox.borderColor) {
438 mainDiv.style.borderColor = contentBox.borderColor;
439 }
440 if (contentBox.borderRadius) {
441 var borderRadiusMeasure = '%';
442 if (contentBox.borderRadiusType) {
443 var borderRadiusMeasure = contentBox.borderRadiusType;
444 }
445 mainDiv.style.borderRadius = contentBox.borderRadius + borderRadiusMeasure;
446 }
447 mainDiv.style.borderWidth = contentBox.borderWidth + "px";
448 if (contentBox.padding) {
449 mainDiv.style.padding = contentBox.padding + "px";
450 }
451 var widthToSet = sizeConfig.width || defaultWidth;
452 if (widthToSet.indexOf("%") > -1) {
453 var widthNum = parseFloat(widthToSet);
454 if (widthToSet.indexOf("fullScreen") > -1) {
455 widthNum = window.innerWidth;
456 }
457 var closeButtonWidthToSubtract = parseInt(closeButton.width);
458 if (closeBehavior.showButton == false || config.closeButton.type == 'button') {
459 closeButtonWidthToSubtract = 0;
460 }
461 widthToSet = (((widthNum / 100) * window.innerWidth) - (2 * (contentBox.padding ? contentBox.padding : 0)) - parseFloat(mainDiv.style.borderLeftWidth) - parseFloat(mainDiv.style.borderRightWidth) - (parseFloat(contentBox.shadowSpread) / 2) - closeButtonWidthToSubtract) + 'px';
462 } else {
463 widthToSet = parseFloat(widthToSet) - 2 * (contentBox.padding ? contentBox.padding : 0) + 'px';
464 }
465 mainDiv.style.width = widthToSet;
466 if (config.popupType == 'image') {
467 mainDiv.style.backgroundImage = "url(" + contentBox.backgroundImage + ")";
468 }
469 if (contentBox.showBackground) {
470 if (contentBox.backgroundImage) {
471 mainDiv.style.backgroundImage = "url(" + contentBox.backgroundImage + ")";
472 }
473 if (contentBox.backgroundMode == "cover") {
474 mainDiv.style.backgroundSize = "cover";
475 mainDiv.style.backgroundRepeat = "no-repeat";
476 } else if (contentBox.backgroundMode == "contain") {
477 mainDiv.style.backgroundSize = "contain";
478 mainDiv.style.backgroundRepeat = "no-repeat";
479 } else if (contentBox.backgroundMode == "repeat") {
480 mainDiv.style.backgroundRepeat = "repeat";
481 } else if (contentBox.backgroundMode == 'fit') {
482 if (!fitBackgroundImg) {
483 fitBackgroundImg = document.createElement('img');
484 fitBackgroundImg.style.position = 'fixed';
485 fitBackgroundImg.style.bottom = '-9999999999999px';
486 fitBackgroundImg.className = 'sgpb-background-image-' + config.popupId;
487 document.body.appendChild(fitBackgroundImg);
488 fitBackgroundImg.onload = function() {
489 changePopupDimensionRelatedImage(this);
490 };
491 fitBackgroundImg.src = contentBox.backgroundImage;
492 mainDiv.style.backgroundSize = '100% 100%';
493 mainDiv.style.backgroundRepeat = 'no-repeat';
494 }
495 } else {
496 mainDiv.style.backgroundRepeat = "no-repeat";
497 }
498 }
499 if (window.sgWindowOldWidth != window.innerWidth || window.sgWindowOldHeight != window.innerHeight) {
500 window.sgWindowOldWidth = window.innerWidth;
501 window.sgWindowOldHeight = window.innerHeight;
502 var images = document.getElementsByClassName('sgpb-background-image-' + config.popupId);
503 if (images.length) {
504 changePopupDimensionRelatedImage(images[0]);
505 }
506 }
507 mainDiv.style.backgroundPosition = contentBox.backgroundPosition;
508 var heightToSet = sizeConfig.height || defaultHeight;
509 if (typeof heightToSet != 'undefined' && heightToSet.indexOf("%") > -1) {
510 var heightNum = parseFloat(heightToSet);
511 heightToSet = (((heightNum / 100) * window.innerHeight) - (2 * (contentBox.padding ? contentBox.padding : 0)) - parseInt(mainDiv.style.borderTopWidth) - parseInt(mainDiv.style.borderBottomWidth)) + "px";
512 } else {
513 heightToSet = parseInt(heightToSet) - 2 * (contentBox.padding ? contentBox.padding : 0) + "px";
514 if (sizeConfig.width.indexOf("fullScreen") > -1) {
515 heightToSet = (window.innerHeight) + "px";
516 }
517 }
518 mainDiv.style.height = heightToSet;
519 if (contentBox.showBackground && contentBox.backgroundColor) {
520 mainDiv.style.backgroundColor = contentBox.backgroundColor;
521 }
522 if (contentBox.shadowColor) {
523 mainDiv.style.boxShadow = "0 0 " + contentBox.shadowBlur + "px " + contentBox.shadowSpread + "px " + contentBox.shadowColor;
524 }
525 if (contentBox.scrollingEnabled) {
526 mainDiv.style.overflow = "auto";
527 } else {
528 mainDiv.style.overflow = "hidden";
529 }
530 }
531
532 function changePopupDimensionRelatedImage(image) {
533 var result = resizeConfig(image);
534 var oldSizeConfig = getSizeConfig();
535 oldSizeConfig.width = result.width + 'px';
536 oldSizeConfig.height = result.height + 'px';
537 oldSizeConfig.modified = true;
538 this.sizeConfig = oldSizeConfig;
539 windowResizeHandler();
540 }
541
542 function resizeConfig(backgroundImage) {
543 var maxWidth = parseInt(this.calculatedMaxWidth);
544 var maxHeight = parseInt(this.calculatedMaxHeight);
545 var imageWidth = backgroundImage.width;
546 var imageHeight = backgroundImage.height;
547 var windowMaxHeight = parseInt(calculateMaxHeight(window.innerHeight));
548 var windowMaxWidth = parseInt(calculateMaxWidth(window.innerWidth));
549 if (isNaN(maxHeight) || maxHeight > windowMaxHeight) {
550 maxHeight = windowMaxHeight;
551 }
552 if (isNaN(maxWidth) || maxWidth > windowMaxWidth) {
553 maxWidth = windowMaxWidth;
554 }
555 var widthDifference = imageWidth - maxWidth;
556 var heightDifference = imageHeight - maxHeight;
557 if (heightDifference > widthDifference) {
558 if (imageHeight > maxHeight) {
559 var modifiedHeightPercent = 100 - (maxHeight / imageHeight) * 100;
560 var withMustDecrease = (imageWidth * modifiedHeightPercent) / 100;
561 var modifiedWidth = imageWidth - withMustDecrease;
562 imageWidth = modifiedWidth;
563 imageHeight = maxHeight;
564 }
565 } else if (imageWidth > maxWidth) {
566 var modifiedWidthPercent = Math.floor((widthDifference / imageWidth) * 100);
567 var heightMustDecrease = Math.floor((imageHeight * modifiedWidthPercent) / 100);
568 var modifiedHeight = imageHeight - heightMustDecrease;
569 imageWidth -= widthDifference;
570 imageHeight -= heightMustDecrease;
571 }
572 var result = {
573 width: imageWidth,
574 height: imageHeight
575 };
576 return result;
577 }
578
579 function calculateMaxWidth(maxWidth) {
580 var sizeConfig = getSizeConfig();
581 var dimension = sizeConfig.width;
582 var contentPadding = (contentBox.padding || 0) * 2;
583 var shadowSpread = (contentBox.shadowSpread || 0) * 2;
584 var borderWidth = (contentBox.borderWidth || 0) * 2;
585 var boxBorderWidth = (contentBox.boxBorderWidth || 0) * 4;
586 var closeButtonRight = (parseInt(closeBehavior.right) || 0) * 2;
587 var closeButtonLeft = (parseInt(closeBehavior.left) || 0) * 2;
588 if (dimension.indexOf('fullScreen') == '-1') {
589 maxWidth -= contentPadding;
590 maxWidth -= 34;
591 maxWidth -= shadowSpread;
592 maxWidth -= borderWidth;
593 maxWidth -= boxBorderWidth;
594 }
595 if (!closeBehavior.buttonInside) {
596 if (closeButtonRight) {
597 maxWidth -= Math.abs(closeButtonRight);
598 }
599 if (closeButtonLeft) {
600 maxWidth -= Math.abs(closeButtonLeft);
601 }
602 }
603 if (maxWidth < 0) {
604 return '30px';
605 }
606 return maxWidth + 'px';
607 }
608
609 function setFitBackground() {
610 if (!fitBackgroundImg) return;
611 var imgHeight = fitBackgroundImg.height;
612 var imgWidth = fitBackgroundImg.width;
613 var winHeight = window.innerHeight;
614 var winWidth = window.innerWidth;
615 var minMargin = 40;
616 var popupWidth = 0,
617 popupHeight = 0;
618 if (imgWidth < (winWidth - 2 * minMargin) && imgHeight < (winHeight - 2 * minMargin)) {
619 popupWidth = imgWidth;
620 popupHeight = imgHeight;
621 } else {
622 var widthDif = winWidth - imgWidth;
623 var heightDif = winHeight - imgHeight;
624 if (widthDif < heightDif) {
625 popupWidth = winWidth - 2 * minMargin;
626 popupHeight = popupWidth * imgHeight / imgWidth;
627 } else {
628 popupHeight = winHeight - 2 * minMargin;
629 popupWidth = popupHeight * imgWidth / imgHeight;
630 }
631 }
632 var sizeConfig = getSizeConfig();
633 var maxWidth = sizeConfig.maxWidth;
634 var maxHeight = sizeConfig.maxHeight;
635 var border = contentBox.borderWidth || 0;
636 var padding = contentBox.padding || 0;
637 var shadow = contentBox.shadowSpread || 0;
638 popupWidth = parseInt(popupWidth - 2);
639 sizeConfig.height = popupHeight + 'px';
640 }
641
642 function calculateMaxHeight(maxHeight) {
643 var sizeConfig = getSizeConfig();
644 var dimension = sizeConfig.width;
645 var contentPadding = (contentBox.padding || 0) * 2;
646 var shadowSpread = (contentBox.shadowSpread || 0) * 4;
647 var borderHeight = (contentBox.borderWidth || 0) * 2;
648 var boxBorderHeight = (contentBox.boxBorderWidth || 0) * 4;
649 var closeButtonTop = (parseInt(closeBehavior.top) || 0) * 2;
650 var closeButtonBottom = (parseInt(closeBehavior.bottom) || 0) * 2;
651 if (dimension.indexOf('fullScreen') != '-1') {} else {
652 maxHeight -= contentPadding;
653 if (shadowSpread) {
654 maxHeight -= shadowSpread;
655 maxHeight -= 35;
656 }
657 maxHeight -= borderHeight;
658 maxHeight -= boxBorderHeight;
659 if (!closeBehavior.buttonInside) {
660 if (closeButtonBottom) {
661 maxHeight -= Math.abs(closeButtonBottom);
662 }
663 if (closeButtonTop) {
664 maxHeight -= Math.abs(closeButtonTop);
665 }
666 }
667 }
668 if (maxHeight < 0) {
669 return '30px';
670 }
671 return maxHeight + 'px';
672 }
673
674 function positionPopup() {
675 contentDiv.style.position = "fixed";
676 var border = contentBox.borderWidth || 0;
677 var padding = contentBox.padding || 0;
678 if (typeof position.left != "undefined" && (!isNaN(parseInt(position.left)) || position.left == "center")) {
679 if (position.left == "center") {
680 contentDiv.style.left = (window.innerWidth - parseInt(mainDiv.clientWidth) - 2 * border) / 2 + "px";
681 } else {
682 contentDiv.style.left = parseInt(position.left) + "px";
683 }
684 } else {
685 if (position.right == "center") {
686 contentDiv.style.left = (window.innerWidth - parseInt(mainDiv.clientWidth) - 2 * border) / 2 + "px";
687 } else {
688 contentDiv.style.left = (window.innerWidth - parseInt(position.right) - parseInt(mainDiv.clientWidth) - 2 * border) + "px";
689 }
690 }
691 if (typeof position.top != "undefined" && (!isNaN(parseInt(position.top)) || position.top == "center")) {
692 if (position.top == "center") {
693 contentDiv.style.top = (window.innerHeight - parseInt(mainDiv.clientHeight) - 2 * border) / 2 + "px";
694 } else {
695 contentDiv.style.top = position.top + "px";
696 }
697 } else {
698 if (position.bottom == "center") {
699 contentDiv.style.top = (window.innerHeight - parseInt(mainDiv.clientHeight) - 2 * border) / 2 + "px";
700 } else {
701 contentDiv.style.bottom = position.bottom + "px";
702 }
703 }
704 }
705
706 function getSizeConfig() {
707 var windowWidth = window.innerWidth;
708 var windowHeight = window.innerHeight;
709 var config = null;
710 var candidates = [];
711 for (var i = 0; i < sizingRanges.length; i++) {
712 var tmpConf = sizingRanges[i];
713 if ((tmpConf.screenFrom.width == -1 && tmpConf.screenTo.width == -1) || (tmpConf.screenFrom.width == -1 && windowWidth < tmpConf.screenTo.width) || (tmpConf.screenTo.width == -1 && windowWidth > tmpConf.screenFrom.width) || (windowWidth < tmpConf.screenTo.width && windowWidth > tmpConf.screenFrom.width)) {
714 candidates.push(tmpConf);
715 }
716 }
717 for (var i = 0; i < candidates.length; i++) {
718 var tmpConf = candidates[i];
719 if ((tmpConf.screenFrom.height == -1 && tmpConf.screenTo.height == -1) || (tmpConf.screenFrom.height == -1 && windowHeight < tmpConf.screenTo.height) || (tmpConf.screenTo.height == -1 && windowHeight > tmpConf.screenFrom.height) || (windowHeight < tmpConf.screenTo.height && windowHeight > tmpConf.screenFrom.height)) {
720 continue;
721 } else {
722 candidates.splice(i, 1);
723 i--;
724 }
725 }
726 config = candidates[0];
727 if (!config) {
728 config = {
729 screenFrom: {
730 width: -1,
731 height: -1
732 },
733 screenTo: {
734 width: -1,
735 height: -1
736 },
737 width: "640px",
738 height: defaultHeight,
739 maxWidth: -1,
740 maxHeight: -1,
741 minWidth: -1,
742 minHeight: -1
743 }
744 }
745 return config;
746 }
747
748 function drawOverlay() {
749 if (!overlay.visible) {
750 return;
751 }
752 overlayDiv = document.createElement("DIV");
753 overlayDiv.style.zIndex = defaultZIndex;
754 overlayDiv.style.backgroundColor = overlay.color;
755 overlayDiv.style.opacity = overlay.opacity / 100;
756 overlayDiv.style.position = "fixed";
757 overlayDiv.style.left = "0";
758 overlayDiv.style.top = "0";
759 overlayDiv.style.width = "100%";
760 overlayDiv.style.height = "100%";
761 if (overlay.addClass) {
762 overlayDiv.className = overlay.addClass;
763 }
764 if (closeBehavior.overlayShouldClose) {
765 overlayDiv.onclick = closePopup;
766 }
767 document.body.appendChild(overlayDiv);
768 }
769
770 function removeOverlay() {
771 if (overlayDiv) {
772 overlayDiv.style.display = "none";
773 document.body.removeChild(overlayDiv);
774 overlayDiv = null;
775 }
776 }
777
778 function setCloseButton(mainDiv) {
779 if (!closeButton.data) {
780 return;
781 }
782 if (closeBehavior.showButton === false) {
783 return;
784 }
785 closeButtonImage.style.zIndex = defaultZIndex + 20;
786 closeButtonImage.style.position = "absolute";
787 closeButtonImage.style.float = "left";
788 closeButtonImage.style.top = closeBehavior.top;
789 closeButtonImage.style.right = closeBehavior.right;
790 closeButtonImage.style.bottom = closeBehavior.bottom;
791 closeButtonImage.style.left = closeBehavior.left;
792 if (closeButton.type == 'button') {
793 closeButtonImage.id = prefix + '-close-button';
794 closeButtonImage.innerHTML = config.closeButton.text;
795 }
796 closeButtonImage.style.width = closeButton.width + closeButton.widthType;
797 closeButtonImage.style.cursor = "pointer";
798 closeButtonImage.style.height = closeButton.height + closeButton.heightType;
799 closeButtonImage.src = closeButton.data;
800 closeButtonImage.style.backgroundRepeat = "no-repeat";
801 closeButtonImage.style.backgroundSize = "cover";
802 closeButtonImage.onclick = closePopup;
803 positionCloseButton(mainDiv);
804 }
805
806 function positionCloseButton(mainDiv) {
807 if (closeBehavior.buttonPosition == "left") {
808 closeButtonImage.style.left = (closeButton.width / 2 + parseFloat(closeBehavior.leftPosition)) + "px";
809 } else if (closeBehavior.buttonPosition == "right") {
810 var border = contentBox.borderWidth || 0;
811 var left = 0;
812 var mainDivWidth = mainDiv.style.width;
813 if (mainDiv.style.maxWidth && parseInt(mainDivWidth) > parseInt(mainDiv.style.maxWidth)) {
814 mainDivWidth = mainDiv.style.maxWidth;
815 }
816 left = parseFloat(mainDivWidth) - Math.ceil(closeButton.width / 2) + 2 * contentBox.padding + 2 * border;
817 if (closeBehavior.leftPosition) {
818 left = left - parseFloat(closeBehavior.leftPosition);
819 }
820 closeButtonImage.style.left = left + "px";
821 }
822 closeButtonImage.style.top = parseFloat(closeBehavior.topPosition) + "px";
823 }
824
825 function onWindowRsize() {
826 clearTimeout(resizeTimeout);
827 resizeTimeout = setTimeout(function() {
828 resizeBox();
829 positionPopup();
830 positionCloseButton(mainDiv);
831 jQuery(window).trigger('sgpbPopupReload')
832 }, 0);
833 }
834
835 function windowResizeHandler() {
836 resizeBox();
837 positionPopup();
838 positionCloseButton(mainDiv);
839 jQuery(window).trigger('sgpbPopupReload')
840 }
841
842 function setOpenAnimation() {
843 if (!openAnimation.status) {
844 return false;
845 }
846 contentDiv.style.animationTimingFunction = "linear";
847 var border = contentBox.borderWidth || 0;
848 var padding = contentBox.padding || 0;
849 if (openAnimation.type == "slideleft") {
850 var start = window.innerWidth - parseInt(contentDiv.style.left) + 2 * border;
851 addAnimationClass(OPEN_ANIMATION_SLIDELEFT.replace(/\{start\}/g, start + "px"));
852 contentDiv.style.animationName = "slideinfromright";
853 } else if (openAnimation.type == "slideright") {
854 var start = parseInt(mainDiv.style.width) + parseInt(contentDiv.style.left) + 2 * border + 2 * padding;
855 addAnimationClass(OPEN_ANIMATION_SLIDERIGHT.replace(/\{start\}/g, "-" + start + "px"));
856 contentDiv.style.animationName = "slideinfromleft";
857 } else if (openAnimation.type == "pop") {
858 addAnimationClass(OPEN_ANIMATION_POP);
859 contentDiv.style.transform = "scale(1)";
860 contentDiv.style.animationName = "popin";
861 contentDiv.style.opacity = "1";
862 } else if (openAnimation.type == "fade") {
863 addAnimationClass(OPEN_ANIMATION_FADE);
864 contentDiv.style.animationName = "fadein";
865 contentDiv.style.opacity = "1";
866 } else if (openAnimation.type == "flip") {
867 addAnimationClass(OPEN_ANIMATION_FLIP);
868 contentDiv.style.animationName = "flipintoright";
869 contentDiv.style.transform = "translateX(0)";
870 } else if (openAnimation.type == "turn") {
871 addAnimationClass(OPEN_ANIMATION_FLIP);
872 contentDiv.style.animationName = "flipintoright";
873 contentDiv.style.transform = "translateX(0)";
874 contentDiv.style.transformOrigin = "0";
875 } else if (openAnimation.type == "flow") {
876 addAnimationClass(OPEN_ANIMATION_FLOW);
877 contentDiv.style.animationName = "flowinfromright";
878 contentDiv.style.transformOrigin = "50% 30%";
879 } else if (openAnimation.type == "slideup") {
880 var bottom = 0;
881 if (contentDiv.style.bottom) {
882 bottom = parseInt(mainDiv.style.height) + 2 * border + parseInt(contentDiv.style.bottom) + 2 * padding;
883 } else {
884 bottom = window.innerHeight - parseInt(contentDiv.style.top) + 2 * border;
885 }
886 var start = bottom;
887 addAnimationClass(OPEN_ANIMATION_SLIDEUP.replace(/\{start\}/g, start + "px"));
888 contentDiv.style.animationName = "slideinfrombottom";
889 } else if (openAnimation.type == "slidedown") {
890 var top = 0;
891 if (contentDiv.style.top) {
892 top = parseInt(contentDiv.style.top) + 2 * border + 2 * padding;
893 } else {
894 top = window.innerHeight - parseInt(contentDiv.style.bottom) - parseInt(mainDiv.style.height);
895 }
896 var start = top + parseInt(mainDiv.style.height);
897 addAnimationClass(OPEN_ANIMATION_SLIDEDOWN.replace(/\{start\}/g, "-" + start + "px"));
898 contentDiv.style.animationName = "slideinfromtop";
899 } else {
900 contentDiv.className += ' sg-animated ' + openAnimation.type;
901 }
902 contentDiv.style.animationDuration = openAnimation.speed + "ms";
903 }
904
905 function setCloseAnimation() {
906 contentDiv.style.animationTimingFunction = "linear";
907 var border = contentBox.borderWidth || 0;
908 var padding = contentBox.padding || 0;
909 if (closeAnimation.type == "slideleft") {
910 var end = parseInt(mainDiv.style.width) + parseInt(contentDiv.style.left) + 2 * border + 2 * padding;
911 addAnimationClass(CLOSE_ANIMATION_SLIDELEFT.replace(/\{end\}/g, "-" + end + "px"));
912 contentDiv.style.animationName = "slideouttoleft";
913 } else if (closeAnimation.type == "slideright") {
914 var end = window.innerWidth - parseInt(contentDiv.style.left) + 2 * border;
915 addAnimationClass(CLOSE_ANIMATION_SLIDERIGHT.replace(/\{end\}/g, end + "px"));
916 contentDiv.style.animationName = "slideouttoright";
917 } else if (closeAnimation.type == "pop") {
918 addAnimationClass(CLOSE_ANIMATION_POP);
919 contentDiv.style.animationName = "popout";
920 contentDiv.style.transform = "scale(0)";
921 contentDiv.style.opacity = "0";
922 } else if (closeAnimation.type == "fade") {
923 addAnimationClass(CLOSE_ANIMATION_FADE);
924 contentDiv.style.animationName = "fadeout";
925 contentDiv.style.opacity = "0";
926 } else if (closeAnimation.type == "flip") {
927 addAnimationClass(CLOSE_ANIMATION_FLIP);
928 contentDiv.style.animationName = "flipouttoright";
929 contentDiv.style.transform = "rotateY(-90deg) scale(.9)";
930 } else if (closeAnimation.type == "turn") {
931 addAnimationClass(CLOSE_ANIMATION_FLIP);
932 contentDiv.style.animationName = "flipouttoright";
933 contentDiv.style.transform = "rotateY(-90deg) scale(.9)";
934 contentDiv.style.transformOrigin = "0";
935 } else if (closeAnimation.type == "flow") {
936 addAnimationClass(CLOSE_ANIMATION_FLOW);
937 contentDiv.style.animationName = "flowouttoright";
938 contentDiv.style.transformOrigin = "50% 30%";
939 } else if (closeAnimation.type == "slideup") {
940 var top = 0;
941 if (contentDiv.style.top) {
942 top = parseInt(contentDiv.style.top) + 2 * border + 2 * padding;
943 } else {
944 top = window.innerHeight - parseInt(contentDiv.style.bottom) - parseInt(mainDiv.style.height);
945 }
946 var end = top + parseInt(mainDiv.style.height);
947 addAnimationClass(CLOSE_ANIMATION_SLIDEUP.replace(/\{end\}/g, "-" + end + "px"));
948 contentDiv.style.animationName = "slideouttotop";
949 } else if (closeAnimation.type == "slidedown") {
950 var bottom = 0;
951 if (contentDiv.style.bottom) {
952 bottom = parseInt(mainDiv.style.height) + 2 * border + parseInt(contentDiv.style.bottom) + 2 * padding;
953 } else {
954 bottom = window.innerHeight - parseInt(contentDiv.style.top) + 2 * border;
955 }
956 var end = bottom;
957 addAnimationClass(CLOSE_ANIMATION_SLIDEDOWN.replace(/\{end\}/g, end + "px"));
958 contentDiv.style.animationName = "slideouttobottom";
959 } else {
960 contentDiv.className = prefix + '-popup-dialog-main-div-theme-wrapper-' + config.popupTheme + ' sg-animated ' + closeAnimation.type;
961 }
962 contentDiv.style.animationDuration = closeAnimation.speed + "ms";
963 window.setTimeout(function() {
964 contentDiv.className = prefix + '-popup-dialog-main-div-theme-wrapper-' + config.popupTheme;
965 contentDiv.style.animationName = "";
966 contentDiv.style.transform = "";
967 contentDiv.style.transformOrigin = "";
968 contentDiv.style.opacity = "";
969 }, parseInt(closeAnimation.speed) + 10);
970 }
971
972 function setOpenEvents() {
973 for (var i = 0; i < events.length; i++) {
974 var event = events[i];
975 switch (event.type) {
976 case "load":
977 setOpenOnLoadEvent();
978 break;
979 case "click":
980 setOpenOnClickEvent(event);
981 break;
982 case "hover":
983 setOpenOnHoverEvent(event);
984 break;
985 case "scroll":
986 setOpenOnScrollEvent(event);
987 break;
988 case "exit":
989 setOpenOnExitEvent(event);
990 break;
991 case "inactivity":
992 setOpenInactivityEvent(event);
993 }
994 }
995 }
996
997 function setOpenOnExitEvent(config) {
998 switch (config.mode) {
999 case "soft":
1000 setSoftExitEvents(config);
1001 break;
1002 case "agressive1":
1003 setAgressive1ExitEvents(config);
1004 break;
1005 case "agressive2":
1006 setAgressive2ExitEvents(config);
1007 break;
1008 case "full":
1009 setFullExitEvents(config);
1010 break;
1011 }
1012 }
1013
1014 function setAgressive1ExitEvents(config) {
1015 window.addEventListener("beforeunload", function(e) {
1016 (e || window.event).returnValue = config.message;
1017 return config.message
1018 })
1019 }
1020
1021 function setAgressive2ExitEvents(config) {
1022 window.addEventListener("beforeunload", function(e) {
1023 openPopup(false, 'onExit');
1024 e.returnValue = config.message;
1025 return config.message
1026 });
1027 }
1028
1029 function setFullExitEvents(config) {
1030 setSoftExitEvents(config);
1031 setAgressive2ExitEvents(config);
1032 }
1033
1034 function setSoftExitEvents(config) {
1035 document.addEventListener("mouseout", function(event) {
1036 if (event.toElement == null && event.relatedTarget == null) {
1037 openPopup(false, 'onExit');
1038 }
1039 })
1040 }
1041
1042 function setOpenOnScrollEvent(config) {
1043 var scrollPos = parseInt(config.position);
1044 if (config.position.indexOf("%") > 0) {
1045 scrollPos = document.body.scrollHeight * (scrollPos / 100) - window.innerHeight / 2;
1046 }
1047 var scrollEventFunction = function() {
1048 if (document.body.scrollTop >= scrollPos || document.documentElement.scrollTop >= scrollPos) {
1049 openPopup(false, 'onScroll');
1050 window.removeEventListener("scroll", scrollEventFunction);
1051 }
1052 };
1053 window.addEventListener("scroll", scrollEventFunction);
1054 }
1055
1056 function setOpenOnLoadEvent() {
1057 if (document.readyState === "complete") {
1058 openPopup(false, 'onLoad');
1059 } else {
1060 window.addEventListener("load", function() {
1061 openPopup(false, 'onLoad');
1062 }, false);
1063 }
1064 }
1065
1066 function setOpenOnClickEvent(config) {
1067 var target = config.target;
1068 if (!target) {
1069 return;
1070 }
1071 var elements = document.getElementsByClassName(target);
1072 for (var i = 0; i < elements.length; i++) {
1073 elements[i].addEventListener("click", function() {
1074 openPopup(false, 'onClick');
1075 });
1076 }
1077 }
1078
1079 function setOpenOnHoverEvent(config) {
1080 var target = config.target;
1081 if (!target) {
1082 return;
1083 }
1084 var elements = document.getElementsByClassName(target);
1085 for (var i = 0; i < elements.length; i++) {
1086 elements[i].addEventListener("mouseover", function() {
1087 openPopup(false, 'onHover');
1088 });
1089 }
1090 }
1091
1092 function setOpenInactivityEvent(config) {
1093 var timer;
1094 var handler = function() {
1095 if (timer) {
1096 clearInterval(timer);
1097 }
1098 timer = setInterval(function() {
1099 openPopup();
1100 }, config.timeout * 1000);
1101 };
1102 document.addEventListener("mousemove", handler);
1103 document.addEventListener("mousedown", handler);
1104 document.addEventListener("keydown", handler);
1105 document.addEventListener("scroll", handler);
1106 handler();
1107 }
1108
1109 function initPopup() {
1110 DIV = document.createElement("div");
1111 DIV.id = prefix + "-popup-dialog-main-div-wrapper";
1112 DIV.className = prefix + "-popup-dialog-main-div-wrapper";
1113 mainDiv = document.createElement("div");
1114 mainDiv.id = prefix + "-popup-dialog-main-div";
1115 var sizeConfig = getSizeConfig();
1116 contentDiv = document.createElement("div");
1117 contentDiv.className = prefix + '-popup-dialog-main-div-theme-wrapper-' + config.popupTheme;
1118 setMainDivStyles(sizeConfig);
1119 if (contentBox.addClass) {
1120 mainDiv.className = contentBox.addClass;
1121 }
1122 DIV.style.display = "none";
1123 var popupContent = getInlineContent();
1124 if (contents) {
1125 var divElement = document.createElement('div');
1126 divElement.setAttribute('style', 'height:100%;width:100%;overflow:' + (contentBox.scrollingEnabled ? 'auto' : 'hidden') + ';');
1127 divElement.appendChild(contents);
1128 mainDiv.appendChild(divElement);
1129 } else {
1130 mainDiv.innerHTML = '<div style="height:100%;width:100%;overflow:' + (contentBox.scrollingEnabled ? "auto" : "hidden") + ';">' + popupContent.innerHTML + '</div>';
1131 }
1132 if (0) {
1133 closeButtonImage = document.createElement(config.closeButton.type);
1134 } else {
1135 closeButtonImage = document.createElement("IMG");
1136 }
1137 if (false) {
1138 closeButtonImage.className = prefix + "-popup-close-button-" + config.popupTheme;
1139 contentDiv.appendChild(closeButtonImage);
1140 }
1141 contentDiv.appendChild(mainDiv);
1142 DIV.appendChild(contentDiv);
1143 document.body.appendChild(DIV);
1144 isInited = true;
1145 setOpenEvents();
1146 }
1147
1148 function getInlineContent() {
1149 var divElement = document.createElement("div");
1150 divElement.innerHTML = '';
1151 if (inline) {
1152 var hrefHtml = document.getElementById(inline);
1153 if (hrefHtml.previousElementSibling) {
1154 SGPopup.inlinePrevTarget = {
1155 hasPreviousElement: true,
1156 node: hrefHtml.previousElementSibling
1157 }
1158 } else {
1159 SGPopup.inlinePrevTarget = {
1160 hasPreviousElement: false,
1161 node: hrefHtml.parentNode
1162 }
1163 }
1164 divElement.appendChild(hrefHtml);
1165 return divElement;
1166 }
1167 return divElement;
1168 }
1169
1170 function openPopup(forced, action) {
1171 if (opened) {
1172 return;
1173 }
1174 coockieValue = SGPopup.getCookie(popupId);
1175 if (coockieValue) {
1176 return;
1177 }
1178 if (showOnce) {
1179 SGPopup.setCookie(popupId, "true", parseInt(showOnce));
1180 }
1181 if (forced !== true) {
1182 if (shouldOpen && typeof shouldOpen == "function") {
1183 if (shouldOpen() === false) {
1184 return;
1185 }
1186 }
1187 }
1188 if (!isInited) {
1189 initPopup();
1190 }
1191 opened = true;
1192 var self = this;
1193 window.addEventListener("resize", onWindowRsize);
1194 if (closeBehavior.contentShouldClose) {
1195 mainDiv.onclick = closePopup;
1196 }
1197 setTimeout(function() {
1198 if (willOpen && typeof willOpen == "function") {
1199 willOpen();
1200 }
1201 drawOverlay();
1202 DIV.style.display = "";
1203 positionPopup();
1204 setOpenAnimation();
1205 setCloseButton(mainDiv);
1206 if (didOpen) {
1207 var callbackArgs = parentThis.getCallbackArgs();
1208 if (typeof didOpen == "function") {
1209 didOpen(callbackArgs);
1210 }
1211 }
1212 }, openDelay);
1213 if (closeBehavior.autoclose && closeBehavior.autoclose > 0) {
1214 setTimeout(closePopup, closeBehavior.autoclose * 1000);
1215 }
1216 if (closeBehavior.escShouldClose) {
1217 document.onkeydown = function(e) {
1218 e = e || window.event;
1219 if (e.keyCode == 27) {
1220 closePopup();
1221 }
1222 };
1223 }
1224 }
1225
1226 function closePopup(forced) {
1227 if (forced !== true) {
1228 if (shouldClose && typeof shouldClose == "function") {
1229 if (shouldClose() === false) {
1230 return;
1231 }
1232 }
1233 }
1234 if (closeBehavior.allowed === false && forced !== true) {
1235 return;
1236 }
1237 if (willClose && typeof willClose == "function") {
1238 willClose();
1239 }
1240 window.removeEventListener("resize", onWindowRsize);
1241 var closeFunction = function() {
1242 if (!DIV) {
1243 return;
1244 }
1245 DIV.style.display = "none";
1246 removeOverlay();
1247 if (didClose && typeof didClose == "function") {
1248 didClose();
1249 opened = false;
1250 }
1251 if (resetInlineContent && typeof resetInlineContent == "function") {
1252 resetInlineContent();
1253 }
1254 };
1255 if (closeAnimation.type != "none" && closeAnimation.speed > 0) {
1256 setCloseAnimation();
1257 setTimeout(closeFunction, closeAnimation.speed);
1258 } else {
1259 closeFunction();
1260 }
1261 }
1262 var resizeBox = function() {
1263 var sizeConfig = getSizeConfig();
1264 setMainDivStyles(sizeConfig)
1265 };
1266 this.getCallbackArgs = function() {
1267 var args = {
1268 event: this.customEvent
1269 }
1270 return args;
1271 };
1272 this.open = function(forced) {
1273 openPopup(forced);
1274 };
1275 this.init = function() {
1276 initPopup();
1277 };
1278 this.close = function(forced) {
1279 closePopup(forced);
1280 };
1281 this.resize = function() {
1282 resizeBox();
1283 };
1284 this.setOpenDelay = function(delay) {
1285 openDelay = delay;
1286 if (isInited) {
1287 initPopup();
1288 }
1289 };
1290 this.getOpenDelay = function() {
1291 return openDelay;
1292 };
1293 this.setOpenAnimation = function(animation) {
1294 openAnimation = animation;
1295 if (isInited) {
1296 initPopup();
1297 }
1298 };
1299 this.getOpenAnimation = function() {
1300 return openAnimation;
1301 };
1302 this.setCloseAnimation = function(animation) {
1303 closeAnimation = animation;
1304 if (isInited) {
1305 initPopup();
1306 }
1307 };
1308 this.getCloseAnimation = function() {
1309 return closeAnimation;
1310 };
1311 this.setCloseBehavior = function(config) {
1312 closeBehavior = config;
1313 if (isInited) {
1314 initPopup();
1315 }
1316 };
1317 this.getCloseBehavior = function() {
1318 return closeBehavior;
1319 };
1320 this.setCloseButton = function(button) {
1321 closeButton = button;
1322 };
1323 this.getCloseButton = function() {
1324 return closeButton;
1325 };
1326 this.setOverlay = function(config) {
1327 overlay = config;
1328 if (isInited) {
1329 initPopup();
1330 }
1331 };
1332 this.getOverlay = function() {
1333 return overlay;
1334 };
1335 this.setContentBox = function(config) {
1336 contentBox = config;
1337 if (isInited) {
1338 initPopup();
1339 }
1340 };
1341 this.getContentBox = function() {
1342 return contentBox;
1343 };
1344 this.setContents = function(content) {
1345 contents = content;
1346 if (isInited) {
1347 initPopup();
1348 }
1349 };
1350 this.getContents = function() {
1351 return contents;
1352 };
1353 this.setPosition = function(config) {
1354 position = config;
1355 };
1356 this.getPosition = function() {
1357 return position;
1358 };
1359 this.setSizingRanges = function(ranges) {
1360 sizingRanges = ranges;
1361 if (isInited) {
1362 initPopup();
1363 }
1364 };
1365 this.getSizingRanges = function() {
1366 return sizingRanges;
1367 };
1368 this.setShouldOpen = function(func) {
1369 shouldOpen = func;
1370 if (isInited) {
1371 initPopup();
1372 }
1373 };
1374 this.getShouldOpen = function() {
1375 return shouldOpen;
1376 };
1377 this.setWillOpen = function(func) {
1378 willOpen = func;
1379 if (isInited) {
1380 initPopup();
1381 }
1382 };
1383 this.getWillOpen = function() {
1384 return willOpen;
1385 };
1386 this.setDidOpen = function(func) {
1387 didOpen = func;
1388 if (isInited) {
1389 initPopup();
1390 }
1391 };
1392 this.getDidOpen = function() {
1393 return didOpen;
1394 };
1395 this.setShouldClose = function(func) {
1396 shouldClose = func;
1397 if (isInited) {
1398 initPopup();
1399 }
1400 };
1401 this.getShouldClose = function() {
1402 return shouldClose;
1403 };
1404 this.setWillClose = function(func) {
1405 willClose = func;
1406 if (isInited) {
1407 initPopup();
1408 }
1409 };
1410 this.getWillClose = function() {
1411 return willClose;
1412 };
1413 this.setDidClose = function(func) {
1414 didClose = func;
1415 if (isInited) {
1416 initPopup();
1417 }
1418 };
1419 this.getDidClose = function() {
1420 return didClose;
1421 };
1422 }
1423 SGPopup.sendGetRequest = function(url, responseHandler, params) {
1424 var req;
1425 if (window.XMLHttpRequest) {
1426 req = new XMLHttpRequest();
1427 } else if (window.ActiveXObject) {
1428 req = new ActiveXObject("Microsoft.XMLHTTP");
1429 }
1430 req.onreadystatechange = function() {
1431 if (req.readyState == 4) {
1432 if (req.status < 400) {
1433 responseHandler(req, params);
1434 } else {}
1435 }
1436 };
1437 req.open("GET", url, true);
1438 req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
1439 req.send(null);
1440 };
1441 SGPopup.getCookie = function(cname) {
1442 var name = cname + "=";
1443 var ca = document.cookie.split(';');
1444 for (var i = 0; i < ca.length; i++) {
1445 var c = ca[i];
1446 while (c.charAt(0) == ' ') {
1447 c = c.substring(1);
1448 }
1449 if (c.indexOf(name) == 0) {
1450 return c.substring(name.length, c.length);
1451 }
1452 }
1453 return "";
1454 };
1455 SGPopup.setCookie = function(cname, cvalue, exdays) {
1456 var exdate = new Date();
1457 if (!exdays || isNaN(exdays)) {
1458 exdays = 365 * 50;
1459 }
1460 exdate.setDate(exdate.getDate() + exdays);
1461 var value = cvalue + ((exdays == null) ? ";" : "; expires=" + exdate.toUTCString());
1462 document.cookie = cname + "=" + value;
1463 };
1464 SGPopup.getPopup = function(el) {
1465 var id = null;
1466 while (el && el != document) {
1467 if (el.hasAttribute("data-sg-popup-hash-id")) {
1468 id = el.getAttribute("data-sg-popup-hash-id");
1469 break;
1470 }
1471 el = el.parentNode;
1472 }
1473 if (id) {
1474 return SGPopupLoader.popups[id];
1475 }
1476 };
1477 SGPopup.openSGPopup = function() {
1478 var ids = SGPopupLoader.ids;
1479 var linkTag = document.createElement("link");
1480 linkTag.rel = "stylesheet";
1481 linkTag.type = "text/css";
1482 linkTag.href = SG_APP_URL + 'public/assets/lib/SGPopup.css';
1483 document.head.appendChild(linkTag);
1484 var responseFunction = function(response, id) {
1485 var config = JSON.parse(response.responseText);
1486 var popup = new SGPopup(config);
1487 SGPopupLoader.popups[id] = popup;
1488 popup.init();
1489 };
1490 for (var i = 0; i < ids.length; i++) {
1491 SGPopup.sendGetRequest(SG_APP_URL + 'api/popups/' + ids[i], responseFunction, ids[i]);
1492 }
1493 };
1494
1495 jQuery(document).ready(function() {
1496 var hiddenDivId = 'sg-christmas-popup-content-wrapper';
1497 if (!jQuery('#'+hiddenDivId).length) {
1498 return false;
1499 }
1500
1501 var popupConfigObj = new PopupConfig();
1502 popupConfigObj.magicCall('setContentPadding', 0);
1503 popupConfigObj.magicCall('setContentBorderRadius', 4);
1504 popupConfigObj.magicCall('setContentBorderRadiusType', 'px');
1505 popupConfigObj.magicCall('setContentBorderWidth', 0);
1506 popupConfigObj.magicCall('setOverlayColor', 'white');
1507 popupConfigObj.magicCall('setContentBorderColor', '#506274');
1508 popupConfigObj.magicCall('setShadowSpread', 1);
1509 popupConfigObj.magicCall('setContentShadowBlur', 4);
1510 popupConfigObj.magicCall('setContentBackgroundColor', 'rgba(1,1,1,0)');
1511 popupConfigObj.magicCall('setContentShadowColor', '');
1512 popupConfigObj.magicCall('setMinWidth', 400);
1513 popupConfigObj.magicCall('setSrcElement', hiddenDivId);
1514 popupConfigObj.magicCall('setOverlayColor', 'black');
1515 popupConfigObj.magicCall('setOverlayOpacity', 40);
1516 var config = popupConfigObj.combineConfigObj();
1517
1518 var popup = new SGPopup(config);
1519 window.backupGuardHalloweenPopup = popup;
1520 popup.open();
1521
1522 jQuery('.sgbg-christmas-close-popup').bind('click', function () {
1523 window.backupGuardHalloweenPopup.close();
1524 jQuery('.backup-guard-discount-notice').remove();
1525 var sgNoticeClosedHandler = new sgRequestHandler('dismiss_discount_notice', {token: BG_BACKUP_STRINGS.nonce});
1526 sgNoticeClosedHandler.run();
1527 });
1528
1529 jQuery('#sg-halloween-popup-content-wrapper').bind('click', function () {
1530 window.open('https://backup-guard.com/products/backup-wordpress#pricing')
1531 });
1532 });