wp/wp-admin/js/color-picker.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    65 				 * @param {HTMLElement} ui The HTMLElement containing the color picker.
    65 				 * @param {HTMLElement} ui The HTMLElement containing the color picker.
    66 				 *
    66 				 *
    67 				 * @return {void}
    67 				 * @return {void}
    68 				 */
    68 				 */
    69 				change: function( event, ui ) {
    69 				change: function( event, ui ) {
    70 					if ( $.isFunction( self.options.change ) ) {
    70 					if ( typeof self.options.change === 'function' ) {
    71 						self.options.change.call( this, event, ui );
    71 						self.options.change.call( this, event, ui );
    72 					}
    72 					}
    73 				},
    73 				},
    74 				width: self.options.width,
    74 				width: self.options.width,
    75 				slider: self.options.slider
    75 				slider: self.options.slider
    99 			if ( self.options.type === 'hue' ) {
    99 			if ( self.options.type === 'hue' ) {
   100 				return self._createHueOnly();
   100 				return self._createHueOnly();
   101 			}
   101 			}
   102 
   102 
   103 			// Bind the close event.
   103 			// Bind the close event.
   104 			self.close = $.proxy( self.close, self );
   104 			self.close = self.close.bind( self );
   105 
   105 
   106 			self.initialValue = el.val();
   106 			self.initialValue = el.val();
   107 
   107 
   108 			// Add a CSS class to the input field.
   108 			// Add a CSS class to the input field.
   109 			el.addClass( 'wp-color-picker' );
   109 			el.addClass( 'wp-color-picker' );
   187 				 * @return {void}
   187 				 * @return {void}
   188 				 */
   188 				 */
   189 				change: function( event, ui ) {
   189 				change: function( event, ui ) {
   190 					self.toggler.css( { backgroundColor: ui.color.toString() } );
   190 					self.toggler.css( { backgroundColor: ui.color.toString() } );
   191 
   191 
   192 					if ( $.isFunction( self.options.change ) ) {
   192 					if ( typeof self.options.change === 'function' ) {
   193 						self.options.change.call( this, event, ui );
   193 						self.options.change.call( this, event, ui );
   194 					}
   194 					}
   195 				}
   195 				}
   196 			} );
   196 			} );
   197 
   197 
   230 			/**
   230 			/**
   231 			 * Open or close the color picker depending on the class.
   231 			 * Open or close the color picker depending on the class.
   232 			 *
   232 			 *
   233 			 * @since 3.5.0
   233 			 * @since 3.5.0
   234 			 */
   234 			 */
   235 			self.toggler.click( function(){
   235 			self.toggler.on( 'click', function(){
   236 				if ( self.toggler.hasClass( 'wp-picker-open' ) ) {
   236 				if ( self.toggler.hasClass( 'wp-picker-open' ) ) {
   237 					self.close();
   237 					self.close();
   238 				} else {
   238 				} else {
   239 					self.open();
   239 					self.open();
   240 				}
   240 				}
   248 			 *
   248 			 *
   249 			 * @param {Event} event The event that's being called.
   249 			 * @param {Event} event The event that's being called.
   250 			 *
   250 			 *
   251 			 * @return {void}
   251 			 * @return {void}
   252 			 */
   252 			 */
   253 			self.element.change( function( event ) {
   253 			self.element.on( 'change', function( event ) {
   254 				var me = $( this ),
   254 				var me = $( this ),
   255 					val = me.val();
   255 					val = me.val();
   256 
   256 
   257 				if ( val === '' || val === '#' ) {
   257 				if ( val === '' || val === '#' ) {
   258 					self.toggler.css( 'backgroundColor', '' );
   258 					self.toggler.css( 'backgroundColor', '' );
   259 					// Fire clear callback if we have one.
   259 					// Fire clear callback if we have one.
   260 					if ( $.isFunction( self.options.clear ) ) {
   260 					if ( typeof self.options.clear === 'function' ) {
   261 						self.options.clear.call( this, event );
   261 						self.options.clear.call( this, event );
   262 					}
   262 					}
   263 				}
   263 				}
   264 			});
   264 			});
   265 
   265 
   270 			 *
   270 			 *
   271 			 * @param {Event} event The event that's being called.
   271 			 * @param {Event} event The event that's being called.
   272 			 *
   272 			 *
   273 			 * @return {void}
   273 			 * @return {void}
   274 			 */
   274 			 */
   275 			self.button.click( function( event ) {
   275 			self.button.on( 'click', function( event ) {
   276 				var me = $( this );
   276 				var me = $( this );
   277 				if ( me.hasClass( 'wp-picker-clear' ) ) {
   277 				if ( me.hasClass( 'wp-picker-clear' ) ) {
   278 					self.element.val( '' );
   278 					self.element.val( '' );
   279 					self.toggler.css( 'backgroundColor', '' );
   279 					self.toggler.css( 'backgroundColor', '' );
   280 					if ( $.isFunction( self.options.clear ) ) {
   280 					if ( typeof self.options.clear === 'function' ) {
   281 						self.options.clear.call( this, event );
   281 						self.options.clear.call( this, event );
   282 					}
   282 					}
   283 				} else if ( me.hasClass( 'wp-picker-default' ) ) {
   283 				} else if ( me.hasClass( 'wp-picker-default' ) ) {
   284 					self.element.val( self.options.defaultColor ).change();
   284 					self.element.val( self.options.defaultColor ).change();
   285 				}
   285 				}