11// @ts -nocheck
22'use strict' ;
33
4+ const containers = [ 'editor' , 'background' , 'toolbar' ] ;
5+ const colors = [ 'super-light' , 'light' , 'dark' , 'super-dark' ] ;
6+
7+ // add corresponding classes when config change
8+ const updateSkinVariantsClasses = ( newClasses ) => {
9+ const domsToUpdate = [
10+ $ ( 'html' ) ,
11+ $ ( 'iframe[name=ace_outer]' ) . contents ( ) . find ( 'html' ) ,
12+ $ ( 'iframe[name=ace_outer]' ) . contents ( ) . find ( 'iframe[name=ace_inner]' ) . contents ( ) . find ( 'html' ) ,
13+ ] ;
14+
15+ colors . forEach ( ( color ) => {
16+ containers . forEach ( ( container ) => {
17+ domsToUpdate . forEach ( ( el ) => { el . removeClass ( `${ color } -${ container } ` ) ; } ) ;
18+ } ) ;
19+ } ) ;
20+
21+ domsToUpdate . forEach ( ( el ) => { el . removeClass ( 'full-width-editor' ) ; } ) ;
22+
23+ domsToUpdate . forEach ( ( el ) => { el . addClass ( newClasses . join ( ' ' ) ) ; } ) ;
24+ } ;
25+
426// Specific hash to display the skin variants builder popup
527if ( window . location . hash . toLowerCase ( ) === '#skinvariantsbuilder' ) {
628 $ ( '#skin-variants' ) . addClass ( 'popup-show' ) ;
729
8- const containers = [ 'editor' , 'background' , 'toolbar' ] ;
9- const colors = [ 'super-light' , 'light' , 'dark' , 'super-dark' ] ;
10-
11- // add corresponding classes when config change
12- const updateSkinVariantsClasses = ( ) => {
13- const domsToUpdate = [
14- $ ( 'html' ) ,
15- $ ( 'iframe[name=ace_outer]' ) . contents ( ) . find ( 'html' ) ,
16- $ ( 'iframe[name=ace_outer]' ) . contents ( ) . find ( 'iframe[name=ace_inner]' ) . contents ( ) . find ( 'html' ) ,
17- ] ;
18- colors . forEach ( ( color ) => {
19- containers . forEach ( ( container ) => {
20- domsToUpdate . forEach ( ( el ) => { el . removeClass ( `${ color } -${ container } ` ) ; } ) ;
21- } ) ;
22- } ) ;
23-
24- domsToUpdate . forEach ( ( el ) => { el . removeClass ( 'full-width-editor' ) ; } ) ;
25-
30+ const getNewClasses = ( ) => {
2631 const newClasses = [ ] ;
2732 $ ( 'select.skin-variant-color' ) . each ( function ( ) {
2833 newClasses . push ( `${ $ ( this ) . val ( ) } -${ $ ( this ) . data ( 'container' ) } ` ) ;
2934 } ) ;
3035 if ( $ ( '#skin-variant-full-width' ) . is ( ':checked' ) ) newClasses . push ( 'full-width-editor' ) ;
3136
32- domsToUpdate . forEach ( ( el ) => { el . addClass ( newClasses . join ( ' ' ) ) ; } ) ;
33-
3437 $ ( '#skin-variants-result' ) . val ( `"skinVariants": "${ newClasses . join ( ' ' ) } ",` ) ;
35- } ;
38+
39+ return newClasses ;
40+ }
3641
3742 // run on init
3843 const updateCheckboxFromSkinClasses = ( ) => {
@@ -48,9 +53,11 @@ if (window.location.hash.toLowerCase() === '#skinvariantsbuilder') {
4853 } ;
4954
5055 $ ( '.skin-variant' ) . on ( 'change' , ( ) => {
51- updateSkinVariantsClasses ( ) ;
56+ updateSkinVariantsClasses ( getNewClasses ( ) ) ;
5257 } ) ;
5358
5459 updateCheckboxFromSkinClasses ( ) ;
55- updateSkinVariantsClasses ( ) ;
60+ updateSkinVariantsClasses ( getNewClasses ( ) ) ;
5661}
62+
63+ exports . updateSkinVariantsClasses = updateSkinVariantsClasses ;
0 commit comments