Mirror of Quill
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10414 lines
301 KiB

  1. /*! jQuery UI - v1.11.4 - 2015-05-10
  2. * http://jqueryui.com
  3. * Includes: core.js, widget.js, mouse.js, position.js, sortable.js, accordion.js, autocomplete.js, button.js, datepicker.js, menu.js, progressbar.js, selectmenu.js, slider.js, spinner.js, tabs.js, tooltip.js
  4. * Copyright 2015 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. /*!
  15. * jQuery UI Core 1.11.4
  16. * http://jqueryui.com
  17. *
  18. * Copyright jQuery Foundation and other contributors
  19. * Released under the MIT license.
  20. * http://jquery.org/license
  21. *
  22. * http://api.jqueryui.com/category/ui-core/
  23. */
  24. // $.ui might exist from components with no dependencies, e.g., $.ui.position
  25. $.ui = $.ui || {};
  26. $.extend( $.ui, {
  27. version: "1.11.4",
  28. keyCode: {
  29. BACKSPACE: 8,
  30. COMMA: 188,
  31. DELETE: 46,
  32. DOWN: 40,
  33. END: 35,
  34. ENTER: 13,
  35. ESCAPE: 27,
  36. HOME: 36,
  37. LEFT: 37,
  38. PAGE_DOWN: 34,
  39. PAGE_UP: 33,
  40. PERIOD: 190,
  41. RIGHT: 39,
  42. SPACE: 32,
  43. TAB: 9,
  44. UP: 38
  45. }
  46. });
  47. // plugins
  48. $.fn.extend({
  49. scrollParent: function( includeHidden ) {
  50. var position = this.css( "position" ),
  51. excludeStaticParent = position === "absolute",
  52. overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/,
  53. scrollParent = this.parents().filter( function() {
  54. var parent = $( this );
  55. if ( excludeStaticParent && parent.css( "position" ) === "static" ) {
  56. return false;
  57. }
  58. return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) );
  59. }).eq( 0 );
  60. return position === "fixed" || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent;
  61. },
  62. uniqueId: (function() {
  63. var uuid = 0;
  64. return function() {
  65. return this.each(function() {
  66. if ( !this.id ) {
  67. this.id = "ui-id-" + ( ++uuid );
  68. }
  69. });
  70. };
  71. })(),
  72. removeUniqueId: function() {
  73. return this.each(function() {
  74. if ( /^ui-id-\d+$/.test( this.id ) ) {
  75. $( this ).removeAttr( "id" );
  76. }
  77. });
  78. }
  79. });
  80. // selectors
  81. function focusable( element, isTabIndexNotNaN ) {
  82. var map, mapName, img,
  83. nodeName = element.nodeName.toLowerCase();
  84. if ( "area" === nodeName ) {
  85. map = element.parentNode;
  86. mapName = map.name;
  87. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  88. return false;
  89. }
  90. img = $( "img[usemap='#" + mapName + "']" )[ 0 ];
  91. return !!img && visible( img );
  92. }
  93. return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ?
  94. !element.disabled :
  95. "a" === nodeName ?
  96. element.href || isTabIndexNotNaN :
  97. isTabIndexNotNaN) &&
  98. // the element and all of its ancestors must be visible
  99. visible( element );
  100. }
  101. function visible( element ) {
  102. return $.expr.filters.visible( element ) &&
  103. !$( element ).parents().addBack().filter(function() {
  104. return $.css( this, "visibility" ) === "hidden";
  105. }).length;
  106. }
  107. $.extend( $.expr[ ":" ], {
  108. data: $.expr.createPseudo ?
  109. $.expr.createPseudo(function( dataName ) {
  110. return function( elem ) {
  111. return !!$.data( elem, dataName );
  112. };
  113. }) :
  114. // support: jQuery <1.8
  115. function( elem, i, match ) {
  116. return !!$.data( elem, match[ 3 ] );
  117. },
  118. focusable: function( element ) {
  119. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  120. },
  121. tabbable: function( element ) {
  122. var tabIndex = $.attr( element, "tabindex" ),
  123. isTabIndexNaN = isNaN( tabIndex );
  124. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  125. }
  126. });
  127. // support: jQuery <1.8
  128. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  129. $.each( [ "Width", "Height" ], function( i, name ) {
  130. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  131. type = name.toLowerCase(),
  132. orig = {
  133. innerWidth: $.fn.innerWidth,
  134. innerHeight: $.fn.innerHeight,
  135. outerWidth: $.fn.outerWidth,
  136. outerHeight: $.fn.outerHeight
  137. };
  138. function reduce( elem, size, border, margin ) {
  139. $.each( side, function() {
  140. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  141. if ( border ) {
  142. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  143. }
  144. if ( margin ) {
  145. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  146. }
  147. });
  148. return size;
  149. }
  150. $.fn[ "inner" + name ] = function( size ) {
  151. if ( size === undefined ) {
  152. return orig[ "inner" + name ].call( this );
  153. }
  154. return this.each(function() {
  155. $( this ).css( type, reduce( this, size ) + "px" );
  156. });
  157. };
  158. $.fn[ "outer" + name] = function( size, margin ) {
  159. if ( typeof size !== "number" ) {
  160. return orig[ "outer" + name ].call( this, size );
  161. }
  162. return this.each(function() {
  163. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  164. });
  165. };
  166. });
  167. }
  168. // support: jQuery <1.8
  169. if ( !$.fn.addBack ) {
  170. $.fn.addBack = function( selector ) {
  171. return this.add( selector == null ?
  172. this.prevObject : this.prevObject.filter( selector )
  173. );
  174. };
  175. }
  176. // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
  177. if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
  178. $.fn.removeData = (function( removeData ) {
  179. return function( key ) {
  180. if ( arguments.length ) {
  181. return removeData.call( this, $.camelCase( key ) );
  182. } else {
  183. return removeData.call( this );
  184. }
  185. };
  186. })( $.fn.removeData );
  187. }
  188. // deprecated
  189. $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
  190. $.fn.extend({
  191. focus: (function( orig ) {
  192. return function( delay, fn ) {
  193. return typeof delay === "number" ?
  194. this.each(function() {
  195. var elem = this;
  196. setTimeout(function() {
  197. $( elem ).focus();
  198. if ( fn ) {
  199. fn.call( elem );
  200. }
  201. }, delay );
  202. }) :
  203. orig.apply( this, arguments );
  204. };
  205. })( $.fn.focus ),
  206. disableSelection: (function() {
  207. var eventType = "onselectstart" in document.createElement( "div" ) ?
  208. "selectstart" :
  209. "mousedown";
  210. return function() {
  211. return this.bind( eventType + ".ui-disableSelection", function( event ) {
  212. event.preventDefault();
  213. });
  214. };
  215. })(),
  216. enableSelection: function() {
  217. return this.unbind( ".ui-disableSelection" );
  218. },
  219. zIndex: function( zIndex ) {
  220. if ( zIndex !== undefined ) {
  221. return this.css( "zIndex", zIndex );
  222. }
  223. if ( this.length ) {
  224. var elem = $( this[ 0 ] ), position, value;
  225. while ( elem.length && elem[ 0 ] !== document ) {
  226. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  227. // This makes behavior of this function consistent across browsers
  228. // WebKit always returns auto if the element is positioned
  229. position = elem.css( "position" );
  230. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  231. // IE returns 0 when zIndex is not specified
  232. // other browsers return a string
  233. // we ignore the case of nested elements with an explicit value of 0
  234. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  235. value = parseInt( elem.css( "zIndex" ), 10 );
  236. if ( !isNaN( value ) && value !== 0 ) {
  237. return value;
  238. }
  239. }
  240. elem = elem.parent();
  241. }
  242. }
  243. return 0;
  244. }
  245. });
  246. // $.ui.plugin is deprecated. Use $.widget() extensions instead.
  247. $.ui.plugin = {
  248. add: function( module, option, set ) {
  249. var i,
  250. proto = $.ui[ module ].prototype;
  251. for ( i in set ) {
  252. proto.plugins[ i ] = proto.plugins[ i ] || [];
  253. proto.plugins[ i ].push( [ option, set[ i ] ] );
  254. }
  255. },
  256. call: function( instance, name, args, allowDisconnected ) {
  257. var i,
  258. set = instance.plugins[ name ];
  259. if ( !set ) {
  260. return;
  261. }
  262. if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) ) {
  263. return;
  264. }
  265. for ( i = 0; i < set.length; i++ ) {
  266. if ( instance.options[ set[ i ][ 0 ] ] ) {
  267. set[ i ][ 1 ].apply( instance.element, args );
  268. }
  269. }
  270. }
  271. };
  272. /*!
  273. * jQuery UI Widget 1.11.4
  274. * http://jqueryui.com
  275. *
  276. * Copyright jQuery Foundation and other contributors
  277. * Released under the MIT license.
  278. * http://jquery.org/license
  279. *
  280. * http://api.jqueryui.com/jQuery.widget/
  281. */
  282. var widget_uuid = 0,
  283. widget_slice = Array.prototype.slice;
  284. $.cleanData = (function( orig ) {
  285. return function( elems ) {
  286. var events, elem, i;
  287. for ( i = 0; (elem = elems[i]) != null; i++ ) {
  288. try {
  289. // Only trigger remove when necessary to save time
  290. events = $._data( elem, "events" );
  291. if ( events && events.remove ) {
  292. $( elem ).triggerHandler( "remove" );
  293. }
  294. // http://bugs.jquery.com/ticket/8235
  295. } catch ( e ) {}
  296. }
  297. orig( elems );
  298. };
  299. })( $.cleanData );
  300. $.widget = function( name, base, prototype ) {
  301. var fullName, existingConstructor, constructor, basePrototype,
  302. // proxiedPrototype allows the provided prototype to remain unmodified
  303. // so that it can be used as a mixin for multiple widgets (#8876)
  304. proxiedPrototype = {},
  305. namespace = name.split( "." )[ 0 ];
  306. name = name.split( "." )[ 1 ];
  307. fullName = namespace + "-" + name;
  308. if ( !prototype ) {
  309. prototype = base;
  310. base = $.Widget;
  311. }
  312. // create selector for plugin
  313. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  314. return !!$.data( elem, fullName );
  315. };
  316. $[ namespace ] = $[ namespace ] || {};
  317. existingConstructor = $[ namespace ][ name ];
  318. constructor = $[ namespace ][ name ] = function( options, element ) {
  319. // allow instantiation without "new" keyword
  320. if ( !this._createWidget ) {
  321. return new constructor( options, element );
  322. }
  323. // allow instantiation without initializing for simple inheritance
  324. // must use "new" keyword (the code above always passes args)
  325. if ( arguments.length ) {
  326. this._createWidget( options, element );
  327. }
  328. };
  329. // extend with the existing constructor to carry over any static properties
  330. $.extend( constructor, existingConstructor, {
  331. version: prototype.version,
  332. // copy the object used to create the prototype in case we need to
  333. // redefine the widget later
  334. _proto: $.extend( {}, prototype ),
  335. // track widgets that inherit from this widget in case this widget is
  336. // redefined after a widget inherits from it
  337. _childConstructors: []
  338. });
  339. basePrototype = new base();
  340. // we need to make the options hash a property directly on the new instance
  341. // otherwise we'll modify the options hash on the prototype that we're
  342. // inheriting from
  343. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  344. $.each( prototype, function( prop, value ) {
  345. if ( !$.isFunction( value ) ) {
  346. proxiedPrototype[ prop ] = value;
  347. return;
  348. }
  349. proxiedPrototype[ prop ] = (function() {
  350. var _super = function() {
  351. return base.prototype[ prop ].apply( this, arguments );
  352. },
  353. _superApply = function( args ) {
  354. return base.prototype[ prop ].apply( this, args );
  355. };
  356. return function() {
  357. var __super = this._super,
  358. __superApply = this._superApply,
  359. returnValue;
  360. this._super = _super;
  361. this._superApply = _superApply;
  362. returnValue = value.apply( this, arguments );
  363. this._super = __super;
  364. this._superApply = __superApply;
  365. return returnValue;
  366. };
  367. })();
  368. });
  369. constructor.prototype = $.widget.extend( basePrototype, {
  370. // TODO: remove support for widgetEventPrefix
  371. // always use the name + a colon as the prefix, e.g., draggable:start
  372. // don't prefix for widgets that aren't DOM-based
  373. widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name
  374. }, proxiedPrototype, {
  375. constructor: constructor,
  376. namespace: namespace,
  377. widgetName: name,
  378. widgetFullName: fullName
  379. });
  380. // If this widget is being redefined then we need to find all widgets that
  381. // are inheriting from it and redefine all of them so that they inherit from
  382. // the new version of this widget. We're essentially trying to replace one
  383. // level in the prototype chain.
  384. if ( existingConstructor ) {
  385. $.each( existingConstructor._childConstructors, function( i, child ) {
  386. var childPrototype = child.prototype;
  387. // redefine the child widget using the same prototype that was
  388. // originally used, but inherit from the new version of the base
  389. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
  390. });
  391. // remove the list of existing child constructors from the old constructor
  392. // so the old child constructors can be garbage collected
  393. delete existingConstructor._childConstructors;
  394. } else {
  395. base._childConstructors.push( constructor );
  396. }
  397. $.widget.bridge( name, constructor );
  398. return constructor;
  399. };
  400. $.widget.extend = function( target ) {
  401. var input = widget_slice.call( arguments, 1 ),
  402. inputIndex = 0,
  403. inputLength = input.length,
  404. key,
  405. value;
  406. for ( ; inputIndex < inputLength; inputIndex++ ) {
  407. for ( key in input[ inputIndex ] ) {
  408. value = input[ inputIndex ][ key ];
  409. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  410. // Clone objects
  411. if ( $.isPlainObject( value ) ) {
  412. target[ key ] = $.isPlainObject( target[ key ] ) ?
  413. $.widget.extend( {}, target[ key ], value ) :
  414. // Don't extend strings, arrays, etc. with objects
  415. $.widget.extend( {}, value );
  416. // Copy everything else by reference
  417. } else {
  418. target[ key ] = value;
  419. }
  420. }
  421. }
  422. }
  423. return target;
  424. };
  425. $.widget.bridge = function( name, object ) {
  426. var fullName = object.prototype.widgetFullName || name;
  427. $.fn[ name ] = function( options ) {
  428. var isMethodCall = typeof options === "string",
  429. args = widget_slice.call( arguments, 1 ),
  430. returnValue = this;
  431. if ( isMethodCall ) {
  432. this.each(function() {
  433. var methodValue,
  434. instance = $.data( this, fullName );
  435. if ( options === "instance" ) {
  436. returnValue = instance;
  437. return false;
  438. }
  439. if ( !instance ) {
  440. return $.error( "cannot call methods on " + name + " prior to initialization; " +
  441. "attempted to call method '" + options + "'" );
  442. }
  443. if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
  444. return $.error( "no such method '" + options + "' for " + name + " widget instance" );
  445. }
  446. methodValue = instance[ options ].apply( instance, args );
  447. if ( methodValue !== instance && methodValue !== undefined ) {
  448. returnValue = methodValue && methodValue.jquery ?
  449. returnValue.pushStack( methodValue.get() ) :
  450. methodValue;
  451. return false;
  452. }
  453. });
  454. } else {
  455. // Allow multiple hashes to be passed on init
  456. if ( args.length ) {
  457. options = $.widget.extend.apply( null, [ options ].concat(args) );
  458. }
  459. this.each(function() {
  460. var instance = $.data( this, fullName );
  461. if ( instance ) {
  462. instance.option( options || {} );
  463. if ( instance._init ) {
  464. instance._init();
  465. }
  466. } else {
  467. $.data( this, fullName, new object( options, this ) );
  468. }
  469. });
  470. }
  471. return returnValue;
  472. };
  473. };
  474. $.Widget = function( /* options, element */ ) {};
  475. $.Widget._childConstructors = [];
  476. $.Widget.prototype = {
  477. widgetName: "widget",
  478. widgetEventPrefix: "",
  479. defaultElement: "<div>",
  480. options: {
  481. disabled: false,
  482. // callbacks
  483. create: null
  484. },
  485. _createWidget: function( options, element ) {
  486. element = $( element || this.defaultElement || this )[ 0 ];
  487. this.element = $( element );
  488. this.uuid = widget_uuid++;
  489. this.eventNamespace = "." + this.widgetName + this.uuid;
  490. this.bindings = $();
  491. this.hoverable = $();
  492. this.focusable = $();
  493. if ( element !== this ) {
  494. $.data( element, this.widgetFullName, this );
  495. this._on( true, this.element, {
  496. remove: function( event ) {
  497. if ( event.target === element ) {
  498. this.destroy();
  499. }
  500. }
  501. });
  502. this.document = $( element.style ?
  503. // element within the document
  504. element.ownerDocument :
  505. // element is window or document
  506. element.document || element );
  507. this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
  508. }
  509. this.options = $.widget.extend( {},
  510. this.options,
  511. this._getCreateOptions(),
  512. options );
  513. this._create();
  514. this._trigger( "create", null, this._getCreateEventData() );
  515. this._init();
  516. },
  517. _getCreateOptions: $.noop,
  518. _getCreateEventData: $.noop,
  519. _create: $.noop,
  520. _init: $.noop,
  521. destroy: function() {
  522. this._destroy();
  523. // we can probably remove the unbind calls in 2.0
  524. // all event bindings should go through this._on()
  525. this.element
  526. .unbind( this.eventNamespace )
  527. .removeData( this.widgetFullName )
  528. // support: jquery <1.6.3
  529. // http://bugs.jquery.com/ticket/9413
  530. .removeData( $.camelCase( this.widgetFullName ) );
  531. this.widget()
  532. .unbind( this.eventNamespace )
  533. .removeAttr( "aria-disabled" )
  534. .removeClass(
  535. this.widgetFullName + "-disabled " +
  536. "ui-state-disabled" );
  537. // clean up events and states
  538. this.bindings.unbind( this.eventNamespace );
  539. this.hoverable.removeClass( "ui-state-hover" );
  540. this.focusable.removeClass( "ui-state-focus" );
  541. },
  542. _destroy: $.noop,
  543. widget: function() {
  544. return this.element;
  545. },
  546. option: function( key, value ) {
  547. var options = key,
  548. parts,
  549. curOption,
  550. i;
  551. if ( arguments.length === 0 ) {
  552. // don't return a reference to the internal hash
  553. return $.widget.extend( {}, this.options );
  554. }
  555. if ( typeof key === "string" ) {
  556. // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  557. options = {};
  558. parts = key.split( "." );
  559. key = parts.shift();
  560. if ( parts.length ) {
  561. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  562. for ( i = 0; i < parts.length - 1; i++ ) {
  563. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  564. curOption = curOption[ parts[ i ] ];
  565. }
  566. key = parts.pop();
  567. if ( arguments.length === 1 ) {
  568. return curOption[ key ] === undefined ? null : curOption[ key ];
  569. }
  570. curOption[ key ] = value;
  571. } else {
  572. if ( arguments.length === 1 ) {
  573. return this.options[ key ] === undefined ? null : this.options[ key ];
  574. }
  575. options[ key ] = value;
  576. }
  577. }
  578. this._setOptions( options );
  579. return this;
  580. },
  581. _setOptions: function( options ) {
  582. var key;
  583. for ( key in options ) {
  584. this._setOption( key, options[ key ] );
  585. }
  586. return this;
  587. },
  588. _setOption: function( key, value ) {
  589. this.options[ key ] = value;
  590. if ( key === "disabled" ) {
  591. this.widget()
  592. .toggleClass( this.widgetFullName + "-disabled", !!value );
  593. // If the widget is becoming disabled, then nothing is interactive
  594. if ( value ) {
  595. this.hoverable.removeClass( "ui-state-hover" );
  596. this.focusable.removeClass( "ui-state-focus" );
  597. }
  598. }
  599. return this;
  600. },
  601. enable: function() {
  602. return this._setOptions({ disabled: false });
  603. },
  604. disable: function() {
  605. return this._setOptions({ disabled: true });
  606. },
  607. _on: function( suppressDisabledCheck, element, handlers ) {
  608. var delegateElement,
  609. instance = this;
  610. // no suppressDisabledCheck flag, shuffle arguments
  611. if ( typeof suppressDisabledCheck !== "boolean" ) {
  612. handlers = element;
  613. element = suppressDisabledCheck;
  614. suppressDisabledCheck = false;
  615. }
  616. // no element argument, shuffle and use this.element
  617. if ( !handlers ) {
  618. handlers = element;
  619. element = this.element;
  620. delegateElement = this.widget();
  621. } else {
  622. element = delegateElement = $( element );
  623. this.bindings = this.bindings.add( element );
  624. }
  625. $.each( handlers, function( event, handler ) {
  626. function handlerProxy() {
  627. // allow widgets to customize the disabled handling
  628. // - disabled as an array instead of boolean
  629. // - disabled class as method for disabling individual parts
  630. if ( !suppressDisabledCheck &&
  631. ( instance.options.disabled === true ||
  632. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  633. return;
  634. }
  635. return ( typeof handler === "string" ? instance[ handler ] : handler )
  636. .apply( instance, arguments );
  637. }
  638. // copy the guid so direct unbinding works
  639. if ( typeof handler !== "string" ) {
  640. handlerProxy.guid = handler.guid =
  641. handler.guid || handlerProxy.guid || $.guid++;
  642. }
  643. var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
  644. eventName = match[1] + instance.eventNamespace,
  645. selector = match[2];
  646. if ( selector ) {
  647. delegateElement.delegate( selector, eventName, handlerProxy );
  648. } else {
  649. element.bind( eventName, handlerProxy );
  650. }
  651. });
  652. },
  653. _off: function( element, eventName ) {
  654. eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) +
  655. this.eventNamespace;
  656. element.unbind( eventName ).undelegate( eventName );
  657. // Clear the stack to avoid memory leaks (#10056)
  658. this.bindings = $( this.bindings.not( element ).get() );
  659. this.focusable = $( this.focusable.not( element ).get() );
  660. this.hoverable = $( this.hoverable.not( element ).get() );
  661. },
  662. _delay: function( handler, delay ) {
  663. function handlerProxy() {
  664. return ( typeof handler === "string" ? instance[ handler ] : handler )
  665. .apply( instance, arguments );
  666. }
  667. var instance = this;
  668. return setTimeout( handlerProxy, delay || 0 );
  669. },
  670. _hoverable: function( element ) {
  671. this.hoverable = this.hoverable.add( element );
  672. this._on( element, {
  673. mouseenter: function( event ) {
  674. $( event.currentTarget ).addClass( "ui-state-hover" );
  675. },
  676. mouseleave: function( event ) {
  677. $( event.currentTarget ).removeClass( "ui-state-hover" );
  678. }
  679. });
  680. },
  681. _focusable: function( element ) {
  682. this.focusable = this.focusable.add( element );
  683. this._on( element, {
  684. focusin: function( event ) {
  685. $( event.currentTarget ).addClass( "ui-state-focus" );
  686. },
  687. focusout: function( event ) {
  688. $( event.currentTarget ).removeClass( "ui-state-focus" );
  689. }
  690. });
  691. },
  692. _trigger: function( type, event, data ) {
  693. var prop, orig,
  694. callback = this.options[ type ];
  695. data = data || {};
  696. event = $.Event( event );
  697. event.type = ( type === this.widgetEventPrefix ?
  698. type :
  699. this.widgetEventPrefix + type ).toLowerCase();
  700. // the original event may come from any element
  701. // so we need to reset the target on the new event
  702. event.target = this.element[ 0 ];
  703. // copy original event properties over to the new event
  704. orig = event.originalEvent;
  705. if ( orig ) {
  706. for ( prop in orig ) {
  707. if ( !( prop in event ) ) {
  708. event[ prop ] = orig[ prop ];
  709. }
  710. }
  711. }
  712. this.element.trigger( event, data );
  713. return !( $.isFunction( callback ) &&
  714. callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
  715. event.isDefaultPrevented() );
  716. }
  717. };
  718. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  719. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  720. if ( typeof options === "string" ) {
  721. options = { effect: options };
  722. }
  723. var hasOptions,
  724. effectName = !options ?
  725. method :
  726. options === true || typeof options === "number" ?
  727. defaultEffect :
  728. options.effect || defaultEffect;
  729. options = options || {};
  730. if ( typeof options === "number" ) {
  731. options = { duration: options };
  732. }
  733. hasOptions = !$.isEmptyObject( options );
  734. options.complete = callback;
  735. if ( options.delay ) {
  736. element.delay( options.delay );
  737. }
  738. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  739. element[ method ]( options );
  740. } else if ( effectName !== method && element[ effectName ] ) {
  741. element[ effectName ]( options.duration, options.easing, callback );
  742. } else {
  743. element.queue(function( next ) {
  744. $( this )[ method ]();
  745. if ( callback ) {
  746. callback.call( element[ 0 ] );
  747. }
  748. next();
  749. });
  750. }
  751. };
  752. });
  753. var widget = $.widget;
  754. /*!
  755. * jQuery UI Mouse 1.11.4
  756. * http://jqueryui.com
  757. *
  758. * Copyright jQuery Foundation and other contributors
  759. * Released under the MIT license.
  760. * http://jquery.org/license
  761. *
  762. * http://api.jqueryui.com/mouse/
  763. */
  764. var mouseHandled = false;
  765. $( document ).mouseup( function() {
  766. mouseHandled = false;
  767. });
  768. var mouse = $.widget("ui.mouse", {
  769. version: "1.11.4",
  770. options: {
  771. cancel: "input,textarea,button,select,option",
  772. distance: 1,
  773. delay: 0
  774. },
  775. _mouseInit: function() {
  776. var that = this;
  777. this.element
  778. .bind("mousedown." + this.widgetName, function(event) {
  779. return that._mouseDown(event);
  780. })
  781. .bind("click." + this.widgetName, function(event) {
  782. if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
  783. $.removeData(event.target, that.widgetName + ".preventClickEvent");
  784. event.stopImmediatePropagation();
  785. return false;
  786. }
  787. });
  788. this.started = false;
  789. },
  790. // TODO: make sure destroying one instance of mouse doesn't mess with
  791. // other instances of mouse
  792. _mouseDestroy: function() {
  793. this.element.unbind("." + this.widgetName);
  794. if ( this._mouseMoveDelegate ) {
  795. this.document
  796. .unbind("mousemove." + this.widgetName, this._mouseMoveDelegate)
  797. .unbind("mouseup." + this.widgetName, this._mouseUpDelegate);
  798. }
  799. },
  800. _mouseDown: function(event) {
  801. // don't let more than one widget handle mouseStart
  802. if ( mouseHandled ) {
  803. return;
  804. }
  805. this._mouseMoved = false;
  806. // we may have missed mouseup (out of window)
  807. (this._mouseStarted && this._mouseUp(event));
  808. this._mouseDownEvent = event;
  809. var that = this,
  810. btnIsLeft = (event.which === 1),
  811. // event.target.nodeName works around a bug in IE 8 with
  812. // disabled inputs (#7620)
  813. elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
  814. if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
  815. return true;
  816. }
  817. this.mouseDelayMet = !this.options.delay;
  818. if (!this.mouseDelayMet) {
  819. this._mouseDelayTimer = setTimeout(function() {
  820. that.mouseDelayMet = true;
  821. }, this.options.delay);
  822. }
  823. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  824. this._mouseStarted = (this._mouseStart(event) !== false);
  825. if (!this._mouseStarted) {
  826. event.preventDefault();
  827. return true;
  828. }
  829. }
  830. // Click event may never have fired (Gecko & Opera)
  831. if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
  832. $.removeData(event.target, this.widgetName + ".preventClickEvent");
  833. }
  834. // these delegates are required to keep context
  835. this._mouseMoveDelegate = function(event) {
  836. return that._mouseMove(event);
  837. };
  838. this._mouseUpDelegate = function(event) {
  839. return that._mouseUp(event);
  840. };
  841. this.document
  842. .bind( "mousemove." + this.widgetName, this._mouseMoveDelegate )
  843. .bind( "mouseup." + this.widgetName, this._mouseUpDelegate );
  844. event.preventDefault();
  845. mouseHandled = true;
  846. return true;
  847. },
  848. _mouseMove: function(event) {
  849. // Only check for mouseups outside the document if you've moved inside the document
  850. // at least once. This prevents the firing of mouseup in the case of IE<9, which will
  851. // fire a mousemove event if content is placed under the cursor. See #7778
  852. // Support: IE <9
  853. if ( this._mouseMoved ) {
  854. // IE mouseup check - mouseup happened when mouse was out of window
  855. if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
  856. return this._mouseUp(event);
  857. // Iframe mouseup check - mouseup occurred in another document
  858. } else if ( !event.which ) {
  859. return this._mouseUp( event );
  860. }
  861. }
  862. if ( event.which || event.button ) {
  863. this._mouseMoved = true;
  864. }
  865. if (this._mouseStarted) {
  866. this._mouseDrag(event);
  867. return event.preventDefault();
  868. }
  869. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  870. this._mouseStarted =
  871. (this._mouseStart(this._mouseDownEvent, event) !== false);
  872. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  873. }
  874. return !this._mouseStarted;
  875. },
  876. _mouseUp: function(event) {
  877. this.document
  878. .unbind( "mousemove." + this.widgetName, this._mouseMoveDelegate )
  879. .unbind( "mouseup." + this.widgetName, this._mouseUpDelegate );
  880. if (this._mouseStarted) {
  881. this._mouseStarted = false;
  882. if (event.target === this._mouseDownEvent.target) {
  883. $.data(event.target, this.widgetName + ".preventClickEvent", true);
  884. }
  885. this._mouseStop(event);
  886. }
  887. mouseHandled = false;
  888. return false;
  889. },
  890. _mouseDistanceMet: function(event) {
  891. return (Math.max(
  892. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  893. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  894. ) >= this.options.distance
  895. );
  896. },
  897. _mouseDelayMet: function(/* event */) {
  898. return this.mouseDelayMet;
  899. },
  900. // These are placeholder methods, to be overriden by extending plugin
  901. _mouseStart: function(/* event */) {},
  902. _mouseDrag: function(/* event */) {},
  903. _mouseStop: function(/* event */) {},
  904. _mouseCapture: function(/* event */) { return true; }
  905. });
  906. /*!
  907. * jQuery UI Position 1.11.4
  908. * http://jqueryui.com
  909. *
  910. * Copyright jQuery Foundation and other contributors
  911. * Released under the MIT license.
  912. * http://jquery.org/license
  913. *
  914. * http://api.jqueryui.com/position/
  915. */
  916. (function() {
  917. $.ui = $.ui || {};
  918. var cachedScrollbarWidth, supportsOffsetFractions,
  919. max = Math.max,
  920. abs = Math.abs,
  921. round = Math.round,
  922. rhorizontal = /left|center|right/,
  923. rvertical = /top|center|bottom/,
  924. roffset = /[\+\-]\d+(\.[\d]+)?%?/,
  925. rposition = /^\w+/,
  926. rpercent = /%$/,
  927. _position = $.fn.position;
  928. function getOffsets( offsets, width, height ) {
  929. return [
  930. parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  931. parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  932. ];
  933. }
  934. function parseCss( element, property ) {
  935. return parseInt( $.css( element, property ), 10 ) || 0;
  936. }
  937. function getDimensions( elem ) {
  938. var raw = elem[0];
  939. if ( raw.nodeType === 9 ) {
  940. return {
  941. width: elem.width(),
  942. height: elem.height(),
  943. offset: { top: 0, left: 0 }
  944. };
  945. }
  946. if ( $.isWindow( raw ) ) {
  947. return {
  948. width: elem.width(),
  949. height: elem.height(),
  950. offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
  951. };
  952. }
  953. if ( raw.preventDefault ) {
  954. return {
  955. width: 0,
  956. height: 0,
  957. offset: { top: raw.pageY, left: raw.pageX }
  958. };
  959. }
  960. return {
  961. width: elem.outerWidth(),
  962. height: elem.outerHeight(),
  963. offset: elem.offset()
  964. };
  965. }
  966. $.position = {
  967. scrollbarWidth: function() {
  968. if ( cachedScrollbarWidth !== undefined ) {
  969. return cachedScrollbarWidth;
  970. }
  971. var w1, w2,
  972. div = $( "<div style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
  973. innerDiv = div.children()[0];
  974. $( "body" ).append( div );
  975. w1 = innerDiv.offsetWidth;
  976. div.css( "overflow", "scroll" );
  977. w2 = innerDiv.offsetWidth;
  978. if ( w1 === w2 ) {
  979. w2 = div[0].clientWidth;
  980. }
  981. div.remove();
  982. return (cachedScrollbarWidth = w1 - w2);
  983. },
  984. getScrollInfo: function( within ) {
  985. var overflowX = within.isWindow || within.isDocument ? "" :
  986. within.element.css( "overflow-x" ),
  987. overflowY = within.isWindow || within.isDocument ? "" :
  988. within.element.css( "overflow-y" ),
  989. hasOverflowX = overflowX === "scroll" ||
  990. ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
  991. hasOverflowY = overflowY === "scroll" ||
  992. ( overflowY === "auto" && within.height < within.element[0].scrollHeight );
  993. return {
  994. width: hasOverflowY ? $.position.scrollbarWidth() : 0,
  995. height: hasOverflowX ? $.position.scrollbarWidth() : 0
  996. };
  997. },
  998. getWithinInfo: function( element ) {
  999. var withinElement = $( element || window ),
  1000. isWindow = $.isWindow( withinElement[0] ),
  1001. isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9;
  1002. return {
  1003. element: withinElement,
  1004. isWindow: isWindow,
  1005. isDocument: isDocument,
  1006. offset: withinElement.offset() || { left: 0, top: 0 },
  1007. scrollLeft: withinElement.scrollLeft(),
  1008. scrollTop: withinElement.scrollTop(),
  1009. // support: jQuery 1.6.x
  1010. // jQuery 1.6 doesn't support .outerWidth/Height() on documents or windows
  1011. width: isWindow || isDocument ? withinElement.width() : withinElement.outerWidth(),
  1012. height: isWindow || isDocument ? withinElement.height() : withinElement.outerHeight()
  1013. };
  1014. }
  1015. };
  1016. $.fn.position = function( options ) {
  1017. if ( !options || !options.of ) {
  1018. return _position.apply( this, arguments );
  1019. }
  1020. // make a copy, we don't want to modify arguments
  1021. options = $.extend( {}, options );
  1022. var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
  1023. target = $( options.of ),
  1024. within = $.position.getWithinInfo( options.within ),
  1025. scrollInfo = $.position.getScrollInfo( within ),
  1026. collision = ( options.collision || "flip" ).split( " " ),
  1027. offsets = {};
  1028. dimensions = getDimensions( target );
  1029. if ( target[0].preventDefault ) {
  1030. // force left top to allow flipping
  1031. options.at = "left top";
  1032. }
  1033. targetWidth = dimensions.width;
  1034. targetHeight = dimensions.height;
  1035. targetOffset = dimensions.offset;
  1036. // clone to reuse original targetOffset later
  1037. basePosition = $.extend( {}, targetOffset );
  1038. // force my and at to have valid horizontal and vertical positions
  1039. // if a value is missing or invalid, it will be converted to center
  1040. $.each( [ "my", "at" ], function() {
  1041. var pos = ( options[ this ] || "" ).split( " " ),
  1042. horizontalOffset,
  1043. verticalOffset;
  1044. if ( pos.length === 1) {
  1045. pos = rhorizontal.test( pos[ 0 ] ) ?
  1046. pos.concat( [ "center" ] ) :
  1047. rvertical.test( pos[ 0 ] ) ?
  1048. [ "center" ].concat( pos ) :
  1049. [ "center", "center" ];
  1050. }
  1051. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  1052. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  1053. // calculate offsets
  1054. horizontalOffset = roffset.exec( pos[ 0 ] );
  1055. verticalOffset = roffset.exec( pos[ 1 ] );
  1056. offsets[ this ] = [
  1057. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  1058. verticalOffset ? verticalOffset[ 0 ] : 0
  1059. ];
  1060. // reduce to just the positions without the offsets
  1061. options[ this ] = [
  1062. rposition.exec( pos[ 0 ] )[ 0 ],
  1063. rposition.exec( pos[ 1 ] )[ 0 ]
  1064. ];
  1065. });
  1066. // normalize collision option
  1067. if ( collision.length === 1 ) {
  1068. collision[ 1 ] = collision[ 0 ];
  1069. }
  1070. if ( options.at[ 0 ] === "right" ) {
  1071. basePosition.left += targetWidth;
  1072. } else if ( options.at[ 0 ] === "center" ) {
  1073. basePosition.left += targetWidth / 2;
  1074. }
  1075. if ( options.at[ 1 ] === "bottom" ) {
  1076. basePosition.top += targetHeight;
  1077. } else if ( options.at[ 1 ] === "center" ) {
  1078. basePosition.top += targetHeight / 2;
  1079. }
  1080. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  1081. basePosition.left += atOffset[ 0 ];
  1082. basePosition.top += atOffset[ 1 ];
  1083. return this.each(function() {
  1084. var collisionPosition, using,
  1085. elem = $( this ),
  1086. elemWidth = elem.outerWidth(),
  1087. elemHeight = elem.outerHeight(),
  1088. marginLeft = parseCss( this, "marginLeft" ),
  1089. marginTop = parseCss( this, "marginTop" ),
  1090. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
  1091. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
  1092. position = $.extend( {}, basePosition ),
  1093. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  1094. if ( options.my[ 0 ] === "right" ) {
  1095. position.left -= elemWidth;
  1096. } else if ( options.my[ 0 ] === "center" ) {
  1097. position.left -= elemWidth / 2;
  1098. }
  1099. if ( options.my[ 1 ] === "bottom" ) {
  1100. position.top -= elemHeight;
  1101. } else if ( options.my[ 1 ] === "center" ) {
  1102. position.top -= elemHeight / 2;
  1103. }
  1104. position.left += myOffset[ 0 ];
  1105. position.top += myOffset[ 1 ];
  1106. // if the browser doesn't support fractions, then round for consistent results
  1107. if ( !supportsOffsetFractions ) {
  1108. position.left = round( position.left );
  1109. position.top = round( position.top );
  1110. }
  1111. collisionPosition = {
  1112. marginLeft: marginLeft,
  1113. marginTop: marginTop
  1114. };
  1115. $.each( [ "left", "top" ], function( i, dir ) {
  1116. if ( $.ui.position[ collision[ i ] ] ) {
  1117. $.ui.position[ collision[ i ] ][ dir ]( position, {
  1118. targetWidth: targetWidth,
  1119. targetHeight: targetHeight,
  1120. elemWidth: elemWidth,
  1121. elemHeight: elemHeight,
  1122. collisionPosition: collisionPosition,
  1123. collisionWidth: collisionWidth,
  1124. collisionHeight: collisionHeight,
  1125. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  1126. my: options.my,
  1127. at: options.at,
  1128. within: within,
  1129. elem: elem
  1130. });
  1131. }
  1132. });
  1133. if ( options.using ) {
  1134. // adds feedback as second argument to using callback, if present
  1135. using = function( props ) {
  1136. var left = targetOffset.left - position.left,
  1137. right = left + targetWidth - elemWidth,
  1138. top = targetOffset.top - position.top,
  1139. bottom = top + targetHeight - elemHeight,
  1140. feedback = {
  1141. target: {
  1142. element: target,
  1143. left: targetOffset.left,
  1144. top: targetOffset.top,
  1145. width: targetWidth,
  1146. height: targetHeight
  1147. },
  1148. element: {
  1149. element: elem,
  1150. left: position.left,
  1151. top: position.top,
  1152. width: elemWidth,
  1153. height: elemHeight
  1154. },
  1155. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  1156. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  1157. };
  1158. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  1159. feedback.horizontal = "center";
  1160. }
  1161. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  1162. feedback.vertical = "middle";
  1163. }
  1164. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  1165. feedback.important = "horizontal";
  1166. } else {
  1167. feedback.important = "vertical";
  1168. }
  1169. options.using.call( this, props, feedback );
  1170. };
  1171. }
  1172. elem.offset( $.extend( position, { using: using } ) );
  1173. });
  1174. };
  1175. $.ui.position = {
  1176. fit: {
  1177. left: function( position, data ) {
  1178. var within = data.within,
  1179. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  1180. outerWidth = within.width,
  1181. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  1182. overLeft = withinOffset - collisionPosLeft,
  1183. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  1184. newOverRight;
  1185. // element is wider than within
  1186. if ( data.collisionWidth > outerWidth ) {
  1187. // element is initially over the left side of within
  1188. if ( overLeft > 0 && overRight <= 0 ) {
  1189. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
  1190. position.left += overLeft - newOverRight;
  1191. // element is initially over right side of within
  1192. } else if ( overRight > 0 && overLeft <= 0 ) {
  1193. position.left = withinOffset;
  1194. // element is initially over both left and right sides of within
  1195. } else {
  1196. if ( overLeft > overRight ) {
  1197. position.left = withinOffset + outerWidth - data.collisionWidth;
  1198. } else {
  1199. position.left = withinOffset;
  1200. }
  1201. }
  1202. // too far left -> align with left edge
  1203. } else if ( overLeft > 0 ) {
  1204. position.left += overLeft;
  1205. // too far right -> align with right edge
  1206. } else if ( overRight > 0 ) {
  1207. position.left -= overRight;
  1208. // adjust based on position and margin
  1209. } else {
  1210. position.left = max( position.left - collisionPosLeft, position.left );
  1211. }
  1212. },
  1213. top: function( position, data ) {
  1214. var within = data.within,
  1215. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  1216. outerHeight = data.within.height,
  1217. collisionPosTop = position.top - data.collisionPosition.marginTop,
  1218. overTop = withinOffset - collisionPosTop,
  1219. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  1220. newOverBottom;
  1221. // element is taller than within
  1222. if ( data.collisionHeight > outerHeight ) {
  1223. // element is initially over the top of within
  1224. if ( overTop > 0 && overBottom <= 0 ) {
  1225. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
  1226. position.top += overTop - newOverBottom;
  1227. // element is initially over bottom of within
  1228. } else if ( overBottom > 0 && overTop <= 0 ) {
  1229. position.top = withinOffset;
  1230. // element is initially over both top and bottom of within
  1231. } else {
  1232. if ( overTop > overBottom ) {
  1233. position.top = withinOffset + outerHeight - data.collisionHeight;
  1234. } else {
  1235. position.top = withinOffset;
  1236. }
  1237. }
  1238. // too far up -> align with top
  1239. } else if ( overTop > 0 ) {
  1240. position.top += overTop;
  1241. // too far down -> align with bottom edge
  1242. } else if ( overBottom > 0 ) {
  1243. position.top -= overBottom;
  1244. // adjust based on position and margin
  1245. } else {
  1246. position.top = max( position.top - collisionPosTop, position.top );
  1247. }
  1248. }
  1249. },
  1250. flip: {
  1251. left: function( position, data ) {
  1252. var within = data.within,
  1253. withinOffset = within.offset.left + within.scrollLeft,
  1254. outerWidth = within.width,
  1255. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  1256. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  1257. overLeft = collisionPosLeft - offsetLeft,
  1258. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  1259. myOffset = data.my[ 0 ] === "left" ?
  1260. -data.elemWidth :
  1261. data.my[ 0 ] === "right" ?
  1262. data.elemWidth :
  1263. 0,
  1264. atOffset = data.at[ 0 ] === "left" ?
  1265. data.targetWidth :
  1266. data.at[ 0 ] === "right" ?
  1267. -data.targetWidth :
  1268. 0,
  1269. offset = -2 * data.offset[ 0 ],
  1270. newOverRight,
  1271. newOverLeft;
  1272. if ( overLeft < 0 ) {
  1273. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
  1274. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  1275. position.left += myOffset + atOffset + offset;
  1276. }
  1277. } else if ( overRight > 0 ) {
  1278. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
  1279. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  1280. position.left += myOffset + atOffset + offset;
  1281. }
  1282. }
  1283. },
  1284. top: function( position, data ) {
  1285. var within = data.within,
  1286. withinOffset = within.offset.top + within.scrollTop,
  1287. outerHeight = within.height,
  1288. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  1289. collisionPosTop = position.top - data.collisionPosition.marginTop,
  1290. overTop = collisionPosTop - offsetTop,
  1291. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  1292. top = data.my[ 1 ] === "top",
  1293. myOffset = top ?
  1294. -data.elemHeight :
  1295. data.my[ 1 ] === "bottom" ?
  1296. data.elemHeight :
  1297. 0,
  1298. atOffset = data.at[ 1 ] === "top" ?
  1299. data.targetHeight :
  1300. data.at[ 1 ] === "bottom" ?
  1301. -data.targetHeight :
  1302. 0,
  1303. offset = -2 * data.offset[ 1 ],
  1304. newOverTop,
  1305. newOverBottom;
  1306. if ( overTop < 0 ) {
  1307. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
  1308. if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {
  1309. position.top += myOffset + atOffset + offset;
  1310. }
  1311. } else if ( overBottom > 0 ) {
  1312. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
  1313. if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {
  1314. position.top += myOffset + atOffset + offset;
  1315. }
  1316. }
  1317. }
  1318. },
  1319. flipfit: {
  1320. left: function() {
  1321. $.ui.position.flip.left.apply( this, arguments );
  1322. $.ui.position.fit.left.apply( this, arguments );
  1323. },
  1324. top: function() {
  1325. $.ui.position.flip.top.apply( this, arguments );
  1326. $.ui.position.fit.top.apply( this, arguments );
  1327. }
  1328. }
  1329. };
  1330. // fraction support test
  1331. (function() {
  1332. var testElement, testElementParent, testElementStyle, offsetLeft, i,
  1333. body = document.getElementsByTagName( "body" )[ 0 ],
  1334. div = document.createElement( "div" );
  1335. //Create a "fake body" for testing based on method used in jQuery.support
  1336. testElement = document.createElement( body ? "div" : "body" );
  1337. testElementStyle = {
  1338. visibility: "hidden",
  1339. width: 0,
  1340. height: 0,
  1341. border: 0,
  1342. margin: 0,
  1343. background: "none"
  1344. };
  1345. if ( body ) {
  1346. $.extend( testElementStyle, {
  1347. position: "absolute",
  1348. left: "-1000px",
  1349. top: "-1000px"
  1350. });
  1351. }
  1352. for ( i in testElementStyle ) {
  1353. testElement.style[ i ] = testElementStyle[ i ];
  1354. }
  1355. testElement.appendChild( div );
  1356. testElementParent = body || document.documentElement;
  1357. testElementParent.insertBefore( testElement, testElementParent.firstChild );
  1358. div.style.cssText = "position: absolute; left: 10.7432222px;";
  1359. offsetLeft = $( div ).offset().left;
  1360. supportsOffsetFractions = offsetLeft > 10 && offsetLeft < 11;
  1361. testElement.innerHTML = "";
  1362. testElementParent.removeChild( testElement );
  1363. })();
  1364. })();
  1365. var position = $.ui.position;
  1366. /*!
  1367. * jQuery UI Sortable 1.11.4
  1368. * http://jqueryui.com
  1369. *
  1370. * Copyright jQuery Foundation and other contributors
  1371. * Released under the MIT license.
  1372. * http://jquery.org/license
  1373. *
  1374. * http://api.jqueryui.com/sortable/
  1375. */
  1376. var sortable = $.widget("ui.sortable", $.ui.mouse, {
  1377. version: "1.11.4",
  1378. widgetEventPrefix: "sort",
  1379. ready: false,
  1380. options: {
  1381. appendTo: "parent",
  1382. axis: false,
  1383. connectWith: false,
  1384. containment: false,
  1385. cursor: "auto",
  1386. cursorAt: false,
  1387. dropOnEmpty: true,
  1388. forcePlaceholderSize: false,
  1389. forceHelperSize: false,
  1390. grid: false,
  1391. handle: false,
  1392. helper: "original",
  1393. items: "> *",
  1394. opacity: false,
  1395. placeholder: false,
  1396. revert: false,
  1397. scroll: true,
  1398. scrollSensitivity: 20,
  1399. scrollSpeed: 20,
  1400. scope: "default",
  1401. tolerance: "intersect",
  1402. zIndex: 1000,
  1403. // callbacks
  1404. activate: null,
  1405. beforeStop: null,
  1406. change: null,
  1407. deactivate: null,
  1408. out: null,
  1409. over: null,
  1410. receive: null,
  1411. remove: null,
  1412. sort: null,
  1413. start: null,
  1414. stop: null,
  1415. update: null
  1416. },
  1417. _isOverAxis: function( x, reference, size ) {
  1418. return ( x >= reference ) && ( x < ( reference + size ) );
  1419. },
  1420. _isFloating: function( item ) {
  1421. return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
  1422. },
  1423. _create: function() {
  1424. this.containerCache = {};
  1425. this.element.addClass("ui-sortable");
  1426. //Get the items
  1427. this.refresh();
  1428. //Let's determine the parent's offset
  1429. this.offset = this.element.offset();
  1430. //Initialize mouse events for interaction
  1431. this._mouseInit();
  1432. this._setHandleClassName();
  1433. //We're ready to go
  1434. this.ready = true;
  1435. },
  1436. _setOption: function( key, value ) {
  1437. this._super( key, value );
  1438. if ( key === "handle" ) {
  1439. this._setHandleClassName();
  1440. }
  1441. },
  1442. _setHandleClassName: function() {
  1443. this.element.find( ".ui-sortable-handle" ).removeClass( "ui-sortable-handle" );
  1444. $.each( this.items, function() {
  1445. ( this.instance.options.handle ?
  1446. this.item.find( this.instance.options.handle ) : this.item )
  1447. .addClass( "ui-sortable-handle" );
  1448. });
  1449. },
  1450. _destroy: function() {
  1451. this.element
  1452. .removeClass( "ui-sortable ui-sortable-disabled" )
  1453. .find( ".ui-sortable-handle" )
  1454. .removeClass( "ui-sortable-handle" );
  1455. this._mouseDestroy();
  1456. for ( var i = this.items.length - 1; i >= 0; i-- ) {
  1457. this.items[i].item.removeData(this.widgetName + "-item");
  1458. }
  1459. return this;
  1460. },
  1461. _mouseCapture: function(event, overrideHandle) {
  1462. var currentItem = null,
  1463. validHandle = false,
  1464. that = this;
  1465. if (this.reverting) {
  1466. return false;
  1467. }
  1468. if(this.options.disabled || this.options.type === "static") {
  1469. return false;
  1470. }
  1471. //We have to refresh the items data once first
  1472. this._refreshItems(event);
  1473. //Find out if the clicked node (or one of its parents) is a actual item in this.items
  1474. $(event.target).parents().each(function() {
  1475. if($.data(this, that.widgetName + "-item") === that) {
  1476. currentItem = $(this);
  1477. return false;
  1478. }
  1479. });
  1480. if($.data(event.target, that.widgetName + "-item") === that) {
  1481. currentItem = $(event.target);
  1482. }
  1483. if(!currentItem) {
  1484. return false;
  1485. }
  1486. if(this.options.handle && !overrideHandle) {
  1487. $(this.options.handle, currentItem).find("*").addBack().each(function() {
  1488. if(this === event.target) {
  1489. validHandle = true;
  1490. }
  1491. });
  1492. if(!validHandle) {
  1493. return false;
  1494. }
  1495. }
  1496. this.currentItem = currentItem;
  1497. this._removeCurrentsFromItems();
  1498. return true;
  1499. },
  1500. _mouseStart: function(event, overrideHandle, noActivation) {
  1501. var i, body,
  1502. o = this.options;
  1503. this.currentContainer = this;
  1504. //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
  1505. this.refreshPositions();
  1506. //Create and append the visible helper
  1507. this.helper = this._createHelper(event);
  1508. //Cache the helper size
  1509. this._cacheHelperProportions();
  1510. /*
  1511. * - Position generation -
  1512. * This block generates everything position related - it's the core of draggables.
  1513. */
  1514. //Cache the margins of the original element
  1515. this._cacheMargins();
  1516. //Get the next scrolling parent
  1517. this.scrollParent = this.helper.scrollParent();
  1518. //The element's absolute position on the page minus margins
  1519. this.offset = this.currentItem.offset();
  1520. this.offset = {
  1521. top: this.offset.top - this.margins.top,
  1522. left: this.offset.left - this.margins.left
  1523. };
  1524. $.extend(this.offset, {
  1525. click: { //Where the click happened, relative to the element
  1526. left: event.pageX - this.offset.left,
  1527. top: event.pageY - this.offset.top
  1528. },
  1529. parent: this._getParentOffset(),
  1530. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  1531. });
  1532. // Only after we got the offset, we can change the helper's position to absolute
  1533. // TODO: Still need to figure out a way to make relative sorting possible
  1534. this.helper.css("position", "absolute");
  1535. this.cssPosition = this.helper.css("position");
  1536. //Generate the original position
  1537. this.originalPosition = this._generatePosition(event);
  1538. this.originalPageX = event.pageX;
  1539. this.originalPageY = event.pageY;
  1540. //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
  1541. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  1542. //Cache the former DOM position
  1543. this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
  1544. //If the helper is not the original, hide the original so it's not playing any role during the drag, won't cause anything bad this way
  1545. if(this.helper[0] !== this.currentItem[0]) {
  1546. this.currentItem.hide();
  1547. }
  1548. //Create the placeholder
  1549. this._createPlaceholder();
  1550. //Set a containment if given in the options
  1551. if(o.containment) {
  1552. this._setContainment();
  1553. }
  1554. if( o.cursor && o.cursor !== "auto" ) { // cursor option
  1555. body = this.document.find( "body" );
  1556. // support: IE
  1557. this.storedCursor = body.css( "cursor" );
  1558. body.css( "cursor", o.cursor );
  1559. this.storedStylesheet = $( "<style>*{ cursor: "+o.cursor+" !important; }</style>" ).appendTo( body );
  1560. }
  1561. if(o.opacity) { // opacity option
  1562. if (this.helper.css("opacity")) {
  1563. this._storedOpacity = this.helper.css("opacity");
  1564. }
  1565. this.helper.css("opacity", o.opacity);
  1566. }
  1567. if(o.zIndex) { // zIndex option
  1568. if (this.helper.css("zIndex")) {
  1569. this._storedZIndex = this.helper.css("zIndex");
  1570. }
  1571. this.helper.css("zIndex", o.zIndex);
  1572. }
  1573. //Prepare scrolling
  1574. if(this.scrollParent[0] !== this.document[0] && this.scrollParent[0].tagName !== "HTML") {
  1575. this.overflowOffset = this.scrollParent.offset();
  1576. }
  1577. //Call callbacks
  1578. this._trigger("start", event, this._uiHash());
  1579. //Recache the helper size
  1580. if(!this._preserveHelperProportions) {
  1581. this._cacheHelperProportions();
  1582. }
  1583. //Post "activate" events to possible containers
  1584. if( !noActivation ) {
  1585. for ( i = this.containers.length - 1; i >= 0; i-- ) {
  1586. this.containers[ i ]._trigger( "activate", event, this._uiHash( this ) );
  1587. }
  1588. }
  1589. //Prepare possible droppables
  1590. if($.ui.ddmanager) {
  1591. $.ui.ddmanager.current = this;
  1592. }
  1593. if ($.ui.ddmanager && !o.dropBehaviour) {
  1594. $.ui.ddmanager.prepareOffsets(this, event);
  1595. }
  1596. this.dragging = true;
  1597. this.helper.addClass("ui-sortable-helper");
  1598. this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  1599. return true;
  1600. },
  1601. _mouseDrag: function(event) {
  1602. var i, item, itemElement, intersection,
  1603. o = this.options,
  1604. scrolled = false;
  1605. //Compute the helpers position
  1606. this.position = this._generatePosition(event);
  1607. this.positionAbs = this._convertPositionTo("absolute");
  1608. if (!this.lastPositionAbs) {
  1609. this.lastPositionAbs = this.positionAbs;
  1610. }
  1611. //Do scrolling
  1612. if(this.options.scroll) {
  1613. if(this.scrollParent[0] !== this.document[0] && this.scrollParent[0].tagName !== "HTML") {
  1614. if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
  1615. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
  1616. } else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) {
  1617. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
  1618. }
  1619. if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
  1620. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
  1621. } else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
  1622. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
  1623. }
  1624. } else {
  1625. if(event.pageY - this.document.scrollTop() < o.scrollSensitivity) {
  1626. scrolled = this.document.scrollTop(this.document.scrollTop() - o.scrollSpeed);
  1627. } else if(this.window.height() - (event.pageY - this.document.scrollTop()) < o.scrollSensitivity) {
  1628. scrolled = this.document.scrollTop(this.document.scrollTop() + o.scrollSpeed);
  1629. }
  1630. if(event.pageX - this.document.scrollLeft() < o.scrollSensitivity) {
  1631. scrolled = this.document.scrollLeft(this.document.scrollLeft() - o.scrollSpeed);
  1632. } else if(this.window.width() - (event.pageX - this.document.scrollLeft()) < o.scrollSensitivity) {
  1633. scrolled = this.document.scrollLeft(this.document.scrollLeft() + o.scrollSpeed);
  1634. }
  1635. }
  1636. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
  1637. $.ui.ddmanager.prepareOffsets(this, event);
  1638. }
  1639. }
  1640. //Regenerate the absolute position used for position checks
  1641. this.positionAbs = this._convertPositionTo("absolute");
  1642. //Set the helper position
  1643. if(!this.options.axis || this.options.axis !== "y") {
  1644. this.helper[0].style.left = this.position.left+"px";
  1645. }
  1646. if(!this.options.axis || this.options.axis !== "x") {
  1647. this.helper[0].style.top = this.position.top+"px";
  1648. }
  1649. //Rearrange
  1650. for (i = this.items.length - 1; i >= 0; i--) {
  1651. //Cache variables and intersection, continue if no intersection
  1652. item = this.items[i];
  1653. itemElement = item.item[0];
  1654. intersection = this._intersectsWithPointer(item);
  1655. if (!intersection) {
  1656. continue;
  1657. }
  1658. // Only put the placeholder inside the current Container, skip all
  1659. // items from other containers. This works because when moving
  1660. // an item from one container to another the
  1661. // currentContainer is switched before the placeholder is moved.
  1662. //
  1663. // Without this, moving items in "sub-sortables" can cause
  1664. // the placeholder to jitter between the outer and inner container.
  1665. if (item.instance !== this.currentContainer) {
  1666. continue;
  1667. }
  1668. // cannot intersect with itself
  1669. // no useless actions that have been done before
  1670. // no action if the item moved is the parent of the item checked
  1671. if (itemElement !== this.currentItem[0] &&
  1672. this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement &&
  1673. !$.contains(this.placeholder[0], itemElement) &&
  1674. (this.options.type === "semi-dynamic" ? !$.contains(this.element[0], itemElement) : true)
  1675. ) {
  1676. this.direction = intersection === 1 ? "down" : "up";
  1677. if (this.options.tolerance === "pointer" || this._intersectsWithSides(item)) {
  1678. this._rearrange(event, item);
  1679. } else {
  1680. break;
  1681. }
  1682. this._trigger("change", event, this._uiHash());
  1683. break;
  1684. }
  1685. }
  1686. //Post events to containers
  1687. this._contactContainers(event);
  1688. //Interconnect with droppables
  1689. if($.ui.ddmanager) {
  1690. $.ui.ddmanager.drag(this, event);
  1691. }
  1692. //Call callbacks
  1693. this._trigger("sort", event, this._uiHash());
  1694. this.lastPositionAbs = this.positionAbs;
  1695. return false;
  1696. },
  1697. _mouseStop: function(event, noPropagation) {
  1698. if(!event) {
  1699. return;
  1700. }
  1701. //If we are using droppables, inform the manager about the drop
  1702. if ($.ui.ddmanager && !this.options.dropBehaviour) {
  1703. $.ui.ddmanager.drop(this, event);
  1704. }
  1705. if(this.options.revert) {
  1706. var that = this,
  1707. cur = this.placeholder.offset(),
  1708. axis = this.options.axis,
  1709. animation = {};
  1710. if ( !axis || axis === "x" ) {
  1711. animation.left = cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] === this.document[0].body ? 0 : this.offsetParent[0].scrollLeft);
  1712. }
  1713. if ( !axis || axis === "y" ) {
  1714. animation.top = cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] === this.document[0].body ? 0 : this.offsetParent[0].scrollTop);
  1715. }
  1716. this.reverting = true;
  1717. $(this.helper).animate( animation, parseInt(this.options.revert, 10) || 500, function() {
  1718. that._clear(event);
  1719. });
  1720. } else {
  1721. this._clear(event, noPropagation);
  1722. }
  1723. return false;
  1724. },
  1725. cancel: function() {
  1726. if(this.dragging) {
  1727. this._mouseUp({ target: null });
  1728. if(this.options.helper === "original") {
  1729. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  1730. } else {
  1731. this.currentItem.show();
  1732. }
  1733. //Post deactivating events to containers
  1734. for (var i = this.containers.length - 1; i >= 0; i--){
  1735. this.containers[i]._trigger("deactivate", null, this._uiHash(this));
  1736. if(this.containers[i].containerCache.over) {
  1737. this.containers[i]._trigger("out", null, this._uiHash(this));
  1738. this.containers[i].containerCache.over = 0;
  1739. }
  1740. }
  1741. }
  1742. if (this.placeholder) {
  1743. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  1744. if(this.placeholder[0].parentNode) {
  1745. this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  1746. }
  1747. if(this.options.helper !== "original" && this.helper && this.helper[0].parentNode) {
  1748. this.helper.remove();
  1749. }
  1750. $.extend(this, {
  1751. helper: null,
  1752. dragging: false,
  1753. reverting: false,
  1754. _noFinalSort: null
  1755. });
  1756. if(this.domPosition.prev) {
  1757. $(this.domPosition.prev).after(this.currentItem);
  1758. } else {
  1759. $(this.domPosition.parent).prepend(this.currentItem);
  1760. }
  1761. }
  1762. return this;
  1763. },
  1764. serialize: function(o) {
  1765. var items = this._getItemsAsjQuery(o && o.connected),
  1766. str = [];
  1767. o = o || {};
  1768. $(items).each(function() {
  1769. var res = ($(o.item || this).attr(o.attribute || "id") || "").match(o.expression || (/(.+)[\-=_](.+)/));
  1770. if (res) {
  1771. str.push((o.key || res[1]+"[]")+"="+(o.key && o.expression ? res[1] : res[2]));
  1772. }
  1773. });
  1774. if(!str.length && o.key) {
  1775. str.push(o.key + "=");
  1776. }
  1777. return str.join("&");
  1778. },
  1779. toArray: function(o) {
  1780. var items = this._getItemsAsjQuery(o && o.connected),
  1781. ret = [];
  1782. o = o || {};
  1783. items.each(function() { ret.push($(o.item || this).attr(o.attribute || "id") || ""); });
  1784. return ret;
  1785. },
  1786. /* Be careful with the following core functions */
  1787. _intersectsWith: function(item) {
  1788. var x1 = this.positionAbs.left,
  1789. x2 = x1 + this.helperProportions.width,
  1790. y1 = this.positionAbs.top,
  1791. y2 = y1 + this.helperProportions.height,
  1792. l = item.left,
  1793. r = l + item.width,
  1794. t = item.top,
  1795. b = t + item.height,
  1796. dyClick = this.offset.click.top,
  1797. dxClick = this.offset.click.left,
  1798. isOverElementHeight = ( this.options.axis === "x" ) || ( ( y1 + dyClick ) > t && ( y1 + dyClick ) < b ),
  1799. isOverElementWidth = ( this.options.axis === "y" ) || ( ( x1 + dxClick ) > l && ( x1 + dxClick ) < r ),
  1800. isOverElement = isOverElementHeight && isOverElementWidth;
  1801. if ( this.options.tolerance === "pointer" ||
  1802. this.options.forcePointerForContainers ||
  1803. (this.options.tolerance !== "pointer" && this.helperProportions[this.floating ? "width" : "height"] > item[this.floating ? "width" : "height"])
  1804. ) {
  1805. return isOverElement;
  1806. } else {
  1807. return (l < x1 + (this.helperProportions.width / 2) && // Right Half
  1808. x2 - (this.helperProportions.width / 2) < r && // Left Half
  1809. t < y1 + (this.helperProportions.height / 2) && // Bottom Half
  1810. y2 - (this.helperProportions.height / 2) < b ); // Top Half
  1811. }
  1812. },
  1813. _intersectsWithPointer: function(item) {
  1814. var isOverElementHeight = (this.options.axis === "x") || this._isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
  1815. isOverElementWidth = (this.options.axis === "y") || this._isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
  1816. isOverElement = isOverElementHeight && isOverElementWidth,
  1817. verticalDirection = this._getDragVerticalDirection(),
  1818. horizontalDirection = this._getDragHorizontalDirection();
  1819. if (!isOverElement) {
  1820. return false;
  1821. }
  1822. return this.floating ?
  1823. ( ((horizontalDirection && horizontalDirection === "right") || verticalDirection === "down") ? 2 : 1 )
  1824. : ( verticalDirection && (verticalDirection === "down" ? 2 : 1) );
  1825. },
  1826. _intersectsWithSides: function(item) {
  1827. var isOverBottomHalf = this._isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
  1828. isOverRightHalf = this._isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
  1829. verticalDirection = this._getDragVerticalDirection(),
  1830. horizontalDirection = this._getDragHorizontalDirection();
  1831. if (this.floating && horizontalDirection) {
  1832. return ((horizontalDirection === "right" && isOverRightHalf) || (horizontalDirection === "left" && !isOverRightHalf));
  1833. } else {
  1834. return verticalDirection && ((verticalDirection === "down" && isOverBottomHalf) || (verticalDirection === "up" && !isOverBottomHalf));
  1835. }
  1836. },
  1837. _getDragVerticalDirection: function() {
  1838. var delta = this.positionAbs.top - this.lastPositionAbs.top;
  1839. return delta !== 0 && (delta > 0 ? "down" : "up");
  1840. },
  1841. _getDragHorizontalDirection: function() {
  1842. var delta = this.positionAbs.left - this.lastPositionAbs.left;
  1843. return delta !== 0 && (delta > 0 ? "right" : "left");
  1844. },
  1845. refresh: function(event) {
  1846. this._refreshItems(event);
  1847. this._setHandleClassName();
  1848. this.refreshPositions();
  1849. return this;
  1850. },
  1851. _connectWith: function() {
  1852. var options = this.options;
  1853. return options.connectWith.constructor === String ? [options.connectWith] : options.connectWith;
  1854. },
  1855. _getItemsAsjQuery: function(connected) {
  1856. var i, j, cur, inst,
  1857. items = [],
  1858. queries = [],
  1859. connectWith = this._connectWith();
  1860. if(connectWith && connected) {
  1861. for (i = connectWith.length - 1; i >= 0; i--){
  1862. cur = $(connectWith[i], this.document[0]);
  1863. for ( j = cur.length - 1; j >= 0; j--){
  1864. inst = $.data(cur[j], this.widgetFullName);
  1865. if(inst && inst !== this && !inst.options.disabled) {
  1866. queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), inst]);
  1867. }
  1868. }
  1869. }
  1870. }
  1871. queries.push([$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element).not(".ui-sortable-helper").not(".ui-sortable-placeholder"), this]);
  1872. function addItems() {
  1873. items.push( this );
  1874. }
  1875. for (i = queries.length - 1; i >= 0; i--){
  1876. queries[i][0].each( addItems );
  1877. }
  1878. return $(items);
  1879. },
  1880. _removeCurrentsFromItems: function() {
  1881. var list = this.currentItem.find(":data(" + this.widgetName + "-item)");
  1882. this.items = $.grep(this.items, function (item) {
  1883. for (var j=0; j < list.length; j++) {
  1884. if(list[j] === item.item[0]) {
  1885. return false;
  1886. }
  1887. }
  1888. return true;
  1889. });
  1890. },
  1891. _refreshItems: function(event) {
  1892. this.items = [];
  1893. this.containers = [this];
  1894. var i, j, cur, inst, targetData, _queries, item, queriesLength,
  1895. items = this.items,
  1896. queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]],
  1897. connectWith = this._connectWith();
  1898. if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
  1899. for (i = connectWith.length - 1; i >= 0; i--){
  1900. cur = $(connectWith[i], this.document[0]);
  1901. for (j = cur.length - 1; j >= 0; j--){
  1902. inst = $.data(cur[j], this.widgetFullName);
  1903. if(inst && inst !== this && !inst.options.disabled) {
  1904. queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
  1905. this.containers.push(inst);
  1906. }
  1907. }
  1908. }
  1909. }
  1910. for (i = queries.length - 1; i >= 0; i--) {
  1911. targetData = queries[i][1];
  1912. _queries = queries[i][0];
  1913. for (j=0, queriesLength = _queries.length; j < queriesLength; j++) {
  1914. item = $(_queries[j]);
  1915. item.data(this.widgetName + "-item", targetData); // Data for target checking (mouse manager)
  1916. items.push({
  1917. item: item,
  1918. instance: targetData,
  1919. width: 0, height: 0,
  1920. left: 0, top: 0
  1921. });
  1922. }
  1923. }
  1924. },
  1925. refreshPositions: function(fast) {
  1926. // Determine whether items are being displayed horizontally
  1927. this.floating = this.items.length ?
  1928. this.options.axis === "x" || this._isFloating( this.items[ 0 ].item ) :
  1929. false;
  1930. //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
  1931. if(this.offsetParent && this.helper) {
  1932. this.offset.parent = this._getParentOffset();
  1933. }
  1934. var i, item, t, p;
  1935. for (i = this.items.length - 1; i >= 0; i--){
  1936. item = this.items[i];
  1937. //We ignore calculating positions of all connected containers when we're not over them
  1938. if(item.instance !== this.currentContainer && this.currentContainer && item.item[0] !== this.currentItem[0]) {
  1939. continue;
  1940. }
  1941. t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
  1942. if (!fast) {
  1943. item.width = t.outerWidth();
  1944. item.height = t.outerHeight();
  1945. }
  1946. p = t.offset();
  1947. item.left = p.left;
  1948. item.top = p.top;
  1949. }
  1950. if(this.options.custom && this.options.custom.refreshContainers) {
  1951. this.options.custom.refreshContainers.call(this);
  1952. } else {
  1953. for (i = this.containers.length - 1; i >= 0; i--){
  1954. p = this.containers[i].element.offset();
  1955. this.containers[i].containerCache.left = p.left;
  1956. this.containers[i].containerCache.top = p.top;
  1957. this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
  1958. this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
  1959. }
  1960. }
  1961. return this;
  1962. },
  1963. _createPlaceholder: function(that) {
  1964. that = that || this;
  1965. var className,
  1966. o = that.options;
  1967. if(!o.placeholder || o.placeholder.constructor === String) {
  1968. className = o.placeholder;
  1969. o.placeholder = {
  1970. element: function() {
  1971. var nodeName = that.currentItem[0].nodeName.toLowerCase(),
  1972. element = $( "<" + nodeName + ">", that.document[0] )
  1973. .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
  1974. .removeClass("ui-sortable-helper");
  1975. if ( nodeName === "tbody" ) {
  1976. that._createTrPlaceholder(
  1977. that.currentItem.find( "tr" ).eq( 0 ),
  1978. $( "<tr>", that.document[ 0 ] ).appendTo( element )
  1979. );
  1980. } else if ( nodeName === "tr" ) {
  1981. that._createTrPlaceholder( that.currentItem, element );
  1982. } else if ( nodeName === "img" ) {
  1983. element.attr( "src", that.currentItem.attr( "src" ) );
  1984. }
  1985. if ( !className ) {
  1986. element.css( "visibility", "hidden" );
  1987. }
  1988. return element;
  1989. },
  1990. update: function(container, p) {
  1991. // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that
  1992. // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified
  1993. if(className && !o.forcePlaceholderSize) {
  1994. return;
  1995. }
  1996. //If the element doesn't have a actual height by itself (without styles coming from a stylesheet), it receives the inline height from the dragged item
  1997. if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css("paddingTop")||0, 10) - parseInt(that.currentItem.css("paddingBottom")||0, 10)); }
  1998. if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css("paddingLeft")||0, 10) - parseInt(that.currentItem.css("paddingRight")||0, 10)); }
  1999. }
  2000. };
  2001. }
  2002. //Create the placeholder
  2003. that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));
  2004. //Append it after the actual current item
  2005. that.currentItem.after(that.placeholder);
  2006. //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
  2007. o.placeholder.update(that, that.placeholder);
  2008. },
  2009. _createTrPlaceholder: function( sourceTr, targetTr ) {
  2010. var that = this;
  2011. sourceTr.children().each(function() {
  2012. $( "<td>&#160;</td>", that.document[ 0 ] )
  2013. .attr( "colspan", $( this ).attr( "colspan" ) || 1 )
  2014. .appendTo( targetTr );
  2015. });
  2016. },
  2017. _contactContainers: function(event) {
  2018. var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, cur, nearBottom, floating, axis,
  2019. innermostContainer = null,
  2020. innermostIndex = null;
  2021. // get innermost container that intersects with item
  2022. for (i = this.containers.length - 1; i >= 0; i--) {
  2023. // never consider a container that's located within the item itself
  2024. if($.contains(this.currentItem[0], this.containers[i].element[0])) {
  2025. continue;
  2026. }
  2027. if(this._intersectsWith(this.containers[i].containerCache)) {
  2028. // if we've already found a container and it's more "inner" than this, then continue
  2029. if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0])) {
  2030. continue;
  2031. }
  2032. innermostContainer = this.containers[i];
  2033. innermostIndex = i;
  2034. } else {
  2035. // container doesn't intersect. trigger "out" event if necessary
  2036. if(this.containers[i].containerCache.over) {
  2037. this.containers[i]._trigger("out", event, this._uiHash(this));
  2038. this.containers[i].containerCache.over = 0;
  2039. }
  2040. }
  2041. }
  2042. // if no intersecting containers found, return
  2043. if(!innermostContainer) {
  2044. return;
  2045. }
  2046. // move the item into the container if it's not there already
  2047. if(this.containers.length === 1) {
  2048. if (!this.containers[innermostIndex].containerCache.over) {
  2049. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  2050. this.containers[innermostIndex].containerCache.over = 1;
  2051. }
  2052. } else {
  2053. //When entering a new container, we will find the item with the least distance and append our item near it
  2054. dist = 10000;
  2055. itemWithLeastDistance = null;
  2056. floating = innermostContainer.floating || this._isFloating(this.currentItem);
  2057. posProperty = floating ? "left" : "top";
  2058. sizeProperty = floating ? "width" : "height";
  2059. axis = floating ? "clientX" : "clientY";
  2060. for (j = this.items.length - 1; j >= 0; j--) {
  2061. if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) {
  2062. continue;
  2063. }
  2064. if(this.items[j].item[0] === this.currentItem[0]) {
  2065. continue;
  2066. }
  2067. cur = this.items[j].item.offset()[posProperty];
  2068. nearBottom = false;
  2069. if ( event[ axis ] - cur > this.items[ j ][ sizeProperty ] / 2 ) {
  2070. nearBottom = true;
  2071. }
  2072. if ( Math.abs( event[ axis ] - cur ) < dist ) {
  2073. dist = Math.abs( event[ axis ] - cur );
  2074. itemWithLeastDistance = this.items[ j ];
  2075. this.direction = nearBottom ? "up": "down";
  2076. }
  2077. }
  2078. //Check if dropOnEmpty is enabled
  2079. if(!itemWithLeastDistance && !this.options.dropOnEmpty) {
  2080. return;
  2081. }
  2082. if(this.currentContainer === this.containers[innermostIndex]) {
  2083. if ( !this.currentContainer.containerCache.over ) {
  2084. this.containers[ innermostIndex ]._trigger( "over", event, this._uiHash() );
  2085. this.currentContainer.containerCache.over = 1;
  2086. }
  2087. return;
  2088. }
  2089. itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
  2090. this._trigger("change", event, this._uiHash());
  2091. this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
  2092. this.currentContainer = this.containers[innermostIndex];
  2093. //Update the placeholder
  2094. this.options.placeholder.update(this.currentContainer, this.placeholder);
  2095. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  2096. this.containers[innermostIndex].containerCache.over = 1;
  2097. }
  2098. },
  2099. _createHelper: function(event) {
  2100. var o = this.options,
  2101. helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper === "clone" ? this.currentItem.clone() : this.currentItem);
  2102. //Add the helper to the DOM if that didn't happen already
  2103. if(!helper.parents("body").length) {
  2104. $(o.appendTo !== "parent" ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
  2105. }
  2106. if(helper[0] === this.currentItem[0]) {
  2107. this._storedCSS = { width: this.currentItem[0].style.width, height: this.currentItem[0].style.height, position: this.currentItem.css("position"), top: this.currentItem.css("top"), left: this.currentItem.css("left") };
  2108. }
  2109. if(!helper[0].style.width || o.forceHelperSize) {
  2110. helper.width(this.currentItem.width());
  2111. }
  2112. if(!helper[0].style.height || o.forceHelperSize) {
  2113. helper.height(this.currentItem.height());
  2114. }
  2115. return helper;
  2116. },
  2117. _adjustOffsetFromHelper: function(obj) {
  2118. if (typeof obj === "string") {
  2119. obj = obj.split(" ");
  2120. }
  2121. if ($.isArray(obj)) {
  2122. obj = {left: +obj[0], top: +obj[1] || 0};
  2123. }
  2124. if ("left" in obj) {
  2125. this.offset.click.left = obj.left + this.margins.left;
  2126. }
  2127. if ("right" in obj) {
  2128. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  2129. }
  2130. if ("top" in obj) {
  2131. this.offset.click.top = obj.top + this.margins.top;
  2132. }
  2133. if ("bottom" in obj) {
  2134. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  2135. }
  2136. },
  2137. _getParentOffset: function() {
  2138. //Get the offsetParent and cache its position
  2139. this.offsetParent = this.helper.offsetParent();
  2140. var po = this.offsetParent.offset();
  2141. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  2142. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  2143. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  2144. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  2145. if(this.cssPosition === "absolute" && this.scrollParent[0] !== this.document[0] && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  2146. po.left += this.scrollParent.scrollLeft();
  2147. po.top += this.scrollParent.scrollTop();
  2148. }
  2149. // This needs to be actually done for all browsers, since pageX/pageY includes this information
  2150. // with an ugly IE fix
  2151. if( this.offsetParent[0] === this.document[0].body || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
  2152. po = { top: 0, left: 0 };
  2153. }
  2154. return {
  2155. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  2156. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  2157. };
  2158. },
  2159. _getRelativeOffset: function() {
  2160. if(this.cssPosition === "relative") {
  2161. var p = this.currentItem.position();
  2162. return {
  2163. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  2164. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  2165. };
  2166. } else {
  2167. return { top: 0, left: 0 };
  2168. }
  2169. },
  2170. _cacheMargins: function() {
  2171. this.margins = {
  2172. left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
  2173. top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
  2174. };
  2175. },
  2176. _cacheHelperProportions: function() {
  2177. this.helperProportions = {
  2178. width: this.helper.outerWidth(),
  2179. height: this.helper.outerHeight()
  2180. };
  2181. },
  2182. _setContainment: function() {
  2183. var ce, co, over,
  2184. o = this.options;
  2185. if(o.containment === "parent") {
  2186. o.containment = this.helper[0].parentNode;
  2187. }
  2188. if(o.containment === "document" || o.containment === "window") {
  2189. this.containment = [
  2190. 0 - this.offset.relative.left - this.offset.parent.left,
  2191. 0 - this.offset.relative.top - this.offset.parent.top,
  2192. o.containment === "document" ? this.document.width() : this.window.width() - this.helperProportions.width - this.margins.left,
  2193. (o.containment === "document" ? this.document.width() : this.window.height() || this.document[0].body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  2194. ];
  2195. }
  2196. if(!(/^(document|window|parent)$/).test(o.containment)) {
  2197. ce = $(o.containment)[0];
  2198. co = $(o.containment).offset();
  2199. over = ($(ce).css("overflow") !== "hidden");
  2200. this.containment = [
  2201. co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left,
  2202. co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top,
  2203. co.left+(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left,
  2204. co.top+(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top
  2205. ];
  2206. }
  2207. },
  2208. _convertPositionTo: function(d, pos) {
  2209. if(!pos) {
  2210. pos = this.position;
  2211. }
  2212. var mod = d === "absolute" ? 1 : -1,
  2213. scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== this.document[0] && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
  2214. scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  2215. return {
  2216. top: (
  2217. pos.top + // The absolute mouse position
  2218. this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  2219. this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
  2220. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  2221. ),
  2222. left: (
  2223. pos.left + // The absolute mouse position
  2224. this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  2225. this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
  2226. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  2227. )
  2228. };
  2229. },
  2230. _generatePosition: function(event) {
  2231. var top, left,
  2232. o = this.options,
  2233. pageX = event.pageX,
  2234. pageY = event.pageY,
  2235. scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== this.document[0] && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  2236. // This is another very weird special case that only happens for relative elements:
  2237. // 1. If the css position is relative
  2238. // 2. and the scroll parent is the document or similar to the offset parent
  2239. // we have to refresh the relative offset during the scroll so there are no jumps
  2240. if(this.cssPosition === "relative" && !(this.scrollParent[0] !== this.document[0] && this.scrollParent[0] !== this.offsetParent[0])) {
  2241. this.offset.relative = this._getRelativeOffset();
  2242. }
  2243. /*
  2244. * - Position constraining -
  2245. * Constrain the position to a mix of grid, containment.
  2246. */
  2247. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  2248. if(this.containment) {
  2249. if(event.pageX - this.offset.click.left < this.containment[0]) {
  2250. pageX = this.containment[0] + this.offset.click.left;
  2251. }
  2252. if(event.pageY - this.offset.click.top < this.containment[1]) {
  2253. pageY = this.containment[1] + this.offset.click.top;
  2254. }
  2255. if(event.pageX - this.offset.click.left > this.containment[2]) {
  2256. pageX = this.containment[2] + this.offset.click.left;
  2257. }
  2258. if(event.pageY - this.offset.click.top > this.containment[3]) {
  2259. pageY = this.containment[3] + this.offset.click.top;
  2260. }
  2261. }
  2262. if(o.grid) {
  2263. top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
  2264. pageY = this.containment ? ( (top - this.offset.click.top >= this.containment[1] && top - this.offset.click.top <= this.containment[3]) ? top : ((top - this.offset.click.top >= this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
  2265. left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
  2266. pageX = this.containment ? ( (left - this.offset.click.left >= this.containment[0] && left - this.offset.click.left <= this.containment[2]) ? left : ((left - this.offset.click.left >= this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
  2267. }
  2268. }
  2269. return {
  2270. top: (
  2271. pageY - // The absolute mouse position
  2272. this.offset.click.top - // Click offset (relative to the element)
  2273. this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
  2274. this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
  2275. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  2276. ),
  2277. left: (
  2278. pageX - // The absolute mouse position
  2279. this.offset.click.left - // Click offset (relative to the element)
  2280. this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
  2281. this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
  2282. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  2283. )
  2284. };
  2285. },
  2286. _rearrange: function(event, i, a, hardRefresh) {
  2287. a ? a[0].appendChild(this.placeholder[0]) : i.item[0].parentNode.insertBefore(this.placeholder[0], (this.direction === "down" ? i.item[0] : i.item[0].nextSibling));
  2288. //Various things done here to improve the performance:
  2289. // 1. we create a setTimeout, that calls refreshPositions
  2290. // 2. on the instance, we have a counter variable, that get's higher after every append
  2291. // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
  2292. // 4. this lets only the last addition to the timeout stack through
  2293. this.counter = this.counter ? ++this.counter : 1;
  2294. var counter = this.counter;
  2295. this._delay(function() {
  2296. if(counter === this.counter) {
  2297. this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
  2298. }
  2299. });
  2300. },
  2301. _clear: function(event, noPropagation) {
  2302. this.reverting = false;
  2303. // We delay all events that have to be triggered to after the point where the placeholder has been removed and
  2304. // everything else normalized again
  2305. var i,
  2306. delayedTriggers = [];
  2307. // We first have to update the dom position of the actual currentItem
  2308. // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
  2309. if(!this._noFinalSort && this.currentItem.parent().length) {
  2310. this.placeholder.before(this.currentItem);
  2311. }
  2312. this._noFinalSort = null;
  2313. if(this.helper[0] === this.currentItem[0]) {
  2314. for(i in this._storedCSS) {
  2315. if(this._storedCSS[i] === "auto" || this._storedCSS[i] === "static") {
  2316. this._storedCSS[i] = "";
  2317. }
  2318. }
  2319. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  2320. } else {
  2321. this.currentItem.show();
  2322. }
  2323. if(this.fromOutside && !noPropagation) {
  2324. delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
  2325. }
  2326. if((this.fromOutside || this.domPosition.prev !== this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent !== this.currentItem.parent()[0]) && !noPropagation) {
  2327. delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
  2328. }
  2329. // Check if the items Container has Changed and trigger appropriate
  2330. // events.
  2331. if (this !== this.currentContainer) {
  2332. if(!noPropagation) {
  2333. delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); });
  2334. delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  2335. delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  2336. }
  2337. }
  2338. //Post events to containers
  2339. function delayEvent( type, instance, container ) {
  2340. return function( event ) {
  2341. container._trigger( type, event, instance._uiHash( instance ) );
  2342. };
  2343. }
  2344. for (i = this.containers.length - 1; i >= 0; i--){
  2345. if (!noPropagation) {
  2346. delayedTriggers.push( delayEvent( "deactivate", this, this.containers[ i ] ) );
  2347. }
  2348. if(this.containers[i].containerCache.over) {
  2349. delayedTriggers.push( delayEvent( "out", this, this.containers[ i ] ) );
  2350. this.containers[i].containerCache.over = 0;
  2351. }
  2352. }
  2353. //Do what was originally in plugins
  2354. if ( this.storedCursor ) {
  2355. this.document.find( "body" ).css( "cursor", this.storedCursor );
  2356. this.storedStylesheet.remove();
  2357. }
  2358. if(this._storedOpacity) {
  2359. this.helper.css("opacity", this._storedOpacity);
  2360. }
  2361. if(this._storedZIndex) {
  2362. this.helper.css("zIndex", this._storedZIndex === "auto" ? "" : this._storedZIndex);
  2363. }
  2364. this.dragging = false;
  2365. if(!noPropagation) {
  2366. this._trigger("beforeStop", event, this._uiHash());
  2367. }
  2368. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  2369. this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  2370. if ( !this.cancelHelperRemoval ) {
  2371. if ( this.helper[ 0 ] !== this.currentItem[ 0 ] ) {
  2372. this.helper.remove();
  2373. }
  2374. this.helper = null;
  2375. }
  2376. if(!noPropagation) {
  2377. for (i=0; i < delayedTriggers.length; i++) {
  2378. delayedTriggers[i].call(this, event);
  2379. } //Trigger all delayed events
  2380. this._trigger("stop", event, this._uiHash());
  2381. }
  2382. this.fromOutside = false;
  2383. return !this.cancelHelperRemoval;
  2384. },
  2385. _trigger: function() {
  2386. if ($.Widget.prototype._trigger.apply(this, arguments) === false) {
  2387. this.cancel();
  2388. }
  2389. },
  2390. _uiHash: function(_inst) {
  2391. var inst = _inst || this;
  2392. return {
  2393. helper: inst.helper,
  2394. placeholder: inst.placeholder || $([]),
  2395. position: inst.position,
  2396. originalPosition: inst.originalPosition,
  2397. offset: inst.positionAbs,
  2398. item: inst.currentItem,
  2399. sender: _inst ? _inst.element : null
  2400. };
  2401. }
  2402. });
  2403. /*!
  2404. * jQuery UI Accordion 1.11.4
  2405. * http://jqueryui.com
  2406. *
  2407. * Copyright jQuery Foundation and other contributors
  2408. * Released under the MIT license.
  2409. * http://jquery.org/license
  2410. *
  2411. * http://api.jqueryui.com/accordion/
  2412. */
  2413. var accordion = $.widget( "ui.accordion", {
  2414. version: "1.11.4",
  2415. options: {
  2416. active: 0,
  2417. animate: {},
  2418. collapsible: false,
  2419. event: "click",
  2420. header: "> li > :first-child,> :not(li):even",
  2421. heightStyle: "auto",
  2422. icons: {
  2423. activeHeader: "ui-icon-triangle-1-s",
  2424. header: "ui-icon-triangle-1-e"
  2425. },
  2426. // callbacks
  2427. activate: null,
  2428. beforeActivate: null
  2429. },
  2430. hideProps: {
  2431. borderTopWidth: "hide",
  2432. borderBottomWidth: "hide",
  2433. paddingTop: "hide",
  2434. paddingBottom: "hide",
  2435. height: "hide"
  2436. },
  2437. showProps: {
  2438. borderTopWidth: "show",
  2439. borderBottomWidth: "show",
  2440. paddingTop: "show",
  2441. paddingBottom: "show",
  2442. height: "show"
  2443. },
  2444. _create: function() {
  2445. var options = this.options;
  2446. this.prevShow = this.prevHide = $();
  2447. this.element.addClass( "ui-accordion ui-widget ui-helper-reset" )
  2448. // ARIA
  2449. .attr( "role", "tablist" );
  2450. // don't allow collapsible: false and active: false / null
  2451. if ( !options.collapsible && (options.active === false || options.active == null) ) {
  2452. options.active = 0;
  2453. }
  2454. this._processPanels();
  2455. // handle negative values
  2456. if ( options.active < 0 ) {
  2457. options.active += this.headers.length;
  2458. }
  2459. this._refresh();
  2460. },
  2461. _getCreateEventData: function() {
  2462. return {
  2463. header: this.active,
  2464. panel: !this.active.length ? $() : this.active.next()
  2465. };
  2466. },
  2467. _createIcons: function() {
  2468. var icons = this.options.icons;
  2469. if ( icons ) {
  2470. $( "<span>" )
  2471. .addClass( "ui-accordion-header-icon ui-icon " + icons.header )
  2472. .prependTo( this.headers );
  2473. this.active.children( ".ui-accordion-header-icon" )
  2474. .removeClass( icons.header )
  2475. .addClass( icons.activeHeader );
  2476. this.headers.addClass( "ui-accordion-icons" );
  2477. }
  2478. },
  2479. _destroyIcons: function() {
  2480. this.headers
  2481. .removeClass( "ui-accordion-icons" )
  2482. .children( ".ui-accordion-header-icon" )
  2483. .remove();
  2484. },
  2485. _destroy: function() {
  2486. var contents;
  2487. // clean up main element
  2488. this.element
  2489. .removeClass( "ui-accordion ui-widget ui-helper-reset" )
  2490. .removeAttr( "role" );
  2491. // clean up headers
  2492. this.headers
  2493. .removeClass( "ui-accordion-header ui-accordion-header-active ui-state-default " +
  2494. "ui-corner-all ui-state-active ui-state-disabled ui-corner-top" )
  2495. .removeAttr( "role" )
  2496. .removeAttr( "aria-expanded" )
  2497. .removeAttr( "aria-selected" )
  2498. .removeAttr( "aria-controls" )
  2499. .removeAttr( "tabIndex" )
  2500. .removeUniqueId();
  2501. this._destroyIcons();
  2502. // clean up content panels
  2503. contents = this.headers.next()
  2504. .removeClass( "ui-helper-reset ui-widget-content ui-corner-bottom " +
  2505. "ui-accordion-content ui-accordion-content-active ui-state-disabled" )
  2506. .css( "display", "" )
  2507. .removeAttr( "role" )
  2508. .removeAttr( "aria-hidden" )
  2509. .removeAttr( "aria-labelledby" )
  2510. .removeUniqueId();
  2511. if ( this.options.heightStyle !== "content" ) {
  2512. contents.css( "height", "" );
  2513. }
  2514. },
  2515. _setOption: function( key, value ) {
  2516. if ( key === "active" ) {
  2517. // _activate() will handle invalid values and update this.options
  2518. this._activate( value );
  2519. return;
  2520. }
  2521. if ( key === "event" ) {
  2522. if ( this.options.event ) {
  2523. this._off( this.headers, this.options.event );
  2524. }
  2525. this._setupEvents( value );
  2526. }
  2527. this._super( key, value );
  2528. // setting collapsible: false while collapsed; open first panel
  2529. if ( key === "collapsible" && !value && this.options.active === false ) {
  2530. this._activate( 0 );
  2531. }
  2532. if ( key === "icons" ) {
  2533. this._destroyIcons();
  2534. if ( value ) {
  2535. this._createIcons();
  2536. }
  2537. }
  2538. // #5332 - opacity doesn't cascade to positioned elements in IE
  2539. // so we need to add the disabled class to the headers and panels
  2540. if ( key === "disabled" ) {
  2541. this.element
  2542. .toggleClass( "ui-state-disabled", !!value )
  2543. .attr( "aria-disabled", value );
  2544. this.headers.add( this.headers.next() )
  2545. .toggleClass( "ui-state-disabled", !!value );
  2546. }
  2547. },
  2548. _keydown: function( event ) {
  2549. if ( event.altKey || event.ctrlKey ) {
  2550. return;
  2551. }
  2552. var keyCode = $.ui.keyCode,
  2553. length = this.headers.length,
  2554. currentIndex = this.headers.index( event.target ),
  2555. toFocus = false;
  2556. switch ( event.keyCode ) {
  2557. case keyCode.RIGHT:
  2558. case keyCode.DOWN:
  2559. toFocus = this.headers[ ( currentIndex + 1 ) % length ];
  2560. break;
  2561. case keyCode.LEFT:
  2562. case keyCode.UP:
  2563. toFocus = this.headers[ ( currentIndex - 1 + length ) % length ];
  2564. break;
  2565. case keyCode.SPACE:
  2566. case keyCode.ENTER:
  2567. this._eventHandler( event );
  2568. break;
  2569. case keyCode.HOME:
  2570. toFocus = this.headers[ 0 ];
  2571. break;
  2572. case keyCode.END:
  2573. toFocus = this.headers[ length - 1 ];
  2574. break;
  2575. }
  2576. if ( toFocus ) {
  2577. $( event.target ).attr( "tabIndex", -1 );
  2578. $( toFocus ).attr( "tabIndex", 0 );
  2579. toFocus.focus();
  2580. event.preventDefault();
  2581. }
  2582. },
  2583. _panelKeyDown: function( event ) {
  2584. if ( event.keyCode === $.ui.keyCode.UP && event.ctrlKey ) {
  2585. $( event.currentTarget ).prev().focus();
  2586. }
  2587. },
  2588. refresh: function() {
  2589. var options = this.options;
  2590. this._processPanels();
  2591. // was collapsed or no panel
  2592. if ( ( options.active === false && options.collapsible === true ) || !this.headers.length ) {
  2593. options.active = false;
  2594. this.active = $();
  2595. // active false only when collapsible is true
  2596. } else if ( options.active === false ) {
  2597. this._activate( 0 );
  2598. // was active, but active panel is gone
  2599. } else if ( this.active.length && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
  2600. // all remaining panel are disabled
  2601. if ( this.headers.length === this.headers.find(".ui-state-disabled").length ) {
  2602. options.active = false;
  2603. this.active = $();
  2604. // activate previous panel
  2605. } else {
  2606. this._activate( Math.max( 0, options.active - 1 ) );
  2607. }
  2608. // was active, active panel still exists
  2609. } else {
  2610. // make sure active index is correct
  2611. options.active = this.headers.index( this.active );
  2612. }
  2613. this._destroyIcons();
  2614. this._refresh();
  2615. },
  2616. _processPanels: function() {
  2617. var prevHeaders = this.headers,
  2618. prevPanels = this.panels;
  2619. this.headers = this.element.find( this.options.header )
  2620. .addClass( "ui-accordion-header ui-state-default ui-corner-all" );
  2621. this.panels = this.headers.next()
  2622. .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" )
  2623. .filter( ":not(.ui-accordion-content-active)" )
  2624. .hide();
  2625. // Avoid memory leaks (#10056)
  2626. if ( prevPanels ) {
  2627. this._off( prevHeaders.not( this.headers ) );
  2628. this._off( prevPanels.not( this.panels ) );
  2629. }
  2630. },
  2631. _refresh: function() {
  2632. var maxHeight,
  2633. options = this.options,
  2634. heightStyle = options.heightStyle,
  2635. parent = this.element.parent();
  2636. this.active = this._findActive( options.active )
  2637. .addClass( "ui-accordion-header-active ui-state-active ui-corner-top" )
  2638. .removeClass( "ui-corner-all" );
  2639. this.active.next()
  2640. .addClass( "ui-accordion-content-active" )
  2641. .show();
  2642. this.headers
  2643. .attr( "role", "tab" )
  2644. .each(function() {
  2645. var header = $( this ),
  2646. headerId = header.uniqueId().attr( "id" ),
  2647. panel = header.next(),
  2648. panelId = panel.uniqueId().attr( "id" );
  2649. header.attr( "aria-controls", panelId );
  2650. panel.attr( "aria-labelledby", headerId );
  2651. })
  2652. .next()
  2653. .attr( "role", "tabpanel" );
  2654. this.headers
  2655. .not( this.active )
  2656. .attr({
  2657. "aria-selected": "false",
  2658. "aria-expanded": "false",
  2659. tabIndex: -1
  2660. })
  2661. .next()
  2662. .attr({
  2663. "aria-hidden": "true"
  2664. })
  2665. .hide();
  2666. // make sure at least one header is in the tab order
  2667. if ( !this.active.length ) {
  2668. this.headers.eq( 0 ).attr( "tabIndex", 0 );
  2669. } else {
  2670. this.active.attr({
  2671. "aria-selected": "true",
  2672. "aria-expanded": "true",
  2673. tabIndex: 0
  2674. })
  2675. .next()
  2676. .attr({
  2677. "aria-hidden": "false"
  2678. });
  2679. }
  2680. this._createIcons();
  2681. this._setupEvents( options.event );
  2682. if ( heightStyle === "fill" ) {
  2683. maxHeight = parent.height();
  2684. this.element.siblings( ":visible" ).each(function() {
  2685. var elem = $( this ),
  2686. position = elem.css( "position" );
  2687. if ( position === "absolute" || position === "fixed" ) {
  2688. return;
  2689. }
  2690. maxHeight -= elem.outerHeight( true );
  2691. });
  2692. this.headers.each(function() {
  2693. maxHeight -= $( this ).outerHeight( true );
  2694. });
  2695. this.headers.next()
  2696. .each(function() {
  2697. $( this ).height( Math.max( 0, maxHeight -
  2698. $( this ).innerHeight() + $( this ).height() ) );
  2699. })
  2700. .css( "overflow", "auto" );
  2701. } else if ( heightStyle === "auto" ) {
  2702. maxHeight = 0;
  2703. this.headers.next()
  2704. .each(function() {
  2705. maxHeight = Math.max( maxHeight, $( this ).css( "height", "" ).height() );
  2706. })
  2707. .height( maxHeight );
  2708. }
  2709. },
  2710. _activate: function( index ) {
  2711. var active = this._findActive( index )[ 0 ];
  2712. // trying to activate the already active panel
  2713. if ( active === this.active[ 0 ] ) {
  2714. return;
  2715. }
  2716. // trying to collapse, simulate a click on the currently active header
  2717. active = active || this.active[ 0 ];
  2718. this._eventHandler({
  2719. target: active,
  2720. currentTarget: active,
  2721. preventDefault: $.noop
  2722. });
  2723. },
  2724. _findActive: function( selector ) {
  2725. return typeof selector === "number" ? this.headers.eq( selector ) : $();
  2726. },
  2727. _setupEvents: function( event ) {
  2728. var events = {
  2729. keydown: "_keydown"
  2730. };
  2731. if ( event ) {
  2732. $.each( event.split( " " ), function( index, eventName ) {
  2733. events[ eventName ] = "_eventHandler";
  2734. });
  2735. }
  2736. this._off( this.headers.add( this.headers.next() ) );
  2737. this._on( this.headers, events );
  2738. this._on( this.headers.next(), { keydown: "_panelKeyDown" });
  2739. this._hoverable( this.headers );
  2740. this._focusable( this.headers );
  2741. },
  2742. _eventHandler: function( event ) {
  2743. var options = this.options,
  2744. active = this.active,
  2745. clicked = $( event.currentTarget ),
  2746. clickedIsActive = clicked[ 0 ] === active[ 0 ],
  2747. collapsing = clickedIsActive && options.collapsible,
  2748. toShow = collapsing ? $() : clicked.next(),
  2749. toHide = active.next(),
  2750. eventData = {
  2751. oldHeader: active,
  2752. oldPanel: toHide,
  2753. newHeader: collapsing ? $() : clicked,
  2754. newPanel: toShow
  2755. };
  2756. event.preventDefault();
  2757. if (
  2758. // click on active header, but not collapsible
  2759. ( clickedIsActive && !options.collapsible ) ||
  2760. // allow canceling activation
  2761. ( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
  2762. return;
  2763. }
  2764. options.active = collapsing ? false : this.headers.index( clicked );
  2765. // when the call to ._toggle() comes after the class changes
  2766. // it causes a very odd bug in IE 8 (see #6720)
  2767. this.active = clickedIsActive ? $() : clicked;
  2768. this._toggle( eventData );
  2769. // switch classes
  2770. // corner classes on the previously active header stay after the animation
  2771. active.removeClass( "ui-accordion-header-active ui-state-active" );
  2772. if ( options.icons ) {
  2773. active.children( ".ui-accordion-header-icon" )
  2774. .removeClass( options.icons.activeHeader )
  2775. .addClass( options.icons.header );
  2776. }
  2777. if ( !clickedIsActive ) {
  2778. clicked
  2779. .removeClass( "ui-corner-all" )
  2780. .addClass( "ui-accordion-header-active ui-state-active ui-corner-top" );
  2781. if ( options.icons ) {
  2782. clicked.children( ".ui-accordion-header-icon" )
  2783. .removeClass( options.icons.header )
  2784. .addClass( options.icons.activeHeader );
  2785. }
  2786. clicked
  2787. .next()
  2788. .addClass( "ui-accordion-content-active" );
  2789. }
  2790. },
  2791. _toggle: function( data ) {
  2792. var toShow = data.newPanel,
  2793. toHide = this.prevShow.length ? this.prevShow : data.oldPanel;
  2794. // handle activating a panel during the animation for another activation
  2795. this.prevShow.add( this.prevHide ).stop( true, true );
  2796. this.prevShow = toShow;
  2797. this.prevHide = toHide;
  2798. if ( this.options.animate ) {
  2799. this._animate( toShow, toHide, data );
  2800. } else {
  2801. toHide.hide();
  2802. toShow.show();
  2803. this._toggleComplete( data );
  2804. }
  2805. toHide.attr({
  2806. "aria-hidden": "true"
  2807. });
  2808. toHide.prev().attr({
  2809. "aria-selected": "false",
  2810. "aria-expanded": "false"
  2811. });
  2812. // if we're switching panels, remove the old header from the tab order
  2813. // if we're opening from collapsed state, remove the previous header from the tab order
  2814. // if we're collapsing, then keep the collapsing header in the tab order
  2815. if ( toShow.length && toHide.length ) {
  2816. toHide.prev().attr({
  2817. "tabIndex": -1,
  2818. "aria-expanded": "false"
  2819. });
  2820. } else if ( toShow.length ) {
  2821. this.headers.filter(function() {
  2822. return parseInt( $( this ).attr( "tabIndex" ), 10 ) === 0;
  2823. })
  2824. .attr( "tabIndex", -1 );
  2825. }
  2826. toShow
  2827. .attr( "aria-hidden", "false" )
  2828. .prev()
  2829. .attr({
  2830. "aria-selected": "true",
  2831. "aria-expanded": "true",
  2832. tabIndex: 0
  2833. });
  2834. },
  2835. _animate: function( toShow, toHide, data ) {
  2836. var total, easing, duration,
  2837. that = this,
  2838. adjust = 0,
  2839. boxSizing = toShow.css( "box-sizing" ),
  2840. down = toShow.length &&
  2841. ( !toHide.length || ( toShow.index() < toHide.index() ) ),
  2842. animate = this.options.animate || {},
  2843. options = down && animate.down || animate,
  2844. complete = function() {
  2845. that._toggleComplete( data );
  2846. };
  2847. if ( typeof options === "number" ) {
  2848. duration = options;
  2849. }
  2850. if ( typeof options === "string" ) {
  2851. easing = options;
  2852. }
  2853. // fall back from options to animation in case of partial down settings
  2854. easing = easing || options.easing || animate.easing;
  2855. duration = duration || options.duration || animate.duration;
  2856. if ( !toHide.length ) {
  2857. return toShow.animate( this.showProps, duration, easing, complete );
  2858. }
  2859. if ( !toShow.length ) {
  2860. return toHide.animate( this.hideProps, duration, easing, complete );
  2861. }
  2862. total = toShow.show().outerHeight();
  2863. toHide.animate( this.hideProps, {
  2864. duration: duration,
  2865. easing: easing,
  2866. step: function( now, fx ) {
  2867. fx.now = Math.round( now );
  2868. }
  2869. });
  2870. toShow
  2871. .hide()
  2872. .animate( this.showProps, {
  2873. duration: duration,
  2874. easing: easing,
  2875. complete: complete,
  2876. step: function( now, fx ) {
  2877. fx.now = Math.round( now );
  2878. if ( fx.prop !== "height" ) {
  2879. if ( boxSizing === "content-box" ) {
  2880. adjust += fx.now;
  2881. }
  2882. } else if ( that.options.heightStyle !== "content" ) {
  2883. fx.now = Math.round( total - toHide.outerHeight() - adjust );
  2884. adjust = 0;
  2885. }
  2886. }
  2887. });
  2888. },
  2889. _toggleComplete: function( data ) {
  2890. var toHide = data.oldPanel;
  2891. toHide
  2892. .removeClass( "ui-accordion-content-active" )
  2893. .prev()
  2894. .removeClass( "ui-corner-top" )
  2895. .addClass( "ui-corner-all" );
  2896. // Work around for rendering bug in IE (#5421)
  2897. if ( toHide.length ) {
  2898. toHide.parent()[ 0 ].className = toHide.parent()[ 0 ].className;
  2899. }
  2900. this._trigger( "activate", null, data );
  2901. }
  2902. });
  2903. /*!
  2904. * jQuery UI Menu 1.11.4
  2905. * http://jqueryui.com
  2906. *
  2907. * Copyright jQuery Foundation and other contributors
  2908. * Released under the MIT license.
  2909. * http://jquery.org/license
  2910. *
  2911. * http://api.jqueryui.com/menu/
  2912. */
  2913. var menu = $.widget( "ui.menu", {
  2914. version: "1.11.4",
  2915. defaultElement: "<ul>",
  2916. delay: 300,
  2917. options: {
  2918. icons: {
  2919. submenu: "ui-icon-carat-1-e"
  2920. },
  2921. items: "> *",
  2922. menus: "ul",
  2923. position: {
  2924. my: "left-1 top",
  2925. at: "right top"
  2926. },
  2927. role: "menu",
  2928. // callbacks
  2929. blur: null,
  2930. focus: null,
  2931. select: null
  2932. },
  2933. _create: function() {
  2934. this.activeMenu = this.element;
  2935. // Flag used to prevent firing of the click handler
  2936. // as the event bubbles up through nested menus
  2937. this.mouseHandled = false;
  2938. this.element
  2939. .uniqueId()
  2940. .addClass( "ui-menu ui-widget ui-widget-content" )
  2941. .toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length )
  2942. .attr({
  2943. role: this.options.role,
  2944. tabIndex: 0
  2945. });
  2946. if ( this.options.disabled ) {
  2947. this.element
  2948. .addClass( "ui-state-disabled" )
  2949. .attr( "aria-disabled", "true" );
  2950. }
  2951. this._on({
  2952. // Prevent focus from sticking to links inside menu after clicking
  2953. // them (focus should always stay on UL during navigation).
  2954. "mousedown .ui-menu-item": function( event ) {
  2955. event.preventDefault();
  2956. },
  2957. "click .ui-menu-item": function( event ) {
  2958. var target = $( event.target );
  2959. if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) {
  2960. this.select( event );
  2961. // Only set the mouseHandled flag if the event will bubble, see #9469.
  2962. if ( !event.isPropagationStopped() ) {
  2963. this.mouseHandled = true;
  2964. }
  2965. // Open submenu on click
  2966. if ( target.has( ".ui-menu" ).length ) {
  2967. this.expand( event );
  2968. } else if ( !this.element.is( ":focus" ) && $( this.document[ 0 ].activeElement ).closest( ".ui-menu" ).length ) {
  2969. // Redirect focus to the menu
  2970. this.element.trigger( "focus", [ true ] );
  2971. // If the active item is on the top level, let it stay active.
  2972. // Otherwise, blur the active item since it is no longer visible.
  2973. if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) {
  2974. clearTimeout( this.timer );
  2975. }
  2976. }
  2977. }
  2978. },
  2979. "mouseenter .ui-menu-item": function( event ) {
  2980. // Ignore mouse events while typeahead is active, see #10458.
  2981. // Prevents focusing the wrong item when typeahead causes a scroll while the mouse
  2982. // is over an item in the menu
  2983. if ( this.previousFilter ) {
  2984. return;
  2985. }
  2986. var target = $( event.currentTarget );
  2987. // Remove ui-state-active class from siblings of the newly focused menu item
  2988. // to avoid a jump caused by adjacent elements both having a class with a border
  2989. target.siblings( ".ui-state-active" ).removeClass( "ui-state-active" );
  2990. this.focus( event, target );
  2991. },
  2992. mouseleave: "collapseAll",
  2993. "mouseleave .ui-menu": "collapseAll",
  2994. focus: function( event, keepActiveItem ) {
  2995. // If there's already an active item, keep it active
  2996. // If not, activate the first item
  2997. var item = this.active || this.element.find( this.options.items ).eq( 0 );
  2998. if ( !keepActiveItem ) {
  2999. this.focus( event, item );
  3000. }
  3001. },
  3002. blur: function( event ) {
  3003. this._delay(function() {
  3004. if ( !$.contains( this.element[0], this.document[0].activeElement ) ) {
  3005. this.collapseAll( event );
  3006. }
  3007. });
  3008. },
  3009. keydown: "_keydown"
  3010. });
  3011. this.refresh();
  3012. // Clicks outside of a menu collapse any open menus
  3013. this._on( this.document, {
  3014. click: function( event ) {
  3015. if ( this._closeOnDocumentClick( event ) ) {
  3016. this.collapseAll( event );
  3017. }
  3018. // Reset the mouseHandled flag
  3019. this.mouseHandled = false;
  3020. }
  3021. });
  3022. },
  3023. _destroy: function() {
  3024. // Destroy (sub)menus
  3025. this.element
  3026. .removeAttr( "aria-activedescendant" )
  3027. .find( ".ui-menu" ).addBack()
  3028. .removeClass( "ui-menu ui-widget ui-widget-content ui-menu-icons ui-front" )
  3029. .removeAttr( "role" )
  3030. .removeAttr( "tabIndex" )
  3031. .removeAttr( "aria-labelledby" )
  3032. .removeAttr( "aria-expanded" )
  3033. .removeAttr( "aria-hidden" )
  3034. .removeAttr( "aria-disabled" )
  3035. .removeUniqueId()
  3036. .show();
  3037. // Destroy menu items
  3038. this.element.find( ".ui-menu-item" )
  3039. .removeClass( "ui-menu-item" )
  3040. .removeAttr( "role" )
  3041. .removeAttr( "aria-disabled" )
  3042. .removeUniqueId()
  3043. .removeClass( "ui-state-hover" )
  3044. .removeAttr( "tabIndex" )
  3045. .removeAttr( "role" )
  3046. .removeAttr( "aria-haspopup" )
  3047. .children().each( function() {
  3048. var elem = $( this );
  3049. if ( elem.data( "ui-menu-submenu-carat" ) ) {
  3050. elem.remove();
  3051. }
  3052. });
  3053. // Destroy menu dividers
  3054. this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" );
  3055. },
  3056. _keydown: function( event ) {
  3057. var match, prev, character, skip,
  3058. preventDefault = true;
  3059. switch ( event.keyCode ) {
  3060. case $.ui.keyCode.PAGE_UP:
  3061. this.previousPage( event );
  3062. break;
  3063. case $.ui.keyCode.PAGE_DOWN:
  3064. this.nextPage( event );
  3065. break;
  3066. case $.ui.keyCode.HOME:
  3067. this._move( "first", "first", event );
  3068. break;
  3069. case $.ui.keyCode.END:
  3070. this._move( "last", "last", event );
  3071. break;
  3072. case $.ui.keyCode.UP:
  3073. this.previous( event );
  3074. break;
  3075. case $.ui.keyCode.DOWN:
  3076. this.next( event );
  3077. break;
  3078. case $.ui.keyCode.LEFT:
  3079. this.collapse( event );
  3080. break;
  3081. case $.ui.keyCode.RIGHT:
  3082. if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
  3083. this.expand( event );
  3084. }
  3085. break;
  3086. case $.ui.keyCode.ENTER:
  3087. case $.ui.keyCode.SPACE:
  3088. this._activate( event );
  3089. break;
  3090. case $.ui.keyCode.ESCAPE:
  3091. this.collapse( event );
  3092. break;
  3093. default:
  3094. preventDefault = false;
  3095. prev = this.previousFilter || "";
  3096. character = String.fromCharCode( event.keyCode );
  3097. skip = false;
  3098. clearTimeout( this.filterTimer );
  3099. if ( character === prev ) {
  3100. skip = true;
  3101. } else {
  3102. character = prev + character;
  3103. }
  3104. match = this._filterMenuItems( character );
  3105. match = skip && match.index( this.active.next() ) !== -1 ?
  3106. this.active.nextAll( ".ui-menu-item" ) :
  3107. match;
  3108. // If no matches on the current filter, reset to the last character pressed
  3109. // to move down the menu to the first item that starts with that character
  3110. if ( !match.length ) {
  3111. character = String.fromCharCode( event.keyCode );
  3112. match = this._filterMenuItems( character );
  3113. }
  3114. if ( match.length ) {
  3115. this.focus( event, match );
  3116. this.previousFilter = character;
  3117. this.filterTimer = this._delay(function() {
  3118. delete this.previousFilter;
  3119. }, 1000 );
  3120. } else {
  3121. delete this.previousFilter;
  3122. }
  3123. }
  3124. if ( preventDefault ) {
  3125. event.preventDefault();
  3126. }
  3127. },
  3128. _activate: function( event ) {
  3129. if ( !this.active.is( ".ui-state-disabled" ) ) {
  3130. if ( this.active.is( "[aria-haspopup='true']" ) ) {
  3131. this.expand( event );
  3132. } else {
  3133. this.select( event );
  3134. }
  3135. }
  3136. },
  3137. refresh: function() {
  3138. var menus, items,
  3139. that = this,
  3140. icon = this.options.icons.submenu,
  3141. submenus = this.element.find( this.options.menus );
  3142. this.element.toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length );
  3143. // Initialize nested menus
  3144. submenus.filter( ":not(.ui-menu)" )
  3145. .addClass( "ui-menu ui-widget ui-widget-content ui-front" )
  3146. .hide()
  3147. .attr({
  3148. role: this.options.role,
  3149. "aria-hidden": "true",
  3150. "aria-expanded": "false"
  3151. })
  3152. .each(function() {
  3153. var menu = $( this ),
  3154. item = menu.parent(),
  3155. submenuCarat = $( "<span>" )
  3156. .addClass( "ui-menu-icon ui-icon " + icon )
  3157. .data( "ui-menu-submenu-carat", true );
  3158. item
  3159. .attr( "aria-haspopup", "true" )
  3160. .prepend( submenuCarat );
  3161. menu.attr( "aria-labelledby", item.attr( "id" ) );
  3162. });
  3163. menus = submenus.add( this.element );
  3164. items = menus.find( this.options.items );
  3165. // Initialize menu-items containing spaces and/or dashes only as dividers
  3166. items.not( ".ui-menu-item" ).each(function() {
  3167. var item = $( this );
  3168. if ( that._isDivider( item ) ) {
  3169. item.addClass( "ui-widget-content ui-menu-divider" );
  3170. }
  3171. });
  3172. // Don't refresh list items that are already adapted
  3173. items.not( ".ui-menu-item, .ui-menu-divider" )
  3174. .addClass( "ui-menu-item" )
  3175. .uniqueId()
  3176. .attr({
  3177. tabIndex: -1,
  3178. role: this._itemRole()
  3179. });
  3180. // Add aria-disabled attribute to any disabled menu item
  3181. items.filter( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
  3182. // If the active item has been removed, blur the menu
  3183. if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
  3184. this.blur();
  3185. }
  3186. },
  3187. _itemRole: function() {
  3188. return {
  3189. menu: "menuitem",
  3190. listbox: "option"
  3191. }[ this.options.role ];
  3192. },
  3193. _setOption: function( key, value ) {
  3194. if ( key === "icons" ) {
  3195. this.element.find( ".ui-menu-icon" )
  3196. .removeClass( this.options.icons.submenu )
  3197. .addClass( value.submenu );
  3198. }
  3199. if ( key === "disabled" ) {
  3200. this.element
  3201. .toggleClass( "ui-state-disabled", !!value )
  3202. .attr( "aria-disabled", value );
  3203. }
  3204. this._super( key, value );
  3205. },
  3206. focus: function( event, item ) {
  3207. var nested, focused;
  3208. this.blur( event, event && event.type === "focus" );
  3209. this._scrollIntoView( item );
  3210. this.active = item.first();
  3211. focused = this.active.addClass( "ui-state-focus" ).removeClass( "ui-state-active" );
  3212. // Only update aria-activedescendant if there's a role
  3213. // otherwise we assume focus is managed elsewhere
  3214. if ( this.options.role ) {
  3215. this.element.attr( "aria-activedescendant", focused.attr( "id" ) );
  3216. }
  3217. // Highlight active parent menu item, if any
  3218. this.active
  3219. .parent()
  3220. .closest( ".ui-menu-item" )
  3221. .addClass( "ui-state-active" );
  3222. if ( event && event.type === "keydown" ) {
  3223. this._close();
  3224. } else {
  3225. this.timer = this._delay(function() {
  3226. this._close();
  3227. }, this.delay );
  3228. }
  3229. nested = item.children( ".ui-menu" );
  3230. if ( nested.length && event && ( /^mouse/.test( event.type ) ) ) {
  3231. this._startOpening(nested);
  3232. }
  3233. this.activeMenu = item.parent();
  3234. this._trigger( "focus", event, { item: item } );
  3235. },
  3236. _scrollIntoView: function( item ) {
  3237. var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
  3238. if ( this._hasScroll() ) {
  3239. borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0;
  3240. paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0;
  3241. offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
  3242. scroll = this.activeMenu.scrollTop();
  3243. elementHeight = this.activeMenu.height();
  3244. itemHeight = item.outerHeight();
  3245. if ( offset < 0 ) {
  3246. this.activeMenu.scrollTop( scroll + offset );
  3247. } else if ( offset + itemHeight > elementHeight ) {
  3248. this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
  3249. }
  3250. }
  3251. },
  3252. blur: function( event, fromFocus ) {
  3253. if ( !fromFocus ) {
  3254. clearTimeout( this.timer );
  3255. }
  3256. if ( !this.active ) {
  3257. return;
  3258. }
  3259. this.active.removeClass( "ui-state-focus" );
  3260. this.active = null;
  3261. this._trigger( "blur", event, { item: this.active } );
  3262. },
  3263. _startOpening: function( submenu ) {
  3264. clearTimeout( this.timer );
  3265. // Don't open if already open fixes a Firefox bug that caused a .5 pixel
  3266. // shift in the submenu position when mousing over the carat icon
  3267. if ( submenu.attr( "aria-hidden" ) !== "true" ) {
  3268. return;
  3269. }
  3270. this.timer = this._delay(function() {
  3271. this._close();
  3272. this._open( submenu );
  3273. }, this.delay );
  3274. },
  3275. _open: function( submenu ) {
  3276. var position = $.extend({
  3277. of: this.active
  3278. }, this.options.position );
  3279. clearTimeout( this.timer );
  3280. this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) )
  3281. .hide()
  3282. .attr( "aria-hidden", "true" );
  3283. submenu
  3284. .show()
  3285. .removeAttr( "aria-hidden" )
  3286. .attr( "aria-expanded", "true" )
  3287. .position( position );
  3288. },
  3289. collapseAll: function( event, all ) {
  3290. clearTimeout( this.timer );
  3291. this.timer = this._delay(function() {
  3292. // If we were passed an event, look for the submenu that contains the event
  3293. var currentMenu = all ? this.element :
  3294. $( event && event.target ).closest( this.element.find( ".ui-menu" ) );
  3295. // If we found no valid submenu ancestor, use the main menu to close all sub menus anyway
  3296. if ( !currentMenu.length ) {
  3297. currentMenu = this.element;
  3298. }
  3299. this._close( currentMenu );
  3300. this.blur( event );
  3301. this.activeMenu = currentMenu;
  3302. }, this.delay );
  3303. },
  3304. // With no arguments, closes the currently active menu - if nothing is active
  3305. // it closes all menus. If passed an argument, it will search for menus BELOW
  3306. _close: function( startMenu ) {
  3307. if ( !startMenu ) {
  3308. startMenu = this.active ? this.active.parent() : this.element;
  3309. }
  3310. startMenu
  3311. .find( ".ui-menu" )
  3312. .hide()
  3313. .attr( "aria-hidden", "true" )
  3314. .attr( "aria-expanded", "false" )
  3315. .end()
  3316. .find( ".ui-state-active" ).not( ".ui-state-focus" )
  3317. .removeClass( "ui-state-active" );
  3318. },
  3319. _closeOnDocumentClick: function( event ) {
  3320. return !$( event.target ).closest( ".ui-menu" ).length;
  3321. },
  3322. _isDivider: function( item ) {
  3323. // Match hyphen, em dash, en dash
  3324. return !/[^\-\u2014\u2013\s]/.test( item.text() );
  3325. },
  3326. collapse: function( event ) {
  3327. var newItem = this.active &&
  3328. this.active.parent().closest( ".ui-menu-item", this.element );
  3329. if ( newItem && newItem.length ) {
  3330. this._close();
  3331. this.focus( event, newItem );
  3332. }
  3333. },
  3334. expand: function( event ) {
  3335. var newItem = this.active &&
  3336. this.active
  3337. .children( ".ui-menu " )
  3338. .find( this.options.items )
  3339. .first();
  3340. if ( newItem && newItem.length ) {
  3341. this._open( newItem.parent() );
  3342. // Delay so Firefox will not hide activedescendant change in expanding submenu from AT
  3343. this._delay(function() {
  3344. this.focus( event, newItem );
  3345. });
  3346. }
  3347. },
  3348. next: function( event ) {
  3349. this._move( "next", "first", event );
  3350. },
  3351. previous: function( event ) {
  3352. this._move( "prev", "last", event );
  3353. },
  3354. isFirstItem: function() {
  3355. return this.active && !this.active.prevAll( ".ui-menu-item" ).length;
  3356. },
  3357. isLastItem: function() {
  3358. return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
  3359. },
  3360. _move: function( direction, filter, event ) {
  3361. var next;
  3362. if ( this.active ) {
  3363. if ( direction === "first" || direction === "last" ) {
  3364. next = this.active
  3365. [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
  3366. .eq( -1 );
  3367. } else {
  3368. next = this.active
  3369. [ direction + "All" ]( ".ui-menu-item" )
  3370. .eq( 0 );
  3371. }
  3372. }
  3373. if ( !next || !next.length || !this.active ) {
  3374. next = this.activeMenu.find( this.options.items )[ filter ]();
  3375. }
  3376. this.focus( event, next );
  3377. },
  3378. nextPage: function( event ) {
  3379. var item, base, height;
  3380. if ( !this.active ) {
  3381. this.next( event );
  3382. return;
  3383. }
  3384. if ( this.isLastItem() ) {
  3385. return;
  3386. }
  3387. if ( this._hasScroll() ) {
  3388. base = this.active.offset().top;
  3389. height = this.element.height();
  3390. this.active.nextAll( ".ui-menu-item" ).each(function() {
  3391. item = $( this );
  3392. return item.offset().top - base - height < 0;
  3393. });
  3394. this.focus( event, item );
  3395. } else {
  3396. this.focus( event, this.activeMenu.find( this.options.items )
  3397. [ !this.active ? "first" : "last" ]() );
  3398. }
  3399. },
  3400. previousPage: function( event ) {
  3401. var item, base, height;
  3402. if ( !this.active ) {
  3403. this.next( event );
  3404. return;
  3405. }
  3406. if ( this.isFirstItem() ) {
  3407. return;
  3408. }
  3409. if ( this._hasScroll() ) {
  3410. base = this.active.offset().top;
  3411. height = this.element.height();
  3412. this.active.prevAll( ".ui-menu-item" ).each(function() {
  3413. item = $( this );
  3414. return item.offset().top - base + height > 0;
  3415. });
  3416. this.focus( event, item );
  3417. } else {
  3418. this.focus( event, this.activeMenu.find( this.options.items ).first() );
  3419. }
  3420. },
  3421. _hasScroll: function() {
  3422. return this.element.outerHeight() < this.element.prop( "scrollHeight" );
  3423. },
  3424. select: function( event ) {
  3425. // TODO: It should never be possible to not have an active item at this
  3426. // point, but the tests don't trigger mouseenter before click.
  3427. this.active = this.active || $( event.target ).closest( ".ui-menu-item" );
  3428. var ui = { item: this.active };
  3429. if ( !this.active.has( ".ui-menu" ).length ) {
  3430. this.collapseAll( event, true );
  3431. }
  3432. this._trigger( "select", event, ui );
  3433. },
  3434. _filterMenuItems: function(character) {
  3435. var escapedCharacter = character.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" ),
  3436. regex = new RegExp( "^" + escapedCharacter, "i" );
  3437. return this.activeMenu
  3438. .find( this.options.items )
  3439. // Only match on items, not dividers or other content (#10571)
  3440. .filter( ".ui-menu-item" )
  3441. .filter(function() {
  3442. return regex.test( $.trim( $( this ).text() ) );
  3443. });
  3444. }
  3445. });
  3446. /*!
  3447. * jQuery UI Autocomplete 1.11.4
  3448. * http://jqueryui.com
  3449. *
  3450. * Copyright jQuery Foundation and other contributors
  3451. * Released under the MIT license.
  3452. * http://jquery.org/license
  3453. *
  3454. * http://api.jqueryui.com/autocomplete/
  3455. */
  3456. $.widget( "ui.autocomplete", {
  3457. version: "1.11.4",
  3458. defaultElement: "<input>",
  3459. options: {
  3460. appendTo: null,
  3461. autoFocus: false,
  3462. delay: 300,
  3463. minLength: 1,
  3464. position: {
  3465. my: "left top",
  3466. at: "left bottom",
  3467. collision: "none"
  3468. },
  3469. source: null,
  3470. // callbacks
  3471. change: null,
  3472. close: null,
  3473. focus: null,
  3474. open: null,
  3475. response: null,
  3476. search: null,
  3477. select: null
  3478. },
  3479. requestIndex: 0,
  3480. pending: 0,
  3481. _create: function() {
  3482. // Some browsers only repeat keydown events, not keypress events,
  3483. // so we use the suppressKeyPress flag to determine if we've already
  3484. // handled the keydown event. #7269
  3485. // Unfortunately the code for & in keypress is the same as the up arrow,
  3486. // so we use the suppressKeyPressRepeat flag to avoid handling keypress
  3487. // events when we know the keydown event was used to modify the
  3488. // search term. #7799
  3489. var suppressKeyPress, suppressKeyPressRepeat, suppressInput,
  3490. nodeName = this.element[ 0 ].nodeName.toLowerCase(),
  3491. isTextarea = nodeName === "textarea",
  3492. isInput = nodeName === "input";
  3493. this.isMultiLine =
  3494. // Textareas are always multi-line
  3495. isTextarea ? true :
  3496. // Inputs are always single-line, even if inside a contentEditable element
  3497. // IE also treats inputs as contentEditable
  3498. isInput ? false :
  3499. // All other element types are determined by whether or not they're contentEditable
  3500. this.element.prop( "isContentEditable" );
  3501. this.valueMethod = this.element[ isTextarea || isInput ? "val" : "text" ];
  3502. this.isNewMenu = true;
  3503. this.element
  3504. .addClass( "ui-autocomplete-input" )
  3505. .attr( "autocomplete", "off" );
  3506. this._on( this.element, {
  3507. keydown: function( event ) {
  3508. if ( this.element.prop( "readOnly" ) ) {
  3509. suppressKeyPress = true;
  3510. suppressInput = true;
  3511. suppressKeyPressRepeat = true;
  3512. return;
  3513. }
  3514. suppressKeyPress = false;
  3515. suppressInput = false;
  3516. suppressKeyPressRepeat = false;
  3517. var keyCode = $.ui.keyCode;
  3518. switch ( event.keyCode ) {
  3519. case keyCode.PAGE_UP:
  3520. suppressKeyPress = true;
  3521. this._move( "previousPage", event );
  3522. break;
  3523. case keyCode.PAGE_DOWN:
  3524. suppressKeyPress = true;
  3525. this._move( "nextPage", event );
  3526. break;
  3527. case keyCode.UP:
  3528. suppressKeyPress = true;
  3529. this._keyEvent( "previous", event );
  3530. break;
  3531. case keyCode.DOWN:
  3532. suppressKeyPress = true;
  3533. this._keyEvent( "next", event );
  3534. break;
  3535. case keyCode.ENTER:
  3536. // when menu is open and has focus
  3537. if ( this.menu.active ) {
  3538. // #6055 - Opera still allows the keypress to occur
  3539. // which causes forms to submit
  3540. suppressKeyPress = true;
  3541. event.preventDefault();
  3542. this.menu.select( event );
  3543. }
  3544. break;
  3545. case keyCode.TAB:
  3546. if ( this.menu.active ) {
  3547. this.menu.select( event );
  3548. }
  3549. break;
  3550. case keyCode.ESCAPE:
  3551. if ( this.menu.element.is( ":visible" ) ) {
  3552. if ( !this.isMultiLine ) {
  3553. this._value( this.term );
  3554. }
  3555. this.close( event );
  3556. // Different browsers have different default behavior for escape
  3557. // Single press can mean undo or clear
  3558. // Double press in IE means clear the whole form
  3559. event.preventDefault();
  3560. }
  3561. break;
  3562. default:
  3563. suppressKeyPressRepeat = true;
  3564. // search timeout should be triggered before the input value is changed
  3565. this._searchTimeout( event );
  3566. break;
  3567. }
  3568. },
  3569. keypress: function( event ) {
  3570. if ( suppressKeyPress ) {
  3571. suppressKeyPress = false;
  3572. if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
  3573. event.preventDefault();
  3574. }
  3575. return;
  3576. }
  3577. if ( suppressKeyPressRepeat ) {
  3578. return;
  3579. }
  3580. // replicate some key handlers to allow them to repeat in Firefox and Opera
  3581. var keyCode = $.ui.keyCode;
  3582. switch ( event.keyCode ) {
  3583. case keyCode.PAGE_UP:
  3584. this._move( "previousPage", event );
  3585. break;
  3586. case keyCode.PAGE_DOWN:
  3587. this._move( "nextPage", event );
  3588. break;
  3589. case keyCode.UP:
  3590. this._keyEvent( "previous", event );
  3591. break;
  3592. case keyCode.DOWN:
  3593. this._keyEvent( "next", event );
  3594. break;
  3595. }
  3596. },
  3597. input: function( event ) {
  3598. if ( suppressInput ) {
  3599. suppressInput = false;
  3600. event.preventDefault();
  3601. return;
  3602. }
  3603. this._searchTimeout( event );
  3604. },
  3605. focus: function() {
  3606. this.selectedItem = null;
  3607. this.previous = this._value();
  3608. },
  3609. blur: function( event ) {
  3610. if ( this.cancelBlur ) {
  3611. delete this.cancelBlur;
  3612. return;
  3613. }
  3614. clearTimeout( this.searching );
  3615. this.close( event );
  3616. this._change( event );
  3617. }
  3618. });
  3619. this._initSource();
  3620. this.menu = $( "<ul>" )
  3621. .addClass( "ui-autocomplete ui-front" )
  3622. .appendTo( this._appendTo() )
  3623. .menu({
  3624. // disable ARIA support, the live region takes care of that
  3625. role: null
  3626. })
  3627. .hide()
  3628. .menu( "instance" );
  3629. this._on( this.menu.element, {
  3630. mousedown: function( event ) {
  3631. // prevent moving focus out of the text field
  3632. event.preventDefault();
  3633. // IE doesn't prevent moving focus even with event.preventDefault()
  3634. // so we set a flag to know when we should ignore the blur event
  3635. this.cancelBlur = true;
  3636. this._delay(function() {
  3637. delete this.cancelBlur;
  3638. });
  3639. // clicking on the scrollbar causes focus to shift to the body
  3640. // but we can't detect a mouseup or a click immediately afterward
  3641. // so we have to track the next mousedown and close the menu if
  3642. // the user clicks somewhere outside of the autocomplete
  3643. var menuElement = this.menu.element[ 0 ];
  3644. if ( !$( event.target ).closest( ".ui-menu-item" ).length ) {
  3645. this._delay(function() {
  3646. var that = this;
  3647. this.document.one( "mousedown", function( event ) {
  3648. if ( event.target !== that.element[ 0 ] &&
  3649. event.target !== menuElement &&
  3650. !$.contains( menuElement, event.target ) ) {
  3651. that.close();
  3652. }
  3653. });
  3654. });
  3655. }
  3656. },
  3657. menufocus: function( event, ui ) {
  3658. var label, item;
  3659. // support: Firefox
  3660. // Prevent accidental activation of menu items in Firefox (#7024 #9118)
  3661. if ( this.isNewMenu ) {
  3662. this.isNewMenu = false;
  3663. if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) {
  3664. this.menu.blur();
  3665. this.document.one( "mousemove", function() {
  3666. $( event.target ).trigger( event.originalEvent );
  3667. });
  3668. return;
  3669. }
  3670. }
  3671. item = ui.item.data( "ui-autocomplete-item" );
  3672. if ( false !== this._trigger( "focus", event, { item: item } ) ) {
  3673. // use value to match what will end up in the input, if it was a key event
  3674. if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
  3675. this._value( item.value );
  3676. }
  3677. }
  3678. // Announce the value in the liveRegion
  3679. label = ui.item.attr( "aria-label" ) || item.value;
  3680. if ( label && $.trim( label ).length ) {
  3681. this.liveRegion.children().hide();
  3682. $( "<div>" ).text( label ).appendTo( this.liveRegion );
  3683. }
  3684. },
  3685. menuselect: function( event, ui ) {
  3686. var item = ui.item.data( "ui-autocomplete-item" ),
  3687. previous = this.previous;
  3688. // only trigger when focus was lost (click on menu)
  3689. if ( this.element[ 0 ] !== this.document[ 0 ].activeElement ) {
  3690. this.element.focus();
  3691. this.previous = previous;
  3692. // #6109 - IE triggers two focus events and the second
  3693. // is asynchronous, so we need to reset the previous
  3694. // term synchronously and asynchronously :-(
  3695. this._delay(function() {
  3696. this.previous = previous;
  3697. this.selectedItem = item;
  3698. });
  3699. }
  3700. if ( false !== this._trigger( "select", event, { item: item } ) ) {
  3701. this._value( item.value );
  3702. }
  3703. // reset the term after the select event
  3704. // this allows custom select handling to work properly
  3705. this.term = this._value();
  3706. this.close( event );
  3707. this.selectedItem = item;
  3708. }
  3709. });
  3710. this.liveRegion = $( "<span>", {
  3711. role: "status",
  3712. "aria-live": "assertive",
  3713. "aria-relevant": "additions"
  3714. })
  3715. .addClass( "ui-helper-hidden-accessible" )
  3716. .appendTo( this.document[ 0 ].body );
  3717. // turning off autocomplete prevents the browser from remembering the
  3718. // value when navigating through history, so we re-enable autocomplete
  3719. // if the page is unloaded before the widget is destroyed. #7790
  3720. this._on( this.window, {
  3721. beforeunload: function() {
  3722. this.element.removeAttr( "autocomplete" );
  3723. }
  3724. });
  3725. },
  3726. _destroy: function() {
  3727. clearTimeout( this.searching );
  3728. this.element
  3729. .removeClass( "ui-autocomplete-input" )
  3730. .removeAttr( "autocomplete" );
  3731. this.menu.element.remove();
  3732. this.liveRegion.remove();
  3733. },
  3734. _setOption: function( key, value ) {
  3735. this._super( key, value );
  3736. if ( key === "source" ) {
  3737. this._initSource();
  3738. }
  3739. if ( key === "appendTo" ) {
  3740. this.menu.element.appendTo( this._appendTo() );
  3741. }
  3742. if ( key === "disabled" && value && this.xhr ) {
  3743. this.xhr.abort();
  3744. }
  3745. },
  3746. _appendTo: function() {
  3747. var element = this.options.appendTo;
  3748. if ( element ) {
  3749. element = element.jquery || element.nodeType ?
  3750. $( element ) :
  3751. this.document.find( element ).eq( 0 );
  3752. }
  3753. if ( !element || !element[ 0 ] ) {
  3754. element = this.element.closest( ".ui-front" );
  3755. }
  3756. if ( !element.length ) {
  3757. element = this.document[ 0 ].body;
  3758. }
  3759. return element;
  3760. },
  3761. _initSource: function() {
  3762. var array, url,
  3763. that = this;
  3764. if ( $.isArray( this.options.source ) ) {
  3765. array = this.options.source;
  3766. this.source = function( request, response ) {
  3767. response( $.ui.autocomplete.filter( array, request.term ) );
  3768. };
  3769. } else if ( typeof this.options.source === "string" ) {
  3770. url = this.options.source;
  3771. this.source = function( request, response ) {
  3772. if ( that.xhr ) {
  3773. that.xhr.abort();
  3774. }
  3775. that.xhr = $.ajax({
  3776. url: url,
  3777. data: request,
  3778. dataType: "json",
  3779. success: function( data ) {
  3780. response( data );
  3781. },
  3782. error: function() {
  3783. response([]);
  3784. }
  3785. });
  3786. };
  3787. } else {
  3788. this.source = this.options.source;
  3789. }
  3790. },
  3791. _searchTimeout: function( event ) {
  3792. clearTimeout( this.searching );
  3793. this.searching = this._delay(function() {
  3794. // Search if the value has changed, or if the user retypes the same value (see #7434)
  3795. var equalValues = this.term === this._value(),
  3796. menuVisible = this.menu.element.is( ":visible" ),
  3797. modifierKey = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
  3798. if ( !equalValues || ( equalValues && !menuVisible && !modifierKey ) ) {
  3799. this.selectedItem = null;
  3800. this.search( null, event );
  3801. }
  3802. }, this.options.delay );
  3803. },
  3804. search: function( value, event ) {
  3805. value = value != null ? value : this._value();
  3806. // always save the actual value, not the one passed as an argument
  3807. this.term = this._value();
  3808. if ( value.length < this.options.minLength ) {
  3809. return this.close( event );
  3810. }
  3811. if ( this._trigger( "search", event ) === false ) {
  3812. return;
  3813. }
  3814. return this._search( value );
  3815. },
  3816. _search: function( value ) {
  3817. this.pending++;
  3818. this.element.addClass( "ui-autocomplete-loading" );
  3819. this.cancelSearch = false;
  3820. this.source( { term: value }, this._response() );
  3821. },
  3822. _response: function() {
  3823. var index = ++this.requestIndex;
  3824. return $.proxy(function( content ) {
  3825. if ( index === this.requestIndex ) {
  3826. this.__response( content );
  3827. }
  3828. this.pending--;
  3829. if ( !this.pending ) {
  3830. this.element.removeClass( "ui-autocomplete-loading" );
  3831. }
  3832. }, this );
  3833. },
  3834. __response: function( content ) {
  3835. if ( content ) {
  3836. content = this._normalize( content );
  3837. }
  3838. this._trigger( "response", null, { content: content } );
  3839. if ( !this.options.disabled && content && content.length && !this.cancelSearch ) {
  3840. this._suggest( content );
  3841. this._trigger( "open" );
  3842. } else {
  3843. // use ._close() instead of .close() so we don't cancel future searches
  3844. this._close();
  3845. }
  3846. },
  3847. close: function( event ) {
  3848. this.cancelSearch = true;
  3849. this._close( event );
  3850. },
  3851. _close: function( event ) {
  3852. if ( this.menu.element.is( ":visible" ) ) {
  3853. this.menu.element.hide();
  3854. this.menu.blur();
  3855. this.isNewMenu = true;
  3856. this._trigger( "close", event );
  3857. }
  3858. },
  3859. _change: function( event ) {
  3860. if ( this.previous !== this._value() ) {
  3861. this._trigger( "change", event, { item: this.selectedItem } );
  3862. }
  3863. },
  3864. _normalize: function( items ) {
  3865. // assume all items have the right format when the first item is complete
  3866. if ( items.length && items[ 0 ].label && items[ 0 ].value ) {
  3867. return items;
  3868. }
  3869. return $.map( items, function( item ) {
  3870. if ( typeof item === "string" ) {
  3871. return {
  3872. label: item,
  3873. value: item
  3874. };
  3875. }
  3876. return $.extend( {}, item, {
  3877. label: item.label || item.value,
  3878. value: item.value || item.label
  3879. });
  3880. });
  3881. },
  3882. _suggest: function( items ) {
  3883. var ul = this.menu.element.empty();
  3884. this._renderMenu( ul, items );
  3885. this.isNewMenu = true;
  3886. this.menu.refresh();
  3887. // size and position menu
  3888. ul.show();
  3889. this._resizeMenu();
  3890. ul.position( $.extend({
  3891. of: this.element
  3892. }, this.options.position ) );
  3893. if ( this.options.autoFocus ) {
  3894. this.menu.next();
  3895. }
  3896. },
  3897. _resizeMenu: function() {
  3898. var ul = this.menu.element;
  3899. ul.outerWidth( Math.max(
  3900. // Firefox wraps long text (possibly a rounding bug)
  3901. // so we add 1px to avoid the wrapping (#7513)
  3902. ul.width( "" ).outerWidth() + 1,
  3903. this.element.outerWidth()
  3904. ) );
  3905. },
  3906. _renderMenu: function( ul, items ) {
  3907. var that = this;
  3908. $.each( items, function( index, item ) {
  3909. that._renderItemData( ul, item );
  3910. });
  3911. },
  3912. _renderItemData: function( ul, item ) {
  3913. return this._renderItem( ul, item ).data( "ui-autocomplete-item", item );
  3914. },
  3915. _renderItem: function( ul, item ) {
  3916. return $( "<li>" ).text( item.label ).appendTo( ul );
  3917. },
  3918. _move: function( direction, event ) {
  3919. if ( !this.menu.element.is( ":visible" ) ) {
  3920. this.search( null, event );
  3921. return;
  3922. }
  3923. if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
  3924. this.menu.isLastItem() && /^next/.test( direction ) ) {
  3925. if ( !this.isMultiLine ) {
  3926. this._value( this.term );
  3927. }
  3928. this.menu.blur();
  3929. return;
  3930. }
  3931. this.menu[ direction ]( event );
  3932. },
  3933. widget: function() {
  3934. return this.menu.element;
  3935. },
  3936. _value: function() {
  3937. return this.valueMethod.apply( this.element, arguments );
  3938. },
  3939. _keyEvent: function( keyEvent, event ) {
  3940. if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
  3941. this._move( keyEvent, event );
  3942. // prevents moving cursor to beginning/end of the text field in some browsers
  3943. event.preventDefault();
  3944. }
  3945. }
  3946. });
  3947. $.extend( $.ui.autocomplete, {
  3948. escapeRegex: function( value ) {
  3949. return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
  3950. },
  3951. filter: function( array, term ) {
  3952. var matcher = new RegExp( $.ui.autocomplete.escapeRegex( term ), "i" );
  3953. return $.grep( array, function( value ) {
  3954. return matcher.test( value.label || value.value || value );
  3955. });
  3956. }
  3957. });
  3958. // live region extension, adding a `messages` option
  3959. // NOTE: This is an experimental API. We are still investigating
  3960. // a full solution for string manipulation and internationalization.
  3961. $.widget( "ui.autocomplete", $.ui.autocomplete, {
  3962. options: {
  3963. messages: {
  3964. noResults: "No search results.",
  3965. results: function( amount ) {
  3966. return amount + ( amount > 1 ? " results are" : " result is" ) +
  3967. " available, use up and down arrow keys to navigate.";
  3968. }
  3969. }
  3970. },
  3971. __response: function( content ) {
  3972. var message;
  3973. this._superApply( arguments );
  3974. if ( this.options.disabled || this.cancelSearch ) {
  3975. return;
  3976. }
  3977. if ( content && content.length ) {
  3978. message = this.options.messages.results( content.length );
  3979. } else {
  3980. message = this.options.messages.noResults;
  3981. }
  3982. this.liveRegion.children().hide();
  3983. $( "<div>" ).text( message ).appendTo( this.liveRegion );
  3984. }
  3985. });
  3986. var autocomplete = $.ui.autocomplete;
  3987. /*!
  3988. * jQuery UI Button 1.11.4
  3989. * http://jqueryui.com
  3990. *
  3991. * Copyright jQuery Foundation and other contributors
  3992. * Released under the MIT license.
  3993. * http://jquery.org/license
  3994. *
  3995. * http://api.jqueryui.com/button/
  3996. */
  3997. var lastActive,
  3998. baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
  3999. typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only",
  4000. formResetHandler = function() {
  4001. var form = $( this );
  4002. setTimeout(function() {
  4003. form.find( ":ui-button" ).button( "refresh" );
  4004. }, 1 );
  4005. },
  4006. radioGroup = function( radio ) {
  4007. var name = radio.name,
  4008. form = radio.form,
  4009. radios = $( [] );
  4010. if ( name ) {
  4011. name = name.replace( /'/g, "\\'" );
  4012. if ( form ) {
  4013. radios = $( form ).find( "[name='" + name + "'][type=radio]" );
  4014. } else {
  4015. radios = $( "[name='" + name + "'][type=radio]", radio.ownerDocument )
  4016. .filter(function() {
  4017. return !this.form;
  4018. });
  4019. }
  4020. }
  4021. return radios;
  4022. };
  4023. $.widget( "ui.button", {
  4024. version: "1.11.4",
  4025. defaultElement: "<button>",
  4026. options: {
  4027. disabled: null,
  4028. text: true,
  4029. label: null,
  4030. icons: {
  4031. primary: null,
  4032. secondary: null
  4033. }
  4034. },
  4035. _create: function() {
  4036. this.element.closest( "form" )
  4037. .unbind( "reset" + this.eventNamespace )
  4038. .bind( "reset" + this.eventNamespace, formResetHandler );
  4039. if ( typeof this.options.disabled !== "boolean" ) {
  4040. this.options.disabled = !!this.element.prop( "disabled" );
  4041. } else {
  4042. this.element.prop( "disabled", this.options.disabled );
  4043. }
  4044. this._determineButtonType();
  4045. this.hasTitle = !!this.buttonElement.attr( "title" );
  4046. var that = this,
  4047. options = this.options,
  4048. toggleButton = this.type === "checkbox" || this.type === "radio",
  4049. activeClass = !toggleButton ? "ui-state-active" : "";
  4050. if ( options.label === null ) {
  4051. options.label = (this.type === "input" ? this.buttonElement.val() : this.buttonElement.html());
  4052. }
  4053. this._hoverable( this.buttonElement );
  4054. this.buttonElement
  4055. .addClass( baseClasses )
  4056. .attr( "role", "button" )
  4057. .bind( "mouseenter" + this.eventNamespace, function() {
  4058. if ( options.disabled ) {
  4059. return;
  4060. }
  4061. if ( this === lastActive ) {
  4062. $( this ).addClass( "ui-state-active" );
  4063. }
  4064. })
  4065. .bind( "mouseleave" + this.eventNamespace, function() {
  4066. if ( options.disabled ) {
  4067. return;
  4068. }
  4069. $( this ).removeClass( activeClass );
  4070. })
  4071. .bind( "click" + this.eventNamespace, function( event ) {
  4072. if ( options.disabled ) {
  4073. event.preventDefault();
  4074. event.stopImmediatePropagation();
  4075. }
  4076. });
  4077. // Can't use _focusable() because the element that receives focus
  4078. // and the element that gets the ui-state-focus class are different
  4079. this._on({
  4080. focus: function() {
  4081. this.buttonElement.addClass( "ui-state-focus" );
  4082. },
  4083. blur: function() {
  4084. this.buttonElement.removeClass( "ui-state-focus" );
  4085. }
  4086. });
  4087. if ( toggleButton ) {
  4088. this.element.bind( "change" + this.eventNamespace, function() {
  4089. that.refresh();
  4090. });
  4091. }
  4092. if ( this.type === "checkbox" ) {
  4093. this.buttonElement.bind( "click" + this.eventNamespace, function() {
  4094. if ( options.disabled ) {
  4095. return false;
  4096. }
  4097. });
  4098. } else if ( this.type === "radio" ) {
  4099. this.buttonElement.bind( "click" + this.eventNamespace, function() {
  4100. if ( options.disabled ) {
  4101. return false;
  4102. }
  4103. $( this ).addClass( "ui-state-active" );
  4104. that.buttonElement.attr( "aria-pressed", "true" );
  4105. var radio = that.element[ 0 ];
  4106. radioGroup( radio )
  4107. .not( radio )
  4108. .map(function() {
  4109. return $( this ).button( "widget" )[ 0 ];
  4110. })
  4111. .removeClass( "ui-state-active" )
  4112. .attr( "aria-pressed", "false" );
  4113. });
  4114. } else {
  4115. this.buttonElement
  4116. .bind( "mousedown" + this.eventNamespace, function() {
  4117. if ( options.disabled ) {
  4118. return false;
  4119. }
  4120. $( this ).addClass( "ui-state-active" );
  4121. lastActive = this;
  4122. that.document.one( "mouseup", function() {
  4123. lastActive = null;
  4124. });
  4125. })
  4126. .bind( "mouseup" + this.eventNamespace, function() {
  4127. if ( options.disabled ) {
  4128. return false;
  4129. }
  4130. $( this ).removeClass( "ui-state-active" );
  4131. })
  4132. .bind( "keydown" + this.eventNamespace, function(event) {
  4133. if ( options.disabled ) {
  4134. return false;
  4135. }
  4136. if ( event.keyCode === $.ui.keyCode.SPACE || event.keyCode === $.ui.keyCode.ENTER ) {
  4137. $( this ).addClass( "ui-state-active" );
  4138. }
  4139. })
  4140. // see #8559, we bind to blur here in case the button element loses
  4141. // focus between keydown and keyup, it would be left in an "active" state
  4142. .bind( "keyup" + this.eventNamespace + " blur" + this.eventNamespace, function() {
  4143. $( this ).removeClass( "ui-state-active" );
  4144. });
  4145. if ( this.buttonElement.is("a") ) {
  4146. this.buttonElement.keyup(function(event) {
  4147. if ( event.keyCode === $.ui.keyCode.SPACE ) {
  4148. // TODO pass through original event correctly (just as 2nd argument doesn't work)
  4149. $( this ).click();
  4150. }
  4151. });
  4152. }
  4153. }
  4154. this._setOption( "disabled", options.disabled );
  4155. this._resetButton();
  4156. },
  4157. _determineButtonType: function() {
  4158. var ancestor, labelSelector, checked;
  4159. if ( this.element.is("[type=checkbox]") ) {
  4160. this.type = "checkbox";
  4161. } else if ( this.element.is("[type=radio]") ) {
  4162. this.type = "radio";
  4163. } else if ( this.element.is("input") ) {
  4164. this.type = "input";
  4165. } else {
  4166. this.type = "button";
  4167. }
  4168. if ( this.type === "checkbox" || this.type === "radio" ) {
  4169. // we don't search against the document in case the element
  4170. // is disconnected from the DOM
  4171. ancestor = this.element.parents().last();
  4172. labelSelector = "label[for='" + this.element.attr("id") + "']";
  4173. this.buttonElement = ancestor.find( labelSelector );
  4174. if ( !this.buttonElement.length ) {
  4175. ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings();
  4176. this.buttonElement = ancestor.filter( labelSelector );
  4177. if ( !this.buttonElement.length ) {
  4178. this.buttonElement = ancestor.find( labelSelector );
  4179. }
  4180. }
  4181. this.element.addClass( "ui-helper-hidden-accessible" );
  4182. checked = this.element.is( ":checked" );
  4183. if ( checked ) {
  4184. this.buttonElement.addClass( "ui-state-active" );
  4185. }
  4186. this.buttonElement.prop( "aria-pressed", checked );
  4187. } else {
  4188. this.buttonElement = this.element;
  4189. }
  4190. },
  4191. widget: function() {
  4192. return this.buttonElement;
  4193. },
  4194. _destroy: function() {
  4195. this.element
  4196. .removeClass( "ui-helper-hidden-accessible" );
  4197. this.buttonElement
  4198. .removeClass( baseClasses + " ui-state-active " + typeClasses )
  4199. .removeAttr( "role" )
  4200. .removeAttr( "aria-pressed" )
  4201. .html( this.buttonElement.find(".ui-button-text").html() );
  4202. if ( !this.hasTitle ) {
  4203. this.buttonElement.removeAttr( "title" );
  4204. }
  4205. },
  4206. _setOption: function( key, value ) {
  4207. this._super( key, value );
  4208. if ( key === "disabled" ) {
  4209. this.widget().toggleClass( "ui-state-disabled", !!value );
  4210. this.element.prop( "disabled", !!value );
  4211. if ( value ) {
  4212. if ( this.type === "checkbox" || this.type === "radio" ) {
  4213. this.buttonElement.removeClass( "ui-state-focus" );
  4214. } else {
  4215. this.buttonElement.removeClass( "ui-state-focus ui-state-active" );
  4216. }
  4217. }
  4218. return;
  4219. }
  4220. this._resetButton();
  4221. },
  4222. refresh: function() {
  4223. //See #8237 & #8828
  4224. var isDisabled = this.element.is( "input, button" ) ? this.element.is( ":disabled" ) : this.element.hasClass( "ui-button-disabled" );
  4225. if ( isDisabled !== this.options.disabled ) {
  4226. this._setOption( "disabled", isDisabled );
  4227. }
  4228. if ( this.type === "radio" ) {
  4229. radioGroup( this.element[0] ).each(function() {
  4230. if ( $( this ).is( ":checked" ) ) {
  4231. $( this ).button( "widget" )
  4232. .addClass( "ui-state-active" )
  4233. .attr( "aria-pressed", "true" );
  4234. } else {
  4235. $( this ).button( "widget" )
  4236. .removeClass( "ui-state-active" )
  4237. .attr( "aria-pressed", "false" );
  4238. }
  4239. });
  4240. } else if ( this.type === "checkbox" ) {
  4241. if ( this.element.is( ":checked" ) ) {
  4242. this.buttonElement
  4243. .addClass( "ui-state-active" )
  4244. .attr( "aria-pressed", "true" );
  4245. } else {
  4246. this.buttonElement
  4247. .removeClass( "ui-state-active" )
  4248. .attr( "aria-pressed", "false" );
  4249. }
  4250. }
  4251. },
  4252. _resetButton: function() {
  4253. if ( this.type === "input" ) {
  4254. if ( this.options.label ) {
  4255. this.element.val( this.options.label );
  4256. }
  4257. return;
  4258. }
  4259. var buttonElement = this.buttonElement.removeClass( typeClasses ),
  4260. buttonText = $( "<span></span>", this.document[0] )
  4261. .addClass( "ui-button-text" )
  4262. .html( this.options.label )
  4263. .appendTo( buttonElement.empty() )
  4264. .text(),
  4265. icons = this.options.icons,
  4266. multipleIcons = icons.primary && icons.secondary,
  4267. buttonClasses = [];
  4268. if ( icons.primary || icons.secondary ) {
  4269. if ( this.options.text ) {
  4270. buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) );
  4271. }
  4272. if ( icons.primary ) {
  4273. buttonElement.prepend( "<span class='ui-button-icon-primary ui-icon " + icons.primary + "'></span>" );
  4274. }
  4275. if ( icons.secondary ) {
  4276. buttonElement.append( "<span class='ui-button-icon-secondary ui-icon " + icons.secondary + "'></span>" );
  4277. }
  4278. if ( !this.options.text ) {
  4279. buttonClasses.push( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" );
  4280. if ( !this.hasTitle ) {
  4281. buttonElement.attr( "title", $.trim( buttonText ) );
  4282. }
  4283. }
  4284. } else {
  4285. buttonClasses.push( "ui-button-text-only" );
  4286. }
  4287. buttonElement.addClass( buttonClasses.join( " " ) );
  4288. }
  4289. });
  4290. $.widget( "ui.buttonset", {
  4291. version: "1.11.4",
  4292. options: {
  4293. items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(ui-button)"
  4294. },
  4295. _create: function() {
  4296. this.element.addClass( "ui-buttonset" );
  4297. },
  4298. _init: function() {
  4299. this.refresh();
  4300. },
  4301. _setOption: function( key, value ) {
  4302. if ( key === "disabled" ) {
  4303. this.buttons.button( "option", key, value );
  4304. }
  4305. this._super( key, value );
  4306. },
  4307. refresh: function() {
  4308. var rtl = this.element.css( "direction" ) === "rtl",
  4309. allButtons = this.element.find( this.options.items ),
  4310. existingButtons = allButtons.filter( ":ui-button" );
  4311. // Initialize new buttons
  4312. allButtons.not( ":ui-button" ).button();
  4313. // Refresh existing buttons
  4314. existingButtons.button( "refresh" );
  4315. this.buttons = allButtons
  4316. .map(function() {
  4317. return $( this ).button( "widget" )[ 0 ];
  4318. })
  4319. .removeClass( "ui-corner-all ui-corner-left ui-corner-right" )
  4320. .filter( ":first" )
  4321. .addClass( rtl ? "ui-corner-right" : "ui-corner-left" )
  4322. .end()
  4323. .filter( ":last" )
  4324. .addClass( rtl ? "ui-corner-left" : "ui-corner-right" )
  4325. .end()
  4326. .end();
  4327. },
  4328. _destroy: function() {
  4329. this.element.removeClass( "ui-buttonset" );
  4330. this.buttons
  4331. .map(function() {
  4332. return $( this ).button( "widget" )[ 0 ];
  4333. })
  4334. .removeClass( "ui-corner-left ui-corner-right" )
  4335. .end()
  4336. .button( "destroy" );
  4337. }
  4338. });
  4339. var button = $.ui.button;
  4340. /*!
  4341. * jQuery UI Datepicker 1.11.4
  4342. * http://jqueryui.com
  4343. *
  4344. * Copyright jQuery Foundation and other contributors
  4345. * Released under the MIT license.
  4346. * http://jquery.org/license
  4347. *
  4348. * http://api.jqueryui.com/datepicker/
  4349. */
  4350. $.extend($.ui, { datepicker: { version: "1.11.4" } });
  4351. var datepicker_instActive;
  4352. function datepicker_getZindex( elem ) {
  4353. var position, value;
  4354. while ( elem.length && elem[ 0 ] !== document ) {
  4355. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  4356. // This makes behavior of this function consistent across browsers
  4357. // WebKit always returns auto if the element is positioned
  4358. position = elem.css( "position" );
  4359. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  4360. // IE returns 0 when zIndex is not specified
  4361. // other browsers return a string
  4362. // we ignore the case of nested elements with an explicit value of 0
  4363. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  4364. value = parseInt( elem.css( "zIndex" ), 10 );
  4365. if ( !isNaN( value ) && value !== 0 ) {
  4366. return value;
  4367. }
  4368. }
  4369. elem = elem.parent();
  4370. }
  4371. return 0;
  4372. }
  4373. /* Date picker manager.
  4374. Use the singleton instance of this class, $.datepicker, to interact with the date picker.
  4375. Settings for (groups of) date pickers are maintained in an instance object,
  4376. allowing multiple different settings on the same page. */
  4377. function Datepicker() {
  4378. this._curInst = null; // The current instance in use
  4379. this._keyEvent = false; // If the last event was a key event
  4380. this._disabledInputs = []; // List of date picker inputs that have been disabled
  4381. this._datepickerShowing = false; // True if the popup picker is showing , false if not
  4382. this._inDialog = false; // True if showing within a "dialog", false if not
  4383. this._mainDivId = "ui-datepicker-div"; // The ID of the main datepicker division
  4384. this._inlineClass = "ui-datepicker-inline"; // The name of the inline marker class
  4385. this._appendClass = "ui-datepicker-append"; // The name of the append marker class
  4386. this._triggerClass = "ui-datepicker-trigger"; // The name of the trigger marker class
  4387. this._dialogClass = "ui-datepicker-dialog"; // The name of the dialog marker class
  4388. this._disableClass = "ui-datepicker-disabled"; // The name of the disabled covering marker class
  4389. this._unselectableClass = "ui-datepicker-unselectable"; // The name of the unselectable cell marker class
  4390. this._currentClass = "ui-datepicker-current-day"; // The name of the current day marker class
  4391. this._dayOverClass = "ui-datepicker-days-cell-over"; // The name of the day hover marker class
  4392. this.regional = []; // Available regional settings, indexed by language code
  4393. this.regional[""] = { // Default regional settings
  4394. closeText: "Done", // Display text for close link
  4395. prevText: "Prev", // Display text for previous month link
  4396. nextText: "Next", // Display text for next month link
  4397. currentText: "Today", // Display text for current month link
  4398. monthNames: ["January","February","March","April","May","June",
  4399. "July","August","September","October","November","December"], // Names of months for drop-down and formatting
  4400. monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], // For formatting
  4401. dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], // For formatting
  4402. dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], // For formatting
  4403. dayNamesMin: ["Su","Mo","Tu","We","Th","Fr","Sa"], // Column headings for days starting at Sunday
  4404. weekHeader: "Wk", // Column header for week of the year
  4405. dateFormat: "mm/dd/yy", // See format options on parseDate
  4406. firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
  4407. isRTL: false, // True if right-to-left language, false if left-to-right
  4408. showMonthAfterYear: false, // True if the year select precedes month, false for month then year
  4409. yearSuffix: "" // Additional text to append to the year in the month headers
  4410. };
  4411. this._defaults = { // Global defaults for all the date picker instances
  4412. showOn: "focus", // "focus" for popup on focus,
  4413. // "button" for trigger button, or "both" for either
  4414. showAnim: "fadeIn", // Name of jQuery animation for popup
  4415. showOptions: {}, // Options for enhanced animations
  4416. defaultDate: null, // Used when field is blank: actual date,
  4417. // +/-number for offset from today, null for today
  4418. appendText: "", // Display text following the input box, e.g. showing the format
  4419. buttonText: "...", // Text for trigger button
  4420. buttonImage: "", // URL for trigger button image
  4421. buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
  4422. hideIfNoPrevNext: false, // True to hide next/previous month links
  4423. // if not applicable, false to just disable them
  4424. navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
  4425. gotoCurrent: false, // True if today link goes back to current selection instead
  4426. changeMonth: false, // True if month can be selected directly, false if only prev/next
  4427. changeYear: false, // True if year can be selected directly, false if only prev/next
  4428. yearRange: "c-10:c+10", // Range of years to display in drop-down,
  4429. // either relative to today's year (-nn:+nn), relative to currently displayed year
  4430. // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
  4431. showOtherMonths: false, // True to show dates in other months, false to leave blank
  4432. selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
  4433. showWeek: false, // True to show week of the year, false to not show it
  4434. calculateWeek: this.iso8601Week, // How to calculate the week of the year,
  4435. // takes a Date and returns the number of the week for it
  4436. shortYearCutoff: "+10", // Short year values < this are in the current century,
  4437. // > this are in the previous century,
  4438. // string value starting with "+" for current year + value
  4439. minDate: null, // The earliest selectable date, or null for no limit
  4440. maxDate: null, // The latest selectable date, or null for no limit
  4441. duration: "fast", // Duration of display/closure
  4442. beforeShowDay: null, // Function that takes a date and returns an array with
  4443. // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or "",
  4444. // [2] = cell title (optional), e.g. $.datepicker.noWeekends
  4445. beforeShow: null, // Function that takes an input field and
  4446. // returns a set of custom settings for the date picker
  4447. onSelect: null, // Define a callback function when a date is selected
  4448. onChangeMonthYear: null, // Define a callback function when the month or year is changed
  4449. onClose: null, // Define a callback function when the datepicker is closed
  4450. numberOfMonths: 1, // Number of months to show at a time
  4451. showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
  4452. stepMonths: 1, // Number of months to step back/forward
  4453. stepBigMonths: 12, // Number of months to step back/forward for the big links
  4454. altField: "", // Selector for an alternate field to store selected dates into
  4455. altFormat: "", // The date format to use for the alternate field
  4456. constrainInput: true, // The input is constrained by the current date format
  4457. showButtonPanel: false, // True to show button panel, false to not show it
  4458. autoSize: false, // True to size the input for the date format, false to leave as is
  4459. disabled: false // The initial disabled state
  4460. };
  4461. $.extend(this._defaults, this.regional[""]);
  4462. this.regional.en = $.extend( true, {}, this.regional[ "" ]);
  4463. this.regional[ "en-US" ] = $.extend( true, {}, this.regional.en );
  4464. this.dpDiv = datepicker_bindHover($("<div id='" + this._mainDivId + "' class='ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>"));
  4465. }
  4466. $.extend(Datepicker.prototype, {
  4467. /* Class name added to elements to indicate already configured with a date picker. */
  4468. markerClassName: "hasDatepicker",
  4469. //Keep track of the maximum number of rows displayed (see #7043)
  4470. maxRows: 4,
  4471. // TODO rename to "widget" when switching to widget factory
  4472. _widgetDatepicker: function() {
  4473. return this.dpDiv;
  4474. },
  4475. /* Override the default settings for all instances of the date picker.
  4476. * @param settings object - the new settings to use as defaults (anonymous object)
  4477. * @return the manager object
  4478. */
  4479. setDefaults: function(settings) {
  4480. datepicker_extendRemove(this._defaults, settings || {});
  4481. return this;
  4482. },
  4483. /* Attach the date picker to a jQuery selection.
  4484. * @param target element - the target input field or division or span
  4485. * @param settings object - the new settings to use for this date picker instance (anonymous)
  4486. */
  4487. _attachDatepicker: function(target, settings) {
  4488. var nodeName, inline, inst;
  4489. nodeName = target.nodeName.toLowerCase();
  4490. inline = (nodeName === "div" || nodeName === "span");
  4491. if (!target.id) {
  4492. this.uuid += 1;
  4493. target.id = "dp" + this.uuid;
  4494. }
  4495. inst = this._newInst($(target), inline);
  4496. inst.settings = $.extend({}, settings || {});
  4497. if (nodeName === "input") {
  4498. this._connectDatepicker(target, inst);
  4499. } else if (inline) {
  4500. this._inlineDatepicker(target, inst);
  4501. }
  4502. },
  4503. /* Create a new instance object. */
  4504. _newInst: function(target, inline) {
  4505. var id = target[0].id.replace(/([^A-Za-z0-9_\-])/g, "\\\\$1"); // escape jQuery meta chars
  4506. return {id: id, input: target, // associated target
  4507. selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
  4508. drawMonth: 0, drawYear: 0, // month being drawn
  4509. inline: inline, // is datepicker inline or not
  4510. dpDiv: (!inline ? this.dpDiv : // presentation div
  4511. datepicker_bindHover($("<div class='" + this._inlineClass + " ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all'></div>")))};
  4512. },
  4513. /* Attach the date picker to an input field. */
  4514. _connectDatepicker: function(target, inst) {
  4515. var input = $(target);
  4516. inst.append = $([]);
  4517. inst.trigger = $([]);
  4518. if (input.hasClass(this.markerClassName)) {
  4519. return;
  4520. }
  4521. this._attachments(input, inst);
  4522. input.addClass(this.markerClassName).keydown(this._doKeyDown).
  4523. keypress(this._doKeyPress).keyup(this._doKeyUp);
  4524. this._autoSize(inst);
  4525. $.data(target, "datepicker", inst);
  4526. //If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665)
  4527. if( inst.settings.disabled ) {
  4528. this._disableDatepicker( target );
  4529. }
  4530. },
  4531. /* Make attachments based on settings. */
  4532. _attachments: function(input, inst) {
  4533. var showOn, buttonText, buttonImage,
  4534. appendText = this._get(inst, "appendText"),
  4535. isRTL = this._get(inst, "isRTL");
  4536. if (inst.append) {
  4537. inst.append.remove();
  4538. }
  4539. if (appendText) {
  4540. inst.append = $("<span class='" + this._appendClass + "'>" + appendText + "</span>");
  4541. input[isRTL ? "before" : "after"](inst.append);
  4542. }
  4543. input.unbind("focus", this._showDatepicker);
  4544. if (inst.trigger) {
  4545. inst.trigger.remove();
  4546. }
  4547. showOn = this._get(inst, "showOn");
  4548. if (showOn === "focus" || showOn === "both") { // pop-up date picker when in the marked field
  4549. input.focus(this._showDatepicker);
  4550. }
  4551. if (showOn === "button" || showOn === "both") { // pop-up date picker when button clicked
  4552. buttonText = this._get(inst, "buttonText");
  4553. buttonImage = this._get(inst, "buttonImage");
  4554. inst.trigger = $(this._get(inst, "buttonImageOnly") ?
  4555. $("<img/>").addClass(this._triggerClass).
  4556. attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
  4557. $("<button type='button'></button>").addClass(this._triggerClass).
  4558. html(!buttonImage ? buttonText : $("<img/>").attr(
  4559. { src:buttonImage, alt:buttonText, title:buttonText })));
  4560. input[isRTL ? "before" : "after"](inst.trigger);
  4561. inst.trigger.click(function() {
  4562. if ($.datepicker._datepickerShowing && $.datepicker._lastInput === input[0]) {
  4563. $.datepicker._hideDatepicker();
  4564. } else if ($.datepicker._datepickerShowing && $.datepicker._lastInput !== input[0]) {
  4565. $.datepicker._hideDatepicker();
  4566. $.datepicker._showDatepicker(input[0]);
  4567. } else {
  4568. $.datepicker._showDatepicker(input[0]);
  4569. }
  4570. return false;
  4571. });
  4572. }
  4573. },
  4574. /* Apply the maximum length for the date format. */
  4575. _autoSize: function(inst) {
  4576. if (this._get(inst, "autoSize") && !inst.inline) {
  4577. var findMax, max, maxI, i,
  4578. date = new Date(2009, 12 - 1, 20), // Ensure double digits
  4579. dateFormat = this._get(inst, "dateFormat");
  4580. if (dateFormat.match(/[DM]/)) {
  4581. findMax = function(names) {
  4582. max = 0;
  4583. maxI = 0;
  4584. for (i = 0; i < names.length; i++) {
  4585. if (names[i].length > max) {
  4586. max = names[i].length;
  4587. maxI = i;
  4588. }
  4589. }
  4590. return maxI;
  4591. };
  4592. date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ?
  4593. "monthNames" : "monthNamesShort"))));
  4594. date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ?
  4595. "dayNames" : "dayNamesShort"))) + 20 - date.getDay());
  4596. }
  4597. inst.input.attr("size", this._formatDate(inst, date).length);
  4598. }
  4599. },
  4600. /* Attach an inline date picker to a div. */
  4601. _inlineDatepicker: function(target, inst) {
  4602. var divSpan = $(target);
  4603. if (divSpan.hasClass(this.markerClassName)) {
  4604. return;
  4605. }
  4606. divSpan.addClass(this.markerClassName).append(inst.dpDiv);
  4607. $.data(target, "datepicker", inst);
  4608. this._setDate(inst, this._getDefaultDate(inst), true);
  4609. this._updateDatepicker(inst);
  4610. this._updateAlternate(inst);
  4611. //If disabled option is true, disable the datepicker before showing it (see ticket #5665)
  4612. if( inst.settings.disabled ) {
  4613. this._disableDatepicker( target );
  4614. }
  4615. // Set display:block in place of inst.dpDiv.show() which won't work on disconnected elements
  4616. // http://bugs.jqueryui.com/ticket/7552 - A Datepicker created on a detached div has zero height
  4617. inst.dpDiv.css( "display", "block" );
  4618. },
  4619. /* Pop-up the date picker in a "dialog" box.
  4620. * @param input element - ignored
  4621. * @param date string or Date - the initial date to display
  4622. * @param onSelect function - the function to call when a date is selected
  4623. * @param settings object - update the dialog date picker instance's settings (anonymous object)
  4624. * @param pos int[2] - coordinates for the dialog's position within the screen or
  4625. * event - with x/y coordinates or
  4626. * leave empty for default (screen centre)
  4627. * @return the manager object
  4628. */
  4629. _dialogDatepicker: function(input, date, onSelect, settings, pos) {
  4630. var id, browserWidth, browserHeight, scrollX, scrollY,
  4631. inst = this._dialogInst; // internal instance
  4632. if (!inst) {
  4633. this.uuid += 1;
  4634. id = "dp" + this.uuid;
  4635. this._dialogInput = $("<input type='text' id='" + id +
  4636. "' style='position: absolute; top: -100px; width: 0px;'/>");
  4637. this._dialogInput.keydown(this._doKeyDown);
  4638. $("body").append(this._dialogInput);
  4639. inst = this._dialogInst = this._newInst(this._dialogInput, false);
  4640. inst.settings = {};
  4641. $.data(this._dialogInput[0], "datepicker", inst);
  4642. }
  4643. datepicker_extendRemove(inst.settings, settings || {});
  4644. date = (date && date.constructor === Date ? this._formatDate(inst, date) : date);
  4645. this._dialogInput.val(date);
  4646. this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
  4647. if (!this._pos) {
  4648. browserWidth = document.documentElement.clientWidth;
  4649. browserHeight = document.documentElement.clientHeight;
  4650. scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
  4651. scrollY = document.documentElement.scrollTop || document.body.scrollTop;
  4652. this._pos = // should use actual width/height below
  4653. [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
  4654. }
  4655. // move input on screen for focus, but hidden behind dialog
  4656. this._dialogInput.css("left", (this._pos[0] + 20) + "px").css("top", this._pos[1] + "px");
  4657. inst.settings.onSelect = onSelect;
  4658. this._inDialog = true;
  4659. this.dpDiv.addClass(this._dialogClass);
  4660. this._showDatepicker(this._dialogInput[0]);
  4661. if ($.blockUI) {
  4662. $.blockUI(this.dpDiv);
  4663. }
  4664. $.data(this._dialogInput[0], "datepicker", inst);
  4665. return this;
  4666. },
  4667. /* Detach a datepicker from its control.
  4668. * @param target element - the target input field or division or span
  4669. */
  4670. _destroyDatepicker: function(target) {
  4671. var nodeName,
  4672. $target = $(target),
  4673. inst = $.data(target, "datepicker");
  4674. if (!$target.hasClass(this.markerClassName)) {
  4675. return;
  4676. }
  4677. nodeName = target.nodeName.toLowerCase();
  4678. $.removeData(target, "datepicker");
  4679. if (nodeName === "input") {
  4680. inst.append.remove();
  4681. inst.trigger.remove();
  4682. $target.removeClass(this.markerClassName).
  4683. unbind("focus", this._showDatepicker).
  4684. unbind("keydown", this._doKeyDown).
  4685. unbind("keypress", this._doKeyPress).
  4686. unbind("keyup", this._doKeyUp);
  4687. } else if (nodeName === "div" || nodeName === "span") {
  4688. $target.removeClass(this.markerClassName).empty();
  4689. }
  4690. if ( datepicker_instActive === inst ) {
  4691. datepicker_instActive = null;
  4692. }
  4693. },
  4694. /* Enable the date picker to a jQuery selection.
  4695. * @param target element - the target input field or division or span
  4696. */
  4697. _enableDatepicker: function(target) {
  4698. var nodeName, inline,
  4699. $target = $(target),
  4700. inst = $.data(target, "datepicker");
  4701. if (!$target.hasClass(this.markerClassName)) {
  4702. return;
  4703. }
  4704. nodeName = target.nodeName.toLowerCase();
  4705. if (nodeName === "input") {
  4706. target.disabled = false;
  4707. inst.trigger.filter("button").
  4708. each(function() { this.disabled = false; }).end().
  4709. filter("img").css({opacity: "1.0", cursor: ""});
  4710. } else if (nodeName === "div" || nodeName === "span") {
  4711. inline = $target.children("." + this._inlineClass);
  4712. inline.children().removeClass("ui-state-disabled");
  4713. inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
  4714. prop("disabled", false);
  4715. }
  4716. this._disabledInputs = $.map(this._disabledInputs,
  4717. function(value) { return (value === target ? null : value); }); // delete entry
  4718. },
  4719. /* Disable the date picker to a jQuery selection.
  4720. * @param target element - the target input field or division or span
  4721. */
  4722. _disableDatepicker: function(target) {
  4723. var nodeName, inline,
  4724. $target = $(target),
  4725. inst = $.data(target, "datepicker");
  4726. if (!$target.hasClass(this.markerClassName)) {
  4727. return;
  4728. }
  4729. nodeName = target.nodeName.toLowerCase();
  4730. if (nodeName === "input") {
  4731. target.disabled = true;
  4732. inst.trigger.filter("button").
  4733. each(function() { this.disabled = true; }).end().
  4734. filter("img").css({opacity: "0.5", cursor: "default"});
  4735. } else if (nodeName === "div" || nodeName === "span") {
  4736. inline = $target.children("." + this._inlineClass);
  4737. inline.children().addClass("ui-state-disabled");
  4738. inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
  4739. prop("disabled", true);
  4740. }
  4741. this._disabledInputs = $.map(this._disabledInputs,
  4742. function(value) { return (value === target ? null : value); }); // delete entry
  4743. this._disabledInputs[this._disabledInputs.length] = target;
  4744. },
  4745. /* Is the first field in a jQuery collection disabled as a datepicker?
  4746. * @param target element - the target input field or division or span
  4747. * @return boolean - true if disabled, false if enabled
  4748. */
  4749. _isDisabledDatepicker: function(target) {
  4750. if (!target) {
  4751. return false;
  4752. }
  4753. for (var i = 0; i < this._disabledInputs.length; i++) {
  4754. if (this._disabledInputs[i] === target) {
  4755. return true;
  4756. }
  4757. }
  4758. return false;
  4759. },
  4760. /* Retrieve the instance data for the target control.
  4761. * @param target element - the target input field or division or span
  4762. * @return object - the associated instance data
  4763. * @throws error if a jQuery problem getting data
  4764. */
  4765. _getInst: function(target) {
  4766. try {
  4767. return $.data(target, "datepicker");
  4768. }
  4769. catch (err) {
  4770. throw "Missing instance data for this datepicker";
  4771. }
  4772. },
  4773. /* Update or retrieve the settings for a date picker attached to an input field or division.
  4774. * @param target element - the target input field or division or span
  4775. * @param name object - the new settings to update or
  4776. * string - the name of the setting to change or retrieve,
  4777. * when retrieving also "all" for all instance settings or
  4778. * "defaults" for all global defaults
  4779. * @param value any - the new value for the setting
  4780. * (omit if above is an object or to retrieve a value)
  4781. */
  4782. _optionDatepicker: function(target, name, value) {
  4783. var settings, date, minDate, maxDate,
  4784. inst = this._getInst(target);
  4785. if (arguments.length === 2 && typeof name === "string") {
  4786. return (name === "defaults" ? $.extend({}, $.datepicker._defaults) :
  4787. (inst ? (name === "all" ? $.extend({}, inst.settings) :
  4788. this._get(inst, name)) : null));
  4789. }
  4790. settings = name || {};
  4791. if (typeof name === "string") {
  4792. settings = {};
  4793. settings[name] = value;
  4794. }
  4795. if (inst) {
  4796. if (this._curInst === inst) {
  4797. this._hideDatepicker();
  4798. }
  4799. date = this._getDateDatepicker(target, true);
  4800. minDate = this._getMinMaxDate(inst, "min");
  4801. maxDate = this._getMinMaxDate(inst, "max");
  4802. datepicker_extendRemove(inst.settings, settings);
  4803. // reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided
  4804. if (minDate !== null && settings.dateFormat !== undefined && settings.minDate === undefined) {
  4805. inst.settings.minDate = this._formatDate(inst, minDate);
  4806. }
  4807. if (maxDate !== null && settings.dateFormat !== undefined && settings.maxDate === undefined) {
  4808. inst.settings.maxDate = this._formatDate(inst, maxDate);
  4809. }
  4810. if ( "disabled" in settings ) {
  4811. if ( settings.disabled ) {
  4812. this._disableDatepicker(target);
  4813. } else {
  4814. this._enableDatepicker(target);
  4815. }
  4816. }
  4817. this._attachments($(target), inst);
  4818. this._autoSize(inst);
  4819. this._setDate(inst, date);
  4820. this._updateAlternate(inst);
  4821. this._updateDatepicker(inst);
  4822. }
  4823. },
  4824. // change method deprecated
  4825. _changeDatepicker: function(target, name, value) {
  4826. this._optionDatepicker(target, name, value);
  4827. },
  4828. /* Redraw the date picker attached to an input field or division.
  4829. * @param target element - the target input field or division or span
  4830. */
  4831. _refreshDatepicker: function(target) {
  4832. var inst = this._getInst(target);
  4833. if (inst) {
  4834. this._updateDatepicker(inst);
  4835. }
  4836. },
  4837. /* Set the dates for a jQuery selection.
  4838. * @param target element - the target input field or division or span
  4839. * @param date Date - the new date
  4840. */
  4841. _setDateDatepicker: function(target, date) {
  4842. var inst = this._getInst(target);
  4843. if (inst) {
  4844. this._setDate(inst, date);
  4845. this._updateDatepicker(inst);
  4846. this._updateAlternate(inst);
  4847. }
  4848. },
  4849. /* Get the date(s) for the first entry in a jQuery selection.
  4850. * @param target element - the target input field or division or span
  4851. * @param noDefault boolean - true if no default date is to be used
  4852. * @return Date - the current date
  4853. */
  4854. _getDateDatepicker: function(target, noDefault) {
  4855. var inst = this._getInst(target);
  4856. if (inst && !inst.inline) {
  4857. this._setDateFromField(inst, noDefault);
  4858. }
  4859. return (inst ? this._getDate(inst) : null);
  4860. },
  4861. /* Handle keystrokes. */
  4862. _doKeyDown: function(event) {
  4863. var onSelect, dateStr, sel,
  4864. inst = $.datepicker._getInst(event.target),
  4865. handled = true,
  4866. isRTL = inst.dpDiv.is(".ui-datepicker-rtl");
  4867. inst._keyEvent = true;
  4868. if ($.datepicker._datepickerShowing) {
  4869. switch (event.keyCode) {
  4870. case 9: $.datepicker._hideDatepicker();
  4871. handled = false;
  4872. break; // hide on tab out
  4873. case 13: sel = $("td." + $.datepicker._dayOverClass + ":not(." +
  4874. $.datepicker._currentClass + ")", inst.dpDiv);
  4875. if (sel[0]) {
  4876. $.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
  4877. }
  4878. onSelect = $.datepicker._get(inst, "onSelect");
  4879. if (onSelect) {
  4880. dateStr = $.datepicker._formatDate(inst);
  4881. // trigger custom callback
  4882. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
  4883. } else {
  4884. $.datepicker._hideDatepicker();
  4885. }
  4886. return false; // don't submit the form
  4887. case 27: $.datepicker._hideDatepicker();
  4888. break; // hide on escape
  4889. case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  4890. -$.datepicker._get(inst, "stepBigMonths") :
  4891. -$.datepicker._get(inst, "stepMonths")), "M");
  4892. break; // previous month/year on page up/+ ctrl
  4893. case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  4894. +$.datepicker._get(inst, "stepBigMonths") :
  4895. +$.datepicker._get(inst, "stepMonths")), "M");
  4896. break; // next month/year on page down/+ ctrl
  4897. case 35: if (event.ctrlKey || event.metaKey) {
  4898. $.datepicker._clearDate(event.target);
  4899. }
  4900. handled = event.ctrlKey || event.metaKey;
  4901. break; // clear on ctrl or command +end
  4902. case 36: if (event.ctrlKey || event.metaKey) {
  4903. $.datepicker._gotoToday(event.target);
  4904. }
  4905. handled = event.ctrlKey || event.metaKey;
  4906. break; // current on ctrl or command +home
  4907. case 37: if (event.ctrlKey || event.metaKey) {
  4908. $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), "D");
  4909. }
  4910. handled = event.ctrlKey || event.metaKey;
  4911. // -1 day on ctrl or command +left
  4912. if (event.originalEvent.altKey) {
  4913. $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  4914. -$.datepicker._get(inst, "stepBigMonths") :
  4915. -$.datepicker._get(inst, "stepMonths")), "M");
  4916. }
  4917. // next month/year on alt +left on Mac
  4918. break;
  4919. case 38: if (event.ctrlKey || event.metaKey) {
  4920. $.datepicker._adjustDate(event.target, -7, "D");
  4921. }
  4922. handled = event.ctrlKey || event.metaKey;
  4923. break; // -1 week on ctrl or command +up
  4924. case 39: if (event.ctrlKey || event.metaKey) {
  4925. $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), "D");
  4926. }
  4927. handled = event.ctrlKey || event.metaKey;
  4928. // +1 day on ctrl or command +right
  4929. if (event.originalEvent.altKey) {
  4930. $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  4931. +$.datepicker._get(inst, "stepBigMonths") :
  4932. +$.datepicker._get(inst, "stepMonths")), "M");
  4933. }
  4934. // next month/year on alt +right
  4935. break;
  4936. case 40: if (event.ctrlKey || event.metaKey) {
  4937. $.datepicker._adjustDate(event.target, +7, "D");
  4938. }
  4939. handled = event.ctrlKey || event.metaKey;
  4940. break; // +1 week on ctrl or command +down
  4941. default: handled = false;
  4942. }
  4943. } else if (event.keyCode === 36 && event.ctrlKey) { // display the date picker on ctrl+home
  4944. $.datepicker._showDatepicker(this);
  4945. } else {
  4946. handled = false;
  4947. }
  4948. if (handled) {
  4949. event.preventDefault();
  4950. event.stopPropagation();
  4951. }
  4952. },
  4953. /* Filter entered characters - based on date format. */
  4954. _doKeyPress: function(event) {
  4955. var chars, chr,
  4956. inst = $.datepicker._getInst(event.target);
  4957. if ($.datepicker._get(inst, "constrainInput")) {
  4958. chars = $.datepicker._possibleChars($.datepicker._get(inst, "dateFormat"));
  4959. chr = String.fromCharCode(event.charCode == null ? event.keyCode : event.charCode);
  4960. return event.ctrlKey || event.metaKey || (chr < " " || !chars || chars.indexOf(chr) > -1);
  4961. }
  4962. },
  4963. /* Synchronise manual entry and field/alternate field. */
  4964. _doKeyUp: function(event) {
  4965. var date,
  4966. inst = $.datepicker._getInst(event.target);
  4967. if (inst.input.val() !== inst.lastVal) {
  4968. try {
  4969. date = $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"),
  4970. (inst.input ? inst.input.val() : null),
  4971. $.datepicker._getFormatConfig(inst));
  4972. if (date) { // only if valid
  4973. $.datepicker._setDateFromField(inst);
  4974. $.datepicker._updateAlternate(inst);
  4975. $.datepicker._updateDatepicker(inst);
  4976. }
  4977. }
  4978. catch (err) {
  4979. }
  4980. }
  4981. return true;
  4982. },
  4983. /* Pop-up the date picker for a given input field.
  4984. * If false returned from beforeShow event handler do not show.
  4985. * @param input element - the input field attached to the date picker or
  4986. * event - if triggered by focus
  4987. */
  4988. _showDatepicker: function(input) {
  4989. input = input.target || input;
  4990. if (input.nodeName.toLowerCase() !== "input") { // find from button/image trigger
  4991. input = $("input", input.parentNode)[0];
  4992. }
  4993. if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput === input) { // already here
  4994. return;
  4995. }
  4996. var inst, beforeShow, beforeShowSettings, isFixed,
  4997. offset, showAnim, duration;
  4998. inst = $.datepicker._getInst(input);
  4999. if ($.datepicker._curInst && $.datepicker._curInst !== inst) {
  5000. $.datepicker._curInst.dpDiv.stop(true, true);
  5001. if ( inst && $.datepicker._datepickerShowing ) {
  5002. $.datepicker._hideDatepicker( $.datepicker._curInst.input[0] );
  5003. }
  5004. }
  5005. beforeShow = $.datepicker._get(inst, "beforeShow");
  5006. beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {};
  5007. if(beforeShowSettings === false){
  5008. return;
  5009. }
  5010. datepicker_extendRemove(inst.settings, beforeShowSettings);
  5011. inst.lastVal = null;
  5012. $.datepicker._lastInput = input;
  5013. $.datepicker._setDateFromField(inst);
  5014. if ($.datepicker._inDialog) { // hide cursor
  5015. input.value = "";
  5016. }
  5017. if (!$.datepicker._pos) { // position below input
  5018. $.datepicker._pos = $.datepicker._findPos(input);
  5019. $.datepicker._pos[1] += input.offsetHeight; // add the height
  5020. }
  5021. isFixed = false;
  5022. $(input).parents().each(function() {
  5023. isFixed |= $(this).css("position") === "fixed";
  5024. return !isFixed;
  5025. });
  5026. offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
  5027. $.datepicker._pos = null;
  5028. //to avoid flashes on Firefox
  5029. inst.dpDiv.empty();
  5030. // determine sizing offscreen
  5031. inst.dpDiv.css({position: "absolute", display: "block", top: "-1000px"});
  5032. $.datepicker._updateDatepicker(inst);
  5033. // fix width for dynamic number of date pickers
  5034. // and adjust position before showing
  5035. offset = $.datepicker._checkOffset(inst, offset, isFixed);
  5036. inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
  5037. "static" : (isFixed ? "fixed" : "absolute")), display: "none",
  5038. left: offset.left + "px", top: offset.top + "px"});
  5039. if (!inst.inline) {
  5040. showAnim = $.datepicker._get(inst, "showAnim");
  5041. duration = $.datepicker._get(inst, "duration");
  5042. inst.dpDiv.css( "z-index", datepicker_getZindex( $( input ) ) + 1 );
  5043. $.datepicker._datepickerShowing = true;
  5044. if ( $.effects && $.effects.effect[ showAnim ] ) {
  5045. inst.dpDiv.show(showAnim, $.datepicker._get(inst, "showOptions"), duration);
  5046. } else {
  5047. inst.dpDiv[showAnim || "show"](showAnim ? duration : null);
  5048. }
  5049. if ( $.datepicker._shouldFocusInput( inst ) ) {
  5050. inst.input.focus();
  5051. }
  5052. $.datepicker._curInst = inst;
  5053. }
  5054. },
  5055. /* Generate the date picker content. */
  5056. _updateDatepicker: function(inst) {
  5057. this.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
  5058. datepicker_instActive = inst; // for delegate hover events
  5059. inst.dpDiv.empty().append(this._generateHTML(inst));
  5060. this._attachHandlers(inst);
  5061. var origyearshtml,
  5062. numMonths = this._getNumberOfMonths(inst),
  5063. cols = numMonths[1],
  5064. width = 17,
  5065. activeCell = inst.dpDiv.find( "." + this._dayOverClass + " a" );
  5066. if ( activeCell.length > 0 ) {
  5067. datepicker_handleMouseover.apply( activeCell.get( 0 ) );
  5068. }
  5069. inst.dpDiv.removeClass("ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4").width("");
  5070. if (cols > 1) {
  5071. inst.dpDiv.addClass("ui-datepicker-multi-" + cols).css("width", (width * cols) + "em");
  5072. }
  5073. inst.dpDiv[(numMonths[0] !== 1 || numMonths[1] !== 1 ? "add" : "remove") +
  5074. "Class"]("ui-datepicker-multi");
  5075. inst.dpDiv[(this._get(inst, "isRTL") ? "add" : "remove") +
  5076. "Class"]("ui-datepicker-rtl");
  5077. if (inst === $.datepicker._curInst && $.datepicker._datepickerShowing && $.datepicker._shouldFocusInput( inst ) ) {
  5078. inst.input.focus();
  5079. }
  5080. // deffered render of the years select (to avoid flashes on Firefox)
  5081. if( inst.yearshtml ){
  5082. origyearshtml = inst.yearshtml;
  5083. setTimeout(function(){
  5084. //assure that inst.yearshtml didn't change.
  5085. if( origyearshtml === inst.yearshtml && inst.yearshtml ){
  5086. inst.dpDiv.find("select.ui-datepicker-year:first").replaceWith(inst.yearshtml);
  5087. }
  5088. origyearshtml = inst.yearshtml = null;
  5089. }, 0);
  5090. }
  5091. },
  5092. // #6694 - don't focus the input if it's already focused
  5093. // this breaks the change event in IE
  5094. // Support: IE and jQuery <1.9
  5095. _shouldFocusInput: function( inst ) {
  5096. return inst.input && inst.input.is( ":visible" ) && !inst.input.is( ":disabled" ) && !inst.input.is( ":focus" );
  5097. },
  5098. /* Check positioning to remain on screen. */
  5099. _checkOffset: function(inst, offset, isFixed) {
  5100. var dpWidth = inst.dpDiv.outerWidth(),
  5101. dpHeight = inst.dpDiv.outerHeight(),
  5102. inputWidth = inst.input ? inst.input.outerWidth() : 0,
  5103. inputHeight = inst.input ? inst.input.outerHeight() : 0,
  5104. viewWidth = document.documentElement.clientWidth + (isFixed ? 0 : $(document).scrollLeft()),
  5105. viewHeight = document.documentElement.clientHeight + (isFixed ? 0 : $(document).scrollTop());
  5106. offset.left -= (this._get(inst, "isRTL") ? (dpWidth - inputWidth) : 0);
  5107. offset.left -= (isFixed && offset.left === inst.input.offset().left) ? $(document).scrollLeft() : 0;
  5108. offset.top -= (isFixed && offset.top === (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
  5109. // now check if datepicker is showing outside window viewport - move to a better place if so.
  5110. offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
  5111. Math.abs(offset.left + dpWidth - viewWidth) : 0);
  5112. offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
  5113. Math.abs(dpHeight + inputHeight) : 0);
  5114. return offset;
  5115. },
  5116. /* Find an object's position on the screen. */
  5117. _findPos: function(obj) {
  5118. var position,
  5119. inst = this._getInst(obj),
  5120. isRTL = this._get(inst, "isRTL");
  5121. while (obj && (obj.type === "hidden" || obj.nodeType !== 1 || $.expr.filters.hidden(obj))) {
  5122. obj = obj[isRTL ? "previousSibling" : "nextSibling"];
  5123. }
  5124. position = $(obj).offset();
  5125. return [position.left, position.top];
  5126. },
  5127. /* Hide the date picker from view.
  5128. * @param input element - the input field attached to the date picker
  5129. */
  5130. _hideDatepicker: function(input) {
  5131. var showAnim, duration, postProcess, onClose,
  5132. inst = this._curInst;
  5133. if (!inst || (input && inst !== $.data(input, "datepicker"))) {
  5134. return;
  5135. }
  5136. if (this._datepickerShowing) {
  5137. showAnim = this._get(inst, "showAnim");
  5138. duration = this._get(inst, "duration");
  5139. postProcess = function() {
  5140. $.datepicker._tidyDialog(inst);
  5141. };
  5142. // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed
  5143. if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) ) {
  5144. inst.dpDiv.hide(showAnim, $.datepicker._get(inst, "showOptions"), duration, postProcess);
  5145. } else {
  5146. inst.dpDiv[(showAnim === "slideDown" ? "slideUp" :
  5147. (showAnim === "fadeIn" ? "fadeOut" : "hide"))]((showAnim ? duration : null), postProcess);
  5148. }
  5149. if (!showAnim) {
  5150. postProcess();
  5151. }
  5152. this._datepickerShowing = false;
  5153. onClose = this._get(inst, "onClose");
  5154. if (onClose) {
  5155. onClose.apply((inst.input ? inst.input[0] : null), [(inst.input ? inst.input.val() : ""), inst]);
  5156. }
  5157. this._lastInput = null;
  5158. if (this._inDialog) {
  5159. this._dialogInput.css({ position: "absolute", left: "0", top: "-100px" });
  5160. if ($.blockUI) {
  5161. $.unblockUI();
  5162. $("body").append(this.dpDiv);
  5163. }
  5164. }
  5165. this._inDialog = false;
  5166. }
  5167. },
  5168. /* Tidy up after a dialog display. */
  5169. _tidyDialog: function(inst) {
  5170. inst.dpDiv.removeClass(this._dialogClass).unbind(".ui-datepicker-calendar");
  5171. },
  5172. /* Close date picker if clicked elsewhere. */
  5173. _checkExternalClick: function(event) {
  5174. if (!$.datepicker._curInst) {
  5175. return;
  5176. }
  5177. var $target = $(event.target),
  5178. inst = $.datepicker._getInst($target[0]);
  5179. if ( ( ( $target[0].id !== $.datepicker._mainDivId &&
  5180. $target.parents("#" + $.datepicker._mainDivId).length === 0 &&
  5181. !$target.hasClass($.datepicker.markerClassName) &&
  5182. !$target.closest("." + $.datepicker._triggerClass).length &&
  5183. $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) ||
  5184. ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst !== inst ) ) {
  5185. $.datepicker._hideDatepicker();
  5186. }
  5187. },
  5188. /* Adjust one of the date sub-fields. */
  5189. _adjustDate: function(id, offset, period) {
  5190. var target = $(id),
  5191. inst = this._getInst(target[0]);
  5192. if (this._isDisabledDatepicker(target[0])) {
  5193. return;
  5194. }
  5195. this._adjustInstDate(inst, offset +
  5196. (period === "M" ? this._get(inst, "showCurrentAtPos") : 0), // undo positioning
  5197. period);
  5198. this._updateDatepicker(inst);
  5199. },
  5200. /* Action for current link. */
  5201. _gotoToday: function(id) {
  5202. var date,
  5203. target = $(id),
  5204. inst = this._getInst(target[0]);
  5205. if (this._get(inst, "gotoCurrent") && inst.currentDay) {
  5206. inst.selectedDay = inst.currentDay;
  5207. inst.drawMonth = inst.selectedMonth = inst.currentMonth;
  5208. inst.drawYear = inst.selectedYear = inst.currentYear;
  5209. } else {
  5210. date = new Date();
  5211. inst.selectedDay = date.getDate();
  5212. inst.drawMonth = inst.selectedMonth = date.getMonth();
  5213. inst.drawYear = inst.selectedYear = date.getFullYear();
  5214. }
  5215. this._notifyChange(inst);
  5216. this._adjustDate(target);
  5217. },
  5218. /* Action for selecting a new month/year. */
  5219. _selectMonthYear: function(id, select, period) {
  5220. var target = $(id),
  5221. inst = this._getInst(target[0]);
  5222. inst["selected" + (period === "M" ? "Month" : "Year")] =
  5223. inst["draw" + (period === "M" ? "Month" : "Year")] =
  5224. parseInt(select.options[select.selectedIndex].value,10);
  5225. this._notifyChange(inst);
  5226. this._adjustDate(target);
  5227. },
  5228. /* Action for selecting a day. */
  5229. _selectDay: function(id, month, year, td) {
  5230. var inst,
  5231. target = $(id);
  5232. if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
  5233. return;
  5234. }
  5235. inst = this._getInst(target[0]);
  5236. inst.selectedDay = inst.currentDay = $("a", td).html();
  5237. inst.selectedMonth = inst.currentMonth = month;
  5238. inst.selectedYear = inst.currentYear = year;
  5239. this._selectDate(id, this._formatDate(inst,
  5240. inst.currentDay, inst.currentMonth, inst.currentYear));
  5241. },
  5242. /* Erase the input field and hide the date picker. */
  5243. _clearDate: function(id) {
  5244. var target = $(id);
  5245. this._selectDate(target, "");
  5246. },
  5247. /* Update the input field with the selected date. */
  5248. _selectDate: function(id, dateStr) {
  5249. var onSelect,
  5250. target = $(id),
  5251. inst = this._getInst(target[0]);
  5252. dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
  5253. if (inst.input) {
  5254. inst.input.val(dateStr);
  5255. }
  5256. this._updateAlternate(inst);
  5257. onSelect = this._get(inst, "onSelect");
  5258. if (onSelect) {
  5259. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
  5260. } else if (inst.input) {
  5261. inst.input.trigger("change"); // fire the change event
  5262. }
  5263. if (inst.inline){
  5264. this._updateDatepicker(inst);
  5265. } else {
  5266. this._hideDatepicker();
  5267. this._lastInput = inst.input[0];
  5268. if (typeof(inst.input[0]) !== "object") {
  5269. inst.input.focus(); // restore focus
  5270. }
  5271. this._lastInput = null;
  5272. }
  5273. },
  5274. /* Update any alternate field to synchronise with the main field. */
  5275. _updateAlternate: function(inst) {
  5276. var altFormat, date, dateStr,
  5277. altField = this._get(inst, "altField");
  5278. if (altField) { // update alternate field too
  5279. altFormat = this._get(inst, "altFormat") || this._get(inst, "dateFormat");
  5280. date = this._getDate(inst);
  5281. dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
  5282. $(altField).each(function() { $(this).val(dateStr); });
  5283. }
  5284. },
  5285. /* Set as beforeShowDay function to prevent selection of weekends.
  5286. * @param date Date - the date to customise
  5287. * @return [boolean, string] - is this date selectable?, what is its CSS class?
  5288. */
  5289. noWeekends: function(date) {
  5290. var day = date.getDay();
  5291. return [(day > 0 && day < 6), ""];
  5292. },
  5293. /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
  5294. * @param date Date - the date to get the week for
  5295. * @return number - the number of the week within the year that contains this date
  5296. */
  5297. iso8601Week: function(date) {
  5298. var time,
  5299. checkDate = new Date(date.getTime());
  5300. // Find Thursday of this week starting on Monday
  5301. checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
  5302. time = checkDate.getTime();
  5303. checkDate.setMonth(0); // Compare with Jan 1
  5304. checkDate.setDate(1);
  5305. return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
  5306. },
  5307. /* Parse a string value into a date object.
  5308. * See formatDate below for the possible formats.
  5309. *
  5310. * @param format string - the expected format of the date
  5311. * @param value string - the date in the above format
  5312. * @param settings Object - attributes include:
  5313. * shortYearCutoff number - the cutoff year for determining the century (optional)
  5314. * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  5315. * dayNames string[7] - names of the days from Sunday (optional)
  5316. * monthNamesShort string[12] - abbreviated names of the months (optional)
  5317. * monthNames string[12] - names of the months (optional)
  5318. * @return Date - the extracted date value or null if value is blank
  5319. */
  5320. parseDate: function (format, value, settings) {
  5321. if (format == null || value == null) {
  5322. throw "Invalid arguments";
  5323. }
  5324. value = (typeof value === "object" ? value.toString() : value + "");
  5325. if (value === "") {
  5326. return null;
  5327. }
  5328. var iFormat, dim, extra,
  5329. iValue = 0,
  5330. shortYearCutoffTemp = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff,
  5331. shortYearCutoff = (typeof shortYearCutoffTemp !== "string" ? shortYearCutoffTemp :
  5332. new Date().getFullYear() % 100 + parseInt(shortYearCutoffTemp, 10)),
  5333. dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort,
  5334. dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames,
  5335. monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort,
  5336. monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames,
  5337. year = -1,
  5338. month = -1,
  5339. day = -1,
  5340. doy = -1,
  5341. literal = false,
  5342. date,
  5343. // Check whether a format character is doubled
  5344. lookAhead = function(match) {
  5345. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
  5346. if (matches) {
  5347. iFormat++;
  5348. }
  5349. return matches;
  5350. },
  5351. // Extract a number from the string value
  5352. getNumber = function(match) {
  5353. var isDoubled = lookAhead(match),
  5354. size = (match === "@" ? 14 : (match === "!" ? 20 :
  5355. (match === "y" && isDoubled ? 4 : (match === "o" ? 3 : 2)))),
  5356. minSize = (match === "y" ? size : 1),
  5357. digits = new RegExp("^\\d{" + minSize + "," + size + "}"),
  5358. num = value.substring(iValue).match(digits);
  5359. if (!num) {
  5360. throw "Missing number at position " + iValue;
  5361. }
  5362. iValue += num[0].length;
  5363. return parseInt(num[0], 10);
  5364. },
  5365. // Extract a name from the string value and convert to an index
  5366. getName = function(match, shortNames, longNames) {
  5367. var index = -1,
  5368. names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
  5369. return [ [k, v] ];
  5370. }).sort(function (a, b) {
  5371. return -(a[1].length - b[1].length);
  5372. });
  5373. $.each(names, function (i, pair) {
  5374. var name = pair[1];
  5375. if (value.substr(iValue, name.length).toLowerCase() === name.toLowerCase()) {
  5376. index = pair[0];
  5377. iValue += name.length;
  5378. return false;
  5379. }
  5380. });
  5381. if (index !== -1) {
  5382. return index + 1;
  5383. } else {
  5384. throw "Unknown name at position " + iValue;
  5385. }
  5386. },
  5387. // Confirm that a literal character matches the string value
  5388. checkLiteral = function() {
  5389. if (value.charAt(iValue) !== format.charAt(iFormat)) {
  5390. throw "Unexpected literal at position " + iValue;
  5391. }
  5392. iValue++;
  5393. };
  5394. for (iFormat = 0; iFormat < format.length; iFormat++) {
  5395. if (literal) {
  5396. if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
  5397. literal = false;
  5398. } else {
  5399. checkLiteral();
  5400. }
  5401. } else {
  5402. switch (format.charAt(iFormat)) {
  5403. case "d":
  5404. day = getNumber("d");
  5405. break;
  5406. case "D":
  5407. getName("D", dayNamesShort, dayNames);
  5408. break;
  5409. case "o":
  5410. doy = getNumber("o");
  5411. break;
  5412. case "m":
  5413. month = getNumber("m");
  5414. break;
  5415. case "M":
  5416. month = getName("M", monthNamesShort, monthNames);
  5417. break;
  5418. case "y":
  5419. year = getNumber("y");
  5420. break;
  5421. case "@":
  5422. date = new Date(getNumber("@"));
  5423. year = date.getFullYear();
  5424. month = date.getMonth() + 1;
  5425. day = date.getDate();
  5426. break;
  5427. case "!":
  5428. date = new Date((getNumber("!") - this._ticksTo1970) / 10000);
  5429. year = date.getFullYear();
  5430. month = date.getMonth() + 1;
  5431. day = date.getDate();
  5432. break;
  5433. case "'":
  5434. if (lookAhead("'")){
  5435. checkLiteral();
  5436. } else {
  5437. literal = true;
  5438. }
  5439. break;
  5440. default:
  5441. checkLiteral();
  5442. }
  5443. }
  5444. }
  5445. if (iValue < value.length){
  5446. extra = value.substr(iValue);
  5447. if (!/^\s+/.test(extra)) {
  5448. throw "Extra/unparsed characters found in date: " + extra;
  5449. }
  5450. }
  5451. if (year === -1) {
  5452. year = new Date().getFullYear();
  5453. } else if (year < 100) {
  5454. year += new Date().getFullYear() - new Date().getFullYear() % 100 +
  5455. (year <= shortYearCutoff ? 0 : -100);
  5456. }
  5457. if (doy > -1) {
  5458. month = 1;
  5459. day = doy;
  5460. do {
  5461. dim = this._getDaysInMonth(year, month - 1);
  5462. if (day <= dim) {
  5463. break;
  5464. }
  5465. month++;
  5466. day -= dim;
  5467. } while (true);
  5468. }
  5469. date = this._daylightSavingAdjust(new Date(year, month - 1, day));
  5470. if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
  5471. throw "Invalid date"; // E.g. 31/02/00
  5472. }
  5473. return date;
  5474. },
  5475. /* Standard date formats. */
  5476. ATOM: "yy-mm-dd", // RFC 3339 (ISO 8601)
  5477. COOKIE: "D, dd M yy",
  5478. ISO_8601: "yy-mm-dd",
  5479. RFC_822: "D, d M y",
  5480. RFC_850: "DD, dd-M-y",
  5481. RFC_1036: "D, d M y",
  5482. RFC_1123: "D, d M yy",
  5483. RFC_2822: "D, d M yy",
  5484. RSS: "D, d M y", // RFC 822
  5485. TICKS: "!",
  5486. TIMESTAMP: "@",
  5487. W3C: "yy-mm-dd", // ISO 8601
  5488. _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
  5489. Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
  5490. /* Format a date object into a string value.
  5491. * The format can be combinations of the following:
  5492. * d - day of month (no leading zero)
  5493. * dd - day of month (two digit)
  5494. * o - day of year (no leading zeros)
  5495. * oo - day of year (three digit)
  5496. * D - day name short
  5497. * DD - day name long
  5498. * m - month of year (no leading zero)
  5499. * mm - month of year (two digit)
  5500. * M - month name short
  5501. * MM - month name long
  5502. * y - year (two digit)
  5503. * yy - year (four digit)
  5504. * @ - Unix timestamp (ms since 01/01/1970)
  5505. * ! - Windows ticks (100ns since 01/01/0001)
  5506. * "..." - literal text
  5507. * '' - single quote
  5508. *
  5509. * @param format string - the desired format of the date
  5510. * @param date Date - the date value to format
  5511. * @param settings Object - attributes include:
  5512. * dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  5513. * dayNames string[7] - names of the days from Sunday (optional)
  5514. * monthNamesShort string[12] - abbreviated names of the months (optional)
  5515. * monthNames string[12] - names of the months (optional)
  5516. * @return string - the date in the above format
  5517. */
  5518. formatDate: function (format, date, settings) {
  5519. if (!date) {
  5520. return "";
  5521. }
  5522. var iFormat,
  5523. dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort,
  5524. dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames,
  5525. monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort,
  5526. monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames,
  5527. // Check whether a format character is doubled
  5528. lookAhead = function(match) {
  5529. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
  5530. if (matches) {
  5531. iFormat++;
  5532. }
  5533. return matches;
  5534. },
  5535. // Format a number, with leading zero if necessary
  5536. formatNumber = function(match, value, len) {
  5537. var num = "" + value;
  5538. if (lookAhead(match)) {
  5539. while (num.length < len) {
  5540. num = "0" + num;
  5541. }
  5542. }
  5543. return num;
  5544. },
  5545. // Format a name, short or long as requested
  5546. formatName = function(match, value, shortNames, longNames) {
  5547. return (lookAhead(match) ? longNames[value] : shortNames[value]);
  5548. },
  5549. output = "",
  5550. literal = false;
  5551. if (date) {
  5552. for (iFormat = 0; iFormat < format.length; iFormat++) {
  5553. if (literal) {
  5554. if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
  5555. literal = false;
  5556. } else {
  5557. output += format.charAt(iFormat);
  5558. }
  5559. } else {
  5560. switch (format.charAt(iFormat)) {
  5561. case "d":
  5562. output += formatNumber("d", date.getDate(), 2);
  5563. break;
  5564. case "D":
  5565. output += formatName("D", date.getDay(), dayNamesShort, dayNames);
  5566. break;
  5567. case "o":
  5568. output += formatNumber("o",
  5569. Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
  5570. break;
  5571. case "m":
  5572. output += formatNumber("m", date.getMonth() + 1, 2);
  5573. break;
  5574. case "M":
  5575. output += formatName("M", date.getMonth(), monthNamesShort, monthNames);
  5576. break;
  5577. case "y":
  5578. output += (lookAhead("y") ? date.getFullYear() :
  5579. (date.getYear() % 100 < 10 ? "0" : "") + date.getYear() % 100);
  5580. break;
  5581. case "@":
  5582. output += date.getTime();
  5583. break;
  5584. case "!":
  5585. output += date.getTime() * 10000 + this._ticksTo1970;
  5586. break;
  5587. case "'":
  5588. if (lookAhead("'")) {
  5589. output += "'";
  5590. } else {
  5591. literal = true;
  5592. }
  5593. break;
  5594. default:
  5595. output += format.charAt(iFormat);
  5596. }
  5597. }
  5598. }
  5599. }
  5600. return output;
  5601. },
  5602. /* Extract all possible characters from the date format. */
  5603. _possibleChars: function (format) {
  5604. var iFormat,
  5605. chars = "",
  5606. literal = false,
  5607. // Check whether a format character is doubled
  5608. lookAhead = function(match) {
  5609. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
  5610. if (matches) {
  5611. iFormat++;
  5612. }
  5613. return matches;
  5614. };
  5615. for (iFormat = 0; iFormat < format.length; iFormat++) {
  5616. if (literal) {
  5617. if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
  5618. literal = false;
  5619. } else {
  5620. chars += format.charAt(iFormat);
  5621. }
  5622. } else {
  5623. switch (format.charAt(iFormat)) {
  5624. case "d": case "m": case "y": case "@":
  5625. chars += "0123456789";
  5626. break;
  5627. case "D": case "M":
  5628. return null; // Accept anything
  5629. case "'":
  5630. if (lookAhead("'")) {
  5631. chars += "'";
  5632. } else {
  5633. literal = true;
  5634. }
  5635. break;
  5636. default:
  5637. chars += format.charAt(iFormat);
  5638. }
  5639. }
  5640. }
  5641. return chars;
  5642. },
  5643. /* Get a setting value, defaulting if necessary. */
  5644. _get: function(inst, name) {
  5645. return inst.settings[name] !== undefined ?
  5646. inst.settings[name] : this._defaults[name];
  5647. },
  5648. /* Parse existing date and initialise date picker. */
  5649. _setDateFromField: function(inst, noDefault) {
  5650. if (inst.input.val() === inst.lastVal) {
  5651. return;
  5652. }
  5653. var dateFormat = this._get(inst, "dateFormat"),
  5654. dates = inst.lastVal = inst.input ? inst.input.val() : null,
  5655. defaultDate = this._getDefaultDate(inst),
  5656. date = defaultDate,
  5657. settings = this._getFormatConfig(inst);
  5658. try {
  5659. date = this.parseDate(dateFormat, dates, settings) || defaultDate;
  5660. } catch (event) {
  5661. dates = (noDefault ? "" : dates);
  5662. }
  5663. inst.selectedDay = date.getDate();
  5664. inst.drawMonth = inst.selectedMonth = date.getMonth();
  5665. inst.drawYear = inst.selectedYear = date.getFullYear();
  5666. inst.currentDay = (dates ? date.getDate() : 0);
  5667. inst.currentMonth = (dates ? date.getMonth() : 0);
  5668. inst.currentYear = (dates ? date.getFullYear() : 0);
  5669. this._adjustInstDate(inst);
  5670. },
  5671. /* Retrieve the default date shown on opening. */
  5672. _getDefaultDate: function(inst) {
  5673. return this._restrictMinMax(inst,
  5674. this._determineDate(inst, this._get(inst, "defaultDate"), new Date()));
  5675. },
  5676. /* A date may be specified as an exact value or a relative one. */
  5677. _determineDate: function(inst, date, defaultDate) {
  5678. var offsetNumeric = function(offset) {
  5679. var date = new Date();
  5680. date.setDate(date.getDate() + offset);
  5681. return date;
  5682. },
  5683. offsetString = function(offset) {
  5684. try {
  5685. return $.datepicker.parseDate($.datepicker._get(inst, "dateFormat"),
  5686. offset, $.datepicker._getFormatConfig(inst));
  5687. }
  5688. catch (e) {
  5689. // Ignore
  5690. }
  5691. var date = (offset.toLowerCase().match(/^c/) ?
  5692. $.datepicker._getDate(inst) : null) || new Date(),
  5693. year = date.getFullYear(),
  5694. month = date.getMonth(),
  5695. day = date.getDate(),
  5696. pattern = /([+\-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g,
  5697. matches = pattern.exec(offset);
  5698. while (matches) {
  5699. switch (matches[2] || "d") {
  5700. case "d" : case "D" :
  5701. day += parseInt(matches[1],10); break;
  5702. case "w" : case "W" :
  5703. day += parseInt(matches[1],10) * 7; break;
  5704. case "m" : case "M" :
  5705. month += parseInt(matches[1],10);
  5706. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  5707. break;
  5708. case "y": case "Y" :
  5709. year += parseInt(matches[1],10);
  5710. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  5711. break;
  5712. }
  5713. matches = pattern.exec(offset);
  5714. }
  5715. return new Date(year, month, day);
  5716. },
  5717. newDate = (date == null || date === "" ? defaultDate : (typeof date === "string" ? offsetString(date) :
  5718. (typeof date === "number" ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));
  5719. newDate = (newDate && newDate.toString() === "Invalid Date" ? defaultDate : newDate);
  5720. if (newDate) {
  5721. newDate.setHours(0);
  5722. newDate.setMinutes(0);
  5723. newDate.setSeconds(0);
  5724. newDate.setMilliseconds(0);
  5725. }
  5726. return this._daylightSavingAdjust(newDate);
  5727. },
  5728. /* Handle switch to/from daylight saving.
  5729. * Hours may be non-zero on daylight saving cut-over:
  5730. * > 12 when midnight changeover, but then cannot generate
  5731. * midnight datetime, so jump to 1AM, otherwise reset.
  5732. * @param date (Date) the date to check
  5733. * @return (Date) the corrected date
  5734. */
  5735. _daylightSavingAdjust: function(date) {
  5736. if (!date) {
  5737. return null;
  5738. }
  5739. date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
  5740. return date;
  5741. },
  5742. /* Set the date(s) directly. */
  5743. _setDate: function(inst, date, noChange) {
  5744. var clear = !date,
  5745. origMonth = inst.selectedMonth,
  5746. origYear = inst.selectedYear,
  5747. newDate = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
  5748. inst.selectedDay = inst.currentDay = newDate.getDate();
  5749. inst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth();
  5750. inst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear();
  5751. if ((origMonth !== inst.selectedMonth || origYear !== inst.selectedYear) && !noChange) {
  5752. this._notifyChange(inst);
  5753. }
  5754. this._adjustInstDate(inst);
  5755. if (inst.input) {
  5756. inst.input.val(clear ? "" : this._formatDate(inst));
  5757. }
  5758. },
  5759. /* Retrieve the date(s) directly. */
  5760. _getDate: function(inst) {
  5761. var startDate = (!inst.currentYear || (inst.input && inst.input.val() === "") ? null :
  5762. this._daylightSavingAdjust(new Date(
  5763. inst.currentYear, inst.currentMonth, inst.currentDay)));
  5764. return startDate;
  5765. },
  5766. /* Attach the onxxx handlers. These are declared statically so
  5767. * they work with static code transformers like Caja.
  5768. */
  5769. _attachHandlers: function(inst) {
  5770. var stepMonths = this._get(inst, "stepMonths"),
  5771. id = "#" + inst.id.replace( /\\\\/g, "\\" );
  5772. inst.dpDiv.find("[data-handler]").map(function () {
  5773. var handler = {
  5774. prev: function () {
  5775. $.datepicker._adjustDate(id, -stepMonths, "M");
  5776. },
  5777. next: function () {
  5778. $.datepicker._adjustDate(id, +stepMonths, "M");
  5779. },
  5780. hide: function () {
  5781. $.datepicker._hideDatepicker();
  5782. },
  5783. today: function () {
  5784. $.datepicker._gotoToday(id);
  5785. },
  5786. selectDay: function () {
  5787. $.datepicker._selectDay(id, +this.getAttribute("data-month"), +this.getAttribute("data-year"), this);
  5788. return false;
  5789. },
  5790. selectMonth: function () {
  5791. $.datepicker._selectMonthYear(id, this, "M");
  5792. return false;
  5793. },
  5794. selectYear: function () {
  5795. $.datepicker._selectMonthYear(id, this, "Y");
  5796. return false;
  5797. }
  5798. };
  5799. $(this).bind(this.getAttribute("data-event"), handler[this.getAttribute("data-handler")]);
  5800. });
  5801. },
  5802. /* Generate the HTML for the current state of the date picker. */
  5803. _generateHTML: function(inst) {
  5804. var maxDraw, prevText, prev, nextText, next, currentText, gotoDate,
  5805. controls, buttonPanel, firstDay, showWeek, dayNames, dayNamesMin,
  5806. monthNames, monthNamesShort, beforeShowDay, showOtherMonths,
  5807. selectOtherMonths, defaultDate, html, dow, row, group, col, selectedDate,
  5808. cornerClass, calender, thead, day, daysInMonth, leadDays, curRows, numRows,
  5809. printDate, dRow, tbody, daySettings, otherMonth, unselectable,
  5810. tempDate = new Date(),
  5811. today = this._daylightSavingAdjust(
  5812. new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate())), // clear time
  5813. isRTL = this._get(inst, "isRTL"),
  5814. showButtonPanel = this._get(inst, "showButtonPanel"),
  5815. hideIfNoPrevNext = this._get(inst, "hideIfNoPrevNext"),
  5816. navigationAsDateFormat = this._get(inst, "navigationAsDateFormat"),
  5817. numMonths = this._getNumberOfMonths(inst),
  5818. showCurrentAtPos = this._get(inst, "showCurrentAtPos"),
  5819. stepMonths = this._get(inst, "stepMonths"),
  5820. isMultiMonth = (numMonths[0] !== 1 || numMonths[1] !== 1),
  5821. currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
  5822. new Date(inst.currentYear, inst.currentMonth, inst.currentDay))),
  5823. minDate = this._getMinMaxDate(inst, "min"),
  5824. maxDate = this._getMinMaxDate(inst, "max"),
  5825. drawMonth = inst.drawMonth - showCurrentAtPos,
  5826. drawYear = inst.drawYear;
  5827. if (drawMonth < 0) {
  5828. drawMonth += 12;
  5829. drawYear--;
  5830. }
  5831. if (maxDate) {
  5832. maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
  5833. maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
  5834. maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
  5835. while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
  5836. drawMonth--;
  5837. if (drawMonth < 0) {
  5838. drawMonth = 11;
  5839. drawYear--;
  5840. }
  5841. }
  5842. }
  5843. inst.drawMonth = drawMonth;
  5844. inst.drawYear = drawYear;
  5845. prevText = this._get(inst, "prevText");
  5846. prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
  5847. this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
  5848. this._getFormatConfig(inst)));
  5849. prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
  5850. "<a class='ui-datepicker-prev ui-corner-all' data-handler='prev' data-event='click'" +
  5851. " title='" + prevText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w") + "'>" + prevText + "</span></a>" :
  5852. (hideIfNoPrevNext ? "" : "<a class='ui-datepicker-prev ui-corner-all ui-state-disabled' title='"+ prevText +"'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "e" : "w") + "'>" + prevText + "</span></a>"));
  5853. nextText = this._get(inst, "nextText");
  5854. nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
  5855. this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
  5856. this._getFormatConfig(inst)));
  5857. next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
  5858. "<a class='ui-datepicker-next ui-corner-all' data-handler='next' data-event='click'" +
  5859. " title='" + nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e") + "'>" + nextText + "</span></a>" :
  5860. (hideIfNoPrevNext ? "" : "<a class='ui-datepicker-next ui-corner-all ui-state-disabled' title='"+ nextText + "'><span class='ui-icon ui-icon-circle-triangle-" + ( isRTL ? "w" : "e") + "'>" + nextText + "</span></a>"));
  5861. currentText = this._get(inst, "currentText");
  5862. gotoDate = (this._get(inst, "gotoCurrent") && inst.currentDay ? currentDate : today);
  5863. currentText = (!navigationAsDateFormat ? currentText :
  5864. this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
  5865. controls = (!inst.inline ? "<button type='button' class='ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all' data-handler='hide' data-event='click'>" +
  5866. this._get(inst, "closeText") + "</button>" : "");
  5867. buttonPanel = (showButtonPanel) ? "<div class='ui-datepicker-buttonpane ui-widget-content'>" + (isRTL ? controls : "") +
  5868. (this._isInRange(inst, gotoDate) ? "<button type='button' class='ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all' data-handler='today' data-event='click'" +
  5869. ">" + currentText + "</button>" : "") + (isRTL ? "" : controls) + "</div>" : "";
  5870. firstDay = parseInt(this._get(inst, "firstDay"),10);
  5871. firstDay = (isNaN(firstDay) ? 0 : firstDay);
  5872. showWeek = this._get(inst, "showWeek");
  5873. dayNames = this._get(inst, "dayNames");
  5874. dayNamesMin = this._get(inst, "dayNamesMin");
  5875. monthNames = this._get(inst, "monthNames");
  5876. monthNamesShort = this._get(inst, "monthNamesShort");
  5877. beforeShowDay = this._get(inst, "beforeShowDay");
  5878. showOtherMonths = this._get(inst, "showOtherMonths");
  5879. selectOtherMonths = this._get(inst, "selectOtherMonths");
  5880. defaultDate = this._getDefaultDate(inst);
  5881. html = "";
  5882. dow;
  5883. for (row = 0; row < numMonths[0]; row++) {
  5884. group = "";
  5885. this.maxRows = 4;
  5886. for (col = 0; col < numMonths[1]; col++) {
  5887. selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
  5888. cornerClass = " ui-corner-all";
  5889. calender = "";
  5890. if (isMultiMonth) {
  5891. calender += "<div class='ui-datepicker-group";
  5892. if (numMonths[1] > 1) {
  5893. switch (col) {
  5894. case 0: calender += " ui-datepicker-group-first";
  5895. cornerClass = " ui-corner-" + (isRTL ? "right" : "left"); break;
  5896. case numMonths[1]-1: calender += " ui-datepicker-group-last";
  5897. cornerClass = " ui-corner-" + (isRTL ? "left" : "right"); break;
  5898. default: calender += " ui-datepicker-group-middle"; cornerClass = ""; break;
  5899. }
  5900. }
  5901. calender += "'>";
  5902. }
  5903. calender += "<div class='ui-datepicker-header ui-widget-header ui-helper-clearfix" + cornerClass + "'>" +
  5904. (/all|left/.test(cornerClass) && row === 0 ? (isRTL ? next : prev) : "") +
  5905. (/all|right/.test(cornerClass) && row === 0 ? (isRTL ? prev : next) : "") +
  5906. this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
  5907. row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
  5908. "</div><table class='ui-datepicker-calendar'><thead>" +
  5909. "<tr>";
  5910. thead = (showWeek ? "<th class='ui-datepicker-week-col'>" + this._get(inst, "weekHeader") + "</th>" : "");
  5911. for (dow = 0; dow < 7; dow++) { // days of the week
  5912. day = (dow + firstDay) % 7;
  5913. thead += "<th scope='col'" + ((dow + firstDay + 6) % 7 >= 5 ? " class='ui-datepicker-week-end'" : "") + ">" +
  5914. "<span title='" + dayNames[day] + "'>" + dayNamesMin[day] + "</span></th>";
  5915. }
  5916. calender += thead + "</tr></thead><tbody>";
  5917. daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
  5918. if (drawYear === inst.selectedYear && drawMonth === inst.selectedMonth) {
  5919. inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
  5920. }
  5921. leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
  5922. curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
  5923. numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
  5924. this.maxRows = numRows;
  5925. printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
  5926. for (dRow = 0; dRow < numRows; dRow++) { // create date picker rows
  5927. calender += "<tr>";
  5928. tbody = (!showWeek ? "" : "<td class='ui-datepicker-week-col'>" +
  5929. this._get(inst, "calculateWeek")(printDate) + "</td>");
  5930. for (dow = 0; dow < 7; dow++) { // create date picker days
  5931. daySettings = (beforeShowDay ?
  5932. beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, ""]);
  5933. otherMonth = (printDate.getMonth() !== drawMonth);
  5934. unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
  5935. (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
  5936. tbody += "<td class='" +
  5937. ((dow + firstDay + 6) % 7 >= 5 ? " ui-datepicker-week-end" : "") + // highlight weekends
  5938. (otherMonth ? " ui-datepicker-other-month" : "") + // highlight days from other months
  5939. ((printDate.getTime() === selectedDate.getTime() && drawMonth === inst.selectedMonth && inst._keyEvent) || // user pressed key
  5940. (defaultDate.getTime() === printDate.getTime() && defaultDate.getTime() === selectedDate.getTime()) ?
  5941. // or defaultDate is current printedDate and defaultDate is selectedDate
  5942. " " + this._dayOverClass : "") + // highlight selected day
  5943. (unselectable ? " " + this._unselectableClass + " ui-state-disabled": "") + // highlight unselectable days
  5944. (otherMonth && !showOtherMonths ? "" : " " + daySettings[1] + // highlight custom dates
  5945. (printDate.getTime() === currentDate.getTime() ? " " + this._currentClass : "") + // highlight selected day
  5946. (printDate.getTime() === today.getTime() ? " ui-datepicker-today" : "")) + "'" + // highlight today (if different)
  5947. ((!otherMonth || showOtherMonths) && daySettings[2] ? " title='" + daySettings[2].replace(/'/g, "&#39;") + "'" : "") + // cell title
  5948. (unselectable ? "" : " data-handler='selectDay' data-event='click' data-month='" + printDate.getMonth() + "' data-year='" + printDate.getFullYear() + "'") + ">" + // actions
  5949. (otherMonth && !showOtherMonths ? "&#xa0;" : // display for other months
  5950. (unselectable ? "<span class='ui-state-default'>" + printDate.getDate() + "</span>" : "<a class='ui-state-default" +
  5951. (printDate.getTime() === today.getTime() ? " ui-state-highlight" : "") +
  5952. (printDate.getTime() === currentDate.getTime() ? " ui-state-active" : "") + // highlight selected day
  5953. (otherMonth ? " ui-priority-secondary" : "") + // distinguish dates from other months
  5954. "' href='#'>" + printDate.getDate() + "</a>")) + "</td>"; // display selectable date
  5955. printDate.setDate(printDate.getDate() + 1);
  5956. printDate = this._daylightSavingAdjust(printDate);
  5957. }
  5958. calender += tbody + "</tr>";
  5959. }
  5960. drawMonth++;
  5961. if (drawMonth > 11) {
  5962. drawMonth = 0;
  5963. drawYear++;
  5964. }
  5965. calender += "</tbody></table>" + (isMultiMonth ? "</div>" +
  5966. ((numMonths[0] > 0 && col === numMonths[1]-1) ? "<div class='ui-datepicker-row-break'></div>" : "") : "");
  5967. group += calender;
  5968. }
  5969. html += group;
  5970. }
  5971. html += buttonPanel;
  5972. inst._keyEvent = false;
  5973. return html;
  5974. },
  5975. /* Generate the month and year header. */
  5976. _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
  5977. secondary, monthNames, monthNamesShort) {
  5978. var inMinYear, inMaxYear, month, years, thisYear, determineYear, year, endYear,
  5979. changeMonth = this._get(inst, "changeMonth"),
  5980. changeYear = this._get(inst, "changeYear"),
  5981. showMonthAfterYear = this._get(inst, "showMonthAfterYear"),
  5982. html = "<div class='ui-datepicker-title'>",
  5983. monthHtml = "";
  5984. // month selection
  5985. if (secondary || !changeMonth) {
  5986. monthHtml += "<span class='ui-datepicker-month'>" + monthNames[drawMonth] + "</span>";
  5987. } else {
  5988. inMinYear = (minDate && minDate.getFullYear() === drawYear);
  5989. inMaxYear = (maxDate && maxDate.getFullYear() === drawYear);
  5990. monthHtml += "<select class='ui-datepicker-month' data-handler='selectMonth' data-event='change'>";
  5991. for ( month = 0; month < 12; month++) {
  5992. if ((!inMinYear || month >= minDate.getMonth()) && (!inMaxYear || month <= maxDate.getMonth())) {
  5993. monthHtml += "<option value='" + month + "'" +
  5994. (month === drawMonth ? " selected='selected'" : "") +
  5995. ">" + monthNamesShort[month] + "</option>";
  5996. }
  5997. }
  5998. monthHtml += "</select>";
  5999. }
  6000. if (!showMonthAfterYear) {
  6001. html += monthHtml + (secondary || !(changeMonth && changeYear) ? "&#xa0;" : "");
  6002. }
  6003. // year selection
  6004. if ( !inst.yearshtml ) {
  6005. inst.yearshtml = "";
  6006. if (secondary || !changeYear) {
  6007. html += "<span class='ui-datepicker-year'>" + drawYear + "</span>";
  6008. } else {
  6009. // determine range of years to display
  6010. years = this._get(inst, "yearRange").split(":");
  6011. thisYear = new Date().getFullYear();
  6012. determineYear = function(value) {
  6013. var year = (value.match(/c[+\-].*/) ? drawYear + parseInt(value.substring(1), 10) :
  6014. (value.match(/[+\-].*/) ? thisYear + parseInt(value, 10) :
  6015. parseInt(value, 10)));
  6016. return (isNaN(year) ? thisYear : year);
  6017. };
  6018. year = determineYear(years[0]);
  6019. endYear = Math.max(year, determineYear(years[1] || ""));
  6020. year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
  6021. endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
  6022. inst.yearshtml += "<select class='ui-datepicker-year' data-handler='selectYear' data-event='change'>";
  6023. for (; year <= endYear; year++) {
  6024. inst.yearshtml += "<option value='" + year + "'" +
  6025. (year === drawYear ? " selected='selected'" : "") +
  6026. ">" + year + "</option>";
  6027. }
  6028. inst.yearshtml += "</select>";
  6029. html += inst.yearshtml;
  6030. inst.yearshtml = null;
  6031. }
  6032. }
  6033. html += this._get(inst, "yearSuffix");
  6034. if (showMonthAfterYear) {
  6035. html += (secondary || !(changeMonth && changeYear) ? "&#xa0;" : "") + monthHtml;
  6036. }
  6037. html += "</div>"; // Close datepicker_header
  6038. return html;
  6039. },
  6040. /* Adjust one of the date sub-fields. */
  6041. _adjustInstDate: function(inst, offset, period) {
  6042. var year = inst.drawYear + (period === "Y" ? offset : 0),
  6043. month = inst.drawMonth + (period === "M" ? offset : 0),
  6044. day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) + (period === "D" ? offset : 0),
  6045. date = this._restrictMinMax(inst, this._daylightSavingAdjust(new Date(year, month, day)));
  6046. inst.selectedDay = date.getDate();
  6047. inst.drawMonth = inst.selectedMonth = date.getMonth();
  6048. inst.drawYear = inst.selectedYear = date.getFullYear();
  6049. if (period === "M" || period === "Y") {
  6050. this._notifyChange(inst);
  6051. }
  6052. },
  6053. /* Ensure a date is within any min/max bounds. */
  6054. _restrictMinMax: function(inst, date) {
  6055. var minDate = this._getMinMaxDate(inst, "min"),
  6056. maxDate = this._getMinMaxDate(inst, "max"),
  6057. newDate = (minDate && date < minDate ? minDate : date);
  6058. return (maxDate && newDate > maxDate ? maxDate : newDate);
  6059. },
  6060. /* Notify change of month/year. */
  6061. _notifyChange: function(inst) {
  6062. var onChange = this._get(inst, "onChangeMonthYear");
  6063. if (onChange) {
  6064. onChange.apply((inst.input ? inst.input[0] : null),
  6065. [inst.selectedYear, inst.selectedMonth + 1, inst]);
  6066. }
  6067. },
  6068. /* Determine the number of months to show. */
  6069. _getNumberOfMonths: function(inst) {
  6070. var numMonths = this._get(inst, "numberOfMonths");
  6071. return (numMonths == null ? [1, 1] : (typeof numMonths === "number" ? [1, numMonths] : numMonths));
  6072. },
  6073. /* Determine the current maximum date - ensure no time components are set. */
  6074. _getMinMaxDate: function(inst, minMax) {
  6075. return this._determineDate(inst, this._get(inst, minMax + "Date"), null);
  6076. },
  6077. /* Find the number of days in a given month. */
  6078. _getDaysInMonth: function(year, month) {
  6079. return 32 - this._daylightSavingAdjust(new Date(year, month, 32)).getDate();
  6080. },
  6081. /* Find the day of the week of the first of a month. */
  6082. _getFirstDayOfMonth: function(year, month) {
  6083. return new Date(year, month, 1).getDay();
  6084. },
  6085. /* Determines if we should allow a "next/prev" month display change. */
  6086. _canAdjustMonth: function(inst, offset, curYear, curMonth) {
  6087. var numMonths = this._getNumberOfMonths(inst),
  6088. date = this._daylightSavingAdjust(new Date(curYear,
  6089. curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
  6090. if (offset < 0) {
  6091. date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
  6092. }
  6093. return this._isInRange(inst, date);
  6094. },
  6095. /* Is the given date in the accepted range? */
  6096. _isInRange: function(inst, date) {
  6097. var yearSplit, currentYear,
  6098. minDate = this._getMinMaxDate(inst, "min"),
  6099. maxDate = this._getMinMaxDate(inst, "max"),
  6100. minYear = null,
  6101. maxYear = null,
  6102. years = this._get(inst, "yearRange");
  6103. if (years){
  6104. yearSplit = years.split(":");
  6105. currentYear = new Date().getFullYear();
  6106. minYear = parseInt(yearSplit[0], 10);
  6107. maxYear = parseInt(yearSplit[1], 10);
  6108. if ( yearSplit[0].match(/[+\-].*/) ) {
  6109. minYear += currentYear;
  6110. }
  6111. if ( yearSplit[1].match(/[+\-].*/) ) {
  6112. maxYear += currentYear;
  6113. }
  6114. }
  6115. return ((!minDate || date.getTime() >= minDate.getTime()) &&
  6116. (!maxDate || date.getTime() <= maxDate.getTime()) &&
  6117. (!minYear || date.getFullYear() >= minYear) &&
  6118. (!maxYear || date.getFullYear() <= maxYear));
  6119. },
  6120. /* Provide the configuration settings for formatting/parsing. */
  6121. _getFormatConfig: function(inst) {
  6122. var shortYearCutoff = this._get(inst, "shortYearCutoff");
  6123. shortYearCutoff = (typeof shortYearCutoff !== "string" ? shortYearCutoff :
  6124. new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
  6125. return {shortYearCutoff: shortYearCutoff,
  6126. dayNamesShort: this._get(inst, "dayNamesShort"), dayNames: this._get(inst, "dayNames"),
  6127. monthNamesShort: this._get(inst, "monthNamesShort"), monthNames: this._get(inst, "monthNames")};
  6128. },
  6129. /* Format the given date for display. */
  6130. _formatDate: function(inst, day, month, year) {
  6131. if (!day) {
  6132. inst.currentDay = inst.selectedDay;
  6133. inst.currentMonth = inst.selectedMonth;
  6134. inst.currentYear = inst.selectedYear;
  6135. }
  6136. var date = (day ? (typeof day === "object" ? day :
  6137. this._daylightSavingAdjust(new Date(year, month, day))) :
  6138. this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  6139. return this.formatDate(this._get(inst, "dateFormat"), date, this._getFormatConfig(inst));
  6140. }
  6141. });
  6142. /*
  6143. * Bind hover events for datepicker elements.
  6144. * Done via delegate so the binding only occurs once in the lifetime of the parent div.
  6145. * Global datepicker_instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.
  6146. */
  6147. function datepicker_bindHover(dpDiv) {
  6148. var selector = "button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a";
  6149. return dpDiv.delegate(selector, "mouseout", function() {
  6150. $(this).removeClass("ui-state-hover");
  6151. if (this.className.indexOf("ui-datepicker-prev") !== -1) {
  6152. $(this).removeClass("ui-datepicker-prev-hover");
  6153. }
  6154. if (this.className.indexOf("ui-datepicker-next") !== -1) {
  6155. $(this).removeClass("ui-datepicker-next-hover");
  6156. }
  6157. })
  6158. .delegate( selector, "mouseover", datepicker_handleMouseover );
  6159. }
  6160. function datepicker_handleMouseover() {
  6161. if (!$.datepicker._isDisabledDatepicker( datepicker_instActive.inline? datepicker_instActive.dpDiv.parent()[0] : datepicker_instActive.input[0])) {
  6162. $(this).parents(".ui-datepicker-calendar").find("a").removeClass("ui-state-hover");
  6163. $(this).addClass("ui-state-hover");
  6164. if (this.className.indexOf("ui-datepicker-prev") !== -1) {
  6165. $(this).addClass("ui-datepicker-prev-hover");
  6166. }
  6167. if (this.className.indexOf("ui-datepicker-next") !== -1) {
  6168. $(this).addClass("ui-datepicker-next-hover");
  6169. }
  6170. }
  6171. }
  6172. /* jQuery extend now ignores nulls! */
  6173. function datepicker_extendRemove(target, props) {
  6174. $.extend(target, props);
  6175. for (var name in props) {
  6176. if (props[name] == null) {
  6177. target[name] = props[name];
  6178. }
  6179. }
  6180. return target;
  6181. }
  6182. /* Invoke the datepicker functionality.
  6183. @param options string - a command, optionally followed by additional parameters or
  6184. Object - settings for attaching new datepicker functionality
  6185. @return jQuery object */
  6186. $.fn.datepicker = function(options){
  6187. /* Verify an empty collection wasn't passed - Fixes #6976 */
  6188. if ( !this.length ) {
  6189. return this;
  6190. }
  6191. /* Initialise the date picker. */
  6192. if (!$.datepicker.initialized) {
  6193. $(document).mousedown($.datepicker._checkExternalClick);
  6194. $.datepicker.initialized = true;
  6195. }
  6196. /* Append datepicker main container to body if not exist. */
  6197. if ($("#"+$.datepicker._mainDivId).length === 0) {
  6198. $("body").append($.datepicker.dpDiv);
  6199. }
  6200. var otherArgs = Array.prototype.slice.call(arguments, 1);
  6201. if (typeof options === "string" && (options === "isDisabled" || options === "getDate" || options === "widget")) {
  6202. return $.datepicker["_" + options + "Datepicker"].
  6203. apply($.datepicker, [this[0]].concat(otherArgs));
  6204. }
  6205. if (options === "option" && arguments.length === 2 && typeof arguments[1] === "string") {
  6206. return $.datepicker["_" + options + "Datepicker"].
  6207. apply($.datepicker, [this[0]].concat(otherArgs));
  6208. }
  6209. return this.each(function() {
  6210. typeof options === "string" ?
  6211. $.datepicker["_" + options + "Datepicker"].
  6212. apply($.datepicker, [this].concat(otherArgs)) :
  6213. $.datepicker._attachDatepicker(this, options);
  6214. });
  6215. };
  6216. $.datepicker = new Datepicker(); // singleton instance
  6217. $.datepicker.initialized = false;
  6218. $.datepicker.uuid = new Date().getTime();
  6219. $.datepicker.version = "1.11.4";
  6220. var datepicker = $.datepicker;
  6221. /*!
  6222. * jQuery UI Progressbar 1.11.4
  6223. * http://jqueryui.com
  6224. *
  6225. * Copyright jQuery Foundation and other contributors
  6226. * Released under the MIT license.
  6227. * http://jquery.org/license
  6228. *
  6229. * http://api.jqueryui.com/progressbar/
  6230. */
  6231. var progressbar = $.widget( "ui.progressbar", {
  6232. version: "1.11.4",
  6233. options: {
  6234. max: 100,
  6235. value: 0,
  6236. change: null,
  6237. complete: null
  6238. },
  6239. min: 0,
  6240. _create: function() {
  6241. // Constrain initial value
  6242. this.oldValue = this.options.value = this._constrainedValue();
  6243. this.element
  6244. .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
  6245. .attr({
  6246. // Only set static values, aria-valuenow and aria-valuemax are
  6247. // set inside _refreshValue()
  6248. role: "progressbar",
  6249. "aria-valuemin": this.min
  6250. });
  6251. this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
  6252. .appendTo( this.element );
  6253. this._refreshValue();
  6254. },
  6255. _destroy: function() {
  6256. this.element
  6257. .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
  6258. .removeAttr( "role" )
  6259. .removeAttr( "aria-valuemin" )
  6260. .removeAttr( "aria-valuemax" )
  6261. .removeAttr( "aria-valuenow" );
  6262. this.valueDiv.remove();
  6263. },
  6264. value: function( newValue ) {
  6265. if ( newValue === undefined ) {
  6266. return this.options.value;
  6267. }
  6268. this.options.value = this._constrainedValue( newValue );
  6269. this._refreshValue();
  6270. },
  6271. _constrainedValue: function( newValue ) {
  6272. if ( newValue === undefined ) {
  6273. newValue = this.options.value;
  6274. }
  6275. this.indeterminate = newValue === false;
  6276. // sanitize value
  6277. if ( typeof newValue !== "number" ) {
  6278. newValue = 0;
  6279. }
  6280. return this.indeterminate ? false :
  6281. Math.min( this.options.max, Math.max( this.min, newValue ) );
  6282. },
  6283. _setOptions: function( options ) {
  6284. // Ensure "value" option is set after other values (like max)
  6285. var value = options.value;
  6286. delete options.value;
  6287. this._super( options );
  6288. this.options.value = this._constrainedValue( value );
  6289. this._refreshValue();
  6290. },
  6291. _setOption: function( key, value ) {
  6292. if ( key === "max" ) {
  6293. // Don't allow a max less than min
  6294. value = Math.max( this.min, value );
  6295. }
  6296. if ( key === "disabled" ) {
  6297. this.element
  6298. .toggleClass( "ui-state-disabled", !!value )
  6299. .attr( "aria-disabled", value );
  6300. }
  6301. this._super( key, value );
  6302. },
  6303. _percentage: function() {
  6304. return this.indeterminate ? 100 : 100 * ( this.options.value - this.min ) / ( this.options.max - this.min );
  6305. },
  6306. _refreshValue: function() {
  6307. var value = this.options.value,
  6308. percentage = this._percentage();
  6309. this.valueDiv
  6310. .toggle( this.indeterminate || value > this.min )
  6311. .toggleClass( "ui-corner-right", value === this.options.max )
  6312. .width( percentage.toFixed(0) + "%" );
  6313. this.element.toggleClass( "ui-progressbar-indeterminate", this.indeterminate );
  6314. if ( this.indeterminate ) {
  6315. this.element.removeAttr( "aria-valuenow" );
  6316. if ( !this.overlayDiv ) {
  6317. this.overlayDiv = $( "<div class='ui-progressbar-overlay'></div>" ).appendTo( this.valueDiv );
  6318. }
  6319. } else {
  6320. this.element.attr({
  6321. "aria-valuemax": this.options.max,
  6322. "aria-valuenow": value
  6323. });
  6324. if ( this.overlayDiv ) {
  6325. this.overlayDiv.remove();
  6326. this.overlayDiv = null;
  6327. }
  6328. }
  6329. if ( this.oldValue !== value ) {
  6330. this.oldValue = value;
  6331. this._trigger( "change" );
  6332. }
  6333. if ( value === this.options.max ) {
  6334. this._trigger( "complete" );
  6335. }
  6336. }
  6337. });
  6338. /*!
  6339. * jQuery UI Selectmenu 1.11.4
  6340. * http://jqueryui.com
  6341. *
  6342. * Copyright jQuery Foundation and other contributors
  6343. * Released under the MIT license.
  6344. * http://jquery.org/license
  6345. *
  6346. * http://api.jqueryui.com/selectmenu
  6347. */
  6348. var selectmenu = $.widget( "ui.selectmenu", {
  6349. version: "1.11.4",
  6350. defaultElement: "<select>",
  6351. options: {
  6352. appendTo: null,
  6353. disabled: null,
  6354. icons: {
  6355. button: "ui-icon-triangle-1-s"
  6356. },
  6357. position: {
  6358. my: "left top",
  6359. at: "left bottom",
  6360. collision: "none"
  6361. },
  6362. width: null,
  6363. // callbacks
  6364. change: null,
  6365. close: null,
  6366. focus: null,
  6367. open: null,
  6368. select: null
  6369. },
  6370. _create: function() {
  6371. var selectmenuId = this.element.uniqueId().attr( "id" );
  6372. this.ids = {
  6373. element: selectmenuId,
  6374. button: selectmenuId + "-button",
  6375. menu: selectmenuId + "-menu"
  6376. };
  6377. this._drawButton();
  6378. this._drawMenu();
  6379. if ( this.options.disabled ) {
  6380. this.disable();
  6381. }
  6382. },
  6383. _drawButton: function() {
  6384. var that = this;
  6385. // Associate existing label with the new button
  6386. this.label = $( "label[for='" + this.ids.element + "']" ).attr( "for", this.ids.button );
  6387. this._on( this.label, {
  6388. click: function( event ) {
  6389. this.button.focus();
  6390. event.preventDefault();
  6391. }
  6392. });
  6393. // Hide original select element
  6394. this.element.hide();
  6395. // Create button
  6396. this.button = $( "<span>", {
  6397. "class": "ui-selectmenu-button ui-widget ui-state-default ui-corner-all",
  6398. tabindex: this.options.disabled ? -1 : 0,
  6399. id: this.ids.button,
  6400. role: "combobox",
  6401. "aria-expanded": "false",
  6402. "aria-autocomplete": "list",
  6403. "aria-owns": this.ids.menu,
  6404. "aria-haspopup": "true"
  6405. })
  6406. .insertAfter( this.element );
  6407. $( "<span>", {
  6408. "class": "ui-icon " + this.options.icons.button
  6409. })
  6410. .prependTo( this.button );
  6411. this.buttonText = $( "<span>", {
  6412. "class": "ui-selectmenu-text"
  6413. })
  6414. .appendTo( this.button );
  6415. this._setText( this.buttonText, this.element.find( "option:selected" ).text() );
  6416. this._resizeButton();
  6417. this._on( this.button, this._buttonEvents );
  6418. this.button.one( "focusin", function() {
  6419. // Delay rendering the menu items until the button receives focus.
  6420. // The menu may have already been rendered via a programmatic open.
  6421. if ( !that.menuItems ) {
  6422. that._refreshMenu();
  6423. }
  6424. });
  6425. this._hoverable( this.button );
  6426. this._focusable( this.button );
  6427. },
  6428. _drawMenu: function() {
  6429. var that = this;
  6430. // Create menu
  6431. this.menu = $( "<ul>", {
  6432. "aria-hidden": "true",
  6433. "aria-labelledby": this.ids.button,
  6434. id: this.ids.menu
  6435. });
  6436. // Wrap menu
  6437. this.menuWrap = $( "<div>", {
  6438. "class": "ui-selectmenu-menu ui-front"
  6439. })
  6440. .append( this.menu )
  6441. .appendTo( this._appendTo() );
  6442. // Initialize menu widget
  6443. this.menuInstance = this.menu
  6444. .menu({
  6445. role: "listbox",
  6446. select: function( event, ui ) {
  6447. event.preventDefault();
  6448. // support: IE8
  6449. // If the item was selected via a click, the text selection
  6450. // will be destroyed in IE
  6451. that._setSelection();
  6452. that._select( ui.item.data( "ui-selectmenu-item" ), event );
  6453. },
  6454. focus: function( event, ui ) {
  6455. var item = ui.item.data( "ui-selectmenu-item" );
  6456. // Prevent inital focus from firing and check if its a newly focused item
  6457. if ( that.focusIndex != null && item.index !== that.focusIndex ) {
  6458. that._trigger( "focus", event, { item: item } );
  6459. if ( !that.isOpen ) {
  6460. that._select( item, event );
  6461. }
  6462. }
  6463. that.focusIndex = item.index;
  6464. that.button.attr( "aria-activedescendant",
  6465. that.menuItems.eq( item.index ).attr( "id" ) );
  6466. }
  6467. })
  6468. .menu( "instance" );
  6469. // Adjust menu styles to dropdown
  6470. this.menu
  6471. .addClass( "ui-corner-bottom" )
  6472. .removeClass( "ui-corner-all" );
  6473. // Don't close the menu on mouseleave
  6474. this.menuInstance._off( this.menu, "mouseleave" );
  6475. // Cancel the menu's collapseAll on document click
  6476. this.menuInstance._closeOnDocumentClick = function() {
  6477. return false;
  6478. };
  6479. // Selects often contain empty items, but never contain dividers
  6480. this.menuInstance._isDivider = function() {
  6481. return false;
  6482. };
  6483. },
  6484. refresh: function() {
  6485. this._refreshMenu();
  6486. this._setText( this.buttonText, this._getSelectedItem().text() );
  6487. if ( !this.options.width ) {
  6488. this._resizeButton();
  6489. }
  6490. },
  6491. _refreshMenu: function() {
  6492. this.menu.empty();
  6493. var item,
  6494. options = this.element.find( "option" );
  6495. if ( !options.length ) {
  6496. return;
  6497. }
  6498. this._parseOptions( options );
  6499. this._renderMenu( this.menu, this.items );
  6500. this.menuInstance.refresh();
  6501. this.menuItems = this.menu.find( "li" ).not( ".ui-selectmenu-optgroup" );
  6502. item = this._getSelectedItem();
  6503. // Update the menu to have the correct item focused
  6504. this.menuInstance.focus( null, item );
  6505. this._setAria( item.data( "ui-selectmenu-item" ) );
  6506. // Set disabled state
  6507. this._setOption( "disabled", this.element.prop( "disabled" ) );
  6508. },
  6509. open: function( event ) {
  6510. if ( this.options.disabled ) {
  6511. return;
  6512. }
  6513. // If this is the first time the menu is being opened, render the items
  6514. if ( !this.menuItems ) {
  6515. this._refreshMenu();
  6516. } else {
  6517. // Menu clears focus on close, reset focus to selected item
  6518. this.menu.find( ".ui-state-focus" ).removeClass( "ui-state-focus" );
  6519. this.menuInstance.focus( null, this._getSelectedItem() );
  6520. }
  6521. this.isOpen = true;
  6522. this._toggleAttr();
  6523. this._resizeMenu();
  6524. this._position();
  6525. this._on( this.document, this._documentClick );
  6526. this._trigger( "open", event );
  6527. },
  6528. _position: function() {
  6529. this.menuWrap.position( $.extend( { of: this.button }, this.options.position ) );
  6530. },
  6531. close: function( event ) {
  6532. if ( !this.isOpen ) {
  6533. return;
  6534. }
  6535. this.isOpen = false;
  6536. this._toggleAttr();
  6537. this.range = null;
  6538. this._off( this.document );
  6539. this._trigger( "close", event );
  6540. },
  6541. widget: function() {
  6542. return this.button;
  6543. },
  6544. menuWidget: function() {
  6545. return this.menu;
  6546. },
  6547. _renderMenu: function( ul, items ) {
  6548. var that = this,
  6549. currentOptgroup = "";
  6550. $.each( items, function( index, item ) {
  6551. if ( item.optgroup !== currentOptgroup ) {
  6552. $( "<li>", {
  6553. "class": "ui-selectmenu-optgroup ui-menu-divider" +
  6554. ( item.element.parent( "optgroup" ).prop( "disabled" ) ?
  6555. " ui-state-disabled" :
  6556. "" ),
  6557. text: item.optgroup
  6558. })
  6559. .appendTo( ul );
  6560. currentOptgroup = item.optgroup;
  6561. }
  6562. that._renderItemData( ul, item );
  6563. });
  6564. },
  6565. _renderItemData: function( ul, item ) {
  6566. return this._renderItem( ul, item ).data( "ui-selectmenu-item", item );
  6567. },
  6568. _renderItem: function( ul, item ) {
  6569. var li = $( "<li>" );
  6570. if ( item.disabled ) {
  6571. li.addClass( "ui-state-disabled" );
  6572. }
  6573. this._setText( li, item.label );
  6574. return li.appendTo( ul );
  6575. },
  6576. _setText: function( element, value ) {
  6577. if ( value ) {
  6578. element.text( value );
  6579. } else {
  6580. element.html( "&#160;" );
  6581. }
  6582. },
  6583. _move: function( direction, event ) {
  6584. var item, next,
  6585. filter = ".ui-menu-item";
  6586. if ( this.isOpen ) {
  6587. item = this.menuItems.eq( this.focusIndex );
  6588. } else {
  6589. item = this.menuItems.eq( this.element[ 0 ].selectedIndex );
  6590. filter += ":not(.ui-state-disabled)";
  6591. }
  6592. if ( direction === "first" || direction === "last" ) {
  6593. next = item[ direction === "first" ? "prevAll" : "nextAll" ]( filter ).eq( -1 );
  6594. } else {
  6595. next = item[ direction + "All" ]( filter ).eq( 0 );
  6596. }
  6597. if ( next.length ) {
  6598. this.menuInstance.focus( event, next );
  6599. }
  6600. },
  6601. _getSelectedItem: function() {
  6602. return this.menuItems.eq( this.element[ 0 ].selectedIndex );
  6603. },
  6604. _toggle: function( event ) {
  6605. this[ this.isOpen ? "close" : "open" ]( event );
  6606. },
  6607. _setSelection: function() {
  6608. var selection;
  6609. if ( !this.range ) {
  6610. return;
  6611. }
  6612. if ( window.getSelection ) {
  6613. selection = window.getSelection();
  6614. selection.removeAllRanges();
  6615. selection.addRange( this.range );
  6616. // support: IE8
  6617. } else {
  6618. this.range.select();
  6619. }
  6620. // support: IE
  6621. // Setting the text selection kills the button focus in IE, but
  6622. // restoring the focus doesn't kill the selection.
  6623. this.button.focus();
  6624. },
  6625. _documentClick: {
  6626. mousedown: function( event ) {
  6627. if ( !this.isOpen ) {
  6628. return;
  6629. }
  6630. if ( !$( event.target ).closest( ".ui-selectmenu-menu, #" + this.ids.button ).length ) {
  6631. this.close( event );
  6632. }
  6633. }
  6634. },
  6635. _buttonEvents: {
  6636. // Prevent text selection from being reset when interacting with the selectmenu (#10144)
  6637. mousedown: function() {
  6638. var selection;
  6639. if ( window.getSelection ) {
  6640. selection = window.getSelection();
  6641. if ( selection.rangeCount ) {
  6642. this.range = selection.getRangeAt( 0 );
  6643. }
  6644. // support: IE8
  6645. } else {
  6646. this.range = document.selection.createRange();
  6647. }
  6648. },
  6649. click: function( event ) {
  6650. this._setSelection();
  6651. this._toggle( event );
  6652. },
  6653. keydown: function( event ) {
  6654. var preventDefault = true;
  6655. switch ( event.keyCode ) {
  6656. case $.ui.keyCode.TAB:
  6657. case $.ui.keyCode.ESCAPE:
  6658. this.close( event );
  6659. preventDefault = false;
  6660. break;
  6661. case $.ui.keyCode.ENTER:
  6662. if ( this.isOpen ) {
  6663. this._selectFocusedItem( event );
  6664. }
  6665. break;
  6666. case $.ui.keyCode.UP:
  6667. if ( event.altKey ) {
  6668. this._toggle( event );
  6669. } else {
  6670. this._move( "prev", event );
  6671. }
  6672. break;
  6673. case $.ui.keyCode.DOWN:
  6674. if ( event.altKey ) {
  6675. this._toggle( event );
  6676. } else {
  6677. this._move( "next", event );
  6678. }
  6679. break;
  6680. case $.ui.keyCode.SPACE:
  6681. if ( this.isOpen ) {
  6682. this._selectFocusedItem( event );
  6683. } else {
  6684. this._toggle( event );
  6685. }
  6686. break;
  6687. case $.ui.keyCode.LEFT:
  6688. this._move( "prev", event );
  6689. break;
  6690. case $.ui.keyCode.RIGHT:
  6691. this._move( "next", event );
  6692. break;
  6693. case $.ui.keyCode.HOME:
  6694. case $.ui.keyCode.PAGE_UP:
  6695. this._move( "first", event );
  6696. break;
  6697. case $.ui.keyCode.END:
  6698. case $.ui.keyCode.PAGE_DOWN:
  6699. this._move( "last", event );
  6700. break;
  6701. default:
  6702. this.menu.trigger( event );
  6703. preventDefault = false;
  6704. }
  6705. if ( preventDefault ) {
  6706. event.preventDefault();
  6707. }
  6708. }
  6709. },
  6710. _selectFocusedItem: function( event ) {
  6711. var item = this.menuItems.eq( this.focusIndex );
  6712. if ( !item.hasClass( "ui-state-disabled" ) ) {
  6713. this._select( item.data( "ui-selectmenu-item" ), event );
  6714. }
  6715. },
  6716. _select: function( item, event ) {
  6717. var oldIndex = this.element[ 0 ].selectedIndex;
  6718. // Change native select element
  6719. this.element[ 0 ].selectedIndex = item.index;
  6720. this._setText( this.buttonText, item.label );
  6721. this._setAria( item );
  6722. this._trigger( "select", event, { item: item } );
  6723. if ( item.index !== oldIndex ) {
  6724. this._trigger( "change", event, { item: item } );
  6725. }
  6726. this.close( event );
  6727. },
  6728. _setAria: function( item ) {
  6729. var id = this.menuItems.eq( item.index ).attr( "id" );
  6730. this.button.attr({
  6731. "aria-labelledby": id,
  6732. "aria-activedescendant": id
  6733. });
  6734. this.menu.attr( "aria-activedescendant", id );
  6735. },
  6736. _setOption: function( key, value ) {
  6737. if ( key === "icons" ) {
  6738. this.button.find( "span.ui-icon" )
  6739. .removeClass( this.options.icons.button )
  6740. .addClass( value.button );
  6741. }
  6742. this._super( key, value );
  6743. if ( key === "appendTo" ) {
  6744. this.menuWrap.appendTo( this._appendTo() );
  6745. }
  6746. if ( key === "disabled" ) {
  6747. this.menuInstance.option( "disabled", value );
  6748. this.button
  6749. .toggleClass( "ui-state-disabled", value )
  6750. .attr( "aria-disabled", value );
  6751. this.element.prop( "disabled", value );
  6752. if ( value ) {
  6753. this.button.attr( "tabindex", -1 );
  6754. this.close();
  6755. } else {
  6756. this.button.attr( "tabindex", 0 );
  6757. }
  6758. }
  6759. if ( key === "width" ) {
  6760. this._resizeButton();
  6761. }
  6762. },
  6763. _appendTo: function() {
  6764. var element = this.options.appendTo;
  6765. if ( element ) {
  6766. element = element.jquery || element.nodeType ?
  6767. $( element ) :
  6768. this.document.find( element ).eq( 0 );
  6769. }
  6770. if ( !element || !element[ 0 ] ) {
  6771. element = this.element.closest( ".ui-front" );
  6772. }
  6773. if ( !element.length ) {
  6774. element = this.document[ 0 ].body;
  6775. }
  6776. return element;
  6777. },
  6778. _toggleAttr: function() {
  6779. this.button
  6780. .toggleClass( "ui-corner-top", this.isOpen )
  6781. .toggleClass( "ui-corner-all", !this.isOpen )
  6782. .attr( "aria-expanded", this.isOpen );
  6783. this.menuWrap.toggleClass( "ui-selectmenu-open", this.isOpen );
  6784. this.menu.attr( "aria-hidden", !this.isOpen );
  6785. },
  6786. _resizeButton: function() {
  6787. var width = this.options.width;
  6788. if ( !width ) {
  6789. width = this.element.show().outerWidth();
  6790. this.element.hide();
  6791. }
  6792. this.button.outerWidth( width );
  6793. },
  6794. _resizeMenu: function() {
  6795. this.menu.outerWidth( Math.max(
  6796. this.button.outerWidth(),
  6797. // support: IE10
  6798. // IE10 wraps long text (possibly a rounding bug)
  6799. // so we add 1px to avoid the wrapping
  6800. this.menu.width( "" ).outerWidth() + 1
  6801. ) );
  6802. },
  6803. _getCreateOptions: function() {
  6804. return { disabled: this.element.prop( "disabled" ) };
  6805. },
  6806. _parseOptions: function( options ) {
  6807. var data = [];
  6808. options.each(function( index, item ) {
  6809. var option = $( item ),
  6810. optgroup = option.parent( "optgroup" );
  6811. data.push({
  6812. element: option,
  6813. index: index,
  6814. value: option.val(),
  6815. label: option.text(),
  6816. optgroup: optgroup.attr( "label" ) || "",
  6817. disabled: optgroup.prop( "disabled" ) || option.prop( "disabled" )
  6818. });
  6819. });
  6820. this.items = data;
  6821. },
  6822. _destroy: function() {
  6823. this.menuWrap.remove();
  6824. this.button.remove();
  6825. this.element.show();
  6826. this.element.removeUniqueId();
  6827. this.label.attr( "for", this.ids.element );
  6828. }
  6829. });
  6830. /*!
  6831. * jQuery UI Slider 1.11.4
  6832. * http://jqueryui.com
  6833. *
  6834. * Copyright jQuery Foundation and other contributors
  6835. * Released under the MIT license.
  6836. * http://jquery.org/license
  6837. *
  6838. * http://api.jqueryui.com/slider/
  6839. */
  6840. var slider = $.widget( "ui.slider", $.ui.mouse, {
  6841. version: "1.11.4",
  6842. widgetEventPrefix: "slide",
  6843. options: {
  6844. animate: false,
  6845. distance: 0,
  6846. max: 100,
  6847. min: 0,
  6848. orientation: "horizontal",
  6849. range: false,
  6850. step: 1,
  6851. value: 0,
  6852. values: null,
  6853. // callbacks
  6854. change: null,
  6855. slide: null,
  6856. start: null,
  6857. stop: null
  6858. },
  6859. // number of pages in a slider
  6860. // (how many times can you page up/down to go through the whole range)
  6861. numPages: 5,
  6862. _create: function() {
  6863. this._keySliding = false;
  6864. this._mouseSliding = false;
  6865. this._animateOff = true;
  6866. this._handleIndex = null;
  6867. this._detectOrientation();
  6868. this._mouseInit();
  6869. this._calculateNewMax();
  6870. this.element
  6871. .addClass( "ui-slider" +
  6872. " ui-slider-" + this.orientation +
  6873. " ui-widget" +
  6874. " ui-widget-content" +
  6875. " ui-corner-all");
  6876. this._refresh();
  6877. this._setOption( "disabled", this.options.disabled );
  6878. this._animateOff = false;
  6879. },
  6880. _refresh: function() {
  6881. this._createRange();
  6882. this._createHandles();
  6883. this._setupEvents();
  6884. this._refreshValue();
  6885. },
  6886. _createHandles: function() {
  6887. var i, handleCount,
  6888. options = this.options,
  6889. existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
  6890. handle = "<span class='ui-slider-handle ui-state-default ui-corner-all' tabindex='0'></span>",
  6891. handles = [];
  6892. handleCount = ( options.values && options.values.length ) || 1;
  6893. if ( existingHandles.length > handleCount ) {
  6894. existingHandles.slice( handleCount ).remove();
  6895. existingHandles = existingHandles.slice( 0, handleCount );
  6896. }
  6897. for ( i = existingHandles.length; i < handleCount; i++ ) {
  6898. handles.push( handle );
  6899. }
  6900. this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( this.element ) );
  6901. this.handle = this.handles.eq( 0 );
  6902. this.handles.each(function( i ) {
  6903. $( this ).data( "ui-slider-handle-index", i );
  6904. });
  6905. },
  6906. _createRange: function() {
  6907. var options = this.options,
  6908. classes = "";
  6909. if ( options.range ) {
  6910. if ( options.range === true ) {
  6911. if ( !options.values ) {
  6912. options.values = [ this._valueMin(), this._valueMin() ];
  6913. } else if ( options.values.length && options.values.length !== 2 ) {
  6914. options.values = [ options.values[0], options.values[0] ];
  6915. } else if ( $.isArray( options.values ) ) {
  6916. options.values = options.values.slice(0);
  6917. }
  6918. }
  6919. if ( !this.range || !this.range.length ) {
  6920. this.range = $( "<div></div>" )
  6921. .appendTo( this.element );
  6922. classes = "ui-slider-range" +
  6923. // note: this isn't the most fittingly semantic framework class for this element,
  6924. // but worked best visually with a variety of themes
  6925. " ui-widget-header ui-corner-all";
  6926. } else {
  6927. this.range.removeClass( "ui-slider-range-min ui-slider-range-max" )
  6928. // Handle range switching from true to min/max
  6929. .css({
  6930. "left": "",
  6931. "bottom": ""
  6932. });
  6933. }
  6934. this.range.addClass( classes +
  6935. ( ( options.range === "min" || options.range === "max" ) ? " ui-slider-range-" + options.range : "" ) );
  6936. } else {
  6937. if ( this.range ) {
  6938. this.range.remove();
  6939. }
  6940. this.range = null;
  6941. }
  6942. },
  6943. _setupEvents: function() {
  6944. this._off( this.handles );
  6945. this._on( this.handles, this._handleEvents );
  6946. this._hoverable( this.handles );
  6947. this._focusable( this.handles );
  6948. },
  6949. _destroy: function() {
  6950. this.handles.remove();
  6951. if ( this.range ) {
  6952. this.range.remove();
  6953. }
  6954. this.element
  6955. .removeClass( "ui-slider" +
  6956. " ui-slider-horizontal" +
  6957. " ui-slider-vertical" +
  6958. " ui-widget" +
  6959. " ui-widget-content" +
  6960. " ui-corner-all" );
  6961. this._mouseDestroy();
  6962. },
  6963. _mouseCapture: function( event ) {
  6964. var position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle,
  6965. that = this,
  6966. o = this.options;
  6967. if ( o.disabled ) {
  6968. return false;
  6969. }
  6970. this.elementSize = {
  6971. width: this.element.outerWidth(),
  6972. height: this.element.outerHeight()
  6973. };
  6974. this.elementOffset = this.element.offset();
  6975. position = { x: event.pageX, y: event.pageY };
  6976. normValue = this._normValueFromMouse( position );
  6977. distance = this._valueMax() - this._valueMin() + 1;
  6978. this.handles.each(function( i ) {
  6979. var thisDistance = Math.abs( normValue - that.values(i) );
  6980. if (( distance > thisDistance ) ||
  6981. ( distance === thisDistance &&
  6982. (i === that._lastChangedValue || that.values(i) === o.min ))) {
  6983. distance = thisDistance;
  6984. closestHandle = $( this );
  6985. index = i;
  6986. }
  6987. });
  6988. allowed = this._start( event, index );
  6989. if ( allowed === false ) {
  6990. return false;
  6991. }
  6992. this._mouseSliding = true;
  6993. this._handleIndex = index;
  6994. closestHandle
  6995. .addClass( "ui-state-active" )
  6996. .focus();
  6997. offset = closestHandle.offset();
  6998. mouseOverHandle = !$( event.target ).parents().addBack().is( ".ui-slider-handle" );
  6999. this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
  7000. left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
  7001. top: event.pageY - offset.top -
  7002. ( closestHandle.height() / 2 ) -
  7003. ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) -
  7004. ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) +
  7005. ( parseInt( closestHandle.css("marginTop"), 10 ) || 0)
  7006. };
  7007. if ( !this.handles.hasClass( "ui-state-hover" ) ) {
  7008. this._slide( event, index, normValue );
  7009. }
  7010. this._animateOff = true;
  7011. return true;
  7012. },
  7013. _mouseStart: function() {
  7014. return true;
  7015. },
  7016. _mouseDrag: function( event ) {
  7017. var position = { x: event.pageX, y: event.pageY },
  7018. normValue = this._normValueFromMouse( position );
  7019. this._slide( event, this._handleIndex, normValue );
  7020. return false;
  7021. },
  7022. _mouseStop: function( event ) {
  7023. this.handles.removeClass( "ui-state-active" );
  7024. this._mouseSliding = false;
  7025. this._stop( event, this._handleIndex );
  7026. this._change( event, this._handleIndex );
  7027. this._handleIndex = null;
  7028. this._clickOffset = null;
  7029. this._animateOff = false;
  7030. return false;
  7031. },
  7032. _detectOrientation: function() {
  7033. this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
  7034. },
  7035. _normValueFromMouse: function( position ) {
  7036. var pixelTotal,
  7037. pixelMouse,
  7038. percentMouse,
  7039. valueTotal,
  7040. valueMouse;
  7041. if ( this.orientation === "horizontal" ) {
  7042. pixelTotal = this.elementSize.width;
  7043. pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 );
  7044. } else {
  7045. pixelTotal = this.elementSize.height;
  7046. pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 );
  7047. }
  7048. percentMouse = ( pixelMouse / pixelTotal );
  7049. if ( percentMouse > 1 ) {
  7050. percentMouse = 1;
  7051. }
  7052. if ( percentMouse < 0 ) {
  7053. percentMouse = 0;
  7054. }
  7055. if ( this.orientation === "vertical" ) {
  7056. percentMouse = 1 - percentMouse;
  7057. }
  7058. valueTotal = this._valueMax() - this._valueMin();
  7059. valueMouse = this._valueMin() + percentMouse * valueTotal;
  7060. return this._trimAlignValue( valueMouse );
  7061. },
  7062. _start: function( event, index ) {
  7063. var uiHash = {
  7064. handle: this.handles[ index ],
  7065. value: this.value()
  7066. };
  7067. if ( this.options.values && this.options.values.length ) {
  7068. uiHash.value = this.values( index );
  7069. uiHash.values = this.values();
  7070. }
  7071. return this._trigger( "start", event, uiHash );
  7072. },
  7073. _slide: function( event, index, newVal ) {
  7074. var otherVal,
  7075. newValues,
  7076. allowed;
  7077. if ( this.options.values && this.options.values.length ) {
  7078. otherVal = this.values( index ? 0 : 1 );
  7079. if ( ( this.options.values.length === 2 && this.options.range === true ) &&
  7080. ( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
  7081. ) {
  7082. newVal = otherVal;
  7083. }
  7084. if ( newVal !== this.values( index ) ) {
  7085. newValues = this.values();
  7086. newValues[ index ] = newVal;
  7087. // A slide can be canceled by returning false from the slide callback
  7088. allowed = this._trigger( "slide", event, {
  7089. handle: this.handles[ index ],
  7090. value: newVal,
  7091. values: newValues
  7092. } );
  7093. otherVal = this.values( index ? 0 : 1 );
  7094. if ( allowed !== false ) {
  7095. this.values( index, newVal );
  7096. }
  7097. }
  7098. } else {
  7099. if ( newVal !== this.value() ) {
  7100. // A slide can be canceled by returning false from the slide callback
  7101. allowed = this._trigger( "slide", event, {
  7102. handle: this.handles[ index ],
  7103. value: newVal
  7104. } );
  7105. if ( allowed !== false ) {
  7106. this.value( newVal );
  7107. }
  7108. }
  7109. }
  7110. },
  7111. _stop: function( event, index ) {
  7112. var uiHash = {
  7113. handle: this.handles[ index ],
  7114. value: this.value()
  7115. };
  7116. if ( this.options.values && this.options.values.length ) {
  7117. uiHash.value = this.values( index );
  7118. uiHash.values = this.values();
  7119. }
  7120. this._trigger( "stop", event, uiHash );
  7121. },
  7122. _change: function( event, index ) {
  7123. if ( !this._keySliding && !this._mouseSliding ) {
  7124. var uiHash = {
  7125. handle: this.handles[ index ],
  7126. value: this.value()
  7127. };
  7128. if ( this.options.values && this.options.values.length ) {
  7129. uiHash.value = this.values( index );
  7130. uiHash.values = this.values();
  7131. }
  7132. //store the last changed value index for reference when handles overlap
  7133. this._lastChangedValue = index;
  7134. this._trigger( "change", event, uiHash );
  7135. }
  7136. },
  7137. value: function( newValue ) {
  7138. if ( arguments.length ) {
  7139. this.options.value = this._trimAlignValue( newValue );
  7140. this._refreshValue();
  7141. this._change( null, 0 );
  7142. return;
  7143. }
  7144. return this._value();
  7145. },
  7146. values: function( index, newValue ) {
  7147. var vals,
  7148. newValues,
  7149. i;
  7150. if ( arguments.length > 1 ) {
  7151. this.options.values[ index ] = this._trimAlignValue( newValue );
  7152. this._refreshValue();
  7153. this._change( null, index );
  7154. return;
  7155. }
  7156. if ( arguments.length ) {
  7157. if ( $.isArray( arguments[ 0 ] ) ) {
  7158. vals = this.options.values;
  7159. newValues = arguments[ 0 ];
  7160. for ( i = 0; i < vals.length; i += 1 ) {
  7161. vals[ i ] = this._trimAlignValue( newValues[ i ] );
  7162. this._change( null, i );
  7163. }
  7164. this._refreshValue();
  7165. } else {
  7166. if ( this.options.values && this.options.values.length ) {
  7167. return this._values( index );
  7168. } else {
  7169. return this.value();
  7170. }
  7171. }
  7172. } else {
  7173. return this._values();
  7174. }
  7175. },
  7176. _setOption: function( key, value ) {
  7177. var i,
  7178. valsLength = 0;
  7179. if ( key === "range" && this.options.range === true ) {
  7180. if ( value === "min" ) {
  7181. this.options.value = this._values( 0 );
  7182. this.options.values = null;
  7183. } else if ( value === "max" ) {
  7184. this.options.value = this._values( this.options.values.length - 1 );
  7185. this.options.values = null;
  7186. }
  7187. }
  7188. if ( $.isArray( this.options.values ) ) {
  7189. valsLength = this.options.values.length;
  7190. }
  7191. if ( key === "disabled" ) {
  7192. this.element.toggleClass( "ui-state-disabled", !!value );
  7193. }
  7194. this._super( key, value );
  7195. switch ( key ) {
  7196. case "orientation":
  7197. this._detectOrientation();
  7198. this.element
  7199. .removeClass( "ui-slider-horizontal ui-slider-vertical" )
  7200. .addClass( "ui-slider-" + this.orientation );
  7201. this._refreshValue();
  7202. // Reset positioning from previous orientation
  7203. this.handles.css( value === "horizontal" ? "bottom" : "left", "" );
  7204. break;
  7205. case "value":
  7206. this._animateOff = true;
  7207. this._refreshValue();
  7208. this._change( null, 0 );
  7209. this._animateOff = false;
  7210. break;
  7211. case "values":
  7212. this._animateOff = true;
  7213. this._refreshValue();
  7214. for ( i = 0; i < valsLength; i += 1 ) {
  7215. this._change( null, i );
  7216. }
  7217. this._animateOff = false;
  7218. break;
  7219. case "step":
  7220. case "min":
  7221. case "max":
  7222. this._animateOff = true;
  7223. this._calculateNewMax();
  7224. this._refreshValue();
  7225. this._animateOff = false;
  7226. break;
  7227. case "range":
  7228. this._animateOff = true;
  7229. this._refresh();
  7230. this._animateOff = false;
  7231. break;
  7232. }
  7233. },
  7234. //internal value getter
  7235. // _value() returns value trimmed by min and max, aligned by step
  7236. _value: function() {
  7237. var val = this.options.value;
  7238. val = this._trimAlignValue( val );
  7239. return val;
  7240. },
  7241. //internal values getter
  7242. // _values() returns array of values trimmed by min and max, aligned by step
  7243. // _values( index ) returns single value trimmed by min and max, aligned by step
  7244. _values: function( index ) {
  7245. var val,
  7246. vals,
  7247. i;
  7248. if ( arguments.length ) {
  7249. val = this.options.values[ index ];
  7250. val = this._trimAlignValue( val );
  7251. return val;
  7252. } else if ( this.options.values && this.options.values.length ) {
  7253. // .slice() creates a copy of the array
  7254. // this copy gets trimmed by min and max and then returned
  7255. vals = this.options.values.slice();
  7256. for ( i = 0; i < vals.length; i += 1) {
  7257. vals[ i ] = this._trimAlignValue( vals[ i ] );
  7258. }
  7259. return vals;
  7260. } else {
  7261. return [];
  7262. }
  7263. },
  7264. // returns the step-aligned value that val is closest to, between (inclusive) min and max
  7265. _trimAlignValue: function( val ) {
  7266. if ( val <= this._valueMin() ) {
  7267. return this._valueMin();
  7268. }
  7269. if ( val >= this._valueMax() ) {
  7270. return this._valueMax();
  7271. }
  7272. var step = ( this.options.step > 0 ) ? this.options.step : 1,
  7273. valModStep = (val - this._valueMin()) % step,
  7274. alignValue = val - valModStep;
  7275. if ( Math.abs(valModStep) * 2 >= step ) {
  7276. alignValue += ( valModStep > 0 ) ? step : ( -step );
  7277. }
  7278. // Since JavaScript has problems with large floats, round
  7279. // the final value to 5 digits after the decimal point (see #4124)
  7280. return parseFloat( alignValue.toFixed(5) );
  7281. },
  7282. _calculateNewMax: function() {
  7283. var max = this.options.max,
  7284. min = this._valueMin(),
  7285. step = this.options.step,
  7286. aboveMin = Math.floor( ( +( max - min ).toFixed( this._precision() ) ) / step ) * step;
  7287. max = aboveMin + min;
  7288. this.max = parseFloat( max.toFixed( this._precision() ) );
  7289. },
  7290. _precision: function() {
  7291. var precision = this._precisionOf( this.options.step );
  7292. if ( this.options.min !== null ) {
  7293. precision = Math.max( precision, this._precisionOf( this.options.min ) );
  7294. }
  7295. return precision;
  7296. },
  7297. _precisionOf: function( num ) {
  7298. var str = num.toString(),
  7299. decimal = str.indexOf( "." );
  7300. return decimal === -1 ? 0 : str.length - decimal - 1;
  7301. },
  7302. _valueMin: function() {
  7303. return this.options.min;
  7304. },
  7305. _valueMax: function() {
  7306. return this.max;
  7307. },
  7308. _refreshValue: function() {
  7309. var lastValPercent, valPercent, value, valueMin, valueMax,
  7310. oRange = this.options.range,
  7311. o = this.options,
  7312. that = this,
  7313. animate = ( !this._animateOff ) ? o.animate : false,
  7314. _set = {};
  7315. if ( this.options.values && this.options.values.length ) {
  7316. this.handles.each(function( i ) {
  7317. valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100;
  7318. _set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
  7319. $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
  7320. if ( that.options.range === true ) {
  7321. if ( that.orientation === "horizontal" ) {
  7322. if ( i === 0 ) {
  7323. that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
  7324. }
  7325. if ( i === 1 ) {
  7326. that.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
  7327. }
  7328. } else {
  7329. if ( i === 0 ) {
  7330. that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
  7331. }
  7332. if ( i === 1 ) {
  7333. that.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
  7334. }
  7335. }
  7336. }
  7337. lastValPercent = valPercent;
  7338. });
  7339. } else {
  7340. value = this.value();
  7341. valueMin = this._valueMin();
  7342. valueMax = this._valueMax();
  7343. valPercent = ( valueMax !== valueMin ) ?
  7344. ( value - valueMin ) / ( valueMax - valueMin ) * 100 :
  7345. 0;
  7346. _set[ this.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
  7347. this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
  7348. if ( oRange === "min" && this.orientation === "horizontal" ) {
  7349. this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate );
  7350. }
  7351. if ( oRange === "max" && this.orientation === "horizontal" ) {
  7352. this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
  7353. }
  7354. if ( oRange === "min" && this.orientation === "vertical" ) {
  7355. this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate );
  7356. }
  7357. if ( oRange === "max" && this.orientation === "vertical" ) {
  7358. this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
  7359. }
  7360. }
  7361. },
  7362. _handleEvents: {
  7363. keydown: function( event ) {
  7364. var allowed, curVal, newVal, step,
  7365. index = $( event.target ).data( "ui-slider-handle-index" );
  7366. switch ( event.keyCode ) {
  7367. case $.ui.keyCode.HOME:
  7368. case $.ui.keyCode.END:
  7369. case $.ui.keyCode.PAGE_UP:
  7370. case $.ui.keyCode.PAGE_DOWN:
  7371. case $.ui.keyCode.UP:
  7372. case $.ui.keyCode.RIGHT:
  7373. case $.ui.keyCode.DOWN:
  7374. case $.ui.keyCode.LEFT:
  7375. event.preventDefault();
  7376. if ( !this._keySliding ) {
  7377. this._keySliding = true;
  7378. $( event.target ).addClass( "ui-state-active" );
  7379. allowed = this._start( event, index );
  7380. if ( allowed === false ) {
  7381. return;
  7382. }
  7383. }
  7384. break;
  7385. }
  7386. step = this.options.step;
  7387. if ( this.options.values && this.options.values.length ) {
  7388. curVal = newVal = this.values( index );
  7389. } else {
  7390. curVal = newVal = this.value();
  7391. }
  7392. switch ( event.keyCode ) {
  7393. case $.ui.keyCode.HOME:
  7394. newVal = this._valueMin();
  7395. break;
  7396. case $.ui.keyCode.END:
  7397. newVal = this._valueMax();
  7398. break;
  7399. case $.ui.keyCode.PAGE_UP:
  7400. newVal = this._trimAlignValue(
  7401. curVal + ( ( this._valueMax() - this._valueMin() ) / this.numPages )
  7402. );
  7403. break;
  7404. case $.ui.keyCode.PAGE_DOWN:
  7405. newVal = this._trimAlignValue(
  7406. curVal - ( (this._valueMax() - this._valueMin()) / this.numPages ) );
  7407. break;
  7408. case $.ui.keyCode.UP:
  7409. case $.ui.keyCode.RIGHT:
  7410. if ( curVal === this._valueMax() ) {
  7411. return;
  7412. }
  7413. newVal = this._trimAlignValue( curVal + step );
  7414. break;
  7415. case $.ui.keyCode.DOWN:
  7416. case $.ui.keyCode.LEFT:
  7417. if ( curVal === this._valueMin() ) {
  7418. return;
  7419. }
  7420. newVal = this._trimAlignValue( curVal - step );
  7421. break;
  7422. }
  7423. this._slide( event, index, newVal );
  7424. },
  7425. keyup: function( event ) {
  7426. var index = $( event.target ).data( "ui-slider-handle-index" );
  7427. if ( this._keySliding ) {
  7428. this._keySliding = false;
  7429. this._stop( event, index );
  7430. this._change( event, index );
  7431. $( event.target ).removeClass( "ui-state-active" );
  7432. }
  7433. }
  7434. }
  7435. });
  7436. /*!
  7437. * jQuery UI Spinner 1.11.4
  7438. * http://jqueryui.com
  7439. *
  7440. * Copyright jQuery Foundation and other contributors
  7441. * Released under the MIT license.
  7442. * http://jquery.org/license
  7443. *
  7444. * http://api.jqueryui.com/spinner/
  7445. */
  7446. function spinner_modifier( fn ) {
  7447. return function() {
  7448. var previous = this.element.val();
  7449. fn.apply( this, arguments );
  7450. this._refresh();
  7451. if ( previous !== this.element.val() ) {
  7452. this._trigger( "change" );
  7453. }
  7454. };
  7455. }
  7456. var spinner = $.widget( "ui.spinner", {
  7457. version: "1.11.4",
  7458. defaultElement: "<input>",
  7459. widgetEventPrefix: "spin",
  7460. options: {
  7461. culture: null,
  7462. icons: {
  7463. down: "ui-icon-triangle-1-s",
  7464. up: "ui-icon-triangle-1-n"
  7465. },
  7466. incremental: true,
  7467. max: null,
  7468. min: null,
  7469. numberFormat: null,
  7470. page: 10,
  7471. step: 1,
  7472. change: null,
  7473. spin: null,
  7474. start: null,
  7475. stop: null
  7476. },
  7477. _create: function() {
  7478. // handle string values that need to be parsed
  7479. this._setOption( "max", this.options.max );
  7480. this._setOption( "min", this.options.min );
  7481. this._setOption( "step", this.options.step );
  7482. // Only format if there is a value, prevents the field from being marked
  7483. // as invalid in Firefox, see #9573.
  7484. if ( this.value() !== "" ) {
  7485. // Format the value, but don't constrain.
  7486. this._value( this.element.val(), true );
  7487. }
  7488. this._draw();
  7489. this._on( this._events );
  7490. this._refresh();
  7491. // turning off autocomplete prevents the browser from remembering the
  7492. // value when navigating through history, so we re-enable autocomplete
  7493. // if the page is unloaded before the widget is destroyed. #7790
  7494. this._on( this.window, {
  7495. beforeunload: function() {
  7496. this.element.removeAttr( "autocomplete" );
  7497. }
  7498. });
  7499. },
  7500. _getCreateOptions: function() {
  7501. var options = {},
  7502. element = this.element;
  7503. $.each( [ "min", "max", "step" ], function( i, option ) {
  7504. var value = element.attr( option );
  7505. if ( value !== undefined && value.length ) {
  7506. options[ option ] = value;
  7507. }
  7508. });
  7509. return options;
  7510. },
  7511. _events: {
  7512. keydown: function( event ) {
  7513. if ( this._start( event ) && this._keydown( event ) ) {
  7514. event.preventDefault();
  7515. }
  7516. },
  7517. keyup: "_stop",
  7518. focus: function() {
  7519. this.previous = this.element.val();
  7520. },
  7521. blur: function( event ) {
  7522. if ( this.cancelBlur ) {
  7523. delete this.cancelBlur;
  7524. return;
  7525. }
  7526. this._stop();
  7527. this._refresh();
  7528. if ( this.previous !== this.element.val() ) {
  7529. this._trigger( "change", event );
  7530. }
  7531. },
  7532. mousewheel: function( event, delta ) {
  7533. if ( !delta ) {
  7534. return;
  7535. }
  7536. if ( !this.spinning && !this._start( event ) ) {
  7537. return false;
  7538. }
  7539. this._spin( (delta > 0 ? 1 : -1) * this.options.step, event );
  7540. clearTimeout( this.mousewheelTimer );
  7541. this.mousewheelTimer = this._delay(function() {
  7542. if ( this.spinning ) {
  7543. this._stop( event );
  7544. }
  7545. }, 100 );
  7546. event.preventDefault();
  7547. },
  7548. "mousedown .ui-spinner-button": function( event ) {
  7549. var previous;
  7550. // We never want the buttons to have focus; whenever the user is
  7551. // interacting with the spinner, the focus should be on the input.
  7552. // If the input is focused then this.previous is properly set from
  7553. // when the input first received focus. If the input is not focused
  7554. // then we need to set this.previous based on the value before spinning.
  7555. previous = this.element[0] === this.document[0].activeElement ?
  7556. this.previous : this.element.val();
  7557. function checkFocus() {
  7558. var isActive = this.element[0] === this.document[0].activeElement;
  7559. if ( !isActive ) {
  7560. this.element.focus();
  7561. this.previous = previous;
  7562. // support: IE
  7563. // IE sets focus asynchronously, so we need to check if focus
  7564. // moved off of the input because the user clicked on the button.
  7565. this._delay(function() {
  7566. this.previous = previous;
  7567. });
  7568. }
  7569. }
  7570. // ensure focus is on (or stays on) the text field
  7571. event.preventDefault();
  7572. checkFocus.call( this );
  7573. // support: IE
  7574. // IE doesn't prevent moving focus even with event.preventDefault()
  7575. // so we set a flag to know when we should ignore the blur event
  7576. // and check (again) if focus moved off of the input.
  7577. this.cancelBlur = true;
  7578. this._delay(function() {
  7579. delete this.cancelBlur;
  7580. checkFocus.call( this );
  7581. });
  7582. if ( this._start( event ) === false ) {
  7583. return;
  7584. }
  7585. this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event );
  7586. },
  7587. "mouseup .ui-spinner-button": "_stop",
  7588. "mouseenter .ui-spinner-button": function( event ) {
  7589. // button will add ui-state-active if mouse was down while mouseleave and kept down
  7590. if ( !$( event.currentTarget ).hasClass( "ui-state-active" ) ) {
  7591. return;
  7592. }
  7593. if ( this._start( event ) === false ) {
  7594. return false;
  7595. }
  7596. this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event );
  7597. },
  7598. // TODO: do we really want to consider this a stop?
  7599. // shouldn't we just stop the repeater and wait until mouseup before
  7600. // we trigger the stop event?
  7601. "mouseleave .ui-spinner-button": "_stop"
  7602. },
  7603. _draw: function() {
  7604. var uiSpinner = this.uiSpinner = this.element
  7605. .addClass( "ui-spinner-input" )
  7606. .attr( "autocomplete", "off" )
  7607. .wrap( this._uiSpinnerHtml() )
  7608. .parent()
  7609. // add buttons
  7610. .append( this._buttonHtml() );
  7611. this.element.attr( "role", "spinbutton" );
  7612. // button bindings
  7613. this.buttons = uiSpinner.find( ".ui-spinner-button" )
  7614. .attr( "tabIndex", -1 )
  7615. .button()
  7616. .removeClass( "ui-corner-all" );
  7617. // IE 6 doesn't understand height: 50% for the buttons
  7618. // unless the wrapper has an explicit height
  7619. if ( this.buttons.height() > Math.ceil( uiSpinner.height() * 0.5 ) &&
  7620. uiSpinner.height() > 0 ) {
  7621. uiSpinner.height( uiSpinner.height() );
  7622. }
  7623. // disable spinner if element was already disabled
  7624. if ( this.options.disabled ) {
  7625. this.disable();
  7626. }
  7627. },
  7628. _keydown: function( event ) {
  7629. var options = this.options,
  7630. keyCode = $.ui.keyCode;
  7631. switch ( event.keyCode ) {
  7632. case keyCode.UP:
  7633. this._repeat( null, 1, event );
  7634. return true;
  7635. case keyCode.DOWN:
  7636. this._repeat( null, -1, event );
  7637. return true;
  7638. case keyCode.PAGE_UP:
  7639. this._repeat( null, options.page, event );
  7640. return true;
  7641. case keyCode.PAGE_DOWN:
  7642. this._repeat( null, -options.page, event );
  7643. return true;
  7644. }
  7645. return false;
  7646. },
  7647. _uiSpinnerHtml: function() {
  7648. return "<span class='ui-spinner ui-widget ui-widget-content ui-corner-all'></span>";
  7649. },
  7650. _buttonHtml: function() {
  7651. return "" +
  7652. "<a class='ui-spinner-button ui-spinner-up ui-corner-tr'>" +
  7653. "<span class='ui-icon " + this.options.icons.up + "'>&#9650;</span>" +
  7654. "</a>" +
  7655. "<a class='ui-spinner-button ui-spinner-down ui-corner-br'>" +
  7656. "<span class='ui-icon " + this.options.icons.down + "'>&#9660;</span>" +
  7657. "</a>";
  7658. },
  7659. _start: function( event ) {
  7660. if ( !this.spinning && this._trigger( "start", event ) === false ) {
  7661. return false;
  7662. }
  7663. if ( !this.counter ) {
  7664. this.counter = 1;
  7665. }
  7666. this.spinning = true;
  7667. return true;
  7668. },
  7669. _repeat: function( i, steps, event ) {
  7670. i = i || 500;
  7671. clearTimeout( this.timer );
  7672. this.timer = this._delay(function() {
  7673. this._repeat( 40, steps, event );
  7674. }, i );
  7675. this._spin( steps * this.options.step, event );
  7676. },
  7677. _spin: function( step, event ) {
  7678. var value = this.value() || 0;
  7679. if ( !this.counter ) {
  7680. this.counter = 1;
  7681. }
  7682. value = this._adjustValue( value + step * this._increment( this.counter ) );
  7683. if ( !this.spinning || this._trigger( "spin", event, { value: value } ) !== false) {
  7684. this._value( value );
  7685. this.counter++;
  7686. }
  7687. },
  7688. _increment: function( i ) {
  7689. var incremental = this.options.incremental;
  7690. if ( incremental ) {
  7691. return $.isFunction( incremental ) ?
  7692. incremental( i ) :
  7693. Math.floor( i * i * i / 50000 - i * i / 500 + 17 * i / 200 + 1 );
  7694. }
  7695. return 1;
  7696. },
  7697. _precision: function() {
  7698. var precision = this._precisionOf( this.options.step );
  7699. if ( this.options.min !== null ) {
  7700. precision = Math.max( precision, this._precisionOf( this.options.min ) );
  7701. }
  7702. return precision;
  7703. },
  7704. _precisionOf: function( num ) {
  7705. var str = num.toString(),
  7706. decimal = str.indexOf( "." );
  7707. return decimal === -1 ? 0 : str.length - decimal - 1;
  7708. },
  7709. _adjustValue: function( value ) {
  7710. var base, aboveMin,
  7711. options = this.options;
  7712. // make sure we're at a valid step
  7713. // - find out where we are relative to the base (min or 0)
  7714. base = options.min !== null ? options.min : 0;
  7715. aboveMin = value - base;
  7716. // - round to the nearest step
  7717. aboveMin = Math.round(aboveMin / options.step) * options.step;
  7718. // - rounding is based on 0, so adjust back to our base
  7719. value = base + aboveMin;
  7720. // fix precision from bad JS floating point math
  7721. value = parseFloat( value.toFixed( this._precision() ) );
  7722. // clamp the value
  7723. if ( options.max !== null && value > options.max) {
  7724. return options.max;
  7725. }
  7726. if ( options.min !== null && value < options.min ) {
  7727. return options.min;
  7728. }
  7729. return value;
  7730. },
  7731. _stop: function( event ) {
  7732. if ( !this.spinning ) {
  7733. return;
  7734. }
  7735. clearTimeout( this.timer );
  7736. clearTimeout( this.mousewheelTimer );
  7737. this.counter = 0;
  7738. this.spinning = false;
  7739. this._trigger( "stop", event );
  7740. },
  7741. _setOption: function( key, value ) {
  7742. if ( key === "culture" || key === "numberFormat" ) {
  7743. var prevValue = this._parse( this.element.val() );
  7744. this.options[ key ] = value;
  7745. this.element.val( this._format( prevValue ) );
  7746. return;
  7747. }
  7748. if ( key === "max" || key === "min" || key === "step" ) {
  7749. if ( typeof value === "string" ) {
  7750. value = this._parse( value );
  7751. }
  7752. }
  7753. if ( key === "icons" ) {
  7754. this.buttons.first().find( ".ui-icon" )
  7755. .removeClass( this.options.icons.up )
  7756. .addClass( value.up );
  7757. this.buttons.last().find( ".ui-icon" )
  7758. .removeClass( this.options.icons.down )
  7759. .addClass( value.down );
  7760. }
  7761. this._super( key, value );
  7762. if ( key === "disabled" ) {
  7763. this.widget().toggleClass( "ui-state-disabled", !!value );
  7764. this.element.prop( "disabled", !!value );
  7765. this.buttons.button( value ? "disable" : "enable" );
  7766. }
  7767. },
  7768. _setOptions: spinner_modifier(function( options ) {
  7769. this._super( options );
  7770. }),
  7771. _parse: function( val ) {
  7772. if ( typeof val === "string" && val !== "" ) {
  7773. val = window.Globalize && this.options.numberFormat ?
  7774. Globalize.parseFloat( val, 10, this.options.culture ) : +val;
  7775. }
  7776. return val === "" || isNaN( val ) ? null : val;
  7777. },
  7778. _format: function( value ) {
  7779. if ( value === "" ) {
  7780. return "";
  7781. }
  7782. return window.Globalize && this.options.numberFormat ?
  7783. Globalize.format( value, this.options.numberFormat, this.options.culture ) :
  7784. value;
  7785. },
  7786. _refresh: function() {
  7787. this.element.attr({
  7788. "aria-valuemin": this.options.min,
  7789. "aria-valuemax": this.options.max,
  7790. // TODO: what should we do with values that can't be parsed?
  7791. "aria-valuenow": this._parse( this.element.val() )
  7792. });
  7793. },
  7794. isValid: function() {
  7795. var value = this.value();
  7796. // null is invalid
  7797. if ( value === null ) {
  7798. return false;
  7799. }
  7800. // if value gets adjusted, it's invalid
  7801. return value === this._adjustValue( value );
  7802. },
  7803. // update the value without triggering change
  7804. _value: function( value, allowAny ) {
  7805. var parsed;
  7806. if ( value !== "" ) {
  7807. parsed = this._parse( value );
  7808. if ( parsed !== null ) {
  7809. if ( !allowAny ) {
  7810. parsed = this._adjustValue( parsed );
  7811. }
  7812. value = this._format( parsed );
  7813. }
  7814. }
  7815. this.element.val( value );
  7816. this._refresh();
  7817. },
  7818. _destroy: function() {
  7819. this.element
  7820. .removeClass( "ui-spinner-input" )
  7821. .prop( "disabled", false )
  7822. .removeAttr( "autocomplete" )
  7823. .removeAttr( "role" )
  7824. .removeAttr( "aria-valuemin" )
  7825. .removeAttr( "aria-valuemax" )
  7826. .removeAttr( "aria-valuenow" );
  7827. this.uiSpinner.replaceWith( this.element );
  7828. },
  7829. stepUp: spinner_modifier(function( steps ) {
  7830. this._stepUp( steps );
  7831. }),
  7832. _stepUp: function( steps ) {
  7833. if ( this._start() ) {
  7834. this._spin( (steps || 1) * this.options.step );
  7835. this._stop();
  7836. }
  7837. },
  7838. stepDown: spinner_modifier(function( steps ) {
  7839. this._stepDown( steps );
  7840. }),
  7841. _stepDown: function( steps ) {
  7842. if ( this._start() ) {
  7843. this._spin( (steps || 1) * -this.options.step );
  7844. this._stop();
  7845. }
  7846. },
  7847. pageUp: spinner_modifier(function( pages ) {
  7848. this._stepUp( (pages || 1) * this.options.page );
  7849. }),
  7850. pageDown: spinner_modifier(function( pages ) {
  7851. this._stepDown( (pages || 1) * this.options.page );
  7852. }),
  7853. value: function( newVal ) {
  7854. if ( !arguments.length ) {
  7855. return this._parse( this.element.val() );
  7856. }
  7857. spinner_modifier( this._value ).call( this, newVal );
  7858. },
  7859. widget: function() {
  7860. return this.uiSpinner;
  7861. }
  7862. });
  7863. /*!
  7864. * jQuery UI Tabs 1.11.4
  7865. * http://jqueryui.com
  7866. *
  7867. * Copyright jQuery Foundation and other contributors
  7868. * Released under the MIT license.
  7869. * http://jquery.org/license
  7870. *
  7871. * http://api.jqueryui.com/tabs/
  7872. */
  7873. var tabs = $.widget( "ui.tabs", {
  7874. version: "1.11.4",
  7875. delay: 300,
  7876. options: {
  7877. active: null,
  7878. collapsible: false,
  7879. event: "click",
  7880. heightStyle: "content",
  7881. hide: null,
  7882. show: null,
  7883. // callbacks
  7884. activate: null,
  7885. beforeActivate: null,
  7886. beforeLoad: null,
  7887. load: null
  7888. },
  7889. _isLocal: (function() {
  7890. var rhash = /#.*$/;
  7891. return function( anchor ) {
  7892. var anchorUrl, locationUrl;
  7893. // support: IE7
  7894. // IE7 doesn't normalize the href property when set via script (#9317)
  7895. anchor = anchor.cloneNode( false );
  7896. anchorUrl = anchor.href.replace( rhash, "" );
  7897. locationUrl = location.href.replace( rhash, "" );
  7898. // decoding may throw an error if the URL isn't UTF-8 (#9518)
  7899. try {
  7900. anchorUrl = decodeURIComponent( anchorUrl );
  7901. } catch ( error ) {}
  7902. try {
  7903. locationUrl = decodeURIComponent( locationUrl );
  7904. } catch ( error ) {}
  7905. return anchor.hash.length > 1 && anchorUrl === locationUrl;
  7906. };
  7907. })(),
  7908. _create: function() {
  7909. var that = this,
  7910. options = this.options;
  7911. this.running = false;
  7912. this.element
  7913. .addClass( "ui-tabs ui-widget ui-widget-content ui-corner-all" )
  7914. .toggleClass( "ui-tabs-collapsible", options.collapsible );
  7915. this._processTabs();
  7916. options.active = this._initialActive();
  7917. // Take disabling tabs via class attribute from HTML
  7918. // into account and update option properly.
  7919. if ( $.isArray( options.disabled ) ) {
  7920. options.disabled = $.unique( options.disabled.concat(
  7921. $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
  7922. return that.tabs.index( li );
  7923. })
  7924. ) ).sort();
  7925. }
  7926. // check for length avoids error when initializing empty list
  7927. if ( this.options.active !== false && this.anchors.length ) {
  7928. this.active = this._findActive( options.active );
  7929. } else {
  7930. this.active = $();
  7931. }
  7932. this._refresh();
  7933. if ( this.active.length ) {
  7934. this.load( options.active );
  7935. }
  7936. },
  7937. _initialActive: function() {
  7938. var active = this.options.active,
  7939. collapsible = this.options.collapsible,
  7940. locationHash = location.hash.substring( 1 );
  7941. if ( active === null ) {
  7942. // check the fragment identifier in the URL
  7943. if ( locationHash ) {
  7944. this.tabs.each(function( i, tab ) {
  7945. if ( $( tab ).attr( "aria-controls" ) === locationHash ) {
  7946. active = i;
  7947. return false;
  7948. }
  7949. });
  7950. }
  7951. // check for a tab marked active via a class
  7952. if ( active === null ) {
  7953. active = this.tabs.index( this.tabs.filter( ".ui-tabs-active" ) );
  7954. }
  7955. // no active tab, set to false
  7956. if ( active === null || active === -1 ) {
  7957. active = this.tabs.length ? 0 : false;
  7958. }
  7959. }
  7960. // handle numbers: negative, out of range
  7961. if ( active !== false ) {
  7962. active = this.tabs.index( this.tabs.eq( active ) );
  7963. if ( active === -1 ) {
  7964. active = collapsible ? false : 0;
  7965. }
  7966. }
  7967. // don't allow collapsible: false and active: false
  7968. if ( !collapsible && active === false && this.anchors.length ) {
  7969. active = 0;
  7970. }
  7971. return active;
  7972. },
  7973. _getCreateEventData: function() {
  7974. return {
  7975. tab: this.active,
  7976. panel: !this.active.length ? $() : this._getPanelForTab( this.active )
  7977. };
  7978. },
  7979. _tabKeydown: function( event ) {
  7980. var focusedTab = $( this.document[0].activeElement ).closest( "li" ),
  7981. selectedIndex = this.tabs.index( focusedTab ),
  7982. goingForward = true;
  7983. if ( this._handlePageNav( event ) ) {
  7984. return;
  7985. }
  7986. switch ( event.keyCode ) {
  7987. case $.ui.keyCode.RIGHT:
  7988. case $.ui.keyCode.DOWN:
  7989. selectedIndex++;
  7990. break;
  7991. case $.ui.keyCode.UP:
  7992. case $.ui.keyCode.LEFT:
  7993. goingForward = false;
  7994. selectedIndex--;
  7995. break;
  7996. case $.ui.keyCode.END:
  7997. selectedIndex = this.anchors.length - 1;
  7998. break;
  7999. case $.ui.keyCode.HOME:
  8000. selectedIndex = 0;
  8001. break;
  8002. case $.ui.keyCode.SPACE:
  8003. // Activate only, no collapsing
  8004. event.preventDefault();
  8005. clearTimeout( this.activating );
  8006. this._activate( selectedIndex );
  8007. return;
  8008. case $.ui.keyCode.ENTER:
  8009. // Toggle (cancel delayed activation, allow collapsing)
  8010. event.preventDefault();
  8011. clearTimeout( this.activating );
  8012. // Determine if we should collapse or activate
  8013. this._activate( selectedIndex === this.options.active ? false : selectedIndex );
  8014. return;
  8015. default:
  8016. return;
  8017. }
  8018. // Focus the appropriate tab, based on which key was pressed
  8019. event.preventDefault();
  8020. clearTimeout( this.activating );
  8021. selectedIndex = this._focusNextTab( selectedIndex, goingForward );
  8022. // Navigating with control/command key will prevent automatic activation
  8023. if ( !event.ctrlKey && !event.metaKey ) {
  8024. // Update aria-selected immediately so that AT think the tab is already selected.
  8025. // Otherwise AT may confuse the user by stating that they need to activate the tab,
  8026. // but the tab will already be activated by the time the announcement finishes.
  8027. focusedTab.attr( "aria-selected", "false" );
  8028. this.tabs.eq( selectedIndex ).attr( "aria-selected", "true" );
  8029. this.activating = this._delay(function() {
  8030. this.option( "active", selectedIndex );
  8031. }, this.delay );
  8032. }
  8033. },
  8034. _panelKeydown: function( event ) {
  8035. if ( this._handlePageNav( event ) ) {
  8036. return;
  8037. }
  8038. // Ctrl+up moves focus to the current tab
  8039. if ( event.ctrlKey && event.keyCode === $.ui.keyCode.UP ) {
  8040. event.preventDefault();
  8041. this.active.focus();
  8042. }
  8043. },
  8044. // Alt+page up/down moves focus to the previous/next tab (and activates)
  8045. _handlePageNav: function( event ) {
  8046. if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_UP ) {
  8047. this._activate( this._focusNextTab( this.options.active - 1, false ) );
  8048. return true;
  8049. }
  8050. if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_DOWN ) {
  8051. this._activate( this._focusNextTab( this.options.active + 1, true ) );
  8052. return true;
  8053. }
  8054. },
  8055. _findNextTab: function( index, goingForward ) {
  8056. var lastTabIndex = this.tabs.length - 1;
  8057. function constrain() {
  8058. if ( index > lastTabIndex ) {
  8059. index = 0;
  8060. }
  8061. if ( index < 0 ) {
  8062. index = lastTabIndex;
  8063. }
  8064. return index;
  8065. }
  8066. while ( $.inArray( constrain(), this.options.disabled ) !== -1 ) {
  8067. index = goingForward ? index + 1 : index - 1;
  8068. }
  8069. return index;
  8070. },
  8071. _focusNextTab: function( index, goingForward ) {
  8072. index = this._findNextTab( index, goingForward );
  8073. this.tabs.eq( index ).focus();
  8074. return index;
  8075. },
  8076. _setOption: function( key, value ) {
  8077. if ( key === "active" ) {
  8078. // _activate() will handle invalid values and update this.options
  8079. this._activate( value );
  8080. return;
  8081. }
  8082. if ( key === "disabled" ) {
  8083. // don't use the widget factory's disabled handling
  8084. this._setupDisabled( value );
  8085. return;
  8086. }
  8087. this._super( key, value);
  8088. if ( key === "collapsible" ) {
  8089. this.element.toggleClass( "ui-tabs-collapsible", value );
  8090. // Setting collapsible: false while collapsed; open first panel
  8091. if ( !value && this.options.active === false ) {
  8092. this._activate( 0 );
  8093. }
  8094. }
  8095. if ( key === "event" ) {
  8096. this._setupEvents( value );
  8097. }
  8098. if ( key === "heightStyle" ) {
  8099. this._setupHeightStyle( value );
  8100. }
  8101. },
  8102. _sanitizeSelector: function( hash ) {
  8103. return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : "";
  8104. },
  8105. refresh: function() {
  8106. var options = this.options,
  8107. lis = this.tablist.children( ":has(a[href])" );
  8108. // get disabled tabs from class attribute from HTML
  8109. // this will get converted to a boolean if needed in _refresh()
  8110. options.disabled = $.map( lis.filter( ".ui-state-disabled" ), function( tab ) {
  8111. return lis.index( tab );
  8112. });
  8113. this._processTabs();
  8114. // was collapsed or no tabs
  8115. if ( options.active === false || !this.anchors.length ) {
  8116. options.active = false;
  8117. this.active = $();
  8118. // was active, but active tab is gone
  8119. } else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) {
  8120. // all remaining tabs are disabled
  8121. if ( this.tabs.length === options.disabled.length ) {
  8122. options.active = false;
  8123. this.active = $();
  8124. // activate previous tab
  8125. } else {
  8126. this._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) );
  8127. }
  8128. // was active, active tab still exists
  8129. } else {
  8130. // make sure active index is correct
  8131. options.active = this.tabs.index( this.active );
  8132. }
  8133. this._refresh();
  8134. },
  8135. _refresh: function() {
  8136. this._setupDisabled( this.options.disabled );
  8137. this._setupEvents( this.options.event );
  8138. this._setupHeightStyle( this.options.heightStyle );
  8139. this.tabs.not( this.active ).attr({
  8140. "aria-selected": "false",
  8141. "aria-expanded": "false",
  8142. tabIndex: -1
  8143. });
  8144. this.panels.not( this._getPanelForTab( this.active ) )
  8145. .hide()
  8146. .attr({
  8147. "aria-hidden": "true"
  8148. });
  8149. // Make sure one tab is in the tab order
  8150. if ( !this.active.length ) {
  8151. this.tabs.eq( 0 ).attr( "tabIndex", 0 );
  8152. } else {
  8153. this.active
  8154. .addClass( "ui-tabs-active ui-state-active" )
  8155. .attr({
  8156. "aria-selected": "true",
  8157. "aria-expanded": "true",
  8158. tabIndex: 0
  8159. });
  8160. this._getPanelForTab( this.active )
  8161. .show()
  8162. .attr({
  8163. "aria-hidden": "false"
  8164. });
  8165. }
  8166. },
  8167. _processTabs: function() {
  8168. var that = this,
  8169. prevTabs = this.tabs,
  8170. prevAnchors = this.anchors,
  8171. prevPanels = this.panels;
  8172. this.tablist = this._getList()
  8173. .addClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" )
  8174. .attr( "role", "tablist" )
  8175. // Prevent users from focusing disabled tabs via click
  8176. .delegate( "> li", "mousedown" + this.eventNamespace, function( event ) {
  8177. if ( $( this ).is( ".ui-state-disabled" ) ) {
  8178. event.preventDefault();
  8179. }
  8180. })
  8181. // support: IE <9
  8182. // Preventing the default action in mousedown doesn't prevent IE
  8183. // from focusing the element, so if the anchor gets focused, blur.
  8184. // We don't have to worry about focusing the previously focused
  8185. // element since clicking on a non-focusable element should focus
  8186. // the body anyway.
  8187. .delegate( ".ui-tabs-anchor", "focus" + this.eventNamespace, function() {
  8188. if ( $( this ).closest( "li" ).is( ".ui-state-disabled" ) ) {
  8189. this.blur();
  8190. }
  8191. });
  8192. this.tabs = this.tablist.find( "> li:has(a[href])" )
  8193. .addClass( "ui-state-default ui-corner-top" )
  8194. .attr({
  8195. role: "tab",
  8196. tabIndex: -1
  8197. });
  8198. this.anchors = this.tabs.map(function() {
  8199. return $( "a", this )[ 0 ];
  8200. })
  8201. .addClass( "ui-tabs-anchor" )
  8202. .attr({
  8203. role: "presentation",
  8204. tabIndex: -1
  8205. });
  8206. this.panels = $();
  8207. this.anchors.each(function( i, anchor ) {
  8208. var selector, panel, panelId,
  8209. anchorId = $( anchor ).uniqueId().attr( "id" ),
  8210. tab = $( anchor ).closest( "li" ),
  8211. originalAriaControls = tab.attr( "aria-controls" );
  8212. // inline tab
  8213. if ( that._isLocal( anchor ) ) {
  8214. selector = anchor.hash;
  8215. panelId = selector.substring( 1 );
  8216. panel = that.element.find( that._sanitizeSelector( selector ) );
  8217. // remote tab
  8218. } else {
  8219. // If the tab doesn't already have aria-controls,
  8220. // generate an id by using a throw-away element
  8221. panelId = tab.attr( "aria-controls" ) || $( {} ).uniqueId()[ 0 ].id;
  8222. selector = "#" + panelId;
  8223. panel = that.element.find( selector );
  8224. if ( !panel.length ) {
  8225. panel = that._createPanel( panelId );
  8226. panel.insertAfter( that.panels[ i - 1 ] || that.tablist );
  8227. }
  8228. panel.attr( "aria-live", "polite" );
  8229. }
  8230. if ( panel.length) {
  8231. that.panels = that.panels.add( panel );
  8232. }
  8233. if ( originalAriaControls ) {
  8234. tab.data( "ui-tabs-aria-controls", originalAriaControls );
  8235. }
  8236. tab.attr({
  8237. "aria-controls": panelId,
  8238. "aria-labelledby": anchorId
  8239. });
  8240. panel.attr( "aria-labelledby", anchorId );
  8241. });
  8242. this.panels
  8243. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  8244. .attr( "role", "tabpanel" );
  8245. // Avoid memory leaks (#10056)
  8246. if ( prevTabs ) {
  8247. this._off( prevTabs.not( this.tabs ) );
  8248. this._off( prevAnchors.not( this.anchors ) );
  8249. this._off( prevPanels.not( this.panels ) );
  8250. }
  8251. },
  8252. // allow overriding how to find the list for rare usage scenarios (#7715)
  8253. _getList: function() {
  8254. return this.tablist || this.element.find( "ol,ul" ).eq( 0 );
  8255. },
  8256. _createPanel: function( id ) {
  8257. return $( "<div>" )
  8258. .attr( "id", id )
  8259. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  8260. .data( "ui-tabs-destroy", true );
  8261. },
  8262. _setupDisabled: function( disabled ) {
  8263. if ( $.isArray( disabled ) ) {
  8264. if ( !disabled.length ) {
  8265. disabled = false;
  8266. } else if ( disabled.length === this.anchors.length ) {
  8267. disabled = true;
  8268. }
  8269. }
  8270. // disable tabs
  8271. for ( var i = 0, li; ( li = this.tabs[ i ] ); i++ ) {
  8272. if ( disabled === true || $.inArray( i, disabled ) !== -1 ) {
  8273. $( li )
  8274. .addClass( "ui-state-disabled" )
  8275. .attr( "aria-disabled", "true" );
  8276. } else {
  8277. $( li )
  8278. .removeClass( "ui-state-disabled" )
  8279. .removeAttr( "aria-disabled" );
  8280. }
  8281. }
  8282. this.options.disabled = disabled;
  8283. },
  8284. _setupEvents: function( event ) {
  8285. var events = {};
  8286. if ( event ) {
  8287. $.each( event.split(" "), function( index, eventName ) {
  8288. events[ eventName ] = "_eventHandler";
  8289. });
  8290. }
  8291. this._off( this.anchors.add( this.tabs ).add( this.panels ) );
  8292. // Always prevent the default action, even when disabled
  8293. this._on( true, this.anchors, {
  8294. click: function( event ) {
  8295. event.preventDefault();
  8296. }
  8297. });
  8298. this._on( this.anchors, events );
  8299. this._on( this.tabs, { keydown: "_tabKeydown" } );
  8300. this._on( this.panels, { keydown: "_panelKeydown" } );
  8301. this._focusable( this.tabs );
  8302. this._hoverable( this.tabs );
  8303. },
  8304. _setupHeightStyle: function( heightStyle ) {
  8305. var maxHeight,
  8306. parent = this.element.parent();
  8307. if ( heightStyle === "fill" ) {
  8308. maxHeight = parent.height();
  8309. maxHeight -= this.element.outerHeight() - this.element.height();
  8310. this.element.siblings( ":visible" ).each(function() {
  8311. var elem = $( this ),
  8312. position = elem.css( "position" );
  8313. if ( position === "absolute" || position === "fixed" ) {
  8314. return;
  8315. }
  8316. maxHeight -= elem.outerHeight( true );
  8317. });
  8318. this.element.children().not( this.panels ).each(function() {
  8319. maxHeight -= $( this ).outerHeight( true );
  8320. });
  8321. this.panels.each(function() {
  8322. $( this ).height( Math.max( 0, maxHeight -
  8323. $( this ).innerHeight() + $( this ).height() ) );
  8324. })
  8325. .css( "overflow", "auto" );
  8326. } else if ( heightStyle === "auto" ) {
  8327. maxHeight = 0;
  8328. this.panels.each(function() {
  8329. maxHeight = Math.max( maxHeight, $( this ).height( "" ).height() );
  8330. }).height( maxHeight );
  8331. }
  8332. },
  8333. _eventHandler: function( event ) {
  8334. var options = this.options,
  8335. active = this.active,
  8336. anchor = $( event.currentTarget ),
  8337. tab = anchor.closest( "li" ),
  8338. clickedIsActive = tab[ 0 ] === active[ 0 ],
  8339. collapsing = clickedIsActive && options.collapsible,
  8340. toShow = collapsing ? $() : this._getPanelForTab( tab ),
  8341. toHide = !active.length ? $() : this._getPanelForTab( active ),
  8342. eventData = {
  8343. oldTab: active,
  8344. oldPanel: toHide,
  8345. newTab: collapsing ? $() : tab,
  8346. newPanel: toShow
  8347. };
  8348. event.preventDefault();
  8349. if ( tab.hasClass( "ui-state-disabled" ) ||
  8350. // tab is already loading
  8351. tab.hasClass( "ui-tabs-loading" ) ||
  8352. // can't switch durning an animation
  8353. this.running ||
  8354. // click on active header, but not collapsible
  8355. ( clickedIsActive && !options.collapsible ) ||
  8356. // allow canceling activation
  8357. ( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
  8358. return;
  8359. }
  8360. options.active = collapsing ? false : this.tabs.index( tab );
  8361. this.active = clickedIsActive ? $() : tab;
  8362. if ( this.xhr ) {
  8363. this.xhr.abort();
  8364. }
  8365. if ( !toHide.length && !toShow.length ) {
  8366. $.error( "jQuery UI Tabs: Mismatching fragment identifier." );
  8367. }
  8368. if ( toShow.length ) {
  8369. this.load( this.tabs.index( tab ), event );
  8370. }
  8371. this._toggle( event, eventData );
  8372. },
  8373. // handles show/hide for selecting tabs
  8374. _toggle: function( event, eventData ) {
  8375. var that = this,
  8376. toShow = eventData.newPanel,
  8377. toHide = eventData.oldPanel;
  8378. this.running = true;
  8379. function complete() {
  8380. that.running = false;
  8381. that._trigger( "activate", event, eventData );
  8382. }
  8383. function show() {
  8384. eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
  8385. if ( toShow.length && that.options.show ) {
  8386. that._show( toShow, that.options.show, complete );
  8387. } else {
  8388. toShow.show();
  8389. complete();
  8390. }
  8391. }
  8392. // start out by hiding, then showing, then completing
  8393. if ( toHide.length && this.options.hide ) {
  8394. this._hide( toHide, this.options.hide, function() {
  8395. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  8396. show();
  8397. });
  8398. } else {
  8399. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  8400. toHide.hide();
  8401. show();
  8402. }
  8403. toHide.attr( "aria-hidden", "true" );
  8404. eventData.oldTab.attr({
  8405. "aria-selected": "false",
  8406. "aria-expanded": "false"
  8407. });
  8408. // If we're switching tabs, remove the old tab from the tab order.
  8409. // If we're opening from collapsed state, remove the previous tab from the tab order.
  8410. // If we're collapsing, then keep the collapsing tab in the tab order.
  8411. if ( toShow.length && toHide.length ) {
  8412. eventData.oldTab.attr( "tabIndex", -1 );
  8413. } else if ( toShow.length ) {
  8414. this.tabs.filter(function() {
  8415. return $( this ).attr( "tabIndex" ) === 0;
  8416. })
  8417. .attr( "tabIndex", -1 );
  8418. }
  8419. toShow.attr( "aria-hidden", "false" );
  8420. eventData.newTab.attr({
  8421. "aria-selected": "true",
  8422. "aria-expanded": "true",
  8423. tabIndex: 0
  8424. });
  8425. },
  8426. _activate: function( index ) {
  8427. var anchor,
  8428. active = this._findActive( index );
  8429. // trying to activate the already active panel
  8430. if ( active[ 0 ] === this.active[ 0 ] ) {
  8431. return;
  8432. }
  8433. // trying to collapse, simulate a click on the current active header
  8434. if ( !active.length ) {
  8435. active = this.active;
  8436. }
  8437. anchor = active.find( ".ui-tabs-anchor" )[ 0 ];
  8438. this._eventHandler({
  8439. target: anchor,
  8440. currentTarget: anchor,
  8441. preventDefault: $.noop
  8442. });
  8443. },
  8444. _findActive: function( index ) {
  8445. return index === false ? $() : this.tabs.eq( index );
  8446. },
  8447. _getIndex: function( index ) {
  8448. // meta-function to give users option to provide a href string instead of a numerical index.
  8449. if ( typeof index === "string" ) {
  8450. index = this.anchors.index( this.anchors.filter( "[href$='" + index + "']" ) );
  8451. }
  8452. return index;
  8453. },
  8454. _destroy: function() {
  8455. if ( this.xhr ) {
  8456. this.xhr.abort();
  8457. }
  8458. this.element.removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" );
  8459. this.tablist
  8460. .removeClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" )
  8461. .removeAttr( "role" );
  8462. this.anchors
  8463. .removeClass( "ui-tabs-anchor" )
  8464. .removeAttr( "role" )
  8465. .removeAttr( "tabIndex" )
  8466. .removeUniqueId();
  8467. this.tablist.unbind( this.eventNamespace );
  8468. this.tabs.add( this.panels ).each(function() {
  8469. if ( $.data( this, "ui-tabs-destroy" ) ) {
  8470. $( this ).remove();
  8471. } else {
  8472. $( this )
  8473. .removeClass( "ui-state-default ui-state-active ui-state-disabled " +
  8474. "ui-corner-top ui-corner-bottom ui-widget-content ui-tabs-active ui-tabs-panel" )
  8475. .removeAttr( "tabIndex" )
  8476. .removeAttr( "aria-live" )
  8477. .removeAttr( "aria-busy" )
  8478. .removeAttr( "aria-selected" )
  8479. .removeAttr( "aria-labelledby" )
  8480. .removeAttr( "aria-hidden" )
  8481. .removeAttr( "aria-expanded" )
  8482. .removeAttr( "role" );
  8483. }
  8484. });
  8485. this.tabs.each(function() {
  8486. var li = $( this ),
  8487. prev = li.data( "ui-tabs-aria-controls" );
  8488. if ( prev ) {
  8489. li
  8490. .attr( "aria-controls", prev )
  8491. .removeData( "ui-tabs-aria-controls" );
  8492. } else {
  8493. li.removeAttr( "aria-controls" );
  8494. }
  8495. });
  8496. this.panels.show();
  8497. if ( this.options.heightStyle !== "content" ) {
  8498. this.panels.css( "height", "" );
  8499. }
  8500. },
  8501. enable: function( index ) {
  8502. var disabled = this.options.disabled;
  8503. if ( disabled === false ) {
  8504. return;
  8505. }
  8506. if ( index === undefined ) {
  8507. disabled = false;
  8508. } else {
  8509. index = this._getIndex( index );
  8510. if ( $.isArray( disabled ) ) {
  8511. disabled = $.map( disabled, function( num ) {
  8512. return num !== index ? num : null;
  8513. });
  8514. } else {
  8515. disabled = $.map( this.tabs, function( li, num ) {
  8516. return num !== index ? num : null;
  8517. });
  8518. }
  8519. }
  8520. this._setupDisabled( disabled );
  8521. },
  8522. disable: function( index ) {
  8523. var disabled = this.options.disabled;
  8524. if ( disabled === true ) {
  8525. return;
  8526. }
  8527. if ( index === undefined ) {
  8528. disabled = true;
  8529. } else {
  8530. index = this._getIndex( index );
  8531. if ( $.inArray( index, disabled ) !== -1 ) {
  8532. return;
  8533. }
  8534. if ( $.isArray( disabled ) ) {
  8535. disabled = $.merge( [ index ], disabled ).sort();
  8536. } else {
  8537. disabled = [ index ];
  8538. }
  8539. }
  8540. this._setupDisabled( disabled );
  8541. },
  8542. load: function( index, event ) {
  8543. index = this._getIndex( index );
  8544. var that = this,
  8545. tab = this.tabs.eq( index ),
  8546. anchor = tab.find( ".ui-tabs-anchor" ),
  8547. panel = this._getPanelForTab( tab ),
  8548. eventData = {
  8549. tab: tab,
  8550. panel: panel
  8551. },
  8552. complete = function( jqXHR, status ) {
  8553. if ( status === "abort" ) {
  8554. that.panels.stop( false, true );
  8555. }
  8556. tab.removeClass( "ui-tabs-loading" );
  8557. panel.removeAttr( "aria-busy" );
  8558. if ( jqXHR === that.xhr ) {
  8559. delete that.xhr;
  8560. }
  8561. };
  8562. // not remote
  8563. if ( this._isLocal( anchor[ 0 ] ) ) {
  8564. return;
  8565. }
  8566. this.xhr = $.ajax( this._ajaxSettings( anchor, event, eventData ) );
  8567. // support: jQuery <1.8
  8568. // jQuery <1.8 returns false if the request is canceled in beforeSend,
  8569. // but as of 1.8, $.ajax() always returns a jqXHR object.
  8570. if ( this.xhr && this.xhr.statusText !== "canceled" ) {
  8571. tab.addClass( "ui-tabs-loading" );
  8572. panel.attr( "aria-busy", "true" );
  8573. this.xhr
  8574. .done(function( response, status, jqXHR ) {
  8575. // support: jQuery <1.8
  8576. // http://bugs.jquery.com/ticket/11778
  8577. setTimeout(function() {
  8578. panel.html( response );
  8579. that._trigger( "load", event, eventData );
  8580. complete( jqXHR, status );
  8581. }, 1 );
  8582. })
  8583. .fail(function( jqXHR, status ) {
  8584. // support: jQuery <1.8
  8585. // http://bugs.jquery.com/ticket/11778
  8586. setTimeout(function() {
  8587. complete( jqXHR, status );
  8588. }, 1 );
  8589. });
  8590. }
  8591. },
  8592. _ajaxSettings: function( anchor, event, eventData ) {
  8593. var that = this;
  8594. return {
  8595. url: anchor.attr( "href" ),
  8596. beforeSend: function( jqXHR, settings ) {
  8597. return that._trigger( "beforeLoad", event,
  8598. $.extend( { jqXHR: jqXHR, ajaxSettings: settings }, eventData ) );
  8599. }
  8600. };
  8601. },
  8602. _getPanelForTab: function( tab ) {
  8603. var id = $( tab ).attr( "aria-controls" );
  8604. return this.element.find( this._sanitizeSelector( "#" + id ) );
  8605. }
  8606. });
  8607. /*!
  8608. * jQuery UI Tooltip 1.11.4
  8609. * http://jqueryui.com
  8610. *
  8611. * Copyright jQuery Foundation and other contributors
  8612. * Released under the MIT license.
  8613. * http://jquery.org/license
  8614. *
  8615. * http://api.jqueryui.com/tooltip/
  8616. */
  8617. var tooltip = $.widget( "ui.tooltip", {
  8618. version: "1.11.4",
  8619. options: {
  8620. content: function() {
  8621. // support: IE<9, Opera in jQuery <1.7
  8622. // .text() can't accept undefined, so coerce to a string
  8623. var title = $( this ).attr( "title" ) || "";
  8624. // Escape title, since we're going from an attribute to raw HTML
  8625. return $( "<a>" ).text( title ).html();
  8626. },
  8627. hide: true,
  8628. // Disabled elements have inconsistent behavior across browsers (#8661)
  8629. items: "[title]:not([disabled])",
  8630. position: {
  8631. my: "left top+15",
  8632. at: "left bottom",
  8633. collision: "flipfit flip"
  8634. },
  8635. show: true,
  8636. tooltipClass: null,
  8637. track: false,
  8638. // callbacks
  8639. close: null,
  8640. open: null
  8641. },
  8642. _addDescribedBy: function( elem, id ) {
  8643. var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ );
  8644. describedby.push( id );
  8645. elem
  8646. .data( "ui-tooltip-id", id )
  8647. .attr( "aria-describedby", $.trim( describedby.join( " " ) ) );
  8648. },
  8649. _removeDescribedBy: function( elem ) {
  8650. var id = elem.data( "ui-tooltip-id" ),
  8651. describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ),
  8652. index = $.inArray( id, describedby );
  8653. if ( index !== -1 ) {
  8654. describedby.splice( index, 1 );
  8655. }
  8656. elem.removeData( "ui-tooltip-id" );
  8657. describedby = $.trim( describedby.join( " " ) );
  8658. if ( describedby ) {
  8659. elem.attr( "aria-describedby", describedby );
  8660. } else {
  8661. elem.removeAttr( "aria-describedby" );
  8662. }
  8663. },
  8664. _create: function() {
  8665. this._on({
  8666. mouseover: "open",
  8667. focusin: "open"
  8668. });
  8669. // IDs of generated tooltips, needed for destroy
  8670. this.tooltips = {};
  8671. // IDs of parent tooltips where we removed the title attribute
  8672. this.parents = {};
  8673. if ( this.options.disabled ) {
  8674. this._disable();
  8675. }
  8676. // Append the aria-live region so tooltips announce correctly
  8677. this.liveRegion = $( "<div>" )
  8678. .attr({
  8679. role: "log",
  8680. "aria-live": "assertive",
  8681. "aria-relevant": "additions"
  8682. })
  8683. .addClass( "ui-helper-hidden-accessible" )
  8684. .appendTo( this.document[ 0 ].body );
  8685. },
  8686. _setOption: function( key, value ) {
  8687. var that = this;
  8688. if ( key === "disabled" ) {
  8689. this[ value ? "_disable" : "_enable" ]();
  8690. this.options[ key ] = value;
  8691. // disable element style changes
  8692. return;
  8693. }
  8694. this._super( key, value );
  8695. if ( key === "content" ) {
  8696. $.each( this.tooltips, function( id, tooltipData ) {
  8697. that._updateContent( tooltipData.element );
  8698. });
  8699. }
  8700. },
  8701. _disable: function() {
  8702. var that = this;
  8703. // close open tooltips
  8704. $.each( this.tooltips, function( id, tooltipData ) {
  8705. var event = $.Event( "blur" );
  8706. event.target = event.currentTarget = tooltipData.element[ 0 ];
  8707. that.close( event, true );
  8708. });
  8709. // remove title attributes to prevent native tooltips
  8710. this.element.find( this.options.items ).addBack().each(function() {
  8711. var element = $( this );
  8712. if ( element.is( "[title]" ) ) {
  8713. element
  8714. .data( "ui-tooltip-title", element.attr( "title" ) )
  8715. .removeAttr( "title" );
  8716. }
  8717. });
  8718. },
  8719. _enable: function() {
  8720. // restore title attributes
  8721. this.element.find( this.options.items ).addBack().each(function() {
  8722. var element = $( this );
  8723. if ( element.data( "ui-tooltip-title" ) ) {
  8724. element.attr( "title", element.data( "ui-tooltip-title" ) );
  8725. }
  8726. });
  8727. },
  8728. open: function( event ) {
  8729. var that = this,
  8730. target = $( event ? event.target : this.element )
  8731. // we need closest here due to mouseover bubbling,
  8732. // but always pointing at the same event target
  8733. .closest( this.options.items );
  8734. // No element to show a tooltip for or the tooltip is already open
  8735. if ( !target.length || target.data( "ui-tooltip-id" ) ) {
  8736. return;
  8737. }
  8738. if ( target.attr( "title" ) ) {
  8739. target.data( "ui-tooltip-title", target.attr( "title" ) );
  8740. }
  8741. target.data( "ui-tooltip-open", true );
  8742. // kill parent tooltips, custom or native, for hover
  8743. if ( event && event.type === "mouseover" ) {
  8744. target.parents().each(function() {
  8745. var parent = $( this ),
  8746. blurEvent;
  8747. if ( parent.data( "ui-tooltip-open" ) ) {
  8748. blurEvent = $.Event( "blur" );
  8749. blurEvent.target = blurEvent.currentTarget = this;
  8750. that.close( blurEvent, true );
  8751. }
  8752. if ( parent.attr( "title" ) ) {
  8753. parent.uniqueId();
  8754. that.parents[ this.id ] = {
  8755. element: this,
  8756. title: parent.attr( "title" )
  8757. };
  8758. parent.attr( "title", "" );
  8759. }
  8760. });
  8761. }
  8762. this._registerCloseHandlers( event, target );
  8763. this._updateContent( target, event );
  8764. },
  8765. _updateContent: function( target, event ) {
  8766. var content,
  8767. contentOption = this.options.content,
  8768. that = this,
  8769. eventType = event ? event.type : null;
  8770. if ( typeof contentOption === "string" ) {
  8771. return this._open( event, target, contentOption );
  8772. }
  8773. content = contentOption.call( target[0], function( response ) {
  8774. // IE may instantly serve a cached response for ajax requests
  8775. // delay this call to _open so the other call to _open runs first
  8776. that._delay(function() {
  8777. // Ignore async response if tooltip was closed already
  8778. if ( !target.data( "ui-tooltip-open" ) ) {
  8779. return;
  8780. }
  8781. // jQuery creates a special event for focusin when it doesn't
  8782. // exist natively. To improve performance, the native event
  8783. // object is reused and the type is changed. Therefore, we can't
  8784. // rely on the type being correct after the event finished
  8785. // bubbling, so we set it back to the previous value. (#8740)
  8786. if ( event ) {
  8787. event.type = eventType;
  8788. }
  8789. this._open( event, target, response );
  8790. });
  8791. });
  8792. if ( content ) {
  8793. this._open( event, target, content );
  8794. }
  8795. },
  8796. _open: function( event, target, content ) {
  8797. var tooltipData, tooltip, delayedShow, a11yContent,
  8798. positionOption = $.extend( {}, this.options.position );
  8799. if ( !content ) {
  8800. return;
  8801. }
  8802. // Content can be updated multiple times. If the tooltip already
  8803. // exists, then just update the content and bail.
  8804. tooltipData = this._find( target );
  8805. if ( tooltipData ) {
  8806. tooltipData.tooltip.find( ".ui-tooltip-content" ).html( content );
  8807. return;
  8808. }
  8809. // if we have a title, clear it to prevent the native tooltip
  8810. // we have to check first to avoid defining a title if none exists
  8811. // (we don't want to cause an element to start matching [title])
  8812. //
  8813. // We use removeAttr only for key events, to allow IE to export the correct
  8814. // accessible attributes. For mouse events, set to empty string to avoid
  8815. // native tooltip showing up (happens only when removing inside mouseover).
  8816. if ( target.is( "[title]" ) ) {
  8817. if ( event && event.type === "mouseover" ) {
  8818. target.attr( "title", "" );
  8819. } else {
  8820. target.removeAttr( "title" );
  8821. }
  8822. }
  8823. tooltipData = this._tooltip( target );
  8824. tooltip = tooltipData.tooltip;
  8825. this._addDescribedBy( target, tooltip.attr( "id" ) );
  8826. tooltip.find( ".ui-tooltip-content" ).html( content );
  8827. // Support: Voiceover on OS X, JAWS on IE <= 9
  8828. // JAWS announces deletions even when aria-relevant="additions"
  8829. // Voiceover will sometimes re-read the entire log region's contents from the beginning
  8830. this.liveRegion.children().hide();
  8831. if ( content.clone ) {
  8832. a11yContent = content.clone();
  8833. a11yContent.removeAttr( "id" ).find( "[id]" ).removeAttr( "id" );
  8834. } else {
  8835. a11yContent = content;
  8836. }
  8837. $( "<div>" ).html( a11yContent ).appendTo( this.liveRegion );
  8838. function position( event ) {
  8839. positionOption.of = event;
  8840. if ( tooltip.is( ":hidden" ) ) {
  8841. return;
  8842. }
  8843. tooltip.position( positionOption );
  8844. }
  8845. if ( this.options.track && event && /^mouse/.test( event.type ) ) {
  8846. this._on( this.document, {
  8847. mousemove: position
  8848. });
  8849. // trigger once to override element-relative positioning
  8850. position( event );
  8851. } else {
  8852. tooltip.position( $.extend({
  8853. of: target
  8854. }, this.options.position ) );
  8855. }
  8856. tooltip.hide();
  8857. this._show( tooltip, this.options.show );
  8858. // Handle tracking tooltips that are shown with a delay (#8644). As soon
  8859. // as the tooltip is visible, position the tooltip using the most recent
  8860. // event.
  8861. if ( this.options.show && this.options.show.delay ) {
  8862. delayedShow = this.delayedShow = setInterval(function() {
  8863. if ( tooltip.is( ":visible" ) ) {
  8864. position( positionOption.of );
  8865. clearInterval( delayedShow );
  8866. }
  8867. }, $.fx.interval );
  8868. }
  8869. this._trigger( "open", event, { tooltip: tooltip } );
  8870. },
  8871. _registerCloseHandlers: function( event, target ) {
  8872. var events = {
  8873. keyup: function( event ) {
  8874. if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
  8875. var fakeEvent = $.Event(event);
  8876. fakeEvent.currentTarget = target[0];
  8877. this.close( fakeEvent, true );
  8878. }
  8879. }
  8880. };
  8881. // Only bind remove handler for delegated targets. Non-delegated
  8882. // tooltips will handle this in destroy.
  8883. if ( target[ 0 ] !== this.element[ 0 ] ) {
  8884. events.remove = function() {
  8885. this._removeTooltip( this._find( target ).tooltip );
  8886. };
  8887. }
  8888. if ( !event || event.type === "mouseover" ) {
  8889. events.mouseleave = "close";
  8890. }
  8891. if ( !event || event.type === "focusin" ) {
  8892. events.focusout = "close";
  8893. }
  8894. this._on( true, target, events );
  8895. },
  8896. close: function( event ) {
  8897. var tooltip,
  8898. that = this,
  8899. target = $( event ? event.currentTarget : this.element ),
  8900. tooltipData = this._find( target );
  8901. // The tooltip may already be closed
  8902. if ( !tooltipData ) {
  8903. // We set ui-tooltip-open immediately upon open (in open()), but only set the
  8904. // additional data once there's actually content to show (in _open()). So even if the
  8905. // tooltip doesn't have full data, we always remove ui-tooltip-open in case we're in
  8906. // the period between open() and _open().
  8907. target.removeData( "ui-tooltip-open" );
  8908. return;
  8909. }
  8910. tooltip = tooltipData.tooltip;
  8911. // disabling closes the tooltip, so we need to track when we're closing
  8912. // to avoid an infinite loop in case the tooltip becomes disabled on close
  8913. if ( tooltipData.closing ) {
  8914. return;
  8915. }
  8916. // Clear the interval for delayed tracking tooltips
  8917. clearInterval( this.delayedShow );
  8918. // only set title if we had one before (see comment in _open())
  8919. // If the title attribute has changed since open(), don't restore
  8920. if ( target.data( "ui-tooltip-title" ) && !target.attr( "title" ) ) {
  8921. target.attr( "title", target.data( "ui-tooltip-title" ) );
  8922. }
  8923. this._removeDescribedBy( target );
  8924. tooltipData.hiding = true;
  8925. tooltip.stop( true );
  8926. this._hide( tooltip, this.options.hide, function() {
  8927. that._removeTooltip( $( this ) );
  8928. });
  8929. target.removeData( "ui-tooltip-open" );
  8930. this._off( target, "mouseleave focusout keyup" );
  8931. // Remove 'remove' binding only on delegated targets
  8932. if ( target[ 0 ] !== this.element[ 0 ] ) {
  8933. this._off( target, "remove" );
  8934. }
  8935. this._off( this.document, "mousemove" );
  8936. if ( event && event.type === "mouseleave" ) {
  8937. $.each( this.parents, function( id, parent ) {
  8938. $( parent.element ).attr( "title", parent.title );
  8939. delete that.parents[ id ];
  8940. });
  8941. }
  8942. tooltipData.closing = true;
  8943. this._trigger( "close", event, { tooltip: tooltip } );
  8944. if ( !tooltipData.hiding ) {
  8945. tooltipData.closing = false;
  8946. }
  8947. },
  8948. _tooltip: function( element ) {
  8949. var tooltip = $( "<div>" )
  8950. .attr( "role", "tooltip" )
  8951. .addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content " +
  8952. ( this.options.tooltipClass || "" ) ),
  8953. id = tooltip.uniqueId().attr( "id" );
  8954. $( "<div>" )
  8955. .addClass( "ui-tooltip-content" )
  8956. .appendTo( tooltip );
  8957. tooltip.appendTo( this.document[0].body );
  8958. return this.tooltips[ id ] = {
  8959. element: element,
  8960. tooltip: tooltip
  8961. };
  8962. },
  8963. _find: function( target ) {
  8964. var id = target.data( "ui-tooltip-id" );
  8965. return id ? this.tooltips[ id ] : null;
  8966. },
  8967. _removeTooltip: function( tooltip ) {
  8968. tooltip.remove();
  8969. delete this.tooltips[ tooltip.attr( "id" ) ];
  8970. },
  8971. _destroy: function() {
  8972. var that = this;
  8973. // close open tooltips
  8974. $.each( this.tooltips, function( id, tooltipData ) {
  8975. // Delegate to close method to handle common cleanup
  8976. var event = $.Event( "blur" ),
  8977. element = tooltipData.element;
  8978. event.target = event.currentTarget = element[ 0 ];
  8979. that.close( event, true );
  8980. // Remove immediately; destroying an open tooltip doesn't use the
  8981. // hide animation
  8982. $( "#" + id ).remove();
  8983. // Restore the title
  8984. if ( element.data( "ui-tooltip-title" ) ) {
  8985. // If the title attribute has changed since open(), don't restore
  8986. if ( !element.attr( "title" ) ) {
  8987. element.attr( "title", element.data( "ui-tooltip-title" ) );
  8988. }
  8989. element.removeData( "ui-tooltip-title" );
  8990. }
  8991. });
  8992. this.liveRegion.remove();
  8993. }
  8994. });
  8995. }));