preset.js (1283B)
1 wp.customize.controlConstructor['kirki-preset'] = wp.customize.Control.extend({ 2 3 ready: function() { 4 5 'use strict'; 6 7 var control = this, 8 element = this.container.find( 'select' ), 9 selectValue; 10 11 // Init selectize 12 jQuery( element ).selectize(); 13 14 // Trigger a change 15 this.container.on( 'change', 'select', function() { 16 17 // Get the control's value 18 selectValue = jQuery( this ).val(); 19 20 // Update the value using the customizer API and trigger the "save" button 21 control.setting.set( selectValue ); 22 23 // We have to get the choices of this control 24 // and then start parsing them to see what we have to do for each of the choices. 25 jQuery.each( control.params.choices, function( key, value ) { 26 27 // If the current value of the control is the key of the choice, 28 // then we can continue processing, Otherwise there's no reason to do anything. 29 if ( selectValue === key ) { 30 31 // Each choice has an array of settings defined in it. 32 // We'll have to loop through them all and apply the changes needed to them. 33 jQuery.each( value.settings, function( presetSetting, presetSettingValue ) { 34 kirkiSetSettingValue( presetSetting, presetSettingValue ); 35 }); 36 37 } 38 39 }); 40 41 wp.customize.previewer.refresh(); 42 43 }); 44 45 } 46 });