Brak opisu

core.js 48KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. /*! jQuery UI - v1.12.1 - 2020-09-25
  2. * http://jqueryui.com
  3. * Includes: data.js, disable-selection.js, escape-selector.js, focusable.js, form-reset-mixin.js, form.js, ie.js, jquery-1-7.js, keycode.js, labels.js, plugin.js, position.js, safe-active-element.js, safe-blur.js, scroll-parent.js, tabbable.js, unique-id.js, version.js, widget.js
  4. * Copyright jQuery Foundation and other contributors; Licensed */
  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. // Source: version.js
  15. $.ui = $.ui || {};
  16. $.ui.version = "1.12.1";
  17. // Source: data.js
  18. /*!
  19. * jQuery UI :data 1.12.1
  20. * http://jqueryui.com
  21. *
  22. * Copyright jQuery Foundation and other contributors
  23. * Released under the MIT license.
  24. * http://jquery.org/license
  25. */
  26. //>>label: :data Selector
  27. //>>group: Core
  28. //>>description: Selects elements which have data stored under the specified key.
  29. //>>docs: http://api.jqueryui.com/data-selector/
  30. $.extend( $.expr[ ":" ], {
  31. data: $.expr.createPseudo ?
  32. $.expr.createPseudo( function( dataName ) {
  33. return function( elem ) {
  34. return !!$.data( elem, dataName );
  35. };
  36. } ) :
  37. // Support: jQuery <1.8
  38. function( elem, i, match ) {
  39. return !!$.data( elem, match[ 3 ] );
  40. }
  41. } );
  42. // Source: disable-selection.js
  43. /*!
  44. * jQuery UI Disable Selection 1.12.1
  45. * http://jqueryui.com
  46. *
  47. * Copyright jQuery Foundation and other contributors
  48. * Released under the MIT license.
  49. * http://jquery.org/license
  50. */
  51. //>>label: disableSelection
  52. //>>group: Core
  53. //>>description: Disable selection of text content within the set of matched elements.
  54. //>>docs: http://api.jqueryui.com/disableSelection/
  55. // This file is deprecated
  56. $.fn.extend( {
  57. disableSelection: ( function() {
  58. var eventType = "onselectstart" in document.createElement( "div" ) ?
  59. "selectstart" :
  60. "mousedown";
  61. return function() {
  62. return this.on( eventType + ".ui-disableSelection", function( event ) {
  63. event.preventDefault();
  64. } );
  65. };
  66. } )(),
  67. enableSelection: function() {
  68. return this.off( ".ui-disableSelection" );
  69. }
  70. } );
  71. // Source: escape-selector.js
  72. // Internal use only
  73. $.ui.escapeSelector = ( function() {
  74. var selectorEscape = /([!"#$%&'()*+,./:;<=>?@[\]^`{|}~])/g;
  75. return function( selector ) {
  76. return selector.replace( selectorEscape, "\\$1" );
  77. };
  78. } )();
  79. // Source: focusable.js
  80. /*!
  81. * jQuery UI Focusable 1.12.1
  82. * http://jqueryui.com
  83. *
  84. * Copyright jQuery Foundation and other contributors
  85. * Released under the MIT license.
  86. * http://jquery.org/license
  87. */
  88. //>>label: :focusable Selector
  89. //>>group: Core
  90. //>>description: Selects elements which can be focused.
  91. //>>docs: http://api.jqueryui.com/focusable-selector/
  92. // Selectors
  93. $.ui.focusable = function( element, hasTabindex ) {
  94. var map, mapName, img, focusableIfVisible, fieldset,
  95. nodeName = element.nodeName.toLowerCase();
  96. if ( "area" === nodeName ) {
  97. map = element.parentNode;
  98. mapName = map.name;
  99. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  100. return false;
  101. }
  102. img = $( "img[usemap='#" + mapName + "']" );
  103. return img.length > 0 && img.is( ":visible" );
  104. }
  105. if ( /^(input|select|textarea|button|object)$/.test( nodeName ) ) {
  106. focusableIfVisible = !element.disabled;
  107. if ( focusableIfVisible ) {
  108. // Form controls within a disabled fieldset are disabled.
  109. // However, controls within the fieldset's legend do not get disabled.
  110. // Since controls generally aren't placed inside legends, we skip
  111. // this portion of the check.
  112. fieldset = $( element ).closest( "fieldset" )[ 0 ];
  113. if ( fieldset ) {
  114. focusableIfVisible = !fieldset.disabled;
  115. }
  116. }
  117. } else if ( "a" === nodeName ) {
  118. focusableIfVisible = element.href || hasTabindex;
  119. } else {
  120. focusableIfVisible = hasTabindex;
  121. }
  122. return focusableIfVisible && $( element ).is( ":visible" ) && visible( $( element ) );
  123. };
  124. // Support: IE 8 only
  125. // IE 8 doesn't resolve inherit to visible/hidden for computed values
  126. function visible( element ) {
  127. var visibility = element.css( "visibility" );
  128. while ( visibility === "inherit" ) {
  129. element = element.parent();
  130. visibility = element.css( "visibility" );
  131. }
  132. return visibility !== "hidden";
  133. }
  134. $.extend( $.expr[ ":" ], {
  135. focusable: function( element ) {
  136. return $.ui.focusable( element, $.attr( element, "tabindex" ) != null );
  137. }
  138. } );
  139. // Source: form.js
  140. // Support: IE8 Only
  141. // IE8 does not support the form attribute and when it is supplied. It overwrites the form prop
  142. // with a string, so we need to find the proper form.
  143. $.fn.form = function() {
  144. return typeof this[ 0 ].form === "string" ? this.closest( "form" ) : $( this[ 0 ].form );
  145. };
  146. // Source: form-reset-mixin.js
  147. /*!
  148. * jQuery UI Form Reset Mixin 1.12.1
  149. * http://jqueryui.com
  150. *
  151. * Copyright jQuery Foundation and other contributors
  152. * Released under the MIT license.
  153. * http://jquery.org/license
  154. */
  155. //>>label: Form Reset Mixin
  156. //>>group: Core
  157. //>>description: Refresh input widgets when their form is reset
  158. //>>docs: http://api.jqueryui.com/form-reset-mixin/
  159. $.ui.formResetMixin = {
  160. _formResetHandler: function() {
  161. var form = $( this );
  162. // Wait for the form reset to actually happen before refreshing
  163. setTimeout( function() {
  164. var instances = form.data( "ui-form-reset-instances" );
  165. $.each( instances, function() {
  166. this.refresh();
  167. } );
  168. } );
  169. },
  170. _bindFormResetHandler: function() {
  171. this.form = this.element.form();
  172. if ( !this.form.length ) {
  173. return;
  174. }
  175. var instances = this.form.data( "ui-form-reset-instances" ) || [];
  176. if ( !instances.length ) {
  177. // We don't use _on() here because we use a single event handler per form
  178. this.form.on( "reset.ui-form-reset", this._formResetHandler );
  179. }
  180. instances.push( this );
  181. this.form.data( "ui-form-reset-instances", instances );
  182. },
  183. _unbindFormResetHandler: function() {
  184. if ( !this.form.length ) {
  185. return;
  186. }
  187. var instances = this.form.data( "ui-form-reset-instances" );
  188. instances.splice( $.inArray( this, instances ), 1 );
  189. if ( instances.length ) {
  190. this.form.data( "ui-form-reset-instances", instances );
  191. } else {
  192. this.form
  193. .removeData( "ui-form-reset-instances" )
  194. .off( "reset.ui-form-reset" );
  195. }
  196. }
  197. };
  198. // Source: ie.js
  199. // This file is deprecated
  200. $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
  201. // Source: jquery-1-7.js
  202. /*!
  203. * jQuery UI Support for jQuery core 1.7.x 1.12.1
  204. * http://jqueryui.com
  205. *
  206. * Copyright jQuery Foundation and other contributors
  207. * Released under the MIT license.
  208. * http://jquery.org/license
  209. *
  210. */
  211. //>>label: jQuery 1.7 Support
  212. //>>group: Core
  213. //>>description: Support version 1.7.x of jQuery core
  214. // Support: jQuery 1.7 only
  215. // Not a great way to check versions, but since we only support 1.7+ and only
  216. // need to detect <1.8, this is a simple check that should suffice. Checking
  217. // for "1.7." would be a bit safer, but the version string is 1.7, not 1.7.0
  218. // and we'll never reach 1.70.0 (if we do, we certainly won't be supporting
  219. // 1.7 anymore). See #11197 for why we're not using feature detection.
  220. if ( $.fn.jquery.substring( 0, 3 ) === "1.7" ) {
  221. // Setters for .innerWidth(), .innerHeight(), .outerWidth(), .outerHeight()
  222. // Unlike jQuery Core 1.8+, these only support numeric values to set the
  223. // dimensions in pixels
  224. $.each( [ "Width", "Height" ], function( i, name ) {
  225. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  226. type = name.toLowerCase(),
  227. orig = {
  228. innerWidth: $.fn.innerWidth,
  229. innerHeight: $.fn.innerHeight,
  230. outerWidth: $.fn.outerWidth,
  231. outerHeight: $.fn.outerHeight
  232. };
  233. function reduce( elem, size, border, margin ) {
  234. $.each( side, function() {
  235. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  236. if ( border ) {
  237. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  238. }
  239. if ( margin ) {
  240. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  241. }
  242. } );
  243. return size;
  244. }
  245. $.fn[ "inner" + name ] = function( size ) {
  246. if ( size === undefined ) {
  247. return orig[ "inner" + name ].call( this );
  248. }
  249. return this.each( function() {
  250. $( this ).css( type, reduce( this, size ) + "px" );
  251. } );
  252. };
  253. $.fn[ "outer" + name ] = function( size, margin ) {
  254. if ( typeof size !== "number" ) {
  255. return orig[ "outer" + name ].call( this, size );
  256. }
  257. return this.each( function() {
  258. $( this ).css( type, reduce( this, size, true, margin ) + "px" );
  259. } );
  260. };
  261. } );
  262. $.fn.addBack = function( selector ) {
  263. return this.add( selector == null ?
  264. this.prevObject : this.prevObject.filter( selector )
  265. );
  266. };
  267. }
  268. // Source: keycode.js
  269. /*!
  270. * jQuery UI Keycode 1.12.1
  271. * http://jqueryui.com
  272. *
  273. * Copyright jQuery Foundation and other contributors
  274. * Released under the MIT license.
  275. * http://jquery.org/license
  276. */
  277. //>>label: Keycode
  278. //>>group: Core
  279. //>>description: Provide keycodes as keynames
  280. //>>docs: http://api.jqueryui.com/jQuery.ui.keyCode/
  281. $.ui.keyCode = {
  282. BACKSPACE: 8,
  283. COMMA: 188,
  284. DELETE: 46,
  285. DOWN: 40,
  286. END: 35,
  287. ENTER: 13,
  288. ESCAPE: 27,
  289. HOME: 36,
  290. LEFT: 37,
  291. PAGE_DOWN: 34,
  292. PAGE_UP: 33,
  293. PERIOD: 190,
  294. RIGHT: 39,
  295. SPACE: 32,
  296. TAB: 9,
  297. UP: 38
  298. };
  299. // Source: labels.js
  300. /*!
  301. * jQuery UI Labels 1.12.1
  302. * http://jqueryui.com
  303. *
  304. * Copyright jQuery Foundation and other contributors
  305. * Released under the MIT license.
  306. * http://jquery.org/license
  307. */
  308. //>>label: labels
  309. //>>group: Core
  310. //>>description: Find all the labels associated with a given input
  311. //>>docs: http://api.jqueryui.com/labels/
  312. $.fn.labels = function() {
  313. var ancestor, selector, id, labels, ancestors;
  314. // Check control.labels first
  315. if ( this[ 0 ].labels && this[ 0 ].labels.length ) {
  316. return this.pushStack( this[ 0 ].labels );
  317. }
  318. // Support: IE <= 11, FF <= 37, Android <= 2.3 only
  319. // Above browsers do not support control.labels. Everything below is to support them
  320. // as well as document fragments. control.labels does not work on document fragments
  321. labels = this.eq( 0 ).parents( "label" );
  322. // Look for the label based on the id
  323. id = this.attr( "id" );
  324. if ( id ) {
  325. // We don't search against the document in case the element
  326. // is disconnected from the DOM
  327. ancestor = this.eq( 0 ).parents().last();
  328. // Get a full set of top level ancestors
  329. ancestors = ancestor.add( ancestor.length ? ancestor.siblings() : this.siblings() );
  330. // Create a selector for the label based on the id
  331. selector = "label[for='" + $.ui.escapeSelector( id ) + "']";
  332. labels = labels.add( ancestors.find( selector ).addBack( selector ) );
  333. }
  334. // Return whatever we have found for labels
  335. return this.pushStack( labels );
  336. };
  337. // Source: plugin.js
  338. // $.ui.plugin is deprecated. Use $.widget() extensions instead.
  339. $.ui.plugin = {
  340. add: function( module, option, set ) {
  341. var i,
  342. proto = $.ui[ module ].prototype;
  343. for ( i in set ) {
  344. proto.plugins[ i ] = proto.plugins[ i ] || [];
  345. proto.plugins[ i ].push( [ option, set[ i ] ] );
  346. }
  347. },
  348. call: function( instance, name, args, allowDisconnected ) {
  349. var i,
  350. set = instance.plugins[ name ];
  351. if ( !set ) {
  352. return;
  353. }
  354. if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode ||
  355. instance.element[ 0 ].parentNode.nodeType === 11 ) ) {
  356. return;
  357. }
  358. for ( i = 0; i < set.length; i++ ) {
  359. if ( instance.options[ set[ i ][ 0 ] ] ) {
  360. set[ i ][ 1 ].apply( instance.element, args );
  361. }
  362. }
  363. }
  364. };
  365. // Source: position.js
  366. /*!
  367. * jQuery UI Position 1.12.1
  368. * http://jqueryui.com
  369. *
  370. * Copyright jQuery Foundation and other contributors
  371. * Released under the MIT license.
  372. * http://jquery.org/license
  373. *
  374. * http://api.jqueryui.com/position/
  375. */
  376. //>>label: Position
  377. //>>group: Core
  378. //>>description: Positions elements relative to other elements.
  379. //>>docs: http://api.jqueryui.com/position/
  380. //>>demos: http://jqueryui.com/position/
  381. ( function() {
  382. var cachedScrollbarWidth,
  383. max = Math.max,
  384. abs = Math.abs,
  385. rhorizontal = /left|center|right/,
  386. rvertical = /top|center|bottom/,
  387. roffset = /[\+\-]\d+(\.[\d]+)?%?/,
  388. rposition = /^\w+/,
  389. rpercent = /%$/,
  390. _position = $.fn.position;
  391. function getOffsets( offsets, width, height ) {
  392. return [
  393. parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  394. parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  395. ];
  396. }
  397. function parseCss( element, property ) {
  398. return parseInt( $.css( element, property ), 10 ) || 0;
  399. }
  400. function getDimensions( elem ) {
  401. var raw = elem[ 0 ];
  402. if ( raw.nodeType === 9 ) {
  403. return {
  404. width: elem.width(),
  405. height: elem.height(),
  406. offset: { top: 0, left: 0 }
  407. };
  408. }
  409. if ( $.isWindow( raw ) ) {
  410. return {
  411. width: elem.width(),
  412. height: elem.height(),
  413. offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
  414. };
  415. }
  416. if ( raw.preventDefault ) {
  417. return {
  418. width: 0,
  419. height: 0,
  420. offset: { top: raw.pageY, left: raw.pageX }
  421. };
  422. }
  423. return {
  424. width: elem.outerWidth(),
  425. height: elem.outerHeight(),
  426. offset: elem.offset()
  427. };
  428. }
  429. $.position = {
  430. scrollbarWidth: function() {
  431. if ( cachedScrollbarWidth !== undefined ) {
  432. return cachedScrollbarWidth;
  433. }
  434. var w1, w2,
  435. div = $( "<div " +
  436. "style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'>" +
  437. "<div style='height:100px;width:auto;'></div></div>" ),
  438. innerDiv = div.children()[ 0 ];
  439. $( "body" ).append( div );
  440. w1 = innerDiv.offsetWidth;
  441. div.css( "overflow", "scroll" );
  442. w2 = innerDiv.offsetWidth;
  443. if ( w1 === w2 ) {
  444. w2 = div[ 0 ].clientWidth;
  445. }
  446. div.remove();
  447. return ( cachedScrollbarWidth = w1 - w2 );
  448. },
  449. getScrollInfo: function( within ) {
  450. var overflowX = within.isWindow || within.isDocument ? "" :
  451. within.element.css( "overflow-x" ),
  452. overflowY = within.isWindow || within.isDocument ? "" :
  453. within.element.css( "overflow-y" ),
  454. hasOverflowX = overflowX === "scroll" ||
  455. ( overflowX === "auto" && within.width < within.element[ 0 ].scrollWidth ),
  456. hasOverflowY = overflowY === "scroll" ||
  457. ( overflowY === "auto" && within.height < within.element[ 0 ].scrollHeight );
  458. return {
  459. width: hasOverflowY ? $.position.scrollbarWidth() : 0,
  460. height: hasOverflowX ? $.position.scrollbarWidth() : 0
  461. };
  462. },
  463. getWithinInfo: function( element ) {
  464. var withinElement = $( element || window ),
  465. isWindow = $.isWindow( withinElement[ 0 ] ),
  466. isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
  467. hasOffset = !isWindow && !isDocument;
  468. return {
  469. element: withinElement,
  470. isWindow: isWindow,
  471. isDocument: isDocument,
  472. offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
  473. scrollLeft: withinElement.scrollLeft(),
  474. scrollTop: withinElement.scrollTop(),
  475. width: withinElement.outerWidth(),
  476. height: withinElement.outerHeight()
  477. };
  478. }
  479. };
  480. $.fn.position = function( options ) {
  481. if ( !options || !options.of ) {
  482. return _position.apply( this, arguments );
  483. }
  484. // Make a copy, we don't want to modify arguments
  485. options = $.extend( {}, options );
  486. var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
  487. target = $( options.of ),
  488. within = $.position.getWithinInfo( options.within ),
  489. scrollInfo = $.position.getScrollInfo( within ),
  490. collision = ( options.collision || "flip" ).split( " " ),
  491. offsets = {};
  492. dimensions = getDimensions( target );
  493. if ( target[ 0 ].preventDefault ) {
  494. // Force left top to allow flipping
  495. options.at = "left top";
  496. }
  497. targetWidth = dimensions.width;
  498. targetHeight = dimensions.height;
  499. targetOffset = dimensions.offset;
  500. // Clone to reuse original targetOffset later
  501. basePosition = $.extend( {}, targetOffset );
  502. // Force my and at to have valid horizontal and vertical positions
  503. // if a value is missing or invalid, it will be converted to center
  504. $.each( [ "my", "at" ], function() {
  505. var pos = ( options[ this ] || "" ).split( " " ),
  506. horizontalOffset,
  507. verticalOffset;
  508. if ( pos.length === 1 ) {
  509. pos = rhorizontal.test( pos[ 0 ] ) ?
  510. pos.concat( [ "center" ] ) :
  511. rvertical.test( pos[ 0 ] ) ?
  512. [ "center" ].concat( pos ) :
  513. [ "center", "center" ];
  514. }
  515. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  516. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  517. // Calculate offsets
  518. horizontalOffset = roffset.exec( pos[ 0 ] );
  519. verticalOffset = roffset.exec( pos[ 1 ] );
  520. offsets[ this ] = [
  521. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  522. verticalOffset ? verticalOffset[ 0 ] : 0
  523. ];
  524. // Reduce to just the positions without the offsets
  525. options[ this ] = [
  526. rposition.exec( pos[ 0 ] )[ 0 ],
  527. rposition.exec( pos[ 1 ] )[ 0 ]
  528. ];
  529. } );
  530. // Normalize collision option
  531. if ( collision.length === 1 ) {
  532. collision[ 1 ] = collision[ 0 ];
  533. }
  534. if ( options.at[ 0 ] === "right" ) {
  535. basePosition.left += targetWidth;
  536. } else if ( options.at[ 0 ] === "center" ) {
  537. basePosition.left += targetWidth / 2;
  538. }
  539. if ( options.at[ 1 ] === "bottom" ) {
  540. basePosition.top += targetHeight;
  541. } else if ( options.at[ 1 ] === "center" ) {
  542. basePosition.top += targetHeight / 2;
  543. }
  544. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  545. basePosition.left += atOffset[ 0 ];
  546. basePosition.top += atOffset[ 1 ];
  547. return this.each( function() {
  548. var collisionPosition, using,
  549. elem = $( this ),
  550. elemWidth = elem.outerWidth(),
  551. elemHeight = elem.outerHeight(),
  552. marginLeft = parseCss( this, "marginLeft" ),
  553. marginTop = parseCss( this, "marginTop" ),
  554. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) +
  555. scrollInfo.width,
  556. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) +
  557. scrollInfo.height,
  558. position = $.extend( {}, basePosition ),
  559. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  560. if ( options.my[ 0 ] === "right" ) {
  561. position.left -= elemWidth;
  562. } else if ( options.my[ 0 ] === "center" ) {
  563. position.left -= elemWidth / 2;
  564. }
  565. if ( options.my[ 1 ] === "bottom" ) {
  566. position.top -= elemHeight;
  567. } else if ( options.my[ 1 ] === "center" ) {
  568. position.top -= elemHeight / 2;
  569. }
  570. position.left += myOffset[ 0 ];
  571. position.top += myOffset[ 1 ];
  572. collisionPosition = {
  573. marginLeft: marginLeft,
  574. marginTop: marginTop
  575. };
  576. $.each( [ "left", "top" ], function( i, dir ) {
  577. if ( $.ui.position[ collision[ i ] ] ) {
  578. $.ui.position[ collision[ i ] ][ dir ]( position, {
  579. targetWidth: targetWidth,
  580. targetHeight: targetHeight,
  581. elemWidth: elemWidth,
  582. elemHeight: elemHeight,
  583. collisionPosition: collisionPosition,
  584. collisionWidth: collisionWidth,
  585. collisionHeight: collisionHeight,
  586. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  587. my: options.my,
  588. at: options.at,
  589. within: within,
  590. elem: elem
  591. } );
  592. }
  593. } );
  594. if ( options.using ) {
  595. // Adds feedback as second argument to using callback, if present
  596. using = function( props ) {
  597. var left = targetOffset.left - position.left,
  598. right = left + targetWidth - elemWidth,
  599. top = targetOffset.top - position.top,
  600. bottom = top + targetHeight - elemHeight,
  601. feedback = {
  602. target: {
  603. element: target,
  604. left: targetOffset.left,
  605. top: targetOffset.top,
  606. width: targetWidth,
  607. height: targetHeight
  608. },
  609. element: {
  610. element: elem,
  611. left: position.left,
  612. top: position.top,
  613. width: elemWidth,
  614. height: elemHeight
  615. },
  616. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  617. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  618. };
  619. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  620. feedback.horizontal = "center";
  621. }
  622. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  623. feedback.vertical = "middle";
  624. }
  625. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  626. feedback.important = "horizontal";
  627. } else {
  628. feedback.important = "vertical";
  629. }
  630. options.using.call( this, props, feedback );
  631. };
  632. }
  633. elem.offset( $.extend( position, { using: using } ) );
  634. } );
  635. };
  636. $.ui.position = {
  637. fit: {
  638. left: function( position, data ) {
  639. var within = data.within,
  640. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  641. outerWidth = within.width,
  642. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  643. overLeft = withinOffset - collisionPosLeft,
  644. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  645. newOverRight;
  646. // Element is wider than within
  647. if ( data.collisionWidth > outerWidth ) {
  648. // Element is initially over the left side of within
  649. if ( overLeft > 0 && overRight <= 0 ) {
  650. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth -
  651. withinOffset;
  652. position.left += overLeft - newOverRight;
  653. // Element is initially over right side of within
  654. } else if ( overRight > 0 && overLeft <= 0 ) {
  655. position.left = withinOffset;
  656. // Element is initially over both left and right sides of within
  657. } else {
  658. if ( overLeft > overRight ) {
  659. position.left = withinOffset + outerWidth - data.collisionWidth;
  660. } else {
  661. position.left = withinOffset;
  662. }
  663. }
  664. // Too far left -> align with left edge
  665. } else if ( overLeft > 0 ) {
  666. position.left += overLeft;
  667. // Too far right -> align with right edge
  668. } else if ( overRight > 0 ) {
  669. position.left -= overRight;
  670. // Adjust based on position and margin
  671. } else {
  672. position.left = max( position.left - collisionPosLeft, position.left );
  673. }
  674. },
  675. top: function( position, data ) {
  676. var within = data.within,
  677. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  678. outerHeight = data.within.height,
  679. collisionPosTop = position.top - data.collisionPosition.marginTop,
  680. overTop = withinOffset - collisionPosTop,
  681. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  682. newOverBottom;
  683. // Element is taller than within
  684. if ( data.collisionHeight > outerHeight ) {
  685. // Element is initially over the top of within
  686. if ( overTop > 0 && overBottom <= 0 ) {
  687. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight -
  688. withinOffset;
  689. position.top += overTop - newOverBottom;
  690. // Element is initially over bottom of within
  691. } else if ( overBottom > 0 && overTop <= 0 ) {
  692. position.top = withinOffset;
  693. // Element is initially over both top and bottom of within
  694. } else {
  695. if ( overTop > overBottom ) {
  696. position.top = withinOffset + outerHeight - data.collisionHeight;
  697. } else {
  698. position.top = withinOffset;
  699. }
  700. }
  701. // Too far up -> align with top
  702. } else if ( overTop > 0 ) {
  703. position.top += overTop;
  704. // Too far down -> align with bottom edge
  705. } else if ( overBottom > 0 ) {
  706. position.top -= overBottom;
  707. // Adjust based on position and margin
  708. } else {
  709. position.top = max( position.top - collisionPosTop, position.top );
  710. }
  711. }
  712. },
  713. flip: {
  714. left: function( position, data ) {
  715. var within = data.within,
  716. withinOffset = within.offset.left + within.scrollLeft,
  717. outerWidth = within.width,
  718. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  719. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  720. overLeft = collisionPosLeft - offsetLeft,
  721. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  722. myOffset = data.my[ 0 ] === "left" ?
  723. -data.elemWidth :
  724. data.my[ 0 ] === "right" ?
  725. data.elemWidth :
  726. 0,
  727. atOffset = data.at[ 0 ] === "left" ?
  728. data.targetWidth :
  729. data.at[ 0 ] === "right" ?
  730. -data.targetWidth :
  731. 0,
  732. offset = -2 * data.offset[ 0 ],
  733. newOverRight,
  734. newOverLeft;
  735. if ( overLeft < 0 ) {
  736. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth -
  737. outerWidth - withinOffset;
  738. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  739. position.left += myOffset + atOffset + offset;
  740. }
  741. } else if ( overRight > 0 ) {
  742. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset +
  743. atOffset + offset - offsetLeft;
  744. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  745. position.left += myOffset + atOffset + offset;
  746. }
  747. }
  748. },
  749. top: function( position, data ) {
  750. var within = data.within,
  751. withinOffset = within.offset.top + within.scrollTop,
  752. outerHeight = within.height,
  753. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  754. collisionPosTop = position.top - data.collisionPosition.marginTop,
  755. overTop = collisionPosTop - offsetTop,
  756. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  757. top = data.my[ 1 ] === "top",
  758. myOffset = top ?
  759. -data.elemHeight :
  760. data.my[ 1 ] === "bottom" ?
  761. data.elemHeight :
  762. 0,
  763. atOffset = data.at[ 1 ] === "top" ?
  764. data.targetHeight :
  765. data.at[ 1 ] === "bottom" ?
  766. -data.targetHeight :
  767. 0,
  768. offset = -2 * data.offset[ 1 ],
  769. newOverTop,
  770. newOverBottom;
  771. if ( overTop < 0 ) {
  772. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight -
  773. outerHeight - withinOffset;
  774. if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {
  775. position.top += myOffset + atOffset + offset;
  776. }
  777. } else if ( overBottom > 0 ) {
  778. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset +
  779. offset - offsetTop;
  780. if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {
  781. position.top += myOffset + atOffset + offset;
  782. }
  783. }
  784. }
  785. },
  786. flipfit: {
  787. left: function() {
  788. $.ui.position.flip.left.apply( this, arguments );
  789. $.ui.position.fit.left.apply( this, arguments );
  790. },
  791. top: function() {
  792. $.ui.position.flip.top.apply( this, arguments );
  793. $.ui.position.fit.top.apply( this, arguments );
  794. }
  795. }
  796. };
  797. } )();
  798. // Source: safe-active-element.js
  799. $.ui.safeActiveElement = function( document ) {
  800. var activeElement;
  801. // Support: IE 9 only
  802. // IE9 throws an "Unspecified error" accessing document.activeElement from an <iframe>
  803. try {
  804. activeElement = document.activeElement;
  805. } catch ( error ) {
  806. activeElement = document.body;
  807. }
  808. // Support: IE 9 - 11 only
  809. // IE may return null instead of an element
  810. // Interestingly, this only seems to occur when NOT in an iframe
  811. if ( !activeElement ) {
  812. activeElement = document.body;
  813. }
  814. // Support: IE 11 only
  815. // IE11 returns a seemingly empty object in some cases when accessing
  816. // document.activeElement from an <iframe>
  817. if ( !activeElement.nodeName ) {
  818. activeElement = document.body;
  819. }
  820. return activeElement;
  821. };
  822. // Source: safe-blur.js
  823. $.ui.safeBlur = function( element ) {
  824. // Support: IE9 - 10 only
  825. // If the <body> is blurred, IE will switch windows, see #9420
  826. if ( element && element.nodeName.toLowerCase() !== "body" ) {
  827. $( element ).trigger( "blur" );
  828. }
  829. };
  830. // Source: scroll-parent.js
  831. /*!
  832. * jQuery UI Scroll Parent 1.12.1
  833. * http://jqueryui.com
  834. *
  835. * Copyright jQuery Foundation and other contributors
  836. * Released under the MIT license.
  837. * http://jquery.org/license
  838. */
  839. //>>label: scrollParent
  840. //>>group: Core
  841. //>>description: Get the closest ancestor element that is scrollable.
  842. //>>docs: http://api.jqueryui.com/scrollParent/
  843. $.fn.scrollParent = function( includeHidden ) {
  844. var position = this.css( "position" ),
  845. excludeStaticParent = position === "absolute",
  846. overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
  847. scrollParent = this.parents().filter( function() {
  848. var parent = $( this );
  849. if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
  850. return false;
  851. }
  852. return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) +
  853. parent.css( "overflow-x" ) );
  854. } ).eq( 0 );
  855. return position === "fixed" || !scrollParent.length ?
  856. $( this[ 0 ].ownerDocument || document ) :
  857. scrollParent;
  858. };
  859. // Source: tabbable.js
  860. /*!
  861. * jQuery UI Tabbable 1.12.1
  862. * http://jqueryui.com
  863. *
  864. * Copyright jQuery Foundation and other contributors
  865. * Released under the MIT license.
  866. * http://jquery.org/license
  867. */
  868. //>>label: :tabbable Selector
  869. //>>group: Core
  870. //>>description: Selects elements which can be tabbed to.
  871. //>>docs: http://api.jqueryui.com/tabbable-selector/
  872. $.extend( $.expr[ ":" ], {
  873. tabbable: function( element ) {
  874. var tabIndex = $.attr( element, "tabindex" ),
  875. hasTabindex = tabIndex != null;
  876. return ( !hasTabindex || tabIndex >= 0 ) && $.ui.focusable( element, hasTabindex );
  877. }
  878. } );
  879. // Source: unique-id.js
  880. /*!
  881. * jQuery UI Unique ID 1.12.1
  882. * http://jqueryui.com
  883. *
  884. * Copyright jQuery Foundation and other contributors
  885. * Released under the MIT license.
  886. * http://jquery.org/license
  887. */
  888. //>>label: uniqueId
  889. //>>group: Core
  890. //>>description: Functions to generate and remove uniqueId's
  891. //>>docs: http://api.jqueryui.com/uniqueId/
  892. $.fn.extend( {
  893. uniqueId: ( function() {
  894. var uuid = 0;
  895. return function() {
  896. return this.each( function() {
  897. if ( !this.id ) {
  898. this.id = "ui-id-" + ( ++uuid );
  899. }
  900. } );
  901. };
  902. } )(),
  903. removeUniqueId: function() {
  904. return this.each( function() {
  905. if ( /^ui-id-\d+$/.test( this.id ) ) {
  906. $( this ).removeAttr( "id" );
  907. }
  908. } );
  909. }
  910. } );
  911. // Source: widget.js
  912. /*!
  913. * jQuery UI Widget 1.12.1
  914. * http://jqueryui.com
  915. *
  916. * Copyright jQuery Foundation and other contributors
  917. * Released under the MIT license.
  918. * http://jquery.org/license
  919. */
  920. //>>label: Widget
  921. //>>group: Core
  922. //>>description: Provides a factory for creating stateful widgets with a common API.
  923. //>>docs: http://api.jqueryui.com/jQuery.widget/
  924. //>>demos: http://jqueryui.com/widget/
  925. var widgetUuid = 0;
  926. var widgetSlice = Array.prototype.slice;
  927. $.cleanData = ( function( orig ) {
  928. return function( elems ) {
  929. var events, elem, i;
  930. for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) {
  931. try {
  932. // Only trigger remove when necessary to save time
  933. events = $._data( elem, "events" );
  934. if ( events && events.remove ) {
  935. $( elem ).triggerHandler( "remove" );
  936. }
  937. // Http://bugs.jquery.com/ticket/8235
  938. } catch ( e ) {}
  939. }
  940. orig( elems );
  941. };
  942. } )( $.cleanData );
  943. $.widget = function( name, base, prototype ) {
  944. var existingConstructor, constructor, basePrototype;
  945. // ProxiedPrototype allows the provided prototype to remain unmodified
  946. // so that it can be used as a mixin for multiple widgets (#8876)
  947. var proxiedPrototype = {};
  948. var namespace = name.split( "." )[ 0 ];
  949. name = name.split( "." )[ 1 ];
  950. var fullName = namespace + "-" + name;
  951. if ( !prototype ) {
  952. prototype = base;
  953. base = $.Widget;
  954. }
  955. if ( $.isArray( prototype ) ) {
  956. prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
  957. }
  958. // Create selector for plugin
  959. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  960. return !!$.data( elem, fullName );
  961. };
  962. $[ namespace ] = $[ namespace ] || {};
  963. existingConstructor = $[ namespace ][ name ];
  964. constructor = $[ namespace ][ name ] = function( options, element ) {
  965. // Allow instantiation without "new" keyword
  966. if ( !this._createWidget ) {
  967. return new constructor( options, element );
  968. }
  969. // Allow instantiation without initializing for simple inheritance
  970. // must use "new" keyword (the code above always passes args)
  971. if ( arguments.length ) {
  972. this._createWidget( options, element );
  973. }
  974. };
  975. // Extend with the existing constructor to carry over any static properties
  976. $.extend( constructor, existingConstructor, {
  977. version: prototype.version,
  978. // Copy the object used to create the prototype in case we need to
  979. // redefine the widget later
  980. _proto: $.extend( {}, prototype ),
  981. // Track widgets that inherit from this widget in case this widget is
  982. // redefined after a widget inherits from it
  983. _childConstructors: []
  984. } );
  985. basePrototype = new base();
  986. // We need to make the options hash a property directly on the new instance
  987. // otherwise we'll modify the options hash on the prototype that we're
  988. // inheriting from
  989. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  990. $.each( prototype, function( prop, value ) {
  991. if ( !$.isFunction( value ) ) {
  992. proxiedPrototype[ prop ] = value;
  993. return;
  994. }
  995. proxiedPrototype[ prop ] = ( function() {
  996. function _super() {
  997. return base.prototype[ prop ].apply( this, arguments );
  998. }
  999. function _superApply( args ) {
  1000. return base.prototype[ prop ].apply( this, args );
  1001. }
  1002. return function() {
  1003. var __super = this._super;
  1004. var __superApply = this._superApply;
  1005. var returnValue;
  1006. this._super = _super;
  1007. this._superApply = _superApply;
  1008. returnValue = value.apply( this, arguments );
  1009. this._super = __super;
  1010. this._superApply = __superApply;
  1011. return returnValue;
  1012. };
  1013. } )();
  1014. } );
  1015. constructor.prototype = $.widget.extend( basePrototype, {
  1016. // TODO: remove support for widgetEventPrefix
  1017. // always use the name + a colon as the prefix, e.g., draggable:start
  1018. // don't prefix for widgets that aren't DOM-based
  1019. widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name
  1020. }, proxiedPrototype, {
  1021. constructor: constructor,
  1022. namespace: namespace,
  1023. widgetName: name,
  1024. widgetFullName: fullName
  1025. } );
  1026. // If this widget is being redefined then we need to find all widgets that
  1027. // are inheriting from it and redefine all of them so that they inherit from
  1028. // the new version of this widget. We're essentially trying to replace one
  1029. // level in the prototype chain.
  1030. if ( existingConstructor ) {
  1031. $.each( existingConstructor._childConstructors, function( i, child ) {
  1032. var childPrototype = child.prototype;
  1033. // Redefine the child widget using the same prototype that was
  1034. // originally used, but inherit from the new version of the base
  1035. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor,
  1036. child._proto );
  1037. } );
  1038. // Remove the list of existing child constructors from the old constructor
  1039. // so the old child constructors can be garbage collected
  1040. delete existingConstructor._childConstructors;
  1041. } else {
  1042. base._childConstructors.push( constructor );
  1043. }
  1044. $.widget.bridge( name, constructor );
  1045. return constructor;
  1046. };
  1047. $.widget.extend = function( target ) {
  1048. var input = widgetSlice.call( arguments, 1 );
  1049. var inputIndex = 0;
  1050. var inputLength = input.length;
  1051. var key;
  1052. var value;
  1053. for ( ; inputIndex < inputLength; inputIndex++ ) {
  1054. for ( key in input[ inputIndex ] ) {
  1055. value = input[ inputIndex ][ key ];
  1056. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  1057. // Clone objects
  1058. if ( $.isPlainObject( value ) ) {
  1059. target[ key ] = $.isPlainObject( target[ key ] ) ?
  1060. $.widget.extend( {}, target[ key ], value ) :
  1061. // Don't extend strings, arrays, etc. with objects
  1062. $.widget.extend( {}, value );
  1063. // Copy everything else by reference
  1064. } else {
  1065. target[ key ] = value;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. return target;
  1071. };
  1072. $.widget.bridge = function( name, object ) {
  1073. var fullName = object.prototype.widgetFullName || name;
  1074. $.fn[ name ] = function( options ) {
  1075. var isMethodCall = typeof options === "string";
  1076. var args = widgetSlice.call( arguments, 1 );
  1077. var returnValue = this;
  1078. if ( isMethodCall ) {
  1079. // If this is an empty collection, we need to have the instance method
  1080. // return undefined instead of the jQuery instance
  1081. if ( !this.length && options === "instance" ) {
  1082. returnValue = undefined;
  1083. } else {
  1084. this.each( function() {
  1085. var methodValue;
  1086. var instance = $.data( this, fullName );
  1087. if ( options === "instance" ) {
  1088. returnValue = instance;
  1089. return false;
  1090. }
  1091. if ( !instance ) {
  1092. return $.error( "cannot call methods on " + name +
  1093. " prior to initialization; " +
  1094. "attempted to call method '" + options + "'" );
  1095. }
  1096. if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
  1097. return $.error( "no such method '" + options + "' for " + name +
  1098. " widget instance" );
  1099. }
  1100. methodValue = instance[ options ].apply( instance, args );
  1101. if ( methodValue !== instance && methodValue !== undefined ) {
  1102. returnValue = methodValue && methodValue.jquery ?
  1103. returnValue.pushStack( methodValue.get() ) :
  1104. methodValue;
  1105. return false;
  1106. }
  1107. } );
  1108. }
  1109. } else {
  1110. // Allow multiple hashes to be passed on init
  1111. if ( args.length ) {
  1112. options = $.widget.extend.apply( null, [ options ].concat( args ) );
  1113. }
  1114. this.each( function() {
  1115. var instance = $.data( this, fullName );
  1116. if ( instance ) {
  1117. instance.option( options || {} );
  1118. if ( instance._init ) {
  1119. instance._init();
  1120. }
  1121. } else {
  1122. $.data( this, fullName, new object( options, this ) );
  1123. }
  1124. } );
  1125. }
  1126. return returnValue;
  1127. };
  1128. };
  1129. $.Widget = function( /* options, element */ ) {};
  1130. $.Widget._childConstructors = [];
  1131. $.Widget.prototype = {
  1132. widgetName: "widget",
  1133. widgetEventPrefix: "",
  1134. defaultElement: "<div>",
  1135. options: {
  1136. classes: {},
  1137. disabled: false,
  1138. // Callbacks
  1139. create: null
  1140. },
  1141. _createWidget: function( options, element ) {
  1142. element = $( element || this.defaultElement || this )[ 0 ];
  1143. this.element = $( element );
  1144. this.uuid = widgetUuid++;
  1145. this.eventNamespace = "." + this.widgetName + this.uuid;
  1146. this.bindings = $();
  1147. this.hoverable = $();
  1148. this.focusable = $();
  1149. this.classesElementLookup = {};
  1150. if ( element !== this ) {
  1151. $.data( element, this.widgetFullName, this );
  1152. this._on( true, this.element, {
  1153. remove: function( event ) {
  1154. if ( event.target === element ) {
  1155. this.destroy();
  1156. }
  1157. }
  1158. } );
  1159. this.document = $( element.style ?
  1160. // Element within the document
  1161. element.ownerDocument :
  1162. // Element is window or document
  1163. element.document || element );
  1164. this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
  1165. }
  1166. this.options = $.widget.extend( {},
  1167. this.options,
  1168. this._getCreateOptions(),
  1169. options );
  1170. this._create();
  1171. if ( this.options.disabled ) {
  1172. this._setOptionDisabled( this.options.disabled );
  1173. }
  1174. this._trigger( "create", null, this._getCreateEventData() );
  1175. this._init();
  1176. },
  1177. _getCreateOptions: function() {
  1178. return {};
  1179. },
  1180. _getCreateEventData: $.noop,
  1181. _create: $.noop,
  1182. _init: $.noop,
  1183. destroy: function() {
  1184. var that = this;
  1185. this._destroy();
  1186. $.each( this.classesElementLookup, function( key, value ) {
  1187. that._removeClass( value, key );
  1188. } );
  1189. // We can probably remove the unbind calls in 2.0
  1190. // all event bindings should go through this._on()
  1191. this.element
  1192. .off( this.eventNamespace )
  1193. .removeData( this.widgetFullName );
  1194. this.widget()
  1195. .off( this.eventNamespace )
  1196. .removeAttr( "aria-disabled" );
  1197. // Clean up events and states
  1198. this.bindings.off( this.eventNamespace );
  1199. },
  1200. _destroy: $.noop,
  1201. widget: function() {
  1202. return this.element;
  1203. },
  1204. option: function( key, value ) {
  1205. var options = key;
  1206. var parts;
  1207. var curOption;
  1208. var i;
  1209. if ( arguments.length === 0 ) {
  1210. // Don't return a reference to the internal hash
  1211. return $.widget.extend( {}, this.options );
  1212. }
  1213. if ( typeof key === "string" ) {
  1214. // Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  1215. options = {};
  1216. parts = key.split( "." );
  1217. key = parts.shift();
  1218. if ( parts.length ) {
  1219. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  1220. for ( i = 0; i < parts.length - 1; i++ ) {
  1221. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  1222. curOption = curOption[ parts[ i ] ];
  1223. }
  1224. key = parts.pop();
  1225. if ( arguments.length === 1 ) {
  1226. return curOption[ key ] === undefined ? null : curOption[ key ];
  1227. }
  1228. curOption[ key ] = value;
  1229. } else {
  1230. if ( arguments.length === 1 ) {
  1231. return this.options[ key ] === undefined ? null : this.options[ key ];
  1232. }
  1233. options[ key ] = value;
  1234. }
  1235. }
  1236. this._setOptions( options );
  1237. return this;
  1238. },
  1239. _setOptions: function( options ) {
  1240. var key;
  1241. for ( key in options ) {
  1242. this._setOption( key, options[ key ] );
  1243. }
  1244. return this;
  1245. },
  1246. _setOption: function( key, value ) {
  1247. if ( key === "classes" ) {
  1248. this._setOptionClasses( value );
  1249. }
  1250. this.options[ key ] = value;
  1251. if ( key === "disabled" ) {
  1252. this._setOptionDisabled( value );
  1253. }
  1254. return this;
  1255. },
  1256. _setOptionClasses: function( value ) {
  1257. var classKey, elements, currentElements;
  1258. for ( classKey in value ) {
  1259. currentElements = this.classesElementLookup[ classKey ];
  1260. if ( value[ classKey ] === this.options.classes[ classKey ] ||
  1261. !currentElements ||
  1262. !currentElements.length ) {
  1263. continue;
  1264. }
  1265. // We are doing this to create a new jQuery object because the _removeClass() call
  1266. // on the next line is going to destroy the reference to the current elements being
  1267. // tracked. We need to save a copy of this collection so that we can add the new classes
  1268. // below.
  1269. elements = $( currentElements.get() );
  1270. this._removeClass( currentElements, classKey );
  1271. // We don't use _addClass() here, because that uses this.options.classes
  1272. // for generating the string of classes. We want to use the value passed in from
  1273. // _setOption(), this is the new value of the classes option which was passed to
  1274. // _setOption(). We pass this value directly to _classes().
  1275. elements.addClass( this._classes( {
  1276. element: elements,
  1277. keys: classKey,
  1278. classes: value,
  1279. add: true
  1280. } ) );
  1281. }
  1282. },
  1283. _setOptionDisabled: function( value ) {
  1284. this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value );
  1285. // If the widget is becoming disabled, then nothing is interactive
  1286. if ( value ) {
  1287. this._removeClass( this.hoverable, null, "ui-state-hover" );
  1288. this._removeClass( this.focusable, null, "ui-state-focus" );
  1289. }
  1290. },
  1291. enable: function() {
  1292. return this._setOptions( { disabled: false } );
  1293. },
  1294. disable: function() {
  1295. return this._setOptions( { disabled: true } );
  1296. },
  1297. _classes: function( options ) {
  1298. var full = [];
  1299. var that = this;
  1300. options = $.extend( {
  1301. element: this.element,
  1302. classes: this.options.classes || {}
  1303. }, options );
  1304. function processClassString( classes, checkOption ) {
  1305. var current, i;
  1306. for ( i = 0; i < classes.length; i++ ) {
  1307. current = that.classesElementLookup[ classes[ i ] ] || $();
  1308. if ( options.add ) {
  1309. current = $( $.unique( current.get().concat( options.element.get() ) ) );
  1310. } else {
  1311. current = $( current.not( options.element ).get() );
  1312. }
  1313. that.classesElementLookup[ classes[ i ] ] = current;
  1314. full.push( classes[ i ] );
  1315. if ( checkOption && options.classes[ classes[ i ] ] ) {
  1316. full.push( options.classes[ classes[ i ] ] );
  1317. }
  1318. }
  1319. }
  1320. this._on( options.element, {
  1321. "remove": "_untrackClassesElement"
  1322. } );
  1323. if ( options.keys ) {
  1324. processClassString( options.keys.match( /\S+/g ) || [], true );
  1325. }
  1326. if ( options.extra ) {
  1327. processClassString( options.extra.match( /\S+/g ) || [] );
  1328. }
  1329. return full.join( " " );
  1330. },
  1331. _untrackClassesElement: function( event ) {
  1332. var that = this;
  1333. $.each( that.classesElementLookup, function( key, value ) {
  1334. if ( $.inArray( event.target, value ) !== -1 ) {
  1335. that.classesElementLookup[ key ] = $( value.not( event.target ).get() );
  1336. }
  1337. } );
  1338. },
  1339. _removeClass: function( element, keys, extra ) {
  1340. return this._toggleClass( element, keys, extra, false );
  1341. },
  1342. _addClass: function( element, keys, extra ) {
  1343. return this._toggleClass( element, keys, extra, true );
  1344. },
  1345. _toggleClass: function( element, keys, extra, add ) {
  1346. add = ( typeof add === "boolean" ) ? add : extra;
  1347. var shift = ( typeof element === "string" || element === null ),
  1348. options = {
  1349. extra: shift ? keys : extra,
  1350. keys: shift ? element : keys,
  1351. element: shift ? this.element : element,
  1352. add: add
  1353. };
  1354. options.element.toggleClass( this._classes( options ), add );
  1355. return this;
  1356. },
  1357. _on: function( suppressDisabledCheck, element, handlers ) {
  1358. var delegateElement;
  1359. var instance = this;
  1360. // No suppressDisabledCheck flag, shuffle arguments
  1361. if ( typeof suppressDisabledCheck !== "boolean" ) {
  1362. handlers = element;
  1363. element = suppressDisabledCheck;
  1364. suppressDisabledCheck = false;
  1365. }
  1366. // No element argument, shuffle and use this.element
  1367. if ( !handlers ) {
  1368. handlers = element;
  1369. element = this.element;
  1370. delegateElement = this.widget();
  1371. } else {
  1372. element = delegateElement = $( element );
  1373. this.bindings = this.bindings.add( element );
  1374. }
  1375. $.each( handlers, function( event, handler ) {
  1376. function handlerProxy() {
  1377. // Allow widgets to customize the disabled handling
  1378. // - disabled as an array instead of boolean
  1379. // - disabled class as method for disabling individual parts
  1380. if ( !suppressDisabledCheck &&
  1381. ( instance.options.disabled === true ||
  1382. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  1383. return;
  1384. }
  1385. return ( typeof handler === "string" ? instance[ handler ] : handler )
  1386. .apply( instance, arguments );
  1387. }
  1388. // Copy the guid so direct unbinding works
  1389. if ( typeof handler !== "string" ) {
  1390. handlerProxy.guid = handler.guid =
  1391. handler.guid || handlerProxy.guid || $.guid++;
  1392. }
  1393. var match = event.match( /^([\w:-]*)\s*(.*)$/ );
  1394. var eventName = match[ 1 ] + instance.eventNamespace;
  1395. var selector = match[ 2 ];
  1396. if ( selector ) {
  1397. delegateElement.on( eventName, selector, handlerProxy );
  1398. } else {
  1399. element.on( eventName, handlerProxy );
  1400. }
  1401. } );
  1402. },
  1403. _off: function( element, eventName ) {
  1404. eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) +
  1405. this.eventNamespace;
  1406. element.off( eventName ).off( eventName );
  1407. // Clear the stack to avoid memory leaks (#10056)
  1408. this.bindings = $( this.bindings.not( element ).get() );
  1409. this.focusable = $( this.focusable.not( element ).get() );
  1410. this.hoverable = $( this.hoverable.not( element ).get() );
  1411. },
  1412. _delay: function( handler, delay ) {
  1413. function handlerProxy() {
  1414. return ( typeof handler === "string" ? instance[ handler ] : handler )
  1415. .apply( instance, arguments );
  1416. }
  1417. var instance = this;
  1418. return setTimeout( handlerProxy, delay || 0 );
  1419. },
  1420. _hoverable: function( element ) {
  1421. this.hoverable = this.hoverable.add( element );
  1422. this._on( element, {
  1423. mouseenter: function( event ) {
  1424. this._addClass( $( event.currentTarget ), null, "ui-state-hover" );
  1425. },
  1426. mouseleave: function( event ) {
  1427. this._removeClass( $( event.currentTarget ), null, "ui-state-hover" );
  1428. }
  1429. } );
  1430. },
  1431. _focusable: function( element ) {
  1432. this.focusable = this.focusable.add( element );
  1433. this._on( element, {
  1434. focusin: function( event ) {
  1435. this._addClass( $( event.currentTarget ), null, "ui-state-focus" );
  1436. },
  1437. focusout: function( event ) {
  1438. this._removeClass( $( event.currentTarget ), null, "ui-state-focus" );
  1439. }
  1440. } );
  1441. },
  1442. _trigger: function( type, event, data ) {
  1443. var prop, orig;
  1444. var callback = this.options[ type ];
  1445. data = data || {};
  1446. event = $.Event( event );
  1447. event.type = ( type === this.widgetEventPrefix ?
  1448. type :
  1449. this.widgetEventPrefix + type ).toLowerCase();
  1450. // The original event may come from any element
  1451. // so we need to reset the target on the new event
  1452. event.target = this.element[ 0 ];
  1453. // Copy original event properties over to the new event
  1454. orig = event.originalEvent;
  1455. if ( orig ) {
  1456. for ( prop in orig ) {
  1457. if ( !( prop in event ) ) {
  1458. event[ prop ] = orig[ prop ];
  1459. }
  1460. }
  1461. }
  1462. this.element.trigger( event, data );
  1463. return !( $.isFunction( callback ) &&
  1464. callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false ||
  1465. event.isDefaultPrevented() );
  1466. }
  1467. };
  1468. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  1469. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  1470. if ( typeof options === "string" ) {
  1471. options = { effect: options };
  1472. }
  1473. var hasOptions;
  1474. var effectName = !options ?
  1475. method :
  1476. options === true || typeof options === "number" ?
  1477. defaultEffect :
  1478. options.effect || defaultEffect;
  1479. options = options || {};
  1480. if ( typeof options === "number" ) {
  1481. options = { duration: options };
  1482. }
  1483. hasOptions = !$.isEmptyObject( options );
  1484. options.complete = callback;
  1485. if ( options.delay ) {
  1486. element.delay( options.delay );
  1487. }
  1488. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  1489. element[ method ]( options );
  1490. } else if ( effectName !== method && element[ effectName ] ) {
  1491. element[ effectName ]( options.duration, options.easing, callback );
  1492. } else {
  1493. element.queue( function( next ) {
  1494. $( this )[ method ]();
  1495. if ( callback ) {
  1496. callback.call( element[ 0 ] );
  1497. }
  1498. next();
  1499. } );
  1500. }
  1501. };
  1502. } );
  1503. } ) );