PageRenderTime 171ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 2ms

/Scripts/jquery-ui-1.9.2.js

https://bitbucket.org/parivedasolutions/attributeroutingtest
JavaScript | 14912 lines | 12590 code | 1470 blank | 852 comment | 2060 complexity | 42417a1984f6f113247bb13a09a26542 MD5 | raw file
  1. /*! jQuery UI - v1.9.2 - 2012-11-23
  2. * http://jqueryui.com
  3. * Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.draggable.js, jquery.ui.droppable.js, jquery.ui.resizable.js, jquery.ui.selectable.js, jquery.ui.sortable.js, jquery.ui.effect.js, jquery.ui.accordion.js, jquery.ui.autocomplete.js, jquery.ui.button.js, jquery.ui.datepicker.js, jquery.ui.dialog.js, jquery.ui.effect-blind.js, jquery.ui.effect-bounce.js, jquery.ui.effect-clip.js, jquery.ui.effect-drop.js, jquery.ui.effect-explode.js, jquery.ui.effect-fade.js, jquery.ui.effect-fold.js, jquery.ui.effect-highlight.js, jquery.ui.effect-pulsate.js, jquery.ui.effect-scale.js, jquery.ui.effect-shake.js, jquery.ui.effect-slide.js, jquery.ui.effect-transfer.js, jquery.ui.menu.js, jquery.ui.position.js, jquery.ui.progressbar.js, jquery.ui.slider.js, jquery.ui.spinner.js, jquery.ui.tabs.js, jquery.ui.tooltip.js
  4. * Copyright 2012 jQuery Foundation and other contributors; Licensed MIT */
  5. (function( $, undefined ) {
  6. var uuid = 0,
  7. runiqueId = /^ui-id-\d+$/;
  8. // prevent duplicate loading
  9. // this is only a problem because we proxy existing functions
  10. // and we don't want to double proxy them
  11. $.ui = $.ui || {};
  12. if ( $.ui.version ) {
  13. return;
  14. }
  15. $.extend( $.ui, {
  16. version: "1.9.2",
  17. keyCode: {
  18. BACKSPACE: 8,
  19. COMMA: 188,
  20. DELETE: 46,
  21. DOWN: 40,
  22. END: 35,
  23. ENTER: 13,
  24. ESCAPE: 27,
  25. HOME: 36,
  26. LEFT: 37,
  27. NUMPAD_ADD: 107,
  28. NUMPAD_DECIMAL: 110,
  29. NUMPAD_DIVIDE: 111,
  30. NUMPAD_ENTER: 108,
  31. NUMPAD_MULTIPLY: 106,
  32. NUMPAD_SUBTRACT: 109,
  33. PAGE_DOWN: 34,
  34. PAGE_UP: 33,
  35. PERIOD: 190,
  36. RIGHT: 39,
  37. SPACE: 32,
  38. TAB: 9,
  39. UP: 38
  40. }
  41. });
  42. // plugins
  43. $.fn.extend({
  44. _focus: $.fn.focus,
  45. focus: function( delay, fn ) {
  46. return typeof delay === "number" ?
  47. this.each(function() {
  48. var elem = this;
  49. setTimeout(function() {
  50. $( elem ).focus();
  51. if ( fn ) {
  52. fn.call( elem );
  53. }
  54. }, delay );
  55. }) :
  56. this._focus.apply( this, arguments );
  57. },
  58. scrollParent: function() {
  59. var scrollParent;
  60. if (($.ui.ie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
  61. scrollParent = this.parents().filter(function() {
  62. return (/(relative|absolute|fixed)/).test($.css(this,'position')) && (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x'));
  63. }).eq(0);
  64. } else {
  65. scrollParent = this.parents().filter(function() {
  66. return (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x'));
  67. }).eq(0);
  68. }
  69. return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
  70. },
  71. zIndex: function( zIndex ) {
  72. if ( zIndex !== undefined ) {
  73. return this.css( "zIndex", zIndex );
  74. }
  75. if ( this.length ) {
  76. var elem = $( this[ 0 ] ), position, value;
  77. while ( elem.length && elem[ 0 ] !== document ) {
  78. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  79. // This makes behavior of this function consistent across browsers
  80. // WebKit always returns auto if the element is positioned
  81. position = elem.css( "position" );
  82. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  83. // IE returns 0 when zIndex is not specified
  84. // other browsers return a string
  85. // we ignore the case of nested elements with an explicit value of 0
  86. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  87. value = parseInt( elem.css( "zIndex" ), 10 );
  88. if ( !isNaN( value ) && value !== 0 ) {
  89. return value;
  90. }
  91. }
  92. elem = elem.parent();
  93. }
  94. }
  95. return 0;
  96. },
  97. uniqueId: function() {
  98. return this.each(function() {
  99. if ( !this.id ) {
  100. this.id = "ui-id-" + (++uuid);
  101. }
  102. });
  103. },
  104. removeUniqueId: function() {
  105. return this.each(function() {
  106. if ( runiqueId.test( this.id ) ) {
  107. $( this ).removeAttr( "id" );
  108. }
  109. });
  110. }
  111. });
  112. // selectors
  113. function focusable( element, isTabIndexNotNaN ) {
  114. var map, mapName, img,
  115. nodeName = element.nodeName.toLowerCase();
  116. if ( "area" === nodeName ) {
  117. map = element.parentNode;
  118. mapName = map.name;
  119. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  120. return false;
  121. }
  122. img = $( "img[usemap=#" + mapName + "]" )[0];
  123. return !!img && visible( img );
  124. }
  125. return ( /input|select|textarea|button|object/.test( nodeName ) ?
  126. !element.disabled :
  127. "a" === nodeName ?
  128. element.href || isTabIndexNotNaN :
  129. isTabIndexNotNaN) &&
  130. // the element and all of its ancestors must be visible
  131. visible( element );
  132. }
  133. function visible( element ) {
  134. return $.expr.filters.visible( element ) &&
  135. !$( element ).parents().andSelf().filter(function() {
  136. return $.css( this, "visibility" ) === "hidden";
  137. }).length;
  138. }
  139. $.extend( $.expr[ ":" ], {
  140. data: $.expr.createPseudo ?
  141. $.expr.createPseudo(function( dataName ) {
  142. return function( elem ) {
  143. return !!$.data( elem, dataName );
  144. };
  145. }) :
  146. // support: jQuery <1.8
  147. function( elem, i, match ) {
  148. return !!$.data( elem, match[ 3 ] );
  149. },
  150. focusable: function( element ) {
  151. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  152. },
  153. tabbable: function( element ) {
  154. var tabIndex = $.attr( element, "tabindex" ),
  155. isTabIndexNaN = isNaN( tabIndex );
  156. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  157. }
  158. });
  159. // support
  160. $(function() {
  161. var body = document.body,
  162. div = body.appendChild( div = document.createElement( "div" ) );
  163. // access offsetHeight before setting the style to prevent a layout bug
  164. // in IE 9 which causes the element to continue to take up space even
  165. // after it is removed from the DOM (#8026)
  166. div.offsetHeight;
  167. $.extend( div.style, {
  168. minHeight: "100px",
  169. height: "auto",
  170. padding: 0,
  171. borderWidth: 0
  172. });
  173. $.support.minHeight = div.offsetHeight === 100;
  174. $.support.selectstart = "onselectstart" in div;
  175. // set display to none to avoid a layout bug in IE
  176. // http://dev.jquery.com/ticket/4014
  177. body.removeChild( div ).style.display = "none";
  178. });
  179. // support: jQuery <1.8
  180. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  181. $.each( [ "Width", "Height" ], function( i, name ) {
  182. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  183. type = name.toLowerCase(),
  184. orig = {
  185. innerWidth: $.fn.innerWidth,
  186. innerHeight: $.fn.innerHeight,
  187. outerWidth: $.fn.outerWidth,
  188. outerHeight: $.fn.outerHeight
  189. };
  190. function reduce( elem, size, border, margin ) {
  191. $.each( side, function() {
  192. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  193. if ( border ) {
  194. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  195. }
  196. if ( margin ) {
  197. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  198. }
  199. });
  200. return size;
  201. }
  202. $.fn[ "inner" + name ] = function( size ) {
  203. if ( size === undefined ) {
  204. return orig[ "inner" + name ].call( this );
  205. }
  206. return this.each(function() {
  207. $( this ).css( type, reduce( this, size ) + "px" );
  208. });
  209. };
  210. $.fn[ "outer" + name] = function( size, margin ) {
  211. if ( typeof size !== "number" ) {
  212. return orig[ "outer" + name ].call( this, size );
  213. }
  214. return this.each(function() {
  215. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  216. });
  217. };
  218. });
  219. }
  220. // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
  221. if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
  222. $.fn.removeData = (function( removeData ) {
  223. return function( key ) {
  224. if ( arguments.length ) {
  225. return removeData.call( this, $.camelCase( key ) );
  226. } else {
  227. return removeData.call( this );
  228. }
  229. };
  230. })( $.fn.removeData );
  231. }
  232. // deprecated
  233. (function() {
  234. var uaMatch = /msie ([\w.]+)/.exec( navigator.userAgent.toLowerCase() ) || [];
  235. $.ui.ie = uaMatch.length ? true : false;
  236. $.ui.ie6 = parseFloat( uaMatch[ 1 ], 10 ) === 6;
  237. })();
  238. $.fn.extend({
  239. disableSelection: function() {
  240. return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
  241. ".ui-disableSelection", function( event ) {
  242. event.preventDefault();
  243. });
  244. },
  245. enableSelection: function() {
  246. return this.unbind( ".ui-disableSelection" );
  247. }
  248. });
  249. $.extend( $.ui, {
  250. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  251. plugin: {
  252. add: function( module, option, set ) {
  253. var i,
  254. proto = $.ui[ module ].prototype;
  255. for ( i in set ) {
  256. proto.plugins[ i ] = proto.plugins[ i ] || [];
  257. proto.plugins[ i ].push( [ option, set[ i ] ] );
  258. }
  259. },
  260. call: function( instance, name, args ) {
  261. var i,
  262. set = instance.plugins[ name ];
  263. if ( !set || !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) {
  264. return;
  265. }
  266. for ( i = 0; i < set.length; i++ ) {
  267. if ( instance.options[ set[ i ][ 0 ] ] ) {
  268. set[ i ][ 1 ].apply( instance.element, args );
  269. }
  270. }
  271. }
  272. },
  273. contains: $.contains,
  274. // only used by resizable
  275. hasScroll: function( el, a ) {
  276. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  277. if ( $( el ).css( "overflow" ) === "hidden") {
  278. return false;
  279. }
  280. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  281. has = false;
  282. if ( el[ scroll ] > 0 ) {
  283. return true;
  284. }
  285. // TODO: determine which cases actually cause this to happen
  286. // if the element doesn't have the scroll set, see if it's possible to
  287. // set the scroll
  288. el[ scroll ] = 1;
  289. has = ( el[ scroll ] > 0 );
  290. el[ scroll ] = 0;
  291. return has;
  292. },
  293. // these are odd functions, fix the API or move into individual plugins
  294. isOverAxis: function( x, reference, size ) {
  295. //Determines when x coordinate is over "b" element axis
  296. return ( x > reference ) && ( x < ( reference + size ) );
  297. },
  298. isOver: function( y, x, top, left, height, width ) {
  299. //Determines when x, y coordinates is over "b" element
  300. return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );
  301. }
  302. });
  303. })( jQuery );
  304. (function( $, undefined ) {
  305. var uuid = 0,
  306. slice = Array.prototype.slice,
  307. _cleanData = $.cleanData;
  308. $.cleanData = function( elems ) {
  309. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  310. try {
  311. $( elem ).triggerHandler( "remove" );
  312. // http://bugs.jquery.com/ticket/8235
  313. } catch( e ) {}
  314. }
  315. _cleanData( elems );
  316. };
  317. $.widget = function( name, base, prototype ) {
  318. var fullName, existingConstructor, constructor, basePrototype,
  319. namespace = name.split( "." )[ 0 ];
  320. name = name.split( "." )[ 1 ];
  321. fullName = namespace + "-" + name;
  322. if ( !prototype ) {
  323. prototype = base;
  324. base = $.Widget;
  325. }
  326. // create selector for plugin
  327. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  328. return !!$.data( elem, fullName );
  329. };
  330. $[ namespace ] = $[ namespace ] || {};
  331. existingConstructor = $[ namespace ][ name ];
  332. constructor = $[ namespace ][ name ] = function( options, element ) {
  333. // allow instantiation without "new" keyword
  334. if ( !this._createWidget ) {
  335. return new constructor( options, element );
  336. }
  337. // allow instantiation without initializing for simple inheritance
  338. // must use "new" keyword (the code above always passes args)
  339. if ( arguments.length ) {
  340. this._createWidget( options, element );
  341. }
  342. };
  343. // extend with the existing constructor to carry over any static properties
  344. $.extend( constructor, existingConstructor, {
  345. version: prototype.version,
  346. // copy the object used to create the prototype in case we need to
  347. // redefine the widget later
  348. _proto: $.extend( {}, prototype ),
  349. // track widgets that inherit from this widget in case this widget is
  350. // redefined after a widget inherits from it
  351. _childConstructors: []
  352. });
  353. basePrototype = new base();
  354. // we need to make the options hash a property directly on the new instance
  355. // otherwise we'll modify the options hash on the prototype that we're
  356. // inheriting from
  357. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  358. $.each( prototype, function( prop, value ) {
  359. if ( $.isFunction( value ) ) {
  360. prototype[ prop ] = (function() {
  361. var _super = function() {
  362. return base.prototype[ prop ].apply( this, arguments );
  363. },
  364. _superApply = function( args ) {
  365. return base.prototype[ prop ].apply( this, args );
  366. };
  367. return function() {
  368. var __super = this._super,
  369. __superApply = this._superApply,
  370. returnValue;
  371. this._super = _super;
  372. this._superApply = _superApply;
  373. returnValue = value.apply( this, arguments );
  374. this._super = __super;
  375. this._superApply = __superApply;
  376. return returnValue;
  377. };
  378. })();
  379. }
  380. });
  381. constructor.prototype = $.widget.extend( basePrototype, {
  382. // TODO: remove support for widgetEventPrefix
  383. // always use the name + a colon as the prefix, e.g., draggable:start
  384. // don't prefix for widgets that aren't DOM-based
  385. widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name
  386. }, prototype, {
  387. constructor: constructor,
  388. namespace: namespace,
  389. widgetName: name,
  390. // TODO remove widgetBaseClass, see #8155
  391. widgetBaseClass: fullName,
  392. widgetFullName: fullName
  393. });
  394. // If this widget is being redefined then we need to find all widgets that
  395. // are inheriting from it and redefine all of them so that they inherit from
  396. // the new version of this widget. We're essentially trying to replace one
  397. // level in the prototype chain.
  398. if ( existingConstructor ) {
  399. $.each( existingConstructor._childConstructors, function( i, child ) {
  400. var childPrototype = child.prototype;
  401. // redefine the child widget using the same prototype that was
  402. // originally used, but inherit from the new version of the base
  403. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
  404. });
  405. // remove the list of existing child constructors from the old constructor
  406. // so the old child constructors can be garbage collected
  407. delete existingConstructor._childConstructors;
  408. } else {
  409. base._childConstructors.push( constructor );
  410. }
  411. $.widget.bridge( name, constructor );
  412. };
  413. $.widget.extend = function( target ) {
  414. var input = slice.call( arguments, 1 ),
  415. inputIndex = 0,
  416. inputLength = input.length,
  417. key,
  418. value;
  419. for ( ; inputIndex < inputLength; inputIndex++ ) {
  420. for ( key in input[ inputIndex ] ) {
  421. value = input[ inputIndex ][ key ];
  422. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  423. // Clone objects
  424. if ( $.isPlainObject( value ) ) {
  425. target[ key ] = $.isPlainObject( target[ key ] ) ?
  426. $.widget.extend( {}, target[ key ], value ) :
  427. // Don't extend strings, arrays, etc. with objects
  428. $.widget.extend( {}, value );
  429. // Copy everything else by reference
  430. } else {
  431. target[ key ] = value;
  432. }
  433. }
  434. }
  435. }
  436. return target;
  437. };
  438. $.widget.bridge = function( name, object ) {
  439. var fullName = object.prototype.widgetFullName || name;
  440. $.fn[ name ] = function( options ) {
  441. var isMethodCall = typeof options === "string",
  442. args = slice.call( arguments, 1 ),
  443. returnValue = this;
  444. // allow multiple hashes to be passed on init
  445. options = !isMethodCall && args.length ?
  446. $.widget.extend.apply( null, [ options ].concat(args) ) :
  447. options;
  448. if ( isMethodCall ) {
  449. this.each(function() {
  450. var methodValue,
  451. instance = $.data( this, fullName );
  452. if ( !instance ) {
  453. return $.error( "cannot call methods on " + name + " prior to initialization; " +
  454. "attempted to call method '" + options + "'" );
  455. }
  456. if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
  457. return $.error( "no such method '" + options + "' for " + name + " widget instance" );
  458. }
  459. methodValue = instance[ options ].apply( instance, args );
  460. if ( methodValue !== instance && methodValue !== undefined ) {
  461. returnValue = methodValue && methodValue.jquery ?
  462. returnValue.pushStack( methodValue.get() ) :
  463. methodValue;
  464. return false;
  465. }
  466. });
  467. } else {
  468. this.each(function() {
  469. var instance = $.data( this, fullName );
  470. if ( instance ) {
  471. instance.option( options || {} )._init();
  472. } else {
  473. $.data( this, fullName, new object( options, this ) );
  474. }
  475. });
  476. }
  477. return returnValue;
  478. };
  479. };
  480. $.Widget = function( /* options, element */ ) {};
  481. $.Widget._childConstructors = [];
  482. $.Widget.prototype = {
  483. widgetName: "widget",
  484. widgetEventPrefix: "",
  485. defaultElement: "<div>",
  486. options: {
  487. disabled: false,
  488. // callbacks
  489. create: null
  490. },
  491. _createWidget: function( options, element ) {
  492. element = $( element || this.defaultElement || this )[ 0 ];
  493. this.element = $( element );
  494. this.uuid = uuid++;
  495. this.eventNamespace = "." + this.widgetName + this.uuid;
  496. this.options = $.widget.extend( {},
  497. this.options,
  498. this._getCreateOptions(),
  499. options );
  500. this.bindings = $();
  501. this.hoverable = $();
  502. this.focusable = $();
  503. if ( element !== this ) {
  504. // 1.9 BC for #7810
  505. // TODO remove dual storage
  506. $.data( element, this.widgetName, this );
  507. $.data( element, this.widgetFullName, this );
  508. this._on( true, this.element, {
  509. remove: function( event ) {
  510. if ( event.target === element ) {
  511. this.destroy();
  512. }
  513. }
  514. });
  515. this.document = $( element.style ?
  516. // element within the document
  517. element.ownerDocument :
  518. // element is window or document
  519. element.document || element );
  520. this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
  521. }
  522. this._create();
  523. this._trigger( "create", null, this._getCreateEventData() );
  524. this._init();
  525. },
  526. _getCreateOptions: $.noop,
  527. _getCreateEventData: $.noop,
  528. _create: $.noop,
  529. _init: $.noop,
  530. destroy: function() {
  531. this._destroy();
  532. // we can probably remove the unbind calls in 2.0
  533. // all event bindings should go through this._on()
  534. this.element
  535. .unbind( this.eventNamespace )
  536. // 1.9 BC for #7810
  537. // TODO remove dual storage
  538. .removeData( this.widgetName )
  539. .removeData( this.widgetFullName )
  540. // support: jquery <1.6.3
  541. // http://bugs.jquery.com/ticket/9413
  542. .removeData( $.camelCase( this.widgetFullName ) );
  543. this.widget()
  544. .unbind( this.eventNamespace )
  545. .removeAttr( "aria-disabled" )
  546. .removeClass(
  547. this.widgetFullName + "-disabled " +
  548. "ui-state-disabled" );
  549. // clean up events and states
  550. this.bindings.unbind( this.eventNamespace );
  551. this.hoverable.removeClass( "ui-state-hover" );
  552. this.focusable.removeClass( "ui-state-focus" );
  553. },
  554. _destroy: $.noop,
  555. widget: function() {
  556. return this.element;
  557. },
  558. option: function( key, value ) {
  559. var options = key,
  560. parts,
  561. curOption,
  562. i;
  563. if ( arguments.length === 0 ) {
  564. // don't return a reference to the internal hash
  565. return $.widget.extend( {}, this.options );
  566. }
  567. if ( typeof key === "string" ) {
  568. // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  569. options = {};
  570. parts = key.split( "." );
  571. key = parts.shift();
  572. if ( parts.length ) {
  573. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  574. for ( i = 0; i < parts.length - 1; i++ ) {
  575. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  576. curOption = curOption[ parts[ i ] ];
  577. }
  578. key = parts.pop();
  579. if ( value === undefined ) {
  580. return curOption[ key ] === undefined ? null : curOption[ key ];
  581. }
  582. curOption[ key ] = value;
  583. } else {
  584. if ( value === undefined ) {
  585. return this.options[ key ] === undefined ? null : this.options[ key ];
  586. }
  587. options[ key ] = value;
  588. }
  589. }
  590. this._setOptions( options );
  591. return this;
  592. },
  593. _setOptions: function( options ) {
  594. var key;
  595. for ( key in options ) {
  596. this._setOption( key, options[ key ] );
  597. }
  598. return this;
  599. },
  600. _setOption: function( key, value ) {
  601. this.options[ key ] = value;
  602. if ( key === "disabled" ) {
  603. this.widget()
  604. .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
  605. .attr( "aria-disabled", value );
  606. this.hoverable.removeClass( "ui-state-hover" );
  607. this.focusable.removeClass( "ui-state-focus" );
  608. }
  609. return this;
  610. },
  611. enable: function() {
  612. return this._setOption( "disabled", false );
  613. },
  614. disable: function() {
  615. return this._setOption( "disabled", true );
  616. },
  617. _on: function( suppressDisabledCheck, element, handlers ) {
  618. var delegateElement,
  619. instance = this;
  620. // no suppressDisabledCheck flag, shuffle arguments
  621. if ( typeof suppressDisabledCheck !== "boolean" ) {
  622. handlers = element;
  623. element = suppressDisabledCheck;
  624. suppressDisabledCheck = false;
  625. }
  626. // no element argument, shuffle and use this.element
  627. if ( !handlers ) {
  628. handlers = element;
  629. element = this.element;
  630. delegateElement = this.widget();
  631. } else {
  632. // accept selectors, DOM elements
  633. element = delegateElement = $( element );
  634. this.bindings = this.bindings.add( element );
  635. }
  636. $.each( handlers, function( event, handler ) {
  637. function handlerProxy() {
  638. // allow widgets to customize the disabled handling
  639. // - disabled as an array instead of boolean
  640. // - disabled class as method for disabling individual parts
  641. if ( !suppressDisabledCheck &&
  642. ( instance.options.disabled === true ||
  643. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  644. return;
  645. }
  646. return ( typeof handler === "string" ? instance[ handler ] : handler )
  647. .apply( instance, arguments );
  648. }
  649. // copy the guid so direct unbinding works
  650. if ( typeof handler !== "string" ) {
  651. handlerProxy.guid = handler.guid =
  652. handler.guid || handlerProxy.guid || $.guid++;
  653. }
  654. var match = event.match( /^(\w+)\s*(.*)$/ ),
  655. eventName = match[1] + instance.eventNamespace,
  656. selector = match[2];
  657. if ( selector ) {
  658. delegateElement.delegate( selector, eventName, handlerProxy );
  659. } else {
  660. element.bind( eventName, handlerProxy );
  661. }
  662. });
  663. },
  664. _off: function( element, eventName ) {
  665. eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
  666. element.unbind( eventName ).undelegate( eventName );
  667. },
  668. _delay: function( handler, delay ) {
  669. function handlerProxy() {
  670. return ( typeof handler === "string" ? instance[ handler ] : handler )
  671. .apply( instance, arguments );
  672. }
  673. var instance = this;
  674. return setTimeout( handlerProxy, delay || 0 );
  675. },
  676. _hoverable: function( element ) {
  677. this.hoverable = this.hoverable.add( element );
  678. this._on( element, {
  679. mouseenter: function( event ) {
  680. $( event.currentTarget ).addClass( "ui-state-hover" );
  681. },
  682. mouseleave: function( event ) {
  683. $( event.currentTarget ).removeClass( "ui-state-hover" );
  684. }
  685. });
  686. },
  687. _focusable: function( element ) {
  688. this.focusable = this.focusable.add( element );
  689. this._on( element, {
  690. focusin: function( event ) {
  691. $( event.currentTarget ).addClass( "ui-state-focus" );
  692. },
  693. focusout: function( event ) {
  694. $( event.currentTarget ).removeClass( "ui-state-focus" );
  695. }
  696. });
  697. },
  698. _trigger: function( type, event, data ) {
  699. var prop, orig,
  700. callback = this.options[ type ];
  701. data = data || {};
  702. event = $.Event( event );
  703. event.type = ( type === this.widgetEventPrefix ?
  704. type :
  705. this.widgetEventPrefix + type ).toLowerCase();
  706. // the original event may come from any element
  707. // so we need to reset the target on the new event
  708. event.target = this.element[ 0 ];
  709. // copy original event properties over to the new event
  710. orig = event.originalEvent;
  711. if ( orig ) {
  712. for ( prop in orig ) {
  713. if ( !( prop in event ) ) {
  714. event[ prop ] = orig[ prop ];
  715. }
  716. }
  717. }
  718. this.element.trigger( event, data );
  719. return !( $.isFunction( callback ) &&
  720. callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
  721. event.isDefaultPrevented() );
  722. }
  723. };
  724. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  725. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  726. if ( typeof options === "string" ) {
  727. options = { effect: options };
  728. }
  729. var hasOptions,
  730. effectName = !options ?
  731. method :
  732. options === true || typeof options === "number" ?
  733. defaultEffect :
  734. options.effect || defaultEffect;
  735. options = options || {};
  736. if ( typeof options === "number" ) {
  737. options = { duration: options };
  738. }
  739. hasOptions = !$.isEmptyObject( options );
  740. options.complete = callback;
  741. if ( options.delay ) {
  742. element.delay( options.delay );
  743. }
  744. if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
  745. element[ method ]( options );
  746. } else if ( effectName !== method && element[ effectName ] ) {
  747. element[ effectName ]( options.duration, options.easing, callback );
  748. } else {
  749. element.queue(function( next ) {
  750. $( this )[ method ]();
  751. if ( callback ) {
  752. callback.call( element[ 0 ] );
  753. }
  754. next();
  755. });
  756. }
  757. };
  758. });
  759. // DEPRECATED
  760. if ( $.uiBackCompat !== false ) {
  761. $.Widget.prototype._getCreateOptions = function() {
  762. return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
  763. };
  764. }
  765. })( jQuery );
  766. (function( $, undefined ) {
  767. var mouseHandled = false;
  768. $( document ).mouseup( function( e ) {
  769. mouseHandled = false;
  770. });
  771. $.widget("ui.mouse", {
  772. version: "1.9.2",
  773. options: {
  774. cancel: 'input,textarea,button,select,option',
  775. distance: 1,
  776. delay: 0
  777. },
  778. _mouseInit: function() {
  779. var that = this;
  780. this.element
  781. .bind('mousedown.'+this.widgetName, function(event) {
  782. return that._mouseDown(event);
  783. })
  784. .bind('click.'+this.widgetName, function(event) {
  785. if (true === $.data(event.target, that.widgetName + '.preventClickEvent')) {
  786. $.removeData(event.target, that.widgetName + '.preventClickEvent');
  787. event.stopImmediatePropagation();
  788. return false;
  789. }
  790. });
  791. this.started = false;
  792. },
  793. // TODO: make sure destroying one instance of mouse doesn't mess with
  794. // other instances of mouse
  795. _mouseDestroy: function() {
  796. this.element.unbind('.'+this.widgetName);
  797. if ( this._mouseMoveDelegate ) {
  798. $(document)
  799. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  800. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  801. }
  802. },
  803. _mouseDown: function(event) {
  804. // don't let more than one widget handle mouseStart
  805. if( mouseHandled ) { return; }
  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. $(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. // IE mouseup check - mouseup happened when mouse was out of window
  850. if ($.ui.ie && !(document.documentMode >= 9) && !event.button) {
  851. return this._mouseUp(event);
  852. }
  853. if (this._mouseStarted) {
  854. this._mouseDrag(event);
  855. return event.preventDefault();
  856. }
  857. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  858. this._mouseStarted =
  859. (this._mouseStart(this._mouseDownEvent, event) !== false);
  860. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  861. }
  862. return !this._mouseStarted;
  863. },
  864. _mouseUp: function(event) {
  865. $(document)
  866. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  867. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  868. if (this._mouseStarted) {
  869. this._mouseStarted = false;
  870. if (event.target === this._mouseDownEvent.target) {
  871. $.data(event.target, this.widgetName + '.preventClickEvent', true);
  872. }
  873. this._mouseStop(event);
  874. }
  875. return false;
  876. },
  877. _mouseDistanceMet: function(event) {
  878. return (Math.max(
  879. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  880. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  881. ) >= this.options.distance
  882. );
  883. },
  884. _mouseDelayMet: function(event) {
  885. return this.mouseDelayMet;
  886. },
  887. // These are placeholder methods, to be overriden by extending plugin
  888. _mouseStart: function(event) {},
  889. _mouseDrag: function(event) {},
  890. _mouseStop: function(event) {},
  891. _mouseCapture: function(event) { return true; }
  892. });
  893. })(jQuery);
  894. (function( $, undefined ) {
  895. $.widget("ui.draggable", $.ui.mouse, {
  896. version: "1.9.2",
  897. widgetEventPrefix: "drag",
  898. options: {
  899. addClasses: true,
  900. appendTo: "parent",
  901. axis: false,
  902. connectToSortable: false,
  903. containment: false,
  904. cursor: "auto",
  905. cursorAt: false,
  906. grid: false,
  907. handle: false,
  908. helper: "original",
  909. iframeFix: false,
  910. opacity: false,
  911. refreshPositions: false,
  912. revert: false,
  913. revertDuration: 500,
  914. scope: "default",
  915. scroll: true,
  916. scrollSensitivity: 20,
  917. scrollSpeed: 20,
  918. snap: false,
  919. snapMode: "both",
  920. snapTolerance: 20,
  921. stack: false,
  922. zIndex: false
  923. },
  924. _create: function() {
  925. if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
  926. this.element[0].style.position = 'relative';
  927. (this.options.addClasses && this.element.addClass("ui-draggable"));
  928. (this.options.disabled && this.element.addClass("ui-draggable-disabled"));
  929. this._mouseInit();
  930. },
  931. _destroy: function() {
  932. this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" );
  933. this._mouseDestroy();
  934. },
  935. _mouseCapture: function(event) {
  936. var o = this.options;
  937. // among others, prevent a drag on a resizable-handle
  938. if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle'))
  939. return false;
  940. //Quit if we're not on a valid handle
  941. this.handle = this._getHandle(event);
  942. if (!this.handle)
  943. return false;
  944. $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
  945. $('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
  946. .css({
  947. width: this.offsetWidth+"px", height: this.offsetHeight+"px",
  948. position: "absolute", opacity: "0.001", zIndex: 1000
  949. })
  950. .css($(this).offset())
  951. .appendTo("body");
  952. });
  953. return true;
  954. },
  955. _mouseStart: function(event) {
  956. var o = this.options;
  957. //Create and append the visible helper
  958. this.helper = this._createHelper(event);
  959. this.helper.addClass("ui-draggable-dragging");
  960. //Cache the helper size
  961. this._cacheHelperProportions();
  962. //If ddmanager is used for droppables, set the global draggable
  963. if($.ui.ddmanager)
  964. $.ui.ddmanager.current = this;
  965. /*
  966. * - Position generation -
  967. * This block generates everything position related - it's the core of draggables.
  968. */
  969. //Cache the margins of the original element
  970. this._cacheMargins();
  971. //Store the helper's css position
  972. this.cssPosition = this.helper.css("position");
  973. this.scrollParent = this.helper.scrollParent();
  974. //The element's absolute position on the page minus margins
  975. this.offset = this.positionAbs = this.element.offset();
  976. this.offset = {
  977. top: this.offset.top - this.margins.top,
  978. left: this.offset.left - this.margins.left
  979. };
  980. $.extend(this.offset, {
  981. click: { //Where the click happened, relative to the element
  982. left: event.pageX - this.offset.left,
  983. top: event.pageY - this.offset.top
  984. },
  985. parent: this._getParentOffset(),
  986. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  987. });
  988. //Generate the original position
  989. this.originalPosition = this.position = this._generatePosition(event);
  990. this.originalPageX = event.pageX;
  991. this.originalPageY = event.pageY;
  992. //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
  993. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  994. //Set a containment if given in the options
  995. if(o.containment)
  996. this._setContainment();
  997. //Trigger event + callbacks
  998. if(this._trigger("start", event) === false) {
  999. this._clear();
  1000. return false;
  1001. }
  1002. //Recache the helper size
  1003. this._cacheHelperProportions();
  1004. //Prepare the droppable offsets
  1005. if ($.ui.ddmanager && !o.dropBehaviour)
  1006. $.ui.ddmanager.prepareOffsets(this, event);
  1007. this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  1008. //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
  1009. if ( $.ui.ddmanager ) $.ui.ddmanager.dragStart(this, event);
  1010. return true;
  1011. },
  1012. _mouseDrag: function(event, noPropagation) {
  1013. //Compute the helpers position
  1014. this.position = this._generatePosition(event);
  1015. this.positionAbs = this._convertPositionTo("absolute");
  1016. //Call plugins and callbacks and use the resulting position if something is returned
  1017. if (!noPropagation) {
  1018. var ui = this._uiHash();
  1019. if(this._trigger('drag', event, ui) === false) {
  1020. this._mouseUp({});
  1021. return false;
  1022. }
  1023. this.position = ui.position;
  1024. }
  1025. if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
  1026. if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
  1027. if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
  1028. return false;
  1029. },
  1030. _mouseStop: function(event) {
  1031. //If we are using droppables, inform the manager about the drop
  1032. var dropped = false;
  1033. if ($.ui.ddmanager && !this.options.dropBehaviour)
  1034. dropped = $.ui.ddmanager.drop(this, event);
  1035. //if a drop comes from outside (a sortable)
  1036. if(this.dropped) {
  1037. dropped = this.dropped;
  1038. this.dropped = false;
  1039. }
  1040. //if the original element is no longer in the DOM don't bother to continue (see #8269)
  1041. var element = this.element[0], elementInDom = false;
  1042. while ( element && (element = element.parentNode) ) {
  1043. if (element == document ) {
  1044. elementInDom = true;
  1045. }
  1046. }
  1047. if ( !elementInDom && this.options.helper === "original" )
  1048. return false;
  1049. if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) {
  1050. var that = this;
  1051. $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
  1052. if(that._trigger("stop", event) !== false) {
  1053. that._clear();
  1054. }
  1055. });
  1056. } else {
  1057. if(this._trigger("stop", event) !== false) {
  1058. this._clear();
  1059. }
  1060. }
  1061. return false;
  1062. },
  1063. _mouseUp: function(event) {
  1064. //Remove frame helpers
  1065. $("div.ui-draggable-iframeFix").each(function() {
  1066. this.parentNode.removeChild(this);
  1067. });
  1068. //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
  1069. if( $.ui.ddmanager ) $.ui.ddmanager.dragStop(this, event);
  1070. return $.ui.mouse.prototype._mouseUp.call(this, event);
  1071. },
  1072. cancel: function() {
  1073. if(this.helper.is(".ui-draggable-dragging")) {
  1074. this._mouseUp({});
  1075. } else {
  1076. this._clear();
  1077. }
  1078. return this;
  1079. },
  1080. _getHandle: function(event) {
  1081. var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
  1082. $(this.options.handle, this.element)
  1083. .find("*")
  1084. .andSelf()
  1085. .each(function() {
  1086. if(this == event.target) handle = true;
  1087. });
  1088. return handle;
  1089. },
  1090. _createHelper: function(event) {
  1091. var o = this.options;
  1092. var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone().removeAttr('id') : this.element);
  1093. if(!helper.parents('body').length)
  1094. helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
  1095. if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position")))
  1096. helper.css("position", "absolute");
  1097. return helper;
  1098. },
  1099. _adjustOffsetFromHelper: function(obj) {
  1100. if (typeof obj == 'string') {
  1101. obj = obj.split(' ');
  1102. }
  1103. if ($.isArray(obj)) {
  1104. obj = {left: +obj[0], top: +obj[1] || 0};
  1105. }
  1106. if ('left' in obj) {
  1107. this.offset.click.left = obj.left + this.margins.left;
  1108. }
  1109. if ('right' in obj) {
  1110. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  1111. }
  1112. if ('top' in obj) {
  1113. this.offset.click.top = obj.top + this.margins.top;
  1114. }
  1115. if ('bottom' in obj) {
  1116. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  1117. }
  1118. },
  1119. _getParentOffset: function() {
  1120. //Get the offsetParent and cache its position
  1121. this.offsetParent = this.helper.offsetParent();
  1122. var po = this.offsetParent.offset();
  1123. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  1124. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  1125. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  1126. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  1127. if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  1128. po.left += this.scrollParent.scrollLeft();
  1129. po.top += this.scrollParent.scrollTop();
  1130. }
  1131. if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
  1132. || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.ui.ie)) //Ugly IE fix
  1133. po = { top: 0, left: 0 };
  1134. return {
  1135. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  1136. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  1137. };
  1138. },
  1139. _getRelativeOffset: function() {
  1140. if(this.cssPosition == "relative") {
  1141. var p = this.element.position();
  1142. return {
  1143. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  1144. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  1145. };
  1146. } else {
  1147. return { top: 0, left: 0 };
  1148. }
  1149. },
  1150. _cacheMargins: function() {
  1151. this.margins = {
  1152. left: (parseInt(this.element.css("marginLeft"),10) || 0),
  1153. top: (parseInt(this.element.css("marginTop"),10) || 0),
  1154. right: (parseInt(this.element.css("marginRight"),10) || 0),
  1155. bottom: (parseInt(this.element.css("marginBottom"),10) || 0)
  1156. };
  1157. },
  1158. _cacheHelperProportions: function() {
  1159. this.helperProportions = {
  1160. width: this.helper.outerWidth(),
  1161. height: this.helper.outerHeight()
  1162. };
  1163. },
  1164. _setContainment: function() {
  1165. var o = this.options;
  1166. if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
  1167. if(o.containment == 'document' || o.containment == 'window') this.containment = [
  1168. o.containment == 'document' ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
  1169. o.containment == 'document' ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
  1170. (o.containment == 'document' ? 0 : $(window).scrollLeft()) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
  1171. (o.containment == 'document' ? 0 : $(window).scrollTop()) + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  1172. ];
  1173. if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) {
  1174. var c = $(o.containment);
  1175. var ce = c[0]; if(!ce) return;
  1176. var co = c.offset();
  1177. var over = ($(ce).css("overflow") != 'hidden');
  1178. this.containment = [
  1179. (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
  1180. (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
  1181. (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 - this.margins.right,
  1182. (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 - this.margins.bottom
  1183. ];
  1184. this.relative_container = c;
  1185. } else if(o.containment.constructor == Array) {
  1186. this.containment = o.containment;
  1187. }
  1188. },
  1189. _convertPositionTo: function(d, pos) {
  1190. if(!pos) pos = this.position;
  1191. var mod = d == "absolute" ? 1 : -1;
  1192. var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  1193. return {
  1194. top: (
  1195. pos.top // The absolute mouse position
  1196. + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  1197. + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
  1198. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  1199. ),
  1200. left: (
  1201. pos.left // The absolute mouse position
  1202. + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  1203. + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
  1204. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  1205. )
  1206. };
  1207. },
  1208. _generatePosition: function(event) {
  1209. var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  1210. var pageX = event.pageX;
  1211. var pageY = event.pageY;
  1212. /*
  1213. * - Position constraining -
  1214. * Constrain the position to a mix of grid, containment.
  1215. */
  1216. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  1217. var containment;
  1218. if(this.containment) {
  1219. if (this.relative_container){
  1220. var co = this.relative_container.offset();
  1221. containment = [ this.containment[0] + co.left,
  1222. this.containment[1] + co.top,
  1223. this.containment[2] + co.left,
  1224. this.containment[3] + co.top ];
  1225. }
  1226. else {
  1227. containment = this.containment;
  1228. }
  1229. if(event.pageX - this.offset.click.left < containment[0]) pageX = containment[0] + this.offset.click.left;
  1230. if(event.pageY - this.offset.click.top < containment[1]) pageY = containment[1] + this.offset.click.top;
  1231. if(event.pageX - this.offset.click.left > containment[2]) pageX = containment[2] + this.offset.click.left;
  1232. if(event.pageY - this.offset.click.top > containment[3]) pageY = containment[3] + this.offset.click.top;
  1233. }
  1234. if(o.grid) {
  1235. //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
  1236. var top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
  1237. pageY = containment ? (!(top - this.offset.click.top < containment[1] || top - this.offset.click.top > containment[3]) ? top : (!(top - this.offset.click.top < containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
  1238. var left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX;
  1239. pageX = containment ? (!(left - this.offset.click.left < containment[0] || left - this.offset.click.left > containment[2]) ? left : (!(left - this.offset.click.left < containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
  1240. }
  1241. }
  1242. return {
  1243. top: (
  1244. pageY // The absolute mouse position
  1245. - this.offset.click.top // Click offset (relative to the element)
  1246. - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
  1247. - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
  1248. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  1249. ),
  1250. left: (
  1251. pageX // The absolute mouse position
  1252. - this.offset.click.left // Click offset (relative to the element)
  1253. - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
  1254. - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
  1255. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  1256. )
  1257. };
  1258. },
  1259. _clear: function() {
  1260. this.helper.removeClass("ui-draggable-dragging");
  1261. if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove();
  1262. //if($.ui.ddmanager) $.ui.ddmanager.current = null;
  1263. this.helper = null;
  1264. this.cancelHelperRemoval = false;
  1265. },
  1266. // From now on bulk stuff - mainly helpers
  1267. _trigger: function(type, event, ui) {
  1268. ui = ui || this._uiHash();
  1269. $.ui.plugin.call(this, type, [event, ui]);
  1270. if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins
  1271. return $.Widget.prototype._trigger.call(this, type, event, ui);
  1272. },
  1273. plugins: {},
  1274. _uiHash: function(event) {
  1275. return {
  1276. helper: this.helper,
  1277. position: this.position,
  1278. originalPosition: this.originalPosition,
  1279. offset: this.positionAbs
  1280. };
  1281. }
  1282. });
  1283. $.ui.plugin.add("draggable", "connectToSortable", {
  1284. start: function(event, ui) {
  1285. var inst = $(this).data("draggable"), o = inst.options,
  1286. uiSortable = $.extend({}, ui, { item: inst.element });
  1287. inst.sortables = [];
  1288. $(o.connectToSortable).each(function() {
  1289. var sortable = $.data(this, 'sortable');
  1290. if (sortable && !sortable.options.disabled) {
  1291. inst.sortables.push({
  1292. instance: sortable,
  1293. shouldRevert: sortable.options.revert
  1294. });
  1295. sortable.refreshPositions(); // Call the sortable's refreshPositions at drag start to refresh the containerCache since the sortable container cache is used in drag and needs to be up to date (this will ensure it's initialised as well as being kept in step with any changes that might have happened on the page).
  1296. sortable._trigger("activate", event, uiSortable);
  1297. }
  1298. });
  1299. },
  1300. stop: function(event, ui) {
  1301. //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
  1302. var inst = $(this).data("draggable"),
  1303. uiSortable = $.extend({}, ui, { item: inst.element });
  1304. $.each(inst.sortables, function() {
  1305. if(this.instance.isOver) {
  1306. this.instance.isOver = 0;
  1307. inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
  1308. this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
  1309. //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid'
  1310. if(this.shouldRevert) this.instance.options.revert = true;
  1311. //Trigger the stop of the sortable
  1312. this.instance._mouseStop(event);
  1313. this.instance.options.helper = this.instance.options._helper;
  1314. //If the helper has been the original item, restore properties in the sortable
  1315. if(inst.options.helper == 'original')
  1316. this.instance.currentItem.css({ top: 'auto', left: 'auto' });
  1317. } else {
  1318. this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
  1319. this.instance._trigger("deactivate", event, uiSortable);
  1320. }
  1321. });
  1322. },
  1323. drag: function(event, ui) {
  1324. var inst = $(this).data("draggable"), that = this;
  1325. var checkPos = function(o) {
  1326. var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
  1327. var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
  1328. var itemHeight = o.height, itemWidth = o.width;
  1329. var itemTop = o.top, itemLeft = o.left;
  1330. return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
  1331. };
  1332. $.each(inst.sortables, function(i) {
  1333. var innermostIntersecting = false;
  1334. var thisSortable = this;
  1335. //Copy over some variables to allow calling the sortable's native _intersectsWith
  1336. this.instance.positionAbs = inst.positionAbs;
  1337. this.instance.helperProportions = inst.helperProportions;
  1338. this.instance.offset.click = inst.offset.click;
  1339. if(this.instance._intersectsWith(this.instance.containerCache)) {
  1340. innermostIntersecting = true;
  1341. $.each(inst.sortables, function () {
  1342. this.instance.positionAbs = inst.positionAbs;
  1343. this.instance.helperProportions = inst.helperProportions;
  1344. this.instance.offset.click = inst.offset.click;
  1345. if (this != thisSortable
  1346. && this.instance._intersectsWith(this.instance.containerCache)
  1347. && $.ui.contains(thisSortable.instance.element[0], this.instance.element[0]))
  1348. innermostIntersecting = false;
  1349. return innermostIntersecting;
  1350. });
  1351. }
  1352. if(innermostIntersecting) {
  1353. //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
  1354. if(!this.instance.isOver) {
  1355. this.instance.isOver = 1;
  1356. //Now we fake the start of dragging for the sortable instance,
  1357. //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
  1358. //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
  1359. this.instance.currentItem = $(that).clone().removeAttr('id').appendTo(this.instance.element).data("sortable-item", true);
  1360. this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
  1361. this.instance.options.helper = function() { return ui.helper[0]; };
  1362. event.target = this.instance.currentItem[0];
  1363. this.instance._mouseCapture(event, true);
  1364. this.instance._mouseStart(event, true, true);
  1365. //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
  1366. this.instance.offset.click.top = inst.offset.click.top;
  1367. this.instance.offset.click.left = inst.offset.click.left;
  1368. this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
  1369. this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
  1370. inst._trigger("toSortable", event);
  1371. inst.dropped = this.instance.element; //draggable revert needs that
  1372. //hack so receive/update callbacks work (mostly)
  1373. inst.currentItem = inst.element;
  1374. this.instance.fromOutside = inst;
  1375. }
  1376. //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
  1377. if(this.instance.currentItem) this.instance._mouseDrag(event);
  1378. } else {
  1379. //If it doesn't intersect with the sortable, and it intersected before,
  1380. //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
  1381. if(this.instance.isOver) {
  1382. this.instance.isOver = 0;
  1383. this.instance.cancelHelperRemoval = true;
  1384. //Prevent reverting on this forced stop
  1385. this.instance.options.revert = false;
  1386. // The out event needs to be triggered independently
  1387. this.instance._trigger('out', event, this.instance._uiHash(this.instance));
  1388. this.instance._mouseStop(event, true);
  1389. this.instance.options.helper = this.instance.options._helper;
  1390. //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
  1391. this.instance.currentItem.remove();
  1392. if(this.instance.placeholder) this.instance.placeholder.remove();
  1393. inst._trigger("fromSortable", event);
  1394. inst.dropped = false; //draggable revert needs that
  1395. }
  1396. };
  1397. });
  1398. }
  1399. });
  1400. $.ui.plugin.add("draggable", "cursor", {
  1401. start: function(event, ui) {
  1402. var t = $('body'), o = $(this).data('draggable').options;
  1403. if (t.css("cursor")) o._cursor = t.css("cursor");
  1404. t.css("cursor", o.cursor);
  1405. },
  1406. stop: function(event, ui) {
  1407. var o = $(this).data('draggable').options;
  1408. if (o._cursor) $('body').css("cursor", o._cursor);
  1409. }
  1410. });
  1411. $.ui.plugin.add("draggable", "opacity", {
  1412. start: function(event, ui) {
  1413. var t = $(ui.helper), o = $(this).data('draggable').options;
  1414. if(t.css("opacity")) o._opacity = t.css("opacity");
  1415. t.css('opacity', o.opacity);
  1416. },
  1417. stop: function(event, ui) {
  1418. var o = $(this).data('draggable').options;
  1419. if(o._opacity) $(ui.helper).css('opacity', o._opacity);
  1420. }
  1421. });
  1422. $.ui.plugin.add("draggable", "scroll", {
  1423. start: function(event, ui) {
  1424. var i = $(this).data("draggable");
  1425. if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
  1426. },
  1427. drag: function(event, ui) {
  1428. var i = $(this).data("draggable"), o = i.options, scrolled = false;
  1429. if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {
  1430. if(!o.axis || o.axis != 'x') {
  1431. if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
  1432. i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
  1433. else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity)
  1434. i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
  1435. }
  1436. if(!o.axis || o.axis != 'y') {
  1437. if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
  1438. i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
  1439. else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity)
  1440. i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
  1441. }
  1442. } else {
  1443. if(!o.axis || o.axis != 'x') {
  1444. if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
  1445. scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
  1446. else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
  1447. scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
  1448. }
  1449. if(!o.axis || o.axis != 'y') {
  1450. if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
  1451. scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
  1452. else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
  1453. scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
  1454. }
  1455. }
  1456. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
  1457. $.ui.ddmanager.prepareOffsets(i, event);
  1458. }
  1459. });
  1460. $.ui.plugin.add("draggable", "snap", {
  1461. start: function(event, ui) {
  1462. var i = $(this).data("draggable"), o = i.options;
  1463. i.snapElements = [];
  1464. $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() {
  1465. var $t = $(this); var $o = $t.offset();
  1466. if(this != i.element[0]) i.snapElements.push({
  1467. item: this,
  1468. width: $t.outerWidth(), height: $t.outerHeight(),
  1469. top: $o.top, left: $o.left
  1470. });
  1471. });
  1472. },
  1473. drag: function(event, ui) {
  1474. var inst = $(this).data("draggable"), o = inst.options;
  1475. var d = o.snapTolerance;
  1476. var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
  1477. y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
  1478. for (var i = inst.snapElements.length - 1; i >= 0; i--){
  1479. var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width,
  1480. t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
  1481. //Yes, I know, this is insane ;)
  1482. if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) {
  1483. if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
  1484. inst.snapElements[i].snapping = false;
  1485. continue;
  1486. }
  1487. if(o.snapMode != 'inner') {
  1488. var ts = Math.abs(t - y2) <= d;
  1489. var bs = Math.abs(b - y1) <= d;
  1490. var ls = Math.abs(l - x2) <= d;
  1491. var rs = Math.abs(r - x1) <= d;
  1492. if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
  1493. if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
  1494. if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
  1495. if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
  1496. }
  1497. var first = (ts || bs || ls || rs);
  1498. if(o.snapMode != 'outer') {
  1499. var ts = Math.abs(t - y1) <= d;
  1500. var bs = Math.abs(b - y2) <= d;
  1501. var ls = Math.abs(l - x1) <= d;
  1502. var rs = Math.abs(r - x2) <= d;
  1503. if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top;
  1504. if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
  1505. if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
  1506. if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
  1507. }
  1508. if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first))
  1509. (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
  1510. inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
  1511. };
  1512. }
  1513. });
  1514. $.ui.plugin.add("draggable", "stack", {
  1515. start: function(event, ui) {
  1516. var o = $(this).data("draggable").options;
  1517. var group = $.makeArray($(o.stack)).sort(function(a,b) {
  1518. return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
  1519. });
  1520. if (!group.length) { return; }
  1521. var min = parseInt(group[0].style.zIndex) || 0;
  1522. $(group).each(function(i) {
  1523. this.style.zIndex = min + i;
  1524. });
  1525. this[0].style.zIndex = min + group.length;
  1526. }
  1527. });
  1528. $.ui.plugin.add("draggable", "zIndex", {
  1529. start: function(event, ui) {
  1530. var t = $(ui.helper), o = $(this).data("draggable").options;
  1531. if(t.css("zIndex")) o._zIndex = t.css("zIndex");
  1532. t.css('zIndex', o.zIndex);
  1533. },
  1534. stop: function(event, ui) {
  1535. var o = $(this).data("draggable").options;
  1536. if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex);
  1537. }
  1538. });
  1539. })(jQuery);
  1540. (function( $, undefined ) {
  1541. $.widget("ui.droppable", {
  1542. version: "1.9.2",
  1543. widgetEventPrefix: "drop",
  1544. options: {
  1545. accept: '*',
  1546. activeClass: false,
  1547. addClasses: true,
  1548. greedy: false,
  1549. hoverClass: false,
  1550. scope: 'default',
  1551. tolerance: 'intersect'
  1552. },
  1553. _create: function() {
  1554. var o = this.options, accept = o.accept;
  1555. this.isover = 0; this.isout = 1;
  1556. this.accept = $.isFunction(accept) ? accept : function(d) {
  1557. return d.is(accept);
  1558. };
  1559. //Store the droppable's proportions
  1560. this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
  1561. // Add the reference and positions to the manager
  1562. $.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || [];
  1563. $.ui.ddmanager.droppables[o.scope].push(this);
  1564. (o.addClasses && this.element.addClass("ui-droppable"));
  1565. },
  1566. _destroy: function() {
  1567. var drop = $.ui.ddmanager.droppables[this.options.scope];
  1568. for ( var i = 0; i < drop.length; i++ )
  1569. if ( drop[i] == this )
  1570. drop.splice(i, 1);
  1571. this.element.removeClass("ui-droppable ui-droppable-disabled");
  1572. },
  1573. _setOption: function(key, value) {
  1574. if(key == 'accept') {
  1575. this.accept = $.isFunction(value) ? value : function(d) {
  1576. return d.is(value);
  1577. };
  1578. }
  1579. $.Widget.prototype._setOption.apply(this, arguments);
  1580. },
  1581. _activate: function(event) {
  1582. var draggable = $.ui.ddmanager.current;
  1583. if(this.options.activeClass) this.element.addClass(this.options.activeClass);
  1584. (draggable && this._trigger('activate', event, this.ui(draggable)));
  1585. },
  1586. _deactivate: function(event) {
  1587. var draggable = $.ui.ddmanager.current;
  1588. if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
  1589. (draggable && this._trigger('deactivate', event, this.ui(draggable)));
  1590. },
  1591. _over: function(event) {
  1592. var draggable = $.ui.ddmanager.current;
  1593. if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
  1594. if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  1595. if(this.options.hoverClass) this.element.addClass(this.options.hoverClass);
  1596. this._trigger('over', event, this.ui(draggable));
  1597. }
  1598. },
  1599. _out: function(event) {
  1600. var draggable = $.ui.ddmanager.current;
  1601. if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
  1602. if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  1603. if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
  1604. this._trigger('out', event, this.ui(draggable));
  1605. }
  1606. },
  1607. _drop: function(event,custom) {
  1608. var draggable = custom || $.ui.ddmanager.current;
  1609. if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
  1610. var childrenIntersection = false;
  1611. this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() {
  1612. var inst = $.data(this, 'droppable');
  1613. if(
  1614. inst.options.greedy
  1615. && !inst.options.disabled
  1616. && inst.options.scope == draggable.options.scope
  1617. && inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element))
  1618. && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
  1619. ) { childrenIntersection = true; return false; }
  1620. });
  1621. if(childrenIntersection) return false;
  1622. if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  1623. if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
  1624. if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
  1625. this._trigger('drop', event, this.ui(draggable));
  1626. return this.element;
  1627. }
  1628. return false;
  1629. },
  1630. ui: function(c) {
  1631. return {
  1632. draggable: (c.currentItem || c.element),
  1633. helper: c.helper,
  1634. position: c.position,
  1635. offset: c.positionAbs
  1636. };
  1637. }
  1638. });
  1639. $.ui.intersect = function(draggable, droppable, toleranceMode) {
  1640. if (!droppable.offset) return false;
  1641. var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
  1642. y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
  1643. var l = droppable.offset.left, r = l + droppable.proportions.width,
  1644. t = droppable.offset.top, b = t + droppable.proportions.height;
  1645. switch (toleranceMode) {
  1646. case 'fit':
  1647. return (l <= x1 && x2 <= r
  1648. && t <= y1 && y2 <= b);
  1649. break;
  1650. case 'intersect':
  1651. return (l < x1 + (draggable.helperProportions.width / 2) // Right Half
  1652. && x2 - (draggable.helperProportions.width / 2) < r // Left Half
  1653. && t < y1 + (draggable.helperProportions.height / 2) // Bottom Half
  1654. && y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
  1655. break;
  1656. case 'pointer':
  1657. var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left),
  1658. draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top),
  1659. isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
  1660. return isOver;
  1661. break;
  1662. case 'touch':
  1663. return (
  1664. (y1 >= t && y1 <= b) || // Top edge touching
  1665. (y2 >= t && y2 <= b) || // Bottom edge touching
  1666. (y1 < t && y2 > b) // Surrounded vertically
  1667. ) && (
  1668. (x1 >= l && x1 <= r) || // Left edge touching
  1669. (x2 >= l && x2 <= r) || // Right edge touching
  1670. (x1 < l && x2 > r) // Surrounded horizontally
  1671. );
  1672. break;
  1673. default:
  1674. return false;
  1675. break;
  1676. }
  1677. };
  1678. /*
  1679. This manager tracks offsets of draggables and droppables
  1680. */
  1681. $.ui.ddmanager = {
  1682. current: null,
  1683. droppables: { 'default': [] },
  1684. prepareOffsets: function(t, event) {
  1685. var m = $.ui.ddmanager.droppables[t.options.scope] || [];
  1686. var type = event ? event.type : null; // workaround for #2317
  1687. var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
  1688. droppablesLoop: for (var i = 0; i < m.length; i++) {
  1689. if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted
  1690. for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item
  1691. m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
  1692. if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables
  1693. m[i].offset = m[i].element.offset();
  1694. m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
  1695. }
  1696. },
  1697. drop: function(draggable, event) {
  1698. var dropped = false;
  1699. $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
  1700. if(!this.options) return;
  1701. if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance))
  1702. dropped = this._drop.call(this, event) || dropped;
  1703. if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  1704. this.isout = 1; this.isover = 0;
  1705. this._deactivate.call(this, event);
  1706. }
  1707. });
  1708. return dropped;
  1709. },
  1710. dragStart: function( draggable, event ) {
  1711. //Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003)
  1712. draggable.element.parentsUntil( "body" ).bind( "scroll.droppable", function() {
  1713. if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
  1714. });
  1715. },
  1716. drag: function(draggable, event) {
  1717. //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
  1718. if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
  1719. //Run through all droppables and check their positions based on specific tolerance options
  1720. $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
  1721. if(this.options.disabled || this.greedyChild || !this.visible) return;
  1722. var intersects = $.ui.intersect(draggable, this, this.options.tolerance);
  1723. var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null);
  1724. if(!c) return;
  1725. var parentInstance;
  1726. if (this.options.greedy) {
  1727. // find droppable parents with same scope
  1728. var scope = this.options.scope;
  1729. var parent = this.element.parents(':data(droppable)').filter(function () {
  1730. return $.data(this, 'droppable').options.scope === scope;
  1731. });
  1732. if (parent.length) {
  1733. parentInstance = $.data(parent[0], 'droppable');
  1734. parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
  1735. }
  1736. }
  1737. // we just moved into a greedy child
  1738. if (parentInstance && c == 'isover') {
  1739. parentInstance['isover'] = 0;
  1740. parentInstance['isout'] = 1;
  1741. parentInstance._out.call(parentInstance, event);
  1742. }
  1743. this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
  1744. this[c == "isover" ? "_over" : "_out"].call(this, event);
  1745. // we just moved out of a greedy child
  1746. if (parentInstance && c == 'isout') {
  1747. parentInstance['isout'] = 0;
  1748. parentInstance['isover'] = 1;
  1749. parentInstance._over.call(parentInstance, event);
  1750. }
  1751. });
  1752. },
  1753. dragStop: function( draggable, event ) {
  1754. draggable.element.parentsUntil( "body" ).unbind( "scroll.droppable" );
  1755. //Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003)
  1756. if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
  1757. }
  1758. };
  1759. })(jQuery);
  1760. (function( $, undefined ) {
  1761. $.widget("ui.resizable", $.ui.mouse, {
  1762. version: "1.9.2",
  1763. widgetEventPrefix: "resize",
  1764. options: {
  1765. alsoResize: false,
  1766. animate: false,
  1767. animateDuration: "slow",
  1768. animateEasing: "swing",
  1769. aspectRatio: false,
  1770. autoHide: false,
  1771. containment: false,
  1772. ghost: false,
  1773. grid: false,
  1774. handles: "e,s,se",
  1775. helper: false,
  1776. maxHeight: null,
  1777. maxWidth: null,
  1778. minHeight: 10,
  1779. minWidth: 10,
  1780. zIndex: 1000
  1781. },
  1782. _create: function() {
  1783. var that = this, o = this.options;
  1784. this.element.addClass("ui-resizable");
  1785. $.extend(this, {
  1786. _aspectRatio: !!(o.aspectRatio),
  1787. aspectRatio: o.aspectRatio,
  1788. originalElement: this.element,
  1789. _proportionallyResizeElements: [],
  1790. _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null
  1791. });
  1792. //Wrap the element if it cannot hold child nodes
  1793. if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
  1794. //Create a wrapper element and set the wrapper to the new current internal element
  1795. this.element.wrap(
  1796. $('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({
  1797. position: this.element.css('position'),
  1798. width: this.element.outerWidth(),
  1799. height: this.element.outerHeight(),
  1800. top: this.element.css('top'),
  1801. left: this.element.css('left')
  1802. })
  1803. );
  1804. //Overwrite the original this.element
  1805. this.element = this.element.parent().data(
  1806. "resizable", this.element.data('resizable')
  1807. );
  1808. this.elementIsWrapper = true;
  1809. //Move margins to the wrapper
  1810. this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
  1811. this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
  1812. //Prevent Safari textarea resize
  1813. this.originalResizeStyle = this.originalElement.css('resize');
  1814. this.originalElement.css('resize', 'none');
  1815. //Push the actual element to our proportionallyResize internal array
  1816. this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' }));
  1817. // avoid IE jump (hard set the margin)
  1818. this.originalElement.css({ margin: this.originalElement.css('margin') });
  1819. // fix handlers offset
  1820. this._proportionallyResize();
  1821. }
  1822. this.handles = o.handles || (!$('.ui-resizable-handle', this.element).length ? "e,s,se" : { n: '.ui-resizable-n', e: '.ui-resizable-e', s: '.ui-resizable-s', w: '.ui-resizable-w', se: '.ui-resizable-se', sw: '.ui-resizable-sw', ne: '.ui-resizable-ne', nw: '.ui-resizable-nw' });
  1823. if(this.handles.constructor == String) {
  1824. if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw';
  1825. var n = this.handles.split(","); this.handles = {};
  1826. for(var i = 0; i < n.length; i++) {
  1827. var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle;
  1828. var axis = $('<div class="ui-resizable-handle ' + hname + '"></div>');
  1829. // Apply zIndex to all handles - see #7960
  1830. axis.css({ zIndex: o.zIndex });
  1831. //TODO : What's going on here?
  1832. if ('se' == handle) {
  1833. axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se');
  1834. };
  1835. //Insert into internal handles object and append to element
  1836. this.handles[handle] = '.ui-resizable-'+handle;
  1837. this.element.append(axis);
  1838. }
  1839. }
  1840. this._renderAxis = function(target) {
  1841. target = target || this.element;
  1842. for(var i in this.handles) {
  1843. if(this.handles[i].constructor == String)
  1844. this.handles[i] = $(this.handles[i], this.element).show();
  1845. //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
  1846. if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
  1847. var axis = $(this.handles[i], this.element), padWrapper = 0;
  1848. //Checking the correct pad and border
  1849. padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
  1850. //The padding type i have to apply...
  1851. var padPos = [ 'padding',
  1852. /ne|nw|n/.test(i) ? 'Top' :
  1853. /se|sw|s/.test(i) ? 'Bottom' :
  1854. /^e$/.test(i) ? 'Right' : 'Left' ].join("");
  1855. target.css(padPos, padWrapper);
  1856. this._proportionallyResize();
  1857. }
  1858. //TODO: What's that good for? There's not anything to be executed left
  1859. if(!$(this.handles[i]).length)
  1860. continue;
  1861. }
  1862. };
  1863. //TODO: make renderAxis a prototype function
  1864. this._renderAxis(this.element);
  1865. this._handles = $('.ui-resizable-handle', this.element)
  1866. .disableSelection();
  1867. //Matching axis name
  1868. this._handles.mouseover(function() {
  1869. if (!that.resizing) {
  1870. if (this.className)
  1871. var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
  1872. //Axis, default = se
  1873. that.axis = axis && axis[1] ? axis[1] : 'se';
  1874. }
  1875. });
  1876. //If we want to auto hide the elements
  1877. if (o.autoHide) {
  1878. this._handles.hide();
  1879. $(this.element)
  1880. .addClass("ui-resizable-autohide")
  1881. .mouseenter(function() {
  1882. if (o.disabled) return;
  1883. $(this).removeClass("ui-resizable-autohide");
  1884. that._handles.show();
  1885. })
  1886. .mouseleave(function(){
  1887. if (o.disabled) return;
  1888. if (!that.resizing) {
  1889. $(this).addClass("ui-resizable-autohide");
  1890. that._handles.hide();
  1891. }
  1892. });
  1893. }
  1894. //Initialize the mouse interaction
  1895. this._mouseInit();
  1896. },
  1897. _destroy: function() {
  1898. this._mouseDestroy();
  1899. var _destroy = function(exp) {
  1900. $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
  1901. .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
  1902. };
  1903. //TODO: Unwrap at same DOM position
  1904. if (this.elementIsWrapper) {
  1905. _destroy(this.element);
  1906. var wrapper = this.element;
  1907. this.originalElement.css({
  1908. position: wrapper.css('position'),
  1909. width: wrapper.outerWidth(),
  1910. height: wrapper.outerHeight(),
  1911. top: wrapper.css('top'),
  1912. left: wrapper.css('left')
  1913. }).insertAfter( wrapper );
  1914. wrapper.remove();
  1915. }
  1916. this.originalElement.css('resize', this.originalResizeStyle);
  1917. _destroy(this.originalElement);
  1918. return this;
  1919. },
  1920. _mouseCapture: function(event) {
  1921. var handle = false;
  1922. for (var i in this.handles) {
  1923. if ($(this.handles[i])[0] == event.target) {
  1924. handle = true;
  1925. }
  1926. }
  1927. return !this.options.disabled && handle;
  1928. },
  1929. _mouseStart: function(event) {
  1930. var o = this.options, iniPos = this.element.position(), el = this.element;
  1931. this.resizing = true;
  1932. this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() };
  1933. // bugfix for http://dev.jquery.com/ticket/1749
  1934. if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) {
  1935. el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left });
  1936. }
  1937. this._renderProxy();
  1938. var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top'));
  1939. if (o.containment) {
  1940. curleft += $(o.containment).scrollLeft() || 0;
  1941. curtop += $(o.containment).scrollTop() || 0;
  1942. }
  1943. //Store needed variables
  1944. this.offset = this.helper.offset();
  1945. this.position = { left: curleft, top: curtop };
  1946. this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  1947. this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  1948. this.originalPosition = { left: curleft, top: curtop };
  1949. this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
  1950. this.originalMousePosition = { left: event.pageX, top: event.pageY };
  1951. //Aspect Ratio
  1952. this.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
  1953. var cursor = $('.ui-resizable-' + this.axis).css('cursor');
  1954. $('body').css('cursor', cursor == 'auto' ? this.axis + '-resize' : cursor);
  1955. el.addClass("ui-resizable-resizing");
  1956. this._propagate("start", event);
  1957. return true;
  1958. },
  1959. _mouseDrag: function(event) {
  1960. //Increase performance, avoid regex
  1961. var el = this.helper, o = this.options, props = {},
  1962. that = this, smp = this.originalMousePosition, a = this.axis;
  1963. var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0;
  1964. var trigger = this._change[a];
  1965. if (!trigger) return false;
  1966. // Calculate the attrs that will be change
  1967. var data = trigger.apply(this, [event, dx, dy]);
  1968. // Put this in the mouseDrag handler since the user can start pressing shift while resizing
  1969. this._updateVirtualBoundaries(event.shiftKey);
  1970. if (this._aspectRatio || event.shiftKey)
  1971. data = this._updateRatio(data, event);
  1972. data = this._respectSize(data, event);
  1973. // plugins callbacks need to be called first
  1974. this._propagate("resize", event);
  1975. el.css({
  1976. top: this.position.top + "px", left: this.position.left + "px",
  1977. width: this.size.width + "px", height: this.size.height + "px"
  1978. });
  1979. if (!this._helper && this._proportionallyResizeElements.length)
  1980. this._proportionallyResize();
  1981. this._updateCache(data);
  1982. // calling the user callback at the end
  1983. this._trigger('resize', event, this.ui());
  1984. return false;
  1985. },
  1986. _mouseStop: function(event) {
  1987. this.resizing = false;
  1988. var o = this.options, that = this;
  1989. if(this._helper) {
  1990. var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  1991. soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
  1992. soffsetw = ista ? 0 : that.sizeDiff.width;
  1993. var s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) },
  1994. left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
  1995. top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;
  1996. if (!o.animate)
  1997. this.element.css($.extend(s, { top: top, left: left }));
  1998. that.helper.height(that.size.height);
  1999. that.helper.width(that.size.width);
  2000. if (this._helper && !o.animate) this._proportionallyResize();
  2001. }
  2002. $('body').css('cursor', 'auto');
  2003. this.element.removeClass("ui-resizable-resizing");
  2004. this._propagate("stop", event);
  2005. if (this._helper) this.helper.remove();
  2006. return false;
  2007. },
  2008. _updateVirtualBoundaries: function(forceAspectRatio) {
  2009. var o = this.options, pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b;
  2010. b = {
  2011. minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
  2012. maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity,
  2013. minHeight: isNumber(o.minHeight) ? o.minHeight : 0,
  2014. maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity
  2015. };
  2016. if(this._aspectRatio || forceAspectRatio) {
  2017. // We want to create an enclosing box whose aspect ration is the requested one
  2018. // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
  2019. pMinWidth = b.minHeight * this.aspectRatio;
  2020. pMinHeight = b.minWidth / this.aspectRatio;
  2021. pMaxWidth = b.maxHeight * this.aspectRatio;
  2022. pMaxHeight = b.maxWidth / this.aspectRatio;
  2023. if(pMinWidth > b.minWidth) b.minWidth = pMinWidth;
  2024. if(pMinHeight > b.minHeight) b.minHeight = pMinHeight;
  2025. if(pMaxWidth < b.maxWidth) b.maxWidth = pMaxWidth;
  2026. if(pMaxHeight < b.maxHeight) b.maxHeight = pMaxHeight;
  2027. }
  2028. this._vBoundaries = b;
  2029. },
  2030. _updateCache: function(data) {
  2031. var o = this.options;
  2032. this.offset = this.helper.offset();
  2033. if (isNumber(data.left)) this.position.left = data.left;
  2034. if (isNumber(data.top)) this.position.top = data.top;
  2035. if (isNumber(data.height)) this.size.height = data.height;
  2036. if (isNumber(data.width)) this.size.width = data.width;
  2037. },
  2038. _updateRatio: function(data, event) {
  2039. var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
  2040. if (isNumber(data.height)) data.width = (data.height * this.aspectRatio);
  2041. else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio);
  2042. if (a == 'sw') {
  2043. data.left = cpos.left + (csize.width - data.width);
  2044. data.top = null;
  2045. }
  2046. if (a == 'nw') {
  2047. data.top = cpos.top + (csize.height - data.height);
  2048. data.left = cpos.left + (csize.width - data.width);
  2049. }
  2050. return data;
  2051. },
  2052. _respectSize: function(data, event) {
  2053. var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis,
  2054. ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
  2055. isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
  2056. if (isminw) data.width = o.minWidth;
  2057. if (isminh) data.height = o.minHeight;
  2058. if (ismaxw) data.width = o.maxWidth;
  2059. if (ismaxh) data.height = o.maxHeight;
  2060. var dw = this.originalPosition.left + this.originalSize.width, dh = this.position.top + this.size.height;
  2061. var cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
  2062. if (isminw && cw) data.left = dw - o.minWidth;
  2063. if (ismaxw && cw) data.left = dw - o.maxWidth;
  2064. if (isminh && ch) data.top = dh - o.minHeight;
  2065. if (ismaxh && ch) data.top = dh - o.maxHeight;
  2066. // fixing jump error on top/left - bug #2330
  2067. var isNotwh = !data.width && !data.height;
  2068. if (isNotwh && !data.left && data.top) data.top = null;
  2069. else if (isNotwh && !data.top && data.left) data.left = null;
  2070. return data;
  2071. },
  2072. _proportionallyResize: function() {
  2073. var o = this.options;
  2074. if (!this._proportionallyResizeElements.length) return;
  2075. var element = this.helper || this.element;
  2076. for (var i=0; i < this._proportionallyResizeElements.length; i++) {
  2077. var prel = this._proportionallyResizeElements[i];
  2078. if (!this.borderDif) {
  2079. var b = [prel.css('borderTopWidth'), prel.css('borderRightWidth'), prel.css('borderBottomWidth'), prel.css('borderLeftWidth')],
  2080. p = [prel.css('paddingTop'), prel.css('paddingRight'), prel.css('paddingBottom'), prel.css('paddingLeft')];
  2081. this.borderDif = $.map(b, function(v, i) {
  2082. var border = parseInt(v,10)||0, padding = parseInt(p[i],10)||0;
  2083. return border + padding;
  2084. });
  2085. }
  2086. prel.css({
  2087. height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0,
  2088. width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
  2089. });
  2090. };
  2091. },
  2092. _renderProxy: function() {
  2093. var el = this.element, o = this.options;
  2094. this.elementOffset = el.offset();
  2095. if(this._helper) {
  2096. this.helper = this.helper || $('<div style="overflow:hidden;"></div>');
  2097. // fix ie6 offset TODO: This seems broken
  2098. var ie6offset = ($.ui.ie6 ? 1 : 0),
  2099. pxyoffset = ( $.ui.ie6 ? 2 : -1 );
  2100. this.helper.addClass(this._helper).css({
  2101. width: this.element.outerWidth() + pxyoffset,
  2102. height: this.element.outerHeight() + pxyoffset,
  2103. position: 'absolute',
  2104. left: this.elementOffset.left - ie6offset +'px',
  2105. top: this.elementOffset.top - ie6offset +'px',
  2106. zIndex: ++o.zIndex //TODO: Don't modify option
  2107. });
  2108. this.helper
  2109. .appendTo("body")
  2110. .disableSelection();
  2111. } else {
  2112. this.helper = this.element;
  2113. }
  2114. },
  2115. _change: {
  2116. e: function(event, dx, dy) {
  2117. return { width: this.originalSize.width + dx };
  2118. },
  2119. w: function(event, dx, dy) {
  2120. var o = this.options, cs = this.originalSize, sp = this.originalPosition;
  2121. return { left: sp.left + dx, width: cs.width - dx };
  2122. },
  2123. n: function(event, dx, dy) {
  2124. var o = this.options, cs = this.originalSize, sp = this.originalPosition;
  2125. return { top: sp.top + dy, height: cs.height - dy };
  2126. },
  2127. s: function(event, dx, dy) {
  2128. return { height: this.originalSize.height + dy };
  2129. },
  2130. se: function(event, dx, dy) {
  2131. return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  2132. },
  2133. sw: function(event, dx, dy) {
  2134. return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  2135. },
  2136. ne: function(event, dx, dy) {
  2137. return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  2138. },
  2139. nw: function(event, dx, dy) {
  2140. return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  2141. }
  2142. },
  2143. _propagate: function(n, event) {
  2144. $.ui.plugin.call(this, n, [event, this.ui()]);
  2145. (n != "resize" && this._trigger(n, event, this.ui()));
  2146. },
  2147. plugins: {},
  2148. ui: function() {
  2149. return {
  2150. originalElement: this.originalElement,
  2151. element: this.element,
  2152. helper: this.helper,
  2153. position: this.position,
  2154. size: this.size,
  2155. originalSize: this.originalSize,
  2156. originalPosition: this.originalPosition
  2157. };
  2158. }
  2159. });
  2160. /*
  2161. * Resizable Extensions
  2162. */
  2163. $.ui.plugin.add("resizable", "alsoResize", {
  2164. start: function (event, ui) {
  2165. var that = $(this).data("resizable"), o = that.options;
  2166. var _store = function (exp) {
  2167. $(exp).each(function() {
  2168. var el = $(this);
  2169. el.data("resizable-alsoresize", {
  2170. width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
  2171. left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10)
  2172. });
  2173. });
  2174. };
  2175. if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) {
  2176. if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
  2177. else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
  2178. }else{
  2179. _store(o.alsoResize);
  2180. }
  2181. },
  2182. resize: function (event, ui) {
  2183. var that = $(this).data("resizable"), o = that.options, os = that.originalSize, op = that.originalPosition;
  2184. var delta = {
  2185. height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
  2186. top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
  2187. },
  2188. _alsoResize = function (exp, c) {
  2189. $(exp).each(function() {
  2190. var el = $(this), start = $(this).data("resizable-alsoresize"), style = {},
  2191. css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left'];
  2192. $.each(css, function (i, prop) {
  2193. var sum = (start[prop]||0) + (delta[prop]||0);
  2194. if (sum && sum >= 0)
  2195. style[prop] = sum || null;
  2196. });
  2197. el.css(style);
  2198. });
  2199. };
  2200. if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) {
  2201. $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
  2202. }else{
  2203. _alsoResize(o.alsoResize);
  2204. }
  2205. },
  2206. stop: function (event, ui) {
  2207. $(this).removeData("resizable-alsoresize");
  2208. }
  2209. });
  2210. $.ui.plugin.add("resizable", "animate", {
  2211. stop: function(event, ui) {
  2212. var that = $(this).data("resizable"), o = that.options;
  2213. var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  2214. soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
  2215. soffsetw = ista ? 0 : that.sizeDiff.width;
  2216. var style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
  2217. left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
  2218. top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;
  2219. that.element.animate(
  2220. $.extend(style, top && left ? { top: top, left: left } : {}), {
  2221. duration: o.animateDuration,
  2222. easing: o.animateEasing,
  2223. step: function() {
  2224. var data = {
  2225. width: parseInt(that.element.css('width'), 10),
  2226. height: parseInt(that.element.css('height'), 10),
  2227. top: parseInt(that.element.css('top'), 10),
  2228. left: parseInt(that.element.css('left'), 10)
  2229. };
  2230. if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height });
  2231. // propagating resize, and updating values for each animation step
  2232. that._updateCache(data);
  2233. that._propagate("resize", event);
  2234. }
  2235. }
  2236. );
  2237. }
  2238. });
  2239. $.ui.plugin.add("resizable", "containment", {
  2240. start: function(event, ui) {
  2241. var that = $(this).data("resizable"), o = that.options, el = that.element;
  2242. var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
  2243. if (!ce) return;
  2244. that.containerElement = $(ce);
  2245. if (/document/.test(oc) || oc == document) {
  2246. that.containerOffset = { left: 0, top: 0 };
  2247. that.containerPosition = { left: 0, top: 0 };
  2248. that.parentData = {
  2249. element: $(document), left: 0, top: 0,
  2250. width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
  2251. };
  2252. }
  2253. // i'm a node, so compute top, left, right, bottom
  2254. else {
  2255. var element = $(ce), p = [];
  2256. $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
  2257. that.containerOffset = element.offset();
  2258. that.containerPosition = element.position();
  2259. that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
  2260. var co = that.containerOffset, ch = that.containerSize.height, cw = that.containerSize.width,
  2261. width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
  2262. that.parentData = {
  2263. element: ce, left: co.left, top: co.top, width: width, height: height
  2264. };
  2265. }
  2266. },
  2267. resize: function(event, ui) {
  2268. var that = $(this).data("resizable"), o = that.options,
  2269. ps = that.containerSize, co = that.containerOffset, cs = that.size, cp = that.position,
  2270. pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement;
  2271. if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co;
  2272. if (cp.left < (that._helper ? co.left : 0)) {
  2273. that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left));
  2274. if (pRatio) that.size.height = that.size.width / that.aspectRatio;
  2275. that.position.left = o.helper ? co.left : 0;
  2276. }
  2277. if (cp.top < (that._helper ? co.top : 0)) {
  2278. that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top);
  2279. if (pRatio) that.size.width = that.size.height * that.aspectRatio;
  2280. that.position.top = that._helper ? co.top : 0;
  2281. }
  2282. that.offset.left = that.parentData.left+that.position.left;
  2283. that.offset.top = that.parentData.top+that.position.top;
  2284. var woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width ),
  2285. hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
  2286. var isParent = that.containerElement.get(0) == that.element.parent().get(0),
  2287. isOffsetRelative = /relative|absolute/.test(that.containerElement.css('position'));
  2288. if(isParent && isOffsetRelative) woset -= that.parentData.left;
  2289. if (woset + that.size.width >= that.parentData.width) {
  2290. that.size.width = that.parentData.width - woset;
  2291. if (pRatio) that.size.height = that.size.width / that.aspectRatio;
  2292. }
  2293. if (hoset + that.size.height >= that.parentData.height) {
  2294. that.size.height = that.parentData.height - hoset;
  2295. if (pRatio) that.size.width = that.size.height * that.aspectRatio;
  2296. }
  2297. },
  2298. stop: function(event, ui){
  2299. var that = $(this).data("resizable"), o = that.options, cp = that.position,
  2300. co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement;
  2301. var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height;
  2302. if (that._helper && !o.animate && (/relative/).test(ce.css('position')))
  2303. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  2304. if (that._helper && !o.animate && (/static/).test(ce.css('position')))
  2305. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  2306. }
  2307. });
  2308. $.ui.plugin.add("resizable", "ghost", {
  2309. start: function(event, ui) {
  2310. var that = $(this).data("resizable"), o = that.options, cs = that.size;
  2311. that.ghost = that.originalElement.clone();
  2312. that.ghost
  2313. .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
  2314. .addClass('ui-resizable-ghost')
  2315. .addClass(typeof o.ghost == 'string' ? o.ghost : '');
  2316. that.ghost.appendTo(that.helper);
  2317. },
  2318. resize: function(event, ui){
  2319. var that = $(this).data("resizable"), o = that.options;
  2320. if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width });
  2321. },
  2322. stop: function(event, ui){
  2323. var that = $(this).data("resizable"), o = that.options;
  2324. if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0));
  2325. }
  2326. });
  2327. $.ui.plugin.add("resizable", "grid", {
  2328. resize: function(event, ui) {
  2329. var that = $(this).data("resizable"), o = that.options, cs = that.size, os = that.originalSize, op = that.originalPosition, a = that.axis, ratio = o._aspectRatio || event.shiftKey;
  2330. o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid;
  2331. var ox = Math.round((cs.width - os.width) / (o.grid[0]||1)) * (o.grid[0]||1), oy = Math.round((cs.height - os.height) / (o.grid[1]||1)) * (o.grid[1]||1);
  2332. if (/^(se|s|e)$/.test(a)) {
  2333. that.size.width = os.width + ox;
  2334. that.size.height = os.height + oy;
  2335. }
  2336. else if (/^(ne)$/.test(a)) {
  2337. that.size.width = os.width + ox;
  2338. that.size.height = os.height + oy;
  2339. that.position.top = op.top - oy;
  2340. }
  2341. else if (/^(sw)$/.test(a)) {
  2342. that.size.width = os.width + ox;
  2343. that.size.height = os.height + oy;
  2344. that.position.left = op.left - ox;
  2345. }
  2346. else {
  2347. that.size.width = os.width + ox;
  2348. that.size.height = os.height + oy;
  2349. that.position.top = op.top - oy;
  2350. that.position.left = op.left - ox;
  2351. }
  2352. }
  2353. });
  2354. var num = function(v) {
  2355. return parseInt(v, 10) || 0;
  2356. };
  2357. var isNumber = function(value) {
  2358. return !isNaN(parseInt(value, 10));
  2359. };
  2360. })(jQuery);
  2361. (function( $, undefined ) {
  2362. $.widget("ui.selectable", $.ui.mouse, {
  2363. version: "1.9.2",
  2364. options: {
  2365. appendTo: 'body',
  2366. autoRefresh: true,
  2367. distance: 0,
  2368. filter: '*',
  2369. tolerance: 'touch'
  2370. },
  2371. _create: function() {
  2372. var that = this;
  2373. this.element.addClass("ui-selectable");
  2374. this.dragged = false;
  2375. // cache selectee children based on filter
  2376. var selectees;
  2377. this.refresh = function() {
  2378. selectees = $(that.options.filter, that.element[0]);
  2379. selectees.addClass("ui-selectee");
  2380. selectees.each(function() {
  2381. var $this = $(this);
  2382. var pos = $this.offset();
  2383. $.data(this, "selectable-item", {
  2384. element: this,
  2385. $element: $this,
  2386. left: pos.left,
  2387. top: pos.top,
  2388. right: pos.left + $this.outerWidth(),
  2389. bottom: pos.top + $this.outerHeight(),
  2390. startselected: false,
  2391. selected: $this.hasClass('ui-selected'),
  2392. selecting: $this.hasClass('ui-selecting'),
  2393. unselecting: $this.hasClass('ui-unselecting')
  2394. });
  2395. });
  2396. };
  2397. this.refresh();
  2398. this.selectees = selectees.addClass("ui-selectee");
  2399. this._mouseInit();
  2400. this.helper = $("<div class='ui-selectable-helper'></div>");
  2401. },
  2402. _destroy: function() {
  2403. this.selectees
  2404. .removeClass("ui-selectee")
  2405. .removeData("selectable-item");
  2406. this.element
  2407. .removeClass("ui-selectable ui-selectable-disabled");
  2408. this._mouseDestroy();
  2409. },
  2410. _mouseStart: function(event) {
  2411. var that = this;
  2412. this.opos = [event.pageX, event.pageY];
  2413. if (this.options.disabled)
  2414. return;
  2415. var options = this.options;
  2416. this.selectees = $(options.filter, this.element[0]);
  2417. this._trigger("start", event);
  2418. $(options.appendTo).append(this.helper);
  2419. // position helper (lasso)
  2420. this.helper.css({
  2421. "left": event.clientX,
  2422. "top": event.clientY,
  2423. "width": 0,
  2424. "height": 0
  2425. });
  2426. if (options.autoRefresh) {
  2427. this.refresh();
  2428. }
  2429. this.selectees.filter('.ui-selected').each(function() {
  2430. var selectee = $.data(this, "selectable-item");
  2431. selectee.startselected = true;
  2432. if (!event.metaKey && !event.ctrlKey) {
  2433. selectee.$element.removeClass('ui-selected');
  2434. selectee.selected = false;
  2435. selectee.$element.addClass('ui-unselecting');
  2436. selectee.unselecting = true;
  2437. // selectable UNSELECTING callback
  2438. that._trigger("unselecting", event, {
  2439. unselecting: selectee.element
  2440. });
  2441. }
  2442. });
  2443. $(event.target).parents().andSelf().each(function() {
  2444. var selectee = $.data(this, "selectable-item");
  2445. if (selectee) {
  2446. var doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected');
  2447. selectee.$element
  2448. .removeClass(doSelect ? "ui-unselecting" : "ui-selected")
  2449. .addClass(doSelect ? "ui-selecting" : "ui-unselecting");
  2450. selectee.unselecting = !doSelect;
  2451. selectee.selecting = doSelect;
  2452. selectee.selected = doSelect;
  2453. // selectable (UN)SELECTING callback
  2454. if (doSelect) {
  2455. that._trigger("selecting", event, {
  2456. selecting: selectee.element
  2457. });
  2458. } else {
  2459. that._trigger("unselecting", event, {
  2460. unselecting: selectee.element
  2461. });
  2462. }
  2463. return false;
  2464. }
  2465. });
  2466. },
  2467. _mouseDrag: function(event) {
  2468. var that = this;
  2469. this.dragged = true;
  2470. if (this.options.disabled)
  2471. return;
  2472. var options = this.options;
  2473. var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY;
  2474. if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
  2475. if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
  2476. this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
  2477. this.selectees.each(function() {
  2478. var selectee = $.data(this, "selectable-item");
  2479. //prevent helper from being selected if appendTo: selectable
  2480. if (!selectee || selectee.element == that.element[0])
  2481. return;
  2482. var hit = false;
  2483. if (options.tolerance == 'touch') {
  2484. hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
  2485. } else if (options.tolerance == 'fit') {
  2486. hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
  2487. }
  2488. if (hit) {
  2489. // SELECT
  2490. if (selectee.selected) {
  2491. selectee.$element.removeClass('ui-selected');
  2492. selectee.selected = false;
  2493. }
  2494. if (selectee.unselecting) {
  2495. selectee.$element.removeClass('ui-unselecting');
  2496. selectee.unselecting = false;
  2497. }
  2498. if (!selectee.selecting) {
  2499. selectee.$element.addClass('ui-selecting');
  2500. selectee.selecting = true;
  2501. // selectable SELECTING callback
  2502. that._trigger("selecting", event, {
  2503. selecting: selectee.element
  2504. });
  2505. }
  2506. } else {
  2507. // UNSELECT
  2508. if (selectee.selecting) {
  2509. if ((event.metaKey || event.ctrlKey) && selectee.startselected) {
  2510. selectee.$element.removeClass('ui-selecting');
  2511. selectee.selecting = false;
  2512. selectee.$element.addClass('ui-selected');
  2513. selectee.selected = true;
  2514. } else {
  2515. selectee.$element.removeClass('ui-selecting');
  2516. selectee.selecting = false;
  2517. if (selectee.startselected) {
  2518. selectee.$element.addClass('ui-unselecting');
  2519. selectee.unselecting = true;
  2520. }
  2521. // selectable UNSELECTING callback
  2522. that._trigger("unselecting", event, {
  2523. unselecting: selectee.element
  2524. });
  2525. }
  2526. }
  2527. if (selectee.selected) {
  2528. if (!event.metaKey && !event.ctrlKey && !selectee.startselected) {
  2529. selectee.$element.removeClass('ui-selected');
  2530. selectee.selected = false;
  2531. selectee.$element.addClass('ui-unselecting');
  2532. selectee.unselecting = true;
  2533. // selectable UNSELECTING callback
  2534. that._trigger("unselecting", event, {
  2535. unselecting: selectee.element
  2536. });
  2537. }
  2538. }
  2539. }
  2540. });
  2541. return false;
  2542. },
  2543. _mouseStop: function(event) {
  2544. var that = this;
  2545. this.dragged = false;
  2546. var options = this.options;
  2547. $('.ui-unselecting', this.element[0]).each(function() {
  2548. var selectee = $.data(this, "selectable-item");
  2549. selectee.$element.removeClass('ui-unselecting');
  2550. selectee.unselecting = false;
  2551. selectee.startselected = false;
  2552. that._trigger("unselected", event, {
  2553. unselected: selectee.element
  2554. });
  2555. });
  2556. $('.ui-selecting', this.element[0]).each(function() {
  2557. var selectee = $.data(this, "selectable-item");
  2558. selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
  2559. selectee.selecting = false;
  2560. selectee.selected = true;
  2561. selectee.startselected = true;
  2562. that._trigger("selected", event, {
  2563. selected: selectee.element
  2564. });
  2565. });
  2566. this._trigger("stop", event);
  2567. this.helper.remove();
  2568. return false;
  2569. }
  2570. });
  2571. })(jQuery);
  2572. (function( $, undefined ) {
  2573. $.widget("ui.sortable", $.ui.mouse, {
  2574. version: "1.9.2",
  2575. widgetEventPrefix: "sort",
  2576. ready: false,
  2577. options: {
  2578. appendTo: "parent",
  2579. axis: false,
  2580. connectWith: false,
  2581. containment: false,
  2582. cursor: 'auto',
  2583. cursorAt: false,
  2584. dropOnEmpty: true,
  2585. forcePlaceholderSize: false,
  2586. forceHelperSize: false,
  2587. grid: false,
  2588. handle: false,
  2589. helper: "original",
  2590. items: '> *',
  2591. opacity: false,
  2592. placeholder: false,
  2593. revert: false,
  2594. scroll: true,
  2595. scrollSensitivity: 20,
  2596. scrollSpeed: 20,
  2597. scope: "default",
  2598. tolerance: "intersect",
  2599. zIndex: 1000
  2600. },
  2601. _create: function() {
  2602. var o = this.options;
  2603. this.containerCache = {};
  2604. this.element.addClass("ui-sortable");
  2605. //Get the items
  2606. this.refresh();
  2607. //Let's determine if the items are being displayed horizontally
  2608. this.floating = this.items.length ? o.axis === 'x' || (/left|right/).test(this.items[0].item.css('float')) || (/inline|table-cell/).test(this.items[0].item.css('display')) : false;
  2609. //Let's determine the parent's offset
  2610. this.offset = this.element.offset();
  2611. //Initialize mouse events for interaction
  2612. this._mouseInit();
  2613. //We're ready to go
  2614. this.ready = true
  2615. },
  2616. _destroy: function() {
  2617. this.element
  2618. .removeClass("ui-sortable ui-sortable-disabled");
  2619. this._mouseDestroy();
  2620. for ( var i = this.items.length - 1; i >= 0; i-- )
  2621. this.items[i].item.removeData(this.widgetName + "-item");
  2622. return this;
  2623. },
  2624. _setOption: function(key, value){
  2625. if ( key === "disabled" ) {
  2626. this.options[ key ] = value;
  2627. this.widget().toggleClass( "ui-sortable-disabled", !!value );
  2628. } else {
  2629. // Don't call widget base _setOption for disable as it adds ui-state-disabled class
  2630. $.Widget.prototype._setOption.apply(this, arguments);
  2631. }
  2632. },
  2633. _mouseCapture: function(event, overrideHandle) {
  2634. var that = this;
  2635. if (this.reverting) {
  2636. return false;
  2637. }
  2638. if(this.options.disabled || this.options.type == 'static') return false;
  2639. //We have to refresh the items data once first
  2640. this._refreshItems(event);
  2641. //Find out if the clicked node (or one of its parents) is a actual item in this.items
  2642. var currentItem = null, nodes = $(event.target).parents().each(function() {
  2643. if($.data(this, that.widgetName + '-item') == that) {
  2644. currentItem = $(this);
  2645. return false;
  2646. }
  2647. });
  2648. if($.data(event.target, that.widgetName + '-item') == that) currentItem = $(event.target);
  2649. if(!currentItem) return false;
  2650. if(this.options.handle && !overrideHandle) {
  2651. var validHandle = false;
  2652. $(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == event.target) validHandle = true; });
  2653. if(!validHandle) return false;
  2654. }
  2655. this.currentItem = currentItem;
  2656. this._removeCurrentsFromItems();
  2657. return true;
  2658. },
  2659. _mouseStart: function(event, overrideHandle, noActivation) {
  2660. var o = this.options;
  2661. this.currentContainer = this;
  2662. //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
  2663. this.refreshPositions();
  2664. //Create and append the visible helper
  2665. this.helper = this._createHelper(event);
  2666. //Cache the helper size
  2667. this._cacheHelperProportions();
  2668. /*
  2669. * - Position generation -
  2670. * This block generates everything position related - it's the core of draggables.
  2671. */
  2672. //Cache the margins of the original element
  2673. this._cacheMargins();
  2674. //Get the next scrolling parent
  2675. this.scrollParent = this.helper.scrollParent();
  2676. //The element's absolute position on the page minus margins
  2677. this.offset = this.currentItem.offset();
  2678. this.offset = {
  2679. top: this.offset.top - this.margins.top,
  2680. left: this.offset.left - this.margins.left
  2681. };
  2682. $.extend(this.offset, {
  2683. click: { //Where the click happened, relative to the element
  2684. left: event.pageX - this.offset.left,
  2685. top: event.pageY - this.offset.top
  2686. },
  2687. parent: this._getParentOffset(),
  2688. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  2689. });
  2690. // Only after we got the offset, we can change the helper's position to absolute
  2691. // TODO: Still need to figure out a way to make relative sorting possible
  2692. this.helper.css("position", "absolute");
  2693. this.cssPosition = this.helper.css("position");
  2694. //Generate the original position
  2695. this.originalPosition = this._generatePosition(event);
  2696. this.originalPageX = event.pageX;
  2697. this.originalPageY = event.pageY;
  2698. //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
  2699. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  2700. //Cache the former DOM position
  2701. this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
  2702. //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
  2703. if(this.helper[0] != this.currentItem[0]) {
  2704. this.currentItem.hide();
  2705. }
  2706. //Create the placeholder
  2707. this._createPlaceholder();
  2708. //Set a containment if given in the options
  2709. if(o.containment)
  2710. this._setContainment();
  2711. if(o.cursor) { // cursor option
  2712. if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor");
  2713. $('body').css("cursor", o.cursor);
  2714. }
  2715. if(o.opacity) { // opacity option
  2716. if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity");
  2717. this.helper.css("opacity", o.opacity);
  2718. }
  2719. if(o.zIndex) { // zIndex option
  2720. if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex");
  2721. this.helper.css("zIndex", o.zIndex);
  2722. }
  2723. //Prepare scrolling
  2724. if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML')
  2725. this.overflowOffset = this.scrollParent.offset();
  2726. //Call callbacks
  2727. this._trigger("start", event, this._uiHash());
  2728. //Recache the helper size
  2729. if(!this._preserveHelperProportions)
  2730. this._cacheHelperProportions();
  2731. //Post 'activate' events to possible containers
  2732. if(!noActivation) {
  2733. for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); }
  2734. }
  2735. //Prepare possible droppables
  2736. if($.ui.ddmanager)
  2737. $.ui.ddmanager.current = this;
  2738. if ($.ui.ddmanager && !o.dropBehaviour)
  2739. $.ui.ddmanager.prepareOffsets(this, event);
  2740. this.dragging = true;
  2741. this.helper.addClass("ui-sortable-helper");
  2742. this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  2743. return true;
  2744. },
  2745. _mouseDrag: function(event) {
  2746. //Compute the helpers position
  2747. this.position = this._generatePosition(event);
  2748. this.positionAbs = this._convertPositionTo("absolute");
  2749. if (!this.lastPositionAbs) {
  2750. this.lastPositionAbs = this.positionAbs;
  2751. }
  2752. //Do scrolling
  2753. if(this.options.scroll) {
  2754. var o = this.options, scrolled = false;
  2755. if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
  2756. if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
  2757. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
  2758. else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity)
  2759. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
  2760. if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
  2761. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
  2762. else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity)
  2763. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
  2764. } else {
  2765. if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
  2766. scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
  2767. else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
  2768. scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
  2769. if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
  2770. scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
  2771. else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
  2772. scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
  2773. }
  2774. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
  2775. $.ui.ddmanager.prepareOffsets(this, event);
  2776. }
  2777. //Regenerate the absolute position used for position checks
  2778. this.positionAbs = this._convertPositionTo("absolute");
  2779. //Set the helper position
  2780. if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
  2781. if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
  2782. //Rearrange
  2783. for (var i = this.items.length - 1; i >= 0; i--) {
  2784. //Cache variables and intersection, continue if no intersection
  2785. var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
  2786. if (!intersection) continue;
  2787. // Only put the placeholder inside the current Container, skip all
  2788. // items form other containers. This works because when moving
  2789. // an item from one container to another the
  2790. // currentContainer is switched before the placeholder is moved.
  2791. //
  2792. // Without this moving items in "sub-sortables" can cause the placeholder to jitter
  2793. // beetween the outer and inner container.
  2794. if (item.instance !== this.currentContainer) continue;
  2795. if (itemElement != this.currentItem[0] //cannot intersect with itself
  2796. && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
  2797. && !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
  2798. && (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true)
  2799. //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
  2800. ) {
  2801. this.direction = intersection == 1 ? "down" : "up";
  2802. if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
  2803. this._rearrange(event, item);
  2804. } else {
  2805. break;
  2806. }
  2807. this._trigger("change", event, this._uiHash());
  2808. break;
  2809. }
  2810. }
  2811. //Post events to containers
  2812. this._contactContainers(event);
  2813. //Interconnect with droppables
  2814. if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
  2815. //Call callbacks
  2816. this._trigger('sort', event, this._uiHash());
  2817. this.lastPositionAbs = this.positionAbs;
  2818. return false;
  2819. },
  2820. _mouseStop: function(event, noPropagation) {
  2821. if(!event) return;
  2822. //If we are using droppables, inform the manager about the drop
  2823. if ($.ui.ddmanager && !this.options.dropBehaviour)
  2824. $.ui.ddmanager.drop(this, event);
  2825. if(this.options.revert) {
  2826. var that = this;
  2827. var cur = this.placeholder.offset();
  2828. this.reverting = true;
  2829. $(this.helper).animate({
  2830. left: cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft),
  2831. top: cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop)
  2832. }, parseInt(this.options.revert, 10) || 500, function() {
  2833. that._clear(event);
  2834. });
  2835. } else {
  2836. this._clear(event, noPropagation);
  2837. }
  2838. return false;
  2839. },
  2840. cancel: function() {
  2841. if(this.dragging) {
  2842. this._mouseUp({ target: null });
  2843. if(this.options.helper == "original")
  2844. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  2845. else
  2846. this.currentItem.show();
  2847. //Post deactivating events to containers
  2848. for (var i = this.containers.length - 1; i >= 0; i--){
  2849. this.containers[i]._trigger("deactivate", null, this._uiHash(this));
  2850. if(this.containers[i].containerCache.over) {
  2851. this.containers[i]._trigger("out", null, this._uiHash(this));
  2852. this.containers[i].containerCache.over = 0;
  2853. }
  2854. }
  2855. }
  2856. if (this.placeholder) {
  2857. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  2858. if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  2859. if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove();
  2860. $.extend(this, {
  2861. helper: null,
  2862. dragging: false,
  2863. reverting: false,
  2864. _noFinalSort: null
  2865. });
  2866. if(this.domPosition.prev) {
  2867. $(this.domPosition.prev).after(this.currentItem);
  2868. } else {
  2869. $(this.domPosition.parent).prepend(this.currentItem);
  2870. }
  2871. }
  2872. return this;
  2873. },
  2874. serialize: function(o) {
  2875. var items = this._getItemsAsjQuery(o && o.connected);
  2876. var str = []; o = o || {};
  2877. $(items).each(function() {
  2878. var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
  2879. if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2]));
  2880. });
  2881. if(!str.length && o.key) {
  2882. str.push(o.key + '=');
  2883. }
  2884. return str.join('&');
  2885. },
  2886. toArray: function(o) {
  2887. var items = this._getItemsAsjQuery(o && o.connected);
  2888. var ret = []; o = o || {};
  2889. items.each(function() { ret.push($(o.item || this).attr(o.attribute || 'id') || ''); });
  2890. return ret;
  2891. },
  2892. /* Be careful with the following core functions */
  2893. _intersectsWith: function(item) {
  2894. var x1 = this.positionAbs.left,
  2895. x2 = x1 + this.helperProportions.width,
  2896. y1 = this.positionAbs.top,
  2897. y2 = y1 + this.helperProportions.height;
  2898. var l = item.left,
  2899. r = l + item.width,
  2900. t = item.top,
  2901. b = t + item.height;
  2902. var dyClick = this.offset.click.top,
  2903. dxClick = this.offset.click.left;
  2904. var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
  2905. if( this.options.tolerance == "pointer"
  2906. || this.options.forcePointerForContainers
  2907. || (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])
  2908. ) {
  2909. return isOverElement;
  2910. } else {
  2911. return (l < x1 + (this.helperProportions.width / 2) // Right Half
  2912. && x2 - (this.helperProportions.width / 2) < r // Left Half
  2913. && t < y1 + (this.helperProportions.height / 2) // Bottom Half
  2914. && y2 - (this.helperProportions.height / 2) < b ); // Top Half
  2915. }
  2916. },
  2917. _intersectsWithPointer: function(item) {
  2918. var isOverElementHeight = (this.options.axis === 'x') || $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
  2919. isOverElementWidth = (this.options.axis === 'y') || $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
  2920. isOverElement = isOverElementHeight && isOverElementWidth,
  2921. verticalDirection = this._getDragVerticalDirection(),
  2922. horizontalDirection = this._getDragHorizontalDirection();
  2923. if (!isOverElement)
  2924. return false;
  2925. return this.floating ?
  2926. ( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 )
  2927. : ( verticalDirection && (verticalDirection == "down" ? 2 : 1) );
  2928. },
  2929. _intersectsWithSides: function(item) {
  2930. var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
  2931. isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
  2932. verticalDirection = this._getDragVerticalDirection(),
  2933. horizontalDirection = this._getDragHorizontalDirection();
  2934. if (this.floating && horizontalDirection) {
  2935. return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
  2936. } else {
  2937. return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf));
  2938. }
  2939. },
  2940. _getDragVerticalDirection: function() {
  2941. var delta = this.positionAbs.top - this.lastPositionAbs.top;
  2942. return delta != 0 && (delta > 0 ? "down" : "up");
  2943. },
  2944. _getDragHorizontalDirection: function() {
  2945. var delta = this.positionAbs.left - this.lastPositionAbs.left;
  2946. return delta != 0 && (delta > 0 ? "right" : "left");
  2947. },
  2948. refresh: function(event) {
  2949. this._refreshItems(event);
  2950. this.refreshPositions();
  2951. return this;
  2952. },
  2953. _connectWith: function() {
  2954. var options = this.options;
  2955. return options.connectWith.constructor == String
  2956. ? [options.connectWith]
  2957. : options.connectWith;
  2958. },
  2959. _getItemsAsjQuery: function(connected) {
  2960. var items = [];
  2961. var queries = [];
  2962. var connectWith = this._connectWith();
  2963. if(connectWith && connected) {
  2964. for (var i = connectWith.length - 1; i >= 0; i--){
  2965. var cur = $(connectWith[i]);
  2966. for (var j = cur.length - 1; j >= 0; j--){
  2967. var inst = $.data(cur[j], this.widgetName);
  2968. if(inst && inst != this && !inst.options.disabled) {
  2969. 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]);
  2970. }
  2971. };
  2972. };
  2973. }
  2974. 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]);
  2975. for (var i = queries.length - 1; i >= 0; i--){
  2976. queries[i][0].each(function() {
  2977. items.push(this);
  2978. });
  2979. };
  2980. return $(items);
  2981. },
  2982. _removeCurrentsFromItems: function() {
  2983. var list = this.currentItem.find(":data(" + this.widgetName + "-item)");
  2984. this.items = $.grep(this.items, function (item) {
  2985. for (var j=0; j < list.length; j++) {
  2986. if(list[j] == item.item[0])
  2987. return false;
  2988. };
  2989. return true;
  2990. });
  2991. },
  2992. _refreshItems: function(event) {
  2993. this.items = [];
  2994. this.containers = [this];
  2995. var items = this.items;
  2996. var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]];
  2997. var connectWith = this._connectWith();
  2998. if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
  2999. for (var i = connectWith.length - 1; i >= 0; i--){
  3000. var cur = $(connectWith[i]);
  3001. for (var j = cur.length - 1; j >= 0; j--){
  3002. var inst = $.data(cur[j], this.widgetName);
  3003. if(inst && inst != this && !inst.options.disabled) {
  3004. queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
  3005. this.containers.push(inst);
  3006. }
  3007. };
  3008. };
  3009. }
  3010. for (var i = queries.length - 1; i >= 0; i--) {
  3011. var targetData = queries[i][1];
  3012. var _queries = queries[i][0];
  3013. for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) {
  3014. var item = $(_queries[j]);
  3015. item.data(this.widgetName + '-item', targetData); // Data for target checking (mouse manager)
  3016. items.push({
  3017. item: item,
  3018. instance: targetData,
  3019. width: 0, height: 0,
  3020. left: 0, top: 0
  3021. });
  3022. };
  3023. };
  3024. },
  3025. refreshPositions: function(fast) {
  3026. //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
  3027. if(this.offsetParent && this.helper) {
  3028. this.offset.parent = this._getParentOffset();
  3029. }
  3030. for (var i = this.items.length - 1; i >= 0; i--){
  3031. var item = this.items[i];
  3032. //We ignore calculating positions of all connected containers when we're not over them
  3033. if(item.instance != this.currentContainer && this.currentContainer && item.item[0] != this.currentItem[0])
  3034. continue;
  3035. var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
  3036. if (!fast) {
  3037. item.width = t.outerWidth();
  3038. item.height = t.outerHeight();
  3039. }
  3040. var p = t.offset();
  3041. item.left = p.left;
  3042. item.top = p.top;
  3043. };
  3044. if(this.options.custom && this.options.custom.refreshContainers) {
  3045. this.options.custom.refreshContainers.call(this);
  3046. } else {
  3047. for (var i = this.containers.length - 1; i >= 0; i--){
  3048. var p = this.containers[i].element.offset();
  3049. this.containers[i].containerCache.left = p.left;
  3050. this.containers[i].containerCache.top = p.top;
  3051. this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
  3052. this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
  3053. };
  3054. }
  3055. return this;
  3056. },
  3057. _createPlaceholder: function(that) {
  3058. that = that || this;
  3059. var o = that.options;
  3060. if(!o.placeholder || o.placeholder.constructor == String) {
  3061. var className = o.placeholder;
  3062. o.placeholder = {
  3063. element: function() {
  3064. var el = $(document.createElement(that.currentItem[0].nodeName))
  3065. .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
  3066. .removeClass("ui-sortable-helper")[0];
  3067. if(!className)
  3068. el.style.visibility = "hidden";
  3069. return el;
  3070. },
  3071. update: function(container, p) {
  3072. // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that
  3073. // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified
  3074. if(className && !o.forcePlaceholderSize) return;
  3075. //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
  3076. if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css('paddingTop')||0, 10) - parseInt(that.currentItem.css('paddingBottom')||0, 10)); };
  3077. if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); };
  3078. }
  3079. };
  3080. }
  3081. //Create the placeholder
  3082. that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));
  3083. //Append it after the actual current item
  3084. that.currentItem.after(that.placeholder);
  3085. //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
  3086. o.placeholder.update(that, that.placeholder);
  3087. },
  3088. _contactContainers: function(event) {
  3089. // get innermost container that intersects with item
  3090. var innermostContainer = null, innermostIndex = null;
  3091. for (var i = this.containers.length - 1; i >= 0; i--){
  3092. // never consider a container that's located within the item itself
  3093. if($.contains(this.currentItem[0], this.containers[i].element[0]))
  3094. continue;
  3095. if(this._intersectsWith(this.containers[i].containerCache)) {
  3096. // if we've already found a container and it's more "inner" than this, then continue
  3097. if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0]))
  3098. continue;
  3099. innermostContainer = this.containers[i];
  3100. innermostIndex = i;
  3101. } else {
  3102. // container doesn't intersect. trigger "out" event if necessary
  3103. if(this.containers[i].containerCache.over) {
  3104. this.containers[i]._trigger("out", event, this._uiHash(this));
  3105. this.containers[i].containerCache.over = 0;
  3106. }
  3107. }
  3108. }
  3109. // if no intersecting containers found, return
  3110. if(!innermostContainer) return;
  3111. // move the item into the container if it's not there already
  3112. if(this.containers.length === 1) {
  3113. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  3114. this.containers[innermostIndex].containerCache.over = 1;
  3115. } else {
  3116. //When entering a new container, we will find the item with the least distance and append our item near it
  3117. var dist = 10000; var itemWithLeastDistance = null;
  3118. var posProperty = this.containers[innermostIndex].floating ? 'left' : 'top';
  3119. var sizeProperty = this.containers[innermostIndex].floating ? 'width' : 'height';
  3120. var base = this.positionAbs[posProperty] + this.offset.click[posProperty];
  3121. for (var j = this.items.length - 1; j >= 0; j--) {
  3122. if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue;
  3123. if(this.items[j].item[0] == this.currentItem[0]) continue;
  3124. var cur = this.items[j].item.offset()[posProperty];
  3125. var nearBottom = false;
  3126. if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
  3127. nearBottom = true;
  3128. cur += this.items[j][sizeProperty];
  3129. }
  3130. if(Math.abs(cur - base) < dist) {
  3131. dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
  3132. this.direction = nearBottom ? "up": "down";
  3133. }
  3134. }
  3135. if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
  3136. return;
  3137. this.currentContainer = this.containers[innermostIndex];
  3138. itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
  3139. this._trigger("change", event, this._uiHash());
  3140. this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
  3141. //Update the placeholder
  3142. this.options.placeholder.update(this.currentContainer, this.placeholder);
  3143. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  3144. this.containers[innermostIndex].containerCache.over = 1;
  3145. }
  3146. },
  3147. _createHelper: function(event) {
  3148. var o = this.options;
  3149. var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == 'clone' ? this.currentItem.clone() : this.currentItem);
  3150. if(!helper.parents('body').length) //Add the helper to the DOM if that didn't happen already
  3151. $(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
  3152. if(helper[0] == this.currentItem[0])
  3153. 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") };
  3154. if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width());
  3155. if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height());
  3156. return helper;
  3157. },
  3158. _adjustOffsetFromHelper: function(obj) {
  3159. if (typeof obj == 'string') {
  3160. obj = obj.split(' ');
  3161. }
  3162. if ($.isArray(obj)) {
  3163. obj = {left: +obj[0], top: +obj[1] || 0};
  3164. }
  3165. if ('left' in obj) {
  3166. this.offset.click.left = obj.left + this.margins.left;
  3167. }
  3168. if ('right' in obj) {
  3169. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  3170. }
  3171. if ('top' in obj) {
  3172. this.offset.click.top = obj.top + this.margins.top;
  3173. }
  3174. if ('bottom' in obj) {
  3175. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  3176. }
  3177. },
  3178. _getParentOffset: function() {
  3179. //Get the offsetParent and cache its position
  3180. this.offsetParent = this.helper.offsetParent();
  3181. var po = this.offsetParent.offset();
  3182. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  3183. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  3184. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  3185. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  3186. if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  3187. po.left += this.scrollParent.scrollLeft();
  3188. po.top += this.scrollParent.scrollTop();
  3189. }
  3190. if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
  3191. || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.ui.ie)) //Ugly IE fix
  3192. po = { top: 0, left: 0 };
  3193. return {
  3194. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  3195. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  3196. };
  3197. },
  3198. _getRelativeOffset: function() {
  3199. if(this.cssPosition == "relative") {
  3200. var p = this.currentItem.position();
  3201. return {
  3202. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  3203. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  3204. };
  3205. } else {
  3206. return { top: 0, left: 0 };
  3207. }
  3208. },
  3209. _cacheMargins: function() {
  3210. this.margins = {
  3211. left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
  3212. top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
  3213. };
  3214. },
  3215. _cacheHelperProportions: function() {
  3216. this.helperProportions = {
  3217. width: this.helper.outerWidth(),
  3218. height: this.helper.outerHeight()
  3219. };
  3220. },
  3221. _setContainment: function() {
  3222. var o = this.options;
  3223. if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
  3224. if(o.containment == 'document' || o.containment == 'window') this.containment = [
  3225. 0 - this.offset.relative.left - this.offset.parent.left,
  3226. 0 - this.offset.relative.top - this.offset.parent.top,
  3227. $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
  3228. ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  3229. ];
  3230. if(!(/^(document|window|parent)$/).test(o.containment)) {
  3231. var ce = $(o.containment)[0];
  3232. var co = $(o.containment).offset();
  3233. var over = ($(ce).css("overflow") != 'hidden');
  3234. this.containment = [
  3235. co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left,
  3236. co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top,
  3237. 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,
  3238. 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
  3239. ];
  3240. }
  3241. },
  3242. _convertPositionTo: function(d, pos) {
  3243. if(!pos) pos = this.position;
  3244. var mod = d == "absolute" ? 1 : -1;
  3245. var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  3246. return {
  3247. top: (
  3248. pos.top // The absolute mouse position
  3249. + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  3250. + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
  3251. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  3252. ),
  3253. left: (
  3254. pos.left // The absolute mouse position
  3255. + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  3256. + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
  3257. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  3258. )
  3259. };
  3260. },
  3261. _generatePosition: function(event) {
  3262. var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  3263. // This is another very weird special case that only happens for relative elements:
  3264. // 1. If the css position is relative
  3265. // 2. and the scroll parent is the document or similar to the offset parent
  3266. // we have to refresh the relative offset during the scroll so there are no jumps
  3267. if(this.cssPosition == 'relative' && !(this.scrollParent[0] != document && this.scrollParent[0] != this.offsetParent[0])) {
  3268. this.offset.relative = this._getRelativeOffset();
  3269. }
  3270. var pageX = event.pageX;
  3271. var pageY = event.pageY;
  3272. /*
  3273. * - Position constraining -
  3274. * Constrain the position to a mix of grid, containment.
  3275. */
  3276. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  3277. if(this.containment) {
  3278. if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left;
  3279. if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top;
  3280. if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left;
  3281. if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top;
  3282. }
  3283. if(o.grid) {
  3284. var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
  3285. 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;
  3286. var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
  3287. 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;
  3288. }
  3289. }
  3290. return {
  3291. top: (
  3292. pageY // The absolute mouse position
  3293. - this.offset.click.top // Click offset (relative to the element)
  3294. - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
  3295. - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
  3296. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  3297. ),
  3298. left: (
  3299. pageX // The absolute mouse position
  3300. - this.offset.click.left // Click offset (relative to the element)
  3301. - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
  3302. - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
  3303. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  3304. )
  3305. };
  3306. },
  3307. _rearrange: function(event, i, a, hardRefresh) {
  3308. 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));
  3309. //Various things done here to improve the performance:
  3310. // 1. we create a setTimeout, that calls refreshPositions
  3311. // 2. on the instance, we have a counter variable, that get's higher after every append
  3312. // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
  3313. // 4. this lets only the last addition to the timeout stack through
  3314. this.counter = this.counter ? ++this.counter : 1;
  3315. var counter = this.counter;
  3316. this._delay(function() {
  3317. if(counter == this.counter) this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
  3318. });
  3319. },
  3320. _clear: function(event, noPropagation) {
  3321. this.reverting = false;
  3322. // We delay all events that have to be triggered to after the point where the placeholder has been removed and
  3323. // everything else normalized again
  3324. var delayedTriggers = [];
  3325. // We first have to update the dom position of the actual currentItem
  3326. // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
  3327. if(!this._noFinalSort && this.currentItem.parent().length) this.placeholder.before(this.currentItem);
  3328. this._noFinalSort = null;
  3329. if(this.helper[0] == this.currentItem[0]) {
  3330. for(var i in this._storedCSS) {
  3331. if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = '';
  3332. }
  3333. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  3334. } else {
  3335. this.currentItem.show();
  3336. }
  3337. if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
  3338. if((this.fromOutside || this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) && !noPropagation) delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
  3339. // Check if the items Container has Changed and trigger appropriate
  3340. // events.
  3341. if (this !== this.currentContainer) {
  3342. if(!noPropagation) {
  3343. delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); });
  3344. delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  3345. delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  3346. }
  3347. }
  3348. //Post events to containers
  3349. for (var i = this.containers.length - 1; i >= 0; i--){
  3350. if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
  3351. if(this.containers[i].containerCache.over) {
  3352. delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
  3353. this.containers[i].containerCache.over = 0;
  3354. }
  3355. }
  3356. //Do what was originally in plugins
  3357. if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor
  3358. if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset opacity
  3359. if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index
  3360. this.dragging = false;
  3361. if(this.cancelHelperRemoval) {
  3362. if(!noPropagation) {
  3363. this._trigger("beforeStop", event, this._uiHash());
  3364. for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
  3365. this._trigger("stop", event, this._uiHash());
  3366. }
  3367. this.fromOutside = false;
  3368. return false;
  3369. }
  3370. if(!noPropagation) this._trigger("beforeStop", event, this._uiHash());
  3371. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  3372. this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  3373. if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null;
  3374. if(!noPropagation) {
  3375. for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
  3376. this._trigger("stop", event, this._uiHash());
  3377. }
  3378. this.fromOutside = false;
  3379. return true;
  3380. },
  3381. _trigger: function() {
  3382. if ($.Widget.prototype._trigger.apply(this, arguments) === false) {
  3383. this.cancel();
  3384. }
  3385. },
  3386. _uiHash: function(_inst) {
  3387. var inst = _inst || this;
  3388. return {
  3389. helper: inst.helper,
  3390. placeholder: inst.placeholder || $([]),
  3391. position: inst.position,
  3392. originalPosition: inst.originalPosition,
  3393. offset: inst.positionAbs,
  3394. item: inst.currentItem,
  3395. sender: _inst ? _inst.element : null
  3396. };
  3397. }
  3398. });
  3399. })(jQuery);
  3400. ;(jQuery.effects || (function($, undefined) {
  3401. var backCompat = $.uiBackCompat !== false,
  3402. // prefix used for storing data on .data()
  3403. dataSpace = "ui-effects-";
  3404. $.effects = {
  3405. effect: {}
  3406. };
  3407. /*!
  3408. * jQuery Color Animations v2.0.0
  3409. * http://jquery.com/
  3410. *
  3411. * Copyright 2012 jQuery Foundation and other contributors
  3412. * Released under the MIT license.
  3413. * http://jquery.org/license
  3414. *
  3415. * Date: Mon Aug 13 13:41:02 2012 -0500
  3416. */
  3417. (function( jQuery, undefined ) {
  3418. var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor".split(" "),
  3419. // plusequals test for += 100 -= 100
  3420. rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
  3421. // a set of RE's that can match strings and generate color tuples.
  3422. stringParsers = [{
  3423. re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
  3424. parse: function( execResult ) {
  3425. return [
  3426. execResult[ 1 ],
  3427. execResult[ 2 ],
  3428. execResult[ 3 ],
  3429. execResult[ 4 ]
  3430. ];
  3431. }
  3432. }, {
  3433. re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
  3434. parse: function( execResult ) {
  3435. return [
  3436. execResult[ 1 ] * 2.55,
  3437. execResult[ 2 ] * 2.55,
  3438. execResult[ 3 ] * 2.55,
  3439. execResult[ 4 ]
  3440. ];
  3441. }
  3442. }, {
  3443. // this regex ignores A-F because it's compared against an already lowercased string
  3444. re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
  3445. parse: function( execResult ) {
  3446. return [
  3447. parseInt( execResult[ 1 ], 16 ),
  3448. parseInt( execResult[ 2 ], 16 ),
  3449. parseInt( execResult[ 3 ], 16 )
  3450. ];
  3451. }
  3452. }, {
  3453. // this regex ignores A-F because it's compared against an already lowercased string
  3454. re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
  3455. parse: function( execResult ) {
  3456. return [
  3457. parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
  3458. parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
  3459. parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
  3460. ];
  3461. }
  3462. }, {
  3463. re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
  3464. space: "hsla",
  3465. parse: function( execResult ) {
  3466. return [
  3467. execResult[ 1 ],
  3468. execResult[ 2 ] / 100,
  3469. execResult[ 3 ] / 100,
  3470. execResult[ 4 ]
  3471. ];
  3472. }
  3473. }],
  3474. // jQuery.Color( )
  3475. color = jQuery.Color = function( color, green, blue, alpha ) {
  3476. return new jQuery.Color.fn.parse( color, green, blue, alpha );
  3477. },
  3478. spaces = {
  3479. rgba: {
  3480. props: {
  3481. red: {
  3482. idx: 0,
  3483. type: "byte"
  3484. },
  3485. green: {
  3486. idx: 1,
  3487. type: "byte"
  3488. },
  3489. blue: {
  3490. idx: 2,
  3491. type: "byte"
  3492. }
  3493. }
  3494. },
  3495. hsla: {
  3496. props: {
  3497. hue: {
  3498. idx: 0,
  3499. type: "degrees"
  3500. },
  3501. saturation: {
  3502. idx: 1,
  3503. type: "percent"
  3504. },
  3505. lightness: {
  3506. idx: 2,
  3507. type: "percent"
  3508. }
  3509. }
  3510. }
  3511. },
  3512. propTypes = {
  3513. "byte": {
  3514. floor: true,
  3515. max: 255
  3516. },
  3517. "percent": {
  3518. max: 1
  3519. },
  3520. "degrees": {
  3521. mod: 360,
  3522. floor: true
  3523. }
  3524. },
  3525. support = color.support = {},
  3526. // element for support tests
  3527. supportElem = jQuery( "<p>" )[ 0 ],
  3528. // colors = jQuery.Color.names
  3529. colors,
  3530. // local aliases of functions called often
  3531. each = jQuery.each;
  3532. // determine rgba support immediately
  3533. supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
  3534. support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
  3535. // define cache name and alpha properties
  3536. // for rgba and hsla spaces
  3537. each( spaces, function( spaceName, space ) {
  3538. space.cache = "_" + spaceName;
  3539. space.props.alpha = {
  3540. idx: 3,
  3541. type: "percent",
  3542. def: 1
  3543. };
  3544. });
  3545. function clamp( value, prop, allowEmpty ) {
  3546. var type = propTypes[ prop.type ] || {};
  3547. if ( value == null ) {
  3548. return (allowEmpty || !prop.def) ? null : prop.def;
  3549. }
  3550. // ~~ is an short way of doing floor for positive numbers
  3551. value = type.floor ? ~~value : parseFloat( value );
  3552. // IE will pass in empty strings as value for alpha,
  3553. // which will hit this case
  3554. if ( isNaN( value ) ) {
  3555. return prop.def;
  3556. }
  3557. if ( type.mod ) {
  3558. // we add mod before modding to make sure that negatives values
  3559. // get converted properly: -10 -> 350
  3560. return (value + type.mod) % type.mod;
  3561. }
  3562. // for now all property types without mod have min and max
  3563. return 0 > value ? 0 : type.max < value ? type.max : value;
  3564. }
  3565. function stringParse( string ) {
  3566. var inst = color(),
  3567. rgba = inst._rgba = [];
  3568. string = string.toLowerCase();
  3569. each( stringParsers, function( i, parser ) {
  3570. var parsed,
  3571. match = parser.re.exec( string ),
  3572. values = match && parser.parse( match ),
  3573. spaceName = parser.space || "rgba";
  3574. if ( values ) {
  3575. parsed = inst[ spaceName ]( values );
  3576. // if this was an rgba parse the assignment might happen twice
  3577. // oh well....
  3578. inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
  3579. rgba = inst._rgba = parsed._rgba;
  3580. // exit each( stringParsers ) here because we matched
  3581. return false;
  3582. }
  3583. });
  3584. // Found a stringParser that handled it
  3585. if ( rgba.length ) {
  3586. // if this came from a parsed string, force "transparent" when alpha is 0
  3587. // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
  3588. if ( rgba.join() === "0,0,0,0" ) {
  3589. jQuery.extend( rgba, colors.transparent );
  3590. }
  3591. return inst;
  3592. }
  3593. // named colors
  3594. return colors[ string ];
  3595. }
  3596. color.fn = jQuery.extend( color.prototype, {
  3597. parse: function( red, green, blue, alpha ) {
  3598. if ( red === undefined ) {
  3599. this._rgba = [ null, null, null, null ];
  3600. return this;
  3601. }
  3602. if ( red.jquery || red.nodeType ) {
  3603. red = jQuery( red ).css( green );
  3604. green = undefined;
  3605. }
  3606. var inst = this,
  3607. type = jQuery.type( red ),
  3608. rgba = this._rgba = [];
  3609. // more than 1 argument specified - assume ( red, green, blue, alpha )
  3610. if ( green !== undefined ) {
  3611. red = [ red, green, blue, alpha ];
  3612. type = "array";
  3613. }
  3614. if ( type === "string" ) {
  3615. return this.parse( stringParse( red ) || colors._default );
  3616. }
  3617. if ( type === "array" ) {
  3618. each( spaces.rgba.props, function( key, prop ) {
  3619. rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
  3620. });
  3621. return this;
  3622. }
  3623. if ( type === "object" ) {
  3624. if ( red instanceof color ) {
  3625. each( spaces, function( spaceName, space ) {
  3626. if ( red[ space.cache ] ) {
  3627. inst[ space.cache ] = red[ space.cache ].slice();
  3628. }
  3629. });
  3630. } else {
  3631. each( spaces, function( spaceName, space ) {
  3632. var cache = space.cache;
  3633. each( space.props, function( key, prop ) {
  3634. // if the cache doesn't exist, and we know how to convert
  3635. if ( !inst[ cache ] && space.to ) {
  3636. // if the value was null, we don't need to copy it
  3637. // if the key was alpha, we don't need to copy it either
  3638. if ( key === "alpha" || red[ key ] == null ) {
  3639. return;
  3640. }
  3641. inst[ cache ] = space.to( inst._rgba );
  3642. }
  3643. // this is the only case where we allow nulls for ALL properties.
  3644. // call clamp with alwaysAllowEmpty
  3645. inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
  3646. });
  3647. // everything defined but alpha?
  3648. if ( inst[ cache ] && $.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
  3649. // use the default of 1
  3650. inst[ cache ][ 3 ] = 1;
  3651. if ( space.from ) {
  3652. inst._rgba = space.from( inst[ cache ] );
  3653. }
  3654. }
  3655. });
  3656. }
  3657. return this;
  3658. }
  3659. },
  3660. is: function( compare ) {
  3661. var is = color( compare ),
  3662. same = true,
  3663. inst = this;
  3664. each( spaces, function( _, space ) {
  3665. var localCache,
  3666. isCache = is[ space.cache ];
  3667. if (isCache) {
  3668. localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
  3669. each( space.props, function( _, prop ) {
  3670. if ( isCache[ prop.idx ] != null ) {
  3671. same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
  3672. return same;
  3673. }
  3674. });
  3675. }
  3676. return same;
  3677. });
  3678. return same;
  3679. },
  3680. _space: function() {
  3681. var used = [],
  3682. inst = this;
  3683. each( spaces, function( spaceName, space ) {
  3684. if ( inst[ space.cache ] ) {
  3685. used.push( spaceName );
  3686. }
  3687. });
  3688. return used.pop();
  3689. },
  3690. transition: function( other, distance ) {
  3691. var end = color( other ),
  3692. spaceName = end._space(),
  3693. space = spaces[ spaceName ],
  3694. startColor = this.alpha() === 0 ? color( "transparent" ) : this,
  3695. start = startColor[ space.cache ] || space.to( startColor._rgba ),
  3696. result = start.slice();
  3697. end = end[ space.cache ];
  3698. each( space.props, function( key, prop ) {
  3699. var index = prop.idx,
  3700. startValue = start[ index ],
  3701. endValue = end[ index ],
  3702. type = propTypes[ prop.type ] || {};
  3703. // if null, don't override start value
  3704. if ( endValue === null ) {
  3705. return;
  3706. }
  3707. // if null - use end
  3708. if ( startValue === null ) {
  3709. result[ index ] = endValue;
  3710. } else {
  3711. if ( type.mod ) {
  3712. if ( endValue - startValue > type.mod / 2 ) {
  3713. startValue += type.mod;
  3714. } else if ( startValue - endValue > type.mod / 2 ) {
  3715. startValue -= type.mod;
  3716. }
  3717. }
  3718. result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
  3719. }
  3720. });
  3721. return this[ spaceName ]( result );
  3722. },
  3723. blend: function( opaque ) {
  3724. // if we are already opaque - return ourself
  3725. if ( this._rgba[ 3 ] === 1 ) {
  3726. return this;
  3727. }
  3728. var rgb = this._rgba.slice(),
  3729. a = rgb.pop(),
  3730. blend = color( opaque )._rgba;
  3731. return color( jQuery.map( rgb, function( v, i ) {
  3732. return ( 1 - a ) * blend[ i ] + a * v;
  3733. }));
  3734. },
  3735. toRgbaString: function() {
  3736. var prefix = "rgba(",
  3737. rgba = jQuery.map( this._rgba, function( v, i ) {
  3738. return v == null ? ( i > 2 ? 1 : 0 ) : v;
  3739. });
  3740. if ( rgba[ 3 ] === 1 ) {
  3741. rgba.pop();
  3742. prefix = "rgb(";
  3743. }
  3744. return prefix + rgba.join() + ")";
  3745. },
  3746. toHslaString: function() {
  3747. var prefix = "hsla(",
  3748. hsla = jQuery.map( this.hsla(), function( v, i ) {
  3749. if ( v == null ) {
  3750. v = i > 2 ? 1 : 0;
  3751. }
  3752. // catch 1 and 2
  3753. if ( i && i < 3 ) {
  3754. v = Math.round( v * 100 ) + "%";
  3755. }
  3756. return v;
  3757. });
  3758. if ( hsla[ 3 ] === 1 ) {
  3759. hsla.pop();
  3760. prefix = "hsl(";
  3761. }
  3762. return prefix + hsla.join() + ")";
  3763. },
  3764. toHexString: function( includeAlpha ) {
  3765. var rgba = this._rgba.slice(),
  3766. alpha = rgba.pop();
  3767. if ( includeAlpha ) {
  3768. rgba.push( ~~( alpha * 255 ) );
  3769. }
  3770. return "#" + jQuery.map( rgba, function( v ) {
  3771. // default to 0 when nulls exist
  3772. v = ( v || 0 ).toString( 16 );
  3773. return v.length === 1 ? "0" + v : v;
  3774. }).join("");
  3775. },
  3776. toString: function() {
  3777. return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
  3778. }
  3779. });
  3780. color.fn.parse.prototype = color.fn;
  3781. // hsla conversions adapted from:
  3782. // https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
  3783. function hue2rgb( p, q, h ) {
  3784. h = ( h + 1 ) % 1;
  3785. if ( h * 6 < 1 ) {
  3786. return p + (q - p) * h * 6;
  3787. }
  3788. if ( h * 2 < 1) {
  3789. return q;
  3790. }
  3791. if ( h * 3 < 2 ) {
  3792. return p + (q - p) * ((2/3) - h) * 6;
  3793. }
  3794. return p;
  3795. }
  3796. spaces.hsla.to = function ( rgba ) {
  3797. if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
  3798. return [ null, null, null, rgba[ 3 ] ];
  3799. }
  3800. var r = rgba[ 0 ] / 255,
  3801. g = rgba[ 1 ] / 255,
  3802. b = rgba[ 2 ] / 255,
  3803. a = rgba[ 3 ],
  3804. max = Math.max( r, g, b ),
  3805. min = Math.min( r, g, b ),
  3806. diff = max - min,
  3807. add = max + min,
  3808. l = add * 0.5,
  3809. h, s;
  3810. if ( min === max ) {
  3811. h = 0;
  3812. } else if ( r === max ) {
  3813. h = ( 60 * ( g - b ) / diff ) + 360;
  3814. } else if ( g === max ) {
  3815. h = ( 60 * ( b - r ) / diff ) + 120;
  3816. } else {
  3817. h = ( 60 * ( r - g ) / diff ) + 240;
  3818. }
  3819. if ( l === 0 || l === 1 ) {
  3820. s = l;
  3821. } else if ( l <= 0.5 ) {
  3822. s = diff / add;
  3823. } else {
  3824. s = diff / ( 2 - add );
  3825. }
  3826. return [ Math.round(h) % 360, s, l, a == null ? 1 : a ];
  3827. };
  3828. spaces.hsla.from = function ( hsla ) {
  3829. if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
  3830. return [ null, null, null, hsla[ 3 ] ];
  3831. }
  3832. var h = hsla[ 0 ] / 360,
  3833. s = hsla[ 1 ],
  3834. l = hsla[ 2 ],
  3835. a = hsla[ 3 ],
  3836. q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
  3837. p = 2 * l - q;
  3838. return [
  3839. Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
  3840. Math.round( hue2rgb( p, q, h ) * 255 ),
  3841. Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
  3842. a
  3843. ];
  3844. };
  3845. each( spaces, function( spaceName, space ) {
  3846. var props = space.props,
  3847. cache = space.cache,
  3848. to = space.to,
  3849. from = space.from;
  3850. // makes rgba() and hsla()
  3851. color.fn[ spaceName ] = function( value ) {
  3852. // generate a cache for this space if it doesn't exist
  3853. if ( to && !this[ cache ] ) {
  3854. this[ cache ] = to( this._rgba );
  3855. }
  3856. if ( value === undefined ) {
  3857. return this[ cache ].slice();
  3858. }
  3859. var ret,
  3860. type = jQuery.type( value ),
  3861. arr = ( type === "array" || type === "object" ) ? value : arguments,
  3862. local = this[ cache ].slice();
  3863. each( props, function( key, prop ) {
  3864. var val = arr[ type === "object" ? key : prop.idx ];
  3865. if ( val == null ) {
  3866. val = local[ prop.idx ];
  3867. }
  3868. local[ prop.idx ] = clamp( val, prop );
  3869. });
  3870. if ( from ) {
  3871. ret = color( from( local ) );
  3872. ret[ cache ] = local;
  3873. return ret;
  3874. } else {
  3875. return color( local );
  3876. }
  3877. };
  3878. // makes red() green() blue() alpha() hue() saturation() lightness()
  3879. each( props, function( key, prop ) {
  3880. // alpha is included in more than one space
  3881. if ( color.fn[ key ] ) {
  3882. return;
  3883. }
  3884. color.fn[ key ] = function( value ) {
  3885. var vtype = jQuery.type( value ),
  3886. fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ),
  3887. local = this[ fn ](),
  3888. cur = local[ prop.idx ],
  3889. match;
  3890. if ( vtype === "undefined" ) {
  3891. return cur;
  3892. }
  3893. if ( vtype === "function" ) {
  3894. value = value.call( this, cur );
  3895. vtype = jQuery.type( value );
  3896. }
  3897. if ( value == null && prop.empty ) {
  3898. return this;
  3899. }
  3900. if ( vtype === "string" ) {
  3901. match = rplusequals.exec( value );
  3902. if ( match ) {
  3903. value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
  3904. }
  3905. }
  3906. local[ prop.idx ] = value;
  3907. return this[ fn ]( local );
  3908. };
  3909. });
  3910. });
  3911. // add .fx.step functions
  3912. each( stepHooks, function( i, hook ) {
  3913. jQuery.cssHooks[ hook ] = {
  3914. set: function( elem, value ) {
  3915. var parsed, curElem,
  3916. backgroundColor = "";
  3917. if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) {
  3918. value = color( parsed || value );
  3919. if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
  3920. curElem = hook === "backgroundColor" ? elem.parentNode : elem;
  3921. while (
  3922. (backgroundColor === "" || backgroundColor === "transparent") &&
  3923. curElem && curElem.style
  3924. ) {
  3925. try {
  3926. backgroundColor = jQuery.css( curElem, "backgroundColor" );
  3927. curElem = curElem.parentNode;
  3928. } catch ( e ) {
  3929. }
  3930. }
  3931. value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
  3932. backgroundColor :
  3933. "_default" );
  3934. }
  3935. value = value.toRgbaString();
  3936. }
  3937. try {
  3938. elem.style[ hook ] = value;
  3939. } catch( error ) {
  3940. // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
  3941. }
  3942. }
  3943. };
  3944. jQuery.fx.step[ hook ] = function( fx ) {
  3945. if ( !fx.colorInit ) {
  3946. fx.start = color( fx.elem, hook );
  3947. fx.end = color( fx.end );
  3948. fx.colorInit = true;
  3949. }
  3950. jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
  3951. };
  3952. });
  3953. jQuery.cssHooks.borderColor = {
  3954. expand: function( value ) {
  3955. var expanded = {};
  3956. each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
  3957. expanded[ "border" + part + "Color" ] = value;
  3958. });
  3959. return expanded;
  3960. }
  3961. };
  3962. // Basic color names only.
  3963. // Usage of any of the other color names requires adding yourself or including
  3964. // jquery.color.svg-names.js.
  3965. colors = jQuery.Color.names = {
  3966. // 4.1. Basic color keywords
  3967. aqua: "#00ffff",
  3968. black: "#000000",
  3969. blue: "#0000ff",
  3970. fuchsia: "#ff00ff",
  3971. gray: "#808080",
  3972. green: "#008000",
  3973. lime: "#00ff00",
  3974. maroon: "#800000",
  3975. navy: "#000080",
  3976. olive: "#808000",
  3977. purple: "#800080",
  3978. red: "#ff0000",
  3979. silver: "#c0c0c0",
  3980. teal: "#008080",
  3981. white: "#ffffff",
  3982. yellow: "#ffff00",
  3983. // 4.2.3. "transparent" color keyword
  3984. transparent: [ null, null, null, 0 ],
  3985. _default: "#ffffff"
  3986. };
  3987. })( jQuery );
  3988. /******************************************************************************/
  3989. /****************************** CLASS ANIMATIONS ******************************/
  3990. /******************************************************************************/
  3991. (function() {
  3992. var classAnimationActions = [ "add", "remove", "toggle" ],
  3993. shorthandStyles = {
  3994. border: 1,
  3995. borderBottom: 1,
  3996. borderColor: 1,
  3997. borderLeft: 1,
  3998. borderRight: 1,
  3999. borderTop: 1,
  4000. borderWidth: 1,
  4001. margin: 1,
  4002. padding: 1
  4003. };
  4004. $.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ], function( _, prop ) {
  4005. $.fx.step[ prop ] = function( fx ) {
  4006. if ( fx.end !== "none" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) {
  4007. jQuery.style( fx.elem, prop, fx.end );
  4008. fx.setAttr = true;
  4009. }
  4010. };
  4011. });
  4012. function getElementStyles() {
  4013. var style = this.ownerDocument.defaultView ?
  4014. this.ownerDocument.defaultView.getComputedStyle( this, null ) :
  4015. this.currentStyle,
  4016. newStyle = {},
  4017. key,
  4018. len;
  4019. // webkit enumerates style porperties
  4020. if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {
  4021. len = style.length;
  4022. while ( len-- ) {
  4023. key = style[ len ];
  4024. if ( typeof style[ key ] === "string" ) {
  4025. newStyle[ $.camelCase( key ) ] = style[ key ];
  4026. }
  4027. }
  4028. } else {
  4029. for ( key in style ) {
  4030. if ( typeof style[ key ] === "string" ) {
  4031. newStyle[ key ] = style[ key ];
  4032. }
  4033. }
  4034. }
  4035. return newStyle;
  4036. }
  4037. function styleDifference( oldStyle, newStyle ) {
  4038. var diff = {},
  4039. name, value;
  4040. for ( name in newStyle ) {
  4041. value = newStyle[ name ];
  4042. if ( oldStyle[ name ] !== value ) {
  4043. if ( !shorthandStyles[ name ] ) {
  4044. if ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) {
  4045. diff[ name ] = value;
  4046. }
  4047. }
  4048. }
  4049. }
  4050. return diff;
  4051. }
  4052. $.effects.animateClass = function( value, duration, easing, callback ) {
  4053. var o = $.speed( duration, easing, callback );
  4054. return this.queue( function() {
  4055. var animated = $( this ),
  4056. baseClass = animated.attr( "class" ) || "",
  4057. applyClassChange,
  4058. allAnimations = o.children ? animated.find( "*" ).andSelf() : animated;
  4059. // map the animated objects to store the original styles.
  4060. allAnimations = allAnimations.map(function() {
  4061. var el = $( this );
  4062. return {
  4063. el: el,
  4064. start: getElementStyles.call( this )
  4065. };
  4066. });
  4067. // apply class change
  4068. applyClassChange = function() {
  4069. $.each( classAnimationActions, function(i, action) {
  4070. if ( value[ action ] ) {
  4071. animated[ action + "Class" ]( value[ action ] );
  4072. }
  4073. });
  4074. };
  4075. applyClassChange();
  4076. // map all animated objects again - calculate new styles and diff
  4077. allAnimations = allAnimations.map(function() {
  4078. this.end = getElementStyles.call( this.el[ 0 ] );
  4079. this.diff = styleDifference( this.start, this.end );
  4080. return this;
  4081. });
  4082. // apply original class
  4083. animated.attr( "class", baseClass );
  4084. // map all animated objects again - this time collecting a promise
  4085. allAnimations = allAnimations.map(function() {
  4086. var styleInfo = this,
  4087. dfd = $.Deferred(),
  4088. opts = jQuery.extend({}, o, {
  4089. queue: false,
  4090. complete: function() {
  4091. dfd.resolve( styleInfo );
  4092. }
  4093. });
  4094. this.el.animate( this.diff, opts );
  4095. return dfd.promise();
  4096. });
  4097. // once all animations have completed:
  4098. $.when.apply( $, allAnimations.get() ).done(function() {
  4099. // set the final class
  4100. applyClassChange();
  4101. // for each animated element,
  4102. // clear all css properties that were animated
  4103. $.each( arguments, function() {
  4104. var el = this.el;
  4105. $.each( this.diff, function(key) {
  4106. el.css( key, '' );
  4107. });
  4108. });
  4109. // this is guarnteed to be there if you use jQuery.speed()
  4110. // it also handles dequeuing the next anim...
  4111. o.complete.call( animated[ 0 ] );
  4112. });
  4113. });
  4114. };
  4115. $.fn.extend({
  4116. _addClass: $.fn.addClass,
  4117. addClass: function( classNames, speed, easing, callback ) {
  4118. return speed ?
  4119. $.effects.animateClass.call( this,
  4120. { add: classNames }, speed, easing, callback ) :
  4121. this._addClass( classNames );
  4122. },
  4123. _removeClass: $.fn.removeClass,
  4124. removeClass: function( classNames, speed, easing, callback ) {
  4125. return speed ?
  4126. $.effects.animateClass.call( this,
  4127. { remove: classNames }, speed, easing, callback ) :
  4128. this._removeClass( classNames );
  4129. },
  4130. _toggleClass: $.fn.toggleClass,
  4131. toggleClass: function( classNames, force, speed, easing, callback ) {
  4132. if ( typeof force === "boolean" || force === undefined ) {
  4133. if ( !speed ) {
  4134. // without speed parameter
  4135. return this._toggleClass( classNames, force );
  4136. } else {
  4137. return $.effects.animateClass.call( this,
  4138. (force ? { add: classNames } : { remove: classNames }),
  4139. speed, easing, callback );
  4140. }
  4141. } else {
  4142. // without force parameter
  4143. return $.effects.animateClass.call( this,
  4144. { toggle: classNames }, force, speed, easing );
  4145. }
  4146. },
  4147. switchClass: function( remove, add, speed, easing, callback) {
  4148. return $.effects.animateClass.call( this, {
  4149. add: add,
  4150. remove: remove
  4151. }, speed, easing, callback );
  4152. }
  4153. });
  4154. })();
  4155. /******************************************************************************/
  4156. /*********************************** EFFECTS **********************************/
  4157. /******************************************************************************/
  4158. (function() {
  4159. $.extend( $.effects, {
  4160. version: "1.9.2",
  4161. // Saves a set of properties in a data storage
  4162. save: function( element, set ) {
  4163. for( var i=0; i < set.length; i++ ) {
  4164. if ( set[ i ] !== null ) {
  4165. element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
  4166. }
  4167. }
  4168. },
  4169. // Restores a set of previously saved properties from a data storage
  4170. restore: function( element, set ) {
  4171. var val, i;
  4172. for( i=0; i < set.length; i++ ) {
  4173. if ( set[ i ] !== null ) {
  4174. val = element.data( dataSpace + set[ i ] );
  4175. // support: jQuery 1.6.2
  4176. // http://bugs.jquery.com/ticket/9917
  4177. // jQuery 1.6.2 incorrectly returns undefined for any falsy value.
  4178. // We can't differentiate between "" and 0 here, so we just assume
  4179. // empty string since it's likely to be a more common value...
  4180. if ( val === undefined ) {
  4181. val = "";
  4182. }
  4183. element.css( set[ i ], val );
  4184. }
  4185. }
  4186. },
  4187. setMode: function( el, mode ) {
  4188. if (mode === "toggle") {
  4189. mode = el.is( ":hidden" ) ? "show" : "hide";
  4190. }
  4191. return mode;
  4192. },
  4193. // Translates a [top,left] array into a baseline value
  4194. // this should be a little more flexible in the future to handle a string & hash
  4195. getBaseline: function( origin, original ) {
  4196. var y, x;
  4197. switch ( origin[ 0 ] ) {
  4198. case "top": y = 0; break;
  4199. case "middle": y = 0.5; break;
  4200. case "bottom": y = 1; break;
  4201. default: y = origin[ 0 ] / original.height;
  4202. }
  4203. switch ( origin[ 1 ] ) {
  4204. case "left": x = 0; break;
  4205. case "center": x = 0.5; break;
  4206. case "right": x = 1; break;
  4207. default: x = origin[ 1 ] / original.width;
  4208. }
  4209. return {
  4210. x: x,
  4211. y: y
  4212. };
  4213. },
  4214. // Wraps the element around a wrapper that copies position properties
  4215. createWrapper: function( element ) {
  4216. // if the element is already wrapped, return it
  4217. if ( element.parent().is( ".ui-effects-wrapper" )) {
  4218. return element.parent();
  4219. }
  4220. // wrap the element
  4221. var props = {
  4222. width: element.outerWidth(true),
  4223. height: element.outerHeight(true),
  4224. "float": element.css( "float" )
  4225. },
  4226. wrapper = $( "<div></div>" )
  4227. .addClass( "ui-effects-wrapper" )
  4228. .css({
  4229. fontSize: "100%",
  4230. background: "transparent",
  4231. border: "none",
  4232. margin: 0,
  4233. padding: 0
  4234. }),
  4235. // Store the size in case width/height are defined in % - Fixes #5245
  4236. size = {
  4237. width: element.width(),
  4238. height: element.height()
  4239. },
  4240. active = document.activeElement;
  4241. // support: Firefox
  4242. // Firefox incorrectly exposes anonymous content
  4243. // https://bugzilla.mozilla.org/show_bug.cgi?id=561664
  4244. try {
  4245. active.id;
  4246. } catch( e ) {
  4247. active = document.body;
  4248. }
  4249. element.wrap( wrapper );
  4250. // Fixes #7595 - Elements lose focus when wrapped.
  4251. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  4252. $( active ).focus();
  4253. }
  4254. wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
  4255. // transfer positioning properties to the wrapper
  4256. if ( element.css( "position" ) === "static" ) {
  4257. wrapper.css({ position: "relative" });
  4258. element.css({ position: "relative" });
  4259. } else {
  4260. $.extend( props, {
  4261. position: element.css( "position" ),
  4262. zIndex: element.css( "z-index" )
  4263. });
  4264. $.each([ "top", "left", "bottom", "right" ], function(i, pos) {
  4265. props[ pos ] = element.css( pos );
  4266. if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
  4267. props[ pos ] = "auto";
  4268. }
  4269. });
  4270. element.css({
  4271. position: "relative",
  4272. top: 0,
  4273. left: 0,
  4274. right: "auto",
  4275. bottom: "auto"
  4276. });
  4277. }
  4278. element.css(size);
  4279. return wrapper.css( props ).show();
  4280. },
  4281. removeWrapper: function( element ) {
  4282. var active = document.activeElement;
  4283. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  4284. element.parent().replaceWith( element );
  4285. // Fixes #7595 - Elements lose focus when wrapped.
  4286. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  4287. $( active ).focus();
  4288. }
  4289. }
  4290. return element;
  4291. },
  4292. setTransition: function( element, list, factor, value ) {
  4293. value = value || {};
  4294. $.each( list, function( i, x ) {
  4295. var unit = element.cssUnit( x );
  4296. if ( unit[ 0 ] > 0 ) {
  4297. value[ x ] = unit[ 0 ] * factor + unit[ 1 ];
  4298. }
  4299. });
  4300. return value;
  4301. }
  4302. });
  4303. // return an effect options object for the given parameters:
  4304. function _normalizeArguments( effect, options, speed, callback ) {
  4305. // allow passing all options as the first parameter
  4306. if ( $.isPlainObject( effect ) ) {
  4307. options = effect;
  4308. effect = effect.effect;
  4309. }
  4310. // convert to an object
  4311. effect = { effect: effect };
  4312. // catch (effect, null, ...)
  4313. if ( options == null ) {
  4314. options = {};
  4315. }
  4316. // catch (effect, callback)
  4317. if ( $.isFunction( options ) ) {
  4318. callback = options;
  4319. speed = null;
  4320. options = {};
  4321. }
  4322. // catch (effect, speed, ?)
  4323. if ( typeof options === "number" || $.fx.speeds[ options ] ) {
  4324. callback = speed;
  4325. speed = options;
  4326. options = {};
  4327. }
  4328. // catch (effect, options, callback)
  4329. if ( $.isFunction( speed ) ) {
  4330. callback = speed;
  4331. speed = null;
  4332. }
  4333. // add options to effect
  4334. if ( options ) {
  4335. $.extend( effect, options );
  4336. }
  4337. speed = speed || options.duration;
  4338. effect.duration = $.fx.off ? 0 :
  4339. typeof speed === "number" ? speed :
  4340. speed in $.fx.speeds ? $.fx.speeds[ speed ] :
  4341. $.fx.speeds._default;
  4342. effect.complete = callback || options.complete;
  4343. return effect;
  4344. }
  4345. function standardSpeed( speed ) {
  4346. // valid standard speeds
  4347. if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) {
  4348. return true;
  4349. }
  4350. // invalid strings - treat as "normal" speed
  4351. if ( typeof speed === "string" && !$.effects.effect[ speed ] ) {
  4352. // TODO: remove in 2.0 (#7115)
  4353. if ( backCompat && $.effects[ speed ] ) {
  4354. return false;
  4355. }
  4356. return true;
  4357. }
  4358. return false;
  4359. }
  4360. $.fn.extend({
  4361. effect: function( /* effect, options, speed, callback */ ) {
  4362. var args = _normalizeArguments.apply( this, arguments ),
  4363. mode = args.mode,
  4364. queue = args.queue,
  4365. effectMethod = $.effects.effect[ args.effect ],
  4366. // DEPRECATED: remove in 2.0 (#7115)
  4367. oldEffectMethod = !effectMethod && backCompat && $.effects[ args.effect ];
  4368. if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) {
  4369. // delegate to the original method (e.g., .show()) if possible
  4370. if ( mode ) {
  4371. return this[ mode ]( args.duration, args.complete );
  4372. } else {
  4373. return this.each( function() {
  4374. if ( args.complete ) {
  4375. args.complete.call( this );
  4376. }
  4377. });
  4378. }
  4379. }
  4380. function run( next ) {
  4381. var elem = $( this ),
  4382. complete = args.complete,
  4383. mode = args.mode;
  4384. function done() {
  4385. if ( $.isFunction( complete ) ) {
  4386. complete.call( elem[0] );
  4387. }
  4388. if ( $.isFunction( next ) ) {
  4389. next();
  4390. }
  4391. }
  4392. // if the element is hiddden and mode is hide,
  4393. // or element is visible and mode is show
  4394. if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
  4395. done();
  4396. } else {
  4397. effectMethod.call( elem[0], args, done );
  4398. }
  4399. }
  4400. // TODO: remove this check in 2.0, effectMethod will always be true
  4401. if ( effectMethod ) {
  4402. return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
  4403. } else {
  4404. // DEPRECATED: remove in 2.0 (#7115)
  4405. return oldEffectMethod.call(this, {
  4406. options: args,
  4407. duration: args.duration,
  4408. callback: args.complete,
  4409. mode: args.mode
  4410. });
  4411. }
  4412. },
  4413. _show: $.fn.show,
  4414. show: function( speed ) {
  4415. if ( standardSpeed( speed ) ) {
  4416. return this._show.apply( this, arguments );
  4417. } else {
  4418. var args = _normalizeArguments.apply( this, arguments );
  4419. args.mode = "show";
  4420. return this.effect.call( this, args );
  4421. }
  4422. },
  4423. _hide: $.fn.hide,
  4424. hide: function( speed ) {
  4425. if ( standardSpeed( speed ) ) {
  4426. return this._hide.apply( this, arguments );
  4427. } else {
  4428. var args = _normalizeArguments.apply( this, arguments );
  4429. args.mode = "hide";
  4430. return this.effect.call( this, args );
  4431. }
  4432. },
  4433. // jQuery core overloads toggle and creates _toggle
  4434. __toggle: $.fn.toggle,
  4435. toggle: function( speed ) {
  4436. if ( standardSpeed( speed ) || typeof speed === "boolean" || $.isFunction( speed ) ) {
  4437. return this.__toggle.apply( this, arguments );
  4438. } else {
  4439. var args = _normalizeArguments.apply( this, arguments );
  4440. args.mode = "toggle";
  4441. return this.effect.call( this, args );
  4442. }
  4443. },
  4444. // helper functions
  4445. cssUnit: function(key) {
  4446. var style = this.css( key ),
  4447. val = [];
  4448. $.each( [ "em", "px", "%", "pt" ], function( i, unit ) {
  4449. if ( style.indexOf( unit ) > 0 ) {
  4450. val = [ parseFloat( style ), unit ];
  4451. }
  4452. });
  4453. return val;
  4454. }
  4455. });
  4456. })();
  4457. /******************************************************************************/
  4458. /*********************************** EASING ***********************************/
  4459. /******************************************************************************/
  4460. (function() {
  4461. // based on easing equations from Robert Penner (http://www.robertpenner.com/easing)
  4462. var baseEasings = {};
  4463. $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) {
  4464. baseEasings[ name ] = function( p ) {
  4465. return Math.pow( p, i + 2 );
  4466. };
  4467. });
  4468. $.extend( baseEasings, {
  4469. Sine: function ( p ) {
  4470. return 1 - Math.cos( p * Math.PI / 2 );
  4471. },
  4472. Circ: function ( p ) {
  4473. return 1 - Math.sqrt( 1 - p * p );
  4474. },
  4475. Elastic: function( p ) {
  4476. return p === 0 || p === 1 ? p :
  4477. -Math.pow( 2, 8 * (p - 1) ) * Math.sin( ( (p - 1) * 80 - 7.5 ) * Math.PI / 15 );
  4478. },
  4479. Back: function( p ) {
  4480. return p * p * ( 3 * p - 2 );
  4481. },
  4482. Bounce: function ( p ) {
  4483. var pow2,
  4484. bounce = 4;
  4485. while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
  4486. return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
  4487. }
  4488. });
  4489. $.each( baseEasings, function( name, easeIn ) {
  4490. $.easing[ "easeIn" + name ] = easeIn;
  4491. $.easing[ "easeOut" + name ] = function( p ) {
  4492. return 1 - easeIn( 1 - p );
  4493. };
  4494. $.easing[ "easeInOut" + name ] = function( p ) {
  4495. return p < 0.5 ?
  4496. easeIn( p * 2 ) / 2 :
  4497. 1 - easeIn( p * -2 + 2 ) / 2;
  4498. };
  4499. });
  4500. })();
  4501. })(jQuery));
  4502. (function( $, undefined ) {
  4503. var uid = 0,
  4504. hideProps = {},
  4505. showProps = {};
  4506. hideProps.height = hideProps.paddingTop = hideProps.paddingBottom =
  4507. hideProps.borderTopWidth = hideProps.borderBottomWidth = "hide";
  4508. showProps.height = showProps.paddingTop = showProps.paddingBottom =
  4509. showProps.borderTopWidth = showProps.borderBottomWidth = "show";
  4510. $.widget( "ui.accordion", {
  4511. version: "1.9.2",
  4512. options: {
  4513. active: 0,
  4514. animate: {},
  4515. collapsible: false,
  4516. event: "click",
  4517. header: "> li > :first-child,> :not(li):even",
  4518. heightStyle: "auto",
  4519. icons: {
  4520. activeHeader: "ui-icon-triangle-1-s",
  4521. header: "ui-icon-triangle-1-e"
  4522. },
  4523. // callbacks
  4524. activate: null,
  4525. beforeActivate: null
  4526. },
  4527. _create: function() {
  4528. var accordionId = this.accordionId = "ui-accordion-" +
  4529. (this.element.attr( "id" ) || ++uid),
  4530. options = this.options;
  4531. this.prevShow = this.prevHide = $();
  4532. this.element.addClass( "ui-accordion ui-widget ui-helper-reset" );
  4533. this.headers = this.element.find( options.header )
  4534. .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" );
  4535. this._hoverable( this.headers );
  4536. this._focusable( this.headers );
  4537. this.headers.next()
  4538. .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" )
  4539. .hide();
  4540. // don't allow collapsible: false and active: false / null
  4541. if ( !options.collapsible && (options.active === false || options.active == null) ) {
  4542. options.active = 0;
  4543. }
  4544. // handle negative values
  4545. if ( options.active < 0 ) {
  4546. options.active += this.headers.length;
  4547. }
  4548. this.active = this._findActive( options.active )
  4549. .addClass( "ui-accordion-header-active ui-state-active" )
  4550. .toggleClass( "ui-corner-all ui-corner-top" );
  4551. this.active.next()
  4552. .addClass( "ui-accordion-content-active" )
  4553. .show();
  4554. this._createIcons();
  4555. this.refresh();
  4556. // ARIA
  4557. this.element.attr( "role", "tablist" );
  4558. this.headers
  4559. .attr( "role", "tab" )
  4560. .each(function( i ) {
  4561. var header = $( this ),
  4562. headerId = header.attr( "id" ),
  4563. panel = header.next(),
  4564. panelId = panel.attr( "id" );
  4565. if ( !headerId ) {
  4566. headerId = accordionId + "-header-" + i;
  4567. header.attr( "id", headerId );
  4568. }
  4569. if ( !panelId ) {
  4570. panelId = accordionId + "-panel-" + i;
  4571. panel.attr( "id", panelId );
  4572. }
  4573. header.attr( "aria-controls", panelId );
  4574. panel.attr( "aria-labelledby", headerId );
  4575. })
  4576. .next()
  4577. .attr( "role", "tabpanel" );
  4578. this.headers
  4579. .not( this.active )
  4580. .attr({
  4581. "aria-selected": "false",
  4582. tabIndex: -1
  4583. })
  4584. .next()
  4585. .attr({
  4586. "aria-expanded": "false",
  4587. "aria-hidden": "true"
  4588. })
  4589. .hide();
  4590. // make sure at least one header is in the tab order
  4591. if ( !this.active.length ) {
  4592. this.headers.eq( 0 ).attr( "tabIndex", 0 );
  4593. } else {
  4594. this.active.attr({
  4595. "aria-selected": "true",
  4596. tabIndex: 0
  4597. })
  4598. .next()
  4599. .attr({
  4600. "aria-expanded": "true",
  4601. "aria-hidden": "false"
  4602. });
  4603. }
  4604. this._on( this.headers, { keydown: "_keydown" });
  4605. this._on( this.headers.next(), { keydown: "_panelKeyDown" });
  4606. this._setupEvents( options.event );
  4607. },
  4608. _getCreateEventData: function() {
  4609. return {
  4610. header: this.active,
  4611. content: !this.active.length ? $() : this.active.next()
  4612. };
  4613. },
  4614. _createIcons: function() {
  4615. var icons = this.options.icons;
  4616. if ( icons ) {
  4617. $( "<span>" )
  4618. .addClass( "ui-accordion-header-icon ui-icon " + icons.header )
  4619. .prependTo( this.headers );
  4620. this.active.children( ".ui-accordion-header-icon" )
  4621. .removeClass( icons.header )
  4622. .addClass( icons.activeHeader );
  4623. this.headers.addClass( "ui-accordion-icons" );
  4624. }
  4625. },
  4626. _destroyIcons: function() {
  4627. this.headers
  4628. .removeClass( "ui-accordion-icons" )
  4629. .children( ".ui-accordion-header-icon" )
  4630. .remove();
  4631. },
  4632. _destroy: function() {
  4633. var contents;
  4634. // clean up main element
  4635. this.element
  4636. .removeClass( "ui-accordion ui-widget ui-helper-reset" )
  4637. .removeAttr( "role" );
  4638. // clean up headers
  4639. this.headers
  4640. .removeClass( "ui-accordion-header ui-accordion-header-active ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-state-disabled ui-corner-top" )
  4641. .removeAttr( "role" )
  4642. .removeAttr( "aria-selected" )
  4643. .removeAttr( "aria-controls" )
  4644. .removeAttr( "tabIndex" )
  4645. .each(function() {
  4646. if ( /^ui-accordion/.test( this.id ) ) {
  4647. this.removeAttribute( "id" );
  4648. }
  4649. });
  4650. this._destroyIcons();
  4651. // clean up content panels
  4652. contents = this.headers.next()
  4653. .css( "display", "" )
  4654. .removeAttr( "role" )
  4655. .removeAttr( "aria-expanded" )
  4656. .removeAttr( "aria-hidden" )
  4657. .removeAttr( "aria-labelledby" )
  4658. .removeClass( "ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active ui-state-disabled" )
  4659. .each(function() {
  4660. if ( /^ui-accordion/.test( this.id ) ) {
  4661. this.removeAttribute( "id" );
  4662. }
  4663. });
  4664. if ( this.options.heightStyle !== "content" ) {
  4665. contents.css( "height", "" );
  4666. }
  4667. },
  4668. _setOption: function( key, value ) {
  4669. if ( key === "active" ) {
  4670. // _activate() will handle invalid values and update this.options
  4671. this._activate( value );
  4672. return;
  4673. }
  4674. if ( key === "event" ) {
  4675. if ( this.options.event ) {
  4676. this._off( this.headers, this.options.event );
  4677. }
  4678. this._setupEvents( value );
  4679. }
  4680. this._super( key, value );
  4681. // setting collapsible: false while collapsed; open first panel
  4682. if ( key === "collapsible" && !value && this.options.active === false ) {
  4683. this._activate( 0 );
  4684. }
  4685. if ( key === "icons" ) {
  4686. this._destroyIcons();
  4687. if ( value ) {
  4688. this._createIcons();
  4689. }
  4690. }
  4691. // #5332 - opacity doesn't cascade to positioned elements in IE
  4692. // so we need to add the disabled class to the headers and panels
  4693. if ( key === "disabled" ) {
  4694. this.headers.add( this.headers.next() )
  4695. .toggleClass( "ui-state-disabled", !!value );
  4696. }
  4697. },
  4698. _keydown: function( event ) {
  4699. if ( event.altKey || event.ctrlKey ) {
  4700. return;
  4701. }
  4702. var keyCode = $.ui.keyCode,
  4703. length = this.headers.length,
  4704. currentIndex = this.headers.index( event.target ),
  4705. toFocus = false;
  4706. switch ( event.keyCode ) {
  4707. case keyCode.RIGHT:
  4708. case keyCode.DOWN:
  4709. toFocus = this.headers[ ( currentIndex + 1 ) % length ];
  4710. break;
  4711. case keyCode.LEFT:
  4712. case keyCode.UP:
  4713. toFocus = this.headers[ ( currentIndex - 1 + length ) % length ];
  4714. break;
  4715. case keyCode.SPACE:
  4716. case keyCode.ENTER:
  4717. this._eventHandler( event );
  4718. break;
  4719. case keyCode.HOME:
  4720. toFocus = this.headers[ 0 ];
  4721. break;
  4722. case keyCode.END:
  4723. toFocus = this.headers[ length - 1 ];
  4724. break;
  4725. }
  4726. if ( toFocus ) {
  4727. $( event.target ).attr( "tabIndex", -1 );
  4728. $( toFocus ).attr( "tabIndex", 0 );
  4729. toFocus.focus();
  4730. event.preventDefault();
  4731. }
  4732. },
  4733. _panelKeyDown : function( event ) {
  4734. if ( event.keyCode === $.ui.keyCode.UP && event.ctrlKey ) {
  4735. $( event.currentTarget ).prev().focus();
  4736. }
  4737. },
  4738. refresh: function() {
  4739. var maxHeight, overflow,
  4740. heightStyle = this.options.heightStyle,
  4741. parent = this.element.parent();
  4742. if ( heightStyle === "fill" ) {
  4743. // IE 6 treats height like minHeight, so we need to turn off overflow
  4744. // in order to get a reliable height
  4745. // we use the minHeight support test because we assume that only
  4746. // browsers that don't support minHeight will treat height as minHeight
  4747. if ( !$.support.minHeight ) {
  4748. overflow = parent.css( "overflow" );
  4749. parent.css( "overflow", "hidden");
  4750. }
  4751. maxHeight = parent.height();
  4752. this.element.siblings( ":visible" ).each(function() {
  4753. var elem = $( this ),
  4754. position = elem.css( "position" );
  4755. if ( position === "absolute" || position === "fixed" ) {
  4756. return;
  4757. }
  4758. maxHeight -= elem.outerHeight( true );
  4759. });
  4760. if ( overflow ) {
  4761. parent.css( "overflow", overflow );
  4762. }
  4763. this.headers.each(function() {
  4764. maxHeight -= $( this ).outerHeight( true );
  4765. });
  4766. this.headers.next()
  4767. .each(function() {
  4768. $( this ).height( Math.max( 0, maxHeight -
  4769. $( this ).innerHeight() + $( this ).height() ) );
  4770. })
  4771. .css( "overflow", "auto" );
  4772. } else if ( heightStyle === "auto" ) {
  4773. maxHeight = 0;
  4774. this.headers.next()
  4775. .each(function() {
  4776. maxHeight = Math.max( maxHeight, $( this ).css( "height", "" ).height() );
  4777. })
  4778. .height( maxHeight );
  4779. }
  4780. },
  4781. _activate: function( index ) {
  4782. var active = this._findActive( index )[ 0 ];
  4783. // trying to activate the already active panel
  4784. if ( active === this.active[ 0 ] ) {
  4785. return;
  4786. }
  4787. // trying to collapse, simulate a click on the currently active header
  4788. active = active || this.active[ 0 ];
  4789. this._eventHandler({
  4790. target: active,
  4791. currentTarget: active,
  4792. preventDefault: $.noop
  4793. });
  4794. },
  4795. _findActive: function( selector ) {
  4796. return typeof selector === "number" ? this.headers.eq( selector ) : $();
  4797. },
  4798. _setupEvents: function( event ) {
  4799. var events = {};
  4800. if ( !event ) {
  4801. return;
  4802. }
  4803. $.each( event.split(" "), function( index, eventName ) {
  4804. events[ eventName ] = "_eventHandler";
  4805. });
  4806. this._on( this.headers, events );
  4807. },
  4808. _eventHandler: function( event ) {
  4809. var options = this.options,
  4810. active = this.active,
  4811. clicked = $( event.currentTarget ),
  4812. clickedIsActive = clicked[ 0 ] === active[ 0 ],
  4813. collapsing = clickedIsActive && options.collapsible,
  4814. toShow = collapsing ? $() : clicked.next(),
  4815. toHide = active.next(),
  4816. eventData = {
  4817. oldHeader: active,
  4818. oldPanel: toHide,
  4819. newHeader: collapsing ? $() : clicked,
  4820. newPanel: toShow
  4821. };
  4822. event.preventDefault();
  4823. if (
  4824. // click on active header, but not collapsible
  4825. ( clickedIsActive && !options.collapsible ) ||
  4826. // allow canceling activation
  4827. ( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
  4828. return;
  4829. }
  4830. options.active = collapsing ? false : this.headers.index( clicked );
  4831. // when the call to ._toggle() comes after the class changes
  4832. // it causes a very odd bug in IE 8 (see #6720)
  4833. this.active = clickedIsActive ? $() : clicked;
  4834. this._toggle( eventData );
  4835. // switch classes
  4836. // corner classes on the previously active header stay after the animation
  4837. active.removeClass( "ui-accordion-header-active ui-state-active" );
  4838. if ( options.icons ) {
  4839. active.children( ".ui-accordion-header-icon" )
  4840. .removeClass( options.icons.activeHeader )
  4841. .addClass( options.icons.header );
  4842. }
  4843. if ( !clickedIsActive ) {
  4844. clicked
  4845. .removeClass( "ui-corner-all" )
  4846. .addClass( "ui-accordion-header-active ui-state-active ui-corner-top" );
  4847. if ( options.icons ) {
  4848. clicked.children( ".ui-accordion-header-icon" )
  4849. .removeClass( options.icons.header )
  4850. .addClass( options.icons.activeHeader );
  4851. }
  4852. clicked
  4853. .next()
  4854. .addClass( "ui-accordion-content-active" );
  4855. }
  4856. },
  4857. _toggle: function( data ) {
  4858. var toShow = data.newPanel,
  4859. toHide = this.prevShow.length ? this.prevShow : data.oldPanel;
  4860. // handle activating a panel during the animation for another activation
  4861. this.prevShow.add( this.prevHide ).stop( true, true );
  4862. this.prevShow = toShow;
  4863. this.prevHide = toHide;
  4864. if ( this.options.animate ) {
  4865. this._animate( toShow, toHide, data );
  4866. } else {
  4867. toHide.hide();
  4868. toShow.show();
  4869. this._toggleComplete( data );
  4870. }
  4871. toHide.attr({
  4872. "aria-expanded": "false",
  4873. "aria-hidden": "true"
  4874. });
  4875. toHide.prev().attr( "aria-selected", "false" );
  4876. // if we're switching panels, remove the old header from the tab order
  4877. // if we're opening from collapsed state, remove the previous header from the tab order
  4878. // if we're collapsing, then keep the collapsing header in the tab order
  4879. if ( toShow.length && toHide.length ) {
  4880. toHide.prev().attr( "tabIndex", -1 );
  4881. } else if ( toShow.length ) {
  4882. this.headers.filter(function() {
  4883. return $( this ).attr( "tabIndex" ) === 0;
  4884. })
  4885. .attr( "tabIndex", -1 );
  4886. }
  4887. toShow
  4888. .attr({
  4889. "aria-expanded": "true",
  4890. "aria-hidden": "false"
  4891. })
  4892. .prev()
  4893. .attr({
  4894. "aria-selected": "true",
  4895. tabIndex: 0
  4896. });
  4897. },
  4898. _animate: function( toShow, toHide, data ) {
  4899. var total, easing, duration,
  4900. that = this,
  4901. adjust = 0,
  4902. down = toShow.length &&
  4903. ( !toHide.length || ( toShow.index() < toHide.index() ) ),
  4904. animate = this.options.animate || {},
  4905. options = down && animate.down || animate,
  4906. complete = function() {
  4907. that._toggleComplete( data );
  4908. };
  4909. if ( typeof options === "number" ) {
  4910. duration = options;
  4911. }
  4912. if ( typeof options === "string" ) {
  4913. easing = options;
  4914. }
  4915. // fall back from options to animation in case of partial down settings
  4916. easing = easing || options.easing || animate.easing;
  4917. duration = duration || options.duration || animate.duration;
  4918. if ( !toHide.length ) {
  4919. return toShow.animate( showProps, duration, easing, complete );
  4920. }
  4921. if ( !toShow.length ) {
  4922. return toHide.animate( hideProps, duration, easing, complete );
  4923. }
  4924. total = toShow.show().outerHeight();
  4925. toHide.animate( hideProps, {
  4926. duration: duration,
  4927. easing: easing,
  4928. step: function( now, fx ) {
  4929. fx.now = Math.round( now );
  4930. }
  4931. });
  4932. toShow
  4933. .hide()
  4934. .animate( showProps, {
  4935. duration: duration,
  4936. easing: easing,
  4937. complete: complete,
  4938. step: function( now, fx ) {
  4939. fx.now = Math.round( now );
  4940. if ( fx.prop !== "height" ) {
  4941. adjust += fx.now;
  4942. } else if ( that.options.heightStyle !== "content" ) {
  4943. fx.now = Math.round( total - toHide.outerHeight() - adjust );
  4944. adjust = 0;
  4945. }
  4946. }
  4947. });
  4948. },
  4949. _toggleComplete: function( data ) {
  4950. var toHide = data.oldPanel;
  4951. toHide
  4952. .removeClass( "ui-accordion-content-active" )
  4953. .prev()
  4954. .removeClass( "ui-corner-top" )
  4955. .addClass( "ui-corner-all" );
  4956. // Work around for rendering bug in IE (#5421)
  4957. if ( toHide.length ) {
  4958. toHide.parent()[0].className = toHide.parent()[0].className;
  4959. }
  4960. this._trigger( "activate", null, data );
  4961. }
  4962. });
  4963. // DEPRECATED
  4964. if ( $.uiBackCompat !== false ) {
  4965. // navigation options
  4966. (function( $, prototype ) {
  4967. $.extend( prototype.options, {
  4968. navigation: false,
  4969. navigationFilter: function() {
  4970. return this.href.toLowerCase() === location.href.toLowerCase();
  4971. }
  4972. });
  4973. var _create = prototype._create;
  4974. prototype._create = function() {
  4975. if ( this.options.navigation ) {
  4976. var that = this,
  4977. headers = this.element.find( this.options.header ),
  4978. content = headers.next(),
  4979. current = headers.add( content )
  4980. .find( "a" )
  4981. .filter( this.options.navigationFilter )
  4982. [ 0 ];
  4983. if ( current ) {
  4984. headers.add( content ).each( function( index ) {
  4985. if ( $.contains( this, current ) ) {
  4986. that.options.active = Math.floor( index / 2 );
  4987. return false;
  4988. }
  4989. });
  4990. }
  4991. }
  4992. _create.call( this );
  4993. };
  4994. }( jQuery, jQuery.ui.accordion.prototype ) );
  4995. // height options
  4996. (function( $, prototype ) {
  4997. $.extend( prototype.options, {
  4998. heightStyle: null, // remove default so we fall back to old values
  4999. autoHeight: true, // use heightStyle: "auto"
  5000. clearStyle: false, // use heightStyle: "content"
  5001. fillSpace: false // use heightStyle: "fill"
  5002. });
  5003. var _create = prototype._create,
  5004. _setOption = prototype._setOption;
  5005. $.extend( prototype, {
  5006. _create: function() {
  5007. this.options.heightStyle = this.options.heightStyle ||
  5008. this._mergeHeightStyle();
  5009. _create.call( this );
  5010. },
  5011. _setOption: function( key ) {
  5012. if ( key === "autoHeight" || key === "clearStyle" || key === "fillSpace" ) {
  5013. this.options.heightStyle = this._mergeHeightStyle();
  5014. }
  5015. _setOption.apply( this, arguments );
  5016. },
  5017. _mergeHeightStyle: function() {
  5018. var options = this.options;
  5019. if ( options.fillSpace ) {
  5020. return "fill";
  5021. }
  5022. if ( options.clearStyle ) {
  5023. return "content";
  5024. }
  5025. if ( options.autoHeight ) {
  5026. return "auto";
  5027. }
  5028. }
  5029. });
  5030. }( jQuery, jQuery.ui.accordion.prototype ) );
  5031. // icon options
  5032. (function( $, prototype ) {
  5033. $.extend( prototype.options.icons, {
  5034. activeHeader: null, // remove default so we fall back to old values
  5035. headerSelected: "ui-icon-triangle-1-s"
  5036. });
  5037. var _createIcons = prototype._createIcons;
  5038. prototype._createIcons = function() {
  5039. if ( this.options.icons ) {
  5040. this.options.icons.activeHeader = this.options.icons.activeHeader ||
  5041. this.options.icons.headerSelected;
  5042. }
  5043. _createIcons.call( this );
  5044. };
  5045. }( jQuery, jQuery.ui.accordion.prototype ) );
  5046. // expanded active option, activate method
  5047. (function( $, prototype ) {
  5048. prototype.activate = prototype._activate;
  5049. var _findActive = prototype._findActive;
  5050. prototype._findActive = function( index ) {
  5051. if ( index === -1 ) {
  5052. index = false;
  5053. }
  5054. if ( index && typeof index !== "number" ) {
  5055. index = this.headers.index( this.headers.filter( index ) );
  5056. if ( index === -1 ) {
  5057. index = false;
  5058. }
  5059. }
  5060. return _findActive.call( this, index );
  5061. };
  5062. }( jQuery, jQuery.ui.accordion.prototype ) );
  5063. // resize method
  5064. jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh;
  5065. // change events
  5066. (function( $, prototype ) {
  5067. $.extend( prototype.options, {
  5068. change: null,
  5069. changestart: null
  5070. });
  5071. var _trigger = prototype._trigger;
  5072. prototype._trigger = function( type, event, data ) {
  5073. var ret = _trigger.apply( this, arguments );
  5074. if ( !ret ) {
  5075. return false;
  5076. }
  5077. if ( type === "beforeActivate" ) {
  5078. ret = _trigger.call( this, "changestart", event, {
  5079. oldHeader: data.oldHeader,
  5080. oldContent: data.oldPanel,
  5081. newHeader: data.newHeader,
  5082. newContent: data.newPanel
  5083. });
  5084. } else if ( type === "activate" ) {
  5085. ret = _trigger.call( this, "change", event, {
  5086. oldHeader: data.oldHeader,
  5087. oldContent: data.oldPanel,
  5088. newHeader: data.newHeader,
  5089. newContent: data.newPanel
  5090. });
  5091. }
  5092. return ret;
  5093. };
  5094. }( jQuery, jQuery.ui.accordion.prototype ) );
  5095. // animated option
  5096. // NOTE: this only provides support for "slide", "bounceslide", and easings
  5097. // not the full $.ui.accordion.animations API
  5098. (function( $, prototype ) {
  5099. $.extend( prototype.options, {
  5100. animate: null,
  5101. animated: "slide"
  5102. });
  5103. var _create = prototype._create;
  5104. prototype._create = function() {
  5105. var options = this.options;
  5106. if ( options.animate === null ) {
  5107. if ( !options.animated ) {
  5108. options.animate = false;
  5109. } else if ( options.animated === "slide" ) {
  5110. options.animate = 300;
  5111. } else if ( options.animated === "bounceslide" ) {
  5112. options.animate = {
  5113. duration: 200,
  5114. down: {
  5115. easing: "easeOutBounce",
  5116. duration: 1000
  5117. }
  5118. };
  5119. } else {
  5120. options.animate = options.animated;
  5121. }
  5122. }
  5123. _create.call( this );
  5124. };
  5125. }( jQuery, jQuery.ui.accordion.prototype ) );
  5126. }
  5127. })( jQuery );
  5128. (function( $, undefined ) {
  5129. // used to prevent race conditions with remote data sources
  5130. var requestIndex = 0;
  5131. $.widget( "ui.autocomplete", {
  5132. version: "1.9.2",
  5133. defaultElement: "<input>",
  5134. options: {
  5135. appendTo: "body",
  5136. autoFocus: false,
  5137. delay: 300,
  5138. minLength: 1,
  5139. position: {
  5140. my: "left top",
  5141. at: "left bottom",
  5142. collision: "none"
  5143. },
  5144. source: null,
  5145. // callbacks
  5146. change: null,
  5147. close: null,
  5148. focus: null,
  5149. open: null,
  5150. response: null,
  5151. search: null,
  5152. select: null
  5153. },
  5154. pending: 0,
  5155. _create: function() {
  5156. // Some browsers only repeat keydown events, not keypress events,
  5157. // so we use the suppressKeyPress flag to determine if we've already
  5158. // handled the keydown event. #7269
  5159. // Unfortunately the code for & in keypress is the same as the up arrow,
  5160. // so we use the suppressKeyPressRepeat flag to avoid handling keypress
  5161. // events when we know the keydown event was used to modify the
  5162. // search term. #7799
  5163. var suppressKeyPress, suppressKeyPressRepeat, suppressInput;
  5164. this.isMultiLine = this._isMultiLine();
  5165. this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ];
  5166. this.isNewMenu = true;
  5167. this.element
  5168. .addClass( "ui-autocomplete-input" )
  5169. .attr( "autocomplete", "off" );
  5170. this._on( this.element, {
  5171. keydown: function( event ) {
  5172. if ( this.element.prop( "readOnly" ) ) {
  5173. suppressKeyPress = true;
  5174. suppressInput = true;
  5175. suppressKeyPressRepeat = true;
  5176. return;
  5177. }
  5178. suppressKeyPress = false;
  5179. suppressInput = false;
  5180. suppressKeyPressRepeat = false;
  5181. var keyCode = $.ui.keyCode;
  5182. switch( event.keyCode ) {
  5183. case keyCode.PAGE_UP:
  5184. suppressKeyPress = true;
  5185. this._move( "previousPage", event );
  5186. break;
  5187. case keyCode.PAGE_DOWN:
  5188. suppressKeyPress = true;
  5189. this._move( "nextPage", event );
  5190. break;
  5191. case keyCode.UP:
  5192. suppressKeyPress = true;
  5193. this._keyEvent( "previous", event );
  5194. break;
  5195. case keyCode.DOWN:
  5196. suppressKeyPress = true;
  5197. this._keyEvent( "next", event );
  5198. break;
  5199. case keyCode.ENTER:
  5200. case keyCode.NUMPAD_ENTER:
  5201. // when menu is open and has focus
  5202. if ( this.menu.active ) {
  5203. // #6055 - Opera still allows the keypress to occur
  5204. // which causes forms to submit
  5205. suppressKeyPress = true;
  5206. event.preventDefault();
  5207. this.menu.select( event );
  5208. }
  5209. break;
  5210. case keyCode.TAB:
  5211. if ( this.menu.active ) {
  5212. this.menu.select( event );
  5213. }
  5214. break;
  5215. case keyCode.ESCAPE:
  5216. if ( this.menu.element.is( ":visible" ) ) {
  5217. this._value( this.term );
  5218. this.close( event );
  5219. // Different browsers have different default behavior for escape
  5220. // Single press can mean undo or clear
  5221. // Double press in IE means clear the whole form
  5222. event.preventDefault();
  5223. }
  5224. break;
  5225. default:
  5226. suppressKeyPressRepeat = true;
  5227. // search timeout should be triggered before the input value is changed
  5228. this._searchTimeout( event );
  5229. break;
  5230. }
  5231. },
  5232. keypress: function( event ) {
  5233. if ( suppressKeyPress ) {
  5234. suppressKeyPress = false;
  5235. event.preventDefault();
  5236. return;
  5237. }
  5238. if ( suppressKeyPressRepeat ) {
  5239. return;
  5240. }
  5241. // replicate some key handlers to allow them to repeat in Firefox and Opera
  5242. var keyCode = $.ui.keyCode;
  5243. switch( event.keyCode ) {
  5244. case keyCode.PAGE_UP:
  5245. this._move( "previousPage", event );
  5246. break;
  5247. case keyCode.PAGE_DOWN:
  5248. this._move( "nextPage", event );
  5249. break;
  5250. case keyCode.UP:
  5251. this._keyEvent( "previous", event );
  5252. break;
  5253. case keyCode.DOWN:
  5254. this._keyEvent( "next", event );
  5255. break;
  5256. }
  5257. },
  5258. input: function( event ) {
  5259. if ( suppressInput ) {
  5260. suppressInput = false;
  5261. event.preventDefault();
  5262. return;
  5263. }
  5264. this._searchTimeout( event );
  5265. },
  5266. focus: function() {
  5267. this.selectedItem = null;
  5268. this.previous = this._value();
  5269. },
  5270. blur: function( event ) {
  5271. if ( this.cancelBlur ) {
  5272. delete this.cancelBlur;
  5273. return;
  5274. }
  5275. clearTimeout( this.searching );
  5276. this.close( event );
  5277. this._change( event );
  5278. }
  5279. });
  5280. this._initSource();
  5281. this.menu = $( "<ul>" )
  5282. .addClass( "ui-autocomplete" )
  5283. .appendTo( this.document.find( this.options.appendTo || "body" )[ 0 ] )
  5284. .menu({
  5285. // custom key handling for now
  5286. input: $(),
  5287. // disable ARIA support, the live region takes care of that
  5288. role: null
  5289. })
  5290. .zIndex( this.element.zIndex() + 1 )
  5291. .hide()
  5292. .data( "menu" );
  5293. this._on( this.menu.element, {
  5294. mousedown: function( event ) {
  5295. // prevent moving focus out of the text field
  5296. event.preventDefault();
  5297. // IE doesn't prevent moving focus even with event.preventDefault()
  5298. // so we set a flag to know when we should ignore the blur event
  5299. this.cancelBlur = true;
  5300. this._delay(function() {
  5301. delete this.cancelBlur;
  5302. });
  5303. // clicking on the scrollbar causes focus to shift to the body
  5304. // but we can't detect a mouseup or a click immediately afterward
  5305. // so we have to track the next mousedown and close the menu if
  5306. // the user clicks somewhere outside of the autocomplete
  5307. var menuElement = this.menu.element[ 0 ];
  5308. if ( !$( event.target ).closest( ".ui-menu-item" ).length ) {
  5309. this._delay(function() {
  5310. var that = this;
  5311. this.document.one( "mousedown", function( event ) {
  5312. if ( event.target !== that.element[ 0 ] &&
  5313. event.target !== menuElement &&
  5314. !$.contains( menuElement, event.target ) ) {
  5315. that.close();
  5316. }
  5317. });
  5318. });
  5319. }
  5320. },
  5321. menufocus: function( event, ui ) {
  5322. // #7024 - Prevent accidental activation of menu items in Firefox
  5323. if ( this.isNewMenu ) {
  5324. this.isNewMenu = false;
  5325. if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) {
  5326. this.menu.blur();
  5327. this.document.one( "mousemove", function() {
  5328. $( event.target ).trigger( event.originalEvent );
  5329. });
  5330. return;
  5331. }
  5332. }
  5333. // back compat for _renderItem using item.autocomplete, via #7810
  5334. // TODO remove the fallback, see #8156
  5335. var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" );
  5336. if ( false !== this._trigger( "focus", event, { item: item } ) ) {
  5337. // use value to match what will end up in the input, if it was a key event
  5338. if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
  5339. this._value( item.value );
  5340. }
  5341. } else {
  5342. // Normally the input is populated with the item's value as the
  5343. // menu is navigated, causing screen readers to notice a change and
  5344. // announce the item. Since the focus event was canceled, this doesn't
  5345. // happen, so we update the live region so that screen readers can
  5346. // still notice the change and announce it.
  5347. this.liveRegion.text( item.value );
  5348. }
  5349. },
  5350. menuselect: function( event, ui ) {
  5351. // back compat for _renderItem using item.autocomplete, via #7810
  5352. // TODO remove the fallback, see #8156
  5353. var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" ),
  5354. previous = this.previous;
  5355. // only trigger when focus was lost (click on menu)
  5356. if ( this.element[0] !== this.document[0].activeElement ) {
  5357. this.element.focus();
  5358. this.previous = previous;
  5359. // #6109 - IE triggers two focus events and the second
  5360. // is asynchronous, so we need to reset the previous
  5361. // term synchronously and asynchronously :-(
  5362. this._delay(function() {
  5363. this.previous = previous;
  5364. this.selectedItem = item;
  5365. });
  5366. }
  5367. if ( false !== this._trigger( "select", event, { item: item } ) ) {
  5368. this._value( item.value );
  5369. }
  5370. // reset the term after the select event
  5371. // this allows custom select handling to work properly
  5372. this.term = this._value();
  5373. this.close( event );
  5374. this.selectedItem = item;
  5375. }
  5376. });
  5377. this.liveRegion = $( "<span>", {
  5378. role: "status",
  5379. "aria-live": "polite"
  5380. })
  5381. .addClass( "ui-helper-hidden-accessible" )
  5382. .insertAfter( this.element );
  5383. if ( $.fn.bgiframe ) {
  5384. this.menu.element.bgiframe();
  5385. }
  5386. // turning off autocomplete prevents the browser from remembering the
  5387. // value when navigating through history, so we re-enable autocomplete
  5388. // if the page is unloaded before the widget is destroyed. #7790
  5389. this._on( this.window, {
  5390. beforeunload: function() {
  5391. this.element.removeAttr( "autocomplete" );
  5392. }
  5393. });
  5394. },
  5395. _destroy: function() {
  5396. clearTimeout( this.searching );
  5397. this.element
  5398. .removeClass( "ui-autocomplete-input" )
  5399. .removeAttr( "autocomplete" );
  5400. this.menu.element.remove();
  5401. this.liveRegion.remove();
  5402. },
  5403. _setOption: function( key, value ) {
  5404. this._super( key, value );
  5405. if ( key === "source" ) {
  5406. this._initSource();
  5407. }
  5408. if ( key === "appendTo" ) {
  5409. this.menu.element.appendTo( this.document.find( value || "body" )[0] );
  5410. }
  5411. if ( key === "disabled" && value && this.xhr ) {
  5412. this.xhr.abort();
  5413. }
  5414. },
  5415. _isMultiLine: function() {
  5416. // Textareas are always multi-line
  5417. if ( this.element.is( "textarea" ) ) {
  5418. return true;
  5419. }
  5420. // Inputs are always single-line, even if inside a contentEditable element
  5421. // IE also treats inputs as contentEditable
  5422. if ( this.element.is( "input" ) ) {
  5423. return false;
  5424. }
  5425. // All other element types are determined by whether or not they're contentEditable
  5426. return this.element.prop( "isContentEditable" );
  5427. },
  5428. _initSource: function() {
  5429. var array, url,
  5430. that = this;
  5431. if ( $.isArray(this.options.source) ) {
  5432. array = this.options.source;
  5433. this.source = function( request, response ) {
  5434. response( $.ui.autocomplete.filter( array, request.term ) );
  5435. };
  5436. } else if ( typeof this.options.source === "string" ) {
  5437. url = this.options.source;
  5438. this.source = function( request, response ) {
  5439. if ( that.xhr ) {
  5440. that.xhr.abort();
  5441. }
  5442. that.xhr = $.ajax({
  5443. url: url,
  5444. data: request,
  5445. dataType: "json",
  5446. success: function( data ) {
  5447. response( data );
  5448. },
  5449. error: function() {
  5450. response( [] );
  5451. }
  5452. });
  5453. };
  5454. } else {
  5455. this.source = this.options.source;
  5456. }
  5457. },
  5458. _searchTimeout: function( event ) {
  5459. clearTimeout( this.searching );
  5460. this.searching = this._delay(function() {
  5461. // only search if the value has changed
  5462. if ( this.term !== this._value() ) {
  5463. this.selectedItem = null;
  5464. this.search( null, event );
  5465. }
  5466. }, this.options.delay );
  5467. },
  5468. search: function( value, event ) {
  5469. value = value != null ? value : this._value();
  5470. // always save the actual value, not the one passed as an argument
  5471. this.term = this._value();
  5472. if ( value.length < this.options.minLength ) {
  5473. return this.close( event );
  5474. }
  5475. if ( this._trigger( "search", event ) === false ) {
  5476. return;
  5477. }
  5478. return this._search( value );
  5479. },
  5480. _search: function( value ) {
  5481. this.pending++;
  5482. this.element.addClass( "ui-autocomplete-loading" );
  5483. this.cancelSearch = false;
  5484. this.source( { term: value }, this._response() );
  5485. },
  5486. _response: function() {
  5487. var that = this,
  5488. index = ++requestIndex;
  5489. return function( content ) {
  5490. if ( index === requestIndex ) {
  5491. that.__response( content );
  5492. }
  5493. that.pending--;
  5494. if ( !that.pending ) {
  5495. that.element.removeClass( "ui-autocomplete-loading" );
  5496. }
  5497. };
  5498. },
  5499. __response: function( content ) {
  5500. if ( content ) {
  5501. content = this._normalize( content );
  5502. }
  5503. this._trigger( "response", null, { content: content } );
  5504. if ( !this.options.disabled && content && content.length && !this.cancelSearch ) {
  5505. this._suggest( content );
  5506. this._trigger( "open" );
  5507. } else {
  5508. // use ._close() instead of .close() so we don't cancel future searches
  5509. this._close();
  5510. }
  5511. },
  5512. close: function( event ) {
  5513. this.cancelSearch = true;
  5514. this._close( event );
  5515. },
  5516. _close: function( event ) {
  5517. if ( this.menu.element.is( ":visible" ) ) {
  5518. this.menu.element.hide();
  5519. this.menu.blur();
  5520. this.isNewMenu = true;
  5521. this._trigger( "close", event );
  5522. }
  5523. },
  5524. _change: function( event ) {
  5525. if ( this.previous !== this._value() ) {
  5526. this._trigger( "change", event, { item: this.selectedItem } );
  5527. }
  5528. },
  5529. _normalize: function( items ) {
  5530. // assume all items have the right format when the first item is complete
  5531. if ( items.length && items[0].label && items[0].value ) {
  5532. return items;
  5533. }
  5534. return $.map( items, function( item ) {
  5535. if ( typeof item === "string" ) {
  5536. return {
  5537. label: item,
  5538. value: item
  5539. };
  5540. }
  5541. return $.extend({
  5542. label: item.label || item.value,
  5543. value: item.value || item.label
  5544. }, item );
  5545. });
  5546. },
  5547. _suggest: function( items ) {
  5548. var ul = this.menu.element
  5549. .empty()
  5550. .zIndex( this.element.zIndex() + 1 );
  5551. this._renderMenu( ul, items );
  5552. this.menu.refresh();
  5553. // size and position menu
  5554. ul.show();
  5555. this._resizeMenu();
  5556. ul.position( $.extend({
  5557. of: this.element
  5558. }, this.options.position ));
  5559. if ( this.options.autoFocus ) {
  5560. this.menu.next();
  5561. }
  5562. },
  5563. _resizeMenu: function() {
  5564. var ul = this.menu.element;
  5565. ul.outerWidth( Math.max(
  5566. // Firefox wraps long text (possibly a rounding bug)
  5567. // so we add 1px to avoid the wrapping (#7513)
  5568. ul.width( "" ).outerWidth() + 1,
  5569. this.element.outerWidth()
  5570. ) );
  5571. },
  5572. _renderMenu: function( ul, items ) {
  5573. var that = this;
  5574. $.each( items, function( index, item ) {
  5575. that._renderItemData( ul, item );
  5576. });
  5577. },
  5578. _renderItemData: function( ul, item ) {
  5579. return this._renderItem( ul, item ).data( "ui-autocomplete-item", item );
  5580. },
  5581. _renderItem: function( ul, item ) {
  5582. return $( "<li>" )
  5583. .append( $( "<a>" ).text( item.label ) )
  5584. .appendTo( ul );
  5585. },
  5586. _move: function( direction, event ) {
  5587. if ( !this.menu.element.is( ":visible" ) ) {
  5588. this.search( null, event );
  5589. return;
  5590. }
  5591. if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
  5592. this.menu.isLastItem() && /^next/.test( direction ) ) {
  5593. this._value( this.term );
  5594. this.menu.blur();
  5595. return;
  5596. }
  5597. this.menu[ direction ]( event );
  5598. },
  5599. widget: function() {
  5600. return this.menu.element;
  5601. },
  5602. _value: function() {
  5603. return this.valueMethod.apply( this.element, arguments );
  5604. },
  5605. _keyEvent: function( keyEvent, event ) {
  5606. if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
  5607. this._move( keyEvent, event );
  5608. // prevents moving cursor to beginning/end of the text field in some browsers
  5609. event.preventDefault();
  5610. }
  5611. }
  5612. });
  5613. $.extend( $.ui.autocomplete, {
  5614. escapeRegex: function( value ) {
  5615. return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
  5616. },
  5617. filter: function(array, term) {
  5618. var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
  5619. return $.grep( array, function(value) {
  5620. return matcher.test( value.label || value.value || value );
  5621. });
  5622. }
  5623. });
  5624. // live region extension, adding a `messages` option
  5625. // NOTE: This is an experimental API. We are still investigating
  5626. // a full solution for string manipulation and internationalization.
  5627. $.widget( "ui.autocomplete", $.ui.autocomplete, {
  5628. options: {
  5629. messages: {
  5630. noResults: "No search results.",
  5631. results: function( amount ) {
  5632. return amount + ( amount > 1 ? " results are" : " result is" ) +
  5633. " available, use up and down arrow keys to navigate.";
  5634. }
  5635. }
  5636. },
  5637. __response: function( content ) {
  5638. var message;
  5639. this._superApply( arguments );
  5640. if ( this.options.disabled || this.cancelSearch ) {
  5641. return;
  5642. }
  5643. if ( content && content.length ) {
  5644. message = this.options.messages.results( content.length );
  5645. } else {
  5646. message = this.options.messages.noResults;
  5647. }
  5648. this.liveRegion.text( message );
  5649. }
  5650. });
  5651. }( jQuery ));
  5652. (function( $, undefined ) {
  5653. var lastActive, startXPos, startYPos, clickDragged,
  5654. baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
  5655. stateClasses = "ui-state-hover ui-state-active ",
  5656. 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",
  5657. formResetHandler = function() {
  5658. var buttons = $( this ).find( ":ui-button" );
  5659. setTimeout(function() {
  5660. buttons.button( "refresh" );
  5661. }, 1 );
  5662. },
  5663. radioGroup = function( radio ) {
  5664. var name = radio.name,
  5665. form = radio.form,
  5666. radios = $( [] );
  5667. if ( name ) {
  5668. if ( form ) {
  5669. radios = $( form ).find( "[name='" + name + "']" );
  5670. } else {
  5671. radios = $( "[name='" + name + "']", radio.ownerDocument )
  5672. .filter(function() {
  5673. return !this.form;
  5674. });
  5675. }
  5676. }
  5677. return radios;
  5678. };
  5679. $.widget( "ui.button", {
  5680. version: "1.9.2",
  5681. defaultElement: "<button>",
  5682. options: {
  5683. disabled: null,
  5684. text: true,
  5685. label: null,
  5686. icons: {
  5687. primary: null,
  5688. secondary: null
  5689. }
  5690. },
  5691. _create: function() {
  5692. this.element.closest( "form" )
  5693. .unbind( "reset" + this.eventNamespace )
  5694. .bind( "reset" + this.eventNamespace, formResetHandler );
  5695. if ( typeof this.options.disabled !== "boolean" ) {
  5696. this.options.disabled = !!this.element.prop( "disabled" );
  5697. } else {
  5698. this.element.prop( "disabled", this.options.disabled );
  5699. }
  5700. this._determineButtonType();
  5701. this.hasTitle = !!this.buttonElement.attr( "title" );
  5702. var that = this,
  5703. options = this.options,
  5704. toggleButton = this.type === "checkbox" || this.type === "radio",
  5705. activeClass = !toggleButton ? "ui-state-active" : "",
  5706. focusClass = "ui-state-focus";
  5707. if ( options.label === null ) {
  5708. options.label = (this.type === "input" ? this.buttonElement.val() : this.buttonElement.html());
  5709. }
  5710. this._hoverable( this.buttonElement );
  5711. this.buttonElement
  5712. .addClass( baseClasses )
  5713. .attr( "role", "button" )
  5714. .bind( "mouseenter" + this.eventNamespace, function() {
  5715. if ( options.disabled ) {
  5716. return;
  5717. }
  5718. if ( this === lastActive ) {
  5719. $( this ).addClass( "ui-state-active" );
  5720. }
  5721. })
  5722. .bind( "mouseleave" + this.eventNamespace, function() {
  5723. if ( options.disabled ) {
  5724. return;
  5725. }
  5726. $( this ).removeClass( activeClass );
  5727. })
  5728. .bind( "click" + this.eventNamespace, function( event ) {
  5729. if ( options.disabled ) {
  5730. event.preventDefault();
  5731. event.stopImmediatePropagation();
  5732. }
  5733. });
  5734. this.element
  5735. .bind( "focus" + this.eventNamespace, function() {
  5736. // no need to check disabled, focus won't be triggered anyway
  5737. that.buttonElement.addClass( focusClass );
  5738. })
  5739. .bind( "blur" + this.eventNamespace, function() {
  5740. that.buttonElement.removeClass( focusClass );
  5741. });
  5742. if ( toggleButton ) {
  5743. this.element.bind( "change" + this.eventNamespace, function() {
  5744. if ( clickDragged ) {
  5745. return;
  5746. }
  5747. that.refresh();
  5748. });
  5749. // if mouse moves between mousedown and mouseup (drag) set clickDragged flag
  5750. // prevents issue where button state changes but checkbox/radio checked state
  5751. // does not in Firefox (see ticket #6970)
  5752. this.buttonElement
  5753. .bind( "mousedown" + this.eventNamespace, function( event ) {
  5754. if ( options.disabled ) {
  5755. return;
  5756. }
  5757. clickDragged = false;
  5758. startXPos = event.pageX;
  5759. startYPos = event.pageY;
  5760. })
  5761. .bind( "mouseup" + this.eventNamespace, function( event ) {
  5762. if ( options.disabled ) {
  5763. return;
  5764. }
  5765. if ( startXPos !== event.pageX || startYPos !== event.pageY ) {
  5766. clickDragged = true;
  5767. }
  5768. });
  5769. }
  5770. if ( this.type === "checkbox" ) {
  5771. this.buttonElement.bind( "click" + this.eventNamespace, function() {
  5772. if ( options.disabled || clickDragged ) {
  5773. return false;
  5774. }
  5775. $( this ).toggleClass( "ui-state-active" );
  5776. that.buttonElement.attr( "aria-pressed", that.element[0].checked );
  5777. });
  5778. } else if ( this.type === "radio" ) {
  5779. this.buttonElement.bind( "click" + this.eventNamespace, function() {
  5780. if ( options.disabled || clickDragged ) {
  5781. return false;
  5782. }
  5783. $( this ).addClass( "ui-state-active" );
  5784. that.buttonElement.attr( "aria-pressed", "true" );
  5785. var radio = that.element[ 0 ];
  5786. radioGroup( radio )
  5787. .not( radio )
  5788. .map(function() {
  5789. return $( this ).button( "widget" )[ 0 ];
  5790. })
  5791. .removeClass( "ui-state-active" )
  5792. .attr( "aria-pressed", "false" );
  5793. });
  5794. } else {
  5795. this.buttonElement
  5796. .bind( "mousedown" + this.eventNamespace, function() {
  5797. if ( options.disabled ) {
  5798. return false;
  5799. }
  5800. $( this ).addClass( "ui-state-active" );
  5801. lastActive = this;
  5802. that.document.one( "mouseup", function() {
  5803. lastActive = null;
  5804. });
  5805. })
  5806. .bind( "mouseup" + this.eventNamespace, function() {
  5807. if ( options.disabled ) {
  5808. return false;
  5809. }
  5810. $( this ).removeClass( "ui-state-active" );
  5811. })
  5812. .bind( "keydown" + this.eventNamespace, function(event) {
  5813. if ( options.disabled ) {
  5814. return false;
  5815. }
  5816. if ( event.keyCode === $.ui.keyCode.SPACE || event.keyCode === $.ui.keyCode.ENTER ) {
  5817. $( this ).addClass( "ui-state-active" );
  5818. }
  5819. })
  5820. .bind( "keyup" + this.eventNamespace, function() {
  5821. $( this ).removeClass( "ui-state-active" );
  5822. });
  5823. if ( this.buttonElement.is("a") ) {
  5824. this.buttonElement.keyup(function(event) {
  5825. if ( event.keyCode === $.ui.keyCode.SPACE ) {
  5826. // TODO pass through original event correctly (just as 2nd argument doesn't work)
  5827. $( this ).click();
  5828. }
  5829. });
  5830. }
  5831. }
  5832. // TODO: pull out $.Widget's handling for the disabled option into
  5833. // $.Widget.prototype._setOptionDisabled so it's easy to proxy and can
  5834. // be overridden by individual plugins
  5835. this._setOption( "disabled", options.disabled );
  5836. this._resetButton();
  5837. },
  5838. _determineButtonType: function() {
  5839. var ancestor, labelSelector, checked;
  5840. if ( this.element.is("[type=checkbox]") ) {
  5841. this.type = "checkbox";
  5842. } else if ( this.element.is("[type=radio]") ) {
  5843. this.type = "radio";
  5844. } else if ( this.element.is("input") ) {
  5845. this.type = "input";
  5846. } else {
  5847. this.type = "button";
  5848. }
  5849. if ( this.type === "checkbox" || this.type === "radio" ) {
  5850. // we don't search against the document in case the element
  5851. // is disconnected from the DOM
  5852. ancestor = this.element.parents().last();
  5853. labelSelector = "label[for='" + this.element.attr("id") + "']";
  5854. this.buttonElement = ancestor.find( labelSelector );
  5855. if ( !this.buttonElement.length ) {
  5856. ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings();
  5857. this.buttonElement = ancestor.filter( labelSelector );
  5858. if ( !this.buttonElement.length ) {
  5859. this.buttonElement = ancestor.find( labelSelector );
  5860. }
  5861. }
  5862. this.element.addClass( "ui-helper-hidden-accessible" );
  5863. checked = this.element.is( ":checked" );
  5864. if ( checked ) {
  5865. this.buttonElement.addClass( "ui-state-active" );
  5866. }
  5867. this.buttonElement.prop( "aria-pressed", checked );
  5868. } else {
  5869. this.buttonElement = this.element;
  5870. }
  5871. },
  5872. widget: function() {
  5873. return this.buttonElement;
  5874. },
  5875. _destroy: function() {
  5876. this.element
  5877. .removeClass( "ui-helper-hidden-accessible" );
  5878. this.buttonElement
  5879. .removeClass( baseClasses + " " + stateClasses + " " + typeClasses )
  5880. .removeAttr( "role" )
  5881. .removeAttr( "aria-pressed" )
  5882. .html( this.buttonElement.find(".ui-button-text").html() );
  5883. if ( !this.hasTitle ) {
  5884. this.buttonElement.removeAttr( "title" );
  5885. }
  5886. },
  5887. _setOption: function( key, value ) {
  5888. this._super( key, value );
  5889. if ( key === "disabled" ) {
  5890. if ( value ) {
  5891. this.element.prop( "disabled", true );
  5892. } else {
  5893. this.element.prop( "disabled", false );
  5894. }
  5895. return;
  5896. }
  5897. this._resetButton();
  5898. },
  5899. refresh: function() {
  5900. //See #8237 & #8828
  5901. var isDisabled = this.element.is( "input, button" ) ? this.element.is( ":disabled" ) : this.element.hasClass( "ui-button-disabled" );
  5902. if ( isDisabled !== this.options.disabled ) {
  5903. this._setOption( "disabled", isDisabled );
  5904. }
  5905. if ( this.type === "radio" ) {
  5906. radioGroup( this.element[0] ).each(function() {
  5907. if ( $( this ).is( ":checked" ) ) {
  5908. $( this ).button( "widget" )
  5909. .addClass( "ui-state-active" )
  5910. .attr( "aria-pressed", "true" );
  5911. } else {
  5912. $( this ).button( "widget" )
  5913. .removeClass( "ui-state-active" )
  5914. .attr( "aria-pressed", "false" );
  5915. }
  5916. });
  5917. } else if ( this.type === "checkbox" ) {
  5918. if ( this.element.is( ":checked" ) ) {
  5919. this.buttonElement
  5920. .addClass( "ui-state-active" )
  5921. .attr( "aria-pressed", "true" );
  5922. } else {
  5923. this.buttonElement
  5924. .removeClass( "ui-state-active" )
  5925. .attr( "aria-pressed", "false" );
  5926. }
  5927. }
  5928. },
  5929. _resetButton: function() {
  5930. if ( this.type === "input" ) {
  5931. if ( this.options.label ) {
  5932. this.element.val( this.options.label );
  5933. }
  5934. return;
  5935. }
  5936. var buttonElement = this.buttonElement.removeClass( typeClasses ),
  5937. buttonText = $( "<span></span>", this.document[0] )
  5938. .addClass( "ui-button-text" )
  5939. .html( this.options.label )
  5940. .appendTo( buttonElement.empty() )
  5941. .text(),
  5942. icons = this.options.icons,
  5943. multipleIcons = icons.primary && icons.secondary,
  5944. buttonClasses = [];
  5945. if ( icons.primary || icons.secondary ) {
  5946. if ( this.options.text ) {
  5947. buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) );
  5948. }
  5949. if ( icons.primary ) {
  5950. buttonElement.prepend( "<span class='ui-button-icon-primary ui-icon " + icons.primary + "'></span>" );
  5951. }
  5952. if ( icons.secondary ) {
  5953. buttonElement.append( "<span class='ui-button-icon-secondary ui-icon " + icons.secondary + "'></span>" );
  5954. }
  5955. if ( !this.options.text ) {
  5956. buttonClasses.push( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" );
  5957. if ( !this.hasTitle ) {
  5958. buttonElement.attr( "title", $.trim( buttonText ) );
  5959. }
  5960. }
  5961. } else {
  5962. buttonClasses.push( "ui-button-text-only" );
  5963. }
  5964. buttonElement.addClass( buttonClasses.join( " " ) );
  5965. }
  5966. });
  5967. $.widget( "ui.buttonset", {
  5968. version: "1.9.2",
  5969. options: {
  5970. items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(button)"
  5971. },
  5972. _create: function() {
  5973. this.element.addClass( "ui-buttonset" );
  5974. },
  5975. _init: function() {
  5976. this.refresh();
  5977. },
  5978. _setOption: function( key, value ) {
  5979. if ( key === "disabled" ) {
  5980. this.buttons.button( "option", key, value );
  5981. }
  5982. this._super( key, value );
  5983. },
  5984. refresh: function() {
  5985. var rtl = this.element.css( "direction" ) === "rtl";
  5986. this.buttons = this.element.find( this.options.items )
  5987. .filter( ":ui-button" )
  5988. .button( "refresh" )
  5989. .end()
  5990. .not( ":ui-button" )
  5991. .button()
  5992. .end()
  5993. .map(function() {
  5994. return $( this ).button( "widget" )[ 0 ];
  5995. })
  5996. .removeClass( "ui-corner-all ui-corner-left ui-corner-right" )
  5997. .filter( ":first" )
  5998. .addClass( rtl ? "ui-corner-right" : "ui-corner-left" )
  5999. .end()
  6000. .filter( ":last" )
  6001. .addClass( rtl ? "ui-corner-left" : "ui-corner-right" )
  6002. .end()
  6003. .end();
  6004. },
  6005. _destroy: function() {
  6006. this.element.removeClass( "ui-buttonset" );
  6007. this.buttons
  6008. .map(function() {
  6009. return $( this ).button( "widget" )[ 0 ];
  6010. })
  6011. .removeClass( "ui-corner-left ui-corner-right" )
  6012. .end()
  6013. .button( "destroy" );
  6014. }
  6015. });
  6016. }( jQuery ) );
  6017. (function( $, undefined ) {
  6018. $.extend($.ui, { datepicker: { version: "1.9.2" } });
  6019. var PROP_NAME = 'datepicker';
  6020. var dpuuid = new Date().getTime();
  6021. var instActive;
  6022. /* Date picker manager.
  6023. Use the singleton instance of this class, $.datepicker, to interact with the date picker.
  6024. Settings for (groups of) date pickers are maintained in an instance object,
  6025. allowing multiple different settings on the same page. */
  6026. function Datepicker() {
  6027. this.debug = false; // Change this to true to start debugging
  6028. this._curInst = null; // The current instance in use
  6029. this._keyEvent = false; // If the last event was a key event
  6030. this._disabledInputs = []; // List of date picker inputs that have been disabled
  6031. this._datepickerShowing = false; // True if the popup picker is showing , false if not
  6032. this._inDialog = false; // True if showing within a "dialog", false if not
  6033. this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
  6034. this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
  6035. this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
  6036. this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
  6037. this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
  6038. this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
  6039. this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
  6040. this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
  6041. this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
  6042. this.regional = []; // Available regional settings, indexed by language code
  6043. this.regional[''] = { // Default regional settings
  6044. closeText: 'Done', // Display text for close link
  6045. prevText: 'Prev', // Display text for previous month link
  6046. nextText: 'Next', // Display text for next month link
  6047. currentText: 'Today', // Display text for current month link
  6048. monthNames: ['January','February','March','April','May','June',
  6049. 'July','August','September','October','November','December'], // Names of months for drop-down and formatting
  6050. monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
  6051. dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
  6052. dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
  6053. dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
  6054. weekHeader: 'Wk', // Column header for week of the year
  6055. dateFormat: 'mm/dd/yy', // See format options on parseDate
  6056. firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
  6057. isRTL: false, // True if right-to-left language, false if left-to-right
  6058. showMonthAfterYear: false, // True if the year select precedes month, false for month then year
  6059. yearSuffix: '' // Additional text to append to the year in the month headers
  6060. };
  6061. this._defaults = { // Global defaults for all the date picker instances
  6062. showOn: 'focus', // 'focus' for popup on focus,
  6063. // 'button' for trigger button, or 'both' for either
  6064. showAnim: 'fadeIn', // Name of jQuery animation for popup
  6065. showOptions: {}, // Options for enhanced animations
  6066. defaultDate: null, // Used when field is blank: actual date,
  6067. // +/-number for offset from today, null for today
  6068. appendText: '', // Display text following the input box, e.g. showing the format
  6069. buttonText: '...', // Text for trigger button
  6070. buttonImage: '', // URL for trigger button image
  6071. buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
  6072. hideIfNoPrevNext: false, // True to hide next/previous month links
  6073. // if not applicable, false to just disable them
  6074. navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
  6075. gotoCurrent: false, // True if today link goes back to current selection instead
  6076. changeMonth: false, // True if month can be selected directly, false if only prev/next
  6077. changeYear: false, // True if year can be selected directly, false if only prev/next
  6078. yearRange: 'c-10:c+10', // Range of years to display in drop-down,
  6079. // either relative to today's year (-nn:+nn), relative to currently displayed year
  6080. // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
  6081. showOtherMonths: false, // True to show dates in other months, false to leave blank
  6082. selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
  6083. showWeek: false, // True to show week of the year, false to not show it
  6084. calculateWeek: this.iso8601Week, // How to calculate the week of the year,
  6085. // takes a Date and returns the number of the week for it
  6086. shortYearCutoff: '+10', // Short year values < this are in the current century,
  6087. // > this are in the previous century,
  6088. // string value starting with '+' for current year + value
  6089. minDate: null, // The earliest selectable date, or null for no limit
  6090. maxDate: null, // The latest selectable date, or null for no limit
  6091. duration: 'fast', // Duration of display/closure
  6092. beforeShowDay: null, // Function that takes a date and returns an array with
  6093. // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
  6094. // [2] = cell title (optional), e.g. $.datepicker.noWeekends
  6095. beforeShow: null, // Function that takes an input field and
  6096. // returns a set of custom settings for the date picker
  6097. onSelect: null, // Define a callback function when a date is selected
  6098. onChangeMonthYear: null, // Define a callback function when the month or year is changed
  6099. onClose: null, // Define a callback function when the datepicker is closed
  6100. numberOfMonths: 1, // Number of months to show at a time
  6101. showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
  6102. stepMonths: 1, // Number of months to step back/forward
  6103. stepBigMonths: 12, // Number of months to step back/forward for the big links
  6104. altField: '', // Selector for an alternate field to store selected dates into
  6105. altFormat: '', // The date format to use for the alternate field
  6106. constrainInput: true, // The input is constrained by the current date format
  6107. showButtonPanel: false, // True to show button panel, false to not show it
  6108. autoSize: false, // True to size the input for the date format, false to leave as is
  6109. disabled: false // The initial disabled state
  6110. };
  6111. $.extend(this._defaults, this.regional['']);
  6112. this.dpDiv = bindHover($('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'));
  6113. }
  6114. $.extend(Datepicker.prototype, {
  6115. /* Class name added to elements to indicate already configured with a date picker. */
  6116. markerClassName: 'hasDatepicker',
  6117. //Keep track of the maximum number of rows displayed (see #7043)
  6118. maxRows: 4,
  6119. /* Debug logging (if enabled). */
  6120. log: function () {
  6121. if (this.debug)
  6122. console.log.apply('', arguments);
  6123. },
  6124. // TODO rename to "widget" when switching to widget factory
  6125. _widgetDatepicker: function() {
  6126. return this.dpDiv;
  6127. },
  6128. /* Override the default settings for all instances of the date picker.
  6129. @param settings object - the new settings to use as defaults (anonymous object)
  6130. @return the manager object */
  6131. setDefaults: function(settings) {
  6132. extendRemove(this._defaults, settings || {});
  6133. return this;
  6134. },
  6135. /* Attach the date picker to a jQuery selection.
  6136. @param target element - the target input field or division or span
  6137. @param settings object - the new settings to use for this date picker instance (anonymous) */
  6138. _attachDatepicker: function(target, settings) {
  6139. // check for settings on the control itself - in namespace 'date:'
  6140. var inlineSettings = null;
  6141. for (var attrName in this._defaults) {
  6142. var attrValue = target.getAttribute('date:' + attrName);
  6143. if (attrValue) {
  6144. inlineSettings = inlineSettings || {};
  6145. try {
  6146. inlineSettings[attrName] = eval(attrValue);
  6147. } catch (err) {
  6148. inlineSettings[attrName] = attrValue;
  6149. }
  6150. }
  6151. }
  6152. var nodeName = target.nodeName.toLowerCase();
  6153. var inline = (nodeName == 'div' || nodeName == 'span');
  6154. if (!target.id) {
  6155. this.uuid += 1;
  6156. target.id = 'dp' + this.uuid;
  6157. }
  6158. var inst = this._newInst($(target), inline);
  6159. inst.settings = $.extend({}, settings || {}, inlineSettings || {});
  6160. if (nodeName == 'input') {
  6161. this._connectDatepicker(target, inst);
  6162. } else if (inline) {
  6163. this._inlineDatepicker(target, inst);
  6164. }
  6165. },
  6166. /* Create a new instance object. */
  6167. _newInst: function(target, inline) {
  6168. var id = target[0].id.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); // escape jQuery meta chars
  6169. return {id: id, input: target, // associated target
  6170. selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
  6171. drawMonth: 0, drawYear: 0, // month being drawn
  6172. inline: inline, // is datepicker inline or not
  6173. dpDiv: (!inline ? this.dpDiv : // presentation div
  6174. bindHover($('<div class="' + this._inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>')))};
  6175. },
  6176. /* Attach the date picker to an input field. */
  6177. _connectDatepicker: function(target, inst) {
  6178. var input = $(target);
  6179. inst.append = $([]);
  6180. inst.trigger = $([]);
  6181. if (input.hasClass(this.markerClassName))
  6182. return;
  6183. this._attachments(input, inst);
  6184. input.addClass(this.markerClassName).keydown(this._doKeyDown).
  6185. keypress(this._doKeyPress).keyup(this._doKeyUp).
  6186. bind("setData.datepicker", function(event, key, value) {
  6187. inst.settings[key] = value;
  6188. }).bind("getData.datepicker", function(event, key) {
  6189. return this._get(inst, key);
  6190. });
  6191. this._autoSize(inst);
  6192. $.data(target, PROP_NAME, inst);
  6193. //If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665)
  6194. if( inst.settings.disabled ) {
  6195. this._disableDatepicker( target );
  6196. }
  6197. },
  6198. /* Make attachments based on settings. */
  6199. _attachments: function(input, inst) {
  6200. var appendText = this._get(inst, 'appendText');
  6201. var isRTL = this._get(inst, 'isRTL');
  6202. if (inst.append)
  6203. inst.append.remove();
  6204. if (appendText) {
  6205. inst.append = $('<span class="' + this._appendClass + '">' + appendText + '</span>');
  6206. input[isRTL ? 'before' : 'after'](inst.append);
  6207. }
  6208. input.unbind('focus', this._showDatepicker);
  6209. if (inst.trigger)
  6210. inst.trigger.remove();
  6211. var showOn = this._get(inst, 'showOn');
  6212. if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
  6213. input.focus(this._showDatepicker);
  6214. if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
  6215. var buttonText = this._get(inst, 'buttonText');
  6216. var buttonImage = this._get(inst, 'buttonImage');
  6217. inst.trigger = $(this._get(inst, 'buttonImageOnly') ?
  6218. $('<img/>').addClass(this._triggerClass).
  6219. attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
  6220. $('<button type="button"></button>').addClass(this._triggerClass).
  6221. html(buttonImage == '' ? buttonText : $('<img/>').attr(
  6222. { src:buttonImage, alt:buttonText, title:buttonText })));
  6223. input[isRTL ? 'before' : 'after'](inst.trigger);
  6224. inst.trigger.click(function() {
  6225. if ($.datepicker._datepickerShowing && $.datepicker._lastInput == input[0])
  6226. $.datepicker._hideDatepicker();
  6227. else if ($.datepicker._datepickerShowing && $.datepicker._lastInput != input[0]) {
  6228. $.datepicker._hideDatepicker();
  6229. $.datepicker._showDatepicker(input[0]);
  6230. } else
  6231. $.datepicker._showDatepicker(input[0]);
  6232. return false;
  6233. });
  6234. }
  6235. },
  6236. /* Apply the maximum length for the date format. */
  6237. _autoSize: function(inst) {
  6238. if (this._get(inst, 'autoSize') && !inst.inline) {
  6239. var date = new Date(2009, 12 - 1, 20); // Ensure double digits
  6240. var dateFormat = this._get(inst, 'dateFormat');
  6241. if (dateFormat.match(/[DM]/)) {
  6242. var findMax = function(names) {
  6243. var max = 0;
  6244. var maxI = 0;
  6245. for (var i = 0; i < names.length; i++) {
  6246. if (names[i].length > max) {
  6247. max = names[i].length;
  6248. maxI = i;
  6249. }
  6250. }
  6251. return maxI;
  6252. };
  6253. date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ?
  6254. 'monthNames' : 'monthNamesShort'))));
  6255. date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ?
  6256. 'dayNames' : 'dayNamesShort'))) + 20 - date.getDay());
  6257. }
  6258. inst.input.attr('size', this._formatDate(inst, date).length);
  6259. }
  6260. },
  6261. /* Attach an inline date picker to a div. */
  6262. _inlineDatepicker: function(target, inst) {
  6263. var divSpan = $(target);
  6264. if (divSpan.hasClass(this.markerClassName))
  6265. return;
  6266. divSpan.addClass(this.markerClassName).append(inst.dpDiv).
  6267. bind("setData.datepicker", function(event, key, value){
  6268. inst.settings[key] = value;
  6269. }).bind("getData.datepicker", function(event, key){
  6270. return this._get(inst, key);
  6271. });
  6272. $.data(target, PROP_NAME, inst);
  6273. this._setDate(inst, this._getDefaultDate(inst), true);
  6274. this._updateDatepicker(inst);
  6275. this._updateAlternate(inst);
  6276. //If disabled option is true, disable the datepicker before showing it (see ticket #5665)
  6277. if( inst.settings.disabled ) {
  6278. this._disableDatepicker( target );
  6279. }
  6280. // Set display:block in place of inst.dpDiv.show() which won't work on disconnected elements
  6281. // http://bugs.jqueryui.com/ticket/7552 - A Datepicker created on a detached div has zero height
  6282. inst.dpDiv.css( "display", "block" );
  6283. },
  6284. /* Pop-up the date picker in a "dialog" box.
  6285. @param input element - ignored
  6286. @param date string or Date - the initial date to display
  6287. @param onSelect function - the function to call when a date is selected
  6288. @param settings object - update the dialog date picker instance's settings (anonymous object)
  6289. @param pos int[2] - coordinates for the dialog's position within the screen or
  6290. event - with x/y coordinates or
  6291. leave empty for default (screen centre)
  6292. @return the manager object */
  6293. _dialogDatepicker: function(input, date, onSelect, settings, pos) {
  6294. var inst = this._dialogInst; // internal instance
  6295. if (!inst) {
  6296. this.uuid += 1;
  6297. var id = 'dp' + this.uuid;
  6298. this._dialogInput = $('<input type="text" id="' + id +
  6299. '" style="position: absolute; top: -100px; width: 0px;"/>');
  6300. this._dialogInput.keydown(this._doKeyDown);
  6301. $('body').append(this._dialogInput);
  6302. inst = this._dialogInst = this._newInst(this._dialogInput, false);
  6303. inst.settings = {};
  6304. $.data(this._dialogInput[0], PROP_NAME, inst);
  6305. }
  6306. extendRemove(inst.settings, settings || {});
  6307. date = (date && date.constructor == Date ? this._formatDate(inst, date) : date);
  6308. this._dialogInput.val(date);
  6309. this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
  6310. if (!this._pos) {
  6311. var browserWidth = document.documentElement.clientWidth;
  6312. var browserHeight = document.documentElement.clientHeight;
  6313. var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
  6314. var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
  6315. this._pos = // should use actual width/height below
  6316. [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
  6317. }
  6318. // move input on screen for focus, but hidden behind dialog
  6319. this._dialogInput.css('left', (this._pos[0] + 20) + 'px').css('top', this._pos[1] + 'px');
  6320. inst.settings.onSelect = onSelect;
  6321. this._inDialog = true;
  6322. this.dpDiv.addClass(this._dialogClass);
  6323. this._showDatepicker(this._dialogInput[0]);
  6324. if ($.blockUI)
  6325. $.blockUI(this.dpDiv);
  6326. $.data(this._dialogInput[0], PROP_NAME, inst);
  6327. return this;
  6328. },
  6329. /* Detach a datepicker from its control.
  6330. @param target element - the target input field or division or span */
  6331. _destroyDatepicker: function(target) {
  6332. var $target = $(target);
  6333. var inst = $.data(target, PROP_NAME);
  6334. if (!$target.hasClass(this.markerClassName)) {
  6335. return;
  6336. }
  6337. var nodeName = target.nodeName.toLowerCase();
  6338. $.removeData(target, PROP_NAME);
  6339. if (nodeName == 'input') {
  6340. inst.append.remove();
  6341. inst.trigger.remove();
  6342. $target.removeClass(this.markerClassName).
  6343. unbind('focus', this._showDatepicker).
  6344. unbind('keydown', this._doKeyDown).
  6345. unbind('keypress', this._doKeyPress).
  6346. unbind('keyup', this._doKeyUp);
  6347. } else if (nodeName == 'div' || nodeName == 'span')
  6348. $target.removeClass(this.markerClassName).empty();
  6349. },
  6350. /* Enable the date picker to a jQuery selection.
  6351. @param target element - the target input field or division or span */
  6352. _enableDatepicker: function(target) {
  6353. var $target = $(target);
  6354. var inst = $.data(target, PROP_NAME);
  6355. if (!$target.hasClass(this.markerClassName)) {
  6356. return;
  6357. }
  6358. var nodeName = target.nodeName.toLowerCase();
  6359. if (nodeName == 'input') {
  6360. target.disabled = false;
  6361. inst.trigger.filter('button').
  6362. each(function() { this.disabled = false; }).end().
  6363. filter('img').css({opacity: '1.0', cursor: ''});
  6364. }
  6365. else if (nodeName == 'div' || nodeName == 'span') {
  6366. var inline = $target.children('.' + this._inlineClass);
  6367. inline.children().removeClass('ui-state-disabled');
  6368. inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
  6369. prop("disabled", false);
  6370. }
  6371. this._disabledInputs = $.map(this._disabledInputs,
  6372. function(value) { return (value == target ? null : value); }); // delete entry
  6373. },
  6374. /* Disable the date picker to a jQuery selection.
  6375. @param target element - the target input field or division or span */
  6376. _disableDatepicker: function(target) {
  6377. var $target = $(target);
  6378. var inst = $.data(target, PROP_NAME);
  6379. if (!$target.hasClass(this.markerClassName)) {
  6380. return;
  6381. }
  6382. var nodeName = target.nodeName.toLowerCase();
  6383. if (nodeName == 'input') {
  6384. target.disabled = true;
  6385. inst.trigger.filter('button').
  6386. each(function() { this.disabled = true; }).end().
  6387. filter('img').css({opacity: '0.5', cursor: 'default'});
  6388. }
  6389. else if (nodeName == 'div' || nodeName == 'span') {
  6390. var inline = $target.children('.' + this._inlineClass);
  6391. inline.children().addClass('ui-state-disabled');
  6392. inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
  6393. prop("disabled", true);
  6394. }
  6395. this._disabledInputs = $.map(this._disabledInputs,
  6396. function(value) { return (value == target ? null : value); }); // delete entry
  6397. this._disabledInputs[this._disabledInputs.length] = target;
  6398. },
  6399. /* Is the first field in a jQuery collection disabled as a datepicker?
  6400. @param target element - the target input field or division or span
  6401. @return boolean - true if disabled, false if enabled */
  6402. _isDisabledDatepicker: function(target) {
  6403. if (!target) {
  6404. return false;
  6405. }
  6406. for (var i = 0; i < this._disabledInputs.length; i++) {
  6407. if (this._disabledInputs[i] == target)
  6408. return true;
  6409. }
  6410. return false;
  6411. },
  6412. /* Retrieve the instance data for the target control.
  6413. @param target element - the target input field or division or span
  6414. @return object - the associated instance data
  6415. @throws error if a jQuery problem getting data */
  6416. _getInst: function(target) {
  6417. try {
  6418. return $.data(target, PROP_NAME);
  6419. }
  6420. catch (err) {
  6421. throw 'Missing instance data for this datepicker';
  6422. }
  6423. },
  6424. /* Update or retrieve the settings for a date picker attached to an input field or division.
  6425. @param target element - the target input field or division or span
  6426. @param name object - the new settings to update or
  6427. string - the name of the setting to change or retrieve,
  6428. when retrieving also 'all' for all instance settings or
  6429. 'defaults' for all global defaults
  6430. @param value any - the new value for the setting
  6431. (omit if above is an object or to retrieve a value) */
  6432. _optionDatepicker: function(target, name, value) {
  6433. var inst = this._getInst(target);
  6434. if (arguments.length == 2 && typeof name == 'string') {
  6435. return (name == 'defaults' ? $.extend({}, $.datepicker._defaults) :
  6436. (inst ? (name == 'all' ? $.extend({}, inst.settings) :
  6437. this._get(inst, name)) : null));
  6438. }
  6439. var settings = name || {};
  6440. if (typeof name == 'string') {
  6441. settings = {};
  6442. settings[name] = value;
  6443. }
  6444. if (inst) {
  6445. if (this._curInst == inst) {
  6446. this._hideDatepicker();
  6447. }
  6448. var date = this._getDateDatepicker(target, true);
  6449. var minDate = this._getMinMaxDate(inst, 'min');
  6450. var maxDate = this._getMinMaxDate(inst, 'max');
  6451. extendRemove(inst.settings, settings);
  6452. // reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided
  6453. if (minDate !== null && settings['dateFormat'] !== undefined && settings['minDate'] === undefined)
  6454. inst.settings.minDate = this._formatDate(inst, minDate);
  6455. if (maxDate !== null && settings['dateFormat'] !== undefined && settings['maxDate'] === undefined)
  6456. inst.settings.maxDate = this._formatDate(inst, maxDate);
  6457. this._attachments($(target), inst);
  6458. this._autoSize(inst);
  6459. this._setDate(inst, date);
  6460. this._updateAlternate(inst);
  6461. this._updateDatepicker(inst);
  6462. }
  6463. },
  6464. // change method deprecated
  6465. _changeDatepicker: function(target, name, value) {
  6466. this._optionDatepicker(target, name, value);
  6467. },
  6468. /* Redraw the date picker attached to an input field or division.
  6469. @param target element - the target input field or division or span */
  6470. _refreshDatepicker: function(target) {
  6471. var inst = this._getInst(target);
  6472. if (inst) {
  6473. this._updateDatepicker(inst);
  6474. }
  6475. },
  6476. /* Set the dates for a jQuery selection.
  6477. @param target element - the target input field or division or span
  6478. @param date Date - the new date */
  6479. _setDateDatepicker: function(target, date) {
  6480. var inst = this._getInst(target);
  6481. if (inst) {
  6482. this._setDate(inst, date);
  6483. this._updateDatepicker(inst);
  6484. this._updateAlternate(inst);
  6485. }
  6486. },
  6487. /* Get the date(s) for the first entry in a jQuery selection.
  6488. @param target element - the target input field or division or span
  6489. @param noDefault boolean - true if no default date is to be used
  6490. @return Date - the current date */
  6491. _getDateDatepicker: function(target, noDefault) {
  6492. var inst = this._getInst(target);
  6493. if (inst && !inst.inline)
  6494. this._setDateFromField(inst, noDefault);
  6495. return (inst ? this._getDate(inst) : null);
  6496. },
  6497. /* Handle keystrokes. */
  6498. _doKeyDown: function(event) {
  6499. var inst = $.datepicker._getInst(event.target);
  6500. var handled = true;
  6501. var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
  6502. inst._keyEvent = true;
  6503. if ($.datepicker._datepickerShowing)
  6504. switch (event.keyCode) {
  6505. case 9: $.datepicker._hideDatepicker();
  6506. handled = false;
  6507. break; // hide on tab out
  6508. case 13: var sel = $('td.' + $.datepicker._dayOverClass + ':not(.' +
  6509. $.datepicker._currentClass + ')', inst.dpDiv);
  6510. if (sel[0])
  6511. $.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
  6512. var onSelect = $.datepicker._get(inst, 'onSelect');
  6513. if (onSelect) {
  6514. var dateStr = $.datepicker._formatDate(inst);
  6515. // trigger custom callback
  6516. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
  6517. }
  6518. else
  6519. $.datepicker._hideDatepicker();
  6520. return false; // don't submit the form
  6521. break; // select the value on enter
  6522. case 27: $.datepicker._hideDatepicker();
  6523. break; // hide on escape
  6524. case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  6525. -$.datepicker._get(inst, 'stepBigMonths') :
  6526. -$.datepicker._get(inst, 'stepMonths')), 'M');
  6527. break; // previous month/year on page up/+ ctrl
  6528. case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  6529. +$.datepicker._get(inst, 'stepBigMonths') :
  6530. +$.datepicker._get(inst, 'stepMonths')), 'M');
  6531. break; // next month/year on page down/+ ctrl
  6532. case 35: if (event.ctrlKey || event.metaKey) $.datepicker._clearDate(event.target);
  6533. handled = event.ctrlKey || event.metaKey;
  6534. break; // clear on ctrl or command +end
  6535. case 36: if (event.ctrlKey || event.metaKey) $.datepicker._gotoToday(event.target);
  6536. handled = event.ctrlKey || event.metaKey;
  6537. break; // current on ctrl or command +home
  6538. case 37: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), 'D');
  6539. handled = event.ctrlKey || event.metaKey;
  6540. // -1 day on ctrl or command +left
  6541. if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  6542. -$.datepicker._get(inst, 'stepBigMonths') :
  6543. -$.datepicker._get(inst, 'stepMonths')), 'M');
  6544. // next month/year on alt +left on Mac
  6545. break;
  6546. case 38: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, -7, 'D');
  6547. handled = event.ctrlKey || event.metaKey;
  6548. break; // -1 week on ctrl or command +up
  6549. case 39: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), 'D');
  6550. handled = event.ctrlKey || event.metaKey;
  6551. // +1 day on ctrl or command +right
  6552. if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  6553. +$.datepicker._get(inst, 'stepBigMonths') :
  6554. +$.datepicker._get(inst, 'stepMonths')), 'M');
  6555. // next month/year on alt +right
  6556. break;
  6557. case 40: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, +7, 'D');
  6558. handled = event.ctrlKey || event.metaKey;
  6559. break; // +1 week on ctrl or command +down
  6560. default: handled = false;
  6561. }
  6562. else if (event.keyCode == 36 && event.ctrlKey) // display the date picker on ctrl+home
  6563. $.datepicker._showDatepicker(this);
  6564. else {
  6565. handled = false;
  6566. }
  6567. if (handled) {
  6568. event.preventDefault();
  6569. event.stopPropagation();
  6570. }
  6571. },
  6572. /* Filter entered characters - based on date format. */
  6573. _doKeyPress: function(event) {
  6574. var inst = $.datepicker._getInst(event.target);
  6575. if ($.datepicker._get(inst, 'constrainInput')) {
  6576. var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
  6577. var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
  6578. return event.ctrlKey || event.metaKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
  6579. }
  6580. },
  6581. /* Synchronise manual entry and field/alternate field. */
  6582. _doKeyUp: function(event) {
  6583. var inst = $.datepicker._getInst(event.target);
  6584. if (inst.input.val() != inst.lastVal) {
  6585. try {
  6586. var date = $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
  6587. (inst.input ? inst.input.val() : null),
  6588. $.datepicker._getFormatConfig(inst));
  6589. if (date) { // only if valid
  6590. $.datepicker._setDateFromField(inst);
  6591. $.datepicker._updateAlternate(inst);
  6592. $.datepicker._updateDatepicker(inst);
  6593. }
  6594. }
  6595. catch (err) {
  6596. $.datepicker.log(err);
  6597. }
  6598. }
  6599. return true;
  6600. },
  6601. /* Pop-up the date picker for a given input field.
  6602. If false returned from beforeShow event handler do not show.
  6603. @param input element - the input field attached to the date picker or
  6604. event - if triggered by focus */
  6605. _showDatepicker: function(input) {
  6606. input = input.target || input;
  6607. if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
  6608. input = $('input', input.parentNode)[0];
  6609. if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput == input) // already here
  6610. return;
  6611. var inst = $.datepicker._getInst(input);
  6612. if ($.datepicker._curInst && $.datepicker._curInst != inst) {
  6613. $.datepicker._curInst.dpDiv.stop(true, true);
  6614. if ( inst && $.datepicker._datepickerShowing ) {
  6615. $.datepicker._hideDatepicker( $.datepicker._curInst.input[0] );
  6616. }
  6617. }
  6618. var beforeShow = $.datepicker._get(inst, 'beforeShow');
  6619. var beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {};
  6620. if(beforeShowSettings === false){
  6621. //false
  6622. return;
  6623. }
  6624. extendRemove(inst.settings, beforeShowSettings);
  6625. inst.lastVal = null;
  6626. $.datepicker._lastInput = input;
  6627. $.datepicker._setDateFromField(inst);
  6628. if ($.datepicker._inDialog) // hide cursor
  6629. input.value = '';
  6630. if (!$.datepicker._pos) { // position below input
  6631. $.datepicker._pos = $.datepicker._findPos(input);
  6632. $.datepicker._pos[1] += input.offsetHeight; // add the height
  6633. }
  6634. var isFixed = false;
  6635. $(input).parents().each(function() {
  6636. isFixed |= $(this).css('position') == 'fixed';
  6637. return !isFixed;
  6638. });
  6639. var offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
  6640. $.datepicker._pos = null;
  6641. //to avoid flashes on Firefox
  6642. inst.dpDiv.empty();
  6643. // determine sizing offscreen
  6644. inst.dpDiv.css({position: 'absolute', display: 'block', top: '-1000px'});
  6645. $.datepicker._updateDatepicker(inst);
  6646. // fix width for dynamic number of date pickers
  6647. // and adjust position before showing
  6648. offset = $.datepicker._checkOffset(inst, offset, isFixed);
  6649. inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
  6650. 'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
  6651. left: offset.left + 'px', top: offset.top + 'px'});
  6652. if (!inst.inline) {
  6653. var showAnim = $.datepicker._get(inst, 'showAnim');
  6654. var duration = $.datepicker._get(inst, 'duration');
  6655. var postProcess = function() {
  6656. var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
  6657. if( !! cover.length ){
  6658. var borders = $.datepicker._getBorders(inst.dpDiv);
  6659. cover.css({left: -borders[0], top: -borders[1],
  6660. width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()});
  6661. }
  6662. };
  6663. inst.dpDiv.zIndex($(input).zIndex()+1);
  6664. $.datepicker._datepickerShowing = true;
  6665. // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed
  6666. if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) )
  6667. inst.dpDiv.show(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
  6668. else
  6669. inst.dpDiv[showAnim || 'show']((showAnim ? duration : null), postProcess);
  6670. if (!showAnim || !duration)
  6671. postProcess();
  6672. if (inst.input.is(':visible') && !inst.input.is(':disabled'))
  6673. inst.input.focus();
  6674. $.datepicker._curInst = inst;
  6675. }
  6676. },
  6677. /* Generate the date picker content. */
  6678. _updateDatepicker: function(inst) {
  6679. this.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
  6680. var borders = $.datepicker._getBorders(inst.dpDiv);
  6681. instActive = inst; // for delegate hover events
  6682. inst.dpDiv.empty().append(this._generateHTML(inst));
  6683. this._attachHandlers(inst);
  6684. var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
  6685. if( !!cover.length ){ //avoid call to outerXXXX() when not in IE6
  6686. cover.css({left: -borders[0], top: -borders[1], width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()})
  6687. }
  6688. inst.dpDiv.find('.' + this._dayOverClass + ' a').mouseover();
  6689. var numMonths = this._getNumberOfMonths(inst);
  6690. var cols = numMonths[1];
  6691. var width = 17;
  6692. inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
  6693. if (cols > 1)
  6694. inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em');
  6695. inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') +
  6696. 'Class']('ui-datepicker-multi');
  6697. inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') +
  6698. 'Class']('ui-datepicker-rtl');
  6699. if (inst == $.datepicker._curInst && $.datepicker._datepickerShowing && inst.input &&
  6700. // #6694 - don't focus the input if it's already focused
  6701. // this breaks the change event in IE
  6702. inst.input.is(':visible') && !inst.input.is(':disabled') && inst.input[0] != document.activeElement)
  6703. inst.input.focus();
  6704. // deffered render of the years select (to avoid flashes on Firefox)
  6705. if( inst.yearshtml ){
  6706. var origyearshtml = inst.yearshtml;
  6707. setTimeout(function(){
  6708. //assure that inst.yearshtml didn't change.
  6709. if( origyearshtml === inst.yearshtml && inst.yearshtml ){
  6710. inst.dpDiv.find('select.ui-datepicker-year:first').replaceWith(inst.yearshtml);
  6711. }
  6712. origyearshtml = inst.yearshtml = null;
  6713. }, 0);
  6714. }
  6715. },
  6716. /* Retrieve the size of left and top borders for an element.
  6717. @param elem (jQuery object) the element of interest
  6718. @return (number[2]) the left and top borders */
  6719. _getBorders: function(elem) {
  6720. var convert = function(value) {
  6721. return {thin: 1, medium: 2, thick: 3}[value] || value;
  6722. };
  6723. return [parseFloat(convert(elem.css('border-left-width'))),
  6724. parseFloat(convert(elem.css('border-top-width')))];
  6725. },
  6726. /* Check positioning to remain on screen. */
  6727. _checkOffset: function(inst, offset, isFixed) {
  6728. var dpWidth = inst.dpDiv.outerWidth();
  6729. var dpHeight = inst.dpDiv.outerHeight();
  6730. var inputWidth = inst.input ? inst.input.outerWidth() : 0;
  6731. var inputHeight = inst.input ? inst.input.outerHeight() : 0;
  6732. var viewWidth = document.documentElement.clientWidth + (isFixed ? 0 : $(document).scrollLeft());
  6733. var viewHeight = document.documentElement.clientHeight + (isFixed ? 0 : $(document).scrollTop());
  6734. offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
  6735. offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
  6736. offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
  6737. // now check if datepicker is showing outside window viewport - move to a better place if so.
  6738. offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
  6739. Math.abs(offset.left + dpWidth - viewWidth) : 0);
  6740. offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
  6741. Math.abs(dpHeight + inputHeight) : 0);
  6742. return offset;
  6743. },
  6744. /* Find an object's position on the screen. */
  6745. _findPos: function(obj) {
  6746. var inst = this._getInst(obj);
  6747. var isRTL = this._get(inst, 'isRTL');
  6748. while (obj && (obj.type == 'hidden' || obj.nodeType != 1 || $.expr.filters.hidden(obj))) {
  6749. obj = obj[isRTL ? 'previousSibling' : 'nextSibling'];
  6750. }
  6751. var position = $(obj).offset();
  6752. return [position.left, position.top];
  6753. },
  6754. /* Hide the date picker from view.
  6755. @param input element - the input field attached to the date picker */
  6756. _hideDatepicker: function(input) {
  6757. var inst = this._curInst;
  6758. if (!inst || (input && inst != $.data(input, PROP_NAME)))
  6759. return;
  6760. if (this._datepickerShowing) {
  6761. var showAnim = this._get(inst, 'showAnim');
  6762. var duration = this._get(inst, 'duration');
  6763. var postProcess = function() {
  6764. $.datepicker._tidyDialog(inst);
  6765. };
  6766. // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed
  6767. if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) )
  6768. inst.dpDiv.hide(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
  6769. else
  6770. inst.dpDiv[(showAnim == 'slideDown' ? 'slideUp' :
  6771. (showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess);
  6772. if (!showAnim)
  6773. postProcess();
  6774. this._datepickerShowing = false;
  6775. var onClose = this._get(inst, 'onClose');
  6776. if (onClose)
  6777. onClose.apply((inst.input ? inst.input[0] : null),
  6778. [(inst.input ? inst.input.val() : ''), inst]);
  6779. this._lastInput = null;
  6780. if (this._inDialog) {
  6781. this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
  6782. if ($.blockUI) {
  6783. $.unblockUI();
  6784. $('body').append(this.dpDiv);
  6785. }
  6786. }
  6787. this._inDialog = false;
  6788. }
  6789. },
  6790. /* Tidy up after a dialog display. */
  6791. _tidyDialog: function(inst) {
  6792. inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker-calendar');
  6793. },
  6794. /* Close date picker if clicked elsewhere. */
  6795. _checkExternalClick: function(event) {
  6796. if (!$.datepicker._curInst)
  6797. return;
  6798. var $target = $(event.target),
  6799. inst = $.datepicker._getInst($target[0]);
  6800. if ( ( ( $target[0].id != $.datepicker._mainDivId &&
  6801. $target.parents('#' + $.datepicker._mainDivId).length == 0 &&
  6802. !$target.hasClass($.datepicker.markerClassName) &&
  6803. !$target.closest("." + $.datepicker._triggerClass).length &&
  6804. $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) ||
  6805. ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst != inst ) )
  6806. $.datepicker._hideDatepicker();
  6807. },
  6808. /* Adjust one of the date sub-fields. */
  6809. _adjustDate: function(id, offset, period) {
  6810. var target = $(id);
  6811. var inst = this._getInst(target[0]);
  6812. if (this._isDisabledDatepicker(target[0])) {
  6813. return;
  6814. }
  6815. this._adjustInstDate(inst, offset +
  6816. (period == 'M' ? this._get(inst, 'showCurrentAtPos') : 0), // undo positioning
  6817. period);
  6818. this._updateDatepicker(inst);
  6819. },
  6820. /* Action for current link. */
  6821. _gotoToday: function(id) {
  6822. var target = $(id);
  6823. var inst = this._getInst(target[0]);
  6824. if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
  6825. inst.selectedDay = inst.currentDay;
  6826. inst.drawMonth = inst.selectedMonth = inst.currentMonth;
  6827. inst.drawYear = inst.selectedYear = inst.currentYear;
  6828. }
  6829. else {
  6830. var date = new Date();
  6831. inst.selectedDay = date.getDate();
  6832. inst.drawMonth = inst.selectedMonth = date.getMonth();
  6833. inst.drawYear = inst.selectedYear = date.getFullYear();
  6834. }
  6835. this._notifyChange(inst);
  6836. this._adjustDate(target);
  6837. },
  6838. /* Action for selecting a new month/year. */
  6839. _selectMonthYear: function(id, select, period) {
  6840. var target = $(id);
  6841. var inst = this._getInst(target[0]);
  6842. inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
  6843. inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
  6844. parseInt(select.options[select.selectedIndex].value,10);
  6845. this._notifyChange(inst);
  6846. this._adjustDate(target);
  6847. },
  6848. /* Action for selecting a day. */
  6849. _selectDay: function(id, month, year, td) {
  6850. var target = $(id);
  6851. if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
  6852. return;
  6853. }
  6854. var inst = this._getInst(target[0]);
  6855. inst.selectedDay = inst.currentDay = $('a', td).html();
  6856. inst.selectedMonth = inst.currentMonth = month;
  6857. inst.selectedYear = inst.currentYear = year;
  6858. this._selectDate(id, this._formatDate(inst,
  6859. inst.currentDay, inst.currentMonth, inst.currentYear));
  6860. },
  6861. /* Erase the input field and hide the date picker. */
  6862. _clearDate: function(id) {
  6863. var target = $(id);
  6864. var inst = this._getInst(target[0]);
  6865. this._selectDate(target, '');
  6866. },
  6867. /* Update the input field with the selected date. */
  6868. _selectDate: function(id, dateStr) {
  6869. var target = $(id);
  6870. var inst = this._getInst(target[0]);
  6871. dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
  6872. if (inst.input)
  6873. inst.input.val(dateStr);
  6874. this._updateAlternate(inst);
  6875. var onSelect = this._get(inst, 'onSelect');
  6876. if (onSelect)
  6877. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
  6878. else if (inst.input)
  6879. inst.input.trigger('change'); // fire the change event
  6880. if (inst.inline)
  6881. this._updateDatepicker(inst);
  6882. else {
  6883. this._hideDatepicker();
  6884. this._lastInput = inst.input[0];
  6885. if (typeof(inst.input[0]) != 'object')
  6886. inst.input.focus(); // restore focus
  6887. this._lastInput = null;
  6888. }
  6889. },
  6890. /* Update any alternate field to synchronise with the main field. */
  6891. _updateAlternate: function(inst) {
  6892. var altField = this._get(inst, 'altField');
  6893. if (altField) { // update alternate field too
  6894. var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
  6895. var date = this._getDate(inst);
  6896. var dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
  6897. $(altField).each(function() { $(this).val(dateStr); });
  6898. }
  6899. },
  6900. /* Set as beforeShowDay function to prevent selection of weekends.
  6901. @param date Date - the date to customise
  6902. @return [boolean, string] - is this date selectable?, what is its CSS class? */
  6903. noWeekends: function(date) {
  6904. var day = date.getDay();
  6905. return [(day > 0 && day < 6), ''];
  6906. },
  6907. /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
  6908. @param date Date - the date to get the week for
  6909. @return number - the number of the week within the year that contains this date */
  6910. iso8601Week: function(date) {
  6911. var checkDate = new Date(date.getTime());
  6912. // Find Thursday of this week starting on Monday
  6913. checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
  6914. var time = checkDate.getTime();
  6915. checkDate.setMonth(0); // Compare with Jan 1
  6916. checkDate.setDate(1);
  6917. return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
  6918. },
  6919. /* Parse a string value into a date object.
  6920. See formatDate below for the possible formats.
  6921. @param format string - the expected format of the date
  6922. @param value string - the date in the above format
  6923. @param settings Object - attributes include:
  6924. shortYearCutoff number - the cutoff year for determining the century (optional)
  6925. dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  6926. dayNames string[7] - names of the days from Sunday (optional)
  6927. monthNamesShort string[12] - abbreviated names of the months (optional)
  6928. monthNames string[12] - names of the months (optional)
  6929. @return Date - the extracted date value or null if value is blank */
  6930. parseDate: function (format, value, settings) {
  6931. if (format == null || value == null)
  6932. throw 'Invalid arguments';
  6933. value = (typeof value == 'object' ? value.toString() : value + '');
  6934. if (value == '')
  6935. return null;
  6936. var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
  6937. shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
  6938. new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
  6939. var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
  6940. var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
  6941. var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
  6942. var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
  6943. var year = -1;
  6944. var month = -1;
  6945. var day = -1;
  6946. var doy = -1;
  6947. var literal = false;
  6948. // Check whether a format character is doubled
  6949. var lookAhead = function(match) {
  6950. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  6951. if (matches)
  6952. iFormat++;
  6953. return matches;
  6954. };
  6955. // Extract a number from the string value
  6956. var getNumber = function(match) {
  6957. var isDoubled = lookAhead(match);
  6958. var size = (match == '@' ? 14 : (match == '!' ? 20 :
  6959. (match == 'y' && isDoubled ? 4 : (match == 'o' ? 3 : 2))));
  6960. var digits = new RegExp('^\\d{1,' + size + '}');
  6961. var num = value.substring(iValue).match(digits);
  6962. if (!num)
  6963. throw 'Missing number at position ' + iValue;
  6964. iValue += num[0].length;
  6965. return parseInt(num[0], 10);
  6966. };
  6967. // Extract a name from the string value and convert to an index
  6968. var getName = function(match, shortNames, longNames) {
  6969. var names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
  6970. return [ [k, v] ];
  6971. }).sort(function (a, b) {
  6972. return -(a[1].length - b[1].length);
  6973. });
  6974. var index = -1;
  6975. $.each(names, function (i, pair) {
  6976. var name = pair[1];
  6977. if (value.substr(iValue, name.length).toLowerCase() == name.toLowerCase()) {
  6978. index = pair[0];
  6979. iValue += name.length;
  6980. return false;
  6981. }
  6982. });
  6983. if (index != -1)
  6984. return index + 1;
  6985. else
  6986. throw 'Unknown name at position ' + iValue;
  6987. };
  6988. // Confirm that a literal character matches the string value
  6989. var checkLiteral = function() {
  6990. if (value.charAt(iValue) != format.charAt(iFormat))
  6991. throw 'Unexpected literal at position ' + iValue;
  6992. iValue++;
  6993. };
  6994. var iValue = 0;
  6995. for (var iFormat = 0; iFormat < format.length; iFormat++) {
  6996. if (literal)
  6997. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  6998. literal = false;
  6999. else
  7000. checkLiteral();
  7001. else
  7002. switch (format.charAt(iFormat)) {
  7003. case 'd':
  7004. day = getNumber('d');
  7005. break;
  7006. case 'D':
  7007. getName('D', dayNamesShort, dayNames);
  7008. break;
  7009. case 'o':
  7010. doy = getNumber('o');
  7011. break;
  7012. case 'm':
  7013. month = getNumber('m');
  7014. break;
  7015. case 'M':
  7016. month = getName('M', monthNamesShort, monthNames);
  7017. break;
  7018. case 'y':
  7019. year = getNumber('y');
  7020. break;
  7021. case '@':
  7022. var date = new Date(getNumber('@'));
  7023. year = date.getFullYear();
  7024. month = date.getMonth() + 1;
  7025. day = date.getDate();
  7026. break;
  7027. case '!':
  7028. var date = new Date((getNumber('!') - this._ticksTo1970) / 10000);
  7029. year = date.getFullYear();
  7030. month = date.getMonth() + 1;
  7031. day = date.getDate();
  7032. break;
  7033. case "'":
  7034. if (lookAhead("'"))
  7035. checkLiteral();
  7036. else
  7037. literal = true;
  7038. break;
  7039. default:
  7040. checkLiteral();
  7041. }
  7042. }
  7043. if (iValue < value.length){
  7044. var extra = value.substr(iValue);
  7045. if (!/^\s+/.test(extra)) {
  7046. throw "Extra/unparsed characters found in date: " + extra;
  7047. }
  7048. }
  7049. if (year == -1)
  7050. year = new Date().getFullYear();
  7051. else if (year < 100)
  7052. year += new Date().getFullYear() - new Date().getFullYear() % 100 +
  7053. (year <= shortYearCutoff ? 0 : -100);
  7054. if (doy > -1) {
  7055. month = 1;
  7056. day = doy;
  7057. do {
  7058. var dim = this._getDaysInMonth(year, month - 1);
  7059. if (day <= dim)
  7060. break;
  7061. month++;
  7062. day -= dim;
  7063. } while (true);
  7064. }
  7065. var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
  7066. if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
  7067. throw 'Invalid date'; // E.g. 31/02/00
  7068. return date;
  7069. },
  7070. /* Standard date formats. */
  7071. ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
  7072. COOKIE: 'D, dd M yy',
  7073. ISO_8601: 'yy-mm-dd',
  7074. RFC_822: 'D, d M y',
  7075. RFC_850: 'DD, dd-M-y',
  7076. RFC_1036: 'D, d M y',
  7077. RFC_1123: 'D, d M yy',
  7078. RFC_2822: 'D, d M yy',
  7079. RSS: 'D, d M y', // RFC 822
  7080. TICKS: '!',
  7081. TIMESTAMP: '@',
  7082. W3C: 'yy-mm-dd', // ISO 8601
  7083. _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
  7084. Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
  7085. /* Format a date object into a string value.
  7086. The format can be combinations of the following:
  7087. d - day of month (no leading zero)
  7088. dd - day of month (two digit)
  7089. o - day of year (no leading zeros)
  7090. oo - day of year (three digit)
  7091. D - day name short
  7092. DD - day name long
  7093. m - month of year (no leading zero)
  7094. mm - month of year (two digit)
  7095. M - month name short
  7096. MM - month name long
  7097. y - year (two digit)
  7098. yy - year (four digit)
  7099. @ - Unix timestamp (ms since 01/01/1970)
  7100. ! - Windows ticks (100ns since 01/01/0001)
  7101. '...' - literal text
  7102. '' - single quote
  7103. @param format string - the desired format of the date
  7104. @param date Date - the date value to format
  7105. @param settings Object - attributes include:
  7106. dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  7107. dayNames string[7] - names of the days from Sunday (optional)
  7108. monthNamesShort string[12] - abbreviated names of the months (optional)
  7109. monthNames string[12] - names of the months (optional)
  7110. @return string - the date in the above format */
  7111. formatDate: function (format, date, settings) {
  7112. if (!date)
  7113. return '';
  7114. var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
  7115. var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
  7116. var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
  7117. var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
  7118. // Check whether a format character is doubled
  7119. var lookAhead = function(match) {
  7120. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  7121. if (matches)
  7122. iFormat++;
  7123. return matches;
  7124. };
  7125. // Format a number, with leading zero if necessary
  7126. var formatNumber = function(match, value, len) {
  7127. var num = '' + value;
  7128. if (lookAhead(match))
  7129. while (num.length < len)
  7130. num = '0' + num;
  7131. return num;
  7132. };
  7133. // Format a name, short or long as requested
  7134. var formatName = function(match, value, shortNames, longNames) {
  7135. return (lookAhead(match) ? longNames[value] : shortNames[value]);
  7136. };
  7137. var output = '';
  7138. var literal = false;
  7139. if (date)
  7140. for (var iFormat = 0; iFormat < format.length; iFormat++) {
  7141. if (literal)
  7142. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  7143. literal = false;
  7144. else
  7145. output += format.charAt(iFormat);
  7146. else
  7147. switch (format.charAt(iFormat)) {
  7148. case 'd':
  7149. output += formatNumber('d', date.getDate(), 2);
  7150. break;
  7151. case 'D':
  7152. output += formatName('D', date.getDay(), dayNamesShort, dayNames);
  7153. break;
  7154. case 'o':
  7155. output += formatNumber('o',
  7156. Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
  7157. break;
  7158. case 'm':
  7159. output += formatNumber('m', date.getMonth() + 1, 2);
  7160. break;
  7161. case 'M':
  7162. output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
  7163. break;
  7164. case 'y':
  7165. output += (lookAhead('y') ? date.getFullYear() :
  7166. (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
  7167. break;
  7168. case '@':
  7169. output += date.getTime();
  7170. break;
  7171. case '!':
  7172. output += date.getTime() * 10000 + this._ticksTo1970;
  7173. break;
  7174. case "'":
  7175. if (lookAhead("'"))
  7176. output += "'";
  7177. else
  7178. literal = true;
  7179. break;
  7180. default:
  7181. output += format.charAt(iFormat);
  7182. }
  7183. }
  7184. return output;
  7185. },
  7186. /* Extract all possible characters from the date format. */
  7187. _possibleChars: function (format) {
  7188. var chars = '';
  7189. var literal = false;
  7190. // Check whether a format character is doubled
  7191. var lookAhead = function(match) {
  7192. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  7193. if (matches)
  7194. iFormat++;
  7195. return matches;
  7196. };
  7197. for (var iFormat = 0; iFormat < format.length; iFormat++)
  7198. if (literal)
  7199. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  7200. literal = false;
  7201. else
  7202. chars += format.charAt(iFormat);
  7203. else
  7204. switch (format.charAt(iFormat)) {
  7205. case 'd': case 'm': case 'y': case '@':
  7206. chars += '0123456789';
  7207. break;
  7208. case 'D': case 'M':
  7209. return null; // Accept anything
  7210. case "'":
  7211. if (lookAhead("'"))
  7212. chars += "'";
  7213. else
  7214. literal = true;
  7215. break;
  7216. default:
  7217. chars += format.charAt(iFormat);
  7218. }
  7219. return chars;
  7220. },
  7221. /* Get a setting value, defaulting if necessary. */
  7222. _get: function(inst, name) {
  7223. return inst.settings[name] !== undefined ?
  7224. inst.settings[name] : this._defaults[name];
  7225. },
  7226. /* Parse existing date and initialise date picker. */
  7227. _setDateFromField: function(inst, noDefault) {
  7228. if (inst.input.val() == inst.lastVal) {
  7229. return;
  7230. }
  7231. var dateFormat = this._get(inst, 'dateFormat');
  7232. var dates = inst.lastVal = inst.input ? inst.input.val() : null;
  7233. var date, defaultDate;
  7234. date = defaultDate = this._getDefaultDate(inst);
  7235. var settings = this._getFormatConfig(inst);
  7236. try {
  7237. date = this.parseDate(dateFormat, dates, settings) || defaultDate;
  7238. } catch (event) {
  7239. this.log(event);
  7240. dates = (noDefault ? '' : dates);
  7241. }
  7242. inst.selectedDay = date.getDate();
  7243. inst.drawMonth = inst.selectedMonth = date.getMonth();
  7244. inst.drawYear = inst.selectedYear = date.getFullYear();
  7245. inst.currentDay = (dates ? date.getDate() : 0);
  7246. inst.currentMonth = (dates ? date.getMonth() : 0);
  7247. inst.currentYear = (dates ? date.getFullYear() : 0);
  7248. this._adjustInstDate(inst);
  7249. },
  7250. /* Retrieve the default date shown on opening. */
  7251. _getDefaultDate: function(inst) {
  7252. return this._restrictMinMax(inst,
  7253. this._determineDate(inst, this._get(inst, 'defaultDate'), new Date()));
  7254. },
  7255. /* A date may be specified as an exact value or a relative one. */
  7256. _determineDate: function(inst, date, defaultDate) {
  7257. var offsetNumeric = function(offset) {
  7258. var date = new Date();
  7259. date.setDate(date.getDate() + offset);
  7260. return date;
  7261. };
  7262. var offsetString = function(offset) {
  7263. try {
  7264. return $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
  7265. offset, $.datepicker._getFormatConfig(inst));
  7266. }
  7267. catch (e) {
  7268. // Ignore
  7269. }
  7270. var date = (offset.toLowerCase().match(/^c/) ?
  7271. $.datepicker._getDate(inst) : null) || new Date();
  7272. var year = date.getFullYear();
  7273. var month = date.getMonth();
  7274. var day = date.getDate();
  7275. var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
  7276. var matches = pattern.exec(offset);
  7277. while (matches) {
  7278. switch (matches[2] || 'd') {
  7279. case 'd' : case 'D' :
  7280. day += parseInt(matches[1],10); break;
  7281. case 'w' : case 'W' :
  7282. day += parseInt(matches[1],10) * 7; break;
  7283. case 'm' : case 'M' :
  7284. month += parseInt(matches[1],10);
  7285. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  7286. break;
  7287. case 'y': case 'Y' :
  7288. year += parseInt(matches[1],10);
  7289. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  7290. break;
  7291. }
  7292. matches = pattern.exec(offset);
  7293. }
  7294. return new Date(year, month, day);
  7295. };
  7296. var newDate = (date == null || date === '' ? defaultDate : (typeof date == 'string' ? offsetString(date) :
  7297. (typeof date == 'number' ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));
  7298. newDate = (newDate && newDate.toString() == 'Invalid Date' ? defaultDate : newDate);
  7299. if (newDate) {
  7300. newDate.setHours(0);
  7301. newDate.setMinutes(0);
  7302. newDate.setSeconds(0);
  7303. newDate.setMilliseconds(0);
  7304. }
  7305. return this._daylightSavingAdjust(newDate);
  7306. },
  7307. /* Handle switch to/from daylight saving.
  7308. Hours may be non-zero on daylight saving cut-over:
  7309. > 12 when midnight changeover, but then cannot generate
  7310. midnight datetime, so jump to 1AM, otherwise reset.
  7311. @param date (Date) the date to check
  7312. @return (Date) the corrected date */
  7313. _daylightSavingAdjust: function(date) {
  7314. if (!date) return null;
  7315. date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
  7316. return date;
  7317. },
  7318. /* Set the date(s) directly. */
  7319. _setDate: function(inst, date, noChange) {
  7320. var clear = !date;
  7321. var origMonth = inst.selectedMonth;
  7322. var origYear = inst.selectedYear;
  7323. var newDate = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
  7324. inst.selectedDay = inst.currentDay = newDate.getDate();
  7325. inst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth();
  7326. inst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear();
  7327. if ((origMonth != inst.selectedMonth || origYear != inst.selectedYear) && !noChange)
  7328. this._notifyChange(inst);
  7329. this._adjustInstDate(inst);
  7330. if (inst.input) {
  7331. inst.input.val(clear ? '' : this._formatDate(inst));
  7332. }
  7333. },
  7334. /* Retrieve the date(s) directly. */
  7335. _getDate: function(inst) {
  7336. var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null :
  7337. this._daylightSavingAdjust(new Date(
  7338. inst.currentYear, inst.currentMonth, inst.currentDay)));
  7339. return startDate;
  7340. },
  7341. /* Attach the onxxx handlers. These are declared statically so
  7342. * they work with static code transformers like Caja.
  7343. */
  7344. _attachHandlers: function(inst) {
  7345. var stepMonths = this._get(inst, 'stepMonths');
  7346. var id = '#' + inst.id.replace( /\\\\/g, "\\" );
  7347. inst.dpDiv.find('[data-handler]').map(function () {
  7348. var handler = {
  7349. prev: function () {
  7350. window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, -stepMonths, 'M');
  7351. },
  7352. next: function () {
  7353. window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, +stepMonths, 'M');
  7354. },
  7355. hide: function () {
  7356. window['DP_jQuery_' + dpuuid].datepicker._hideDatepicker();
  7357. },
  7358. today: function () {
  7359. window['DP_jQuery_' + dpuuid].datepicker._gotoToday(id);
  7360. },
  7361. selectDay: function () {
  7362. window['DP_jQuery_' + dpuuid].datepicker._selectDay(id, +this.getAttribute('data-month'), +this.getAttribute('data-year'), this);
  7363. return false;
  7364. },
  7365. selectMonth: function () {
  7366. window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'M');
  7367. return false;
  7368. },
  7369. selectYear: function () {
  7370. window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'Y');
  7371. return false;
  7372. }
  7373. };
  7374. $(this).bind(this.getAttribute('data-event'), handler[this.getAttribute('data-handler')]);
  7375. });
  7376. },
  7377. /* Generate the HTML for the current state of the date picker. */
  7378. _generateHTML: function(inst) {
  7379. var today = new Date();
  7380. today = this._daylightSavingAdjust(
  7381. new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
  7382. var isRTL = this._get(inst, 'isRTL');
  7383. var showButtonPanel = this._get(inst, 'showButtonPanel');
  7384. var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
  7385. var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
  7386. var numMonths = this._getNumberOfMonths(inst);
  7387. var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
  7388. var stepMonths = this._get(inst, 'stepMonths');
  7389. var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
  7390. var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
  7391. new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  7392. var minDate = this._getMinMaxDate(inst, 'min');
  7393. var maxDate = this._getMinMaxDate(inst, 'max');
  7394. var drawMonth = inst.drawMonth - showCurrentAtPos;
  7395. var drawYear = inst.drawYear;
  7396. if (drawMonth < 0) {
  7397. drawMonth += 12;
  7398. drawYear--;
  7399. }
  7400. if (maxDate) {
  7401. var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
  7402. maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
  7403. maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
  7404. while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
  7405. drawMonth--;
  7406. if (drawMonth < 0) {
  7407. drawMonth = 11;
  7408. drawYear--;
  7409. }
  7410. }
  7411. }
  7412. inst.drawMonth = drawMonth;
  7413. inst.drawYear = drawYear;
  7414. var prevText = this._get(inst, 'prevText');
  7415. prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
  7416. this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
  7417. this._getFormatConfig(inst)));
  7418. var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
  7419. '<a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click"' +
  7420. ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
  7421. (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>'));
  7422. var nextText = this._get(inst, 'nextText');
  7423. nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
  7424. this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
  7425. this._getFormatConfig(inst)));
  7426. var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
  7427. '<a class="ui-datepicker-next ui-corner-all" data-handler="next" data-event="click"' +
  7428. ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
  7429. (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>'));
  7430. var currentText = this._get(inst, 'currentText');
  7431. var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
  7432. currentText = (!navigationAsDateFormat ? currentText :
  7433. this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
  7434. var 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">' +
  7435. this._get(inst, 'closeText') + '</button>' : '');
  7436. var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
  7437. (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"' +
  7438. '>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
  7439. var firstDay = parseInt(this._get(inst, 'firstDay'),10);
  7440. firstDay = (isNaN(firstDay) ? 0 : firstDay);
  7441. var showWeek = this._get(inst, 'showWeek');
  7442. var dayNames = this._get(inst, 'dayNames');
  7443. var dayNamesShort = this._get(inst, 'dayNamesShort');
  7444. var dayNamesMin = this._get(inst, 'dayNamesMin');
  7445. var monthNames = this._get(inst, 'monthNames');
  7446. var monthNamesShort = this._get(inst, 'monthNamesShort');
  7447. var beforeShowDay = this._get(inst, 'beforeShowDay');
  7448. var showOtherMonths = this._get(inst, 'showOtherMonths');
  7449. var selectOtherMonths = this._get(inst, 'selectOtherMonths');
  7450. var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
  7451. var defaultDate = this._getDefaultDate(inst);
  7452. var html = '';
  7453. for (var row = 0; row < numMonths[0]; row++) {
  7454. var group = '';
  7455. this.maxRows = 4;
  7456. for (var col = 0; col < numMonths[1]; col++) {
  7457. var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
  7458. var cornerClass = ' ui-corner-all';
  7459. var calender = '';
  7460. if (isMultiMonth) {
  7461. calender += '<div class="ui-datepicker-group';
  7462. if (numMonths[1] > 1)
  7463. switch (col) {
  7464. case 0: calender += ' ui-datepicker-group-first';
  7465. cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
  7466. case numMonths[1]-1: calender += ' ui-datepicker-group-last';
  7467. cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
  7468. default: calender += ' ui-datepicker-group-middle'; cornerClass = ''; break;
  7469. }
  7470. calender += '">';
  7471. }
  7472. calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
  7473. (/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
  7474. (/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
  7475. this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
  7476. row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
  7477. '</div><table class="ui-datepicker-calendar"><thead>' +
  7478. '<tr>';
  7479. var thead = (showWeek ? '<th class="ui-datepicker-week-col">' + this._get(inst, 'weekHeader') + '</th>' : '');
  7480. for (var dow = 0; dow < 7; dow++) { // days of the week
  7481. var day = (dow + firstDay) % 7;
  7482. thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
  7483. '<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
  7484. }
  7485. calender += thead + '</tr></thead><tbody>';
  7486. var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
  7487. if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
  7488. inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
  7489. var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
  7490. var curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
  7491. var numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
  7492. this.maxRows = numRows;
  7493. var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
  7494. for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
  7495. calender += '<tr>';
  7496. var tbody = (!showWeek ? '' : '<td class="ui-datepicker-week-col">' +
  7497. this._get(inst, 'calculateWeek')(printDate) + '</td>');
  7498. for (var dow = 0; dow < 7; dow++) { // create date picker days
  7499. var daySettings = (beforeShowDay ?
  7500. beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
  7501. var otherMonth = (printDate.getMonth() != drawMonth);
  7502. var unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
  7503. (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
  7504. tbody += '<td class="' +
  7505. ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
  7506. (otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
  7507. ((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
  7508. (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
  7509. // or defaultDate is current printedDate and defaultDate is selectedDate
  7510. ' ' + this._dayOverClass : '') + // highlight selected day
  7511. (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable days
  7512. (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
  7513. (printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
  7514. (printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
  7515. ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
  7516. (unselectable ? '' : ' data-handler="selectDay" data-event="click" data-month="' + printDate.getMonth() + '" data-year="' + printDate.getFullYear() + '"') + '>' + // actions
  7517. (otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
  7518. (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
  7519. (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
  7520. (printDate.getTime() == currentDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
  7521. (otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
  7522. '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
  7523. printDate.setDate(printDate.getDate() + 1);
  7524. printDate = this._daylightSavingAdjust(printDate);
  7525. }
  7526. calender += tbody + '</tr>';
  7527. }
  7528. drawMonth++;
  7529. if (drawMonth > 11) {
  7530. drawMonth = 0;
  7531. drawYear++;
  7532. }
  7533. calender += '</tbody></table>' + (isMultiMonth ? '</div>' +
  7534. ((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
  7535. group += calender;
  7536. }
  7537. html += group;
  7538. }
  7539. html += buttonPanel + ($.ui.ie6 && !inst.inline ?
  7540. '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
  7541. inst._keyEvent = false;
  7542. return html;
  7543. },
  7544. /* Generate the month and year header. */
  7545. _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
  7546. secondary, monthNames, monthNamesShort) {
  7547. var changeMonth = this._get(inst, 'changeMonth');
  7548. var changeYear = this._get(inst, 'changeYear');
  7549. var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');
  7550. var html = '<div class="ui-datepicker-title">';
  7551. var monthHtml = '';
  7552. // month selection
  7553. if (secondary || !changeMonth)
  7554. monthHtml += '<span class="ui-datepicker-month">' + monthNames[drawMonth] + '</span>';
  7555. else {
  7556. var inMinYear = (minDate && minDate.getFullYear() == drawYear);
  7557. var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
  7558. monthHtml += '<select class="ui-datepicker-month" data-handler="selectMonth" data-event="change">';
  7559. for (var month = 0; month < 12; month++) {
  7560. if ((!inMinYear || month >= minDate.getMonth()) &&
  7561. (!inMaxYear || month <= maxDate.getMonth()))
  7562. monthHtml += '<option value="' + month + '"' +
  7563. (month == drawMonth ? ' selected="selected"' : '') +
  7564. '>' + monthNamesShort[month] + '</option>';
  7565. }
  7566. monthHtml += '</select>';
  7567. }
  7568. if (!showMonthAfterYear)
  7569. html += monthHtml + (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '');
  7570. // year selection
  7571. if ( !inst.yearshtml ) {
  7572. inst.yearshtml = '';
  7573. if (secondary || !changeYear)
  7574. html += '<span class="ui-datepicker-year">' + drawYear + '</span>';
  7575. else {
  7576. // determine range of years to display
  7577. var years = this._get(inst, 'yearRange').split(':');
  7578. var thisYear = new Date().getFullYear();
  7579. var determineYear = function(value) {
  7580. var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
  7581. (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
  7582. parseInt(value, 10)));
  7583. return (isNaN(year) ? thisYear : year);
  7584. };
  7585. var year = determineYear(years[0]);
  7586. var endYear = Math.max(year, determineYear(years[1] || ''));
  7587. year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
  7588. endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
  7589. inst.yearshtml += '<select class="ui-datepicker-year" data-handler="selectYear" data-event="change">';
  7590. for (; year <= endYear; year++) {
  7591. inst.yearshtml += '<option value="' + year + '"' +
  7592. (year == drawYear ? ' selected="selected"' : '') +
  7593. '>' + year + '</option>';
  7594. }
  7595. inst.yearshtml += '</select>';
  7596. html += inst.yearshtml;
  7597. inst.yearshtml = null;
  7598. }
  7599. }
  7600. html += this._get(inst, 'yearSuffix');
  7601. if (showMonthAfterYear)
  7602. html += (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '') + monthHtml;
  7603. html += '</div>'; // Close datepicker_header
  7604. return html;
  7605. },
  7606. /* Adjust one of the date sub-fields. */
  7607. _adjustInstDate: function(inst, offset, period) {
  7608. var year = inst.drawYear + (period == 'Y' ? offset : 0);
  7609. var month = inst.drawMonth + (period == 'M' ? offset : 0);
  7610. var day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) +
  7611. (period == 'D' ? offset : 0);
  7612. var date = this._restrictMinMax(inst,
  7613. this._daylightSavingAdjust(new Date(year, month, day)));
  7614. inst.selectedDay = date.getDate();
  7615. inst.drawMonth = inst.selectedMonth = date.getMonth();
  7616. inst.drawYear = inst.selectedYear = date.getFullYear();
  7617. if (period == 'M' || period == 'Y')
  7618. this._notifyChange(inst);
  7619. },
  7620. /* Ensure a date is within any min/max bounds. */
  7621. _restrictMinMax: function(inst, date) {
  7622. var minDate = this._getMinMaxDate(inst, 'min');
  7623. var maxDate = this._getMinMaxDate(inst, 'max');
  7624. var newDate = (minDate && date < minDate ? minDate : date);
  7625. newDate = (maxDate && newDate > maxDate ? maxDate : newDate);
  7626. return newDate;
  7627. },
  7628. /* Notify change of month/year. */
  7629. _notifyChange: function(inst) {
  7630. var onChange = this._get(inst, 'onChangeMonthYear');
  7631. if (onChange)
  7632. onChange.apply((inst.input ? inst.input[0] : null),
  7633. [inst.selectedYear, inst.selectedMonth + 1, inst]);
  7634. },
  7635. /* Determine the number of months to show. */
  7636. _getNumberOfMonths: function(inst) {
  7637. var numMonths = this._get(inst, 'numberOfMonths');
  7638. return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
  7639. },
  7640. /* Determine the current maximum date - ensure no time components are set. */
  7641. _getMinMaxDate: function(inst, minMax) {
  7642. return this._determineDate(inst, this._get(inst, minMax + 'Date'), null);
  7643. },
  7644. /* Find the number of days in a given month. */
  7645. _getDaysInMonth: function(year, month) {
  7646. return 32 - this._daylightSavingAdjust(new Date(year, month, 32)).getDate();
  7647. },
  7648. /* Find the day of the week of the first of a month. */
  7649. _getFirstDayOfMonth: function(year, month) {
  7650. return new Date(year, month, 1).getDay();
  7651. },
  7652. /* Determines if we should allow a "next/prev" month display change. */
  7653. _canAdjustMonth: function(inst, offset, curYear, curMonth) {
  7654. var numMonths = this._getNumberOfMonths(inst);
  7655. var date = this._daylightSavingAdjust(new Date(curYear,
  7656. curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
  7657. if (offset < 0)
  7658. date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
  7659. return this._isInRange(inst, date);
  7660. },
  7661. /* Is the given date in the accepted range? */
  7662. _isInRange: function(inst, date) {
  7663. var minDate = this._getMinMaxDate(inst, 'min');
  7664. var maxDate = this._getMinMaxDate(inst, 'max');
  7665. return ((!minDate || date.getTime() >= minDate.getTime()) &&
  7666. (!maxDate || date.getTime() <= maxDate.getTime()));
  7667. },
  7668. /* Provide the configuration settings for formatting/parsing. */
  7669. _getFormatConfig: function(inst) {
  7670. var shortYearCutoff = this._get(inst, 'shortYearCutoff');
  7671. shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
  7672. new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
  7673. return {shortYearCutoff: shortYearCutoff,
  7674. dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'),
  7675. monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')};
  7676. },
  7677. /* Format the given date for display. */
  7678. _formatDate: function(inst, day, month, year) {
  7679. if (!day) {
  7680. inst.currentDay = inst.selectedDay;
  7681. inst.currentMonth = inst.selectedMonth;
  7682. inst.currentYear = inst.selectedYear;
  7683. }
  7684. var date = (day ? (typeof day == 'object' ? day :
  7685. this._daylightSavingAdjust(new Date(year, month, day))) :
  7686. this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  7687. return this.formatDate(this._get(inst, 'dateFormat'), date, this._getFormatConfig(inst));
  7688. }
  7689. });
  7690. /*
  7691. * Bind hover events for datepicker elements.
  7692. * Done via delegate so the binding only occurs once in the lifetime of the parent div.
  7693. * Global instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.
  7694. */
  7695. function bindHover(dpDiv) {
  7696. var selector = 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a';
  7697. return dpDiv.delegate(selector, 'mouseout', function() {
  7698. $(this).removeClass('ui-state-hover');
  7699. if (this.className.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover');
  7700. if (this.className.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover');
  7701. })
  7702. .delegate(selector, 'mouseover', function(){
  7703. if (!$.datepicker._isDisabledDatepicker( instActive.inline ? dpDiv.parent()[0] : instActive.input[0])) {
  7704. $(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
  7705. $(this).addClass('ui-state-hover');
  7706. if (this.className.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover');
  7707. if (this.className.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover');
  7708. }
  7709. });
  7710. }
  7711. /* jQuery extend now ignores nulls! */
  7712. function extendRemove(target, props) {
  7713. $.extend(target, props);
  7714. for (var name in props)
  7715. if (props[name] == null || props[name] == undefined)
  7716. target[name] = props[name];
  7717. return target;
  7718. };
  7719. /* Invoke the datepicker functionality.
  7720. @param options string - a command, optionally followed by additional parameters or
  7721. Object - settings for attaching new datepicker functionality
  7722. @return jQuery object */
  7723. $.fn.datepicker = function(options){
  7724. /* Verify an empty collection wasn't passed - Fixes #6976 */
  7725. if ( !this.length ) {
  7726. return this;
  7727. }
  7728. /* Initialise the date picker. */
  7729. if (!$.datepicker.initialized) {
  7730. $(document).mousedown($.datepicker._checkExternalClick).
  7731. find(document.body).append($.datepicker.dpDiv);
  7732. $.datepicker.initialized = true;
  7733. }
  7734. var otherArgs = Array.prototype.slice.call(arguments, 1);
  7735. if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget'))
  7736. return $.datepicker['_' + options + 'Datepicker'].
  7737. apply($.datepicker, [this[0]].concat(otherArgs));
  7738. if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
  7739. return $.datepicker['_' + options + 'Datepicker'].
  7740. apply($.datepicker, [this[0]].concat(otherArgs));
  7741. return this.each(function() {
  7742. typeof options == 'string' ?
  7743. $.datepicker['_' + options + 'Datepicker'].
  7744. apply($.datepicker, [this].concat(otherArgs)) :
  7745. $.datepicker._attachDatepicker(this, options);
  7746. });
  7747. };
  7748. $.datepicker = new Datepicker(); // singleton instance
  7749. $.datepicker.initialized = false;
  7750. $.datepicker.uuid = new Date().getTime();
  7751. $.datepicker.version = "1.9.2";
  7752. // Workaround for #4055
  7753. // Add another global to avoid noConflict issues with inline event handlers
  7754. window['DP_jQuery_' + dpuuid] = $;
  7755. })(jQuery);
  7756. (function( $, undefined ) {
  7757. var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
  7758. sizeRelatedOptions = {
  7759. buttons: true,
  7760. height: true,
  7761. maxHeight: true,
  7762. maxWidth: true,
  7763. minHeight: true,
  7764. minWidth: true,
  7765. width: true
  7766. },
  7767. resizableRelatedOptions = {
  7768. maxHeight: true,
  7769. maxWidth: true,
  7770. minHeight: true,
  7771. minWidth: true
  7772. };
  7773. $.widget("ui.dialog", {
  7774. version: "1.9.2",
  7775. options: {
  7776. autoOpen: true,
  7777. buttons: {},
  7778. closeOnEscape: true,
  7779. closeText: "close",
  7780. dialogClass: "",
  7781. draggable: true,
  7782. hide: null,
  7783. height: "auto",
  7784. maxHeight: false,
  7785. maxWidth: false,
  7786. minHeight: 150,
  7787. minWidth: 150,
  7788. modal: false,
  7789. position: {
  7790. my: "center",
  7791. at: "center",
  7792. of: window,
  7793. collision: "fit",
  7794. // ensure that the titlebar is never outside the document
  7795. using: function( pos ) {
  7796. var topOffset = $( this ).css( pos ).offset().top;
  7797. if ( topOffset < 0 ) {
  7798. $( this ).css( "top", pos.top - topOffset );
  7799. }
  7800. }
  7801. },
  7802. resizable: true,
  7803. show: null,
  7804. stack: true,
  7805. title: "",
  7806. width: 300,
  7807. zIndex: 1000
  7808. },
  7809. _create: function() {
  7810. this.originalTitle = this.element.attr( "title" );
  7811. // #5742 - .attr() might return a DOMElement
  7812. if ( typeof this.originalTitle !== "string" ) {
  7813. this.originalTitle = "";
  7814. }
  7815. this.oldPosition = {
  7816. parent: this.element.parent(),
  7817. index: this.element.parent().children().index( this.element )
  7818. };
  7819. this.options.title = this.options.title || this.originalTitle;
  7820. var that = this,
  7821. options = this.options,
  7822. title = options.title || "&#160;",
  7823. uiDialog,
  7824. uiDialogTitlebar,
  7825. uiDialogTitlebarClose,
  7826. uiDialogTitle,
  7827. uiDialogButtonPane;
  7828. uiDialog = ( this.uiDialog = $( "<div>" ) )
  7829. .addClass( uiDialogClasses + options.dialogClass )
  7830. .css({
  7831. display: "none",
  7832. outline: 0, // TODO: move to stylesheet
  7833. zIndex: options.zIndex
  7834. })
  7835. // setting tabIndex makes the div focusable
  7836. .attr( "tabIndex", -1)
  7837. .keydown(function( event ) {
  7838. if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
  7839. event.keyCode === $.ui.keyCode.ESCAPE ) {
  7840. that.close( event );
  7841. event.preventDefault();
  7842. }
  7843. })
  7844. .mousedown(function( event ) {
  7845. that.moveToTop( false, event );
  7846. })
  7847. .appendTo( "body" );
  7848. this.element
  7849. .show()
  7850. .removeAttr( "title" )
  7851. .addClass( "ui-dialog-content ui-widget-content" )
  7852. .appendTo( uiDialog );
  7853. uiDialogTitlebar = ( this.uiDialogTitlebar = $( "<div>" ) )
  7854. .addClass( "ui-dialog-titlebar ui-widget-header " +
  7855. "ui-corner-all ui-helper-clearfix" )
  7856. .bind( "mousedown", function() {
  7857. // Dialog isn't getting focus when dragging (#8063)
  7858. uiDialog.focus();
  7859. })
  7860. .prependTo( uiDialog );
  7861. uiDialogTitlebarClose = $( "<a href='#'></a>" )
  7862. .addClass( "ui-dialog-titlebar-close ui-corner-all" )
  7863. .attr( "role", "button" )
  7864. .click(function( event ) {
  7865. event.preventDefault();
  7866. that.close( event );
  7867. })
  7868. .appendTo( uiDialogTitlebar );
  7869. ( this.uiDialogTitlebarCloseText = $( "<span>" ) )
  7870. .addClass( "ui-icon ui-icon-closethick" )
  7871. .text( options.closeText )
  7872. .appendTo( uiDialogTitlebarClose );
  7873. uiDialogTitle = $( "<span>" )
  7874. .uniqueId()
  7875. .addClass( "ui-dialog-title" )
  7876. .html( title )
  7877. .prependTo( uiDialogTitlebar );
  7878. uiDialogButtonPane = ( this.uiDialogButtonPane = $( "<div>" ) )
  7879. .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" );
  7880. ( this.uiButtonSet = $( "<div>" ) )
  7881. .addClass( "ui-dialog-buttonset" )
  7882. .appendTo( uiDialogButtonPane );
  7883. uiDialog.attr({
  7884. role: "dialog",
  7885. "aria-labelledby": uiDialogTitle.attr( "id" )
  7886. });
  7887. uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection();
  7888. this._hoverable( uiDialogTitlebarClose );
  7889. this._focusable( uiDialogTitlebarClose );
  7890. if ( options.draggable && $.fn.draggable ) {
  7891. this._makeDraggable();
  7892. }
  7893. if ( options.resizable && $.fn.resizable ) {
  7894. this._makeResizable();
  7895. }
  7896. this._createButtons( options.buttons );
  7897. this._isOpen = false;
  7898. if ( $.fn.bgiframe ) {
  7899. uiDialog.bgiframe();
  7900. }
  7901. // prevent tabbing out of modal dialogs
  7902. this._on( uiDialog, { keydown: function( event ) {
  7903. if ( !options.modal || event.keyCode !== $.ui.keyCode.TAB ) {
  7904. return;
  7905. }
  7906. var tabbables = $( ":tabbable", uiDialog ),
  7907. first = tabbables.filter( ":first" ),
  7908. last = tabbables.filter( ":last" );
  7909. if ( event.target === last[0] && !event.shiftKey ) {
  7910. first.focus( 1 );
  7911. return false;
  7912. } else if ( event.target === first[0] && event.shiftKey ) {
  7913. last.focus( 1 );
  7914. return false;
  7915. }
  7916. }});
  7917. },
  7918. _init: function() {
  7919. if ( this.options.autoOpen ) {
  7920. this.open();
  7921. }
  7922. },
  7923. _destroy: function() {
  7924. var next,
  7925. oldPosition = this.oldPosition;
  7926. if ( this.overlay ) {
  7927. this.overlay.destroy();
  7928. }
  7929. this.uiDialog.hide();
  7930. this.element
  7931. .removeClass( "ui-dialog-content ui-widget-content" )
  7932. .hide()
  7933. .appendTo( "body" );
  7934. this.uiDialog.remove();
  7935. if ( this.originalTitle ) {
  7936. this.element.attr( "title", this.originalTitle );
  7937. }
  7938. next = oldPosition.parent.children().eq( oldPosition.index );
  7939. // Don't try to place the dialog next to itself (#8613)
  7940. if ( next.length && next[ 0 ] !== this.element[ 0 ] ) {
  7941. next.before( this.element );
  7942. } else {
  7943. oldPosition.parent.append( this.element );
  7944. }
  7945. },
  7946. widget: function() {
  7947. return this.uiDialog;
  7948. },
  7949. close: function( event ) {
  7950. var that = this,
  7951. maxZ, thisZ;
  7952. if ( !this._isOpen ) {
  7953. return;
  7954. }
  7955. if ( false === this._trigger( "beforeClose", event ) ) {
  7956. return;
  7957. }
  7958. this._isOpen = false;
  7959. if ( this.overlay ) {
  7960. this.overlay.destroy();
  7961. }
  7962. if ( this.options.hide ) {
  7963. this._hide( this.uiDialog, this.options.hide, function() {
  7964. that._trigger( "close", event );
  7965. });
  7966. } else {
  7967. this.uiDialog.hide();
  7968. this._trigger( "close", event );
  7969. }
  7970. $.ui.dialog.overlay.resize();
  7971. // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
  7972. if ( this.options.modal ) {
  7973. maxZ = 0;
  7974. $( ".ui-dialog" ).each(function() {
  7975. if ( this !== that.uiDialog[0] ) {
  7976. thisZ = $( this ).css( "z-index" );
  7977. if ( !isNaN( thisZ ) ) {
  7978. maxZ = Math.max( maxZ, thisZ );
  7979. }
  7980. }
  7981. });
  7982. $.ui.dialog.maxZ = maxZ;
  7983. }
  7984. return this;
  7985. },
  7986. isOpen: function() {
  7987. return this._isOpen;
  7988. },
  7989. // the force parameter allows us to move modal dialogs to their correct
  7990. // position on open
  7991. moveToTop: function( force, event ) {
  7992. var options = this.options,
  7993. saveScroll;
  7994. if ( ( options.modal && !force ) ||
  7995. ( !options.stack && !options.modal ) ) {
  7996. return this._trigger( "focus", event );
  7997. }
  7998. if ( options.zIndex > $.ui.dialog.maxZ ) {
  7999. $.ui.dialog.maxZ = options.zIndex;
  8000. }
  8001. if ( this.overlay ) {
  8002. $.ui.dialog.maxZ += 1;
  8003. $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ;
  8004. this.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ );
  8005. }
  8006. // Save and then restore scroll
  8007. // Opera 9.5+ resets when parent z-index is changed.
  8008. // http://bugs.jqueryui.com/ticket/3193
  8009. saveScroll = {
  8010. scrollTop: this.element.scrollTop(),
  8011. scrollLeft: this.element.scrollLeft()
  8012. };
  8013. $.ui.dialog.maxZ += 1;
  8014. this.uiDialog.css( "z-index", $.ui.dialog.maxZ );
  8015. this.element.attr( saveScroll );
  8016. this._trigger( "focus", event );
  8017. return this;
  8018. },
  8019. open: function() {
  8020. if ( this._isOpen ) {
  8021. return;
  8022. }
  8023. var hasFocus,
  8024. options = this.options,
  8025. uiDialog = this.uiDialog;
  8026. this._size();
  8027. this._position( options.position );
  8028. uiDialog.show( options.show );
  8029. this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null;
  8030. this.moveToTop( true );
  8031. // set focus to the first tabbable element in the content area or the first button
  8032. // if there are no tabbable elements, set focus on the dialog itself
  8033. hasFocus = this.element.find( ":tabbable" );
  8034. if ( !hasFocus.length ) {
  8035. hasFocus = this.uiDialogButtonPane.find( ":tabbable" );
  8036. if ( !hasFocus.length ) {
  8037. hasFocus = uiDialog;
  8038. }
  8039. }
  8040. hasFocus.eq( 0 ).focus();
  8041. this._isOpen = true;
  8042. this._trigger( "open" );
  8043. return this;
  8044. },
  8045. _createButtons: function( buttons ) {
  8046. var that = this,
  8047. hasButtons = false;
  8048. // if we already have a button pane, remove it
  8049. this.uiDialogButtonPane.remove();
  8050. this.uiButtonSet.empty();
  8051. if ( typeof buttons === "object" && buttons !== null ) {
  8052. $.each( buttons, function() {
  8053. return !(hasButtons = true);
  8054. });
  8055. }
  8056. if ( hasButtons ) {
  8057. $.each( buttons, function( name, props ) {
  8058. var button, click;
  8059. props = $.isFunction( props ) ?
  8060. { click: props, text: name } :
  8061. props;
  8062. // Default to a non-submitting button
  8063. props = $.extend( { type: "button" }, props );
  8064. // Change the context for the click callback to be the main element
  8065. click = props.click;
  8066. props.click = function() {
  8067. click.apply( that.element[0], arguments );
  8068. };
  8069. button = $( "<button></button>", props )
  8070. .appendTo( that.uiButtonSet );
  8071. if ( $.fn.button ) {
  8072. button.button();
  8073. }
  8074. });
  8075. this.uiDialog.addClass( "ui-dialog-buttons" );
  8076. this.uiDialogButtonPane.appendTo( this.uiDialog );
  8077. } else {
  8078. this.uiDialog.removeClass( "ui-dialog-buttons" );
  8079. }
  8080. },
  8081. _makeDraggable: function() {
  8082. var that = this,
  8083. options = this.options;
  8084. function filteredUi( ui ) {
  8085. return {
  8086. position: ui.position,
  8087. offset: ui.offset
  8088. };
  8089. }
  8090. this.uiDialog.draggable({
  8091. cancel: ".ui-dialog-content, .ui-dialog-titlebar-close",
  8092. handle: ".ui-dialog-titlebar",
  8093. containment: "document",
  8094. start: function( event, ui ) {
  8095. $( this )
  8096. .addClass( "ui-dialog-dragging" );
  8097. that._trigger( "dragStart", event, filteredUi( ui ) );
  8098. },
  8099. drag: function( event, ui ) {
  8100. that._trigger( "drag", event, filteredUi( ui ) );
  8101. },
  8102. stop: function( event, ui ) {
  8103. options.position = [
  8104. ui.position.left - that.document.scrollLeft(),
  8105. ui.position.top - that.document.scrollTop()
  8106. ];
  8107. $( this )
  8108. .removeClass( "ui-dialog-dragging" );
  8109. that._trigger( "dragStop", event, filteredUi( ui ) );
  8110. $.ui.dialog.overlay.resize();
  8111. }
  8112. });
  8113. },
  8114. _makeResizable: function( handles ) {
  8115. handles = (handles === undefined ? this.options.resizable : handles);
  8116. var that = this,
  8117. options = this.options,
  8118. // .ui-resizable has position: relative defined in the stylesheet
  8119. // but dialogs have to use absolute or fixed positioning
  8120. position = this.uiDialog.css( "position" ),
  8121. resizeHandles = typeof handles === 'string' ?
  8122. handles :
  8123. "n,e,s,w,se,sw,ne,nw";
  8124. function filteredUi( ui ) {
  8125. return {
  8126. originalPosition: ui.originalPosition,
  8127. originalSize: ui.originalSize,
  8128. position: ui.position,
  8129. size: ui.size
  8130. };
  8131. }
  8132. this.uiDialog.resizable({
  8133. cancel: ".ui-dialog-content",
  8134. containment: "document",
  8135. alsoResize: this.element,
  8136. maxWidth: options.maxWidth,
  8137. maxHeight: options.maxHeight,
  8138. minWidth: options.minWidth,
  8139. minHeight: this._minHeight(),
  8140. handles: resizeHandles,
  8141. start: function( event, ui ) {
  8142. $( this ).addClass( "ui-dialog-resizing" );
  8143. that._trigger( "resizeStart", event, filteredUi( ui ) );
  8144. },
  8145. resize: function( event, ui ) {
  8146. that._trigger( "resize", event, filteredUi( ui ) );
  8147. },
  8148. stop: function( event, ui ) {
  8149. $( this ).removeClass( "ui-dialog-resizing" );
  8150. options.height = $( this ).height();
  8151. options.width = $( this ).width();
  8152. that._trigger( "resizeStop", event, filteredUi( ui ) );
  8153. $.ui.dialog.overlay.resize();
  8154. }
  8155. })
  8156. .css( "position", position )
  8157. .find( ".ui-resizable-se" )
  8158. .addClass( "ui-icon ui-icon-grip-diagonal-se" );
  8159. },
  8160. _minHeight: function() {
  8161. var options = this.options;
  8162. if ( options.height === "auto" ) {
  8163. return options.minHeight;
  8164. } else {
  8165. return Math.min( options.minHeight, options.height );
  8166. }
  8167. },
  8168. _position: function( position ) {
  8169. var myAt = [],
  8170. offset = [ 0, 0 ],
  8171. isVisible;
  8172. if ( position ) {
  8173. // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
  8174. // if (typeof position == 'string' || $.isArray(position)) {
  8175. // myAt = $.isArray(position) ? position : position.split(' ');
  8176. if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
  8177. myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ];
  8178. if ( myAt.length === 1 ) {
  8179. myAt[ 1 ] = myAt[ 0 ];
  8180. }
  8181. $.each( [ "left", "top" ], function( i, offsetPosition ) {
  8182. if ( +myAt[ i ] === myAt[ i ] ) {
  8183. offset[ i ] = myAt[ i ];
  8184. myAt[ i ] = offsetPosition;
  8185. }
  8186. });
  8187. position = {
  8188. my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
  8189. myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
  8190. at: myAt.join( " " )
  8191. };
  8192. }
  8193. position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
  8194. } else {
  8195. position = $.ui.dialog.prototype.options.position;
  8196. }
  8197. // need to show the dialog to get the actual offset in the position plugin
  8198. isVisible = this.uiDialog.is( ":visible" );
  8199. if ( !isVisible ) {
  8200. this.uiDialog.show();
  8201. }
  8202. this.uiDialog.position( position );
  8203. if ( !isVisible ) {
  8204. this.uiDialog.hide();
  8205. }
  8206. },
  8207. _setOptions: function( options ) {
  8208. var that = this,
  8209. resizableOptions = {},
  8210. resize = false;
  8211. $.each( options, function( key, value ) {
  8212. that._setOption( key, value );
  8213. if ( key in sizeRelatedOptions ) {
  8214. resize = true;
  8215. }
  8216. if ( key in resizableRelatedOptions ) {
  8217. resizableOptions[ key ] = value;
  8218. }
  8219. });
  8220. if ( resize ) {
  8221. this._size();
  8222. }
  8223. if ( this.uiDialog.is( ":data(resizable)" ) ) {
  8224. this.uiDialog.resizable( "option", resizableOptions );
  8225. }
  8226. },
  8227. _setOption: function( key, value ) {
  8228. var isDraggable, isResizable,
  8229. uiDialog = this.uiDialog;
  8230. switch ( key ) {
  8231. case "buttons":
  8232. this._createButtons( value );
  8233. break;
  8234. case "closeText":
  8235. // ensure that we always pass a string
  8236. this.uiDialogTitlebarCloseText.text( "" + value );
  8237. break;
  8238. case "dialogClass":
  8239. uiDialog
  8240. .removeClass( this.options.dialogClass )
  8241. .addClass( uiDialogClasses + value );
  8242. break;
  8243. case "disabled":
  8244. if ( value ) {
  8245. uiDialog.addClass( "ui-dialog-disabled" );
  8246. } else {
  8247. uiDialog.removeClass( "ui-dialog-disabled" );
  8248. }
  8249. break;
  8250. case "draggable":
  8251. isDraggable = uiDialog.is( ":data(draggable)" );
  8252. if ( isDraggable && !value ) {
  8253. uiDialog.draggable( "destroy" );
  8254. }
  8255. if ( !isDraggable && value ) {
  8256. this._makeDraggable();
  8257. }
  8258. break;
  8259. case "position":
  8260. this._position( value );
  8261. break;
  8262. case "resizable":
  8263. // currently resizable, becoming non-resizable
  8264. isResizable = uiDialog.is( ":data(resizable)" );
  8265. if ( isResizable && !value ) {
  8266. uiDialog.resizable( "destroy" );
  8267. }
  8268. // currently resizable, changing handles
  8269. if ( isResizable && typeof value === "string" ) {
  8270. uiDialog.resizable( "option", "handles", value );
  8271. }
  8272. // currently non-resizable, becoming resizable
  8273. if ( !isResizable && value !== false ) {
  8274. this._makeResizable( value );
  8275. }
  8276. break;
  8277. case "title":
  8278. // convert whatever was passed in o a string, for html() to not throw up
  8279. $( ".ui-dialog-title", this.uiDialogTitlebar )
  8280. .html( "" + ( value || "&#160;" ) );
  8281. break;
  8282. }
  8283. this._super( key, value );
  8284. },
  8285. _size: function() {
  8286. /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
  8287. * divs will both have width and height set, so we need to reset them
  8288. */
  8289. var nonContentHeight, minContentHeight, autoHeight,
  8290. options = this.options,
  8291. isVisible = this.uiDialog.is( ":visible" );
  8292. // reset content sizing
  8293. this.element.show().css({
  8294. width: "auto",
  8295. minHeight: 0,
  8296. height: 0
  8297. });
  8298. if ( options.minWidth > options.width ) {
  8299. options.width = options.minWidth;
  8300. }
  8301. // reset wrapper sizing
  8302. // determine the height of all the non-content elements
  8303. nonContentHeight = this.uiDialog.css({
  8304. height: "auto",
  8305. width: options.width
  8306. })
  8307. .outerHeight();
  8308. minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
  8309. if ( options.height === "auto" ) {
  8310. // only needed for IE6 support
  8311. if ( $.support.minHeight ) {
  8312. this.element.css({
  8313. minHeight: minContentHeight,
  8314. height: "auto"
  8315. });
  8316. } else {
  8317. this.uiDialog.show();
  8318. autoHeight = this.element.css( "height", "auto" ).height();
  8319. if ( !isVisible ) {
  8320. this.uiDialog.hide();
  8321. }
  8322. this.element.height( Math.max( autoHeight, minContentHeight ) );
  8323. }
  8324. } else {
  8325. this.element.height( Math.max( options.height - nonContentHeight, 0 ) );
  8326. }
  8327. if (this.uiDialog.is( ":data(resizable)" ) ) {
  8328. this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
  8329. }
  8330. }
  8331. });
  8332. $.extend($.ui.dialog, {
  8333. uuid: 0,
  8334. maxZ: 0,
  8335. getTitleId: function($el) {
  8336. var id = $el.attr( "id" );
  8337. if ( !id ) {
  8338. this.uuid += 1;
  8339. id = this.uuid;
  8340. }
  8341. return "ui-dialog-title-" + id;
  8342. },
  8343. overlay: function( dialog ) {
  8344. this.$el = $.ui.dialog.overlay.create( dialog );
  8345. }
  8346. });
  8347. $.extend( $.ui.dialog.overlay, {
  8348. instances: [],
  8349. // reuse old instances due to IE memory leak with alpha transparency (see #5185)
  8350. oldInstances: [],
  8351. maxZ: 0,
  8352. events: $.map(
  8353. "focus,mousedown,mouseup,keydown,keypress,click".split( "," ),
  8354. function( event ) {
  8355. return event + ".dialog-overlay";
  8356. }
  8357. ).join( " " ),
  8358. create: function( dialog ) {
  8359. if ( this.instances.length === 0 ) {
  8360. // prevent use of anchors and inputs
  8361. // we use a setTimeout in case the overlay is created from an
  8362. // event that we're going to be cancelling (see #2804)
  8363. setTimeout(function() {
  8364. // handle $(el).dialog().dialog('close') (see #4065)
  8365. if ( $.ui.dialog.overlay.instances.length ) {
  8366. $( document ).bind( $.ui.dialog.overlay.events, function( event ) {
  8367. // stop events if the z-index of the target is < the z-index of the overlay
  8368. // we cannot return true when we don't want to cancel the event (#3523)
  8369. if ( $( event.target ).zIndex() < $.ui.dialog.overlay.maxZ ) {
  8370. return false;
  8371. }
  8372. });
  8373. }
  8374. }, 1 );
  8375. // handle window resize
  8376. $( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize );
  8377. }
  8378. var $el = ( this.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay" ) );
  8379. // allow closing by pressing the escape key
  8380. $( document ).bind( "keydown.dialog-overlay", function( event ) {
  8381. var instances = $.ui.dialog.overlay.instances;
  8382. // only react to the event if we're the top overlay
  8383. if ( instances.length !== 0 && instances[ instances.length - 1 ] === $el &&
  8384. dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
  8385. event.keyCode === $.ui.keyCode.ESCAPE ) {
  8386. dialog.close( event );
  8387. event.preventDefault();
  8388. }
  8389. });
  8390. $el.appendTo( document.body ).css({
  8391. width: this.width(),
  8392. height: this.height()
  8393. });
  8394. if ( $.fn.bgiframe ) {
  8395. $el.bgiframe();
  8396. }
  8397. this.instances.push( $el );
  8398. return $el;
  8399. },
  8400. destroy: function( $el ) {
  8401. var indexOf = $.inArray( $el, this.instances ),
  8402. maxZ = 0;
  8403. if ( indexOf !== -1 ) {
  8404. this.oldInstances.push( this.instances.splice( indexOf, 1 )[ 0 ] );
  8405. }
  8406. if ( this.instances.length === 0 ) {
  8407. $( [ document, window ] ).unbind( ".dialog-overlay" );
  8408. }
  8409. $el.height( 0 ).width( 0 ).remove();
  8410. // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
  8411. $.each( this.instances, function() {
  8412. maxZ = Math.max( maxZ, this.css( "z-index" ) );
  8413. });
  8414. this.maxZ = maxZ;
  8415. },
  8416. height: function() {
  8417. var scrollHeight,
  8418. offsetHeight;
  8419. // handle IE
  8420. if ( $.ui.ie ) {
  8421. scrollHeight = Math.max(
  8422. document.documentElement.scrollHeight,
  8423. document.body.scrollHeight
  8424. );
  8425. offsetHeight = Math.max(
  8426. document.documentElement.offsetHeight,
  8427. document.body.offsetHeight
  8428. );
  8429. if ( scrollHeight < offsetHeight ) {
  8430. return $( window ).height() + "px";
  8431. } else {
  8432. return scrollHeight + "px";
  8433. }
  8434. // handle "good" browsers
  8435. } else {
  8436. return $( document ).height() + "px";
  8437. }
  8438. },
  8439. width: function() {
  8440. var scrollWidth,
  8441. offsetWidth;
  8442. // handle IE
  8443. if ( $.ui.ie ) {
  8444. scrollWidth = Math.max(
  8445. document.documentElement.scrollWidth,
  8446. document.body.scrollWidth
  8447. );
  8448. offsetWidth = Math.max(
  8449. document.documentElement.offsetWidth,
  8450. document.body.offsetWidth
  8451. );
  8452. if ( scrollWidth < offsetWidth ) {
  8453. return $( window ).width() + "px";
  8454. } else {
  8455. return scrollWidth + "px";
  8456. }
  8457. // handle "good" browsers
  8458. } else {
  8459. return $( document ).width() + "px";
  8460. }
  8461. },
  8462. resize: function() {
  8463. /* If the dialog is draggable and the user drags it past the
  8464. * right edge of the window, the document becomes wider so we
  8465. * need to stretch the overlay. If the user then drags the
  8466. * dialog back to the left, the document will become narrower,
  8467. * so we need to shrink the overlay to the appropriate size.
  8468. * This is handled by shrinking the overlay before setting it
  8469. * to the full document size.
  8470. */
  8471. var $overlays = $( [] );
  8472. $.each( $.ui.dialog.overlay.instances, function() {
  8473. $overlays = $overlays.add( this );
  8474. });
  8475. $overlays.css({
  8476. width: 0,
  8477. height: 0
  8478. }).css({
  8479. width: $.ui.dialog.overlay.width(),
  8480. height: $.ui.dialog.overlay.height()
  8481. });
  8482. }
  8483. });
  8484. $.extend( $.ui.dialog.overlay.prototype, {
  8485. destroy: function() {
  8486. $.ui.dialog.overlay.destroy( this.$el );
  8487. }
  8488. });
  8489. }( jQuery ) );
  8490. (function( $, undefined ) {
  8491. var rvertical = /up|down|vertical/,
  8492. rpositivemotion = /up|left|vertical|horizontal/;
  8493. $.effects.effect.blind = function( o, done ) {
  8494. // Create element
  8495. var el = $( this ),
  8496. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  8497. mode = $.effects.setMode( el, o.mode || "hide" ),
  8498. direction = o.direction || "up",
  8499. vertical = rvertical.test( direction ),
  8500. ref = vertical ? "height" : "width",
  8501. ref2 = vertical ? "top" : "left",
  8502. motion = rpositivemotion.test( direction ),
  8503. animation = {},
  8504. show = mode === "show",
  8505. wrapper, distance, margin;
  8506. // if already wrapped, the wrapper's properties are my property. #6245
  8507. if ( el.parent().is( ".ui-effects-wrapper" ) ) {
  8508. $.effects.save( el.parent(), props );
  8509. } else {
  8510. $.effects.save( el, props );
  8511. }
  8512. el.show();
  8513. wrapper = $.effects.createWrapper( el ).css({
  8514. overflow: "hidden"
  8515. });
  8516. distance = wrapper[ ref ]();
  8517. margin = parseFloat( wrapper.css( ref2 ) ) || 0;
  8518. animation[ ref ] = show ? distance : 0;
  8519. if ( !motion ) {
  8520. el
  8521. .css( vertical ? "bottom" : "right", 0 )
  8522. .css( vertical ? "top" : "left", "auto" )
  8523. .css({ position: "absolute" });
  8524. animation[ ref2 ] = show ? margin : distance + margin;
  8525. }
  8526. // start at 0 if we are showing
  8527. if ( show ) {
  8528. wrapper.css( ref, 0 );
  8529. if ( ! motion ) {
  8530. wrapper.css( ref2, margin + distance );
  8531. }
  8532. }
  8533. // Animate
  8534. wrapper.animate( animation, {
  8535. duration: o.duration,
  8536. easing: o.easing,
  8537. queue: false,
  8538. complete: function() {
  8539. if ( mode === "hide" ) {
  8540. el.hide();
  8541. }
  8542. $.effects.restore( el, props );
  8543. $.effects.removeWrapper( el );
  8544. done();
  8545. }
  8546. });
  8547. };
  8548. })(jQuery);
  8549. (function( $, undefined ) {
  8550. $.effects.effect.bounce = function( o, done ) {
  8551. var el = $( this ),
  8552. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  8553. // defaults:
  8554. mode = $.effects.setMode( el, o.mode || "effect" ),
  8555. hide = mode === "hide",
  8556. show = mode === "show",
  8557. direction = o.direction || "up",
  8558. distance = o.distance,
  8559. times = o.times || 5,
  8560. // number of internal animations
  8561. anims = times * 2 + ( show || hide ? 1 : 0 ),
  8562. speed = o.duration / anims,
  8563. easing = o.easing,
  8564. // utility:
  8565. ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  8566. motion = ( direction === "up" || direction === "left" ),
  8567. i,
  8568. upAnim,
  8569. downAnim,
  8570. // we will need to re-assemble the queue to stack our animations in place
  8571. queue = el.queue(),
  8572. queuelen = queue.length;
  8573. // Avoid touching opacity to prevent clearType and PNG issues in IE
  8574. if ( show || hide ) {
  8575. props.push( "opacity" );
  8576. }
  8577. $.effects.save( el, props );
  8578. el.show();
  8579. $.effects.createWrapper( el ); // Create Wrapper
  8580. // default distance for the BIGGEST bounce is the outer Distance / 3
  8581. if ( !distance ) {
  8582. distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
  8583. }
  8584. if ( show ) {
  8585. downAnim = { opacity: 1 };
  8586. downAnim[ ref ] = 0;
  8587. // if we are showing, force opacity 0 and set the initial position
  8588. // then do the "first" animation
  8589. el.css( "opacity", 0 )
  8590. .css( ref, motion ? -distance * 2 : distance * 2 )
  8591. .animate( downAnim, speed, easing );
  8592. }
  8593. // start at the smallest distance if we are hiding
  8594. if ( hide ) {
  8595. distance = distance / Math.pow( 2, times - 1 );
  8596. }
  8597. downAnim = {};
  8598. downAnim[ ref ] = 0;
  8599. // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
  8600. for ( i = 0; i < times; i++ ) {
  8601. upAnim = {};
  8602. upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
  8603. el.animate( upAnim, speed, easing )
  8604. .animate( downAnim, speed, easing );
  8605. distance = hide ? distance * 2 : distance / 2;
  8606. }
  8607. // Last Bounce when Hiding
  8608. if ( hide ) {
  8609. upAnim = { opacity: 0 };
  8610. upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
  8611. el.animate( upAnim, speed, easing );
  8612. }
  8613. el.queue(function() {
  8614. if ( hide ) {
  8615. el.hide();
  8616. }
  8617. $.effects.restore( el, props );
  8618. $.effects.removeWrapper( el );
  8619. done();
  8620. });
  8621. // inject all the animations we just queued to be first in line (after "inprogress")
  8622. if ( queuelen > 1) {
  8623. queue.splice.apply( queue,
  8624. [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
  8625. }
  8626. el.dequeue();
  8627. };
  8628. })(jQuery);
  8629. (function( $, undefined ) {
  8630. $.effects.effect.clip = function( o, done ) {
  8631. // Create element
  8632. var el = $( this ),
  8633. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  8634. mode = $.effects.setMode( el, o.mode || "hide" ),
  8635. show = mode === "show",
  8636. direction = o.direction || "vertical",
  8637. vert = direction === "vertical",
  8638. size = vert ? "height" : "width",
  8639. position = vert ? "top" : "left",
  8640. animation = {},
  8641. wrapper, animate, distance;
  8642. // Save & Show
  8643. $.effects.save( el, props );
  8644. el.show();
  8645. // Create Wrapper
  8646. wrapper = $.effects.createWrapper( el ).css({
  8647. overflow: "hidden"
  8648. });
  8649. animate = ( el[0].tagName === "IMG" ) ? wrapper : el;
  8650. distance = animate[ size ]();
  8651. // Shift
  8652. if ( show ) {
  8653. animate.css( size, 0 );
  8654. animate.css( position, distance / 2 );
  8655. }
  8656. // Create Animation Object:
  8657. animation[ size ] = show ? distance : 0;
  8658. animation[ position ] = show ? 0 : distance / 2;
  8659. // Animate
  8660. animate.animate( animation, {
  8661. queue: false,
  8662. duration: o.duration,
  8663. easing: o.easing,
  8664. complete: function() {
  8665. if ( !show ) {
  8666. el.hide();
  8667. }
  8668. $.effects.restore( el, props );
  8669. $.effects.removeWrapper( el );
  8670. done();
  8671. }
  8672. });
  8673. };
  8674. })(jQuery);
  8675. (function( $, undefined ) {
  8676. $.effects.effect.drop = function( o, done ) {
  8677. var el = $( this ),
  8678. props = [ "position", "top", "bottom", "left", "right", "opacity", "height", "width" ],
  8679. mode = $.effects.setMode( el, o.mode || "hide" ),
  8680. show = mode === "show",
  8681. direction = o.direction || "left",
  8682. ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  8683. motion = ( direction === "up" || direction === "left" ) ? "pos" : "neg",
  8684. animation = {
  8685. opacity: show ? 1 : 0
  8686. },
  8687. distance;
  8688. // Adjust
  8689. $.effects.save( el, props );
  8690. el.show();
  8691. $.effects.createWrapper( el );
  8692. distance = o.distance || el[ ref === "top" ? "outerHeight": "outerWidth" ]( true ) / 2;
  8693. if ( show ) {
  8694. el
  8695. .css( "opacity", 0 )
  8696. .css( ref, motion === "pos" ? -distance : distance );
  8697. }
  8698. // Animation
  8699. animation[ ref ] = ( show ?
  8700. ( motion === "pos" ? "+=" : "-=" ) :
  8701. ( motion === "pos" ? "-=" : "+=" ) ) +
  8702. distance;
  8703. // Animate
  8704. el.animate( animation, {
  8705. queue: false,
  8706. duration: o.duration,
  8707. easing: o.easing,
  8708. complete: function() {
  8709. if ( mode === "hide" ) {
  8710. el.hide();
  8711. }
  8712. $.effects.restore( el, props );
  8713. $.effects.removeWrapper( el );
  8714. done();
  8715. }
  8716. });
  8717. };
  8718. })(jQuery);
  8719. (function( $, undefined ) {
  8720. $.effects.effect.explode = function( o, done ) {
  8721. var rows = o.pieces ? Math.round( Math.sqrt( o.pieces ) ) : 3,
  8722. cells = rows,
  8723. el = $( this ),
  8724. mode = $.effects.setMode( el, o.mode || "hide" ),
  8725. show = mode === "show",
  8726. // show and then visibility:hidden the element before calculating offset
  8727. offset = el.show().css( "visibility", "hidden" ).offset(),
  8728. // width and height of a piece
  8729. width = Math.ceil( el.outerWidth() / cells ),
  8730. height = Math.ceil( el.outerHeight() / rows ),
  8731. pieces = [],
  8732. // loop
  8733. i, j, left, top, mx, my;
  8734. // children animate complete:
  8735. function childComplete() {
  8736. pieces.push( this );
  8737. if ( pieces.length === rows * cells ) {
  8738. animComplete();
  8739. }
  8740. }
  8741. // clone the element for each row and cell.
  8742. for( i = 0; i < rows ; i++ ) { // ===>
  8743. top = offset.top + i * height;
  8744. my = i - ( rows - 1 ) / 2 ;
  8745. for( j = 0; j < cells ; j++ ) { // |||
  8746. left = offset.left + j * width;
  8747. mx = j - ( cells - 1 ) / 2 ;
  8748. // Create a clone of the now hidden main element that will be absolute positioned
  8749. // within a wrapper div off the -left and -top equal to size of our pieces
  8750. el
  8751. .clone()
  8752. .appendTo( "body" )
  8753. .wrap( "<div></div>" )
  8754. .css({
  8755. position: "absolute",
  8756. visibility: "visible",
  8757. left: -j * width,
  8758. top: -i * height
  8759. })
  8760. // select the wrapper - make it overflow: hidden and absolute positioned based on
  8761. // where the original was located +left and +top equal to the size of pieces
  8762. .parent()
  8763. .addClass( "ui-effects-explode" )
  8764. .css({
  8765. position: "absolute",
  8766. overflow: "hidden",
  8767. width: width,
  8768. height: height,
  8769. left: left + ( show ? mx * width : 0 ),
  8770. top: top + ( show ? my * height : 0 ),
  8771. opacity: show ? 0 : 1
  8772. }).animate({
  8773. left: left + ( show ? 0 : mx * width ),
  8774. top: top + ( show ? 0 : my * height ),
  8775. opacity: show ? 1 : 0
  8776. }, o.duration || 500, o.easing, childComplete );
  8777. }
  8778. }
  8779. function animComplete() {
  8780. el.css({
  8781. visibility: "visible"
  8782. });
  8783. $( pieces ).remove();
  8784. if ( !show ) {
  8785. el.hide();
  8786. }
  8787. done();
  8788. }
  8789. };
  8790. })(jQuery);
  8791. (function( $, undefined ) {
  8792. $.effects.effect.fade = function( o, done ) {
  8793. var el = $( this ),
  8794. mode = $.effects.setMode( el, o.mode || "toggle" );
  8795. el.animate({
  8796. opacity: mode
  8797. }, {
  8798. queue: false,
  8799. duration: o.duration,
  8800. easing: o.easing,
  8801. complete: done
  8802. });
  8803. };
  8804. })( jQuery );
  8805. (function( $, undefined ) {
  8806. $.effects.effect.fold = function( o, done ) {
  8807. // Create element
  8808. var el = $( this ),
  8809. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  8810. mode = $.effects.setMode( el, o.mode || "hide" ),
  8811. show = mode === "show",
  8812. hide = mode === "hide",
  8813. size = o.size || 15,
  8814. percent = /([0-9]+)%/.exec( size ),
  8815. horizFirst = !!o.horizFirst,
  8816. widthFirst = show !== horizFirst,
  8817. ref = widthFirst ? [ "width", "height" ] : [ "height", "width" ],
  8818. duration = o.duration / 2,
  8819. wrapper, distance,
  8820. animation1 = {},
  8821. animation2 = {};
  8822. $.effects.save( el, props );
  8823. el.show();
  8824. // Create Wrapper
  8825. wrapper = $.effects.createWrapper( el ).css({
  8826. overflow: "hidden"
  8827. });
  8828. distance = widthFirst ?
  8829. [ wrapper.width(), wrapper.height() ] :
  8830. [ wrapper.height(), wrapper.width() ];
  8831. if ( percent ) {
  8832. size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ hide ? 0 : 1 ];
  8833. }
  8834. if ( show ) {
  8835. wrapper.css( horizFirst ? {
  8836. height: 0,
  8837. width: size
  8838. } : {
  8839. height: size,
  8840. width: 0
  8841. });
  8842. }
  8843. // Animation
  8844. animation1[ ref[ 0 ] ] = show ? distance[ 0 ] : size;
  8845. animation2[ ref[ 1 ] ] = show ? distance[ 1 ] : 0;
  8846. // Animate
  8847. wrapper
  8848. .animate( animation1, duration, o.easing )
  8849. .animate( animation2, duration, o.easing, function() {
  8850. if ( hide ) {
  8851. el.hide();
  8852. }
  8853. $.effects.restore( el, props );
  8854. $.effects.removeWrapper( el );
  8855. done();
  8856. });
  8857. };
  8858. })(jQuery);
  8859. (function( $, undefined ) {
  8860. $.effects.effect.highlight = function( o, done ) {
  8861. var elem = $( this ),
  8862. props = [ "backgroundImage", "backgroundColor", "opacity" ],
  8863. mode = $.effects.setMode( elem, o.mode || "show" ),
  8864. animation = {
  8865. backgroundColor: elem.css( "backgroundColor" )
  8866. };
  8867. if (mode === "hide") {
  8868. animation.opacity = 0;
  8869. }
  8870. $.effects.save( elem, props );
  8871. elem
  8872. .show()
  8873. .css({
  8874. backgroundImage: "none",
  8875. backgroundColor: o.color || "#ffff99"
  8876. })
  8877. .animate( animation, {
  8878. queue: false,
  8879. duration: o.duration,
  8880. easing: o.easing,
  8881. complete: function() {
  8882. if ( mode === "hide" ) {
  8883. elem.hide();
  8884. }
  8885. $.effects.restore( elem, props );
  8886. done();
  8887. }
  8888. });
  8889. };
  8890. })(jQuery);
  8891. (function( $, undefined ) {
  8892. $.effects.effect.pulsate = function( o, done ) {
  8893. var elem = $( this ),
  8894. mode = $.effects.setMode( elem, o.mode || "show" ),
  8895. show = mode === "show",
  8896. hide = mode === "hide",
  8897. showhide = ( show || mode === "hide" ),
  8898. // showing or hiding leaves of the "last" animation
  8899. anims = ( ( o.times || 5 ) * 2 ) + ( showhide ? 1 : 0 ),
  8900. duration = o.duration / anims,
  8901. animateTo = 0,
  8902. queue = elem.queue(),
  8903. queuelen = queue.length,
  8904. i;
  8905. if ( show || !elem.is(":visible")) {
  8906. elem.css( "opacity", 0 ).show();
  8907. animateTo = 1;
  8908. }
  8909. // anims - 1 opacity "toggles"
  8910. for ( i = 1; i < anims; i++ ) {
  8911. elem.animate({
  8912. opacity: animateTo
  8913. }, duration, o.easing );
  8914. animateTo = 1 - animateTo;
  8915. }
  8916. elem.animate({
  8917. opacity: animateTo
  8918. }, duration, o.easing);
  8919. elem.queue(function() {
  8920. if ( hide ) {
  8921. elem.hide();
  8922. }
  8923. done();
  8924. });
  8925. // We just queued up "anims" animations, we need to put them next in the queue
  8926. if ( queuelen > 1 ) {
  8927. queue.splice.apply( queue,
  8928. [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
  8929. }
  8930. elem.dequeue();
  8931. };
  8932. })(jQuery);
  8933. (function( $, undefined ) {
  8934. $.effects.effect.puff = function( o, done ) {
  8935. var elem = $( this ),
  8936. mode = $.effects.setMode( elem, o.mode || "hide" ),
  8937. hide = mode === "hide",
  8938. percent = parseInt( o.percent, 10 ) || 150,
  8939. factor = percent / 100,
  8940. original = {
  8941. height: elem.height(),
  8942. width: elem.width(),
  8943. outerHeight: elem.outerHeight(),
  8944. outerWidth: elem.outerWidth()
  8945. };
  8946. $.extend( o, {
  8947. effect: "scale",
  8948. queue: false,
  8949. fade: true,
  8950. mode: mode,
  8951. complete: done,
  8952. percent: hide ? percent : 100,
  8953. from: hide ?
  8954. original :
  8955. {
  8956. height: original.height * factor,
  8957. width: original.width * factor,
  8958. outerHeight: original.outerHeight * factor,
  8959. outerWidth: original.outerWidth * factor
  8960. }
  8961. });
  8962. elem.effect( o );
  8963. };
  8964. $.effects.effect.scale = function( o, done ) {
  8965. // Create element
  8966. var el = $( this ),
  8967. options = $.extend( true, {}, o ),
  8968. mode = $.effects.setMode( el, o.mode || "effect" ),
  8969. percent = parseInt( o.percent, 10 ) ||
  8970. ( parseInt( o.percent, 10 ) === 0 ? 0 : ( mode === "hide" ? 0 : 100 ) ),
  8971. direction = o.direction || "both",
  8972. origin = o.origin,
  8973. original = {
  8974. height: el.height(),
  8975. width: el.width(),
  8976. outerHeight: el.outerHeight(),
  8977. outerWidth: el.outerWidth()
  8978. },
  8979. factor = {
  8980. y: direction !== "horizontal" ? (percent / 100) : 1,
  8981. x: direction !== "vertical" ? (percent / 100) : 1
  8982. };
  8983. // We are going to pass this effect to the size effect:
  8984. options.effect = "size";
  8985. options.queue = false;
  8986. options.complete = done;
  8987. // Set default origin and restore for show/hide
  8988. if ( mode !== "effect" ) {
  8989. options.origin = origin || ["middle","center"];
  8990. options.restore = true;
  8991. }
  8992. options.from = o.from || ( mode === "show" ? {
  8993. height: 0,
  8994. width: 0,
  8995. outerHeight: 0,
  8996. outerWidth: 0
  8997. } : original );
  8998. options.to = {
  8999. height: original.height * factor.y,
  9000. width: original.width * factor.x,
  9001. outerHeight: original.outerHeight * factor.y,
  9002. outerWidth: original.outerWidth * factor.x
  9003. };
  9004. // Fade option to support puff
  9005. if ( options.fade ) {
  9006. if ( mode === "show" ) {
  9007. options.from.opacity = 0;
  9008. options.to.opacity = 1;
  9009. }
  9010. if ( mode === "hide" ) {
  9011. options.from.opacity = 1;
  9012. options.to.opacity = 0;
  9013. }
  9014. }
  9015. // Animate
  9016. el.effect( options );
  9017. };
  9018. $.effects.effect.size = function( o, done ) {
  9019. // Create element
  9020. var original, baseline, factor,
  9021. el = $( this ),
  9022. props0 = [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ],
  9023. // Always restore
  9024. props1 = [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ],
  9025. // Copy for children
  9026. props2 = [ "width", "height", "overflow" ],
  9027. cProps = [ "fontSize" ],
  9028. vProps = [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ],
  9029. hProps = [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ],
  9030. // Set options
  9031. mode = $.effects.setMode( el, o.mode || "effect" ),
  9032. restore = o.restore || mode !== "effect",
  9033. scale = o.scale || "both",
  9034. origin = o.origin || [ "middle", "center" ],
  9035. position = el.css( "position" ),
  9036. props = restore ? props0 : props1,
  9037. zero = {
  9038. height: 0,
  9039. width: 0,
  9040. outerHeight: 0,
  9041. outerWidth: 0
  9042. };
  9043. if ( mode === "show" ) {
  9044. el.show();
  9045. }
  9046. original = {
  9047. height: el.height(),
  9048. width: el.width(),
  9049. outerHeight: el.outerHeight(),
  9050. outerWidth: el.outerWidth()
  9051. };
  9052. if ( o.mode === "toggle" && mode === "show" ) {
  9053. el.from = o.to || zero;
  9054. el.to = o.from || original;
  9055. } else {
  9056. el.from = o.from || ( mode === "show" ? zero : original );
  9057. el.to = o.to || ( mode === "hide" ? zero : original );
  9058. }
  9059. // Set scaling factor
  9060. factor = {
  9061. from: {
  9062. y: el.from.height / original.height,
  9063. x: el.from.width / original.width
  9064. },
  9065. to: {
  9066. y: el.to.height / original.height,
  9067. x: el.to.width / original.width
  9068. }
  9069. };
  9070. // Scale the css box
  9071. if ( scale === "box" || scale === "both" ) {
  9072. // Vertical props scaling
  9073. if ( factor.from.y !== factor.to.y ) {
  9074. props = props.concat( vProps );
  9075. el.from = $.effects.setTransition( el, vProps, factor.from.y, el.from );
  9076. el.to = $.effects.setTransition( el, vProps, factor.to.y, el.to );
  9077. }
  9078. // Horizontal props scaling
  9079. if ( factor.from.x !== factor.to.x ) {
  9080. props = props.concat( hProps );
  9081. el.from = $.effects.setTransition( el, hProps, factor.from.x, el.from );
  9082. el.to = $.effects.setTransition( el, hProps, factor.to.x, el.to );
  9083. }
  9084. }
  9085. // Scale the content
  9086. if ( scale === "content" || scale === "both" ) {
  9087. // Vertical props scaling
  9088. if ( factor.from.y !== factor.to.y ) {
  9089. props = props.concat( cProps ).concat( props2 );
  9090. el.from = $.effects.setTransition( el, cProps, factor.from.y, el.from );
  9091. el.to = $.effects.setTransition( el, cProps, factor.to.y, el.to );
  9092. }
  9093. }
  9094. $.effects.save( el, props );
  9095. el.show();
  9096. $.effects.createWrapper( el );
  9097. el.css( "overflow", "hidden" ).css( el.from );
  9098. // Adjust
  9099. if (origin) { // Calculate baseline shifts
  9100. baseline = $.effects.getBaseline( origin, original );
  9101. el.from.top = ( original.outerHeight - el.outerHeight() ) * baseline.y;
  9102. el.from.left = ( original.outerWidth - el.outerWidth() ) * baseline.x;
  9103. el.to.top = ( original.outerHeight - el.to.outerHeight ) * baseline.y;
  9104. el.to.left = ( original.outerWidth - el.to.outerWidth ) * baseline.x;
  9105. }
  9106. el.css( el.from ); // set top & left
  9107. // Animate
  9108. if ( scale === "content" || scale === "both" ) { // Scale the children
  9109. // Add margins/font-size
  9110. vProps = vProps.concat([ "marginTop", "marginBottom" ]).concat(cProps);
  9111. hProps = hProps.concat([ "marginLeft", "marginRight" ]);
  9112. props2 = props0.concat(vProps).concat(hProps);
  9113. el.find( "*[width]" ).each( function(){
  9114. var child = $( this ),
  9115. c_original = {
  9116. height: child.height(),
  9117. width: child.width(),
  9118. outerHeight: child.outerHeight(),
  9119. outerWidth: child.outerWidth()
  9120. };
  9121. if (restore) {
  9122. $.effects.save(child, props2);
  9123. }
  9124. child.from = {
  9125. height: c_original.height * factor.from.y,
  9126. width: c_original.width * factor.from.x,
  9127. outerHeight: c_original.outerHeight * factor.from.y,
  9128. outerWidth: c_original.outerWidth * factor.from.x
  9129. };
  9130. child.to = {
  9131. height: c_original.height * factor.to.y,
  9132. width: c_original.width * factor.to.x,
  9133. outerHeight: c_original.height * factor.to.y,
  9134. outerWidth: c_original.width * factor.to.x
  9135. };
  9136. // Vertical props scaling
  9137. if ( factor.from.y !== factor.to.y ) {
  9138. child.from = $.effects.setTransition( child, vProps, factor.from.y, child.from );
  9139. child.to = $.effects.setTransition( child, vProps, factor.to.y, child.to );
  9140. }
  9141. // Horizontal props scaling
  9142. if ( factor.from.x !== factor.to.x ) {
  9143. child.from = $.effects.setTransition( child, hProps, factor.from.x, child.from );
  9144. child.to = $.effects.setTransition( child, hProps, factor.to.x, child.to );
  9145. }
  9146. // Animate children
  9147. child.css( child.from );
  9148. child.animate( child.to, o.duration, o.easing, function() {
  9149. // Restore children
  9150. if ( restore ) {
  9151. $.effects.restore( child, props2 );
  9152. }
  9153. });
  9154. });
  9155. }
  9156. // Animate
  9157. el.animate( el.to, {
  9158. queue: false,
  9159. duration: o.duration,
  9160. easing: o.easing,
  9161. complete: function() {
  9162. if ( el.to.opacity === 0 ) {
  9163. el.css( "opacity", el.from.opacity );
  9164. }
  9165. if( mode === "hide" ) {
  9166. el.hide();
  9167. }
  9168. $.effects.restore( el, props );
  9169. if ( !restore ) {
  9170. // we need to calculate our new positioning based on the scaling
  9171. if ( position === "static" ) {
  9172. el.css({
  9173. position: "relative",
  9174. top: el.to.top,
  9175. left: el.to.left
  9176. });
  9177. } else {
  9178. $.each([ "top", "left" ], function( idx, pos ) {
  9179. el.css( pos, function( _, str ) {
  9180. var val = parseInt( str, 10 ),
  9181. toRef = idx ? el.to.left : el.to.top;
  9182. // if original was "auto", recalculate the new value from wrapper
  9183. if ( str === "auto" ) {
  9184. return toRef + "px";
  9185. }
  9186. return val + toRef + "px";
  9187. });
  9188. });
  9189. }
  9190. }
  9191. $.effects.removeWrapper( el );
  9192. done();
  9193. }
  9194. });
  9195. };
  9196. })(jQuery);
  9197. (function( $, undefined ) {
  9198. $.effects.effect.shake = function( o, done ) {
  9199. var el = $( this ),
  9200. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  9201. mode = $.effects.setMode( el, o.mode || "effect" ),
  9202. direction = o.direction || "left",
  9203. distance = o.distance || 20,
  9204. times = o.times || 3,
  9205. anims = times * 2 + 1,
  9206. speed = Math.round(o.duration/anims),
  9207. ref = (direction === "up" || direction === "down") ? "top" : "left",
  9208. positiveMotion = (direction === "up" || direction === "left"),
  9209. animation = {},
  9210. animation1 = {},
  9211. animation2 = {},
  9212. i,
  9213. // we will need to re-assemble the queue to stack our animations in place
  9214. queue = el.queue(),
  9215. queuelen = queue.length;
  9216. $.effects.save( el, props );
  9217. el.show();
  9218. $.effects.createWrapper( el );
  9219. // Animation
  9220. animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance;
  9221. animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2;
  9222. animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2;
  9223. // Animate
  9224. el.animate( animation, speed, o.easing );
  9225. // Shakes
  9226. for ( i = 1; i < times; i++ ) {
  9227. el.animate( animation1, speed, o.easing ).animate( animation2, speed, o.easing );
  9228. }
  9229. el
  9230. .animate( animation1, speed, o.easing )
  9231. .animate( animation, speed / 2, o.easing )
  9232. .queue(function() {
  9233. if ( mode === "hide" ) {
  9234. el.hide();
  9235. }
  9236. $.effects.restore( el, props );
  9237. $.effects.removeWrapper( el );
  9238. done();
  9239. });
  9240. // inject all the animations we just queued to be first in line (after "inprogress")
  9241. if ( queuelen > 1) {
  9242. queue.splice.apply( queue,
  9243. [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
  9244. }
  9245. el.dequeue();
  9246. };
  9247. })(jQuery);
  9248. (function( $, undefined ) {
  9249. $.effects.effect.slide = function( o, done ) {
  9250. // Create element
  9251. var el = $( this ),
  9252. props = [ "position", "top", "bottom", "left", "right", "width", "height" ],
  9253. mode = $.effects.setMode( el, o.mode || "show" ),
  9254. show = mode === "show",
  9255. direction = o.direction || "left",
  9256. ref = (direction === "up" || direction === "down") ? "top" : "left",
  9257. positiveMotion = (direction === "up" || direction === "left"),
  9258. distance,
  9259. animation = {};
  9260. // Adjust
  9261. $.effects.save( el, props );
  9262. el.show();
  9263. distance = o.distance || el[ ref === "top" ? "outerHeight" : "outerWidth" ]( true );
  9264. $.effects.createWrapper( el ).css({
  9265. overflow: "hidden"
  9266. });
  9267. if ( show ) {
  9268. el.css( ref, positiveMotion ? (isNaN(distance) ? "-" + distance : -distance) : distance );
  9269. }
  9270. // Animation
  9271. animation[ ref ] = ( show ?
  9272. ( positiveMotion ? "+=" : "-=") :
  9273. ( positiveMotion ? "-=" : "+=")) +
  9274. distance;
  9275. // Animate
  9276. el.animate( animation, {
  9277. queue: false,
  9278. duration: o.duration,
  9279. easing: o.easing,
  9280. complete: function() {
  9281. if ( mode === "hide" ) {
  9282. el.hide();
  9283. }
  9284. $.effects.restore( el, props );
  9285. $.effects.removeWrapper( el );
  9286. done();
  9287. }
  9288. });
  9289. };
  9290. })(jQuery);
  9291. (function( $, undefined ) {
  9292. $.effects.effect.transfer = function( o, done ) {
  9293. var elem = $( this ),
  9294. target = $( o.to ),
  9295. targetFixed = target.css( "position" ) === "fixed",
  9296. body = $("body"),
  9297. fixTop = targetFixed ? body.scrollTop() : 0,
  9298. fixLeft = targetFixed ? body.scrollLeft() : 0,
  9299. endPosition = target.offset(),
  9300. animation = {
  9301. top: endPosition.top - fixTop ,
  9302. left: endPosition.left - fixLeft ,
  9303. height: target.innerHeight(),
  9304. width: target.innerWidth()
  9305. },
  9306. startPosition = elem.offset(),
  9307. transfer = $( '<div class="ui-effects-transfer"></div>' )
  9308. .appendTo( document.body )
  9309. .addClass( o.className )
  9310. .css({
  9311. top: startPosition.top - fixTop ,
  9312. left: startPosition.left - fixLeft ,
  9313. height: elem.innerHeight(),
  9314. width: elem.innerWidth(),
  9315. position: targetFixed ? "fixed" : "absolute"
  9316. })
  9317. .animate( animation, o.duration, o.easing, function() {
  9318. transfer.remove();
  9319. done();
  9320. });
  9321. };
  9322. })(jQuery);
  9323. (function( $, undefined ) {
  9324. var mouseHandled = false;
  9325. $.widget( "ui.menu", {
  9326. version: "1.9.2",
  9327. defaultElement: "<ul>",
  9328. delay: 300,
  9329. options: {
  9330. icons: {
  9331. submenu: "ui-icon-carat-1-e"
  9332. },
  9333. menus: "ul",
  9334. position: {
  9335. my: "left top",
  9336. at: "right top"
  9337. },
  9338. role: "menu",
  9339. // callbacks
  9340. blur: null,
  9341. focus: null,
  9342. select: null
  9343. },
  9344. _create: function() {
  9345. this.activeMenu = this.element;
  9346. this.element
  9347. .uniqueId()
  9348. .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
  9349. .toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length )
  9350. .attr({
  9351. role: this.options.role,
  9352. tabIndex: 0
  9353. })
  9354. // need to catch all clicks on disabled menu
  9355. // not possible through _on
  9356. .bind( "click" + this.eventNamespace, $.proxy(function( event ) {
  9357. if ( this.options.disabled ) {
  9358. event.preventDefault();
  9359. }
  9360. }, this ));
  9361. if ( this.options.disabled ) {
  9362. this.element
  9363. .addClass( "ui-state-disabled" )
  9364. .attr( "aria-disabled", "true" );
  9365. }
  9366. this._on({
  9367. // Prevent focus from sticking to links inside menu after clicking
  9368. // them (focus should always stay on UL during navigation).
  9369. "mousedown .ui-menu-item > a": function( event ) {
  9370. event.preventDefault();
  9371. },
  9372. "click .ui-state-disabled > a": function( event ) {
  9373. event.preventDefault();
  9374. },
  9375. "click .ui-menu-item:has(a)": function( event ) {
  9376. var target = $( event.target ).closest( ".ui-menu-item" );
  9377. if ( !mouseHandled && target.not( ".ui-state-disabled" ).length ) {
  9378. mouseHandled = true;
  9379. this.select( event );
  9380. // Open submenu on click
  9381. if ( target.has( ".ui-menu" ).length ) {
  9382. this.expand( event );
  9383. } else if ( !this.element.is( ":focus" ) ) {
  9384. // Redirect focus to the menu
  9385. this.element.trigger( "focus", [ true ] );
  9386. // If the active item is on the top level, let it stay active.
  9387. // Otherwise, blur the active item since it is no longer visible.
  9388. if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) {
  9389. clearTimeout( this.timer );
  9390. }
  9391. }
  9392. }
  9393. },
  9394. "mouseenter .ui-menu-item": function( event ) {
  9395. var target = $( event.currentTarget );
  9396. // Remove ui-state-active class from siblings of the newly focused menu item
  9397. // to avoid a jump caused by adjacent elements both having a class with a border
  9398. target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" );
  9399. this.focus( event, target );
  9400. },
  9401. mouseleave: "collapseAll",
  9402. "mouseleave .ui-menu": "collapseAll",
  9403. focus: function( event, keepActiveItem ) {
  9404. // If there's already an active item, keep it active
  9405. // If not, activate the first item
  9406. var item = this.active || this.element.children( ".ui-menu-item" ).eq( 0 );
  9407. if ( !keepActiveItem ) {
  9408. this.focus( event, item );
  9409. }
  9410. },
  9411. blur: function( event ) {
  9412. this._delay(function() {
  9413. if ( !$.contains( this.element[0], this.document[0].activeElement ) ) {
  9414. this.collapseAll( event );
  9415. }
  9416. });
  9417. },
  9418. keydown: "_keydown"
  9419. });
  9420. this.refresh();
  9421. // Clicks outside of a menu collapse any open menus
  9422. this._on( this.document, {
  9423. click: function( event ) {
  9424. if ( !$( event.target ).closest( ".ui-menu" ).length ) {
  9425. this.collapseAll( event );
  9426. }
  9427. // Reset the mouseHandled flag
  9428. mouseHandled = false;
  9429. }
  9430. });
  9431. },
  9432. _destroy: function() {
  9433. // Destroy (sub)menus
  9434. this.element
  9435. .removeAttr( "aria-activedescendant" )
  9436. .find( ".ui-menu" ).andSelf()
  9437. .removeClass( "ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" )
  9438. .removeAttr( "role" )
  9439. .removeAttr( "tabIndex" )
  9440. .removeAttr( "aria-labelledby" )
  9441. .removeAttr( "aria-expanded" )
  9442. .removeAttr( "aria-hidden" )
  9443. .removeAttr( "aria-disabled" )
  9444. .removeUniqueId()
  9445. .show();
  9446. // Destroy menu items
  9447. this.element.find( ".ui-menu-item" )
  9448. .removeClass( "ui-menu-item" )
  9449. .removeAttr( "role" )
  9450. .removeAttr( "aria-disabled" )
  9451. .children( "a" )
  9452. .removeUniqueId()
  9453. .removeClass( "ui-corner-all ui-state-hover" )
  9454. .removeAttr( "tabIndex" )
  9455. .removeAttr( "role" )
  9456. .removeAttr( "aria-haspopup" )
  9457. .children().each( function() {
  9458. var elem = $( this );
  9459. if ( elem.data( "ui-menu-submenu-carat" ) ) {
  9460. elem.remove();
  9461. }
  9462. });
  9463. // Destroy menu dividers
  9464. this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" );
  9465. },
  9466. _keydown: function( event ) {
  9467. var match, prev, character, skip, regex,
  9468. preventDefault = true;
  9469. function escape( value ) {
  9470. return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
  9471. }
  9472. switch ( event.keyCode ) {
  9473. case $.ui.keyCode.PAGE_UP:
  9474. this.previousPage( event );
  9475. break;
  9476. case $.ui.keyCode.PAGE_DOWN:
  9477. this.nextPage( event );
  9478. break;
  9479. case $.ui.keyCode.HOME:
  9480. this._move( "first", "first", event );
  9481. break;
  9482. case $.ui.keyCode.END:
  9483. this._move( "last", "last", event );
  9484. break;
  9485. case $.ui.keyCode.UP:
  9486. this.previous( event );
  9487. break;
  9488. case $.ui.keyCode.DOWN:
  9489. this.next( event );
  9490. break;
  9491. case $.ui.keyCode.LEFT:
  9492. this.collapse( event );
  9493. break;
  9494. case $.ui.keyCode.RIGHT:
  9495. if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
  9496. this.expand( event );
  9497. }
  9498. break;
  9499. case $.ui.keyCode.ENTER:
  9500. case $.ui.keyCode.SPACE:
  9501. this._activate( event );
  9502. break;
  9503. case $.ui.keyCode.ESCAPE:
  9504. this.collapse( event );
  9505. break;
  9506. default:
  9507. preventDefault = false;
  9508. prev = this.previousFilter || "";
  9509. character = String.fromCharCode( event.keyCode );
  9510. skip = false;
  9511. clearTimeout( this.filterTimer );
  9512. if ( character === prev ) {
  9513. skip = true;
  9514. } else {
  9515. character = prev + character;
  9516. }
  9517. regex = new RegExp( "^" + escape( character ), "i" );
  9518. match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
  9519. return regex.test( $( this ).children( "a" ).text() );
  9520. });
  9521. match = skip && match.index( this.active.next() ) !== -1 ?
  9522. this.active.nextAll( ".ui-menu-item" ) :
  9523. match;
  9524. // If no matches on the current filter, reset to the last character pressed
  9525. // to move down the menu to the first item that starts with that character
  9526. if ( !match.length ) {
  9527. character = String.fromCharCode( event.keyCode );
  9528. regex = new RegExp( "^" + escape( character ), "i" );
  9529. match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
  9530. return regex.test( $( this ).children( "a" ).text() );
  9531. });
  9532. }
  9533. if ( match.length ) {
  9534. this.focus( event, match );
  9535. if ( match.length > 1 ) {
  9536. this.previousFilter = character;
  9537. this.filterTimer = this._delay(function() {
  9538. delete this.previousFilter;
  9539. }, 1000 );
  9540. } else {
  9541. delete this.previousFilter;
  9542. }
  9543. } else {
  9544. delete this.previousFilter;
  9545. }
  9546. }
  9547. if ( preventDefault ) {
  9548. event.preventDefault();
  9549. }
  9550. },
  9551. _activate: function( event ) {
  9552. if ( !this.active.is( ".ui-state-disabled" ) ) {
  9553. if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
  9554. this.expand( event );
  9555. } else {
  9556. this.select( event );
  9557. }
  9558. }
  9559. },
  9560. refresh: function() {
  9561. var menus,
  9562. icon = this.options.icons.submenu,
  9563. submenus = this.element.find( this.options.menus );
  9564. // Initialize nested menus
  9565. submenus.filter( ":not(.ui-menu)" )
  9566. .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
  9567. .hide()
  9568. .attr({
  9569. role: this.options.role,
  9570. "aria-hidden": "true",
  9571. "aria-expanded": "false"
  9572. })
  9573. .each(function() {
  9574. var menu = $( this ),
  9575. item = menu.prev( "a" ),
  9576. submenuCarat = $( "<span>" )
  9577. .addClass( "ui-menu-icon ui-icon " + icon )
  9578. .data( "ui-menu-submenu-carat", true );
  9579. item
  9580. .attr( "aria-haspopup", "true" )
  9581. .prepend( submenuCarat );
  9582. menu.attr( "aria-labelledby", item.attr( "id" ) );
  9583. });
  9584. menus = submenus.add( this.element );
  9585. // Don't refresh list items that are already adapted
  9586. menus.children( ":not(.ui-menu-item):has(a)" )
  9587. .addClass( "ui-menu-item" )
  9588. .attr( "role", "presentation" )
  9589. .children( "a" )
  9590. .uniqueId()
  9591. .addClass( "ui-corner-all" )
  9592. .attr({
  9593. tabIndex: -1,
  9594. role: this._itemRole()
  9595. });
  9596. // Initialize unlinked menu-items containing spaces and/or dashes only as dividers
  9597. menus.children( ":not(.ui-menu-item)" ).each(function() {
  9598. var item = $( this );
  9599. // hyphen, em dash, en dash
  9600. if ( !/[^\-â&#x20AC;&#x201D;â&#x20AC;&#x201C;\s]/.test( item.text() ) ) {
  9601. item.addClass( "ui-widget-content ui-menu-divider" );
  9602. }
  9603. });
  9604. // Add aria-disabled attribute to any disabled menu item
  9605. menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
  9606. // If the active item has been removed, blur the menu
  9607. if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
  9608. this.blur();
  9609. }
  9610. },
  9611. _itemRole: function() {
  9612. return {
  9613. menu: "menuitem",
  9614. listbox: "option"
  9615. }[ this.options.role ];
  9616. },
  9617. focus: function( event, item ) {
  9618. var nested, focused;
  9619. this.blur( event, event && event.type === "focus" );
  9620. this._scrollIntoView( item );
  9621. this.active = item.first();
  9622. focused = this.active.children( "a" ).addClass( "ui-state-focus" );
  9623. // Only update aria-activedescendant if there's a role
  9624. // otherwise we assume focus is managed elsewhere
  9625. if ( this.options.role ) {
  9626. this.element.attr( "aria-activedescendant", focused.attr( "id" ) );
  9627. }
  9628. // Highlight active parent menu item, if any
  9629. this.active
  9630. .parent()
  9631. .closest( ".ui-menu-item" )
  9632. .children( "a:first" )
  9633. .addClass( "ui-state-active" );
  9634. if ( event && event.type === "keydown" ) {
  9635. this._close();
  9636. } else {
  9637. this.timer = this._delay(function() {
  9638. this._close();
  9639. }, this.delay );
  9640. }
  9641. nested = item.children( ".ui-menu" );
  9642. if ( nested.length && ( /^mouse/.test( event.type ) ) ) {
  9643. this._startOpening(nested);
  9644. }
  9645. this.activeMenu = item.parent();
  9646. this._trigger( "focus", event, { item: item } );
  9647. },
  9648. _scrollIntoView: function( item ) {
  9649. var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
  9650. if ( this._hasScroll() ) {
  9651. borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0;
  9652. paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0;
  9653. offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
  9654. scroll = this.activeMenu.scrollTop();
  9655. elementHeight = this.activeMenu.height();
  9656. itemHeight = item.height();
  9657. if ( offset < 0 ) {
  9658. this.activeMenu.scrollTop( scroll + offset );
  9659. } else if ( offset + itemHeight > elementHeight ) {
  9660. this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
  9661. }
  9662. }
  9663. },
  9664. blur: function( event, fromFocus ) {
  9665. if ( !fromFocus ) {
  9666. clearTimeout( this.timer );
  9667. }
  9668. if ( !this.active ) {
  9669. return;
  9670. }
  9671. this.active.children( "a" ).removeClass( "ui-state-focus" );
  9672. this.active = null;
  9673. this._trigger( "blur", event, { item: this.active } );
  9674. },
  9675. _startOpening: function( submenu ) {
  9676. clearTimeout( this.timer );
  9677. // Don't open if already open fixes a Firefox bug that caused a .5 pixel
  9678. // shift in the submenu position when mousing over the carat icon
  9679. if ( submenu.attr( "aria-hidden" ) !== "true" ) {
  9680. return;
  9681. }
  9682. this.timer = this._delay(function() {
  9683. this._close();
  9684. this._open( submenu );
  9685. }, this.delay );
  9686. },
  9687. _open: function( submenu ) {
  9688. var position = $.extend({
  9689. of: this.active
  9690. }, this.options.position );
  9691. clearTimeout( this.timer );
  9692. this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) )
  9693. .hide()
  9694. .attr( "aria-hidden", "true" );
  9695. submenu
  9696. .show()
  9697. .removeAttr( "aria-hidden" )
  9698. .attr( "aria-expanded", "true" )
  9699. .position( position );
  9700. },
  9701. collapseAll: function( event, all ) {
  9702. clearTimeout( this.timer );
  9703. this.timer = this._delay(function() {
  9704. // If we were passed an event, look for the submenu that contains the event
  9705. var currentMenu = all ? this.element :
  9706. $( event && event.target ).closest( this.element.find( ".ui-menu" ) );
  9707. // If we found no valid submenu ancestor, use the main menu to close all sub menus anyway
  9708. if ( !currentMenu.length ) {
  9709. currentMenu = this.element;
  9710. }
  9711. this._close( currentMenu );
  9712. this.blur( event );
  9713. this.activeMenu = currentMenu;
  9714. }, this.delay );
  9715. },
  9716. // With no arguments, closes the currently active menu - if nothing is active
  9717. // it closes all menus. If passed an argument, it will search for menus BELOW
  9718. _close: function( startMenu ) {
  9719. if ( !startMenu ) {
  9720. startMenu = this.active ? this.active.parent() : this.element;
  9721. }
  9722. startMenu
  9723. .find( ".ui-menu" )
  9724. .hide()
  9725. .attr( "aria-hidden", "true" )
  9726. .attr( "aria-expanded", "false" )
  9727. .end()
  9728. .find( "a.ui-state-active" )
  9729. .removeClass( "ui-state-active" );
  9730. },
  9731. collapse: function( event ) {
  9732. var newItem = this.active &&
  9733. this.active.parent().closest( ".ui-menu-item", this.element );
  9734. if ( newItem && newItem.length ) {
  9735. this._close();
  9736. this.focus( event, newItem );
  9737. }
  9738. },
  9739. expand: function( event ) {
  9740. var newItem = this.active &&
  9741. this.active
  9742. .children( ".ui-menu " )
  9743. .children( ".ui-menu-item" )
  9744. .first();
  9745. if ( newItem && newItem.length ) {
  9746. this._open( newItem.parent() );
  9747. // Delay so Firefox will not hide activedescendant change in expanding submenu from AT
  9748. this._delay(function() {
  9749. this.focus( event, newItem );
  9750. });
  9751. }
  9752. },
  9753. next: function( event ) {
  9754. this._move( "next", "first", event );
  9755. },
  9756. previous: function( event ) {
  9757. this._move( "prev", "last", event );
  9758. },
  9759. isFirstItem: function() {
  9760. return this.active && !this.active.prevAll( ".ui-menu-item" ).length;
  9761. },
  9762. isLastItem: function() {
  9763. return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
  9764. },
  9765. _move: function( direction, filter, event ) {
  9766. var next;
  9767. if ( this.active ) {
  9768. if ( direction === "first" || direction === "last" ) {
  9769. next = this.active
  9770. [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
  9771. .eq( -1 );
  9772. } else {
  9773. next = this.active
  9774. [ direction + "All" ]( ".ui-menu-item" )
  9775. .eq( 0 );
  9776. }
  9777. }
  9778. if ( !next || !next.length || !this.active ) {
  9779. next = this.activeMenu.children( ".ui-menu-item" )[ filter ]();
  9780. }
  9781. this.focus( event, next );
  9782. },
  9783. nextPage: function( event ) {
  9784. var item, base, height;
  9785. if ( !this.active ) {
  9786. this.next( event );
  9787. return;
  9788. }
  9789. if ( this.isLastItem() ) {
  9790. return;
  9791. }
  9792. if ( this._hasScroll() ) {
  9793. base = this.active.offset().top;
  9794. height = this.element.height();
  9795. this.active.nextAll( ".ui-menu-item" ).each(function() {
  9796. item = $( this );
  9797. return item.offset().top - base - height < 0;
  9798. });
  9799. this.focus( event, item );
  9800. } else {
  9801. this.focus( event, this.activeMenu.children( ".ui-menu-item" )
  9802. [ !this.active ? "first" : "last" ]() );
  9803. }
  9804. },
  9805. previousPage: function( event ) {
  9806. var item, base, height;
  9807. if ( !this.active ) {
  9808. this.next( event );
  9809. return;
  9810. }
  9811. if ( this.isFirstItem() ) {
  9812. return;
  9813. }
  9814. if ( this._hasScroll() ) {
  9815. base = this.active.offset().top;
  9816. height = this.element.height();
  9817. this.active.prevAll( ".ui-menu-item" ).each(function() {
  9818. item = $( this );
  9819. return item.offset().top - base + height > 0;
  9820. });
  9821. this.focus( event, item );
  9822. } else {
  9823. this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
  9824. }
  9825. },
  9826. _hasScroll: function() {
  9827. return this.element.outerHeight() < this.element.prop( "scrollHeight" );
  9828. },
  9829. select: function( event ) {
  9830. // TODO: It should never be possible to not have an active item at this
  9831. // point, but the tests don't trigger mouseenter before click.
  9832. this.active = this.active || $( event.target ).closest( ".ui-menu-item" );
  9833. var ui = { item: this.active };
  9834. if ( !this.active.has( ".ui-menu" ).length ) {
  9835. this.collapseAll( event, true );
  9836. }
  9837. this._trigger( "select", event, ui );
  9838. }
  9839. });
  9840. }( jQuery ));
  9841. (function( $, undefined ) {
  9842. $.ui = $.ui || {};
  9843. var cachedScrollbarWidth,
  9844. max = Math.max,
  9845. abs = Math.abs,
  9846. round = Math.round,
  9847. rhorizontal = /left|center|right/,
  9848. rvertical = /top|center|bottom/,
  9849. roffset = /[\+\-]\d+%?/,
  9850. rposition = /^\w+/,
  9851. rpercent = /%$/,
  9852. _position = $.fn.position;
  9853. function getOffsets( offsets, width, height ) {
  9854. return [
  9855. parseInt( offsets[ 0 ], 10 ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  9856. parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  9857. ];
  9858. }
  9859. function parseCss( element, property ) {
  9860. return parseInt( $.css( element, property ), 10 ) || 0;
  9861. }
  9862. $.position = {
  9863. scrollbarWidth: function() {
  9864. if ( cachedScrollbarWidth !== undefined ) {
  9865. return cachedScrollbarWidth;
  9866. }
  9867. var w1, w2,
  9868. div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
  9869. innerDiv = div.children()[0];
  9870. $( "body" ).append( div );
  9871. w1 = innerDiv.offsetWidth;
  9872. div.css( "overflow", "scroll" );
  9873. w2 = innerDiv.offsetWidth;
  9874. if ( w1 === w2 ) {
  9875. w2 = div[0].clientWidth;
  9876. }
  9877. div.remove();
  9878. return (cachedScrollbarWidth = w1 - w2);
  9879. },
  9880. getScrollInfo: function( within ) {
  9881. var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ),
  9882. overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ),
  9883. hasOverflowX = overflowX === "scroll" ||
  9884. ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
  9885. hasOverflowY = overflowY === "scroll" ||
  9886. ( overflowY === "auto" && within.height < within.element[0].scrollHeight );
  9887. return {
  9888. width: hasOverflowX ? $.position.scrollbarWidth() : 0,
  9889. height: hasOverflowY ? $.position.scrollbarWidth() : 0
  9890. };
  9891. },
  9892. getWithinInfo: function( element ) {
  9893. var withinElement = $( element || window ),
  9894. isWindow = $.isWindow( withinElement[0] );
  9895. return {
  9896. element: withinElement,
  9897. isWindow: isWindow,
  9898. offset: withinElement.offset() || { left: 0, top: 0 },
  9899. scrollLeft: withinElement.scrollLeft(),
  9900. scrollTop: withinElement.scrollTop(),
  9901. width: isWindow ? withinElement.width() : withinElement.outerWidth(),
  9902. height: isWindow ? withinElement.height() : withinElement.outerHeight()
  9903. };
  9904. }
  9905. };
  9906. $.fn.position = function( options ) {
  9907. if ( !options || !options.of ) {
  9908. return _position.apply( this, arguments );
  9909. }
  9910. // make a copy, we don't want to modify arguments
  9911. options = $.extend( {}, options );
  9912. var atOffset, targetWidth, targetHeight, targetOffset, basePosition,
  9913. target = $( options.of ),
  9914. within = $.position.getWithinInfo( options.within ),
  9915. scrollInfo = $.position.getScrollInfo( within ),
  9916. targetElem = target[0],
  9917. collision = ( options.collision || "flip" ).split( " " ),
  9918. offsets = {};
  9919. if ( targetElem.nodeType === 9 ) {
  9920. targetWidth = target.width();
  9921. targetHeight = target.height();
  9922. targetOffset = { top: 0, left: 0 };
  9923. } else if ( $.isWindow( targetElem ) ) {
  9924. targetWidth = target.width();
  9925. targetHeight = target.height();
  9926. targetOffset = { top: target.scrollTop(), left: target.scrollLeft() };
  9927. } else if ( targetElem.preventDefault ) {
  9928. // force left top to allow flipping
  9929. options.at = "left top";
  9930. targetWidth = targetHeight = 0;
  9931. targetOffset = { top: targetElem.pageY, left: targetElem.pageX };
  9932. } else {
  9933. targetWidth = target.outerWidth();
  9934. targetHeight = target.outerHeight();
  9935. targetOffset = target.offset();
  9936. }
  9937. // clone to reuse original targetOffset later
  9938. basePosition = $.extend( {}, targetOffset );
  9939. // force my and at to have valid horizontal and vertical positions
  9940. // if a value is missing or invalid, it will be converted to center
  9941. $.each( [ "my", "at" ], function() {
  9942. var pos = ( options[ this ] || "" ).split( " " ),
  9943. horizontalOffset,
  9944. verticalOffset;
  9945. if ( pos.length === 1) {
  9946. pos = rhorizontal.test( pos[ 0 ] ) ?
  9947. pos.concat( [ "center" ] ) :
  9948. rvertical.test( pos[ 0 ] ) ?
  9949. [ "center" ].concat( pos ) :
  9950. [ "center", "center" ];
  9951. }
  9952. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  9953. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  9954. // calculate offsets
  9955. horizontalOffset = roffset.exec( pos[ 0 ] );
  9956. verticalOffset = roffset.exec( pos[ 1 ] );
  9957. offsets[ this ] = [
  9958. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  9959. verticalOffset ? verticalOffset[ 0 ] : 0
  9960. ];
  9961. // reduce to just the positions without the offsets
  9962. options[ this ] = [
  9963. rposition.exec( pos[ 0 ] )[ 0 ],
  9964. rposition.exec( pos[ 1 ] )[ 0 ]
  9965. ];
  9966. });
  9967. // normalize collision option
  9968. if ( collision.length === 1 ) {
  9969. collision[ 1 ] = collision[ 0 ];
  9970. }
  9971. if ( options.at[ 0 ] === "right" ) {
  9972. basePosition.left += targetWidth;
  9973. } else if ( options.at[ 0 ] === "center" ) {
  9974. basePosition.left += targetWidth / 2;
  9975. }
  9976. if ( options.at[ 1 ] === "bottom" ) {
  9977. basePosition.top += targetHeight;
  9978. } else if ( options.at[ 1 ] === "center" ) {
  9979. basePosition.top += targetHeight / 2;
  9980. }
  9981. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  9982. basePosition.left += atOffset[ 0 ];
  9983. basePosition.top += atOffset[ 1 ];
  9984. return this.each(function() {
  9985. var collisionPosition, using,
  9986. elem = $( this ),
  9987. elemWidth = elem.outerWidth(),
  9988. elemHeight = elem.outerHeight(),
  9989. marginLeft = parseCss( this, "marginLeft" ),
  9990. marginTop = parseCss( this, "marginTop" ),
  9991. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
  9992. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
  9993. position = $.extend( {}, basePosition ),
  9994. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  9995. if ( options.my[ 0 ] === "right" ) {
  9996. position.left -= elemWidth;
  9997. } else if ( options.my[ 0 ] === "center" ) {
  9998. position.left -= elemWidth / 2;
  9999. }
  10000. if ( options.my[ 1 ] === "bottom" ) {
  10001. position.top -= elemHeight;
  10002. } else if ( options.my[ 1 ] === "center" ) {
  10003. position.top -= elemHeight / 2;
  10004. }
  10005. position.left += myOffset[ 0 ];
  10006. position.top += myOffset[ 1 ];
  10007. // if the browser doesn't support fractions, then round for consistent results
  10008. if ( !$.support.offsetFractions ) {
  10009. position.left = round( position.left );
  10010. position.top = round( position.top );
  10011. }
  10012. collisionPosition = {
  10013. marginLeft: marginLeft,
  10014. marginTop: marginTop
  10015. };
  10016. $.each( [ "left", "top" ], function( i, dir ) {
  10017. if ( $.ui.position[ collision[ i ] ] ) {
  10018. $.ui.position[ collision[ i ] ][ dir ]( position, {
  10019. targetWidth: targetWidth,
  10020. targetHeight: targetHeight,
  10021. elemWidth: elemWidth,
  10022. elemHeight: elemHeight,
  10023. collisionPosition: collisionPosition,
  10024. collisionWidth: collisionWidth,
  10025. collisionHeight: collisionHeight,
  10026. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  10027. my: options.my,
  10028. at: options.at,
  10029. within: within,
  10030. elem : elem
  10031. });
  10032. }
  10033. });
  10034. if ( $.fn.bgiframe ) {
  10035. elem.bgiframe();
  10036. }
  10037. if ( options.using ) {
  10038. // adds feedback as second argument to using callback, if present
  10039. using = function( props ) {
  10040. var left = targetOffset.left - position.left,
  10041. right = left + targetWidth - elemWidth,
  10042. top = targetOffset.top - position.top,
  10043. bottom = top + targetHeight - elemHeight,
  10044. feedback = {
  10045. target: {
  10046. element: target,
  10047. left: targetOffset.left,
  10048. top: targetOffset.top,
  10049. width: targetWidth,
  10050. height: targetHeight
  10051. },
  10052. element: {
  10053. element: elem,
  10054. left: position.left,
  10055. top: position.top,
  10056. width: elemWidth,
  10057. height: elemHeight
  10058. },
  10059. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  10060. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  10061. };
  10062. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  10063. feedback.horizontal = "center";
  10064. }
  10065. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  10066. feedback.vertical = "middle";
  10067. }
  10068. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  10069. feedback.important = "horizontal";
  10070. } else {
  10071. feedback.important = "vertical";
  10072. }
  10073. options.using.call( this, props, feedback );
  10074. };
  10075. }
  10076. elem.offset( $.extend( position, { using: using } ) );
  10077. });
  10078. };
  10079. $.ui.position = {
  10080. fit: {
  10081. left: function( position, data ) {
  10082. var within = data.within,
  10083. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  10084. outerWidth = within.width,
  10085. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  10086. overLeft = withinOffset - collisionPosLeft,
  10087. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  10088. newOverRight;
  10089. // element is wider than within
  10090. if ( data.collisionWidth > outerWidth ) {
  10091. // element is initially over the left side of within
  10092. if ( overLeft > 0 && overRight <= 0 ) {
  10093. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
  10094. position.left += overLeft - newOverRight;
  10095. // element is initially over right side of within
  10096. } else if ( overRight > 0 && overLeft <= 0 ) {
  10097. position.left = withinOffset;
  10098. // element is initially over both left and right sides of within
  10099. } else {
  10100. if ( overLeft > overRight ) {
  10101. position.left = withinOffset + outerWidth - data.collisionWidth;
  10102. } else {
  10103. position.left = withinOffset;
  10104. }
  10105. }
  10106. // too far left -> align with left edge
  10107. } else if ( overLeft > 0 ) {
  10108. position.left += overLeft;
  10109. // too far right -> align with right edge
  10110. } else if ( overRight > 0 ) {
  10111. position.left -= overRight;
  10112. // adjust based on position and margin
  10113. } else {
  10114. position.left = max( position.left - collisionPosLeft, position.left );
  10115. }
  10116. },
  10117. top: function( position, data ) {
  10118. var within = data.within,
  10119. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  10120. outerHeight = data.within.height,
  10121. collisionPosTop = position.top - data.collisionPosition.marginTop,
  10122. overTop = withinOffset - collisionPosTop,
  10123. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  10124. newOverBottom;
  10125. // element is taller than within
  10126. if ( data.collisionHeight > outerHeight ) {
  10127. // element is initially over the top of within
  10128. if ( overTop > 0 && overBottom <= 0 ) {
  10129. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
  10130. position.top += overTop - newOverBottom;
  10131. // element is initially over bottom of within
  10132. } else if ( overBottom > 0 && overTop <= 0 ) {
  10133. position.top = withinOffset;
  10134. // element is initially over both top and bottom of within
  10135. } else {
  10136. if ( overTop > overBottom ) {
  10137. position.top = withinOffset + outerHeight - data.collisionHeight;
  10138. } else {
  10139. position.top = withinOffset;
  10140. }
  10141. }
  10142. // too far up -> align with top
  10143. } else if ( overTop > 0 ) {
  10144. position.top += overTop;
  10145. // too far down -> align with bottom edge
  10146. } else if ( overBottom > 0 ) {
  10147. position.top -= overBottom;
  10148. // adjust based on position and margin
  10149. } else {
  10150. position.top = max( position.top - collisionPosTop, position.top );
  10151. }
  10152. }
  10153. },
  10154. flip: {
  10155. left: function( position, data ) {
  10156. var within = data.within,
  10157. withinOffset = within.offset.left + within.scrollLeft,
  10158. outerWidth = within.width,
  10159. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  10160. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  10161. overLeft = collisionPosLeft - offsetLeft,
  10162. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  10163. myOffset = data.my[ 0 ] === "left" ?
  10164. -data.elemWidth :
  10165. data.my[ 0 ] === "right" ?
  10166. data.elemWidth :
  10167. 0,
  10168. atOffset = data.at[ 0 ] === "left" ?
  10169. data.targetWidth :
  10170. data.at[ 0 ] === "right" ?
  10171. -data.targetWidth :
  10172. 0,
  10173. offset = -2 * data.offset[ 0 ],
  10174. newOverRight,
  10175. newOverLeft;
  10176. if ( overLeft < 0 ) {
  10177. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
  10178. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  10179. position.left += myOffset + atOffset + offset;
  10180. }
  10181. }
  10182. else if ( overRight > 0 ) {
  10183. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
  10184. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  10185. position.left += myOffset + atOffset + offset;
  10186. }
  10187. }
  10188. },
  10189. top: function( position, data ) {
  10190. var within = data.within,
  10191. withinOffset = within.offset.top + within.scrollTop,
  10192. outerHeight = within.height,
  10193. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  10194. collisionPosTop = position.top - data.collisionPosition.marginTop,
  10195. overTop = collisionPosTop - offsetTop,
  10196. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  10197. top = data.my[ 1 ] === "top",
  10198. myOffset = top ?
  10199. -data.elemHeight :
  10200. data.my[ 1 ] === "bottom" ?
  10201. data.elemHeight :
  10202. 0,
  10203. atOffset = data.at[ 1 ] === "top" ?
  10204. data.targetHeight :
  10205. data.at[ 1 ] === "bottom" ?
  10206. -data.targetHeight :
  10207. 0,
  10208. offset = -2 * data.offset[ 1 ],
  10209. newOverTop,
  10210. newOverBottom;
  10211. if ( overTop < 0 ) {
  10212. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
  10213. if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) ) {
  10214. position.top += myOffset + atOffset + offset;
  10215. }
  10216. }
  10217. else if ( overBottom > 0 ) {
  10218. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
  10219. if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || abs( newOverTop ) < overBottom ) ) {
  10220. position.top += myOffset + atOffset + offset;
  10221. }
  10222. }
  10223. }
  10224. },
  10225. flipfit: {
  10226. left: function() {
  10227. $.ui.position.flip.left.apply( this, arguments );
  10228. $.ui.position.fit.left.apply( this, arguments );
  10229. },
  10230. top: function() {
  10231. $.ui.position.flip.top.apply( this, arguments );
  10232. $.ui.position.fit.top.apply( this, arguments );
  10233. }
  10234. }
  10235. };
  10236. // fraction support test
  10237. (function () {
  10238. var testElement, testElementParent, testElementStyle, offsetLeft, i,
  10239. body = document.getElementsByTagName( "body" )[ 0 ],
  10240. div = document.createElement( "div" );
  10241. //Create a "fake body" for testing based on method used in jQuery.support
  10242. testElement = document.createElement( body ? "div" : "body" );
  10243. testElementStyle = {
  10244. visibility: "hidden",
  10245. width: 0,
  10246. height: 0,
  10247. border: 0,
  10248. margin: 0,
  10249. background: "none"
  10250. };
  10251. if ( body ) {
  10252. $.extend( testElementStyle, {
  10253. position: "absolute",
  10254. left: "-1000px",
  10255. top: "-1000px"
  10256. });
  10257. }
  10258. for ( i in testElementStyle ) {
  10259. testElement.style[ i ] = testElementStyle[ i ];
  10260. }
  10261. testElement.appendChild( div );
  10262. testElementParent = body || document.documentElement;
  10263. testElementParent.insertBefore( testElement, testElementParent.firstChild );
  10264. div.style.cssText = "position: absolute; left: 10.7432222px;";
  10265. offsetLeft = $( div ).offset().left;
  10266. $.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11;
  10267. testElement.innerHTML = "";
  10268. testElementParent.removeChild( testElement );
  10269. })();
  10270. // DEPRECATED
  10271. if ( $.uiBackCompat !== false ) {
  10272. // offset option
  10273. (function( $ ) {
  10274. var _position = $.fn.position;
  10275. $.fn.position = function( options ) {
  10276. if ( !options || !options.offset ) {
  10277. return _position.call( this, options );
  10278. }
  10279. var offset = options.offset.split( " " ),
  10280. at = options.at.split( " " );
  10281. if ( offset.length === 1 ) {
  10282. offset[ 1 ] = offset[ 0 ];
  10283. }
  10284. if ( /^\d/.test( offset[ 0 ] ) ) {
  10285. offset[ 0 ] = "+" + offset[ 0 ];
  10286. }
  10287. if ( /^\d/.test( offset[ 1 ] ) ) {
  10288. offset[ 1 ] = "+" + offset[ 1 ];
  10289. }
  10290. if ( at.length === 1 ) {
  10291. if ( /left|center|right/.test( at[ 0 ] ) ) {
  10292. at[ 1 ] = "center";
  10293. } else {
  10294. at[ 1 ] = at[ 0 ];
  10295. at[ 0 ] = "center";
  10296. }
  10297. }
  10298. return _position.call( this, $.extend( options, {
  10299. at: at[ 0 ] + offset[ 0 ] + " " + at[ 1 ] + offset[ 1 ],
  10300. offset: undefined
  10301. } ) );
  10302. };
  10303. }( jQuery ) );
  10304. }
  10305. }( jQuery ) );
  10306. (function( $, undefined ) {
  10307. $.widget( "ui.progressbar", {
  10308. version: "1.9.2",
  10309. options: {
  10310. value: 0,
  10311. max: 100
  10312. },
  10313. min: 0,
  10314. _create: function() {
  10315. this.element
  10316. .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
  10317. .attr({
  10318. role: "progressbar",
  10319. "aria-valuemin": this.min,
  10320. "aria-valuemax": this.options.max,
  10321. "aria-valuenow": this._value()
  10322. });
  10323. this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
  10324. .appendTo( this.element );
  10325. this.oldValue = this._value();
  10326. this._refreshValue();
  10327. },
  10328. _destroy: function() {
  10329. this.element
  10330. .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
  10331. .removeAttr( "role" )
  10332. .removeAttr( "aria-valuemin" )
  10333. .removeAttr( "aria-valuemax" )
  10334. .removeAttr( "aria-valuenow" );
  10335. this.valueDiv.remove();
  10336. },
  10337. value: function( newValue ) {
  10338. if ( newValue === undefined ) {
  10339. return this._value();
  10340. }
  10341. this._setOption( "value", newValue );
  10342. return this;
  10343. },
  10344. _setOption: function( key, value ) {
  10345. if ( key === "value" ) {
  10346. this.options.value = value;
  10347. this._refreshValue();
  10348. if ( this._value() === this.options.max ) {
  10349. this._trigger( "complete" );
  10350. }
  10351. }
  10352. this._super( key, value );
  10353. },
  10354. _value: function() {
  10355. var val = this.options.value;
  10356. // normalize invalid value
  10357. if ( typeof val !== "number" ) {
  10358. val = 0;
  10359. }
  10360. return Math.min( this.options.max, Math.max( this.min, val ) );
  10361. },
  10362. _percentage: function() {
  10363. return 100 * this._value() / this.options.max;
  10364. },
  10365. _refreshValue: function() {
  10366. var value = this.value(),
  10367. percentage = this._percentage();
  10368. if ( this.oldValue !== value ) {
  10369. this.oldValue = value;
  10370. this._trigger( "change" );
  10371. }
  10372. this.valueDiv
  10373. .toggle( value > this.min )
  10374. .toggleClass( "ui-corner-right", value === this.options.max )
  10375. .width( percentage.toFixed(0) + "%" );
  10376. this.element.attr( "aria-valuenow", value );
  10377. }
  10378. });
  10379. })( jQuery );
  10380. (function( $, undefined ) {
  10381. // number of pages in a slider
  10382. // (how many times can you page up/down to go through the whole range)
  10383. var numPages = 5;
  10384. $.widget( "ui.slider", $.ui.mouse, {
  10385. version: "1.9.2",
  10386. widgetEventPrefix: "slide",
  10387. options: {
  10388. animate: false,
  10389. distance: 0,
  10390. max: 100,
  10391. min: 0,
  10392. orientation: "horizontal",
  10393. range: false,
  10394. step: 1,
  10395. value: 0,
  10396. values: null
  10397. },
  10398. _create: function() {
  10399. var i, handleCount,
  10400. o = this.options,
  10401. existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
  10402. handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
  10403. handles = [];
  10404. this._keySliding = false;
  10405. this._mouseSliding = false;
  10406. this._animateOff = true;
  10407. this._handleIndex = null;
  10408. this._detectOrientation();
  10409. this._mouseInit();
  10410. this.element
  10411. .addClass( "ui-slider" +
  10412. " ui-slider-" + this.orientation +
  10413. " ui-widget" +
  10414. " ui-widget-content" +
  10415. " ui-corner-all" +
  10416. ( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) );
  10417. this.range = $([]);
  10418. if ( o.range ) {
  10419. if ( o.range === true ) {
  10420. if ( !o.values ) {
  10421. o.values = [ this._valueMin(), this._valueMin() ];
  10422. }
  10423. if ( o.values.length && o.values.length !== 2 ) {
  10424. o.values = [ o.values[0], o.values[0] ];
  10425. }
  10426. }
  10427. this.range = $( "<div></div>" )
  10428. .appendTo( this.element )
  10429. .addClass( "ui-slider-range" +
  10430. // note: this isn't the most fittingly semantic framework class for this element,
  10431. // but worked best visually with a variety of themes
  10432. " ui-widget-header" +
  10433. ( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) );
  10434. }
  10435. handleCount = ( o.values && o.values.length ) || 1;
  10436. for ( i = existingHandles.length; i < handleCount; i++ ) {
  10437. handles.push( handle );
  10438. }
  10439. this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( this.element ) );
  10440. this.handle = this.handles.eq( 0 );
  10441. this.handles.add( this.range ).filter( "a" )
  10442. .click(function( event ) {
  10443. event.preventDefault();
  10444. })
  10445. .mouseenter(function() {
  10446. if ( !o.disabled ) {
  10447. $( this ).addClass( "ui-state-hover" );
  10448. }
  10449. })
  10450. .mouseleave(function() {
  10451. $( this ).removeClass( "ui-state-hover" );
  10452. })
  10453. .focus(function() {
  10454. if ( !o.disabled ) {
  10455. $( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" );
  10456. $( this ).addClass( "ui-state-focus" );
  10457. } else {
  10458. $( this ).blur();
  10459. }
  10460. })
  10461. .blur(function() {
  10462. $( this ).removeClass( "ui-state-focus" );
  10463. });
  10464. this.handles.each(function( i ) {
  10465. $( this ).data( "ui-slider-handle-index", i );
  10466. });
  10467. this._on( this.handles, {
  10468. keydown: function( event ) {
  10469. var allowed, curVal, newVal, step,
  10470. index = $( event.target ).data( "ui-slider-handle-index" );
  10471. switch ( event.keyCode ) {
  10472. case $.ui.keyCode.HOME:
  10473. case $.ui.keyCode.END:
  10474. case $.ui.keyCode.PAGE_UP:
  10475. case $.ui.keyCode.PAGE_DOWN:
  10476. case $.ui.keyCode.UP:
  10477. case $.ui.keyCode.RIGHT:
  10478. case $.ui.keyCode.DOWN:
  10479. case $.ui.keyCode.LEFT:
  10480. event.preventDefault();
  10481. if ( !this._keySliding ) {
  10482. this._keySliding = true;
  10483. $( event.target ).addClass( "ui-state-active" );
  10484. allowed = this._start( event, index );
  10485. if ( allowed === false ) {
  10486. return;
  10487. }
  10488. }
  10489. break;
  10490. }
  10491. step = this.options.step;
  10492. if ( this.options.values && this.options.values.length ) {
  10493. curVal = newVal = this.values( index );
  10494. } else {
  10495. curVal = newVal = this.value();
  10496. }
  10497. switch ( event.keyCode ) {
  10498. case $.ui.keyCode.HOME:
  10499. newVal = this._valueMin();
  10500. break;
  10501. case $.ui.keyCode.END:
  10502. newVal = this._valueMax();
  10503. break;
  10504. case $.ui.keyCode.PAGE_UP:
  10505. newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
  10506. break;
  10507. case $.ui.keyCode.PAGE_DOWN:
  10508. newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
  10509. break;
  10510. case $.ui.keyCode.UP:
  10511. case $.ui.keyCode.RIGHT:
  10512. if ( curVal === this._valueMax() ) {
  10513. return;
  10514. }
  10515. newVal = this._trimAlignValue( curVal + step );
  10516. break;
  10517. case $.ui.keyCode.DOWN:
  10518. case $.ui.keyCode.LEFT:
  10519. if ( curVal === this._valueMin() ) {
  10520. return;
  10521. }
  10522. newVal = this._trimAlignValue( curVal - step );
  10523. break;
  10524. }
  10525. this._slide( event, index, newVal );
  10526. },
  10527. keyup: function( event ) {
  10528. var index = $( event.target ).data( "ui-slider-handle-index" );
  10529. if ( this._keySliding ) {
  10530. this._keySliding = false;
  10531. this._stop( event, index );
  10532. this._change( event, index );
  10533. $( event.target ).removeClass( "ui-state-active" );
  10534. }
  10535. }
  10536. });
  10537. this._refreshValue();
  10538. this._animateOff = false;
  10539. },
  10540. _destroy: function() {
  10541. this.handles.remove();
  10542. this.range.remove();
  10543. this.element
  10544. .removeClass( "ui-slider" +
  10545. " ui-slider-horizontal" +
  10546. " ui-slider-vertical" +
  10547. " ui-slider-disabled" +
  10548. " ui-widget" +
  10549. " ui-widget-content" +
  10550. " ui-corner-all" );
  10551. this._mouseDestroy();
  10552. },
  10553. _mouseCapture: function( event ) {
  10554. var position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle,
  10555. that = this,
  10556. o = this.options;
  10557. if ( o.disabled ) {
  10558. return false;
  10559. }
  10560. this.elementSize = {
  10561. width: this.element.outerWidth(),
  10562. height: this.element.outerHeight()
  10563. };
  10564. this.elementOffset = this.element.offset();
  10565. position = { x: event.pageX, y: event.pageY };
  10566. normValue = this._normValueFromMouse( position );
  10567. distance = this._valueMax() - this._valueMin() + 1;
  10568. this.handles.each(function( i ) {
  10569. var thisDistance = Math.abs( normValue - that.values(i) );
  10570. if ( distance > thisDistance ) {
  10571. distance = thisDistance;
  10572. closestHandle = $( this );
  10573. index = i;
  10574. }
  10575. });
  10576. // workaround for bug #3736 (if both handles of a range are at 0,
  10577. // the first is always used as the one with least distance,
  10578. // and moving it is obviously prevented by preventing negative ranges)
  10579. if( o.range === true && this.values(1) === o.min ) {
  10580. index += 1;
  10581. closestHandle = $( this.handles[index] );
  10582. }
  10583. allowed = this._start( event, index );
  10584. if ( allowed === false ) {
  10585. return false;
  10586. }
  10587. this._mouseSliding = true;
  10588. this._handleIndex = index;
  10589. closestHandle
  10590. .addClass( "ui-state-active" )
  10591. .focus();
  10592. offset = closestHandle.offset();
  10593. mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" );
  10594. this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
  10595. left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
  10596. top: event.pageY - offset.top -
  10597. ( closestHandle.height() / 2 ) -
  10598. ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) -
  10599. ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) +
  10600. ( parseInt( closestHandle.css("marginTop"), 10 ) || 0)
  10601. };
  10602. if ( !this.handles.hasClass( "ui-state-hover" ) ) {
  10603. this._slide( event, index, normValue );
  10604. }
  10605. this._animateOff = true;
  10606. return true;
  10607. },
  10608. _mouseStart: function() {
  10609. return true;
  10610. },
  10611. _mouseDrag: function( event ) {
  10612. var position = { x: event.pageX, y: event.pageY },
  10613. normValue = this._normValueFromMouse( position );
  10614. this._slide( event, this._handleIndex, normValue );
  10615. return false;
  10616. },
  10617. _mouseStop: function( event ) {
  10618. this.handles.removeClass( "ui-state-active" );
  10619. this._mouseSliding = false;
  10620. this._stop( event, this._handleIndex );
  10621. this._change( event, this._handleIndex );
  10622. this._handleIndex = null;
  10623. this._clickOffset = null;
  10624. this._animateOff = false;
  10625. return false;
  10626. },
  10627. _detectOrientation: function() {
  10628. this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
  10629. },
  10630. _normValueFromMouse: function( position ) {
  10631. var pixelTotal,
  10632. pixelMouse,
  10633. percentMouse,
  10634. valueTotal,
  10635. valueMouse;
  10636. if ( this.orientation === "horizontal" ) {
  10637. pixelTotal = this.elementSize.width;
  10638. pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 );
  10639. } else {
  10640. pixelTotal = this.elementSize.height;
  10641. pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 );
  10642. }
  10643. percentMouse = ( pixelMouse / pixelTotal );
  10644. if ( percentMouse > 1 ) {
  10645. percentMouse = 1;
  10646. }
  10647. if ( percentMouse < 0 ) {
  10648. percentMouse = 0;
  10649. }
  10650. if ( this.orientation === "vertical" ) {
  10651. percentMouse = 1 - percentMouse;
  10652. }
  10653. valueTotal = this._valueMax() - this._valueMin();
  10654. valueMouse = this._valueMin() + percentMouse * valueTotal;
  10655. return this._trimAlignValue( valueMouse );
  10656. },
  10657. _start: function( event, index ) {
  10658. var uiHash = {
  10659. handle: this.handles[ index ],
  10660. value: this.value()
  10661. };
  10662. if ( this.options.values && this.options.values.length ) {
  10663. uiHash.value = this.values( index );
  10664. uiHash.values = this.values();
  10665. }
  10666. return this._trigger( "start", event, uiHash );
  10667. },
  10668. _slide: function( event, index, newVal ) {
  10669. var otherVal,
  10670. newValues,
  10671. allowed;
  10672. if ( this.options.values && this.options.values.length ) {
  10673. otherVal = this.values( index ? 0 : 1 );
  10674. if ( ( this.options.values.length === 2 && this.options.range === true ) &&
  10675. ( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
  10676. ) {
  10677. newVal = otherVal;
  10678. }
  10679. if ( newVal !== this.values( index ) ) {
  10680. newValues = this.values();
  10681. newValues[ index ] = newVal;
  10682. // A slide can be canceled by returning false from the slide callback
  10683. allowed = this._trigger( "slide", event, {
  10684. handle: this.handles[ index ],
  10685. value: newVal,
  10686. values: newValues
  10687. } );
  10688. otherVal = this.values( index ? 0 : 1 );
  10689. if ( allowed !== false ) {
  10690. this.values( index, newVal, true );
  10691. }
  10692. }
  10693. } else {
  10694. if ( newVal !== this.value() ) {
  10695. // A slide can be canceled by returning false from the slide callback
  10696. allowed = this._trigger( "slide", event, {
  10697. handle: this.handles[ index ],
  10698. value: newVal
  10699. } );
  10700. if ( allowed !== false ) {
  10701. this.value( newVal );
  10702. }
  10703. }
  10704. }
  10705. },
  10706. _stop: function( event, index ) {
  10707. var uiHash = {
  10708. handle: this.handles[ index ],
  10709. value: this.value()
  10710. };
  10711. if ( this.options.values && this.options.values.length ) {
  10712. uiHash.value = this.values( index );
  10713. uiHash.values = this.values();
  10714. }
  10715. this._trigger( "stop", event, uiHash );
  10716. },
  10717. _change: function( event, index ) {
  10718. if ( !this._keySliding && !this._mouseSliding ) {
  10719. var uiHash = {
  10720. handle: this.handles[ index ],
  10721. value: this.value()
  10722. };
  10723. if ( this.options.values && this.options.values.length ) {
  10724. uiHash.value = this.values( index );
  10725. uiHash.values = this.values();
  10726. }
  10727. this._trigger( "change", event, uiHash );
  10728. }
  10729. },
  10730. value: function( newValue ) {
  10731. if ( arguments.length ) {
  10732. this.options.value = this._trimAlignValue( newValue );
  10733. this._refreshValue();
  10734. this._change( null, 0 );
  10735. return;
  10736. }
  10737. return this._value();
  10738. },
  10739. values: function( index, newValue ) {
  10740. var vals,
  10741. newValues,
  10742. i;
  10743. if ( arguments.length > 1 ) {
  10744. this.options.values[ index ] = this._trimAlignValue( newValue );
  10745. this._refreshValue();
  10746. this._change( null, index );
  10747. return;
  10748. }
  10749. if ( arguments.length ) {
  10750. if ( $.isArray( arguments[ 0 ] ) ) {
  10751. vals = this.options.values;
  10752. newValues = arguments[ 0 ];
  10753. for ( i = 0; i < vals.length; i += 1 ) {
  10754. vals[ i ] = this._trimAlignValue( newValues[ i ] );
  10755. this._change( null, i );
  10756. }
  10757. this._refreshValue();
  10758. } else {
  10759. if ( this.options.values && this.options.values.length ) {
  10760. return this._values( index );
  10761. } else {
  10762. return this.value();
  10763. }
  10764. }
  10765. } else {
  10766. return this._values();
  10767. }
  10768. },
  10769. _setOption: function( key, value ) {
  10770. var i,
  10771. valsLength = 0;
  10772. if ( $.isArray( this.options.values ) ) {
  10773. valsLength = this.options.values.length;
  10774. }
  10775. $.Widget.prototype._setOption.apply( this, arguments );
  10776. switch ( key ) {
  10777. case "disabled":
  10778. if ( value ) {
  10779. this.handles.filter( ".ui-state-focus" ).blur();
  10780. this.handles.removeClass( "ui-state-hover" );
  10781. this.handles.prop( "disabled", true );
  10782. this.element.addClass( "ui-disabled" );
  10783. } else {
  10784. this.handles.prop( "disabled", false );
  10785. this.element.removeClass( "ui-disabled" );
  10786. }
  10787. break;
  10788. case "orientation":
  10789. this._detectOrientation();
  10790. this.element
  10791. .removeClass( "ui-slider-horizontal ui-slider-vertical" )
  10792. .addClass( "ui-slider-" + this.orientation );
  10793. this._refreshValue();
  10794. break;
  10795. case "value":
  10796. this._animateOff = true;
  10797. this._refreshValue();
  10798. this._change( null, 0 );
  10799. this._animateOff = false;
  10800. break;
  10801. case "values":
  10802. this._animateOff = true;
  10803. this._refreshValue();
  10804. for ( i = 0; i < valsLength; i += 1 ) {
  10805. this._change( null, i );
  10806. }
  10807. this._animateOff = false;
  10808. break;
  10809. case "min":
  10810. case "max":
  10811. this._animateOff = true;
  10812. this._refreshValue();
  10813. this._animateOff = false;
  10814. break;
  10815. }
  10816. },
  10817. //internal value getter
  10818. // _value() returns value trimmed by min and max, aligned by step
  10819. _value: function() {
  10820. var val = this.options.value;
  10821. val = this._trimAlignValue( val );
  10822. return val;
  10823. },
  10824. //internal values getter
  10825. // _values() returns array of values trimmed by min and max, aligned by step
  10826. // _values( index ) returns single value trimmed by min and max, aligned by step
  10827. _values: function( index ) {
  10828. var val,
  10829. vals,
  10830. i;
  10831. if ( arguments.length ) {
  10832. val = this.options.values[ index ];
  10833. val = this._trimAlignValue( val );
  10834. return val;
  10835. } else {
  10836. // .slice() creates a copy of the array
  10837. // this copy gets trimmed by min and max and then returned
  10838. vals = this.options.values.slice();
  10839. for ( i = 0; i < vals.length; i+= 1) {
  10840. vals[ i ] = this._trimAlignValue( vals[ i ] );
  10841. }
  10842. return vals;
  10843. }
  10844. },
  10845. // returns the step-aligned value that val is closest to, between (inclusive) min and max
  10846. _trimAlignValue: function( val ) {
  10847. if ( val <= this._valueMin() ) {
  10848. return this._valueMin();
  10849. }
  10850. if ( val >= this._valueMax() ) {
  10851. return this._valueMax();
  10852. }
  10853. var step = ( this.options.step > 0 ) ? this.options.step : 1,
  10854. valModStep = (val - this._valueMin()) % step,
  10855. alignValue = val - valModStep;
  10856. if ( Math.abs(valModStep) * 2 >= step ) {
  10857. alignValue += ( valModStep > 0 ) ? step : ( -step );
  10858. }
  10859. // Since JavaScript has problems with large floats, round
  10860. // the final value to 5 digits after the decimal point (see #4124)
  10861. return parseFloat( alignValue.toFixed(5) );
  10862. },
  10863. _valueMin: function() {
  10864. return this.options.min;
  10865. },
  10866. _valueMax: function() {
  10867. return this.options.max;
  10868. },
  10869. _refreshValue: function() {
  10870. var lastValPercent, valPercent, value, valueMin, valueMax,
  10871. oRange = this.options.range,
  10872. o = this.options,
  10873. that = this,
  10874. animate = ( !this._animateOff ) ? o.animate : false,
  10875. _set = {};
  10876. if ( this.options.values && this.options.values.length ) {
  10877. this.handles.each(function( i ) {
  10878. valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100;
  10879. _set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
  10880. $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
  10881. if ( that.options.range === true ) {
  10882. if ( that.orientation === "horizontal" ) {
  10883. if ( i === 0 ) {
  10884. that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
  10885. }
  10886. if ( i === 1 ) {
  10887. that.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
  10888. }
  10889. } else {
  10890. if ( i === 0 ) {
  10891. that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
  10892. }
  10893. if ( i === 1 ) {
  10894. that.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
  10895. }
  10896. }
  10897. }
  10898. lastValPercent = valPercent;
  10899. });
  10900. } else {
  10901. value = this.value();
  10902. valueMin = this._valueMin();
  10903. valueMax = this._valueMax();
  10904. valPercent = ( valueMax !== valueMin ) ?
  10905. ( value - valueMin ) / ( valueMax - valueMin ) * 100 :
  10906. 0;
  10907. _set[ this.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
  10908. this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
  10909. if ( oRange === "min" && this.orientation === "horizontal" ) {
  10910. this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate );
  10911. }
  10912. if ( oRange === "max" && this.orientation === "horizontal" ) {
  10913. this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
  10914. }
  10915. if ( oRange === "min" && this.orientation === "vertical" ) {
  10916. this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate );
  10917. }
  10918. if ( oRange === "max" && this.orientation === "vertical" ) {
  10919. this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
  10920. }
  10921. }
  10922. }
  10923. });
  10924. }(jQuery));
  10925. (function( $ ) {
  10926. function modifier( fn ) {
  10927. return function() {
  10928. var previous = this.element.val();
  10929. fn.apply( this, arguments );
  10930. this._refresh();
  10931. if ( previous !== this.element.val() ) {
  10932. this._trigger( "change" );
  10933. }
  10934. };
  10935. }
  10936. $.widget( "ui.spinner", {
  10937. version: "1.9.2",
  10938. defaultElement: "<input>",
  10939. widgetEventPrefix: "spin",
  10940. options: {
  10941. culture: null,
  10942. icons: {
  10943. down: "ui-icon-triangle-1-s",
  10944. up: "ui-icon-triangle-1-n"
  10945. },
  10946. incremental: true,
  10947. max: null,
  10948. min: null,
  10949. numberFormat: null,
  10950. page: 10,
  10951. step: 1,
  10952. change: null,
  10953. spin: null,
  10954. start: null,
  10955. stop: null
  10956. },
  10957. _create: function() {
  10958. // handle string values that need to be parsed
  10959. this._setOption( "max", this.options.max );
  10960. this._setOption( "min", this.options.min );
  10961. this._setOption( "step", this.options.step );
  10962. // format the value, but don't constrain
  10963. this._value( this.element.val(), true );
  10964. this._draw();
  10965. this._on( this._events );
  10966. this._refresh();
  10967. // turning off autocomplete prevents the browser from remembering the
  10968. // value when navigating through history, so we re-enable autocomplete
  10969. // if the page is unloaded before the widget is destroyed. #7790
  10970. this._on( this.window, {
  10971. beforeunload: function() {
  10972. this.element.removeAttr( "autocomplete" );
  10973. }
  10974. });
  10975. },
  10976. _getCreateOptions: function() {
  10977. var options = {},
  10978. element = this.element;
  10979. $.each( [ "min", "max", "step" ], function( i, option ) {
  10980. var value = element.attr( option );
  10981. if ( value !== undefined && value.length ) {
  10982. options[ option ] = value;
  10983. }
  10984. });
  10985. return options;
  10986. },
  10987. _events: {
  10988. keydown: function( event ) {
  10989. if ( this._start( event ) && this._keydown( event ) ) {
  10990. event.preventDefault();
  10991. }
  10992. },
  10993. keyup: "_stop",
  10994. focus: function() {
  10995. this.previous = this.element.val();
  10996. },
  10997. blur: function( event ) {
  10998. if ( this.cancelBlur ) {
  10999. delete this.cancelBlur;
  11000. return;
  11001. }
  11002. this._refresh();
  11003. if ( this.previous !== this.element.val() ) {
  11004. this._trigger( "change", event );
  11005. }
  11006. },
  11007. mousewheel: function( event, delta ) {
  11008. if ( !delta ) {
  11009. return;
  11010. }
  11011. if ( !this.spinning && !this._start( event ) ) {
  11012. return false;
  11013. }
  11014. this._spin( (delta > 0 ? 1 : -1) * this.options.step, event );
  11015. clearTimeout( this.mousewheelTimer );
  11016. this.mousewheelTimer = this._delay(function() {
  11017. if ( this.spinning ) {
  11018. this._stop( event );
  11019. }
  11020. }, 100 );
  11021. event.preventDefault();
  11022. },
  11023. "mousedown .ui-spinner-button": function( event ) {
  11024. var previous;
  11025. // We never want the buttons to have focus; whenever the user is
  11026. // interacting with the spinner, the focus should be on the input.
  11027. // If the input is focused then this.previous is properly set from
  11028. // when the input first received focus. If the input is not focused
  11029. // then we need to set this.previous based on the value before spinning.
  11030. previous = this.element[0] === this.document[0].activeElement ?
  11031. this.previous : this.element.val();
  11032. function checkFocus() {
  11033. var isActive = this.element[0] === this.document[0].activeElement;
  11034. if ( !isActive ) {
  11035. this.element.focus();
  11036. this.previous = previous;
  11037. // support: IE
  11038. // IE sets focus asynchronously, so we need to check if focus
  11039. // moved off of the input because the user clicked on the button.
  11040. this._delay(function() {
  11041. this.previous = previous;
  11042. });
  11043. }
  11044. }
  11045. // ensure focus is on (or stays on) the text field
  11046. event.preventDefault();
  11047. checkFocus.call( this );
  11048. // support: IE
  11049. // IE doesn't prevent moving focus even with event.preventDefault()
  11050. // so we set a flag to know when we should ignore the blur event
  11051. // and check (again) if focus moved off of the input.
  11052. this.cancelBlur = true;
  11053. this._delay(function() {
  11054. delete this.cancelBlur;
  11055. checkFocus.call( this );
  11056. });
  11057. if ( this._start( event ) === false ) {
  11058. return;
  11059. }
  11060. this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event );
  11061. },
  11062. "mouseup .ui-spinner-button": "_stop",
  11063. "mouseenter .ui-spinner-button": function( event ) {
  11064. // button will add ui-state-active if mouse was down while mouseleave and kept down
  11065. if ( !$( event.currentTarget ).hasClass( "ui-state-active" ) ) {
  11066. return;
  11067. }
  11068. if ( this._start( event ) === false ) {
  11069. return false;
  11070. }
  11071. this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event );
  11072. },
  11073. // TODO: do we really want to consider this a stop?
  11074. // shouldn't we just stop the repeater and wait until mouseup before
  11075. // we trigger the stop event?
  11076. "mouseleave .ui-spinner-button": "_stop"
  11077. },
  11078. _draw: function() {
  11079. var uiSpinner = this.uiSpinner = this.element
  11080. .addClass( "ui-spinner-input" )
  11081. .attr( "autocomplete", "off" )
  11082. .wrap( this._uiSpinnerHtml() )
  11083. .parent()
  11084. // add buttons
  11085. .append( this._buttonHtml() );
  11086. this.element.attr( "role", "spinbutton" );
  11087. // button bindings
  11088. this.buttons = uiSpinner.find( ".ui-spinner-button" )
  11089. .attr( "tabIndex", -1 )
  11090. .button()
  11091. .removeClass( "ui-corner-all" );
  11092. // IE 6 doesn't understand height: 50% for the buttons
  11093. // unless the wrapper has an explicit height
  11094. if ( this.buttons.height() > Math.ceil( uiSpinner.height() * 0.5 ) &&
  11095. uiSpinner.height() > 0 ) {
  11096. uiSpinner.height( uiSpinner.height() );
  11097. }
  11098. // disable spinner if element was already disabled
  11099. if ( this.options.disabled ) {
  11100. this.disable();
  11101. }
  11102. },
  11103. _keydown: function( event ) {
  11104. var options = this.options,
  11105. keyCode = $.ui.keyCode;
  11106. switch ( event.keyCode ) {
  11107. case keyCode.UP:
  11108. this._repeat( null, 1, event );
  11109. return true;
  11110. case keyCode.DOWN:
  11111. this._repeat( null, -1, event );
  11112. return true;
  11113. case keyCode.PAGE_UP:
  11114. this._repeat( null, options.page, event );
  11115. return true;
  11116. case keyCode.PAGE_DOWN:
  11117. this._repeat( null, -options.page, event );
  11118. return true;
  11119. }
  11120. return false;
  11121. },
  11122. _uiSpinnerHtml: function() {
  11123. return "<span class='ui-spinner ui-widget ui-widget-content ui-corner-all'></span>";
  11124. },
  11125. _buttonHtml: function() {
  11126. return "" +
  11127. "<a class='ui-spinner-button ui-spinner-up ui-corner-tr'>" +
  11128. "<span class='ui-icon " + this.options.icons.up + "'>&#9650;</span>" +
  11129. "</a>" +
  11130. "<a class='ui-spinner-button ui-spinner-down ui-corner-br'>" +
  11131. "<span class='ui-icon " + this.options.icons.down + "'>&#9660;</span>" +
  11132. "</a>";
  11133. },
  11134. _start: function( event ) {
  11135. if ( !this.spinning && this._trigger( "start", event ) === false ) {
  11136. return false;
  11137. }
  11138. if ( !this.counter ) {
  11139. this.counter = 1;
  11140. }
  11141. this.spinning = true;
  11142. return true;
  11143. },
  11144. _repeat: function( i, steps, event ) {
  11145. i = i || 500;
  11146. clearTimeout( this.timer );
  11147. this.timer = this._delay(function() {
  11148. this._repeat( 40, steps, event );
  11149. }, i );
  11150. this._spin( steps * this.options.step, event );
  11151. },
  11152. _spin: function( step, event ) {
  11153. var value = this.value() || 0;
  11154. if ( !this.counter ) {
  11155. this.counter = 1;
  11156. }
  11157. value = this._adjustValue( value + step * this._increment( this.counter ) );
  11158. if ( !this.spinning || this._trigger( "spin", event, { value: value } ) !== false) {
  11159. this._value( value );
  11160. this.counter++;
  11161. }
  11162. },
  11163. _increment: function( i ) {
  11164. var incremental = this.options.incremental;
  11165. if ( incremental ) {
  11166. return $.isFunction( incremental ) ?
  11167. incremental( i ) :
  11168. Math.floor( i*i*i/50000 - i*i/500 + 17*i/200 + 1 );
  11169. }
  11170. return 1;
  11171. },
  11172. _precision: function() {
  11173. var precision = this._precisionOf( this.options.step );
  11174. if ( this.options.min !== null ) {
  11175. precision = Math.max( precision, this._precisionOf( this.options.min ) );
  11176. }
  11177. return precision;
  11178. },
  11179. _precisionOf: function( num ) {
  11180. var str = num.toString(),
  11181. decimal = str.indexOf( "." );
  11182. return decimal === -1 ? 0 : str.length - decimal - 1;
  11183. },
  11184. _adjustValue: function( value ) {
  11185. var base, aboveMin,
  11186. options = this.options;
  11187. // make sure we're at a valid step
  11188. // - find out where we are relative to the base (min or 0)
  11189. base = options.min !== null ? options.min : 0;
  11190. aboveMin = value - base;
  11191. // - round to the nearest step
  11192. aboveMin = Math.round(aboveMin / options.step) * options.step;
  11193. // - rounding is based on 0, so adjust back to our base
  11194. value = base + aboveMin;
  11195. // fix precision from bad JS floating point math
  11196. value = parseFloat( value.toFixed( this._precision() ) );
  11197. // clamp the value
  11198. if ( options.max !== null && value > options.max) {
  11199. return options.max;
  11200. }
  11201. if ( options.min !== null && value < options.min ) {
  11202. return options.min;
  11203. }
  11204. return value;
  11205. },
  11206. _stop: function( event ) {
  11207. if ( !this.spinning ) {
  11208. return;
  11209. }
  11210. clearTimeout( this.timer );
  11211. clearTimeout( this.mousewheelTimer );
  11212. this.counter = 0;
  11213. this.spinning = false;
  11214. this._trigger( "stop", event );
  11215. },
  11216. _setOption: function( key, value ) {
  11217. if ( key === "culture" || key === "numberFormat" ) {
  11218. var prevValue = this._parse( this.element.val() );
  11219. this.options[ key ] = value;
  11220. this.element.val( this._format( prevValue ) );
  11221. return;
  11222. }
  11223. if ( key === "max" || key === "min" || key === "step" ) {
  11224. if ( typeof value === "string" ) {
  11225. value = this._parse( value );
  11226. }
  11227. }
  11228. this._super( key, value );
  11229. if ( key === "disabled" ) {
  11230. if ( value ) {
  11231. this.element.prop( "disabled", true );
  11232. this.buttons.button( "disable" );
  11233. } else {
  11234. this.element.prop( "disabled", false );
  11235. this.buttons.button( "enable" );
  11236. }
  11237. }
  11238. },
  11239. _setOptions: modifier(function( options ) {
  11240. this._super( options );
  11241. this._value( this.element.val() );
  11242. }),
  11243. _parse: function( val ) {
  11244. if ( typeof val === "string" && val !== "" ) {
  11245. val = window.Globalize && this.options.numberFormat ?
  11246. Globalize.parseFloat( val, 10, this.options.culture ) : +val;
  11247. }
  11248. return val === "" || isNaN( val ) ? null : val;
  11249. },
  11250. _format: function( value ) {
  11251. if ( value === "" ) {
  11252. return "";
  11253. }
  11254. return window.Globalize && this.options.numberFormat ?
  11255. Globalize.format( value, this.options.numberFormat, this.options.culture ) :
  11256. value;
  11257. },
  11258. _refresh: function() {
  11259. this.element.attr({
  11260. "aria-valuemin": this.options.min,
  11261. "aria-valuemax": this.options.max,
  11262. // TODO: what should we do with values that can't be parsed?
  11263. "aria-valuenow": this._parse( this.element.val() )
  11264. });
  11265. },
  11266. // update the value without triggering change
  11267. _value: function( value, allowAny ) {
  11268. var parsed;
  11269. if ( value !== "" ) {
  11270. parsed = this._parse( value );
  11271. if ( parsed !== null ) {
  11272. if ( !allowAny ) {
  11273. parsed = this._adjustValue( parsed );
  11274. }
  11275. value = this._format( parsed );
  11276. }
  11277. }
  11278. this.element.val( value );
  11279. this._refresh();
  11280. },
  11281. _destroy: function() {
  11282. this.element
  11283. .removeClass( "ui-spinner-input" )
  11284. .prop( "disabled", false )
  11285. .removeAttr( "autocomplete" )
  11286. .removeAttr( "role" )
  11287. .removeAttr( "aria-valuemin" )
  11288. .removeAttr( "aria-valuemax" )
  11289. .removeAttr( "aria-valuenow" );
  11290. this.uiSpinner.replaceWith( this.element );
  11291. },
  11292. stepUp: modifier(function( steps ) {
  11293. this._stepUp( steps );
  11294. }),
  11295. _stepUp: function( steps ) {
  11296. this._spin( (steps || 1) * this.options.step );
  11297. },
  11298. stepDown: modifier(function( steps ) {
  11299. this._stepDown( steps );
  11300. }),
  11301. _stepDown: function( steps ) {
  11302. this._spin( (steps || 1) * -this.options.step );
  11303. },
  11304. pageUp: modifier(function( pages ) {
  11305. this._stepUp( (pages || 1) * this.options.page );
  11306. }),
  11307. pageDown: modifier(function( pages ) {
  11308. this._stepDown( (pages || 1) * this.options.page );
  11309. }),
  11310. value: function( newVal ) {
  11311. if ( !arguments.length ) {
  11312. return this._parse( this.element.val() );
  11313. }
  11314. modifier( this._value ).call( this, newVal );
  11315. },
  11316. widget: function() {
  11317. return this.uiSpinner;
  11318. }
  11319. });
  11320. }( jQuery ) );
  11321. (function( $, undefined ) {
  11322. var tabId = 0,
  11323. rhash = /#.*$/;
  11324. function getNextTabId() {
  11325. return ++tabId;
  11326. }
  11327. function isLocal( anchor ) {
  11328. return anchor.hash.length > 1 &&
  11329. anchor.href.replace( rhash, "" ) ===
  11330. location.href.replace( rhash, "" )
  11331. // support: Safari 5.1
  11332. // Safari 5.1 doesn't encode spaces in window.location
  11333. // but it does encode spaces from anchors (#8777)
  11334. .replace( /\s/g, "%20" );
  11335. }
  11336. $.widget( "ui.tabs", {
  11337. version: "1.9.2",
  11338. delay: 300,
  11339. options: {
  11340. active: null,
  11341. collapsible: false,
  11342. event: "click",
  11343. heightStyle: "content",
  11344. hide: null,
  11345. show: null,
  11346. // callbacks
  11347. activate: null,
  11348. beforeActivate: null,
  11349. beforeLoad: null,
  11350. load: null
  11351. },
  11352. _create: function() {
  11353. var that = this,
  11354. options = this.options,
  11355. active = options.active,
  11356. locationHash = location.hash.substring( 1 );
  11357. this.running = false;
  11358. this.element
  11359. .addClass( "ui-tabs ui-widget ui-widget-content ui-corner-all" )
  11360. .toggleClass( "ui-tabs-collapsible", options.collapsible )
  11361. // Prevent users from focusing disabled tabs via click
  11362. .delegate( ".ui-tabs-nav > li", "mousedown" + this.eventNamespace, function( event ) {
  11363. if ( $( this ).is( ".ui-state-disabled" ) ) {
  11364. event.preventDefault();
  11365. }
  11366. })
  11367. // support: IE <9
  11368. // Preventing the default action in mousedown doesn't prevent IE
  11369. // from focusing the element, so if the anchor gets focused, blur.
  11370. // We don't have to worry about focusing the previously focused
  11371. // element since clicking on a non-focusable element should focus
  11372. // the body anyway.
  11373. .delegate( ".ui-tabs-anchor", "focus" + this.eventNamespace, function() {
  11374. if ( $( this ).closest( "li" ).is( ".ui-state-disabled" ) ) {
  11375. this.blur();
  11376. }
  11377. });
  11378. this._processTabs();
  11379. if ( active === null ) {
  11380. // check the fragment identifier in the URL
  11381. if ( locationHash ) {
  11382. this.tabs.each(function( i, tab ) {
  11383. if ( $( tab ).attr( "aria-controls" ) === locationHash ) {
  11384. active = i;
  11385. return false;
  11386. }
  11387. });
  11388. }
  11389. // check for a tab marked active via a class
  11390. if ( active === null ) {
  11391. active = this.tabs.index( this.tabs.filter( ".ui-tabs-active" ) );
  11392. }
  11393. // no active tab, set to false
  11394. if ( active === null || active === -1 ) {
  11395. active = this.tabs.length ? 0 : false;
  11396. }
  11397. }
  11398. // handle numbers: negative, out of range
  11399. if ( active !== false ) {
  11400. active = this.tabs.index( this.tabs.eq( active ) );
  11401. if ( active === -1 ) {
  11402. active = options.collapsible ? false : 0;
  11403. }
  11404. }
  11405. options.active = active;
  11406. // don't allow collapsible: false and active: false
  11407. if ( !options.collapsible && options.active === false && this.anchors.length ) {
  11408. options.active = 0;
  11409. }
  11410. // Take disabling tabs via class attribute from HTML
  11411. // into account and update option properly.
  11412. if ( $.isArray( options.disabled ) ) {
  11413. options.disabled = $.unique( options.disabled.concat(
  11414. $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
  11415. return that.tabs.index( li );
  11416. })
  11417. ) ).sort();
  11418. }
  11419. // check for length avoids error when initializing empty list
  11420. if ( this.options.active !== false && this.anchors.length ) {
  11421. this.active = this._findActive( this.options.active );
  11422. } else {
  11423. this.active = $();
  11424. }
  11425. this._refresh();
  11426. if ( this.active.length ) {
  11427. this.load( options.active );
  11428. }
  11429. },
  11430. _getCreateEventData: function() {
  11431. return {
  11432. tab: this.active,
  11433. panel: !this.active.length ? $() : this._getPanelForTab( this.active )
  11434. };
  11435. },
  11436. _tabKeydown: function( event ) {
  11437. var focusedTab = $( this.document[0].activeElement ).closest( "li" ),
  11438. selectedIndex = this.tabs.index( focusedTab ),
  11439. goingForward = true;
  11440. if ( this._handlePageNav( event ) ) {
  11441. return;
  11442. }
  11443. switch ( event.keyCode ) {
  11444. case $.ui.keyCode.RIGHT:
  11445. case $.ui.keyCode.DOWN:
  11446. selectedIndex++;
  11447. break;
  11448. case $.ui.keyCode.UP:
  11449. case $.ui.keyCode.LEFT:
  11450. goingForward = false;
  11451. selectedIndex--;
  11452. break;
  11453. case $.ui.keyCode.END:
  11454. selectedIndex = this.anchors.length - 1;
  11455. break;
  11456. case $.ui.keyCode.HOME:
  11457. selectedIndex = 0;
  11458. break;
  11459. case $.ui.keyCode.SPACE:
  11460. // Activate only, no collapsing
  11461. event.preventDefault();
  11462. clearTimeout( this.activating );
  11463. this._activate( selectedIndex );
  11464. return;
  11465. case $.ui.keyCode.ENTER:
  11466. // Toggle (cancel delayed activation, allow collapsing)
  11467. event.preventDefault();
  11468. clearTimeout( this.activating );
  11469. // Determine if we should collapse or activate
  11470. this._activate( selectedIndex === this.options.active ? false : selectedIndex );
  11471. return;
  11472. default:
  11473. return;
  11474. }
  11475. // Focus the appropriate tab, based on which key was pressed
  11476. event.preventDefault();
  11477. clearTimeout( this.activating );
  11478. selectedIndex = this._focusNextTab( selectedIndex, goingForward );
  11479. // Navigating with control key will prevent automatic activation
  11480. if ( !event.ctrlKey ) {
  11481. // Update aria-selected immediately so that AT think the tab is already selected.
  11482. // Otherwise AT may confuse the user by stating that they need to activate the tab,
  11483. // but the tab will already be activated by the time the announcement finishes.
  11484. focusedTab.attr( "aria-selected", "false" );
  11485. this.tabs.eq( selectedIndex ).attr( "aria-selected", "true" );
  11486. this.activating = this._delay(function() {
  11487. this.option( "active", selectedIndex );
  11488. }, this.delay );
  11489. }
  11490. },
  11491. _panelKeydown: function( event ) {
  11492. if ( this._handlePageNav( event ) ) {
  11493. return;
  11494. }
  11495. // Ctrl+up moves focus to the current tab
  11496. if ( event.ctrlKey && event.keyCode === $.ui.keyCode.UP ) {
  11497. event.preventDefault();
  11498. this.active.focus();
  11499. }
  11500. },
  11501. // Alt+page up/down moves focus to the previous/next tab (and activates)
  11502. _handlePageNav: function( event ) {
  11503. if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_UP ) {
  11504. this._activate( this._focusNextTab( this.options.active - 1, false ) );
  11505. return true;
  11506. }
  11507. if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_DOWN ) {
  11508. this._activate( this._focusNextTab( this.options.active + 1, true ) );
  11509. return true;
  11510. }
  11511. },
  11512. _findNextTab: function( index, goingForward ) {
  11513. var lastTabIndex = this.tabs.length - 1;
  11514. function constrain() {
  11515. if ( index > lastTabIndex ) {
  11516. index = 0;
  11517. }
  11518. if ( index < 0 ) {
  11519. index = lastTabIndex;
  11520. }
  11521. return index;
  11522. }
  11523. while ( $.inArray( constrain(), this.options.disabled ) !== -1 ) {
  11524. index = goingForward ? index + 1 : index - 1;
  11525. }
  11526. return index;
  11527. },
  11528. _focusNextTab: function( index, goingForward ) {
  11529. index = this._findNextTab( index, goingForward );
  11530. this.tabs.eq( index ).focus();
  11531. return index;
  11532. },
  11533. _setOption: function( key, value ) {
  11534. if ( key === "active" ) {
  11535. // _activate() will handle invalid values and update this.options
  11536. this._activate( value );
  11537. return;
  11538. }
  11539. if ( key === "disabled" ) {
  11540. // don't use the widget factory's disabled handling
  11541. this._setupDisabled( value );
  11542. return;
  11543. }
  11544. this._super( key, value);
  11545. if ( key === "collapsible" ) {
  11546. this.element.toggleClass( "ui-tabs-collapsible", value );
  11547. // Setting collapsible: false while collapsed; open first panel
  11548. if ( !value && this.options.active === false ) {
  11549. this._activate( 0 );
  11550. }
  11551. }
  11552. if ( key === "event" ) {
  11553. this._setupEvents( value );
  11554. }
  11555. if ( key === "heightStyle" ) {
  11556. this._setupHeightStyle( value );
  11557. }
  11558. },
  11559. _tabId: function( tab ) {
  11560. return tab.attr( "aria-controls" ) || "ui-tabs-" + getNextTabId();
  11561. },
  11562. _sanitizeSelector: function( hash ) {
  11563. return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : "";
  11564. },
  11565. refresh: function() {
  11566. var options = this.options,
  11567. lis = this.tablist.children( ":has(a[href])" );
  11568. // get disabled tabs from class attribute from HTML
  11569. // this will get converted to a boolean if needed in _refresh()
  11570. options.disabled = $.map( lis.filter( ".ui-state-disabled" ), function( tab ) {
  11571. return lis.index( tab );
  11572. });
  11573. this._processTabs();
  11574. // was collapsed or no tabs
  11575. if ( options.active === false || !this.anchors.length ) {
  11576. options.active = false;
  11577. this.active = $();
  11578. // was active, but active tab is gone
  11579. } else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) {
  11580. // all remaining tabs are disabled
  11581. if ( this.tabs.length === options.disabled.length ) {
  11582. options.active = false;
  11583. this.active = $();
  11584. // activate previous tab
  11585. } else {
  11586. this._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) );
  11587. }
  11588. // was active, active tab still exists
  11589. } else {
  11590. // make sure active index is correct
  11591. options.active = this.tabs.index( this.active );
  11592. }
  11593. this._refresh();
  11594. },
  11595. _refresh: function() {
  11596. this._setupDisabled( this.options.disabled );
  11597. this._setupEvents( this.options.event );
  11598. this._setupHeightStyle( this.options.heightStyle );
  11599. this.tabs.not( this.active ).attr({
  11600. "aria-selected": "false",
  11601. tabIndex: -1
  11602. });
  11603. this.panels.not( this._getPanelForTab( this.active ) )
  11604. .hide()
  11605. .attr({
  11606. "aria-expanded": "false",
  11607. "aria-hidden": "true"
  11608. });
  11609. // Make sure one tab is in the tab order
  11610. if ( !this.active.length ) {
  11611. this.tabs.eq( 0 ).attr( "tabIndex", 0 );
  11612. } else {
  11613. this.active
  11614. .addClass( "ui-tabs-active ui-state-active" )
  11615. .attr({
  11616. "aria-selected": "true",
  11617. tabIndex: 0
  11618. });
  11619. this._getPanelForTab( this.active )
  11620. .show()
  11621. .attr({
  11622. "aria-expanded": "true",
  11623. "aria-hidden": "false"
  11624. });
  11625. }
  11626. },
  11627. _processTabs: function() {
  11628. var that = this;
  11629. this.tablist = this._getList()
  11630. .addClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" )
  11631. .attr( "role", "tablist" );
  11632. this.tabs = this.tablist.find( "> li:has(a[href])" )
  11633. .addClass( "ui-state-default ui-corner-top" )
  11634. .attr({
  11635. role: "tab",
  11636. tabIndex: -1
  11637. });
  11638. this.anchors = this.tabs.map(function() {
  11639. return $( "a", this )[ 0 ];
  11640. })
  11641. .addClass( "ui-tabs-anchor" )
  11642. .attr({
  11643. role: "presentation",
  11644. tabIndex: -1
  11645. });
  11646. this.panels = $();
  11647. this.anchors.each(function( i, anchor ) {
  11648. var selector, panel, panelId,
  11649. anchorId = $( anchor ).uniqueId().attr( "id" ),
  11650. tab = $( anchor ).closest( "li" ),
  11651. originalAriaControls = tab.attr( "aria-controls" );
  11652. // inline tab
  11653. if ( isLocal( anchor ) ) {
  11654. selector = anchor.hash;
  11655. panel = that.element.find( that._sanitizeSelector( selector ) );
  11656. // remote tab
  11657. } else {
  11658. panelId = that._tabId( tab );
  11659. selector = "#" + panelId;
  11660. panel = that.element.find( selector );
  11661. if ( !panel.length ) {
  11662. panel = that._createPanel( panelId );
  11663. panel.insertAfter( that.panels[ i - 1 ] || that.tablist );
  11664. }
  11665. panel.attr( "aria-live", "polite" );
  11666. }
  11667. if ( panel.length) {
  11668. that.panels = that.panels.add( panel );
  11669. }
  11670. if ( originalAriaControls ) {
  11671. tab.data( "ui-tabs-aria-controls", originalAriaControls );
  11672. }
  11673. tab.attr({
  11674. "aria-controls": selector.substring( 1 ),
  11675. "aria-labelledby": anchorId
  11676. });
  11677. panel.attr( "aria-labelledby", anchorId );
  11678. });
  11679. this.panels
  11680. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  11681. .attr( "role", "tabpanel" );
  11682. },
  11683. // allow overriding how to find the list for rare usage scenarios (#7715)
  11684. _getList: function() {
  11685. return this.element.find( "ol,ul" ).eq( 0 );
  11686. },
  11687. _createPanel: function( id ) {
  11688. return $( "<div>" )
  11689. .attr( "id", id )
  11690. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  11691. .data( "ui-tabs-destroy", true );
  11692. },
  11693. _setupDisabled: function( disabled ) {
  11694. if ( $.isArray( disabled ) ) {
  11695. if ( !disabled.length ) {
  11696. disabled = false;
  11697. } else if ( disabled.length === this.anchors.length ) {
  11698. disabled = true;
  11699. }
  11700. }
  11701. // disable tabs
  11702. for ( var i = 0, li; ( li = this.tabs[ i ] ); i++ ) {
  11703. if ( disabled === true || $.inArray( i, disabled ) !== -1 ) {
  11704. $( li )
  11705. .addClass( "ui-state-disabled" )
  11706. .attr( "aria-disabled", "true" );
  11707. } else {
  11708. $( li )
  11709. .removeClass( "ui-state-disabled" )
  11710. .removeAttr( "aria-disabled" );
  11711. }
  11712. }
  11713. this.options.disabled = disabled;
  11714. },
  11715. _setupEvents: function( event ) {
  11716. var events = {
  11717. click: function( event ) {
  11718. event.preventDefault();
  11719. }
  11720. };
  11721. if ( event ) {
  11722. $.each( event.split(" "), function( index, eventName ) {
  11723. events[ eventName ] = "_eventHandler";
  11724. });
  11725. }
  11726. this._off( this.anchors.add( this.tabs ).add( this.panels ) );
  11727. this._on( this.anchors, events );
  11728. this._on( this.tabs, { keydown: "_tabKeydown" } );
  11729. this._on( this.panels, { keydown: "_panelKeydown" } );
  11730. this._focusable( this.tabs );
  11731. this._hoverable( this.tabs );
  11732. },
  11733. _setupHeightStyle: function( heightStyle ) {
  11734. var maxHeight, overflow,
  11735. parent = this.element.parent();
  11736. if ( heightStyle === "fill" ) {
  11737. // IE 6 treats height like minHeight, so we need to turn off overflow
  11738. // in order to get a reliable height
  11739. // we use the minHeight support test because we assume that only
  11740. // browsers that don't support minHeight will treat height as minHeight
  11741. if ( !$.support.minHeight ) {
  11742. overflow = parent.css( "overflow" );
  11743. parent.css( "overflow", "hidden");
  11744. }
  11745. maxHeight = parent.height();
  11746. this.element.siblings( ":visible" ).each(function() {
  11747. var elem = $( this ),
  11748. position = elem.css( "position" );
  11749. if ( position === "absolute" || position === "fixed" ) {
  11750. return;
  11751. }
  11752. maxHeight -= elem.outerHeight( true );
  11753. });
  11754. if ( overflow ) {
  11755. parent.css( "overflow", overflow );
  11756. }
  11757. this.element.children().not( this.panels ).each(function() {
  11758. maxHeight -= $( this ).outerHeight( true );
  11759. });
  11760. this.panels.each(function() {
  11761. $( this ).height( Math.max( 0, maxHeight -
  11762. $( this ).innerHeight() + $( this ).height() ) );
  11763. })
  11764. .css( "overflow", "auto" );
  11765. } else if ( heightStyle === "auto" ) {
  11766. maxHeight = 0;
  11767. this.panels.each(function() {
  11768. maxHeight = Math.max( maxHeight, $( this ).height( "" ).height() );
  11769. }).height( maxHeight );
  11770. }
  11771. },
  11772. _eventHandler: function( event ) {
  11773. var options = this.options,
  11774. active = this.active,
  11775. anchor = $( event.currentTarget ),
  11776. tab = anchor.closest( "li" ),
  11777. clickedIsActive = tab[ 0 ] === active[ 0 ],
  11778. collapsing = clickedIsActive && options.collapsible,
  11779. toShow = collapsing ? $() : this._getPanelForTab( tab ),
  11780. toHide = !active.length ? $() : this._getPanelForTab( active ),
  11781. eventData = {
  11782. oldTab: active,
  11783. oldPanel: toHide,
  11784. newTab: collapsing ? $() : tab,
  11785. newPanel: toShow
  11786. };
  11787. event.preventDefault();
  11788. if ( tab.hasClass( "ui-state-disabled" ) ||
  11789. // tab is already loading
  11790. tab.hasClass( "ui-tabs-loading" ) ||
  11791. // can't switch durning an animation
  11792. this.running ||
  11793. // click on active header, but not collapsible
  11794. ( clickedIsActive && !options.collapsible ) ||
  11795. // allow canceling activation
  11796. ( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
  11797. return;
  11798. }
  11799. options.active = collapsing ? false : this.tabs.index( tab );
  11800. this.active = clickedIsActive ? $() : tab;
  11801. if ( this.xhr ) {
  11802. this.xhr.abort();
  11803. }
  11804. if ( !toHide.length && !toShow.length ) {
  11805. $.error( "jQuery UI Tabs: Mismatching fragment identifier." );
  11806. }
  11807. if ( toShow.length ) {
  11808. this.load( this.tabs.index( tab ), event );
  11809. }
  11810. this._toggle( event, eventData );
  11811. },
  11812. // handles show/hide for selecting tabs
  11813. _toggle: function( event, eventData ) {
  11814. var that = this,
  11815. toShow = eventData.newPanel,
  11816. toHide = eventData.oldPanel;
  11817. this.running = true;
  11818. function complete() {
  11819. that.running = false;
  11820. that._trigger( "activate", event, eventData );
  11821. }
  11822. function show() {
  11823. eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
  11824. if ( toShow.length && that.options.show ) {
  11825. that._show( toShow, that.options.show, complete );
  11826. } else {
  11827. toShow.show();
  11828. complete();
  11829. }
  11830. }
  11831. // start out by hiding, then showing, then completing
  11832. if ( toHide.length && this.options.hide ) {
  11833. this._hide( toHide, this.options.hide, function() {
  11834. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  11835. show();
  11836. });
  11837. } else {
  11838. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  11839. toHide.hide();
  11840. show();
  11841. }
  11842. toHide.attr({
  11843. "aria-expanded": "false",
  11844. "aria-hidden": "true"
  11845. });
  11846. eventData.oldTab.attr( "aria-selected", "false" );
  11847. // If we're switching tabs, remove the old tab from the tab order.
  11848. // If we're opening from collapsed state, remove the previous tab from the tab order.
  11849. // If we're collapsing, then keep the collapsing tab in the tab order.
  11850. if ( toShow.length && toHide.length ) {
  11851. eventData.oldTab.attr( "tabIndex", -1 );
  11852. } else if ( toShow.length ) {
  11853. this.tabs.filter(function() {
  11854. return $( this ).attr( "tabIndex" ) === 0;
  11855. })
  11856. .attr( "tabIndex", -1 );
  11857. }
  11858. toShow.attr({
  11859. "aria-expanded": "true",
  11860. "aria-hidden": "false"
  11861. });
  11862. eventData.newTab.attr({
  11863. "aria-selected": "true",
  11864. tabIndex: 0
  11865. });
  11866. },
  11867. _activate: function( index ) {
  11868. var anchor,
  11869. active = this._findActive( index );
  11870. // trying to activate the already active panel
  11871. if ( active[ 0 ] === this.active[ 0 ] ) {
  11872. return;
  11873. }
  11874. // trying to collapse, simulate a click on the current active header
  11875. if ( !active.length ) {
  11876. active = this.active;
  11877. }
  11878. anchor = active.find( ".ui-tabs-anchor" )[ 0 ];
  11879. this._eventHandler({
  11880. target: anchor,
  11881. currentTarget: anchor,
  11882. preventDefault: $.noop
  11883. });
  11884. },
  11885. _findActive: function( index ) {
  11886. return index === false ? $() : this.tabs.eq( index );
  11887. },
  11888. _getIndex: function( index ) {
  11889. // meta-function to give users option to provide a href string instead of a numerical index.
  11890. if ( typeof index === "string" ) {
  11891. index = this.anchors.index( this.anchors.filter( "[href$='" + index + "']" ) );
  11892. }
  11893. return index;
  11894. },
  11895. _destroy: function() {
  11896. if ( this.xhr ) {
  11897. this.xhr.abort();
  11898. }
  11899. this.element.removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" );
  11900. this.tablist
  11901. .removeClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" )
  11902. .removeAttr( "role" );
  11903. this.anchors
  11904. .removeClass( "ui-tabs-anchor" )
  11905. .removeAttr( "role" )
  11906. .removeAttr( "tabIndex" )
  11907. .removeData( "href.tabs" )
  11908. .removeData( "load.tabs" )
  11909. .removeUniqueId();
  11910. this.tabs.add( this.panels ).each(function() {
  11911. if ( $.data( this, "ui-tabs-destroy" ) ) {
  11912. $( this ).remove();
  11913. } else {
  11914. $( this )
  11915. .removeClass( "ui-state-default ui-state-active ui-state-disabled " +
  11916. "ui-corner-top ui-corner-bottom ui-widget-content ui-tabs-active ui-tabs-panel" )
  11917. .removeAttr( "tabIndex" )
  11918. .removeAttr( "aria-live" )
  11919. .removeAttr( "aria-busy" )
  11920. .removeAttr( "aria-selected" )
  11921. .removeAttr( "aria-labelledby" )
  11922. .removeAttr( "aria-hidden" )
  11923. .removeAttr( "aria-expanded" )
  11924. .removeAttr( "role" );
  11925. }
  11926. });
  11927. this.tabs.each(function() {
  11928. var li = $( this ),
  11929. prev = li.data( "ui-tabs-aria-controls" );
  11930. if ( prev ) {
  11931. li.attr( "aria-controls", prev );
  11932. } else {
  11933. li.removeAttr( "aria-controls" );
  11934. }
  11935. });
  11936. this.panels.show();
  11937. if ( this.options.heightStyle !== "content" ) {
  11938. this.panels.css( "height", "" );
  11939. }
  11940. },
  11941. enable: function( index ) {
  11942. var disabled = this.options.disabled;
  11943. if ( disabled === false ) {
  11944. return;
  11945. }
  11946. if ( index === undefined ) {
  11947. disabled = false;
  11948. } else {
  11949. index = this._getIndex( index );
  11950. if ( $.isArray( disabled ) ) {
  11951. disabled = $.map( disabled, function( num ) {
  11952. return num !== index ? num : null;
  11953. });
  11954. } else {
  11955. disabled = $.map( this.tabs, function( li, num ) {
  11956. return num !== index ? num : null;
  11957. });
  11958. }
  11959. }
  11960. this._setupDisabled( disabled );
  11961. },
  11962. disable: function( index ) {
  11963. var disabled = this.options.disabled;
  11964. if ( disabled === true ) {
  11965. return;
  11966. }
  11967. if ( index === undefined ) {
  11968. disabled = true;
  11969. } else {
  11970. index = this._getIndex( index );
  11971. if ( $.inArray( index, disabled ) !== -1 ) {
  11972. return;
  11973. }
  11974. if ( $.isArray( disabled ) ) {
  11975. disabled = $.merge( [ index ], disabled ).sort();
  11976. } else {
  11977. disabled = [ index ];
  11978. }
  11979. }
  11980. this._setupDisabled( disabled );
  11981. },
  11982. load: function( index, event ) {
  11983. index = this._getIndex( index );
  11984. var that = this,
  11985. tab = this.tabs.eq( index ),
  11986. anchor = tab.find( ".ui-tabs-anchor" ),
  11987. panel = this._getPanelForTab( tab ),
  11988. eventData = {
  11989. tab: tab,
  11990. panel: panel
  11991. };
  11992. // not remote
  11993. if ( isLocal( anchor[ 0 ] ) ) {
  11994. return;
  11995. }
  11996. this.xhr = $.ajax( this._ajaxSettings( anchor, event, eventData ) );
  11997. // support: jQuery <1.8
  11998. // jQuery <1.8 returns false if the request is canceled in beforeSend,
  11999. // but as of 1.8, $.ajax() always returns a jqXHR object.
  12000. if ( this.xhr && this.xhr.statusText !== "canceled" ) {
  12001. tab.addClass( "ui-tabs-loading" );
  12002. panel.attr( "aria-busy", "true" );
  12003. this.xhr
  12004. .success(function( response ) {
  12005. // support: jQuery <1.8
  12006. // http://bugs.jquery.com/ticket/11778
  12007. setTimeout(function() {
  12008. panel.html( response );
  12009. that._trigger( "load", event, eventData );
  12010. }, 1 );
  12011. })
  12012. .complete(function( jqXHR, status ) {
  12013. // support: jQuery <1.8
  12014. // http://bugs.jquery.com/ticket/11778
  12015. setTimeout(function() {
  12016. if ( status === "abort" ) {
  12017. that.panels.stop( false, true );
  12018. }
  12019. tab.removeClass( "ui-tabs-loading" );
  12020. panel.removeAttr( "aria-busy" );
  12021. if ( jqXHR === that.xhr ) {
  12022. delete that.xhr;
  12023. }
  12024. }, 1 );
  12025. });
  12026. }
  12027. },
  12028. // TODO: Remove this function in 1.10 when ajaxOptions is removed
  12029. _ajaxSettings: function( anchor, event, eventData ) {
  12030. var that = this;
  12031. return {
  12032. url: anchor.attr( "href" ),
  12033. beforeSend: function( jqXHR, settings ) {
  12034. return that._trigger( "beforeLoad", event,
  12035. $.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
  12036. }
  12037. };
  12038. },
  12039. _getPanelForTab: function( tab ) {
  12040. var id = $( tab ).attr( "aria-controls" );
  12041. return this.element.find( this._sanitizeSelector( "#" + id ) );
  12042. }
  12043. });
  12044. // DEPRECATED
  12045. if ( $.uiBackCompat !== false ) {
  12046. // helper method for a lot of the back compat extensions
  12047. $.ui.tabs.prototype._ui = function( tab, panel ) {
  12048. return {
  12049. tab: tab,
  12050. panel: panel,
  12051. index: this.anchors.index( tab )
  12052. };
  12053. };
  12054. // url method
  12055. $.widget( "ui.tabs", $.ui.tabs, {
  12056. url: function( index, url ) {
  12057. this.anchors.eq( index ).attr( "href", url );
  12058. }
  12059. });
  12060. // TODO: Remove _ajaxSettings() method when removing this extension
  12061. // ajaxOptions and cache options
  12062. $.widget( "ui.tabs", $.ui.tabs, {
  12063. options: {
  12064. ajaxOptions: null,
  12065. cache: false
  12066. },
  12067. _create: function() {
  12068. this._super();
  12069. var that = this;
  12070. this._on({ tabsbeforeload: function( event, ui ) {
  12071. // tab is already cached
  12072. if ( $.data( ui.tab[ 0 ], "cache.tabs" ) ) {
  12073. event.preventDefault();
  12074. return;
  12075. }
  12076. ui.jqXHR.success(function() {
  12077. if ( that.options.cache ) {
  12078. $.data( ui.tab[ 0 ], "cache.tabs", true );
  12079. }
  12080. });
  12081. }});
  12082. },
  12083. _ajaxSettings: function( anchor, event, ui ) {
  12084. var ajaxOptions = this.options.ajaxOptions;
  12085. return $.extend( {}, ajaxOptions, {
  12086. error: function( xhr, status ) {
  12087. try {
  12088. // Passing index avoid a race condition when this method is
  12089. // called after the user has selected another tab.
  12090. // Pass the anchor that initiated this request allows
  12091. // loadError to manipulate the tab content panel via $(a.hash)
  12092. ajaxOptions.error(
  12093. xhr, status, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
  12094. }
  12095. catch ( error ) {}
  12096. }
  12097. }, this._superApply( arguments ) );
  12098. },
  12099. _setOption: function( key, value ) {
  12100. // reset cache if switching from cached to not cached
  12101. if ( key === "cache" && value === false ) {
  12102. this.anchors.removeData( "cache.tabs" );
  12103. }
  12104. this._super( key, value );
  12105. },
  12106. _destroy: function() {
  12107. this.anchors.removeData( "cache.tabs" );
  12108. this._super();
  12109. },
  12110. url: function( index ){
  12111. this.anchors.eq( index ).removeData( "cache.tabs" );
  12112. this._superApply( arguments );
  12113. }
  12114. });
  12115. // abort method
  12116. $.widget( "ui.tabs", $.ui.tabs, {
  12117. abort: function() {
  12118. if ( this.xhr ) {
  12119. this.xhr.abort();
  12120. }
  12121. }
  12122. });
  12123. // spinner
  12124. $.widget( "ui.tabs", $.ui.tabs, {
  12125. options: {
  12126. spinner: "<em>Loading&#8230;</em>"
  12127. },
  12128. _create: function() {
  12129. this._super();
  12130. this._on({
  12131. tabsbeforeload: function( event, ui ) {
  12132. // Don't react to nested tabs or tabs that don't use a spinner
  12133. if ( event.target !== this.element[ 0 ] ||
  12134. !this.options.spinner ) {
  12135. return;
  12136. }
  12137. var span = ui.tab.find( "span" ),
  12138. html = span.html();
  12139. span.html( this.options.spinner );
  12140. ui.jqXHR.complete(function() {
  12141. span.html( html );
  12142. });
  12143. }
  12144. });
  12145. }
  12146. });
  12147. // enable/disable events
  12148. $.widget( "ui.tabs", $.ui.tabs, {
  12149. options: {
  12150. enable: null,
  12151. disable: null
  12152. },
  12153. enable: function( index ) {
  12154. var options = this.options,
  12155. trigger;
  12156. if ( index && options.disabled === true ||
  12157. ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) !== -1 ) ) {
  12158. trigger = true;
  12159. }
  12160. this._superApply( arguments );
  12161. if ( trigger ) {
  12162. this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  12163. }
  12164. },
  12165. disable: function( index ) {
  12166. var options = this.options,
  12167. trigger;
  12168. if ( index && options.disabled === false ||
  12169. ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) === -1 ) ) {
  12170. trigger = true;
  12171. }
  12172. this._superApply( arguments );
  12173. if ( trigger ) {
  12174. this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  12175. }
  12176. }
  12177. });
  12178. // add/remove methods and events
  12179. $.widget( "ui.tabs", $.ui.tabs, {
  12180. options: {
  12181. add: null,
  12182. remove: null,
  12183. tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
  12184. },
  12185. add: function( url, label, index ) {
  12186. if ( index === undefined ) {
  12187. index = this.anchors.length;
  12188. }
  12189. var doInsertAfter, panel,
  12190. options = this.options,
  12191. li = $( options.tabTemplate
  12192. .replace( /#\{href\}/g, url )
  12193. .replace( /#\{label\}/g, label ) ),
  12194. id = !url.indexOf( "#" ) ?
  12195. url.replace( "#", "" ) :
  12196. this._tabId( li );
  12197. li.addClass( "ui-state-default ui-corner-top" ).data( "ui-tabs-destroy", true );
  12198. li.attr( "aria-controls", id );
  12199. doInsertAfter = index >= this.tabs.length;
  12200. // try to find an existing element before creating a new one
  12201. panel = this.element.find( "#" + id );
  12202. if ( !panel.length ) {
  12203. panel = this._createPanel( id );
  12204. if ( doInsertAfter ) {
  12205. if ( index > 0 ) {
  12206. panel.insertAfter( this.panels.eq( -1 ) );
  12207. } else {
  12208. panel.appendTo( this.element );
  12209. }
  12210. } else {
  12211. panel.insertBefore( this.panels[ index ] );
  12212. }
  12213. }
  12214. panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide();
  12215. if ( doInsertAfter ) {
  12216. li.appendTo( this.tablist );
  12217. } else {
  12218. li.insertBefore( this.tabs[ index ] );
  12219. }
  12220. options.disabled = $.map( options.disabled, function( n ) {
  12221. return n >= index ? ++n : n;
  12222. });
  12223. this.refresh();
  12224. if ( this.tabs.length === 1 && options.active === false ) {
  12225. this.option( "active", 0 );
  12226. }
  12227. this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  12228. return this;
  12229. },
  12230. remove: function( index ) {
  12231. index = this._getIndex( index );
  12232. var options = this.options,
  12233. tab = this.tabs.eq( index ).remove(),
  12234. panel = this._getPanelForTab( tab ).remove();
  12235. // If selected tab was removed focus tab to the right or
  12236. // in case the last tab was removed the tab to the left.
  12237. // We check for more than 2 tabs, because if there are only 2,
  12238. // then when we remove this tab, there will only be one tab left
  12239. // so we don't need to detect which tab to activate.
  12240. if ( tab.hasClass( "ui-tabs-active" ) && this.anchors.length > 2 ) {
  12241. this._activate( index + ( index + 1 < this.anchors.length ? 1 : -1 ) );
  12242. }
  12243. options.disabled = $.map(
  12244. $.grep( options.disabled, function( n ) {
  12245. return n !== index;
  12246. }),
  12247. function( n ) {
  12248. return n >= index ? --n : n;
  12249. });
  12250. this.refresh();
  12251. this._trigger( "remove", null, this._ui( tab.find( "a" )[ 0 ], panel[ 0 ] ) );
  12252. return this;
  12253. }
  12254. });
  12255. // length method
  12256. $.widget( "ui.tabs", $.ui.tabs, {
  12257. length: function() {
  12258. return this.anchors.length;
  12259. }
  12260. });
  12261. // panel ids (idPrefix option + title attribute)
  12262. $.widget( "ui.tabs", $.ui.tabs, {
  12263. options: {
  12264. idPrefix: "ui-tabs-"
  12265. },
  12266. _tabId: function( tab ) {
  12267. var a = tab.is( "li" ) ? tab.find( "a[href]" ) : tab;
  12268. a = a[0];
  12269. return $( a ).closest( "li" ).attr( "aria-controls" ) ||
  12270. a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF\-]/g, "" ) ||
  12271. this.options.idPrefix + getNextTabId();
  12272. }
  12273. });
  12274. // _createPanel method
  12275. $.widget( "ui.tabs", $.ui.tabs, {
  12276. options: {
  12277. panelTemplate: "<div></div>"
  12278. },
  12279. _createPanel: function( id ) {
  12280. return $( this.options.panelTemplate )
  12281. .attr( "id", id )
  12282. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  12283. .data( "ui-tabs-destroy", true );
  12284. }
  12285. });
  12286. // selected option
  12287. $.widget( "ui.tabs", $.ui.tabs, {
  12288. _create: function() {
  12289. var options = this.options;
  12290. if ( options.active === null && options.selected !== undefined ) {
  12291. options.active = options.selected === -1 ? false : options.selected;
  12292. }
  12293. this._super();
  12294. options.selected = options.active;
  12295. if ( options.selected === false ) {
  12296. options.selected = -1;
  12297. }
  12298. },
  12299. _setOption: function( key, value ) {
  12300. if ( key !== "selected" ) {
  12301. return this._super( key, value );
  12302. }
  12303. var options = this.options;
  12304. this._super( "active", value === -1 ? false : value );
  12305. options.selected = options.active;
  12306. if ( options.selected === false ) {
  12307. options.selected = -1;
  12308. }
  12309. },
  12310. _eventHandler: function() {
  12311. this._superApply( arguments );
  12312. this.options.selected = this.options.active;
  12313. if ( this.options.selected === false ) {
  12314. this.options.selected = -1;
  12315. }
  12316. }
  12317. });
  12318. // show and select event
  12319. $.widget( "ui.tabs", $.ui.tabs, {
  12320. options: {
  12321. show: null,
  12322. select: null
  12323. },
  12324. _create: function() {
  12325. this._super();
  12326. if ( this.options.active !== false ) {
  12327. this._trigger( "show", null, this._ui(
  12328. this.active.find( ".ui-tabs-anchor" )[ 0 ],
  12329. this._getPanelForTab( this.active )[ 0 ] ) );
  12330. }
  12331. },
  12332. _trigger: function( type, event, data ) {
  12333. var tab, panel,
  12334. ret = this._superApply( arguments );
  12335. if ( !ret ) {
  12336. return false;
  12337. }
  12338. if ( type === "beforeActivate" ) {
  12339. tab = data.newTab.length ? data.newTab : data.oldTab;
  12340. panel = data.newPanel.length ? data.newPanel : data.oldPanel;
  12341. ret = this._super( "select", event, {
  12342. tab: tab.find( ".ui-tabs-anchor" )[ 0],
  12343. panel: panel[ 0 ],
  12344. index: tab.closest( "li" ).index()
  12345. });
  12346. } else if ( type === "activate" && data.newTab.length ) {
  12347. ret = this._super( "show", event, {
  12348. tab: data.newTab.find( ".ui-tabs-anchor" )[ 0 ],
  12349. panel: data.newPanel[ 0 ],
  12350. index: data.newTab.closest( "li" ).index()
  12351. });
  12352. }
  12353. return ret;
  12354. }
  12355. });
  12356. // select method
  12357. $.widget( "ui.tabs", $.ui.tabs, {
  12358. select: function( index ) {
  12359. index = this._getIndex( index );
  12360. if ( index === -1 ) {
  12361. if ( this.options.collapsible && this.options.selected !== -1 ) {
  12362. index = this.options.selected;
  12363. } else {
  12364. return;
  12365. }
  12366. }
  12367. this.anchors.eq( index ).trigger( this.options.event + this.eventNamespace );
  12368. }
  12369. });
  12370. // cookie option
  12371. (function() {
  12372. var listId = 0;
  12373. $.widget( "ui.tabs", $.ui.tabs, {
  12374. options: {
  12375. cookie: null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
  12376. },
  12377. _create: function() {
  12378. var options = this.options,
  12379. active;
  12380. if ( options.active == null && options.cookie ) {
  12381. active = parseInt( this._cookie(), 10 );
  12382. if ( active === -1 ) {
  12383. active = false;
  12384. }
  12385. options.active = active;
  12386. }
  12387. this._super();
  12388. },
  12389. _cookie: function( active ) {
  12390. var cookie = [ this.cookie ||
  12391. ( this.cookie = this.options.cookie.name || "ui-tabs-" + (++listId) ) ];
  12392. if ( arguments.length ) {
  12393. cookie.push( active === false ? -1 : active );
  12394. cookie.push( this.options.cookie );
  12395. }
  12396. return $.cookie.apply( null, cookie );
  12397. },
  12398. _refresh: function() {
  12399. this._super();
  12400. if ( this.options.cookie ) {
  12401. this._cookie( this.options.active, this.options.cookie );
  12402. }
  12403. },
  12404. _eventHandler: function() {
  12405. this._superApply( arguments );
  12406. if ( this.options.cookie ) {
  12407. this._cookie( this.options.active, this.options.cookie );
  12408. }
  12409. },
  12410. _destroy: function() {
  12411. this._super();
  12412. if ( this.options.cookie ) {
  12413. this._cookie( null, this.options.cookie );
  12414. }
  12415. }
  12416. });
  12417. })();
  12418. // load event
  12419. $.widget( "ui.tabs", $.ui.tabs, {
  12420. _trigger: function( type, event, data ) {
  12421. var _data = $.extend( {}, data );
  12422. if ( type === "load" ) {
  12423. _data.panel = _data.panel[ 0 ];
  12424. _data.tab = _data.tab.find( ".ui-tabs-anchor" )[ 0 ];
  12425. }
  12426. return this._super( type, event, _data );
  12427. }
  12428. });
  12429. // fx option
  12430. // The new animation options (show, hide) conflict with the old show callback.
  12431. // The old fx option wins over show/hide anyway (always favor back-compat).
  12432. // If a user wants to use the new animation API, they must give up the old API.
  12433. $.widget( "ui.tabs", $.ui.tabs, {
  12434. options: {
  12435. fx: null // e.g. { height: "toggle", opacity: "toggle", duration: 200 }
  12436. },
  12437. _getFx: function() {
  12438. var hide, show,
  12439. fx = this.options.fx;
  12440. if ( fx ) {
  12441. if ( $.isArray( fx ) ) {
  12442. hide = fx[ 0 ];
  12443. show = fx[ 1 ];
  12444. } else {
  12445. hide = show = fx;
  12446. }
  12447. }
  12448. return fx ? { show: show, hide: hide } : null;
  12449. },
  12450. _toggle: function( event, eventData ) {
  12451. var that = this,
  12452. toShow = eventData.newPanel,
  12453. toHide = eventData.oldPanel,
  12454. fx = this._getFx();
  12455. if ( !fx ) {
  12456. return this._super( event, eventData );
  12457. }
  12458. that.running = true;
  12459. function complete() {
  12460. that.running = false;
  12461. that._trigger( "activate", event, eventData );
  12462. }
  12463. function show() {
  12464. eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
  12465. if ( toShow.length && fx.show ) {
  12466. toShow
  12467. .animate( fx.show, fx.show.duration, function() {
  12468. complete();
  12469. });
  12470. } else {
  12471. toShow.show();
  12472. complete();
  12473. }
  12474. }
  12475. // start out by hiding, then showing, then completing
  12476. if ( toHide.length && fx.hide ) {
  12477. toHide.animate( fx.hide, fx.hide.duration, function() {
  12478. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  12479. show();
  12480. });
  12481. } else {
  12482. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  12483. toHide.hide();
  12484. show();
  12485. }
  12486. }
  12487. });
  12488. }
  12489. })( jQuery );
  12490. (function( $ ) {
  12491. var increments = 0;
  12492. function addDescribedBy( elem, id ) {
  12493. var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ );
  12494. describedby.push( id );
  12495. elem
  12496. .data( "ui-tooltip-id", id )
  12497. .attr( "aria-describedby", $.trim( describedby.join( " " ) ) );
  12498. }
  12499. function removeDescribedBy( elem ) {
  12500. var id = elem.data( "ui-tooltip-id" ),
  12501. describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ),
  12502. index = $.inArray( id, describedby );
  12503. if ( index !== -1 ) {
  12504. describedby.splice( index, 1 );
  12505. }
  12506. elem.removeData( "ui-tooltip-id" );
  12507. describedby = $.trim( describedby.join( " " ) );
  12508. if ( describedby ) {
  12509. elem.attr( "aria-describedby", describedby );
  12510. } else {
  12511. elem.removeAttr( "aria-describedby" );
  12512. }
  12513. }
  12514. $.widget( "ui.tooltip", {
  12515. version: "1.9.2",
  12516. options: {
  12517. content: function() {
  12518. return $( this ).attr( "title" );
  12519. },
  12520. hide: true,
  12521. // Disabled elements have inconsistent behavior across browsers (#8661)
  12522. items: "[title]:not([disabled])",
  12523. position: {
  12524. my: "left top+15",
  12525. at: "left bottom",
  12526. collision: "flipfit flip"
  12527. },
  12528. show: true,
  12529. tooltipClass: null,
  12530. track: false,
  12531. // callbacks
  12532. close: null,
  12533. open: null
  12534. },
  12535. _create: function() {
  12536. this._on({
  12537. mouseover: "open",
  12538. focusin: "open"
  12539. });
  12540. // IDs of generated tooltips, needed for destroy
  12541. this.tooltips = {};
  12542. // IDs of parent tooltips where we removed the title attribute
  12543. this.parents = {};
  12544. if ( this.options.disabled ) {
  12545. this._disable();
  12546. }
  12547. },
  12548. _setOption: function( key, value ) {
  12549. var that = this;
  12550. if ( key === "disabled" ) {
  12551. this[ value ? "_disable" : "_enable" ]();
  12552. this.options[ key ] = value;
  12553. // disable element style changes
  12554. return;
  12555. }
  12556. this._super( key, value );
  12557. if ( key === "content" ) {
  12558. $.each( this.tooltips, function( id, element ) {
  12559. that._updateContent( element );
  12560. });
  12561. }
  12562. },
  12563. _disable: function() {
  12564. var that = this;
  12565. // close open tooltips
  12566. $.each( this.tooltips, function( id, element ) {
  12567. var event = $.Event( "blur" );
  12568. event.target = event.currentTarget = element[0];
  12569. that.close( event, true );
  12570. });
  12571. // remove title attributes to prevent native tooltips
  12572. this.element.find( this.options.items ).andSelf().each(function() {
  12573. var element = $( this );
  12574. if ( element.is( "[title]" ) ) {
  12575. element
  12576. .data( "ui-tooltip-title", element.attr( "title" ) )
  12577. .attr( "title", "" );
  12578. }
  12579. });
  12580. },
  12581. _enable: function() {
  12582. // restore title attributes
  12583. this.element.find( this.options.items ).andSelf().each(function() {
  12584. var element = $( this );
  12585. if ( element.data( "ui-tooltip-title" ) ) {
  12586. element.attr( "title", element.data( "ui-tooltip-title" ) );
  12587. }
  12588. });
  12589. },
  12590. open: function( event ) {
  12591. var that = this,
  12592. target = $( event ? event.target : this.element )
  12593. // we need closest here due to mouseover bubbling,
  12594. // but always pointing at the same event target
  12595. .closest( this.options.items );
  12596. // No element to show a tooltip for or the tooltip is already open
  12597. if ( !target.length || target.data( "ui-tooltip-id" ) ) {
  12598. return;
  12599. }
  12600. if ( target.attr( "title" ) ) {
  12601. target.data( "ui-tooltip-title", target.attr( "title" ) );
  12602. }
  12603. target.data( "ui-tooltip-open", true );
  12604. // kill parent tooltips, custom or native, for hover
  12605. if ( event && event.type === "mouseover" ) {
  12606. target.parents().each(function() {
  12607. var parent = $( this ),
  12608. blurEvent;
  12609. if ( parent.data( "ui-tooltip-open" ) ) {
  12610. blurEvent = $.Event( "blur" );
  12611. blurEvent.target = blurEvent.currentTarget = this;
  12612. that.close( blurEvent, true );
  12613. }
  12614. if ( parent.attr( "title" ) ) {
  12615. parent.uniqueId();
  12616. that.parents[ this.id ] = {
  12617. element: this,
  12618. title: parent.attr( "title" )
  12619. };
  12620. parent.attr( "title", "" );
  12621. }
  12622. });
  12623. }
  12624. this._updateContent( target, event );
  12625. },
  12626. _updateContent: function( target, event ) {
  12627. var content,
  12628. contentOption = this.options.content,
  12629. that = this,
  12630. eventType = event ? event.type : null;
  12631. if ( typeof contentOption === "string" ) {
  12632. return this._open( event, target, contentOption );
  12633. }
  12634. content = contentOption.call( target[0], function( response ) {
  12635. // ignore async response if tooltip was closed already
  12636. if ( !target.data( "ui-tooltip-open" ) ) {
  12637. return;
  12638. }
  12639. // IE may instantly serve a cached response for ajax requests
  12640. // delay this call to _open so the other call to _open runs first
  12641. that._delay(function() {
  12642. // jQuery creates a special event for focusin when it doesn't
  12643. // exist natively. To improve performance, the native event
  12644. // object is reused and the type is changed. Therefore, we can't
  12645. // rely on the type being correct after the event finished
  12646. // bubbling, so we set it back to the previous value. (#8740)
  12647. if ( event ) {
  12648. event.type = eventType;
  12649. }
  12650. this._open( event, target, response );
  12651. });
  12652. });
  12653. if ( content ) {
  12654. this._open( event, target, content );
  12655. }
  12656. },
  12657. _open: function( event, target, content ) {
  12658. var tooltip, events, delayedShow,
  12659. positionOption = $.extend( {}, this.options.position );
  12660. if ( !content ) {
  12661. return;
  12662. }
  12663. // Content can be updated multiple times. If the tooltip already
  12664. // exists, then just update the content and bail.
  12665. tooltip = this._find( target );
  12666. if ( tooltip.length ) {
  12667. tooltip.find( ".ui-tooltip-content" ).html( content );
  12668. return;
  12669. }
  12670. // if we have a title, clear it to prevent the native tooltip
  12671. // we have to check first to avoid defining a title if none exists
  12672. // (we don't want to cause an element to start matching [title])
  12673. //
  12674. // We use removeAttr only for key events, to allow IE to export the correct
  12675. // accessible attributes. For mouse events, set to empty string to avoid
  12676. // native tooltip showing up (happens only when removing inside mouseover).
  12677. if ( target.is( "[title]" ) ) {
  12678. if ( event && event.type === "mouseover" ) {
  12679. target.attr( "title", "" );
  12680. } else {
  12681. target.removeAttr( "title" );
  12682. }
  12683. }
  12684. tooltip = this._tooltip( target );
  12685. addDescribedBy( target, tooltip.attr( "id" ) );
  12686. tooltip.find( ".ui-tooltip-content" ).html( content );
  12687. function position( event ) {
  12688. positionOption.of = event;
  12689. if ( tooltip.is( ":hidden" ) ) {
  12690. return;
  12691. }
  12692. tooltip.position( positionOption );
  12693. }
  12694. if ( this.options.track && event && /^mouse/.test( event.type ) ) {
  12695. this._on( this.document, {
  12696. mousemove: position
  12697. });
  12698. // trigger once to override element-relative positioning
  12699. position( event );
  12700. } else {
  12701. tooltip.position( $.extend({
  12702. of: target
  12703. }, this.options.position ) );
  12704. }
  12705. tooltip.hide();
  12706. this._show( tooltip, this.options.show );
  12707. // Handle tracking tooltips that are shown with a delay (#8644). As soon
  12708. // as the tooltip is visible, position the tooltip using the most recent
  12709. // event.
  12710. if ( this.options.show && this.options.show.delay ) {
  12711. delayedShow = setInterval(function() {
  12712. if ( tooltip.is( ":visible" ) ) {
  12713. position( positionOption.of );
  12714. clearInterval( delayedShow );
  12715. }
  12716. }, $.fx.interval );
  12717. }
  12718. this._trigger( "open", event, { tooltip: tooltip } );
  12719. events = {
  12720. keyup: function( event ) {
  12721. if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
  12722. var fakeEvent = $.Event(event);
  12723. fakeEvent.currentTarget = target[0];
  12724. this.close( fakeEvent, true );
  12725. }
  12726. },
  12727. remove: function() {
  12728. this._removeTooltip( tooltip );
  12729. }
  12730. };
  12731. if ( !event || event.type === "mouseover" ) {
  12732. events.mouseleave = "close";
  12733. }
  12734. if ( !event || event.type === "focusin" ) {
  12735. events.focusout = "close";
  12736. }
  12737. this._on( true, target, events );
  12738. },
  12739. close: function( event ) {
  12740. var that = this,
  12741. target = $( event ? event.currentTarget : this.element ),
  12742. tooltip = this._find( target );
  12743. // disabling closes the tooltip, so we need to track when we're closing
  12744. // to avoid an infinite loop in case the tooltip becomes disabled on close
  12745. if ( this.closing ) {
  12746. return;
  12747. }
  12748. // only set title if we had one before (see comment in _open())
  12749. if ( target.data( "ui-tooltip-title" ) ) {
  12750. target.attr( "title", target.data( "ui-tooltip-title" ) );
  12751. }
  12752. removeDescribedBy( target );
  12753. tooltip.stop( true );
  12754. this._hide( tooltip, this.options.hide, function() {
  12755. that._removeTooltip( $( this ) );
  12756. });
  12757. target.removeData( "ui-tooltip-open" );
  12758. this._off( target, "mouseleave focusout keyup" );
  12759. // Remove 'remove' binding only on delegated targets
  12760. if ( target[0] !== this.element[0] ) {
  12761. this._off( target, "remove" );
  12762. }
  12763. this._off( this.document, "mousemove" );
  12764. if ( event && event.type === "mouseleave" ) {
  12765. $.each( this.parents, function( id, parent ) {
  12766. $( parent.element ).attr( "title", parent.title );
  12767. delete that.parents[ id ];
  12768. });
  12769. }
  12770. this.closing = true;
  12771. this._trigger( "close", event, { tooltip: tooltip } );
  12772. this.closing = false;
  12773. },
  12774. _tooltip: function( element ) {
  12775. var id = "ui-tooltip-" + increments++,
  12776. tooltip = $( "<div>" )
  12777. .attr({
  12778. id: id,
  12779. role: "tooltip"
  12780. })
  12781. .addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content " +
  12782. ( this.options.tooltipClass || "" ) );
  12783. $( "<div>" )
  12784. .addClass( "ui-tooltip-content" )
  12785. .appendTo( tooltip );
  12786. tooltip.appendTo( this.document[0].body );
  12787. if ( $.fn.bgiframe ) {
  12788. tooltip.bgiframe();
  12789. }
  12790. this.tooltips[ id ] = element;
  12791. return tooltip;
  12792. },
  12793. _find: function( target ) {
  12794. var id = target.data( "ui-tooltip-id" );
  12795. return id ? $( "#" + id ) : $();
  12796. },
  12797. _removeTooltip: function( tooltip ) {
  12798. tooltip.remove();
  12799. delete this.tooltips[ tooltip.attr( "id" ) ];
  12800. },
  12801. _destroy: function() {
  12802. var that = this;
  12803. // close open tooltips
  12804. $.each( this.tooltips, function( id, element ) {
  12805. // Delegate to close method to handle common cleanup
  12806. var event = $.Event( "blur" );
  12807. event.target = event.currentTarget = element[0];
  12808. that.close( event, true );
  12809. // Remove immediately; destroying an open tooltip doesn't use the
  12810. // hide animation
  12811. $( "#" + id ).remove();
  12812. // Restore the title
  12813. if ( element.data( "ui-tooltip-title" ) ) {
  12814. element.attr( "title", element.data( "ui-tooltip-title" ) );
  12815. element.removeData( "ui-tooltip-title" );
  12816. }
  12817. });
  12818. }
  12819. });
  12820. }( jQuery ) );