| @@ -6,8 +6,16 @@ | ||
| 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 | + | |
| 10 | 18 | // helper function for setting CSS styles |
| 11 | 19 | function css(element, styles) { |
| 12 | 20 | if( styles.background_color ) { |
| 13 | 21 | element.style.background = styles.background_color; |
| @@ -75,9 +83,15 @@ | ||
| 75 | 83 | box.element.firstChild.firstChild.className += " first-child"; |
| 76 | 84 | box.element.firstChild.lastChild.className += " last-child"; |
| 77 | 85 | } |
| 78 | 86 | |
| 79 | - // set flag to prevent initialising twice | |
| 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 | + | |
| 80 | 94 | options.inited = true; |
| 81 | 95 | |
| 82 | 96 | // trigger "done" event. |
| 83 | 97 | Boxzilla.trigger('done'); |
| @@ -97,7 +111,7 @@ | ||
| 97 | 111 | } |
| 98 | 112 | } |
| 99 | 113 | } |
| 100 | 114 | |
| 101 | - window.addEventListener('load', openMailChimpForWordPressBox); | |
| 102 | - createBoxesFromConfig(); | |
| 103 | -})(); | |
| 115 | + // create boxes as soon as document.ready fires | |
| 116 | + ready(createBoxesFromConfig); | |
| 117 | +})(); | |