wp.customize.controlConstructor['hoo-color'] = wp.customize.Control.extend({ // When we're finished loading continue processing ready: function() { 'use strict'; var control = this; // Init the control. if ( ! _.isUndefined( window.hooControlLoader ) && _.isFunction( hooControlLoader ) ) { hooControlLoader( control ); } else { control.initHooControl(); } }, initHooControl: function() { var control = this, picker = this.container.find( '.hoo-color-control' ), clear; control.container.find( '.hoo-controls-loading-spinner' ).hide(); // If we have defined any extra choices, make sure they are passed-on to Iris. if ( ! _.isUndefined( control.params.choices ) ) { picker.wpColorPicker( control.params.choices ); } // Tweaks to make the "clear" buttons work. setTimeout( function() { clear = control.container.find( '.wp-picker-clear' ); clear.click( function() { control.setting.set( '' ); }); }, 500 ); // Saves our settings to the WP API picker.wpColorPicker({ change: function() { // Small hack: the picker needs a small delay setTimeout( function() { control.setting.set( picker.val() ); }, 100 ); } }); } });