balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

color.js (1051B)


      1 ( function ( $, rwmb ) {
      2 	'use strict';
      3 
      4 	/**
      5 	 * Transform an input into a color picker.
      6 	 */
      7 	function transform() {
      8 		var $this = $( this );
      9 
     10 		function triggerChange() {
     11 			$this.trigger( 'color:change' ).trigger( 'mb_change' );
     12 		}
     13 
     14 		var $container = $this.closest( '.wp-picker-container' ),
     15 			// Hack: the picker needs a small delay (learn from the Kirki plugin).
     16 			options = $.extend(
     17 				{
     18 					change: function () {
     19 						setTimeout( triggerChange, 20 );
     20 					},
     21 					clear: function () {
     22 						setTimeout( triggerChange, 20 );
     23 					}
     24 				},
     25 				$this.data( 'options' )
     26 			);
     27 
     28 		// Clone doesn't have input for color picker, we have to add the input and remove the color picker container
     29 		if ( $container.length > 0 ) {
     30 			$this.insertBefore( $container );
     31 			$container.remove();
     32 		}
     33 
     34 		// Show color picker.
     35 		$this.wpColorPicker( options );
     36 	}
     37 
     38 	function init( e ) {
     39 		$( e.target ).find( '.rwmb-color' ).each( transform );
     40 	}
     41 
     42 	rwmb.$document
     43 		.on( 'mb_ready', init )
     44 		.on( 'clone', '.rwmb-color', transform );
     45 } )( jQuery, rwmb );