PluginProbe
Boxzilla – WordPress Popup Builder / 3.1.16
Boxzilla – WordPress Popup Builder v3.1.16
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
boxzilla / assets / browserify / script.js

script.js in Boxzilla – WordPress Popup Builder 3.1.16, at assets/browserify/script.js

104 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 'use strict';
3
4 var Boxzilla = require('boxzilla');
5 var options = window.boxzilla_options;
6
7 // expose Boxzilla object to window
8 window.Boxzilla = Boxzilla;
9
10 // helper function for setting CSS styles
11 function css(element, styles) {
12 if( styles.background_color ) {
13 element.style.background = styles.background_color;
14 }
15
16 if( styles.color ) {
17 element.style.color = styles.color;
18 }
19
20 if( styles.border_color ) {
21 element.style.borderColor = styles.border_color;
22 }
23
24 if( styles.border_width ) {
25 element.style.borderWidth = parseInt(styles.border_width) + "px";
26 }
27
28 if( styles.border_style ) {
29 element.style.borderStyle = styles.border_style;
30 }
31
32 if( styles.width ) {
33 element.style.maxWidth = parseInt(styles.width) + "px";
34 }
35 }
36
37 function createBoxesFromConfig() {
38 var isLoggedIn = document.body.className.indexOf('logged-in') > -1;
39
40 // failsafe against including script twice.
41 if( options.inited ) {
42 return;
43 }
44
45 // print message when test mode is enabled
46 if( isLoggedIn && options.testMode ) {
47 console.log( 'Boxzilla: Test mode is enabled. Please disable test mode if you\'re done testing.' );
48 }
49
50 // init boxzilla
51 Boxzilla.init();
52
53 // create boxes from options
54 for( var i=0; i < options.boxes.length; i++ ) {
55 // get opts
56 var boxOpts = options.boxes[i];
57 boxOpts.testMode = isLoggedIn && options.testMode;
58
59 // fix http:// links in box content....
60 if( window.location.protocol === "https:" && window.location.host ) {
61 var o = "http://" + window.location.host;
62 var n = o.replace('http://', 'https://');
63 boxOpts.content = boxOpts.content.replace(o, n);
64 }
65
66 // create box
67 var box = Boxzilla.create(boxOpts.id, boxOpts);
68
69 // add box slug to box element as classname
70 box.element.className = box.element.className + ' boxzilla-' + boxOpts.post.slug;
71
72 // add custom css to box
73 css(box.element, boxOpts.css);
74
75 box.element.firstChild.firstChild.className += " first-child";
76 box.element.firstChild.lastChild.className += " last-child";
77 }
78
79 // set flag to prevent initialising twice
80 options.inited = true;
81
82 // trigger "done" event.
83 Boxzilla.trigger('done');
84 }
85
86 function openMailChimpForWordPressBox() {
87 if( typeof(window.mc4wp_forms_config) === "object" && window.mc4wp_forms_config.submitted_form ) {
88 var selector = '#' + window.mc4wp_forms_config.submitted_form.element_id;
89 var boxes = Boxzilla.boxes;
90 for( var boxId in boxes ) {
91 if(!boxes.hasOwnProperty(boxId)) { continue; }
92 var box = boxes[boxId];
93 if( box.element.querySelector(selector)) {
94 box.show();
95 return;
96 }
97 }
98 }
99 }
100
101 window.addEventListener('load', openMailChimpForWordPressBox);
102 createBoxesFromConfig();
103 })();
104