jquery-ui.js 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659
  1. /*! jQuery UI - v1.12.1 - 2018-12-06
  2. * http://jqueryui.com
  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 */
  5. (function( factory ) {
  6. if ( typeof define === "function" && define.amd ) {
  7. // AMD. Register as an anonymous module.
  8. define([ "jquery" ], factory );
  9. } else {
  10. // Browser globals
  11. factory( jQuery );
  12. }
  13. }(function( $ ) {
  14. $.ui = $.ui || {};
  15. var version = $.ui.version = "1.12.1";
  16. /*!
  17. * jQuery UI Widget 1.12.1
  18. * http://jqueryui.com
  19. *
  20. * Copyright jQuery Foundation and other contributors
  21. * Released under the MIT license.
  22. * http://jquery.org/license
  23. */
  24. //>>label: Widget
  25. //>>group: Core
  26. //>>description: Provides a factory for creating stateful widgets with a common API.
  27. //>>docs: http://api.jqueryui.com/jQuery.widget/
  28. //>>demos: http://jqueryui.com/widget/
  29. var widgetUuid = 0;
  30. var widgetSlice = Array.prototype.slice;
  31. $.cleanData = ( function( orig ) {
  32. return function( elems ) {
  33. var events, elem, i;
  34. for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
  35. try {
  36. // Only trigger remove when necessary to save time
  37. events = $._data( elem, "events" );
  38. if ( events && events.remove ) {
  39. $( elem ).triggerHandler( "remove" );
  40. }
  41. // Http://bugs.jquery.com/ticket/8235
  42. } catch ( e ) {}
  43. }
  44. orig( elems );
  45. };
  46. } )( $.cleanData );
  47. $.widget = function( name, base, prototype ) {
  48. var existingConstructor, constructor, basePrototype;
  49. // ProxiedPrototype allows the provided prototype to remain unmodified
  50. // so that it can be used as a mixin for multiple widgets (#8876)
  51. var proxiedPrototype = {};
  52. var namespace = name.split( "." )[ 0 ];
  53. name = name.split( "." )[ 1 ];
  54. var fullName = namespace + "-" + name;
  55. if ( !prototype ) {
  56. prototype = base;
  57. base = $.Widget;
  58. }
  59. if ( $.isArray( prototype ) ) {
  60. prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
  61. }
  62. // Create selector for plugin
  63. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  64. return !!$.data( elem, fullName );
  65. };
  66. $[ namespace ] = $[ namespace ] || {};
  67. existingConstructor = $[ namespace ][ name ];
  68. constructor = $[ namespace ][ name ] = function( options, element ) {
  69. // Allow instantiation without "new" keyword
  70. if ( !this._createWidget ) {
  71. return new constructor( options, element );
  72. }
  73. // Allow instantiation without initializing for simple inheritance
  74. // must use "new" keyword (the code above always passes args)
  75. if ( arguments.length ) {
  76. this._createWidget( options, element );
  77. }
  78. };
  79. // Extend with the existing constructor to carry over any static properties
  80. $.extend( constructor, existingConstructor, {
  81. version: prototype.version,
  82. // Copy the object used to create the prototype in case we need to
  83. // redefine the widget later
  84. _proto: $.extend( {}, prototype ),
  85. // Track widgets that inherit from this widget in case this widget is
  86. // redefined after a widget inherits from it
  87. _childConstructors: []
  88. } );
  89. basePrototype = new base();
  90. // We need to make the options hash a property directly on the new instance
  91. // otherwise we'll modify the options hash on the prototype that we're
  92. // inheriting from
  93. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  94. $.each( prototype, function( prop, value ) {
  95. if ( !$.isFunction( value ) ) {
  96. proxiedPrototype[ prop ] = value;
  97. return;
  98. }
  99. proxiedPrototype[ prop ] = ( function() {
  100. function _super() {
  101. return base.prototype[ prop ].apply( this, arguments );
  102. }
  103. function _superApply( args ) {
  104. return base.prototype[ prop ].apply( this, args );
  105. }
  106. return function() {
  107. var __super = this._super;
  108. var __superApply = this._superApply;
  109. var returnValue;
  110. this._super = _super;
  111. this._superApply = _superApply;
  112. returnValue = value.apply( this, arguments );
  113. this._super = __super;
  114. this._superApply = __superApply;
  115. return returnValue;
  116. };
  117. } )();
  118. } );
  119. constructor.prototype = $.widget.extend( basePrototype, {
  120. // TODO: remove support for widgetEventPrefix
  121. // always use the name + a colon as the prefix, e.g., draggable:start
  122. // don't prefix for widgets that aren't DOM-based
  123. widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name
  124. }, proxiedPrototype, {
  125. constructor: constructor,
  126. namespace: namespace,
  127. widgetName: name,
  128. widgetFullName: fullName
  129. } );
  130. // If this widget is being redefined then we need to find all widgets that
  131. // are inheriting from it and redefine all of them so that they inherit from
  132. // the new version of this widget. We're essentially trying to replace one
  133. // level in the prototype chain.
  134. if ( existingConstructor ) {
  135. $.each( existingConstructor._childConstructors, function( i, child ) {
  136. var childPrototype = child.prototype;
  137. // Redefine the child widget using the same prototype that was
  138. // originally used, but inherit from the new version of the base
  139. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor,
  140. child._proto );
  141. } );
  142. // Remove the list of existing child constructors from the old constructor
  143. // so the old child constructors can be garbage collected
  144. delete existingConstructor._childConstructors;
  145. } else {
  146. base._childConstructors.push( constructor );
  147. }
  148. $.widget.bridge( name, constructor );
  149. return constructor;
  150. };
  151. $.widget.extend = function( target ) {
  152. var input = widgetSlice.call( arguments, 1 );
  153. var inputIndex = 0;
  154. var inputLength = input.length;
  155. var key;
  156. var value;
  157. for ( ; inputIndex < inputLength; inputIndex++ ) {
  158. for ( key in input[ inputIndex ] ) {
  159. value = input[ inputIndex ][ key ];
  160. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  161. // Clone objects
  162. if ( $.isPlainObject( value ) ) {
  163. target[ key ] = $.isPlainObject( target[ key ] ) ?
  164. $.widget.extend( {}, target[ key ], value ) :
  165. // Don't extend strings, arrays, etc. with objects
  166. $.widget.extend( {}, value );
  167. // Copy everything else by reference
  168. } else {
  169. target[ key ] = value;
  170. }
  171. }
  172. }
  173. }
  174. return target;
  175. };
  176. $.widget.bridge = function( name, object ) {
  177. var fullName = object.prototype.widgetFullName || name;
  178. $.fn[ name ] = function( options ) {
  179. var isMethodCall = typeof options === "string";
  180. var args = widgetSlice.call( arguments, 1 );
  181. var returnValue = this;
  182. if ( isMethodCall ) {
  183. // If this is an empty collection, we need to have the instance method
  184. // return undefined instead of the jQuery instance
  185. if ( !this.length && options === "instance" ) {
  186. returnValue = undefined;
  187. } else {
  188. this.each( function() {
  189. var methodValue;
  190. var instance = $.data( this, fullName );
  191. if ( options === "instance" ) {
  192. returnValue = instance;
  193. return false;
  194. }
  195. if ( !instance ) {
  196. return $.error( "cannot call methods on " + name +
  197. " prior to initialization; " +
  198. "attempted to call method '" + options + "'" );
  199. }
  200. if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
  201. return $.error( "no such method '" + options + "' for " + name +
  202. " widget instance" );
  203. }
  204. methodValue = instance[ options ].apply( instance, args );
  205. if ( methodValue !== instance && methodValue !== undefined ) {
  206. returnValue = methodValue && methodValue.jquery ?
  207. returnValue.pushStack( methodValue.get() ) :
  208. methodValue;
  209. return false;
  210. }
  211. } );
  212. }
  213. } else {
  214. // Allow multiple hashes to be passed on init
  215. if ( args.length ) {
  216. options = $.widget.extend.apply( null, [ options ].concat( args ) );
  217. }
  218. this.each( function() {
  219. var instance = $.data( this, fullName );
  220. if ( instance ) {
  221. instance.option( options || {} );
  222. if ( instance._init ) {
  223. instance._init();
  224. }
  225. } else {
  226. $.data( this, fullName, new object( options, this ) );
  227. }
  228. } );
  229. }
  230. return returnValue;
  231. };
  232. };
  233. $.Widget = function( /* options, element */ ) {};
  234. $.Widget._childConstructors = [];
  235. $.Widget.prototype = {
  236. widgetName: "widget",
  237. widgetEventPrefix: "",
  238. defaultElement: "<div>",
  239. options: {
  240. classes: {},
  241. disabled: false,
  242. // Callbacks
  243. create: null
  244. },
  245. _createWidget: function( options, element ) {
  246. element = $( element || this.defaultElement || this )[ 0 ];
  247. this.element = $( element );
  248. this.uuid = widgetUuid++;
  249. this.eventNamespace = "." + this.widgetName + this.uuid;
  250. this.bindings = $();
  251. this.hoverable = $();
  252. this.focusable = $();
  253. this.classesElementLookup = {};
  254. if ( element !== this ) {
  255. $.data( element, this.widgetFullName, this );
  256. this._on( true, this.element, {
  257. remove: function( event ) {
  258. if ( event.target === element ) {
  259. this.destroy();
  260. }
  261. }
  262. } );
  263. this.document = $( element.style ?
  264. // Element within the document
  265. element.ownerDocument :
  266. // Element is window or document
  267. element.document || element );
  268. this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
  269. }
  270. this.options = $.widget.extend( {},
  271. this.options,
  272. this._getCreateOptions(),
  273. options );
  274. this._create();
  275. if ( this.options.disabled ) {
  276. this._setOptionDisabled( this.options.disabled );
  277. }
  278. this._trigger( "create", null, this._getCreateEventData() );
  279. this._init();
  280. },
  281. _getCreateOptions: function() {
  282. return {};
  283. },
  284. _getCreateEventData: $.noop,
  285. _create: $.noop,
  286. _init: $.noop,
  287. destroy: function() {
  288. var that = this;
  289. this._destroy();
  290. $.each( this.classesElementLookup, function( key, value ) {
  291. that._removeClass( value, key );
  292. } );
  293. // We can probably remove the unbind calls in 2.0
  294. // all event bindings should go through this._on()
  295. this.element
  296. .off( this.eventNamespace )
  297. .removeData( this.widgetFullName );
  298. this.widget()
  299. .off( this.eventNamespace )
  300. .removeAttr( "aria-disabled" );
  301. // Clean up events and states
  302. this.bindings.off( this.eventNamespace );
  303. },
  304. _destroy: $.noop,
  305. widget: function() {
  306. return this.element;
  307. },
  308. option: function( key, value ) {
  309. var options = key;
  310. var parts;
  311. var curOption;
  312. var i;
  313. if ( arguments.length === 0 ) {
  314. // Don't return a reference to the internal hash
  315. return $.widget.extend( {}, this.options );
  316. }
  317. if ( typeof key === "string" ) {
  318. // Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  319. options = {};
  320. parts = key.split( "." );
  321. key = parts.shift();
  322. if ( parts.length ) {
  323. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  324. for ( i = 0; i < parts.length - 1; i++ ) {
  325. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  326. curOption = curOption[ parts[ i ] ];
  327. }
  328. key = parts.pop();
  329. if ( arguments.length === 1 ) {
  330. return curOption[ key ] === undefined ? null : curOption[ key ];
  331. }
  332. curOption[ key ] = value;
  333. } else {
  334. if ( arguments.length === 1 ) {
  335. return this.options[ key ] === undefined ? null : this.options[ key ];
  336. }
  337. options[ key ] = value;
  338. }
  339. }
  340. this._setOptions( options );
  341. return this;
  342. },
  343. _setOptions: function( options ) {
  344. var key;
  345. for ( key in options ) {
  346. this._setOption( key, options[ key ] );
  347. }
  348. return this;
  349. },
  350. _setOption: function( key, value ) {
  351. if ( key === "classes" ) {
  352. this._setOptionClasses( value );
  353. }
  354. this.options[ key ] = value;
  355. if ( key === "disabled" ) {
  356. this._setOptionDisabled( value );
  357. }
  358. return this;
  359. },
  360. _setOptionClasses: function( value ) {
  361. var classKey, elements, currentElements;
  362. for ( classKey in value ) {
  363. currentElements = this.classesElementLookup[ classKey ];
  364. if ( value[ classKey ] === this.options.classes[ classKey ] ||
  365. !currentElements ||
  366. !currentElements.length ) {
  367. continue;
  368. }
  369. // We are doing this to create a new jQuery object because the _removeClass() call
  370. // on the next line is going to destroy the reference to the current elements being
  371. // tracked. We need to save a copy of this collection so that we can add the new classes
  372. // below.
  373. elements = $( currentElements.get() );
  374. this._removeClass( currentElements, classKey );
  375. // We don't use _addClass() here, because that uses this.options.classes
  376. // for generating the string of classes. We want to use the value passed in from
  377. // _setOption(), this is the new value of the classes option which was passed to
  378. // _setOption(). We pass this value directly to _classes().
  379. elements.addClass( this._classes( {
  380. element: elements,
  381. keys: classKey,
  382. classes: value,
  383. add: true
  384. } ) );
  385. }
  386. },
  387. _setOptionDisabled: function( value ) {
  388. this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
  389. // If the widget is becoming disabled, then nothing is interactive
  390. if ( value ) {
  391. this._removeClass( this.hoverable, null, "ui-state-hover" );
  392. this._removeClass( this.focusable, null, "ui-state-focus" );
  393. }
  394. },
  395. enable: function() {
  396. return this._setOptions( { disabled: false } );
  397. },
  398. disable: function() {
  399. return this._setOptions( { disabled: true } );
  400. },
  401. _classes: function( options ) {
  402. var full = [];
  403. var that = this;
  404. options = $.extend( {
  405. element: this.element,
  406. classes: this.options.classes || {}
  407. }, options );
  408. function processClassString( classes, checkOption ) {
  409. var current, i;
  410. for ( i = 0; i < classes.length; i++ ) {
  411. current = that.classesElementLookup[ classes[ i ] ] || $();
  412. if ( options.add ) {
  413. current = $( $.unique( current.get().concat( options.element.get() ) ) );
  414. } else {
  415. current = $( current.not( options.element ).get() );
  416. }
  417. that.classesElementLookup[ classes[ i ] ] = current;
  418. full.push( classes[ i ] );
  419. if ( checkOption && options.classes[ classes[ i ] ] ) {
  420. full.push( options.classes[ classes[ i ] ] );
  421. }
  422. }
  423. }
  424. this._on( options.element, {
  425. "remove": "_untrackClassesElement"
  426. } );
  427. if ( options.keys ) {
  428. processClassString( options.keys.match( /\S+/g ) || [], true );
  429. }
  430. if ( options.extra ) {
  431. processClassString( options.extra.match( /\S+/g ) || [] );
  432. }
  433. return full.join( " " );
  434. },
  435. _untrackClassesElement: function( event ) {
  436. var that = this;
  437. $.each( that.classesElementLookup, function( key, value ) {
  438. if ( $.inArray( event.target, value ) !== -1 ) {
  439. that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
  440. }
  441. } );
  442. },
  443. _removeClass: function( element, keys, extra ) {
  444. return this._toggleClass( element, keys, extra, false );
  445. },
  446. _addClass: function( element, keys, extra ) {
  447. return this._toggleClass( element, keys, extra, true );
  448. },
  449. _toggleClass: function( element, keys, extra, add ) {
  450. add = ( typeof add === "boolean" ) ? add : extra;
  451. var shift = ( typeof element === "string" || element === null ),
  452. options = {
  453. extra: shift ? keys : extra,
  454. keys: shift ? element : keys,
  455. element: shift ? this.element : element,
  456. add: add
  457. };
  458. options.element.toggleClass( this._classes( options ), add );
  459. return this;
  460. },
  461. _on: function( suppressDisabledCheck, element, handlers ) {
  462. var delegateElement;
  463. var instance = this;
  464. // No suppressDisabledCheck flag, shuffle arguments
  465. if ( typeof suppressDisabledCheck !== "boolean" ) {
  466. handlers = element;
  467. element = suppressDisabledCheck;
  468. suppressDisabledCheck = false;
  469. }
  470. // No element argument, shuffle and use this.element
  471. if ( !handlers ) {
  472. handlers = element;
  473. element = this.element;
  474. delegateElement = this.widget();
  475. } else {
  476. element = delegateElement = $( element );
  477. this.bindings = this.bindings.add( element );
  478. }
  479. $.each( handlers, function( event, handler ) {
  480. function handlerProxy() {
  481. // Allow widgets to customize the disabled handling
  482. // - disabled as an array instead of boolean
  483. // - disabled class as method for disabling individual parts
  484. if ( !suppressDisabledCheck &&
  485. ( instance.options.disabled === true ||
  486. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  487. return;
  488. }
  489. return ( typeof handler === "string" ? instance[ handler ] : handler )
  490. .apply( instance, arguments );
  491. }
  492. // Copy the guid so direct unbinding works
  493. if ( typeof handler !== "string" ) {
  494. handlerProxy.guid = handler.guid =
  495. handler.guid || handlerProxy.guid || $.guid++;
  496. }
  497. var match = event.match( /^([\w:-]*)\s*(.*)$/ );
  498. var eventName = match[ 1 ] + instance.eventNamespace;
  499. var selector = match[ 2 ];
  500. if ( selector ) {
  501. delegateElement.on( eventName, selector, handlerProxy );
  502. } else {
  503. element.on( eventName, handlerProxy );
  504. }
  505. } );
  506. },
  507. _off: function( element, eventName ) {
  508. eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
  509. this.eventNamespace;
  510. element.off( eventName ).off( eventName );
  511. // Clear the stack to avoid memory leaks (#10056)
  512. this.bindings = $( this.bindings.not( element ).get() );
  513. this.focusable = $( this.focusable.not( element ).get() );
  514. this.hoverable = $( this.hoverable.not( element ).get() );
  515. },
  516. _delay: function( handler, delay ) {
  517. function handlerProxy() {
  518. return ( typeof handler === "string" ? instance[ handler ] : handler )
  519. .apply( instance, arguments );
  520. }
  521. var instance = this;
  522. return setTimeout( handlerProxy, delay || 0 );
  523. },
  524. _hoverable: function( element ) {
  525. this.hoverable = this.hoverable.add( element );
  526. this._on( element, {
  527. mouseenter: function( event ) {
  528. this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
  529. },
  530. mouseleave: function( event ) {
  531. this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
  532. }
  533. } );
  534. },
  535. _focusable: function( element ) {
  536. this.focusable = this.focusable.add( element );
  537. this._on( element, {
  538. focusin: function( event ) {
  539. this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
  540. },
  541. focusout: function( event ) {
  542. this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
  543. }
  544. } );
  545. },
  546. _trigger: function( type, event, data ) {
  547. var prop, orig;
  548. var callback = this.options[ type ];
  549. data = data || {};
  550. event = $.Event( event );
  551. event.type = ( type === this.widgetEventPrefix ?
  552. type :
  553. this.widgetEventPrefix + type ).toLowerCase();
  554. // The original event may come from any element
  555. // so we need to reset the target on the new event
  556. event.target = this.element[ 0 ];
  557. // Copy original event properties over to the new event
  558. orig = event.originalEvent;
  559. if ( orig ) {
  560. for ( prop in orig ) {
  561. if ( !( prop in event ) ) {
  562. event[ prop ] = orig[ prop ];
  563. }
  564. }
  565. }
  566. this.element.trigger( event, data );
  567. return !( $.isFunction( callback ) &&
  568. callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
  569. event.isDefaultPrevented() );
  570. }
  571. };
  572. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  573. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  574. if ( typeof options === "string" ) {
  575. options = { effect: options };
  576. }
  577. var hasOptions;
  578. var effectName = !options ?
  579. method :
  580. options === true || typeof options === "number" ?
  581. defaultEffect :
  582. options.effect || defaultEffect;
  583. options = options || {};
  584. if ( typeof options === "number" ) {
  585. options = { duration: options };
  586. }
  587. hasOptions = !$.isEmptyObject( options );
  588. options.complete = callback;
  589. if ( options.delay ) {
  590. element.delay( options.delay );
  591. }
  592. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  593. element[ method ]( options );
  594. } else if ( effectName !== method && element[ effectName ] ) {
  595. element[ effectName ]( options.duration, options.easing, callback );
  596. } else {
  597. element.queue( function( next ) {
  598. $( this )[ method ]();
  599. if ( callback ) {
  600. callback.call( element[ 0 ] );
  601. }
  602. next();
  603. } );
  604. }
  605. };
  606. } );
  607. var widget = $.widget;
  608. /*!
  609. * jQuery UI Position 1.12.1
  610. * http://jqueryui.com
  611. *
  612. * Copyright jQuery Foundation and other contributors
  613. * Released under the MIT license.
  614. * http://jquery.org/license
  615. *
  616. * http://api.jqueryui.com/position/
  617. */
  618. //>>label: Position
  619. //>>group: Core
  620. //>>description: Positions elements relative to other elements.
  621. //>>docs: http://api.jqueryui.com/position/
  622. //>>demos: http://jqueryui.com/position/
  623. ( function() {
  624. var cachedScrollbarWidth,
  625. max = Math.max,
  626. abs = Math.abs,
  627. rhorizontal = /left|center|right/,
  628. rvertical = /top|center|bottom/,
  629. roffset = /[\+\-]\d+(\.[\d]+)?%?/,
  630. rposition = /^\w+/,
  631. rpercent = /%$/,
  632. _position = $.fn.position;
  633. function getOffsets( offsets, width, height ) {
  634. return [
  635. parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  636. parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  637. ];
  638. }
  639. function parseCss( element, property ) {
  640. return parseInt( $.css( element, property ), 10 ) || 0;
  641. }
  642. function getDimensions( elem ) {
  643. var raw = elem[ 0 ];
  644. if ( raw.nodeType === 9 ) {
  645. return {
  646. width: elem.width(),
  647. height: elem.height(),
  648. offset: { top: 0, left: 0 }
  649. };
  650. }
  651. if ( $.isWindow( raw ) ) {
  652. return {
  653. width: elem.width(),
  654. height: elem.height(),
  655. offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
  656. };
  657. }
  658. if ( raw.preventDefault ) {
  659. return {
  660. width: 0,
  661. height: 0,
  662. offset: { top: raw.pageY, left: raw.pageX }
  663. };
  664. }
  665. return {
  666. width: elem.outerWidth(),
  667. height: elem.outerHeight(),
  668. offset: elem.offset()
  669. };
  670. }
  671. $.position = {
  672. scrollbarWidth: function() {
  673. if ( cachedScrollbarWidth !== undefined ) {
  674. return cachedScrollbarWidth;
  675. }
  676. var w1, w2,
  677. div = $( "<div " +
  678. "style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'>" +
  679. "<div style='height:100px;width:auto;'></div></div>" ),
  680. innerDiv = div.children()[ 0 ];
  681. $( "body" ).append( div );
  682. w1 = innerDiv.offsetWidth;
  683. div.css( "overflow", "scroll" );
  684. w2 = innerDiv.offsetWidth;
  685. if ( w1 === w2 ) {
  686. w2 = div[ 0 ].clientWidth;
  687. }
  688. div.remove();
  689. return ( cachedScrollbarWidth = w1 - w2 );
  690. },
  691. getScrollInfo: function( within ) {
  692. var overflowX = within.isWindow || within.isDocument ? "" :
  693. within.element.css( "overflow-x" ),
  694. overflowY = within.isWindow || within.isDocument ? "" :
  695. within.element.css( "overflow-y" ),
  696. hasOverflowX = overflowX === "scroll" ||
  697. ( overflowX === "auto" && within.width < within.element[ 0 ].scrollWidth ),
  698. hasOverflowY = overflowY === "scroll" ||
  699. ( overflowY === "auto" && within.height < within.element[ 0 ].scrollHeight );
  700. return {
  701. width: hasOverflowY ? $.position.scrollbarWidth() : 0,
  702. height: hasOverflowX ? $.position.scrollbarWidth() : 0
  703. };
  704. },
  705. getWithinInfo: function( element ) {
  706. var withinElement = $( element || window ),
  707. isWindow = $.isWindow( withinElement[ 0 ] ),
  708. isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
  709. hasOffset = !isWindow && !isDocument;
  710. return {
  711. element: withinElement,
  712. isWindow: isWindow,
  713. isDocument: isDocument,
  714. offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
  715. scrollLeft: withinElement.scrollLeft(),
  716. scrollTop: withinElement.scrollTop(),
  717. width: withinElement.outerWidth(),
  718. height: withinElement.outerHeight()
  719. };
  720. }
  721. };
  722. $.fn.position = function( options ) {
  723. if ( !options || !options.of ) {
  724. return _position.apply( this, arguments );
  725. }
  726. // Make a copy, we don't want to modify arguments
  727. options = $.extend( {}, options );
  728. var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
  729. target = $( options.of ),
  730. within = $.position.getWithinInfo( options.within ),
  731. scrollInfo = $.position.getScrollInfo( within ),
  732. collision = ( options.collision || "flip" ).split( " " ),
  733. offsets = {};
  734. dimensions = getDimensions( target );
  735. if ( target[ 0 ].preventDefault ) {
  736. // Force left top to allow flipping
  737. options.at = "left top";
  738. }
  739. targetWidth = dimensions.width;
  740. targetHeight = dimensions.height;
  741. targetOffset = dimensions.offset;
  742. // Clone to reuse original targetOffset later
  743. basePosition = $.extend( {}, targetOffset );
  744. // Force my and at to have valid horizontal and vertical positions
  745. // if a value is missing or invalid, it will be converted to center
  746. $.each( [ "my", "at" ], function() {
  747. var pos = ( options[ this ] || "" ).split( " " ),
  748. horizontalOffset,
  749. verticalOffset;
  750. if ( pos.length === 1 ) {
  751. pos = rhorizontal.test( pos[ 0 ] ) ?
  752. pos.concat( [ "center" ] ) :
  753. rvertical.test( pos[ 0 ] ) ?
  754. [ "center" ].concat( pos ) :
  755. [ "center", "center" ];
  756. }
  757. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  758. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  759. // Calculate offsets
  760. horizontalOffset = roffset.exec( pos[ 0 ] );
  761. verticalOffset = roffset.exec( pos[ 1 ] );
  762. offsets[ this ] = [
  763. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  764. verticalOffset ? verticalOffset[ 0 ] : 0
  765. ];
  766. // Reduce to just the positions without the offsets
  767. options[ this ] = [
  768. rposition.exec( pos[ 0 ] )[ 0 ],
  769. rposition.exec( pos[ 1 ] )[ 0 ]
  770. ];
  771. } );
  772. // Normalize collision option
  773. if ( collision.length === 1 ) {
  774. collision[ 1 ] = collision[ 0 ];
  775. }
  776. if ( options.at[ 0 ] === "right" ) {
  777. basePosition.left += targetWidth;
  778. } else if ( options.at[ 0 ] === "center" ) {
  779. basePosition.left += targetWidth / 2;
  780. }
  781. if ( options.at[ 1 ] === "bottom" ) {
  782. basePosition.top += targetHeight;
  783. } else if ( options.at[ 1 ] === "center" ) {
  784. basePosition.top += targetHeight / 2;
  785. }
  786. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  787. basePosition.left += atOffset[ 0 ];
  788. basePosition.top += atOffset[ 1 ];
  789. return this.each( function() {
  790. var collisionPosition, using,
  791. elem = $( this ),
  792. elemWidth = elem.outerWidth(),
  793. elemHeight = elem.outerHeight(),
  794. marginLeft = parseCss( this, "marginLeft" ),
  795. marginTop = parseCss( this, "marginTop" ),
  796. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) +
  797. scrollInfo.width,
  798. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) +
  799. scrollInfo.height,
  800. position = $.extend( {}, basePosition ),
  801. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  802. if ( options.my[ 0 ] === "right" ) {
  803. position.left -= elemWidth;
  804. } else if ( options.my[ 0 ] === "center" ) {
  805. position.left -= elemWidth / 2;
  806. }
  807. if ( options.my[ 1 ] === "bottom" ) {
  808. position.top -= elemHeight;
  809. } else if ( options.my[ 1 ] === "center" ) {
  810. position.top -= elemHeight / 2;
  811. }
  812. position.left += myOffset[ 0 ];
  813. position.top += myOffset[ 1 ];
  814. collisionPosition = {
  815. marginLeft: marginLeft,
  816. marginTop: marginTop
  817. };
  818. $.each( [ "left", "top" ], function( i, dir ) {
  819. if ( $.ui.position[ collision[ i ] ] ) {
  820. $.ui.position[ collision[ i ] ][ dir ]( position, {
  821. targetWidth: targetWidth,
  822. targetHeight: targetHeight,
  823. elemWidth: elemWidth,
  824. elemHeight: elemHeight,
  825. collisionPosition: collisionPosition,
  826. collisionWidth: collisionWidth,
  827. collisionHeight: collisionHeight,
  828. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  829. my: options.my,
  830. at: options.at,
  831. within: within,
  832. elem: elem
  833. } );
  834. }
  835. } );
  836. if ( options.using ) {
  837. // Adds feedback as second argument to using callback, if present
  838. using = function( props ) {
  839. var left = targetOffset.left - position.left,
  840. right = left + targetWidth - elemWidth,
  841. top = targetOffset.top - position.top,
  842. bottom = top + targetHeight - elemHeight,
  843. feedback = {
  844. target: {
  845. element: target,
  846. left: targetOffset.left,
  847. top: targetOffset.top,
  848. width: targetWidth,
  849. height: targetHeight
  850. },
  851. element: {
  852. element: elem,
  853. left: position.left,
  854. top: position.top,
  855. width: elemWidth,
  856. height: elemHeight
  857. },
  858. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  859. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  860. };
  861. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  862. feedback.horizontal = "center";
  863. }
  864. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  865. feedback.vertical = "middle";
  866. }
  867. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  868. feedback.important = "horizontal";
  869. } else {
  870. feedback.important = "vertical";
  871. }
  872. options.using.call( this, props, feedback );
  873. };
  874. }
  875. elem.offset( $.extend( position, { using: using } ) );
  876. } );
  877. };
  878. $.ui.position = {
  879. fit: {
  880. left: function( position, data ) {
  881. var within = data.within,
  882. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  883. outerWidth = within.width,
  884. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  885. overLeft = withinOffset - collisionPosLeft,
  886. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  887. newOverRight;
  888. // Element is wider than within
  889. if ( data.collisionWidth > outerWidth ) {
  890. // Element is initially over the left side of within
  891. if ( overLeft > 0 && overRight <= 0 ) {
  892. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth -
  893. withinOffset;
  894. position.left += overLeft - newOverRight;
  895. // Element is initially over right side of within
  896. } else if ( overRight > 0 && overLeft <= 0 ) {
  897. position.left = withinOffset;
  898. // Element is initially over both left and right sides of within
  899. } else {
  900. if ( overLeft > overRight ) {
  901. position.left = withinOffset + outerWidth - data.collisionWidth;
  902. } else {
  903. position.left = withinOffset;
  904. }
  905. }
  906. // Too far left -> align with left edge
  907. } else if ( overLeft > 0 ) {
  908. position.left += overLeft;
  909. // Too far right -> align with right edge
  910. } else if ( overRight > 0 ) {
  911. position.left -= overRight;
  912. // Adjust based on position and margin
  913. } else {
  914. position.left = max( position.left - collisionPosLeft, position.left );
  915. }
  916. },
  917. top: function( position, data ) {
  918. var within = data.within,
  919. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  920. outerHeight = data.within.height,
  921. collisionPosTop = position.top - data.collisionPosition.marginTop,
  922. overTop = withinOffset - collisionPosTop,
  923. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  924. newOverBottom;
  925. // Element is taller than within
  926. if ( data.collisionHeight > outerHeight ) {
  927. // Element is initially over the top of within
  928. if ( overTop > 0 && overBottom <= 0 ) {
  929. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight -
  930. withinOffset;
  931. position.top += overTop - newOverBottom;
  932. // Element is initially over bottom of within
  933. } else if ( overBottom > 0 && overTop <= 0 ) {
  934. position.top = withinOffset;
  935. // Element is initially over both top and bottom of within
  936. } else {
  937. if ( overTop > overBottom ) {
  938. position.top = withinOffset + outerHeight - data.collisionHeight;
  939. } else {
  940. position.top = withinOffset;
  941. }
  942. }
  943. // Too far up -> align with top
  944. } else if ( overTop > 0 ) {
  945. position.top += overTop;
  946. // Too far down -> align with bottom edge
  947. } else if ( overBottom > 0 ) {
  948. position.top -= overBottom;
  949. // Adjust based on position and margin
  950. } else {
  951. position.top = max( position.top - collisionPosTop, position.top );
  952. }
  953. }
  954. },
  955. flip: {
  956. left: function( position, data ) {
  957. var within = data.within,
  958. withinOffset = within.offset.left + within.scrollLeft,
  959. outerWidth = within.width,
  960. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  961. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  962. overLeft = collisionPosLeft - offsetLeft,
  963. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  964. myOffset = data.my[ 0 ] === "left" ?
  965. -data.elemWidth :
  966. data.my[ 0 ] === "right" ?
  967. data.elemWidth :
  968. 0,
  969. atOffset = data.at[ 0 ] === "left" ?
  970. data.targetWidth :
  971. data.at[ 0 ] === "right" ?
  972. -data.targetWidth :
  973. 0,
  974. offset = -2 * data.offset[ 0 ],
  975. newOverRight,
  976. newOverLeft;
  977. if ( overLeft < 0 ) {
  978. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth -
  979. outerWidth - withinOffset;
  980. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  981. position.left += myOffset + atOffset + offset;
  982. }
  983. } else if ( overRight > 0 ) {
  984. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset +
  985. atOffset + offset - offsetLeft;
  986. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  987. position.left += myOffset + atOffset + offset;
  988. }
  989. }
  990. },
  991. top: function( position, data ) {
  992. var within = data.within,
  993. withinOffset = within.offset.top + within.scrollTop,
  994. outerHeight = within.height,
  995. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  996. collisionPosTop = position.top - data.collisionPosition.marginTop,
  997. overTop = collisionPosTop - offsetTop,
  998. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  999. top = data.my[ 1 ] === "top",
  1000. myOffset = top ?
  1001. -data.elemHeight :
  1002. data.my[ 1 ] === "bottom" ?
  1003. data.elemHeight :
  1004. 0,
  1005. atOffset = data.at[ 1 ] === "top" ?
  1006. data.targetHeight :
  1007. data.at[ 1 ] === "bottom" ?
  1008. -data.targetHeight :
  1009. 0,
  1010. offset = -2 * data.offset[ 1 ],
  1011. newOverTop,
  1012. newOverBottom;
  1013. if ( overTop < 0 ) {
  1014. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight -
  1015. outerHeight - withinOffset;
  1016. if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {
  1017. position.top += myOffset + atOffset + offset;
  1018. }
  1019. } else if ( overBottom > 0 ) {
  1020. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset +
  1021. offset - offsetTop;
  1022. if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {
  1023. position.top += myOffset + atOffset + offset;
  1024. }
  1025. }
  1026. }
  1027. },
  1028. flipfit: {
  1029. left: function() {
  1030. $.ui.position.flip.left.apply( this, arguments );
  1031. $.ui.position.fit.left.apply( this, arguments );
  1032. },
  1033. top: function() {
  1034. $.ui.position.flip.top.apply( this, arguments );
  1035. $.ui.position.fit.top.apply( this, arguments );
  1036. }
  1037. }
  1038. };
  1039. } )();
  1040. var position = $.ui.position;
  1041. /*!
  1042. * jQuery UI Keycode 1.12.1
  1043. * http://jqueryui.com
  1044. *
  1045. * Copyright jQuery Foundation and other contributors
  1046. * Released under the MIT license.
  1047. * http://jquery.org/license
  1048. */
  1049. //>>label: Keycode
  1050. //>>group: Core
  1051. //>>description: Provide keycodes as keynames
  1052. //>>docs: http://api.jqueryui.com/jQuery.ui.keyCode/
  1053. var keycode = $.ui.keyCode = {
  1054. BACKSPACE: 8,
  1055. COMMA: 188,
  1056. DELETE: 46,
  1057. DOWN: 40,
  1058. END: 35,
  1059. ENTER: 13,
  1060. ESCAPE: 27,
  1061. HOME: 36,
  1062. LEFT: 37,
  1063. PAGE_DOWN: 34,
  1064. PAGE_UP: 33,
  1065. PERIOD: 190,
  1066. RIGHT: 39,
  1067. SPACE: 32,
  1068. TAB: 9,
  1069. UP: 38
  1070. };
  1071. /*!
  1072. * jQuery UI Unique ID 1.12.1
  1073. * http://jqueryui.com
  1074. *
  1075. * Copyright jQuery Foundation and other contributors
  1076. * Released under the MIT license.
  1077. * http://jquery.org/license
  1078. */
  1079. //>>label: uniqueId
  1080. //>>group: Core
  1081. //>>description: Functions to generate and remove uniqueId's
  1082. //>>docs: http://api.jqueryui.com/uniqueId/
  1083. var uniqueId = $.fn.extend( {
  1084. uniqueId: ( function() {
  1085. var uuid = 0;
  1086. return function() {
  1087. return this.each( function() {
  1088. if ( !this.id ) {
  1089. this.id = "ui-id-" + ( ++uuid );
  1090. }
  1091. } );
  1092. };
  1093. } )(),
  1094. removeUniqueId: function() {
  1095. return this.each( function() {
  1096. if ( /^ui-id-\d+$/.test( this.id ) ) {
  1097. $( this ).removeAttr( "id" );
  1098. }
  1099. } );
  1100. }
  1101. } );
  1102. var safeActiveElement = $.ui.safeActiveElement = function( document ) {
  1103. var activeElement;
  1104. // Support: IE 9 only
  1105. // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
  1106. try {
  1107. activeElement = document.activeElement;
  1108. } catch ( error ) {
  1109. activeElement = document.body;
  1110. }
  1111. // Support: IE 9 - 11 only
  1112. // IE may return null instead of an element
  1113. // Interestingly, this only seems to occur when NOT in an iframe
  1114. if ( !activeElement ) {
  1115. activeElement = document.body;
  1116. }
  1117. // Support: IE 11 only
  1118. // IE11 returns a seemingly empty object in some cases when accessing
  1119. // document.activeElement from an <iframe>
  1120. if ( !activeElement.nodeName ) {
  1121. activeElement = document.body;
  1122. }
  1123. return activeElement;
  1124. };
  1125. /*!
  1126. * jQuery UI Menu 1.12.1
  1127. * http://jqueryui.com
  1128. *
  1129. * Copyright jQuery Foundation and other contributors
  1130. * Released under the MIT license.
  1131. * http://jquery.org/license
  1132. */
  1133. //>>label: Menu
  1134. //>>group: Widgets
  1135. //>>description: Creates nestable menus.
  1136. //>>docs: http://api.jqueryui.com/menu/
  1137. //>>demos: http://jqueryui.com/menu/
  1138. //>>css.structure: ../../themes/base/core.css
  1139. //>>css.structure: ../../themes/base/menu.css
  1140. //>>css.theme: ../../themes/base/theme.css
  1141. var widgetsMenu = $.widget( "ui.menu", {
  1142. version: "1.12.1",
  1143. defaultElement: "<ul>",
  1144. delay: 300,
  1145. options: {
  1146. icons: {
  1147. submenu: "ui-icon-caret-1-e"
  1148. },
  1149. items: "> *",
  1150. menus: "ul",
  1151. position: {
  1152. my: "left top",
  1153. at: "right top"
  1154. },
  1155. role: "menu",
  1156. // Callbacks
  1157. blur: null,
  1158. focus: null,
  1159. select: null
  1160. },
  1161. _create: function() {
  1162. this.activeMenu = this.element;
  1163. // Flag used to prevent firing of the click handler
  1164. // as the event bubbles up through nested menus
  1165. this.mouseHandled = false;
  1166. this.element
  1167. .uniqueId()
  1168. .attr( {
  1169. role: this.options.role,
  1170. tabIndex: 0
  1171. } );
  1172. this._addClass( "ui-menu", "ui-widget ui-widget-content" );
  1173. this._on( {
  1174. // Prevent focus from sticking to links inside menu after clicking
  1175. // them (focus should always stay on UL during navigation).
  1176. "mousedown .ui-menu-item": function( event ) {
  1177. event.preventDefault();
  1178. },
  1179. "click .ui-menu-item": function( event ) {
  1180. var target = $( event.target );
  1181. var active = $( $.ui.safeActiveElement( this.document[ 0 ] ) );
  1182. if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) {
  1183. this.select( event );
  1184. // Only set the mouseHandled flag if the event will bubble, see #9469.
  1185. if ( !event.isPropagationStopped() ) {
  1186. this.mouseHandled = true;
  1187. }
  1188. // Open submenu on click
  1189. if ( target.has( ".ui-menu" ).length ) {
  1190. this.expand( event );
  1191. } else if ( !this.element.is( ":focus" ) &&
  1192. active.closest( ".ui-menu" ).length ) {
  1193. // Redirect focus to the menu
  1194. this.element.trigger( "focus", [ true ] );
  1195. // If the active item is on the top level, let it stay active.
  1196. // Otherwise, blur the active item since it is no longer visible.
  1197. if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) {
  1198. clearTimeout( this.timer );
  1199. }
  1200. }
  1201. }
  1202. },
  1203. "mouseenter .ui-menu-item": function( event ) {
  1204. // Ignore mouse events while typeahead is active, see #10458.
  1205. // Prevents focusing the wrong item when typeahead causes a scroll while the mouse
  1206. // is over an item in the menu
  1207. if ( this.previousFilter ) {
  1208. return;
  1209. }
  1210. var actualTarget = $( event.target ).closest( ".ui-menu-item" ),
  1211. target = $( event.currentTarget );
  1212. // Ignore bubbled events on parent items, see #11641
  1213. if ( actualTarget[ 0 ] !== target[ 0 ] ) {
  1214. return;
  1215. }
  1216. // Remove ui-state-active class from siblings of the newly focused menu item
  1217. // to avoid a jump caused by adjacent elements both having a class with a border
  1218. this._removeClass( target.siblings().children( ".ui-state-active" ),
  1219. null, "ui-state-active" );
  1220. this.focus( event, target );
  1221. },
  1222. mouseleave: "collapseAll",
  1223. "mouseleave .ui-menu": "collapseAll",
  1224. focus: function( event, keepActiveItem ) {
  1225. // If there's already an active item, keep it active
  1226. // If not, activate the first item
  1227. var item = this.active || this.element.find( this.options.items ).eq( 0 );
  1228. if ( !keepActiveItem ) {
  1229. this.focus( event, item );
  1230. }
  1231. },
  1232. blur: function( event ) {
  1233. this._delay( function() {
  1234. var notContained = !$.contains(
  1235. this.element[ 0 ],
  1236. $.ui.safeActiveElement( this.document[ 0 ] )
  1237. );
  1238. if ( notContained ) {
  1239. this.collapseAll( event );
  1240. }
  1241. } );
  1242. },
  1243. keydown: "_keydown"
  1244. } );
  1245. this.refresh();
  1246. // Clicks outside of a menu collapse any open menus
  1247. this._on( this.document, {
  1248. click: function( event ) {
  1249. if ( this._closeOnDocumentClick( event ) ) {
  1250. this.collapseAll( event );
  1251. }
  1252. // Reset the mouseHandled flag
  1253. this.mouseHandled = false;
  1254. }
  1255. } );
  1256. },
  1257. _destroy: function() {
  1258. var items = this.element.find( ".ui-menu-item" )
  1259. .removeAttr( "role aria-disabled" ),
  1260. submenus = items.children( ".ui-menu-item-wrapper" )
  1261. .removeUniqueId()
  1262. .removeAttr( "tabIndex role aria-haspopup" );
  1263. // Destroy (sub)menus
  1264. this.element
  1265. .removeAttr( "aria-activedescendant" )
  1266. .find( ".ui-menu" ).addBack()
  1267. .removeAttr( "role aria-labelledby aria-expanded aria-hidden aria-disabled " +
  1268. "tabIndex" )
  1269. .removeUniqueId()
  1270. .show();
  1271. submenus.children().each( function() {
  1272. var elem = $( this );
  1273. if ( elem.data( "ui-menu-submenu-caret" ) ) {
  1274. elem.remove();
  1275. }
  1276. } );
  1277. },
  1278. _keydown: function( event ) {
  1279. var match, prev, character, skip,
  1280. preventDefault = true;
  1281. switch ( event.keyCode ) {
  1282. case $.ui.keyCode.PAGE_UP:
  1283. this.previousPage( event );
  1284. break;
  1285. case $.ui.keyCode.PAGE_DOWN:
  1286. this.nextPage( event );
  1287. break;
  1288. case $.ui.keyCode.HOME:
  1289. this._move( "first", "first", event );
  1290. break;
  1291. case $.ui.keyCode.END:
  1292. this._move( "last", "last", event );
  1293. break;
  1294. case $.ui.keyCode.UP:
  1295. this.previous( event );
  1296. break;
  1297. case $.ui.keyCode.DOWN:
  1298. this.next( event );
  1299. break;
  1300. case $.ui.keyCode.LEFT:
  1301. this.collapse( event );
  1302. break;
  1303. case $.ui.keyCode.RIGHT:
  1304. if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
  1305. this.expand( event );
  1306. }
  1307. break;
  1308. case $.ui.keyCode.ENTER:
  1309. case $.ui.keyCode.SPACE:
  1310. this._activate( event );
  1311. break;
  1312. case $.ui.keyCode.ESCAPE:
  1313. this.collapse( event );
  1314. break;
  1315. default:
  1316. preventDefault = false;
  1317. prev = this.previousFilter || "";
  1318. skip = false;
  1319. // Support number pad values
  1320. character = event.keyCode >= 96 && event.keyCode <= 105 ?
  1321. ( event.keyCode - 96 ).toString() : String.fromCharCode( event.keyCode );
  1322. clearTimeout( this.filterTimer );
  1323. if ( character === prev ) {
  1324. skip = true;
  1325. } else {
  1326. character = prev + character;
  1327. }
  1328. match = this._filterMenuItems( character );
  1329. match = skip && match.index( this.active.next() ) !== -1 ?
  1330. this.active.nextAll( ".ui-menu-item" ) :
  1331. match;
  1332. // If no matches on the current filter, reset to the last character pressed
  1333. // to move down the menu to the first item that starts with that character
  1334. if ( !match.length ) {
  1335. character = String.fromCharCode( event.keyCode );
  1336. match = this._filterMenuItems( character );
  1337. }
  1338. if ( match.length ) {
  1339. this.focus( event, match );
  1340. this.previousFilter = character;
  1341. this.filterTimer = this._delay( function() {
  1342. delete this.previousFilter;
  1343. }, 1000 );
  1344. } else {
  1345. delete this.previousFilter;
  1346. }
  1347. }
  1348. if ( preventDefault ) {
  1349. event.preventDefault();
  1350. }
  1351. },
  1352. _activate: function( event ) {
  1353. if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
  1354. if ( this.active.children( "[aria-haspopup='true']" ).length ) {
  1355. this.expand( event );
  1356. } else {
  1357. this.select( event );
  1358. }
  1359. }
  1360. },
  1361. refresh: function() {
  1362. var menus, items, newSubmenus, newItems, newWrappers,
  1363. that = this,
  1364. icon = this.options.icons.submenu,
  1365. submenus = this.element.find( this.options.menus );
  1366. this._toggleClass( "ui-menu-icons", null, !!this.element.find( ".ui-icon" ).length );
  1367. // Initialize nested menus
  1368. newSubmenus = submenus.filter( ":not(.ui-menu)" )
  1369. .hide()
  1370. .attr( {
  1371. role: this.options.role,
  1372. "aria-hidden": "true",
  1373. "aria-expanded": "false"
  1374. } )
  1375. .each( function() {
  1376. var menu = $( this ),
  1377. item = menu.prev(),
  1378. submenuCaret = $( "<span>" ).data( "ui-menu-submenu-caret", true );
  1379. that._addClass( submenuCaret, "ui-menu-icon", "ui-icon " + icon );
  1380. item
  1381. .attr( "aria-haspopup", "true" )
  1382. .prepend( submenuCaret );
  1383. menu.attr( "aria-labelledby", item.attr( "id" ) );
  1384. } );
  1385. this._addClass( newSubmenus, "ui-menu", "ui-widget ui-widget-content ui-front" );
  1386. menus = submenus.add( this.element );
  1387. items = menus.find( this.options.items );
  1388. // Initialize menu-items containing spaces and/or dashes only as dividers
  1389. items.not( ".ui-menu-item" ).each( function() {
  1390. var item = $( this );
  1391. if ( that._isDivider( item ) ) {
  1392. that._addClass( item, "ui-menu-divider", "ui-widget-content" );
  1393. }
  1394. } );
  1395. // Don't refresh list items that are already adapted
  1396. newItems = items.not( ".ui-menu-item, .ui-menu-divider" );
  1397. newWrappers = newItems.children()
  1398. .not( ".ui-menu" )
  1399. .uniqueId()
  1400. .attr( {
  1401. tabIndex: -1,
  1402. role: this._itemRole()
  1403. } );
  1404. this._addClass( newItems, "ui-menu-item" )
  1405. ._addClass( newWrappers, "ui-menu-item-wrapper" );
  1406. // Add aria-disabled attribute to any disabled menu item
  1407. items.filter( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
  1408. // If the active item has been removed, blur the menu
  1409. if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
  1410. this.blur();
  1411. }
  1412. },
  1413. _itemRole: function() {
  1414. return {
  1415. menu: "menuitem",
  1416. listbox: "option"
  1417. }[ this.options.role ];
  1418. },
  1419. _setOption: function( key, value ) {
  1420. if ( key === "icons" ) {
  1421. var icons = this.element.find( ".ui-menu-icon" );
  1422. this._removeClass( icons, null, this.options.icons.submenu )
  1423. ._addClass( icons, null, value.submenu );
  1424. }
  1425. this._super( key, value );
  1426. },
  1427. _setOptionDisabled: function( value ) {
  1428. this._super( value );
  1429. this.element.attr( "aria-disabled", String( value ) );
  1430. this._toggleClass( null, "ui-state-disabled", !!value );
  1431. },
  1432. focus: function( event, item ) {
  1433. var nested, focused, activeParent;
  1434. this.blur( event, event && event.type === "focus" );
  1435. this._scrollIntoView( item );
  1436. this.active = item.first();
  1437. focused = this.active.children( ".ui-menu-item-wrapper" );
  1438. this._addClass( focused, null, "ui-state-active" );
  1439. // Only update aria-activedescendant if there's a role
  1440. // otherwise we assume focus is managed elsewhere
  1441. if ( this.options.role ) {
  1442. this.element.attr( "aria-activedescendant", focused.attr( "id" ) );
  1443. }
  1444. // Highlight active parent menu item, if any
  1445. activeParent = this.active
  1446. .parent()
  1447. .closest( ".ui-menu-item" )
  1448. .children( ".ui-menu-item-wrapper" );
  1449. this._addClass( activeParent, null, "ui-state-active" );
  1450. if ( event && event.type === "keydown" ) {
  1451. this._close();
  1452. } else {
  1453. this.timer = this._delay( function() {
  1454. this._close();
  1455. }, this.delay );
  1456. }
  1457. nested = item.children( ".ui-menu" );
  1458. if ( nested.length && event && ( /^mouse/.test( event.type ) ) ) {
  1459. this._startOpening( nested );
  1460. }
  1461. this.activeMenu = item.parent();
  1462. this._trigger( "focus", event, { item: item } );
  1463. },
  1464. _scrollIntoView: function( item ) {
  1465. var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
  1466. if ( this._hasScroll() ) {
  1467. borderTop = parseFloat( $.css( this.activeMenu[ 0 ], "borderTopWidth" ) ) || 0;
  1468. paddingTop = parseFloat( $.css( this.activeMenu[ 0 ], "paddingTop" ) ) || 0;
  1469. offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
  1470. scroll = this.activeMenu.scrollTop();
  1471. elementHeight = this.activeMenu.height();
  1472. itemHeight = item.outerHeight();
  1473. if ( offset < 0 ) {
  1474. this.activeMenu.scrollTop( scroll + offset );
  1475. } else if ( offset + itemHeight > elementHeight ) {
  1476. this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
  1477. }
  1478. }
  1479. },
  1480. blur: function( event, fromFocus ) {
  1481. if ( !fromFocus ) {
  1482. clearTimeout( this.timer );
  1483. }
  1484. if ( !this.active ) {
  1485. return;
  1486. }
  1487. this._removeClass( this.active.children( ".ui-menu-item-wrapper" ),
  1488. null, "ui-state-active" );
  1489. this._trigger( "blur", event, { item: this.active } );
  1490. this.active = null;
  1491. },
  1492. _startOpening: function( submenu ) {
  1493. clearTimeout( this.timer );
  1494. // Don't open if already open fixes a Firefox bug that caused a .5 pixel
  1495. // shift in the submenu position when mousing over the caret icon
  1496. if ( submenu.attr( "aria-hidden" ) !== "true" ) {
  1497. return;
  1498. }
  1499. this.timer = this._delay( function() {
  1500. this._close();
  1501. this._open( submenu );
  1502. }, this.delay );
  1503. },
  1504. _open: function( submenu ) {
  1505. var position = $.extend( {
  1506. of: this.active
  1507. }, this.options.position );
  1508. clearTimeout( this.timer );
  1509. this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) )
  1510. .hide()
  1511. .attr( "aria-hidden", "true" );
  1512. submenu
  1513. .show()
  1514. .removeAttr( "aria-hidden" )
  1515. .attr( "aria-expanded", "true" )
  1516. .position( position );
  1517. },
  1518. collapseAll: function( event, all ) {
  1519. clearTimeout( this.timer );
  1520. this.timer = this._delay( function() {
  1521. // If we were passed an event, look for the submenu that contains the event
  1522. var currentMenu = all ? this.element :
  1523. $( event && event.target ).closest( this.element.find( ".ui-menu" ) );
  1524. // If we found no valid submenu ancestor, use the main menu to close all
  1525. // sub menus anyway
  1526. if ( !currentMenu.length ) {
  1527. currentMenu = this.element;
  1528. }
  1529. this._close( currentMenu );
  1530. this.blur( event );
  1531. // Work around active item staying active after menu is blurred
  1532. this._removeClass( currentMenu.find( ".ui-state-active" ), null, "ui-state-active" );
  1533. this.activeMenu = currentMenu;
  1534. }, this.delay );
  1535. },
  1536. // With no arguments, closes the currently active menu - if nothing is active
  1537. // it closes all menus. If passed an argument, it will search for menus BELOW
  1538. _close: function( startMenu ) {
  1539. if ( !startMenu ) {
  1540. startMenu = this.active ? this.active.parent() : this.element;
  1541. }
  1542. startMenu.find( ".ui-menu" )
  1543. .hide()
  1544. .attr( "aria-hidden", "true" )
  1545. .attr( "aria-expanded", "false" );
  1546. },
  1547. _closeOnDocumentClick: function( event ) {
  1548. return !$( event.target ).closest( ".ui-menu" ).length;
  1549. },
  1550. _isDivider: function( item ) {
  1551. // Match hyphen, em dash, en dash
  1552. return !/[^\-\u2014\u2013\s]/.test( item.text() );
  1553. },
  1554. collapse: function( event ) {
  1555. var newItem = this.active &&
  1556. this.active.parent().closest( ".ui-menu-item", this.element );
  1557. if ( newItem && newItem.length ) {
  1558. this._close();
  1559. this.focus( event, newItem );
  1560. }
  1561. },
  1562. expand: function( event ) {
  1563. var newItem = this.active &&
  1564. this.active
  1565. .children( ".ui-menu " )
  1566. .find( this.options.items )
  1567. .first();
  1568. if ( newItem && newItem.length ) {
  1569. this._open( newItem.parent() );
  1570. // Delay so Firefox will not hide activedescendant change in expanding submenu from AT
  1571. this._delay( function() {
  1572. this.focus( event, newItem );
  1573. } );
  1574. }
  1575. },
  1576. next: function( event ) {
  1577. this._move( "next", "first", event );
  1578. },
  1579. previous: function( event ) {
  1580. this._move( "prev", "last", event );
  1581. },
  1582. isFirstItem: function() {
  1583. return this.active && !this.active.prevAll( ".ui-menu-item" ).length;
  1584. },
  1585. isLastItem: function() {
  1586. return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
  1587. },
  1588. _move: function( direction, filter, event ) {
  1589. var next;
  1590. if ( this.active ) {
  1591. if ( direction === "first" || direction === "last" ) {
  1592. next = this.active
  1593. [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
  1594. .eq( -1 );
  1595. } else {
  1596. next = this.active
  1597. [ direction + "All" ]( ".ui-menu-item" )
  1598. .eq( 0 );
  1599. }
  1600. }
  1601. if ( !next || !next.length || !this.active ) {
  1602. next = this.activeMenu.find( this.options.items )[ filter ]();
  1603. }
  1604. this.focus( event, next );
  1605. },
  1606. nextPage: function( event ) {
  1607. var item, base, height;
  1608. if ( !this.active ) {
  1609. this.next( event );
  1610. return;
  1611. }
  1612. if ( this.isLastItem() ) {
  1613. return;
  1614. }
  1615. if ( this._hasScroll() ) {
  1616. base = this.active.offset().top;
  1617. height = this.element.height();
  1618. this.active.nextAll( ".ui-menu-item" ).each( function() {
  1619. item = $( this );
  1620. return item.offset().top - base - height < 0;
  1621. } );
  1622. this.focus( event, item );
  1623. } else {
  1624. this.focus( event, this.activeMenu.find( this.options.items )
  1625. [ !this.active ? "first" : "last" ]() );
  1626. }
  1627. },
  1628. previousPage: function( event ) {
  1629. var item, base, height;
  1630. if ( !this.active ) {
  1631. this.next( event );
  1632. return;
  1633. }
  1634. if ( this.isFirstItem() ) {
  1635. return;
  1636. }
  1637. if ( this._hasScroll() ) {
  1638. base = this.active.offset().top;
  1639. height = this.element.height();
  1640. this.active.prevAll( ".ui-menu-item" ).each( function() {
  1641. item = $( this );
  1642. return item.offset().top - base + height > 0;
  1643. } );
  1644. this.focus( event, item );
  1645. } else {
  1646. this.focus( event, this.activeMenu.find( this.options.items ).first() );
  1647. }
  1648. },
  1649. _hasScroll: function() {
  1650. return this.element.outerHeight() < this.element.prop( "scrollHeight" );
  1651. },
  1652. select: function( event ) {
  1653. // TODO: It should never be possible to not have an active item at this
  1654. // point, but the tests don't trigger mouseenter before click.
  1655. this.active = this.active || $( event.target ).closest( ".ui-menu-item" );
  1656. var ui = { item: this.active };
  1657. if ( !this.active.has( ".ui-menu" ).length ) {
  1658. this.collapseAll( event, true );
  1659. }
  1660. this._trigger( "select", event, ui );
  1661. },
  1662. _filterMenuItems: function( character ) {
  1663. var escapedCharacter = character.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" ),
  1664. regex = new RegExp( "^" + escapedCharacter, "i" );
  1665. return this.activeMenu
  1666. .find( this.options.items )
  1667. // Only match on items, not dividers or other content (#10571)
  1668. .filter( ".ui-menu-item" )
  1669. .filter( function() {
  1670. return regex.test(
  1671. $.trim( $( this ).children( ".ui-menu-item-wrapper" ).text() ) );
  1672. } );
  1673. }
  1674. } );
  1675. /*!
  1676. * jQuery UI Autocomplete 1.12.1
  1677. * http://jqueryui.com
  1678. *
  1679. * Copyright jQuery Foundation and other contributors
  1680. * Released under the MIT license.
  1681. * http://jquery.org/license
  1682. */
  1683. //>>label: Autocomplete
  1684. //>>group: Widgets
  1685. //>>description: Lists suggested words as the user is typing.
  1686. //>>docs: http://api.jqueryui.com/autocomplete/
  1687. //>>demos: http://jqueryui.com/autocomplete/
  1688. //>>css.structure: ../../themes/base/core.css
  1689. //>>css.structure: ../../themes/base/autocomplete.css
  1690. //>>css.theme: ../../themes/base/theme.css
  1691. $.widget( "ui.autocomplete", {
  1692. version: "1.12.1",
  1693. defaultElement: "<input>",
  1694. options: {
  1695. appendTo: null,
  1696. autoFocus: false,
  1697. delay: 300,
  1698. minLength: 1,
  1699. position: {
  1700. my: "left top",
  1701. at: "left bottom",
  1702. collision: "none"
  1703. },
  1704. source: null,
  1705. // Callbacks
  1706. change: null,
  1707. close: null,
  1708. focus: null,
  1709. open: null,
  1710. response: null,
  1711. search: null,
  1712. select: null
  1713. },
  1714. requestIndex: 0,
  1715. pending: 0,
  1716. _create: function() {
  1717. // Some browsers only repeat keydown events, not keypress events,
  1718. // so we use the suppressKeyPress flag to determine if we've already
  1719. // handled the keydown event. #7269
  1720. // Unfortunately the code for & in keypress is the same as the up arrow,
  1721. // so we use the suppressKeyPressRepeat flag to avoid handling keypress
  1722. // events when we know the keydown event was used to modify the
  1723. // search term. #7799
  1724. var suppressKeyPress, suppressKeyPressRepeat, suppressInput,
  1725. nodeName = this.element[ 0 ].nodeName.toLowerCase(),
  1726. isTextarea = nodeName === "textarea",
  1727. isInput = nodeName === "input";
  1728. // Textareas are always multi-line
  1729. // Inputs are always single-line, even if inside a contentEditable element
  1730. // IE also treats inputs as contentEditable
  1731. // All other element types are determined by whether or not they're contentEditable
  1732. this.isMultiLine = isTextarea || !isInput && this._isContentEditable( this.element );
  1733. this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ];
  1734. this.isNewMenu = true;
  1735. this._addClass( "ui-autocomplete-input" );
  1736. this.element.attr( "autocomplete", "off" );
  1737. this._on( this.element, {
  1738. keydown: function( event ) {
  1739. if ( this.element.prop( "readOnly" ) ) {
  1740. suppressKeyPress = true;
  1741. suppressInput = true;
  1742. suppressKeyPressRepeat = true;
  1743. return;
  1744. }
  1745. suppressKeyPress = false;
  1746. suppressInput = false;
  1747. suppressKeyPressRepeat = false;
  1748. var keyCode = $.ui.keyCode;
  1749. switch ( event.keyCode ) {
  1750. case keyCode.PAGE_UP:
  1751. suppressKeyPress = true;
  1752. this._move( "previousPage", event );
  1753. break;
  1754. case keyCode.PAGE_DOWN:
  1755. suppressKeyPress = true;
  1756. this._move( "nextPage", event );
  1757. break;
  1758. case keyCode.UP:
  1759. suppressKeyPress = true;
  1760. this._keyEvent( "previous", event );
  1761. break;
  1762. case keyCode.DOWN:
  1763. suppressKeyPress = true;
  1764. this._keyEvent( "next", event );
  1765. break;
  1766. case keyCode.ENTER:
  1767. // when menu is open and has focus
  1768. if ( this.menu.active ) {
  1769. // #6055 - Opera still allows the keypress to occur
  1770. // which causes forms to submit
  1771. suppressKeyPress = true;
  1772. event.preventDefault();
  1773. this.menu.select( event );
  1774. }
  1775. break;
  1776. case keyCode.TAB:
  1777. if ( this.menu.active ) {
  1778. this.menu.select( event );
  1779. }
  1780. break;
  1781. case keyCode.ESCAPE:
  1782. if ( this.menu.element.is( ":visible" ) ) {
  1783. if ( !this.isMultiLine ) {
  1784. this._value( this.term );
  1785. }
  1786. this.close( event );
  1787. // Different browsers have different default behavior for escape
  1788. // Single press can mean undo or clear
  1789. // Double press in IE means clear the whole form
  1790. event.preventDefault();
  1791. }
  1792. break;
  1793. default:
  1794. suppressKeyPressRepeat = true;
  1795. // search timeout should be triggered before the input value is changed
  1796. this._searchTimeout( event );
  1797. break;
  1798. }
  1799. },
  1800. keypress: function( event ) {
  1801. if ( suppressKeyPress ) {
  1802. suppressKeyPress = false;
  1803. if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
  1804. event.preventDefault();
  1805. }
  1806. return;
  1807. }
  1808. if ( suppressKeyPressRepeat ) {
  1809. return;
  1810. }
  1811. // Replicate some key handlers to allow them to repeat in Firefox and Opera
  1812. var keyCode = $.ui.keyCode;
  1813. switch ( event.keyCode ) {
  1814. case keyCode.PAGE_UP:
  1815. this._move( "previousPage", event );
  1816. break;
  1817. case keyCode.PAGE_DOWN:
  1818. this._move( "nextPage", event );
  1819. break;
  1820. case keyCode.UP:
  1821. this._keyEvent( "previous", event );
  1822. break;
  1823. case keyCode.DOWN:
  1824. this._keyEvent( "next", event );
  1825. break;
  1826. }
  1827. },
  1828. input: function( event ) {
  1829. if ( suppressInput ) {
  1830. suppressInput = false;
  1831. event.preventDefault();
  1832. return;
  1833. }
  1834. this._searchTimeout( event );
  1835. },
  1836. focus: function() {
  1837. this.selectedItem = null;
  1838. this.previous = this._value();
  1839. },
  1840. blur: function( event ) {
  1841. if ( this.cancelBlur ) {
  1842. delete this.cancelBlur;
  1843. return;
  1844. }
  1845. clearTimeout( this.searching );
  1846. this.close( event );
  1847. this._change( event );
  1848. }
  1849. } );
  1850. this._initSource();
  1851. this.menu = $( "<ul>" )
  1852. .appendTo( this._appendTo() )
  1853. .menu( {
  1854. // disable ARIA support, the live region takes care of that
  1855. role: null
  1856. } )
  1857. .hide()
  1858. .menu( "instance" );
  1859. this._addClass( this.menu.element, "ui-autocomplete", "ui-front" );
  1860. this._on( this.menu.element, {
  1861. mousedown: function( event ) {
  1862. // prevent moving focus out of the text field
  1863. event.preventDefault();
  1864. // IE doesn't prevent moving focus even with event.preventDefault()
  1865. // so we set a flag to know when we should ignore the blur event
  1866. this.cancelBlur = true;
  1867. this._delay( function() {
  1868. delete this.cancelBlur;
  1869. // Support: IE 8 only
  1870. // Right clicking a menu item or selecting text from the menu items will
  1871. // result in focus moving out of the input. However, we've already received
  1872. // and ignored the blur event because of the cancelBlur flag set above. So
  1873. // we restore focus to ensure that the menu closes properly based on the user's
  1874. // next actions.
  1875. if ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {
  1876. this.element.trigger( "focus" );
  1877. }
  1878. } );
  1879. },
  1880. menufocus: function( event, ui ) {
  1881. var label, item;
  1882. // support: Firefox
  1883. // Prevent accidental activation of menu items in Firefox (#7024 #9118)
  1884. if ( this.isNewMenu ) {
  1885. this.isNewMenu = false;
  1886. if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) {
  1887. this.menu.blur();
  1888. this.document.one( "mousemove", function() {
  1889. $( event.target ).trigger( event.originalEvent );
  1890. } );
  1891. return;
  1892. }
  1893. }
  1894. item = ui.item.data( "ui-autocomplete-item" );
  1895. if ( false !== this._trigger( "focus", event, { item: item } ) ) {
  1896. // use value to match what will end up in the input, if it was a key event
  1897. if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
  1898. this._value( item.value );
  1899. }
  1900. }
  1901. // Announce the value in the liveRegion
  1902. label = ui.item.attr( "aria-label" ) || item.value;
  1903. if ( label && $.trim( label ).length ) {
  1904. this.liveRegion.children().hide();
  1905. $( "<div>" ).text( label ).appendTo( this.liveRegion );
  1906. }
  1907. },
  1908. menuselect: function( event, ui ) {
  1909. var item = ui.item.data( "ui-autocomplete-item" ),
  1910. previous = this.previous;
  1911. // Only trigger when focus was lost (click on menu)
  1912. if ( this.element[ 0 ] !== $.ui.safeActiveElement( this.document[ 0 ] ) ) {
  1913. this.element.trigger( "focus" );
  1914. this.previous = previous;
  1915. // #6109 - IE triggers two focus events and the second
  1916. // is asynchronous, so we need to reset the previous
  1917. // term synchronously and asynchronously :-(
  1918. this._delay( function() {
  1919. this.previous = previous;
  1920. this.selectedItem = item;
  1921. } );
  1922. }
  1923. if ( false !== this._trigger( "select", event, { item: item } ) ) {
  1924. this._value( item.value );
  1925. }
  1926. // reset the term after the select event
  1927. // this allows custom select handling to work properly
  1928. this.term = this._value();
  1929. this.close( event );
  1930. this.selectedItem = item;
  1931. }
  1932. } );
  1933. this.liveRegion = $( "<div>", {
  1934. role: "status",
  1935. "aria-live": "assertive",
  1936. "aria-relevant": "additions"
  1937. } )
  1938. .appendTo( this.document[ 0 ].body );
  1939. this._addClass( this.liveRegion, null, "ui-helper-hidden-accessible" );
  1940. // Turning off autocomplete prevents the browser from remembering the
  1941. // value when navigating through history, so we re-enable autocomplete
  1942. // if the page is unloaded before the widget is destroyed. #7790
  1943. this._on( this.window, {
  1944. beforeunload: function() {
  1945. this.element.removeAttr( "autocomplete" );
  1946. }
  1947. } );
  1948. },
  1949. _destroy: function() {
  1950. clearTimeout( this.searching );
  1951. this.element.removeAttr( "autocomplete" );
  1952. this.menu.element.remove();
  1953. this.liveRegion.remove();
  1954. },
  1955. _setOption: function( key, value ) {
  1956. this._super( key, value );
  1957. if ( key === "source" ) {
  1958. this._initSource();
  1959. }
  1960. if ( key === "appendTo" ) {
  1961. this.menu.element.appendTo( this._appendTo() );
  1962. }
  1963. if ( key === "disabled" && value && this.xhr ) {
  1964. this.xhr.abort();
  1965. }
  1966. },
  1967. _isEventTargetInWidget: function( event ) {
  1968. var menuElement = this.menu.element[ 0 ];
  1969. return event.target === this.element[ 0 ] ||
  1970. event.target === menuElement ||
  1971. $.contains( menuElement, event.target );
  1972. },
  1973. _closeOnClickOutside: function( event ) {
  1974. if ( !this._isEventTargetInWidget( event ) ) {
  1975. this.close();
  1976. }
  1977. },
  1978. _appendTo: function() {
  1979. var element = this.options.appendTo;
  1980. if ( element ) {
  1981. element = element.jquery || element.nodeType ?
  1982. $( element ) :
  1983. this.document.find( element ).eq( 0 );
  1984. }
  1985. if ( !element || !element[ 0 ] ) {
  1986. element = this.element.closest( ".ui-front, dialog" );
  1987. }
  1988. if ( !element.length ) {
  1989. element = this.document[ 0 ].body;
  1990. }
  1991. return element;
  1992. },
  1993. _initSource: function() {
  1994. var array, url,
  1995. that = this;
  1996. if ( $.isArray( this.options.source ) ) {
  1997. array = this.options.source;
  1998. this.source = function( request, response ) {
  1999. response( $.ui.autocomplete.filter( array, request.term ) );
  2000. };
  2001. } else if ( typeof this.options.source === "string" ) {
  2002. url = this.options.source;
  2003. this.source = function( request, response ) {
  2004. if ( that.xhr ) {
  2005. that.xhr.abort();
  2006. }
  2007. that.xhr = $.ajax( {
  2008. url: url,
  2009. data: request,
  2010. dataType: "json",
  2011. success: function( data ) {
  2012. response( data );
  2013. },
  2014. error: function() {
  2015. response( [] );
  2016. }
  2017. } );
  2018. };
  2019. } else {
  2020. this.source = this.options.source;
  2021. }
  2022. },
  2023. _searchTimeout: function( event ) {
  2024. clearTimeout( this.searching );
  2025. this.searching = this._delay( function() {
  2026. // Search if the value has changed, or if the user retypes the same value (see #7434)
  2027. var equalValues = this.term === this._value(),
  2028. menuVisible = this.menu.element.is( ":visible" ),
  2029. modifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
  2030. if ( !equalValues || ( equalValues && !menuVisible && !modifierKey ) ) {
  2031. this.selectedItem = null;
  2032. this.search( null, event );
  2033. }
  2034. }, this.options.delay );
  2035. },
  2036. search: function( value, event ) {
  2037. value = value != null ? value : this._value();
  2038. // Always save the actual value, not the one passed as an argument
  2039. this.term = this._value();
  2040. if ( value.length < this.options.minLength ) {
  2041. return this.close( event );
  2042. }
  2043. if ( this._trigger( "search", event ) === false ) {
  2044. return;
  2045. }
  2046. return this._search( value );
  2047. },
  2048. _search: function( value ) {
  2049. this.pending++;
  2050. this._addClass( "ui-autocomplete-loading" );
  2051. this.cancelSearch = false;
  2052. this.source( { term: value }, this._response() );
  2053. },
  2054. _response: function() {
  2055. var index = ++this.requestIndex;
  2056. return $.proxy( function( content ) {
  2057. if ( index === this.requestIndex ) {
  2058. this.__response( content );
  2059. }
  2060. this.pending--;
  2061. if ( !this.pending ) {
  2062. this._removeClass( "ui-autocomplete-loading" );
  2063. }
  2064. }, this );
  2065. },
  2066. __response: function( content ) {
  2067. if ( content ) {
  2068. content = this._normalize( content );
  2069. }
  2070. this._trigger( "response", null, { content: content } );
  2071. if ( !this.options.disabled && content && content.length && !this.cancelSearch ) {
  2072. this._suggest( content );
  2073. this._trigger( "open" );
  2074. } else {
  2075. // use ._close() instead of .close() so we don't cancel future searches
  2076. this._close();
  2077. }
  2078. },
  2079. close: function( event ) {
  2080. this.cancelSearch = true;
  2081. this._close( event );
  2082. },
  2083. _close: function( event ) {
  2084. // Remove the handler that closes the menu on outside clicks
  2085. this._off( this.document, "mousedown" );
  2086. if ( this.menu.element.is( ":visible" ) ) {
  2087. this.menu.element.hide();
  2088. this.menu.blur();
  2089. this.isNewMenu = true;
  2090. this._trigger( "close", event );
  2091. }
  2092. },
  2093. _change: function( event ) {
  2094. if ( this.previous !== this._value() ) {
  2095. this._trigger( "change", event, { item: this.selectedItem } );
  2096. }
  2097. },
  2098. _normalize: function( items ) {
  2099. // assume all items have the right format when the first item is complete
  2100. if ( items.length && items[ 0 ].label && items[ 0 ].value ) {
  2101. return items;
  2102. }
  2103. return $.map( items, function( item ) {
  2104. if ( typeof item === "string" ) {
  2105. return {
  2106. label: item,
  2107. value: item
  2108. };
  2109. }
  2110. return $.extend( {}, item, {
  2111. label: item.label || item.value,
  2112. value: item.value || item.label
  2113. } );
  2114. } );
  2115. },
  2116. _suggest: function( items ) {
  2117. var ul = this.menu.element.empty();
  2118. this._renderMenu( ul, items );
  2119. this.isNewMenu = true;
  2120. this.menu.refresh();
  2121. // Size and position menu
  2122. ul.show();
  2123. this._resizeMenu();
  2124. ul.position( $.extend( {
  2125. of: this.element
  2126. }, this.options.position ) );
  2127. if ( this.options.autoFocus ) {
  2128. this.menu.next();
  2129. }
  2130. // Listen for interactions outside of the widget (#6642)
  2131. this._on( this.document, {
  2132. mousedown: "_closeOnClickOutside"
  2133. } );
  2134. },
  2135. _resizeMenu: function() {
  2136. var ul = this.menu.element;
  2137. ul.outerWidth( Math.max(
  2138. // Firefox wraps long text (possibly a rounding bug)
  2139. // so we add 1px to avoid the wrapping (#7513)
  2140. ul.width( "" ).outerWidth() + 1,
  2141. this.element.outerWidth()
  2142. ) );
  2143. },
  2144. _renderMenu: function( ul, items ) {
  2145. var that = this;
  2146. $.each( items, function( index, item ) {
  2147. that._renderItemData( ul, item );
  2148. } );
  2149. },
  2150. _renderItemData: function( ul, item ) {
  2151. return this._renderItem( ul, item ).data( "ui-autocomplete-item", item );
  2152. },
  2153. _renderItem: function( ul, item ) {
  2154. return $( "<li>" )
  2155. .append( $( "<div>" ).text( item.label ) )
  2156. .appendTo( ul );
  2157. },
  2158. _move: function( direction, event ) {
  2159. if ( !this.menu.element.is( ":visible" ) ) {
  2160. this.search( null, event );
  2161. return;
  2162. }
  2163. if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
  2164. this.menu.isLastItem() && /^next/.test( direction ) ) {
  2165. if ( !this.isMultiLine ) {
  2166. this._value( this.term );
  2167. }
  2168. this.menu.blur();
  2169. return;
  2170. }
  2171. this.menu[ direction ]( event );
  2172. },
  2173. widget: function() {
  2174. return this.menu.element;
  2175. },
  2176. _value: function() {
  2177. return this.valueMethod.apply( this.element, arguments );
  2178. },
  2179. _keyEvent: function( keyEvent, event ) {
  2180. if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
  2181. this._move( keyEvent, event );
  2182. // Prevents moving cursor to beginning/end of the text field in some browsers
  2183. event.preventDefault();
  2184. }
  2185. },
  2186. // Support: Chrome <=50
  2187. // We should be able to just use this.element.prop( "isContentEditable" )
  2188. // but hidden elements always report false in Chrome.
  2189. // https://code.google.com/p/chromium/issues/detail?id=313082
  2190. _isContentEditable: function( element ) {
  2191. if ( !element.length ) {
  2192. return false;
  2193. }
  2194. var editable = element.prop( "contentEditable" );
  2195. if ( editable === "inherit" ) {
  2196. return this._isContentEditable( element.parent() );
  2197. }
  2198. return editable === "true";
  2199. }
  2200. } );
  2201. $.extend( $.ui.autocomplete, {
  2202. escapeRegex: function( value ) {
  2203. return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
  2204. },
  2205. filter: function( array, term ) {
  2206. var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" );
  2207. return $.grep( array, function( value ) {
  2208. return matcher.test( value.label || value.value || value );
  2209. } );
  2210. }
  2211. } );
  2212. // Live region extension, adding a `messages` option
  2213. // NOTE: This is an experimental API. We are still investigating
  2214. // a full solution for string manipulation and internationalization.
  2215. $.widget( "ui.autocomplete", $.ui.autocomplete, {
  2216. options: {
  2217. messages: {
  2218. noResults: "No search results.",
  2219. results: function( amount ) {
  2220. return amount + ( amount > 1 ? " results are" : " result is" ) +
  2221. " available, use up and down arrow keys to navigate.";
  2222. }
  2223. }
  2224. },
  2225. __response: function( content ) {
  2226. var message;
  2227. this._superApply( arguments );
  2228. if ( this.options.disabled || this.cancelSearch ) {
  2229. return;
  2230. }
  2231. if ( content && content.length ) {
  2232. message = this.options.messages.results( content.length );
  2233. } else {
  2234. message = this.options.messages.noResults;
  2235. }
  2236. this.liveRegion.children().hide();
  2237. $( "<div>" ).text( message ).appendTo( this.liveRegion );
  2238. }
  2239. } );
  2240. var widgetsAutocomplete = $.ui.autocomplete;
  2241. }));