(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 -1; // failsafe against including script twice. if (options.inited) { return; } // print message when test mode is enabled if (isLoggedIn && options.testMode) { console.log('Boxzilla: Test mode is enabled. Please disable test mode if you\'re done testing.'); } // init boxzilla Boxzilla.init(); // create boxes from options for (var i = 0; i < options.boxes.length; i++) { // get opts var boxOpts = options.boxes[i]; boxOpts.testMode = isLoggedIn && options.testMode; // fix http:// links in box content.... if (window.location.protocol === "https:" && window.location.host) { var o = "http://" + window.location.host; var n = o.replace('http://', 'https://'); boxOpts.content = boxOpts.content.replace(o, n); } // create box var box = Boxzilla.create(boxOpts.id, boxOpts); // add box slug to box element as classname box.element.className = box.element.className + ' boxzilla-' + boxOpts.post.slug; // add custom css to box css(box.element, boxOpts.css); box.element.firstChild.firstChild.className += " first-child"; box.element.firstChild.lastChild.className += " last-child"; } /** * If a MailChimp for WordPress form was submitted, open the box containing that form (if any) * * TODO: Just set location hash from MailChimp for WP? */ window.addEventListener('load', openMailChimpForWordPressBox); options.inited = true; // trigger "done" event. Boxzilla.trigger('done'); } function openMailChimpForWordPressBox() { if (_typeof(window.mc4wp_forms_config) === "object" && window.mc4wp_forms_config.submitted_form) { var selector = '#' + window.mc4wp_forms_config.submitted_form.element_id; var boxes = Boxzilla.boxes; for (var boxId in boxes) { if (!boxes.hasOwnProperty(boxId)) { continue; } var box = boxes[boxId]; if (box.element.querySelector(selector)) { box.show(); return; } } } } // create boxes as soon as document.ready fires ready(createBoxesFromConfig); })(); },{"boxzilla":4}],2:[function(require,module,exports){ 'use strict'; var duration = 320; function css(element, styles) { for (var property in styles) { element.style[property] = styles[property]; } } function initObjectProperties(properties, value) { var newObject = {}; for (var i = 0; i < properties.length; i++) { newObject[properties[i]] = value; } return newObject; } function copyObjectProperties(properties, object) { var newObject = {}; for (var i = 0; i < properties.length; i++) { newObject[properties[i]] = object[properties[i]]; } return newObject; } /** * Checks if the given element is currently being animated. * * @param element * @returns {boolean} */ function animated(element) { return !!element.getAttribute('data-animated'); } /** * Toggles the element using the given animation. * * @param element * @param animation Either "fade" or "slide" */ function toggle(element, animation) { var nowVisible = element.style.display != 'none' || element.offsetLeft > 0; // create clone for reference var clone = element.cloneNode(true); var cleanup = function cleanup() { element.removeAttribute('data-animated'); element.setAttribute('style', clone.getAttribute('style')); element.style.display = nowVisible ? 'none' : ''; }; // store attribute so everyone knows we're animating this element element.setAttribute('data-animated', "true"); // toggle element visiblity right away if we're making something visible if (!nowVisible) { element.style.display = ''; } var hiddenStyles, visibleStyles; // animate properties if (animation === 'slide') { hiddenStyles = initObjectProperties(["height", "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom"], 0); visibleStyles = {}; if (!nowVisible) { var computedStyles = window.getComputedStyle(element); visibleStyles = copyObjectProperties(["height", "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom"], computedStyles); css(element, hiddenStyles); } // don't show a scrollbar during animation element.style.overflowY = 'hidden'; animate(element, nowVisible ? hiddenStyles : visibleStyles, cleanup); } else { hiddenStyles = { opacity: 0 }; visibleStyles = { opacity: 1 }; if (!nowVisible) { css(element, hiddenStyles); } animate(element, nowVisible ? hiddenStyles : visibleStyles, cleanup); } } function animate(element, targetStyles, fn) { var last = +new Date(); var initialStyles = window.getComputedStyle(element); var currentStyles = {}; var propSteps = {}; for (var property in targetStyles) { // make sure we have an object filled with floats targetStyles[property] = parseFloat(targetStyles[property]); // calculate step size & current value var to = targetStyles[property]; var current = parseFloat(initialStyles[property]); // is there something to do? if (current == to) { delete targetStyles[property]; continue; } propSteps[property] = (to - current) / duration; // points per second currentStyles[property] = current; } var tick = function tick() { var now = +new Date(); var timeSinceLastTick = now - last; var done = true; var step, to, increment, newValue; for (var property in targetStyles) { step = propSteps[property]; to = targetStyles[property]; increment = step * timeSinceLastTick; newValue = currentStyles[property] + increment; if (step > 0 && newValue >= to || step < 0 && newValue <= to) { newValue = to; } else { done = false; } // store new value currentStyles[property] = newValue; var suffix = property !== "opacity" ? "px" : ""; element.style[property] = newValue + suffix; } last = +new Date(); // keep going until we're done for all props if (!done) { window.requestAnimationFrame && requestAnimationFrame(tick) || setTimeout(tick, 32); } else { // call callback fn && fn(); } }; tick(); } module.exports = { 'toggle': toggle, 'animate': animate, 'animated': animated }; },{}],3:[function(require,module,exports){ 'use strict'; var defaults = { 'animation': 'fade', 'rehide': false, 'content': '', 'cookie': null, 'icon': '×', 'minimumScreenWidth': 0, 'position': 'center', 'testMode': false, 'trigger': false, 'closable': true }, Boxzilla, Animator = require('./animator.js'); /** * Merge 2 objects, values of the latter overwriting the former. * * @param obj1 * @param obj2 * @returns {*} */ function merge(obj1, obj2) { var obj3 = {}; for (var attrname in obj1) { obj3[attrname] = obj1[attrname]; } for (var attrname in obj2) { obj3[attrname] = obj2[attrname]; } return obj3; } /** * Get the real height of entire document. * @returns {number} */ function getDocumentHeight() { var body = document.body, html = document.documentElement; var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight); return height; } // Box Object var Box = function Box(id, config) { this.id = id; // store config values this.config = merge(defaults, config); // store ref to overlay this.overlay = document.getElementById('boxzilla-overlay'); // state this.visible = false; this.dismissed = false; this.triggered = false; this.triggerHeight = 0; this.cookieSet = false; this.element = null; this.closeIcon = null; // if a trigger was given, calculate values once and store if (this.config.trigger) { if (this.config.trigger.method === 'percentage' || this.config.trigger.method === 'element') { this.triggerHeight = this.calculateTriggerHeight(); } this.cookieSet = this.isCookieSet(); } // create dom elements for this box this.dom(); // further initialise the box this.events(); }; // initialise the box Box.prototype.events = function () { var box = this; // attach event to "close" icon inside box if (this.closeIcon) { this.closeIcon.addEventListener('click', this.dismiss.bind(this)); } this.element.addEventListener('click', function (e) { if (e.target.tagName === 'A') { Boxzilla.trigger('box.interactions.link', [box, e.target]); } }, false); this.element.addEventListener('submit', function (e) { box.setCookie(); Boxzilla.trigger('box.interactions.form', [box, e.target]); }, false); // maybe show box right away if (this.fits() && this.locationHashRefersBox()) { window.addEventListener('load', this.show.bind(this)); } }; // generate dom elements for this box Box.prototype.dom = function () { var wrapper = document.createElement('div'); wrapper.className = 'boxzilla-container boxzilla-' + this.config.position + '-container'; var box = document.createElement('div'); box.setAttribute('id', 'boxzilla-' + this.id); box.className = 'boxzilla boxzilla-' + this.id + ' boxzilla-' + this.config.position; box.style.display = 'none'; wrapper.appendChild(box); var content = document.createElement('div'); content.className = 'boxzilla-content'; content.innerHTML = this.config.content; box.appendChild(content); // remove