PluginProbe
Boxzilla – WordPress Popup Builder / 3.2.4
Boxzilla – WordPress Popup Builder v3.2.4
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/browserify/script.js +64 -44 3.1.133.2.4 View file →
@@ -6,16 +6,8 @@
6 6
7 7 // expose Boxzilla object to window
8 8 window.Boxzilla = Boxzilla;
9 9
10 - function ready(fn) {
11 - if (document.readyState != 'loading'){
12 - fn();
13 - } else {
14 - document.addEventListener('DOMContentLoaded', fn);
15 - }
16 - }
17 -
18 10 // helper function for setting CSS styles
19 11 function css(element, styles) {
20 12 if( styles.background_color ) {
21 13 element.style.background = styles.background_color;
@@ -42,23 +34,14 @@
42 34 }
43 35 }
44 36
45 37 function createBoxesFromConfig() {
46 - var isLoggedIn = document.body.className.indexOf('logged-in') > -1;
47 -
38 +
48 39 // failsafe against including script twice.
49 40 if( options.inited ) {
50 41 return;
51 42 }
52 43
53 - // print message when test mode is enabled
54 - if( isLoggedIn && options.testMode ) {
55 - console.log( 'Boxzilla: Test mode is enabled. Please disable test mode if you\'re done testing.' );
56 - }
57 -
58 - // init boxzilla
59 - Boxzilla.init();
60 -
61 44 // create boxes from options
62 45 for( var i=0; i < options.boxes.length; i++ ) {
63 46 // get opts
64 47 var boxOpts = options.boxes[i];
@@ -63,15 +46,17 @@
63 46 // get opts
64 47 var boxOpts = options.boxes[i];
65 48 boxOpts.testMode = isLoggedIn && options.testMode;
66 49
67 - // fix http:// links in box content....
68 - if( window.location.protocol === "https:" && window.location.host ) {
69 - var o = "http://" + window.location.host;
70 - var n = o.replace('http://', 'https://');
71 - boxOpts.content = boxOpts.content.replace(o, n);
50 + // find box content element, bail if not found
51 + var boxContentElement = document.getElementById('boxzilla-box-'+ boxOpts.id +'-content');
52 + if( ! boxContentElement) {
53 + continue;
72 54 }
73 55
56 + // use element as content option
57 + boxOpts.content = boxContentElement;
58 +
74 59 // create box
75 60 var box = Boxzilla.create(boxOpts.id, boxOpts);
76 61
77 62 // add box slug to box element as classname
@@ -81,37 +66,72 @@
81 66 css(box.element, boxOpts.css);
82 67
83 68 box.element.firstChild.firstChild.className += " first-child";
84 69 box.element.firstChild.lastChild.className += " last-child";
70 +
71 + // maybe show box right away
72 + if( box.fits() && locationHashRefersBox(box) ) {
73 + box.show();
74 + }
85 75 }
86 76
87 - /**
88 - * If a MailChimp for WordPress form was submitted, open the box containing that form (if any)
89 - *
90 - * TODO: Just set location hash from MailChimp for WP?
91 - */
92 - window.addEventListener('load', openMailChimpForWordPressBox);
93 -
77 + // set flag to prevent initialising twice
94 78 options.inited = true;
95 79
96 80 // trigger "done" event.
97 81 Boxzilla.trigger('done');
82 +
83 + // maybe open box with MC4WP form in it
84 + maybeOpenMailChimpForWordPressBox();
98 85 }
99 86
100 - function openMailChimpForWordPressBox() {
101 - if( typeof(window.mc4wp_forms_config) === "object" && window.mc4wp_forms_config.submitted_form ) {
102 - var selector = '#' + window.mc4wp_forms_config.submitted_form.element_id;
103 - var boxes = Boxzilla.boxes;
104 - for( var boxId in boxes ) {
105 - if(!boxes.hasOwnProperty(boxId)) { continue; }
106 - var box = boxes[boxId];
107 - if( box.element.querySelector(selector)) {
108 - box.show();
109 - return;
110 - }
87 + function locationHashRefersBox(box) {
88 + if( ! window.location.hash || 0 === window.location.hash.length ) {
89 + return false;
90 + }
91 +
92 + var elementId = window.location.hash.substring(1);
93 +
94 + // only attempt on strings looking like an ID
95 + var regex = /^[a-zA-Z\-\_0-9]+$/;
96 + if( ! regex.test(elementId) ) {
97 + return false;
98 + }
99 +
100 + if( elementId === box.element.id ) {
101 + return true;
102 + } else if( box.element.querySelector('#' + elementId) ) {
103 + return true;
104 + }
105 +
106 + return false;
107 + }
108 +
109 + function maybeOpenMailChimpForWordPressBox() {
110 + if( typeof(window.mc4wp_forms_config) !== "object" || ! window.mc4wp_forms_config.submitted_form ) {
111 + return;
112 + }
113 +
114 + var selector = '#' + window.mc4wp_forms_config.submitted_form.element_id;
115 + var boxes = Boxzilla.boxes;
116 + for( var boxId in boxes ) {
117 + if(!boxes.hasOwnProperty(boxId)) { continue; }
118 + var box = boxes[boxId];
119 + if( box.element.querySelector(selector)) {
120 + box.show();
121 + return;
111 122 }
112 123 }
124 + }
125 +
126 + // print message when test mode is enabled
127 + var isLoggedIn = document.body.className.indexOf('logged-in') > -1;
128 + if( isLoggedIn && options.testMode ) {
129 + console.log( 'Boxzilla: Test mode is enabled. Please disable test mode if you\'re done testing.' );
113 130 }
114 131
115 - // create boxes as soon as document.ready fires
116 - ready(createBoxesFromConfig);
117 -})();
132 + // init boxzilla
133 + Boxzilla.init();
134 +
135 + // on window.load, create DOM elements for boxes
136 + window.addEventListener('load', createBoxesFromConfig);
137 +})();