wp/wp-includes/js/jquery/ui/spinner.js
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     1 /*!
     1 /*!
     2  * jQuery UI Spinner 1.12.1
     2  * jQuery UI Spinner 1.13.1
     3  * http://jqueryui.com
     3  * http://jqueryui.com
     4  *
     4  *
     5  * Copyright jQuery Foundation and other contributors
     5  * Copyright jQuery Foundation and other contributors
     6  * Released under the MIT license.
     6  * Released under the MIT license.
     7  * http://jquery.org/license
     7  * http://jquery.org/license
    15 //>>css.structure: ../../themes/base/core.css
    15 //>>css.structure: ../../themes/base/core.css
    16 //>>css.structure: ../../themes/base/spinner.css
    16 //>>css.structure: ../../themes/base/spinner.css
    17 //>>css.theme: ../../themes/base/theme.css
    17 //>>css.theme: ../../themes/base/theme.css
    18 
    18 
    19 ( function( factory ) {
    19 ( function( factory ) {
       
    20 	"use strict";
       
    21 
    20 	if ( typeof define === "function" && define.amd ) {
    22 	if ( typeof define === "function" && define.amd ) {
    21 
    23 
    22 		// AMD. Register as an anonymous module.
    24 		// AMD. Register as an anonymous module.
    23 		define( [
    25 		define( [
    24 			"jquery",
    26 			"jquery",
    28 	} else {
    30 	} else {
    29 
    31 
    30 		// Browser globals
    32 		// Browser globals
    31 		factory( jQuery );
    33 		factory( jQuery );
    32 	}
    34 	}
    33 }( function( $ ) {
    35 } )( function( $ ) {
    34 
    36 "use strict";
    35 function spinnerModifer( fn ) {
    37 
       
    38 function spinnerModifier( fn ) {
    36 	return function() {
    39 	return function() {
    37 		var previous = this.element.val();
    40 		var previous = this.element.val();
    38 		fn.apply( this, arguments );
    41 		fn.apply( this, arguments );
    39 		this._refresh();
    42 		this._refresh();
    40 		if ( previous !== this.element.val() ) {
    43 		if ( previous !== this.element.val() ) {
    42 		}
    45 		}
    43 	};
    46 	};
    44 }
    47 }
    45 
    48 
    46 $.widget( "ui.spinner", {
    49 $.widget( "ui.spinner", {
    47 	version: "1.12.1",
    50 	version: "1.13.1",
    48 	defaultElement: "<input>",
    51 	defaultElement: "<input>",
    49 	widgetEventPrefix: "spin",
    52 	widgetEventPrefix: "spin",
    50 	options: {
    53 	options: {
    51 		classes: {
    54 		classes: {
    52 			"ui-spinner": "ui-corner-all",
    55 			"ui-spinner": "ui-corner-all",
   135 			if ( this.previous !== this.element.val() ) {
   138 			if ( this.previous !== this.element.val() ) {
   136 				this._trigger( "change", event );
   139 				this._trigger( "change", event );
   137 			}
   140 			}
   138 		},
   141 		},
   139 		mousewheel: function( event, delta ) {
   142 		mousewheel: function( event, delta ) {
   140 			if ( !delta ) {
   143 			var activeElement = $.ui.safeActiveElement( this.document[ 0 ] );
       
   144 			var isActive = this.element[ 0 ] === activeElement;
       
   145 
       
   146 			if ( !isActive || !delta ) {
   141 				return;
   147 				return;
   142 			}
   148 			}
       
   149 
   143 			if ( !this.spinning && !this._start( event ) ) {
   150 			if ( !this.spinning && !this._start( event ) ) {
   144 				return false;
   151 				return false;
   145 			}
   152 			}
   146 
   153 
   147 			this._spin( ( delta > 0 ? 1 : -1 ) * this.options.step, event );
   154 			this._spin( ( delta > 0 ? 1 : -1 ) * this.options.step, event );
   225 		this.uiSpinner = this.element
   232 		this.uiSpinner = this.element
   226 			.attr( "autocomplete", "off" )
   233 			.attr( "autocomplete", "off" )
   227 			.wrap( "<span>" )
   234 			.wrap( "<span>" )
   228 			.parent()
   235 			.parent()
   229 
   236 
   230 				// Add buttons
   237 			// Add buttons
   231 				.append(
   238 			.append(
   232 					"<a></a><a></a>"
   239 				"<a></a><a></a>"
   233 				);
   240 			);
   234 	},
   241 	},
   235 
   242 
   236 	_draw: function() {
   243 	_draw: function() {
   237 		this._enhance();
   244 		this._enhance();
   238 
   245 
   266 		} );
   273 		} );
   267 
   274 
   268 		// IE 6 doesn't understand height: 50% for the buttons
   275 		// IE 6 doesn't understand height: 50% for the buttons
   269 		// unless the wrapper has an explicit height
   276 		// unless the wrapper has an explicit height
   270 		if ( this.buttons.height() > Math.ceil( this.uiSpinner.height() * 0.5 ) &&
   277 		if ( this.buttons.height() > Math.ceil( this.uiSpinner.height() * 0.5 ) &&
   271 				this.uiSpinner.height() > 0 ) {
   278 			this.uiSpinner.height() > 0 ) {
   272 			this.uiSpinner.height( this.uiSpinner.height() );
   279 			this.uiSpinner.height( this.uiSpinner.height() );
   273 		}
   280 		}
   274 	},
   281 	},
   275 
   282 
   276 	_keydown: function( event ) {
   283 	_keydown: function( event ) {
   277 		var options = this.options,
   284 		var options = this.options,
   278 			keyCode = $.ui.keyCode;
   285 			keyCode = $.ui.keyCode;
   279 
   286 
   280 		switch ( event.keyCode ) {
   287 		switch ( event.keyCode ) {
   281 		case keyCode.UP:
   288 			case keyCode.UP:
   282 			this._repeat( null, 1, event );
   289 				this._repeat( null, 1, event );
   283 			return true;
   290 				return true;
   284 		case keyCode.DOWN:
   291 			case keyCode.DOWN:
   285 			this._repeat( null, -1, event );
   292 				this._repeat( null, -1, event );
   286 			return true;
   293 				return true;
   287 		case keyCode.PAGE_UP:
   294 			case keyCode.PAGE_UP:
   288 			this._repeat( null, options.page, event );
   295 				this._repeat( null, options.page, event );
   289 			return true;
   296 				return true;
   290 		case keyCode.PAGE_DOWN:
   297 			case keyCode.PAGE_DOWN:
   291 			this._repeat( null, -options.page, event );
   298 				this._repeat( null, -options.page, event );
   292 			return true;
   299 				return true;
   293 		}
   300 		}
   294 
   301 
   295 		return false;
   302 		return false;
   296 	},
   303 	},
   297 
   304 
   335 
   342 
   336 	_increment: function( i ) {
   343 	_increment: function( i ) {
   337 		var incremental = this.options.incremental;
   344 		var incremental = this.options.incremental;
   338 
   345 
   339 		if ( incremental ) {
   346 		if ( incremental ) {
   340 			return $.isFunction( incremental ) ?
   347 			return typeof incremental === "function" ?
   341 				incremental( i ) :
   348 				incremental( i ) :
   342 				Math.floor( i * i * i / 50000 - i * i / 500 + 17 * i / 200 + 1 );
   349 				Math.floor( i * i * i / 50000 - i * i / 500 + 17 * i / 200 + 1 );
   343 		}
   350 		}
   344 
   351 
   345 		return 1;
   352 		return 1;
   433 		this._toggleClass( this.uiSpinner, null, "ui-state-disabled", !!value );
   440 		this._toggleClass( this.uiSpinner, null, "ui-state-disabled", !!value );
   434 		this.element.prop( "disabled", !!value );
   441 		this.element.prop( "disabled", !!value );
   435 		this.buttons.button( value ? "disable" : "enable" );
   442 		this.buttons.button( value ? "disable" : "enable" );
   436 	},
   443 	},
   437 
   444 
   438 	_setOptions: spinnerModifer( function( options ) {
   445 	_setOptions: spinnerModifier( function( options ) {
   439 		this._super( options );
   446 		this._super( options );
   440 	} ),
   447 	} ),
   441 
   448 
   442 	_parse: function( val ) {
   449 	_parse: function( val ) {
   443 		if ( typeof val === "string" && val !== "" ) {
   450 		if ( typeof val === "string" && val !== "" ) {
   500 			.removeAttr( "autocomplete role aria-valuemin aria-valuemax aria-valuenow" );
   507 			.removeAttr( "autocomplete role aria-valuemin aria-valuemax aria-valuenow" );
   501 
   508 
   502 		this.uiSpinner.replaceWith( this.element );
   509 		this.uiSpinner.replaceWith( this.element );
   503 	},
   510 	},
   504 
   511 
   505 	stepUp: spinnerModifer( function( steps ) {
   512 	stepUp: spinnerModifier( function( steps ) {
   506 		this._stepUp( steps );
   513 		this._stepUp( steps );
   507 	} ),
   514 	} ),
   508 	_stepUp: function( steps ) {
   515 	_stepUp: function( steps ) {
   509 		if ( this._start() ) {
   516 		if ( this._start() ) {
   510 			this._spin( ( steps || 1 ) * this.options.step );
   517 			this._spin( ( steps || 1 ) * this.options.step );
   511 			this._stop();
   518 			this._stop();
   512 		}
   519 		}
   513 	},
   520 	},
   514 
   521 
   515 	stepDown: spinnerModifer( function( steps ) {
   522 	stepDown: spinnerModifier( function( steps ) {
   516 		this._stepDown( steps );
   523 		this._stepDown( steps );
   517 	} ),
   524 	} ),
   518 	_stepDown: function( steps ) {
   525 	_stepDown: function( steps ) {
   519 		if ( this._start() ) {
   526 		if ( this._start() ) {
   520 			this._spin( ( steps || 1 ) * -this.options.step );
   527 			this._spin( ( steps || 1 ) * -this.options.step );
   521 			this._stop();
   528 			this._stop();
   522 		}
   529 		}
   523 	},
   530 	},
   524 
   531 
   525 	pageUp: spinnerModifer( function( pages ) {
   532 	pageUp: spinnerModifier( function( pages ) {
   526 		this._stepUp( ( pages || 1 ) * this.options.page );
   533 		this._stepUp( ( pages || 1 ) * this.options.page );
   527 	} ),
   534 	} ),
   528 
   535 
   529 	pageDown: spinnerModifer( function( pages ) {
   536 	pageDown: spinnerModifier( function( pages ) {
   530 		this._stepDown( ( pages || 1 ) * this.options.page );
   537 		this._stepDown( ( pages || 1 ) * this.options.page );
   531 	} ),
   538 	} ),
   532 
   539 
   533 	value: function( newVal ) {
   540 	value: function( newVal ) {
   534 		if ( !arguments.length ) {
   541 		if ( !arguments.length ) {
   535 			return this._parse( this.element.val() );
   542 			return this._parse( this.element.val() );
   536 		}
   543 		}
   537 		spinnerModifer( this._value ).call( this, newVal );
   544 		spinnerModifier( this._value ).call( this, newVal );
   538 	},
   545 	},
   539 
   546 
   540 	widget: function() {
   547 	widget: function() {
   541 		return this.uiSpinner;
   548 		return this.uiSpinner;
   542 	}
   549 	}
   552 			this.uiSpinner = this.element
   559 			this.uiSpinner = this.element
   553 				.attr( "autocomplete", "off" )
   560 				.attr( "autocomplete", "off" )
   554 				.wrap( this._uiSpinnerHtml() )
   561 				.wrap( this._uiSpinnerHtml() )
   555 				.parent()
   562 				.parent()
   556 
   563 
   557 					// Add buttons
   564 				// Add buttons
   558 					.append( this._buttonHtml() );
   565 				.append( this._buttonHtml() );
   559 		},
   566 		},
   560 		_uiSpinnerHtml: function() {
   567 		_uiSpinnerHtml: function() {
   561 			return "<span>";
   568 			return "<span>";
   562 		},
   569 		},
   563 
   570 
   567 	} );
   574 	} );
   568 }
   575 }
   569 
   576 
   570 return $.ui.spinner;
   577 return $.ui.spinner;
   571 
   578 
   572 } ) );
   579 } );