PluginProbe
Boxzilla – WordPress Popup Builder / 3.1.3
Boxzilla – WordPress Popup Builder v3.1.3
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
← All changes | assets/js/script.js +247 -371 3.1.123.1.3 View file →
@@ -1,136 +1,90 @@
1 1 (function () { var require = undefined; var module = undefined; var exports = undefined; var define = undefined; (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2 2 'use strict';
3 3
4 -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4 +var Boxzilla = require('boxzilla');
5 +var options = window.boxzilla_options;
6 +var isLoggedIn = document.body.className.indexOf('logged-in') > -1;
5 7
6 -(function () {
7 - 'use strict';
8 +// print message when test mode is enabled
9 +if( isLoggedIn && options.testMode ) {
10 + console.log( 'Boxzilla: Test mode is enabled. Please disable test mode if you\'re done testing.' );
11 +}
8 12
9 - var Boxzilla = require('boxzilla');
10 - var options = window.boxzilla_options;
13 +// init boxzilla
14 +Boxzilla.init();
11 15
12 - // expose Boxzilla object to window
13 - window.Boxzilla = Boxzilla;
16 +// create boxes from options
17 +for( var i=0; i < options.boxes.length; i++ ) {
18 + // get opts
19 + var boxOpts = options.boxes[i];
20 + boxOpts.testMode = isLoggedIn && options.testMode;
14 21
15 - function ready(fn) {
16 - if (document.readyState != 'loading') {
17 - fn();
18 - } else {
19 - document.addEventListener('DOMContentLoaded', fn);
20 - }
22 + // fix http:// links in box content....
23 + if( window.location.origin.substring(0, 5) === "https" ) {
24 + boxOpts.content = boxOpts.content.replace(window.location.origin.replace("https", "http"), window.location.origin);
21 25 }
22 26
23 - // helper function for setting CSS styles
24 - function css(element, styles) {
25 - if (styles.background_color) {
26 - element.style.background = styles.background_color;
27 - }
27 + // create box
28 + var box = Boxzilla.create( boxOpts.id, boxOpts);
29 +
30 + // add custom css to box
31 + css(box.element, boxOpts.css);
32 +}
28 33
29 - if (styles.color) {
30 - element.style.color = styles.color;
31 - }
34 +// helper function for setting CSS styles
35 +function css(element, styles) {
36 + if( styles.background_color ) {
37 + element.style.background = styles.background_color;
38 + }
32 39
33 - if (styles.border_color) {
34 - element.style.borderColor = styles.border_color;
35 - }
40 + if( styles.color ) {
41 + element.style.color = styles.color;
42 + }
36 43
37 - if (styles.border_width) {
38 - element.style.borderWidth = parseInt(styles.border_width) + "px";
39 - }
44 + if( styles.border_color ) {
45 + element.style.borderColor = styles.border_color;
46 + }
40 47
41 - if (styles.border_style) {
42 - element.style.borderStyle = styles.border_style;
43 - }
48 + if( styles.border_width ) {
49 + element.style.borderWidth = parseInt(styles.border_width) + "px";
50 + }
44 51
45 - if (styles.width) {
46 - element.style.maxWidth = parseInt(styles.width) + "px";
47 - }
52 + if( styles.border_style ) {
53 + element.style.borderStyle = styles.border_style;
48 54 }
49 55
50 - function createBoxesFromConfig() {
51 - var isLoggedIn = document.body.className.indexOf('logged-in') > -1;
52 -
53 - // failsafe against including script twice.
54 - if (options.inited) {
55 - return;
56 - }
57 -
58 - // print message when test mode is enabled
59 - if (isLoggedIn && options.testMode) {
60 - console.log('Boxzilla: Test mode is enabled. Please disable test mode if you\'re done testing.');
61 - }
62 -
63 - // init boxzilla
64 - Boxzilla.init();
65 -
66 - // create boxes from options
67 - for (var i = 0; i < options.boxes.length; i++) {
68 - // get opts
69 - var boxOpts = options.boxes[i];
70 - boxOpts.testMode = isLoggedIn && options.testMode;
71 -
72 - // fix http:// links in box content....
73 - if (window.location.protocol === "https:" && window.location.host) {
74 - var o = "http://" + window.location.host;
75 - var n = o.replace('http://', 'https://');
76 - boxOpts.content = boxOpts.content.replace(o, n);
77 - }
78 -
79 - // create box
80 - var box = Boxzilla.create(boxOpts.id, boxOpts);
81 -
82 - // add box slug to box element as classname
83 - box.element.className = box.element.className + ' boxzilla-' + boxOpts.post.slug;
84 -
85 - // add custom css to box
86 - css(box.element, boxOpts.css);
87 -
88 - box.element.firstChild.firstChild.className += " first-child";
89 - box.element.firstChild.lastChild.className += " last-child";
90 - }
91 -
92 - /**
93 - * If a MailChimp for WordPress form was submitted, open the box containing that form (if any)
94 - *
95 - * TODO: Just set location hash from MailChimp for WP?
96 - */
97 - window.addEventListener('load', openMailChimpForWordPressBox);
98 -
99 - options.inited = true;
100 -
101 - // trigger "done" event.
102 - Boxzilla.trigger('done');
56 + if( styles.width ) {
57 + element.style.maxWidth = parseInt(styles.width) + "px";
103 58 }
59 +}
104 60
105 - function openMailChimpForWordPressBox() {
106 - if (_typeof(window.mc4wp_forms_config) === "object" && window.mc4wp_forms_config.submitted_form) {
107 - var selector = '#' + window.mc4wp_forms_config.submitted_form.element_id;
108 - var boxes = Boxzilla.boxes;
109 - for (var boxId in boxes) {
110 - if (!boxes.hasOwnProperty(boxId)) {
111 - continue;
112 - }
113 - var box = boxes[boxId];
114 - if (box.element.querySelector(selector)) {
115 - box.show();
116 - return;
117 - }
61 +/**
62 + * If a MailChimp for WordPress form was submitted, open the box containing that form (if any)
63 + *
64 + * TODO: Just set location hash from MailChimp for WP?
65 + */
66 +window.addEventListener('load', function() {
67 + if( typeof(window.mc4wp_forms_config) === "object" && window.mc4wp_forms_config.submitted_form ) {
68 + var selector = '#' + window.mc4wp_forms_config.submitted_form.element_id;
69 + var boxes = Boxzilla.boxes;
70 + for( var boxId in boxes ) {
71 + if(!boxes.hasOwnProperty(boxId)) { continue; }
72 + var box = boxes[boxId];
73 + if( box.element.querySelector(selector)) {
74 + box.show();
75 + return;
118 76 }
119 77 }
120 78 }
79 +});
121 80
122 - // create boxes as soon as document.ready fires
123 - ready(createBoxesFromConfig);
124 -})();
125 -
81 +window.Boxzilla = Boxzilla;
126 82 },{"boxzilla":4}],2:[function(require,module,exports){
127 -'use strict';
128 -
129 83 var duration = 320;
130 84
131 85 function css(element, styles) {
132 - for (var property in styles) {
86 + for(var property in styles) {
133 87 element.style[property] = styles[property];
134 88 }
135 89 }
136 90
@@ -135,9 +89,9 @@
135 89 }
136 90
137 91 function initObjectProperties(properties, value) {
138 92 var newObject = {};
139 - for (var i = 0; i < properties.length; i++) {
93 + for(var i=0; i<properties.length; i++) {
140 94 newObject[properties[i]] = value;
141 95 }
142 96 return newObject;
143 97 }
@@ -142,10 +96,10 @@
142 96 return newObject;
143 97 }
144 98
145 99 function copyObjectProperties(properties, object) {
146 - var newObject = {};
147 - for (var i = 0; i < properties.length; i++) {
100 + var newObject = {}
101 + for(var i=0; i<properties.length; i++) {
148 102 newObject[properties[i]] = object[properties[i]];
149 103 }
150 104 return newObject;
151 105 }
@@ -156,9 +110,9 @@
156 110 * @param element
157 111 * @returns {boolean}
158 112 */
159 113 function animated(element) {
160 - return !!element.getAttribute('data-animated');
114 + return !! element.getAttribute('data-animated');
161 115 }
162 116
163 117 /**
164 118 * Toggles the element using the given animation.
@@ -170,9 +124,9 @@
170 124 var nowVisible = element.style.display != 'none' || element.offsetLeft > 0;
171 125
172 126 // create clone for reference
173 127 var clone = element.cloneNode(true);
174 - var cleanup = function cleanup() {
128 + var cleanup = function() {
175 129 element.removeAttribute('data-animated');
176 130 element.setAttribute('style', clone.getAttribute('style'));
177 131 element.style.display = nowVisible ? 'none' : '';
178 132 };
@@ -180,9 +134,9 @@
180 134 // store attribute so everyone knows we're animating this element
181 135 element.setAttribute('data-animated', "true");
182 136
183 137 // toggle element visiblity right away if we're making something visible
184 - if (!nowVisible) {
138 + if( ! nowVisible ) {
185 139 element.style.display = '';
186 140 }
187 141
188 142 var hiddenStyles, visibleStyles;
@@ -187,13 +141,13 @@
187 141
188 142 var hiddenStyles, visibleStyles;
189 143
190 144 // animate properties
191 - if (animation === 'slide') {
145 + if( animation === 'slide' ) {
192 146 hiddenStyles = initObjectProperties(["height", "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom"], 0);
193 147 visibleStyles = {};
194 148
195 - if (!nowVisible) {
149 + if( ! nowVisible ) {
196 150 var computedStyles = window.getComputedStyle(element);
197 151 visibleStyles = copyObjectProperties(["height", "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom"], computedStyles);
198 152 css(element, hiddenStyles);
199 153 }
@@ -203,9 +157,9 @@
203 157 animate(element, nowVisible ? hiddenStyles : visibleStyles, cleanup);
204 158 } else {
205 159 hiddenStyles = { opacity: 0 };
206 160 visibleStyles = { opacity: 1 };
207 - if (!nowVisible) {
161 + if( ! nowVisible ) {
208 162 css(element, hiddenStyles);
209 163 }
210 164
211 165 animate(element, nowVisible ? hiddenStyles : visibleStyles, cleanup);
@@ -217,9 +171,9 @@
217 171 var initialStyles = window.getComputedStyle(element);
218 172 var currentStyles = {};
219 173 var propSteps = {};
220 174
221 - for (var property in targetStyles) {
175 + for(var property in targetStyles) {
222 176 // make sure we have an object filled with floats
223 177 targetStyles[property] = parseFloat(targetStyles[property]);
224 178
225 179 // calculate step size & current value
@@ -226,30 +180,30 @@
226 180 var to = targetStyles[property];
227 181 var current = parseFloat(initialStyles[property]);
228 182
229 183 // is there something to do?
230 - if (current == to) {
184 + if( current == to ) {
231 185 delete targetStyles[property];
232 186 continue;
233 187 }
234 188
235 - propSteps[property] = (to - current) / duration; // points per second
189 + propSteps[property] = ( to - current ) / duration; // points per second
236 190 currentStyles[property] = current;
237 191 }
238 192
239 - var tick = function tick() {
193 + var tick = function() {
240 194 var now = +new Date();
241 195 var timeSinceLastTick = now - last;
242 196 var done = true;
243 197
244 198 var step, to, increment, newValue;
245 - for (var property in targetStyles) {
199 + for(var property in targetStyles ) {
246 200 step = propSteps[property];
247 201 to = targetStyles[property];
248 - increment = step * timeSinceLastTick;
202 + increment = step * timeSinceLastTick;
249 203 newValue = currentStyles[property] + increment;
250 204
251 - if (step > 0 && newValue >= to || step < 0 && newValue <= to) {
205 + if( step > 0 && newValue >= to || step < 0 && newValue <= to ) {
252 206 newValue = to;
253 207 } else {
254 208 done = false;
255 209 }
@@ -263,10 +217,10 @@
263 217
264 218 last = +new Date();
265 219
266 220 // keep going until we're done for all props
267 - if (!done) {
268 - window.requestAnimationFrame && requestAnimationFrame(tick) || setTimeout(tick, 32);
221 + if(!done) {
222 + (window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 32);
269 223 } else {
270 224 // call callback
271 225 fn && fn();
272 226 }
@@ -274,29 +228,29 @@
274 228
275 229 tick();
276 230 }
277 231
232 +
278 233 module.exports = {
279 234 'toggle': toggle,
280 235 'animate': animate,
281 236 'animated': animated
282 237 };
283 -
284 238 },{}],3:[function(require,module,exports){
285 239 'use strict';
286 240
287 241 var defaults = {
288 - 'animation': 'fade',
289 - 'rehide': false,
290 - 'content': '',
291 - 'cookie': null,
292 - 'icon': '&times',
293 - 'screenWidthCondition': null,
294 - 'position': 'center',
295 - 'testMode': false,
296 - 'trigger': false,
297 - 'closable': true
298 -},
242 + 'animation': 'fade',
243 + 'rehide': false,
244 + 'content': '',
245 + 'cookie': null,
246 + 'icon': '&times',
247 + 'minimumScreenWidth': 0,
248 + 'position': 'center',
249 + 'testMode': false,
250 + 'trigger': false,
251 + 'closable': true
252 + },
299 253 Boxzilla,
300 254 Animator = require('./animator.js');
301 255
302 256 /**
@@ -305,16 +259,12 @@
305 259 * @param obj1
306 260 * @param obj2
307 261 * @returns {*}
308 262 */
309 -function merge(obj1, obj2) {
263 +function merge( obj1, obj2 ) {
310 264 var obj3 = {};
311 - for (var attrname in obj1) {
312 - obj3[attrname] = obj1[attrname];
313 - }
314 - for (var attrname in obj2) {
315 - obj3[attrname] = obj2[attrname];
316 - }
265 + for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
266 + for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
317 267 return obj3;
318 268 }
319 269
320 270 /**
@@ -324,16 +274,17 @@
324 274 function getDocumentHeight() {
325 275 var body = document.body,
326 276 html = document.documentElement;
327 277
328 - var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
278 + var height = Math.max( body.scrollHeight, body.offsetHeight,
279 + html.clientHeight, html.scrollHeight, html.offsetHeight );
329 280
330 281 return height;
331 282 }
332 283
333 284 // Box Object
334 -var Box = function Box(id, config) {
335 - this.id = id;
285 +var Box = function( id, config ) {
286 + this.id = id;
336 287
337 288 // store config values
338 289 this.config = merge(defaults, config);
339 290
@@ -340,11 +291,11 @@
340 291 // store ref to overlay
341 292 this.overlay = document.getElementById('boxzilla-overlay');
342 293
343 294 // state
344 - this.visible = false;
345 - this.dismissed = false;
346 - this.triggered = false;
295 + this.visible = false;
296 + this.dismissed = false;
297 + this.triggered = false;
347 298 this.triggerHeight = 0;
348 299 this.cookieSet = false;
349 300 this.element = null;
350 301 this.closeIcon = null;
@@ -349,10 +300,10 @@
349 300 this.element = null;
350 301 this.closeIcon = null;
351 302
352 303 // if a trigger was given, calculate values once and store
353 - if (this.config.trigger) {
354 - if (this.config.trigger.method === 'percentage' || this.config.trigger.method === 'element') {
304 + if( this.config.trigger ) {
305 + if( this.config.trigger.method === 'percentage' || this.config.trigger.method === 'element' ) {
355 306 this.triggerHeight = this.calculateTriggerHeight();
356 307 }
357 308
358 309 this.cookieSet = this.isCookieSet();
@@ -365,35 +316,41 @@
365 316 this.events();
366 317 };
367 318
368 319 // initialise the box
369 -Box.prototype.events = function () {
320 +Box.prototype.events = function() {
370 321 var box = this;
371 322
372 323 // attach event to "close" icon inside box
373 - if (this.closeIcon) {
374 - this.closeIcon.addEventListener('click', this.dismiss.bind(this));
375 - }
324 + this.closeIcon && this.closeIcon.addEventListener('click', box.dismiss.bind(this));
376 325
377 - this.element.addEventListener('click', function (e) {
378 - if (e.target.tagName === 'A') {
379 - Boxzilla.trigger('box.interactions.link', [box, e.target]);
326 + this.element.addEventListener('click', function(e) {
327 + if( e.target.tagName === 'A' ) {
328 + Boxzilla.trigger('box.interactions.link', [ box, e.target ] );
380 329 }
381 330 }, false);
382 331
383 - this.element.addEventListener('submit', function (e) {
332 + this.element.addEventListener('submit', function(e) {
384 333 box.setCookie();
385 - Boxzilla.trigger('box.interactions.form', [box, e.target]);
334 + Boxzilla.trigger('box.interactions.form', [ box, e.target ]);
386 335 }, false);
336 +
337 + window.addEventListener("hashchange", function() {
338 + var needle = "#boxzilla-" + box.id;
339 + if( location.hash === needle ) {
340 + box.toggle();
341 + }
342 + });
387 343
388 344 // maybe show box right away
389 - if (this.fits() && this.locationHashRefersBox()) {
345 + if( this.fits() && this.locationHashRefersBox() ) {
390 346 window.addEventListener('load', this.show.bind(this));
391 347 }
348 +
392 349 };
393 350
394 351 // generate dom elements for this box
395 -Box.prototype.dom = function () {
352 +Box.prototype.dom = function() {
396 353 var wrapper = document.createElement('div');
397 354 wrapper.className = 'boxzilla-container boxzilla-' + this.config.position + '-container';
398 355
399 356 var box = document.createElement('div');
@@ -408,18 +365,18 @@
408 365 box.appendChild(content);
409 366
410 367 // remove <script> from box content and append them to the document body
411 368 var scripts = content.querySelectorAll('script');
412 - if (scripts.length) {
369 + if(scripts.length) {
413 370 var script = document.createElement('script');
414 - for (var i = 0; i < scripts.length; i++) {
371 + for( var i=0; i<scripts.length; i++ ) {
415 372 script.appendChild(document.createTextNode(scripts[i].text));
416 373 scripts[i].parentNode.removeChild(scripts[i]);
417 374 }
418 375 document.body.appendChild(script);
419 376 }
420 -
421 - if (this.config.closable && this.config.icon) {
377 +
378 + if( this.config.closable && this.config.icon ) {
422 379 var closeIcon = document.createElement('span');
423 380 closeIcon.className = "boxzilla-close-icon";
424 381 closeIcon.innerHTML = this.config.icon;
425 382 box.appendChild(closeIcon);
@@ -430,9 +387,9 @@
430 387 this.element = box;
431 388 };
432 389
433 390 // set (calculate) custom box styling depending on box options
434 -Box.prototype.setCustomBoxStyling = function () {
391 +Box.prototype.setCustomBoxStyling = function() {
435 392
436 393 // reset element to its initial state
437 394 var origDisplay = this.element.style.display;
438 395 this.element.style.display = '';
@@ -443,16 +400,16 @@
443 400 var windowHeight = window.innerHeight;
444 401 var boxHeight = this.element.clientHeight;
445 402
446 403 // add scrollbar to box and limit height
447 - if (boxHeight > windowHeight) {
404 + if( boxHeight > windowHeight ) {
448 405 this.element.style.maxHeight = windowHeight + "px";
449 406 this.element.style.overflowY = 'scroll';
450 407 }
451 408
452 409 // set new top margin for boxes which are centered
453 - if (this.config.position === 'center') {
454 - var newTopMargin = (windowHeight - boxHeight) / 2;
410 + if( this.config.position === 'center' ) {
411 + var newTopMargin = ( ( windowHeight - boxHeight ) / 2 );
455 412 newTopMargin = newTopMargin >= 0 ? newTopMargin : 0;
456 413 this.element.style.marginTop = newTopMargin + "px";
457 414 }
458 415
@@ -459,27 +416,27 @@
459 416 this.element.style.display = origDisplay;
460 417 };
461 418
462 419 // toggle visibility of the box
463 -Box.prototype.toggle = function (show) {
420 +Box.prototype.toggle = function(show) {
464 421
465 422 // revert visibility if no explicit argument is given
466 - if (typeof show === "undefined") {
467 - show = !this.visible;
423 + if( typeof( show ) === "undefined" ) {
424 + show = ! this.visible;
468 425 }
469 426
470 427 // is box already at desired visibility?
471 - if (show === this.visible) {
428 + if( show === this.visible ) {
472 429 return false;
473 430 }
474 431
475 432 // is box being animated?
476 - if (Animator.animated(this.element)) {
433 + if( Animator.animated(this.element) ) {
477 434 return false;
478 435 }
479 436
480 437 // if box should be hidden but is not closable, bail.
481 - if (!show && !this.config.closable) {
438 + if( ! show && ! this.config.closable ) {
482 439 return false;
483 440 }
484 441
485 442 // set new visibility status
@@ -488,43 +445,48 @@
488 445 // calculate new styling rules
489 446 this.setCustomBoxStyling();
490 447
491 448 // trigger event
492 - Boxzilla.trigger('box.' + (show ? 'show' : 'hide'), [this]);
449 + Boxzilla.trigger('box.' + ( show ? 'show' : 'hide' ), [ this ] );
493 450
494 451 // show or hide box using selected animation
495 - if (this.config.position === 'center') {
496 - this.overlay.classList.toggle('boxzilla-' + this.id + '-overlay');
452 + if( this.config.position === 'center' ) {
497 453 Animator.toggle(this.overlay, "fade");
498 454 }
499 455
500 456 Animator.toggle(this.element, this.config.animation);
501 457
458 + // focus on first input field in box
459 + var firstInput = this.element.querySelector('input, textarea');
460 + if(firstInput) {
461 + firstInput.focus();
462 + }
463 +
502 464 return true;
503 465 };
504 466
505 467 // show the box
506 -Box.prototype.show = function () {
468 +Box.prototype.show = function() {
507 469 return this.toggle(true);
508 470 };
509 471
510 472 // hide the box
511 -Box.prototype.hide = function () {
473 +Box.prototype.hide = function() {
512 474 return this.toggle(false);
513 475 };
514 476
515 477 // calculate trigger height
516 -Box.prototype.calculateTriggerHeight = function () {
478 +Box.prototype.calculateTriggerHeight = function() {
517 479 var triggerHeight = 0;
518 480
519 - if (this.config.trigger.method === 'element') {
481 + if( this.config.trigger.method === 'element' ) {
520 482 var triggerElement = document.body.querySelector(this.config.trigger.value);
521 - if (triggerElement) {
483 + if( triggerElement ) {
522 484 var offset = triggerElement.getBoundingClientRect();
523 485 triggerHeight = offset.top;
524 486 }
525 - } else if (this.config.trigger.method === 'percentage') {
526 - triggerHeight = this.config.trigger.value / 100 * getDocumentHeight();
487 + } else if( this.config.trigger.method === 'percentage' ) {
488 + triggerHeight = ( this.config.trigger.value / 100 * getDocumentHeight() );
527 489 }
528 490
529 491 return triggerHeight;
530 492 };
@@ -529,18 +491,18 @@
529 491 return triggerHeight;
530 492 };
531 493
532 494 // checks whether window.location.hash equals the box element ID or that of any element inside the box
533 -Box.prototype.locationHashRefersBox = function () {
495 +Box.prototype.locationHashRefersBox = function() {
534 496
535 - if (!window.location.hash || 0 === window.location.hash.length) {
497 + if( ! window.location.hash || 0 === window.location.hash.length ) {
536 498 return false;
537 499 }
538 500
539 501 var elementId = window.location.hash.substring(1);
540 - if (elementId === this.element.id) {
502 + if( elementId === this.element.id ) {
541 503 return true;
542 - } else if (this.element.querySelector('#' + elementId)) {
504 + } else if( this.element.querySelector('#' + elementId) ) {
543 505 return true;
544 506 }
545 507
546 508 return false;
@@ -545,57 +507,49 @@
545 507
546 508 return false;
547 509 };
548 510
549 -Box.prototype.fits = function () {
550 - if (!this.config.screenWidthCondition || !this.config.screenWidthCondition.value) {
511 +Box.prototype.fits = function() {
512 + if( this.config.minimumScreenWidth <= 0 ) {
551 513 return true;
552 514 }
553 515
554 - switch (this.config.screenWidthCondition.condition) {
555 - case "larger":
556 - return window.innerWidth > this.config.screenWidthCondition.value;
557 - case "smaller":
558 - return window.innerWidth < this.config.screenWidthCondition.value;
559 - }
560 -
561 - // meh.. condition should be "smaller" or "larger", just return true.
562 - return true;
516 + return window.innerWidth > this.config.minimumScreenWidth
563 517 };
564 518
565 519 // is this box enabled?
566 -Box.prototype.mayAutoShow = function () {
520 +Box.prototype.mayAutoShow = function() {
567 521
568 - if (this.dismissed) {
522 + if( this.dismissed ) {
569 523 return false;
570 524 }
571 525
572 526 // check if box fits on given minimum screen width
573 - if (!this.fits()) {
527 + if( ! this.fits() ) {
574 528 return false;
575 529 }
576 530
577 531 // if trigger empty or error in calculating triggerHeight, return false
578 - if (!this.config.trigger) {
532 + if( ! this.config.trigger ) {
579 533 return false;
580 534 }
581 535
582 536 // rely on cookie value (show if not set, don't show if set)
583 - return !this.cookieSet;
537 + return ! this.cookieSet;
584 538 };
585 539
586 -Box.prototype.mayRehide = function () {
540 +Box.prototype.mayRehide = function() {
587 541 return this.config.rehide && this.triggered;
588 542 };
589 543
590 -Box.prototype.isCookieSet = function () {
544 +Box.prototype.isCookieSet = function() {
591 545 // always show on test mode
592 - if (this.config.testMode) {
546 + if(this.config.testMode) {
593 547 return false;
594 548 }
595 549
596 550 // if either cookie is null or trigger & dismiss are both falsey, don't bother checking.
597 - if (!this.config.cookie || !this.config.cookie.triggered && !this.config.cookie.dismissed) {
551 + if(!this.config.cookie || ( ! this.config.cookie.triggered && ! this.config.cookie.dismissed ) ) {
598 552 return false;
599 553 }
600 554
601 555 var cookieSet = document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + 'boxzilla_box_' + this.id + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1") === "true";
@@ -602,64 +556,44 @@
602 556 return cookieSet;
603 557 };
604 558
605 559 // set cookie that disables automatically showing the box
606 -Box.prototype.setCookie = function (hours) {
560 +Box.prototype.setCookie = function(hours) {
607 561 var expiryDate = new Date();
608 - expiryDate.setHours(expiryDate.getHours() + hours);
609 - document.cookie = 'boxzilla_box_' + this.id + '=true; expires=' + expiryDate.toUTCString() + '; path=/';
562 + expiryDate.setHours( expiryDate.getHours() + hours);
563 + document.cookie = 'boxzilla_box_'+ this.id + '=true; expires='+ expiryDate.toUTCString() +'; path=/';
610 564 };
611 565
612 -Box.prototype.trigger = function () {
566 +Box.prototype.trigger = function() {
613 567 var shown = this.show();
614 - if (!shown) {
568 + if( ! shown ) {
615 569 return;
616 570 }
617 571
618 572 this.triggered = true;
619 - if (this.config.cookie && this.config.cookie.triggered) {
573 + if(this.config.cookie && this.config.cookie.triggered) {
620 574 this.setCookie(this.config.cookie.triggered);
621 575 }
622 576 };
623 577
624 -/**
625 - * Dismisses the box and optionally sets a cookie.
626 - *
627 - * @param e The event that triggered this dismissal.
628 - * @returns {boolean}
629 - */
630 -Box.prototype.dismiss = function (e) {
631 - // prevent default action
632 - e && e.preventDefault();
633 -
634 - // only dismiss box if it's currently open.
635 - if (!this.visible) {
636 - return false;
637 - }
638 -
639 - // hide box element
578 +Box.prototype.dismiss = function() {
640 579 this.hide();
641 580
642 - // set cookie
643 - if (this.config.cookie && this.config.cookie.dismissed) {
581 + if(this.config.cookie && this.config.cookie.dismissed) {
644 582 this.setCookie(this.config.cookie.dismissed);
645 583 }
646 584
647 585 this.dismissed = true;
648 - Boxzilla.trigger('box.dismiss', [this]);
649 - return true;
586 + Boxzilla.trigger('box.dismiss', [ this ]);
650 587 };
651 588
652 -module.exports = function (_Boxzilla) {
589 +module.exports = function(_Boxzilla) {
653 590 Boxzilla = _Boxzilla;
654 591 return Box;
655 592 };
656 -
657 593 },{"./animator.js":2}],4:[function(require,module,exports){
658 594 'use strict';
659 595
660 -var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
661 -
662 596 var EventEmitter = require('wolfy87-eventemitter'),
663 597 Boxzilla = Object.create(EventEmitter.prototype),
664 598 Box = require('./box.js')(Boxzilla),
665 599 Timer = require('./timer.js'),
@@ -664,22 +598,19 @@
664 598 Box = require('./box.js')(Boxzilla),
665 599 Timer = require('./timer.js'),
666 600 boxes = [],
667 601 overlay,
668 - scrollElement = window,
669 - exitIntentDelayTimer,
670 - exitIntentTriggered,
671 - siteTimer,
672 - pageTimer,
673 - pageViews;
602 + exitIntentDelayTimer, exitIntentTriggered,
603 + siteTimer, pageTimer, pageViews;
674 604
675 605 function throttle(fn, threshhold, scope) {
676 606 threshhold || (threshhold = 250);
677 - var last, deferTimer;
607 + var last,
608 + deferTimer;
678 609 return function () {
679 610 var context = scope || this;
680 611
681 - var now = +new Date(),
612 + var now = +new Date,
682 613 args = arguments;
683 614 if (last && now < last + threshhold) {
684 615 // hold on to it
685 616 clearTimeout(deferTimer);
@@ -704,18 +635,18 @@
704 635 // check "pageviews" criteria for each box
705 636 function checkPageViewsCriteria() {
706 637
707 638 // don't bother if another box is currently open
708 - if (isAnyBoxVisible()) {
639 + if( isAnyBoxVisible() ) {
709 640 return;
710 641 }
711 642
712 - boxes.forEach(function (box) {
713 - if (!box.mayAutoShow()) {
643 + boxes.forEach(function(box) {
644 + if( ! box.mayAutoShow() ) {
714 645 return;
715 646 }
716 647
717 - if (box.config.trigger.method === 'pageviews' && pageViews >= box.config.trigger.value) {
648 + if( box.config.trigger.method === 'pageviews' && pageViews >= box.config.trigger.value ) {
718 649 box.trigger();
719 650 }
720 651 });
721 652 }
@@ -722,14 +653,14 @@
722 653
723 654 // check time trigger criteria for each box
724 655 function checkTimeCriteria() {
725 656 // don't bother if another box is currently open
726 - if (isAnyBoxVisible()) {
657 + if( isAnyBoxVisible() ) {
727 658 return;
728 659 }
729 660
730 - boxes.forEach(function (box) {
731 - if (!box.mayAutoShow()) {
661 + boxes.forEach(function(box) {
662 + if( ! box.mayAutoShow() ) {
732 663 return;
733 664 }
734 665
735 666 // check "time on site" trigger
@@ -745,26 +676,24 @@
745 676 }
746 677
747 678 // check triggerHeight criteria for all boxes
748 679 function checkHeightCriteria() {
680 + var scrollY = ( window.scrollY || window.pageYOffset ) + window.innerHeight * 0.75;
749 681
750 - var scrollY = scrollElement.hasOwnProperty('scrollY') ? scrollElement.scrollY : scrollElement.scrollTop;
751 - scrollY = scrollY + window.innerHeight * 0.75;
682 + // don't bother if another box is currently open
683 + if( isAnyBoxVisible() ) {
684 + return;
685 + }
752 686
753 - boxes.forEach(function (box) {
754 - if (!box.mayAutoShow() || box.triggerHeight <= 0) {
687 + boxes.forEach(function(box) {
688 +
689 + if( ! box.mayAutoShow() || box.triggerHeight <= 0 ) {
755 690 return;
756 691 }
757 692
758 - if (scrollY > box.triggerHeight) {
759 - // don't bother if another box is currently open
760 - if (isAnyBoxVisible()) {
761 - return;
762 - }
763 -
764 - // trigger box
693 + if( scrollY > box.triggerHeight ) {
765 694 box.trigger();
766 - } else if (box.mayRehide()) {
695 + } else if( box.mayRehide() ) {
767 696 box.hide();
768 697 }
769 698 });
770 699 }
@@ -770,9 +699,9 @@
770 699 }
771 700
772 701 // recalculate heights and variables based on height
773 702 function recalculateHeights() {
774 - boxes.forEach(function (box) {
703 + boxes.forEach(function(box) {
775 704 box.setCustomBoxStyling();
776 705 });
777 706 }
778 707
@@ -779,15 +708,15 @@
779 708 function onOverlayClick(e) {
780 709 var x = e.offsetX;
781 710 var y = e.offsetY;
782 711
783 - // calculate if click was less than 40px outside box to avoid closing it by accident
784 - boxes.forEach(function (box) {
712 + // calculate if click was near a box to avoid closing it (click error margin)
713 + boxes.forEach(function(box) {
785 714 var rect = box.element.getBoundingClientRect();
786 - var margin = 40;
715 + var margin = 100 + ( window.innerWidth * 0.05 );
787 716
788 717 // if click was not anywhere near box, dismiss it.
789 - if (x < rect.left - margin || x > rect.right + margin || y < rect.top - margin || y > rect.bottom + margin) {
718 + if( x < ( rect.left - margin ) || x > ( rect.right + margin ) || y < ( rect.top - margin ) || y > ( rect.bottom + margin ) ) {
790 719 box.dismiss();
791 720 }
792 721 });
793 722 }
@@ -793,14 +722,14 @@
793 722 }
794 723
795 724 function triggerExitIntent() {
796 725 // do nothing if already triggered OR another box is visible.
797 - if (exitIntentTriggered || isAnyBoxVisible()) {
726 + if(exitIntentTriggered || isAnyBoxVisible() ) {
798 727 return;
799 728 }
800 729
801 - boxes.forEach(function (box) {
802 - if (box.mayAutoShow() && box.config.trigger.method === 'exit_intent') {
730 + boxes.forEach(function(box) {
731 + if(box.mayAutoShow() && box.config.trigger.method === 'exit_intent' ) {
803 732 box.trigger();
804 733 }
805 734 });
806 735
@@ -810,9 +739,9 @@
810 739 function onMouseLeave(e) {
811 740 var delay = 400;
812 741
813 742 // did mouse leave at top of window?
814 - if (e.clientY <= 0) {
743 + if( e.clientY <= 0 ) {
815 744 exitIntentDelayTimer = window.setTimeout(triggerExitIntent, delay);
816 745 }
817 746 }
818 747
@@ -817,12 +746,12 @@
817 746 }
818 747
819 748 function isAnyBoxVisible() {
820 749
821 - for (var i = 0; i < boxes.length; i++) {
750 + for( var i=0; i<boxes.length; i++ ) {
822 751 var box = boxes[i];
823 752
824 - if (box.visible) {
753 + if( box.visible ) {
825 754 return true;
826 755 }
827 756 }
828 757
@@ -829,42 +758,22 @@
829 758 return false;
830 759 }
831 760
832 761 function onMouseEnter() {
833 - if (exitIntentDelayTimer) {
762 + if( exitIntentDelayTimer ) {
834 763 window.clearInterval(exitIntentDelayTimer);
835 764 exitIntentDelayTimer = null;
836 765 }
837 766 }
838 767
839 -function onElementClick(e) {
840 - // find <a> element in up to 3 parent elements
841 - var el = e.target || e.srcElement;
842 - var depth = 3;
843 - for (var i = 0; i <= depth; i++) {
844 - if (!el || el.tagName === 'A') {
845 - break;
846 - }
847 -
848 - el = el.parentElement;
849 - }
850 -
851 - if (el && el.tagName === 'A' && el.getAttribute('href').toLowerCase().indexOf('#boxzilla-') === 0) {
852 - var boxId = el.getAttribute('href').toLowerCase().substring("#boxzilla-".length);
853 - Boxzilla.toggle(boxId);
854 - }
855 -}
856 -
857 768 var timers = {
858 - start: function start() {
859 - try {
860 - var sessionTime = sessionStorage.getItem('boxzilla_timer');
861 - if (sessionTime) siteTimer.time = sessionTime;
862 - } catch (e) {}
769 + start: function() {
770 + var sessionTime = sessionStorage.getItem('boxzilla_timer');
771 + if( sessionTime ) siteTimer.time = sessionTime;
863 772 siteTimer.start();
864 773 pageTimer.start();
865 774 },
866 - stop: function stop() {
775 + stop: function() {
867 776 sessionStorage.setItem('boxzilla_timer', siteTimer.time);
868 777 siteTimer.stop();
869 778 pageTimer.stop();
870 779 }
@@ -870,19 +779,12 @@
870 779 }
871 780 };
872 781
873 782 // initialise & add event listeners
874 -Boxzilla.init = function () {
875 - document.body.addEventListener('click', onElementClick, false);
876 -
877 - try {
878 - pageViews = sessionStorage.getItem('boxzilla_pageviews') || 0;
879 - } catch (e) {
880 - pageViews = 0;
881 - }
882 -
883 - siteTimer = new Timer(0);
783 +Boxzilla.init = function() {
784 + siteTimer = new Timer(sessionStorage.getItem('boxzilla_timer') || 0);
884 785 pageTimer = new Timer(0);
786 + pageViews = sessionStorage.getItem('boxzilla_pageviews') || 0;
885 787
886 788 // insert styles into DOM
887 789 var styles = require('./styles.js');
888 790 var styleElement = document.createElement('style');
@@ -896,15 +798,14 @@
896 798 overlay.id = 'boxzilla-overlay';
897 799 document.body.appendChild(overlay);
898 800
899 801 // event binds
900 - scrollElement.addEventListener('touchstart', throttle(checkHeightCriteria), true);
901 - scrollElement.addEventListener('scroll', throttle(checkHeightCriteria), true);
802 + window.addEventListener('scroll', throttle(checkHeightCriteria));
902 803 window.addEventListener('resize', throttle(recalculateHeights));
903 - window.addEventListener('load', recalculateHeights);
804 + window.addEventListener('load', recalculateHeights );
904 805 overlay.addEventListener('click', onOverlayClick);
905 806 window.setInterval(checkTimeCriteria, 1000);
906 - window.setTimeout(checkPageViewsCriteria, 1000);
807 + window.setTimeout(checkPageViewsCriteria, 1000 );
907 808 document.documentElement.addEventListener('mouseleave', onMouseLeave);
908 809 document.documentElement.addEventListener('mouseenter', onMouseEnter);
909 810 document.addEventListener('keyup', onKeyUp);
910 811
@@ -909,9 +810,9 @@
909 810 document.addEventListener('keyup', onKeyUp);
910 811
911 812 timers.start();
912 813 window.addEventListener('focus', timers.start);
913 - window.addEventListener('beforeunload', function () {
814 + window.addEventListener('beforeunload', function() {
914 815 timers.stop();
915 816 sessionStorage.setItem('boxzilla_pageviews', ++pageViews);
916 817 });
917 818 window.addEventListener('blur', timers.stop);
@@ -926,72 +827,53 @@
926 827 * @param object opts
927 828 *
928 829 * @returns Box
929 830 */
930 -Boxzilla.create = function (id, opts) {
931 -
932 - // preserve backwards compat for minimumScreenWidth option
933 - if (typeof opts.minimumScreenWidth !== "undefined") {
934 - opts.screenWidthCondition = {
935 - condition: "larger",
936 - value: opts.minimumScreenWidth
937 - };
938 - }
939 -
831 +Boxzilla.create = function(id, opts) {
940 832 var box = new Box(id, opts);
941 833 boxes.push(box);
942 834 return box;
943 835 };
944 836
945 -Boxzilla.get = function (id) {
946 - for (var i = 0; i < boxes.length; i++) {
837 +Boxzilla.get = function(id) {
838 + for( var i=0; i<boxes.length; i++) {
947 839 var box = boxes[i];
948 - if (box.id == id) {
840 + if( box.id == id ) {
949 841 return box;
950 842 }
951 843 }
844 +}
952 845
953 - throw new Error("No box exists with ID " + id);
954 -};
955 -
956 846 // dismiss a single box (or all by omitting id param)
957 -Boxzilla.dismiss = function (id) {
847 +Boxzilla.dismiss = function(id) {
958 848 // if no id given, dismiss all current open boxes
959 - if (typeof id === "undefined") {
960 - boxes.forEach(function (box) {
961 - box.dismiss();
962 - });
963 - } else if (_typeof(boxes[id]) === "object") {
849 + if( typeof(id) === "undefined" ) {
850 + boxes.forEach(function(box) { box.dismiss(); });
851 + } else if( typeof( boxes[id] ) === "object" ) {
964 852 Boxzilla.get(id).dismiss();
965 853 }
966 854 };
967 855
968 -Boxzilla.hide = function (id) {
969 - if (typeof id === "undefined") {
970 - boxes.forEach(function (box) {
971 - box.hide();
972 - });
856 +Boxzilla.hide = function(id) {
857 + if( typeof(id) === "undefined" ) {
858 + boxes.forEach(function(box) { box.hide(); });
973 859 } else {
974 860 Boxzilla.get(id).hide();
975 861 }
976 862 };
977 863
978 -Boxzilla.show = function (id) {
979 - if (typeof id === "undefined") {
980 - boxes.forEach(function (box) {
981 - box.show();
982 - });
983 - } else {
864 +Boxzilla.show = function(id) {
865 + if( typeof(id) === "undefined" ) {
866 + boxes.forEach(function(box) { box.show(); });
867 + } else if( typeof( boxes[id] ) === "object" ) {
984 868 Boxzilla.get(id).show();
985 869 }
986 870 };
987 871
988 -Boxzilla.toggle = function (id) {
989 - if (typeof id === "undefined") {
990 - boxes.forEach(function (box) {
991 - box.toggle();
992 - });
993 - } else {
872 +Boxzilla.toggle = function(id) {
873 + if( typeof(id) === "undefined" ) {
874 + boxes.forEach(function(box) { box.toggle(); });
875 + } else if( typeof( boxes[id] ) === "object" ) {
994 876 Boxzilla.get(id).toggle();
995 877 }
996 878 };
997 879
@@ -997,41 +879,36 @@
997 879
998 880 // expose each individual box.
999 881 Boxzilla.boxes = boxes;
1000 882
1001 -// expose boxzilla object
1002 883 window.Boxzilla = Boxzilla;
1003 884
1004 -if (typeof module !== 'undefined' && module.exports) {
885 +if ( typeof module !== 'undefined' && module.exports ) {
1005 886 module.exports = Boxzilla;
1006 887 }
1007 -
1008 888 },{"./box.js":3,"./styles.js":5,"./timer.js":6,"wolfy87-eventemitter":7}],5:[function(require,module,exports){
1009 -"use strict";
1010 -
1011 -var styles = "#boxzilla-overlay{position:fixed;background:rgba(0,0,0,.65);width:100%;height:100%;left:0;top:0;z-index:99999}.boxzilla-center-container{position:fixed;top:0;left:0;right:0;height:0;text-align:center;z-index:999999;line-height:0}.boxzilla-center-container .boxzilla{display:inline-block;text-align:left;position:relative;line-height:normal}.boxzilla{position:fixed;z-index:999999;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;background:#fff;padding:25px}.boxzilla.boxzilla-top-left{top:0;left:0}.boxzilla.boxzilla-top-right{top:0;right:0}.boxzilla.boxzilla-bottom-left{bottom:0;left:0}.boxzilla.boxzilla-bottom-right{bottom:0;right:0}.boxzilla-content>:first-child{margin-top:0;padding-top:0}.boxzilla-content>:last-child{margin-bottom:0;padding-bottom:0}.boxzilla-close-icon{position:absolute;right:0;top:0;text-align:center;padding:6px;cursor:pointer;-webkit-appearance:none;font-size:28px;font-weight:700;line-height:20px;color:#000;opacity:.5}.boxzilla-close-icon:focus,.boxzilla-close-icon:hover{opacity:.8}";
889 +const styles = `#boxzilla-overlay{position:fixed;background:rgba(0,0,0,.65);width:100%;height:100%;left:0;top:0;z-index:99999}.boxzilla-center-container{position:fixed;top:0;left:0;right:0;height:0;text-align:center;z-index:999999;line-height:0}.boxzilla-center-container .boxzilla{display:inline-block;text-align:left;position:relative;line-height:normal}.boxzilla{position:fixed;z-index:999999;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;background:#fff;padding:25px}.boxzilla.boxzilla-top-left{top:0;left:0}.boxzilla.boxzilla-top-right{top:0;right:0}.boxzilla.boxzilla-bottom-left{bottom:0;left:0}.boxzilla.boxzilla-bottom-right{bottom:0;right:0}.boxzilla-content>:first-child{margin-top:0;padding-top:0}.boxzilla-content>:last-child{margin-bottom:0;padding-bottom:0}.boxzilla-close-icon{position:absolute;right:0;top:0;text-align:center;padding:6px;cursor:pointer;-webkit-appearance:none;font-size:28px;font-weight:700;line-height:20px;color:#000;opacity:.5}.boxzilla-close-icon:focus,.boxzilla-close-icon:hover{opacity:.8}`;
1012 890 module.exports = styles;
1013 -
1014 891 },{}],6:[function(require,module,exports){
1015 892 'use strict';
1016 893
1017 -var Timer = function Timer(start) {
894 +var Timer = function(start) {
1018 895 this.time = start;
1019 896 this.interval = 0;
1020 897 };
1021 898
1022 -Timer.prototype.tick = function () {
899 +Timer.prototype.tick = function() {
1023 900 this.time++;
1024 901 };
1025 902
1026 -Timer.prototype.start = function () {
1027 - if (!this.interval) {
903 +Timer.prototype.start = function() {
904 + if( ! this.interval ) {
1028 905 this.interval = window.setInterval(this.tick.bind(this), 1000);
1029 906 }
1030 907 };
1031 908
1032 -Timer.prototype.stop = function () {
1033 - if (this.interval) {
909 +Timer.prototype.stop = function() {
910 + if( this.interval ) {
1034 911 window.clearInterval(this.interval);
1035 912 this.interval = 0;
1036 913 }
1037 914 };
@@ -1036,9 +913,8 @@
1036 913 }
1037 914 };
1038 915
1039 916 module.exports = Timer;
1040 -
1041 917 },{}],7:[function(require,module,exports){
1042 918 /*!
1043 919 * EventEmitter v4.2.11 - git.io/ee
1044 920 * Unlicense - http://unlicense.org/