PluginProbe
Boxzilla – WordPress Popup Builder / 3.2.21
Boxzilla – WordPress Popup Builder v3.2.21
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 +910 -927 3.0.23.2.21 View file →
@@ -1,1139 +1,1122 @@
1 -(function () { var require = 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 -'use strict';
1 +(function () { var require = undefined; var module = undefined; var exports = undefined; var define = undefined; (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2 +"use strict";
3 3
4 -var Boxzilla = require('boxzilla');
5 -var options = window.boxzilla_options;
6 -var isLoggedIn = document.body.className.indexOf('logged-in') > -1;
4 +function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
7 5
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 -}
6 +(function () {
7 + var Boxzilla = require('boxzilla');
12 8
13 -// init boxzilla
14 -Boxzilla.init();
9 + var options = window.boxzilla_options; // helper function for setting CSS styles
15 10
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;
11 + function css(element, styles) {
12 + if (styles.background_color) {
13 + element.style.background = styles.background_color;
14 + }
21 15
22 - // create box
23 - var box = Boxzilla.create( boxOpts.id, boxOpts);
24 -
25 - // add custom css to box
26 - css(box.element, boxOpts.css);
27 -}
16 + if (styles.color) {
17 + element.style.color = styles.color;
18 + }
28 19
29 -function css(element, styles) {
30 - if( styles.background_color ) {
31 - element.style.background = styles.background_color;
20 + if (styles.border_color) {
21 + element.style.borderColor = styles.border_color;
32 22 }
33 23
34 - if( styles.color ) {
35 - element.style.color = styles.color;
24 + if (styles.border_width) {
25 + element.style.borderWidth = parseInt(styles.border_width) + 'px';
36 26 }
37 27
38 - if( styles.border_color ) {
39 - element.style.borderColor = styles.border_color;
28 + if (styles.border_style) {
29 + element.style.borderStyle = styles.border_style;
40 30 }
41 31
42 - if( styles.border_width ) {
43 - element.style.borderWidth = parseInt(styles.border_width) + "px";
32 + if (styles.width) {
33 + element.style.maxWidth = parseInt(styles.width) + 'px';
44 34 }
35 + }
45 36
46 - if( styles.border_style ) {
47 - element.style.borderStyle = styles.border_style;
37 + function createBoxesFromConfig() {
38 + // failsafe against including script twice.
39 + if (options.inited) {
40 + return;
41 + } // create boxes from options
42 +
43 +
44 + for (var key in options.boxes) {
45 + // get opts
46 + var boxOpts = options.boxes[key];
47 + boxOpts.testMode = isLoggedIn && options.testMode; // find box content element, bail if not found
48 +
49 + var boxContentElement = document.getElementById('boxzilla-box-' + boxOpts.id + '-content');
50 +
51 + if (!boxContentElement) {
52 + continue;
53 + } // use element as content option
54 +
55 +
56 + boxOpts.content = boxContentElement; // create box
57 +
58 + var box = Boxzilla.create(boxOpts.id, boxOpts); // add box slug to box element as classname
59 +
60 + box.element.className = box.element.className + ' boxzilla-' + boxOpts.post.slug; // add custom css to box
61 +
62 + css(box.element, boxOpts.css);
63 +
64 + try {
65 + box.element.firstChild.firstChild.className += ' first-child';
66 + box.element.firstChild.lastChild.className += ' last-child';
67 + } catch (e) {} // maybe show box right away
68 +
69 +
70 + if (box.fits() && locationHashRefersBox(box)) {
71 + box.show();
72 + }
73 + } // set flag to prevent initialising twice
74 +
75 +
76 + options.inited = true; // trigger "done" event.
77 +
78 + Boxzilla.trigger('done'); // maybe open box with MC4WP form in it
79 +
80 + maybeOpenMailChimpForWordPressBox();
81 + }
82 +
83 + function locationHashRefersBox(box) {
84 + if (!window.location.hash || window.location.hash.length === 0) {
85 + return false;
86 + } // parse "boxzilla-{id}" from location hash
87 +
88 +
89 + var match = window.location.hash.match(/[#&](boxzilla-\d+)/);
90 +
91 + if (!match || _typeof(match) !== 'object' || match.length < 2) {
92 + return false;
48 93 }
49 94
50 - if( styles.width ) {
51 - element.style.maxWidth = parseInt(styles.width) + "px";
95 + var elementId = match[1];
96 +
97 + if (elementId === box.element.id) {
98 + return true;
99 + } else if (box.element.querySelector('#' + elementId)) {
100 + return true;
52 101 }
102 +
103 + return false;
104 + }
105 +
106 + function maybeOpenMailChimpForWordPressBox() {
107 + if ((_typeof(window.mc4wp_forms_config) !== 'object' || !window.mc4wp_forms_config.submitted_form) && _typeof(window.mc4wp_submitted_form) !== 'object') {
108 + return;
109 + }
110 +
111 + var form = window.mc4wp_submitted_form || window.mc4wp_forms_config.submitted_form;
112 + var selector = '#' + form.element_id;
113 + Boxzilla.boxes.forEach(function (box) {
114 + if (box.element.querySelector(selector)) {
115 + box.show();
116 + }
117 + });
118 + } // print message when test mode is enabled
119 +
120 +
121 + var isLoggedIn = document.body.className.indexOf('logged-in') > -1;
122 +
123 + if (isLoggedIn && options.testMode) {
124 + console.log('Boxzilla: Test mode is enabled. Please disable test mode if you\'re done testing.');
125 + } // init boxzilla
126 +
127 +
128 + Boxzilla.init(); // on window.load, create DOM elements for boxes
129 +
130 + window.addEventListener('load', createBoxesFromConfig);
131 +})();
132 +
133 +},{"boxzilla":4}],2:[function(require,module,exports){
134 +"use strict";
135 +
136 +var duration = 320;
137 +
138 +function css(element, styles) {
139 + for (var property in styles) {
140 + if (!styles.hasOwnProperty(property)) {
141 + continue;
142 + }
143 +
144 + element.style[property] = styles[property];
145 + }
53 146 }
54 147
55 -window.Boxzilla = Boxzilla;
56 -},{"boxzilla":3}],2:[function(require,module,exports){
57 -'use strict';
148 +function initObjectProperties(properties, value) {
149 + var newObject = {};
58 150
59 -var $ = window.jQuery,
60 - defaults = {
61 - 'animation': 'fade',
62 - 'rehide': false,
63 - 'content': '',
64 - 'cookieTime': 0,
65 - 'icon': '&times',
66 - 'minimumScreenWidth': 0,
67 - 'position': 'center',
68 - 'testMode': false,
69 - 'trigger': false,
70 - 'closable': true
71 - }, Boxzilla;
151 + for (var i = 0; i < properties.length; i++) {
152 + newObject[properties[i]] = value;
153 + }
72 154
155 + return newObject;
156 +}
157 +
158 +function copyObjectProperties(properties, object) {
159 + var newObject = {};
160 +
161 + for (var i = 0; i < properties.length; i++) {
162 + newObject[properties[i]] = object[properties[i]];
163 + }
164 +
165 + return newObject;
166 +}
73 167 /**
74 - * Merge 2 objects, values of the latter overwriting the former.
168 + * Checks if the given element is currently being animated.
75 169 *
76 - * @param obj1
77 - * @param obj2
78 - * @returns {*}
170 + * @param element
171 + * @returns {boolean}
79 172 */
80 -function merge( obj1, obj2 ) {
81 - var obj3 = {};
82 - for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; }
83 - for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; }
84 - return obj3;
173 +
174 +
175 +function animated(element) {
176 + return !!element.getAttribute('data-animated');
85 177 }
178 +/**
179 + * Toggles the element using the given animation.
180 + *
181 + * @param element
182 + * @param animation Either "fade" or "slide"
183 + * @param callbackFn
184 + */
86 185
87 -// Box Object
88 -var Box = function( id, config ) {
89 - this.id = id;
90 186
91 - // store config values
92 - this.config = merge(defaults, config);
187 +function toggle(element, animation, callbackFn) {
188 + var nowVisible = element.style.display !== 'none' || element.offsetLeft > 0; // create clone for reference
93 189
94 - // store ref to overlay
95 - this.overlay = document.getElementById('boxzilla-overlay');
190 + var clone = element.cloneNode(true);
96 191
97 - // state
98 - this.visible = false;
99 - this.closed = false;
100 - this.triggered = false;
101 - this.triggerHeight = 0;
102 - this.cookieSet = false;
192 + var cleanup = function cleanup() {
193 + element.removeAttribute('data-animated');
194 + element.setAttribute('style', clone.getAttribute('style'));
195 + element.style.display = nowVisible ? 'none' : '';
103 196
104 - // if a trigger was given, calculate values once and store
105 - if( this.config.trigger ) {
106 - if( this.config.trigger.method === 'percentage' || this.config.trigger.method === 'element' ) {
107 - this.triggerHeight = this.calculateTriggerHeight();
108 - }
197 + if (callbackFn) {
198 + callbackFn();
199 + }
200 + }; // store attribute so everyone knows we're animating this element
109 201
110 - this.cookieSet = this.isCookieSet();
111 - }
112 202
113 - // create dom element for this box
114 - this.element = this.dom();
115 - this.$element = $(this.element);
203 + element.setAttribute('data-animated', 'true'); // toggle element visiblity right away if we're making something visible
116 204
117 - // further initialise the box
118 - this.events();
119 -};
205 + if (!nowVisible) {
206 + element.style.display = '';
207 + }
120 208
121 -// initialise the box
122 -Box.prototype.events = function() {
123 - var box = this;
209 + var hiddenStyles;
210 + var visibleStyles; // animate properties
124 211
125 - // attach event to "close" icon inside box
126 - this.$element.find('.boxzilla-close-icon').click(box.dismiss.bind(this));
212 + if (animation === 'slide') {
213 + hiddenStyles = initObjectProperties(['height', 'borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom'], 0);
214 + visibleStyles = {};
127 215
128 - this.$element.on('click', 'a', function(e) {
129 - Boxzilla.trigger('box.interactions.link', [ box, e.target ] );
130 - });
216 + if (!nowVisible) {
217 + var computedStyles = window.getComputedStyle(element);
218 + visibleStyles = copyObjectProperties(['height', 'borderTopWidth', 'borderBottomWidth', 'paddingTop', 'paddingBottom'], computedStyles); // in some browsers, getComputedStyle returns "auto" value. this falls back to getBoundingClientRect() in those browsers since we need an actual height.
131 219
132 - this.$element.on('submit', 'form', function(e) {
133 - box.setCookie();
134 - Boxzilla.trigger('box.interactions.form', [ box, e.target ]);
135 - });
220 + if (!isFinite(visibleStyles.height)) {
221 + var clientRect = element.getBoundingClientRect();
222 + visibleStyles.height = clientRect.height;
223 + }
136 224
137 - // attach event to all links referring #boxzilla-{box_id}
138 - $(document.body).on('click', 'a[href="#boxzilla-' + box.id + '"]', function() {
139 - box.toggle();
140 - return false;
141 - });
225 + css(element, hiddenStyles);
226 + } // don't show a scrollbar during animation
142 227
143 - // maybe show box right away
144 - if( this.fits() && this.locationHashRefersBox() ) {
145 - $(window).load(this.show.bind(this));
228 +
229 + element.style.overflowY = 'hidden';
230 + animate(element, nowVisible ? hiddenStyles : visibleStyles, cleanup);
231 + } else {
232 + hiddenStyles = {
233 + opacity: 0
234 + };
235 + visibleStyles = {
236 + opacity: 1
237 + };
238 +
239 + if (!nowVisible) {
240 + css(element, hiddenStyles);
146 241 }
147 242
148 -};
243 + animate(element, nowVisible ? hiddenStyles : visibleStyles, cleanup);
244 + }
245 +}
149 246
150 -// generate dom elements for this box
151 -Box.prototype.dom = function() {
152 - var wrapper = document.createElement('div');
153 - wrapper.className = 'boxzilla-container boxzilla-' + this.config.position + '-container';
247 +function animate(element, targetStyles, fn) {
248 + var last = +new Date();
249 + var initialStyles = window.getComputedStyle(element);
250 + var currentStyles = {};
251 + var propSteps = {};
154 252
155 - var box = document.createElement('div');
156 - box.className = 'boxzilla boxzilla-' + this.id + ' boxzilla-' + this.config.position;
157 - box.style.display = 'none';
158 - wrapper.appendChild(box);
253 + for (var property in targetStyles) {
254 + if (!targetStyles.hasOwnProperty(property)) {
255 + continue;
256 + } // make sure we have an object filled with floats
159 257
160 - var content = document.createElement('div');
161 - content.className = 'boxzilla-content';
162 - content.innerHTML = this.config.content;
163 - box.appendChild(content);
164 258
165 - // remove <script> from box content and append them to head
166 - var scripts = content.querySelectorAll('script');
167 - if(scripts.length) {
168 - var script = document.createElement('script');
169 - for( var i=0; i<scripts.length; i++ ) {
170 - script.appendChild(document.createTextNode(scripts[i].text));
171 - scripts[i].parentNode.removeChild(scripts[i]);
172 - }
173 - document.head.appendChild(script);
259 + targetStyles[property] = parseFloat(targetStyles[property]); // calculate step size & current value
260 +
261 + var to = targetStyles[property];
262 + var current = parseFloat(initialStyles[property]); // is there something to do?
263 +
264 + if (current === to) {
265 + delete targetStyles[property];
266 + continue;
174 267 }
175 268
176 - if( this.config.closable && this.config.icon ) {
177 - var icon = document.createElement('span');
178 - icon.className = "boxzilla-close-icon";
179 - icon.innerHTML = this.config.icon;
180 - box.appendChild(icon);
181 - }
269 + propSteps[property] = (to - current) / duration; // points per second
182 270
183 - document.body.appendChild(wrapper);
271 + currentStyles[property] = current;
272 + }
184 273
185 - return box;
186 -};
274 + var tick = function tick() {
275 + var now = +new Date();
276 + var timeSinceLastTick = now - last;
277 + var done = true;
278 + var step, to, increment, newValue;
187 279
188 -// set (calculate) custom box styling depending on box options
189 -Box.prototype.setCustomBoxStyling = function() {
280 + for (var _property in targetStyles) {
281 + if (!targetStyles.hasOwnProperty(_property)) {
282 + continue;
283 + }
190 284
191 - // reset element to its initial state
192 - this.element.style.overflowY = 'auto';
193 - this.element.style.maxHeight = 'none';
285 + step = propSteps[_property];
286 + to = targetStyles[_property];
287 + increment = step * timeSinceLastTick;
288 + newValue = currentStyles[_property] + increment;
194 289
195 - // get new dimensions
196 - var windowHeight = window.innerHeight;
197 - var boxHeight = this.$element.outerHeight();
290 + if (step > 0 && newValue >= to || step < 0 && newValue <= to) {
291 + newValue = to;
292 + } else {
293 + done = false;
294 + } // store new value
198 295
199 - // add scrollbar to box and limit height
200 - if( boxHeight > windowHeight ) {
201 - this.element.style.maxHeight = windowHeight + "px";
202 - this.element.style.overflowY = 'scroll';
296 +
297 + currentStyles[_property] = newValue;
298 + element.style[_property] = _property !== 'opacity' ? newValue + 'px' : newValue;
203 299 }
204 300
205 - // set new top margin for boxes which are centered
206 - if( this.config.position === 'center' ) {
207 - var newTopMargin = ( ( windowHeight - boxHeight ) / 2 );
208 - newTopMargin = newTopMargin >= 0 ? newTopMargin : 0;
209 - this.element.style.marginTop = newTopMargin + "px";
301 + last = +new Date();
302 +
303 + if (!done) {
304 + // keep going until we're done for all props
305 + window.requestAnimationFrame(tick);
306 + } else {
307 + // call callback
308 + fn && fn();
210 309 }
310 + };
211 311
312 + tick();
313 +}
314 +
315 +module.exports = {
316 + toggle: toggle,
317 + animate: animate,
318 + animated: animated
212 319 };
213 320
214 -// toggle visibility of the box
215 -Box.prototype.toggle = function(show) {
321 +},{}],3:[function(require,module,exports){
322 +"use strict";
216 323
217 - // revert visibility if no explicit argument is given
218 - if( typeof( show ) === "undefined" ) {
219 - show = ! this.visible;
324 +var defaults = {
325 + animation: 'fade',
326 + rehide: false,
327 + content: '',
328 + cookie: null,
329 + icon: '&times',
330 + screenWidthCondition: null,
331 + position: 'center',
332 + testMode: false,
333 + trigger: false,
334 + closable: true
335 +};
336 +
337 +var Animator = require('./animator.js');
338 +/**
339 + * Merge 2 objects, values of the latter overwriting the former.
340 + *
341 + * @param obj1
342 + * @param obj2
343 + * @returns {*}
344 + */
345 +
346 +
347 +function merge(obj1, obj2) {
348 + var obj3 = {}; // add obj1 to obj3
349 +
350 + for (var attrname in obj1) {
351 + if (obj1.hasOwnProperty(attrname)) {
352 + obj3[attrname] = obj1[attrname];
220 353 }
354 + } // add obj2 to obj3
221 355
222 - // do nothing if element is being animated
223 - if( this.$element.is(':animated') ) {
224 - return false;
356 +
357 + for (var _attrname in obj2) {
358 + if (obj2.hasOwnProperty(_attrname)) {
359 + obj3[_attrname] = obj2[_attrname];
225 360 }
361 + }
226 362
227 - // is box already at desired visibility?
228 - if( show === this.visible ) {
229 - return false;
363 + return obj3;
364 +}
365 +/**
366 + * Get the real height of entire document.
367 + * @returns {number}
368 + */
369 +
370 +
371 +function getDocumentHeight() {
372 + var body = document.body;
373 + var html = document.documentElement;
374 + return Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
375 +} // Box Object
376 +
377 +
378 +function Box(id, config, fireEvent) {
379 + this.id = id;
380 + this.fireEvent = fireEvent; // store config values
381 +
382 + this.config = merge(defaults, config); // add overlay element to dom and store ref to overlay
383 +
384 + this.overlay = document.createElement('div');
385 + this.overlay.style.display = 'none';
386 + this.overlay.id = 'boxzilla-overlay-' + this.id;
387 + this.overlay.classList.add('boxzilla-overlay');
388 + document.body.appendChild(this.overlay); // state
389 +
390 + this.visible = false;
391 + this.dismissed = false;
392 + this.triggered = false;
393 + this.triggerHeight = this.calculateTriggerHeight();
394 + this.cookieSet = this.isCookieSet();
395 + this.element = null;
396 + this.contentElement = null;
397 + this.closeIcon = null; // create dom elements for this box
398 +
399 + this.dom(); // further initialise the box
400 +
401 + this.events();
402 +} // initialise the box
403 +
404 +
405 +Box.prototype.events = function () {
406 + var box = this; // attach event to "close" icon inside box
407 +
408 + if (this.closeIcon) {
409 + this.closeIcon.addEventListener('click', function (evt) {
410 + evt.preventDefault();
411 + box.dismiss();
412 + });
413 + }
414 +
415 + this.element.addEventListener('click', function (evt) {
416 + if (evt.target.tagName === 'A') {
417 + this.fireEvent('box.interactions.link', [box, evt.target]);
230 418 }
419 + }, false);
420 + this.element.addEventListener('submit', function (evt) {
421 + box.setCookie();
422 + this.fireEvent('box.interactions.form', [box, evt.target]);
423 + }, false);
424 + this.overlay.addEventListener('click', function (e) {
425 + var x = e.offsetX;
426 + var y = e.offsetY; // calculate if click was less than 40px outside box to avoid closing it by accident
231 427
232 - // if box should be hidden but is not closable, bail.
233 - if( ! show && ! this.config.closable ) {
234 - return false;
428 + var rect = box.element.getBoundingClientRect();
429 + var margin = 40; // if click was not anywhere near box, dismiss it.
430 +
431 + if (x < rect.left - margin || x > rect.right + margin || y < rect.top - margin || y > rect.bottom + margin) {
432 + box.dismiss();
235 433 }
434 + });
435 +}; // generate dom elements for this box
236 436
237 - // set new visibility status
238 - this.visible = show;
239 437
240 - // calculate custom styling for which CSS is "too stupid"
241 - this.setCustomBoxStyling();
438 +Box.prototype.dom = function () {
439 + var wrapper = document.createElement('div');
440 + wrapper.className = 'boxzilla-container boxzilla-' + this.config.position + '-container';
441 + var box = document.createElement('div');
442 + box.id = 'boxzilla-' + this.id;
443 + box.className = 'boxzilla boxzilla-' + this.id + ' boxzilla-' + this.config.position;
444 + box.style.display = 'none';
445 + wrapper.appendChild(box);
446 + var content;
242 447
243 - // fadein / fadeout the overlay if position is "center"
244 - if( this.config.position === 'center' ) {
245 - $(this.overlay).fadeToggle('slow');
246 - }
448 + if (typeof this.config.content === 'string') {
449 + content = document.createElement('div');
450 + content.innerHTML = this.config.content;
451 + } else {
452 + content = this.config.content; // make sure element is visible
247 453
248 - // trigger event
249 - Boxzilla.trigger('box.' + ( show ? 'show' : 'hide' ), [ this ] );
454 + content.style.display = '';
455 + }
250 456
251 - // show or hide box using selected animation
252 - if( this.config.animation === 'fade' ) {
253 - this.$element.fadeToggle( 'slow' );
457 + content.className = 'boxzilla-content';
458 + box.appendChild(content);
459 +
460 + if (this.config.closable && this.config.icon) {
461 + var closeIcon = document.createElement('span');
462 + closeIcon.className = 'boxzilla-close-icon';
463 + closeIcon.innerHTML = this.config.icon;
464 + box.appendChild(closeIcon);
465 + this.closeIcon = closeIcon;
466 + }
467 +
468 + document.body.appendChild(wrapper);
469 + this.contentElement = content;
470 + this.element = box;
471 +}; // set (calculate) custom box styling depending on box options
472 +
473 +
474 +Box.prototype.setCustomBoxStyling = function () {
475 + // reset element to its initial state
476 + var origDisplay = this.element.style.display;
477 + this.element.style.display = '';
478 + this.element.style.overflowY = '';
479 + this.element.style.maxHeight = ''; // get new dimensions
480 +
481 + var windowHeight = window.innerHeight;
482 + var boxHeight = this.element.clientHeight; // add scrollbar to box and limit height
483 +
484 + if (boxHeight > windowHeight) {
485 + this.element.style.maxHeight = windowHeight + 'px';
486 + this.element.style.overflowY = 'scroll';
487 + } // set new top margin for boxes which are centered
488 +
489 +
490 + if (this.config.position === 'center') {
491 + var newTopMargin = (windowHeight - boxHeight) / 2;
492 + newTopMargin = newTopMargin >= 0 ? newTopMargin : 0;
493 + this.element.style.marginTop = newTopMargin + 'px';
494 + }
495 +
496 + this.element.style.display = origDisplay;
497 +}; // toggle visibility of the box
498 +
499 +
500 +Box.prototype.toggle = function (show, animate) {
501 + show = typeof show === 'undefined' ? !this.visible : show;
502 + animate = typeof animate === 'undefined' ? true : animate; // is box already at desired visibility?
503 +
504 + if (show === this.visible) {
505 + return false;
506 + } // is box being animated?
507 +
508 +
509 + if (Animator.animated(this.element)) {
510 + return false;
511 + } // if box should be hidden but is not closable, bail.
512 +
513 +
514 + if (!show && !this.config.closable) {
515 + return false;
516 + } // set new visibility status
517 +
518 +
519 + this.visible = show; // calculate new styling rules
520 +
521 + this.setCustomBoxStyling(); // trigger event
522 +
523 + this.fireEvent('box.' + (show ? 'show' : 'hide'), [this]); // show or hide box using selected animation
524 +
525 + if (this.config.position === 'center') {
526 + this.overlay.classList.toggle('boxzilla-' + this.id + '-overlay');
527 +
528 + if (animate) {
529 + Animator.toggle(this.overlay, 'fade');
254 530 } else {
255 - this.$element.slideToggle( 'slow' );
531 + this.overlay.style.display = show ? '' : 'none';
256 532 }
533 + }
257 534
258 - // // focus on first input field in box
259 - // this.$element.find('input').first().focus();
535 + if (animate) {
536 + Animator.toggle(this.element, this.config.animation, function () {
537 + if (this.visible) {
538 + return;
539 + }
260 540
261 - return true;
262 -};
541 + this.contentElement.innerHTML = this.contentElement.innerHTML + '';
542 + }.bind(this));
543 + } else {
544 + this.element.style.display = show ? '' : 'none';
545 + }
263 546
264 -// show the box
265 -Box.prototype.show = function() {
266 - return this.toggle(true);
267 -};
547 + return true;
548 +}; // show the box
268 549
269 -// hide the box
270 -Box.prototype.hide = function() {
271 - return this.toggle(false);
272 -};
273 550
274 -// calculate trigger height
275 -Box.prototype.calculateTriggerHeight = function() {
276 - var triggerHeight = 0;
551 +Box.prototype.show = function (animate) {
552 + return this.toggle(true, animate);
553 +}; // hide the box
277 554
278 - if( this.config.trigger.method === 'element' ) {
279 - var $triggerElement = $(this.config.trigger.value).first();
280 - triggerHeight = ( $triggerElement.length > 0 ) ? $triggerElement.offset().top : 0;
281 - } else if( this.config.trigger.method === 'percentage' ) {
282 - triggerHeight = ( this.config.trigger.value / 100 * $(document).height() );
555 +
556 +Box.prototype.hide = function (animate) {
557 + return this.toggle(false, animate);
558 +}; // calculate trigger height
559 +
560 +
561 +Box.prototype.calculateTriggerHeight = function () {
562 + var triggerHeight = 0;
563 +
564 + if (this.config.trigger) {
565 + if (this.config.trigger.method === 'element') {
566 + var triggerElement = document.body.querySelector(this.config.trigger.value);
567 +
568 + if (triggerElement) {
569 + var offset = triggerElement.getBoundingClientRect();
570 + triggerHeight = offset.top;
571 + }
572 + } else if (this.config.trigger.method === 'percentage') {
573 + triggerHeight = this.config.trigger.value / 100 * getDocumentHeight();
283 574 }
575 + }
284 576
285 - return triggerHeight;
577 + return triggerHeight;
286 578 };
287 579
288 -// set cookie that disables automatically showing the box
289 -Box.prototype.setCookie = function() {
290 - // do nothing if cookieTime evaluates to false
291 - if(! this.config.cookieTime) {
292 - return;
293 - }
580 +Box.prototype.fits = function () {
581 + if (!this.config.screenWidthCondition || !this.config.screenWidthCondition.value) {
582 + return true;
583 + }
294 584
295 - var expiryDate = new Date();
296 - expiryDate.setDate( expiryDate.getDate() + this.config.cookieTime );
297 - document.cookie = 'boxzilla_box_'+ this.id + '=true; expires='+ expiryDate.toUTCString() +'; path=/';
585 + switch (this.config.screenWidthCondition.condition) {
586 + case 'larger':
587 + return window.innerWidth > this.config.screenWidthCondition.value;
588 +
589 + case 'smaller':
590 + return window.innerWidth < this.config.screenWidthCondition.value;
591 + } // meh.. condition should be "smaller" or "larger", just return true.
592 +
593 +
594 + return true;
298 595 };
299 596
300 -// checks whether window.location.hash equals the box element ID or that of any element inside the box
301 -Box.prototype.locationHashRefersBox = function() {
597 +Box.prototype.onResize = function () {
598 + this.triggerHeight = this.calculateTriggerHeight();
599 + this.setCustomBoxStyling();
600 +}; // is this box enabled?
302 601
303 - if( ! window.location.hash || 0 === window.location.hash.length ) {
304 - return false;
305 - }
306 602
307 - var elementId = window.location.hash.substring(1);
308 - if( elementId === this.element.id ) {
309 - return true;
310 - } else if( this.element.querySelector('#' + elementId) ) {
311 - return true;
312 - }
603 +Box.prototype.mayAutoShow = function () {
604 + if (this.dismissed) {
605 + return false;
606 + } // check if box fits on given minimum screen width
313 607
608 +
609 + if (!this.fits()) {
314 610 return false;
611 + } // if trigger empty or error in calculating triggerHeight, return false
612 +
613 +
614 + if (!this.config.trigger) {
615 + return false;
616 + } // rely on cookie value (show if not set, don't show if set)
617 +
618 +
619 + return !this.cookieSet;
315 620 };
316 621
317 -Box.prototype.fits = function() {
318 - if( this.config.minimumScreenWidth <= 0 ) {
319 - return true;
320 - }
622 +Box.prototype.mayRehide = function () {
623 + return this.config.rehide && this.triggered;
624 +};
321 625
322 - return window.innerWidth > this.config.minimumScreenWidth
323 -};
626 +Box.prototype.isCookieSet = function () {
627 + // always show on test mode or when no auto-trigger is configured
628 + if (this.config.testMode || !this.config.trigger) {
629 + return false;
630 + } // if either cookie is null or trigger & dismiss are both falsey, don't bother checking.
324 631
325 -// is this box enabled?
326 -Box.prototype.mayAutoShow = function() {
327 632
328 - // don't show if box was closed (dismissed) before
329 - if( this.closed ) {
330 - return false;
331 - }
633 + if (!this.config.cookie || !this.config.cookie.triggered && !this.config.cookie.dismissed) {
634 + return false;
635 + }
332 636
333 - // check if box fits on given minimum screen width
334 - if( ! this.fits() ) {
335 - return false;
336 - }
637 + return document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + 'boxzilla_box_' + this.id + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1') === 'true';
638 +}; // set cookie that disables automatically showing the box
337 639
338 - // if trigger empty or error in calculating triggerHeight, return false
339 - if( ! this.config.trigger ) {
340 - return false;
341 - }
342 640
343 - // rely on cookie value (show if not set, don't show if set)
344 - return ! this.cookieSet;
641 +Box.prototype.setCookie = function (hours) {
642 + var expiryDate = new Date();
643 + expiryDate.setHours(expiryDate.getHours() + hours);
644 + document.cookie = 'boxzilla_box_' + this.id + '=true; expires=' + expiryDate.toUTCString() + '; path=/';
345 645 };
346 646
347 -Box.prototype.mayRehide = function() {
348 - return this.config.rehide && this.triggered;
647 +Box.prototype.trigger = function () {
648 + var shown = this.show();
649 +
650 + if (!shown) {
651 + return;
652 + }
653 +
654 + this.triggered = true;
655 +
656 + if (this.config.cookie && this.config.cookie.triggered) {
657 + this.setCookie(this.config.cookie.triggered);
658 + }
349 659 };
660 +/**
661 + * Dismisses the box and optionally sets a cookie.
662 + * @param animate
663 + * @returns {boolean}
664 + */
350 665
351 -Box.prototype.isCookieSet = function() {
352 - // always show on test mode
353 - if( this.config.testMode ) {
354 - return false;
355 - }
356 666
357 - // check for cookie
358 - if( ! this.config.cookieTime ) {
359 - return false;
360 - }
667 +Box.prototype.dismiss = function (animate) {
668 + // only dismiss box if it's currently open.
669 + if (!this.visible) {
670 + return false;
671 + } // hide box element
361 672
362 - var cookieSet = document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + 'boxzilla_box_' + this.id + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1") === "true";
363 - return cookieSet;
364 673
674 + this.hide(animate); // set cookie
675 +
676 + if (this.config.cookie && this.config.cookie.dismissed) {
677 + this.setCookie(this.config.cookie.dismissed);
678 + }
679 +
680 + this.dismissed = true;
681 + this.fireEvent('box.dismiss', [this]);
682 + return true;
365 683 };
366 684
367 -Box.prototype.trigger = function() {
368 - var shown = this.show();
369 - if( shown ) {
370 - this.triggered = true;
371 - }
372 -};
685 +module.exports = Box;
373 686
374 -Box.prototype.dismiss = function() {
375 - this.hide();
376 - this.setCookie();
377 - this.closed = true;
378 - Boxzilla.trigger('box.dismiss', [ this ]);
379 -};
687 +},{"./animator.js":2}],4:[function(require,module,exports){
688 +"use strict";
380 689
381 -module.exports = function(_Boxzilla) {
382 - Boxzilla = _Boxzilla;
383 - return Box;
384 -};
385 -},{}],3:[function(require,module,exports){
386 -'use strict';
690 +var Box = require('./box.js');
387 691
388 -var $ = window.jQuery,
389 - EventEmitter = require('wolfy87-eventemitter'),
390 - Boxzilla = Object.create(EventEmitter.prototype),
391 - Box = require('./Box.js')(Boxzilla),
392 - Timer = require('./Timer.js'),
393 - boxes = {},
394 - windowHeight = window.innerHeight,
395 - overlay = document.createElement('div'),
396 - exitIntentDelayTimer,
397 - exitIntentTriggered,
398 - siteTimer = new Timer(sessionStorage.getItem('boxzilla_timer') || 0),
399 - pageTimer = new Timer(0),
400 - pageViews = sessionStorage.getItem('boxzilla_pageviews') || 0;
692 +var throttle = require('./util.js').throttle;
401 693
402 -function each( obj, callback ) {
403 - for( var key in obj ) {
404 - if(! obj.hasOwnProperty(key)) continue;
405 - callback(obj[key]);
406 - }
407 -}
694 +var styles = require('./styles.js');
408 695
409 -function throttle(fn, threshhold, scope) {
410 - threshhold || (threshhold = 250);
411 - var last,
412 - deferTimer;
413 - return function () {
414 - var context = scope || this;
696 +var ExitIntent = require('./triggers/exit-intent.js');
415 697
416 - var now = +new Date,
417 - args = arguments;
418 - if (last && now < last + threshhold) {
419 - // hold on to it
420 - clearTimeout(deferTimer);
421 - deferTimer = setTimeout(function () {
422 - last = now;
423 - fn.apply(context, args);
424 - }, threshhold);
425 - } else {
426 - last = now;
427 - fn.apply(context, args);
428 - }
429 - };
430 -}
698 +var Scroll = require('./triggers/scroll.js');
431 699
432 -// "keyup" listener
433 -function onKeyUp(e) {
434 - if (e.keyCode == 27) {
435 - Boxzilla.dismiss();
436 - }
700 +var Pageviews = require('./triggers/pageviews.js');
701 +
702 +var Time = require('./triggers/time.js');
703 +
704 +var initialised = false;
705 +var boxes = [];
706 +var listeners = {};
707 +
708 +function onKeyUp(evt) {
709 + if (evt.key === 'Escape' || evt.key === 'Esc') {
710 + dismiss();
711 + }
437 712 }
438 713
439 -// check "pageviews" criteria for each box
440 -function checkPageViewsCriteria() {
441 - each(boxes, function(box) {
442 - if( ! box.mayAutoShow() ) {
443 - return;
444 - }
445 -
446 - if( box.config.trigger.method === 'pageviews' && pageViews >= box.config.trigger.value ) {
447 - box.trigger();
448 - }
449 - });
714 +function recalculateHeights() {
715 + boxes.forEach(function (box) {
716 + return box.onResize();
717 + });
450 718 }
451 719
452 -// check time trigger criteria for each box
453 -function checkTimeCriteria() {
454 - each(boxes, function(box) {
455 - if( ! box.mayAutoShow() ) {
456 - return;
457 - }
720 +function onElementClick(evt) {
721 + // bubble up to <a> element
722 + var el = evt.target;
458 723
459 - // check "time on site" trigger
460 - if (box.config.trigger.method === 'time_on_site' && siteTimer.time >= box.config.trigger.value) {
461 - box.trigger();
462 - }
724 + for (var i = 0; i <= 3; i++) {
725 + if (!el || el.tagName === 'A') {
726 + break;
727 + }
463 728
464 - // check "time on page" trigger
465 - if (box.config.trigger.method === 'time_on_page' && pageTimer.time >= box.config.trigger.value) {
466 - box.trigger();
467 - }
468 - });
469 -}
729 + el = el.parentElement;
730 + }
470 731
471 -// check triggerHeight criteria for all boxes
472 -function checkHeightCriteria() {
473 - var scrollY = window.scrollY;
474 - var scrollHeight = scrollY + ( windowHeight * 0.667 );
732 + if (!el || el.tagName !== 'A' || !el.href) {
733 + return;
734 + }
475 735
476 - each(boxes, function(box) {
477 - if( ! box.mayAutoShow() || box.triggerHeight <= 0 ) {
478 - return;
479 - }
736 + var match = el.href.match(/[#&]boxzilla-(.+)/i);
480 737
481 - if( scrollHeight > box.triggerHeight ) {
482 - box.trigger();
483 - } else if( box.mayRehide() ) {
484 - box.hide();
485 - }
486 - });
738 + if (match && match.length > 1) {
739 + toggle(match[1]);
740 + }
487 741 }
488 742
489 -// recalculate heights and variables based on height
490 -function recalculateHeights() {
491 - windowHeight = window.innerHeight;
743 +function trigger(event, args) {
744 + listeners[event] && listeners[event].forEach(function (f) {
745 + return f.apply(null, args);
746 + });
747 +}
492 748
493 - each(boxes, function(box) {
494 - box.setCustomBoxStyling();
495 - });
749 +function on(event, fn) {
750 + listeners[event] = listeners[event] || [];
751 + listeners[event].push(fn);
496 752 }
497 753
498 -function onOverlayClick(e) {
499 - var x = e.offsetX;
500 - var y = e.offsetY;
754 +function off(event, fn) {
755 + listeners[event] && listeners[event].filter(function (f) {
756 + return f !== fn;
757 + });
758 +} // initialise & add event listeners
501 759
502 - // calculate if click was near a box to avoid closing it (click error margin)
503 - each(boxes, function(box) {
504 - var rect = box.element.getBoundingClientRect();
505 - var margin = 100 + ( window.innerWidth * 0.05 );
506 760
507 - // if click was not anywhere near box, dismiss it.
508 - if( x < ( rect.left - margin ) || x > ( rect.right + margin ) || y < ( rect.top - margin ) || y > ( rect.bottom + margin ) ) {
509 - box.dismiss();
510 - }
511 - });
512 -}
761 +function init() {
762 + if (initialised) {
763 + return;
764 + } // insert styles into DOM
513 765
514 -function triggerExitIntent() {
515 - if(exitIntentTriggered) return;
516 766
517 - each(boxes, function(box) {
518 - if(box.mayAutoShow() && box.config.trigger.method === 'exit_intent' ) {
519 - box.trigger();
520 - }
521 - });
767 + var styleElement = document.createElement('style');
768 + styleElement.innerHTML = styles;
769 + document.head.appendChild(styleElement); // init triggers
522 770
523 - exitIntentTriggered = true;
771 + ExitIntent(boxes);
772 + Pageviews(boxes);
773 + Scroll(boxes);
774 + Time(boxes);
775 + document.body.addEventListener('click', onElementClick, true);
776 + window.addEventListener('resize', throttle(recalculateHeights));
777 + window.addEventListener('load', recalculateHeights);
778 + document.addEventListener('keyup', onKeyUp);
779 + trigger('ready');
780 + initialised = true; // ensure this function doesn't run again
524 781 }
525 782
526 -function onMouseLeave(e) {
527 - var delay = 400;
783 +function create(id, opts) {
784 + // preserve backwards compat for minimumScreenWidth option
785 + if (typeof opts.minimumScreenWidth !== 'undefined') {
786 + opts.screenWidthCondition = {
787 + condition: 'larger',
788 + value: opts.minimumScreenWidth
789 + };
790 + }
528 791
529 - // did mouse leave at top of window?
530 - if( e.clientY <= 0 ) {
531 - exitIntentDelayTimer = window.setTimeout(triggerExitIntent, delay);
532 - }
792 + id = String(id);
793 + var box = new Box(id, opts, trigger);
794 + boxes.push(box);
795 + return box;
533 796 }
534 797
535 -function onMouseEnter() {
536 - if( exitIntentDelayTimer ) {
537 - window.clearInterval(exitIntentDelayTimer);
538 - exitIntentDelayTimer = null;
539 - }
540 -}
798 +function get(id) {
799 + id = String(id);
541 800
542 -var timers = {
543 - start: function() {
544 - var sessionTime = sessionStorage.getItem('boxzilla_timer');
545 - if( sessionTime ) siteTimer.time = sessionTime;
546 - siteTimer.start();
547 - pageTimer.start();
548 - },
549 - stop: function() {
550 - sessionStorage.setItem('boxzilla_timer', siteTimer.time);
551 - siteTimer.stop();
552 - pageTimer.stop();
801 + for (var i = 0; i < boxes.length; i++) {
802 + if (boxes[i].id === id) {
803 + return boxes[i];
553 804 }
554 -};
805 + }
555 806
556 -// initialise & add event listeners
557 -Boxzilla.init = function() {
558 - var html = document.documentElement;
807 + throw new Error('No box exists with ID ' + id);
808 +} // dismiss a single box (or all by omitting id param)
559 809
560 - // add overlay element to dom
561 - overlay.id = 'boxzilla-overlay';
562 - document.body.appendChild(overlay);
563 810
564 - // event binds
565 - $(window).on('scroll', throttle(checkHeightCriteria));
566 - $(window).on('resize', throttle(recalculateHeights));
567 - $(window).on('load', recalculateHeights );
568 - $(html).on('mouseleave', onMouseLeave);
569 - $(html).on('mouseenter', onMouseEnter);
570 - $(html).on('keyup', onKeyUp);
571 - $(overlay).click(onOverlayClick);
572 - window.setInterval(checkTimeCriteria, 1000);
573 - window.setTimeout(checkPageViewsCriteria, 1000 );
811 +function dismiss(id, animate) {
812 + if (id) {
813 + get(id).dismiss(animate);
814 + } else {
815 + boxes.forEach(function (box) {
816 + return box.dismiss(animate);
817 + });
818 + }
819 +}
574 820
575 - timers.start();
576 - $(window).on('focus', timers.start);
577 - $(window).on('beforeunload', function() {
578 - timers.stop();
579 - sessionStorage.setItem('boxzilla_pageviews', ++pageViews);
821 +function hide(id, animate) {
822 + if (id) {
823 + get(id).hide(animate);
824 + } else {
825 + boxes.forEach(function (box) {
826 + return box.hide(animate);
580 827 });
581 - $(window).on('blur', timers.stop);
828 + }
829 +}
582 830
583 - Boxzilla.trigger('ready');
584 -};
831 +function show(id, animate) {
832 + if (id) {
833 + get(id).show(animate);
834 + } else {
835 + boxes.forEach(function (box) {
836 + return box.show(animate);
837 + });
838 + }
839 +}
585 840
586 -/**
587 - * Create a new Box
588 - *
589 - * @param string id
590 - * @param object opts
591 - *
592 - * @returns Box
593 - */
594 -Boxzilla.create = function(id, opts) {
595 - boxes[id] = new Box(id, opts);
596 - return boxes[id];
597 -};
841 +function toggle(id, animate) {
842 + if (id) {
843 + get(id).toggle(animate);
844 + } else {
845 + boxes.forEach(function (box) {
846 + return box.toggle(animate);
847 + });
848 + }
849 +} // expose boxzilla object
598 850
599 -// dismiss a single box (or all by omitting id param)
600 -Boxzilla.dismiss = function(id) {
601 - // if no id given, dismiss all current open boxes
602 - if( typeof(id) === "undefined" ) {
603 - each(boxes, function(box) { box.dismiss(); });
604 - } else if( typeof( boxes[id] ) === "object" ) {
605 - boxes[id].dismiss();
606 - }
607 -};
608 851
609 -Boxzilla.hide = function(id) {
610 - if( typeof(id) === "undefined" ) {
611 - each(boxes, function(box) { box.hide(); });
612 - } else if( typeof( boxes[id] ) === "object" ) {
613 - boxes[id].hide();
614 - }
852 +var Boxzilla = {
853 + off: off,
854 + on: on,
855 + get: get,
856 + init: init,
857 + create: create,
858 + trigger: trigger,
859 + show: show,
860 + hide: hide,
861 + dismiss: dismiss,
862 + toggle: toggle,
863 + boxes: boxes
615 864 };
865 +window.Boxzilla = Boxzilla;
616 866
617 -Boxzilla.show = function(id) {
618 - if( typeof(id) === "undefined" ) {
619 - each(boxes, function(box) { box.show(); });
620 - } else if( typeof( boxes[id] ) === "object" ) {
621 - boxes[id].show();
622 - }
623 -};
867 +if (typeof module !== 'undefined' && module.exports) {
868 + module.exports = Boxzilla;
869 +}
624 870
625 -Boxzilla.toggle = function(id) {
626 - if( typeof(id) === "undefined" ) {
627 - each(boxes, function(box) { box.toggle(); });
628 - } else if( typeof( boxes[id] ) === "object" ) {
629 - boxes[id].toggle();
630 - }
631 -};
871 +},{"./box.js":3,"./styles.js":5,"./triggers/exit-intent.js":7,"./triggers/pageviews.js":8,"./triggers/scroll.js":9,"./triggers/time.js":10,"./util.js":11}],5:[function(require,module,exports){
872 +"use strict";
632 873
633 -window.Boxzilla = Boxzilla;
874 +var styles = '#boxzilla-overlay,.boxzilla-overlay{position:fixed;background:rgba(0,0,0,.65);width:100%;height:100%;left:0;top:0;z-index:10000}.boxzilla-center-container{position:fixed;top:0;left:0;right:0;height:0;text-align:center;z-index:11000;line-height:0}.boxzilla-center-container .boxzilla{display:inline-block;text-align:left;position:relative;line-height:normal}.boxzilla{position:fixed;z-index:12000;-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}';
875 +module.exports = styles;
634 876
635 -if ( typeof module !== 'undefined' && module.exports ) {
636 - module.exports = Boxzilla;
637 -}
638 -},{"./Box.js":2,"./Timer.js":4,"wolfy87-eventemitter":5}],4:[function(require,module,exports){
639 -'use strict';
877 +},{}],6:[function(require,module,exports){
878 +"use strict";
640 879
641 -var Timer = function(start) {
642 - this.time = start;
643 - this.interval = 0;
880 +var Timer = function Timer() {
881 + this.time = 0;
882 + this.interval = 0;
644 883 };
645 884
646 -Timer.prototype.tick = function() {
647 - this.time++;
885 +Timer.prototype.tick = function () {
886 + this.time++;
648 887 };
649 888
650 -Timer.prototype.start = function() {
651 - if( ! this.interval ) {
652 - this.interval = window.setInterval(this.tick.bind(this), 1000);
653 - }
889 +Timer.prototype.start = function () {
890 + if (!this.interval) {
891 + this.interval = window.setInterval(this.tick.bind(this), 1000);
892 + }
654 893 };
655 894
656 -Timer.prototype.stop = function() {
895 +Timer.prototype.stop = function () {
896 + if (this.interval) {
657 897 window.clearInterval(this.interval);
658 898 this.interval = 0;
899 + }
659 900 };
660 901
661 902 module.exports = Timer;
662 -},{}],5:[function(require,module,exports){
663 -/*!
664 - * EventEmitter v4.2.11 - git.io/ee
665 - * Unlicense - http://unlicense.org/
666 - * Oliver Caldwell - http://oli.me.uk/
667 - * @preserve
668 - */
669 903
670 -;(function () {
671 - 'use strict';
904 +},{}],7:[function(require,module,exports){
905 +"use strict";
672 906
673 - /**
674 - * Class for managing events.
675 - * Can be extended to provide event functionality in other classes.
676 - *
677 - * @class EventEmitter Manages event registering and emitting.
678 - */
679 - function EventEmitter() {}
907 +module.exports = function (boxes) {
908 + var timeout = null;
909 + var touchStart = {};
680 910
681 - // Shortcuts to improve speed and size
682 - var proto = EventEmitter.prototype;
683 - var exports = this;
684 - var originalGlobalValue = exports.EventEmitter;
911 + function trigger() {
912 + document.documentElement.removeEventListener('mouseleave', onMouseLeave);
913 + document.documentElement.removeEventListener('mouseenter', onMouseEnter);
914 + document.documentElement.removeEventListener('click', clearTimeout);
915 + window.removeEventListener('touchstart', onTouchStart);
916 + window.removeEventListener('touchend', onTouchEnd); // show boxes with exit intent trigger
685 917
686 - /**
687 - * Finds the index of the listener for the event in its storage array.
688 - *
689 - * @param {Function[]} listeners Array of listeners to search through.
690 - * @param {Function} listener Method to look for.
691 - * @return {Number} Index of the specified listener, -1 if not found
692 - * @api private
693 - */
694 - function indexOfListener(listeners, listener) {
695 - var i = listeners.length;
696 - while (i--) {
697 - if (listeners[i].listener === listener) {
698 - return i;
699 - }
700 - }
918 + boxes.forEach(function (box) {
919 + if (box.mayAutoShow() && box.config.trigger.method === 'exit_intent') {
920 + box.trigger();
921 + }
922 + });
923 + }
701 924
702 - return -1;
925 + function clearTimeout() {
926 + if (timeout === null) {
927 + return;
703 928 }
704 929
705 - /**
706 - * Alias a method while keeping the context correct, to allow for overwriting of target method.
707 - *
708 - * @param {String} name The name of the target method.
709 - * @return {Function} The aliased method
710 - * @api private
711 - */
712 - function alias(name) {
713 - return function aliasClosure() {
714 - return this[name].apply(this, arguments);
715 - };
716 - }
930 + window.clearTimeout(timeout);
931 + timeout = null;
932 + }
717 933
718 - /**
719 - * Returns the listener array for the specified event.
720 - * Will initialise the event object and listener arrays if required.
721 - * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
722 - * Each property in the object response is an array of listener functions.
723 - *
724 - * @param {String|RegExp} evt Name of the event to return the listeners from.
725 - * @return {Function[]|Object} All listener functions for the event.
726 - */
727 - proto.getListeners = function getListeners(evt) {
728 - var events = this._getEvents();
729 - var response;
730 - var key;
934 + function onMouseEnter() {
935 + clearTimeout();
936 + }
731 937
732 - // Return a concatenated array of all matching events if
733 - // the selector is a regular expression.
734 - if (evt instanceof RegExp) {
735 - response = {};
736 - for (key in events) {
737 - if (events.hasOwnProperty(key) && evt.test(key)) {
738 - response[key] = events[key];
739 - }
740 - }
741 - }
742 - else {
743 - response = events[evt] || (events[evt] = []);
744 - }
938 + function getAddressBarY() {
939 + if (document.documentMode || /Edge\//.test(navigator.userAgent)) {
940 + return 5;
941 + }
745 942
746 - return response;
747 - };
943 + return 0;
944 + }
748 945
749 - /**
750 - * Takes a list of listener objects and flattens it into a list of listener functions.
751 - *
752 - * @param {Object[]} listeners Raw listener objects.
753 - * @return {Function[]} Just the listener functions.
754 - */
755 - proto.flattenListeners = function flattenListeners(listeners) {
756 - var flatListeners = [];
757 - var i;
946 + function onMouseLeave(evt) {
947 + clearTimeout(); // did mouse leave at top of window?
948 + // add small exception space in the top-right corner
758 949
759 - for (i = 0; i < listeners.length; i += 1) {
760 - flatListeners.push(listeners[i].listener);
761 - }
950 + if (evt.clientY <= getAddressBarY() && evt.clientX < 0.8 * window.innerWidth) {
951 + timeout = window.setTimeout(trigger, 600);
952 + }
953 + }
762 954
763 - return flatListeners;
955 + function onTouchStart() {
956 + clearTimeout();
957 + touchStart = {
958 + timestamp: performance.now(),
959 + scrollY: window.scrollY,
960 + windowHeight: window.innerHeight
764 961 };
962 + }
765 963
766 - /**
767 - * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
768 - *
769 - * @param {String|RegExp} evt Name of the event to return the listeners from.
770 - * @return {Object} All listener functions for an event in an object.
771 - */
772 - proto.getListenersAsObject = function getListenersAsObject(evt) {
773 - var listeners = this.getListeners(evt);
774 - var response;
964 + function onTouchEnd(evt) {
965 + clearTimeout(); // did address bar appear?
775 966
776 - if (listeners instanceof Array) {
777 - response = {};
778 - response[evt] = listeners;
779 - }
967 + if (window.innerHeight > touchStart.windowHeight) {
968 + return;
969 + } // allow a tiny tiny margin for error, to not fire on clicks
780 970
781 - return response || listeners;
782 - };
783 971
784 - /**
785 - * Adds a listener function to the specified event.
786 - * The listener will not be added if it is a duplicate.
787 - * If the listener returns true then it will be removed after it is called.
788 - * If you pass a regular expression as the event name then the listener will be added to all events that match it.
789 - *
790 - * @param {String|RegExp} evt Name of the event to attach the listener to.
791 - * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
792 - * @return {Object} Current instance of EventEmitter for chaining.
793 - */
794 - proto.addListener = function addListener(evt, listener) {
795 - var listeners = this.getListenersAsObject(evt);
796 - var listenerIsWrapped = typeof listener === 'object';
797 - var key;
972 + if (window.scrollY + 20 > touchStart.scrollY) {
973 + return;
974 + }
798 975
799 - for (key in listeners) {
800 - if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
801 - listeners[key].push(listenerIsWrapped ? listener : {
802 - listener: listener,
803 - once: false
804 - });
805 - }
806 - }
976 + if (performance.now() - touchStart.timestamp > 300) {
977 + return;
978 + }
807 979
808 - return this;
809 - };
980 + if (['A', 'INPUT', 'BUTTON'].indexOf(evt.target.tagName) > -1) {
981 + return;
982 + }
810 983
811 - /**
812 - * Alias of addListener
813 - */
814 - proto.on = alias('addListener');
984 + timeout = window.setTimeout(trigger, 800);
985 + }
815 986
816 - /**
817 - * Semi-alias of addListener. It will add a listener that will be
818 - * automatically removed after its first execution.
819 - *
820 - * @param {String|RegExp} evt Name of the event to attach the listener to.
821 - * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
822 - * @return {Object} Current instance of EventEmitter for chaining.
823 - */
824 - proto.addOnceListener = function addOnceListener(evt, listener) {
825 - return this.addListener(evt, {
826 - listener: listener,
827 - once: true
828 - });
829 - };
987 + window.addEventListener('touchstart', onTouchStart);
988 + window.addEventListener('touchend', onTouchEnd);
989 + document.documentElement.addEventListener('mouseenter', onMouseEnter);
990 + document.documentElement.addEventListener('mouseleave', onMouseLeave);
991 + document.documentElement.addEventListener('click', clearTimeout);
992 +};
830 993
831 - /**
832 - * Alias of addOnceListener.
833 - */
834 - proto.once = alias('addOnceListener');
994 +},{}],8:[function(require,module,exports){
995 +"use strict";
835 996
836 - /**
837 - * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
838 - * You need to tell it what event names should be matched by a regex.
839 - *
840 - * @param {String} evt Name of the event to create.
841 - * @return {Object} Current instance of EventEmitter for chaining.
842 - */
843 - proto.defineEvent = function defineEvent(evt) {
844 - this.getListeners(evt);
845 - return this;
846 - };
997 +module.exports = function (boxes) {
998 + var pageviews;
847 999
848 - /**
849 - * Uses defineEvent to define multiple events.
850 - *
851 - * @param {String[]} evts An array of event names to define.
852 - * @return {Object} Current instance of EventEmitter for chaining.
853 - */
854 - proto.defineEvents = function defineEvents(evts) {
855 - for (var i = 0; i < evts.length; i += 1) {
856 - this.defineEvent(evts[i]);
857 - }
858 - return this;
859 - };
1000 + try {
1001 + pageviews = sessionStorage.getItem('boxzilla_pageviews') || 0;
1002 + sessionStorage.setItem('boxzilla_pageviews', ++pageviews);
1003 + } catch (e) {
1004 + pageviews = 0;
1005 + }
860 1006
861 - /**
862 - * Removes a listener function from the specified event.
863 - * When passed a regular expression as the event name, it will remove the listener from all events that match it.
864 - *
865 - * @param {String|RegExp} evt Name of the event to remove the listener from.
866 - * @param {Function} listener Method to remove from the event.
867 - * @return {Object} Current instance of EventEmitter for chaining.
868 - */
869 - proto.removeListener = function removeListener(evt, listener) {
870 - var listeners = this.getListenersAsObject(evt);
871 - var index;
872 - var key;
1007 + window.setTimeout(function () {
1008 + boxes.forEach(function (box) {
1009 + if (box.config.trigger.method === 'pageviews' && pageviews > box.config.trigger.value && box.mayAutoShow()) {
1010 + box.trigger();
1011 + }
1012 + });
1013 + }, 1000);
1014 +};
873 1015
874 - for (key in listeners) {
875 - if (listeners.hasOwnProperty(key)) {
876 - index = indexOfListener(listeners[key], listener);
1016 +},{}],9:[function(require,module,exports){
1017 +"use strict";
877 1018
878 - if (index !== -1) {
879 - listeners[key].splice(index, 1);
880 - }
881 - }
882 - }
1019 +var throttle = require('../util.js').throttle;
883 1020
884 - return this;
885 - };
1021 +module.exports = function (boxes) {
1022 + // check triggerHeight criteria for all boxes
1023 + function checkHeightCriteria() {
1024 + var scrollY = window.hasOwnProperty('pageYOffset') ? window.pageYOffset : window.scrollTop;
1025 + scrollY = scrollY + window.innerHeight * 0.9;
1026 + boxes.forEach(function (box) {
1027 + if (!box.mayAutoShow() || box.triggerHeight <= 0) {
1028 + return;
1029 + }
886 1030
887 - /**
888 - * Alias of removeListener
889 - */
890 - proto.off = alias('removeListener');
1031 + if (scrollY > box.triggerHeight) {
1032 + box.trigger();
1033 + } else if (box.mayRehide() && scrollY < box.triggerHeight - 5) {
1034 + // if box may auto-hide and scrollY is less than triggerHeight (with small margin of error), hide box
1035 + box.hide();
1036 + }
1037 + });
1038 + }
891 1039
892 - /**
893 - * Adds listeners in bulk using the manipulateListeners method.
894 - * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
895 - * You can also pass it a regular expression to add the array of listeners to all events that match it.
896 - * Yeah, this function does quite a bit. That's probably a bad thing.
897 - *
898 - * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
899 - * @param {Function[]} [listeners] An optional array of listener functions to add.
900 - * @return {Object} Current instance of EventEmitter for chaining.
901 - */
902 - proto.addListeners = function addListeners(evt, listeners) {
903 - // Pass through to manipulateListeners
904 - return this.manipulateListeners(false, evt, listeners);
905 - };
1040 + window.addEventListener('touchstart', throttle(checkHeightCriteria), true);
1041 + window.addEventListener('scroll', throttle(checkHeightCriteria), true);
1042 +};
906 1043
907 - /**
908 - * Removes listeners in bulk using the manipulateListeners method.
909 - * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
910 - * You can also pass it an event name and an array of listeners to be removed.
911 - * You can also pass it a regular expression to remove the listeners from all events that match it.
912 - *
913 - * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
914 - * @param {Function[]} [listeners] An optional array of listener functions to remove.
915 - * @return {Object} Current instance of EventEmitter for chaining.
916 - */
917 - proto.removeListeners = function removeListeners(evt, listeners) {
918 - // Pass through to manipulateListeners
919 - return this.manipulateListeners(true, evt, listeners);
920 - };
1044 +},{"../util.js":11}],10:[function(require,module,exports){
1045 +"use strict";
921 1046
922 - /**
923 - * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
924 - * The first argument will determine if the listeners are removed (true) or added (false).
925 - * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
926 - * You can also pass it an event name and an array of listeners to be added/removed.
927 - * You can also pass it a regular expression to manipulate the listeners of all events that match it.
928 - *
929 - * @param {Boolean} remove True if you want to remove listeners, false if you want to add.
930 - * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
931 - * @param {Function[]} [listeners] An optional array of listener functions to add/remove.
932 - * @return {Object} Current instance of EventEmitter for chaining.
933 - */
934 - proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
935 - var i;
936 - var value;
937 - var single = remove ? this.removeListener : this.addListener;
938 - var multiple = remove ? this.removeListeners : this.addListeners;
1047 +var Timer = require('../timer.js');
939 1048
940 - // If evt is an object then pass each of its properties to this method
941 - if (typeof evt === 'object' && !(evt instanceof RegExp)) {
942 - for (i in evt) {
943 - if (evt.hasOwnProperty(i) && (value = evt[i])) {
944 - // Pass the single listener straight through to the singular method
945 - if (typeof value === 'function') {
946 - single.call(this, i, value);
947 - }
948 - else {
949 - // Otherwise pass back to the multiple function
950 - multiple.call(this, i, value);
951 - }
952 - }
953 - }
954 - }
955 - else {
956 - // So evt must be a string
957 - // And listeners must be an array of listeners
958 - // Loop over it and pass each one to the multiple method
959 - i = listeners.length;
960 - while (i--) {
961 - single.call(this, evt, listeners[i]);
962 - }
963 - }
1049 +module.exports = function (boxes) {
1050 + var siteTimer = new Timer();
1051 + var pageTimer = new Timer();
1052 + var timers = {
1053 + start: function start() {
1054 + try {
1055 + var sessionTime = parseInt(sessionStorage.getItem('boxzilla_timer'));
964 1056
965 - return this;
966 - };
967 -
968 - /**
969 - * Removes all listeners from a specified event.
970 - * If you do not specify an event then all listeners will be removed.
971 - * That means every event will be emptied.
972 - * You can also pass a regex to remove all events that match it.
973 - *
974 - * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
975 - * @return {Object} Current instance of EventEmitter for chaining.
976 - */
977 - proto.removeEvent = function removeEvent(evt) {
978 - var type = typeof evt;
979 - var events = this._getEvents();
980 - var key;
981 -
982 - // Remove different things depending on the state of evt
983 - if (type === 'string') {
984 - // Remove all listeners for the specified event
985 - delete events[evt];
1057 + if (sessionTime) {
1058 + siteTimer.time = sessionTime;
986 1059 }
987 - else if (evt instanceof RegExp) {
988 - // Remove all events matching the regex.
989 - for (key in events) {
990 - if (events.hasOwnProperty(key) && evt.test(key)) {
991 - delete events[key];
992 - }
993 - }
994 - }
995 - else {
996 - // Remove all listeners in all events
997 - delete this._events;
998 - }
1060 + } catch (e) {}
999 1061
1000 - return this;
1001 - };
1062 + siteTimer.start();
1063 + pageTimer.start();
1064 + },
1065 + stop: function stop() {
1066 + sessionStorage.setItem('boxzilla_timer', siteTimer.time);
1067 + siteTimer.stop();
1068 + pageTimer.stop();
1069 + }
1070 + }; // start timers
1002 1071
1003 - /**
1004 - * Alias of removeEvent.
1005 - *
1006 - * Added to mirror the node API.
1007 - */
1008 - proto.removeAllListeners = alias('removeEvent');
1072 + timers.start(); // stop timers when leaving page or switching to other tab
1009 1073
1010 - /**
1011 - * Emits an event of your choice.
1012 - * When emitted, every listener attached to that event will be executed.
1013 - * If you pass the optional argument array then those arguments will be passed to every listener upon execution.
1014 - * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
1015 - * So they will not arrive within the array on the other side, they will be separate.
1016 - * You can also pass a regular expression to emit to all events that match it.
1017 - *
1018 - * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
1019 - * @param {Array} [args] Optional array of arguments to be passed to each listener.
1020 - * @return {Object} Current instance of EventEmitter for chaining.
1021 - */
1022 - proto.emitEvent = function emitEvent(evt, args) {
1023 - var listenersMap = this.getListenersAsObject(evt);
1024 - var listeners;
1025 - var listener;
1026 - var i;
1027 - var key;
1028 - var response;
1074 + document.addEventListener('visibilitychange', function () {
1075 + document.hidden ? timers.stop() : timers.start();
1076 + });
1077 + window.addEventListener('beforeunload', function () {
1078 + timers.stop();
1079 + });
1080 + window.setInterval(function () {
1081 + boxes.forEach(function (box) {
1082 + if (box.config.trigger.method === 'time_on_site' && siteTimer.time > box.config.trigger.value && box.mayAutoShow()) {
1083 + box.trigger();
1084 + } else if (box.config.trigger.method === 'time_on_page' && pageTimer.time > box.config.trigger.value && box.mayAutoShow()) {
1085 + box.trigger();
1086 + }
1087 + });
1088 + }, 1000);
1089 +};
1029 1090
1030 - for (key in listenersMap) {
1031 - if (listenersMap.hasOwnProperty(key)) {
1032 - listeners = listenersMap[key].slice(0);
1033 - i = listeners.length;
1091 +},{"../timer.js":6}],11:[function(require,module,exports){
1092 +"use strict";
1034 1093
1035 - while (i--) {
1036 - // If the listener returns true then it shall be removed from the event
1037 - // The function is executed either with a basic call or an apply if there is an args array
1038 - listener = listeners[i];
1094 +function throttle(fn, threshold, scope) {
1095 + threshold || (threshold = 800);
1096 + var last;
1097 + var deferTimer;
1098 + return function () {
1099 + var context = scope || this;
1100 + var now = +new Date();
1101 + var args = arguments;
1039 1102
1040 - if (listener.once === true) {
1041 - this.removeListener(evt, listener.listener);
1042 - }
1103 + if (last && now < last + threshold) {
1104 + // hold on to it
1105 + clearTimeout(deferTimer);
1106 + deferTimer = setTimeout(function () {
1107 + last = now;
1108 + fn.apply(context, args);
1109 + }, threshold);
1110 + } else {
1111 + last = now;
1112 + fn.apply(context, args);
1113 + }
1114 + };
1115 +}
1043 1116
1044 - response = listener.listener.apply(this, args || []);
1117 +module.exports = {
1118 + throttle: throttle
1119 +};
1045 1120
1046 - if (response === this._getOnceReturnValue()) {
1047 - this.removeListener(evt, listener.listener);
1048 - }
1049 - }
1050 - }
1051 - }
1052 -
1053 - return this;
1054 - };
1055 -
1056 - /**
1057 - * Alias of emitEvent
1058 - */
1059 - proto.trigger = alias('emitEvent');
1060 -
1061 - /**
1062 - * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
1063 - * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
1064 - *
1065 - * @param {String|RegExp} evt Name of the event to emit and execute listeners for.
1066 - * @param {...*} Optional additional arguments to be passed to each listener.
1067 - * @return {Object} Current instance of EventEmitter for chaining.
1068 - */
1069 - proto.emit = function emit(evt) {
1070 - var args = Array.prototype.slice.call(arguments, 1);
1071 - return this.emitEvent(evt, args);
1072 - };
1073 -
1074 - /**
1075 - * Sets the current value to check against when executing listeners. If a
1076 - * listeners return value matches the one set here then it will be removed
1077 - * after execution. This value defaults to true.
1078 - *
1079 - * @param {*} value The new value to check for when executing listeners.
1080 - * @return {Object} Current instance of EventEmitter for chaining.
1081 - */
1082 - proto.setOnceReturnValue = function setOnceReturnValue(value) {
1083 - this._onceReturnValue = value;
1084 - return this;
1085 - };
1086 -
1087 - /**
1088 - * Fetches the current value to check against when executing listeners. If
1089 - * the listeners return value matches this one then it should be removed
1090 - * automatically. It will return true by default.
1091 - *
1092 - * @return {*|Boolean} The current value to check for or the default, true.
1093 - * @api private
1094 - */
1095 - proto._getOnceReturnValue = function _getOnceReturnValue() {
1096 - if (this.hasOwnProperty('_onceReturnValue')) {
1097 - return this._onceReturnValue;
1098 - }
1099 - else {
1100 - return true;
1101 - }
1102 - };
1103 -
1104 - /**
1105 - * Fetches the events object and creates one if required.
1106 - *
1107 - * @return {Object} The events storage object.
1108 - * @api private
1109 - */
1110 - proto._getEvents = function _getEvents() {
1111 - return this._events || (this._events = {});
1112 - };
1113 -
1114 - /**
1115 - * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version.
1116 - *
1117 - * @return {Function} Non conflicting EventEmitter class.
1118 - */
1119 - EventEmitter.noConflict = function noConflict() {
1120 - exports.EventEmitter = originalGlobalValue;
1121 - return EventEmitter;
1122 - };
1123 -
1124 - // Expose the class either via AMD, CommonJS or the global object
1125 - if (typeof define === 'function' && define.amd) {
1126 - define(function () {
1127 - return EventEmitter;
1128 - });
1129 - }
1130 - else if (typeof module === 'object' && module.exports){
1131 - module.exports = EventEmitter;
1132 - }
1133 - else {
1134 - exports.EventEmitter = EventEmitter;
1135 - }
1136 -}.call(this));
1137 -
1138 1121 },{}]},{},[1]);
1139 - })();
1122 +; })();