| @@ -17,15 +17,21 @@ | ||
| 17 | 17 | // get opts |
| 18 | 18 | var boxOpts = options.boxes[i]; |
| 19 | 19 | boxOpts.testMode = isLoggedIn && options.testMode; |
| 20 | 20 | |
| 21 | + // fix http:// links in box content.... | |
| 22 | + if( window.location.origin.substring(0, 5) === "https" ) { | |
| 23 | + boxOpts.content = boxOpts.content.replace(window.location.origin.replace("https", "http"), window.location.origin); | |
| 24 | + } | |
| 25 | + | |
| 21 | 26 | // create box |
| 22 | 27 | var box = Boxzilla.create( boxOpts.id, boxOpts); |
| 23 | - | |
| 28 | + | |
| 24 | 29 | // add custom css to box |
| 25 | 30 | css(box.element, boxOpts.css); |
| 26 | 31 | } |
| 27 | 32 | |
| 33 | +// helper function for setting CSS styles | |
| 28 | 34 | function css(element, styles) { |
| 29 | 35 | if( styles.background_color ) { |
| 30 | 36 | element.style.background = styles.background_color; |
| 31 | 37 | } |
| @@ -49,6 +55,26 @@ | ||
| 49 | 55 | if( styles.width ) { |
| 50 | 56 | element.style.maxWidth = parseInt(styles.width) + "px"; |
| 51 | 57 | } |
| 52 | 58 | } |
| 59 | + | |
| 60 | +/** | |
| 61 | + * If a MailChimp for WordPress form was submitted, open the box containing that form (if any) | |
| 62 | + * | |
| 63 | + * TODO: Just set location hash from MailChimp for WP? | |
| 64 | + */ | |
| 65 | +window.addEventListener('load', function() { | |
| 66 | + if( typeof(window.mc4wp_forms_config) === "object" && window.mc4wp_forms_config.submitted_form ) { | |
| 67 | + var selector = '#' + window.mc4wp_forms_config.submitted_form.element_id; | |
| 68 | + var boxes = Boxzilla.boxes; | |
| 69 | + for( var boxId in boxes ) { | |
| 70 | + if(!boxes.hasOwnProperty(boxId)) { continue; } | |
| 71 | + var box = boxes[boxId]; | |
| 72 | + if( box.element.querySelector(selector)) { | |
| 73 | + box.show(); | |
| 74 | + return; | |
| 75 | + } | |
| 76 | + } | |
| 77 | + } | |
| 78 | +}); | |
| 53 | 79 | |
| 54 | 80 | window.Boxzilla = Boxzilla; |