CNAS取数仪器端升级
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

14743 lignes
435KB

  1. /*! jQuery UI - v1.9.0 - 2012-10-05
  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.0",
  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 (($.browser.msie && (/(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. // support: jQuery <1.8
  113. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  114. $.each( [ "Width", "Height" ], function( i, name ) {
  115. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  116. type = name.toLowerCase(),
  117. orig = {
  118. innerWidth: $.fn.innerWidth,
  119. innerHeight: $.fn.innerHeight,
  120. outerWidth: $.fn.outerWidth,
  121. outerHeight: $.fn.outerHeight
  122. };
  123. function reduce( elem, size, border, margin ) {
  124. $.each( side, function() {
  125. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  126. if ( border ) {
  127. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  128. }
  129. if ( margin ) {
  130. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  131. }
  132. });
  133. return size;
  134. }
  135. $.fn[ "inner" + name ] = function( size ) {
  136. if ( size === undefined ) {
  137. return orig[ "inner" + name ].call( this );
  138. }
  139. return this.each(function() {
  140. $( this ).css( type, reduce( this, size ) + "px" );
  141. });
  142. };
  143. $.fn[ "outer" + name] = function( size, margin ) {
  144. if ( typeof size !== "number" ) {
  145. return orig[ "outer" + name ].call( this, size );
  146. }
  147. return this.each(function() {
  148. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  149. });
  150. };
  151. });
  152. }
  153. // selectors
  154. function focusable( element, isTabIndexNotNaN ) {
  155. var map, mapName, img,
  156. nodeName = element.nodeName.toLowerCase();
  157. if ( "area" === nodeName ) {
  158. map = element.parentNode;
  159. mapName = map.name;
  160. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  161. return false;
  162. }
  163. img = $( "img[usemap=#" + mapName + "]" )[0];
  164. return !!img && visible( img );
  165. }
  166. return ( /input|select|textarea|button|object/.test( nodeName ) ?
  167. !element.disabled :
  168. "a" === nodeName ?
  169. element.href || isTabIndexNotNaN :
  170. isTabIndexNotNaN) &&
  171. // the element and all of its ancestors must be visible
  172. visible( element );
  173. }
  174. function visible( element ) {
  175. return !$( element ).parents().andSelf().filter(function() {
  176. return $.css( this, "visibility" ) === "hidden" ||
  177. $.expr.filters.hidden( this );
  178. }).length;
  179. }
  180. $.extend( $.expr[ ":" ], {
  181. data: $.expr.createPseudo ?
  182. $.expr.createPseudo(function( dataName ) {
  183. return function( elem ) {
  184. return !!$.data( elem, dataName );
  185. };
  186. }) :
  187. // support: jQuery <1.8
  188. function( elem, i, match ) {
  189. return !!$.data( elem, match[ 3 ] );
  190. },
  191. focusable: function( element ) {
  192. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  193. },
  194. tabbable: function( element ) {
  195. var tabIndex = $.attr( element, "tabindex" ),
  196. isTabIndexNaN = isNaN( tabIndex );
  197. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  198. }
  199. });
  200. // support
  201. $(function() {
  202. var body = document.body,
  203. div = body.appendChild( div = document.createElement( "div" ) );
  204. // access offsetHeight before setting the style to prevent a layout bug
  205. // in IE 9 which causes the element to continue to take up space even
  206. // after it is removed from the DOM (#8026)
  207. div.offsetHeight;
  208. $.extend( div.style, {
  209. minHeight: "100px",
  210. height: "auto",
  211. padding: 0,
  212. borderWidth: 0
  213. });
  214. $.support.minHeight = div.offsetHeight === 100;
  215. $.support.selectstart = "onselectstart" in div;
  216. // set display to none to avoid a layout bug in IE
  217. // http://dev.jquery.com/ticket/4014
  218. body.removeChild( div ).style.display = "none";
  219. });
  220. // deprecated
  221. $.fn.extend({
  222. disableSelection: function() {
  223. return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
  224. ".ui-disableSelection", function( event ) {
  225. event.preventDefault();
  226. });
  227. },
  228. enableSelection: function() {
  229. return this.unbind( ".ui-disableSelection" );
  230. }
  231. });
  232. $.extend( $.ui, {
  233. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  234. plugin: {
  235. add: function( module, option, set ) {
  236. var i,
  237. proto = $.ui[ module ].prototype;
  238. for ( i in set ) {
  239. proto.plugins[ i ] = proto.plugins[ i ] || [];
  240. proto.plugins[ i ].push( [ option, set[ i ] ] );
  241. }
  242. },
  243. call: function( instance, name, args ) {
  244. var i,
  245. set = instance.plugins[ name ];
  246. if ( !set || !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) {
  247. return;
  248. }
  249. for ( i = 0; i < set.length; i++ ) {
  250. if ( instance.options[ set[ i ][ 0 ] ] ) {
  251. set[ i ][ 1 ].apply( instance.element, args );
  252. }
  253. }
  254. }
  255. },
  256. contains: $.contains,
  257. // only used by resizable
  258. hasScroll: function( el, a ) {
  259. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  260. if ( $( el ).css( "overflow" ) === "hidden") {
  261. return false;
  262. }
  263. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  264. has = false;
  265. if ( el[ scroll ] > 0 ) {
  266. return true;
  267. }
  268. // TODO: determine which cases actually cause this to happen
  269. // if the element doesn't have the scroll set, see if it's possible to
  270. // set the scroll
  271. el[ scroll ] = 1;
  272. has = ( el[ scroll ] > 0 );
  273. el[ scroll ] = 0;
  274. return has;
  275. },
  276. // these are odd functions, fix the API or move into individual plugins
  277. isOverAxis: function( x, reference, size ) {
  278. //Determines when x coordinate is over "b" element axis
  279. return ( x > reference ) && ( x < ( reference + size ) );
  280. },
  281. isOver: function( y, x, top, left, height, width ) {
  282. //Determines when x, y coordinates is over "b" element
  283. return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );
  284. }
  285. });
  286. })( jQuery );
  287. (function( $, undefined ) {
  288. var uuid = 0,
  289. slice = Array.prototype.slice,
  290. _cleanData = $.cleanData;
  291. $.cleanData = function( elems ) {
  292. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  293. try {
  294. $( elem ).triggerHandler( "remove" );
  295. // http://bugs.jquery.com/ticket/8235
  296. } catch( e ) {}
  297. }
  298. _cleanData( elems );
  299. };
  300. $.widget = function( name, base, prototype ) {
  301. var fullName, existingConstructor, constructor, basePrototype,
  302. namespace = name.split( "." )[ 0 ];
  303. name = name.split( "." )[ 1 ];
  304. fullName = namespace + "-" + name;
  305. if ( !prototype ) {
  306. prototype = base;
  307. base = $.Widget;
  308. }
  309. // create selector for plugin
  310. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  311. return !!$.data( elem, fullName );
  312. };
  313. $[ namespace ] = $[ namespace ] || {};
  314. existingConstructor = $[ namespace ][ name ];
  315. constructor = $[ namespace ][ name ] = function( options, element ) {
  316. // allow instantiation without "new" keyword
  317. if ( !this._createWidget ) {
  318. return new constructor( options, element );
  319. }
  320. // allow instantiation without initializing for simple inheritance
  321. // must use "new" keyword (the code above always passes args)
  322. if ( arguments.length ) {
  323. this._createWidget( options, element );
  324. }
  325. };
  326. // extend with the existing constructor to carry over any static properties
  327. $.extend( constructor, existingConstructor, {
  328. version: prototype.version,
  329. // copy the object used to create the prototype in case we need to
  330. // redefine the widget later
  331. _proto: $.extend( {}, prototype ),
  332. // track widgets that inherit from this widget in case this widget is
  333. // redefined after a widget inherits from it
  334. _childConstructors: []
  335. });
  336. basePrototype = new base();
  337. // we need to make the options hash a property directly on the new instance
  338. // otherwise we'll modify the options hash on the prototype that we're
  339. // inheriting from
  340. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  341. $.each( prototype, function( prop, value ) {
  342. if ( $.isFunction( value ) ) {
  343. prototype[ prop ] = (function() {
  344. var _super = function() {
  345. return base.prototype[ prop ].apply( this, arguments );
  346. },
  347. _superApply = function( args ) {
  348. return base.prototype[ prop ].apply( this, args );
  349. };
  350. return function() {
  351. var __super = this._super,
  352. __superApply = this._superApply,
  353. returnValue;
  354. this._super = _super;
  355. this._superApply = _superApply;
  356. returnValue = value.apply( this, arguments );
  357. this._super = __super;
  358. this._superApply = __superApply;
  359. return returnValue;
  360. };
  361. })();
  362. }
  363. });
  364. constructor.prototype = $.widget.extend( basePrototype, {
  365. // TODO: remove support for widgetEventPrefix
  366. // always use the name + a colon as the prefix, e.g., draggable:start
  367. // don't prefix for widgets that aren't DOM-based
  368. widgetEventPrefix: name
  369. }, prototype, {
  370. constructor: constructor,
  371. namespace: namespace,
  372. widgetName: name,
  373. // TODO remove widgetBaseClass, see #8155
  374. widgetBaseClass: fullName,
  375. widgetFullName: fullName
  376. });
  377. // If this widget is being redefined then we need to find all widgets that
  378. // are inheriting from it and redefine all of them so that they inherit from
  379. // the new version of this widget. We're essentially trying to replace one
  380. // level in the prototype chain.
  381. if ( existingConstructor ) {
  382. $.each( existingConstructor._childConstructors, function( i, child ) {
  383. var childPrototype = child.prototype;
  384. // redefine the child widget using the same prototype that was
  385. // originally used, but inherit from the new version of the base
  386. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
  387. });
  388. // remove the list of existing child constructors from the old constructor
  389. // so the old child constructors can be garbage collected
  390. delete existingConstructor._childConstructors;
  391. } else {
  392. base._childConstructors.push( constructor );
  393. }
  394. $.widget.bridge( name, constructor );
  395. };
  396. $.widget.extend = function( target ) {
  397. var input = slice.call( arguments, 1 ),
  398. inputIndex = 0,
  399. inputLength = input.length,
  400. key,
  401. value;
  402. for ( ; inputIndex < inputLength; inputIndex++ ) {
  403. for ( key in input[ inputIndex ] ) {
  404. value = input[ inputIndex ][ key ];
  405. if (input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  406. target[ key ] = $.isPlainObject( value ) ? $.widget.extend( {}, target[ key ], value ) : value;
  407. }
  408. }
  409. }
  410. return target;
  411. };
  412. $.widget.bridge = function( name, object ) {
  413. var fullName = object.prototype.widgetFullName;
  414. $.fn[ name ] = function( options ) {
  415. var isMethodCall = typeof options === "string",
  416. args = slice.call( arguments, 1 ),
  417. returnValue = this;
  418. // allow multiple hashes to be passed on init
  419. options = !isMethodCall && args.length ?
  420. $.widget.extend.apply( null, [ options ].concat(args) ) :
  421. options;
  422. if ( isMethodCall ) {
  423. this.each(function() {
  424. var methodValue,
  425. instance = $.data( this, fullName );
  426. if ( !instance ) {
  427. return $.error( "cannot call methods on " + name + " prior to initialization; " +
  428. "attempted to call method '" + options + "'" );
  429. }
  430. if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
  431. return $.error( "no such method '" + options + "' for " + name + " widget instance" );
  432. }
  433. methodValue = instance[ options ].apply( instance, args );
  434. if ( methodValue !== instance && methodValue !== undefined ) {
  435. returnValue = methodValue && methodValue.jquery ?
  436. returnValue.pushStack( methodValue.get() ) :
  437. methodValue;
  438. return false;
  439. }
  440. });
  441. } else {
  442. this.each(function() {
  443. var instance = $.data( this, fullName );
  444. if ( instance ) {
  445. instance.option( options || {} )._init();
  446. } else {
  447. new object( options, this );
  448. }
  449. });
  450. }
  451. return returnValue;
  452. };
  453. };
  454. $.Widget = function( options, element ) {};
  455. $.Widget._childConstructors = [];
  456. $.Widget.prototype = {
  457. widgetName: "widget",
  458. widgetEventPrefix: "",
  459. defaultElement: "<div>",
  460. options: {
  461. disabled: false,
  462. // callbacks
  463. create: null
  464. },
  465. _createWidget: function( options, element ) {
  466. element = $( element || this.defaultElement || this )[ 0 ];
  467. this.element = $( element );
  468. this.uuid = uuid++;
  469. this.eventNamespace = "." + this.widgetName + this.uuid;
  470. this.options = $.widget.extend( {},
  471. this.options,
  472. this._getCreateOptions(),
  473. options );
  474. this.bindings = $();
  475. this.hoverable = $();
  476. this.focusable = $();
  477. if ( element !== this ) {
  478. // 1.9 BC for #7810
  479. // TODO remove dual storage
  480. $.data( element, this.widgetName, this );
  481. $.data( element, this.widgetFullName, this );
  482. this._on({ remove: "destroy" });
  483. this.document = $( element.style ?
  484. // element within the document
  485. element.ownerDocument :
  486. // element is window or document
  487. element.document || element );
  488. this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
  489. }
  490. this._create();
  491. this._trigger( "create", null, this._getCreateEventData() );
  492. this._init();
  493. },
  494. _getCreateOptions: $.noop,
  495. _getCreateEventData: $.noop,
  496. _create: $.noop,
  497. _init: $.noop,
  498. destroy: function() {
  499. this._destroy();
  500. // we can probably remove the unbind calls in 2.0
  501. // all event bindings should go through this._on()
  502. this.element
  503. .unbind( this.eventNamespace )
  504. // 1.9 BC for #7810
  505. // TODO remove dual storage
  506. .removeData( this.widgetName )
  507. .removeData( this.widgetFullName )
  508. // support: jquery <1.6.3
  509. // http://bugs.jquery.com/ticket/9413
  510. .removeData( $.camelCase( this.widgetFullName ) );
  511. this.widget()
  512. .unbind( this.eventNamespace )
  513. .removeAttr( "aria-disabled" )
  514. .removeClass(
  515. this.widgetFullName + "-disabled " +
  516. "ui-state-disabled" );
  517. // clean up events and states
  518. this.bindings.unbind( this.eventNamespace );
  519. this.hoverable.removeClass( "ui-state-hover" );
  520. this.focusable.removeClass( "ui-state-focus" );
  521. },
  522. _destroy: $.noop,
  523. widget: function() {
  524. return this.element;
  525. },
  526. option: function( key, value ) {
  527. var options = key,
  528. parts,
  529. curOption,
  530. i;
  531. if ( arguments.length === 0 ) {
  532. // don't return a reference to the internal hash
  533. return $.widget.extend( {}, this.options );
  534. }
  535. if ( typeof key === "string" ) {
  536. // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  537. options = {};
  538. parts = key.split( "." );
  539. key = parts.shift();
  540. if ( parts.length ) {
  541. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  542. for ( i = 0; i < parts.length - 1; i++ ) {
  543. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  544. curOption = curOption[ parts[ i ] ];
  545. }
  546. key = parts.pop();
  547. if ( value === undefined ) {
  548. return curOption[ key ] === undefined ? null : curOption[ key ];
  549. }
  550. curOption[ key ] = value;
  551. } else {
  552. if ( value === undefined ) {
  553. return this.options[ key ] === undefined ? null : this.options[ key ];
  554. }
  555. options[ key ] = value;
  556. }
  557. }
  558. this._setOptions( options );
  559. return this;
  560. },
  561. _setOptions: function( options ) {
  562. var key;
  563. for ( key in options ) {
  564. this._setOption( key, options[ key ] );
  565. }
  566. return this;
  567. },
  568. _setOption: function( key, value ) {
  569. this.options[ key ] = value;
  570. if ( key === "disabled" ) {
  571. this.widget()
  572. .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
  573. .attr( "aria-disabled", value );
  574. this.hoverable.removeClass( "ui-state-hover" );
  575. this.focusable.removeClass( "ui-state-focus" );
  576. }
  577. return this;
  578. },
  579. enable: function() {
  580. return this._setOption( "disabled", false );
  581. },
  582. disable: function() {
  583. return this._setOption( "disabled", true );
  584. },
  585. _on: function( element, handlers ) {
  586. // no element argument, shuffle and use this.element
  587. if ( !handlers ) {
  588. handlers = element;
  589. element = this.element;
  590. } else {
  591. // accept selectors, DOM elements
  592. element = $( element );
  593. this.bindings = this.bindings.add( element );
  594. }
  595. var instance = this;
  596. $.each( handlers, function( event, handler ) {
  597. function handlerProxy() {
  598. // allow widgets to customize the disabled handling
  599. // - disabled as an array instead of boolean
  600. // - disabled class as method for disabling individual parts
  601. if ( instance.options.disabled === true ||
  602. $( this ).hasClass( "ui-state-disabled" ) ) {
  603. return;
  604. }
  605. return ( typeof handler === "string" ? instance[ handler ] : handler )
  606. .apply( instance, arguments );
  607. }
  608. // copy the guid so direct unbinding works
  609. if ( typeof handler !== "string" ) {
  610. handlerProxy.guid = handler.guid =
  611. handler.guid || handlerProxy.guid || $.guid++;
  612. }
  613. var match = event.match( /^(\w+)\s*(.*)$/ ),
  614. eventName = match[1] + instance.eventNamespace,
  615. selector = match[2];
  616. if ( selector ) {
  617. instance.widget().delegate( selector, eventName, handlerProxy );
  618. } else {
  619. element.bind( eventName, handlerProxy );
  620. }
  621. });
  622. },
  623. _off: function( element, eventName ) {
  624. eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
  625. element.unbind( eventName ).undelegate( eventName );
  626. },
  627. _delay: function( handler, delay ) {
  628. function handlerProxy() {
  629. return ( typeof handler === "string" ? instance[ handler ] : handler )
  630. .apply( instance, arguments );
  631. }
  632. var instance = this;
  633. return setTimeout( handlerProxy, delay || 0 );
  634. },
  635. _hoverable: function( element ) {
  636. this.hoverable = this.hoverable.add( element );
  637. this._on( element, {
  638. mouseenter: function( event ) {
  639. $( event.currentTarget ).addClass( "ui-state-hover" );
  640. },
  641. mouseleave: function( event ) {
  642. $( event.currentTarget ).removeClass( "ui-state-hover" );
  643. }
  644. });
  645. },
  646. _focusable: function( element ) {
  647. this.focusable = this.focusable.add( element );
  648. this._on( element, {
  649. focusin: function( event ) {
  650. $( event.currentTarget ).addClass( "ui-state-focus" );
  651. },
  652. focusout: function( event ) {
  653. $( event.currentTarget ).removeClass( "ui-state-focus" );
  654. }
  655. });
  656. },
  657. _trigger: function( type, event, data ) {
  658. var prop, orig,
  659. callback = this.options[ type ];
  660. data = data || {};
  661. event = $.Event( event );
  662. event.type = ( type === this.widgetEventPrefix ?
  663. type :
  664. this.widgetEventPrefix + type ).toLowerCase();
  665. // the original event may come from any element
  666. // so we need to reset the target on the new event
  667. event.target = this.element[ 0 ];
  668. // copy original event properties over to the new event
  669. orig = event.originalEvent;
  670. if ( orig ) {
  671. for ( prop in orig ) {
  672. if ( !( prop in event ) ) {
  673. event[ prop ] = orig[ prop ];
  674. }
  675. }
  676. }
  677. this.element.trigger( event, data );
  678. return !( $.isFunction( callback ) &&
  679. callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
  680. event.isDefaultPrevented() );
  681. }
  682. };
  683. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  684. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  685. if ( typeof options === "string" ) {
  686. options = { effect: options };
  687. }
  688. var hasOptions,
  689. effectName = !options ?
  690. method :
  691. options === true || typeof options === "number" ?
  692. defaultEffect :
  693. options.effect || defaultEffect;
  694. options = options || {};
  695. if ( typeof options === "number" ) {
  696. options = { duration: options };
  697. }
  698. hasOptions = !$.isEmptyObject( options );
  699. options.complete = callback;
  700. if ( options.delay ) {
  701. element.delay( options.delay );
  702. }
  703. if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
  704. element[ method ]( options );
  705. } else if ( effectName !== method && element[ effectName ] ) {
  706. element[ effectName ]( options.duration, options.easing, callback );
  707. } else {
  708. element.queue(function( next ) {
  709. $( this )[ method ]();
  710. if ( callback ) {
  711. callback.call( element[ 0 ] );
  712. }
  713. next();
  714. });
  715. }
  716. };
  717. });
  718. // DEPRECATED
  719. if ( $.uiBackCompat !== false ) {
  720. $.Widget.prototype._getCreateOptions = function() {
  721. return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
  722. };
  723. }
  724. })( jQuery );
  725. (function( $, undefined ) {
  726. var mouseHandled = false;
  727. $( document ).mouseup( function( e ) {
  728. mouseHandled = false;
  729. });
  730. $.widget("ui.mouse", {
  731. version: "1.9.0",
  732. options: {
  733. cancel: 'input,textarea,button,select,option',
  734. distance: 1,
  735. delay: 0
  736. },
  737. _mouseInit: function() {
  738. var that = this;
  739. this.element
  740. .bind('mousedown.'+this.widgetName, function(event) {
  741. return that._mouseDown(event);
  742. })
  743. .bind('click.'+this.widgetName, function(event) {
  744. if (true === $.data(event.target, that.widgetName + '.preventClickEvent')) {
  745. $.removeData(event.target, that.widgetName + '.preventClickEvent');
  746. event.stopImmediatePropagation();
  747. return false;
  748. }
  749. });
  750. this.started = false;
  751. },
  752. // TODO: make sure destroying one instance of mouse doesn't mess with
  753. // other instances of mouse
  754. _mouseDestroy: function() {
  755. this.element.unbind('.'+this.widgetName);
  756. if ( this._mouseMoveDelegate ) {
  757. $(document)
  758. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  759. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  760. }
  761. },
  762. _mouseDown: function(event) {
  763. // don't let more than one widget handle mouseStart
  764. if( mouseHandled ) { return; }
  765. // we may have missed mouseup (out of window)
  766. (this._mouseStarted && this._mouseUp(event));
  767. this._mouseDownEvent = event;
  768. var that = this,
  769. btnIsLeft = (event.which === 1),
  770. // event.target.nodeName works around a bug in IE 8 with
  771. // disabled inputs (#7620)
  772. elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
  773. if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
  774. return true;
  775. }
  776. this.mouseDelayMet = !this.options.delay;
  777. if (!this.mouseDelayMet) {
  778. this._mouseDelayTimer = setTimeout(function() {
  779. that.mouseDelayMet = true;
  780. }, this.options.delay);
  781. }
  782. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  783. this._mouseStarted = (this._mouseStart(event) !== false);
  784. if (!this._mouseStarted) {
  785. event.preventDefault();
  786. return true;
  787. }
  788. }
  789. // Click event may never have fired (Gecko & Opera)
  790. if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
  791. $.removeData(event.target, this.widgetName + '.preventClickEvent');
  792. }
  793. // these delegates are required to keep context
  794. this._mouseMoveDelegate = function(event) {
  795. return that._mouseMove(event);
  796. };
  797. this._mouseUpDelegate = function(event) {
  798. return that._mouseUp(event);
  799. };
  800. $(document)
  801. .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  802. .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  803. event.preventDefault();
  804. mouseHandled = true;
  805. return true;
  806. },
  807. _mouseMove: function(event) {
  808. // IE mouseup check - mouseup happened when mouse was out of window
  809. if ($.browser.msie && !(document.documentMode >= 9) && !event.button) {
  810. return this._mouseUp(event);
  811. }
  812. if (this._mouseStarted) {
  813. this._mouseDrag(event);
  814. return event.preventDefault();
  815. }
  816. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  817. this._mouseStarted =
  818. (this._mouseStart(this._mouseDownEvent, event) !== false);
  819. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  820. }
  821. return !this._mouseStarted;
  822. },
  823. _mouseUp: function(event) {
  824. $(document)
  825. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  826. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  827. if (this._mouseStarted) {
  828. this._mouseStarted = false;
  829. if (event.target === this._mouseDownEvent.target) {
  830. $.data(event.target, this.widgetName + '.preventClickEvent', true);
  831. }
  832. this._mouseStop(event);
  833. }
  834. return false;
  835. },
  836. _mouseDistanceMet: function(event) {
  837. return (Math.max(
  838. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  839. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  840. ) >= this.options.distance
  841. );
  842. },
  843. _mouseDelayMet: function(event) {
  844. return this.mouseDelayMet;
  845. },
  846. // These are placeholder methods, to be overriden by extending plugin
  847. _mouseStart: function(event) {},
  848. _mouseDrag: function(event) {},
  849. _mouseStop: function(event) {},
  850. _mouseCapture: function(event) { return true; }
  851. });
  852. })(jQuery);
  853. (function( $, undefined ) {
  854. $.widget("ui.draggable", $.ui.mouse, {
  855. version: "1.9.0",
  856. widgetEventPrefix: "drag",
  857. options: {
  858. addClasses: true,
  859. appendTo: "parent",
  860. axis: false,
  861. connectToSortable: false,
  862. containment: false,
  863. cursor: "auto",
  864. cursorAt: false,
  865. grid: false,
  866. handle: false,
  867. helper: "original",
  868. iframeFix: false,
  869. opacity: false,
  870. refreshPositions: false,
  871. revert: false,
  872. revertDuration: 500,
  873. scope: "default",
  874. scroll: true,
  875. scrollSensitivity: 20,
  876. scrollSpeed: 20,
  877. snap: false,
  878. snapMode: "both",
  879. snapTolerance: 20,
  880. stack: false,
  881. zIndex: false
  882. },
  883. _create: function() {
  884. if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
  885. this.element[0].style.position = 'relative';
  886. (this.options.addClasses && this.element.addClass("ui-draggable"));
  887. (this.options.disabled && this.element.addClass("ui-draggable-disabled"));
  888. this._mouseInit();
  889. },
  890. _destroy: function() {
  891. this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" );
  892. this._mouseDestroy();
  893. },
  894. _mouseCapture: function(event) {
  895. var o = this.options;
  896. // among others, prevent a drag on a resizable-handle
  897. if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle'))
  898. return false;
  899. //Quit if we're not on a valid handle
  900. this.handle = this._getHandle(event);
  901. if (!this.handle)
  902. return false;
  903. $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
  904. $('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
  905. .css({
  906. width: this.offsetWidth+"px", height: this.offsetHeight+"px",
  907. position: "absolute", opacity: "0.001", zIndex: 1000
  908. })
  909. .css($(this).offset())
  910. .appendTo("body");
  911. });
  912. return true;
  913. },
  914. _mouseStart: function(event) {
  915. var o = this.options;
  916. //Create and append the visible helper
  917. this.helper = this._createHelper(event);
  918. this.helper.addClass("ui-draggable-dragging");
  919. //Cache the helper size
  920. this._cacheHelperProportions();
  921. //If ddmanager is used for droppables, set the global draggable
  922. if($.ui.ddmanager)
  923. $.ui.ddmanager.current = this;
  924. /*
  925. * - Position generation -
  926. * This block generates everything position related - it's the core of draggables.
  927. */
  928. //Cache the margins of the original element
  929. this._cacheMargins();
  930. //Store the helper's css position
  931. this.cssPosition = this.helper.css("position");
  932. this.scrollParent = this.helper.scrollParent();
  933. //The element's absolute position on the page minus margins
  934. this.offset = this.positionAbs = this.element.offset();
  935. this.offset = {
  936. top: this.offset.top - this.margins.top,
  937. left: this.offset.left - this.margins.left
  938. };
  939. $.extend(this.offset, {
  940. click: { //Where the click happened, relative to the element
  941. left: event.pageX - this.offset.left,
  942. top: event.pageY - this.offset.top
  943. },
  944. parent: this._getParentOffset(),
  945. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  946. });
  947. //Generate the original position
  948. this.originalPosition = this.position = this._generatePosition(event);
  949. this.originalPageX = event.pageX;
  950. this.originalPageY = event.pageY;
  951. //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
  952. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  953. //Set a containment if given in the options
  954. if(o.containment)
  955. this._setContainment();
  956. //Trigger event + callbacks
  957. if(this._trigger("start", event) === false) {
  958. this._clear();
  959. return false;
  960. }
  961. //Recache the helper size
  962. this._cacheHelperProportions();
  963. //Prepare the droppable offsets
  964. if ($.ui.ddmanager && !o.dropBehaviour)
  965. $.ui.ddmanager.prepareOffsets(this, event);
  966. this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  967. //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
  968. if ( $.ui.ddmanager ) $.ui.ddmanager.dragStart(this, event);
  969. return true;
  970. },
  971. _mouseDrag: function(event, noPropagation) {
  972. //Compute the helpers position
  973. this.position = this._generatePosition(event);
  974. this.positionAbs = this._convertPositionTo("absolute");
  975. //Call plugins and callbacks and use the resulting position if something is returned
  976. if (!noPropagation) {
  977. var ui = this._uiHash();
  978. if(this._trigger('drag', event, ui) === false) {
  979. this._mouseUp({});
  980. return false;
  981. }
  982. this.position = ui.position;
  983. }
  984. if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
  985. if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
  986. if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
  987. return false;
  988. },
  989. _mouseStop: function(event) {
  990. //If we are using droppables, inform the manager about the drop
  991. var dropped = false;
  992. if ($.ui.ddmanager && !this.options.dropBehaviour)
  993. dropped = $.ui.ddmanager.drop(this, event);
  994. //if a drop comes from outside (a sortable)
  995. if(this.dropped) {
  996. dropped = this.dropped;
  997. this.dropped = false;
  998. }
  999. //if the original element is no longer in the DOM don't bother to continue (see #8269)
  1000. var element = this.element[0], elementInDom = false;
  1001. while ( element && (element = element.parentNode) ) {
  1002. if (element == document ) {
  1003. elementInDom = true;
  1004. }
  1005. }
  1006. if ( !elementInDom && this.options.helper === "original" )
  1007. return false;
  1008. 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))) {
  1009. var that = this;
  1010. $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
  1011. if(that._trigger("stop", event) !== false) {
  1012. that._clear();
  1013. }
  1014. });
  1015. } else {
  1016. if(this._trigger("stop", event) !== false) {
  1017. this._clear();
  1018. }
  1019. }
  1020. return false;
  1021. },
  1022. _mouseUp: function(event) {
  1023. //Remove frame helpers
  1024. $("div.ui-draggable-iframeFix").each(function() {
  1025. this.parentNode.removeChild(this);
  1026. });
  1027. //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
  1028. if( $.ui.ddmanager ) $.ui.ddmanager.dragStop(this, event);
  1029. return $.ui.mouse.prototype._mouseUp.call(this, event);
  1030. },
  1031. cancel: function() {
  1032. if(this.helper.is(".ui-draggable-dragging")) {
  1033. this._mouseUp({});
  1034. } else {
  1035. this._clear();
  1036. }
  1037. return this;
  1038. },
  1039. _getHandle: function(event) {
  1040. var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
  1041. $(this.options.handle, this.element)
  1042. .find("*")
  1043. .andSelf()
  1044. .each(function() {
  1045. if(this == event.target) handle = true;
  1046. });
  1047. return handle;
  1048. },
  1049. _createHelper: function(event) {
  1050. var o = this.options;
  1051. var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone().removeAttr('id') : this.element);
  1052. if(!helper.parents('body').length)
  1053. helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
  1054. if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position")))
  1055. helper.css("position", "absolute");
  1056. return helper;
  1057. },
  1058. _adjustOffsetFromHelper: function(obj) {
  1059. if (typeof obj == 'string') {
  1060. obj = obj.split(' ');
  1061. }
  1062. if ($.isArray(obj)) {
  1063. obj = {left: +obj[0], top: +obj[1] || 0};
  1064. }
  1065. if ('left' in obj) {
  1066. this.offset.click.left = obj.left + this.margins.left;
  1067. }
  1068. if ('right' in obj) {
  1069. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  1070. }
  1071. if ('top' in obj) {
  1072. this.offset.click.top = obj.top + this.margins.top;
  1073. }
  1074. if ('bottom' in obj) {
  1075. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  1076. }
  1077. },
  1078. _getParentOffset: function() {
  1079. //Get the offsetParent and cache its position
  1080. this.offsetParent = this.helper.offsetParent();
  1081. var po = this.offsetParent.offset();
  1082. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  1083. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  1084. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  1085. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  1086. if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  1087. po.left += this.scrollParent.scrollLeft();
  1088. po.top += this.scrollParent.scrollTop();
  1089. }
  1090. if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
  1091. || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix
  1092. po = { top: 0, left: 0 };
  1093. return {
  1094. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  1095. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  1096. };
  1097. },
  1098. _getRelativeOffset: function() {
  1099. if(this.cssPosition == "relative") {
  1100. var p = this.element.position();
  1101. return {
  1102. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  1103. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  1104. };
  1105. } else {
  1106. return { top: 0, left: 0 };
  1107. }
  1108. },
  1109. _cacheMargins: function() {
  1110. this.margins = {
  1111. left: (parseInt(this.element.css("marginLeft"),10) || 0),
  1112. top: (parseInt(this.element.css("marginTop"),10) || 0),
  1113. right: (parseInt(this.element.css("marginRight"),10) || 0),
  1114. bottom: (parseInt(this.element.css("marginBottom"),10) || 0)
  1115. };
  1116. },
  1117. _cacheHelperProportions: function() {
  1118. this.helperProportions = {
  1119. width: this.helper.outerWidth(),
  1120. height: this.helper.outerHeight()
  1121. };
  1122. },
  1123. _setContainment: function() {
  1124. var o = this.options;
  1125. if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
  1126. if(o.containment == 'document' || o.containment == 'window') this.containment = [
  1127. o.containment == 'document' ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
  1128. o.containment == 'document' ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
  1129. (o.containment == 'document' ? 0 : $(window).scrollLeft()) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
  1130. (o.containment == 'document' ? 0 : $(window).scrollTop()) + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  1131. ];
  1132. if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) {
  1133. var c = $(o.containment);
  1134. var ce = c[0]; if(!ce) return;
  1135. var co = c.offset();
  1136. var over = ($(ce).css("overflow") != 'hidden');
  1137. this.containment = [
  1138. (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
  1139. (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
  1140. (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,
  1141. (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
  1142. ];
  1143. this.relative_container = c;
  1144. } else if(o.containment.constructor == Array) {
  1145. this.containment = o.containment;
  1146. }
  1147. },
  1148. _convertPositionTo: function(d, pos) {
  1149. if(!pos) pos = this.position;
  1150. var mod = d == "absolute" ? 1 : -1;
  1151. 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);
  1152. return {
  1153. top: (
  1154. pos.top // The absolute mouse position
  1155. + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  1156. + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
  1157. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  1158. ),
  1159. left: (
  1160. pos.left // The absolute mouse position
  1161. + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  1162. + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
  1163. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  1164. )
  1165. };
  1166. },
  1167. _generatePosition: function(event) {
  1168. 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);
  1169. var pageX = event.pageX;
  1170. var pageY = event.pageY;
  1171. /*
  1172. * - Position constraining -
  1173. * Constrain the position to a mix of grid, containment.
  1174. */
  1175. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  1176. var containment;
  1177. if(this.containment) {
  1178. if (this.relative_container){
  1179. var co = this.relative_container.offset();
  1180. containment = [ this.containment[0] + co.left,
  1181. this.containment[1] + co.top,
  1182. this.containment[2] + co.left,
  1183. this.containment[3] + co.top ];
  1184. }
  1185. else {
  1186. containment = this.containment;
  1187. }
  1188. if(event.pageX - this.offset.click.left < containment[0]) pageX = containment[0] + this.offset.click.left;
  1189. if(event.pageY - this.offset.click.top < containment[1]) pageY = containment[1] + this.offset.click.top;
  1190. if(event.pageX - this.offset.click.left > containment[2]) pageX = containment[2] + this.offset.click.left;
  1191. if(event.pageY - this.offset.click.top > containment[3]) pageY = containment[3] + this.offset.click.top;
  1192. }
  1193. if(o.grid) {
  1194. //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
  1195. var top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
  1196. 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;
  1197. var left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX;
  1198. 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;
  1199. }
  1200. }
  1201. return {
  1202. top: (
  1203. pageY // The absolute mouse position
  1204. - this.offset.click.top // Click offset (relative to the element)
  1205. - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
  1206. - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
  1207. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  1208. ),
  1209. left: (
  1210. pageX // The absolute mouse position
  1211. - this.offset.click.left // Click offset (relative to the element)
  1212. - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
  1213. - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
  1214. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  1215. )
  1216. };
  1217. },
  1218. _clear: function() {
  1219. this.helper.removeClass("ui-draggable-dragging");
  1220. if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove();
  1221. //if($.ui.ddmanager) $.ui.ddmanager.current = null;
  1222. this.helper = null;
  1223. this.cancelHelperRemoval = false;
  1224. },
  1225. // From now on bulk stuff - mainly helpers
  1226. _trigger: function(type, event, ui) {
  1227. ui = ui || this._uiHash();
  1228. $.ui.plugin.call(this, type, [event, ui]);
  1229. if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins
  1230. return $.Widget.prototype._trigger.call(this, type, event, ui);
  1231. },
  1232. plugins: {},
  1233. _uiHash: function(event) {
  1234. return {
  1235. helper: this.helper,
  1236. position: this.position,
  1237. originalPosition: this.originalPosition,
  1238. offset: this.positionAbs
  1239. };
  1240. }
  1241. });
  1242. $.ui.plugin.add("draggable", "connectToSortable", {
  1243. start: function(event, ui) {
  1244. var inst = $(this).data("draggable"), o = inst.options,
  1245. uiSortable = $.extend({}, ui, { item: inst.element });
  1246. inst.sortables = [];
  1247. $(o.connectToSortable).each(function() {
  1248. var sortable = $.data(this, 'sortable');
  1249. if (sortable && !sortable.options.disabled) {
  1250. inst.sortables.push({
  1251. instance: sortable,
  1252. shouldRevert: sortable.options.revert
  1253. });
  1254. 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).
  1255. sortable._trigger("activate", event, uiSortable);
  1256. }
  1257. });
  1258. },
  1259. stop: function(event, ui) {
  1260. //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
  1261. var inst = $(this).data("draggable"),
  1262. uiSortable = $.extend({}, ui, { item: inst.element });
  1263. $.each(inst.sortables, function() {
  1264. if(this.instance.isOver) {
  1265. this.instance.isOver = 0;
  1266. inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
  1267. this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
  1268. //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid'
  1269. if(this.shouldRevert) this.instance.options.revert = true;
  1270. //Trigger the stop of the sortable
  1271. this.instance._mouseStop(event);
  1272. this.instance.options.helper = this.instance.options._helper;
  1273. //If the helper has been the original item, restore properties in the sortable
  1274. if(inst.options.helper == 'original')
  1275. this.instance.currentItem.css({ top: 'auto', left: 'auto' });
  1276. } else {
  1277. this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
  1278. this.instance._trigger("deactivate", event, uiSortable);
  1279. }
  1280. });
  1281. },
  1282. drag: function(event, ui) {
  1283. var inst = $(this).data("draggable"), that = this;
  1284. var checkPos = function(o) {
  1285. var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
  1286. var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
  1287. var itemHeight = o.height, itemWidth = o.width;
  1288. var itemTop = o.top, itemLeft = o.left;
  1289. return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
  1290. };
  1291. $.each(inst.sortables, function(i) {
  1292. //Copy over some variables to allow calling the sortable's native _intersectsWith
  1293. this.instance.positionAbs = inst.positionAbs;
  1294. this.instance.helperProportions = inst.helperProportions;
  1295. this.instance.offset.click = inst.offset.click;
  1296. if(this.instance._intersectsWith(this.instance.containerCache)) {
  1297. //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
  1298. if(!this.instance.isOver) {
  1299. this.instance.isOver = 1;
  1300. //Now we fake the start of dragging for the sortable instance,
  1301. //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
  1302. //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)
  1303. this.instance.currentItem = $(that).clone().removeAttr('id').appendTo(this.instance.element).data("sortable-item", true);
  1304. this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
  1305. this.instance.options.helper = function() { return ui.helper[0]; };
  1306. event.target = this.instance.currentItem[0];
  1307. this.instance._mouseCapture(event, true);
  1308. this.instance._mouseStart(event, true, true);
  1309. //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
  1310. this.instance.offset.click.top = inst.offset.click.top;
  1311. this.instance.offset.click.left = inst.offset.click.left;
  1312. this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
  1313. this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
  1314. inst._trigger("toSortable", event);
  1315. inst.dropped = this.instance.element; //draggable revert needs that
  1316. //hack so receive/update callbacks work (mostly)
  1317. inst.currentItem = inst.element;
  1318. this.instance.fromOutside = inst;
  1319. }
  1320. //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
  1321. if(this.instance.currentItem) this.instance._mouseDrag(event);
  1322. } else {
  1323. //If it doesn't intersect with the sortable, and it intersected before,
  1324. //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
  1325. if(this.instance.isOver) {
  1326. this.instance.isOver = 0;
  1327. this.instance.cancelHelperRemoval = true;
  1328. //Prevent reverting on this forced stop
  1329. this.instance.options.revert = false;
  1330. // The out event needs to be triggered independently
  1331. this.instance._trigger('out', event, this.instance._uiHash(this.instance));
  1332. this.instance._mouseStop(event, true);
  1333. this.instance.options.helper = this.instance.options._helper;
  1334. //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
  1335. this.instance.currentItem.remove();
  1336. if(this.instance.placeholder) this.instance.placeholder.remove();
  1337. inst._trigger("fromSortable", event);
  1338. inst.dropped = false; //draggable revert needs that
  1339. }
  1340. };
  1341. });
  1342. }
  1343. });
  1344. $.ui.plugin.add("draggable", "cursor", {
  1345. start: function(event, ui) {
  1346. var t = $('body'), o = $(this).data('draggable').options;
  1347. if (t.css("cursor")) o._cursor = t.css("cursor");
  1348. t.css("cursor", o.cursor);
  1349. },
  1350. stop: function(event, ui) {
  1351. var o = $(this).data('draggable').options;
  1352. if (o._cursor) $('body').css("cursor", o._cursor);
  1353. }
  1354. });
  1355. $.ui.plugin.add("draggable", "opacity", {
  1356. start: function(event, ui) {
  1357. var t = $(ui.helper), o = $(this).data('draggable').options;
  1358. if(t.css("opacity")) o._opacity = t.css("opacity");
  1359. t.css('opacity', o.opacity);
  1360. },
  1361. stop: function(event, ui) {
  1362. var o = $(this).data('draggable').options;
  1363. if(o._opacity) $(ui.helper).css('opacity', o._opacity);
  1364. }
  1365. });
  1366. $.ui.plugin.add("draggable", "scroll", {
  1367. start: function(event, ui) {
  1368. var i = $(this).data("draggable");
  1369. if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset();
  1370. },
  1371. drag: function(event, ui) {
  1372. var i = $(this).data("draggable"), o = i.options, scrolled = false;
  1373. if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') {
  1374. if(!o.axis || o.axis != 'x') {
  1375. if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
  1376. i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
  1377. else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity)
  1378. i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
  1379. }
  1380. if(!o.axis || o.axis != 'y') {
  1381. if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
  1382. i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
  1383. else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity)
  1384. i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
  1385. }
  1386. } else {
  1387. if(!o.axis || o.axis != 'x') {
  1388. if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
  1389. scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
  1390. else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
  1391. scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
  1392. }
  1393. if(!o.axis || o.axis != 'y') {
  1394. if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
  1395. scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
  1396. else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
  1397. scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
  1398. }
  1399. }
  1400. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
  1401. $.ui.ddmanager.prepareOffsets(i, event);
  1402. }
  1403. });
  1404. $.ui.plugin.add("draggable", "snap", {
  1405. start: function(event, ui) {
  1406. var i = $(this).data("draggable"), o = i.options;
  1407. i.snapElements = [];
  1408. $(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() {
  1409. var $t = $(this); var $o = $t.offset();
  1410. if(this != i.element[0]) i.snapElements.push({
  1411. item: this,
  1412. width: $t.outerWidth(), height: $t.outerHeight(),
  1413. top: $o.top, left: $o.left
  1414. });
  1415. });
  1416. },
  1417. drag: function(event, ui) {
  1418. var inst = $(this).data("draggable"), o = inst.options;
  1419. var d = o.snapTolerance;
  1420. var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
  1421. y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
  1422. for (var i = inst.snapElements.length - 1; i >= 0; i--){
  1423. var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width,
  1424. t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
  1425. //Yes, I know, this is insane ;)
  1426. 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))) {
  1427. 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 })));
  1428. inst.snapElements[i].snapping = false;
  1429. continue;
  1430. }
  1431. if(o.snapMode != 'inner') {
  1432. var ts = Math.abs(t - y2) <= d;
  1433. var bs = Math.abs(b - y1) <= d;
  1434. var ls = Math.abs(l - x2) <= d;
  1435. var rs = Math.abs(r - x1) <= d;
  1436. if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
  1437. if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
  1438. if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
  1439. if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
  1440. }
  1441. var first = (ts || bs || ls || rs);
  1442. if(o.snapMode != 'outer') {
  1443. var ts = Math.abs(t - y1) <= d;
  1444. var bs = Math.abs(b - y2) <= d;
  1445. var ls = Math.abs(l - x1) <= d;
  1446. var rs = Math.abs(r - x2) <= d;
  1447. if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top;
  1448. if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
  1449. if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
  1450. if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
  1451. }
  1452. if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first))
  1453. (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
  1454. inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
  1455. };
  1456. }
  1457. });
  1458. $.ui.plugin.add("draggable", "stack", {
  1459. start: function(event, ui) {
  1460. var o = $(this).data("draggable").options;
  1461. var group = $.makeArray($(o.stack)).sort(function(a,b) {
  1462. return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
  1463. });
  1464. if (!group.length) { return; }
  1465. var min = parseInt(group[0].style.zIndex) || 0;
  1466. $(group).each(function(i) {
  1467. this.style.zIndex = min + i;
  1468. });
  1469. this[0].style.zIndex = min + group.length;
  1470. }
  1471. });
  1472. $.ui.plugin.add("draggable", "zIndex", {
  1473. start: function(event, ui) {
  1474. var t = $(ui.helper), o = $(this).data("draggable").options;
  1475. if(t.css("zIndex")) o._zIndex = t.css("zIndex");
  1476. t.css('zIndex', o.zIndex);
  1477. },
  1478. stop: function(event, ui) {
  1479. var o = $(this).data("draggable").options;
  1480. if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex);
  1481. }
  1482. });
  1483. })(jQuery);
  1484. (function( $, undefined ) {
  1485. $.widget("ui.droppable", {
  1486. version: "1.9.0",
  1487. widgetEventPrefix: "drop",
  1488. options: {
  1489. accept: '*',
  1490. activeClass: false,
  1491. addClasses: true,
  1492. greedy: false,
  1493. hoverClass: false,
  1494. scope: 'default',
  1495. tolerance: 'intersect'
  1496. },
  1497. _create: function() {
  1498. var o = this.options, accept = o.accept;
  1499. this.isover = 0; this.isout = 1;
  1500. this.accept = $.isFunction(accept) ? accept : function(d) {
  1501. return d.is(accept);
  1502. };
  1503. //Store the droppable's proportions
  1504. this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
  1505. // Add the reference and positions to the manager
  1506. $.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || [];
  1507. $.ui.ddmanager.droppables[o.scope].push(this);
  1508. (o.addClasses && this.element.addClass("ui-droppable"));
  1509. },
  1510. _destroy: function() {
  1511. var drop = $.ui.ddmanager.droppables[this.options.scope];
  1512. for ( var i = 0; i < drop.length; i++ )
  1513. if ( drop[i] == this )
  1514. drop.splice(i, 1);
  1515. this.element.removeClass("ui-droppable ui-droppable-disabled");
  1516. },
  1517. _setOption: function(key, value) {
  1518. if(key == 'accept') {
  1519. this.accept = $.isFunction(value) ? value : function(d) {
  1520. return d.is(value);
  1521. };
  1522. }
  1523. $.Widget.prototype._setOption.apply(this, arguments);
  1524. },
  1525. _activate: function(event) {
  1526. var draggable = $.ui.ddmanager.current;
  1527. if(this.options.activeClass) this.element.addClass(this.options.activeClass);
  1528. (draggable && this._trigger('activate', event, this.ui(draggable)));
  1529. },
  1530. _deactivate: function(event) {
  1531. var draggable = $.ui.ddmanager.current;
  1532. if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
  1533. (draggable && this._trigger('deactivate', event, this.ui(draggable)));
  1534. },
  1535. _over: function(event) {
  1536. var draggable = $.ui.ddmanager.current;
  1537. if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
  1538. if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  1539. if(this.options.hoverClass) this.element.addClass(this.options.hoverClass);
  1540. this._trigger('over', event, this.ui(draggable));
  1541. }
  1542. },
  1543. _out: function(event) {
  1544. var draggable = $.ui.ddmanager.current;
  1545. if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
  1546. if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  1547. if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
  1548. this._trigger('out', event, this.ui(draggable));
  1549. }
  1550. },
  1551. _drop: function(event,custom) {
  1552. var draggable = custom || $.ui.ddmanager.current;
  1553. if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
  1554. var childrenIntersection = false;
  1555. this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() {
  1556. var inst = $.data(this, 'droppable');
  1557. if(
  1558. inst.options.greedy
  1559. && !inst.options.disabled
  1560. && inst.options.scope == draggable.options.scope
  1561. && inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element))
  1562. && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
  1563. ) { childrenIntersection = true; return false; }
  1564. });
  1565. if(childrenIntersection) return false;
  1566. if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  1567. if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
  1568. if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
  1569. this._trigger('drop', event, this.ui(draggable));
  1570. return this.element;
  1571. }
  1572. return false;
  1573. },
  1574. ui: function(c) {
  1575. return {
  1576. draggable: (c.currentItem || c.element),
  1577. helper: c.helper,
  1578. position: c.position,
  1579. offset: c.positionAbs
  1580. };
  1581. }
  1582. });
  1583. $.ui.intersect = function(draggable, droppable, toleranceMode) {
  1584. if (!droppable.offset) return false;
  1585. var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
  1586. y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
  1587. var l = droppable.offset.left, r = l + droppable.proportions.width,
  1588. t = droppable.offset.top, b = t + droppable.proportions.height;
  1589. switch (toleranceMode) {
  1590. case 'fit':
  1591. return (l <= x1 && x2 <= r
  1592. && t <= y1 && y2 <= b);
  1593. break;
  1594. case 'intersect':
  1595. return (l < x1 + (draggable.helperProportions.width / 2) // Right Half
  1596. && x2 - (draggable.helperProportions.width / 2) < r // Left Half
  1597. && t < y1 + (draggable.helperProportions.height / 2) // Bottom Half
  1598. && y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
  1599. break;
  1600. case 'pointer':
  1601. var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left),
  1602. draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top),
  1603. isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
  1604. return isOver;
  1605. break;
  1606. case 'touch':
  1607. return (
  1608. (y1 >= t && y1 <= b) || // Top edge touching
  1609. (y2 >= t && y2 <= b) || // Bottom edge touching
  1610. (y1 < t && y2 > b) // Surrounded vertically
  1611. ) && (
  1612. (x1 >= l && x1 <= r) || // Left edge touching
  1613. (x2 >= l && x2 <= r) || // Right edge touching
  1614. (x1 < l && x2 > r) // Surrounded horizontally
  1615. );
  1616. break;
  1617. default:
  1618. return false;
  1619. break;
  1620. }
  1621. };
  1622. /*
  1623. This manager tracks offsets of draggables and droppables
  1624. */
  1625. $.ui.ddmanager = {
  1626. current: null,
  1627. droppables: { 'default': [] },
  1628. prepareOffsets: function(t, event) {
  1629. var m = $.ui.ddmanager.droppables[t.options.scope] || [];
  1630. var type = event ? event.type : null; // workaround for #2317
  1631. var list = (t.currentItem || t.element).find(":data(droppable)").andSelf();
  1632. droppablesLoop: for (var i = 0; i < m.length; i++) {
  1633. if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted
  1634. 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
  1635. m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
  1636. if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables
  1637. m[i].offset = m[i].element.offset();
  1638. m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
  1639. }
  1640. },
  1641. drop: function(draggable, event) {
  1642. var dropped = false;
  1643. $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
  1644. if(!this.options) return;
  1645. if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance))
  1646. dropped = this._drop.call(this, event) || dropped;
  1647. if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  1648. this.isout = 1; this.isover = 0;
  1649. this._deactivate.call(this, event);
  1650. }
  1651. });
  1652. return dropped;
  1653. },
  1654. dragStart: function( draggable, event ) {
  1655. //Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003)
  1656. draggable.element.parentsUntil( "body" ).bind( "scroll.droppable", function() {
  1657. if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
  1658. });
  1659. },
  1660. drag: function(draggable, event) {
  1661. //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
  1662. if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
  1663. //Run through all droppables and check their positions based on specific tolerance options
  1664. $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
  1665. if(this.options.disabled || this.greedyChild || !this.visible) return;
  1666. var intersects = $.ui.intersect(draggable, this, this.options.tolerance);
  1667. var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null);
  1668. if(!c) return;
  1669. var parentInstance;
  1670. if (this.options.greedy) {
  1671. // find droppable parents with same scope
  1672. var scope = this.options.scope;
  1673. var parent = this.element.parents(':data(droppable)').filter(function () {
  1674. return $.data(this, 'droppable').options.scope === scope;
  1675. });
  1676. if (parent.length) {
  1677. parentInstance = $.data(parent[0], 'droppable');
  1678. parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
  1679. }
  1680. }
  1681. // we just moved into a greedy child
  1682. if (parentInstance && c == 'isover') {
  1683. parentInstance['isover'] = 0;
  1684. parentInstance['isout'] = 1;
  1685. parentInstance._out.call(parentInstance, event);
  1686. }
  1687. this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
  1688. this[c == "isover" ? "_over" : "_out"].call(this, event);
  1689. // we just moved out of a greedy child
  1690. if (parentInstance && c == 'isout') {
  1691. parentInstance['isout'] = 0;
  1692. parentInstance['isover'] = 1;
  1693. parentInstance._over.call(parentInstance, event);
  1694. }
  1695. });
  1696. },
  1697. dragStop: function( draggable, event ) {
  1698. draggable.element.parentsUntil( "body" ).unbind( "scroll.droppable" );
  1699. //Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003)
  1700. if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
  1701. }
  1702. };
  1703. })(jQuery);
  1704. (function( $, undefined ) {
  1705. $.widget("ui.resizable", $.ui.mouse, {
  1706. version: "1.9.0",
  1707. widgetEventPrefix: "resize",
  1708. options: {
  1709. alsoResize: false,
  1710. animate: false,
  1711. animateDuration: "slow",
  1712. animateEasing: "swing",
  1713. aspectRatio: false,
  1714. autoHide: false,
  1715. containment: false,
  1716. ghost: false,
  1717. grid: false,
  1718. handles: "e,s,se",
  1719. helper: false,
  1720. maxHeight: null,
  1721. maxWidth: null,
  1722. minHeight: 10,
  1723. minWidth: 10,
  1724. zIndex: 1000
  1725. },
  1726. _create: function() {
  1727. var that = this, o = this.options;
  1728. this.element.addClass("ui-resizable");
  1729. $.extend(this, {
  1730. _aspectRatio: !!(o.aspectRatio),
  1731. aspectRatio: o.aspectRatio,
  1732. originalElement: this.element,
  1733. _proportionallyResizeElements: [],
  1734. _helper: o.helper || o.ghost || o.animate ? o.helper || 'ui-resizable-helper' : null
  1735. });
  1736. //Wrap the element if it cannot hold child nodes
  1737. if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
  1738. //Create a wrapper element and set the wrapper to the new current internal element
  1739. this.element.wrap(
  1740. $('<div class="ui-wrapper" style="overflow: hidden;"></div>').css({
  1741. position: this.element.css('position'),
  1742. width: this.element.outerWidth(),
  1743. height: this.element.outerHeight(),
  1744. top: this.element.css('top'),
  1745. left: this.element.css('left')
  1746. })
  1747. );
  1748. //Overwrite the original this.element
  1749. this.element = this.element.parent().data(
  1750. "resizable", this.element.data('resizable')
  1751. );
  1752. this.elementIsWrapper = true;
  1753. //Move margins to the wrapper
  1754. this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
  1755. this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
  1756. //Prevent Safari textarea resize
  1757. this.originalResizeStyle = this.originalElement.css('resize');
  1758. this.originalElement.css('resize', 'none');
  1759. //Push the actual element to our proportionallyResize internal array
  1760. this._proportionallyResizeElements.push(this.originalElement.css({ position: 'static', zoom: 1, display: 'block' }));
  1761. // avoid IE jump (hard set the margin)
  1762. this.originalElement.css({ margin: this.originalElement.css('margin') });
  1763. // fix handlers offset
  1764. this._proportionallyResize();
  1765. }
  1766. 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' });
  1767. if(this.handles.constructor == String) {
  1768. if(this.handles == 'all') this.handles = 'n,e,s,w,se,sw,ne,nw';
  1769. var n = this.handles.split(","); this.handles = {};
  1770. for(var i = 0; i < n.length; i++) {
  1771. var handle = $.trim(n[i]), hname = 'ui-resizable-'+handle;
  1772. var axis = $('<div class="ui-resizable-handle ' + hname + '"></div>');
  1773. // Apply zIndex to all handles - see #7960
  1774. axis.css({ zIndex: o.zIndex });
  1775. //TODO : What's going on here?
  1776. if ('se' == handle) {
  1777. axis.addClass('ui-icon ui-icon-gripsmall-diagonal-se');
  1778. };
  1779. //Insert into internal handles object and append to element
  1780. this.handles[handle] = '.ui-resizable-'+handle;
  1781. this.element.append(axis);
  1782. }
  1783. }
  1784. this._renderAxis = function(target) {
  1785. target = target || this.element;
  1786. for(var i in this.handles) {
  1787. if(this.handles[i].constructor == String)
  1788. this.handles[i] = $(this.handles[i], this.element).show();
  1789. //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
  1790. if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
  1791. var axis = $(this.handles[i], this.element), padWrapper = 0;
  1792. //Checking the correct pad and border
  1793. padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
  1794. //The padding type i have to apply...
  1795. var padPos = [ 'padding',
  1796. /ne|nw|n/.test(i) ? 'Top' :
  1797. /se|sw|s/.test(i) ? 'Bottom' :
  1798. /^e$/.test(i) ? 'Right' : 'Left' ].join("");
  1799. target.css(padPos, padWrapper);
  1800. this._proportionallyResize();
  1801. }
  1802. //TODO: What's that good for? There's not anything to be executed left
  1803. if(!$(this.handles[i]).length)
  1804. continue;
  1805. }
  1806. };
  1807. //TODO: make renderAxis a prototype function
  1808. this._renderAxis(this.element);
  1809. this._handles = $('.ui-resizable-handle', this.element)
  1810. .disableSelection();
  1811. //Matching axis name
  1812. this._handles.mouseover(function() {
  1813. if (!that.resizing) {
  1814. if (this.className)
  1815. var axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
  1816. //Axis, default = se
  1817. that.axis = axis && axis[1] ? axis[1] : 'se';
  1818. }
  1819. });
  1820. //If we want to auto hide the elements
  1821. if (o.autoHide) {
  1822. this._handles.hide();
  1823. $(this.element)
  1824. .addClass("ui-resizable-autohide")
  1825. .mouseenter(function() {
  1826. if (o.disabled) return;
  1827. $(this).removeClass("ui-resizable-autohide");
  1828. that._handles.show();
  1829. })
  1830. .mouseleave(function(){
  1831. if (o.disabled) return;
  1832. if (!that.resizing) {
  1833. $(this).addClass("ui-resizable-autohide");
  1834. that._handles.hide();
  1835. }
  1836. });
  1837. }
  1838. //Initialize the mouse interaction
  1839. this._mouseInit();
  1840. },
  1841. _destroy: function() {
  1842. this._mouseDestroy();
  1843. var _destroy = function(exp) {
  1844. $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
  1845. .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find('.ui-resizable-handle').remove();
  1846. };
  1847. //TODO: Unwrap at same DOM position
  1848. if (this.elementIsWrapper) {
  1849. _destroy(this.element);
  1850. var wrapper = this.element;
  1851. wrapper.after(
  1852. this.originalElement.css({
  1853. position: wrapper.css('position'),
  1854. width: wrapper.outerWidth(),
  1855. height: wrapper.outerHeight(),
  1856. top: wrapper.css('top'),
  1857. left: wrapper.css('left')
  1858. })
  1859. ).remove();
  1860. }
  1861. this.originalElement.css('resize', this.originalResizeStyle);
  1862. _destroy(this.originalElement);
  1863. return this;
  1864. },
  1865. _mouseCapture: function(event) {
  1866. var handle = false;
  1867. for (var i in this.handles) {
  1868. if ($(this.handles[i])[0] == event.target) {
  1869. handle = true;
  1870. }
  1871. }
  1872. return !this.options.disabled && handle;
  1873. },
  1874. _mouseStart: function(event) {
  1875. var o = this.options, iniPos = this.element.position(), el = this.element;
  1876. this.resizing = true;
  1877. this.documentScroll = { top: $(document).scrollTop(), left: $(document).scrollLeft() };
  1878. // bugfix for http://dev.jquery.com/ticket/1749
  1879. if (el.is('.ui-draggable') || (/absolute/).test(el.css('position'))) {
  1880. el.css({ position: 'absolute', top: iniPos.top, left: iniPos.left });
  1881. }
  1882. this._renderProxy();
  1883. var curleft = num(this.helper.css('left')), curtop = num(this.helper.css('top'));
  1884. if (o.containment) {
  1885. curleft += $(o.containment).scrollLeft() || 0;
  1886. curtop += $(o.containment).scrollTop() || 0;
  1887. }
  1888. //Store needed variables
  1889. this.offset = this.helper.offset();
  1890. this.position = { left: curleft, top: curtop };
  1891. this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  1892. this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  1893. this.originalPosition = { left: curleft, top: curtop };
  1894. this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
  1895. this.originalMousePosition = { left: event.pageX, top: event.pageY };
  1896. //Aspect Ratio
  1897. this.aspectRatio = (typeof o.aspectRatio == 'number') ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
  1898. var cursor = $('.ui-resizable-' + this.axis).css('cursor');
  1899. $('body').css('cursor', cursor == 'auto' ? this.axis + '-resize' : cursor);
  1900. el.addClass("ui-resizable-resizing");
  1901. this._propagate("start", event);
  1902. return true;
  1903. },
  1904. _mouseDrag: function(event) {
  1905. //Increase performance, avoid regex
  1906. var el = this.helper, o = this.options, props = {},
  1907. that = this, smp = this.originalMousePosition, a = this.axis;
  1908. var dx = (event.pageX-smp.left)||0, dy = (event.pageY-smp.top)||0;
  1909. var trigger = this._change[a];
  1910. if (!trigger) return false;
  1911. // Calculate the attrs that will be change
  1912. var data = trigger.apply(this, [event, dx, dy]);
  1913. // Put this in the mouseDrag handler since the user can start pressing shift while resizing
  1914. this._updateVirtualBoundaries(event.shiftKey);
  1915. if (this._aspectRatio || event.shiftKey)
  1916. data = this._updateRatio(data, event);
  1917. data = this._respectSize(data, event);
  1918. // plugins callbacks need to be called first
  1919. this._propagate("resize", event);
  1920. el.css({
  1921. top: this.position.top + "px", left: this.position.left + "px",
  1922. width: this.size.width + "px", height: this.size.height + "px"
  1923. });
  1924. if (!this._helper && this._proportionallyResizeElements.length)
  1925. this._proportionallyResize();
  1926. this._updateCache(data);
  1927. // calling the user callback at the end
  1928. this._trigger('resize', event, this.ui());
  1929. return false;
  1930. },
  1931. _mouseStop: function(event) {
  1932. this.resizing = false;
  1933. var o = this.options, that = this;
  1934. if(this._helper) {
  1935. var pr = this._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  1936. soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
  1937. soffsetw = ista ? 0 : that.sizeDiff.width;
  1938. var s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) },
  1939. left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
  1940. top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;
  1941. if (!o.animate)
  1942. this.element.css($.extend(s, { top: top, left: left }));
  1943. that.helper.height(that.size.height);
  1944. that.helper.width(that.size.width);
  1945. if (this._helper && !o.animate) this._proportionallyResize();
  1946. }
  1947. $('body').css('cursor', 'auto');
  1948. this.element.removeClass("ui-resizable-resizing");
  1949. this._propagate("stop", event);
  1950. if (this._helper) this.helper.remove();
  1951. return false;
  1952. },
  1953. _updateVirtualBoundaries: function(forceAspectRatio) {
  1954. var o = this.options, pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b;
  1955. b = {
  1956. minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
  1957. maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity,
  1958. minHeight: isNumber(o.minHeight) ? o.minHeight : 0,
  1959. maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity
  1960. };
  1961. if(this._aspectRatio || forceAspectRatio) {
  1962. // We want to create an enclosing box whose aspect ration is the requested one
  1963. // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
  1964. pMinWidth = b.minHeight * this.aspectRatio;
  1965. pMinHeight = b.minWidth / this.aspectRatio;
  1966. pMaxWidth = b.maxHeight * this.aspectRatio;
  1967. pMaxHeight = b.maxWidth / this.aspectRatio;
  1968. if(pMinWidth > b.minWidth) b.minWidth = pMinWidth;
  1969. if(pMinHeight > b.minHeight) b.minHeight = pMinHeight;
  1970. if(pMaxWidth < b.maxWidth) b.maxWidth = pMaxWidth;
  1971. if(pMaxHeight < b.maxHeight) b.maxHeight = pMaxHeight;
  1972. }
  1973. this._vBoundaries = b;
  1974. },
  1975. _updateCache: function(data) {
  1976. var o = this.options;
  1977. this.offset = this.helper.offset();
  1978. if (isNumber(data.left)) this.position.left = data.left;
  1979. if (isNumber(data.top)) this.position.top = data.top;
  1980. if (isNumber(data.height)) this.size.height = data.height;
  1981. if (isNumber(data.width)) this.size.width = data.width;
  1982. },
  1983. _updateRatio: function(data, event) {
  1984. var o = this.options, cpos = this.position, csize = this.size, a = this.axis;
  1985. if (isNumber(data.height)) data.width = (data.height * this.aspectRatio);
  1986. else if (isNumber(data.width)) data.height = (data.width / this.aspectRatio);
  1987. if (a == 'sw') {
  1988. data.left = cpos.left + (csize.width - data.width);
  1989. data.top = null;
  1990. }
  1991. if (a == 'nw') {
  1992. data.top = cpos.top + (csize.height - data.height);
  1993. data.left = cpos.left + (csize.width - data.width);
  1994. }
  1995. return data;
  1996. },
  1997. _respectSize: function(data, event) {
  1998. var el = this.helper, o = this._vBoundaries, pRatio = this._aspectRatio || event.shiftKey, a = this.axis,
  1999. ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
  2000. isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height);
  2001. if (isminw) data.width = o.minWidth;
  2002. if (isminh) data.height = o.minHeight;
  2003. if (ismaxw) data.width = o.maxWidth;
  2004. if (ismaxh) data.height = o.maxHeight;
  2005. var dw = this.originalPosition.left + this.originalSize.width, dh = this.position.top + this.size.height;
  2006. var cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
  2007. if (isminw && cw) data.left = dw - o.minWidth;
  2008. if (ismaxw && cw) data.left = dw - o.maxWidth;
  2009. if (isminh && ch) data.top = dh - o.minHeight;
  2010. if (ismaxh && ch) data.top = dh - o.maxHeight;
  2011. // fixing jump error on top/left - bug #2330
  2012. var isNotwh = !data.width && !data.height;
  2013. if (isNotwh && !data.left && data.top) data.top = null;
  2014. else if (isNotwh && !data.top && data.left) data.left = null;
  2015. return data;
  2016. },
  2017. _proportionallyResize: function() {
  2018. var o = this.options;
  2019. if (!this._proportionallyResizeElements.length) return;
  2020. var element = this.helper || this.element;
  2021. for (var i=0; i < this._proportionallyResizeElements.length; i++) {
  2022. var prel = this._proportionallyResizeElements[i];
  2023. if (!this.borderDif) {
  2024. var b = [prel.css('borderTopWidth'), prel.css('borderRightWidth'), prel.css('borderBottomWidth'), prel.css('borderLeftWidth')],
  2025. p = [prel.css('paddingTop'), prel.css('paddingRight'), prel.css('paddingBottom'), prel.css('paddingLeft')];
  2026. this.borderDif = $.map(b, function(v, i) {
  2027. var border = parseInt(v,10)||0, padding = parseInt(p[i],10)||0;
  2028. return border + padding;
  2029. });
  2030. }
  2031. prel.css({
  2032. height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0,
  2033. width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
  2034. });
  2035. };
  2036. },
  2037. _renderProxy: function() {
  2038. var el = this.element, o = this.options;
  2039. this.elementOffset = el.offset();
  2040. if(this._helper) {
  2041. this.helper = this.helper || $('<div style="overflow:hidden;"></div>');
  2042. // fix ie6 offset TODO: This seems broken
  2043. var ie6 = $.browser.msie && $.browser.version < 7, ie6offset = (ie6 ? 1 : 0),
  2044. pxyoffset = ( ie6 ? 2 : -1 );
  2045. this.helper.addClass(this._helper).css({
  2046. width: this.element.outerWidth() + pxyoffset,
  2047. height: this.element.outerHeight() + pxyoffset,
  2048. position: 'absolute',
  2049. left: this.elementOffset.left - ie6offset +'px',
  2050. top: this.elementOffset.top - ie6offset +'px',
  2051. zIndex: ++o.zIndex //TODO: Don't modify option
  2052. });
  2053. this.helper
  2054. .appendTo("body")
  2055. .disableSelection();
  2056. } else {
  2057. this.helper = this.element;
  2058. }
  2059. },
  2060. _change: {
  2061. e: function(event, dx, dy) {
  2062. return { width: this.originalSize.width + dx };
  2063. },
  2064. w: function(event, dx, dy) {
  2065. var o = this.options, cs = this.originalSize, sp = this.originalPosition;
  2066. return { left: sp.left + dx, width: cs.width - dx };
  2067. },
  2068. n: function(event, dx, dy) {
  2069. var o = this.options, cs = this.originalSize, sp = this.originalPosition;
  2070. return { top: sp.top + dy, height: cs.height - dy };
  2071. },
  2072. s: function(event, dx, dy) {
  2073. return { height: this.originalSize.height + dy };
  2074. },
  2075. se: function(event, dx, dy) {
  2076. return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  2077. },
  2078. sw: function(event, dx, dy) {
  2079. return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  2080. },
  2081. ne: function(event, dx, dy) {
  2082. return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  2083. },
  2084. nw: function(event, dx, dy) {
  2085. return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  2086. }
  2087. },
  2088. _propagate: function(n, event) {
  2089. $.ui.plugin.call(this, n, [event, this.ui()]);
  2090. (n != "resize" && this._trigger(n, event, this.ui()));
  2091. },
  2092. plugins: {},
  2093. ui: function() {
  2094. return {
  2095. originalElement: this.originalElement,
  2096. element: this.element,
  2097. helper: this.helper,
  2098. position: this.position,
  2099. size: this.size,
  2100. originalSize: this.originalSize,
  2101. originalPosition: this.originalPosition
  2102. };
  2103. }
  2104. });
  2105. /*
  2106. * Resizable Extensions
  2107. */
  2108. $.ui.plugin.add("resizable", "alsoResize", {
  2109. start: function (event, ui) {
  2110. var that = $(this).data("resizable"), o = that.options;
  2111. var _store = function (exp) {
  2112. $(exp).each(function() {
  2113. var el = $(this);
  2114. el.data("resizable-alsoresize", {
  2115. width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
  2116. left: parseInt(el.css('left'), 10), top: parseInt(el.css('top'), 10)
  2117. });
  2118. });
  2119. };
  2120. if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) {
  2121. if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
  2122. else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
  2123. }else{
  2124. _store(o.alsoResize);
  2125. }
  2126. },
  2127. resize: function (event, ui) {
  2128. var that = $(this).data("resizable"), o = that.options, os = that.originalSize, op = that.originalPosition;
  2129. var delta = {
  2130. height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
  2131. top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
  2132. },
  2133. _alsoResize = function (exp, c) {
  2134. $(exp).each(function() {
  2135. var el = $(this), start = $(this).data("resizable-alsoresize"), style = {},
  2136. css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width', 'height'] : ['width', 'height', 'top', 'left'];
  2137. $.each(css, function (i, prop) {
  2138. var sum = (start[prop]||0) + (delta[prop]||0);
  2139. if (sum && sum >= 0)
  2140. style[prop] = sum || null;
  2141. });
  2142. el.css(style);
  2143. });
  2144. };
  2145. if (typeof(o.alsoResize) == 'object' && !o.alsoResize.nodeType) {
  2146. $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
  2147. }else{
  2148. _alsoResize(o.alsoResize);
  2149. }
  2150. },
  2151. stop: function (event, ui) {
  2152. $(this).removeData("resizable-alsoresize");
  2153. }
  2154. });
  2155. $.ui.plugin.add("resizable", "animate", {
  2156. stop: function(event, ui) {
  2157. var that = $(this).data("resizable"), o = that.options;
  2158. var pr = that._proportionallyResizeElements, ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  2159. soffseth = ista && $.ui.hasScroll(pr[0], 'left') /* TODO - jump height */ ? 0 : that.sizeDiff.height,
  2160. soffsetw = ista ? 0 : that.sizeDiff.width;
  2161. var style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
  2162. left = (parseInt(that.element.css('left'), 10) + (that.position.left - that.originalPosition.left)) || null,
  2163. top = (parseInt(that.element.css('top'), 10) + (that.position.top - that.originalPosition.top)) || null;
  2164. that.element.animate(
  2165. $.extend(style, top && left ? { top: top, left: left } : {}), {
  2166. duration: o.animateDuration,
  2167. easing: o.animateEasing,
  2168. step: function() {
  2169. var data = {
  2170. width: parseInt(that.element.css('width'), 10),
  2171. height: parseInt(that.element.css('height'), 10),
  2172. top: parseInt(that.element.css('top'), 10),
  2173. left: parseInt(that.element.css('left'), 10)
  2174. };
  2175. if (pr && pr.length) $(pr[0]).css({ width: data.width, height: data.height });
  2176. // propagating resize, and updating values for each animation step
  2177. that._updateCache(data);
  2178. that._propagate("resize", event);
  2179. }
  2180. }
  2181. );
  2182. }
  2183. });
  2184. $.ui.plugin.add("resizable", "containment", {
  2185. start: function(event, ui) {
  2186. var that = $(this).data("resizable"), o = that.options, el = that.element;
  2187. var oc = o.containment, ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
  2188. if (!ce) return;
  2189. that.containerElement = $(ce);
  2190. if (/document/.test(oc) || oc == document) {
  2191. that.containerOffset = { left: 0, top: 0 };
  2192. that.containerPosition = { left: 0, top: 0 };
  2193. that.parentData = {
  2194. element: $(document), left: 0, top: 0,
  2195. width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
  2196. };
  2197. }
  2198. // i'm a node, so compute top, left, right, bottom
  2199. else {
  2200. var element = $(ce), p = [];
  2201. $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
  2202. that.containerOffset = element.offset();
  2203. that.containerPosition = element.position();
  2204. that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
  2205. var co = that.containerOffset, ch = that.containerSize.height, cw = that.containerSize.width,
  2206. width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw ), height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
  2207. that.parentData = {
  2208. element: ce, left: co.left, top: co.top, width: width, height: height
  2209. };
  2210. }
  2211. },
  2212. resize: function(event, ui) {
  2213. var that = $(this).data("resizable"), o = that.options,
  2214. ps = that.containerSize, co = that.containerOffset, cs = that.size, cp = that.position,
  2215. pRatio = that._aspectRatio || event.shiftKey, cop = { top:0, left:0 }, ce = that.containerElement;
  2216. if (ce[0] != document && (/static/).test(ce.css('position'))) cop = co;
  2217. if (cp.left < (that._helper ? co.left : 0)) {
  2218. that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left));
  2219. if (pRatio) that.size.height = that.size.width / that.aspectRatio;
  2220. that.position.left = o.helper ? co.left : 0;
  2221. }
  2222. if (cp.top < (that._helper ? co.top : 0)) {
  2223. that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top);
  2224. if (pRatio) that.size.width = that.size.height * that.aspectRatio;
  2225. that.position.top = that._helper ? co.top : 0;
  2226. }
  2227. that.offset.left = that.parentData.left+that.position.left;
  2228. that.offset.top = that.parentData.top+that.position.top;
  2229. var woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width ),
  2230. hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
  2231. var isParent = that.containerElement.get(0) == that.element.parent().get(0),
  2232. isOffsetRelative = /relative|absolute/.test(that.containerElement.css('position'));
  2233. if(isParent && isOffsetRelative) woset -= that.parentData.left;
  2234. if (woset + that.size.width >= that.parentData.width) {
  2235. that.size.width = that.parentData.width - woset;
  2236. if (pRatio) that.size.height = that.size.width / that.aspectRatio;
  2237. }
  2238. if (hoset + that.size.height >= that.parentData.height) {
  2239. that.size.height = that.parentData.height - hoset;
  2240. if (pRatio) that.size.width = that.size.height * that.aspectRatio;
  2241. }
  2242. },
  2243. stop: function(event, ui){
  2244. var that = $(this).data("resizable"), o = that.options, cp = that.position,
  2245. co = that.containerOffset, cop = that.containerPosition, ce = that.containerElement;
  2246. var helper = $(that.helper), ho = helper.offset(), w = helper.outerWidth() - that.sizeDiff.width, h = helper.outerHeight() - that.sizeDiff.height;
  2247. if (that._helper && !o.animate && (/relative/).test(ce.css('position')))
  2248. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  2249. if (that._helper && !o.animate && (/static/).test(ce.css('position')))
  2250. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  2251. }
  2252. });
  2253. $.ui.plugin.add("resizable", "ghost", {
  2254. start: function(event, ui) {
  2255. var that = $(this).data("resizable"), o = that.options, cs = that.size;
  2256. that.ghost = that.originalElement.clone();
  2257. that.ghost
  2258. .css({ opacity: .25, display: 'block', position: 'relative', height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
  2259. .addClass('ui-resizable-ghost')
  2260. .addClass(typeof o.ghost == 'string' ? o.ghost : '');
  2261. that.ghost.appendTo(that.helper);
  2262. },
  2263. resize: function(event, ui){
  2264. var that = $(this).data("resizable"), o = that.options;
  2265. if (that.ghost) that.ghost.css({ position: 'relative', height: that.size.height, width: that.size.width });
  2266. },
  2267. stop: function(event, ui){
  2268. var that = $(this).data("resizable"), o = that.options;
  2269. if (that.ghost && that.helper) that.helper.get(0).removeChild(that.ghost.get(0));
  2270. }
  2271. });
  2272. $.ui.plugin.add("resizable", "grid", {
  2273. resize: function(event, ui) {
  2274. 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;
  2275. o.grid = typeof o.grid == "number" ? [o.grid, o.grid] : o.grid;
  2276. 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);
  2277. if (/^(se|s|e)$/.test(a)) {
  2278. that.size.width = os.width + ox;
  2279. that.size.height = os.height + oy;
  2280. }
  2281. else if (/^(ne)$/.test(a)) {
  2282. that.size.width = os.width + ox;
  2283. that.size.height = os.height + oy;
  2284. that.position.top = op.top - oy;
  2285. }
  2286. else if (/^(sw)$/.test(a)) {
  2287. that.size.width = os.width + ox;
  2288. that.size.height = os.height + oy;
  2289. that.position.left = op.left - ox;
  2290. }
  2291. else {
  2292. that.size.width = os.width + ox;
  2293. that.size.height = os.height + oy;
  2294. that.position.top = op.top - oy;
  2295. that.position.left = op.left - ox;
  2296. }
  2297. }
  2298. });
  2299. var num = function(v) {
  2300. return parseInt(v, 10) || 0;
  2301. };
  2302. var isNumber = function(value) {
  2303. return !isNaN(parseInt(value, 10));
  2304. };
  2305. })(jQuery);
  2306. (function( $, undefined ) {
  2307. $.widget("ui.selectable", $.ui.mouse, {
  2308. version: "1.9.0",
  2309. options: {
  2310. appendTo: 'body',
  2311. autoRefresh: true,
  2312. distance: 0,
  2313. filter: '*',
  2314. tolerance: 'touch'
  2315. },
  2316. _create: function() {
  2317. var that = this;
  2318. this.element.addClass("ui-selectable");
  2319. this.dragged = false;
  2320. // cache selectee children based on filter
  2321. var selectees;
  2322. this.refresh = function() {
  2323. selectees = $(that.options.filter, that.element[0]);
  2324. selectees.addClass("ui-selectee");
  2325. selectees.each(function() {
  2326. var $this = $(this);
  2327. var pos = $this.offset();
  2328. $.data(this, "selectable-item", {
  2329. element: this,
  2330. $element: $this,
  2331. left: pos.left,
  2332. top: pos.top,
  2333. right: pos.left + $this.outerWidth(),
  2334. bottom: pos.top + $this.outerHeight(),
  2335. startselected: false,
  2336. selected: $this.hasClass('ui-selected'),
  2337. selecting: $this.hasClass('ui-selecting'),
  2338. unselecting: $this.hasClass('ui-unselecting')
  2339. });
  2340. });
  2341. };
  2342. this.refresh();
  2343. this.selectees = selectees.addClass("ui-selectee");
  2344. this._mouseInit();
  2345. this.helper = $("<div class='ui-selectable-helper'></div>");
  2346. },
  2347. _destroy: function() {
  2348. this.selectees
  2349. .removeClass("ui-selectee")
  2350. .removeData("selectable-item");
  2351. this.element
  2352. .removeClass("ui-selectable ui-selectable-disabled");
  2353. this._mouseDestroy();
  2354. },
  2355. _mouseStart: function(event) {
  2356. var that = this;
  2357. this.opos = [event.pageX, event.pageY];
  2358. if (this.options.disabled)
  2359. return;
  2360. var options = this.options;
  2361. this.selectees = $(options.filter, this.element[0]);
  2362. this._trigger("start", event);
  2363. $(options.appendTo).append(this.helper);
  2364. // position helper (lasso)
  2365. this.helper.css({
  2366. "left": event.clientX,
  2367. "top": event.clientY,
  2368. "width": 0,
  2369. "height": 0
  2370. });
  2371. if (options.autoRefresh) {
  2372. this.refresh();
  2373. }
  2374. this.selectees.filter('.ui-selected').each(function() {
  2375. var selectee = $.data(this, "selectable-item");
  2376. selectee.startselected = true;
  2377. if (!event.metaKey && !event.ctrlKey) {
  2378. selectee.$element.removeClass('ui-selected');
  2379. selectee.selected = false;
  2380. selectee.$element.addClass('ui-unselecting');
  2381. selectee.unselecting = true;
  2382. // selectable UNSELECTING callback
  2383. that._trigger("unselecting", event, {
  2384. unselecting: selectee.element
  2385. });
  2386. }
  2387. });
  2388. $(event.target).parents().andSelf().each(function() {
  2389. var selectee = $.data(this, "selectable-item");
  2390. if (selectee) {
  2391. var doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass('ui-selected');
  2392. selectee.$element
  2393. .removeClass(doSelect ? "ui-unselecting" : "ui-selected")
  2394. .addClass(doSelect ? "ui-selecting" : "ui-unselecting");
  2395. selectee.unselecting = !doSelect;
  2396. selectee.selecting = doSelect;
  2397. selectee.selected = doSelect;
  2398. // selectable (UN)SELECTING callback
  2399. if (doSelect) {
  2400. that._trigger("selecting", event, {
  2401. selecting: selectee.element
  2402. });
  2403. } else {
  2404. that._trigger("unselecting", event, {
  2405. unselecting: selectee.element
  2406. });
  2407. }
  2408. return false;
  2409. }
  2410. });
  2411. },
  2412. _mouseDrag: function(event) {
  2413. var that = this;
  2414. this.dragged = true;
  2415. if (this.options.disabled)
  2416. return;
  2417. var options = this.options;
  2418. var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY;
  2419. if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; }
  2420. if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; }
  2421. this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
  2422. this.selectees.each(function() {
  2423. var selectee = $.data(this, "selectable-item");
  2424. //prevent helper from being selected if appendTo: selectable
  2425. if (!selectee || selectee.element == that.element[0])
  2426. return;
  2427. var hit = false;
  2428. if (options.tolerance == 'touch') {
  2429. hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
  2430. } else if (options.tolerance == 'fit') {
  2431. hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
  2432. }
  2433. if (hit) {
  2434. // SELECT
  2435. if (selectee.selected) {
  2436. selectee.$element.removeClass('ui-selected');
  2437. selectee.selected = false;
  2438. }
  2439. if (selectee.unselecting) {
  2440. selectee.$element.removeClass('ui-unselecting');
  2441. selectee.unselecting = false;
  2442. }
  2443. if (!selectee.selecting) {
  2444. selectee.$element.addClass('ui-selecting');
  2445. selectee.selecting = true;
  2446. // selectable SELECTING callback
  2447. that._trigger("selecting", event, {
  2448. selecting: selectee.element
  2449. });
  2450. }
  2451. } else {
  2452. // UNSELECT
  2453. if (selectee.selecting) {
  2454. if ((event.metaKey || event.ctrlKey) && selectee.startselected) {
  2455. selectee.$element.removeClass('ui-selecting');
  2456. selectee.selecting = false;
  2457. selectee.$element.addClass('ui-selected');
  2458. selectee.selected = true;
  2459. } else {
  2460. selectee.$element.removeClass('ui-selecting');
  2461. selectee.selecting = false;
  2462. if (selectee.startselected) {
  2463. selectee.$element.addClass('ui-unselecting');
  2464. selectee.unselecting = true;
  2465. }
  2466. // selectable UNSELECTING callback
  2467. that._trigger("unselecting", event, {
  2468. unselecting: selectee.element
  2469. });
  2470. }
  2471. }
  2472. if (selectee.selected) {
  2473. if (!event.metaKey && !event.ctrlKey && !selectee.startselected) {
  2474. selectee.$element.removeClass('ui-selected');
  2475. selectee.selected = false;
  2476. selectee.$element.addClass('ui-unselecting');
  2477. selectee.unselecting = true;
  2478. // selectable UNSELECTING callback
  2479. that._trigger("unselecting", event, {
  2480. unselecting: selectee.element
  2481. });
  2482. }
  2483. }
  2484. }
  2485. });
  2486. return false;
  2487. },
  2488. _mouseStop: function(event) {
  2489. var that = this;
  2490. this.dragged = false;
  2491. var options = this.options;
  2492. $('.ui-unselecting', this.element[0]).each(function() {
  2493. var selectee = $.data(this, "selectable-item");
  2494. selectee.$element.removeClass('ui-unselecting');
  2495. selectee.unselecting = false;
  2496. selectee.startselected = false;
  2497. that._trigger("unselected", event, {
  2498. unselected: selectee.element
  2499. });
  2500. });
  2501. $('.ui-selecting', this.element[0]).each(function() {
  2502. var selectee = $.data(this, "selectable-item");
  2503. selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
  2504. selectee.selecting = false;
  2505. selectee.selected = true;
  2506. selectee.startselected = true;
  2507. that._trigger("selected", event, {
  2508. selected: selectee.element
  2509. });
  2510. });
  2511. this._trigger("stop", event);
  2512. this.helper.remove();
  2513. return false;
  2514. }
  2515. });
  2516. })(jQuery);
  2517. (function( $, undefined ) {
  2518. $.widget("ui.sortable", $.ui.mouse, {
  2519. version: "1.9.0",
  2520. widgetEventPrefix: "sort",
  2521. ready: false,
  2522. options: {
  2523. appendTo: "parent",
  2524. axis: false,
  2525. connectWith: false,
  2526. containment: false,
  2527. cursor: 'auto',
  2528. cursorAt: false,
  2529. dropOnEmpty: true,
  2530. forcePlaceholderSize: false,
  2531. forceHelperSize: false,
  2532. grid: false,
  2533. handle: false,
  2534. helper: "original",
  2535. items: '> *',
  2536. opacity: false,
  2537. placeholder: false,
  2538. revert: false,
  2539. scroll: true,
  2540. scrollSensitivity: 20,
  2541. scrollSpeed: 20,
  2542. scope: "default",
  2543. tolerance: "intersect",
  2544. zIndex: 1000
  2545. },
  2546. _create: function() {
  2547. var o = this.options;
  2548. this.containerCache = {};
  2549. this.element.addClass("ui-sortable");
  2550. //Get the items
  2551. this.refresh();
  2552. //Let's determine if the items are being displayed horizontally
  2553. 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;
  2554. //Let's determine the parent's offset
  2555. this.offset = this.element.offset();
  2556. //Initialize mouse events for interaction
  2557. this._mouseInit();
  2558. //We're ready to go
  2559. this.ready = true
  2560. },
  2561. _destroy: function() {
  2562. this.element
  2563. .removeClass("ui-sortable ui-sortable-disabled");
  2564. this._mouseDestroy();
  2565. for ( var i = this.items.length - 1; i >= 0; i-- )
  2566. this.items[i].item.removeData(this.widgetName + "-item");
  2567. return this;
  2568. },
  2569. _setOption: function(key, value){
  2570. if ( key === "disabled" ) {
  2571. this.options[ key ] = value;
  2572. this.widget().toggleClass( "ui-sortable-disabled", !!value );
  2573. } else {
  2574. // Don't call widget base _setOption for disable as it adds ui-state-disabled class
  2575. $.Widget.prototype._setOption.apply(this, arguments);
  2576. }
  2577. },
  2578. _mouseCapture: function(event, overrideHandle) {
  2579. var that = this;
  2580. if (this.reverting) {
  2581. return false;
  2582. }
  2583. if(this.options.disabled || this.options.type == 'static') return false;
  2584. //We have to refresh the items data once first
  2585. this._refreshItems(event);
  2586. //Find out if the clicked node (or one of its parents) is a actual item in this.items
  2587. var currentItem = null, nodes = $(event.target).parents().each(function() {
  2588. if($.data(this, that.widgetName + '-item') == that) {
  2589. currentItem = $(this);
  2590. return false;
  2591. }
  2592. });
  2593. if($.data(event.target, that.widgetName + '-item') == that) currentItem = $(event.target);
  2594. if(!currentItem) return false;
  2595. if(this.options.handle && !overrideHandle) {
  2596. var validHandle = false;
  2597. $(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == event.target) validHandle = true; });
  2598. if(!validHandle) return false;
  2599. }
  2600. this.currentItem = currentItem;
  2601. this._removeCurrentsFromItems();
  2602. return true;
  2603. },
  2604. _mouseStart: function(event, overrideHandle, noActivation) {
  2605. var o = this.options;
  2606. this.currentContainer = this;
  2607. //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
  2608. this.refreshPositions();
  2609. //Create and append the visible helper
  2610. this.helper = this._createHelper(event);
  2611. //Cache the helper size
  2612. this._cacheHelperProportions();
  2613. /*
  2614. * - Position generation -
  2615. * This block generates everything position related - it's the core of draggables.
  2616. */
  2617. //Cache the margins of the original element
  2618. this._cacheMargins();
  2619. //Get the next scrolling parent
  2620. this.scrollParent = this.helper.scrollParent();
  2621. //The element's absolute position on the page minus margins
  2622. this.offset = this.currentItem.offset();
  2623. this.offset = {
  2624. top: this.offset.top - this.margins.top,
  2625. left: this.offset.left - this.margins.left
  2626. };
  2627. $.extend(this.offset, {
  2628. click: { //Where the click happened, relative to the element
  2629. left: event.pageX - this.offset.left,
  2630. top: event.pageY - this.offset.top
  2631. },
  2632. parent: this._getParentOffset(),
  2633. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  2634. });
  2635. // Only after we got the offset, we can change the helper's position to absolute
  2636. // TODO: Still need to figure out a way to make relative sorting possible
  2637. this.helper.css("position", "absolute");
  2638. this.cssPosition = this.helper.css("position");
  2639. //Generate the original position
  2640. this.originalPosition = this._generatePosition(event);
  2641. this.originalPageX = event.pageX;
  2642. this.originalPageY = event.pageY;
  2643. //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
  2644. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  2645. //Cache the former DOM position
  2646. this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
  2647. //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
  2648. if(this.helper[0] != this.currentItem[0]) {
  2649. this.currentItem.hide();
  2650. }
  2651. //Create the placeholder
  2652. this._createPlaceholder();
  2653. //Set a containment if given in the options
  2654. if(o.containment)
  2655. this._setContainment();
  2656. if(o.cursor) { // cursor option
  2657. if ($('body').css("cursor")) this._storedCursor = $('body').css("cursor");
  2658. $('body').css("cursor", o.cursor);
  2659. }
  2660. if(o.opacity) { // opacity option
  2661. if (this.helper.css("opacity")) this._storedOpacity = this.helper.css("opacity");
  2662. this.helper.css("opacity", o.opacity);
  2663. }
  2664. if(o.zIndex) { // zIndex option
  2665. if (this.helper.css("zIndex")) this._storedZIndex = this.helper.css("zIndex");
  2666. this.helper.css("zIndex", o.zIndex);
  2667. }
  2668. //Prepare scrolling
  2669. if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML')
  2670. this.overflowOffset = this.scrollParent.offset();
  2671. //Call callbacks
  2672. this._trigger("start", event, this._uiHash());
  2673. //Recache the helper size
  2674. if(!this._preserveHelperProportions)
  2675. this._cacheHelperProportions();
  2676. //Post 'activate' events to possible containers
  2677. if(!noActivation) {
  2678. for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i]._trigger("activate", event, this._uiHash(this)); }
  2679. }
  2680. //Prepare possible droppables
  2681. if($.ui.ddmanager)
  2682. $.ui.ddmanager.current = this;
  2683. if ($.ui.ddmanager && !o.dropBehaviour)
  2684. $.ui.ddmanager.prepareOffsets(this, event);
  2685. this.dragging = true;
  2686. this.helper.addClass("ui-sortable-helper");
  2687. this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  2688. return true;
  2689. },
  2690. _mouseDrag: function(event) {
  2691. //Compute the helpers position
  2692. this.position = this._generatePosition(event);
  2693. this.positionAbs = this._convertPositionTo("absolute");
  2694. if (!this.lastPositionAbs) {
  2695. this.lastPositionAbs = this.positionAbs;
  2696. }
  2697. //Do scrolling
  2698. if(this.options.scroll) {
  2699. var o = this.options, scrolled = false;
  2700. if(this.scrollParent[0] != document && this.scrollParent[0].tagName != 'HTML') {
  2701. if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity)
  2702. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
  2703. else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity)
  2704. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
  2705. if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity)
  2706. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
  2707. else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity)
  2708. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
  2709. } else {
  2710. if(event.pageY - $(document).scrollTop() < o.scrollSensitivity)
  2711. scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
  2712. else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity)
  2713. scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
  2714. if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity)
  2715. scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
  2716. else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
  2717. scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
  2718. }
  2719. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour)
  2720. $.ui.ddmanager.prepareOffsets(this, event);
  2721. }
  2722. //Regenerate the absolute position used for position checks
  2723. this.positionAbs = this._convertPositionTo("absolute");
  2724. //Set the helper position
  2725. if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
  2726. if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
  2727. //Rearrange
  2728. for (var i = this.items.length - 1; i >= 0; i--) {
  2729. //Cache variables and intersection, continue if no intersection
  2730. var item = this.items[i], itemElement = item.item[0], intersection = this._intersectsWithPointer(item);
  2731. if (!intersection) continue;
  2732. // Only put the placeholder inside the current Container, skip all
  2733. // items form other containers. This works because when moving
  2734. // an item from one container to another the
  2735. // currentContainer is switched before the placeholder is moved.
  2736. //
  2737. // Without this moving items in "sub-sortables" can cause the placeholder to jitter
  2738. // beetween the outer and inner container.
  2739. if (item.instance !== this.currentContainer) continue;
  2740. if (itemElement != this.currentItem[0] //cannot intersect with itself
  2741. && this.placeholder[intersection == 1 ? "next" : "prev"]()[0] != itemElement //no useless actions that have been done before
  2742. && !$.contains(this.placeholder[0], itemElement) //no action if the item moved is the parent of the item checked
  2743. && (this.options.type == 'semi-dynamic' ? !$.contains(this.element[0], itemElement) : true)
  2744. //&& itemElement.parentNode == this.placeholder[0].parentNode // only rearrange items within the same container
  2745. ) {
  2746. this.direction = intersection == 1 ? "down" : "up";
  2747. if (this.options.tolerance == "pointer" || this._intersectsWithSides(item)) {
  2748. this._rearrange(event, item);
  2749. } else {
  2750. break;
  2751. }
  2752. this._trigger("change", event, this._uiHash());
  2753. break;
  2754. }
  2755. }
  2756. //Post events to containers
  2757. this._contactContainers(event);
  2758. //Interconnect with droppables
  2759. if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
  2760. //Call callbacks
  2761. this._trigger('sort', event, this._uiHash());
  2762. this.lastPositionAbs = this.positionAbs;
  2763. return false;
  2764. },
  2765. _mouseStop: function(event, noPropagation) {
  2766. if(!event) return;
  2767. //If we are using droppables, inform the manager about the drop
  2768. if ($.ui.ddmanager && !this.options.dropBehaviour)
  2769. $.ui.ddmanager.drop(this, event);
  2770. if(this.options.revert) {
  2771. var that = this;
  2772. var cur = this.placeholder.offset();
  2773. this.reverting = true;
  2774. $(this.helper).animate({
  2775. left: cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft),
  2776. top: cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop)
  2777. }, parseInt(this.options.revert, 10) || 500, function() {
  2778. that._clear(event);
  2779. });
  2780. } else {
  2781. this._clear(event, noPropagation);
  2782. }
  2783. return false;
  2784. },
  2785. cancel: function() {
  2786. if(this.dragging) {
  2787. this._mouseUp({ target: null });
  2788. if(this.options.helper == "original")
  2789. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  2790. else
  2791. this.currentItem.show();
  2792. //Post deactivating events to containers
  2793. for (var i = this.containers.length - 1; i >= 0; i--){
  2794. this.containers[i]._trigger("deactivate", null, this._uiHash(this));
  2795. if(this.containers[i].containerCache.over) {
  2796. this.containers[i]._trigger("out", null, this._uiHash(this));
  2797. this.containers[i].containerCache.over = 0;
  2798. }
  2799. }
  2800. }
  2801. if (this.placeholder) {
  2802. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  2803. if(this.placeholder[0].parentNode) this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  2804. if(this.options.helper != "original" && this.helper && this.helper[0].parentNode) this.helper.remove();
  2805. $.extend(this, {
  2806. helper: null,
  2807. dragging: false,
  2808. reverting: false,
  2809. _noFinalSort: null
  2810. });
  2811. if(this.domPosition.prev) {
  2812. $(this.domPosition.prev).after(this.currentItem);
  2813. } else {
  2814. $(this.domPosition.parent).prepend(this.currentItem);
  2815. }
  2816. }
  2817. return this;
  2818. },
  2819. serialize: function(o) {
  2820. var items = this._getItemsAsjQuery(o && o.connected);
  2821. var str = []; o = o || {};
  2822. $(items).each(function() {
  2823. var res = ($(o.item || this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
  2824. if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2]));
  2825. });
  2826. if(!str.length && o.key) {
  2827. str.push(o.key + '=');
  2828. }
  2829. return str.join('&');
  2830. },
  2831. toArray: function(o) {
  2832. var items = this._getItemsAsjQuery(o && o.connected);
  2833. var ret = []; o = o || {};
  2834. items.each(function() { ret.push($(o.item || this).attr(o.attribute || 'id') || ''); });
  2835. return ret;
  2836. },
  2837. /* Be careful with the following core functions */
  2838. _intersectsWith: function(item) {
  2839. var x1 = this.positionAbs.left,
  2840. x2 = x1 + this.helperProportions.width,
  2841. y1 = this.positionAbs.top,
  2842. y2 = y1 + this.helperProportions.height;
  2843. var l = item.left,
  2844. r = l + item.width,
  2845. t = item.top,
  2846. b = t + item.height;
  2847. var dyClick = this.offset.click.top,
  2848. dxClick = this.offset.click.left;
  2849. var isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
  2850. if( this.options.tolerance == "pointer"
  2851. || this.options.forcePointerForContainers
  2852. || (this.options.tolerance != "pointer" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])
  2853. ) {
  2854. return isOverElement;
  2855. } else {
  2856. return (l < x1 + (this.helperProportions.width / 2) // Right Half
  2857. && x2 - (this.helperProportions.width / 2) < r // Left Half
  2858. && t < y1 + (this.helperProportions.height / 2) // Bottom Half
  2859. && y2 - (this.helperProportions.height / 2) < b ); // Top Half
  2860. }
  2861. },
  2862. _intersectsWithPointer: function(item) {
  2863. var isOverElementHeight = (this.options.axis === 'x') || $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
  2864. isOverElementWidth = (this.options.axis === 'y') || $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
  2865. isOverElement = isOverElementHeight && isOverElementWidth,
  2866. verticalDirection = this._getDragVerticalDirection(),
  2867. horizontalDirection = this._getDragHorizontalDirection();
  2868. if (!isOverElement)
  2869. return false;
  2870. return this.floating ?
  2871. ( ((horizontalDirection && horizontalDirection == "right") || verticalDirection == "down") ? 2 : 1 )
  2872. : ( verticalDirection && (verticalDirection == "down" ? 2 : 1) );
  2873. },
  2874. _intersectsWithSides: function(item) {
  2875. var isOverBottomHalf = $.ui.isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
  2876. isOverRightHalf = $.ui.isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
  2877. verticalDirection = this._getDragVerticalDirection(),
  2878. horizontalDirection = this._getDragHorizontalDirection();
  2879. if (this.floating && horizontalDirection) {
  2880. return ((horizontalDirection == "right" && isOverRightHalf) || (horizontalDirection == "left" && !isOverRightHalf));
  2881. } else {
  2882. return verticalDirection && ((verticalDirection == "down" && isOverBottomHalf) || (verticalDirection == "up" && !isOverBottomHalf));
  2883. }
  2884. },
  2885. _getDragVerticalDirection: function() {
  2886. var delta = this.positionAbs.top - this.lastPositionAbs.top;
  2887. return delta != 0 && (delta > 0 ? "down" : "up");
  2888. },
  2889. _getDragHorizontalDirection: function() {
  2890. var delta = this.positionAbs.left - this.lastPositionAbs.left;
  2891. return delta != 0 && (delta > 0 ? "right" : "left");
  2892. },
  2893. refresh: function(event) {
  2894. this._refreshItems(event);
  2895. this.refreshPositions();
  2896. return this;
  2897. },
  2898. _connectWith: function() {
  2899. var options = this.options;
  2900. return options.connectWith.constructor == String
  2901. ? [options.connectWith]
  2902. : options.connectWith;
  2903. },
  2904. _getItemsAsjQuery: function(connected) {
  2905. var items = [];
  2906. var queries = [];
  2907. var connectWith = this._connectWith();
  2908. if(connectWith && connected) {
  2909. for (var i = connectWith.length - 1; i >= 0; i--){
  2910. var cur = $(connectWith[i]);
  2911. for (var j = cur.length - 1; j >= 0; j--){
  2912. var inst = $.data(cur[j], this.widgetName);
  2913. if(inst && inst != this && !inst.options.disabled) {
  2914. 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]);
  2915. }
  2916. };
  2917. };
  2918. }
  2919. 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]);
  2920. for (var i = queries.length - 1; i >= 0; i--){
  2921. queries[i][0].each(function() {
  2922. items.push(this);
  2923. });
  2924. };
  2925. return $(items);
  2926. },
  2927. _removeCurrentsFromItems: function() {
  2928. var list = this.currentItem.find(":data(" + this.widgetName + "-item)");
  2929. for (var i=0; i < this.items.length; i++) {
  2930. for (var j=0; j < list.length; j++) {
  2931. if(list[j] == this.items[i].item[0])
  2932. this.items.splice(i,1);
  2933. };
  2934. };
  2935. },
  2936. _refreshItems: function(event) {
  2937. this.items = [];
  2938. this.containers = [this];
  2939. var items = this.items;
  2940. var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]];
  2941. var connectWith = this._connectWith();
  2942. if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
  2943. for (var i = connectWith.length - 1; i >= 0; i--){
  2944. var cur = $(connectWith[i]);
  2945. for (var j = cur.length - 1; j >= 0; j--){
  2946. var inst = $.data(cur[j], this.widgetName);
  2947. if(inst && inst != this && !inst.options.disabled) {
  2948. queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
  2949. this.containers.push(inst);
  2950. }
  2951. };
  2952. };
  2953. }
  2954. for (var i = queries.length - 1; i >= 0; i--) {
  2955. var targetData = queries[i][1];
  2956. var _queries = queries[i][0];
  2957. for (var j=0, queriesLength = _queries.length; j < queriesLength; j++) {
  2958. var item = $(_queries[j]);
  2959. item.data(this.widgetName + '-item', targetData); // Data for target checking (mouse manager)
  2960. items.push({
  2961. item: item,
  2962. instance: targetData,
  2963. width: 0, height: 0,
  2964. left: 0, top: 0
  2965. });
  2966. };
  2967. };
  2968. },
  2969. refreshPositions: function(fast) {
  2970. //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
  2971. if(this.offsetParent && this.helper) {
  2972. this.offset.parent = this._getParentOffset();
  2973. }
  2974. for (var i = this.items.length - 1; i >= 0; i--){
  2975. var item = this.items[i];
  2976. //We ignore calculating positions of all connected containers when we're not over them
  2977. if(item.instance != this.currentContainer && this.currentContainer && item.item[0] != this.currentItem[0])
  2978. continue;
  2979. var t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
  2980. if (!fast) {
  2981. item.width = t.outerWidth();
  2982. item.height = t.outerHeight();
  2983. }
  2984. var p = t.offset();
  2985. item.left = p.left;
  2986. item.top = p.top;
  2987. };
  2988. if(this.options.custom && this.options.custom.refreshContainers) {
  2989. this.options.custom.refreshContainers.call(this);
  2990. } else {
  2991. for (var i = this.containers.length - 1; i >= 0; i--){
  2992. var p = this.containers[i].element.offset();
  2993. this.containers[i].containerCache.left = p.left;
  2994. this.containers[i].containerCache.top = p.top;
  2995. this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
  2996. this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
  2997. };
  2998. }
  2999. return this;
  3000. },
  3001. _createPlaceholder: function(that) {
  3002. that = that || this;
  3003. var o = that.options;
  3004. if(!o.placeholder || o.placeholder.constructor == String) {
  3005. var className = o.placeholder;
  3006. o.placeholder = {
  3007. element: function() {
  3008. var el = $(document.createElement(that.currentItem[0].nodeName))
  3009. .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
  3010. .removeClass("ui-sortable-helper")[0];
  3011. if(!className)
  3012. el.style.visibility = "hidden";
  3013. return el;
  3014. },
  3015. update: function(container, p) {
  3016. // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that
  3017. // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified
  3018. if(className && !o.forcePlaceholderSize) return;
  3019. //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
  3020. if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css('paddingTop')||0, 10) - parseInt(that.currentItem.css('paddingBottom')||0, 10)); };
  3021. if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css('paddingLeft')||0, 10) - parseInt(that.currentItem.css('paddingRight')||0, 10)); };
  3022. }
  3023. };
  3024. }
  3025. //Create the placeholder
  3026. that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));
  3027. //Append it after the actual current item
  3028. that.currentItem.after(that.placeholder);
  3029. //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
  3030. o.placeholder.update(that, that.placeholder);
  3031. },
  3032. _contactContainers: function(event) {
  3033. // get innermost container that intersects with item
  3034. var innermostContainer = null, innermostIndex = null;
  3035. for (var i = this.containers.length - 1; i >= 0; i--){
  3036. // never consider a container that's located within the item itself
  3037. if($.contains(this.currentItem[0], this.containers[i].element[0]))
  3038. continue;
  3039. if(this._intersectsWith(this.containers[i].containerCache)) {
  3040. // if we've already found a container and it's more "inner" than this, then continue
  3041. if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0]))
  3042. continue;
  3043. innermostContainer = this.containers[i];
  3044. innermostIndex = i;
  3045. } else {
  3046. // container doesn't intersect. trigger "out" event if necessary
  3047. if(this.containers[i].containerCache.over) {
  3048. this.containers[i]._trigger("out", event, this._uiHash(this));
  3049. this.containers[i].containerCache.over = 0;
  3050. }
  3051. }
  3052. }
  3053. // if no intersecting containers found, return
  3054. if(!innermostContainer) return;
  3055. // move the item into the container if it's not there already
  3056. if(this.containers.length === 1) {
  3057. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  3058. this.containers[innermostIndex].containerCache.over = 1;
  3059. } else if(this.currentContainer != this.containers[innermostIndex]) {
  3060. //When entering a new container, we will find the item with the least distance and append our item near it
  3061. var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[innermostIndex].floating ? 'left' : 'top'];
  3062. for (var j = this.items.length - 1; j >= 0; j--) {
  3063. if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) continue;
  3064. var cur = this.containers[innermostIndex].floating ? this.items[j].item.offset().left : this.items[j].item.offset().top;
  3065. if(Math.abs(cur - base) < dist) {
  3066. dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
  3067. this.direction = (cur - base > 0) ? 'down' : 'up';
  3068. }
  3069. }
  3070. if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
  3071. return;
  3072. this.currentContainer = this.containers[innermostIndex];
  3073. itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
  3074. this._trigger("change", event, this._uiHash());
  3075. this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
  3076. //Update the placeholder
  3077. this.options.placeholder.update(this.currentContainer, this.placeholder);
  3078. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  3079. this.containers[innermostIndex].containerCache.over = 1;
  3080. }
  3081. },
  3082. _createHelper: function(event) {
  3083. var o = this.options;
  3084. var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper == 'clone' ? this.currentItem.clone() : this.currentItem);
  3085. if(!helper.parents('body').length) //Add the helper to the DOM if that didn't happen already
  3086. $(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
  3087. if(helper[0] == this.currentItem[0])
  3088. 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") };
  3089. if(helper[0].style.width == '' || o.forceHelperSize) helper.width(this.currentItem.width());
  3090. if(helper[0].style.height == '' || o.forceHelperSize) helper.height(this.currentItem.height());
  3091. return helper;
  3092. },
  3093. _adjustOffsetFromHelper: function(obj) {
  3094. if (typeof obj == 'string') {
  3095. obj = obj.split(' ');
  3096. }
  3097. if ($.isArray(obj)) {
  3098. obj = {left: +obj[0], top: +obj[1] || 0};
  3099. }
  3100. if ('left' in obj) {
  3101. this.offset.click.left = obj.left + this.margins.left;
  3102. }
  3103. if ('right' in obj) {
  3104. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  3105. }
  3106. if ('top' in obj) {
  3107. this.offset.click.top = obj.top + this.margins.top;
  3108. }
  3109. if ('bottom' in obj) {
  3110. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  3111. }
  3112. },
  3113. _getParentOffset: function() {
  3114. //Get the offsetParent and cache its position
  3115. this.offsetParent = this.helper.offsetParent();
  3116. var po = this.offsetParent.offset();
  3117. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  3118. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  3119. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  3120. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  3121. if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  3122. po.left += this.scrollParent.scrollLeft();
  3123. po.top += this.scrollParent.scrollTop();
  3124. }
  3125. if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
  3126. || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.browser.msie)) //Ugly IE fix
  3127. po = { top: 0, left: 0 };
  3128. return {
  3129. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  3130. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  3131. };
  3132. },
  3133. _getRelativeOffset: function() {
  3134. if(this.cssPosition == "relative") {
  3135. var p = this.currentItem.position();
  3136. return {
  3137. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  3138. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  3139. };
  3140. } else {
  3141. return { top: 0, left: 0 };
  3142. }
  3143. },
  3144. _cacheMargins: function() {
  3145. this.margins = {
  3146. left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
  3147. top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
  3148. };
  3149. },
  3150. _cacheHelperProportions: function() {
  3151. this.helperProportions = {
  3152. width: this.helper.outerWidth(),
  3153. height: this.helper.outerHeight()
  3154. };
  3155. },
  3156. _setContainment: function() {
  3157. var o = this.options;
  3158. if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
  3159. if(o.containment == 'document' || o.containment == 'window') this.containment = [
  3160. 0 - this.offset.relative.left - this.offset.parent.left,
  3161. 0 - this.offset.relative.top - this.offset.parent.top,
  3162. $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
  3163. ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  3164. ];
  3165. if(!(/^(document|window|parent)$/).test(o.containment)) {
  3166. var ce = $(o.containment)[0];
  3167. var co = $(o.containment).offset();
  3168. var over = ($(ce).css("overflow") != 'hidden');
  3169. this.containment = [
  3170. co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left,
  3171. co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top,
  3172. 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,
  3173. 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
  3174. ];
  3175. }
  3176. },
  3177. _convertPositionTo: function(d, pos) {
  3178. if(!pos) pos = this.position;
  3179. var mod = d == "absolute" ? 1 : -1;
  3180. 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);
  3181. return {
  3182. top: (
  3183. pos.top // The absolute mouse position
  3184. + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  3185. + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
  3186. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  3187. ),
  3188. left: (
  3189. pos.left // The absolute mouse position
  3190. + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  3191. + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
  3192. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  3193. )
  3194. };
  3195. },
  3196. _generatePosition: function(event) {
  3197. 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);
  3198. // This is another very weird special case that only happens for relative elements:
  3199. // 1. If the css position is relative
  3200. // 2. and the scroll parent is the document or similar to the offset parent
  3201. // we have to refresh the relative offset during the scroll so there are no jumps
  3202. if(this.cssPosition == 'relative' && !(this.scrollParent[0] != document && this.scrollParent[0] != this.offsetParent[0])) {
  3203. this.offset.relative = this._getRelativeOffset();
  3204. }
  3205. var pageX = event.pageX;
  3206. var pageY = event.pageY;
  3207. /*
  3208. * - Position constraining -
  3209. * Constrain the position to a mix of grid, containment.
  3210. */
  3211. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  3212. if(this.containment) {
  3213. if(event.pageX - this.offset.click.left < this.containment[0]) pageX = this.containment[0] + this.offset.click.left;
  3214. if(event.pageY - this.offset.click.top < this.containment[1]) pageY = this.containment[1] + this.offset.click.top;
  3215. if(event.pageX - this.offset.click.left > this.containment[2]) pageX = this.containment[2] + this.offset.click.left;
  3216. if(event.pageY - this.offset.click.top > this.containment[3]) pageY = this.containment[3] + this.offset.click.top;
  3217. }
  3218. if(o.grid) {
  3219. var top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
  3220. 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;
  3221. var left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
  3222. 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;
  3223. }
  3224. }
  3225. return {
  3226. top: (
  3227. pageY // The absolute mouse position
  3228. - this.offset.click.top // Click offset (relative to the element)
  3229. - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
  3230. - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
  3231. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  3232. ),
  3233. left: (
  3234. pageX // The absolute mouse position
  3235. - this.offset.click.left // Click offset (relative to the element)
  3236. - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
  3237. - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
  3238. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  3239. )
  3240. };
  3241. },
  3242. _rearrange: function(event, i, a, hardRefresh) {
  3243. 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));
  3244. //Various things done here to improve the performance:
  3245. // 1. we create a setTimeout, that calls refreshPositions
  3246. // 2. on the instance, we have a counter variable, that get's higher after every append
  3247. // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
  3248. // 4. this lets only the last addition to the timeout stack through
  3249. this.counter = this.counter ? ++this.counter : 1;
  3250. var counter = this.counter;
  3251. this._delay(function() {
  3252. if(counter == this.counter) this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
  3253. });
  3254. },
  3255. _clear: function(event, noPropagation) {
  3256. this.reverting = false;
  3257. // We delay all events that have to be triggered to after the point where the placeholder has been removed and
  3258. // everything else normalized again
  3259. var delayedTriggers = [];
  3260. // We first have to update the dom position of the actual currentItem
  3261. // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
  3262. if(!this._noFinalSort && this.currentItem.parent().length) this.placeholder.before(this.currentItem);
  3263. this._noFinalSort = null;
  3264. if(this.helper[0] == this.currentItem[0]) {
  3265. for(var i in this._storedCSS) {
  3266. if(this._storedCSS[i] == 'auto' || this._storedCSS[i] == 'static') this._storedCSS[i] = '';
  3267. }
  3268. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  3269. } else {
  3270. this.currentItem.show();
  3271. }
  3272. if(this.fromOutside && !noPropagation) delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
  3273. 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
  3274. // Check if the items Container has Changed and trigger appropriate
  3275. // events.
  3276. if (this !== this.currentContainer) {
  3277. if(!noPropagation) {
  3278. delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); });
  3279. delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  3280. delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  3281. }
  3282. }
  3283. //Post events to containers
  3284. for (var i = this.containers.length - 1; i >= 0; i--){
  3285. if(!noPropagation) delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
  3286. if(this.containers[i].containerCache.over) {
  3287. delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
  3288. this.containers[i].containerCache.over = 0;
  3289. }
  3290. }
  3291. //Do what was originally in plugins
  3292. if(this._storedCursor) $('body').css("cursor", this._storedCursor); //Reset cursor
  3293. if(this._storedOpacity) this.helper.css("opacity", this._storedOpacity); //Reset opacity
  3294. if(this._storedZIndex) this.helper.css("zIndex", this._storedZIndex == 'auto' ? '' : this._storedZIndex); //Reset z-index
  3295. this.dragging = false;
  3296. if(this.cancelHelperRemoval) {
  3297. if(!noPropagation) {
  3298. this._trigger("beforeStop", event, this._uiHash());
  3299. for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
  3300. this._trigger("stop", event, this._uiHash());
  3301. }
  3302. this.fromOutside = false;
  3303. return false;
  3304. }
  3305. if(!noPropagation) this._trigger("beforeStop", event, this._uiHash());
  3306. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  3307. this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  3308. if(this.helper[0] != this.currentItem[0]) this.helper.remove(); this.helper = null;
  3309. if(!noPropagation) {
  3310. for (var i=0; i < delayedTriggers.length; i++) { delayedTriggers[i].call(this, event); }; //Trigger all delayed events
  3311. this._trigger("stop", event, this._uiHash());
  3312. }
  3313. this.fromOutside = false;
  3314. return true;
  3315. },
  3316. _trigger: function() {
  3317. if ($.Widget.prototype._trigger.apply(this, arguments) === false) {
  3318. this.cancel();
  3319. }
  3320. },
  3321. _uiHash: function(_inst) {
  3322. var inst = _inst || this;
  3323. return {
  3324. helper: inst.helper,
  3325. placeholder: inst.placeholder || $([]),
  3326. position: inst.position,
  3327. originalPosition: inst.originalPosition,
  3328. offset: inst.positionAbs,
  3329. item: inst.currentItem,
  3330. sender: _inst ? _inst.element : null
  3331. };
  3332. }
  3333. });
  3334. })(jQuery);
  3335. ;(jQuery.effects || (function($, undefined) {
  3336. var backCompat = $.uiBackCompat !== false,
  3337. // prefix used for storing data on .data()
  3338. dataSpace = "ui-effects-";
  3339. $.effects = {
  3340. effect: {}
  3341. };
  3342. /*!
  3343. * jQuery Color Animations v2.0.0
  3344. * http://jquery.com/
  3345. *
  3346. * Copyright 2012 jQuery Foundation and other contributors
  3347. * Released under the MIT license.
  3348. * http://jquery.org/license
  3349. *
  3350. * Date: Mon Aug 13 13:41:02 2012 -0500
  3351. */
  3352. (function( jQuery, undefined ) {
  3353. var stepHooks = "backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor".split(" "),
  3354. // plusequals test for += 100 -= 100
  3355. rplusequals = /^([\-+])=\s*(\d+\.?\d*)/,
  3356. // a set of RE's that can match strings and generate color tuples.
  3357. stringParsers = [{
  3358. re: /rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
  3359. parse: function( execResult ) {
  3360. return [
  3361. execResult[ 1 ],
  3362. execResult[ 2 ],
  3363. execResult[ 3 ],
  3364. execResult[ 4 ]
  3365. ];
  3366. }
  3367. }, {
  3368. re: /rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
  3369. parse: function( execResult ) {
  3370. return [
  3371. execResult[ 1 ] * 2.55,
  3372. execResult[ 2 ] * 2.55,
  3373. execResult[ 3 ] * 2.55,
  3374. execResult[ 4 ]
  3375. ];
  3376. }
  3377. }, {
  3378. // this regex ignores A-F because it's compared against an already lowercased string
  3379. re: /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,
  3380. parse: function( execResult ) {
  3381. return [
  3382. parseInt( execResult[ 1 ], 16 ),
  3383. parseInt( execResult[ 2 ], 16 ),
  3384. parseInt( execResult[ 3 ], 16 )
  3385. ];
  3386. }
  3387. }, {
  3388. // this regex ignores A-F because it's compared against an already lowercased string
  3389. re: /#([a-f0-9])([a-f0-9])([a-f0-9])/,
  3390. parse: function( execResult ) {
  3391. return [
  3392. parseInt( execResult[ 1 ] + execResult[ 1 ], 16 ),
  3393. parseInt( execResult[ 2 ] + execResult[ 2 ], 16 ),
  3394. parseInt( execResult[ 3 ] + execResult[ 3 ], 16 )
  3395. ];
  3396. }
  3397. }, {
  3398. re: /hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d+(?:\.\d+)?)\s*)?\)/,
  3399. space: "hsla",
  3400. parse: function( execResult ) {
  3401. return [
  3402. execResult[ 1 ],
  3403. execResult[ 2 ] / 100,
  3404. execResult[ 3 ] / 100,
  3405. execResult[ 4 ]
  3406. ];
  3407. }
  3408. }],
  3409. // jQuery.Color( )
  3410. color = jQuery.Color = function( color, green, blue, alpha ) {
  3411. return new jQuery.Color.fn.parse( color, green, blue, alpha );
  3412. },
  3413. spaces = {
  3414. rgba: {
  3415. props: {
  3416. red: {
  3417. idx: 0,
  3418. type: "byte"
  3419. },
  3420. green: {
  3421. idx: 1,
  3422. type: "byte"
  3423. },
  3424. blue: {
  3425. idx: 2,
  3426. type: "byte"
  3427. }
  3428. }
  3429. },
  3430. hsla: {
  3431. props: {
  3432. hue: {
  3433. idx: 0,
  3434. type: "degrees"
  3435. },
  3436. saturation: {
  3437. idx: 1,
  3438. type: "percent"
  3439. },
  3440. lightness: {
  3441. idx: 2,
  3442. type: "percent"
  3443. }
  3444. }
  3445. }
  3446. },
  3447. propTypes = {
  3448. "byte": {
  3449. floor: true,
  3450. max: 255
  3451. },
  3452. "percent": {
  3453. max: 1
  3454. },
  3455. "degrees": {
  3456. mod: 360,
  3457. floor: true
  3458. }
  3459. },
  3460. support = color.support = {},
  3461. // element for support tests
  3462. supportElem = jQuery( "<p>" )[ 0 ],
  3463. // colors = jQuery.Color.names
  3464. colors,
  3465. // local aliases of functions called often
  3466. each = jQuery.each;
  3467. // determine rgba support immediately
  3468. supportElem.style.cssText = "background-color:rgba(1,1,1,.5)";
  3469. support.rgba = supportElem.style.backgroundColor.indexOf( "rgba" ) > -1;
  3470. // define cache name and alpha properties
  3471. // for rgba and hsla spaces
  3472. each( spaces, function( spaceName, space ) {
  3473. space.cache = "_" + spaceName;
  3474. space.props.alpha = {
  3475. idx: 3,
  3476. type: "percent",
  3477. def: 1
  3478. };
  3479. });
  3480. function clamp( value, prop, allowEmpty ) {
  3481. var type = propTypes[ prop.type ] || {};
  3482. if ( value == null ) {
  3483. return (allowEmpty || !prop.def) ? null : prop.def;
  3484. }
  3485. // ~~ is an short way of doing floor for positive numbers
  3486. value = type.floor ? ~~value : parseFloat( value );
  3487. // IE will pass in empty strings as value for alpha,
  3488. // which will hit this case
  3489. if ( isNaN( value ) ) {
  3490. return prop.def;
  3491. }
  3492. if ( type.mod ) {
  3493. // we add mod before modding to make sure that negatives values
  3494. // get converted properly: -10 -> 350
  3495. return (value + type.mod) % type.mod;
  3496. }
  3497. // for now all property types without mod have min and max
  3498. return 0 > value ? 0 : type.max < value ? type.max : value;
  3499. }
  3500. function stringParse( string ) {
  3501. var inst = color(),
  3502. rgba = inst._rgba = [];
  3503. string = string.toLowerCase();
  3504. each( stringParsers, function( i, parser ) {
  3505. var parsed,
  3506. match = parser.re.exec( string ),
  3507. values = match && parser.parse( match ),
  3508. spaceName = parser.space || "rgba";
  3509. if ( values ) {
  3510. parsed = inst[ spaceName ]( values );
  3511. // if this was an rgba parse the assignment might happen twice
  3512. // oh well....
  3513. inst[ spaces[ spaceName ].cache ] = parsed[ spaces[ spaceName ].cache ];
  3514. rgba = inst._rgba = parsed._rgba;
  3515. // exit each( stringParsers ) here because we matched
  3516. return false;
  3517. }
  3518. });
  3519. // Found a stringParser that handled it
  3520. if ( rgba.length ) {
  3521. // if this came from a parsed string, force "transparent" when alpha is 0
  3522. // chrome, (and maybe others) return "transparent" as rgba(0,0,0,0)
  3523. if ( rgba.join() === "0,0,0,0" ) {
  3524. jQuery.extend( rgba, colors.transparent );
  3525. }
  3526. return inst;
  3527. }
  3528. // named colors
  3529. return colors[ string ];
  3530. }
  3531. color.fn = jQuery.extend( color.prototype, {
  3532. parse: function( red, green, blue, alpha ) {
  3533. if ( red === undefined ) {
  3534. this._rgba = [ null, null, null, null ];
  3535. return this;
  3536. }
  3537. if ( red.jquery || red.nodeType ) {
  3538. red = jQuery( red ).css( green );
  3539. green = undefined;
  3540. }
  3541. var inst = this,
  3542. type = jQuery.type( red ),
  3543. rgba = this._rgba = [],
  3544. source;
  3545. // more than 1 argument specified - assume ( red, green, blue, alpha )
  3546. if ( green !== undefined ) {
  3547. red = [ red, green, blue, alpha ];
  3548. type = "array";
  3549. }
  3550. if ( type === "string" ) {
  3551. return this.parse( stringParse( red ) || colors._default );
  3552. }
  3553. if ( type === "array" ) {
  3554. each( spaces.rgba.props, function( key, prop ) {
  3555. rgba[ prop.idx ] = clamp( red[ prop.idx ], prop );
  3556. });
  3557. return this;
  3558. }
  3559. if ( type === "object" ) {
  3560. if ( red instanceof color ) {
  3561. each( spaces, function( spaceName, space ) {
  3562. if ( red[ space.cache ] ) {
  3563. inst[ space.cache ] = red[ space.cache ].slice();
  3564. }
  3565. });
  3566. } else {
  3567. each( spaces, function( spaceName, space ) {
  3568. var cache = space.cache;
  3569. each( space.props, function( key, prop ) {
  3570. // if the cache doesn't exist, and we know how to convert
  3571. if ( !inst[ cache ] && space.to ) {
  3572. // if the value was null, we don't need to copy it
  3573. // if the key was alpha, we don't need to copy it either
  3574. if ( key === "alpha" || red[ key ] == null ) {
  3575. return;
  3576. }
  3577. inst[ cache ] = space.to( inst._rgba );
  3578. }
  3579. // this is the only case where we allow nulls for ALL properties.
  3580. // call clamp with alwaysAllowEmpty
  3581. inst[ cache ][ prop.idx ] = clamp( red[ key ], prop, true );
  3582. });
  3583. // everything defined but alpha?
  3584. if ( inst[ cache ] && $.inArray( null, inst[ cache ].slice( 0, 3 ) ) < 0 ) {
  3585. // use the default of 1
  3586. inst[ cache ][ 3 ] = 1;
  3587. if ( space.from ) {
  3588. inst._rgba = space.from( inst[ cache ] );
  3589. }
  3590. }
  3591. });
  3592. }
  3593. return this;
  3594. }
  3595. },
  3596. is: function( compare ) {
  3597. var is = color( compare ),
  3598. same = true,
  3599. inst = this;
  3600. each( spaces, function( _, space ) {
  3601. var localCache,
  3602. isCache = is[ space.cache ];
  3603. if (isCache) {
  3604. localCache = inst[ space.cache ] || space.to && space.to( inst._rgba ) || [];
  3605. each( space.props, function( _, prop ) {
  3606. if ( isCache[ prop.idx ] != null ) {
  3607. same = ( isCache[ prop.idx ] === localCache[ prop.idx ] );
  3608. return same;
  3609. }
  3610. });
  3611. }
  3612. return same;
  3613. });
  3614. return same;
  3615. },
  3616. _space: function() {
  3617. var used = [],
  3618. inst = this;
  3619. each( spaces, function( spaceName, space ) {
  3620. if ( inst[ space.cache ] ) {
  3621. used.push( spaceName );
  3622. }
  3623. });
  3624. return used.pop();
  3625. },
  3626. transition: function( other, distance ) {
  3627. var end = color( other ),
  3628. spaceName = end._space(),
  3629. space = spaces[ spaceName ],
  3630. startColor = this.alpha() === 0 ? color( "transparent" ) : this,
  3631. start = startColor[ space.cache ] || space.to( startColor._rgba ),
  3632. result = start.slice();
  3633. end = end[ space.cache ];
  3634. each( space.props, function( key, prop ) {
  3635. var index = prop.idx,
  3636. startValue = start[ index ],
  3637. endValue = end[ index ],
  3638. type = propTypes[ prop.type ] || {};
  3639. // if null, don't override start value
  3640. if ( endValue === null ) {
  3641. return;
  3642. }
  3643. // if null - use end
  3644. if ( startValue === null ) {
  3645. result[ index ] = endValue;
  3646. } else {
  3647. if ( type.mod ) {
  3648. if ( endValue - startValue > type.mod / 2 ) {
  3649. startValue += type.mod;
  3650. } else if ( startValue - endValue > type.mod / 2 ) {
  3651. startValue -= type.mod;
  3652. }
  3653. }
  3654. result[ index ] = clamp( ( endValue - startValue ) * distance + startValue, prop );
  3655. }
  3656. });
  3657. return this[ spaceName ]( result );
  3658. },
  3659. blend: function( opaque ) {
  3660. // if we are already opaque - return ourself
  3661. if ( this._rgba[ 3 ] === 1 ) {
  3662. return this;
  3663. }
  3664. var rgb = this._rgba.slice(),
  3665. a = rgb.pop(),
  3666. blend = color( opaque )._rgba;
  3667. return color( jQuery.map( rgb, function( v, i ) {
  3668. return ( 1 - a ) * blend[ i ] + a * v;
  3669. }));
  3670. },
  3671. toRgbaString: function() {
  3672. var prefix = "rgba(",
  3673. rgba = jQuery.map( this._rgba, function( v, i ) {
  3674. return v == null ? ( i > 2 ? 1 : 0 ) : v;
  3675. });
  3676. if ( rgba[ 3 ] === 1 ) {
  3677. rgba.pop();
  3678. prefix = "rgb(";
  3679. }
  3680. return prefix + rgba.join() + ")";
  3681. },
  3682. toHslaString: function() {
  3683. var prefix = "hsla(",
  3684. hsla = jQuery.map( this.hsla(), function( v, i ) {
  3685. if ( v == null ) {
  3686. v = i > 2 ? 1 : 0;
  3687. }
  3688. // catch 1 and 2
  3689. if ( i && i < 3 ) {
  3690. v = Math.round( v * 100 ) + "%";
  3691. }
  3692. return v;
  3693. });
  3694. if ( hsla[ 3 ] === 1 ) {
  3695. hsla.pop();
  3696. prefix = "hsl(";
  3697. }
  3698. return prefix + hsla.join() + ")";
  3699. },
  3700. toHexString: function( includeAlpha ) {
  3701. var rgba = this._rgba.slice(),
  3702. alpha = rgba.pop();
  3703. if ( includeAlpha ) {
  3704. rgba.push( ~~( alpha * 255 ) );
  3705. }
  3706. return "#" + jQuery.map( rgba, function( v, i ) {
  3707. // default to 0 when nulls exist
  3708. v = ( v || 0 ).toString( 16 );
  3709. return v.length === 1 ? "0" + v : v;
  3710. }).join("");
  3711. },
  3712. toString: function() {
  3713. return this._rgba[ 3 ] === 0 ? "transparent" : this.toRgbaString();
  3714. }
  3715. });
  3716. color.fn.parse.prototype = color.fn;
  3717. // hsla conversions adapted from:
  3718. // https://code.google.com/p/maashaack/source/browse/packages/graphics/trunk/src/graphics/colors/HUE2RGB.as?r=5021
  3719. function hue2rgb( p, q, h ) {
  3720. h = ( h + 1 ) % 1;
  3721. if ( h * 6 < 1 ) {
  3722. return p + (q - p) * h * 6;
  3723. }
  3724. if ( h * 2 < 1) {
  3725. return q;
  3726. }
  3727. if ( h * 3 < 2 ) {
  3728. return p + (q - p) * ((2/3) - h) * 6;
  3729. }
  3730. return p;
  3731. }
  3732. spaces.hsla.to = function ( rgba ) {
  3733. if ( rgba[ 0 ] == null || rgba[ 1 ] == null || rgba[ 2 ] == null ) {
  3734. return [ null, null, null, rgba[ 3 ] ];
  3735. }
  3736. var r = rgba[ 0 ] / 255,
  3737. g = rgba[ 1 ] / 255,
  3738. b = rgba[ 2 ] / 255,
  3739. a = rgba[ 3 ],
  3740. max = Math.max( r, g, b ),
  3741. min = Math.min( r, g, b ),
  3742. diff = max - min,
  3743. add = max + min,
  3744. l = add * 0.5,
  3745. h, s;
  3746. if ( min === max ) {
  3747. h = 0;
  3748. } else if ( r === max ) {
  3749. h = ( 60 * ( g - b ) / diff ) + 360;
  3750. } else if ( g === max ) {
  3751. h = ( 60 * ( b - r ) / diff ) + 120;
  3752. } else {
  3753. h = ( 60 * ( r - g ) / diff ) + 240;
  3754. }
  3755. if ( l === 0 || l === 1 ) {
  3756. s = l;
  3757. } else if ( l <= 0.5 ) {
  3758. s = diff / add;
  3759. } else {
  3760. s = diff / ( 2 - add );
  3761. }
  3762. return [ Math.round(h) % 360, s, l, a == null ? 1 : a ];
  3763. };
  3764. spaces.hsla.from = function ( hsla ) {
  3765. if ( hsla[ 0 ] == null || hsla[ 1 ] == null || hsla[ 2 ] == null ) {
  3766. return [ null, null, null, hsla[ 3 ] ];
  3767. }
  3768. var h = hsla[ 0 ] / 360,
  3769. s = hsla[ 1 ],
  3770. l = hsla[ 2 ],
  3771. a = hsla[ 3 ],
  3772. q = l <= 0.5 ? l * ( 1 + s ) : l + s - l * s,
  3773. p = 2 * l - q,
  3774. r, g, b;
  3775. return [
  3776. Math.round( hue2rgb( p, q, h + ( 1 / 3 ) ) * 255 ),
  3777. Math.round( hue2rgb( p, q, h ) * 255 ),
  3778. Math.round( hue2rgb( p, q, h - ( 1 / 3 ) ) * 255 ),
  3779. a
  3780. ];
  3781. };
  3782. each( spaces, function( spaceName, space ) {
  3783. var props = space.props,
  3784. cache = space.cache,
  3785. to = space.to,
  3786. from = space.from;
  3787. // makes rgba() and hsla()
  3788. color.fn[ spaceName ] = function( value ) {
  3789. // generate a cache for this space if it doesn't exist
  3790. if ( to && !this[ cache ] ) {
  3791. this[ cache ] = to( this._rgba );
  3792. }
  3793. if ( value === undefined ) {
  3794. return this[ cache ].slice();
  3795. }
  3796. var ret,
  3797. type = jQuery.type( value ),
  3798. arr = ( type === "array" || type === "object" ) ? value : arguments,
  3799. local = this[ cache ].slice();
  3800. each( props, function( key, prop ) {
  3801. var val = arr[ type === "object" ? key : prop.idx ];
  3802. if ( val == null ) {
  3803. val = local[ prop.idx ];
  3804. }
  3805. local[ prop.idx ] = clamp( val, prop );
  3806. });
  3807. if ( from ) {
  3808. ret = color( from( local ) );
  3809. ret[ cache ] = local;
  3810. return ret;
  3811. } else {
  3812. return color( local );
  3813. }
  3814. };
  3815. // makes red() green() blue() alpha() hue() saturation() lightness()
  3816. each( props, function( key, prop ) {
  3817. // alpha is included in more than one space
  3818. if ( color.fn[ key ] ) {
  3819. return;
  3820. }
  3821. color.fn[ key ] = function( value ) {
  3822. var vtype = jQuery.type( value ),
  3823. fn = ( key === "alpha" ? ( this._hsla ? "hsla" : "rgba" ) : spaceName ),
  3824. local = this[ fn ](),
  3825. cur = local[ prop.idx ],
  3826. match;
  3827. if ( vtype === "undefined" ) {
  3828. return cur;
  3829. }
  3830. if ( vtype === "function" ) {
  3831. value = value.call( this, cur );
  3832. vtype = jQuery.type( value );
  3833. }
  3834. if ( value == null && prop.empty ) {
  3835. return this;
  3836. }
  3837. if ( vtype === "string" ) {
  3838. match = rplusequals.exec( value );
  3839. if ( match ) {
  3840. value = cur + parseFloat( match[ 2 ] ) * ( match[ 1 ] === "+" ? 1 : -1 );
  3841. }
  3842. }
  3843. local[ prop.idx ] = value;
  3844. return this[ fn ]( local );
  3845. };
  3846. });
  3847. });
  3848. // add .fx.step functions
  3849. each( stepHooks, function( i, hook ) {
  3850. jQuery.cssHooks[ hook ] = {
  3851. set: function( elem, value ) {
  3852. var parsed, curElem,
  3853. backgroundColor = "";
  3854. if ( jQuery.type( value ) !== "string" || ( parsed = stringParse( value ) ) ) {
  3855. value = color( parsed || value );
  3856. if ( !support.rgba && value._rgba[ 3 ] !== 1 ) {
  3857. curElem = hook === "backgroundColor" ? elem.parentNode : elem;
  3858. while (
  3859. (backgroundColor === "" || backgroundColor === "transparent") &&
  3860. curElem && curElem.style
  3861. ) {
  3862. try {
  3863. backgroundColor = jQuery.css( curElem, "backgroundColor" );
  3864. curElem = curElem.parentNode;
  3865. } catch ( e ) {
  3866. }
  3867. }
  3868. value = value.blend( backgroundColor && backgroundColor !== "transparent" ?
  3869. backgroundColor :
  3870. "_default" );
  3871. }
  3872. value = value.toRgbaString();
  3873. }
  3874. try {
  3875. elem.style[ hook ] = value;
  3876. } catch( value ) {
  3877. // wrapped to prevent IE from throwing errors on "invalid" values like 'auto' or 'inherit'
  3878. }
  3879. }
  3880. };
  3881. jQuery.fx.step[ hook ] = function( fx ) {
  3882. if ( !fx.colorInit ) {
  3883. fx.start = color( fx.elem, hook );
  3884. fx.end = color( fx.end );
  3885. fx.colorInit = true;
  3886. }
  3887. jQuery.cssHooks[ hook ].set( fx.elem, fx.start.transition( fx.end, fx.pos ) );
  3888. };
  3889. });
  3890. jQuery.cssHooks.borderColor = {
  3891. expand: function( value ) {
  3892. var expanded = {};
  3893. each( [ "Top", "Right", "Bottom", "Left" ], function( i, part ) {
  3894. expanded[ "border" + part + "Color" ] = value;
  3895. });
  3896. return expanded;
  3897. }
  3898. };
  3899. // Basic color names only.
  3900. // Usage of any of the other color names requires adding yourself or including
  3901. // jquery.color.svg-names.js.
  3902. colors = jQuery.Color.names = {
  3903. // 4.1. Basic color keywords
  3904. aqua: "#00ffff",
  3905. black: "#000000",
  3906. blue: "#0000ff",
  3907. fuchsia: "#ff00ff",
  3908. gray: "#808080",
  3909. green: "#008000",
  3910. lime: "#00ff00",
  3911. maroon: "#800000",
  3912. navy: "#000080",
  3913. olive: "#808000",
  3914. purple: "#800080",
  3915. red: "#ff0000",
  3916. silver: "#c0c0c0",
  3917. teal: "#008080",
  3918. white: "#ffffff",
  3919. yellow: "#ffff00",
  3920. // 4.2.3. "transparent" color keyword
  3921. transparent: [ null, null, null, 0 ],
  3922. _default: "#ffffff"
  3923. };
  3924. })( jQuery );
  3925. /******************************************************************************/
  3926. /****************************** CLASS ANIMATIONS ******************************/
  3927. /******************************************************************************/
  3928. (function() {
  3929. var classAnimationActions = [ "add", "remove", "toggle" ],
  3930. shorthandStyles = {
  3931. border: 1,
  3932. borderBottom: 1,
  3933. borderColor: 1,
  3934. borderLeft: 1,
  3935. borderRight: 1,
  3936. borderTop: 1,
  3937. borderWidth: 1,
  3938. margin: 1,
  3939. padding: 1
  3940. };
  3941. $.each([ "borderLeftStyle", "borderRightStyle", "borderBottomStyle", "borderTopStyle" ], function( _, prop ) {
  3942. $.fx.step[ prop ] = function( fx ) {
  3943. if ( fx.end !== "none" && !fx.setAttr || fx.pos === 1 && !fx.setAttr ) {
  3944. jQuery.style( fx.elem, prop, fx.end );
  3945. fx.setAttr = true;
  3946. }
  3947. };
  3948. });
  3949. function getElementStyles() {
  3950. var style = this.ownerDocument.defaultView ?
  3951. this.ownerDocument.defaultView.getComputedStyle( this, null ) :
  3952. this.currentStyle,
  3953. newStyle = {},
  3954. key,
  3955. camelCase,
  3956. len;
  3957. // webkit enumerates style porperties
  3958. if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {
  3959. len = style.length;
  3960. while ( len-- ) {
  3961. key = style[ len ];
  3962. if ( typeof style[ key ] === "string" ) {
  3963. newStyle[ $.camelCase( key ) ] = style[ key ];
  3964. }
  3965. }
  3966. } else {
  3967. for ( key in style ) {
  3968. if ( typeof style[ key ] === "string" ) {
  3969. newStyle[ key ] = style[ key ];
  3970. }
  3971. }
  3972. }
  3973. return newStyle;
  3974. }
  3975. function styleDifference( oldStyle, newStyle ) {
  3976. var diff = {},
  3977. name, value;
  3978. for ( name in newStyle ) {
  3979. value = newStyle[ name ];
  3980. if ( oldStyle[ name ] !== value ) {
  3981. if ( !shorthandStyles[ name ] ) {
  3982. if ( $.fx.step[ name ] || !isNaN( parseFloat( value ) ) ) {
  3983. diff[ name ] = value;
  3984. }
  3985. }
  3986. }
  3987. }
  3988. return diff;
  3989. }
  3990. $.effects.animateClass = function( value, duration, easing, callback ) {
  3991. var o = $.speed( duration, easing, callback );
  3992. return this.queue( function() {
  3993. var animated = $( this ),
  3994. baseClass = animated.attr( "class" ) || "",
  3995. applyClassChange,
  3996. allAnimations = o.children ? animated.find( "*" ).andSelf() : animated;
  3997. // map the animated objects to store the original styles.
  3998. allAnimations = allAnimations.map(function() {
  3999. var el = $( this );
  4000. return {
  4001. el: el,
  4002. start: getElementStyles.call( this )
  4003. };
  4004. });
  4005. // apply class change
  4006. applyClassChange = function() {
  4007. $.each( classAnimationActions, function(i, action) {
  4008. if ( value[ action ] ) {
  4009. animated[ action + "Class" ]( value[ action ] );
  4010. }
  4011. });
  4012. };
  4013. applyClassChange();
  4014. // map all animated objects again - calculate new styles and diff
  4015. allAnimations = allAnimations.map(function() {
  4016. this.end = getElementStyles.call( this.el[ 0 ] );
  4017. this.diff = styleDifference( this.start, this.end );
  4018. return this;
  4019. });
  4020. // apply original class
  4021. animated.attr( "class", baseClass );
  4022. // map all animated objects again - this time collecting a promise
  4023. allAnimations = allAnimations.map(function() {
  4024. var styleInfo = this,
  4025. dfd = $.Deferred(),
  4026. opts = jQuery.extend({}, o, {
  4027. queue: false,
  4028. complete: function() {
  4029. dfd.resolve( styleInfo );
  4030. }
  4031. });
  4032. this.el.animate( this.diff, opts );
  4033. return dfd.promise();
  4034. });
  4035. // once all animations have completed:
  4036. $.when.apply( $, allAnimations.get() ).done(function() {
  4037. // set the final class
  4038. applyClassChange();
  4039. // for each animated element,
  4040. // clear all css properties that were animated
  4041. $.each( arguments, function() {
  4042. var el = this.el;
  4043. $.each( this.diff, function(key) {
  4044. el.css( key, '' );
  4045. });
  4046. });
  4047. // this is guarnteed to be there if you use jQuery.speed()
  4048. // it also handles dequeuing the next anim...
  4049. o.complete.call( animated[ 0 ] );
  4050. });
  4051. });
  4052. };
  4053. $.fn.extend({
  4054. _addClass: $.fn.addClass,
  4055. addClass: function( classNames, speed, easing, callback ) {
  4056. return speed ?
  4057. $.effects.animateClass.call( this,
  4058. { add: classNames }, speed, easing, callback ) :
  4059. this._addClass( classNames );
  4060. },
  4061. _removeClass: $.fn.removeClass,
  4062. removeClass: function( classNames, speed, easing, callback ) {
  4063. return speed ?
  4064. $.effects.animateClass.call( this,
  4065. { remove: classNames }, speed, easing, callback ) :
  4066. this._removeClass( classNames );
  4067. },
  4068. _toggleClass: $.fn.toggleClass,
  4069. toggleClass: function( classNames, force, speed, easing, callback ) {
  4070. if ( typeof force === "boolean" || force === undefined ) {
  4071. if ( !speed ) {
  4072. // without speed parameter
  4073. return this._toggleClass( classNames, force );
  4074. } else {
  4075. return $.effects.animateClass.call( this,
  4076. (force ? { add: classNames } : { remove: classNames }),
  4077. speed, easing, callback );
  4078. }
  4079. } else {
  4080. // without force parameter
  4081. return $.effects.animateClass.call( this,
  4082. { toggle: classNames }, force, speed, easing );
  4083. }
  4084. },
  4085. switchClass: function( remove, add, speed, easing, callback) {
  4086. return $.effects.animateClass.call( this, {
  4087. add: add,
  4088. remove: remove
  4089. }, speed, easing, callback );
  4090. }
  4091. });
  4092. })();
  4093. /******************************************************************************/
  4094. /*********************************** EFFECTS **********************************/
  4095. /******************************************************************************/
  4096. (function() {
  4097. $.extend( $.effects, {
  4098. version: "1.9.0",
  4099. // Saves a set of properties in a data storage
  4100. save: function( element, set ) {
  4101. for( var i=0; i < set.length; i++ ) {
  4102. if ( set[ i ] !== null ) {
  4103. element.data( dataSpace + set[ i ], element[ 0 ].style[ set[ i ] ] );
  4104. }
  4105. }
  4106. },
  4107. // Restores a set of previously saved properties from a data storage
  4108. restore: function( element, set ) {
  4109. var val, i;
  4110. for( i=0; i < set.length; i++ ) {
  4111. if ( set[ i ] !== null ) {
  4112. val = element.data( dataSpace + set[ i ] );
  4113. // support: jQuery 1.6.2
  4114. // http://bugs.jquery.com/ticket/9917
  4115. // jQuery 1.6.2 incorrectly returns undefined for any falsy value.
  4116. // We can't differentiate between "" and 0 here, so we just assume
  4117. // empty string since it's likely to be a more common value...
  4118. if ( val === undefined ) {
  4119. val = "";
  4120. }
  4121. element.css( set[ i ], val );
  4122. }
  4123. }
  4124. },
  4125. setMode: function( el, mode ) {
  4126. if (mode === "toggle") {
  4127. mode = el.is( ":hidden" ) ? "show" : "hide";
  4128. }
  4129. return mode;
  4130. },
  4131. // Translates a [top,left] array into a baseline value
  4132. // this should be a little more flexible in the future to handle a string & hash
  4133. getBaseline: function( origin, original ) {
  4134. var y, x;
  4135. switch ( origin[ 0 ] ) {
  4136. case "top": y = 0; break;
  4137. case "middle": y = 0.5; break;
  4138. case "bottom": y = 1; break;
  4139. default: y = origin[ 0 ] / original.height;
  4140. }
  4141. switch ( origin[ 1 ] ) {
  4142. case "left": x = 0; break;
  4143. case "center": x = 0.5; break;
  4144. case "right": x = 1; break;
  4145. default: x = origin[ 1 ] / original.width;
  4146. }
  4147. return {
  4148. x: x,
  4149. y: y
  4150. };
  4151. },
  4152. // Wraps the element around a wrapper that copies position properties
  4153. createWrapper: function( element ) {
  4154. // if the element is already wrapped, return it
  4155. if ( element.parent().is( ".ui-effects-wrapper" )) {
  4156. return element.parent();
  4157. }
  4158. // wrap the element
  4159. var props = {
  4160. width: element.outerWidth(true),
  4161. height: element.outerHeight(true),
  4162. "float": element.css( "float" )
  4163. },
  4164. wrapper = $( "<div></div>" )
  4165. .addClass( "ui-effects-wrapper" )
  4166. .css({
  4167. fontSize: "100%",
  4168. background: "transparent",
  4169. border: "none",
  4170. margin: 0,
  4171. padding: 0
  4172. }),
  4173. // Store the size in case width/height are defined in % - Fixes #5245
  4174. size = {
  4175. width: element.width(),
  4176. height: element.height()
  4177. },
  4178. active = document.activeElement;
  4179. // support: Firefox
  4180. // Firefox incorrectly exposes anonymous content
  4181. // https://bugzilla.mozilla.org/show_bug.cgi?id=561664
  4182. try {
  4183. active.id;
  4184. } catch( e ) {
  4185. active = document.body;
  4186. }
  4187. element.wrap( wrapper );
  4188. // Fixes #7595 - Elements lose focus when wrapped.
  4189. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  4190. $( active ).focus();
  4191. }
  4192. wrapper = element.parent(); //Hotfix for jQuery 1.4 since some change in wrap() seems to actually lose the reference to the wrapped element
  4193. // transfer positioning properties to the wrapper
  4194. if ( element.css( "position" ) === "static" ) {
  4195. wrapper.css({ position: "relative" });
  4196. element.css({ position: "relative" });
  4197. } else {
  4198. $.extend( props, {
  4199. position: element.css( "position" ),
  4200. zIndex: element.css( "z-index" )
  4201. });
  4202. $.each([ "top", "left", "bottom", "right" ], function(i, pos) {
  4203. props[ pos ] = element.css( pos );
  4204. if ( isNaN( parseInt( props[ pos ], 10 ) ) ) {
  4205. props[ pos ] = "auto";
  4206. }
  4207. });
  4208. element.css({
  4209. position: "relative",
  4210. top: 0,
  4211. left: 0,
  4212. right: "auto",
  4213. bottom: "auto"
  4214. });
  4215. }
  4216. element.css(size);
  4217. return wrapper.css( props ).show();
  4218. },
  4219. removeWrapper: function( element ) {
  4220. var active = document.activeElement;
  4221. if ( element.parent().is( ".ui-effects-wrapper" ) ) {
  4222. element.parent().replaceWith( element );
  4223. // Fixes #7595 - Elements lose focus when wrapped.
  4224. if ( element[ 0 ] === active || $.contains( element[ 0 ], active ) ) {
  4225. $( active ).focus();
  4226. }
  4227. }
  4228. return element;
  4229. },
  4230. setTransition: function( element, list, factor, value ) {
  4231. value = value || {};
  4232. $.each( list, function( i, x ) {
  4233. var unit = element.cssUnit( x );
  4234. if ( unit[ 0 ] > 0 ) {
  4235. value[ x ] = unit[ 0 ] * factor + unit[ 1 ];
  4236. }
  4237. });
  4238. return value;
  4239. }
  4240. });
  4241. // return an effect options object for the given parameters:
  4242. function _normalizeArguments( effect, options, speed, callback ) {
  4243. // allow passing all optinos as the first parameter
  4244. if ( $.isPlainObject( effect ) ) {
  4245. options = effect;
  4246. effect = effect.effect;
  4247. }
  4248. // convert to an object
  4249. effect = { effect: effect };
  4250. // catch (effect)
  4251. if ( options === undefined ) {
  4252. options = {};
  4253. }
  4254. // catch (effect, callback)
  4255. if ( $.isFunction( options ) ) {
  4256. callback = options;
  4257. speed = null;
  4258. options = {};
  4259. }
  4260. // catch (effect, speed, ?)
  4261. if ( typeof options === "number" || $.fx.speeds[ options ] ) {
  4262. callback = speed;
  4263. speed = options;
  4264. options = {};
  4265. }
  4266. // catch (effect, options, callback)
  4267. if ( $.isFunction( speed ) ) {
  4268. callback = speed;
  4269. speed = null;
  4270. }
  4271. // add options to effect
  4272. if ( options ) {
  4273. $.extend( effect, options );
  4274. }
  4275. speed = speed || options.duration;
  4276. effect.duration = $.fx.off ? 0 :
  4277. typeof speed === "number" ? speed :
  4278. speed in $.fx.speeds ? $.fx.speeds[ speed ] :
  4279. $.fx.speeds._default;
  4280. effect.complete = callback || options.complete;
  4281. return effect;
  4282. }
  4283. function standardSpeed( speed ) {
  4284. // valid standard speeds
  4285. if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) {
  4286. return true;
  4287. }
  4288. // invalid strings - treat as "normal" speed
  4289. if ( typeof speed === "string" && !$.effects.effect[ speed ] ) {
  4290. // TODO: remove in 2.0 (#7115)
  4291. if ( backCompat && $.effects[ speed ] ) {
  4292. return false;
  4293. }
  4294. return true;
  4295. }
  4296. return false;
  4297. }
  4298. $.fn.extend({
  4299. effect: function( effect, options, speed, callback ) {
  4300. var args = _normalizeArguments.apply( this, arguments ),
  4301. mode = args.mode,
  4302. queue = args.queue,
  4303. effectMethod = $.effects.effect[ args.effect ],
  4304. // DEPRECATED: remove in 2.0 (#7115)
  4305. oldEffectMethod = !effectMethod && backCompat && $.effects[ args.effect ];
  4306. if ( $.fx.off || !( effectMethod || oldEffectMethod ) ) {
  4307. // delegate to the original method (e.g., .show()) if possible
  4308. if ( mode ) {
  4309. return this[ mode ]( args.duration, args.complete );
  4310. } else {
  4311. return this.each( function() {
  4312. if ( args.complete ) {
  4313. args.complete.call( this );
  4314. }
  4315. });
  4316. }
  4317. }
  4318. function run( next ) {
  4319. var elem = $( this ),
  4320. complete = args.complete,
  4321. mode = args.mode;
  4322. function done() {
  4323. if ( $.isFunction( complete ) ) {
  4324. complete.call( elem[0] );
  4325. }
  4326. if ( $.isFunction( next ) ) {
  4327. next();
  4328. }
  4329. }
  4330. // if the element is hiddden and mode is hide,
  4331. // or element is visible and mode is show
  4332. if ( elem.is( ":hidden" ) ? mode === "hide" : mode === "show" ) {
  4333. done();
  4334. } else {
  4335. effectMethod.call( elem[0], args, done );
  4336. }
  4337. }
  4338. // TODO: remove this check in 2.0, effectMethod will always be true
  4339. if ( effectMethod ) {
  4340. return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
  4341. } else {
  4342. // DEPRECATED: remove in 2.0 (#7115)
  4343. return oldEffectMethod.call(this, {
  4344. options: args,
  4345. duration: args.duration,
  4346. callback: args.complete,
  4347. mode: args.mode
  4348. });
  4349. }
  4350. },
  4351. _show: $.fn.show,
  4352. show: function( speed ) {
  4353. if ( standardSpeed( speed ) ) {
  4354. return this._show.apply( this, arguments );
  4355. } else {
  4356. var args = _normalizeArguments.apply( this, arguments );
  4357. args.mode = "show";
  4358. return this.effect.call( this, args );
  4359. }
  4360. },
  4361. _hide: $.fn.hide,
  4362. hide: function( speed ) {
  4363. if ( standardSpeed( speed ) ) {
  4364. return this._hide.apply( this, arguments );
  4365. } else {
  4366. var args = _normalizeArguments.apply( this, arguments );
  4367. args.mode = "hide";
  4368. return this.effect.call( this, args );
  4369. }
  4370. },
  4371. // jQuery core overloads toggle and creates _toggle
  4372. __toggle: $.fn.toggle,
  4373. toggle: function( speed ) {
  4374. if ( standardSpeed( speed ) || typeof speed === "boolean" || $.isFunction( speed ) ) {
  4375. return this.__toggle.apply( this, arguments );
  4376. } else {
  4377. var args = _normalizeArguments.apply( this, arguments );
  4378. args.mode = "toggle";
  4379. return this.effect.call( this, args );
  4380. }
  4381. },
  4382. // helper functions
  4383. cssUnit: function(key) {
  4384. var style = this.css( key ),
  4385. val = [];
  4386. $.each( [ "em", "px", "%", "pt" ], function( i, unit ) {
  4387. if ( style.indexOf( unit ) > 0 ) {
  4388. val = [ parseFloat( style ), unit ];
  4389. }
  4390. });
  4391. return val;
  4392. }
  4393. });
  4394. })();
  4395. /******************************************************************************/
  4396. /*********************************** EASING ***********************************/
  4397. /******************************************************************************/
  4398. (function() {
  4399. // based on easing equations from Robert Penner (http://www.robertpenner.com/easing)
  4400. var baseEasings = {};
  4401. $.each( [ "Quad", "Cubic", "Quart", "Quint", "Expo" ], function( i, name ) {
  4402. baseEasings[ name ] = function( p ) {
  4403. return Math.pow( p, i + 2 );
  4404. };
  4405. });
  4406. $.extend( baseEasings, {
  4407. Sine: function ( p ) {
  4408. return 1 - Math.cos( p * Math.PI / 2 );
  4409. },
  4410. Circ: function ( p ) {
  4411. return 1 - Math.sqrt( 1 - p * p );
  4412. },
  4413. Elastic: function( p ) {
  4414. return p === 0 || p === 1 ? p :
  4415. -Math.pow( 2, 8 * (p - 1) ) * Math.sin( ( (p - 1) * 80 - 7.5 ) * Math.PI / 15 );
  4416. },
  4417. Back: function( p ) {
  4418. return p * p * ( 3 * p - 2 );
  4419. },
  4420. Bounce: function ( p ) {
  4421. var pow2,
  4422. bounce = 4;
  4423. while ( p < ( ( pow2 = Math.pow( 2, --bounce ) ) - 1 ) / 11 ) {}
  4424. return 1 / Math.pow( 4, 3 - bounce ) - 7.5625 * Math.pow( ( pow2 * 3 - 2 ) / 22 - p, 2 );
  4425. }
  4426. });
  4427. $.each( baseEasings, function( name, easeIn ) {
  4428. $.easing[ "easeIn" + name ] = easeIn;
  4429. $.easing[ "easeOut" + name ] = function( p ) {
  4430. return 1 - easeIn( 1 - p );
  4431. };
  4432. $.easing[ "easeInOut" + name ] = function( p ) {
  4433. return p < 0.5 ?
  4434. easeIn( p * 2 ) / 2 :
  4435. 1 - easeIn( p * -2 + 2 ) / 2;
  4436. };
  4437. });
  4438. })();
  4439. })(jQuery));
  4440. (function( $, undefined ) {
  4441. var uid = 0,
  4442. hideProps = {},
  4443. showProps = {};
  4444. hideProps.height = hideProps.paddingTop = hideProps.paddingBottom =
  4445. hideProps.borderTopWidth = hideProps.borderBottomWidth = "hide";
  4446. showProps.height = showProps.paddingTop = showProps.paddingBottom =
  4447. showProps.borderTopWidth = showProps.borderBottomWidth = "show";
  4448. $.widget( "ui.accordion", {
  4449. version: "1.9.0",
  4450. options: {
  4451. active: 0,
  4452. animate: {},
  4453. collapsible: false,
  4454. event: "click",
  4455. header: "> li > :first-child,> :not(li):even",
  4456. heightStyle: "auto",
  4457. icons: {
  4458. activeHeader: "ui-icon-triangle-1-s",
  4459. header: "ui-icon-triangle-1-e"
  4460. },
  4461. // callbacks
  4462. activate: null,
  4463. beforeActivate: null
  4464. },
  4465. _create: function() {
  4466. var accordionId = this.accordionId = "ui-accordion-" +
  4467. (this.element.attr( "id" ) || ++uid),
  4468. options = this.options;
  4469. this.prevShow = this.prevHide = $();
  4470. this.element.addClass( "ui-accordion ui-widget ui-helper-reset" );
  4471. this.headers = this.element.find( options.header )
  4472. .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" );
  4473. this._hoverable( this.headers );
  4474. this._focusable( this.headers );
  4475. this.headers.next()
  4476. .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" )
  4477. .hide();
  4478. // don't allow collapsible: false and active: false
  4479. if ( !options.collapsible && options.active === false ) {
  4480. options.active = 0;
  4481. }
  4482. // handle negative values
  4483. if ( options.active < 0 ) {
  4484. options.active += this.headers.length;
  4485. }
  4486. this.active = this._findActive( options.active )
  4487. .addClass( "ui-accordion-header-active ui-state-active" )
  4488. .toggleClass( "ui-corner-all ui-corner-top" );
  4489. this.active.next()
  4490. .addClass( "ui-accordion-content-active" )
  4491. .show();
  4492. this._createIcons();
  4493. this.originalHeight = this.element[0].style.height;
  4494. this.refresh();
  4495. // ARIA
  4496. this.element.attr( "role", "tablist" );
  4497. this.headers
  4498. .attr( "role", "tab" )
  4499. .each(function( i ) {
  4500. var header = $( this ),
  4501. headerId = header.attr( "id" ),
  4502. panel = header.next(),
  4503. panelId = panel.attr( "id" );
  4504. if ( !headerId ) {
  4505. headerId = accordionId + "-header-" + i;
  4506. header.attr( "id", headerId );
  4507. }
  4508. if ( !panelId ) {
  4509. panelId = accordionId + "-panel-" + i;
  4510. panel.attr( "id", panelId );
  4511. }
  4512. header.attr( "aria-controls", panelId );
  4513. panel.attr( "aria-labelledby", headerId );
  4514. })
  4515. .next()
  4516. .attr( "role", "tabpanel" );
  4517. this.headers
  4518. .not( this.active )
  4519. .attr({
  4520. "aria-selected": "false",
  4521. tabIndex: -1
  4522. })
  4523. .next()
  4524. .attr({
  4525. "aria-expanded": "false",
  4526. "aria-hidden": "true"
  4527. })
  4528. .hide();
  4529. // make sure at least one header is in the tab order
  4530. if ( !this.active.length ) {
  4531. this.headers.eq( 0 ).attr( "tabIndex", 0 );
  4532. } else {
  4533. this.active.attr({
  4534. "aria-selected": "true",
  4535. tabIndex: 0
  4536. })
  4537. .next()
  4538. .attr({
  4539. "aria-expanded": "true",
  4540. "aria-hidden": "false"
  4541. });
  4542. }
  4543. this._on( this.headers, { keydown: "_keydown" });
  4544. this._on( this.headers.next(), { keydown: "_panelKeyDown" });
  4545. this._setupEvents( options.event );
  4546. },
  4547. _getCreateEventData: function() {
  4548. return {
  4549. header: this.active,
  4550. content: !this.active.length ? $() : this.active.next()
  4551. };
  4552. },
  4553. _createIcons: function() {
  4554. var icons = this.options.icons;
  4555. if ( icons ) {
  4556. $( "<span>" )
  4557. .addClass( "ui-accordion-header-icon ui-icon " + icons.header )
  4558. .prependTo( this.headers );
  4559. this.active.children( ".ui-accordion-header-icon" )
  4560. .removeClass( icons.header )
  4561. .addClass( icons.activeHeader );
  4562. this.headers.addClass( "ui-accordion-icons" );
  4563. }
  4564. },
  4565. _destroyIcons: function() {
  4566. this.headers
  4567. .removeClass( "ui-accordion-icons" )
  4568. .children( ".ui-accordion-header-icon" )
  4569. .remove();
  4570. },
  4571. _destroy: function() {
  4572. var contents;
  4573. // clean up main element
  4574. this.element
  4575. .removeClass( "ui-accordion ui-widget ui-helper-reset" )
  4576. .removeAttr( "role" );
  4577. // clean up headers
  4578. this.headers
  4579. .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" )
  4580. .removeAttr( "role" )
  4581. .removeAttr( "aria-selected" )
  4582. .removeAttr( "aria-controls" )
  4583. .removeAttr( "tabIndex" )
  4584. .each(function() {
  4585. if ( /^ui-accordion/.test( this.id ) ) {
  4586. this.removeAttribute( "id" );
  4587. }
  4588. });
  4589. this._destroyIcons();
  4590. // clean up content panels
  4591. contents = this.headers.next()
  4592. .css( "display", "" )
  4593. .removeAttr( "role" )
  4594. .removeAttr( "aria-expanded" )
  4595. .removeAttr( "aria-hidden" )
  4596. .removeAttr( "aria-labelledby" )
  4597. .removeClass( "ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active ui-state-disabled" )
  4598. .each(function() {
  4599. if ( /^ui-accordion/.test( this.id ) ) {
  4600. this.removeAttribute( "id" );
  4601. }
  4602. });
  4603. if ( this.options.heightStyle !== "content" ) {
  4604. this.element.css( "height", this.originalHeight );
  4605. contents.css( "height", "" );
  4606. }
  4607. },
  4608. _setOption: function( key, value ) {
  4609. if ( key === "active" ) {
  4610. // _activate() will handle invalid values and update this.options
  4611. this._activate( value );
  4612. return;
  4613. }
  4614. if ( key === "event" ) {
  4615. if ( this.options.event ) {
  4616. this._off( this.headers, this.options.event );
  4617. }
  4618. this._setupEvents( value );
  4619. }
  4620. this._super( key, value );
  4621. // setting collapsible: false while collapsed; open first panel
  4622. if ( key === "collapsible" && !value && this.options.active === false ) {
  4623. this._activate( 0 );
  4624. }
  4625. if ( key === "icons" ) {
  4626. this._destroyIcons();
  4627. if ( value ) {
  4628. this._createIcons();
  4629. }
  4630. }
  4631. // #5332 - opacity doesn't cascade to positioned elements in IE
  4632. // so we need to add the disabled class to the headers and panels
  4633. if ( key === "disabled" ) {
  4634. this.headers.add( this.headers.next() )
  4635. .toggleClass( "ui-state-disabled", !!value );
  4636. }
  4637. },
  4638. _keydown: function( event ) {
  4639. if ( event.altKey || event.ctrlKey ) {
  4640. return;
  4641. }
  4642. var keyCode = $.ui.keyCode,
  4643. length = this.headers.length,
  4644. currentIndex = this.headers.index( event.target ),
  4645. toFocus = false;
  4646. switch ( event.keyCode ) {
  4647. case keyCode.RIGHT:
  4648. case keyCode.DOWN:
  4649. toFocus = this.headers[ ( currentIndex + 1 ) % length ];
  4650. break;
  4651. case keyCode.LEFT:
  4652. case keyCode.UP:
  4653. toFocus = this.headers[ ( currentIndex - 1 + length ) % length ];
  4654. break;
  4655. case keyCode.SPACE:
  4656. case keyCode.ENTER:
  4657. this._eventHandler( event );
  4658. break;
  4659. case keyCode.HOME:
  4660. toFocus = this.headers[ 0 ];
  4661. break;
  4662. case keyCode.END:
  4663. toFocus = this.headers[ length - 1 ];
  4664. break;
  4665. }
  4666. if ( toFocus ) {
  4667. $( event.target ).attr( "tabIndex", -1 );
  4668. $( toFocus ).attr( "tabIndex", 0 );
  4669. toFocus.focus();
  4670. event.preventDefault();
  4671. }
  4672. },
  4673. _panelKeyDown : function( event ) {
  4674. if ( event.keyCode === $.ui.keyCode.UP && event.ctrlKey ) {
  4675. $( event.currentTarget ).prev().focus();
  4676. }
  4677. },
  4678. refresh: function() {
  4679. var maxHeight, overflow,
  4680. heightStyle = this.options.heightStyle,
  4681. parent = this.element.parent();
  4682. this.element.css( "height", this.originalHeight );
  4683. if ( heightStyle === "fill" ) {
  4684. // IE 6 treats height like minHeight, so we need to turn off overflow
  4685. // in order to get a reliable height
  4686. // we use the minHeight support test because we assume that only
  4687. // browsers that don't support minHeight will treat height as minHeight
  4688. if ( !$.support.minHeight ) {
  4689. overflow = parent.css( "overflow" );
  4690. parent.css( "overflow", "hidden");
  4691. }
  4692. maxHeight = parent.height();
  4693. this.element.siblings( ":visible" ).each(function() {
  4694. var elem = $( this ),
  4695. position = elem.css( "position" );
  4696. if ( position === "absolute" || position === "fixed" ) {
  4697. return;
  4698. }
  4699. maxHeight -= elem.outerHeight( true );
  4700. });
  4701. if ( overflow ) {
  4702. parent.css( "overflow", overflow );
  4703. }
  4704. this.headers.each(function() {
  4705. maxHeight -= $( this ).outerHeight( true );
  4706. });
  4707. this.headers.next()
  4708. .each(function() {
  4709. $( this ).height( Math.max( 0, maxHeight -
  4710. $( this ).innerHeight() + $( this ).height() ) );
  4711. })
  4712. .css( "overflow", "auto" );
  4713. } else if ( heightStyle === "auto" ) {
  4714. maxHeight = 0;
  4715. this.headers.next()
  4716. .each(function() {
  4717. maxHeight = Math.max( maxHeight, $( this ).height( "" ).height() );
  4718. })
  4719. .height( maxHeight );
  4720. }
  4721. if ( heightStyle !== "content" ) {
  4722. this.element.height( this.element.height() );
  4723. }
  4724. },
  4725. _activate: function( index ) {
  4726. var active = this._findActive( index )[ 0 ];
  4727. // trying to activate the already active panel
  4728. if ( active === this.active[ 0 ] ) {
  4729. return;
  4730. }
  4731. // trying to collapse, simulate a click on the currently active header
  4732. active = active || this.active[ 0 ];
  4733. this._eventHandler({
  4734. target: active,
  4735. currentTarget: active,
  4736. preventDefault: $.noop
  4737. });
  4738. },
  4739. _findActive: function( selector ) {
  4740. return typeof selector === "number" ? this.headers.eq( selector ) : $();
  4741. },
  4742. _setupEvents: function( event ) {
  4743. var events = {};
  4744. if ( !event ) {
  4745. return;
  4746. }
  4747. $.each( event.split(" "), function( index, eventName ) {
  4748. events[ eventName ] = "_eventHandler";
  4749. });
  4750. this._on( this.headers, events );
  4751. },
  4752. _eventHandler: function( event ) {
  4753. var options = this.options,
  4754. active = this.active,
  4755. clicked = $( event.currentTarget ),
  4756. clickedIsActive = clicked[ 0 ] === active[ 0 ],
  4757. collapsing = clickedIsActive && options.collapsible,
  4758. toShow = collapsing ? $() : clicked.next(),
  4759. toHide = active.next(),
  4760. eventData = {
  4761. oldHeader: active,
  4762. oldPanel: toHide,
  4763. newHeader: collapsing ? $() : clicked,
  4764. newPanel: toShow
  4765. };
  4766. event.preventDefault();
  4767. if (
  4768. // click on active header, but not collapsible
  4769. ( clickedIsActive && !options.collapsible ) ||
  4770. // allow canceling activation
  4771. ( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
  4772. return;
  4773. }
  4774. options.active = collapsing ? false : this.headers.index( clicked );
  4775. // when the call to ._toggle() comes after the class changes
  4776. // it causes a very odd bug in IE 8 (see #6720)
  4777. this.active = clickedIsActive ? $() : clicked;
  4778. this._toggle( eventData );
  4779. // switch classes
  4780. // corner classes on the previously active header stay after the animation
  4781. active.removeClass( "ui-accordion-header-active ui-state-active" );
  4782. if ( options.icons ) {
  4783. active.children( ".ui-accordion-header-icon" )
  4784. .removeClass( options.icons.activeHeader )
  4785. .addClass( options.icons.header );
  4786. }
  4787. if ( !clickedIsActive ) {
  4788. clicked
  4789. .removeClass( "ui-corner-all" )
  4790. .addClass( "ui-accordion-header-active ui-state-active ui-corner-top" );
  4791. if ( options.icons ) {
  4792. clicked.children( ".ui-accordion-header-icon" )
  4793. .removeClass( options.icons.header )
  4794. .addClass( options.icons.activeHeader );
  4795. }
  4796. clicked
  4797. .next()
  4798. .addClass( "ui-accordion-content-active" );
  4799. }
  4800. },
  4801. _toggle: function( data ) {
  4802. var toShow = data.newPanel,
  4803. toHide = this.prevShow.length ? this.prevShow : data.oldPanel;
  4804. // handle activating a panel during the animation for another activation
  4805. this.prevShow.add( this.prevHide ).stop( true, true );
  4806. this.prevShow = toShow;
  4807. this.prevHide = toHide;
  4808. if ( this.options.animate ) {
  4809. this._animate( toShow, toHide, data );
  4810. } else {
  4811. toHide.hide();
  4812. toShow.show();
  4813. this._toggleComplete( data );
  4814. }
  4815. toHide.attr({
  4816. "aria-expanded": "false",
  4817. "aria-hidden": "true"
  4818. });
  4819. toHide.prev().attr( "aria-selected", "false" );
  4820. // if we're switching panels, remove the old header from the tab order
  4821. // if we're opening from collapsed state, remove the previous header from the tab order
  4822. // if we're collapsing, then keep the collapsing header in the tab order
  4823. if ( toShow.length && toHide.length ) {
  4824. toHide.prev().attr( "tabIndex", -1 );
  4825. } else if ( toShow.length ) {
  4826. this.headers.filter(function() {
  4827. return $( this ).attr( "tabIndex" ) === 0;
  4828. })
  4829. .attr( "tabIndex", -1 );
  4830. }
  4831. toShow
  4832. .attr({
  4833. "aria-expanded": "true",
  4834. "aria-hidden": "false"
  4835. })
  4836. .prev()
  4837. .attr({
  4838. "aria-selected": "true",
  4839. tabIndex: 0
  4840. });
  4841. },
  4842. _animate: function( toShow, toHide, data ) {
  4843. var total, easing, duration,
  4844. that = this,
  4845. adjust = 0,
  4846. down = toShow.length &&
  4847. ( !toHide.length || ( toShow.index() < toHide.index() ) ),
  4848. animate = this.options.animate || {},
  4849. options = down && animate.down || animate,
  4850. complete = function() {
  4851. that._toggleComplete( data );
  4852. };
  4853. if ( typeof options === "number" ) {
  4854. duration = options;
  4855. }
  4856. if ( typeof options === "string" ) {
  4857. easing = options;
  4858. }
  4859. // fall back from options to animation in case of partial down settings
  4860. easing = easing || options.easing || animate.easing;
  4861. duration = duration || options.duration || animate.duration;
  4862. if ( !toHide.length ) {
  4863. return toShow.animate( showProps, duration, easing, complete );
  4864. }
  4865. if ( !toShow.length ) {
  4866. return toHide.animate( hideProps, duration, easing, complete );
  4867. }
  4868. total = toShow.show().outerHeight();
  4869. toHide.animate( hideProps, {
  4870. duration: duration,
  4871. easing: easing,
  4872. step: function( now, fx ) {
  4873. fx.now = Math.round( now );
  4874. }
  4875. });
  4876. toShow
  4877. .hide()
  4878. .animate( showProps, {
  4879. duration: duration,
  4880. easing: easing,
  4881. complete: complete,
  4882. step: function( now, fx ) {
  4883. fx.now = Math.round( now );
  4884. if ( fx.prop !== "height" ) {
  4885. adjust += fx.now;
  4886. } else if ( that.options.heightStyle !== "content" ) {
  4887. fx.now = Math.round( total - toHide.outerHeight() - adjust );
  4888. adjust = 0;
  4889. }
  4890. }
  4891. });
  4892. },
  4893. _toggleComplete: function( data ) {
  4894. var toHide = data.oldPanel;
  4895. toHide
  4896. .removeClass( "ui-accordion-content-active" )
  4897. .prev()
  4898. .removeClass( "ui-corner-top" )
  4899. .addClass( "ui-corner-all" );
  4900. // Work around for rendering bug in IE (#5421)
  4901. if ( toHide.length ) {
  4902. toHide.parent()[0].className = toHide.parent()[0].className;
  4903. }
  4904. this._trigger( "activate", null, data );
  4905. }
  4906. });
  4907. // DEPRECATED
  4908. if ( $.uiBackCompat !== false ) {
  4909. // navigation options
  4910. (function( $, prototype ) {
  4911. $.extend( prototype.options, {
  4912. navigation: false,
  4913. navigationFilter: function() {
  4914. return this.href.toLowerCase() === location.href.toLowerCase();
  4915. }
  4916. });
  4917. var _create = prototype._create;
  4918. prototype._create = function() {
  4919. if ( this.options.navigation ) {
  4920. var that = this,
  4921. headers = this.element.find( this.options.header ),
  4922. content = headers.next(),
  4923. current = headers.add( content )
  4924. .find( "a" )
  4925. .filter( this.options.navigationFilter )
  4926. [ 0 ];
  4927. if ( current ) {
  4928. headers.add( content ).each( function( index ) {
  4929. if ( $.contains( this, current ) ) {
  4930. that.options.active = Math.floor( index / 2 );
  4931. return false;
  4932. }
  4933. });
  4934. }
  4935. }
  4936. _create.call( this );
  4937. };
  4938. }( jQuery, jQuery.ui.accordion.prototype ) );
  4939. // height options
  4940. (function( $, prototype ) {
  4941. $.extend( prototype.options, {
  4942. heightStyle: null, // remove default so we fall back to old values
  4943. autoHeight: true, // use heightStyle: "auto"
  4944. clearStyle: false, // use heightStyle: "content"
  4945. fillSpace: false // use heightStyle: "fill"
  4946. });
  4947. var _create = prototype._create,
  4948. _setOption = prototype._setOption;
  4949. $.extend( prototype, {
  4950. _create: function() {
  4951. this.options.heightStyle = this.options.heightStyle ||
  4952. this._mergeHeightStyle();
  4953. _create.call( this );
  4954. },
  4955. _setOption: function( key, value ) {
  4956. if ( key === "autoHeight" || key === "clearStyle" || key === "fillSpace" ) {
  4957. this.options.heightStyle = this._mergeHeightStyle();
  4958. }
  4959. _setOption.apply( this, arguments );
  4960. },
  4961. _mergeHeightStyle: function() {
  4962. var options = this.options;
  4963. if ( options.fillSpace ) {
  4964. return "fill";
  4965. }
  4966. if ( options.clearStyle ) {
  4967. return "content";
  4968. }
  4969. if ( options.autoHeight ) {
  4970. return "auto";
  4971. }
  4972. }
  4973. });
  4974. }( jQuery, jQuery.ui.accordion.prototype ) );
  4975. // icon options
  4976. (function( $, prototype ) {
  4977. $.extend( prototype.options.icons, {
  4978. activeHeader: null, // remove default so we fall back to old values
  4979. headerSelected: "ui-icon-triangle-1-s"
  4980. });
  4981. var _createIcons = prototype._createIcons;
  4982. prototype._createIcons = function() {
  4983. if ( this.options.icons ) {
  4984. this.options.icons.activeHeader = this.options.icons.activeHeader ||
  4985. this.options.icons.headerSelected;
  4986. }
  4987. _createIcons.call( this );
  4988. };
  4989. }( jQuery, jQuery.ui.accordion.prototype ) );
  4990. // expanded active option, activate method
  4991. (function( $, prototype ) {
  4992. prototype.activate = prototype._activate;
  4993. var _findActive = prototype._findActive;
  4994. prototype._findActive = function( index ) {
  4995. if ( index === -1 ) {
  4996. index = false;
  4997. }
  4998. if ( index && typeof index !== "number" ) {
  4999. index = this.headers.index( this.headers.filter( index ) );
  5000. if ( index === -1 ) {
  5001. index = false;
  5002. }
  5003. }
  5004. return _findActive.call( this, index );
  5005. };
  5006. }( jQuery, jQuery.ui.accordion.prototype ) );
  5007. // resize method
  5008. jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh;
  5009. // change events
  5010. (function( $, prototype ) {
  5011. $.extend( prototype.options, {
  5012. change: null,
  5013. changestart: null
  5014. });
  5015. var _trigger = prototype._trigger;
  5016. prototype._trigger = function( type, event, data ) {
  5017. var ret = _trigger.apply( this, arguments );
  5018. if ( !ret ) {
  5019. return false;
  5020. }
  5021. if ( type === "beforeActivate" ) {
  5022. ret = _trigger.call( this, "changestart", event, {
  5023. oldHeader: data.oldHeader,
  5024. oldContent: data.oldPanel,
  5025. newHeader: data.newHeader,
  5026. newContent: data.newPanel
  5027. });
  5028. } else if ( type === "activate" ) {
  5029. ret = _trigger.call( this, "change", event, {
  5030. oldHeader: data.oldHeader,
  5031. oldContent: data.oldPanel,
  5032. newHeader: data.newHeader,
  5033. newContent: data.newPanel
  5034. });
  5035. }
  5036. return ret;
  5037. };
  5038. }( jQuery, jQuery.ui.accordion.prototype ) );
  5039. // animated option
  5040. // NOTE: this only provides support for "slide", "bounceslide", and easings
  5041. // not the full $.ui.accordion.animations API
  5042. (function( $, prototype ) {
  5043. $.extend( prototype.options, {
  5044. animate: null,
  5045. animated: "slide"
  5046. });
  5047. var _create = prototype._create;
  5048. prototype._create = function() {
  5049. var options = this.options;
  5050. if ( options.animate === null ) {
  5051. if ( !options.animated ) {
  5052. options.animate = false;
  5053. } else if ( options.animated === "slide" ) {
  5054. options.animate = 300;
  5055. } else if ( options.animated === "bounceslide" ) {
  5056. options.animate = {
  5057. duration: 200,
  5058. down: {
  5059. easing: "easeOutBounce",
  5060. duration: 1000
  5061. }
  5062. };
  5063. } else {
  5064. options.animate = options.animated;
  5065. }
  5066. }
  5067. _create.call( this );
  5068. };
  5069. }( jQuery, jQuery.ui.accordion.prototype ) );
  5070. }
  5071. })( jQuery );
  5072. (function( $, undefined ) {
  5073. // used to prevent race conditions with remote data sources
  5074. var requestIndex = 0;
  5075. $.widget( "ui.autocomplete", {
  5076. version: "1.9.0",
  5077. defaultElement: "<input>",
  5078. options: {
  5079. appendTo: "body",
  5080. autoFocus: false,
  5081. delay: 300,
  5082. minLength: 1,
  5083. position: {
  5084. my: "left top",
  5085. at: "left bottom",
  5086. collision: "none"
  5087. },
  5088. source: null,
  5089. // callbacks
  5090. change: null,
  5091. close: null,
  5092. focus: null,
  5093. open: null,
  5094. response: null,
  5095. search: null,
  5096. select: null
  5097. },
  5098. pending: 0,
  5099. _create: function() {
  5100. // Some browsers only repeat keydown events, not keypress events,
  5101. // so we use the suppressKeyPress flag to determine if we've already
  5102. // handled the keydown event. #7269
  5103. // Unfortunately the code for & in keypress is the same as the up arrow,
  5104. // so we use the suppressKeyPressRepeat flag to avoid handling keypress
  5105. // events when we know the keydown event was used to modify the
  5106. // search term. #7799
  5107. var suppressKeyPress, suppressKeyPressRepeat, suppressInput;
  5108. this.isMultiLine = this._isMultiLine();
  5109. this.valueMethod = this.element[ this.element.is( "input,textarea" ) ? "val" : "text" ];
  5110. this.isNewMenu = true;
  5111. this.element
  5112. .addClass( "ui-autocomplete-input" )
  5113. .attr( "autocomplete", "off" );
  5114. this._on({
  5115. keydown: function( event ) {
  5116. if ( this.element.prop( "readOnly" ) ) {
  5117. suppressKeyPress = true;
  5118. suppressInput = true;
  5119. suppressKeyPressRepeat = true;
  5120. return;
  5121. }
  5122. suppressKeyPress = false;
  5123. suppressInput = false;
  5124. suppressKeyPressRepeat = false;
  5125. var keyCode = $.ui.keyCode;
  5126. switch( event.keyCode ) {
  5127. case keyCode.PAGE_UP:
  5128. suppressKeyPress = true;
  5129. this._move( "previousPage", event );
  5130. break;
  5131. case keyCode.PAGE_DOWN:
  5132. suppressKeyPress = true;
  5133. this._move( "nextPage", event );
  5134. break;
  5135. case keyCode.UP:
  5136. suppressKeyPress = true;
  5137. this._keyEvent( "previous", event );
  5138. break;
  5139. case keyCode.DOWN:
  5140. suppressKeyPress = true;
  5141. this._keyEvent( "next", event );
  5142. break;
  5143. case keyCode.ENTER:
  5144. case keyCode.NUMPAD_ENTER:
  5145. // when menu is open and has focus
  5146. if ( this.menu.active ) {
  5147. // #6055 - Opera still allows the keypress to occur
  5148. // which causes forms to submit
  5149. suppressKeyPress = true;
  5150. event.preventDefault();
  5151. this.menu.select( event );
  5152. }
  5153. break;
  5154. case keyCode.TAB:
  5155. if ( this.menu.active ) {
  5156. this.menu.select( event );
  5157. }
  5158. break;
  5159. case keyCode.ESCAPE:
  5160. if ( this.menu.element.is( ":visible" ) ) {
  5161. this._value( this.term );
  5162. this.close( event );
  5163. // Different browsers have different default behavior for escape
  5164. // Single press can mean undo or clear
  5165. // Double press in IE means clear the whole form
  5166. event.preventDefault();
  5167. }
  5168. break;
  5169. default:
  5170. suppressKeyPressRepeat = true;
  5171. // search timeout should be triggered before the input value is changed
  5172. this._searchTimeout( event );
  5173. break;
  5174. }
  5175. },
  5176. keypress: function( event ) {
  5177. if ( suppressKeyPress ) {
  5178. suppressKeyPress = false;
  5179. event.preventDefault();
  5180. return;
  5181. }
  5182. if ( suppressKeyPressRepeat ) {
  5183. return;
  5184. }
  5185. // replicate some key handlers to allow them to repeat in Firefox and Opera
  5186. var keyCode = $.ui.keyCode;
  5187. switch( event.keyCode ) {
  5188. case keyCode.PAGE_UP:
  5189. this._move( "previousPage", event );
  5190. break;
  5191. case keyCode.PAGE_DOWN:
  5192. this._move( "nextPage", event );
  5193. break;
  5194. case keyCode.UP:
  5195. this._keyEvent( "previous", event );
  5196. break;
  5197. case keyCode.DOWN:
  5198. this._keyEvent( "next", event );
  5199. break;
  5200. }
  5201. },
  5202. input: function( event ) {
  5203. if ( suppressInput ) {
  5204. suppressInput = false;
  5205. event.preventDefault();
  5206. return;
  5207. }
  5208. this._searchTimeout( event );
  5209. },
  5210. focus: function() {
  5211. this.selectedItem = null;
  5212. this.previous = this._value();
  5213. },
  5214. blur: function( event ) {
  5215. if ( this.cancelBlur ) {
  5216. delete this.cancelBlur;
  5217. return;
  5218. }
  5219. clearTimeout( this.searching );
  5220. this.close( event );
  5221. this._change( event );
  5222. }
  5223. });
  5224. this._initSource();
  5225. this.menu = $( "<ul>" )
  5226. .addClass( "ui-autocomplete" )
  5227. .appendTo( this.document.find( this.options.appendTo || "body" )[ 0 ] )
  5228. .menu({
  5229. // custom key handling for now
  5230. input: $(),
  5231. // disable ARIA support, the live region takes care of that
  5232. role: null
  5233. })
  5234. .zIndex( this.element.zIndex() + 1 )
  5235. .hide()
  5236. .data( "menu" );
  5237. this._on( this.menu.element, {
  5238. mousedown: function( event ) {
  5239. // prevent moving focus out of the text field
  5240. event.preventDefault();
  5241. // IE doesn't prevent moving focus even with event.preventDefault()
  5242. // so we set a flag to know when we should ignore the blur event
  5243. this.cancelBlur = true;
  5244. this._delay(function() {
  5245. delete this.cancelBlur;
  5246. });
  5247. // clicking on the scrollbar causes focus to shift to the body
  5248. // but we can't detect a mouseup or a click immediately afterward
  5249. // so we have to track the next mousedown and close the menu if
  5250. // the user clicks somewhere outside of the autocomplete
  5251. var menuElement = this.menu.element[ 0 ];
  5252. if ( !$( event.target ).closest( ".ui-menu-item" ).length ) {
  5253. this._delay(function() {
  5254. var that = this;
  5255. this.document.one( "mousedown", function( event ) {
  5256. if ( event.target !== that.element[ 0 ] &&
  5257. event.target !== menuElement &&
  5258. !$.contains( menuElement, event.target ) ) {
  5259. that.close();
  5260. }
  5261. });
  5262. });
  5263. }
  5264. },
  5265. menufocus: function( event, ui ) {
  5266. // #7024 - Prevent accidental activation of menu items in Firefox
  5267. if ( this.isNewMenu ) {
  5268. this.isNewMenu = false;
  5269. if ( event.originalEvent && /^mouse/.test( event.originalEvent.type ) ) {
  5270. this.menu.blur();
  5271. this.document.one( "mousemove", function() {
  5272. $( event.target ).trigger( event.originalEvent );
  5273. });
  5274. return;
  5275. }
  5276. }
  5277. // back compat for _renderItem using item.autocomplete, via #7810
  5278. // TODO remove the fallback, see #8156
  5279. var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" );
  5280. if ( false !== this._trigger( "focus", event, { item: item } ) ) {
  5281. // use value to match what will end up in the input, if it was a key event
  5282. if ( event.originalEvent && /^key/.test( event.originalEvent.type ) ) {
  5283. this._value( item.value );
  5284. }
  5285. } else {
  5286. // Normally the input is populated with the item's value as the
  5287. // menu is navigated, causing screen readers to notice a change and
  5288. // announce the item. Since the focus event was canceled, this doesn't
  5289. // happen, so we update the live region so that screen readers can
  5290. // still notice the change and announce it.
  5291. this.liveRegion.text( item.value );
  5292. }
  5293. },
  5294. menuselect: function( event, ui ) {
  5295. // back compat for _renderItem using item.autocomplete, via #7810
  5296. // TODO remove the fallback, see #8156
  5297. var item = ui.item.data( "ui-autocomplete-item" ) || ui.item.data( "item.autocomplete" ),
  5298. previous = this.previous;
  5299. // only trigger when focus was lost (click on menu)
  5300. if ( this.element[0] !== this.document[0].activeElement ) {
  5301. this.element.focus();
  5302. this.previous = previous;
  5303. // #6109 - IE triggers two focus events and the second
  5304. // is asynchronous, so we need to reset the previous
  5305. // term synchronously and asynchronously :-(
  5306. this._delay(function() {
  5307. this.previous = previous;
  5308. this.selectedItem = item;
  5309. });
  5310. }
  5311. if ( false !== this._trigger( "select", event, { item: item } ) ) {
  5312. this._value( item.value );
  5313. }
  5314. // reset the term after the select event
  5315. // this allows custom select handling to work properly
  5316. this.term = this._value();
  5317. this.close( event );
  5318. this.selectedItem = item;
  5319. }
  5320. });
  5321. this.liveRegion = $( "<span>", {
  5322. role: "status",
  5323. "aria-live": "polite"
  5324. })
  5325. .addClass( "ui-helper-hidden-accessible" )
  5326. .insertAfter( this.element );
  5327. if ( $.fn.bgiframe ) {
  5328. this.menu.element.bgiframe();
  5329. }
  5330. // turning off autocomplete prevents the browser from remembering the
  5331. // value when navigating through history, so we re-enable autocomplete
  5332. // if the page is unloaded before the widget is destroyed. #7790
  5333. this._on( this.window, {
  5334. beforeunload: function() {
  5335. this.element.removeAttr( "autocomplete" );
  5336. }
  5337. });
  5338. },
  5339. _destroy: function() {
  5340. clearTimeout( this.searching );
  5341. this.element
  5342. .removeClass( "ui-autocomplete-input" )
  5343. .removeAttr( "autocomplete" );
  5344. this.menu.element.remove();
  5345. this.liveRegion.remove();
  5346. },
  5347. _setOption: function( key, value ) {
  5348. this._super( key, value );
  5349. if ( key === "source" ) {
  5350. this._initSource();
  5351. }
  5352. if ( key === "appendTo" ) {
  5353. this.menu.element.appendTo( this.document.find( value || "body" )[0] );
  5354. }
  5355. if ( key === "disabled" && value && this.xhr ) {
  5356. this.xhr.abort();
  5357. }
  5358. },
  5359. _isMultiLine: function() {
  5360. // Textareas are always multi-line
  5361. if ( this.element.is( "textarea" ) ) {
  5362. return true;
  5363. }
  5364. // Inputs are always single-line, even if inside a contentEditable element
  5365. // IE also treats inputs as contentEditable
  5366. if ( this.element.is( "input" ) ) {
  5367. return false;
  5368. }
  5369. // All other element types are determined by whether or not they're contentEditable
  5370. return this.element.prop( "isContentEditable" );
  5371. },
  5372. _initSource: function() {
  5373. var array, url,
  5374. that = this;
  5375. if ( $.isArray(this.options.source) ) {
  5376. array = this.options.source;
  5377. this.source = function( request, response ) {
  5378. response( $.ui.autocomplete.filter( array, request.term ) );
  5379. };
  5380. } else if ( typeof this.options.source === "string" ) {
  5381. url = this.options.source;
  5382. this.source = function( request, response ) {
  5383. if ( that.xhr ) {
  5384. that.xhr.abort();
  5385. }
  5386. that.xhr = $.ajax({
  5387. url: url,
  5388. data: request,
  5389. dataType: "json",
  5390. success: function( data, status ) {
  5391. response( data );
  5392. },
  5393. error: function() {
  5394. response( [] );
  5395. }
  5396. });
  5397. };
  5398. } else {
  5399. this.source = this.options.source;
  5400. }
  5401. },
  5402. _searchTimeout: function( event ) {
  5403. clearTimeout( this.searching );
  5404. this.searching = this._delay(function() {
  5405. // only search if the value has changed
  5406. if ( this.term !== this._value() ) {
  5407. this.selectedItem = null;
  5408. this.search( null, event );
  5409. }
  5410. }, this.options.delay );
  5411. },
  5412. search: function( value, event ) {
  5413. value = value != null ? value : this._value();
  5414. // always save the actual value, not the one passed as an argument
  5415. this.term = this._value();
  5416. if ( value.length < this.options.minLength ) {
  5417. return this.close( event );
  5418. }
  5419. if ( this._trigger( "search", event ) === false ) {
  5420. return;
  5421. }
  5422. return this._search( value );
  5423. },
  5424. _search: function( value ) {
  5425. this.pending++;
  5426. this.element.addClass( "ui-autocomplete-loading" );
  5427. this.cancelSearch = false;
  5428. this.source( { term: value }, this._response() );
  5429. },
  5430. _response: function() {
  5431. var that = this,
  5432. index = ++requestIndex;
  5433. return function( content ) {
  5434. if ( index === requestIndex ) {
  5435. that.__response( content );
  5436. }
  5437. that.pending--;
  5438. if ( !that.pending ) {
  5439. that.element.removeClass( "ui-autocomplete-loading" );
  5440. }
  5441. };
  5442. },
  5443. __response: function( content ) {
  5444. if ( content ) {
  5445. content = this._normalize( content );
  5446. }
  5447. this._trigger( "response", null, { content: content } );
  5448. if ( !this.options.disabled && content && content.length && !this.cancelSearch ) {
  5449. this._suggest( content );
  5450. this._trigger( "open" );
  5451. } else {
  5452. // use ._close() instead of .close() so we don't cancel future searches
  5453. this._close();
  5454. }
  5455. },
  5456. close: function( event ) {
  5457. this.cancelSearch = true;
  5458. this._close( event );
  5459. },
  5460. _close: function( event ) {
  5461. if ( this.menu.element.is( ":visible" ) ) {
  5462. this.menu.element.hide();
  5463. this.menu.blur();
  5464. this.isNewMenu = true;
  5465. this._trigger( "close", event );
  5466. }
  5467. },
  5468. _change: function( event ) {
  5469. if ( this.previous !== this._value() ) {
  5470. this._trigger( "change", event, { item: this.selectedItem } );
  5471. }
  5472. },
  5473. _normalize: function( items ) {
  5474. // assume all items have the right format when the first item is complete
  5475. if ( items.length && items[0].label && items[0].value ) {
  5476. return items;
  5477. }
  5478. return $.map( items, function( item ) {
  5479. if ( typeof item === "string" ) {
  5480. return {
  5481. label: item,
  5482. value: item
  5483. };
  5484. }
  5485. return $.extend({
  5486. label: item.label || item.value,
  5487. value: item.value || item.label
  5488. }, item );
  5489. });
  5490. },
  5491. _suggest: function( items ) {
  5492. var ul = this.menu.element
  5493. .empty()
  5494. .zIndex( this.element.zIndex() + 1 );
  5495. this._renderMenu( ul, items );
  5496. this.menu.refresh();
  5497. // size and position menu
  5498. ul.show();
  5499. this._resizeMenu();
  5500. ul.position( $.extend({
  5501. of: this.element
  5502. }, this.options.position ));
  5503. if ( this.options.autoFocus ) {
  5504. this.menu.next();
  5505. }
  5506. },
  5507. _resizeMenu: function() {
  5508. var ul = this.menu.element;
  5509. ul.outerWidth( Math.max(
  5510. // Firefox wraps long text (possibly a rounding bug)
  5511. // so we add 1px to avoid the wrapping (#7513)
  5512. ul.width( "" ).outerWidth() + 1,
  5513. this.element.outerWidth()
  5514. ) );
  5515. },
  5516. _renderMenu: function( ul, items ) {
  5517. var that = this;
  5518. $.each( items, function( index, item ) {
  5519. that._renderItemData( ul, item );
  5520. });
  5521. },
  5522. _renderItemData: function( ul, item ) {
  5523. return this._renderItem( ul, item ).data( "ui-autocomplete-item", item );
  5524. },
  5525. _renderItem: function( ul, item ) {
  5526. return $( "<li>" )
  5527. .append( $( "<a>" ).text( item.label ) )
  5528. .appendTo( ul );
  5529. },
  5530. _move: function( direction, event ) {
  5531. if ( !this.menu.element.is( ":visible" ) ) {
  5532. this.search( null, event );
  5533. return;
  5534. }
  5535. if ( this.menu.isFirstItem() && /^previous/.test( direction ) ||
  5536. this.menu.isLastItem() && /^next/.test( direction ) ) {
  5537. this._value( this.term );
  5538. this.menu.blur();
  5539. return;
  5540. }
  5541. this.menu[ direction ]( event );
  5542. },
  5543. widget: function() {
  5544. return this.menu.element;
  5545. },
  5546. _value: function( value ) {
  5547. return this.valueMethod.apply( this.element, arguments );
  5548. },
  5549. _keyEvent: function( keyEvent, event ) {
  5550. if ( !this.isMultiLine || this.menu.element.is( ":visible" ) ) {
  5551. this._move( keyEvent, event );
  5552. // prevents moving cursor to beginning/end of the text field in some browsers
  5553. event.preventDefault();
  5554. }
  5555. }
  5556. });
  5557. $.extend( $.ui.autocomplete, {
  5558. escapeRegex: function( value ) {
  5559. return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
  5560. },
  5561. filter: function(array, term) {
  5562. var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
  5563. return $.grep( array, function(value) {
  5564. return matcher.test( value.label || value.value || value );
  5565. });
  5566. }
  5567. });
  5568. // live region extension, adding a `messages` option
  5569. // NOTE: This is an experimental API. We are still investigating
  5570. // a full solution for string manipulation and internationalization.
  5571. $.widget( "ui.autocomplete", $.ui.autocomplete, {
  5572. options: {
  5573. messages: {
  5574. noResults: "No search results.",
  5575. results: function( amount ) {
  5576. return amount + ( amount > 1 ? " results are" : " result is" ) +
  5577. " available, use up and down arrow keys to navigate.";
  5578. }
  5579. }
  5580. },
  5581. __response: function( content ) {
  5582. var message;
  5583. this._superApply( arguments );
  5584. if ( this.options.disabled || this.cancelSearch ) {
  5585. return;
  5586. }
  5587. if ( content && content.length ) {
  5588. message = this.options.messages.results( content.length );
  5589. } else {
  5590. message = this.options.messages.noResults;
  5591. }
  5592. this.liveRegion.text( message );
  5593. }
  5594. });
  5595. }( jQuery ));
  5596. (function( $, undefined ) {
  5597. var lastActive, startXPos, startYPos, clickDragged,
  5598. baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
  5599. stateClasses = "ui-state-hover ui-state-active ",
  5600. 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",
  5601. formResetHandler = function() {
  5602. var buttons = $( this ).find( ":ui-button" );
  5603. setTimeout(function() {
  5604. buttons.button( "refresh" );
  5605. }, 1 );
  5606. },
  5607. radioGroup = function( radio ) {
  5608. var name = radio.name,
  5609. form = radio.form,
  5610. radios = $( [] );
  5611. if ( name ) {
  5612. if ( form ) {
  5613. radios = $( form ).find( "[name='" + name + "']" );
  5614. } else {
  5615. radios = $( "[name='" + name + "']", radio.ownerDocument )
  5616. .filter(function() {
  5617. return !this.form;
  5618. });
  5619. }
  5620. }
  5621. return radios;
  5622. };
  5623. $.widget( "ui.button", {
  5624. version: "1.9.0",
  5625. defaultElement: "<button>",
  5626. options: {
  5627. disabled: null,
  5628. text: true,
  5629. label: null,
  5630. icons: {
  5631. primary: null,
  5632. secondary: null
  5633. }
  5634. },
  5635. _create: function() {
  5636. this.element.closest( "form" )
  5637. .unbind( "reset" + this.eventNamespace )
  5638. .bind( "reset" + this.eventNamespace, formResetHandler );
  5639. if ( typeof this.options.disabled !== "boolean" ) {
  5640. this.options.disabled = !!this.element.prop( "disabled" );
  5641. } else {
  5642. this.element.prop( "disabled", this.options.disabled );
  5643. }
  5644. this._determineButtonType();
  5645. this.hasTitle = !!this.buttonElement.attr( "title" );
  5646. var that = this,
  5647. options = this.options,
  5648. toggleButton = this.type === "checkbox" || this.type === "radio",
  5649. hoverClass = "ui-state-hover" + ( !toggleButton ? " ui-state-active" : "" ),
  5650. focusClass = "ui-state-focus";
  5651. if ( options.label === null ) {
  5652. options.label = (this.type === "input" ? this.buttonElement.val() : this.buttonElement.html());
  5653. }
  5654. this.buttonElement
  5655. .addClass( baseClasses )
  5656. .attr( "role", "button" )
  5657. .bind( "mouseenter" + this.eventNamespace, function() {
  5658. if ( options.disabled ) {
  5659. return;
  5660. }
  5661. $( this ).addClass( "ui-state-hover" );
  5662. if ( this === lastActive ) {
  5663. $( this ).addClass( "ui-state-active" );
  5664. }
  5665. })
  5666. .bind( "mouseleave" + this.eventNamespace, function() {
  5667. if ( options.disabled ) {
  5668. return;
  5669. }
  5670. $( this ).removeClass( hoverClass );
  5671. })
  5672. .bind( "click" + this.eventNamespace, function( event ) {
  5673. if ( options.disabled ) {
  5674. event.preventDefault();
  5675. event.stopImmediatePropagation();
  5676. }
  5677. });
  5678. this.element
  5679. .bind( "focus" + this.eventNamespace, function() {
  5680. // no need to check disabled, focus won't be triggered anyway
  5681. that.buttonElement.addClass( focusClass );
  5682. })
  5683. .bind( "blur" + this.eventNamespace, function() {
  5684. that.buttonElement.removeClass( focusClass );
  5685. });
  5686. if ( toggleButton ) {
  5687. this.element.bind( "change" + this.eventNamespace, function() {
  5688. if ( clickDragged ) {
  5689. return;
  5690. }
  5691. that.refresh();
  5692. });
  5693. // if mouse moves between mousedown and mouseup (drag) set clickDragged flag
  5694. // prevents issue where button state changes but checkbox/radio checked state
  5695. // does not in Firefox (see ticket #6970)
  5696. this.buttonElement
  5697. .bind( "mousedown" + this.eventNamespace, function( event ) {
  5698. if ( options.disabled ) {
  5699. return;
  5700. }
  5701. clickDragged = false;
  5702. startXPos = event.pageX;
  5703. startYPos = event.pageY;
  5704. })
  5705. .bind( "mouseup" + this.eventNamespace, function( event ) {
  5706. if ( options.disabled ) {
  5707. return;
  5708. }
  5709. if ( startXPos !== event.pageX || startYPos !== event.pageY ) {
  5710. clickDragged = true;
  5711. }
  5712. });
  5713. }
  5714. if ( this.type === "checkbox" ) {
  5715. this.buttonElement.bind( "click" + this.eventNamespace, function() {
  5716. if ( options.disabled || clickDragged ) {
  5717. return false;
  5718. }
  5719. $( this ).toggleClass( "ui-state-active" );
  5720. that.buttonElement.attr( "aria-pressed", that.element[0].checked );
  5721. });
  5722. } else if ( this.type === "radio" ) {
  5723. this.buttonElement.bind( "click" + this.eventNamespace, function() {
  5724. if ( options.disabled || clickDragged ) {
  5725. return false;
  5726. }
  5727. $( this ).addClass( "ui-state-active" );
  5728. that.buttonElement.attr( "aria-pressed", "true" );
  5729. var radio = that.element[ 0 ];
  5730. radioGroup( radio )
  5731. .not( radio )
  5732. .map(function() {
  5733. return $( this ).button( "widget" )[ 0 ];
  5734. })
  5735. .removeClass( "ui-state-active" )
  5736. .attr( "aria-pressed", "false" );
  5737. });
  5738. } else {
  5739. this.buttonElement
  5740. .bind( "mousedown" + this.eventNamespace, function() {
  5741. if ( options.disabled ) {
  5742. return false;
  5743. }
  5744. $( this ).addClass( "ui-state-active" );
  5745. lastActive = this;
  5746. that.document.one( "mouseup", function() {
  5747. lastActive = null;
  5748. });
  5749. })
  5750. .bind( "mouseup" + this.eventNamespace, function() {
  5751. if ( options.disabled ) {
  5752. return false;
  5753. }
  5754. $( this ).removeClass( "ui-state-active" );
  5755. })
  5756. .bind( "keydown" + this.eventNamespace, function(event) {
  5757. if ( options.disabled ) {
  5758. return false;
  5759. }
  5760. if ( event.keyCode === $.ui.keyCode.SPACE || event.keyCode === $.ui.keyCode.ENTER ) {
  5761. $( this ).addClass( "ui-state-active" );
  5762. }
  5763. })
  5764. .bind( "keyup" + this.eventNamespace, function() {
  5765. $( this ).removeClass( "ui-state-active" );
  5766. });
  5767. if ( this.buttonElement.is("a") ) {
  5768. this.buttonElement.keyup(function(event) {
  5769. if ( event.keyCode === $.ui.keyCode.SPACE ) {
  5770. // TODO pass through original event correctly (just as 2nd argument doesn't work)
  5771. $( this ).click();
  5772. }
  5773. });
  5774. }
  5775. }
  5776. // TODO: pull out $.Widget's handling for the disabled option into
  5777. // $.Widget.prototype._setOptionDisabled so it's easy to proxy and can
  5778. // be overridden by individual plugins
  5779. this._setOption( "disabled", options.disabled );
  5780. this._resetButton();
  5781. },
  5782. _determineButtonType: function() {
  5783. var ancestor, labelSelector, checked;
  5784. if ( this.element.is("[type=checkbox]") ) {
  5785. this.type = "checkbox";
  5786. } else if ( this.element.is("[type=radio]") ) {
  5787. this.type = "radio";
  5788. } else if ( this.element.is("input") ) {
  5789. this.type = "input";
  5790. } else {
  5791. this.type = "button";
  5792. }
  5793. if ( this.type === "checkbox" || this.type === "radio" ) {
  5794. // we don't search against the document in case the element
  5795. // is disconnected from the DOM
  5796. ancestor = this.element.parents().last();
  5797. labelSelector = "label[for='" + this.element.attr("id") + "']";
  5798. this.buttonElement = ancestor.find( labelSelector );
  5799. if ( !this.buttonElement.length ) {
  5800. ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings();
  5801. this.buttonElement = ancestor.filter( labelSelector );
  5802. if ( !this.buttonElement.length ) {
  5803. this.buttonElement = ancestor.find( labelSelector );
  5804. }
  5805. }
  5806. this.element.addClass( "ui-helper-hidden-accessible" );
  5807. checked = this.element.is( ":checked" );
  5808. if ( checked ) {
  5809. this.buttonElement.addClass( "ui-state-active" );
  5810. }
  5811. this.buttonElement.prop( "aria-pressed", checked );
  5812. } else {
  5813. this.buttonElement = this.element;
  5814. }
  5815. },
  5816. widget: function() {
  5817. return this.buttonElement;
  5818. },
  5819. _destroy: function() {
  5820. this.element
  5821. .removeClass( "ui-helper-hidden-accessible" );
  5822. this.buttonElement
  5823. .removeClass( baseClasses + " " + stateClasses + " " + typeClasses )
  5824. .removeAttr( "role" )
  5825. .removeAttr( "aria-pressed" )
  5826. .html( this.buttonElement.find(".ui-button-text").html() );
  5827. if ( !this.hasTitle ) {
  5828. this.buttonElement.removeAttr( "title" );
  5829. }
  5830. },
  5831. _setOption: function( key, value ) {
  5832. this._super( key, value );
  5833. if ( key === "disabled" ) {
  5834. if ( value ) {
  5835. this.element.prop( "disabled", true );
  5836. } else {
  5837. this.element.prop( "disabled", false );
  5838. }
  5839. return;
  5840. }
  5841. this._resetButton();
  5842. },
  5843. refresh: function() {
  5844. var isDisabled = this.element.is( ":disabled" );
  5845. if ( isDisabled !== this.options.disabled ) {
  5846. this._setOption( "disabled", isDisabled );
  5847. }
  5848. if ( this.type === "radio" ) {
  5849. radioGroup( this.element[0] ).each(function() {
  5850. if ( $( this ).is( ":checked" ) ) {
  5851. $( this ).button( "widget" )
  5852. .addClass( "ui-state-active" )
  5853. .attr( "aria-pressed", "true" );
  5854. } else {
  5855. $( this ).button( "widget" )
  5856. .removeClass( "ui-state-active" )
  5857. .attr( "aria-pressed", "false" );
  5858. }
  5859. });
  5860. } else if ( this.type === "checkbox" ) {
  5861. if ( this.element.is( ":checked" ) ) {
  5862. this.buttonElement
  5863. .addClass( "ui-state-active" )
  5864. .attr( "aria-pressed", "true" );
  5865. } else {
  5866. this.buttonElement
  5867. .removeClass( "ui-state-active" )
  5868. .attr( "aria-pressed", "false" );
  5869. }
  5870. }
  5871. },
  5872. _resetButton: function() {
  5873. if ( this.type === "input" ) {
  5874. if ( this.options.label ) {
  5875. this.element.val( this.options.label );
  5876. }
  5877. return;
  5878. }
  5879. var buttonElement = this.buttonElement.removeClass( typeClasses ),
  5880. buttonText = $( "<span></span>", this.document[0] )
  5881. .addClass( "ui-button-text" )
  5882. .html( this.options.label )
  5883. .appendTo( buttonElement.empty() )
  5884. .text(),
  5885. icons = this.options.icons,
  5886. multipleIcons = icons.primary && icons.secondary,
  5887. buttonClasses = [];
  5888. if ( icons.primary || icons.secondary ) {
  5889. if ( this.options.text ) {
  5890. buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) );
  5891. }
  5892. if ( icons.primary ) {
  5893. buttonElement.prepend( "<span class='ui-button-icon-primary ui-icon " + icons.primary + "'></span>" );
  5894. }
  5895. if ( icons.secondary ) {
  5896. buttonElement.append( "<span class='ui-button-icon-secondary ui-icon " + icons.secondary + "'></span>" );
  5897. }
  5898. if ( !this.options.text ) {
  5899. buttonClasses.push( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" );
  5900. if ( !this.hasTitle ) {
  5901. buttonElement.attr( "title", $.trim( buttonText ) );
  5902. }
  5903. }
  5904. } else {
  5905. buttonClasses.push( "ui-button-text-only" );
  5906. }
  5907. buttonElement.addClass( buttonClasses.join( " " ) );
  5908. }
  5909. });
  5910. $.widget( "ui.buttonset", {
  5911. version: "1.9.0",
  5912. options: {
  5913. items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(button)"
  5914. },
  5915. _create: function() {
  5916. this.element.addClass( "ui-buttonset" );
  5917. },
  5918. _init: function() {
  5919. this.refresh();
  5920. },
  5921. _setOption: function( key, value ) {
  5922. if ( key === "disabled" ) {
  5923. this.buttons.button( "option", key, value );
  5924. }
  5925. this._super( key, value );
  5926. },
  5927. refresh: function() {
  5928. var rtl = this.element.css( "direction" ) === "rtl";
  5929. this.buttons = this.element.find( this.options.items )
  5930. .filter( ":ui-button" )
  5931. .button( "refresh" )
  5932. .end()
  5933. .not( ":ui-button" )
  5934. .button()
  5935. .end()
  5936. .map(function() {
  5937. return $( this ).button( "widget" )[ 0 ];
  5938. })
  5939. .removeClass( "ui-corner-all ui-corner-left ui-corner-right" )
  5940. .filter( ":first" )
  5941. .addClass( rtl ? "ui-corner-right" : "ui-corner-left" )
  5942. .end()
  5943. .filter( ":last" )
  5944. .addClass( rtl ? "ui-corner-left" : "ui-corner-right" )
  5945. .end()
  5946. .end();
  5947. },
  5948. _destroy: function() {
  5949. this.element.removeClass( "ui-buttonset" );
  5950. this.buttons
  5951. .map(function() {
  5952. return $( this ).button( "widget" )[ 0 ];
  5953. })
  5954. .removeClass( "ui-corner-left ui-corner-right" )
  5955. .end()
  5956. .button( "destroy" );
  5957. }
  5958. });
  5959. }( jQuery ) );
  5960. (function( $, undefined ) {
  5961. $.extend($.ui, { datepicker: { version: "1.9.0" } });
  5962. var PROP_NAME = 'datepicker';
  5963. var dpuuid = new Date().getTime();
  5964. var instActive;
  5965. /* Date picker manager.
  5966. Use the singleton instance of this class, $.datepicker, to interact with the date picker.
  5967. Settings for (groups of) date pickers are maintained in an instance object,
  5968. allowing multiple different settings on the same page. */
  5969. function Datepicker() {
  5970. this.debug = false; // Change this to true to start debugging
  5971. this._curInst = null; // The current instance in use
  5972. this._keyEvent = false; // If the last event was a key event
  5973. this._disabledInputs = []; // List of date picker inputs that have been disabled
  5974. this._datepickerShowing = false; // True if the popup picker is showing , false if not
  5975. this._inDialog = false; // True if showing within a "dialog", false if not
  5976. this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
  5977. this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
  5978. this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
  5979. this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
  5980. this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
  5981. this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
  5982. this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
  5983. this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
  5984. this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
  5985. this.regional = []; // Available regional settings, indexed by language code
  5986. this.regional[''] = { // Default regional settings
  5987. closeText: 'Done', // Display text for close link
  5988. prevText: 'Prev', // Display text for previous month link
  5989. nextText: 'Next', // Display text for next month link
  5990. currentText: 'Today', // Display text for current month link
  5991. monthNames: ['January','February','March','April','May','June',
  5992. 'July','August','September','October','November','December'], // Names of months for drop-down and formatting
  5993. monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
  5994. dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
  5995. dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
  5996. dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
  5997. weekHeader: 'Wk', // Column header for week of the year
  5998. dateFormat: 'mm/dd/yy', // See format options on parseDate
  5999. firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
  6000. isRTL: false, // True if right-to-left language, false if left-to-right
  6001. showMonthAfterYear: false, // True if the year select precedes month, false for month then year
  6002. yearSuffix: '' // Additional text to append to the year in the month headers
  6003. };
  6004. this._defaults = { // Global defaults for all the date picker instances
  6005. showOn: 'focus', // 'focus' for popup on focus,
  6006. // 'button' for trigger button, or 'both' for either
  6007. showAnim: 'fadeIn', // Name of jQuery animation for popup
  6008. showOptions: {}, // Options for enhanced animations
  6009. defaultDate: null, // Used when field is blank: actual date,
  6010. // +/-number for offset from today, null for today
  6011. appendText: '', // Display text following the input box, e.g. showing the format
  6012. buttonText: '...', // Text for trigger button
  6013. buttonImage: '', // URL for trigger button image
  6014. buttonImageOnly: false, // True if the image appears alone, false if it appears on a button
  6015. hideIfNoPrevNext: false, // True to hide next/previous month links
  6016. // if not applicable, false to just disable them
  6017. navigationAsDateFormat: false, // True if date formatting applied to prev/today/next links
  6018. gotoCurrent: false, // True if today link goes back to current selection instead
  6019. changeMonth: false, // True if month can be selected directly, false if only prev/next
  6020. changeYear: false, // True if year can be selected directly, false if only prev/next
  6021. yearRange: 'c-10:c+10', // Range of years to display in drop-down,
  6022. // either relative to today's year (-nn:+nn), relative to currently displayed year
  6023. // (c-nn:c+nn), absolute (nnnn:nnnn), or a combination of the above (nnnn:-n)
  6024. showOtherMonths: false, // True to show dates in other months, false to leave blank
  6025. selectOtherMonths: false, // True to allow selection of dates in other months, false for unselectable
  6026. showWeek: false, // True to show week of the year, false to not show it
  6027. calculateWeek: this.iso8601Week, // How to calculate the week of the year,
  6028. // takes a Date and returns the number of the week for it
  6029. shortYearCutoff: '+10', // Short year values < this are in the current century,
  6030. // > this are in the previous century,
  6031. // string value starting with '+' for current year + value
  6032. minDate: null, // The earliest selectable date, or null for no limit
  6033. maxDate: null, // The latest selectable date, or null for no limit
  6034. duration: 'fast', // Duration of display/closure
  6035. beforeShowDay: null, // Function that takes a date and returns an array with
  6036. // [0] = true if selectable, false if not, [1] = custom CSS class name(s) or '',
  6037. // [2] = cell title (optional), e.g. $.datepicker.noWeekends
  6038. beforeShow: null, // Function that takes an input field and
  6039. // returns a set of custom settings for the date picker
  6040. onSelect: null, // Define a callback function when a date is selected
  6041. onChangeMonthYear: null, // Define a callback function when the month or year is changed
  6042. onClose: null, // Define a callback function when the datepicker is closed
  6043. numberOfMonths: 1, // Number of months to show at a time
  6044. showCurrentAtPos: 0, // The position in multipe months at which to show the current month (starting at 0)
  6045. stepMonths: 1, // Number of months to step back/forward
  6046. stepBigMonths: 12, // Number of months to step back/forward for the big links
  6047. altField: '', // Selector for an alternate field to store selected dates into
  6048. altFormat: '', // The date format to use for the alternate field
  6049. constrainInput: true, // The input is constrained by the current date format
  6050. showButtonPanel: false, // True to show button panel, false to not show it
  6051. autoSize: false, // True to size the input for the date format, false to leave as is
  6052. disabled: false // The initial disabled state
  6053. };
  6054. $.extend(this._defaults, this.regional['']);
  6055. this.dpDiv = bindHover($('<div id="' + this._mainDivId + '" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>'));
  6056. }
  6057. $.extend(Datepicker.prototype, {
  6058. /* Class name added to elements to indicate already configured with a date picker. */
  6059. markerClassName: 'hasDatepicker',
  6060. //Keep track of the maximum number of rows displayed (see #7043)
  6061. maxRows: 4,
  6062. /* Debug logging (if enabled). */
  6063. log: function () {
  6064. if (this.debug)
  6065. console.log.apply('', arguments);
  6066. },
  6067. // TODO rename to "widget" when switching to widget factory
  6068. _widgetDatepicker: function() {
  6069. return this.dpDiv;
  6070. },
  6071. /* Override the default settings for all instances of the date picker.
  6072. @param settings object - the new settings to use as defaults (anonymous object)
  6073. @return the manager object */
  6074. setDefaults: function(settings) {
  6075. extendRemove(this._defaults, settings || {});
  6076. return this;
  6077. },
  6078. /* Attach the date picker to a jQuery selection.
  6079. @param target element - the target input field or division or span
  6080. @param settings object - the new settings to use for this date picker instance (anonymous) */
  6081. _attachDatepicker: function(target, settings) {
  6082. // check for settings on the control itself - in namespace 'date:'
  6083. var inlineSettings = null;
  6084. for (var attrName in this._defaults) {
  6085. var attrValue = target.getAttribute('date:' + attrName);
  6086. if (attrValue) {
  6087. inlineSettings = inlineSettings || {};
  6088. try {
  6089. inlineSettings[attrName] = eval(attrValue);
  6090. } catch (err) {
  6091. inlineSettings[attrName] = attrValue;
  6092. }
  6093. }
  6094. }
  6095. var nodeName = target.nodeName.toLowerCase();
  6096. var inline = (nodeName == 'div' || nodeName == 'span');
  6097. if (!target.id) {
  6098. this.uuid += 1;
  6099. target.id = 'dp' + this.uuid;
  6100. }
  6101. var inst = this._newInst($(target), inline);
  6102. inst.settings = $.extend({}, settings || {}, inlineSettings || {});
  6103. if (nodeName == 'input') {
  6104. this._connectDatepicker(target, inst);
  6105. } else if (inline) {
  6106. this._inlineDatepicker(target, inst);
  6107. }
  6108. },
  6109. /* Create a new instance object. */
  6110. _newInst: function(target, inline) {
  6111. var id = target[0].id.replace(/([^A-Za-z0-9_-])/g, '\\\\$1'); // escape jQuery meta chars
  6112. return {id: id, input: target, // associated target
  6113. selectedDay: 0, selectedMonth: 0, selectedYear: 0, // current selection
  6114. drawMonth: 0, drawYear: 0, // month being drawn
  6115. inline: inline, // is datepicker inline or not
  6116. dpDiv: (!inline ? this.dpDiv : // presentation div
  6117. bindHover($('<div class="' + this._inlineClass + ' ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"></div>')))};
  6118. },
  6119. /* Attach the date picker to an input field. */
  6120. _connectDatepicker: function(target, inst) {
  6121. var input = $(target);
  6122. inst.append = $([]);
  6123. inst.trigger = $([]);
  6124. if (input.hasClass(this.markerClassName))
  6125. return;
  6126. this._attachments(input, inst);
  6127. input.addClass(this.markerClassName).keydown(this._doKeyDown).
  6128. keypress(this._doKeyPress).keyup(this._doKeyUp).
  6129. bind("setData.datepicker", function(event, key, value) {
  6130. inst.settings[key] = value;
  6131. }).bind("getData.datepicker", function(event, key) {
  6132. return this._get(inst, key);
  6133. });
  6134. this._autoSize(inst);
  6135. $.data(target, PROP_NAME, inst);
  6136. //If disabled option is true, disable the datepicker once it has been attached to the input (see ticket #5665)
  6137. if( inst.settings.disabled ) {
  6138. this._disableDatepicker( target );
  6139. }
  6140. },
  6141. /* Make attachments based on settings. */
  6142. _attachments: function(input, inst) {
  6143. var appendText = this._get(inst, 'appendText');
  6144. var isRTL = this._get(inst, 'isRTL');
  6145. if (inst.append)
  6146. inst.append.remove();
  6147. if (appendText) {
  6148. inst.append = $('<span class="' + this._appendClass + '">' + appendText + '</span>');
  6149. input[isRTL ? 'before' : 'after'](inst.append);
  6150. }
  6151. input.unbind('focus', this._showDatepicker);
  6152. if (inst.trigger)
  6153. inst.trigger.remove();
  6154. var showOn = this._get(inst, 'showOn');
  6155. if (showOn == 'focus' || showOn == 'both') // pop-up date picker when in the marked field
  6156. input.focus(this._showDatepicker);
  6157. if (showOn == 'button' || showOn == 'both') { // pop-up date picker when button clicked
  6158. var buttonText = this._get(inst, 'buttonText');
  6159. var buttonImage = this._get(inst, 'buttonImage');
  6160. inst.trigger = $(this._get(inst, 'buttonImageOnly') ?
  6161. $('<img/>').addClass(this._triggerClass).
  6162. attr({ src: buttonImage, alt: buttonText, title: buttonText }) :
  6163. $('<button type="button"></button>').addClass(this._triggerClass).
  6164. html(buttonImage == '' ? buttonText : $('<img/>').attr(
  6165. { src:buttonImage, alt:buttonText, title:buttonText })));
  6166. input[isRTL ? 'before' : 'after'](inst.trigger);
  6167. inst.trigger.click(function() {
  6168. if ($.datepicker._datepickerShowing && $.datepicker._lastInput == input[0])
  6169. $.datepicker._hideDatepicker();
  6170. else if ($.datepicker._datepickerShowing && $.datepicker._lastInput != input[0]) {
  6171. $.datepicker._hideDatepicker();
  6172. $.datepicker._showDatepicker(input[0]);
  6173. } else
  6174. $.datepicker._showDatepicker(input[0]);
  6175. return false;
  6176. });
  6177. }
  6178. },
  6179. /* Apply the maximum length for the date format. */
  6180. _autoSize: function(inst) {
  6181. if (this._get(inst, 'autoSize') && !inst.inline) {
  6182. var date = new Date(2009, 12 - 1, 20); // Ensure double digits
  6183. var dateFormat = this._get(inst, 'dateFormat');
  6184. if (dateFormat.match(/[DM]/)) {
  6185. var findMax = function(names) {
  6186. var max = 0;
  6187. var maxI = 0;
  6188. for (var i = 0; i < names.length; i++) {
  6189. if (names[i].length > max) {
  6190. max = names[i].length;
  6191. maxI = i;
  6192. }
  6193. }
  6194. return maxI;
  6195. };
  6196. date.setMonth(findMax(this._get(inst, (dateFormat.match(/MM/) ?
  6197. 'monthNames' : 'monthNamesShort'))));
  6198. date.setDate(findMax(this._get(inst, (dateFormat.match(/DD/) ?
  6199. 'dayNames' : 'dayNamesShort'))) + 20 - date.getDay());
  6200. }
  6201. inst.input.attr('size', this._formatDate(inst, date).length);
  6202. }
  6203. },
  6204. /* Attach an inline date picker to a div. */
  6205. _inlineDatepicker: function(target, inst) {
  6206. var divSpan = $(target);
  6207. if (divSpan.hasClass(this.markerClassName))
  6208. return;
  6209. divSpan.addClass(this.markerClassName).append(inst.dpDiv).
  6210. bind("setData.datepicker", function(event, key, value){
  6211. inst.settings[key] = value;
  6212. }).bind("getData.datepicker", function(event, key){
  6213. return this._get(inst, key);
  6214. });
  6215. $.data(target, PROP_NAME, inst);
  6216. this._setDate(inst, this._getDefaultDate(inst), true);
  6217. this._updateDatepicker(inst);
  6218. this._updateAlternate(inst);
  6219. //If disabled option is true, disable the datepicker before showing it (see ticket #5665)
  6220. if( inst.settings.disabled ) {
  6221. this._disableDatepicker( target );
  6222. }
  6223. // Set display:block in place of inst.dpDiv.show() which won't work on disconnected elements
  6224. // http://bugs.jqueryui.com/ticket/7552 - A Datepicker created on a detached div has zero height
  6225. inst.dpDiv.css( "display", "block" );
  6226. },
  6227. /* Pop-up the date picker in a "dialog" box.
  6228. @param input element - ignored
  6229. @param date string or Date - the initial date to display
  6230. @param onSelect function - the function to call when a date is selected
  6231. @param settings object - update the dialog date picker instance's settings (anonymous object)
  6232. @param pos int[2] - coordinates for the dialog's position within the screen or
  6233. event - with x/y coordinates or
  6234. leave empty for default (screen centre)
  6235. @return the manager object */
  6236. _dialogDatepicker: function(input, date, onSelect, settings, pos) {
  6237. var inst = this._dialogInst; // internal instance
  6238. if (!inst) {
  6239. this.uuid += 1;
  6240. var id = 'dp' + this.uuid;
  6241. this._dialogInput = $('<input type="text" id="' + id +
  6242. '" style="position: absolute; top: -100px; width: 0px;"/>');
  6243. this._dialogInput.keydown(this._doKeyDown);
  6244. $('body').append(this._dialogInput);
  6245. inst = this._dialogInst = this._newInst(this._dialogInput, false);
  6246. inst.settings = {};
  6247. $.data(this._dialogInput[0], PROP_NAME, inst);
  6248. }
  6249. extendRemove(inst.settings, settings || {});
  6250. date = (date && date.constructor == Date ? this._formatDate(inst, date) : date);
  6251. this._dialogInput.val(date);
  6252. this._pos = (pos ? (pos.length ? pos : [pos.pageX, pos.pageY]) : null);
  6253. if (!this._pos) {
  6254. var browserWidth = document.documentElement.clientWidth;
  6255. var browserHeight = document.documentElement.clientHeight;
  6256. var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
  6257. var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
  6258. this._pos = // should use actual width/height below
  6259. [(browserWidth / 2) - 100 + scrollX, (browserHeight / 2) - 150 + scrollY];
  6260. }
  6261. // move input on screen for focus, but hidden behind dialog
  6262. this._dialogInput.css('left', (this._pos[0] + 20) + 'px').css('top', this._pos[1] + 'px');
  6263. inst.settings.onSelect = onSelect;
  6264. this._inDialog = true;
  6265. this.dpDiv.addClass(this._dialogClass);
  6266. this._showDatepicker(this._dialogInput[0]);
  6267. if ($.blockUI)
  6268. $.blockUI(this.dpDiv);
  6269. $.data(this._dialogInput[0], PROP_NAME, inst);
  6270. return this;
  6271. },
  6272. /* Detach a datepicker from its control.
  6273. @param target element - the target input field or division or span */
  6274. _destroyDatepicker: function(target) {
  6275. var $target = $(target);
  6276. var inst = $.data(target, PROP_NAME);
  6277. if (!$target.hasClass(this.markerClassName)) {
  6278. return;
  6279. }
  6280. var nodeName = target.nodeName.toLowerCase();
  6281. $.removeData(target, PROP_NAME);
  6282. if (nodeName == 'input') {
  6283. inst.append.remove();
  6284. inst.trigger.remove();
  6285. $target.removeClass(this.markerClassName).
  6286. unbind('focus', this._showDatepicker).
  6287. unbind('keydown', this._doKeyDown).
  6288. unbind('keypress', this._doKeyPress).
  6289. unbind('keyup', this._doKeyUp);
  6290. } else if (nodeName == 'div' || nodeName == 'span')
  6291. $target.removeClass(this.markerClassName).empty();
  6292. },
  6293. /* Enable the date picker to a jQuery selection.
  6294. @param target element - the target input field or division or span */
  6295. _enableDatepicker: function(target) {
  6296. var $target = $(target);
  6297. var inst = $.data(target, PROP_NAME);
  6298. if (!$target.hasClass(this.markerClassName)) {
  6299. return;
  6300. }
  6301. var nodeName = target.nodeName.toLowerCase();
  6302. if (nodeName == 'input') {
  6303. target.disabled = false;
  6304. inst.trigger.filter('button').
  6305. each(function() { this.disabled = false; }).end().
  6306. filter('img').css({opacity: '1.0', cursor: ''});
  6307. }
  6308. else if (nodeName == 'div' || nodeName == 'span') {
  6309. var inline = $target.children('.' + this._inlineClass);
  6310. inline.children().removeClass('ui-state-disabled');
  6311. inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
  6312. prop("disabled", false);
  6313. }
  6314. this._disabledInputs = $.map(this._disabledInputs,
  6315. function(value) { return (value == target ? null : value); }); // delete entry
  6316. },
  6317. /* Disable the date picker to a jQuery selection.
  6318. @param target element - the target input field or division or span */
  6319. _disableDatepicker: function(target) {
  6320. var $target = $(target);
  6321. var inst = $.data(target, PROP_NAME);
  6322. if (!$target.hasClass(this.markerClassName)) {
  6323. return;
  6324. }
  6325. var nodeName = target.nodeName.toLowerCase();
  6326. if (nodeName == 'input') {
  6327. target.disabled = true;
  6328. inst.trigger.filter('button').
  6329. each(function() { this.disabled = true; }).end().
  6330. filter('img').css({opacity: '0.5', cursor: 'default'});
  6331. }
  6332. else if (nodeName == 'div' || nodeName == 'span') {
  6333. var inline = $target.children('.' + this._inlineClass);
  6334. inline.children().addClass('ui-state-disabled');
  6335. inline.find("select.ui-datepicker-month, select.ui-datepicker-year").
  6336. prop("disabled", true);
  6337. }
  6338. this._disabledInputs = $.map(this._disabledInputs,
  6339. function(value) { return (value == target ? null : value); }); // delete entry
  6340. this._disabledInputs[this._disabledInputs.length] = target;
  6341. },
  6342. /* Is the first field in a jQuery collection disabled as a datepicker?
  6343. @param target element - the target input field or division or span
  6344. @return boolean - true if disabled, false if enabled */
  6345. _isDisabledDatepicker: function(target) {
  6346. if (!target) {
  6347. return false;
  6348. }
  6349. for (var i = 0; i < this._disabledInputs.length; i++) {
  6350. if (this._disabledInputs[i] == target)
  6351. return true;
  6352. }
  6353. return false;
  6354. },
  6355. /* Retrieve the instance data for the target control.
  6356. @param target element - the target input field or division or span
  6357. @return object - the associated instance data
  6358. @throws error if a jQuery problem getting data */
  6359. _getInst: function(target) {
  6360. try {
  6361. return $.data(target, PROP_NAME);
  6362. }
  6363. catch (err) {
  6364. throw 'Missing instance data for this datepicker';
  6365. }
  6366. },
  6367. /* Update or retrieve the settings for a date picker attached to an input field or division.
  6368. @param target element - the target input field or division or span
  6369. @param name object - the new settings to update or
  6370. string - the name of the setting to change or retrieve,
  6371. when retrieving also 'all' for all instance settings or
  6372. 'defaults' for all global defaults
  6373. @param value any - the new value for the setting
  6374. (omit if above is an object or to retrieve a value) */
  6375. _optionDatepicker: function(target, name, value) {
  6376. var inst = this._getInst(target);
  6377. if (arguments.length == 2 && typeof name == 'string') {
  6378. return (name == 'defaults' ? $.extend({}, $.datepicker._defaults) :
  6379. (inst ? (name == 'all' ? $.extend({}, inst.settings) :
  6380. this._get(inst, name)) : null));
  6381. }
  6382. var settings = name || {};
  6383. if (typeof name == 'string') {
  6384. settings = {};
  6385. settings[name] = value;
  6386. }
  6387. if (inst) {
  6388. if (this._curInst == inst) {
  6389. this._hideDatepicker();
  6390. }
  6391. var date = this._getDateDatepicker(target, true);
  6392. var minDate = this._getMinMaxDate(inst, 'min');
  6393. var maxDate = this._getMinMaxDate(inst, 'max');
  6394. extendRemove(inst.settings, settings);
  6395. // reformat the old minDate/maxDate values if dateFormat changes and a new minDate/maxDate isn't provided
  6396. if (minDate !== null && settings['dateFormat'] !== undefined && settings['minDate'] === undefined)
  6397. inst.settings.minDate = this._formatDate(inst, minDate);
  6398. if (maxDate !== null && settings['dateFormat'] !== undefined && settings['maxDate'] === undefined)
  6399. inst.settings.maxDate = this._formatDate(inst, maxDate);
  6400. this._attachments($(target), inst);
  6401. this._autoSize(inst);
  6402. this._setDate(inst, date);
  6403. this._updateAlternate(inst);
  6404. this._updateDatepicker(inst);
  6405. }
  6406. },
  6407. // change method deprecated
  6408. _changeDatepicker: function(target, name, value) {
  6409. this._optionDatepicker(target, name, value);
  6410. },
  6411. /* Redraw the date picker attached to an input field or division.
  6412. @param target element - the target input field or division or span */
  6413. _refreshDatepicker: function(target) {
  6414. var inst = this._getInst(target);
  6415. if (inst) {
  6416. this._updateDatepicker(inst);
  6417. }
  6418. },
  6419. /* Set the dates for a jQuery selection.
  6420. @param target element - the target input field or division or span
  6421. @param date Date - the new date */
  6422. _setDateDatepicker: function(target, date) {
  6423. var inst = this._getInst(target);
  6424. if (inst) {
  6425. this._setDate(inst, date);
  6426. this._updateDatepicker(inst);
  6427. this._updateAlternate(inst);
  6428. }
  6429. },
  6430. /* Get the date(s) for the first entry in a jQuery selection.
  6431. @param target element - the target input field or division or span
  6432. @param noDefault boolean - true if no default date is to be used
  6433. @return Date - the current date */
  6434. _getDateDatepicker: function(target, noDefault) {
  6435. var inst = this._getInst(target);
  6436. if (inst && !inst.inline)
  6437. this._setDateFromField(inst, noDefault);
  6438. return (inst ? this._getDate(inst) : null);
  6439. },
  6440. /* Handle keystrokes. */
  6441. _doKeyDown: function(event) {
  6442. var inst = $.datepicker._getInst(event.target);
  6443. var handled = true;
  6444. var isRTL = inst.dpDiv.is('.ui-datepicker-rtl');
  6445. inst._keyEvent = true;
  6446. if ($.datepicker._datepickerShowing)
  6447. switch (event.keyCode) {
  6448. case 9: $.datepicker._hideDatepicker();
  6449. handled = false;
  6450. break; // hide on tab out
  6451. case 13: var sel = $('td.' + $.datepicker._dayOverClass + ':not(.' +
  6452. $.datepicker._currentClass + ')', inst.dpDiv);
  6453. if (sel[0])
  6454. $.datepicker._selectDay(event.target, inst.selectedMonth, inst.selectedYear, sel[0]);
  6455. var onSelect = $.datepicker._get(inst, 'onSelect');
  6456. if (onSelect) {
  6457. var dateStr = $.datepicker._formatDate(inst);
  6458. // trigger custom callback
  6459. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);
  6460. }
  6461. else
  6462. $.datepicker._hideDatepicker();
  6463. return false; // don't submit the form
  6464. break; // select the value on enter
  6465. case 27: $.datepicker._hideDatepicker();
  6466. break; // hide on escape
  6467. case 33: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  6468. -$.datepicker._get(inst, 'stepBigMonths') :
  6469. -$.datepicker._get(inst, 'stepMonths')), 'M');
  6470. break; // previous month/year on page up/+ ctrl
  6471. case 34: $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  6472. +$.datepicker._get(inst, 'stepBigMonths') :
  6473. +$.datepicker._get(inst, 'stepMonths')), 'M');
  6474. break; // next month/year on page down/+ ctrl
  6475. case 35: if (event.ctrlKey || event.metaKey) $.datepicker._clearDate(event.target);
  6476. handled = event.ctrlKey || event.metaKey;
  6477. break; // clear on ctrl or command +end
  6478. case 36: if (event.ctrlKey || event.metaKey) $.datepicker._gotoToday(event.target);
  6479. handled = event.ctrlKey || event.metaKey;
  6480. break; // current on ctrl or command +home
  6481. case 37: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? +1 : -1), 'D');
  6482. handled = event.ctrlKey || event.metaKey;
  6483. // -1 day on ctrl or command +left
  6484. if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  6485. -$.datepicker._get(inst, 'stepBigMonths') :
  6486. -$.datepicker._get(inst, 'stepMonths')), 'M');
  6487. // next month/year on alt +left on Mac
  6488. break;
  6489. case 38: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, -7, 'D');
  6490. handled = event.ctrlKey || event.metaKey;
  6491. break; // -1 week on ctrl or command +up
  6492. case 39: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, (isRTL ? -1 : +1), 'D');
  6493. handled = event.ctrlKey || event.metaKey;
  6494. // +1 day on ctrl or command +right
  6495. if (event.originalEvent.altKey) $.datepicker._adjustDate(event.target, (event.ctrlKey ?
  6496. +$.datepicker._get(inst, 'stepBigMonths') :
  6497. +$.datepicker._get(inst, 'stepMonths')), 'M');
  6498. // next month/year on alt +right
  6499. break;
  6500. case 40: if (event.ctrlKey || event.metaKey) $.datepicker._adjustDate(event.target, +7, 'D');
  6501. handled = event.ctrlKey || event.metaKey;
  6502. break; // +1 week on ctrl or command +down
  6503. default: handled = false;
  6504. }
  6505. else if (event.keyCode == 36 && event.ctrlKey) // display the date picker on ctrl+home
  6506. $.datepicker._showDatepicker(this);
  6507. else {
  6508. handled = false;
  6509. }
  6510. if (handled) {
  6511. event.preventDefault();
  6512. event.stopPropagation();
  6513. }
  6514. },
  6515. /* Filter entered characters - based on date format. */
  6516. _doKeyPress: function(event) {
  6517. var inst = $.datepicker._getInst(event.target);
  6518. if ($.datepicker._get(inst, 'constrainInput')) {
  6519. var chars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat'));
  6520. var chr = String.fromCharCode(event.charCode == undefined ? event.keyCode : event.charCode);
  6521. return event.ctrlKey || event.metaKey || (chr < ' ' || !chars || chars.indexOf(chr) > -1);
  6522. }
  6523. },
  6524. /* Synchronise manual entry and field/alternate field. */
  6525. _doKeyUp: function(event) {
  6526. var inst = $.datepicker._getInst(event.target);
  6527. if (inst.input.val() != inst.lastVal) {
  6528. try {
  6529. var date = $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
  6530. (inst.input ? inst.input.val() : null),
  6531. $.datepicker._getFormatConfig(inst));
  6532. if (date) { // only if valid
  6533. $.datepicker._setDateFromField(inst);
  6534. $.datepicker._updateAlternate(inst);
  6535. $.datepicker._updateDatepicker(inst);
  6536. }
  6537. }
  6538. catch (err) {
  6539. $.datepicker.log(err);
  6540. }
  6541. }
  6542. return true;
  6543. },
  6544. /* Pop-up the date picker for a given input field.
  6545. If false returned from beforeShow event handler do not show.
  6546. @param input element - the input field attached to the date picker or
  6547. event - if triggered by focus */
  6548. _showDatepicker: function(input) {
  6549. input = input.target || input;
  6550. if (input.nodeName.toLowerCase() != 'input') // find from button/image trigger
  6551. input = $('input', input.parentNode)[0];
  6552. if ($.datepicker._isDisabledDatepicker(input) || $.datepicker._lastInput == input) // already here
  6553. return;
  6554. var inst = $.datepicker._getInst(input);
  6555. if ($.datepicker._curInst && $.datepicker._curInst != inst) {
  6556. $.datepicker._curInst.dpDiv.stop(true, true);
  6557. if ( inst && $.datepicker._datepickerShowing ) {
  6558. $.datepicker._hideDatepicker( $.datepicker._curInst.input[0] );
  6559. }
  6560. }
  6561. var beforeShow = $.datepicker._get(inst, 'beforeShow');
  6562. var beforeShowSettings = beforeShow ? beforeShow.apply(input, [input, inst]) : {};
  6563. if(beforeShowSettings === false){
  6564. //false
  6565. return;
  6566. }
  6567. extendRemove(inst.settings, beforeShowSettings);
  6568. inst.lastVal = null;
  6569. $.datepicker._lastInput = input;
  6570. $.datepicker._setDateFromField(inst);
  6571. if ($.datepicker._inDialog) // hide cursor
  6572. input.value = '';
  6573. if (!$.datepicker._pos) { // position below input
  6574. $.datepicker._pos = $.datepicker._findPos(input);
  6575. $.datepicker._pos[1] += input.offsetHeight; // add the height
  6576. }
  6577. var isFixed = false;
  6578. $(input).parents().each(function() {
  6579. isFixed |= $(this).css('position') == 'fixed';
  6580. return !isFixed;
  6581. });
  6582. var offset = {left: $.datepicker._pos[0], top: $.datepicker._pos[1]};
  6583. $.datepicker._pos = null;
  6584. //to avoid flashes on Firefox
  6585. inst.dpDiv.empty();
  6586. // determine sizing offscreen
  6587. inst.dpDiv.css({position: 'absolute', display: 'block', top: '-1000px'});
  6588. $.datepicker._updateDatepicker(inst);
  6589. // fix width for dynamic number of date pickers
  6590. // and adjust position before showing
  6591. offset = $.datepicker._checkOffset(inst, offset, isFixed);
  6592. inst.dpDiv.css({position: ($.datepicker._inDialog && $.blockUI ?
  6593. 'static' : (isFixed ? 'fixed' : 'absolute')), display: 'none',
  6594. left: offset.left + 'px', top: offset.top + 'px'});
  6595. if (!inst.inline) {
  6596. var showAnim = $.datepicker._get(inst, 'showAnim');
  6597. var duration = $.datepicker._get(inst, 'duration');
  6598. var postProcess = function() {
  6599. var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
  6600. if( !! cover.length ){
  6601. var borders = $.datepicker._getBorders(inst.dpDiv);
  6602. cover.css({left: -borders[0], top: -borders[1],
  6603. width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()});
  6604. }
  6605. };
  6606. inst.dpDiv.zIndex($(input).zIndex()+1);
  6607. $.datepicker._datepickerShowing = true;
  6608. // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed
  6609. if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) )
  6610. inst.dpDiv.show(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
  6611. else
  6612. inst.dpDiv[showAnim || 'show']((showAnim ? duration : null), postProcess);
  6613. if (!showAnim || !duration)
  6614. postProcess();
  6615. if (inst.input.is(':visible') && !inst.input.is(':disabled'))
  6616. inst.input.focus();
  6617. $.datepicker._curInst = inst;
  6618. }
  6619. },
  6620. /* Generate the date picker content. */
  6621. _updateDatepicker: function(inst) {
  6622. this.maxRows = 4; //Reset the max number of rows being displayed (see #7043)
  6623. var borders = $.datepicker._getBorders(inst.dpDiv);
  6624. instActive = inst; // for delegate hover events
  6625. inst.dpDiv.empty().append(this._generateHTML(inst));
  6626. this._attachHandlers(inst);
  6627. var cover = inst.dpDiv.find('iframe.ui-datepicker-cover'); // IE6- only
  6628. if( !!cover.length ){ //avoid call to outerXXXX() when not in IE6
  6629. cover.css({left: -borders[0], top: -borders[1], width: inst.dpDiv.outerWidth(), height: inst.dpDiv.outerHeight()})
  6630. }
  6631. inst.dpDiv.find('.' + this._dayOverClass + ' a').mouseover();
  6632. var numMonths = this._getNumberOfMonths(inst);
  6633. var cols = numMonths[1];
  6634. var width = 17;
  6635. inst.dpDiv.removeClass('ui-datepicker-multi-2 ui-datepicker-multi-3 ui-datepicker-multi-4').width('');
  6636. if (cols > 1)
  6637. inst.dpDiv.addClass('ui-datepicker-multi-' + cols).css('width', (width * cols) + 'em');
  6638. inst.dpDiv[(numMonths[0] != 1 || numMonths[1] != 1 ? 'add' : 'remove') +
  6639. 'Class']('ui-datepicker-multi');
  6640. inst.dpDiv[(this._get(inst, 'isRTL') ? 'add' : 'remove') +
  6641. 'Class']('ui-datepicker-rtl');
  6642. if (inst == $.datepicker._curInst && $.datepicker._datepickerShowing && inst.input &&
  6643. // #6694 - don't focus the input if it's already focused
  6644. // this breaks the change event in IE
  6645. inst.input.is(':visible') && !inst.input.is(':disabled') && inst.input[0] != document.activeElement)
  6646. inst.input.focus();
  6647. // deffered render of the years select (to avoid flashes on Firefox)
  6648. if( inst.yearshtml ){
  6649. var origyearshtml = inst.yearshtml;
  6650. setTimeout(function(){
  6651. //assure that inst.yearshtml didn't change.
  6652. if( origyearshtml === inst.yearshtml && inst.yearshtml ){
  6653. inst.dpDiv.find('select.ui-datepicker-year:first').replaceWith(inst.yearshtml);
  6654. }
  6655. origyearshtml = inst.yearshtml = null;
  6656. }, 0);
  6657. }
  6658. },
  6659. /* Retrieve the size of left and top borders for an element.
  6660. @param elem (jQuery object) the element of interest
  6661. @return (number[2]) the left and top borders */
  6662. _getBorders: function(elem) {
  6663. var convert = function(value) {
  6664. return {thin: 1, medium: 2, thick: 3}[value] || value;
  6665. };
  6666. return [parseFloat(convert(elem.css('border-left-width'))),
  6667. parseFloat(convert(elem.css('border-top-width')))];
  6668. },
  6669. /* Check positioning to remain on screen. */
  6670. _checkOffset: function(inst, offset, isFixed) {
  6671. var dpWidth = inst.dpDiv.outerWidth();
  6672. var dpHeight = inst.dpDiv.outerHeight();
  6673. var inputWidth = inst.input ? inst.input.outerWidth() : 0;
  6674. var inputHeight = inst.input ? inst.input.outerHeight() : 0;
  6675. var viewWidth = document.documentElement.clientWidth + (isFixed ? 0 : $(document).scrollLeft());
  6676. var viewHeight = document.documentElement.clientHeight + (isFixed ? 0 : $(document).scrollTop());
  6677. offset.left -= (this._get(inst, 'isRTL') ? (dpWidth - inputWidth) : 0);
  6678. offset.left -= (isFixed && offset.left == inst.input.offset().left) ? $(document).scrollLeft() : 0;
  6679. offset.top -= (isFixed && offset.top == (inst.input.offset().top + inputHeight)) ? $(document).scrollTop() : 0;
  6680. // now check if datepicker is showing outside window viewport - move to a better place if so.
  6681. offset.left -= Math.min(offset.left, (offset.left + dpWidth > viewWidth && viewWidth > dpWidth) ?
  6682. Math.abs(offset.left + dpWidth - viewWidth) : 0);
  6683. offset.top -= Math.min(offset.top, (offset.top + dpHeight > viewHeight && viewHeight > dpHeight) ?
  6684. Math.abs(dpHeight + inputHeight) : 0);
  6685. return offset;
  6686. },
  6687. /* Find an object's position on the screen. */
  6688. _findPos: function(obj) {
  6689. var inst = this._getInst(obj);
  6690. var isRTL = this._get(inst, 'isRTL');
  6691. while (obj && (obj.type == 'hidden' || obj.nodeType != 1 || $.expr.filters.hidden(obj))) {
  6692. obj = obj[isRTL ? 'previousSibling' : 'nextSibling'];
  6693. }
  6694. var position = $(obj).offset();
  6695. return [position.left, position.top];
  6696. },
  6697. /* Hide the date picker from view.
  6698. @param input element - the input field attached to the date picker */
  6699. _hideDatepicker: function(input) {
  6700. var inst = this._curInst;
  6701. if (!inst || (input && inst != $.data(input, PROP_NAME)))
  6702. return;
  6703. if (this._datepickerShowing) {
  6704. var showAnim = this._get(inst, 'showAnim');
  6705. var duration = this._get(inst, 'duration');
  6706. var postProcess = function() {
  6707. $.datepicker._tidyDialog(inst);
  6708. };
  6709. // DEPRECATED: after BC for 1.8.x $.effects[ showAnim ] is not needed
  6710. if ( $.effects && ( $.effects.effect[ showAnim ] || $.effects[ showAnim ] ) )
  6711. inst.dpDiv.hide(showAnim, $.datepicker._get(inst, 'showOptions'), duration, postProcess);
  6712. else
  6713. inst.dpDiv[(showAnim == 'slideDown' ? 'slideUp' :
  6714. (showAnim == 'fadeIn' ? 'fadeOut' : 'hide'))]((showAnim ? duration : null), postProcess);
  6715. if (!showAnim)
  6716. postProcess();
  6717. this._datepickerShowing = false;
  6718. var onClose = this._get(inst, 'onClose');
  6719. if (onClose)
  6720. onClose.apply((inst.input ? inst.input[0] : null),
  6721. [(inst.input ? inst.input.val() : ''), inst]);
  6722. this._lastInput = null;
  6723. if (this._inDialog) {
  6724. this._dialogInput.css({ position: 'absolute', left: '0', top: '-100px' });
  6725. if ($.blockUI) {
  6726. $.unblockUI();
  6727. $('body').append(this.dpDiv);
  6728. }
  6729. }
  6730. this._inDialog = false;
  6731. }
  6732. },
  6733. /* Tidy up after a dialog display. */
  6734. _tidyDialog: function(inst) {
  6735. inst.dpDiv.removeClass(this._dialogClass).unbind('.ui-datepicker-calendar');
  6736. },
  6737. /* Close date picker if clicked elsewhere. */
  6738. _checkExternalClick: function(event) {
  6739. if (!$.datepicker._curInst)
  6740. return;
  6741. var $target = $(event.target),
  6742. inst = $.datepicker._getInst($target[0]);
  6743. if ( ( ( $target[0].id != $.datepicker._mainDivId &&
  6744. $target.parents('#' + $.datepicker._mainDivId).length == 0 &&
  6745. !$target.hasClass($.datepicker.markerClassName) &&
  6746. !$target.closest("." + $.datepicker._triggerClass).length &&
  6747. $.datepicker._datepickerShowing && !($.datepicker._inDialog && $.blockUI) ) ) ||
  6748. ( $target.hasClass($.datepicker.markerClassName) && $.datepicker._curInst != inst ) )
  6749. $.datepicker._hideDatepicker();
  6750. },
  6751. /* Adjust one of the date sub-fields. */
  6752. _adjustDate: function(id, offset, period) {
  6753. var target = $(id);
  6754. var inst = this._getInst(target[0]);
  6755. if (this._isDisabledDatepicker(target[0])) {
  6756. return;
  6757. }
  6758. this._adjustInstDate(inst, offset +
  6759. (period == 'M' ? this._get(inst, 'showCurrentAtPos') : 0), // undo positioning
  6760. period);
  6761. this._updateDatepicker(inst);
  6762. },
  6763. /* Action for current link. */
  6764. _gotoToday: function(id) {
  6765. var target = $(id);
  6766. var inst = this._getInst(target[0]);
  6767. if (this._get(inst, 'gotoCurrent') && inst.currentDay) {
  6768. inst.selectedDay = inst.currentDay;
  6769. inst.drawMonth = inst.selectedMonth = inst.currentMonth;
  6770. inst.drawYear = inst.selectedYear = inst.currentYear;
  6771. }
  6772. else {
  6773. var date = new Date();
  6774. inst.selectedDay = date.getDate();
  6775. inst.drawMonth = inst.selectedMonth = date.getMonth();
  6776. inst.drawYear = inst.selectedYear = date.getFullYear();
  6777. }
  6778. this._notifyChange(inst);
  6779. this._adjustDate(target);
  6780. },
  6781. /* Action for selecting a new month/year. */
  6782. _selectMonthYear: function(id, select, period) {
  6783. var target = $(id);
  6784. var inst = this._getInst(target[0]);
  6785. inst['selected' + (period == 'M' ? 'Month' : 'Year')] =
  6786. inst['draw' + (period == 'M' ? 'Month' : 'Year')] =
  6787. parseInt(select.options[select.selectedIndex].value,10);
  6788. this._notifyChange(inst);
  6789. this._adjustDate(target);
  6790. },
  6791. /* Action for selecting a day. */
  6792. _selectDay: function(id, month, year, td) {
  6793. var target = $(id);
  6794. if ($(td).hasClass(this._unselectableClass) || this._isDisabledDatepicker(target[0])) {
  6795. return;
  6796. }
  6797. var inst = this._getInst(target[0]);
  6798. inst.selectedDay = inst.currentDay = $('a', td).html();
  6799. inst.selectedMonth = inst.currentMonth = month;
  6800. inst.selectedYear = inst.currentYear = year;
  6801. this._selectDate(id, this._formatDate(inst,
  6802. inst.currentDay, inst.currentMonth, inst.currentYear));
  6803. },
  6804. /* Erase the input field and hide the date picker. */
  6805. _clearDate: function(id) {
  6806. var target = $(id);
  6807. var inst = this._getInst(target[0]);
  6808. this._selectDate(target, '');
  6809. },
  6810. /* Update the input field with the selected date. */
  6811. _selectDate: function(id, dateStr) {
  6812. var target = $(id);
  6813. var inst = this._getInst(target[0]);
  6814. dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
  6815. if (inst.input)
  6816. inst.input.val(dateStr);
  6817. this._updateAlternate(inst);
  6818. var onSelect = this._get(inst, 'onSelect');
  6819. if (onSelect)
  6820. onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]); // trigger custom callback
  6821. else if (inst.input)
  6822. inst.input.trigger('change'); // fire the change event
  6823. if (inst.inline)
  6824. this._updateDatepicker(inst);
  6825. else {
  6826. this._hideDatepicker();
  6827. this._lastInput = inst.input[0];
  6828. if (typeof(inst.input[0]) != 'object')
  6829. inst.input.focus(); // restore focus
  6830. this._lastInput = null;
  6831. }
  6832. },
  6833. /* Update any alternate field to synchronise with the main field. */
  6834. _updateAlternate: function(inst) {
  6835. var altField = this._get(inst, 'altField');
  6836. if (altField) { // update alternate field too
  6837. var altFormat = this._get(inst, 'altFormat') || this._get(inst, 'dateFormat');
  6838. var date = this._getDate(inst);
  6839. var dateStr = this.formatDate(altFormat, date, this._getFormatConfig(inst));
  6840. $(altField).each(function() { $(this).val(dateStr); });
  6841. }
  6842. },
  6843. /* Set as beforeShowDay function to prevent selection of weekends.
  6844. @param date Date - the date to customise
  6845. @return [boolean, string] - is this date selectable?, what is its CSS class? */
  6846. noWeekends: function(date) {
  6847. var day = date.getDay();
  6848. return [(day > 0 && day < 6), ''];
  6849. },
  6850. /* Set as calculateWeek to determine the week of the year based on the ISO 8601 definition.
  6851. @param date Date - the date to get the week for
  6852. @return number - the number of the week within the year that contains this date */
  6853. iso8601Week: function(date) {
  6854. var checkDate = new Date(date.getTime());
  6855. // Find Thursday of this week starting on Monday
  6856. checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
  6857. var time = checkDate.getTime();
  6858. checkDate.setMonth(0); // Compare with Jan 1
  6859. checkDate.setDate(1);
  6860. return Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 1;
  6861. },
  6862. /* Parse a string value into a date object.
  6863. See formatDate below for the possible formats.
  6864. @param format string - the expected format of the date
  6865. @param value string - the date in the above format
  6866. @param settings Object - attributes include:
  6867. shortYearCutoff number - the cutoff year for determining the century (optional)
  6868. dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  6869. dayNames string[7] - names of the days from Sunday (optional)
  6870. monthNamesShort string[12] - abbreviated names of the months (optional)
  6871. monthNames string[12] - names of the months (optional)
  6872. @return Date - the extracted date value or null if value is blank */
  6873. parseDate: function (format, value, settings) {
  6874. if (format == null || value == null)
  6875. throw 'Invalid arguments';
  6876. value = (typeof value == 'object' ? value.toString() : value + '');
  6877. if (value == '')
  6878. return null;
  6879. var shortYearCutoff = (settings ? settings.shortYearCutoff : null) || this._defaults.shortYearCutoff;
  6880. shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
  6881. new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
  6882. var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
  6883. var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
  6884. var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
  6885. var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
  6886. var year = -1;
  6887. var month = -1;
  6888. var day = -1;
  6889. var doy = -1;
  6890. var literal = false;
  6891. // Check whether a format character is doubled
  6892. var lookAhead = function(match) {
  6893. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  6894. if (matches)
  6895. iFormat++;
  6896. return matches;
  6897. };
  6898. // Extract a number from the string value
  6899. var getNumber = function(match) {
  6900. var isDoubled = lookAhead(match);
  6901. var size = (match == '@' ? 14 : (match == '!' ? 20 :
  6902. (match == 'y' && isDoubled ? 4 : (match == 'o' ? 3 : 2))));
  6903. var digits = new RegExp('^\\d{1,' + size + '}');
  6904. var num = value.substring(iValue).match(digits);
  6905. if (!num)
  6906. throw 'Missing number at position ' + iValue;
  6907. iValue += num[0].length;
  6908. return parseInt(num[0], 10);
  6909. };
  6910. // Extract a name from the string value and convert to an index
  6911. var getName = function(match, shortNames, longNames) {
  6912. var names = $.map(lookAhead(match) ? longNames : shortNames, function (v, k) {
  6913. return [ [k, v] ];
  6914. }).sort(function (a, b) {
  6915. return -(a[1].length - b[1].length);
  6916. });
  6917. var index = -1;
  6918. $.each(names, function (i, pair) {
  6919. var name = pair[1];
  6920. if (value.substr(iValue, name.length).toLowerCase() == name.toLowerCase()) {
  6921. index = pair[0];
  6922. iValue += name.length;
  6923. return false;
  6924. }
  6925. });
  6926. if (index != -1)
  6927. return index + 1;
  6928. else
  6929. throw 'Unknown name at position ' + iValue;
  6930. };
  6931. // Confirm that a literal character matches the string value
  6932. var checkLiteral = function() {
  6933. if (value.charAt(iValue) != format.charAt(iFormat))
  6934. throw 'Unexpected literal at position ' + iValue;
  6935. iValue++;
  6936. };
  6937. var iValue = 0;
  6938. for (var iFormat = 0; iFormat < format.length; iFormat++) {
  6939. if (literal)
  6940. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  6941. literal = false;
  6942. else
  6943. checkLiteral();
  6944. else
  6945. switch (format.charAt(iFormat)) {
  6946. case 'd':
  6947. day = getNumber('d');
  6948. break;
  6949. case 'D':
  6950. getName('D', dayNamesShort, dayNames);
  6951. break;
  6952. case 'o':
  6953. doy = getNumber('o');
  6954. break;
  6955. case 'm':
  6956. month = getNumber('m');
  6957. break;
  6958. case 'M':
  6959. month = getName('M', monthNamesShort, monthNames);
  6960. break;
  6961. case 'y':
  6962. year = getNumber('y');
  6963. break;
  6964. case '@':
  6965. var date = new Date(getNumber('@'));
  6966. year = date.getFullYear();
  6967. month = date.getMonth() + 1;
  6968. day = date.getDate();
  6969. break;
  6970. case '!':
  6971. var date = new Date((getNumber('!') - this._ticksTo1970) / 10000);
  6972. year = date.getFullYear();
  6973. month = date.getMonth() + 1;
  6974. day = date.getDate();
  6975. break;
  6976. case "'":
  6977. if (lookAhead("'"))
  6978. checkLiteral();
  6979. else
  6980. literal = true;
  6981. break;
  6982. default:
  6983. checkLiteral();
  6984. }
  6985. }
  6986. if (iValue < value.length){
  6987. var extra = value.substr(iValue);
  6988. if (!/^\s+/.test(extra)) {
  6989. throw "Extra/unparsed characters found in date: " + extra;
  6990. }
  6991. }
  6992. if (year == -1)
  6993. year = new Date().getFullYear();
  6994. else if (year < 100)
  6995. year += new Date().getFullYear() - new Date().getFullYear() % 100 +
  6996. (year <= shortYearCutoff ? 0 : -100);
  6997. if (doy > -1) {
  6998. month = 1;
  6999. day = doy;
  7000. do {
  7001. var dim = this._getDaysInMonth(year, month - 1);
  7002. if (day <= dim)
  7003. break;
  7004. month++;
  7005. day -= dim;
  7006. } while (true);
  7007. }
  7008. var date = this._daylightSavingAdjust(new Date(year, month - 1, day));
  7009. if (date.getFullYear() != year || date.getMonth() + 1 != month || date.getDate() != day)
  7010. throw 'Invalid date'; // E.g. 31/02/00
  7011. return date;
  7012. },
  7013. /* Standard date formats. */
  7014. ATOM: 'yy-mm-dd', // RFC 3339 (ISO 8601)
  7015. COOKIE: 'D, dd M yy',
  7016. ISO_8601: 'yy-mm-dd',
  7017. RFC_822: 'D, d M y',
  7018. RFC_850: 'DD, dd-M-y',
  7019. RFC_1036: 'D, d M y',
  7020. RFC_1123: 'D, d M yy',
  7021. RFC_2822: 'D, d M yy',
  7022. RSS: 'D, d M y', // RFC 822
  7023. TICKS: '!',
  7024. TIMESTAMP: '@',
  7025. W3C: 'yy-mm-dd', // ISO 8601
  7026. _ticksTo1970: (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) +
  7027. Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000),
  7028. /* Format a date object into a string value.
  7029. The format can be combinations of the following:
  7030. d - day of month (no leading zero)
  7031. dd - day of month (two digit)
  7032. o - day of year (no leading zeros)
  7033. oo - day of year (three digit)
  7034. D - day name short
  7035. DD - day name long
  7036. m - month of year (no leading zero)
  7037. mm - month of year (two digit)
  7038. M - month name short
  7039. MM - month name long
  7040. y - year (two digit)
  7041. yy - year (four digit)
  7042. @ - Unix timestamp (ms since 01/01/1970)
  7043. ! - Windows ticks (100ns since 01/01/0001)
  7044. '...' - literal text
  7045. '' - single quote
  7046. @param format string - the desired format of the date
  7047. @param date Date - the date value to format
  7048. @param settings Object - attributes include:
  7049. dayNamesShort string[7] - abbreviated names of the days from Sunday (optional)
  7050. dayNames string[7] - names of the days from Sunday (optional)
  7051. monthNamesShort string[12] - abbreviated names of the months (optional)
  7052. monthNames string[12] - names of the months (optional)
  7053. @return string - the date in the above format */
  7054. formatDate: function (format, date, settings) {
  7055. if (!date)
  7056. return '';
  7057. var dayNamesShort = (settings ? settings.dayNamesShort : null) || this._defaults.dayNamesShort;
  7058. var dayNames = (settings ? settings.dayNames : null) || this._defaults.dayNames;
  7059. var monthNamesShort = (settings ? settings.monthNamesShort : null) || this._defaults.monthNamesShort;
  7060. var monthNames = (settings ? settings.monthNames : null) || this._defaults.monthNames;
  7061. // Check whether a format character is doubled
  7062. var lookAhead = function(match) {
  7063. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  7064. if (matches)
  7065. iFormat++;
  7066. return matches;
  7067. };
  7068. // Format a number, with leading zero if necessary
  7069. var formatNumber = function(match, value, len) {
  7070. var num = '' + value;
  7071. if (lookAhead(match))
  7072. while (num.length < len)
  7073. num = '0' + num;
  7074. return num;
  7075. };
  7076. // Format a name, short or long as requested
  7077. var formatName = function(match, value, shortNames, longNames) {
  7078. return (lookAhead(match) ? longNames[value] : shortNames[value]);
  7079. };
  7080. var output = '';
  7081. var literal = false;
  7082. if (date)
  7083. for (var iFormat = 0; iFormat < format.length; iFormat++) {
  7084. if (literal)
  7085. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  7086. literal = false;
  7087. else
  7088. output += format.charAt(iFormat);
  7089. else
  7090. switch (format.charAt(iFormat)) {
  7091. case 'd':
  7092. output += formatNumber('d', date.getDate(), 2);
  7093. break;
  7094. case 'D':
  7095. output += formatName('D', date.getDay(), dayNamesShort, dayNames);
  7096. break;
  7097. case 'o':
  7098. output += formatNumber('o',
  7099. Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() - new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
  7100. break;
  7101. case 'm':
  7102. output += formatNumber('m', date.getMonth() + 1, 2);
  7103. break;
  7104. case 'M':
  7105. output += formatName('M', date.getMonth(), monthNamesShort, monthNames);
  7106. break;
  7107. case 'y':
  7108. output += (lookAhead('y') ? date.getFullYear() :
  7109. (date.getYear() % 100 < 10 ? '0' : '') + date.getYear() % 100);
  7110. break;
  7111. case '@':
  7112. output += date.getTime();
  7113. break;
  7114. case '!':
  7115. output += date.getTime() * 10000 + this._ticksTo1970;
  7116. break;
  7117. case "'":
  7118. if (lookAhead("'"))
  7119. output += "'";
  7120. else
  7121. literal = true;
  7122. break;
  7123. default:
  7124. output += format.charAt(iFormat);
  7125. }
  7126. }
  7127. return output;
  7128. },
  7129. /* Extract all possible characters from the date format. */
  7130. _possibleChars: function (format) {
  7131. var chars = '';
  7132. var literal = false;
  7133. // Check whether a format character is doubled
  7134. var lookAhead = function(match) {
  7135. var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
  7136. if (matches)
  7137. iFormat++;
  7138. return matches;
  7139. };
  7140. for (var iFormat = 0; iFormat < format.length; iFormat++)
  7141. if (literal)
  7142. if (format.charAt(iFormat) == "'" && !lookAhead("'"))
  7143. literal = false;
  7144. else
  7145. chars += format.charAt(iFormat);
  7146. else
  7147. switch (format.charAt(iFormat)) {
  7148. case 'd': case 'm': case 'y': case '@':
  7149. chars += '0123456789';
  7150. break;
  7151. case 'D': case 'M':
  7152. return null; // Accept anything
  7153. case "'":
  7154. if (lookAhead("'"))
  7155. chars += "'";
  7156. else
  7157. literal = true;
  7158. break;
  7159. default:
  7160. chars += format.charAt(iFormat);
  7161. }
  7162. return chars;
  7163. },
  7164. /* Get a setting value, defaulting if necessary. */
  7165. _get: function(inst, name) {
  7166. return inst.settings[name] !== undefined ?
  7167. inst.settings[name] : this._defaults[name];
  7168. },
  7169. /* Parse existing date and initialise date picker. */
  7170. _setDateFromField: function(inst, noDefault) {
  7171. if (inst.input.val() == inst.lastVal) {
  7172. return;
  7173. }
  7174. var dateFormat = this._get(inst, 'dateFormat');
  7175. var dates = inst.lastVal = inst.input ? inst.input.val() : null;
  7176. var date, defaultDate;
  7177. date = defaultDate = this._getDefaultDate(inst);
  7178. var settings = this._getFormatConfig(inst);
  7179. try {
  7180. date = this.parseDate(dateFormat, dates, settings) || defaultDate;
  7181. } catch (event) {
  7182. this.log(event);
  7183. dates = (noDefault ? '' : dates);
  7184. }
  7185. inst.selectedDay = date.getDate();
  7186. inst.drawMonth = inst.selectedMonth = date.getMonth();
  7187. inst.drawYear = inst.selectedYear = date.getFullYear();
  7188. inst.currentDay = (dates ? date.getDate() : 0);
  7189. inst.currentMonth = (dates ? date.getMonth() : 0);
  7190. inst.currentYear = (dates ? date.getFullYear() : 0);
  7191. this._adjustInstDate(inst);
  7192. },
  7193. /* Retrieve the default date shown on opening. */
  7194. _getDefaultDate: function(inst) {
  7195. return this._restrictMinMax(inst,
  7196. this._determineDate(inst, this._get(inst, 'defaultDate'), new Date()));
  7197. },
  7198. /* A date may be specified as an exact value or a relative one. */
  7199. _determineDate: function(inst, date, defaultDate) {
  7200. var offsetNumeric = function(offset) {
  7201. var date = new Date();
  7202. date.setDate(date.getDate() + offset);
  7203. return date;
  7204. };
  7205. var offsetString = function(offset) {
  7206. try {
  7207. return $.datepicker.parseDate($.datepicker._get(inst, 'dateFormat'),
  7208. offset, $.datepicker._getFormatConfig(inst));
  7209. }
  7210. catch (e) {
  7211. // Ignore
  7212. }
  7213. var date = (offset.toLowerCase().match(/^c/) ?
  7214. $.datepicker._getDate(inst) : null) || new Date();
  7215. var year = date.getFullYear();
  7216. var month = date.getMonth();
  7217. var day = date.getDate();
  7218. var pattern = /([+-]?[0-9]+)\s*(d|D|w|W|m|M|y|Y)?/g;
  7219. var matches = pattern.exec(offset);
  7220. while (matches) {
  7221. switch (matches[2] || 'd') {
  7222. case 'd' : case 'D' :
  7223. day += parseInt(matches[1],10); break;
  7224. case 'w' : case 'W' :
  7225. day += parseInt(matches[1],10) * 7; break;
  7226. case 'm' : case 'M' :
  7227. month += parseInt(matches[1],10);
  7228. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  7229. break;
  7230. case 'y': case 'Y' :
  7231. year += parseInt(matches[1],10);
  7232. day = Math.min(day, $.datepicker._getDaysInMonth(year, month));
  7233. break;
  7234. }
  7235. matches = pattern.exec(offset);
  7236. }
  7237. return new Date(year, month, day);
  7238. };
  7239. var newDate = (date == null || date === '' ? defaultDate : (typeof date == 'string' ? offsetString(date) :
  7240. (typeof date == 'number' ? (isNaN(date) ? defaultDate : offsetNumeric(date)) : new Date(date.getTime()))));
  7241. newDate = (newDate && newDate.toString() == 'Invalid Date' ? defaultDate : newDate);
  7242. if (newDate) {
  7243. newDate.setHours(0);
  7244. newDate.setMinutes(0);
  7245. newDate.setSeconds(0);
  7246. newDate.setMilliseconds(0);
  7247. }
  7248. return this._daylightSavingAdjust(newDate);
  7249. },
  7250. /* Handle switch to/from daylight saving.
  7251. Hours may be non-zero on daylight saving cut-over:
  7252. > 12 when midnight changeover, but then cannot generate
  7253. midnight datetime, so jump to 1AM, otherwise reset.
  7254. @param date (Date) the date to check
  7255. @return (Date) the corrected date */
  7256. _daylightSavingAdjust: function(date) {
  7257. if (!date) return null;
  7258. date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
  7259. return date;
  7260. },
  7261. /* Set the date(s) directly. */
  7262. _setDate: function(inst, date, noChange) {
  7263. var clear = !date;
  7264. var origMonth = inst.selectedMonth;
  7265. var origYear = inst.selectedYear;
  7266. var newDate = this._restrictMinMax(inst, this._determineDate(inst, date, new Date()));
  7267. inst.selectedDay = inst.currentDay = newDate.getDate();
  7268. inst.drawMonth = inst.selectedMonth = inst.currentMonth = newDate.getMonth();
  7269. inst.drawYear = inst.selectedYear = inst.currentYear = newDate.getFullYear();
  7270. if ((origMonth != inst.selectedMonth || origYear != inst.selectedYear) && !noChange)
  7271. this._notifyChange(inst);
  7272. this._adjustInstDate(inst);
  7273. if (inst.input) {
  7274. inst.input.val(clear ? '' : this._formatDate(inst));
  7275. }
  7276. },
  7277. /* Retrieve the date(s) directly. */
  7278. _getDate: function(inst) {
  7279. var startDate = (!inst.currentYear || (inst.input && inst.input.val() == '') ? null :
  7280. this._daylightSavingAdjust(new Date(
  7281. inst.currentYear, inst.currentMonth, inst.currentDay)));
  7282. return startDate;
  7283. },
  7284. /* Attach the onxxx handlers. These are declared statically so
  7285. * they work with static code transformers like Caja.
  7286. */
  7287. _attachHandlers: function(inst) {
  7288. var stepMonths = this._get(inst, 'stepMonths');
  7289. var id = '#' + inst.id.replace( /\\\\/g, "\\" );
  7290. inst.dpDiv.find('[data-handler]').map(function () {
  7291. var handler = {
  7292. prev: function () {
  7293. window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, -stepMonths, 'M');
  7294. },
  7295. next: function () {
  7296. window['DP_jQuery_' + dpuuid].datepicker._adjustDate(id, +stepMonths, 'M');
  7297. },
  7298. hide: function () {
  7299. window['DP_jQuery_' + dpuuid].datepicker._hideDatepicker();
  7300. },
  7301. today: function () {
  7302. window['DP_jQuery_' + dpuuid].datepicker._gotoToday(id);
  7303. },
  7304. selectDay: function () {
  7305. window['DP_jQuery_' + dpuuid].datepicker._selectDay(id, +this.getAttribute('data-month'), +this.getAttribute('data-year'), this);
  7306. return false;
  7307. },
  7308. selectMonth: function () {
  7309. window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'M');
  7310. return false;
  7311. },
  7312. selectYear: function () {
  7313. window['DP_jQuery_' + dpuuid].datepicker._selectMonthYear(id, this, 'Y');
  7314. return false;
  7315. }
  7316. };
  7317. $(this).bind(this.getAttribute('data-event'), handler[this.getAttribute('data-handler')]);
  7318. });
  7319. },
  7320. /* Generate the HTML for the current state of the date picker. */
  7321. _generateHTML: function(inst) {
  7322. var today = new Date();
  7323. today = this._daylightSavingAdjust(
  7324. new Date(today.getFullYear(), today.getMonth(), today.getDate())); // clear time
  7325. var isRTL = this._get(inst, 'isRTL');
  7326. var showButtonPanel = this._get(inst, 'showButtonPanel');
  7327. var hideIfNoPrevNext = this._get(inst, 'hideIfNoPrevNext');
  7328. var navigationAsDateFormat = this._get(inst, 'navigationAsDateFormat');
  7329. var numMonths = this._getNumberOfMonths(inst);
  7330. var showCurrentAtPos = this._get(inst, 'showCurrentAtPos');
  7331. var stepMonths = this._get(inst, 'stepMonths');
  7332. var isMultiMonth = (numMonths[0] != 1 || numMonths[1] != 1);
  7333. var currentDate = this._daylightSavingAdjust((!inst.currentDay ? new Date(9999, 9, 9) :
  7334. new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  7335. var minDate = this._getMinMaxDate(inst, 'min');
  7336. var maxDate = this._getMinMaxDate(inst, 'max');
  7337. var drawMonth = inst.drawMonth - showCurrentAtPos;
  7338. var drawYear = inst.drawYear;
  7339. if (drawMonth < 0) {
  7340. drawMonth += 12;
  7341. drawYear--;
  7342. }
  7343. if (maxDate) {
  7344. var maxDraw = this._daylightSavingAdjust(new Date(maxDate.getFullYear(),
  7345. maxDate.getMonth() - (numMonths[0] * numMonths[1]) + 1, maxDate.getDate()));
  7346. maxDraw = (minDate && maxDraw < minDate ? minDate : maxDraw);
  7347. while (this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1)) > maxDraw) {
  7348. drawMonth--;
  7349. if (drawMonth < 0) {
  7350. drawMonth = 11;
  7351. drawYear--;
  7352. }
  7353. }
  7354. }
  7355. inst.drawMonth = drawMonth;
  7356. inst.drawYear = drawYear;
  7357. var prevText = this._get(inst, 'prevText');
  7358. prevText = (!navigationAsDateFormat ? prevText : this.formatDate(prevText,
  7359. this._daylightSavingAdjust(new Date(drawYear, drawMonth - stepMonths, 1)),
  7360. this._getFormatConfig(inst)));
  7361. var prev = (this._canAdjustMonth(inst, -1, drawYear, drawMonth) ?
  7362. '<a class="ui-datepicker-prev ui-corner-all" data-handler="prev" data-event="click"' +
  7363. ' title="' + prevText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'e' : 'w') + '">' + prevText + '</span></a>' :
  7364. (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>'));
  7365. var nextText = this._get(inst, 'nextText');
  7366. nextText = (!navigationAsDateFormat ? nextText : this.formatDate(nextText,
  7367. this._daylightSavingAdjust(new Date(drawYear, drawMonth + stepMonths, 1)),
  7368. this._getFormatConfig(inst)));
  7369. var next = (this._canAdjustMonth(inst, +1, drawYear, drawMonth) ?
  7370. '<a class="ui-datepicker-next ui-corner-all" data-handler="next" data-event="click"' +
  7371. ' title="' + nextText + '"><span class="ui-icon ui-icon-circle-triangle-' + ( isRTL ? 'w' : 'e') + '">' + nextText + '</span></a>' :
  7372. (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>'));
  7373. var currentText = this._get(inst, 'currentText');
  7374. var gotoDate = (this._get(inst, 'gotoCurrent') && inst.currentDay ? currentDate : today);
  7375. currentText = (!navigationAsDateFormat ? currentText :
  7376. this.formatDate(currentText, gotoDate, this._getFormatConfig(inst)));
  7377. 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">' +
  7378. this._get(inst, 'closeText') + '</button>' : '');
  7379. var buttonPanel = (showButtonPanel) ? '<div class="ui-datepicker-buttonpane ui-widget-content">' + (isRTL ? controls : '') +
  7380. (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"' +
  7381. '>' + currentText + '</button>' : '') + (isRTL ? '' : controls) + '</div>' : '';
  7382. var firstDay = parseInt(this._get(inst, 'firstDay'),10);
  7383. firstDay = (isNaN(firstDay) ? 0 : firstDay);
  7384. var showWeek = this._get(inst, 'showWeek');
  7385. var dayNames = this._get(inst, 'dayNames');
  7386. var dayNamesShort = this._get(inst, 'dayNamesShort');
  7387. var dayNamesMin = this._get(inst, 'dayNamesMin');
  7388. var monthNames = this._get(inst, 'monthNames');
  7389. var monthNamesShort = this._get(inst, 'monthNamesShort');
  7390. var beforeShowDay = this._get(inst, 'beforeShowDay');
  7391. var showOtherMonths = this._get(inst, 'showOtherMonths');
  7392. var selectOtherMonths = this._get(inst, 'selectOtherMonths');
  7393. var calculateWeek = this._get(inst, 'calculateWeek') || this.iso8601Week;
  7394. var defaultDate = this._getDefaultDate(inst);
  7395. var html = '';
  7396. for (var row = 0; row < numMonths[0]; row++) {
  7397. var group = '';
  7398. this.maxRows = 4;
  7399. for (var col = 0; col < numMonths[1]; col++) {
  7400. var selectedDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, inst.selectedDay));
  7401. var cornerClass = ' ui-corner-all';
  7402. var calender = '';
  7403. if (isMultiMonth) {
  7404. calender += '<div class="ui-datepicker-group';
  7405. if (numMonths[1] > 1)
  7406. switch (col) {
  7407. case 0: calender += ' ui-datepicker-group-first';
  7408. cornerClass = ' ui-corner-' + (isRTL ? 'right' : 'left'); break;
  7409. case numMonths[1]-1: calender += ' ui-datepicker-group-last';
  7410. cornerClass = ' ui-corner-' + (isRTL ? 'left' : 'right'); break;
  7411. default: calender += ' ui-datepicker-group-middle'; cornerClass = ''; break;
  7412. }
  7413. calender += '">';
  7414. }
  7415. calender += '<div class="ui-datepicker-header ui-widget-header ui-helper-clearfix' + cornerClass + '">' +
  7416. (/all|left/.test(cornerClass) && row == 0 ? (isRTL ? next : prev) : '') +
  7417. (/all|right/.test(cornerClass) && row == 0 ? (isRTL ? prev : next) : '') +
  7418. this._generateMonthYearHeader(inst, drawMonth, drawYear, minDate, maxDate,
  7419. row > 0 || col > 0, monthNames, monthNamesShort) + // draw month headers
  7420. '</div><table class="ui-datepicker-calendar"><thead>' +
  7421. '<tr>';
  7422. var thead = (showWeek ? '<th class="ui-datepicker-week-col">' + this._get(inst, 'weekHeader') + '</th>' : '');
  7423. for (var dow = 0; dow < 7; dow++) { // days of the week
  7424. var day = (dow + firstDay) % 7;
  7425. thead += '<th' + ((dow + firstDay + 6) % 7 >= 5 ? ' class="ui-datepicker-week-end"' : '') + '>' +
  7426. '<span title="' + dayNames[day] + '">' + dayNamesMin[day] + '</span></th>';
  7427. }
  7428. calender += thead + '</tr></thead><tbody>';
  7429. var daysInMonth = this._getDaysInMonth(drawYear, drawMonth);
  7430. if (drawYear == inst.selectedYear && drawMonth == inst.selectedMonth)
  7431. inst.selectedDay = Math.min(inst.selectedDay, daysInMonth);
  7432. var leadDays = (this._getFirstDayOfMonth(drawYear, drawMonth) - firstDay + 7) % 7;
  7433. var curRows = Math.ceil((leadDays + daysInMonth) / 7); // calculate the number of rows to generate
  7434. var numRows = (isMultiMonth ? this.maxRows > curRows ? this.maxRows : curRows : curRows); //If multiple months, use the higher number of rows (see #7043)
  7435. this.maxRows = numRows;
  7436. var printDate = this._daylightSavingAdjust(new Date(drawYear, drawMonth, 1 - leadDays));
  7437. for (var dRow = 0; dRow < numRows; dRow++) { // create date picker rows
  7438. calender += '<tr>';
  7439. var tbody = (!showWeek ? '' : '<td class="ui-datepicker-week-col">' +
  7440. this._get(inst, 'calculateWeek')(printDate) + '</td>');
  7441. for (var dow = 0; dow < 7; dow++) { // create date picker days
  7442. var daySettings = (beforeShowDay ?
  7443. beforeShowDay.apply((inst.input ? inst.input[0] : null), [printDate]) : [true, '']);
  7444. var otherMonth = (printDate.getMonth() != drawMonth);
  7445. var unselectable = (otherMonth && !selectOtherMonths) || !daySettings[0] ||
  7446. (minDate && printDate < minDate) || (maxDate && printDate > maxDate);
  7447. tbody += '<td class="' +
  7448. ((dow + firstDay + 6) % 7 >= 5 ? ' ui-datepicker-week-end' : '') + // highlight weekends
  7449. (otherMonth ? ' ui-datepicker-other-month' : '') + // highlight days from other months
  7450. ((printDate.getTime() == selectedDate.getTime() && drawMonth == inst.selectedMonth && inst._keyEvent) || // user pressed key
  7451. (defaultDate.getTime() == printDate.getTime() && defaultDate.getTime() == selectedDate.getTime()) ?
  7452. // or defaultDate is current printedDate and defaultDate is selectedDate
  7453. ' ' + this._dayOverClass : '') + // highlight selected day
  7454. (unselectable ? ' ' + this._unselectableClass + ' ui-state-disabled': '') + // highlight unselectable days
  7455. (otherMonth && !showOtherMonths ? '' : ' ' + daySettings[1] + // highlight custom dates
  7456. (printDate.getTime() == currentDate.getTime() ? ' ' + this._currentClass : '') + // highlight selected day
  7457. (printDate.getTime() == today.getTime() ? ' ui-datepicker-today' : '')) + '"' + // highlight today (if different)
  7458. ((!otherMonth || showOtherMonths) && daySettings[2] ? ' title="' + daySettings[2] + '"' : '') + // cell title
  7459. (unselectable ? '' : ' data-handler="selectDay" data-event="click" data-month="' + printDate.getMonth() + '" data-year="' + printDate.getFullYear() + '"') + '>' + // actions
  7460. (otherMonth && !showOtherMonths ? '&#xa0;' : // display for other months
  7461. (unselectable ? '<span class="ui-state-default">' + printDate.getDate() + '</span>' : '<a class="ui-state-default' +
  7462. (printDate.getTime() == today.getTime() ? ' ui-state-highlight' : '') +
  7463. (printDate.getTime() == currentDate.getTime() ? ' ui-state-active' : '') + // highlight selected day
  7464. (otherMonth ? ' ui-priority-secondary' : '') + // distinguish dates from other months
  7465. '" href="#">' + printDate.getDate() + '</a>')) + '</td>'; // display selectable date
  7466. printDate.setDate(printDate.getDate() + 1);
  7467. printDate = this._daylightSavingAdjust(printDate);
  7468. }
  7469. calender += tbody + '</tr>';
  7470. }
  7471. drawMonth++;
  7472. if (drawMonth > 11) {
  7473. drawMonth = 0;
  7474. drawYear++;
  7475. }
  7476. calender += '</tbody></table>' + (isMultiMonth ? '</div>' +
  7477. ((numMonths[0] > 0 && col == numMonths[1]-1) ? '<div class="ui-datepicker-row-break"></div>' : '') : '');
  7478. group += calender;
  7479. }
  7480. html += group;
  7481. }
  7482. html += buttonPanel + ($.browser.msie && parseInt($.browser.version,10) < 7 && !inst.inline ?
  7483. '<iframe src="javascript:false;" class="ui-datepicker-cover" frameborder="0"></iframe>' : '');
  7484. inst._keyEvent = false;
  7485. return html;
  7486. },
  7487. /* Generate the month and year header. */
  7488. _generateMonthYearHeader: function(inst, drawMonth, drawYear, minDate, maxDate,
  7489. secondary, monthNames, monthNamesShort) {
  7490. var changeMonth = this._get(inst, 'changeMonth');
  7491. var changeYear = this._get(inst, 'changeYear');
  7492. var showMonthAfterYear = this._get(inst, 'showMonthAfterYear');
  7493. var html = '<div class="ui-datepicker-title">';
  7494. var monthHtml = '';
  7495. // month selection
  7496. if (secondary || !changeMonth)
  7497. monthHtml += '<span class="ui-datepicker-month">' + monthNames[drawMonth] + '</span>';
  7498. else {
  7499. var inMinYear = (minDate && minDate.getFullYear() == drawYear);
  7500. var inMaxYear = (maxDate && maxDate.getFullYear() == drawYear);
  7501. monthHtml += '<select class="ui-datepicker-month" data-handler="selectMonth" data-event="change">';
  7502. for (var month = 0; month < 12; month++) {
  7503. if ((!inMinYear || month >= minDate.getMonth()) &&
  7504. (!inMaxYear || month <= maxDate.getMonth()))
  7505. monthHtml += '<option value="' + month + '"' +
  7506. (month == drawMonth ? ' selected="selected"' : '') +
  7507. '>' + monthNamesShort[month] + '</option>';
  7508. }
  7509. monthHtml += '</select>';
  7510. }
  7511. if (!showMonthAfterYear)
  7512. html += monthHtml + (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '');
  7513. // year selection
  7514. if ( !inst.yearshtml ) {
  7515. inst.yearshtml = '';
  7516. if (secondary || !changeYear)
  7517. html += '<span class="ui-datepicker-year">' + drawYear + '</span>';
  7518. else {
  7519. // determine range of years to display
  7520. var years = this._get(inst, 'yearRange').split(':');
  7521. var thisYear = new Date().getFullYear();
  7522. var determineYear = function(value) {
  7523. var year = (value.match(/c[+-].*/) ? drawYear + parseInt(value.substring(1), 10) :
  7524. (value.match(/[+-].*/) ? thisYear + parseInt(value, 10) :
  7525. parseInt(value, 10)));
  7526. return (isNaN(year) ? thisYear : year);
  7527. };
  7528. var year = determineYear(years[0]);
  7529. var endYear = Math.max(year, determineYear(years[1] || ''));
  7530. year = (minDate ? Math.max(year, minDate.getFullYear()) : year);
  7531. endYear = (maxDate ? Math.min(endYear, maxDate.getFullYear()) : endYear);
  7532. inst.yearshtml += '<select class="ui-datepicker-year" data-handler="selectYear" data-event="change">';
  7533. for (; year <= endYear; year++) {
  7534. inst.yearshtml += '<option value="' + year + '"' +
  7535. (year == drawYear ? ' selected="selected"' : '') +
  7536. '>' + year + '</option>';
  7537. }
  7538. inst.yearshtml += '</select>';
  7539. html += inst.yearshtml;
  7540. inst.yearshtml = null;
  7541. }
  7542. }
  7543. html += this._get(inst, 'yearSuffix');
  7544. if (showMonthAfterYear)
  7545. html += (secondary || !(changeMonth && changeYear) ? '&#xa0;' : '') + monthHtml;
  7546. html += '</div>'; // Close datepicker_header
  7547. return html;
  7548. },
  7549. /* Adjust one of the date sub-fields. */
  7550. _adjustInstDate: function(inst, offset, period) {
  7551. var year = inst.drawYear + (period == 'Y' ? offset : 0);
  7552. var month = inst.drawMonth + (period == 'M' ? offset : 0);
  7553. var day = Math.min(inst.selectedDay, this._getDaysInMonth(year, month)) +
  7554. (period == 'D' ? offset : 0);
  7555. var date = this._restrictMinMax(inst,
  7556. this._daylightSavingAdjust(new Date(year, month, day)));
  7557. inst.selectedDay = date.getDate();
  7558. inst.drawMonth = inst.selectedMonth = date.getMonth();
  7559. inst.drawYear = inst.selectedYear = date.getFullYear();
  7560. if (period == 'M' || period == 'Y')
  7561. this._notifyChange(inst);
  7562. },
  7563. /* Ensure a date is within any min/max bounds. */
  7564. _restrictMinMax: function(inst, date) {
  7565. var minDate = this._getMinMaxDate(inst, 'min');
  7566. var maxDate = this._getMinMaxDate(inst, 'max');
  7567. var newDate = (minDate && date < minDate ? minDate : date);
  7568. newDate = (maxDate && newDate > maxDate ? maxDate : newDate);
  7569. return newDate;
  7570. },
  7571. /* Notify change of month/year. */
  7572. _notifyChange: function(inst) {
  7573. var onChange = this._get(inst, 'onChangeMonthYear');
  7574. if (onChange)
  7575. onChange.apply((inst.input ? inst.input[0] : null),
  7576. [inst.selectedYear, inst.selectedMonth + 1, inst]);
  7577. },
  7578. /* Determine the number of months to show. */
  7579. _getNumberOfMonths: function(inst) {
  7580. var numMonths = this._get(inst, 'numberOfMonths');
  7581. return (numMonths == null ? [1, 1] : (typeof numMonths == 'number' ? [1, numMonths] : numMonths));
  7582. },
  7583. /* Determine the current maximum date - ensure no time components are set. */
  7584. _getMinMaxDate: function(inst, minMax) {
  7585. return this._determineDate(inst, this._get(inst, minMax + 'Date'), null);
  7586. },
  7587. /* Find the number of days in a given month. */
  7588. _getDaysInMonth: function(year, month) {
  7589. return 32 - this._daylightSavingAdjust(new Date(year, month, 32)).getDate();
  7590. },
  7591. /* Find the day of the week of the first of a month. */
  7592. _getFirstDayOfMonth: function(year, month) {
  7593. return new Date(year, month, 1).getDay();
  7594. },
  7595. /* Determines if we should allow a "next/prev" month display change. */
  7596. _canAdjustMonth: function(inst, offset, curYear, curMonth) {
  7597. var numMonths = this._getNumberOfMonths(inst);
  7598. var date = this._daylightSavingAdjust(new Date(curYear,
  7599. curMonth + (offset < 0 ? offset : numMonths[0] * numMonths[1]), 1));
  7600. if (offset < 0)
  7601. date.setDate(this._getDaysInMonth(date.getFullYear(), date.getMonth()));
  7602. return this._isInRange(inst, date);
  7603. },
  7604. /* Is the given date in the accepted range? */
  7605. _isInRange: function(inst, date) {
  7606. var minDate = this._getMinMaxDate(inst, 'min');
  7607. var maxDate = this._getMinMaxDate(inst, 'max');
  7608. return ((!minDate || date.getTime() >= minDate.getTime()) &&
  7609. (!maxDate || date.getTime() <= maxDate.getTime()));
  7610. },
  7611. /* Provide the configuration settings for formatting/parsing. */
  7612. _getFormatConfig: function(inst) {
  7613. var shortYearCutoff = this._get(inst, 'shortYearCutoff');
  7614. shortYearCutoff = (typeof shortYearCutoff != 'string' ? shortYearCutoff :
  7615. new Date().getFullYear() % 100 + parseInt(shortYearCutoff, 10));
  7616. return {shortYearCutoff: shortYearCutoff,
  7617. dayNamesShort: this._get(inst, 'dayNamesShort'), dayNames: this._get(inst, 'dayNames'),
  7618. monthNamesShort: this._get(inst, 'monthNamesShort'), monthNames: this._get(inst, 'monthNames')};
  7619. },
  7620. /* Format the given date for display. */
  7621. _formatDate: function(inst, day, month, year) {
  7622. if (!day) {
  7623. inst.currentDay = inst.selectedDay;
  7624. inst.currentMonth = inst.selectedMonth;
  7625. inst.currentYear = inst.selectedYear;
  7626. }
  7627. var date = (day ? (typeof day == 'object' ? day :
  7628. this._daylightSavingAdjust(new Date(year, month, day))) :
  7629. this._daylightSavingAdjust(new Date(inst.currentYear, inst.currentMonth, inst.currentDay)));
  7630. return this.formatDate(this._get(inst, 'dateFormat'), date, this._getFormatConfig(inst));
  7631. }
  7632. });
  7633. /*
  7634. * Bind hover events for datepicker elements.
  7635. * Done via delegate so the binding only occurs once in the lifetime of the parent div.
  7636. * Global instActive, set by _updateDatepicker allows the handlers to find their way back to the active picker.
  7637. */
  7638. function bindHover(dpDiv) {
  7639. var selector = 'button, .ui-datepicker-prev, .ui-datepicker-next, .ui-datepicker-calendar td a';
  7640. return dpDiv.delegate(selector, 'mouseout', function() {
  7641. $(this).removeClass('ui-state-hover');
  7642. if (this.className.indexOf('ui-datepicker-prev') != -1) $(this).removeClass('ui-datepicker-prev-hover');
  7643. if (this.className.indexOf('ui-datepicker-next') != -1) $(this).removeClass('ui-datepicker-next-hover');
  7644. })
  7645. .delegate(selector, 'mouseover', function(){
  7646. if (!$.datepicker._isDisabledDatepicker( instActive.inline ? dpDiv.parent()[0] : instActive.input[0])) {
  7647. $(this).parents('.ui-datepicker-calendar').find('a').removeClass('ui-state-hover');
  7648. $(this).addClass('ui-state-hover');
  7649. if (this.className.indexOf('ui-datepicker-prev') != -1) $(this).addClass('ui-datepicker-prev-hover');
  7650. if (this.className.indexOf('ui-datepicker-next') != -1) $(this).addClass('ui-datepicker-next-hover');
  7651. }
  7652. });
  7653. }
  7654. /* jQuery extend now ignores nulls! */
  7655. function extendRemove(target, props) {
  7656. $.extend(target, props);
  7657. for (var name in props)
  7658. if (props[name] == null || props[name] == undefined)
  7659. target[name] = props[name];
  7660. return target;
  7661. };
  7662. /* Invoke the datepicker functionality.
  7663. @param options string - a command, optionally followed by additional parameters or
  7664. Object - settings for attaching new datepicker functionality
  7665. @return jQuery object */
  7666. $.fn.datepicker = function(options){
  7667. /* Verify an empty collection wasn't passed - Fixes #6976 */
  7668. if ( !this.length ) {
  7669. return this;
  7670. }
  7671. /* Initialise the date picker. */
  7672. if (!$.datepicker.initialized) {
  7673. $(document).mousedown($.datepicker._checkExternalClick).
  7674. find(document.body).append($.datepicker.dpDiv);
  7675. $.datepicker.initialized = true;
  7676. }
  7677. var otherArgs = Array.prototype.slice.call(arguments, 1);
  7678. if (typeof options == 'string' && (options == 'isDisabled' || options == 'getDate' || options == 'widget'))
  7679. return $.datepicker['_' + options + 'Datepicker'].
  7680. apply($.datepicker, [this[0]].concat(otherArgs));
  7681. if (options == 'option' && arguments.length == 2 && typeof arguments[1] == 'string')
  7682. return $.datepicker['_' + options + 'Datepicker'].
  7683. apply($.datepicker, [this[0]].concat(otherArgs));
  7684. return this.each(function() {
  7685. typeof options == 'string' ?
  7686. $.datepicker['_' + options + 'Datepicker'].
  7687. apply($.datepicker, [this].concat(otherArgs)) :
  7688. $.datepicker._attachDatepicker(this, options);
  7689. });
  7690. };
  7691. $.datepicker = new Datepicker(); // singleton instance
  7692. $.datepicker.initialized = false;
  7693. $.datepicker.uuid = new Date().getTime();
  7694. $.datepicker.version = "1.9.0";
  7695. // Workaround for #4055
  7696. // Add another global to avoid noConflict issues with inline event handlers
  7697. window['DP_jQuery_' + dpuuid] = $;
  7698. })(jQuery);
  7699. (function( $, undefined ) {
  7700. var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
  7701. sizeRelatedOptions = {
  7702. buttons: true,
  7703. height: true,
  7704. maxHeight: true,
  7705. maxWidth: true,
  7706. minHeight: true,
  7707. minWidth: true,
  7708. width: true
  7709. },
  7710. resizableRelatedOptions = {
  7711. maxHeight: true,
  7712. maxWidth: true,
  7713. minHeight: true,
  7714. minWidth: true
  7715. };
  7716. $.widget("ui.dialog", {
  7717. version: "1.9.0",
  7718. options: {
  7719. autoOpen: true,
  7720. buttons: {},
  7721. closeOnEscape: true,
  7722. closeText: "close",
  7723. dialogClass: "",
  7724. draggable: true,
  7725. hide: null,
  7726. height: "auto",
  7727. maxHeight: false,
  7728. maxWidth: false,
  7729. minHeight: 150,
  7730. minWidth: 150,
  7731. modal: false,
  7732. position: {
  7733. my: "center",
  7734. at: "center",
  7735. of: window,
  7736. collision: "fit",
  7737. // ensure that the titlebar is never outside the document
  7738. using: function( pos ) {
  7739. var topOffset = $( this ).css( pos ).offset().top;
  7740. if ( topOffset < 0 ) {
  7741. $( this ).css( "top", pos.top - topOffset );
  7742. }
  7743. }
  7744. },
  7745. resizable: true,
  7746. show: null,
  7747. stack: true,
  7748. title: "",
  7749. width: 300,
  7750. zIndex: 1000
  7751. },
  7752. _create: function() {
  7753. this.originalTitle = this.element.attr( "title" );
  7754. // #5742 - .attr() might return a DOMElement
  7755. if ( typeof this.originalTitle !== "string" ) {
  7756. this.originalTitle = "";
  7757. }
  7758. this.oldPosition = {
  7759. parent: this.element.parent(),
  7760. index: this.element.parent().children().index( this.element )
  7761. };
  7762. this.options.title = this.options.title || this.originalTitle;
  7763. var that = this,
  7764. options = this.options,
  7765. title = options.title || "&#160;",
  7766. uiDialog = ( this.uiDialog = $( "<div>" ) )
  7767. .addClass( uiDialogClasses + options.dialogClass )
  7768. .css({
  7769. display: "none",
  7770. outline: 0, // TODO: move to stylesheet
  7771. zIndex: options.zIndex
  7772. })
  7773. // setting tabIndex makes the div focusable
  7774. .attr( "tabIndex", -1)
  7775. .keydown(function( event ) {
  7776. if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
  7777. event.keyCode === $.ui.keyCode.ESCAPE ) {
  7778. that.close( event );
  7779. event.preventDefault();
  7780. }
  7781. })
  7782. .mousedown(function( event ) {
  7783. that.moveToTop( false, event );
  7784. })
  7785. .appendTo( "body" ),
  7786. uiDialogContent = this.element
  7787. .show()
  7788. .removeAttr( "title" )
  7789. .addClass( "ui-dialog-content ui-widget-content" )
  7790. .appendTo( uiDialog ),
  7791. uiDialogTitlebar = ( this.uiDialogTitlebar = $( "<div>" ) )
  7792. .addClass( "ui-dialog-titlebar ui-widget-header " +
  7793. "ui-corner-all ui-helper-clearfix" )
  7794. .prependTo( uiDialog ),
  7795. uiDialogTitlebarClose = $( "<a href='#'></a>" )
  7796. .addClass( "ui-dialog-titlebar-close ui-corner-all" )
  7797. .attr( "role", "button" )
  7798. .click(function( event ) {
  7799. event.preventDefault();
  7800. that.close( event );
  7801. })
  7802. .appendTo( uiDialogTitlebar ),
  7803. uiDialogTitlebarCloseText = ( this.uiDialogTitlebarCloseText = $( "<span>" ) )
  7804. .addClass( "ui-icon ui-icon-closethick" )
  7805. .text( options.closeText )
  7806. .appendTo( uiDialogTitlebarClose ),
  7807. uiDialogTitle = $( "<span>" )
  7808. .uniqueId()
  7809. .addClass( "ui-dialog-title" )
  7810. .html( title )
  7811. .prependTo( uiDialogTitlebar ),
  7812. uiDialogButtonPane = ( this.uiDialogButtonPane = $( "<div>" ) )
  7813. .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ),
  7814. uiButtonSet = ( this.uiButtonSet = $( "<div>" ) )
  7815. .addClass( "ui-dialog-buttonset" )
  7816. .appendTo( uiDialogButtonPane );
  7817. uiDialog.attr({
  7818. role: "dialog",
  7819. "aria-labelledby": uiDialogTitle.attr( "id" )
  7820. });
  7821. uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection();
  7822. this._hoverable( uiDialogTitlebarClose );
  7823. this._focusable( uiDialogTitlebarClose );
  7824. if ( options.draggable && $.fn.draggable ) {
  7825. this._makeDraggable();
  7826. }
  7827. if ( options.resizable && $.fn.resizable ) {
  7828. this._makeResizable();
  7829. }
  7830. this._createButtons( options.buttons );
  7831. this._isOpen = false;
  7832. if ( $.fn.bgiframe ) {
  7833. uiDialog.bgiframe();
  7834. }
  7835. // prevent tabbing out of modal dialogs
  7836. this._on( uiDialog, { keydown: function( event ) {
  7837. if ( !options.modal || event.keyCode !== $.ui.keyCode.TAB ) {
  7838. return;
  7839. }
  7840. var tabbables = $( ":tabbable", uiDialog ),
  7841. first = tabbables.filter( ":first" ),
  7842. last = tabbables.filter( ":last" );
  7843. if ( event.target === last[0] && !event.shiftKey ) {
  7844. first.focus( 1 );
  7845. return false;
  7846. } else if ( event.target === first[0] && event.shiftKey ) {
  7847. last.focus( 1 );
  7848. return false;
  7849. }
  7850. }});
  7851. },
  7852. _init: function() {
  7853. if ( this.options.autoOpen ) {
  7854. this.open();
  7855. }
  7856. },
  7857. _destroy: function() {
  7858. var next,
  7859. oldPosition = this.oldPosition;
  7860. if ( this.overlay ) {
  7861. this.overlay.destroy();
  7862. }
  7863. this.uiDialog.hide();
  7864. this.element
  7865. .removeClass( "ui-dialog-content ui-widget-content" )
  7866. .hide()
  7867. .appendTo( "body" );
  7868. this.uiDialog.remove();
  7869. if ( this.originalTitle ) {
  7870. this.element.attr( "title", this.originalTitle );
  7871. }
  7872. next = oldPosition.parent.children().eq( oldPosition.index );
  7873. // Don't try to place the dialog next to itself (#8613)
  7874. if ( next.length && next[ 0 ] !== this.element[ 0 ] ) {
  7875. next.before( this.element );
  7876. } else {
  7877. oldPosition.parent.append( this.element );
  7878. }
  7879. },
  7880. widget: function() {
  7881. return this.uiDialog;
  7882. },
  7883. close: function( event ) {
  7884. var that = this,
  7885. maxZ, thisZ;
  7886. if ( !this._isOpen ) {
  7887. return;
  7888. }
  7889. if ( false === this._trigger( "beforeClose", event ) ) {
  7890. return;
  7891. }
  7892. this._isOpen = false;
  7893. if ( this.overlay ) {
  7894. this.overlay.destroy();
  7895. }
  7896. if ( this.options.hide ) {
  7897. this.uiDialog.hide( this.options.hide, function() {
  7898. that._trigger( "close", event );
  7899. });
  7900. } else {
  7901. this.uiDialog.hide();
  7902. this._trigger( "close", event );
  7903. }
  7904. $.ui.dialog.overlay.resize();
  7905. // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
  7906. if ( this.options.modal ) {
  7907. maxZ = 0;
  7908. $( ".ui-dialog" ).each(function() {
  7909. if ( this !== that.uiDialog[0] ) {
  7910. thisZ = $( this ).css( "z-index" );
  7911. if ( !isNaN( thisZ ) ) {
  7912. maxZ = Math.max( maxZ, thisZ );
  7913. }
  7914. }
  7915. });
  7916. $.ui.dialog.maxZ = maxZ;
  7917. }
  7918. return this;
  7919. },
  7920. isOpen: function() {
  7921. return this._isOpen;
  7922. },
  7923. // the force parameter allows us to move modal dialogs to their correct
  7924. // position on open
  7925. moveToTop: function( force, event ) {
  7926. var options = this.options,
  7927. saveScroll;
  7928. if ( ( options.modal && !force ) ||
  7929. ( !options.stack && !options.modal ) ) {
  7930. return this._trigger( "focus", event );
  7931. }
  7932. if ( options.zIndex > $.ui.dialog.maxZ ) {
  7933. $.ui.dialog.maxZ = options.zIndex;
  7934. }
  7935. if ( this.overlay ) {
  7936. $.ui.dialog.maxZ += 1;
  7937. $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ;
  7938. this.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ );
  7939. }
  7940. // Save and then restore scroll
  7941. // Opera 9.5+ resets when parent z-index is changed.
  7942. // http://bugs.jqueryui.com/ticket/3193
  7943. saveScroll = {
  7944. scrollTop: this.element.scrollTop(),
  7945. scrollLeft: this.element.scrollLeft()
  7946. };
  7947. $.ui.dialog.maxZ += 1;
  7948. this.uiDialog.css( "z-index", $.ui.dialog.maxZ );
  7949. this.element.attr( saveScroll );
  7950. this._trigger( "focus", event );
  7951. return this;
  7952. },
  7953. open: function() {
  7954. if ( this._isOpen ) {
  7955. return;
  7956. }
  7957. var hasFocus,
  7958. options = this.options,
  7959. uiDialog = this.uiDialog;
  7960. this._size();
  7961. this._position( options.position );
  7962. uiDialog.show( options.show );
  7963. this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null;
  7964. this.moveToTop( true );
  7965. // set focus to the first tabbable element in the content area or the first button
  7966. // if there are no tabbable elements, set focus on the dialog itself
  7967. hasFocus = this.element.find( ":tabbable" );
  7968. if ( !hasFocus.length ) {
  7969. hasFocus = this.uiDialogButtonPane.find( ":tabbable" );
  7970. if ( !hasFocus.length ) {
  7971. hasFocus = uiDialog;
  7972. }
  7973. }
  7974. hasFocus.eq( 0 ).focus();
  7975. this._isOpen = true;
  7976. this._trigger( "open" );
  7977. return this;
  7978. },
  7979. _createButtons: function( buttons ) {
  7980. var uiDialogButtonPane, uiButtonSet,
  7981. that = this,
  7982. hasButtons = false;
  7983. // if we already have a button pane, remove it
  7984. this.uiDialogButtonPane.remove();
  7985. this.uiButtonSet.empty();
  7986. if ( typeof buttons === "object" && buttons !== null ) {
  7987. $.each( buttons, function() {
  7988. return !(hasButtons = true);
  7989. });
  7990. }
  7991. if ( hasButtons ) {
  7992. $.each( buttons, function( name, props ) {
  7993. props = $.isFunction( props ) ?
  7994. { click: props, text: name } :
  7995. props;
  7996. var button = $( "<button type='button'>" )
  7997. .attr( props, true )
  7998. .unbind( "click" )
  7999. .click(function() {
  8000. props.click.apply( that.element[0], arguments );
  8001. })
  8002. .appendTo( that.uiButtonSet );
  8003. if ( $.fn.button ) {
  8004. button.button();
  8005. }
  8006. });
  8007. this.uiDialog.addClass( "ui-dialog-buttons" );
  8008. this.uiDialogButtonPane.appendTo( this.uiDialog );
  8009. } else {
  8010. this.uiDialog.removeClass( "ui-dialog-buttons" );
  8011. }
  8012. },
  8013. _makeDraggable: function() {
  8014. var that = this,
  8015. options = this.options;
  8016. function filteredUi( ui ) {
  8017. return {
  8018. position: ui.position,
  8019. offset: ui.offset
  8020. };
  8021. }
  8022. this.uiDialog.draggable({
  8023. cancel: ".ui-dialog-content, .ui-dialog-titlebar-close",
  8024. handle: ".ui-dialog-titlebar",
  8025. containment: "document",
  8026. start: function( event, ui ) {
  8027. $( this )
  8028. .addClass( "ui-dialog-dragging" );
  8029. that._trigger( "dragStart", event, filteredUi( ui ) );
  8030. },
  8031. drag: function( event, ui ) {
  8032. that._trigger( "drag", event, filteredUi( ui ) );
  8033. },
  8034. stop: function( event, ui ) {
  8035. options.position = [
  8036. ui.position.left - that.document.scrollLeft(),
  8037. ui.position.top - that.document.scrollTop()
  8038. ];
  8039. $( this )
  8040. .removeClass( "ui-dialog-dragging" );
  8041. that._trigger( "dragStop", event, filteredUi( ui ) );
  8042. $.ui.dialog.overlay.resize();
  8043. }
  8044. });
  8045. },
  8046. _makeResizable: function( handles ) {
  8047. handles = (handles === undefined ? this.options.resizable : handles);
  8048. var that = this,
  8049. options = this.options,
  8050. // .ui-resizable has position: relative defined in the stylesheet
  8051. // but dialogs have to use absolute or fixed positioning
  8052. position = this.uiDialog.css( "position" ),
  8053. resizeHandles = typeof handles === 'string' ?
  8054. handles :
  8055. "n,e,s,w,se,sw,ne,nw";
  8056. function filteredUi( ui ) {
  8057. return {
  8058. originalPosition: ui.originalPosition,
  8059. originalSize: ui.originalSize,
  8060. position: ui.position,
  8061. size: ui.size
  8062. };
  8063. }
  8064. this.uiDialog.resizable({
  8065. cancel: ".ui-dialog-content",
  8066. containment: "document",
  8067. alsoResize: this.element,
  8068. maxWidth: options.maxWidth,
  8069. maxHeight: options.maxHeight,
  8070. minWidth: options.minWidth,
  8071. minHeight: this._minHeight(),
  8072. handles: resizeHandles,
  8073. start: function( event, ui ) {
  8074. $( this ).addClass( "ui-dialog-resizing" );
  8075. that._trigger( "resizeStart", event, filteredUi( ui ) );
  8076. },
  8077. resize: function( event, ui ) {
  8078. that._trigger( "resize", event, filteredUi( ui ) );
  8079. },
  8080. stop: function( event, ui ) {
  8081. $( this ).removeClass( "ui-dialog-resizing" );
  8082. options.height = $( this ).height();
  8083. options.width = $( this ).width();
  8084. that._trigger( "resizeStop", event, filteredUi( ui ) );
  8085. $.ui.dialog.overlay.resize();
  8086. }
  8087. })
  8088. .css( "position", position )
  8089. .find( ".ui-resizable-se" )
  8090. .addClass( "ui-icon ui-icon-grip-diagonal-se" );
  8091. },
  8092. _minHeight: function() {
  8093. var options = this.options;
  8094. if ( options.height === "auto" ) {
  8095. return options.minHeight;
  8096. } else {
  8097. return Math.min( options.minHeight, options.height );
  8098. }
  8099. },
  8100. _position: function( position ) {
  8101. var myAt = [],
  8102. offset = [ 0, 0 ],
  8103. isVisible;
  8104. if ( position ) {
  8105. // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
  8106. // if (typeof position == 'string' || $.isArray(position)) {
  8107. // myAt = $.isArray(position) ? position : position.split(' ');
  8108. if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
  8109. myAt = position.split ? position.split( " " ) : [ position[ 0 ], position[ 1 ] ];
  8110. if ( myAt.length === 1 ) {
  8111. myAt[ 1 ] = myAt[ 0 ];
  8112. }
  8113. $.each( [ "left", "top" ], function( i, offsetPosition ) {
  8114. if ( +myAt[ i ] === myAt[ i ] ) {
  8115. offset[ i ] = myAt[ i ];
  8116. myAt[ i ] = offsetPosition;
  8117. }
  8118. });
  8119. position = {
  8120. my: myAt.join( " " ),
  8121. at: myAt.join( " " ),
  8122. offset: offset.join( " " )
  8123. };
  8124. }
  8125. position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
  8126. } else {
  8127. position = $.ui.dialog.prototype.options.position;
  8128. }
  8129. // need to show the dialog to get the actual offset in the position plugin
  8130. isVisible = this.uiDialog.is( ":visible" );
  8131. if ( !isVisible ) {
  8132. this.uiDialog.show();
  8133. }
  8134. this.uiDialog.position( position );
  8135. if ( !isVisible ) {
  8136. this.uiDialog.hide();
  8137. }
  8138. },
  8139. _setOptions: function( options ) {
  8140. var that = this,
  8141. resizableOptions = {},
  8142. resize = false;
  8143. $.each( options, function( key, value ) {
  8144. that._setOption( key, value );
  8145. if ( key in sizeRelatedOptions ) {
  8146. resize = true;
  8147. }
  8148. if ( key in resizableRelatedOptions ) {
  8149. resizableOptions[ key ] = value;
  8150. }
  8151. });
  8152. if ( resize ) {
  8153. this._size();
  8154. }
  8155. if ( this.uiDialog.is( ":data(resizable)" ) ) {
  8156. this.uiDialog.resizable( "option", resizableOptions );
  8157. }
  8158. },
  8159. _setOption: function( key, value ) {
  8160. var isDraggable, isResizable,
  8161. uiDialog = this.uiDialog;
  8162. switch ( key ) {
  8163. case "buttons":
  8164. this._createButtons( value );
  8165. break;
  8166. case "closeText":
  8167. // ensure that we always pass a string
  8168. this.uiDialogTitlebarCloseText.text( "" + value );
  8169. break;
  8170. case "dialogClass":
  8171. uiDialog
  8172. .removeClass( this.options.dialogClass )
  8173. .addClass( uiDialogClasses + value );
  8174. break;
  8175. case "disabled":
  8176. if ( value ) {
  8177. uiDialog.addClass( "ui-dialog-disabled" );
  8178. } else {
  8179. uiDialog.removeClass( "ui-dialog-disabled" );
  8180. }
  8181. break;
  8182. case "draggable":
  8183. isDraggable = uiDialog.is( ":data(draggable)" );
  8184. if ( isDraggable && !value ) {
  8185. uiDialog.draggable( "destroy" );
  8186. }
  8187. if ( !isDraggable && value ) {
  8188. this._makeDraggable();
  8189. }
  8190. break;
  8191. case "position":
  8192. this._position( value );
  8193. break;
  8194. case "resizable":
  8195. // currently resizable, becoming non-resizable
  8196. isResizable = uiDialog.is( ":data(resizable)" );
  8197. if ( isResizable && !value ) {
  8198. uiDialog.resizable( "destroy" );
  8199. }
  8200. // currently resizable, changing handles
  8201. if ( isResizable && typeof value === "string" ) {
  8202. uiDialog.resizable( "option", "handles", value );
  8203. }
  8204. // currently non-resizable, becoming resizable
  8205. if ( !isResizable && value !== false ) {
  8206. this._makeResizable( value );
  8207. }
  8208. break;
  8209. case "title":
  8210. // convert whatever was passed in o a string, for html() to not throw up
  8211. $( ".ui-dialog-title", this.uiDialogTitlebar )
  8212. .html( "" + ( value || "&#160;" ) );
  8213. break;
  8214. }
  8215. this._super( key, value );
  8216. },
  8217. _size: function() {
  8218. /* If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
  8219. * divs will both have width and height set, so we need to reset them
  8220. */
  8221. var nonContentHeight, minContentHeight, autoHeight,
  8222. options = this.options,
  8223. isVisible = this.uiDialog.is( ":visible" );
  8224. // reset content sizing
  8225. this.element.show().css({
  8226. width: "auto",
  8227. minHeight: 0,
  8228. height: 0
  8229. });
  8230. if ( options.minWidth > options.width ) {
  8231. options.width = options.minWidth;
  8232. }
  8233. // reset wrapper sizing
  8234. // determine the height of all the non-content elements
  8235. nonContentHeight = this.uiDialog.css({
  8236. height: "auto",
  8237. width: options.width
  8238. })
  8239. .outerHeight();
  8240. minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
  8241. if ( options.height === "auto" ) {
  8242. // only needed for IE6 support
  8243. if ( $.support.minHeight ) {
  8244. this.element.css({
  8245. minHeight: minContentHeight,
  8246. height: "auto"
  8247. });
  8248. } else {
  8249. this.uiDialog.show();
  8250. autoHeight = this.element.css( "height", "auto" ).height();
  8251. if ( !isVisible ) {
  8252. this.uiDialog.hide();
  8253. }
  8254. this.element.height( Math.max( autoHeight, minContentHeight ) );
  8255. }
  8256. } else {
  8257. this.element.height( Math.max( options.height - nonContentHeight, 0 ) );
  8258. }
  8259. if (this.uiDialog.is( ":data(resizable)" ) ) {
  8260. this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
  8261. }
  8262. }
  8263. });
  8264. $.extend($.ui.dialog, {
  8265. uuid: 0,
  8266. maxZ: 0,
  8267. getTitleId: function($el) {
  8268. var id = $el.attr( "id" );
  8269. if ( !id ) {
  8270. this.uuid += 1;
  8271. id = this.uuid;
  8272. }
  8273. return "ui-dialog-title-" + id;
  8274. },
  8275. overlay: function( dialog ) {
  8276. this.$el = $.ui.dialog.overlay.create( dialog );
  8277. }
  8278. });
  8279. $.extend( $.ui.dialog.overlay, {
  8280. instances: [],
  8281. // reuse old instances due to IE memory leak with alpha transparency (see #5185)
  8282. oldInstances: [],
  8283. maxZ: 0,
  8284. events: $.map(
  8285. "focus,mousedown,mouseup,keydown,keypress,click".split( "," ),
  8286. function( event ) {
  8287. return event + ".dialog-overlay";
  8288. }
  8289. ).join( " " ),
  8290. create: function( dialog ) {
  8291. if ( this.instances.length === 0 ) {
  8292. // prevent use of anchors and inputs
  8293. // we use a setTimeout in case the overlay is created from an
  8294. // event that we're going to be cancelling (see #2804)
  8295. setTimeout(function() {
  8296. // handle $(el).dialog().dialog('close') (see #4065)
  8297. if ( $.ui.dialog.overlay.instances.length ) {
  8298. $( document ).bind( $.ui.dialog.overlay.events, function( event ) {
  8299. // stop events if the z-index of the target is < the z-index of the overlay
  8300. // we cannot return true when we don't want to cancel the event (#3523)
  8301. if ( $( event.target ).zIndex() < $.ui.dialog.overlay.maxZ ) {
  8302. return false;
  8303. }
  8304. });
  8305. }
  8306. }, 1 );
  8307. // handle window resize
  8308. $( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize );
  8309. }
  8310. var $el = ( this.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay" ) );
  8311. // allow closing by pressing the escape key
  8312. $( document ).bind( "keydown.dialog-overlay", function( event ) {
  8313. var instances = $.ui.dialog.overlay.instances;
  8314. // only react to the event if we're the top overlay
  8315. if ( instances.length !== 0 && instances[ instances.length - 1 ] === $el &&
  8316. dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
  8317. event.keyCode === $.ui.keyCode.ESCAPE ) {
  8318. dialog.close( event );
  8319. event.preventDefault();
  8320. }
  8321. });
  8322. $el.appendTo( document.body ).css({
  8323. width: this.width(),
  8324. height: this.height()
  8325. });
  8326. if ( $.fn.bgiframe ) {
  8327. $el.bgiframe();
  8328. }
  8329. this.instances.push( $el );
  8330. return $el;
  8331. },
  8332. destroy: function( $el ) {
  8333. var indexOf = $.inArray( $el, this.instances ),
  8334. maxZ = 0;
  8335. if ( indexOf !== -1 ) {
  8336. this.oldInstances.push( this.instances.splice( indexOf, 1 )[ 0 ] );
  8337. }
  8338. if ( this.instances.length === 0 ) {
  8339. $( [ document, window ] ).unbind( ".dialog-overlay" );
  8340. }
  8341. $el.height( 0 ).width( 0 ).remove();
  8342. // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
  8343. $.each( this.instances, function() {
  8344. maxZ = Math.max( maxZ, this.css( "z-index" ) );
  8345. });
  8346. this.maxZ = maxZ;
  8347. },
  8348. height: function() {
  8349. var scrollHeight,
  8350. offsetHeight;
  8351. // handle IE
  8352. if ( $.browser.msie ) {
  8353. scrollHeight = Math.max(
  8354. document.documentElement.scrollHeight,
  8355. document.body.scrollHeight
  8356. );
  8357. offsetHeight = Math.max(
  8358. document.documentElement.offsetHeight,
  8359. document.body.offsetHeight
  8360. );
  8361. if ( scrollHeight < offsetHeight ) {
  8362. return $( window ).height() + "px";
  8363. } else {
  8364. return scrollHeight + "px";
  8365. }
  8366. // handle "good" browsers
  8367. } else {
  8368. return $( document ).height() + "px";
  8369. }
  8370. },
  8371. width: function() {
  8372. var scrollWidth,
  8373. offsetWidth;
  8374. // handle IE
  8375. if ( $.browser.msie ) {
  8376. scrollWidth = Math.max(
  8377. document.documentElement.scrollWidth,
  8378. document.body.scrollWidth
  8379. );
  8380. offsetWidth = Math.max(
  8381. document.documentElement.offsetWidth,
  8382. document.body.offsetWidth
  8383. );
  8384. if ( scrollWidth < offsetWidth ) {
  8385. return $( window ).width() + "px";
  8386. } else {
  8387. return scrollWidth + "px";
  8388. }
  8389. // handle "good" browsers
  8390. } else {
  8391. return $( document ).width() + "px";
  8392. }
  8393. },
  8394. resize: function() {
  8395. /* If the dialog is draggable and the user drags it past the
  8396. * right edge of the window, the document becomes wider so we
  8397. * need to stretch the overlay. If the user then drags the
  8398. * dialog back to the left, the document will become narrower,
  8399. * so we need to shrink the overlay to the appropriate size.
  8400. * This is handled by shrinking the overlay before setting it
  8401. * to the full document size.
  8402. */
  8403. var $overlays = $( [] );
  8404. $.each( $.ui.dialog.overlay.instances, function() {
  8405. $overlays = $overlays.add( this );
  8406. });
  8407. $overlays.css({
  8408. width: 0,
  8409. height: 0
  8410. }).css({
  8411. width: $.ui.dialog.overlay.width(),
  8412. height: $.ui.dialog.overlay.height()
  8413. });
  8414. }
  8415. });
  8416. $.extend( $.ui.dialog.overlay.prototype, {
  8417. destroy: function() {
  8418. $.ui.dialog.overlay.destroy( this.$el );
  8419. }
  8420. });
  8421. }( jQuery ) );
  8422. (function( $, undefined ) {
  8423. var rvertical = /up|down|vertical/,
  8424. rpositivemotion = /up|left|vertical|horizontal/;
  8425. $.effects.effect.blind = function( o, done ) {
  8426. // Create element
  8427. var el = $( this ),
  8428. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  8429. mode = $.effects.setMode( el, o.mode || "hide" ),
  8430. direction = o.direction || "up",
  8431. vertical = rvertical.test( direction ),
  8432. ref = vertical ? "height" : "width",
  8433. ref2 = vertical ? "top" : "left",
  8434. motion = rpositivemotion.test( direction ),
  8435. animation = {},
  8436. show = mode === "show",
  8437. wrapper, distance, margin;
  8438. // if already wrapped, the wrapper's properties are my property. #6245
  8439. if ( el.parent().is( ".ui-effects-wrapper" ) ) {
  8440. $.effects.save( el.parent(), props );
  8441. } else {
  8442. $.effects.save( el, props );
  8443. }
  8444. el.show();
  8445. wrapper = $.effects.createWrapper( el ).css({
  8446. overflow: "hidden"
  8447. });
  8448. distance = wrapper[ ref ]();
  8449. margin = parseFloat( wrapper.css( ref2 ) ) || 0;
  8450. animation[ ref ] = show ? distance : 0;
  8451. if ( !motion ) {
  8452. el
  8453. .css( vertical ? "bottom" : "right", 0 )
  8454. .css( vertical ? "top" : "left", "auto" )
  8455. .css({ position: "absolute" });
  8456. animation[ ref2 ] = show ? margin : distance + margin;
  8457. }
  8458. // start at 0 if we are showing
  8459. if ( show ) {
  8460. wrapper.css( ref, 0 );
  8461. if ( ! motion ) {
  8462. wrapper.css( ref2, margin + distance );
  8463. }
  8464. }
  8465. // Animate
  8466. wrapper.animate( animation, {
  8467. duration: o.duration,
  8468. easing: o.easing,
  8469. queue: false,
  8470. complete: function() {
  8471. if ( mode === "hide" ) {
  8472. el.hide();
  8473. }
  8474. $.effects.restore( el, props );
  8475. $.effects.removeWrapper( el );
  8476. done();
  8477. }
  8478. });
  8479. };
  8480. })(jQuery);
  8481. (function( $, undefined ) {
  8482. $.effects.effect.bounce = function( o, done ) {
  8483. var el = $( this ),
  8484. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  8485. // defaults:
  8486. mode = $.effects.setMode( el, o.mode || "effect" ),
  8487. hide = mode === "hide",
  8488. show = mode === "show",
  8489. direction = o.direction || "up",
  8490. distance = o.distance,
  8491. times = o.times || 5,
  8492. // number of internal animations
  8493. anims = times * 2 + ( show || hide ? 1 : 0 ),
  8494. speed = o.duration / anims,
  8495. easing = o.easing,
  8496. // utility:
  8497. ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  8498. motion = ( direction === "up" || direction === "left" ),
  8499. i,
  8500. upAnim,
  8501. downAnim,
  8502. // we will need to re-assemble the queue to stack our animations in place
  8503. queue = el.queue(),
  8504. queuelen = queue.length;
  8505. // Avoid touching opacity to prevent clearType and PNG issues in IE
  8506. if ( show || hide ) {
  8507. props.push( "opacity" );
  8508. }
  8509. $.effects.save( el, props );
  8510. el.show();
  8511. $.effects.createWrapper( el ); // Create Wrapper
  8512. // default distance for the BIGGEST bounce is the outer Distance / 3
  8513. if ( !distance ) {
  8514. distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]() / 3;
  8515. }
  8516. if ( show ) {
  8517. downAnim = { opacity: 1 };
  8518. downAnim[ ref ] = 0;
  8519. // if we are showing, force opacity 0 and set the initial position
  8520. // then do the "first" animation
  8521. el.css( "opacity", 0 )
  8522. .css( ref, motion ? -distance * 2 : distance * 2 )
  8523. .animate( downAnim, speed, easing );
  8524. }
  8525. // start at the smallest distance if we are hiding
  8526. if ( hide ) {
  8527. distance = distance / Math.pow( 2, times - 1 );
  8528. }
  8529. downAnim = {};
  8530. downAnim[ ref ] = 0;
  8531. // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
  8532. for ( i = 0; i < times; i++ ) {
  8533. upAnim = {};
  8534. upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
  8535. el.animate( upAnim, speed, easing )
  8536. .animate( downAnim, speed, easing );
  8537. distance = hide ? distance * 2 : distance / 2;
  8538. }
  8539. // Last Bounce when Hiding
  8540. if ( hide ) {
  8541. upAnim = { opacity: 0 };
  8542. upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
  8543. el.animate( upAnim, speed, easing );
  8544. }
  8545. el.queue(function() {
  8546. if ( hide ) {
  8547. el.hide();
  8548. }
  8549. $.effects.restore( el, props );
  8550. $.effects.removeWrapper( el );
  8551. done();
  8552. });
  8553. // inject all the animations we just queued to be first in line (after "inprogress")
  8554. if ( queuelen > 1) {
  8555. queue.splice.apply( queue,
  8556. [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
  8557. }
  8558. el.dequeue();
  8559. };
  8560. })(jQuery);
  8561. (function( $, undefined ) {
  8562. $.effects.effect.clip = function( o, done ) {
  8563. // Create element
  8564. var el = $( this ),
  8565. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  8566. mode = $.effects.setMode( el, o.mode || "hide" ),
  8567. show = mode === "show",
  8568. direction = o.direction || "vertical",
  8569. vert = direction === "vertical",
  8570. size = vert ? "height" : "width",
  8571. position = vert ? "top" : "left",
  8572. animation = {},
  8573. wrapper, animate, distance;
  8574. // Save & Show
  8575. $.effects.save( el, props );
  8576. el.show();
  8577. // Create Wrapper
  8578. wrapper = $.effects.createWrapper( el ).css({
  8579. overflow: "hidden"
  8580. });
  8581. animate = ( el[0].tagName === "IMG" ) ? wrapper : el;
  8582. distance = animate[ size ]();
  8583. // Shift
  8584. if ( show ) {
  8585. animate.css( size, 0 );
  8586. animate.css( position, distance / 2 );
  8587. }
  8588. // Create Animation Object:
  8589. animation[ size ] = show ? distance : 0;
  8590. animation[ position ] = show ? 0 : distance / 2;
  8591. // Animate
  8592. animate.animate( animation, {
  8593. queue: false,
  8594. duration: o.duration,
  8595. easing: o.easing,
  8596. complete: function() {
  8597. if ( !show ) {
  8598. el.hide();
  8599. }
  8600. $.effects.restore( el, props );
  8601. $.effects.removeWrapper( el );
  8602. done();
  8603. }
  8604. });
  8605. };
  8606. })(jQuery);
  8607. (function( $, undefined ) {
  8608. $.effects.effect.drop = function( o, done ) {
  8609. var el = $( this ),
  8610. props = [ "position", "top", "bottom", "left", "right", "opacity", "height", "width" ],
  8611. mode = $.effects.setMode( el, o.mode || "hide" ),
  8612. show = mode === "show",
  8613. direction = o.direction || "left",
  8614. ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
  8615. motion = ( direction === "up" || direction === "left" ) ? "pos" : "neg",
  8616. animation = {
  8617. opacity: show ? 1 : 0
  8618. },
  8619. distance;
  8620. // Adjust
  8621. $.effects.save( el, props );
  8622. el.show();
  8623. $.effects.createWrapper( el );
  8624. distance = o.distance || el[ ref === "top" ? "outerHeight": "outerWidth" ]( true ) / 2;
  8625. if ( show ) {
  8626. el
  8627. .css( "opacity", 0 )
  8628. .css( ref, motion === "pos" ? -distance : distance );
  8629. }
  8630. // Animation
  8631. animation[ ref ] = ( show ?
  8632. ( motion === "pos" ? "+=" : "-=" ) :
  8633. ( motion === "pos" ? "-=" : "+=" ) ) +
  8634. distance;
  8635. // Animate
  8636. el.animate( animation, {
  8637. queue: false,
  8638. duration: o.duration,
  8639. easing: o.easing,
  8640. complete: function() {
  8641. if ( mode === "hide" ) {
  8642. el.hide();
  8643. }
  8644. $.effects.restore( el, props );
  8645. $.effects.removeWrapper( el );
  8646. done();
  8647. }
  8648. });
  8649. };
  8650. })(jQuery);
  8651. (function( $, undefined ) {
  8652. $.effects.effect.explode = function( o, done ) {
  8653. var rows = o.pieces ? Math.round( Math.sqrt( o.pieces ) ) : 3,
  8654. cells = rows,
  8655. el = $( this ),
  8656. mode = $.effects.setMode( el, o.mode || "hide" ),
  8657. show = mode === "show",
  8658. // show and then visibility:hidden the element before calculating offset
  8659. offset = el.show().css( "visibility", "hidden" ).offset(),
  8660. // width and height of a piece
  8661. width = Math.ceil( el.outerWidth() / cells ),
  8662. height = Math.ceil( el.outerHeight() / rows ),
  8663. pieces = [],
  8664. // loop
  8665. i, j, left, top, mx, my;
  8666. // children animate complete:
  8667. function childComplete() {
  8668. pieces.push( this );
  8669. if ( pieces.length === rows * cells ) {
  8670. animComplete();
  8671. }
  8672. }
  8673. // clone the element for each row and cell.
  8674. for( i = 0; i < rows ; i++ ) { // ===>
  8675. top = offset.top + i * height;
  8676. my = i - ( rows - 1 ) / 2 ;
  8677. for( j = 0; j < cells ; j++ ) { // |||
  8678. left = offset.left + j * width;
  8679. mx = j - ( cells - 1 ) / 2 ;
  8680. // Create a clone of the now hidden main element that will be absolute positioned
  8681. // within a wrapper div off the -left and -top equal to size of our pieces
  8682. el
  8683. .clone()
  8684. .appendTo( "body" )
  8685. .wrap( "<div></div>" )
  8686. .css({
  8687. position: "absolute",
  8688. visibility: "visible",
  8689. left: -j * width,
  8690. top: -i * height
  8691. })
  8692. // select the wrapper - make it overflow: hidden and absolute positioned based on
  8693. // where the original was located +left and +top equal to the size of pieces
  8694. .parent()
  8695. .addClass( "ui-effects-explode" )
  8696. .css({
  8697. position: "absolute",
  8698. overflow: "hidden",
  8699. width: width,
  8700. height: height,
  8701. left: left + ( show ? mx * width : 0 ),
  8702. top: top + ( show ? my * height : 0 ),
  8703. opacity: show ? 0 : 1
  8704. }).animate({
  8705. left: left + ( show ? 0 : mx * width ),
  8706. top: top + ( show ? 0 : my * height ),
  8707. opacity: show ? 1 : 0
  8708. }, o.duration || 500, o.easing, childComplete );
  8709. }
  8710. }
  8711. function animComplete() {
  8712. el.css({
  8713. visibility: "visible"
  8714. });
  8715. $( pieces ).remove();
  8716. if ( !show ) {
  8717. el.hide();
  8718. }
  8719. done();
  8720. }
  8721. };
  8722. })(jQuery);
  8723. (function( $, undefined ) {
  8724. $.effects.effect.fade = function( o, done ) {
  8725. var el = $( this ),
  8726. mode = $.effects.setMode( el, o.mode || "toggle" );
  8727. el.animate({
  8728. opacity: mode
  8729. }, {
  8730. queue: false,
  8731. duration: o.duration,
  8732. easing: o.easing,
  8733. complete: done
  8734. });
  8735. };
  8736. })( jQuery );
  8737. (function( $, undefined ) {
  8738. $.effects.effect.fold = function( o, done ) {
  8739. // Create element
  8740. var el = $( this ),
  8741. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  8742. mode = $.effects.setMode( el, o.mode || "hide" ),
  8743. show = mode === "show",
  8744. hide = mode === "hide",
  8745. size = o.size || 15,
  8746. percent = /([0-9]+)%/.exec( size ),
  8747. horizFirst = !!o.horizFirst,
  8748. widthFirst = show !== horizFirst,
  8749. ref = widthFirst ? [ "width", "height" ] : [ "height", "width" ],
  8750. duration = o.duration / 2,
  8751. wrapper, distance,
  8752. animation1 = {},
  8753. animation2 = {};
  8754. $.effects.save( el, props );
  8755. el.show();
  8756. // Create Wrapper
  8757. wrapper = $.effects.createWrapper( el ).css({
  8758. overflow: "hidden"
  8759. });
  8760. distance = widthFirst ?
  8761. [ wrapper.width(), wrapper.height() ] :
  8762. [ wrapper.height(), wrapper.width() ];
  8763. if ( percent ) {
  8764. size = parseInt( percent[ 1 ], 10 ) / 100 * distance[ hide ? 0 : 1 ];
  8765. }
  8766. if ( show ) {
  8767. wrapper.css( horizFirst ? {
  8768. height: 0,
  8769. width: size
  8770. } : {
  8771. height: size,
  8772. width: 0
  8773. });
  8774. }
  8775. // Animation
  8776. animation1[ ref[ 0 ] ] = show ? distance[ 0 ] : size;
  8777. animation2[ ref[ 1 ] ] = show ? distance[ 1 ] : 0;
  8778. // Animate
  8779. wrapper
  8780. .animate( animation1, duration, o.easing )
  8781. .animate( animation2, duration, o.easing, function() {
  8782. if ( hide ) {
  8783. el.hide();
  8784. }
  8785. $.effects.restore( el, props );
  8786. $.effects.removeWrapper( el );
  8787. done();
  8788. });
  8789. };
  8790. })(jQuery);
  8791. (function( $, undefined ) {
  8792. $.effects.effect.highlight = function( o, done ) {
  8793. var elem = $( this ),
  8794. props = [ "backgroundImage", "backgroundColor", "opacity" ],
  8795. mode = $.effects.setMode( elem, o.mode || "show" ),
  8796. animation = {
  8797. backgroundColor: elem.css( "backgroundColor" )
  8798. };
  8799. if (mode === "hide") {
  8800. animation.opacity = 0;
  8801. }
  8802. $.effects.save( elem, props );
  8803. elem
  8804. .show()
  8805. .css({
  8806. backgroundImage: "none",
  8807. backgroundColor: o.color || "#ffff99"
  8808. })
  8809. .animate( animation, {
  8810. queue: false,
  8811. duration: o.duration,
  8812. easing: o.easing,
  8813. complete: function() {
  8814. if ( mode === "hide" ) {
  8815. elem.hide();
  8816. }
  8817. $.effects.restore( elem, props );
  8818. done();
  8819. }
  8820. });
  8821. };
  8822. })(jQuery);
  8823. (function( $, undefined ) {
  8824. $.effects.effect.pulsate = function( o, done ) {
  8825. var elem = $( this ),
  8826. mode = $.effects.setMode( elem, o.mode || "show" ),
  8827. show = mode === "show",
  8828. hide = mode === "hide",
  8829. showhide = ( show || mode === "hide" ),
  8830. // showing or hiding leaves of the "last" animation
  8831. anims = ( ( o.times || 5 ) * 2 ) + ( showhide ? 1 : 0 ),
  8832. duration = o.duration / anims,
  8833. animateTo = 0,
  8834. queue = elem.queue(),
  8835. queuelen = queue.length,
  8836. i;
  8837. if ( show || !elem.is(":visible")) {
  8838. elem.css( "opacity", 0 ).show();
  8839. animateTo = 1;
  8840. }
  8841. // anims - 1 opacity "toggles"
  8842. for ( i = 1; i < anims; i++ ) {
  8843. elem.animate({
  8844. opacity: animateTo
  8845. }, duration, o.easing );
  8846. animateTo = 1 - animateTo;
  8847. }
  8848. elem.animate({
  8849. opacity: animateTo
  8850. }, duration, o.easing);
  8851. elem.queue(function() {
  8852. if ( hide ) {
  8853. elem.hide();
  8854. }
  8855. done();
  8856. });
  8857. // We just queued up "anims" animations, we need to put them next in the queue
  8858. if ( queuelen > 1 ) {
  8859. queue.splice.apply( queue,
  8860. [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
  8861. }
  8862. elem.dequeue();
  8863. };
  8864. })(jQuery);
  8865. (function( $, undefined ) {
  8866. $.effects.effect.puff = function( o, done ) {
  8867. var elem = $( this ),
  8868. mode = $.effects.setMode( elem, o.mode || "hide" ),
  8869. hide = mode === "hide",
  8870. percent = parseInt( o.percent, 10 ) || 150,
  8871. factor = percent / 100,
  8872. original = {
  8873. height: elem.height(),
  8874. width: elem.width()
  8875. };
  8876. $.extend( o, {
  8877. effect: "scale",
  8878. queue: false,
  8879. fade: true,
  8880. mode: mode,
  8881. complete: done,
  8882. percent: hide ? percent : 100,
  8883. from: hide ?
  8884. original :
  8885. {
  8886. height: original.height * factor,
  8887. width: original.width * factor
  8888. }
  8889. });
  8890. elem.effect( o );
  8891. };
  8892. $.effects.effect.scale = function( o, done ) {
  8893. // Create element
  8894. var el = $( this ),
  8895. options = $.extend( true, {}, o ),
  8896. mode = $.effects.setMode( el, o.mode || "effect" ),
  8897. percent = parseInt( o.percent, 10 ) ||
  8898. ( parseInt( o.percent, 10 ) === 0 ? 0 : ( mode === "hide" ? 0 : 100 ) ),
  8899. direction = o.direction || "both",
  8900. origin = o.origin,
  8901. original = {
  8902. height: el.height(),
  8903. width: el.width(),
  8904. outerHeight: el.outerHeight(),
  8905. outerWidth: el.outerWidth()
  8906. },
  8907. factor = {
  8908. y: direction !== "horizontal" ? (percent / 100) : 1,
  8909. x: direction !== "vertical" ? (percent / 100) : 1
  8910. };
  8911. // We are going to pass this effect to the size effect:
  8912. options.effect = "size";
  8913. options.queue = false;
  8914. options.complete = done;
  8915. // Set default origin and restore for show/hide
  8916. if ( mode !== "effect" ) {
  8917. options.origin = origin || ["middle","center"];
  8918. options.restore = true;
  8919. }
  8920. options.from = o.from || ( mode === "show" ? { height: 0, width: 0 } : original );
  8921. options.to = {
  8922. height: original.height * factor.y,
  8923. width: original.width * factor.x,
  8924. outerHeight: original.outerHeight * factor.y,
  8925. outerWidth: original.outerWidth * factor.x
  8926. };
  8927. // Fade option to support puff
  8928. if ( options.fade ) {
  8929. if ( mode === "show" ) {
  8930. options.from.opacity = 0;
  8931. options.to.opacity = 1;
  8932. }
  8933. if ( mode === "hide" ) {
  8934. options.from.opacity = 1;
  8935. options.to.opacity = 0;
  8936. }
  8937. }
  8938. // Animate
  8939. el.effect( options );
  8940. };
  8941. $.effects.effect.size = function( o, done ) {
  8942. // Create element
  8943. var el = $( this ),
  8944. props = [ "position", "top", "bottom", "left", "right", "width", "height", "overflow", "opacity" ],
  8945. // Always restore
  8946. props1 = [ "position", "top", "bottom", "left", "right", "overflow", "opacity" ],
  8947. // Copy for children
  8948. props2 = [ "width", "height", "overflow" ],
  8949. cProps = [ "fontSize" ],
  8950. vProps = [ "borderTopWidth", "borderBottomWidth", "paddingTop", "paddingBottom" ],
  8951. hProps = [ "borderLeftWidth", "borderRightWidth", "paddingLeft", "paddingRight" ],
  8952. // Set options
  8953. mode = $.effects.setMode( el, o.mode || "effect" ),
  8954. restore = o.restore || mode !== "effect",
  8955. scale = o.scale || "both",
  8956. origin = o.origin || [ "middle", "center" ],
  8957. original, baseline, factor,
  8958. position = el.css( "position" );
  8959. if ( mode === "show" ) {
  8960. el.show();
  8961. }
  8962. original = {
  8963. height: el.height(),
  8964. width: el.width(),
  8965. outerHeight: el.outerHeight(),
  8966. outerWidth: el.outerWidth()
  8967. };
  8968. el.from = o.from || original;
  8969. el.to = o.to || original;
  8970. // Set scaling factor
  8971. factor = {
  8972. from: {
  8973. y: el.from.height / original.height,
  8974. x: el.from.width / original.width
  8975. },
  8976. to: {
  8977. y: el.to.height / original.height,
  8978. x: el.to.width / original.width
  8979. }
  8980. };
  8981. // Scale the css box
  8982. if ( scale === "box" || scale === "both" ) {
  8983. // Vertical props scaling
  8984. if ( factor.from.y !== factor.to.y ) {
  8985. props = props.concat( vProps );
  8986. el.from = $.effects.setTransition( el, vProps, factor.from.y, el.from );
  8987. el.to = $.effects.setTransition( el, vProps, factor.to.y, el.to );
  8988. }
  8989. // Horizontal props scaling
  8990. if ( factor.from.x !== factor.to.x ) {
  8991. props = props.concat( hProps );
  8992. el.from = $.effects.setTransition( el, hProps, factor.from.x, el.from );
  8993. el.to = $.effects.setTransition( el, hProps, factor.to.x, el.to );
  8994. }
  8995. }
  8996. // Scale the content
  8997. if ( scale === "content" || scale === "both" ) {
  8998. // Vertical props scaling
  8999. if ( factor.from.y !== factor.to.y ) {
  9000. props = props.concat( cProps );
  9001. el.from = $.effects.setTransition( el, cProps, factor.from.y, el.from );
  9002. el.to = $.effects.setTransition( el, cProps, factor.to.y, el.to );
  9003. }
  9004. }
  9005. $.effects.save( el, restore ? props : props1 );
  9006. el.show();
  9007. $.effects.createWrapper( el );
  9008. el.css( "overflow", "hidden" ).css( el.from );
  9009. // Adjust
  9010. if (origin) { // Calculate baseline shifts
  9011. baseline = $.effects.getBaseline( origin, original );
  9012. el.from.top = ( original.outerHeight - el.outerHeight() ) * baseline.y;
  9013. el.from.left = ( original.outerWidth - el.outerWidth() ) * baseline.x;
  9014. el.to.top = ( original.outerHeight - el.to.outerHeight ) * baseline.y;
  9015. el.to.left = ( original.outerWidth - el.to.outerWidth ) * baseline.x;
  9016. }
  9017. el.css( el.from ); // set top & left
  9018. // Animate
  9019. if ( scale === "content" || scale === "both" ) { // Scale the children
  9020. // Add margins/font-size
  9021. vProps = vProps.concat([ "marginTop", "marginBottom" ]).concat(cProps);
  9022. hProps = hProps.concat([ "marginLeft", "marginRight" ]);
  9023. props2 = props.concat(vProps).concat(hProps);
  9024. el.find( "*[width]" ).each( function(){
  9025. var child = $( this ),
  9026. c_original = {
  9027. height: child.height(),
  9028. width: child.width()
  9029. };
  9030. if (restore) {
  9031. $.effects.save(child, props2);
  9032. }
  9033. child.from = {
  9034. height: c_original.height * factor.from.y,
  9035. width: c_original.width * factor.from.x
  9036. };
  9037. child.to = {
  9038. height: c_original.height * factor.to.y,
  9039. width: c_original.width * factor.to.x
  9040. };
  9041. // Vertical props scaling
  9042. if ( factor.from.y !== factor.to.y ) {
  9043. child.from = $.effects.setTransition( child, vProps, factor.from.y, child.from );
  9044. child.to = $.effects.setTransition( child, vProps, factor.to.y, child.to );
  9045. }
  9046. // Horizontal props scaling
  9047. if ( factor.from.x !== factor.to.x ) {
  9048. child.from = $.effects.setTransition( child, hProps, factor.from.x, child.from );
  9049. child.to = $.effects.setTransition( child, hProps, factor.to.x, child.to );
  9050. }
  9051. // Animate children
  9052. child.css( child.from );
  9053. child.animate( child.to, o.duration, o.easing, function() {
  9054. // Restore children
  9055. if ( restore ) {
  9056. $.effects.restore( child, props2 );
  9057. }
  9058. });
  9059. });
  9060. }
  9061. // Animate
  9062. el.animate( el.to, {
  9063. queue: false,
  9064. duration: o.duration,
  9065. easing: o.easing,
  9066. complete: function() {
  9067. if ( el.to.opacity === 0 ) {
  9068. el.css( "opacity", el.from.opacity );
  9069. }
  9070. if( mode === "hide" ) {
  9071. el.hide();
  9072. }
  9073. $.effects.restore( el, restore ? props : props1 );
  9074. if ( !restore ) {
  9075. // we need to calculate our new positioning based on the scaling
  9076. if ( position === "static" ) {
  9077. el.css({
  9078. position: "relative",
  9079. top: el.to.top,
  9080. left: el.to.left
  9081. });
  9082. } else {
  9083. $.each([ "top", "left" ], function( idx, pos ) {
  9084. el.css( pos, function( _, str ) {
  9085. var val = parseInt( str, 10 ),
  9086. toRef = idx ? el.to.left : el.to.top;
  9087. // if original was "auto", recalculate the new value from wrapper
  9088. if ( str === "auto" ) {
  9089. return toRef + "px";
  9090. }
  9091. return val + toRef + "px";
  9092. });
  9093. });
  9094. }
  9095. }
  9096. $.effects.removeWrapper( el );
  9097. done();
  9098. }
  9099. });
  9100. };
  9101. })(jQuery);
  9102. (function( $, undefined ) {
  9103. $.effects.effect.shake = function( o, done ) {
  9104. var el = $( this ),
  9105. props = [ "position", "top", "bottom", "left", "right", "height", "width" ],
  9106. mode = $.effects.setMode( el, o.mode || "effect" ),
  9107. direction = o.direction || "left",
  9108. distance = o.distance || 20,
  9109. times = o.times || 3,
  9110. anims = times * 2 + 1,
  9111. speed = Math.round(o.duration/anims),
  9112. ref = (direction === "up" || direction === "down") ? "top" : "left",
  9113. positiveMotion = (direction === "up" || direction === "left"),
  9114. animation = {},
  9115. animation1 = {},
  9116. animation2 = {},
  9117. i,
  9118. // we will need to re-assemble the queue to stack our animations in place
  9119. queue = el.queue(),
  9120. queuelen = queue.length;
  9121. $.effects.save( el, props );
  9122. el.show();
  9123. $.effects.createWrapper( el );
  9124. // Animation
  9125. animation[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance;
  9126. animation1[ ref ] = ( positiveMotion ? "+=" : "-=" ) + distance * 2;
  9127. animation2[ ref ] = ( positiveMotion ? "-=" : "+=" ) + distance * 2;
  9128. // Animate
  9129. el.animate( animation, speed, o.easing );
  9130. // Shakes
  9131. for ( i = 1; i < times; i++ ) {
  9132. el.animate( animation1, speed, o.easing ).animate( animation2, speed, o.easing );
  9133. }
  9134. el
  9135. .animate( animation1, speed, o.easing )
  9136. .animate( animation, speed / 2, o.easing )
  9137. .queue(function() {
  9138. if ( mode === "hide" ) {
  9139. el.hide();
  9140. }
  9141. $.effects.restore( el, props );
  9142. $.effects.removeWrapper( el );
  9143. done();
  9144. });
  9145. // inject all the animations we just queued to be first in line (after "inprogress")
  9146. if ( queuelen > 1) {
  9147. queue.splice.apply( queue,
  9148. [ 1, 0 ].concat( queue.splice( queuelen, anims + 1 ) ) );
  9149. }
  9150. el.dequeue();
  9151. };
  9152. })(jQuery);
  9153. (function( $, undefined ) {
  9154. $.effects.effect.slide = function( o, done ) {
  9155. // Create element
  9156. var el = $( this ),
  9157. props = [ "position", "top", "bottom", "left", "right", "width", "height" ],
  9158. mode = $.effects.setMode( el, o.mode || "show" ),
  9159. show = mode === "show",
  9160. direction = o.direction || "left",
  9161. ref = (direction === "up" || direction === "down") ? "top" : "left",
  9162. positiveMotion = (direction === "up" || direction === "left"),
  9163. distance,
  9164. animation = {};
  9165. // Adjust
  9166. $.effects.save( el, props );
  9167. el.show();
  9168. distance = o.distance || el[ ref === "top" ? "outerHeight" : "outerWidth" ]( true );
  9169. $.effects.createWrapper( el ).css({
  9170. overflow: "hidden"
  9171. });
  9172. if ( show ) {
  9173. el.css( ref, positiveMotion ? (isNaN(distance) ? "-" + distance : -distance) : distance );
  9174. }
  9175. // Animation
  9176. animation[ ref ] = ( show ?
  9177. ( positiveMotion ? "+=" : "-=") :
  9178. ( positiveMotion ? "-=" : "+=")) +
  9179. distance;
  9180. // Animate
  9181. el.animate( animation, {
  9182. queue: false,
  9183. duration: o.duration,
  9184. easing: o.easing,
  9185. complete: function() {
  9186. if ( mode === "hide" ) {
  9187. el.hide();
  9188. }
  9189. $.effects.restore( el, props );
  9190. $.effects.removeWrapper( el );
  9191. done();
  9192. }
  9193. });
  9194. };
  9195. })(jQuery);
  9196. (function( $, undefined ) {
  9197. $.effects.effect.transfer = function( o, done ) {
  9198. var elem = $( this ),
  9199. target = $( o.to ),
  9200. targetFixed = target.css( "position" ) === "fixed",
  9201. body = $("body"),
  9202. fixTop = targetFixed ? body.scrollTop() : 0,
  9203. fixLeft = targetFixed ? body.scrollLeft() : 0,
  9204. endPosition = target.offset(),
  9205. animation = {
  9206. top: endPosition.top - fixTop ,
  9207. left: endPosition.left - fixLeft ,
  9208. height: target.innerHeight(),
  9209. width: target.innerWidth()
  9210. },
  9211. startPosition = elem.offset(),
  9212. transfer = $( '<div class="ui-effects-transfer"></div>' )
  9213. .appendTo( document.body )
  9214. .addClass( o.className )
  9215. .css({
  9216. top: startPosition.top - fixTop ,
  9217. left: startPosition.left - fixLeft ,
  9218. height: elem.innerHeight(),
  9219. width: elem.innerWidth(),
  9220. position: targetFixed ? "fixed" : "absolute"
  9221. })
  9222. .animate( animation, o.duration, o.easing, function() {
  9223. transfer.remove();
  9224. done();
  9225. });
  9226. };
  9227. })(jQuery);
  9228. (function( $, undefined ) {
  9229. var mouseHandled = false;
  9230. $.widget( "ui.menu", {
  9231. version: "1.9.0",
  9232. defaultElement: "<ul>",
  9233. delay: 300,
  9234. options: {
  9235. icons: {
  9236. submenu: "ui-icon-carat-1-e"
  9237. },
  9238. menus: "ul",
  9239. position: {
  9240. my: "left top",
  9241. at: "right top"
  9242. },
  9243. role: "menu",
  9244. // callbacks
  9245. blur: null,
  9246. focus: null,
  9247. select: null
  9248. },
  9249. _create: function() {
  9250. this.activeMenu = this.element;
  9251. this.element
  9252. .uniqueId()
  9253. .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
  9254. .toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length )
  9255. .attr({
  9256. role: this.options.role,
  9257. tabIndex: 0
  9258. })
  9259. // need to catch all clicks on disabled menu
  9260. // not possible through _on
  9261. .bind( "click" + this.eventNamespace, $.proxy(function( event ) {
  9262. if ( this.options.disabled ) {
  9263. event.preventDefault();
  9264. }
  9265. }, this ));
  9266. if ( this.options.disabled ) {
  9267. this.element
  9268. .addClass( "ui-state-disabled" )
  9269. .attr( "aria-disabled", "true" );
  9270. }
  9271. this._on({
  9272. // Prevent focus from sticking to links inside menu after clicking
  9273. // them (focus should always stay on UL during navigation).
  9274. "mousedown .ui-menu-item > a": function( event ) {
  9275. event.preventDefault();
  9276. },
  9277. "click .ui-state-disabled > a": function( event ) {
  9278. event.preventDefault();
  9279. },
  9280. "click .ui-menu-item:has(a)": function( event ) {
  9281. var target = $( event.target ).closest( ".ui-menu-item" );
  9282. if ( !mouseHandled && target.not( ".ui-state-disabled" ).length ) {
  9283. mouseHandled = true;
  9284. this.select( event );
  9285. // Open submenu on click
  9286. if ( target.has( ".ui-menu" ).length ) {
  9287. this.expand( event );
  9288. } else if ( !this.element.is( ":focus" ) ) {
  9289. // Redirect focus to the menu
  9290. this.element.trigger( "focus", [ true ] );
  9291. // If the active item is on the top level, let it stay active.
  9292. // Otherwise, blur the active item since it is no longer visible.
  9293. if ( this.active && this.active.parents( ".ui-menu" ).length === 1 ) {
  9294. clearTimeout( this.timer );
  9295. }
  9296. }
  9297. }
  9298. },
  9299. "mouseenter .ui-menu-item": function( event ) {
  9300. var target = $( event.currentTarget );
  9301. // Remove ui-state-active class from siblings of the newly focused menu item
  9302. // to avoid a jump caused by adjacent elements both having a class with a border
  9303. target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" );
  9304. this.focus( event, target );
  9305. },
  9306. mouseleave: "collapseAll",
  9307. "mouseleave .ui-menu": "collapseAll",
  9308. focus: function( event, keepActiveItem ) {
  9309. // If there's already an active item, keep it active
  9310. // If not, activate the first item
  9311. var item = this.active || this.element.children( ".ui-menu-item" ).eq( 0 );
  9312. if ( !keepActiveItem ) {
  9313. this.focus( event, item );
  9314. }
  9315. },
  9316. blur: function( event ) {
  9317. this._delay(function() {
  9318. if ( !$.contains( this.element[0], this.document[0].activeElement ) ) {
  9319. this.collapseAll( event );
  9320. }
  9321. });
  9322. },
  9323. keydown: "_keydown"
  9324. });
  9325. this.refresh();
  9326. // Clicks outside of a menu collapse any open menus
  9327. this._on( this.document, {
  9328. click: function( event ) {
  9329. if ( !$( event.target ).closest( ".ui-menu" ).length ) {
  9330. this.collapseAll( event );
  9331. }
  9332. // Reset the mouseHandled flag
  9333. mouseHandled = false;
  9334. }
  9335. });
  9336. },
  9337. _destroy: function() {
  9338. // Destroy (sub)menus
  9339. this.element
  9340. .removeAttr( "aria-activedescendant" )
  9341. .find( ".ui-menu" ).andSelf()
  9342. .removeClass( "ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" )
  9343. .removeAttr( "role" )
  9344. .removeAttr( "tabIndex" )
  9345. .removeAttr( "aria-labelledby" )
  9346. .removeAttr( "aria-expanded" )
  9347. .removeAttr( "aria-hidden" )
  9348. .removeAttr( "aria-disabled" )
  9349. .removeUniqueId()
  9350. .show();
  9351. // Destroy menu items
  9352. this.element.find( ".ui-menu-item" )
  9353. .removeClass( "ui-menu-item" )
  9354. .removeAttr( "role" )
  9355. .removeAttr( "aria-disabled" )
  9356. .children( "a" )
  9357. .removeUniqueId()
  9358. .removeClass( "ui-corner-all ui-state-hover" )
  9359. .removeAttr( "tabIndex" )
  9360. .removeAttr( "role" )
  9361. .removeAttr( "aria-haspopup" )
  9362. .children().each( function() {
  9363. var elem = $( this );
  9364. if ( elem.data( "ui-menu-submenu-carat" ) ) {
  9365. elem.remove();
  9366. }
  9367. });
  9368. // Destroy menu dividers
  9369. this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" );
  9370. },
  9371. _keydown: function( event ) {
  9372. var match, prev, character, skip, regex,
  9373. preventDefault = true;
  9374. function escape( value ) {
  9375. return value.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" );
  9376. }
  9377. switch ( event.keyCode ) {
  9378. case $.ui.keyCode.PAGE_UP:
  9379. this.previousPage( event );
  9380. break;
  9381. case $.ui.keyCode.PAGE_DOWN:
  9382. this.nextPage( event );
  9383. break;
  9384. case $.ui.keyCode.HOME:
  9385. this._move( "first", "first", event );
  9386. break;
  9387. case $.ui.keyCode.END:
  9388. this._move( "last", "last", event );
  9389. break;
  9390. case $.ui.keyCode.UP:
  9391. this.previous( event );
  9392. break;
  9393. case $.ui.keyCode.DOWN:
  9394. this.next( event );
  9395. break;
  9396. case $.ui.keyCode.LEFT:
  9397. this.collapse( event );
  9398. break;
  9399. case $.ui.keyCode.RIGHT:
  9400. if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
  9401. this.expand( event );
  9402. }
  9403. break;
  9404. case $.ui.keyCode.ENTER:
  9405. case $.ui.keyCode.SPACE:
  9406. this._activate( event );
  9407. break;
  9408. case $.ui.keyCode.ESCAPE:
  9409. this.collapse( event );
  9410. break;
  9411. default:
  9412. preventDefault = false;
  9413. prev = this.previousFilter || "";
  9414. character = String.fromCharCode( event.keyCode );
  9415. skip = false;
  9416. clearTimeout( this.filterTimer );
  9417. if ( character === prev ) {
  9418. skip = true;
  9419. } else {
  9420. character = prev + character;
  9421. }
  9422. regex = new RegExp( "^" + escape( character ), "i" );
  9423. match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
  9424. return regex.test( $( this ).children( "a" ).text() );
  9425. });
  9426. match = skip && match.index( this.active.next() ) !== -1 ?
  9427. this.active.nextAll( ".ui-menu-item" ) :
  9428. match;
  9429. // If no matches on the current filter, reset to the last character pressed
  9430. // to move down the menu to the first item that starts with that character
  9431. if ( !match.length ) {
  9432. character = String.fromCharCode( event.keyCode );
  9433. regex = new RegExp( "^" + escape( character ), "i" );
  9434. match = this.activeMenu.children( ".ui-menu-item" ).filter(function() {
  9435. return regex.test( $( this ).children( "a" ).text() );
  9436. });
  9437. }
  9438. if ( match.length ) {
  9439. this.focus( event, match );
  9440. if ( match.length > 1 ) {
  9441. this.previousFilter = character;
  9442. this.filterTimer = this._delay(function() {
  9443. delete this.previousFilter;
  9444. }, 1000 );
  9445. } else {
  9446. delete this.previousFilter;
  9447. }
  9448. } else {
  9449. delete this.previousFilter;
  9450. }
  9451. }
  9452. if ( preventDefault ) {
  9453. event.preventDefault();
  9454. }
  9455. },
  9456. _activate: function( event ) {
  9457. if ( !this.active.is( ".ui-state-disabled" ) ) {
  9458. if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
  9459. this.expand( event );
  9460. } else {
  9461. this.select( event );
  9462. }
  9463. }
  9464. },
  9465. refresh: function() {
  9466. // Initialize nested menus
  9467. var menus,
  9468. icon = this.options.icons.submenu,
  9469. submenus = this.element.find( this.options.menus + ":not(.ui-menu)" )
  9470. .addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
  9471. .hide()
  9472. .attr({
  9473. role: this.options.role,
  9474. "aria-hidden": "true",
  9475. "aria-expanded": "false"
  9476. });
  9477. // Don't refresh list items that are already adapted
  9478. menus = submenus.add( this.element );
  9479. menus.children( ":not(.ui-menu-item):has(a)" )
  9480. .addClass( "ui-menu-item" )
  9481. .attr( "role", "presentation" )
  9482. .children( "a" )
  9483. .uniqueId()
  9484. .addClass( "ui-corner-all" )
  9485. .attr({
  9486. tabIndex: -1,
  9487. role: this._itemRole()
  9488. });
  9489. // Initialize unlinked menu-items containing spaces and/or dashes only as dividers
  9490. menus.children( ":not(.ui-menu-item)" ).each(function() {
  9491. var item = $( this );
  9492. // hyphen, em dash, en dash
  9493. if ( !/[^\-—–\s]/.test( item.text() ) ) {
  9494. item.addClass( "ui-widget-content ui-menu-divider" );
  9495. }
  9496. });
  9497. // Add aria-disabled attribute to any disabled menu item
  9498. menus.children( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
  9499. submenus.each(function() {
  9500. var menu = $( this ),
  9501. item = menu.prev( "a" ),
  9502. submenuCarat = $( "<span>" )
  9503. .addClass( "ui-menu-icon ui-icon " + icon )
  9504. .data( "ui-menu-submenu-carat", true );
  9505. item
  9506. .attr( "aria-haspopup", "true" )
  9507. .prepend( submenuCarat );
  9508. menu.attr( "aria-labelledby", item.attr( "id" ) );
  9509. });
  9510. // If the active item has been removed, blur the menu
  9511. if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
  9512. this.blur();
  9513. }
  9514. },
  9515. _itemRole: function() {
  9516. return {
  9517. menu: "menuitem",
  9518. listbox: "option"
  9519. }[ this.options.role ];
  9520. },
  9521. focus: function( event, item ) {
  9522. var nested, focused;
  9523. this.blur( event, event && event.type === "focus" );
  9524. this._scrollIntoView( item );
  9525. this.active = item.first();
  9526. focused = this.active.children( "a" ).addClass( "ui-state-focus" );
  9527. // Only update aria-activedescendant if there's a role
  9528. // otherwise we assume focus is managed elsewhere
  9529. if ( this.options.role ) {
  9530. this.element.attr( "aria-activedescendant", focused.attr( "id" ) );
  9531. }
  9532. // Highlight active parent menu item, if any
  9533. this.active
  9534. .parent()
  9535. .closest( ".ui-menu-item" )
  9536. .children( "a:first" )
  9537. .addClass( "ui-state-active" );
  9538. if ( event && event.type === "keydown" ) {
  9539. this._close();
  9540. } else {
  9541. this.timer = this._delay(function() {
  9542. this._close();
  9543. }, this.delay );
  9544. }
  9545. nested = item.children( ".ui-menu" );
  9546. if ( nested.length && ( /^mouse/.test( event.type ) ) ) {
  9547. this._startOpening(nested);
  9548. }
  9549. this.activeMenu = item.parent();
  9550. this._trigger( "focus", event, { item: item } );
  9551. },
  9552. _scrollIntoView: function( item ) {
  9553. var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
  9554. if ( this._hasScroll() ) {
  9555. borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0;
  9556. paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0;
  9557. offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
  9558. scroll = this.activeMenu.scrollTop();
  9559. elementHeight = this.activeMenu.height();
  9560. itemHeight = item.height();
  9561. if ( offset < 0 ) {
  9562. this.activeMenu.scrollTop( scroll + offset );
  9563. } else if ( offset + itemHeight > elementHeight ) {
  9564. this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
  9565. }
  9566. }
  9567. },
  9568. blur: function( event, fromFocus ) {
  9569. if ( !fromFocus ) {
  9570. clearTimeout( this.timer );
  9571. }
  9572. if ( !this.active ) {
  9573. return;
  9574. }
  9575. this.active.children( "a" ).removeClass( "ui-state-focus" );
  9576. this.active = null;
  9577. this._trigger( "blur", event, { item: this.active } );
  9578. },
  9579. _startOpening: function( submenu ) {
  9580. clearTimeout( this.timer );
  9581. // Don't open if already open fixes a Firefox bug that caused a .5 pixel
  9582. // shift in the submenu position when mousing over the carat icon
  9583. if ( submenu.attr( "aria-hidden" ) !== "true" ) {
  9584. return;
  9585. }
  9586. this.timer = this._delay(function() {
  9587. this._close();
  9588. this._open( submenu );
  9589. }, this.delay );
  9590. },
  9591. _open: function( submenu ) {
  9592. var position = $.extend({
  9593. of: this.active
  9594. }, this.options.position );
  9595. clearTimeout( this.timer );
  9596. this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) )
  9597. .hide()
  9598. .attr( "aria-hidden", "true" );
  9599. submenu
  9600. .show()
  9601. .removeAttr( "aria-hidden" )
  9602. .attr( "aria-expanded", "true" )
  9603. .position( position );
  9604. },
  9605. collapseAll: function( event, all ) {
  9606. clearTimeout( this.timer );
  9607. this.timer = this._delay(function() {
  9608. // If we were passed an event, look for the submenu that contains the event
  9609. var currentMenu = all ? this.element :
  9610. $( event && event.target ).closest( this.element.find( ".ui-menu" ) );
  9611. // If we found no valid submenu ancestor, use the main menu to close all sub menus anyway
  9612. if ( !currentMenu.length ) {
  9613. currentMenu = this.element;
  9614. }
  9615. this._close( currentMenu );
  9616. this.blur( event );
  9617. this.activeMenu = currentMenu;
  9618. }, this.delay );
  9619. },
  9620. // With no arguments, closes the currently active menu - if nothing is active
  9621. // it closes all menus. If passed an argument, it will search for menus BELOW
  9622. _close: function( startMenu ) {
  9623. if ( !startMenu ) {
  9624. startMenu = this.active ? this.active.parent() : this.element;
  9625. }
  9626. startMenu
  9627. .find( ".ui-menu" )
  9628. .hide()
  9629. .attr( "aria-hidden", "true" )
  9630. .attr( "aria-expanded", "false" )
  9631. .end()
  9632. .find( "a.ui-state-active" )
  9633. .removeClass( "ui-state-active" );
  9634. },
  9635. collapse: function( event ) {
  9636. var newItem = this.active &&
  9637. this.active.parent().closest( ".ui-menu-item", this.element );
  9638. if ( newItem && newItem.length ) {
  9639. this._close();
  9640. this.focus( event, newItem );
  9641. }
  9642. },
  9643. expand: function( event ) {
  9644. var newItem = this.active &&
  9645. this.active
  9646. .children( ".ui-menu " )
  9647. .children( ".ui-menu-item" )
  9648. .first();
  9649. if ( newItem && newItem.length ) {
  9650. this._open( newItem.parent() );
  9651. // Delay so Firefox will not hide activedescendant change in expanding submenu from AT
  9652. this._delay(function() {
  9653. this.focus( event, newItem );
  9654. });
  9655. }
  9656. },
  9657. next: function( event ) {
  9658. this._move( "next", "first", event );
  9659. },
  9660. previous: function( event ) {
  9661. this._move( "prev", "last", event );
  9662. },
  9663. isFirstItem: function() {
  9664. return this.active && !this.active.prevAll( ".ui-menu-item" ).length;
  9665. },
  9666. isLastItem: function() {
  9667. return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
  9668. },
  9669. _move: function( direction, filter, event ) {
  9670. var next;
  9671. if ( this.active ) {
  9672. if ( direction === "first" || direction === "last" ) {
  9673. next = this.active
  9674. [ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
  9675. .eq( -1 );
  9676. } else {
  9677. next = this.active
  9678. [ direction + "All" ]( ".ui-menu-item" )
  9679. .eq( 0 );
  9680. }
  9681. }
  9682. if ( !next || !next.length || !this.active ) {
  9683. next = this.activeMenu.children( ".ui-menu-item" )[ filter ]();
  9684. }
  9685. this.focus( event, next );
  9686. },
  9687. nextPage: function( event ) {
  9688. var item, base, height;
  9689. if ( !this.active ) {
  9690. this.next( event );
  9691. return;
  9692. }
  9693. if ( this.isLastItem() ) {
  9694. return;
  9695. }
  9696. if ( this._hasScroll() ) {
  9697. base = this.active.offset().top;
  9698. height = this.element.height();
  9699. this.active.nextAll( ".ui-menu-item" ).each(function() {
  9700. item = $( this );
  9701. return item.offset().top - base - height < 0;
  9702. });
  9703. this.focus( event, item );
  9704. } else {
  9705. this.focus( event, this.activeMenu.children( ".ui-menu-item" )
  9706. [ !this.active ? "first" : "last" ]() );
  9707. }
  9708. },
  9709. previousPage: function( event ) {
  9710. var item, base, height;
  9711. if ( !this.active ) {
  9712. this.next( event );
  9713. return;
  9714. }
  9715. if ( this.isFirstItem() ) {
  9716. return;
  9717. }
  9718. if ( this._hasScroll() ) {
  9719. base = this.active.offset().top;
  9720. height = this.element.height();
  9721. this.active.prevAll( ".ui-menu-item" ).each(function() {
  9722. item = $( this );
  9723. return item.offset().top - base + height > 0;
  9724. });
  9725. this.focus( event, item );
  9726. } else {
  9727. this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
  9728. }
  9729. },
  9730. _hasScroll: function() {
  9731. return this.element.outerHeight() < this.element.prop( "scrollHeight" );
  9732. },
  9733. select: function( event ) {
  9734. // TODO: It should never be possible to not have an active item at this
  9735. // point, but the tests don't trigger mouseenter before click.
  9736. this.active = this.active || $( event.target ).closest( ".ui-menu-item" );
  9737. var ui = { item: this.active };
  9738. if ( !this.active.has( ".ui-menu" ).length ) {
  9739. this.collapseAll( event, true );
  9740. }
  9741. this._trigger( "select", event, ui );
  9742. }
  9743. });
  9744. }( jQuery ));
  9745. (function( $, undefined ) {
  9746. $.ui = $.ui || {};
  9747. var cachedScrollbarWidth,
  9748. max = Math.max,
  9749. abs = Math.abs,
  9750. round = Math.round,
  9751. rhorizontal = /left|center|right/,
  9752. rvertical = /top|center|bottom/,
  9753. roffset = /[\+\-]\d+%?/,
  9754. rposition = /^\w+/,
  9755. rpercent = /%$/,
  9756. _position = $.fn.position;
  9757. function getOffsets( offsets, width, height ) {
  9758. return [
  9759. parseInt( offsets[ 0 ], 10 ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  9760. parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  9761. ];
  9762. }
  9763. function parseCss( element, property ) {
  9764. return parseInt( $.css( element, property ), 10 ) || 0;
  9765. }
  9766. $.position = {
  9767. scrollbarWidth: function() {
  9768. if ( cachedScrollbarWidth !== undefined ) {
  9769. return cachedScrollbarWidth;
  9770. }
  9771. var w1, w2,
  9772. div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
  9773. innerDiv = div.children()[0];
  9774. $( "body" ).append( div );
  9775. w1 = innerDiv.offsetWidth;
  9776. div.css( "overflow", "scroll" );
  9777. w2 = innerDiv.offsetWidth;
  9778. if ( w1 === w2 ) {
  9779. w2 = div[0].clientWidth;
  9780. }
  9781. div.remove();
  9782. return (cachedScrollbarWidth = w1 - w2);
  9783. },
  9784. getScrollInfo: function( within ) {
  9785. var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ),
  9786. overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ),
  9787. hasOverflowX = overflowX === "scroll" ||
  9788. ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
  9789. hasOverflowY = overflowY === "scroll" ||
  9790. ( overflowY === "auto" && within.height < within.element[0].scrollHeight );
  9791. return {
  9792. width: hasOverflowX ? $.position.scrollbarWidth() : 0,
  9793. height: hasOverflowY ? $.position.scrollbarWidth() : 0
  9794. };
  9795. },
  9796. getWithinInfo: function( element ) {
  9797. var withinElement = $( element || window ),
  9798. isWindow = $.isWindow( withinElement[0] );
  9799. return {
  9800. element: withinElement,
  9801. isWindow: isWindow,
  9802. offset: withinElement.offset() || { left: 0, top: 0 },
  9803. scrollLeft: withinElement.scrollLeft(),
  9804. scrollTop: withinElement.scrollTop(),
  9805. width: isWindow ? withinElement.width() : withinElement.outerWidth(),
  9806. height: isWindow ? withinElement.height() : withinElement.outerHeight()
  9807. };
  9808. }
  9809. };
  9810. $.fn.position = function( options ) {
  9811. if ( !options || !options.of ) {
  9812. return _position.apply( this, arguments );
  9813. }
  9814. // make a copy, we don't want to modify arguments
  9815. options = $.extend( {}, options );
  9816. var atOffset, targetWidth, targetHeight, targetOffset, basePosition,
  9817. target = $( options.of ),
  9818. within = $.position.getWithinInfo( options.within ),
  9819. scrollInfo = $.position.getScrollInfo( within ),
  9820. targetElem = target[0],
  9821. collision = ( options.collision || "flip" ).split( " " ),
  9822. offsets = {};
  9823. if ( targetElem.nodeType === 9 ) {
  9824. targetWidth = target.width();
  9825. targetHeight = target.height();
  9826. targetOffset = { top: 0, left: 0 };
  9827. } else if ( $.isWindow( targetElem ) ) {
  9828. targetWidth = target.width();
  9829. targetHeight = target.height();
  9830. targetOffset = { top: target.scrollTop(), left: target.scrollLeft() };
  9831. } else if ( targetElem.preventDefault ) {
  9832. // force left top to allow flipping
  9833. options.at = "left top";
  9834. targetWidth = targetHeight = 0;
  9835. targetOffset = { top: targetElem.pageY, left: targetElem.pageX };
  9836. } else {
  9837. targetWidth = target.outerWidth();
  9838. targetHeight = target.outerHeight();
  9839. targetOffset = target.offset();
  9840. }
  9841. // clone to reuse original targetOffset later
  9842. basePosition = $.extend( {}, targetOffset );
  9843. // force my and at to have valid horizontal and vertical positions
  9844. // if a value is missing or invalid, it will be converted to center
  9845. $.each( [ "my", "at" ], function() {
  9846. var pos = ( options[ this ] || "" ).split( " " ),
  9847. horizontalOffset,
  9848. verticalOffset;
  9849. if ( pos.length === 1) {
  9850. pos = rhorizontal.test( pos[ 0 ] ) ?
  9851. pos.concat( [ "center" ] ) :
  9852. rvertical.test( pos[ 0 ] ) ?
  9853. [ "center" ].concat( pos ) :
  9854. [ "center", "center" ];
  9855. }
  9856. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  9857. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  9858. // calculate offsets
  9859. horizontalOffset = roffset.exec( pos[ 0 ] );
  9860. verticalOffset = roffset.exec( pos[ 1 ] );
  9861. offsets[ this ] = [
  9862. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  9863. verticalOffset ? verticalOffset[ 0 ] : 0
  9864. ];
  9865. // reduce to just the positions without the offsets
  9866. options[ this ] = [
  9867. rposition.exec( pos[ 0 ] )[ 0 ],
  9868. rposition.exec( pos[ 1 ] )[ 0 ]
  9869. ];
  9870. });
  9871. // normalize collision option
  9872. if ( collision.length === 1 ) {
  9873. collision[ 1 ] = collision[ 0 ];
  9874. }
  9875. if ( options.at[ 0 ] === "right" ) {
  9876. basePosition.left += targetWidth;
  9877. } else if ( options.at[ 0 ] === "center" ) {
  9878. basePosition.left += targetWidth / 2;
  9879. }
  9880. if ( options.at[ 1 ] === "bottom" ) {
  9881. basePosition.top += targetHeight;
  9882. } else if ( options.at[ 1 ] === "center" ) {
  9883. basePosition.top += targetHeight / 2;
  9884. }
  9885. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  9886. basePosition.left += atOffset[ 0 ];
  9887. basePosition.top += atOffset[ 1 ];
  9888. return this.each(function() {
  9889. var collisionPosition, using,
  9890. elem = $( this ),
  9891. elemWidth = elem.outerWidth(),
  9892. elemHeight = elem.outerHeight(),
  9893. marginLeft = parseCss( this, "marginLeft" ),
  9894. marginTop = parseCss( this, "marginTop" ),
  9895. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
  9896. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
  9897. position = $.extend( {}, basePosition ),
  9898. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  9899. if ( options.my[ 0 ] === "right" ) {
  9900. position.left -= elemWidth;
  9901. } else if ( options.my[ 0 ] === "center" ) {
  9902. position.left -= elemWidth / 2;
  9903. }
  9904. if ( options.my[ 1 ] === "bottom" ) {
  9905. position.top -= elemHeight;
  9906. } else if ( options.my[ 1 ] === "center" ) {
  9907. position.top -= elemHeight / 2;
  9908. }
  9909. position.left += myOffset[ 0 ];
  9910. position.top += myOffset[ 1 ];
  9911. // if the browser doesn't support fractions, then round for consistent results
  9912. if ( !$.support.offsetFractions ) {
  9913. position.left = round( position.left );
  9914. position.top = round( position.top );
  9915. }
  9916. collisionPosition = {
  9917. marginLeft: marginLeft,
  9918. marginTop: marginTop
  9919. };
  9920. $.each( [ "left", "top" ], function( i, dir ) {
  9921. if ( $.ui.position[ collision[ i ] ] ) {
  9922. $.ui.position[ collision[ i ] ][ dir ]( position, {
  9923. targetWidth: targetWidth,
  9924. targetHeight: targetHeight,
  9925. elemWidth: elemWidth,
  9926. elemHeight: elemHeight,
  9927. collisionPosition: collisionPosition,
  9928. collisionWidth: collisionWidth,
  9929. collisionHeight: collisionHeight,
  9930. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  9931. my: options.my,
  9932. at: options.at,
  9933. within: within,
  9934. elem : elem
  9935. });
  9936. }
  9937. });
  9938. if ( $.fn.bgiframe ) {
  9939. elem.bgiframe();
  9940. }
  9941. if ( options.using ) {
  9942. // adds feedback as second argument to using callback, if present
  9943. using = function( props ) {
  9944. var left = targetOffset.left - position.left,
  9945. right = left + targetWidth - elemWidth,
  9946. top = targetOffset.top - position.top,
  9947. bottom = top + targetHeight - elemHeight,
  9948. feedback = {
  9949. target: {
  9950. element: target,
  9951. left: targetOffset.left,
  9952. top: targetOffset.top,
  9953. width: targetWidth,
  9954. height: targetHeight
  9955. },
  9956. element: {
  9957. element: elem,
  9958. left: position.left,
  9959. top: position.top,
  9960. width: elemWidth,
  9961. height: elemHeight
  9962. },
  9963. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  9964. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  9965. };
  9966. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  9967. feedback.horizontal = "center";
  9968. }
  9969. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  9970. feedback.vertical = "middle";
  9971. }
  9972. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  9973. feedback.important = "horizontal";
  9974. } else {
  9975. feedback.important = "vertical";
  9976. }
  9977. options.using.call( this, props, feedback );
  9978. };
  9979. }
  9980. elem.offset( $.extend( position, { using: using } ) );
  9981. });
  9982. };
  9983. $.ui.position = {
  9984. fit: {
  9985. left: function( position, data ) {
  9986. var within = data.within,
  9987. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  9988. outerWidth = within.width,
  9989. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  9990. overLeft = withinOffset - collisionPosLeft,
  9991. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  9992. newOverRight;
  9993. // element is wider than within
  9994. if ( data.collisionWidth > outerWidth ) {
  9995. // element is initially over the left side of within
  9996. if ( overLeft > 0 && overRight <= 0 ) {
  9997. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
  9998. position.left += overLeft - newOverRight;
  9999. // element is initially over right side of within
  10000. } else if ( overRight > 0 && overLeft <= 0 ) {
  10001. position.left = withinOffset;
  10002. // element is initially over both left and right sides of within
  10003. } else {
  10004. if ( overLeft > overRight ) {
  10005. position.left = withinOffset + outerWidth - data.collisionWidth;
  10006. } else {
  10007. position.left = withinOffset;
  10008. }
  10009. }
  10010. // too far left -> align with left edge
  10011. } else if ( overLeft > 0 ) {
  10012. position.left += overLeft;
  10013. // too far right -> align with right edge
  10014. } else if ( overRight > 0 ) {
  10015. position.left -= overRight;
  10016. // adjust based on position and margin
  10017. } else {
  10018. position.left = max( position.left - collisionPosLeft, position.left );
  10019. }
  10020. },
  10021. top: function( position, data ) {
  10022. var within = data.within,
  10023. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  10024. outerHeight = data.within.height,
  10025. collisionPosTop = position.top - data.collisionPosition.marginTop,
  10026. overTop = withinOffset - collisionPosTop,
  10027. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  10028. newOverBottom;
  10029. // element is taller than within
  10030. if ( data.collisionHeight > outerHeight ) {
  10031. // element is initially over the top of within
  10032. if ( overTop > 0 && overBottom <= 0 ) {
  10033. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
  10034. position.top += overTop - newOverBottom;
  10035. // element is initially over bottom of within
  10036. } else if ( overBottom > 0 && overTop <= 0 ) {
  10037. position.top = withinOffset;
  10038. // element is initially over both top and bottom of within
  10039. } else {
  10040. if ( overTop > overBottom ) {
  10041. position.top = withinOffset + outerHeight - data.collisionHeight;
  10042. } else {
  10043. position.top = withinOffset;
  10044. }
  10045. }
  10046. // too far up -> align with top
  10047. } else if ( overTop > 0 ) {
  10048. position.top += overTop;
  10049. // too far down -> align with bottom edge
  10050. } else if ( overBottom > 0 ) {
  10051. position.top -= overBottom;
  10052. // adjust based on position and margin
  10053. } else {
  10054. position.top = max( position.top - collisionPosTop, position.top );
  10055. }
  10056. }
  10057. },
  10058. flip: {
  10059. left: function( position, data ) {
  10060. var within = data.within,
  10061. withinOffset = within.offset.left + within.scrollLeft,
  10062. outerWidth = within.width,
  10063. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  10064. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  10065. overLeft = collisionPosLeft - offsetLeft,
  10066. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  10067. myOffset = data.my[ 0 ] === "left" ?
  10068. -data.elemWidth :
  10069. data.my[ 0 ] === "right" ?
  10070. data.elemWidth :
  10071. 0,
  10072. atOffset = data.at[ 0 ] === "left" ?
  10073. data.targetWidth :
  10074. data.at[ 0 ] === "right" ?
  10075. -data.targetWidth :
  10076. 0,
  10077. offset = -2 * data.offset[ 0 ],
  10078. newOverRight,
  10079. newOverLeft;
  10080. if ( overLeft < 0 ) {
  10081. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
  10082. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  10083. position.left += myOffset + atOffset + offset;
  10084. }
  10085. }
  10086. else if ( overRight > 0 ) {
  10087. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
  10088. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  10089. position.left += myOffset + atOffset + offset;
  10090. }
  10091. }
  10092. },
  10093. top: function( position, data ) {
  10094. var within = data.within,
  10095. withinOffset = within.offset.top + within.scrollTop,
  10096. outerHeight = within.height,
  10097. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  10098. collisionPosTop = position.top - data.collisionPosition.marginTop,
  10099. overTop = collisionPosTop - offsetTop,
  10100. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  10101. top = data.my[ 1 ] === "top",
  10102. myOffset = top ?
  10103. -data.elemHeight :
  10104. data.my[ 1 ] === "bottom" ?
  10105. data.elemHeight :
  10106. 0,
  10107. atOffset = data.at[ 1 ] === "top" ?
  10108. data.targetHeight :
  10109. data.at[ 1 ] === "bottom" ?
  10110. -data.targetHeight :
  10111. 0,
  10112. offset = -2 * data.offset[ 1 ],
  10113. newOverTop,
  10114. newOverBottom;
  10115. if ( overTop < 0 ) {
  10116. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
  10117. if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) ) {
  10118. position.top += myOffset + atOffset + offset;
  10119. }
  10120. }
  10121. else if ( overBottom > 0 ) {
  10122. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
  10123. if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || abs( newOverTop ) < overBottom ) ) {
  10124. position.top += myOffset + atOffset + offset;
  10125. }
  10126. }
  10127. }
  10128. },
  10129. flipfit: {
  10130. left: function() {
  10131. $.ui.position.flip.left.apply( this, arguments );
  10132. $.ui.position.fit.left.apply( this, arguments );
  10133. },
  10134. top: function() {
  10135. $.ui.position.flip.top.apply( this, arguments );
  10136. $.ui.position.fit.top.apply( this, arguments );
  10137. }
  10138. }
  10139. };
  10140. // fraction support test
  10141. (function () {
  10142. var testElement, testElementParent, testElementStyle, offsetLeft, i,
  10143. body = document.getElementsByTagName( "body" )[ 0 ],
  10144. div = document.createElement( "div" );
  10145. //Create a "fake body" for testing based on method used in jQuery.support
  10146. testElement = document.createElement( body ? "div" : "body" );
  10147. testElementStyle = {
  10148. visibility: "hidden",
  10149. width: 0,
  10150. height: 0,
  10151. border: 0,
  10152. margin: 0,
  10153. background: "none"
  10154. };
  10155. if ( body ) {
  10156. $.extend( testElementStyle, {
  10157. position: "absolute",
  10158. left: "-1000px",
  10159. top: "-1000px"
  10160. });
  10161. }
  10162. for ( i in testElementStyle ) {
  10163. testElement.style[ i ] = testElementStyle[ i ];
  10164. }
  10165. testElement.appendChild( div );
  10166. testElementParent = body || document.documentElement;
  10167. testElementParent.insertBefore( testElement, testElementParent.firstChild );
  10168. div.style.cssText = "position: absolute; left: 10.7432222px;";
  10169. offsetLeft = $( div ).offset().left;
  10170. $.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11;
  10171. testElement.innerHTML = "";
  10172. testElementParent.removeChild( testElement );
  10173. })();
  10174. // DEPRECATED
  10175. if ( $.uiBackCompat !== false ) {
  10176. // offset option
  10177. (function( $ ) {
  10178. var _position = $.fn.position;
  10179. $.fn.position = function( options ) {
  10180. if ( !options || !options.offset ) {
  10181. return _position.call( this, options );
  10182. }
  10183. var offset = options.offset.split( " " ),
  10184. at = options.at.split( " " );
  10185. if ( offset.length === 1 ) {
  10186. offset[ 1 ] = offset[ 0 ];
  10187. }
  10188. if ( /^\d/.test( offset[ 0 ] ) ) {
  10189. offset[ 0 ] = "+" + offset[ 0 ];
  10190. }
  10191. if ( /^\d/.test( offset[ 1 ] ) ) {
  10192. offset[ 1 ] = "+" + offset[ 1 ];
  10193. }
  10194. if ( at.length === 1 ) {
  10195. if ( /left|center|right/.test( at[ 0 ] ) ) {
  10196. at[ 1 ] = "center";
  10197. } else {
  10198. at[ 1 ] = at[ 0 ];
  10199. at[ 0 ] = "center";
  10200. }
  10201. }
  10202. return _position.call( this, $.extend( options, {
  10203. at: at[ 0 ] + offset[ 0 ] + " " + at[ 1 ] + offset[ 1 ],
  10204. offset: undefined
  10205. } ) );
  10206. };
  10207. }( jQuery ) );
  10208. }
  10209. }( jQuery ) );
  10210. (function( $, undefined ) {
  10211. $.widget( "ui.progressbar", {
  10212. version: "1.9.0",
  10213. options: {
  10214. value: 0,
  10215. max: 100
  10216. },
  10217. min: 0,
  10218. _create: function() {
  10219. this.element
  10220. .addClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
  10221. .attr({
  10222. role: "progressbar",
  10223. "aria-valuemin": this.min,
  10224. "aria-valuemax": this.options.max,
  10225. "aria-valuenow": this._value()
  10226. });
  10227. this.valueDiv = $( "<div class='ui-progressbar-value ui-widget-header ui-corner-left'></div>" )
  10228. .appendTo( this.element );
  10229. this.oldValue = this._value();
  10230. this._refreshValue();
  10231. },
  10232. _destroy: function() {
  10233. this.element
  10234. .removeClass( "ui-progressbar ui-widget ui-widget-content ui-corner-all" )
  10235. .removeAttr( "role" )
  10236. .removeAttr( "aria-valuemin" )
  10237. .removeAttr( "aria-valuemax" )
  10238. .removeAttr( "aria-valuenow" );
  10239. this.valueDiv.remove();
  10240. },
  10241. value: function( newValue ) {
  10242. if ( newValue === undefined ) {
  10243. return this._value();
  10244. }
  10245. this._setOption( "value", newValue );
  10246. return this;
  10247. },
  10248. _setOption: function( key, value ) {
  10249. if ( key === "value" ) {
  10250. this.options.value = value;
  10251. this._refreshValue();
  10252. if ( this._value() === this.options.max ) {
  10253. this._trigger( "complete" );
  10254. }
  10255. }
  10256. this._super( key, value );
  10257. },
  10258. _value: function() {
  10259. var val = this.options.value;
  10260. // normalize invalid value
  10261. if ( typeof val !== "number" ) {
  10262. val = 0;
  10263. }
  10264. return Math.min( this.options.max, Math.max( this.min, val ) );
  10265. },
  10266. _percentage: function() {
  10267. return 100 * this._value() / this.options.max;
  10268. },
  10269. _refreshValue: function() {
  10270. var value = this.value(),
  10271. percentage = this._percentage();
  10272. if ( this.oldValue !== value ) {
  10273. this.oldValue = value;
  10274. this._trigger( "change" );
  10275. }
  10276. this.valueDiv
  10277. .toggle( value > this.min )
  10278. .toggleClass( "ui-corner-right", value === this.options.max )
  10279. .width( percentage.toFixed(0) + "%" );
  10280. this.element.attr( "aria-valuenow", value );
  10281. }
  10282. });
  10283. })( jQuery );
  10284. (function( $, undefined ) {
  10285. // number of pages in a slider
  10286. // (how many times can you page up/down to go through the whole range)
  10287. var numPages = 5;
  10288. $.widget( "ui.slider", $.ui.mouse, {
  10289. version: "1.9.0",
  10290. widgetEventPrefix: "slide",
  10291. options: {
  10292. animate: false,
  10293. distance: 0,
  10294. max: 100,
  10295. min: 0,
  10296. orientation: "horizontal",
  10297. range: false,
  10298. step: 1,
  10299. value: 0,
  10300. values: null
  10301. },
  10302. _create: function() {
  10303. var i,
  10304. o = this.options,
  10305. existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
  10306. handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
  10307. handleCount = ( o.values && o.values.length ) || 1,
  10308. handles = [];
  10309. this._keySliding = false;
  10310. this._mouseSliding = false;
  10311. this._animateOff = true;
  10312. this._handleIndex = null;
  10313. this._detectOrientation();
  10314. this._mouseInit();
  10315. this.element
  10316. .addClass( "ui-slider" +
  10317. " ui-slider-" + this.orientation +
  10318. " ui-widget" +
  10319. " ui-widget-content" +
  10320. " ui-corner-all" +
  10321. ( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) );
  10322. this.range = $([]);
  10323. if ( o.range ) {
  10324. if ( o.range === true ) {
  10325. if ( !o.values ) {
  10326. o.values = [ this._valueMin(), this._valueMin() ];
  10327. }
  10328. if ( o.values.length && o.values.length !== 2 ) {
  10329. o.values = [ o.values[0], o.values[0] ];
  10330. }
  10331. }
  10332. this.range = $( "<div></div>" )
  10333. .appendTo( this.element )
  10334. .addClass( "ui-slider-range" +
  10335. // note: this isn't the most fittingly semantic framework class for this element,
  10336. // but worked best visually with a variety of themes
  10337. " ui-widget-header" +
  10338. ( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) );
  10339. }
  10340. for ( i = existingHandles.length; i < handleCount; i++ ) {
  10341. handles.push( handle );
  10342. }
  10343. this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( this.element ) );
  10344. this.handle = this.handles.eq( 0 );
  10345. this.handles.add( this.range ).filter( "a" )
  10346. .click(function( event ) {
  10347. event.preventDefault();
  10348. })
  10349. .mouseenter(function() {
  10350. if ( !o.disabled ) {
  10351. $( this ).addClass( "ui-state-hover" );
  10352. }
  10353. })
  10354. .mouseleave(function() {
  10355. $( this ).removeClass( "ui-state-hover" );
  10356. })
  10357. .focus(function() {
  10358. if ( !o.disabled ) {
  10359. $( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" );
  10360. $( this ).addClass( "ui-state-focus" );
  10361. } else {
  10362. $( this ).blur();
  10363. }
  10364. })
  10365. .blur(function() {
  10366. $( this ).removeClass( "ui-state-focus" );
  10367. });
  10368. this.handles.each(function( i ) {
  10369. $( this ).data( "ui-slider-handle-index", i );
  10370. });
  10371. this._on( this.handles, {
  10372. keydown: function( event ) {
  10373. var allowed, curVal, newVal, step,
  10374. index = $( event.target ).data( "ui-slider-handle-index" );
  10375. switch ( event.keyCode ) {
  10376. case $.ui.keyCode.HOME:
  10377. case $.ui.keyCode.END:
  10378. case $.ui.keyCode.PAGE_UP:
  10379. case $.ui.keyCode.PAGE_DOWN:
  10380. case $.ui.keyCode.UP:
  10381. case $.ui.keyCode.RIGHT:
  10382. case $.ui.keyCode.DOWN:
  10383. case $.ui.keyCode.LEFT:
  10384. event.preventDefault();
  10385. if ( !this._keySliding ) {
  10386. this._keySliding = true;
  10387. $( event.target ).addClass( "ui-state-active" );
  10388. allowed = this._start( event, index );
  10389. if ( allowed === false ) {
  10390. return;
  10391. }
  10392. }
  10393. break;
  10394. }
  10395. step = this.options.step;
  10396. if ( this.options.values && this.options.values.length ) {
  10397. curVal = newVal = this.values( index );
  10398. } else {
  10399. curVal = newVal = this.value();
  10400. }
  10401. switch ( event.keyCode ) {
  10402. case $.ui.keyCode.HOME:
  10403. newVal = this._valueMin();
  10404. break;
  10405. case $.ui.keyCode.END:
  10406. newVal = this._valueMax();
  10407. break;
  10408. case $.ui.keyCode.PAGE_UP:
  10409. newVal = this._trimAlignValue( curVal + ( (this._valueMax() - this._valueMin()) / numPages ) );
  10410. break;
  10411. case $.ui.keyCode.PAGE_DOWN:
  10412. newVal = this._trimAlignValue( curVal - ( (this._valueMax() - this._valueMin()) / numPages ) );
  10413. break;
  10414. case $.ui.keyCode.UP:
  10415. case $.ui.keyCode.RIGHT:
  10416. if ( curVal === this._valueMax() ) {
  10417. return;
  10418. }
  10419. newVal = this._trimAlignValue( curVal + step );
  10420. break;
  10421. case $.ui.keyCode.DOWN:
  10422. case $.ui.keyCode.LEFT:
  10423. if ( curVal === this._valueMin() ) {
  10424. return;
  10425. }
  10426. newVal = this._trimAlignValue( curVal - step );
  10427. break;
  10428. }
  10429. this._slide( event, index, newVal );
  10430. },
  10431. keyup: function( event ) {
  10432. var index = $( event.target ).data( "ui-slider-handle-index" );
  10433. if ( this._keySliding ) {
  10434. this._keySliding = false;
  10435. this._stop( event, index );
  10436. this._change( event, index );
  10437. $( event.target ).removeClass( "ui-state-active" );
  10438. }
  10439. }
  10440. });
  10441. this._refreshValue();
  10442. this._animateOff = false;
  10443. },
  10444. _destroy: function() {
  10445. this.handles.remove();
  10446. this.range.remove();
  10447. this.element
  10448. .removeClass( "ui-slider" +
  10449. " ui-slider-horizontal" +
  10450. " ui-slider-vertical" +
  10451. " ui-slider-disabled" +
  10452. " ui-widget" +
  10453. " ui-widget-content" +
  10454. " ui-corner-all" );
  10455. this._mouseDestroy();
  10456. },
  10457. _mouseCapture: function( event ) {
  10458. var position, normValue, distance, closestHandle, index, allowed, offset, mouseOverHandle,
  10459. that = this,
  10460. o = this.options;
  10461. if ( o.disabled ) {
  10462. return false;
  10463. }
  10464. this.elementSize = {
  10465. width: this.element.outerWidth(),
  10466. height: this.element.outerHeight()
  10467. };
  10468. this.elementOffset = this.element.offset();
  10469. position = { x: event.pageX, y: event.pageY };
  10470. normValue = this._normValueFromMouse( position );
  10471. distance = this._valueMax() - this._valueMin() + 1;
  10472. this.handles.each(function( i ) {
  10473. var thisDistance = Math.abs( normValue - that.values(i) );
  10474. if ( distance > thisDistance ) {
  10475. distance = thisDistance;
  10476. closestHandle = $( this );
  10477. index = i;
  10478. }
  10479. });
  10480. // workaround for bug #3736 (if both handles of a range are at 0,
  10481. // the first is always used as the one with least distance,
  10482. // and moving it is obviously prevented by preventing negative ranges)
  10483. if( o.range === true && this.values(1) === o.min ) {
  10484. index += 1;
  10485. closestHandle = $( this.handles[index] );
  10486. }
  10487. allowed = this._start( event, index );
  10488. if ( allowed === false ) {
  10489. return false;
  10490. }
  10491. this._mouseSliding = true;
  10492. this._handleIndex = index;
  10493. closestHandle
  10494. .addClass( "ui-state-active" )
  10495. .focus();
  10496. offset = closestHandle.offset();
  10497. mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" );
  10498. this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
  10499. left: event.pageX - offset.left - ( closestHandle.width() / 2 ),
  10500. top: event.pageY - offset.top -
  10501. ( closestHandle.height() / 2 ) -
  10502. ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) -
  10503. ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) +
  10504. ( parseInt( closestHandle.css("marginTop"), 10 ) || 0)
  10505. };
  10506. if ( !this.handles.hasClass( "ui-state-hover" ) ) {
  10507. this._slide( event, index, normValue );
  10508. }
  10509. this._animateOff = true;
  10510. return true;
  10511. },
  10512. _mouseStart: function( event ) {
  10513. return true;
  10514. },
  10515. _mouseDrag: function( event ) {
  10516. var position = { x: event.pageX, y: event.pageY },
  10517. normValue = this._normValueFromMouse( position );
  10518. this._slide( event, this._handleIndex, normValue );
  10519. return false;
  10520. },
  10521. _mouseStop: function( event ) {
  10522. this.handles.removeClass( "ui-state-active" );
  10523. this._mouseSliding = false;
  10524. this._stop( event, this._handleIndex );
  10525. this._change( event, this._handleIndex );
  10526. this._handleIndex = null;
  10527. this._clickOffset = null;
  10528. this._animateOff = false;
  10529. return false;
  10530. },
  10531. _detectOrientation: function() {
  10532. this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal";
  10533. },
  10534. _normValueFromMouse: function( position ) {
  10535. var pixelTotal,
  10536. pixelMouse,
  10537. percentMouse,
  10538. valueTotal,
  10539. valueMouse;
  10540. if ( this.orientation === "horizontal" ) {
  10541. pixelTotal = this.elementSize.width;
  10542. pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 );
  10543. } else {
  10544. pixelTotal = this.elementSize.height;
  10545. pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 );
  10546. }
  10547. percentMouse = ( pixelMouse / pixelTotal );
  10548. if ( percentMouse > 1 ) {
  10549. percentMouse = 1;
  10550. }
  10551. if ( percentMouse < 0 ) {
  10552. percentMouse = 0;
  10553. }
  10554. if ( this.orientation === "vertical" ) {
  10555. percentMouse = 1 - percentMouse;
  10556. }
  10557. valueTotal = this._valueMax() - this._valueMin();
  10558. valueMouse = this._valueMin() + percentMouse * valueTotal;
  10559. return this._trimAlignValue( valueMouse );
  10560. },
  10561. _start: function( event, index ) {
  10562. var uiHash = {
  10563. handle: this.handles[ index ],
  10564. value: this.value()
  10565. };
  10566. if ( this.options.values && this.options.values.length ) {
  10567. uiHash.value = this.values( index );
  10568. uiHash.values = this.values();
  10569. }
  10570. return this._trigger( "start", event, uiHash );
  10571. },
  10572. _slide: function( event, index, newVal ) {
  10573. var otherVal,
  10574. newValues,
  10575. allowed;
  10576. if ( this.options.values && this.options.values.length ) {
  10577. otherVal = this.values( index ? 0 : 1 );
  10578. if ( ( this.options.values.length === 2 && this.options.range === true ) &&
  10579. ( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) )
  10580. ) {
  10581. newVal = otherVal;
  10582. }
  10583. if ( newVal !== this.values( index ) ) {
  10584. newValues = this.values();
  10585. newValues[ index ] = newVal;
  10586. // A slide can be canceled by returning false from the slide callback
  10587. allowed = this._trigger( "slide", event, {
  10588. handle: this.handles[ index ],
  10589. value: newVal,
  10590. values: newValues
  10591. } );
  10592. otherVal = this.values( index ? 0 : 1 );
  10593. if ( allowed !== false ) {
  10594. this.values( index, newVal, true );
  10595. }
  10596. }
  10597. } else {
  10598. if ( newVal !== this.value() ) {
  10599. // A slide can be canceled by returning false from the slide callback
  10600. allowed = this._trigger( "slide", event, {
  10601. handle: this.handles[ index ],
  10602. value: newVal
  10603. } );
  10604. if ( allowed !== false ) {
  10605. this.value( newVal );
  10606. }
  10607. }
  10608. }
  10609. },
  10610. _stop: function( event, index ) {
  10611. var uiHash = {
  10612. handle: this.handles[ index ],
  10613. value: this.value()
  10614. };
  10615. if ( this.options.values && this.options.values.length ) {
  10616. uiHash.value = this.values( index );
  10617. uiHash.values = this.values();
  10618. }
  10619. this._trigger( "stop", event, uiHash );
  10620. },
  10621. _change: function( event, index ) {
  10622. if ( !this._keySliding && !this._mouseSliding ) {
  10623. var uiHash = {
  10624. handle: this.handles[ index ],
  10625. value: this.value()
  10626. };
  10627. if ( this.options.values && this.options.values.length ) {
  10628. uiHash.value = this.values( index );
  10629. uiHash.values = this.values();
  10630. }
  10631. this._trigger( "change", event, uiHash );
  10632. }
  10633. },
  10634. value: function( newValue ) {
  10635. if ( arguments.length ) {
  10636. this.options.value = this._trimAlignValue( newValue );
  10637. this._refreshValue();
  10638. this._change( null, 0 );
  10639. return;
  10640. }
  10641. return this._value();
  10642. },
  10643. values: function( index, newValue ) {
  10644. var vals,
  10645. newValues,
  10646. i;
  10647. if ( arguments.length > 1 ) {
  10648. this.options.values[ index ] = this._trimAlignValue( newValue );
  10649. this._refreshValue();
  10650. this._change( null, index );
  10651. return;
  10652. }
  10653. if ( arguments.length ) {
  10654. if ( $.isArray( arguments[ 0 ] ) ) {
  10655. vals = this.options.values;
  10656. newValues = arguments[ 0 ];
  10657. for ( i = 0; i < vals.length; i += 1 ) {
  10658. vals[ i ] = this._trimAlignValue( newValues[ i ] );
  10659. this._change( null, i );
  10660. }
  10661. this._refreshValue();
  10662. } else {
  10663. if ( this.options.values && this.options.values.length ) {
  10664. return this._values( index );
  10665. } else {
  10666. return this.value();
  10667. }
  10668. }
  10669. } else {
  10670. return this._values();
  10671. }
  10672. },
  10673. _setOption: function( key, value ) {
  10674. var i,
  10675. valsLength = 0;
  10676. if ( $.isArray( this.options.values ) ) {
  10677. valsLength = this.options.values.length;
  10678. }
  10679. $.Widget.prototype._setOption.apply( this, arguments );
  10680. switch ( key ) {
  10681. case "disabled":
  10682. if ( value ) {
  10683. this.handles.filter( ".ui-state-focus" ).blur();
  10684. this.handles.removeClass( "ui-state-hover" );
  10685. this.handles.prop( "disabled", true );
  10686. this.element.addClass( "ui-disabled" );
  10687. } else {
  10688. this.handles.prop( "disabled", false );
  10689. this.element.removeClass( "ui-disabled" );
  10690. }
  10691. break;
  10692. case "orientation":
  10693. this._detectOrientation();
  10694. this.element
  10695. .removeClass( "ui-slider-horizontal ui-slider-vertical" )
  10696. .addClass( "ui-slider-" + this.orientation );
  10697. this._refreshValue();
  10698. break;
  10699. case "value":
  10700. this._animateOff = true;
  10701. this._refreshValue();
  10702. this._change( null, 0 );
  10703. this._animateOff = false;
  10704. break;
  10705. case "values":
  10706. this._animateOff = true;
  10707. this._refreshValue();
  10708. for ( i = 0; i < valsLength; i += 1 ) {
  10709. this._change( null, i );
  10710. }
  10711. this._animateOff = false;
  10712. break;
  10713. }
  10714. },
  10715. //internal value getter
  10716. // _value() returns value trimmed by min and max, aligned by step
  10717. _value: function() {
  10718. var val = this.options.value;
  10719. val = this._trimAlignValue( val );
  10720. return val;
  10721. },
  10722. //internal values getter
  10723. // _values() returns array of values trimmed by min and max, aligned by step
  10724. // _values( index ) returns single value trimmed by min and max, aligned by step
  10725. _values: function( index ) {
  10726. var val,
  10727. vals,
  10728. i;
  10729. if ( arguments.length ) {
  10730. val = this.options.values[ index ];
  10731. val = this._trimAlignValue( val );
  10732. return val;
  10733. } else {
  10734. // .slice() creates a copy of the array
  10735. // this copy gets trimmed by min and max and then returned
  10736. vals = this.options.values.slice();
  10737. for ( i = 0; i < vals.length; i+= 1) {
  10738. vals[ i ] = this._trimAlignValue( vals[ i ] );
  10739. }
  10740. return vals;
  10741. }
  10742. },
  10743. // returns the step-aligned value that val is closest to, between (inclusive) min and max
  10744. _trimAlignValue: function( val ) {
  10745. if ( val <= this._valueMin() ) {
  10746. return this._valueMin();
  10747. }
  10748. if ( val >= this._valueMax() ) {
  10749. return this._valueMax();
  10750. }
  10751. var step = ( this.options.step > 0 ) ? this.options.step : 1,
  10752. valModStep = (val - this._valueMin()) % step,
  10753. alignValue = val - valModStep;
  10754. if ( Math.abs(valModStep) * 2 >= step ) {
  10755. alignValue += ( valModStep > 0 ) ? step : ( -step );
  10756. }
  10757. // Since JavaScript has problems with large floats, round
  10758. // the final value to 5 digits after the decimal point (see #4124)
  10759. return parseFloat( alignValue.toFixed(5) );
  10760. },
  10761. _valueMin: function() {
  10762. return this.options.min;
  10763. },
  10764. _valueMax: function() {
  10765. return this.options.max;
  10766. },
  10767. _refreshValue: function() {
  10768. var lastValPercent, valPercent, value, valueMin, valueMax,
  10769. oRange = this.options.range,
  10770. o = this.options,
  10771. that = this,
  10772. animate = ( !this._animateOff ) ? o.animate : false,
  10773. _set = {};
  10774. if ( this.options.values && this.options.values.length ) {
  10775. this.handles.each(function( i, j ) {
  10776. valPercent = ( that.values(i) - that._valueMin() ) / ( that._valueMax() - that._valueMin() ) * 100;
  10777. _set[ that.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
  10778. $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
  10779. if ( that.options.range === true ) {
  10780. if ( that.orientation === "horizontal" ) {
  10781. if ( i === 0 ) {
  10782. that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate );
  10783. }
  10784. if ( i === 1 ) {
  10785. that.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
  10786. }
  10787. } else {
  10788. if ( i === 0 ) {
  10789. that.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate );
  10790. }
  10791. if ( i === 1 ) {
  10792. that.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } );
  10793. }
  10794. }
  10795. }
  10796. lastValPercent = valPercent;
  10797. });
  10798. } else {
  10799. value = this.value();
  10800. valueMin = this._valueMin();
  10801. valueMax = this._valueMax();
  10802. valPercent = ( valueMax !== valueMin ) ?
  10803. ( value - valueMin ) / ( valueMax - valueMin ) * 100 :
  10804. 0;
  10805. _set[ this.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%";
  10806. this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate );
  10807. if ( oRange === "min" && this.orientation === "horizontal" ) {
  10808. this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate );
  10809. }
  10810. if ( oRange === "max" && this.orientation === "horizontal" ) {
  10811. this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
  10812. }
  10813. if ( oRange === "min" && this.orientation === "vertical" ) {
  10814. this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate );
  10815. }
  10816. if ( oRange === "max" && this.orientation === "vertical" ) {
  10817. this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } );
  10818. }
  10819. }
  10820. }
  10821. });
  10822. }(jQuery));
  10823. (function( $ ) {
  10824. function modifier( fn ) {
  10825. return function() {
  10826. var previous = this.element.val();
  10827. fn.apply( this, arguments );
  10828. this._refresh();
  10829. if ( previous !== this.element.val() ) {
  10830. this._trigger( "change" );
  10831. }
  10832. };
  10833. }
  10834. $.widget( "ui.spinner", {
  10835. version: "1.9.0",
  10836. defaultElement: "<input>",
  10837. widgetEventPrefix: "spin",
  10838. options: {
  10839. culture: null,
  10840. icons: {
  10841. down: "ui-icon-triangle-1-s",
  10842. up: "ui-icon-triangle-1-n"
  10843. },
  10844. incremental: true,
  10845. max: null,
  10846. min: null,
  10847. numberFormat: null,
  10848. page: 10,
  10849. step: 1,
  10850. change: null,
  10851. spin: null,
  10852. start: null,
  10853. stop: null
  10854. },
  10855. _create: function() {
  10856. // handle string values that need to be parsed
  10857. this._setOption( "max", this.options.max );
  10858. this._setOption( "min", this.options.min );
  10859. this._setOption( "step", this.options.step );
  10860. // format the value, but don't constrain
  10861. this._value( this.element.val(), true );
  10862. this._draw();
  10863. this._on( this._events );
  10864. this._refresh();
  10865. // turning off autocomplete prevents the browser from remembering the
  10866. // value when navigating through history, so we re-enable autocomplete
  10867. // if the page is unloaded before the widget is destroyed. #7790
  10868. this._on( this.window, {
  10869. beforeunload: function() {
  10870. this.element.removeAttr( "autocomplete" );
  10871. }
  10872. });
  10873. },
  10874. _getCreateOptions: function() {
  10875. var options = {},
  10876. element = this.element;
  10877. $.each( [ "min", "max", "step" ], function( i, option ) {
  10878. var value = element.attr( option );
  10879. if ( value !== undefined && value.length ) {
  10880. options[ option ] = value;
  10881. }
  10882. });
  10883. return options;
  10884. },
  10885. _events: {
  10886. keydown: function( event ) {
  10887. if ( this._start( event ) && this._keydown( event ) ) {
  10888. event.preventDefault();
  10889. }
  10890. },
  10891. keyup: "_stop",
  10892. focus: function() {
  10893. this.uiSpinner.addClass( "ui-state-active" );
  10894. this.previous = this.element.val();
  10895. },
  10896. blur: function( event ) {
  10897. if ( this.cancelBlur ) {
  10898. delete this.cancelBlur;
  10899. return;
  10900. }
  10901. this._refresh();
  10902. this.uiSpinner.removeClass( "ui-state-active" );
  10903. if ( this.previous !== this.element.val() ) {
  10904. this._trigger( "change", event );
  10905. }
  10906. },
  10907. mousewheel: function( event, delta ) {
  10908. if ( !delta ) {
  10909. return;
  10910. }
  10911. if ( !this.spinning && !this._start( event ) ) {
  10912. return false;
  10913. }
  10914. this._spin( (delta > 0 ? 1 : -1) * this.options.step, event );
  10915. clearTimeout( this.mousewheelTimer );
  10916. this.mousewheelTimer = this._delay(function() {
  10917. if ( this.spinning ) {
  10918. this._stop( event );
  10919. }
  10920. }, 100 );
  10921. event.preventDefault();
  10922. },
  10923. "mousedown .ui-spinner-button": function( event ) {
  10924. var previous;
  10925. // We never want the buttons to have focus; whenever the user is
  10926. // interacting with the spinner, the focus should be on the input.
  10927. // If the input is focused then this.previous is properly set from
  10928. // when the input first received focus. If the input is not focused
  10929. // then we need to set this.previous based on the value before spinning.
  10930. previous = this.element[0] === this.document[0].activeElement ?
  10931. this.previous : this.element.val();
  10932. function checkFocus() {
  10933. var isActive = this.element[0] === this.document[0].activeElement;
  10934. if ( !isActive ) {
  10935. this.element.focus();
  10936. this.previous = previous;
  10937. // support: IE
  10938. // IE sets focus asynchronously, so we need to check if focus
  10939. // moved off of the input because the user clicked on the button.
  10940. this._delay(function() {
  10941. this.previous = previous;
  10942. });
  10943. }
  10944. }
  10945. // ensure focus is on (or stays on) the text field
  10946. event.preventDefault();
  10947. checkFocus.call( this );
  10948. // support: IE
  10949. // IE doesn't prevent moving focus even with event.preventDefault()
  10950. // so we set a flag to know when we should ignore the blur event
  10951. // and check (again) if focus moved off of the input.
  10952. this.cancelBlur = true;
  10953. this._delay(function() {
  10954. delete this.cancelBlur;
  10955. checkFocus.call( this );
  10956. });
  10957. if ( this._start( event ) === false ) {
  10958. return;
  10959. }
  10960. this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event );
  10961. },
  10962. "mouseup .ui-spinner-button": "_stop",
  10963. "mouseenter .ui-spinner-button": function( event ) {
  10964. // button will add ui-state-active if mouse was down while mouseleave and kept down
  10965. if ( !$( event.currentTarget ).hasClass( "ui-state-active" ) ) {
  10966. return;
  10967. }
  10968. if ( this._start( event ) === false ) {
  10969. return false;
  10970. }
  10971. this._repeat( null, $( event.currentTarget ).hasClass( "ui-spinner-up" ) ? 1 : -1, event );
  10972. },
  10973. // TODO: do we really want to consider this a stop?
  10974. // shouldn't we just stop the repeater and wait until mouseup before
  10975. // we trigger the stop event?
  10976. "mouseleave .ui-spinner-button": "_stop"
  10977. },
  10978. _draw: function() {
  10979. var uiSpinner = this.uiSpinner = this.element
  10980. .addClass( "ui-spinner-input" )
  10981. .attr( "autocomplete", "off" )
  10982. .wrap( this._uiSpinnerHtml() )
  10983. .parent()
  10984. // add buttons
  10985. .append( this._buttonHtml() );
  10986. this._hoverable( uiSpinner );
  10987. this.element.attr( "role", "spinbutton" );
  10988. // button bindings
  10989. this.buttons = uiSpinner.find( ".ui-spinner-button" )
  10990. .attr( "tabIndex", -1 )
  10991. .button()
  10992. .removeClass( "ui-corner-all" );
  10993. // IE 6 doesn't understand height: 50% for the buttons
  10994. // unless the wrapper has an explicit height
  10995. if ( this.buttons.height() > Math.ceil( uiSpinner.height() * 0.5 ) &&
  10996. uiSpinner.height() > 0 ) {
  10997. uiSpinner.height( uiSpinner.height() );
  10998. }
  10999. // disable spinner if element was already disabled
  11000. if ( this.options.disabled ) {
  11001. this.disable();
  11002. }
  11003. },
  11004. _keydown: function( event ) {
  11005. var options = this.options,
  11006. keyCode = $.ui.keyCode;
  11007. switch ( event.keyCode ) {
  11008. case keyCode.UP:
  11009. this._repeat( null, 1, event );
  11010. return true;
  11011. case keyCode.DOWN:
  11012. this._repeat( null, -1, event );
  11013. return true;
  11014. case keyCode.PAGE_UP:
  11015. this._repeat( null, options.page, event );
  11016. return true;
  11017. case keyCode.PAGE_DOWN:
  11018. this._repeat( null, -options.page, event );
  11019. return true;
  11020. }
  11021. return false;
  11022. },
  11023. _uiSpinnerHtml: function() {
  11024. return "<span class='ui-spinner ui-state-default ui-widget ui-widget-content ui-corner-all'></span>";
  11025. },
  11026. _buttonHtml: function() {
  11027. return "" +
  11028. "<a class='ui-spinner-button ui-spinner-up ui-corner-tr'>" +
  11029. "<span class='ui-icon " + this.options.icons.up + "'>&#9650;</span>" +
  11030. "</a>" +
  11031. "<a class='ui-spinner-button ui-spinner-down ui-corner-br'>" +
  11032. "<span class='ui-icon " + this.options.icons.down + "'>&#9660;</span>" +
  11033. "</a>";
  11034. },
  11035. _start: function( event ) {
  11036. if ( !this.spinning && this._trigger( "start", event ) === false ) {
  11037. return false;
  11038. }
  11039. if ( !this.counter ) {
  11040. this.counter = 1;
  11041. }
  11042. this.spinning = true;
  11043. return true;
  11044. },
  11045. _repeat: function( i, steps, event ) {
  11046. i = i || 500;
  11047. clearTimeout( this.timer );
  11048. this.timer = this._delay(function() {
  11049. this._repeat( 40, steps, event );
  11050. }, i );
  11051. this._spin( steps * this.options.step, event );
  11052. },
  11053. _spin: function( step, event ) {
  11054. var value = this.value() || 0;
  11055. if ( !this.counter ) {
  11056. this.counter = 1;
  11057. }
  11058. value = this._adjustValue( value + step * this._increment( this.counter ) );
  11059. if ( !this.spinning || this._trigger( "spin", event, { value: value } ) !== false) {
  11060. this._value( value );
  11061. this.counter++;
  11062. }
  11063. },
  11064. _increment: function( i ) {
  11065. var incremental = this.options.incremental;
  11066. if ( incremental ) {
  11067. return $.isFunction( incremental ) ?
  11068. incremental( i ) :
  11069. Math.floor( i*i*i/50000 - i*i/500 + 17*i/200 + 1 );
  11070. }
  11071. return 1;
  11072. },
  11073. _precision: function() {
  11074. var precision = this._precisionOf( this.options.step );
  11075. if ( this.options.min !== null ) {
  11076. precision = Math.max( precision, this._precisionOf( this.options.min ) );
  11077. }
  11078. return precision;
  11079. },
  11080. _precisionOf: function( num ) {
  11081. var str = num.toString(),
  11082. decimal = str.indexOf( "." );
  11083. return decimal === -1 ? 0 : str.length - decimal - 1;
  11084. },
  11085. _adjustValue: function( value ) {
  11086. var base, aboveMin,
  11087. options = this.options;
  11088. // make sure we're at a valid step
  11089. // - find out where we are relative to the base (min or 0)
  11090. base = options.min !== null ? options.min : 0;
  11091. aboveMin = value - base;
  11092. // - round to the nearest step
  11093. aboveMin = Math.round(aboveMin / options.step) * options.step;
  11094. // - rounding is based on 0, so adjust back to our base
  11095. value = base + aboveMin;
  11096. // fix precision from bad JS floating point math
  11097. value = parseFloat( value.toFixed( this._precision() ) );
  11098. // clamp the value
  11099. if ( options.max !== null && value > options.max) {
  11100. return options.max;
  11101. }
  11102. if ( options.min !== null && value < options.min ) {
  11103. return options.min;
  11104. }
  11105. return value;
  11106. },
  11107. _stop: function( event ) {
  11108. if ( !this.spinning ) {
  11109. return;
  11110. }
  11111. clearTimeout( this.timer );
  11112. clearTimeout( this.mousewheelTimer );
  11113. this.counter = 0;
  11114. this.spinning = false;
  11115. this._trigger( "stop", event );
  11116. },
  11117. _setOption: function( key, value ) {
  11118. if ( key === "culture" || key === "numberFormat" ) {
  11119. var prevValue = this._parse( this.element.val() );
  11120. this.options[ key ] = value;
  11121. this.element.val( this._format( prevValue ) );
  11122. return;
  11123. }
  11124. if ( key === "max" || key === "min" || key === "step" ) {
  11125. if ( typeof value === "string" ) {
  11126. value = this._parse( value );
  11127. }
  11128. }
  11129. this._super( key, value );
  11130. if ( key === "disabled" ) {
  11131. if ( value ) {
  11132. this.element.prop( "disabled", true );
  11133. this.buttons.button( "disable" );
  11134. } else {
  11135. this.element.prop( "disabled", false );
  11136. this.buttons.button( "enable" );
  11137. }
  11138. }
  11139. },
  11140. _setOptions: modifier(function( options ) {
  11141. this._super( options );
  11142. this._value( this.element.val() );
  11143. }),
  11144. _parse: function( val ) {
  11145. if ( typeof val === "string" && val !== "" ) {
  11146. val = window.Globalize && this.options.numberFormat ?
  11147. Globalize.parseFloat( val, 10, this.options.culture ) : +val;
  11148. }
  11149. return val === "" || isNaN( val ) ? null : val;
  11150. },
  11151. _format: function( value ) {
  11152. if ( value === "" ) {
  11153. return "";
  11154. }
  11155. return window.Globalize && this.options.numberFormat ?
  11156. Globalize.format( value, this.options.numberFormat, this.options.culture ) :
  11157. value;
  11158. },
  11159. _refresh: function() {
  11160. this.element.attr({
  11161. "aria-valuemin": this.options.min,
  11162. "aria-valuemax": this.options.max,
  11163. // TODO: what should we do with values that can't be parsed?
  11164. "aria-valuenow": this._parse( this.element.val() )
  11165. });
  11166. },
  11167. // update the value without triggering change
  11168. _value: function( value, allowAny ) {
  11169. var parsed;
  11170. if ( value !== "" ) {
  11171. parsed = this._parse( value );
  11172. if ( parsed !== null ) {
  11173. if ( !allowAny ) {
  11174. parsed = this._adjustValue( parsed );
  11175. }
  11176. value = this._format( parsed );
  11177. }
  11178. }
  11179. this.element.val( value );
  11180. this._refresh();
  11181. },
  11182. _destroy: function() {
  11183. this.element
  11184. .removeClass( "ui-spinner-input" )
  11185. .prop( "disabled", false )
  11186. .removeAttr( "autocomplete" )
  11187. .removeAttr( "role" )
  11188. .removeAttr( "aria-valuemin" )
  11189. .removeAttr( "aria-valuemax" )
  11190. .removeAttr( "aria-valuenow" );
  11191. this.uiSpinner.replaceWith( this.element );
  11192. },
  11193. stepUp: modifier(function( steps ) {
  11194. this._stepUp( steps );
  11195. }),
  11196. _stepUp: function( steps ) {
  11197. this._spin( (steps || 1) * this.options.step );
  11198. },
  11199. stepDown: modifier(function( steps ) {
  11200. this._stepDown( steps );
  11201. }),
  11202. _stepDown: function( steps ) {
  11203. this._spin( (steps || 1) * -this.options.step );
  11204. },
  11205. pageUp: modifier(function( pages ) {
  11206. this._stepUp( (pages || 1) * this.options.page );
  11207. }),
  11208. pageDown: modifier(function( pages ) {
  11209. this._stepDown( (pages || 1) * this.options.page );
  11210. }),
  11211. value: function( newVal ) {
  11212. if ( !arguments.length ) {
  11213. return this._parse( this.element.val() );
  11214. }
  11215. modifier( this._value ).call( this, newVal );
  11216. },
  11217. widget: function() {
  11218. return this.uiSpinner;
  11219. }
  11220. });
  11221. }( jQuery ) );
  11222. (function( $, undefined ) {
  11223. var tabId = 0,
  11224. rhash = /#.*$/;
  11225. function getNextTabId() {
  11226. return ++tabId;
  11227. }
  11228. function isLocal( anchor ) {
  11229. // clone the node to work around IE 6 not normalizing the href property
  11230. // if it's manually set, i.e., a.href = "#foo" kills the normalization
  11231. anchor = anchor.cloneNode( false );
  11232. return anchor.hash.length > 1 &&
  11233. anchor.href.replace( rhash, "" ) === location.href.replace( rhash, "" );
  11234. }
  11235. $.widget( "ui.tabs", {
  11236. version: "1.9.0",
  11237. delay: 300,
  11238. options: {
  11239. active: null,
  11240. collapsible: false,
  11241. event: "click",
  11242. heightStyle: "content",
  11243. hide: null,
  11244. show: null,
  11245. // callbacks
  11246. activate: null,
  11247. beforeActivate: null,
  11248. beforeLoad: null,
  11249. load: null
  11250. },
  11251. _create: function() {
  11252. var panel,
  11253. that = this,
  11254. options = this.options,
  11255. active = options.active;
  11256. this.running = false;
  11257. this.element
  11258. .addClass( "ui-tabs ui-widget ui-widget-content ui-corner-all" )
  11259. .toggleClass( "ui-tabs-collapsible", options.collapsible )
  11260. // Prevent users from focusing disabled tabs via click
  11261. .delegate( ".ui-tabs-nav > li", "mousedown" + this.eventNamespace, function( event ) {
  11262. if ( $( this ).is( ".ui-state-disabled" ) ) {
  11263. event.preventDefault();
  11264. }
  11265. })
  11266. // support: IE <9
  11267. // Preventing the default action in mousedown doesn't prevent IE
  11268. // from focusing the element, so if the anchor gets focused, blur.
  11269. // We don't have to worry about focusing the previously focused
  11270. // element since clicking on a non-focusable element should focus
  11271. // the body anyway.
  11272. .delegate( ".ui-tabs-anchor", "focus" + this.eventNamespace, function() {
  11273. if ( $( this ).closest( "li" ).is( ".ui-state-disabled" ) ) {
  11274. this.blur();
  11275. }
  11276. });
  11277. this._processTabs();
  11278. if ( active === null ) {
  11279. // check the fragment identifier in the URL
  11280. if ( location.hash ) {
  11281. this.anchors.each(function( i, anchor ) {
  11282. if ( anchor.hash === location.hash ) {
  11283. active = i;
  11284. return false;
  11285. }
  11286. });
  11287. }
  11288. // check for a tab marked active via a class
  11289. if ( active === null ) {
  11290. active = this.tabs.filter( ".ui-tabs-active" ).index();
  11291. }
  11292. // no active tab, set to false
  11293. if ( active === null || active === -1 ) {
  11294. active = this.tabs.length ? 0 : false;
  11295. }
  11296. }
  11297. // handle numbers: negative, out of range
  11298. if ( active !== false ) {
  11299. active = this.tabs.index( this.tabs.eq( active ) );
  11300. if ( active === -1 ) {
  11301. active = options.collapsible ? false : 0;
  11302. }
  11303. }
  11304. options.active = active;
  11305. // don't allow collapsible: false and active: false
  11306. if ( !options.collapsible && options.active === false && this.anchors.length ) {
  11307. options.active = 0;
  11308. }
  11309. // Take disabling tabs via class attribute from HTML
  11310. // into account and update option properly.
  11311. if ( $.isArray( options.disabled ) ) {
  11312. options.disabled = $.unique( options.disabled.concat(
  11313. $.map( this.tabs.filter( ".ui-state-disabled" ), function( li ) {
  11314. return that.tabs.index( li );
  11315. })
  11316. ) ).sort();
  11317. }
  11318. // check for length avoids error when initializing empty list
  11319. if ( this.options.active !== false && this.anchors.length ) {
  11320. this.active = this._findActive( this.options.active );
  11321. } else {
  11322. this.active = $();
  11323. }
  11324. this._refresh();
  11325. if ( this.active.length ) {
  11326. this.load( options.active );
  11327. }
  11328. },
  11329. _getCreateEventData: function() {
  11330. return {
  11331. tab: this.active,
  11332. panel: !this.active.length ? $() : this._getPanelForTab( this.active )
  11333. };
  11334. },
  11335. _tabKeydown: function( event ) {
  11336. var focusedTab = $( this.document[0].activeElement ).closest( "li" ),
  11337. selectedIndex = this.tabs.index( focusedTab ),
  11338. goingForward = true;
  11339. if ( this._handlePageNav( event ) ) {
  11340. return;
  11341. }
  11342. switch ( event.keyCode ) {
  11343. case $.ui.keyCode.RIGHT:
  11344. case $.ui.keyCode.DOWN:
  11345. selectedIndex++;
  11346. break;
  11347. case $.ui.keyCode.UP:
  11348. case $.ui.keyCode.LEFT:
  11349. goingForward = false;
  11350. selectedIndex--;
  11351. break;
  11352. case $.ui.keyCode.END:
  11353. selectedIndex = this.anchors.length - 1;
  11354. break;
  11355. case $.ui.keyCode.HOME:
  11356. selectedIndex = 0;
  11357. break;
  11358. case $.ui.keyCode.SPACE:
  11359. // Activate only, no collapsing
  11360. event.preventDefault();
  11361. clearTimeout( this.activating );
  11362. this._activate( selectedIndex );
  11363. return;
  11364. case $.ui.keyCode.ENTER:
  11365. // Toggle (cancel delayed activation, allow collapsing)
  11366. event.preventDefault();
  11367. clearTimeout( this.activating );
  11368. // Determine if we should collapse or activate
  11369. this._activate( selectedIndex === this.options.active ? false : selectedIndex );
  11370. return;
  11371. default:
  11372. return;
  11373. }
  11374. // Focus the appropriate tab, based on which key was pressed
  11375. event.preventDefault();
  11376. clearTimeout( this.activating );
  11377. selectedIndex = this._focusNextTab( selectedIndex, goingForward );
  11378. // Navigating with control key will prevent automatic activation
  11379. if ( !event.ctrlKey ) {
  11380. // Update aria-selected immediately so that AT think the tab is already selected.
  11381. // Otherwise AT may confuse the user by stating that they need to activate the tab,
  11382. // but the tab will already be activated by the time the announcement finishes.
  11383. focusedTab.attr( "aria-selected", "false" );
  11384. this.tabs.eq( selectedIndex ).attr( "aria-selected", "true" );
  11385. this.activating = this._delay(function() {
  11386. this.option( "active", selectedIndex );
  11387. }, this.delay );
  11388. }
  11389. },
  11390. _panelKeydown: function( event ) {
  11391. if ( this._handlePageNav( event ) ) {
  11392. return;
  11393. }
  11394. // Ctrl+up moves focus to the current tab
  11395. if ( event.ctrlKey && event.keyCode === $.ui.keyCode.UP ) {
  11396. event.preventDefault();
  11397. this.active.focus();
  11398. }
  11399. },
  11400. // Alt+page up/down moves focus to the previous/next tab (and activates)
  11401. _handlePageNav: function( event ) {
  11402. if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_UP ) {
  11403. this._activate( this._focusNextTab( this.options.active - 1, false ) );
  11404. return true;
  11405. }
  11406. if ( event.altKey && event.keyCode === $.ui.keyCode.PAGE_DOWN ) {
  11407. this._activate( this._focusNextTab( this.options.active + 1, true ) );
  11408. return true;
  11409. }
  11410. },
  11411. _findNextTab: function( index, goingForward ) {
  11412. var lastTabIndex = this.tabs.length - 1;
  11413. function constrain() {
  11414. if ( index > lastTabIndex ) {
  11415. index = 0;
  11416. }
  11417. if ( index < 0 ) {
  11418. index = lastTabIndex;
  11419. }
  11420. return index;
  11421. }
  11422. while ( $.inArray( constrain(), this.options.disabled ) !== -1 ) {
  11423. index = goingForward ? index + 1 : index - 1;
  11424. }
  11425. return index;
  11426. },
  11427. _focusNextTab: function( index, goingForward ) {
  11428. index = this._findNextTab( index, goingForward );
  11429. this.tabs.eq( index ).focus();
  11430. return index;
  11431. },
  11432. _setOption: function( key, value ) {
  11433. if ( key === "active" ) {
  11434. // _activate() will handle invalid values and update this.options
  11435. this._activate( value );
  11436. return;
  11437. }
  11438. if ( key === "disabled" ) {
  11439. // don't use the widget factory's disabled handling
  11440. this._setupDisabled( value );
  11441. return;
  11442. }
  11443. this._super( key, value);
  11444. if ( key === "collapsible" ) {
  11445. this.element.toggleClass( "ui-tabs-collapsible", value );
  11446. // Setting collapsible: false while collapsed; open first panel
  11447. if ( !value && this.options.active === false ) {
  11448. this._activate( 0 );
  11449. }
  11450. }
  11451. if ( key === "event" ) {
  11452. this._setupEvents( value );
  11453. }
  11454. if ( key === "heightStyle" ) {
  11455. this._setupHeightStyle( value );
  11456. }
  11457. },
  11458. _tabId: function( tab ) {
  11459. return tab.attr( "aria-controls" ) || "ui-tabs-" + getNextTabId();
  11460. },
  11461. _sanitizeSelector: function( hash ) {
  11462. return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : "";
  11463. },
  11464. refresh: function() {
  11465. var next,
  11466. options = this.options,
  11467. lis = this.tablist.children( ":has(a[href])" );
  11468. // get disabled tabs from class attribute from HTML
  11469. // this will get converted to a boolean if needed in _refresh()
  11470. options.disabled = $.map( lis.filter( ".ui-state-disabled" ), function( tab ) {
  11471. return lis.index( tab );
  11472. });
  11473. this._processTabs();
  11474. // was collapsed or no tabs
  11475. if ( options.active === false || !this.anchors.length ) {
  11476. options.active = false;
  11477. this.active = $();
  11478. // was active, but active tab is gone
  11479. } else if ( this.active.length && !$.contains( this.tablist[ 0 ], this.active[ 0 ] ) ) {
  11480. // all remaining tabs are disabled
  11481. if ( this.tabs.length === options.disabled.length ) {
  11482. options.active = false;
  11483. this.active = $();
  11484. // activate previous tab
  11485. } else {
  11486. this._activate( this._findNextTab( Math.max( 0, options.active - 1 ), false ) );
  11487. }
  11488. // was active, active tab still exists
  11489. } else {
  11490. // make sure active index is correct
  11491. options.active = this.tabs.index( this.active );
  11492. }
  11493. this._refresh();
  11494. },
  11495. _refresh: function() {
  11496. this._setupDisabled( this.options.disabled );
  11497. this._setupEvents( this.options.event );
  11498. this._setupHeightStyle( this.options.heightStyle );
  11499. this.tabs.not( this.active ).attr({
  11500. "aria-selected": "false",
  11501. tabIndex: -1
  11502. });
  11503. this.panels.not( this._getPanelForTab( this.active ) )
  11504. .hide()
  11505. .attr({
  11506. "aria-expanded": "false",
  11507. "aria-hidden": "true"
  11508. });
  11509. // Make sure one tab is in the tab order
  11510. if ( !this.active.length ) {
  11511. this.tabs.eq( 0 ).attr( "tabIndex", 0 );
  11512. } else {
  11513. this.active
  11514. .addClass( "ui-tabs-active ui-state-active" )
  11515. .attr({
  11516. "aria-selected": "true",
  11517. tabIndex: 0
  11518. });
  11519. this._getPanelForTab( this.active )
  11520. .show()
  11521. .attr({
  11522. "aria-expanded": "true",
  11523. "aria-hidden": "false"
  11524. });
  11525. }
  11526. },
  11527. _processTabs: function() {
  11528. var that = this;
  11529. this.tablist = this._getList()
  11530. .addClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" )
  11531. .attr( "role", "tablist" );
  11532. this.tabs = this.tablist.find( "> li:has(a[href])" )
  11533. .addClass( "ui-state-default ui-corner-top" )
  11534. .attr({
  11535. role: "tab",
  11536. tabIndex: -1
  11537. });
  11538. this.anchors = this.tabs.map(function() {
  11539. return $( "a", this )[ 0 ];
  11540. })
  11541. .addClass( "ui-tabs-anchor" )
  11542. .attr({
  11543. role: "presentation",
  11544. tabIndex: -1
  11545. });
  11546. this.panels = $();
  11547. this.anchors.each(function( i, anchor ) {
  11548. var selector, panel, panelId,
  11549. anchorId = $( anchor ).uniqueId().attr( "id" ),
  11550. tab = $( anchor ).closest( "li" ),
  11551. originalAriaControls = tab.attr( "aria-controls" );
  11552. // inline tab
  11553. if ( isLocal( anchor ) ) {
  11554. selector = anchor.hash;
  11555. panel = that.element.find( that._sanitizeSelector( selector ) );
  11556. // remote tab
  11557. } else {
  11558. panelId = that._tabId( tab );
  11559. selector = "#" + panelId;
  11560. panel = that.element.find( selector );
  11561. if ( !panel.length ) {
  11562. panel = that._createPanel( panelId );
  11563. panel.insertAfter( that.panels[ i - 1 ] || that.tablist );
  11564. }
  11565. panel.attr( "aria-live", "polite" );
  11566. }
  11567. if ( panel.length) {
  11568. that.panels = that.panels.add( panel );
  11569. }
  11570. if ( originalAriaControls ) {
  11571. tab.data( "ui-tabs-aria-controls", originalAriaControls );
  11572. }
  11573. tab.attr({
  11574. "aria-controls": selector.substring( 1 ),
  11575. "aria-labelledby": anchorId
  11576. });
  11577. panel.attr( "aria-labelledby", anchorId );
  11578. });
  11579. this.panels
  11580. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  11581. .attr( "role", "tabpanel" );
  11582. },
  11583. // allow overriding how to find the list for rare usage scenarios (#7715)
  11584. _getList: function() {
  11585. return this.element.find( "ol,ul" ).eq( 0 );
  11586. },
  11587. _createPanel: function( id ) {
  11588. return $( "<div>" )
  11589. .attr( "id", id )
  11590. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  11591. .data( "ui-tabs-destroy", true );
  11592. },
  11593. _setupDisabled: function( disabled ) {
  11594. if ( $.isArray( disabled ) ) {
  11595. if ( !disabled.length ) {
  11596. disabled = false;
  11597. } else if ( disabled.length === this.anchors.length ) {
  11598. disabled = true;
  11599. }
  11600. }
  11601. // disable tabs
  11602. for ( var i = 0, li; ( li = this.tabs[ i ] ); i++ ) {
  11603. if ( disabled === true || $.inArray( i, disabled ) !== -1 ) {
  11604. $( li )
  11605. .addClass( "ui-state-disabled" )
  11606. .attr( "aria-disabled", "true" );
  11607. } else {
  11608. $( li )
  11609. .removeClass( "ui-state-disabled" )
  11610. .removeAttr( "aria-disabled" );
  11611. }
  11612. }
  11613. this.options.disabled = disabled;
  11614. },
  11615. _setupEvents: function( event ) {
  11616. var events = {
  11617. click: function( event ) {
  11618. event.preventDefault();
  11619. }
  11620. };
  11621. if ( event ) {
  11622. $.each( event.split(" "), function( index, eventName ) {
  11623. events[ eventName ] = "_eventHandler";
  11624. });
  11625. }
  11626. this._off( this.anchors.add( this.tabs ).add( this.panels ) );
  11627. this._on( this.anchors, events );
  11628. this._on( this.tabs, { keydown: "_tabKeydown" } );
  11629. this._on( this.panels, { keydown: "_panelKeydown" } );
  11630. this._focusable( this.tabs );
  11631. this._hoverable( this.tabs );
  11632. },
  11633. _setupHeightStyle: function( heightStyle ) {
  11634. var maxHeight, overflow,
  11635. parent = this.element.parent();
  11636. if ( heightStyle === "fill" ) {
  11637. // IE 6 treats height like minHeight, so we need to turn off overflow
  11638. // in order to get a reliable height
  11639. // we use the minHeight support test because we assume that only
  11640. // browsers that don't support minHeight will treat height as minHeight
  11641. if ( !$.support.minHeight ) {
  11642. overflow = parent.css( "overflow" );
  11643. parent.css( "overflow", "hidden");
  11644. }
  11645. maxHeight = parent.height();
  11646. this.element.siblings( ":visible" ).each(function() {
  11647. var elem = $( this ),
  11648. position = elem.css( "position" );
  11649. if ( position === "absolute" || position === "fixed" ) {
  11650. return;
  11651. }
  11652. maxHeight -= elem.outerHeight( true );
  11653. });
  11654. if ( overflow ) {
  11655. parent.css( "overflow", overflow );
  11656. }
  11657. this.element.children().not( this.panels ).each(function() {
  11658. maxHeight -= $( this ).outerHeight( true );
  11659. });
  11660. this.panels.each(function() {
  11661. $( this ).height( Math.max( 0, maxHeight -
  11662. $( this ).innerHeight() + $( this ).height() ) );
  11663. })
  11664. .css( "overflow", "auto" );
  11665. } else if ( heightStyle === "auto" ) {
  11666. maxHeight = 0;
  11667. this.panels.each(function() {
  11668. maxHeight = Math.max( maxHeight, $( this ).height( "" ).height() );
  11669. }).height( maxHeight );
  11670. }
  11671. },
  11672. _eventHandler: function( event ) {
  11673. var options = this.options,
  11674. active = this.active,
  11675. anchor = $( event.currentTarget ),
  11676. tab = anchor.closest( "li" ),
  11677. clickedIsActive = tab[ 0 ] === active[ 0 ],
  11678. collapsing = clickedIsActive && options.collapsible,
  11679. toShow = collapsing ? $() : this._getPanelForTab( tab ),
  11680. toHide = !active.length ? $() : this._getPanelForTab( active ),
  11681. eventData = {
  11682. oldTab: active,
  11683. oldPanel: toHide,
  11684. newTab: collapsing ? $() : tab,
  11685. newPanel: toShow
  11686. };
  11687. event.preventDefault();
  11688. if ( tab.hasClass( "ui-state-disabled" ) ||
  11689. // tab is already loading
  11690. tab.hasClass( "ui-tabs-loading" ) ||
  11691. // can't switch durning an animation
  11692. this.running ||
  11693. // click on active header, but not collapsible
  11694. ( clickedIsActive && !options.collapsible ) ||
  11695. // allow canceling activation
  11696. ( this._trigger( "beforeActivate", event, eventData ) === false ) ) {
  11697. return;
  11698. }
  11699. options.active = collapsing ? false : this.tabs.index( tab );
  11700. this.active = clickedIsActive ? $() : tab;
  11701. if ( this.xhr ) {
  11702. this.xhr.abort();
  11703. }
  11704. if ( !toHide.length && !toShow.length ) {
  11705. $.error( "jQuery UI Tabs: Mismatching fragment identifier." );
  11706. }
  11707. if ( toShow.length ) {
  11708. this.load( this.tabs.index( tab ), event );
  11709. }
  11710. this._toggle( event, eventData );
  11711. },
  11712. // handles show/hide for selecting tabs
  11713. _toggle: function( event, eventData ) {
  11714. var that = this,
  11715. toShow = eventData.newPanel,
  11716. toHide = eventData.oldPanel;
  11717. this.running = true;
  11718. function complete() {
  11719. that.running = false;
  11720. that._trigger( "activate", event, eventData );
  11721. }
  11722. function show() {
  11723. eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
  11724. if ( toShow.length && that.options.show ) {
  11725. that._show( toShow, that.options.show, complete );
  11726. } else {
  11727. toShow.show();
  11728. complete();
  11729. }
  11730. }
  11731. // start out by hiding, then showing, then completing
  11732. if ( toHide.length && this.options.hide ) {
  11733. this._hide( toHide, this.options.hide, function() {
  11734. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  11735. show();
  11736. });
  11737. } else {
  11738. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  11739. toHide.hide();
  11740. show();
  11741. }
  11742. toHide.attr({
  11743. "aria-expanded": "false",
  11744. "aria-hidden": "true"
  11745. });
  11746. eventData.oldTab.attr( "aria-selected", "false" );
  11747. // If we're switching tabs, remove the old tab from the tab order.
  11748. // If we're opening from collapsed state, remove the previous tab from the tab order.
  11749. // If we're collapsing, then keep the collapsing tab in the tab order.
  11750. if ( toShow.length && toHide.length ) {
  11751. eventData.oldTab.attr( "tabIndex", -1 );
  11752. } else if ( toShow.length ) {
  11753. this.tabs.filter(function() {
  11754. return $( this ).attr( "tabIndex" ) === 0;
  11755. })
  11756. .attr( "tabIndex", -1 );
  11757. }
  11758. toShow.attr({
  11759. "aria-expanded": "true",
  11760. "aria-hidden": "false"
  11761. });
  11762. eventData.newTab.attr({
  11763. "aria-selected": "true",
  11764. tabIndex: 0
  11765. });
  11766. },
  11767. _activate: function( index ) {
  11768. var anchor,
  11769. active = this._findActive( index );
  11770. // trying to activate the already active panel
  11771. if ( active[ 0 ] === this.active[ 0 ] ) {
  11772. return;
  11773. }
  11774. // trying to collapse, simulate a click on the current active header
  11775. if ( !active.length ) {
  11776. active = this.active;
  11777. }
  11778. anchor = active.find( ".ui-tabs-anchor" )[ 0 ];
  11779. this._eventHandler({
  11780. target: anchor,
  11781. currentTarget: anchor,
  11782. preventDefault: $.noop
  11783. });
  11784. },
  11785. _findActive: function( index ) {
  11786. return index === false ? $() : this.tabs.eq( index );
  11787. },
  11788. _getIndex: function( index ) {
  11789. // meta-function to give users option to provide a href string instead of a numerical index.
  11790. if ( typeof index === "string" ) {
  11791. index = this.anchors.index( this.anchors.filter( "[href$='" + index + "']" ) );
  11792. }
  11793. return index;
  11794. },
  11795. _destroy: function() {
  11796. if ( this.xhr ) {
  11797. this.xhr.abort();
  11798. }
  11799. this.element.removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" );
  11800. this.tablist
  11801. .removeClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" )
  11802. .removeAttr( "role" );
  11803. this.anchors
  11804. .removeClass( "ui-tabs-anchor" )
  11805. .removeAttr( "role" )
  11806. .removeAttr( "tabIndex" )
  11807. .removeData( "href.tabs" )
  11808. .removeData( "load.tabs" )
  11809. .removeUniqueId();
  11810. this.tabs.add( this.panels ).each(function() {
  11811. if ( $.data( this, "ui-tabs-destroy" ) ) {
  11812. $( this ).remove();
  11813. } else {
  11814. $( this )
  11815. .removeClass( "ui-state-default ui-state-active ui-state-disabled " +
  11816. "ui-corner-top ui-corner-bottom ui-widget-content ui-tabs-active ui-tabs-panel" )
  11817. .removeAttr( "tabIndex" )
  11818. .removeAttr( "aria-live" )
  11819. .removeAttr( "aria-busy" )
  11820. .removeAttr( "aria-selected" )
  11821. .removeAttr( "aria-labelledby" )
  11822. .removeAttr( "aria-hidden" )
  11823. .removeAttr( "aria-expanded" )
  11824. .removeAttr( "role" );
  11825. }
  11826. });
  11827. this.tabs.each(function() {
  11828. var li = $( this ),
  11829. prev = li.data( "ui-tabs-aria-controls" );
  11830. if ( prev ) {
  11831. li.attr( "aria-controls", prev );
  11832. } else {
  11833. li.removeAttr( "aria-controls" );
  11834. }
  11835. });
  11836. if ( this.options.heightStyle !== "content" ) {
  11837. this.panels.css( "height", "" );
  11838. }
  11839. },
  11840. enable: function( index ) {
  11841. var disabled = this.options.disabled;
  11842. if ( disabled === false ) {
  11843. return;
  11844. }
  11845. if ( index === undefined ) {
  11846. disabled = false;
  11847. } else {
  11848. index = this._getIndex( index );
  11849. if ( $.isArray( disabled ) ) {
  11850. disabled = $.map( disabled, function( num ) {
  11851. return num !== index ? num : null;
  11852. });
  11853. } else {
  11854. disabled = $.map( this.tabs, function( li, num ) {
  11855. return num !== index ? num : null;
  11856. });
  11857. }
  11858. }
  11859. this._setupDisabled( disabled );
  11860. },
  11861. disable: function( index ) {
  11862. var disabled = this.options.disabled;
  11863. if ( disabled === true ) {
  11864. return;
  11865. }
  11866. if ( index === undefined ) {
  11867. disabled = true;
  11868. } else {
  11869. index = this._getIndex( index );
  11870. if ( $.inArray( index, disabled ) !== -1 ) {
  11871. return;
  11872. }
  11873. if ( $.isArray( disabled ) ) {
  11874. disabled = $.merge( [ index ], disabled ).sort();
  11875. } else {
  11876. disabled = [ index ];
  11877. }
  11878. }
  11879. this._setupDisabled( disabled );
  11880. },
  11881. load: function( index, event ) {
  11882. index = this._getIndex( index );
  11883. var that = this,
  11884. tab = this.tabs.eq( index ),
  11885. anchor = tab.find( ".ui-tabs-anchor" ),
  11886. panel = this._getPanelForTab( tab ),
  11887. eventData = {
  11888. tab: tab,
  11889. panel: panel
  11890. };
  11891. // not remote
  11892. if ( isLocal( anchor[ 0 ] ) ) {
  11893. return;
  11894. }
  11895. this.xhr = $.ajax( this._ajaxSettings( anchor, event, eventData ) );
  11896. // support: jQuery <1.8
  11897. // jQuery <1.8 returns false if the request is canceled in beforeSend,
  11898. // but as of 1.8, $.ajax() always returns a jqXHR object.
  11899. if ( this.xhr && this.xhr.statusText !== "canceled" ) {
  11900. tab.addClass( "ui-tabs-loading" );
  11901. panel.attr( "aria-busy", "true" );
  11902. this.xhr
  11903. .success(function( response ) {
  11904. // support: jQuery <1.8
  11905. // http://bugs.jquery.com/ticket/11778
  11906. setTimeout(function() {
  11907. panel.html( response );
  11908. that._trigger( "load", event, eventData );
  11909. }, 1 );
  11910. })
  11911. .complete(function( jqXHR, status ) {
  11912. // support: jQuery <1.8
  11913. // http://bugs.jquery.com/ticket/11778
  11914. setTimeout(function() {
  11915. if ( status === "abort" ) {
  11916. that.panels.stop( false, true );
  11917. }
  11918. tab.removeClass( "ui-tabs-loading" );
  11919. panel.removeAttr( "aria-busy" );
  11920. if ( jqXHR === that.xhr ) {
  11921. delete that.xhr;
  11922. }
  11923. }, 1 );
  11924. });
  11925. }
  11926. },
  11927. // TODO: Remove this function in 1.10 when ajaxOptions is removed
  11928. _ajaxSettings: function( anchor, event, eventData ) {
  11929. var that = this;
  11930. return {
  11931. url: anchor.attr( "href" ),
  11932. beforeSend: function( jqXHR, settings ) {
  11933. return that._trigger( "beforeLoad", event,
  11934. $.extend( { jqXHR : jqXHR, ajaxSettings: settings }, eventData ) );
  11935. }
  11936. };
  11937. },
  11938. _getPanelForTab: function( tab ) {
  11939. var id = $( tab ).attr( "aria-controls" );
  11940. return this.element.find( this._sanitizeSelector( "#" + id ) );
  11941. }
  11942. });
  11943. // DEPRECATED
  11944. if ( $.uiBackCompat !== false ) {
  11945. // helper method for a lot of the back compat extensions
  11946. $.ui.tabs.prototype._ui = function( tab, panel ) {
  11947. return {
  11948. tab: tab,
  11949. panel: panel,
  11950. index: this.anchors.index( tab )
  11951. };
  11952. };
  11953. // url method
  11954. $.widget( "ui.tabs", $.ui.tabs, {
  11955. url: function( index, url ) {
  11956. this.anchors.eq( index ).attr( "href", url );
  11957. }
  11958. });
  11959. // TODO: Remove _ajaxSettings() method when removing this extension
  11960. // ajaxOptions and cache options
  11961. $.widget( "ui.tabs", $.ui.tabs, {
  11962. options: {
  11963. ajaxOptions: null,
  11964. cache: false
  11965. },
  11966. _create: function() {
  11967. this._super();
  11968. var that = this;
  11969. this._on({ tabsbeforeload: function( event, ui ) {
  11970. // tab is already cached
  11971. if ( $.data( ui.tab[ 0 ], "cache.tabs" ) ) {
  11972. event.preventDefault();
  11973. return;
  11974. }
  11975. ui.jqXHR.success(function() {
  11976. if ( that.options.cache ) {
  11977. $.data( ui.tab[ 0 ], "cache.tabs", true );
  11978. }
  11979. });
  11980. }});
  11981. },
  11982. _ajaxSettings: function( anchor, event, ui ) {
  11983. var ajaxOptions = this.options.ajaxOptions;
  11984. return $.extend( {}, ajaxOptions, {
  11985. error: function( xhr, s, e ) {
  11986. try {
  11987. // Passing index avoid a race condition when this method is
  11988. // called after the user has selected another tab.
  11989. // Pass the anchor that initiated this request allows
  11990. // loadError to manipulate the tab content panel via $(a.hash)
  11991. ajaxOptions.error(
  11992. xhr, s, ui.tab.closest( "li" ).index(), ui.tab[ 0 ] );
  11993. }
  11994. catch ( e ) {}
  11995. }
  11996. }, this._superApply( arguments ) );
  11997. },
  11998. _setOption: function( key, value ) {
  11999. // reset cache if switching from cached to not cached
  12000. if ( key === "cache" && value === false ) {
  12001. this.anchors.removeData( "cache.tabs" );
  12002. }
  12003. this._super( key, value );
  12004. },
  12005. _destroy: function() {
  12006. this.anchors.removeData( "cache.tabs" );
  12007. this._super();
  12008. },
  12009. url: function( index, url ){
  12010. this.anchors.eq( index ).removeData( "cache.tabs" );
  12011. this._superApply( arguments );
  12012. }
  12013. });
  12014. // abort method
  12015. $.widget( "ui.tabs", $.ui.tabs, {
  12016. abort: function() {
  12017. if ( this.xhr ) {
  12018. this.xhr.abort();
  12019. }
  12020. }
  12021. });
  12022. // spinner
  12023. $.widget( "ui.tabs", $.ui.tabs, {
  12024. options: {
  12025. spinner: "<em>Loading&#8230;</em>"
  12026. },
  12027. _create: function() {
  12028. this._super();
  12029. this._on({
  12030. tabsbeforeload: function( event, ui ) {
  12031. // Don't react to nested tabs or tabs that don't use a spinner
  12032. if ( event.target !== this.element[ 0 ] ||
  12033. !this.options.spinner ) {
  12034. return;
  12035. }
  12036. var span = ui.tab.find( "span" ),
  12037. html = span.html();
  12038. span.html( this.options.spinner );
  12039. ui.jqXHR.complete(function() {
  12040. span.html( html );
  12041. });
  12042. }
  12043. });
  12044. }
  12045. });
  12046. // enable/disable events
  12047. $.widget( "ui.tabs", $.ui.tabs, {
  12048. options: {
  12049. enable: null,
  12050. disable: null
  12051. },
  12052. enable: function( index ) {
  12053. var options = this.options,
  12054. trigger;
  12055. if ( index && options.disabled === true ||
  12056. ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) !== -1 ) ) {
  12057. trigger = true;
  12058. }
  12059. this._superApply( arguments );
  12060. if ( trigger ) {
  12061. this._trigger( "enable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  12062. }
  12063. },
  12064. disable: function( index ) {
  12065. var options = this.options,
  12066. trigger;
  12067. if ( index && options.disabled === false ||
  12068. ( $.isArray( options.disabled ) && $.inArray( index, options.disabled ) === -1 ) ) {
  12069. trigger = true;
  12070. }
  12071. this._superApply( arguments );
  12072. if ( trigger ) {
  12073. this._trigger( "disable", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  12074. }
  12075. }
  12076. });
  12077. // add/remove methods and events
  12078. $.widget( "ui.tabs", $.ui.tabs, {
  12079. options: {
  12080. add: null,
  12081. remove: null,
  12082. tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>"
  12083. },
  12084. add: function( url, label, index ) {
  12085. if ( index === undefined ) {
  12086. index = this.anchors.length;
  12087. }
  12088. var doInsertAfter, panel,
  12089. options = this.options,
  12090. li = $( options.tabTemplate
  12091. .replace( /#\{href\}/g, url )
  12092. .replace( /#\{label\}/g, label ) ),
  12093. id = !url.indexOf( "#" ) ?
  12094. url.replace( "#", "" ) :
  12095. this._tabId( li );
  12096. li.addClass( "ui-state-default ui-corner-top" ).data( "ui-tabs-destroy", true );
  12097. li.attr( "aria-controls", id );
  12098. doInsertAfter = index >= this.tabs.length;
  12099. // try to find an existing element before creating a new one
  12100. panel = this.element.find( "#" + id );
  12101. if ( !panel.length ) {
  12102. panel = this._createPanel( id );
  12103. if ( doInsertAfter ) {
  12104. if ( index > 0 ) {
  12105. panel.insertAfter( this.panels.eq( -1 ) );
  12106. } else {
  12107. panel.appendTo( this.element );
  12108. }
  12109. } else {
  12110. panel.insertBefore( this.panels[ index ] );
  12111. }
  12112. }
  12113. panel.addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" ).hide();
  12114. if ( doInsertAfter ) {
  12115. li.appendTo( this.tablist );
  12116. } else {
  12117. li.insertBefore( this.tabs[ index ] );
  12118. }
  12119. options.disabled = $.map( options.disabled, function( n ) {
  12120. return n >= index ? ++n : n;
  12121. });
  12122. this.refresh();
  12123. if ( this.tabs.length === 1 && options.active === false ) {
  12124. this.option( "active", 0 );
  12125. }
  12126. this._trigger( "add", null, this._ui( this.anchors[ index ], this.panels[ index ] ) );
  12127. return this;
  12128. },
  12129. remove: function( index ) {
  12130. index = this._getIndex( index );
  12131. var options = this.options,
  12132. tab = this.tabs.eq( index ).remove(),
  12133. panel = this._getPanelForTab( tab ).remove();
  12134. // If selected tab was removed focus tab to the right or
  12135. // in case the last tab was removed the tab to the left.
  12136. // We check for more than 2 tabs, because if there are only 2,
  12137. // then when we remove this tab, there will only be one tab left
  12138. // so we don't need to detect which tab to activate.
  12139. if ( tab.hasClass( "ui-tabs-active" ) && this.anchors.length > 2 ) {
  12140. this._activate( index + ( index + 1 < this.anchors.length ? 1 : -1 ) );
  12141. }
  12142. options.disabled = $.map(
  12143. $.grep( options.disabled, function( n ) {
  12144. return n !== index;
  12145. }),
  12146. function( n ) {
  12147. return n >= index ? --n : n;
  12148. });
  12149. this.refresh();
  12150. this._trigger( "remove", null, this._ui( tab.find( "a" )[ 0 ], panel[ 0 ] ) );
  12151. return this;
  12152. }
  12153. });
  12154. // length method
  12155. $.widget( "ui.tabs", $.ui.tabs, {
  12156. length: function() {
  12157. return this.anchors.length;
  12158. }
  12159. });
  12160. // panel ids (idPrefix option + title attribute)
  12161. $.widget( "ui.tabs", $.ui.tabs, {
  12162. options: {
  12163. idPrefix: "ui-tabs-"
  12164. },
  12165. _tabId: function( tab ) {
  12166. var a = tab.is( "li" ) ? tab.find( "a[href]" ) : tab;
  12167. a = a[0];
  12168. return $( a ).closest( "li" ).attr( "aria-controls" ) ||
  12169. a.title && a.title.replace( /\s/g, "_" ).replace( /[^\w\u00c0-\uFFFF\-]/g, "" ) ||
  12170. this.options.idPrefix + getNextTabId();
  12171. }
  12172. });
  12173. // _createPanel method
  12174. $.widget( "ui.tabs", $.ui.tabs, {
  12175. options: {
  12176. panelTemplate: "<div></div>"
  12177. },
  12178. _createPanel: function( id ) {
  12179. return $( this.options.panelTemplate )
  12180. .attr( "id", id )
  12181. .addClass( "ui-tabs-panel ui-widget-content ui-corner-bottom" )
  12182. .data( "ui-tabs-destroy", true );
  12183. }
  12184. });
  12185. // selected option
  12186. $.widget( "ui.tabs", $.ui.tabs, {
  12187. _create: function() {
  12188. var options = this.options;
  12189. if ( options.active === null && options.selected !== undefined ) {
  12190. options.active = options.selected === -1 ? false : options.selected;
  12191. }
  12192. this._super();
  12193. options.selected = options.active;
  12194. if ( options.selected === false ) {
  12195. options.selected = -1;
  12196. }
  12197. },
  12198. _setOption: function( key, value ) {
  12199. if ( key !== "selected" ) {
  12200. return this._super( key, value );
  12201. }
  12202. var options = this.options;
  12203. this._super( "active", value === -1 ? false : value );
  12204. options.selected = options.active;
  12205. if ( options.selected === false ) {
  12206. options.selected = -1;
  12207. }
  12208. },
  12209. _eventHandler: function( event ) {
  12210. this._superApply( arguments );
  12211. this.options.selected = this.options.active;
  12212. if ( this.options.selected === false ) {
  12213. this.options.selected = -1;
  12214. }
  12215. }
  12216. });
  12217. // show and select event
  12218. $.widget( "ui.tabs", $.ui.tabs, {
  12219. options: {
  12220. show: null,
  12221. select: null
  12222. },
  12223. _create: function() {
  12224. this._super();
  12225. if ( this.options.active !== false ) {
  12226. this._trigger( "show", null, this._ui(
  12227. this.active.find( ".ui-tabs-anchor" )[ 0 ],
  12228. this._getPanelForTab( this.active )[ 0 ] ) );
  12229. }
  12230. },
  12231. _trigger: function( type, event, data ) {
  12232. var ret = this._superApply( arguments );
  12233. if ( !ret ) {
  12234. return false;
  12235. }
  12236. if ( type === "beforeActivate" && data.newTab.length ) {
  12237. ret = this._super( "select", event, {
  12238. tab: data.newTab.find( ".ui-tabs-anchor" )[ 0],
  12239. panel: data.newPanel[ 0 ],
  12240. index: data.newTab.closest( "li" ).index()
  12241. });
  12242. } else if ( type === "activate" && data.newTab.length ) {
  12243. ret = this._super( "show", event, {
  12244. tab: data.newTab.find( ".ui-tabs-anchor" )[ 0 ],
  12245. panel: data.newPanel[ 0 ],
  12246. index: data.newTab.closest( "li" ).index()
  12247. });
  12248. }
  12249. return ret;
  12250. }
  12251. });
  12252. // select method
  12253. $.widget( "ui.tabs", $.ui.tabs, {
  12254. select: function( index ) {
  12255. index = this._getIndex( index );
  12256. if ( index === -1 ) {
  12257. if ( this.options.collapsible && this.options.selected !== -1 ) {
  12258. index = this.options.selected;
  12259. } else {
  12260. return;
  12261. }
  12262. }
  12263. this.anchors.eq( index ).trigger( this.options.event + this.eventNamespace );
  12264. }
  12265. });
  12266. // cookie option
  12267. (function() {
  12268. var listId = 0;
  12269. $.widget( "ui.tabs", $.ui.tabs, {
  12270. options: {
  12271. cookie: null // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
  12272. },
  12273. _create: function() {
  12274. var options = this.options,
  12275. active;
  12276. if ( options.active == null && options.cookie ) {
  12277. active = parseInt( this._cookie(), 10 );
  12278. if ( active === -1 ) {
  12279. active = false;
  12280. }
  12281. options.active = active;
  12282. }
  12283. this._super();
  12284. },
  12285. _cookie: function( active ) {
  12286. var cookie = [ this.cookie ||
  12287. ( this.cookie = this.options.cookie.name || "ui-tabs-" + (++listId) ) ];
  12288. if ( arguments.length ) {
  12289. cookie.push( active === false ? -1 : active );
  12290. cookie.push( this.options.cookie );
  12291. }
  12292. return $.cookie.apply( null, cookie );
  12293. },
  12294. _refresh: function() {
  12295. this._super();
  12296. if ( this.options.cookie ) {
  12297. this._cookie( this.options.active, this.options.cookie );
  12298. }
  12299. },
  12300. _eventHandler: function( event ) {
  12301. this._superApply( arguments );
  12302. if ( this.options.cookie ) {
  12303. this._cookie( this.options.active, this.options.cookie );
  12304. }
  12305. },
  12306. _destroy: function() {
  12307. this._super();
  12308. if ( this.options.cookie ) {
  12309. this._cookie( null, this.options.cookie );
  12310. }
  12311. }
  12312. });
  12313. })();
  12314. // load event
  12315. $.widget( "ui.tabs", $.ui.tabs, {
  12316. _trigger: function( type, event, data ) {
  12317. var _data = $.extend( {}, data );
  12318. if ( type === "load" ) {
  12319. _data.panel = _data.panel[ 0 ];
  12320. _data.tab = _data.tab.find( ".ui-tabs-anchor" )[ 0 ];
  12321. }
  12322. return this._super( type, event, _data );
  12323. }
  12324. });
  12325. // fx option
  12326. // The new animation options (show, hide) conflict with the old show callback.
  12327. // The old fx option wins over show/hide anyway (always favor back-compat).
  12328. // If a user wants to use the new animation API, they must give up the old API.
  12329. $.widget( "ui.tabs", $.ui.tabs, {
  12330. options: {
  12331. fx: null // e.g. { height: "toggle", opacity: "toggle", duration: 200 }
  12332. },
  12333. _getFx: function() {
  12334. var hide, show,
  12335. fx = this.options.fx;
  12336. if ( fx ) {
  12337. if ( $.isArray( fx ) ) {
  12338. hide = fx[ 0 ];
  12339. show = fx[ 1 ];
  12340. } else {
  12341. hide = show = fx;
  12342. }
  12343. }
  12344. return fx ? { show: show, hide: hide } : null;
  12345. },
  12346. _toggle: function( event, eventData ) {
  12347. var that = this,
  12348. toShow = eventData.newPanel,
  12349. toHide = eventData.oldPanel,
  12350. fx = this._getFx();
  12351. if ( !fx ) {
  12352. return this._super( event, eventData );
  12353. }
  12354. that.running = true;
  12355. function complete() {
  12356. that.running = false;
  12357. that._trigger( "activate", event, eventData );
  12358. }
  12359. function show() {
  12360. eventData.newTab.closest( "li" ).addClass( "ui-tabs-active ui-state-active" );
  12361. if ( toShow.length && fx.show ) {
  12362. toShow
  12363. .animate( fx.show, fx.show.duration, function() {
  12364. complete();
  12365. });
  12366. } else {
  12367. toShow.show();
  12368. complete();
  12369. }
  12370. }
  12371. // start out by hiding, then showing, then completing
  12372. if ( toHide.length && fx.hide ) {
  12373. toHide.animate( fx.hide, fx.hide.duration, function() {
  12374. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  12375. show();
  12376. });
  12377. } else {
  12378. eventData.oldTab.closest( "li" ).removeClass( "ui-tabs-active ui-state-active" );
  12379. toHide.hide();
  12380. show();
  12381. }
  12382. }
  12383. });
  12384. }
  12385. })( jQuery );
  12386. (function( $ ) {
  12387. var increments = 0;
  12388. function addDescribedBy( elem, id ) {
  12389. var describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ );
  12390. describedby.push( id );
  12391. elem
  12392. .data( "ui-tooltip-id", id )
  12393. .attr( "aria-describedby", $.trim( describedby.join( " " ) ) );
  12394. }
  12395. function removeDescribedBy( elem ) {
  12396. var id = elem.data( "ui-tooltip-id" ),
  12397. describedby = (elem.attr( "aria-describedby" ) || "").split( /\s+/ ),
  12398. index = $.inArray( id, describedby );
  12399. if ( index !== -1 ) {
  12400. describedby.splice( index, 1 );
  12401. }
  12402. elem.removeData( "ui-tooltip-id" );
  12403. describedby = $.trim( describedby.join( " " ) );
  12404. if ( describedby ) {
  12405. elem.attr( "aria-describedby", describedby );
  12406. } else {
  12407. elem.removeAttr( "aria-describedby" );
  12408. }
  12409. }
  12410. $.widget( "ui.tooltip", {
  12411. version: "1.9.0",
  12412. options: {
  12413. content: function() {
  12414. return $( this ).attr( "title" );
  12415. },
  12416. hide: true,
  12417. items: "[title]",
  12418. position: {
  12419. my: "left+15 center",
  12420. at: "right center",
  12421. collision: "flipfit flipfit"
  12422. },
  12423. show: true,
  12424. tooltipClass: null,
  12425. track: false,
  12426. // callbacks
  12427. close: null,
  12428. open: null
  12429. },
  12430. _create: function() {
  12431. this._on({
  12432. mouseover: "open",
  12433. focusin: "open"
  12434. });
  12435. // IDs of generated tooltips, needed for destroy
  12436. this.tooltips = {};
  12437. },
  12438. _setOption: function( key, value ) {
  12439. var that = this;
  12440. if ( key === "disabled" ) {
  12441. this[ value ? "_disable" : "_enable" ]();
  12442. this.options[ key ] = value;
  12443. // disable element style changes
  12444. return;
  12445. }
  12446. this._super( key, value );
  12447. if ( key === "content" ) {
  12448. $.each( this.tooltips, function( id, element ) {
  12449. that._updateContent( element );
  12450. });
  12451. }
  12452. },
  12453. _disable: function() {
  12454. var that = this;
  12455. // close open tooltips
  12456. $.each( this.tooltips, function( id, element ) {
  12457. var event = $.Event( "blur" );
  12458. event.target = event.currentTarget = element[0];
  12459. that.close( event, true );
  12460. });
  12461. // remove title attributes to prevent native tooltips
  12462. this.element.find( this.options.items ).andSelf().each(function() {
  12463. var element = $( this );
  12464. if ( element.is( "[title]" ) ) {
  12465. element
  12466. .data( "ui-tooltip-title", element.attr( "title" ) )
  12467. .attr( "title", "" );
  12468. }
  12469. });
  12470. },
  12471. _enable: function() {
  12472. // restore title attributes
  12473. this.element.find( this.options.items ).andSelf().each(function() {
  12474. var element = $( this );
  12475. if ( element.data( "ui-tooltip-title" ) ) {
  12476. element.attr( "title", element.data( "ui-tooltip-title" ) );
  12477. }
  12478. });
  12479. },
  12480. open: function( event ) {
  12481. var target = $( event ? event.target : this.element )
  12482. .closest( this.options.items );
  12483. // No element to show a tooltip for
  12484. if ( !target.length ) {
  12485. return;
  12486. }
  12487. // If the tooltip is open and we're tracking then reposition the tooltip.
  12488. // This makes sure that a tracking tooltip doesn't obscure a focused element
  12489. // if the user was hovering when the element gained focused.
  12490. if ( this.options.track && target.data( "ui-tooltip-id" ) ) {
  12491. this._find( target ).position( $.extend({
  12492. of: target
  12493. }, this.options.position ) );
  12494. // Stop tracking (#8622)
  12495. this._off( this.document, "mousemove" );
  12496. return;
  12497. }
  12498. if ( target.attr( "title" ) ) {
  12499. target.data( "ui-tooltip-title", target.attr( "title" ) );
  12500. }
  12501. target.data( "tooltip-open", true );
  12502. this._updateContent( target, event );
  12503. },
  12504. _updateContent: function( target, event ) {
  12505. var content,
  12506. contentOption = this.options.content,
  12507. that = this;
  12508. if ( typeof contentOption === "string" ) {
  12509. return this._open( event, target, contentOption );
  12510. }
  12511. content = contentOption.call( target[0], function( response ) {
  12512. // ignore async response if tooltip was closed already
  12513. if ( !target.data( "tooltip-open" ) ) {
  12514. return;
  12515. }
  12516. // IE may instantly serve a cached response for ajax requests
  12517. // delay this call to _open so the other call to _open runs first
  12518. that._delay(function() {
  12519. this._open( event, target, response );
  12520. });
  12521. });
  12522. if ( content ) {
  12523. this._open( event, target, content );
  12524. }
  12525. },
  12526. _open: function( event, target, content ) {
  12527. var tooltip, positionOption;
  12528. if ( !content ) {
  12529. return;
  12530. }
  12531. // Content can be updated multiple times. If the tooltip already
  12532. // exists, then just update the content and bail.
  12533. tooltip = this._find( target );
  12534. if ( tooltip.length ) {
  12535. tooltip.find( ".ui-tooltip-content" ).html( content );
  12536. return;
  12537. }
  12538. // if we have a title, clear it to prevent the native tooltip
  12539. // we have to check first to avoid defining a title if none exists
  12540. // (we don't want to cause an element to start matching [title])
  12541. //
  12542. // We use removeAttr only for key events, to allow IE to export the correct
  12543. // accessible attributes. For mouse events, set to empty string to avoid
  12544. // native tooltip showing up (happens only when removing inside mouseover).
  12545. if ( target.is( "[title]" ) ) {
  12546. if ( event && event.type === "mouseover" ) {
  12547. target.attr( "title", "" );
  12548. } else {
  12549. target.removeAttr( "title" );
  12550. }
  12551. }
  12552. tooltip = this._tooltip( target );
  12553. addDescribedBy( target, tooltip.attr( "id" ) );
  12554. tooltip.find( ".ui-tooltip-content" ).html( content );
  12555. function position( event ) {
  12556. positionOption.of = event;
  12557. tooltip.position( positionOption );
  12558. }
  12559. if ( this.options.track && event && /^mouse/.test( event.originalEvent.type ) ) {
  12560. positionOption = $.extend( {}, this.options.position );
  12561. this._on( this.document, {
  12562. mousemove: position
  12563. });
  12564. // trigger once to override element-relative positioning
  12565. position( event );
  12566. } else {
  12567. tooltip.position( $.extend({
  12568. of: target
  12569. }, this.options.position ) );
  12570. }
  12571. tooltip.hide();
  12572. this._show( tooltip, this.options.show );
  12573. this._trigger( "open", event, { tooltip: tooltip } );
  12574. this._on( target, {
  12575. mouseleave: "close",
  12576. focusout: "close",
  12577. keyup: function( event ) {
  12578. if ( event.keyCode === $.ui.keyCode.ESCAPE ) {
  12579. var fakeEvent = $.Event(event);
  12580. fakeEvent.currentTarget = target[0];
  12581. this.close( fakeEvent, true );
  12582. }
  12583. }
  12584. });
  12585. },
  12586. close: function( event, force ) {
  12587. var that = this,
  12588. target = $( event ? event.currentTarget : this.element ),
  12589. tooltip = this._find( target );
  12590. // disabling closes the tooltip, so we need to track when we're closing
  12591. // to avoid an infinite loop in case the tooltip becomes disabled on close
  12592. if ( this.closing ) {
  12593. return;
  12594. }
  12595. // don't close if the element has focus
  12596. // this prevents the tooltip from closing if you hover while focused
  12597. //
  12598. // we have to check the event type because tabbing out of the document
  12599. // may leave the element as the activeElement
  12600. if ( !force && event && event.type !== "focusout" &&
  12601. this.document[0].activeElement === target[0] ) {
  12602. return;
  12603. }
  12604. // only set title if we had one before (see comment in _open())
  12605. if ( target.data( "ui-tooltip-title" ) ) {
  12606. target.attr( "title", target.data( "ui-tooltip-title" ) );
  12607. }
  12608. removeDescribedBy( target );
  12609. tooltip.stop( true );
  12610. this._hide( tooltip, this.options.hide, function() {
  12611. $( this ).remove();
  12612. delete that.tooltips[ this.id ];
  12613. });
  12614. target.removeData( "tooltip-open" );
  12615. this._off( target, "mouseleave focusout keyup" );
  12616. this._off( this.document, "mousemove" );
  12617. this.closing = true;
  12618. this._trigger( "close", event, { tooltip: tooltip } );
  12619. this.closing = false;
  12620. },
  12621. _tooltip: function( element ) {
  12622. var id = "ui-tooltip-" + increments++,
  12623. tooltip = $( "<div>" )
  12624. .attr({
  12625. id: id,
  12626. role: "tooltip"
  12627. })
  12628. .addClass( "ui-tooltip ui-widget ui-corner-all ui-widget-content " +
  12629. ( this.options.tooltipClass || "" ) );
  12630. $( "<div>" )
  12631. .addClass( "ui-tooltip-content" )
  12632. .appendTo( tooltip );
  12633. tooltip.appendTo( this.document[0].body );
  12634. if ( $.fn.bgiframe ) {
  12635. tooltip.bgiframe();
  12636. }
  12637. this.tooltips[ id ] = element;
  12638. return tooltip;
  12639. },
  12640. _find: function( target ) {
  12641. var id = target.data( "ui-tooltip-id" );
  12642. return id ? $( "#" + id ) : $();
  12643. },
  12644. _destroy: function() {
  12645. var that = this;
  12646. // close open tooltips
  12647. $.each( this.tooltips, function( id, element ) {
  12648. // Delegate to close method to handle common cleanup
  12649. var event = $.Event( "blur" );
  12650. event.target = event.currentTarget = element[0];
  12651. that.close( event, true );
  12652. // Remove immediately; destroying an open tooltip doesn't use the
  12653. // hide animation
  12654. $( "#" + id ).remove();
  12655. // Restore the title
  12656. if ( element.data( "ui-tooltip-title" ) ) {
  12657. element.attr( "title", element.data( "ui-tooltip-title" ) );
  12658. element.removeData( "ui-tooltip-title" );
  12659. }
  12660. });
  12661. }
  12662. });
  12663. }( jQuery ) );