select.js (1283B)
1 /*jshint -W065 */ 2 wp.customize.controlConstructor['kirki-select'] = wp.customize.Control.extend({ 3 4 ready: function () { 5 6 'use strict'; 7 8 var control = this, 9 element = this.container.find('select'), 10 multiple = parseInt(element.data('multiple')), 11 selectValue; 12 13 // If this is a multi-select control, 14 // then we'll need to initialize selectize using the appropriate arguments. 15 // If this is a single-select, then we can initialize selectize without any arguments. 16 if (multiple > 1) { 17 jQuery(element).selectize({ 18 maxItems: multiple, 19 plugins: ['remove_button', 'drag_drop'] 20 }); 21 } else { 22 jQuery(element).selectize(); 23 } 24 25 // Change value 26 this.container.on('change', 'select', function () { 27 28 selectValue = jQuery(this).val(); 29 30 // If this is a multi-select, then we need to convert the value to an object. 31 if (multiple > 1) { 32 selectValue = _.extend({}, jQuery(this).val()); 33 } else { 34 control.container.find('select').data().selectize.blur(); 35 } 36 37 control.setting.set(selectValue); 38 39 }); 40 41 } 42 43 });