wp/wp-includes/js/jquery/ui/autocomplete.js
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     1 /*!
     1 /*!
     2  * jQuery UI Autocomplete 1.13.1
     2  * jQuery UI Autocomplete 1.13.3
     3  * http://jqueryui.com
     3  * https://jqueryui.com
     4  *
     4  *
     5  * Copyright jQuery Foundation and other contributors
     5  * Copyright OpenJS Foundation and other contributors
     6  * Released under the MIT license.
     6  * Released under the MIT license.
     7  * http://jquery.org/license
     7  * https://jquery.org/license
     8  */
     8  */
     9 
     9 
    10 //>>label: Autocomplete
    10 //>>label: Autocomplete
    11 //>>group: Widgets
    11 //>>group: Widgets
    12 //>>description: Lists suggested words as the user is typing.
    12 //>>description: Lists suggested words as the user is typing.
    13 //>>docs: http://api.jqueryui.com/autocomplete/
    13 //>>docs: https://api.jqueryui.com/autocomplete/
    14 //>>demos: http://jqueryui.com/autocomplete/
    14 //>>demos: https://jqueryui.com/autocomplete/
    15 //>>css.structure: ../../themes/base/core.css
    15 //>>css.structure: ../../themes/base/core.css
    16 //>>css.structure: ../../themes/base/autocomplete.css
    16 //>>css.structure: ../../themes/base/autocomplete.css
    17 //>>css.theme: ../../themes/base/theme.css
    17 //>>css.theme: ../../themes/base/theme.css
    18 
    18 
    19 ( function( factory ) {
    19 ( function( factory ) {
    23 
    23 
    24 		// AMD. Register as an anonymous module.
    24 		// AMD. Register as an anonymous module.
    25 		define( [
    25 		define( [
    26 			"jquery",
    26 			"jquery",
    27 			"./menu",
    27 			"./menu",
    28 			"./core"
    28 			"../keycode",
       
    29 			"../position",
       
    30 			"../safe-active-element",
       
    31 			"../version",
       
    32 			"../widget"
    29 		], factory );
    33 		], factory );
    30 	} else {
    34 	} else {
    31 
    35 
    32 		// Browser globals
    36 		// Browser globals
    33 		factory( jQuery );
    37 		factory( jQuery );
    34 	}
    38 	}
    35 } )( function( $ ) {
    39 } )( function( $ ) {
    36 "use strict";
    40 "use strict";
    37 
    41 
    38 $.widget( "ui.autocomplete", {
    42 $.widget( "ui.autocomplete", {
    39 	version: "1.13.1",
    43 	version: "1.13.3",
    40 	defaultElement: "<input>",
    44 	defaultElement: "<input>",
    41 	options: {
    45 	options: {
    42 		appendTo: null,
    46 		appendTo: null,
    43 		autoFocus: false,
    47 		autoFocus: false,
    44 		delay: 300,
    48 		delay: 300,
   102 				suppressKeyPress = false;
   106 				suppressKeyPress = false;
   103 				suppressInput = false;
   107 				suppressInput = false;
   104 				suppressKeyPressRepeat = false;
   108 				suppressKeyPressRepeat = false;
   105 				var keyCode = $.ui.keyCode;
   109 				var keyCode = $.ui.keyCode;
   106 				switch ( event.keyCode ) {
   110 				switch ( event.keyCode ) {
   107 					case keyCode.PAGE_UP:
   111 				case keyCode.PAGE_UP:
       
   112 					suppressKeyPress = true;
       
   113 					this._move( "previousPage", event );
       
   114 					break;
       
   115 				case keyCode.PAGE_DOWN:
       
   116 					suppressKeyPress = true;
       
   117 					this._move( "nextPage", event );
       
   118 					break;
       
   119 				case keyCode.UP:
       
   120 					suppressKeyPress = true;
       
   121 					this._keyEvent( "previous", event );
       
   122 					break;
       
   123 				case keyCode.DOWN:
       
   124 					suppressKeyPress = true;
       
   125 					this._keyEvent( "next", event );
       
   126 					break;
       
   127 				case keyCode.ENTER:
       
   128 
       
   129 					// when menu is open and has focus
       
   130 					if ( this.menu.active ) {
       
   131 
       
   132 						// #6055 - Opera still allows the keypress to occur
       
   133 						// which causes forms to submit
   108 						suppressKeyPress = true;
   134 						suppressKeyPress = true;
   109 						this._move( "previousPage", event );
   135 						event.preventDefault();
   110 						break;
   136 						this.menu.select( event );
   111 					case keyCode.PAGE_DOWN:
   137 					}
   112 						suppressKeyPress = true;
   138 					break;
   113 						this._move( "nextPage", event );
   139 				case keyCode.TAB:
   114 						break;
   140 					if ( this.menu.active ) {
   115 					case keyCode.UP:
   141 						this.menu.select( event );
   116 						suppressKeyPress = true;
   142 					}
   117 						this._keyEvent( "previous", event );
   143 					break;
   118 						break;
   144 				case keyCode.ESCAPE:
   119 					case keyCode.DOWN:
   145 					if ( this.menu.element.is( ":visible" ) ) {
   120 						suppressKeyPress = true;
   146 						if ( !this.isMultiLine ) {
   121 						this._keyEvent( "next", event );
   147 							this._value( this.term );
   122 						break;
       
   123 					case keyCode.ENTER:
       
   124 
       
   125 						// when menu is open and has focus
       
   126 						if ( this.menu.active ) {
       
   127 
       
   128 							// #6055 - Opera still allows the keypress to occur
       
   129 							// which causes forms to submit
       
   130 							suppressKeyPress = true;
       
   131 							event.preventDefault();
       
   132 							this.menu.select( event );
       
   133 						}
   148 						}
   134 						break;
   149 						this.close( event );
   135 					case keyCode.TAB:
   150 
   136 						if ( this.menu.active ) {
   151 						// Different browsers have different default behavior for escape
   137 							this.menu.select( event );
   152 						// Single press can mean undo or clear
   138 						}
   153 						// Double press in IE means clear the whole form
   139 						break;
   154 						event.preventDefault();
   140 					case keyCode.ESCAPE:
   155 					}
   141 						if ( this.menu.element.is( ":visible" ) ) {
   156 					break;
   142 							if ( !this.isMultiLine ) {
   157 				default:
   143 								this._value( this.term );
   158 					suppressKeyPressRepeat = true;
   144 							}
   159 
   145 							this.close( event );
   160 					// search timeout should be triggered before the input value is changed
   146 
   161 					this._searchTimeout( event );
   147 							// Different browsers have different default behavior for escape
   162 					break;
   148 							// Single press can mean undo or clear
       
   149 							// Double press in IE means clear the whole form
       
   150 							event.preventDefault();
       
   151 						}
       
   152 						break;
       
   153 					default:
       
   154 						suppressKeyPressRepeat = true;
       
   155 
       
   156 						// search timeout should be triggered before the input value is changed
       
   157 						this._searchTimeout( event );
       
   158 						break;
       
   159 				}
   163 				}
   160 			},
   164 			},
   161 			keypress: function( event ) {
   165 			keypress: function( event ) {
   162 				if ( suppressKeyPress ) {
   166 				if ( suppressKeyPress ) {
   163 					suppressKeyPress = false;
   167 					suppressKeyPress = false;
   171 				}
   175 				}
   172 
   176 
   173 				// Replicate some key handlers to allow them to repeat in Firefox and Opera
   177 				// Replicate some key handlers to allow them to repeat in Firefox and Opera
   174 				var keyCode = $.ui.keyCode;
   178 				var keyCode = $.ui.keyCode;
   175 				switch ( event.keyCode ) {
   179 				switch ( event.keyCode ) {
   176 					case keyCode.PAGE_UP:
   180 				case keyCode.PAGE_UP:
   177 						this._move( "previousPage", event );
   181 					this._move( "previousPage", event );
   178 						break;
   182 					break;
   179 					case keyCode.PAGE_DOWN:
   183 				case keyCode.PAGE_DOWN:
   180 						this._move( "nextPage", event );
   184 					this._move( "nextPage", event );
   181 						break;
   185 					break;
   182 					case keyCode.UP:
   186 				case keyCode.UP:
   183 						this._keyEvent( "previous", event );
   187 					this._keyEvent( "previous", event );
   184 						break;
   188 					break;
   185 					case keyCode.DOWN:
   189 				case keyCode.DOWN:
   186 						this._keyEvent( "next", event );
   190 					this._keyEvent( "next", event );
   187 						break;
   191 					break;
   188 				}
   192 				}
   189 			},
   193 			},
   190 			input: function( event ) {
   194 			input: function( event ) {
   191 				if ( suppressInput ) {
   195 				if ( suppressInput ) {
   192 					suppressInput = false;
   196 					suppressInput = false;
   575 		if ( !this.menu.element.is( ":visible" ) ) {
   579 		if ( !this.menu.element.is( ":visible" ) ) {
   576 			this.search( null, event );
   580 			this.search( null, event );
   577 			return;
   581 			return;
   578 		}
   582 		}
   579 		if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
   583 		if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
   580 			this.menu.isLastItem() && /^next/.test( direction ) ) {
   584 				this.menu.isLastItem() && /^next/.test( direction ) ) {
   581 
   585 
   582 			if ( !this.isMultiLine ) {
   586 			if ( !this.isMultiLine ) {
   583 				this._value( this.term );
   587 				this._value( this.term );
   584 			}
   588 			}
   585 
   589