| @@ -14,37 +14,41 @@ | ||
| 14 | 14 | |
| 15 | 15 | // Ensure the global `tp` object exists. |
| 16 | 16 | window.tp = window.tp || {}; |
| 17 | 17 | |
| 18 | -/** | |
| 19 | - * Invoke CodeMirror on the "Custom CSS" textarea. | |
| 20 | - * | |
| 21 | - * @since 1.9.0 | |
| 22 | - */ | |
| 23 | -tp.CM_custom_css = wp.codeEditor.initialize( 'option-custom-css', {} ).codemirror; | |
| 24 | -const $CM_wrapper = tp.CM_custom_css.getWrapperElement(); | |
| 18 | +document.addEventListener( 'DOMContentLoaded', () => { | |
| 25 | 19 | |
| 26 | -/** | |
| 27 | - * Let CodeMirror textarea grow on first focus (with mouse click), if it is not disabled. | |
| 28 | - * | |
| 29 | - * @since 1.0.0 | |
| 30 | - */ | |
| 31 | -const CM_wrapper_mousedown_handler = function () { | |
| 32 | - if ( ! this.classList.contains( 'disabled' ) ) { | |
| 33 | - this.classList.add( 'large' ); | |
| 34 | - tp.CM_custom_css.refresh(); | |
| 35 | - this.removeEventListener( 'mousedown', CM_wrapper_mousedown_handler ); // No need to keep checking for clicks after the textarea height was increased. | |
| 36 | - } | |
| 37 | -}; | |
| 38 | -$CM_wrapper.addEventListener( 'mousedown', CM_wrapper_mousedown_handler ); | |
| 20 | + /** | |
| 21 | + * Invoke CodeMirror on the "Custom CSS" textarea. | |
| 22 | + * | |
| 23 | + * @since 1.9.0 | |
| 24 | + */ | |
| 25 | + tp.CM_custom_css = wp.codeEditor.initialize( 'option-custom-css', {} ).codemirror; | |
| 26 | + const $CM_wrapper = tp.CM_custom_css.getWrapperElement(); | |
| 39 | 27 | |
| 40 | -/** | |
| 41 | - * Enable/disable CodeMirror according to state of "Load Custom CSS" checkbox. | |
| 42 | - * | |
| 43 | - * @since 1.0.0 | |
| 44 | - */ | |
| 45 | -const $cb_use_custom_css = document.getElementById( 'option-use-custom-css' ); | |
| 46 | -$cb_use_custom_css.addEventListener( 'change', function () { | |
| 47 | - tp.CM_custom_css.setOption( 'readOnly', ! this.checked ); | |
| 48 | - $CM_wrapper.classList.toggle( 'disabled', ! this.checked ); | |
| 28 | + /** | |
| 29 | + * Let CodeMirror textarea grow on first focus (with mouse click), if it is not disabled. | |
| 30 | + * | |
| 31 | + * @since 1.0.0 | |
| 32 | + */ | |
| 33 | + const CM_wrapper_mousedown_handler = function () { | |
| 34 | + if ( ! this.classList.contains( 'disabled' ) ) { | |
| 35 | + this.classList.add( 'large' ); | |
| 36 | + tp.CM_custom_css.refresh(); | |
| 37 | + this.removeEventListener( 'mousedown', CM_wrapper_mousedown_handler ); // No need to keep checking for clicks after the textarea height was increased. | |
| 38 | + } | |
| 39 | + }; | |
| 40 | + $CM_wrapper.addEventListener( 'mousedown', CM_wrapper_mousedown_handler ); | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Enable/disable CodeMirror according to state of "Load Custom CSS" checkbox. | |
| 44 | + * | |
| 45 | + * @since 1.0.0 | |
| 46 | + */ | |
| 47 | + const $cb_use_custom_css = document.getElementById( 'option-use-custom-css' ); | |
| 48 | + $cb_use_custom_css.addEventListener( 'change', function () { | |
| 49 | + tp.CM_custom_css.setOption( 'readOnly', ! this.checked ); | |
| 50 | + $CM_wrapper.classList.toggle( 'disabled', ! this.checked ); | |
| 51 | + } ); | |
| 52 | + $cb_use_custom_css.dispatchEvent( new Event( 'change' ) ); | |
| 53 | + | |
| 49 | 54 | } ); |
| 50 | -$cb_use_custom_css.dispatchEvent( new Event( 'change' ) ); | |