Changeset 2893419
- Timestamp:
- 04/04/2023 09:27:50 AM (3 years ago)
- File:
-
- 1 edited
-
admin-ide-dark-mode/trunk/js/aidmAdmin.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
admin-ide-dark-mode/trunk/js/aidmAdmin.js
r2879634 r2893419 1 1 const changeCodeMirrorTheme = () => { 2 // setTimeout -> codeMirror instances are not detected without it3 console.log( 'from const' );4 2 let codeMirrorInstance = document.querySelector( '.CodeMirror' ); 3 5 4 if ( ! codeMirrorInstance ) { 6 5 return false; 7 6 } 7 8 8 codeMirrorInstance.CodeMirror.setOption( 'theme', aidm_theme_preference ); 9 9 … … 14 14 jQuery( document ).ready( ( $ ) => { 15 15 // this part modify the custom css IDE in the customize panel 16 let additionalCSSTab = $( 'li#accordion-section-custom_css h3' ); 17 if ( additionalCSSTab.length > 0 ) { 18 additionalCSSTab.on( 'click', changeCodeMirrorTheme ); 16 // Select the node that will be observed for mutations 17 let targetNode = document.body; 19 18 20 return;21 }19 // Options for the observer (which mutations to observe) 20 let config = { childList: true, subtree: true }; 22 21 23 // this part change IDE througout the admin 24 setTimeout( changeCodeMirrorTheme, 10 ); 25 22 // Create an observer instance 23 let observer = new MutationObserver( () => { 24 // Look for elements with the class name 'CodeMirror' 25 let additionalCSSTab = $( 'li#accordion-section-custom_css > h3' ); 26 let codeMirrorElement = $( '.CodeMirror' ); 27 28 if ( codeMirrorElement.length > 0 ) { 29 // Do something if the element is found 30 changeCodeMirrorTheme(); 31 observer.disconnect(); 32 33 } else if ( additionalCSSTab.length > 0 ) { 34 additionalCSSTab.on( 'click', changeCodeMirrorTheme ); 35 observer.disconnect(); 36 37 } else { 38 setTimeout( () => { 39 observer.disconnect(); 40 }, 3000 ); 41 } 42 }); 43 44 // Start observing the target node for configured mutations 45 observer.observe(targetNode, config); 46 26 47 return; 27 48 });
Note: See TracChangeset
for help on using the changeset viewer.