1 /*! jQuery UI - v1.12.1 - 2018-12-06
3 * Includes: widget.js, position.js, keycode.js, unique-id.js, widgets/autocomplete.js, widgets/menu.js
4 * Copyright jQuery Foundation and other contributors; Licensed MIT */
7 if ( typeof define === "function" && define.amd ) {
9 // AMD. Register as an anonymous module.
10 define([ "jquery" ], factory );
20 var version = $.ui.version = "1.12.1";
24 * jQuery UI Widget 1.12.1
27 * Copyright jQuery Foundation and other contributors
28 * Released under the MIT license.
29 * http://jquery.org/license
34 //>>description: Provides a factory for creating stateful widgets with a common API.
35 //>>docs: http://api.jqueryui.com/jQuery.widget/
36 //>>demos: http://jqueryui.com/widget/
41 var widgetSlice = Array.prototype.slice;
43 $.cleanData = ( function( orig ) {
44 return function( elems ) {
46 for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
49 // Only trigger remove when necessary to save time
50 events = $._data( elem, "events" );
51 if ( events && events.remove ) {
52 $( elem ).triggerHandler( "remove" );
55 // Http://bugs.jquery.com/ticket/8235
62 $.widget = function( name, base, prototype ) {
63 var existingConstructor, constructor, basePrototype;
65 // ProxiedPrototype allows the provided prototype to remain unmodified
66 // so that it can be used as a mixin for multiple widgets (#8876)
67 var proxiedPrototype = {};
69 var namespace = name.split( "." )[ 0 ];
70 name = name.split( "." )[ 1 ];
71 var fullName = namespace + "-" + name;
78 if ( $.isArray( prototype ) ) {
79 prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
82 // Create selector for plugin
83 $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
84 return !!$.data( elem, fullName );
87 $[ namespace ] = $[ namespace ] || {};
88 existingConstructor = $[ namespace ][ name ];
89 constructor = $[ namespace ][ name ] = function( options, element ) {
91 // Allow instantiation without "new" keyword
92 if ( !this._createWidget ) {
93 return new constructor( options, element );
96 // Allow instantiation without initializing for simple inheritance
97 // must use "new" keyword (the code above always passes args)
98 if ( arguments.length ) {
99 this._createWidget( options, element );
103 // Extend with the existing constructor to carry over any static properties
104 $.extend( constructor, existingConstructor, {
105 version: prototype.version,
107 // Copy the object used to create the prototype in case we need to
108 // redefine the widget later
109 _proto: $.extend( {}, prototype ),
111 // Track widgets that inherit from this widget in case this widget is
112 // redefined after a widget inherits from it
113 _childConstructors: []
116 basePrototype = new base();
118 // We need to make the options hash a property directly on the new instance
119 // otherwise we'll modify the options hash on the prototype that we're
121 basePrototype.options = $.widget.extend( {}, basePrototype.options );
122 $.each( prototype, function( prop, value ) {
123 if ( !$.isFunction( value ) ) {
124 proxiedPrototype[ prop ] = value;
127 proxiedPrototype[ prop ] = ( function() {
129 return base.prototype[ prop ].apply( this, arguments );
132 function _superApply( args ) {
133 return base.prototype[ prop ].apply( this, args );
137 var __super = this._super;
138 var __superApply = this._superApply;
141 this._super = _super;
142 this._superApply = _superApply;
144 returnValue = value.apply( this, arguments );
146 this._super = __super;
147 this._superApply = __superApply;
153 constructor.prototype = $.widget.extend( basePrototype, {
155 // TODO: remove support for widgetEventPrefix
156 // always use the name + a colon as the prefix, e.g., draggable:start
157 // don't prefix for widgets that aren't DOM-based
158 widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name
159 }, proxiedPrototype, {
160 constructor: constructor,
161 namespace: namespace,
163 widgetFullName: fullName
166 // If this widget is being redefined then we need to find all widgets that
167 // are inheriting from it and redefine all of them so that they inherit from
168 // the new version of this widget. We're essentially trying to replace one
169 // level in the prototype chain.
170 if ( existingConstructor ) {
171 $.each( existingConstructor._childConstructors, function( i, child ) {
172 var childPrototype = child.prototype;
174 // Redefine the child widget using the same prototype that was
175 // originally used, but inherit from the new version of the base
176 $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor,
180 // Remove the list of existing child constructors from the old constructor
181 // so the old child constructors can be garbage collected
182 delete existingConstructor._childConstructors;
184 base._childConstructors.push( constructor );
187 $.widget.bridge( name, constructor );
192 $.widget.extend = function( target ) {
193 var input = widgetSlice.call( arguments, 1 );
195 var inputLength = input.length;
199 for ( ; inputIndex < inputLength; inputIndex++ ) {
200 for ( key in input[ inputIndex ] ) {
201 value = input[ inputIndex ][ key ];
202 if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
205 if ( $.isPlainObject( value ) ) {
206 target[ key ] = $.isPlainObject( target[ key ] ) ?
207 $.widget.extend( {}, target[ key ], value ) :
209 // Don't extend strings, arrays, etc. with objects
210 $.widget.extend( {}, value );
212 // Copy everything else by reference
214 target[ key ] = value;
222 $.widget.bridge = function( name, object ) {
223 var fullName = object.prototype.widgetFullName || name;
224 $.fn[ name ] = function( options ) {
225 var isMethodCall = typeof options === "string";
226 var args = widgetSlice.call( arguments, 1 );
227 var returnValue = this;
229 if ( isMethodCall ) {
231 // If this is an empty collection, we need to have the instance method
232 // return undefined instead of the jQuery instance
233 if ( !this.length && options === "instance" ) {
234 returnValue = undefined;
236 this.each( function() {
238 var instance = $.data( this, fullName );
240 if ( options === "instance" ) {
241 returnValue = instance;
246 return $.error( "cannot call methods on " + name +
247 " prior to initialization; " +
248 "attempted to call method '" + options + "'" );
251 if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
252 return $.error( "no such method '" + options + "' for " + name +
253 " widget instance" );
256 methodValue = instance[ options ].apply( instance, args );
258 if ( methodValue !== instance && methodValue !== undefined ) {
259 returnValue = methodValue && methodValue.jquery ?
260 returnValue.pushStack( methodValue.get() ) :
268 // Allow multiple hashes to be passed on init
270 options = $.widget.extend.apply( null, [ options ].concat( args ) );
273 this.each( function() {
274 var instance = $.data( this, fullName );
276 instance.option( options || {} );
277 if ( instance._init ) {
281 $.data( this, fullName, new object( options, this ) );
290 $.Widget = function( /* options, element */ ) {};
291 $.Widget._childConstructors = [];
293 $.Widget.prototype = {
294 widgetName: "widget",
295 widgetEventPrefix: "",
296 defaultElement: "<div>",
306 _createWidget: function( options, element ) {
307 element = $( element || this.defaultElement || this )[ 0 ];
308 this.element = $( element );
309 this.uuid = widgetUuid++;
310 this.eventNamespace = "." + this.widgetName + this.uuid;
313 this.hoverable = $();
314 this.focusable = $();
315 this.classesElementLookup = {};
317 if ( element !== this ) {
318 $.data( element, this.widgetFullName, this );
319 this._on( true, this.element, {
320 remove: function( event ) {
321 if ( event.target === element ) {
326 this.document = $( element.style ?
328 // Element within the document
329 element.ownerDocument :
331 // Element is window or document
332 element.document || element );
333 this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
336 this.options = $.widget.extend( {},
338 this._getCreateOptions(),
343 if ( this.options.disabled ) {
344 this._setOptionDisabled( this.options.disabled );
347 this._trigger( "create", null, this._getCreateEventData() );
351 _getCreateOptions: function() {
355 _getCreateEventData: $.noop,
361 destroy: function() {
365 $.each( this.classesElementLookup, function( key, value ) {
366 that._removeClass( value, key );
369 // We can probably remove the unbind calls in 2.0
370 // all event bindings should go through this._on()
372 .off( this.eventNamespace )
373 .removeData( this.widgetFullName );
375 .off( this.eventNamespace )
376 .removeAttr( "aria-disabled" );
378 // Clean up events and states
379 this.bindings.off( this.eventNamespace );
388 option: function( key, value ) {
394 if ( arguments.length === 0 ) {
396 // Don't return a reference to the internal hash
397 return $.widget.extend( {}, this.options );
400 if ( typeof key === "string" ) {
402 // Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
404 parts = key.split( "." );
406 if ( parts.length ) {
407 curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
408 for ( i = 0; i < parts.length - 1; i++ ) {
409 curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
410 curOption = curOption[ parts[ i ] ];
413 if ( arguments.length === 1 ) {
414 return curOption[ key ] === undefined ? null : curOption[ key ];
416 curOption[ key ] = value;
418 if ( arguments.length === 1 ) {
419 return this.options[ key ] === undefined ? null : this.options[ key ];
421 options[ key ] = value;
425 this._setOptions( options );
430 _setOptions: function( options ) {
433 for ( key in options ) {
434 this._setOption( key, options[ key ] );
440 _setOption: function( key, value ) {
441 if ( key === "classes" ) {
442 this._setOptionClasses( value );
445 this.options[ key ] = value;
447 if ( key === "disabled" ) {
448 this._setOptionDisabled( value );
454 _setOptionClasses: function( value ) {
455 var classKey, elements, currentElements;
457 for ( classKey in value ) {
458 currentElements = this.classesElementLookup[ classKey ];
459 if ( value[ classKey ] === this.options.classes[ classKey ] ||
461 !currentElements.length ) {
465 // We are doing this to create a new jQuery object because the _removeClass() call
466 // on the next line is going to destroy the reference to the current elements being
467 // tracked. We need to save a copy of this collection so that we can add the new classes
469 elements = $( currentElements.get() );
470 this._removeClass( currentElements, classKey );
472 // We don't use _addClass() here, because that uses this.options.classes
473 // for generating the string of classes. We want to use the value passed in from
474 // _setOption(), this is the new value of the classes option which was passed to
475 // _setOption(). We pass this value directly to _classes().
476 elements.addClass( this._classes( {
485 _setOptionDisabled: function( value ) {
486 this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
488 // If the widget is becoming disabled, then nothing is interactive
490 this._removeClass( this.hoverable, null, "ui-state-hover" );
491 this._removeClass( this.focusable, null, "ui-state-focus" );
496 return this._setOptions( { disabled: false } );
499 disable: function() {
500 return this._setOptions( { disabled: true } );
503 _classes: function( options ) {
507 options = $.extend( {
508 element: this.element,
509 classes: this.options.classes || {}
512 function processClassString( classes, checkOption ) {
514 for ( i = 0; i < classes.length; i++ ) {
515 current = that.classesElementLookup[ classes[ i ] ] || $();
517 current = $( $.unique( current.get().concat( options.element.get() ) ) );
519 current = $( current.not( options.element ).get() );
521 that.classesElementLookup[ classes[ i ] ] = current;
522 full.push( classes[ i ] );
523 if ( checkOption && options.classes[ classes[ i ] ] ) {
524 full.push( options.classes[ classes[ i ] ] );
529 this._on( options.element, {
530 "remove": "_untrackClassesElement"
533 if ( options.keys ) {
534 processClassString( options.keys.match( /\S+/g ) || [], true );
536 if ( options.extra ) {
537 processClassString( options.extra.match( /\S+/g ) || [] );
540 return full.join( " " );
543 _untrackClassesElement: function( event ) {
545 $.each( that.classesElementLookup, function( key, value ) {
546 if ( $.inArray( event.target, value ) !== -1 ) {
547 that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
552 _removeClass: function( element, keys, extra ) {
553 return this._toggleClass( element, keys, extra, false );
556 _addClass: function( element, keys, extra ) {
557 return this._toggleClass( element, keys, extra, true );
560 _toggleClass: function( element, keys, extra, add ) {
561 add = ( typeof add === "boolean" ) ? add : extra;
562 var shift = ( typeof element === "string" || element === null ),
564 extra: shift ? keys : extra,
565 keys: shift ? element : keys,
566 element: shift ? this.element : element,
569 options.element.toggleClass( this._classes( options ), add );
573 _on: function( suppressDisabledCheck, element, handlers ) {
577 // No suppressDisabledCheck flag, shuffle arguments
578 if ( typeof suppressDisabledCheck !== "boolean" ) {
580 element = suppressDisabledCheck;
581 suppressDisabledCheck = false;
584 // No element argument, shuffle and use this.element
587 element = this.element;
588 delegateElement = this.widget();
590 element = delegateElement = $( element );
591 this.bindings = this.bindings.add( element );
594 $.each( handlers, function( event, handler ) {
595 function handlerProxy() {
597 // Allow widgets to customize the disabled handling
598 // - disabled as an array instead of boolean
599 // - disabled class as method for disabling individual parts
600 if ( !suppressDisabledCheck &&
601 ( instance.options.disabled === true ||
602 $( this ).hasClass( "ui-state-disabled" ) ) ) {
605 return ( typeof handler === "string" ? instance[ handler ] : handler )
606 .apply( instance, arguments );
609 // Copy the guid so direct unbinding works
610 if ( typeof handler !== "string" ) {
611 handlerProxy.guid = handler.guid =
612 handler.guid || handlerProxy.guid || $.guid++;
615 var match = event.match( /^([\w:-]*)\s*(.*)$/ );
616 var eventName = match[ 1 ] + instance.eventNamespace;
617 var selector = match[ 2 ];
620 delegateElement.on( eventName, selector, handlerProxy );
622 element.on( eventName, handlerProxy );
627 _off: function( element, eventName ) {
628 eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
630 element.off( eventName ).off( eventName );
632 // Clear the stack to avoid memory leaks (#10056)
633 this.bindings = $( this.bindings.not( element ).get() );
634 this.focusable = $( this.focusable.not( element ).get() );
635 this.hoverable = $( this.hoverable.not( element ).get() );
638 _delay: function( handler, delay ) {
639 function handlerProxy() {
640 return ( typeof handler === "string" ? instance[ handler ] : handler )
641 .apply( instance, arguments );
644 return setTimeout( handlerProxy, delay || 0 );
647 _hoverable: function( element ) {
648 this.hoverable = this.hoverable.add( element );
650 mouseenter: function( event ) {
651 this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
653 mouseleave: function( event ) {
654 this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
659 _focusable: function( element ) {
660 this.focusable = this.focusable.add( element );
662 focusin: function( event ) {
663 this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
665 focusout: function( event ) {
666 this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
671 _trigger: function( type, event, data ) {
673 var callback = this.options[ type ];
676 event = $.Event( event );
677 event.type = ( type === this.widgetEventPrefix ?
679 this.widgetEventPrefix + type ).toLowerCase();
681 // The original event may come from any element
682 // so we need to reset the target on the new event
683 event.target = this.element[ 0 ];
685 // Copy original event properties over to the new event
686 orig = event.originalEvent;
688 for ( prop in orig ) {
689 if ( !( prop in event ) ) {
690 event[ prop ] = orig[ prop ];
695 this.element.trigger( event, data );
696 return !( $.isFunction( callback ) &&
697 callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
698 event.isDefaultPrevented() );
702 $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
703 $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
704 if ( typeof options === "string" ) {
705 options = { effect: options };
709 var effectName = !options ?
711 options === true || typeof options === "number" ?
713 options.effect || defaultEffect;
715 options = options || {};
716 if ( typeof options === "number" ) {
717 options = { duration: options };
720 hasOptions = !$.isEmptyObject( options );
721 options.complete = callback;
723 if ( options.delay ) {
724 element.delay( options.delay );
727 if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
728 element[ method ]( options );
729 } else if ( effectName !== method && element[ effectName ] ) {
730 element[ effectName ]( options.duration, options.easing, callback );
732 element.queue( function( next ) {
733 $( this )[ method ]();
735 callback.call( element[ 0 ] );
743 var widget = $.widget;
747 * jQuery UI Position 1.12.1
748 * http://jqueryui.com
750 * Copyright jQuery Foundation and other contributors
751 * Released under the MIT license.
752 * http://jquery.org/license
754 * http://api.jqueryui.com/position/
759 //>>description: Positions elements relative to other elements.
760 //>>docs: http://api.jqueryui.com/position/
761 //>>demos: http://jqueryui.com/position/
765 var cachedScrollbarWidth,
768 rhorizontal = /left|center|right/,
769 rvertical = /top|center|bottom/,
770 roffset = /[\+\-]\d+(\.[\d]+)?%?/,
773 _position = $.fn.position;
775 function getOffsets( offsets, width, height ) {
777 parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
778 parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
782 function parseCss( element, property ) {
783 return parseInt( $.css( element, property ), 10 ) || 0;
786 function getDimensions( elem ) {
788 if ( raw.nodeType === 9 ) {
791 height: elem.height(),
792 offset: { top: 0, left: 0 }
795 if ( $.isWindow( raw ) ) {
798 height: elem.height(),
799 offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
802 if ( raw.preventDefault ) {
806 offset: { top: raw.pageY, left: raw.pageX }
810 width: elem.outerWidth(),
811 height: elem.outerHeight(),
812 offset: elem.offset()
817 scrollbarWidth: function() {
818 if ( cachedScrollbarWidth !== undefined ) {
819 return cachedScrollbarWidth;
823 "style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'>" +
824 "<div style='height:100px;width:auto;'></div></div>" ),
825 innerDiv = div.children()[ 0 ];
827 $( "body" ).append( div );
828 w1 = innerDiv.offsetWidth;
829 div.css( "overflow", "scroll" );
831 w2 = innerDiv.offsetWidth;
834 w2 = div[ 0 ].clientWidth;
839 return ( cachedScrollbarWidth = w1 - w2 );
841 getScrollInfo: function( within ) {
842 var overflowX = within.isWindow || within.isDocument ? "" :
843 within.element.css( "overflow-x" ),
844 overflowY = within.isWindow || within.isDocument ? "" :
845 within.element.css( "overflow-y" ),
846 hasOverflowX = overflowX === "scroll" ||
847 ( overflowX === "auto" && within.width < within.element[ 0 ].scrollWidth ),
848 hasOverflowY = overflowY === "scroll" ||
849 ( overflowY === "auto" && within.height < within.element[ 0 ].scrollHeight );
851 width: hasOverflowY ? $.position.scrollbarWidth() : 0,
852 height: hasOverflowX ? $.position.scrollbarWidth() : 0
855 getWithinInfo: function( element ) {
856 var withinElement = $( element || window ),
857 isWindow = $.isWindow( withinElement[ 0 ] ),
858 isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
859 hasOffset = !isWindow && !isDocument;
861 element: withinElement,
863 isDocument: isDocument,
864 offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
865 scrollLeft: withinElement.scrollLeft(),
866 scrollTop: withinElement.scrollTop(),
867 width: withinElement.outerWidth(),
868 height: withinElement.outerHeight()
873 $.fn.position = function( options ) {
874 if ( !options || !options.of ) {
875 return _position.apply( this, arguments );
878 // Make a copy, we don't want to modify arguments
879 options = $.extend( {}, options );
881 var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
882 target = $( options.of ),
883 within = $.position.getWithinInfo( options.within ),
884 scrollInfo = $.position.getScrollInfo( within ),
885 collision = ( options.collision || "flip" ).split( " " ),
888 dimensions = getDimensions( target );
889 if ( target[ 0 ].preventDefault ) {
891 // Force left top to allow flipping
892 options.at = "left top";
894 targetWidth = dimensions.width;
895 targetHeight = dimensions.height;
896 targetOffset = dimensions.offset;
898 // Clone to reuse original targetOffset later
899 basePosition = $.extend( {}, targetOffset );
901 // Force my and at to have valid horizontal and vertical positions
902 // if a value is missing or invalid, it will be converted to center
903 $.each( [ "my", "at" ], function() {
904 var pos = ( options[ this ] || "" ).split( " " ),
908 if ( pos.length === 1 ) {
909 pos = rhorizontal.test( pos[ 0 ] ) ?
910 pos.concat( [ "center" ] ) :
911 rvertical.test( pos[ 0 ] ) ?
912 [ "center" ].concat( pos ) :
913 [ "center", "center" ];
915 pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
916 pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
919 horizontalOffset = roffset.exec( pos[ 0 ] );
920 verticalOffset = roffset.exec( pos[ 1 ] );
922 horizontalOffset ? horizontalOffset[ 0 ] : 0,
923 verticalOffset ? verticalOffset[ 0 ] : 0
926 // Reduce to just the positions without the offsets
928 rposition.exec( pos[ 0 ] )[ 0 ],
929 rposition.exec( pos[ 1 ] )[ 0 ]
933 // Normalize collision option
934 if ( collision.length === 1 ) {
935 collision[ 1 ] = collision[ 0 ];
938 if ( options.at[ 0 ] === "right" ) {
939 basePosition.left += targetWidth;
940 } else if ( options.at[ 0 ] === "center" ) {
941 basePosition.left += targetWidth / 2;
944 if ( options.at[ 1 ] === "bottom" ) {
945 basePosition.top += targetHeight;
946 } else if ( options.at[ 1 ] === "center" ) {
947 basePosition.top += targetHeight / 2;
950 atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
951 basePosition.left += atOffset[ 0 ];
952 basePosition.top += atOffset[ 1 ];
954 return this.each( function() {
955 var collisionPosition, using,
957 elemWidth = elem.outerWidth(),
958 elemHeight = elem.outerHeight(),
959 marginLeft = parseCss( this, "marginLeft" ),
960 marginTop = parseCss( this, "marginTop" ),
961 collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) +
963 collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) +
965 position = $.extend( {}, basePosition ),
966 myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
968 if ( options.my[ 0 ] === "right" ) {
969 position.left -= elemWidth;
970 } else if ( options.my[ 0 ] === "center" ) {
971 position.left -= elemWidth / 2;
974 if ( options.my[ 1 ] === "bottom" ) {
975 position.top -= elemHeight;
976 } else if ( options.my[ 1 ] === "center" ) {
977 position.top -= elemHeight / 2;
980 position.left += myOffset[ 0 ];
981 position.top += myOffset[ 1 ];
983 collisionPosition = {
984 marginLeft: marginLeft,
988 $.each( [ "left", "top" ], function( i, dir ) {
989 if ( $.ui.position[ collision[ i ] ] ) {
990 $.ui.position[ collision[ i ] ][ dir ]( position, {
991 targetWidth: targetWidth,
992 targetHeight: targetHeight,
993 elemWidth: elemWidth,
994 elemHeight: elemHeight,
995 collisionPosition: collisionPosition,
996 collisionWidth: collisionWidth,
997 collisionHeight: collisionHeight,
998 offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
1007 if ( options.using ) {
1009 // Adds feedback as second argument to using callback, if present
1010 using = function( props ) {
1011 var left = targetOffset.left - position.left,
1012 right = left + targetWidth - elemWidth,
1013 top = targetOffset.top - position.top,
1014 bottom = top + targetHeight - elemHeight,
1018 left: targetOffset.left,
1019 top: targetOffset.top,
1021 height: targetHeight
1025 left: position.left,
1030 horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
1031 vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
1033 if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
1034 feedback.horizontal = "center";
1036 if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
1037 feedback.vertical = "middle";
1039 if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
1040 feedback.important = "horizontal";
1042 feedback.important = "vertical";
1044 options.using.call( this, props, feedback );
1048 elem.offset( $.extend( position, { using: using } ) );
1054 left: function( position, data ) {
1055 var within = data.within,
1056 withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
1057 outerWidth = within.width,
1058 collisionPosLeft = position.left - data.collisionPosition.marginLeft,
1059 overLeft = withinOffset - collisionPosLeft,
1060 overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
1063 // Element is wider than within
1064 if ( data.collisionWidth > outerWidth ) {
1066 // Element is initially over the left side of within
1067 if ( overLeft > 0 && overRight <= 0 ) {
1068 newOverRight = position.left + overLeft + data.collisionWidth - outerWidth -
1070 position.left += overLeft - newOverRight;
1072 // Element is initially over right side of within
1073 } else if ( overRight > 0 && overLeft <= 0 ) {
1074 position.left = withinOffset;
1076 // Element is initially over both left and right sides of within
1078 if ( overLeft > overRight ) {
1079 position.left = withinOffset + outerWidth - data.collisionWidth;
1081 position.left = withinOffset;
1085 // Too far left -> align with left edge
1086 } else if ( overLeft > 0 ) {
1087 position.left += overLeft;
1089 // Too far right -> align with right edge
1090 } else if ( overRight > 0 ) {
1091 position.left -= overRight;
1093 // Adjust based on position and margin
1095 position.left = max( position.left - collisionPosLeft, position.left );
1098 top: function( position, data ) {
1099 var within = data.within,
1100 withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
1101 outerHeight = data.within.height,
1102 collisionPosTop = position.top - data.collisionPosition.marginTop,
1103 overTop = withinOffset - collisionPosTop,
1104 overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
1107 // Element is taller than within
1108 if ( data.collisionHeight > outerHeight ) {
1110 // Element is initially over the top of within
1111 if ( overTop > 0 && overBottom <= 0 ) {
1112 newOverBottom = position.top + overTop + data.collisionHeight - outerHeight -
1114 position.top += overTop - newOverBottom;
1116 // Element is initially over bottom of within
1117 } else if ( overBottom > 0 && overTop <= 0 ) {
1118 position.top = withinOffset;
1120 // Element is initially over both top and bottom of within
1122 if ( overTop > overBottom ) {
1123 position.top = withinOffset + outerHeight - data.collisionHeight;
1125 position.top = withinOffset;
1129 // Too far up -> align with top
1130 } else if ( overTop > 0 ) {
1131 position.top += overTop;
1133 // Too far down -> align with bottom edge
1134 } else if ( overBottom > 0 ) {
1135 position.top -= overBottom;
1137 // Adjust based on position and margin
1139 position.top = max( position.top - collisionPosTop, position.top );
1144 left: function( position, data ) {
1145 var within = data.within,
1146 withinOffset = within.offset.left + within.scrollLeft,
1147 outerWidth = within.width,
1148 offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
1149 collisionPosLeft = position.left - data.collisionPosition.marginLeft,
1150 overLeft = collisionPosLeft - offsetLeft,
1151 overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
1152 myOffset = data.my[ 0 ] === "left" ?
1154 data.my[ 0 ] === "right" ?
1157 atOffset = data.at[ 0 ] === "left" ?
1159 data.at[ 0 ] === "right" ?
1162 offset = -2 * data.offset[ 0 ],
1166 if ( overLeft < 0 ) {
1167 newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth -
1168 outerWidth - withinOffset;
1169 if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
1170 position.left += myOffset + atOffset + offset;
1172 } else if ( overRight > 0 ) {
1173 newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset +
1174 atOffset + offset - offsetLeft;
1175 if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
1176 position.left += myOffset + atOffset + offset;
1180 top: function( position, data ) {
1181 var within = data.within,
1182 withinOffset = within.offset.top + within.scrollTop,
1183 outerHeight = within.height,
1184 offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
1185 collisionPosTop = position.top - data.collisionPosition.marginTop,
1186 overTop = collisionPosTop - offsetTop,
1187 overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
1188 top = data.my[ 1 ] === "top",
1191 data.my[ 1 ] === "bottom" ?
1194 atOffset = data.at[ 1 ] === "top" ?
1196 data.at[ 1 ] === "bottom" ?
1197 -data.targetHeight :
1199 offset = -2 * data.offset[ 1 ],
1202 if ( overTop < 0 ) {
1203 newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight -
1204 outerHeight - withinOffset;
1205 if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {
1206 position.top += myOffset + atOffset + offset;
1208 } else if ( overBottom > 0 ) {
1209 newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset +
1211 if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {
1212 position.top += myOffset + atOffset + offset;
1219 $.ui.position.flip.left.apply( this, arguments );
1220 $.ui.position.fit.left.apply( this, arguments );
1223 $.ui.position.flip.top.apply( this, arguments );
1224 $.ui.position.fit.top.apply( this, arguments );
1231 var position = $.ui.position;
1235 * jQuery UI Keycode 1.12.1
1236 * http://jqueryui.com
1238 * Copyright jQuery Foundation and other contributors
1239 * Released under the MIT license.
1240 * http://jquery.org/license
1245 //>>description: Provide keycodes as keynames
1246 //>>docs: http://api.jqueryui.com/jQuery.ui.keyCode/
1249 var keycode = $.ui.keyCode = {
1270 * jQuery UI Unique ID 1.12.1
1271 * http://jqueryui.com
1273 * Copyright jQuery Foundation and other contributors
1274 * Released under the MIT license.
1275 * http://jquery.org/license
1280 //>>description: Functions to generate and remove uniqueId's
1281 //>>docs: http://api.jqueryui.com/uniqueId/
1285 var uniqueId = $.fn.extend( {
1286 uniqueId: ( function() {
1290 return this.each( function() {
1292 this.id = "ui-id-" + ( ++uuid );
1298 removeUniqueId: function() {
1299 return this.each( function() {
1300 if ( /^ui-id-\d+$/.test( this.id ) ) {
1301 $( this ).removeAttr( "id" );
1309 var safeActiveElement = $.ui.safeActiveElement = function( document ) {
1312 // Support: IE 9 only
1313 // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
1315 activeElement = document.activeElement;
1317 activeElement = document.body;
1320 // Support: IE 9 - 11 only
1321 // IE may return null instead of an element
1322 // Interestingly, this only seems to occur when NOT in an iframe
1323 if ( !activeElement ) {
1324 activeElement = document.body;
1327 // Support: IE 11 only
1328 // IE11 returns a seemingly empty object in some cases when accessing
1329 // document.activeElement from an <iframe>
1330 if ( !activeElement.nodeName ) {
1331 activeElement = document.body;
1334 return activeElement;
1339 * jQuery UI Menu 1.12.1
1340 * http://jqueryui.com
1342 * Copyright jQuery Foundation and other contributors
1343 * Released under the MIT license.
1344 * http://jquery.org/license
1349 //>>description: Creates nestable menus.
1350 //>>docs: http://api.jqueryui.com/menu/
1351 //>>demos: http://jqueryui.com/menu/
1352 //>>css.structure: ../../themes/base/core.css
1353 //>>css.structure: ../../themes/base/menu.css
1354 //>>css.theme: ../../themes/base/theme.css
1358 var widgetsMenu = $.widget( "ui.menu", {
1360 defaultElement: "<ul>",
1364 submenu: "ui-icon-caret-1-e"
1380 _create: function() {
1381 this.activeMenu = this.element;
1383 // Flag used to prevent firing of the click handler
1384 // as the event bubbles up through nested menus
1385 this.mouseHandled = false;
1389 role: this.options.role,
1393 this._addClass( "ui-menu", "ui-widget ui-widget-content" );
1396 // Prevent focus from sticking to links inside menu after clicking
1397 // them (focus should always stay on UL during navigation).
1398 "mousedown .ui-menu-item": function( event ) {
1399 event.preventDefault();
1401 "click .ui-menu-item": function( event ) {
1402 var target = $( event.target );
1403 var active = $( $.ui.safeActiveElement( this.document[ 0 ] ) );
1404 if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) {
1405 this.select( event );
1407 // Only set the mouseHandled flag if the event will bubble, see #9469.
1408 if ( !event.isPropagationStopped() ) {
1409 this.mouseHandled = true;
1412 // Open submenu on click
1413 if ( target.has( ".ui-menu" ).length ) {
1414 this.expand( event );
1415 } else if ( !this.element.is( ":focus" ) &&
1416 active.closest( ".ui-menu" ).length ) {
1418 // Redirect focus to the menu
1419 this.element.trigger( "focus", [ true ] );
1421 // If the active item is on the top level, let it stay active.
1422 // Otherwise, blur the active item since it is no longer visible.
1423 if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) {
1424 clearTimeout( this.timer );
1429 "mouseenter .ui-menu-item": function( event ) {
1431 // Ignore mouse events while typeahead is active, see #10458.
1432 // Prevents focusing the wrong item when typeahead causes a scroll while the mouse
1433 // is over an item in the menu
1434 if ( this.previousFilter ) {
1438 var actualTarget = $( event.target ).closest( ".ui-menu-item" ),
1439 target = $( event.currentTarget );
1441 // Ignore bubbled events on parent items, see #11641
1442 if ( actualTarget[ 0 ] !== target[ 0 ] ) {
1446 // Remove ui-state-active class from siblings of the newly focused menu item
1447 // to avoid a jump caused by adjacent elements both having a class with a border
1448 this._removeClass( target.siblings().children( ".ui-state-active" ),
1449 null, "ui-state-active" );
1450 this.focus( event, target );
1452 mouseleave: "collapseAll",
1453 "mouseleave .ui-menu": "collapseAll",
1454 focus: function( event, keepActiveItem ) {
1456 // If there's already an active item, keep it active
1457 // If not, activate the first item
1458 var item = this.active || this.element.find( this.options.items ).eq( 0 );
1460 if ( !keepActiveItem ) {
1461 this.focus( event, item );
1464 blur: function( event ) {
1465 this._delay( function() {
1466 var notContained = !$.contains(
1468 $.ui.safeActiveElement( this.document[ 0 ] )
1470 if ( notContained ) {
1471 this.collapseAll( event );
1480 // Clicks outside of a menu collapse any open menus
1481 this._on( this.document, {
1482 click: function( event ) {
1483 if ( this._closeOnDocumentClick( event ) ) {
1484 this.collapseAll( event );
1487 // Reset the mouseHandled flag
1488 this.mouseHandled = false;
1493 _destroy: function() {
1494 var items = this.element.find( ".ui-menu-item" )
1495 .removeAttr( "role aria-disabled" ),
1496 submenus = items.children( ".ui-menu-item-wrapper" )
1498 .removeAttr( "tabIndex role aria-haspopup" );
1500 // Destroy (sub)menus
1502 .removeAttr( "aria-activedescendant" )
1503 .find( ".ui-menu" ).addBack()
1504 .removeAttr( "role aria-labelledby aria-expanded aria-hidden aria-disabled " +
1509 submenus.children().each( function() {
1510 var elem = $( this );
1511 if ( elem.data( "ui-menu-submenu-caret" ) ) {
1517 _keydown: function( event ) {
1518 var match, prev, character, skip,
1519 preventDefault = true;
1521 switch ( event.keyCode ) {
1522 case $.ui.keyCode.PAGE_UP:
1523 this.previousPage( event );
1525 case $.ui.keyCode.PAGE_DOWN:
1526 this.nextPage( event );
1528 case $.ui.keyCode.HOME:
1529 this._move( "first", "first", event );
1531 case $.ui.keyCode.END:
1532 this._move( "last", "last", event );
1534 case $.ui.keyCode.UP:
1535 this.previous( event );
1537 case $.ui.keyCode.DOWN:
1540 case $.ui.keyCode.LEFT:
1541 this.collapse( event );
1543 case $.ui.keyCode.RIGHT:
1544 if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
1545 this.expand( event );
1548 case $.ui.keyCode.ENTER:
1549 case $.ui.keyCode.SPACE:
1550 this._activate( event );
1552 case $.ui.keyCode.ESCAPE:
1553 this.collapse( event );
1556 preventDefault = false;
1557 prev = this.previousFilter || "";
1560 // Support number pad values
1561 character = event.keyCode >= 96 && event.keyCode <= 105 ?
1562 ( event.keyCode - 96 ).toString() : String.fromCharCode( event.keyCode );
1564 clearTimeout( this.filterTimer );
1566 if ( character === prev ) {
1569 character = prev + character;
1572 match = this._filterMenuItems( character );
1573 match = skip && match.index( this.active.next() ) !== -1 ?
1574 this.active.nextAll( ".ui-menu-item" ) :
1577 // If no matches on the current filter, reset to the last character pressed
1578 // to move down the menu to the first item that starts with that character
1579 if ( !match.length ) {
1580 character = String.fromCharCode( event.keyCode );
1581 match = this._filterMenuItems( character );
1584 if ( match.length ) {
1585 this.focus( event, match );
1586 this.previousFilter = character;
1587 this.filterTimer = this._delay( function() {
1588 delete this.previousFilter;
1591 delete this.previousFilter;
1595 if ( preventDefault ) {
1596 event.preventDefault();
1600 _activate: function( event ) {
1601 if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
1602 if ( this.active.children( "[aria-haspopup='true']" ).length ) {
1603 this.expand( event );
1605 this.select( event );
1610 refresh: function() {
1611 var menus, items, newSubmenus, newItems, newWrappers,
1613 icon = this.options.icons.submenu,
1614 submenus = this.element.find( this.options.menus );
1616 this._toggleClass( "ui-menu-icons", null, !!this.element.find( ".ui-icon" ).length );
1618 // Initialize nested menus
1619 newSubmenus = submenus.filter( ":not(.ui-menu)" )
1622 role: this.options.role,
1623 "aria-hidden": "true",
1624 "aria-expanded": "false"
1627 var menu = $( this ),
1629 submenuCaret = $( "<span>" ).data( "ui-menu-submenu-caret", true );
1631 that._addClass( submenuCaret, "ui-menu-icon", "ui-icon " + icon );
1633 .attr( "aria-haspopup", "true" )
1634 .prepend( submenuCaret );
1635 menu.attr( "aria-labelledby", item.attr( "id" ) );
1638 this._addClass( newSubmenus, "ui-menu", "ui-widget ui-widget-content ui-front" );
1640 menus = submenus.add( this.element );
1641 items = menus.find( this.options.items );
1643 // Initialize menu-items containing spaces and/or dashes only as dividers
1644 items.not( ".ui-menu-item" ).each( function() {
1645 var item = $( this );
1646 if ( that._isDivider( item ) ) {
1647 that._addClass( item, "ui-menu-divider", "ui-widget-content" );
1651 // Don't refresh list items that are already adapted
1652 newItems = items.not( ".ui-menu-item, .ui-menu-divider" );
1653 newWrappers = newItems.children()
1658 role: this._itemRole()
1660 this._addClass( newItems, "ui-menu-item" )
1661 ._addClass( newWrappers, "ui-menu-item-wrapper" );
1663 // Add aria-disabled attribute to any disabled menu item
1664 items.filter( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
1666 // If the active item has been removed, blur the menu
1667 if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
1672 _itemRole: function() {
1676 }[ this.options.role ];
1679 _setOption: function( key, value ) {
1680 if ( key === "icons" ) {
1681 var icons = this.element.find( ".ui-menu-icon" );
1682 this._removeClass( icons, null, this.options.icons.submenu )
1683 ._addClass( icons, null, value.submenu );
1685 this._super( key, value );
1688 _setOptionDisabled: function( value ) {
1689 this._super( value );
1691 this.element.attr( "aria-disabled", String( value ) );
1692 this._toggleClass( null, "ui-state-disabled", !!value );
1695 focus: function( event, item ) {
1696 var nested, focused, activeParent;
1697 this.blur( event, event && event.type === "focus" );
1699 this._scrollIntoView( item );
1701 this.active = item.first();
1703 focused = this.active.children( ".ui-menu-item-wrapper" );
1704 this._addClass( focused, null, "ui-state-active" );
1706 // Only update aria-activedescendant if there's a role
1707 // otherwise we assume focus is managed elsewhere
1708 if ( this.options.role ) {
1709 this.element.attr( "aria-activedescendant", focused.attr( "id" ) );
1712 // Highlight active parent menu item, if any
1713 activeParent = this.active
1715 .closest( ".ui-menu-item" )
1716 .children( ".ui-menu-item-wrapper" );
1717 this._addClass( activeParent, null, "ui-state-active" );
1719 if ( event && event.type === "keydown" ) {
1722 this.timer = this._delay( function() {
1727 nested = item.children( ".ui-menu" );
1728 if ( nested.length && event && ( /^mouse/.test( event.type ) ) ) {
1729 this._startOpening( nested );
1731 this.activeMenu = item.parent();
1733 this._trigger( "focus", event, { item: item } );
1736 _scrollIntoView: function( item ) {
1737 var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
1738 if ( this._hasScroll() ) {
1739 borderTop = parseFloat( $.css( this.activeMenu[ 0 ], "borderTopWidth" ) ) || 0;
1740 paddingTop = parseFloat( $.css( this.activeMenu[ 0 ], "paddingTop" ) ) || 0;
1741 offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
1742 scroll = this.activeMenu.scrollTop();
1743 elementHeight = this.activeMenu.height();
1744 itemHeight = item.outerHeight();
1747 this.activeMenu.scrollTop( scroll + offset );
1748 } else if ( offset + itemHeight > elementHeight ) {
1749 this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
1754 blur: function( event, fromFocus ) {
1756 clearTimeout( this.timer );
1759 if ( !this.active ) {
1763 this._removeClass( this.active.children( ".ui-menu-item-wrapper" ),
1764 null, "ui-state-active" );
1766 this._trigger( "blur", event, { item: this.active } );
1770 _startOpening: function( submenu ) {
1771 clearTimeout( this.timer );
1773 // Don't open if already open fixes a Firefox bug that caused a .5 pixel
1774 // shift in the submenu position when mousing over the caret icon
1775 if ( submenu.attr( "aria-hidden" ) !== "true" ) {
1779 this.timer = this._delay( function() {
1781 this._open( submenu );
1785 _open: function( submenu ) {
1786 var position = $.extend( {
1788 }, this.options.position );
1790 clearTimeout( this.timer );
1791 this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) )
1793 .attr( "aria-hidden", "true" );
1797 .removeAttr( "aria-hidden" )
1798 .attr( "aria-expanded", "true" )
1799 .position( position );
1802 collapseAll: function( event, all ) {
1803 clearTimeout( this.timer );
1804 this.timer = this._delay( function() {
1806 // If we were passed an event, look for the submenu that contains the event
1807 var currentMenu = all ? this.element :
1808 $( event && event.target ).closest( this.element.find( ".ui-menu" ) );
1810 // If we found no valid submenu ancestor, use the main menu to close all
1812 if ( !currentMenu.length ) {
1813 currentMenu = this.element;
1816 this._close( currentMenu );
1820 // Work around active item staying active after menu is blurred
1821 this._removeClass( currentMenu.find( ".ui-state-active" ), null, "ui-state-active" );
1823 this.activeMenu = currentMenu;
1827 // With no arguments, closes the currently active menu - if nothing is active
1828 // it closes all menus. If passed an argument, it will search for menus BELOW
1829 _close: function( startMenu ) {
1831 startMenu = this.active ? this.active.parent() : this.element;
1834 startMenu.find( ".ui-menu" )
1836 .attr( "aria-hidden", "true" )
1837 .attr( "aria-expanded", "false" );
1840 _closeOnDocumentClick: function( event ) {
1841 return !$( event.target ).closest( ".ui-menu" ).length;
1844 _isDivider: function( item ) {
1846 // Match hyphen, em dash, en dash
1847 return !/[^\-\u2014\u2013\s]/.test( item.text() );
1850 collapse: function( event ) {
1851 var newItem = this.active &&
1852 this.active.parent().closest( ".ui-menu-item", this.element );
1853 if ( newItem && newItem.length ) {
1855 this.focus( event, newItem );
1859 expand: function( event ) {
1860 var newItem = this.active &&
1862 .children( ".ui-menu " )
1863 .find( this.options.items )
1866 if ( newItem && newItem.length ) {
1867 this._open( newItem.parent() );
1869 // Delay so Firefox will not hide activedescendant change in expanding submenu from AT
1870 this._delay( function() {
1871 this.focus( event, newItem );
1876 next: function( event ) {
1877 this._move( "next", "first", event );
1880 previous: function( event ) {
1881 this._move( "prev", "last", event );
1884 isFirstItem: function() {
1885 return this.active && !this.active.prevAll( ".ui-menu-item" ).length;
1888 isLastItem: function() {
1889 return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
1892 _move: function( direction, filter, event ) {
1894 if ( this.active ) {
1895 if ( direction === "first" || direction === "last" ) {
1897 [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
1901 [ direction + "All" ]( ".ui-menu-item" )
1905 if ( !next || !next.length || !this.active ) {
1906 next = this.activeMenu.find( this.options.items )[ filter ]();
1909 this.focus( event, next );
1912 nextPage: function( event ) {
1913 var item, base, height;
1915 if ( !this.active ) {
1919 if ( this.isLastItem() ) {
1922 if ( this._hasScroll() ) {
1923 base = this.active.offset().top;
1924 height = this.element.height();
1925 this.active.nextAll( ".ui-menu-item" ).each( function() {
1927 return item.offset().top - base - height < 0;
1930 this.focus( event, item );
1932 this.focus( event, this.activeMenu.find( this.options.items )
1933 [ !this.active ? "first" : "last" ]() );
1937 previousPage: function( event ) {
1938 var item, base, height;
1939 if ( !this.active ) {
1943 if ( this.isFirstItem() ) {
1946 if ( this._hasScroll() ) {
1947 base = this.active.offset().top;
1948 height = this.element.height();
1949 this.active.prevAll( ".ui-menu-item" ).each( function() {
1951 return item.offset().top - base + height > 0;
1954 this.focus( event, item );
1956 this.focus( event, this.activeMenu.find( this.options.items ).first() );
1960 _hasScroll: function() {
1961 return this.element.outerHeight() < this.element.prop( "scrollHeight" );
1964 select: function( event ) {
1966 // TODO: It should never be possible to not have an active item at this
1967 // point, but the tests don't trigger mouseenter before click.
1968 this.active = this.active || $( event.target ).closest( ".ui-menu-item" );
1969 var ui = { item: this.active };
1970 if ( !this.active.has( ".ui-menu" ).length ) {
1971 this.collapseAll( event, true );
1973 this._trigger( "select", event, ui );
1976 _filterMenuItems: function( character ) {
1977 var escapedCharacter = character.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" ),
1978 regex = new RegExp( "^" + escapedCharacter, "i" );
1980 return this.activeMenu
1981 .find( this.options.items )
1983 // Only match on items, not dividers or other content (#10571)
1984 .filter( ".ui-menu-item" )
1985 .filter( function() {
1987 $.trim( $( this ).children( ".ui-menu-item-wrapper" ).text() ) );
1994 * jQuery UI Autocomplete 1.12.1
1995 * http://jqueryui.com
1997 * Copyright jQuery Foundation and other contributors
1998 * Released under the MIT license.
1999 * http://jquery.org/license
2002 //>>label: Autocomplete
2004 //>>description: Lists suggested words as the user is typing.
2005 //>>docs: http://api.jqueryui.com/autocomplete/
2006 //>>demos: http://jqueryui.com/autocomplete/
2007 //>>css.structure: ../../themes/base/core.css
2008 //>>css.structure: ../../themes/base/autocomplete.css
2009 //>>css.theme: ../../themes/base/theme.css
2013 $.widget( "ui.autocomplete", {
2015 defaultElement: "<input>",
2041 _create: function() {
2043 // Some browsers only repeat keydown events, not keypress events,
2044 // so we use the suppressKeyPress flag to determine if we've already
2045 // handled the keydown event. #7269
2046 // Unfortunately the code for & in keypress is the same as the up arrow,
2047 // so we use the suppressKeyPressRepeat flag to avoid handling keypress
2048 // events when we know the keydown event was used to modify the
2049 // search term. #7799
2050 var suppressKeyPress, suppressKeyPressRepeat, suppressInput,
2051 nodeName = this.element[ 0 ].nodeName.toLowerCase(),
2052 isTextarea = nodeName === "textarea",
2053 isInput = nodeName === "input";
2055 // Textareas are always multi-line
2056 // Inputs are always single-line, even if inside a contentEditable element
2057 // IE also treats inputs as contentEditable
2058 // All other element types are determined by whether or not they're contentEditable
2059 this.isMultiLine = isTextarea || !isInput && this._isContentEditable( this.element );
2061 this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ];
2062 this.isNewMenu = true;
2064 this._addClass( "ui-autocomplete-input" );
2065 this.element.attr( "autocomplete", "off" );
2067 this._on( this.element, {
2068 keydown: function( event ) {
2069 if ( this.element.prop( "readOnly" ) ) {
2070 suppressKeyPress = true;
2071 suppressInput = true;
2072 suppressKeyPressRepeat = true;
2076 suppressKeyPress = false;
2077 suppressInput = false;
2078 suppressKeyPressRepeat = false;
2079 var keyCode = $.ui.keyCode;
2080 switch ( event.keyCode ) {
2081 case keyCode.PAGE_UP:
2082 suppressKeyPress = true;
2083 this._move( "previousPage", event );
2085 case keyCode.PAGE_DOWN:
2086 suppressKeyPress = true;
2087 this._move( "nextPage", event );
2090 suppressKeyPress = true;
2091 this._keyEvent( "previous", event );
2094 suppressKeyPress = true;
2095 this._keyEvent( "next", event );
2099 // when menu is open and has focus
2100 if ( this.menu.active ) {
2102 // #6055 - Opera still allows the keypress to occur
2103 // which causes forms to submit
2104 suppressKeyPress = true;
2105 event.preventDefault();
2106 this.menu.select( event );
2110 if ( this.menu.active ) {
2111 this.menu.select( event );
2114 case keyCode.ESCAPE:
2115 if ( this.menu.element.is( ":visible" ) ) {
2116 if ( !this.isMultiLine ) {
2117 this._value( this.term );
2119 this.close( event );
2121 // Different browsers have different default behavior for escape
2122 // Single press can mean undo or clear
2123 // Double press in IE means clear the whole form
2124 event.preventDefault();
2128 suppressKeyPressRepeat = true;
2130 // search timeout should be triggered before the input value is changed
2131 this._searchTimeout( event );
2135 keypress: function( event ) {
2136 if ( suppressKeyPress ) {
2137 suppressKeyPress = false;
2138 if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
2139 event.preventDefault();
2143 if ( suppressKeyPressRepeat ) {
2147 // Replicate some key handlers to allow them to repeat in Firefox and Opera
2148 var keyCode = $.ui.keyCode;
2149 switch ( event.keyCode ) {
2150 case keyCode.PAGE_UP:
2151 this._move( "previousPage", event );
2153 case keyCode.PAGE_DOWN:
2154 this._move( "nextPage", event );
2157 this._keyEvent( "previous", event );
2160 this._keyEvent( "next", event );
2164 input: function( event ) {
2165 if ( suppressInput ) {
2166 suppressInput = false;
2167 event.preventDefault();
2170 this._searchTimeout( event );
2173 this.selectedItem = null;
2174 this.previous = this._value();
2176 blur: function( event ) {
2177 if ( this.cancelBlur ) {
2178 delete this.cancelBlur;
2182 clearTimeout( this.searching );
2183 this.close( event );
2184 this._change( event );
2189 this.menu = $( "<ul>" )
2190 .appendTo( this._appendTo() )
2193 // disable ARIA support, the live region takes care of that
2197 .menu( "instance" );
2199 this._addClass( this.menu.element, "ui-autocomplete", "ui-front" );
2200 this._on( this.menu.element, {
2201 mousedown: function( event ) {
2203 // prevent moving focus out of the text field
2204 event.preventDefault();
2206 // IE doesn't prevent moving focus even with event.preventDefault()
2207 // so we set a flag to know when we should ignore the blur event
2208 this.cancelBlur = true;
2209 this._delay( function() {
2210 delete this.cancelBlur;
2212 // Support: IE 8 only
2213 // Right clicking a menu item or selecting text from the menu items will
2214 // result in focus moving out of the input. However, we've already received
2215 // and ignored the blur event because of the cancelBlur flag set above. So
2216 // we restore focus to ensure that the menu closes properly based on the user's
2218 if ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {
2219 this.element.trigger( "focus" );
2223 menufocus: function( event, ui ) {
2227 // Prevent accidental activation of menu items in Firefox (#7024 #9118)
2228 if ( this.isNewMenu ) {
2229 this.isNewMenu = false;
2230 if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) {
2233 this.document.one( "mousemove", function() {
2234 $( event.target ).trigger( event.originalEvent );
2241 item = ui.item.data( "ui-autocomplete-item" );
2242 if ( false !== this._trigger( "focus", event, { item: item } ) ) {
2244 // use value to match what will end up in the input, if it was a key event
2245 if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
2246 this._value( item.value );
2250 // Announce the value in the liveRegion
2251 label = ui.item.attr( "aria-label" ) || item.value;
2252 if ( label && $.trim( label ).length ) {
2253 this.liveRegion.children().hide();
2254 $( "<div>" ).text( label ).appendTo( this.liveRegion );
2257 menuselect: function( event, ui ) {
2258 var item = ui.item.data( "ui-autocomplete-item" ),
2259 previous = this.previous;
2261 // Only trigger when focus was lost (click on menu)
2262 if ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {
2263 this.element.trigger( "focus" );
2264 this.previous = previous;
2266 // #6109 - IE triggers two focus events and the second
2267 // is asynchronous, so we need to reset the previous
2268 // term synchronously and asynchronously :-(
2269 this._delay( function() {
2270 this.previous = previous;
2271 this.selectedItem = item;
2275 if ( false !== this._trigger( "select", event, { item: item } ) ) {
2276 this._value( item.value );
2279 // reset the term after the select event
2280 // this allows custom select handling to work properly
2281 this.term = this._value();
2283 this.close( event );
2284 this.selectedItem = item;
2288 this.liveRegion = $( "<div>", {
2290 "aria-live": "assertive",
2291 "aria-relevant": "additions"
2293 .appendTo( this.document[ 0 ].body );
2295 this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
2297 // Turning off autocomplete prevents the browser from remembering the
2298 // value when navigating through history, so we re-enable autocomplete
2299 // if the page is unloaded before the widget is destroyed. #7790
2300 this._on( this.window, {
2301 beforeunload: function() {
2302 this.element.removeAttr( "autocomplete" );
2307 _destroy: function() {
2308 clearTimeout( this.searching );
2309 this.element.removeAttr( "autocomplete" );
2310 this.menu.element.remove();
2311 this.liveRegion.remove();
2314 _setOption: function( key, value ) {
2315 this._super( key, value );
2316 if ( key === "source" ) {
2319 if ( key === "appendTo" ) {
2320 this.menu.element.appendTo( this._appendTo() );
2322 if ( key === "disabled" && value && this.xhr ) {
2327 _isEventTargetInWidget: function( event ) {
2328 var menuElement = this.menu.element[ 0 ];
2330 return event.target === this.element[ 0 ] ||
2331 event.target === menuElement ||
2332 $.contains( menuElement, event.target );
2335 _closeOnClickOutside: function( event ) {
2336 if ( !this._isEventTargetInWidget( event ) ) {
2341 _appendTo: function() {
2342 var element = this.options.appendTo;
2345 element = element.jquery || element.nodeType ?
2347 this.document.find( element ).eq( 0 );
2350 if ( !element || !element[ 0 ] ) {
2351 element = this.element.closest( ".ui-front, dialog" );
2354 if ( !element.length ) {
2355 element = this.document[ 0 ].body;
2361 _initSource: function() {
2364 if ( $.isArray( this.options.source ) ) {
2365 array = this.options.source;
2366 this.source = function( request, response ) {
2367 response( $.ui.autocomplete.filter( array, request.term ) );
2369 } else if ( typeof this.options.source === "string" ) {
2370 url = this.options.source;
2371 this.source = function( request, response ) {
2375 that.xhr = $.ajax( {
2379 success: function( data ) {
2388 this.source = this.options.source;
2392 _searchTimeout: function( event ) {
2393 clearTimeout( this.searching );
2394 this.searching = this._delay( function() {
2396 // Search if the value has changed, or if the user retypes the same value (see #7434)
2397 var equalValues = this.term === this._value(),
2398 menuVisible = this.menu.element.is( ":visible" ),
2399 modifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
2401 if ( !equalValues || ( equalValues && !menuVisible && !modifierKey ) ) {
2402 this.selectedItem = null;
2403 this.search( null, event );
2405 }, this.options.delay );
2408 search: function( value, event ) {
2409 value = value != null ? value : this._value();
2411 // Always save the actual value, not the one passed as an argument
2412 this.term = this._value();
2414 if ( value.length < this.options.minLength ) {
2415 return this.close( event );
2418 if ( this._trigger( "search", event ) === false ) {
2422 return this._search( value );
2425 _search: function( value ) {
2427 this._addClass( "ui-autocomplete-loading" );
2428 this.cancelSearch = false;
2430 this.source( { term: value }, this._response() );
2433 _response: function() {
2434 var index = ++this.requestIndex;
2436 return $.proxy( function( content ) {
2437 if ( index === this.requestIndex ) {
2438 this.__response( content );
2442 if ( !this.pending ) {
2443 this._removeClass( "ui-autocomplete-loading" );
2448 __response: function( content ) {
2450 content = this._normalize( content );
2452 this._trigger( "response", null, { content: content } );
2453 if ( !this.options.disabled && content && content.length && !this.cancelSearch ) {
2454 this._suggest( content );
2455 this._trigger( "open" );
2458 // use ._close() instead of .close() so we don't cancel future searches
2463 close: function( event ) {
2464 this.cancelSearch = true;
2465 this._close( event );
2468 _close: function( event ) {
2470 // Remove the handler that closes the menu on outside clicks
2471 this._off( this.document, "mousedown" );
2473 if ( this.menu.element.is( ":visible" ) ) {
2474 this.menu.element.hide();
2476 this.isNewMenu = true;
2477 this._trigger( "close", event );
2481 _change: function( event ) {
2482 if ( this.previous !== this._value() ) {
2483 this._trigger( "change", event, { item: this.selectedItem } );
2487 _normalize: function( items ) {
2489 // assume all items have the right format when the first item is complete
2490 if ( items.length && items[ 0 ].label && items[ 0 ].value ) {
2493 return $.map( items, function( item ) {
2494 if ( typeof item === "string" ) {
2500 return $.extend( {}, item, {
2501 label: item.label || item.value,
2502 value: item.value || item.label
2507 _suggest: function( items ) {
2508 var ul = this.menu.element.empty();
2509 this._renderMenu( ul, items );
2510 this.isNewMenu = true;
2511 this.menu.refresh();
2513 // Size and position menu
2516 ul.position( $.extend( {
2518 }, this.options.position ) );
2520 if ( this.options.autoFocus ) {
2524 // Listen for interactions outside of the widget (#6642)
2525 this._on( this.document, {
2526 mousedown: "_closeOnClickOutside"
2530 _resizeMenu: function() {
2531 var ul = this.menu.element;
2532 ul.outerWidth( Math.max(
2534 // Firefox wraps long text (possibly a rounding bug)
2535 // so we add 1px to avoid the wrapping (#7513)
2536 ul.width( "" ).outerWidth() + 1,
2537 this.element.outerWidth()
2541 _renderMenu: function( ul, items ) {
2543 $.each( items, function( index, item ) {
2544 that._renderItemData( ul, item );
2548 _renderItemData: function( ul, item ) {
2549 return this._renderItem( ul, item ).data( "ui-autocomplete-item", item );
2552 _renderItem: function( ul, item ) {
2554 .append( $( "<div>" ).text( item.label ) )
2558 _move: function( direction, event ) {
2559 if ( !this.menu.element.is( ":visible" ) ) {
2560 this.search( null, event );
2563 if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
2564 this.menu.isLastItem() && /^next/.test( direction ) ) {
2566 if ( !this.isMultiLine ) {
2567 this._value( this.term );
2573 this.menu[ direction ]( event );
2576 widget: function() {
2577 return this.menu.element;
2580 _value: function() {
2581 return this.valueMethod.apply( this.element, arguments );
2584 _keyEvent: function( keyEvent, event ) {
2585 if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
2586 this._move( keyEvent, event );
2588 // Prevents moving cursor to beginning/end of the text field in some browsers
2589 event.preventDefault();
2593 // Support: Chrome <=50
2594 // We should be able to just use this.element.prop( "isContentEditable" )
2595 // but hidden elements always report false in Chrome.
2596 // https://code.google.com/p/chromium/issues/detail?id=313082
2597 _isContentEditable: function( element ) {
2598 if ( !element.length ) {
2602 var editable = element.prop( "contentEditable" );
2604 if ( editable === "inherit" ) {
2605 return this._isContentEditable( element.parent() );
2608 return editable === "true";
2612 $.extend( $.ui.autocomplete, {
2613 escapeRegex: function( value ) {
2614 return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
2616 filter: function( array, term ) {
2617 var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" );
2618 return $.grep( array, function( value ) {
2619 return matcher.test( value.label || value.value || value );
2624 // Live region extension, adding a `messages` option
2625 // NOTE: This is an experimental API. We are still investigating
2626 // a full solution for string manipulation and internationalization.
2627 $.widget( "ui.autocomplete", $.ui.autocomplete, {
2630 noResults: "No search results.",
2631 results: function( amount ) {
2632 return amount + ( amount > 1 ? " results are" : " result is" ) +
2633 " available, use up and down arrow keys to navigate.";
2638 __response: function( content ) {
2640 this._superApply( arguments );
2641 if ( this.options.disabled || this.cancelSearch ) {
2644 if ( content && content.length ) {
2645 message = this.options.messages.results( content.length );
2647 message = this.options.messages.noResults;
2649 this.liveRegion.children().hide();
2650 $( "<div>" ).text( message ).appendTo( this.liveRegion );
2654 var widgetsAutocomplete = $.ui.autocomplete;