/Scripts/jquery-ui-1.9.2.js

https://bitbucket.org/parivedasolutions/attributeroutingtest · JavaScript · 14912 lines · 11965 code · 1895 blank · 1052 comment · 2559 complexity · 42417a1984f6f113247bb13a09a26542 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*! jQuery UI - v1.9.2 - 2012-11-23
  2. * http://jqueryui.com
  3. * Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.draggable.js, jquery.ui.droppable.js, jquery.ui.resizable.js, jquery.ui.selectable.js, jquery.ui.sortable.js, jquery.ui.effect.js, jquery.ui.accordion.js, jquery.ui.autocomplete.js, jquery.ui.button.js, jquery.ui.datepicker.js, jquery.ui.dialog.js, jquery.ui.effect-blind.js, jquery.ui.effect-bounce.js, jquery.ui.effect-clip.js, jquery.ui.effect-drop.js, jquery.ui.effect-explode.js, jquery.ui.effect-fade.js, jquery.ui.effect-fold.js, jquery.ui.effect-highlight.js, jquery.ui.effect-pulsate.js, jquery.ui.effect-scale.js, jquery.ui.effect-shake.js, jquery.ui.effect-slide.js, jquery.ui.effect-transfer.js, jquery.ui.menu.js, jquery.ui.position.js, jquery.ui.progressbar.js, jquery.ui.slider.js, jquery.ui.spinner.js, jquery.ui.tabs.js, jquery.ui.tooltip.js
  4. * Copyright 2012 jQuery Foundation and other contributors; Licensed MIT */
  5. (function( $, undefined ) {
  6. var uuid = 0,
  7. runiqueId = /^ui-id-\d+$/;
  8. // prevent duplicate loading
  9. // this is only a problem because we proxy existing functions
  10. // and we don't want to double proxy them
  11. $.ui = $.ui || {};
  12. if ( $.ui.version ) {
  13. return;
  14. }
  15. $.extend( $.ui, {
  16. version: "1.9.2",
  17. keyCode: {
  18. BACKSPACE: 8,
  19. COMMA: 188,
  20. DELETE: 46,
  21. DOWN: 40,
  22. END: 35,
  23. ENTER: 13,
  24. ESCAPE: 27,
  25. HOME: 36,
  26. LEFT: 37,
  27. NUMPAD_ADD: 107,
  28. NUMPAD_DECIMAL: 110,
  29. NUMPAD_DIVIDE: 111,
  30. NUMPAD_ENTER: 108,
  31. NUMPAD_MULTIPLY: 106,
  32. NUMPAD_SUBTRACT: 109,
  33. PAGE_DOWN: 34,
  34. PAGE_UP: 33,
  35. PERIOD: 190,
  36. RIGHT: 39,
  37. SPACE: 32,
  38. TAB: 9,
  39. UP: 38
  40. }
  41. });
  42. // plugins
  43. $.fn.extend({
  44. _focus: $.fn.focus,
  45. focus: function( delay, fn ) {
  46. return typeof delay === "number" ?
  47. this.each(function() {
  48. var elem = this;
  49. setTimeout(function() {
  50. $( elem ).focus();
  51. if ( fn ) {
  52. fn.call( elem );
  53. }
  54. }, delay );
  55. }) :
  56. this._focus.apply( this, arguments );
  57. },
  58. scrollParent: function() {
  59. var scrollParent;
  60. if (($.ui.ie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
  61. scrollParent = this.parents().filter(function() {
  62. return (/(relative|absolute|fixed)/).test($.css(this,'position')) && (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x'));
  63. }).eq(0);
  64. } else {
  65. scrollParent = this.parents().filter(function() {
  66. return (/(auto|scroll)/).test($.css(this,'overflow')+$.css(this,'overflow-y')+$.css(this,'overflow-x'));
  67. }).eq(0);
  68. }
  69. return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
  70. },
  71. zIndex: function( zIndex ) {
  72. if ( zIndex !== undefined ) {
  73. return this.css( "zIndex", zIndex );
  74. }
  75. if ( this.length ) {
  76. var elem = $( this[ 0 ] ), position, value;
  77. while ( elem.length && elem[ 0 ] !== document ) {
  78. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  79. // This makes behavior of this function consistent across browsers
  80. // WebKit always returns auto if the element is positioned
  81. position = elem.css( "position" );
  82. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  83. // IE returns 0 when zIndex is not specified
  84. // other browsers return a string
  85. // we ignore the case of nested elements with an explicit value of 0
  86. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  87. value = parseInt( elem.css( "zIndex" ), 10 );
  88. if ( !isNaN( value ) && value !== 0 ) {
  89. return value;
  90. }
  91. }
  92. elem = elem.parent();
  93. }
  94. }
  95. return 0;
  96. },
  97. uniqueId: function() {
  98. return this.each(function() {
  99. if ( !this.id ) {
  100. this.id = "ui-id-" + (++uuid);
  101. }
  102. });
  103. },
  104. removeUniqueId: function() {
  105. return this.each(function() {
  106. if ( runiqueId.test( this.id ) ) {
  107. $( this ).removeAttr( "id" );
  108. }
  109. });
  110. }
  111. });
  112. // selectors
  113. function focusable( element, isTabIndexNotNaN ) {
  114. var map, mapName, img,
  115. nodeName = element.nodeName.toLowerCase();
  116. if ( "area" === nodeName ) {
  117. map = element.parentNode;
  118. mapName = map.name;
  119. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  120. return false;
  121. }
  122. img = $( "img[usemap=#" + mapName + "]" )[0];
  123. return !!img && visible( img );
  124. }
  125. return ( /input|select|textarea|button|object/.test( nodeName ) ?
  126. !element.disabled :
  127. "a" === nodeName ?
  128. element.href || isTabIndexNotNaN :
  129. isTabIndexNotNaN) &&
  130. // the element and all of its ancestors must be visible
  131. visible( element );
  132. }
  133. function visible( element ) {
  134. return $.expr.filters.visible( element ) &&
  135. !$( element ).parents().andSelf().filter(function() {
  136. return $.css( this, "visibility" ) === "hidden";
  137. }).length;
  138. }
  139. $.extend( $.expr[ ":" ], {
  140. data: $.expr.createPseudo ?
  141. $.expr.createPseudo(function( dataName ) {
  142. return function( elem ) {
  143. return !!$.data( elem, dataName );
  144. };
  145. }) :
  146. // support: jQuery <1.8
  147. function( elem, i, match ) {
  148. return !!$.data( elem, match[ 3 ] );
  149. },
  150. focusable: function( element ) {
  151. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  152. },
  153. tabbable: function( element ) {
  154. var tabIndex = $.attr( element, "tabindex" ),
  155. isTabIndexNaN = isNaN( tabIndex );
  156. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  157. }
  158. });
  159. // support
  160. $(function() {
  161. var body = document.body,
  162. div = body.appendChild( div = document.createElement( "div" ) );
  163. // access offsetHeight before setting the style to prevent a layout bug
  164. // in IE 9 which causes the element to continue to take up space even
  165. // after it is removed from the DOM (#8026)
  166. div.offsetHeight;
  167. $.extend( div.style, {
  168. minHeight: "100px",
  169. height: "auto",
  170. padding: 0,
  171. borderWidth: 0
  172. });
  173. $.support.minHeight = div.offsetHeight === 100;
  174. $.support.selectstart = "onselectstart" in div;
  175. // set display to none to avoid a layout bug in IE
  176. // http://dev.jquery.com/ticket/4014
  177. body.removeChild( div ).style.display = "none";
  178. });
  179. // support: jQuery <1.8
  180. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  181. $.each( [ "Width", "Height" ], function( i, name ) {
  182. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  183. type = name.toLowerCase(),
  184. orig = {
  185. innerWidth: $.fn.innerWidth,
  186. innerHeight: $.fn.innerHeight,
  187. outerWidth: $.fn.outerWidth,
  188. outerHeight: $.fn.outerHeight
  189. };
  190. function reduce( elem, size, border, margin ) {
  191. $.each( side, function() {
  192. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  193. if ( border ) {
  194. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  195. }
  196. if ( margin ) {
  197. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  198. }
  199. });
  200. return size;
  201. }
  202. $.fn[ "inner" + name ] = function( size ) {
  203. if ( size === undefined ) {
  204. return orig[ "inner" + name ].call( this );
  205. }
  206. return this.each(function() {
  207. $( this ).css( type, reduce( this, size ) + "px" );
  208. });
  209. };
  210. $.fn[ "outer" + name] = function( size, margin ) {
  211. if ( typeof size !== "number" ) {
  212. return orig[ "outer" + name ].call( this, size );
  213. }
  214. return this.each(function() {
  215. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  216. });
  217. };
  218. });
  219. }
  220. // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
  221. if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
  222. $.fn.removeData = (function( removeData ) {
  223. return function( key ) {
  224. if ( arguments.length ) {
  225. return removeData.call( this, $.camelCase( key ) );
  226. } else {
  227. return removeData.call( this );
  228. }
  229. };
  230. })( $.fn.removeData );
  231. }
  232. // deprecated
  233. (function() {
  234. var uaMatch = /msie ([\w.]+)/.exec( navigator.userAgent.toLowerCase() ) || [];
  235. $.ui.ie = uaMatch.length ? true : false;
  236. $.ui.ie6 = parseFloat( uaMatch[ 1 ], 10 ) === 6;
  237. })();
  238. $.fn.extend({
  239. disableSelection: function() {
  240. return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
  241. ".ui-disableSelection", function( event ) {
  242. event.preventDefault();
  243. });
  244. },
  245. enableSelection: function() {
  246. return this.unbind( ".ui-disableSelection" );
  247. }
  248. });
  249. $.extend( $.ui, {
  250. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  251. plugin: {
  252. add: function( module, option, set ) {
  253. var i,
  254. proto = $.ui[ module ].prototype;
  255. for ( i in set ) {
  256. proto.plugins[ i ] = proto.plugins[ i ] || [];
  257. proto.plugins[ i ].push( [ option, set[ i ] ] );
  258. }
  259. },
  260. call: function( instance, name, args ) {
  261. var i,
  262. set = instance.plugins[ name ];
  263. if ( !set || !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) {
  264. return;
  265. }
  266. for ( i = 0; i < set.length; i++ ) {
  267. if ( instance.options[ set[ i ][ 0 ] ] ) {
  268. set[ i ][ 1 ].apply( instance.element, args );
  269. }
  270. }
  271. }
  272. },
  273. contains: $.contains,
  274. // only used by resizable
  275. hasScroll: function( el, a ) {
  276. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  277. if ( $( el ).css( "overflow" ) === "hidden") {
  278. return false;
  279. }
  280. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  281. has = false;
  282. if ( el[ scroll ] > 0 ) {
  283. return true;
  284. }
  285. // TODO: determine which cases actually cause this to happen
  286. // if the element doesn't have the scroll set, see if it's possible to
  287. // set the scroll
  288. el[ scroll ] = 1;
  289. has = ( el[ scroll ] > 0 );
  290. el[ scroll ] = 0;
  291. return has;
  292. },
  293. // these are odd functions, fix the API or move into individual plugins
  294. isOverAxis: function( x, reference, size ) {
  295. //Determines when x coordinate is over "b" element axis
  296. return ( x > reference ) && ( x < ( reference + size ) );
  297. },
  298. isOver: function( y, x, top, left, height, width ) {
  299. //Determines when x, y coordinates is over "b" element
  300. return $.ui.isOverAxis( y, top, height ) && $.ui.isOverAxis( x, left, width );
  301. }
  302. });
  303. })( jQuery );
  304. (function( $, undefined ) {
  305. var uuid = 0,
  306. slice = Array.prototype.slice,
  307. _cleanData = $.cleanData;
  308. $.cleanData = function( elems ) {
  309. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  310. try {
  311. $( elem ).triggerHandler( "remove" );
  312. // http://bugs.jquery.com/ticket/8235
  313. } catch( e ) {}
  314. }
  315. _cleanData( elems );
  316. };
  317. $.widget = function( name, base, prototype ) {
  318. var fullName, existingConstructor, constructor, basePrototype,
  319. namespace = name.split( "." )[ 0 ];
  320. name = name.split( "." )[ 1 ];
  321. fullName = namespace + "-" + name;
  322. if ( !prototype ) {
  323. prototype = base;
  324. base = $.Widget;
  325. }
  326. // create selector for plugin
  327. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  328. return !!$.data( elem, fullName );
  329. };
  330. $[ namespace ] = $[ namespace ] || {};
  331. existingConstructor = $[ namespace ][ name ];
  332. constructor = $[ namespace ][ name ] = function( options, element ) {
  333. // allow instantiation without "new" keyword
  334. if ( !this._createWidget ) {
  335. return new constructor( options, element );
  336. }
  337. // allow instantiation without initializing for simple inheritance
  338. // must use "new" keyword (the code above always passes args)
  339. if ( arguments.length ) {
  340. this._createWidget( options, element );
  341. }
  342. };
  343. // extend with the existing constructor to carry over any static properties
  344. $.extend( constructor, existingConstructor, {
  345. version: prototype.version,
  346. // copy the object used to create the prototype in case we need to
  347. // redefine the widget later
  348. _proto: $.extend( {}, prototype ),
  349. // track widgets that inherit from this widget in case this widget is
  350. // redefined after a widget inherits from it
  351. _childConstructors: []
  352. });
  353. basePrototype = new base();
  354. // we need to make the options hash a property directly on the new instance
  355. // otherwise we'll modify the options hash on the prototype that we're
  356. // inheriting from
  357. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  358. $.each( prototype, function( prop, value ) {
  359. if ( $.isFunction( value ) ) {
  360. prototype[ prop ] = (function() {
  361. var _super = function() {
  362. return base.prototype[ prop ].apply( this, arguments );
  363. },
  364. _superApply = function( args ) {
  365. return base.prototype[ prop ].apply( this, args );
  366. };
  367. return function() {
  368. var __super = this._super,
  369. __superApply = this._superApply,
  370. returnValue;
  371. this._super = _super;
  372. this._superApply = _superApply;
  373. returnValue = value.apply( this, arguments );
  374. this._super = __super;
  375. this._superApply = __superApply;
  376. return returnValue;
  377. };
  378. })();
  379. }
  380. });
  381. constructor.prototype = $.widget.extend( basePrototype, {
  382. // TODO: remove support for widgetEventPrefix
  383. // always use the name + a colon as the prefix, e.g., draggable:start
  384. // don't prefix for widgets that aren't DOM-based
  385. widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name
  386. }, prototype, {
  387. constructor: constructor,
  388. namespace: namespace,
  389. widgetName: name,
  390. // TODO remove widgetBaseClass, see #8155
  391. widgetBaseClass: fullName,
  392. widgetFullName: fullName
  393. });
  394. // If this widget is being redefined then we need to find all widgets that
  395. // are inheriting from it and redefine all of them so that they inherit from
  396. // the new version of this widget. We're essentially trying to replace one
  397. // level in the prototype chain.
  398. if ( existingConstructor ) {
  399. $.each( existingConstructor._childConstructors, function( i, child ) {
  400. var childPrototype = child.prototype;
  401. // redefine the child widget using the same prototype that was
  402. // originally used, but inherit from the new version of the base
  403. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
  404. });
  405. // remove the list of existing child constructors from the old constructor
  406. // so the old child constructors can be garbage collected
  407. delete existingConstructor._childConstructors;
  408. } else {
  409. base._childConstructors.push( constructor );
  410. }
  411. $.widget.bridge( name, constructor );
  412. };
  413. $.widget.extend = function( target ) {
  414. var input = slice.call( arguments, 1 ),
  415. inputIndex = 0,
  416. inputLength = input.length,
  417. key,
  418. value;
  419. for ( ; inputIndex < inputLength; inputIndex++ ) {
  420. for ( key in input[ inputIndex ] ) {
  421. value = input[ inputIndex ][ key ];
  422. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  423. // Clone objects
  424. if ( $.isPlainObject( value ) ) {
  425. target[ key ] = $.isPlainObject( target[ key ] ) ?
  426. $.widget.extend( {}, target[ key ], value ) :
  427. // Don't extend strings, arrays, etc. with objects
  428. $.widget.extend( {}, value );
  429. // Copy everything else by reference
  430. } else {
  431. target[ key ] = value;
  432. }
  433. }
  434. }
  435. }
  436. return target;
  437. };
  438. $.widget.bridge = function( name, object ) {
  439. var fullName = object.prototype.widgetFullName || name;
  440. $.fn[ name ] = function( options ) {
  441. var isMethodCall = typeof options === "string",
  442. args = slice.call( arguments, 1 ),
  443. returnValue = this;
  444. // allow multiple hashes to be passed on init
  445. options = !isMethodCall && args.length ?
  446. $.widget.extend.apply( null, [ options ].concat(args) ) :
  447. options;
  448. if ( isMethodCall ) {
  449. this.each(function() {
  450. var methodValue,
  451. instance = $.data( this, fullName );
  452. if ( !instance ) {
  453. return $.error( "cannot call methods on " + name + " prior to initialization; " +
  454. "attempted to call method '" + options + "'" );
  455. }
  456. if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
  457. return $.error( "no such method '" + options + "' for " + name + " widget instance" );
  458. }
  459. methodValue = instance[ options ].apply( instance, args );
  460. if ( methodValue !== instance && methodValue !== undefined ) {
  461. returnValue = methodValue && methodValue.jquery ?
  462. returnValue.pushStack( methodValue.get() ) :
  463. methodValue;
  464. return false;
  465. }
  466. });
  467. } else {
  468. this.each(function() {
  469. var instance = $.data( this, fullName );
  470. if ( instance ) {
  471. instance.option( options || {} )._init();
  472. } else {
  473. $.data( this, fullName, new object( options, this ) );
  474. }
  475. });
  476. }
  477. return returnValue;
  478. };
  479. };
  480. $.Widget = function( /* options, element */ ) {};
  481. $.Widget._childConstructors = [];
  482. $.Widget.prototype = {
  483. widgetName: "widget",
  484. widgetEventPrefix: "",
  485. defaultElement: "<div>",
  486. options: {
  487. disabled: false,
  488. // callbacks
  489. create: null
  490. },
  491. _createWidget: function( options, element ) {
  492. element = $( element || this.defaultElement || this )[ 0 ];
  493. this.element = $( element );
  494. this.uuid = uuid++;
  495. this.eventNamespace = "." + this.widgetName + this.uuid;
  496. this.options = $.widget.extend( {},
  497. this.options,
  498. this._getCreateOptions(),
  499. options );
  500. this.bindings = $();
  501. this.hoverable = $();
  502. this.focusable = $();
  503. if ( element !== this ) {
  504. // 1.9 BC for #7810
  505. // TODO remove dual storage
  506. $.data( element, this.widgetName, this );
  507. $.data( element, this.widgetFullName, this );
  508. this._on( true, this.element, {
  509. remove: function( event ) {
  510. if ( event.target === element ) {
  511. this.destroy();
  512. }
  513. }
  514. });
  515. this.document = $( element.style ?
  516. // element within the document
  517. element.ownerDocument :
  518. // element is window or document
  519. element.document || element );
  520. this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
  521. }
  522. this._create();
  523. this._trigger( "create", null, this._getCreateEventData() );
  524. this._init();
  525. },
  526. _getCreateOptions: $.noop,
  527. _getCreateEventData: $.noop,
  528. _create: $.noop,
  529. _init: $.noop,
  530. destroy: function() {
  531. this._destroy();
  532. // we can probably remove the unbind calls in 2.0
  533. // all event bindings should go through this._on()
  534. this.element
  535. .unbind( this.eventNamespace )
  536. // 1.9 BC for #7810
  537. // TODO remove dual storage
  538. .removeData( this.widgetName )
  539. .removeData( this.widgetFullName )
  540. // support: jquery <1.6.3
  541. // http://bugs.jquery.com/ticket/9413
  542. .removeData( $.camelCase( this.widgetFullName ) );
  543. this.widget()
  544. .unbind( this.eventNamespace )
  545. .removeAttr( "aria-disabled" )
  546. .removeClass(
  547. this.widgetFullName + "-disabled " +
  548. "ui-state-disabled" );
  549. // clean up events and states
  550. this.bindings.unbind( this.eventNamespace );
  551. this.hoverable.removeClass( "ui-state-hover" );
  552. this.focusable.removeClass( "ui-state-focus" );
  553. },
  554. _destroy: $.noop,
  555. widget: function() {
  556. return this.element;
  557. },
  558. option: function( key, value ) {
  559. var options = key,
  560. parts,
  561. curOption,
  562. i;
  563. if ( arguments.length === 0 ) {
  564. // don't return a reference to the internal hash
  565. return $.widget.extend( {}, this.options );
  566. }
  567. if ( typeof key === "string" ) {
  568. // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  569. options = {};
  570. parts = key.split( "." );
  571. key = parts.shift();
  572. if ( parts.length ) {
  573. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  574. for ( i = 0; i < parts.length - 1; i++ ) {
  575. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  576. curOption = curOption[ parts[ i ] ];
  577. }
  578. key = parts.pop();
  579. if ( value === undefined ) {
  580. return curOption[ key ] === undefined ? null : curOption[ key ];
  581. }
  582. curOption[ key ] = value;
  583. } else {
  584. if ( value === undefined ) {
  585. return this.options[ key ] === undefined ? null : this.options[ key ];
  586. }
  587. options[ key ] = value;
  588. }
  589. }
  590. this._setOptions( options );
  591. return this;
  592. },
  593. _setOptions: function( options ) {
  594. var key;
  595. for ( key in options ) {
  596. this._setOption( key, options[ key ] );
  597. }
  598. return this;
  599. },
  600. _setOption: function( key, value ) {
  601. this.options[ key ] = value;
  602. if ( key === "disabled" ) {
  603. this.widget()
  604. .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
  605. .attr( "aria-disabled", value );
  606. this.hoverable.removeClass( "ui-state-hover" );
  607. this.focusable.removeClass( "ui-state-focus" );
  608. }
  609. return this;
  610. },
  611. enable: function() {
  612. return this._setOption( "disabled", false );
  613. },
  614. disable: function() {
  615. return this._setOption( "disabled", true );
  616. },
  617. _on: function( suppressDisabledCheck, element, handlers ) {
  618. var delegateElement,
  619. instance = this;
  620. // no suppressDisabledCheck flag, shuffle arguments
  621. if ( typeof suppressDisabledCheck !== "boolean" ) {
  622. handlers = element;
  623. element = suppressDisabledCheck;
  624. suppressDisabledCheck = false;
  625. }
  626. // no element argument, shuffle and use this.element
  627. if ( !handlers ) {
  628. handlers = element;
  629. element = this.element;
  630. delegateElement = this.widget();
  631. } else {
  632. // accept selectors, DOM elements
  633. element = delegateElement = $( element );
  634. this.bindings = this.bindings.add( element );
  635. }
  636. $.each( handlers, function( event, handler ) {
  637. function handlerProxy() {
  638. // allow widgets to customize the disabled handling
  639. // - disabled as an array instead of boolean
  640. // - disabled class as method for disabling individual parts
  641. if ( !suppressDisabledCheck &&
  642. ( instance.options.disabled === true ||
  643. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  644. return;
  645. }
  646. return ( typeof handler === "string" ? instance[ handler ] : handler )
  647. .apply( instance, arguments );
  648. }
  649. // copy the guid so direct unbinding works
  650. if ( typeof handler !== "string" ) {
  651. handlerProxy.guid = handler.guid =
  652. handler.guid || handlerProxy.guid || $.guid++;
  653. }
  654. var match = event.match( /^(\w+)\s*(.*)$/ ),
  655. eventName = match[1] + instance.eventNamespace,
  656. selector = match[2];
  657. if ( selector ) {
  658. delegateElement.delegate( selector, eventName, handlerProxy );
  659. } else {
  660. element.bind( eventName, handlerProxy );
  661. }
  662. });
  663. },
  664. _off: function( element, eventName ) {
  665. eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
  666. element.unbind( eventName ).undelegate( eventName );
  667. },
  668. _delay: function( handler, delay ) {
  669. function handlerProxy() {
  670. return ( typeof handler === "string" ? instance[ handler ] : handler )
  671. .apply( instance, arguments );
  672. }
  673. var instance = this;
  674. return setTimeout( handlerProxy, delay || 0 );
  675. },
  676. _hoverable: function( element ) {
  677. this.hoverable = this.hoverable.add( element );
  678. this._on( element, {
  679. mouseenter: function( event ) {
  680. $( event.currentTarget ).addClass( "ui-state-hover" );
  681. },
  682. mouseleave: function( event ) {
  683. $( event.currentTarget ).removeClass( "ui-state-hover" );
  684. }
  685. });
  686. },
  687. _focusable: function( element ) {
  688. this.focusable = this.focusable.add( element );
  689. this._on( element, {
  690. focusin: function( event ) {
  691. $( event.currentTarget ).addClass( "ui-state-focus" );
  692. },
  693. focusout: function( event ) {
  694. $( event.currentTarget ).removeClass( "ui-state-focus" );
  695. }
  696. });
  697. },
  698. _trigger: function( type, event, data ) {
  699. var prop, orig,
  700. callback = this.options[ type ];
  701. data = data || {};
  702. event = $.Event( event );
  703. event.type = ( type === this.widgetEventPrefix ?
  704. type :
  705. this.widgetEventPrefix + type ).toLowerCase();
  706. // the original event may come from any element
  707. // so we need to reset the target on the new event
  708. event.target = this.element[ 0 ];
  709. // copy original event properties over to the new event
  710. orig = event.originalEvent;
  711. if ( orig ) {
  712. for ( prop in orig ) {
  713. if ( !( prop in event ) ) {
  714. event[ prop ] = orig[ prop ];
  715. }
  716. }
  717. }
  718. this.element.trigger( event, data );
  719. return !( $.isFunction( callback ) &&
  720. callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
  721. event.isDefaultPrevented() );
  722. }
  723. };
  724. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  725. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  726. if ( typeof options === "string" ) {
  727. options = { effect: options };
  728. }
  729. var hasOptions,
  730. effectName = !options ?
  731. method :
  732. options === true || typeof options === "number" ?
  733. defaultEffect :
  734. options.effect || defaultEffect;
  735. options = options || {};
  736. if ( typeof options === "number" ) {
  737. options = { duration: options };
  738. }
  739. hasOptions = !$.isEmptyObject( options );
  740. options.complete = callback;
  741. if ( options.delay ) {
  742. element.delay( options.delay );
  743. }
  744. if ( hasOptions && $.effects && ( $.effects.effect[ effectName ] || $.uiBackCompat !== false && $.effects[ effectName ] ) ) {
  745. element[ method ]( options );
  746. } else if ( effectName !== method && element[ effectName ] ) {
  747. element[ effectName ]( options.duration, options.easing, callback );
  748. } else {
  749. element.queue(function( next ) {
  750. $( this )[ method ]();
  751. if ( callback ) {
  752. callback.call( element[ 0 ] );
  753. }
  754. next();
  755. });
  756. }
  757. };
  758. });
  759. // DEPRECATED
  760. if ( $.uiBackCompat !== false ) {
  761. $.Widget.prototype._getCreateOptions = function() {
  762. return $.metadata && $.metadata.get( this.element[0] )[ this.widgetName ];
  763. };
  764. }
  765. })( jQuery );
  766. (function( $, undefined ) {
  767. var mouseHandled = false;
  768. $( document ).mouseup( function( e ) {
  769. mouseHandled = false;
  770. });
  771. $.widget("ui.mouse", {
  772. version: "1.9.2",
  773. options: {
  774. cancel: 'input,textarea,button,select,option',
  775. distance: 1,
  776. delay: 0
  777. },
  778. _mouseInit: function() {
  779. var that = this;
  780. this.element
  781. .bind('mousedown.'+this.widgetName, function(event) {
  782. return that._mouseDown(event);
  783. })
  784. .bind('click.'+this.widgetName, function(event) {
  785. if (true === $.data(event.target, that.widgetName + '.preventClickEvent')) {
  786. $.removeData(event.target, that.widgetName + '.preventClickEvent');
  787. event.stopImmediatePropagation();
  788. return false;
  789. }
  790. });
  791. this.started = false;
  792. },
  793. // TODO: make sure destroying one instance of mouse doesn't mess with
  794. // other instances of mouse
  795. _mouseDestroy: function() {
  796. this.element.unbind('.'+this.widgetName);
  797. if ( this._mouseMoveDelegate ) {
  798. $(document)
  799. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  800. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  801. }
  802. },
  803. _mouseDown: function(event) {
  804. // don't let more than one widget handle mouseStart
  805. if( mouseHandled ) { return; }
  806. // we may have missed mouseup (out of window)
  807. (this._mouseStarted && this._mouseUp(event));
  808. this._mouseDownEvent = event;
  809. var that = this,
  810. btnIsLeft = (event.which === 1),
  811. // event.target.nodeName works around a bug in IE 8 with
  812. // disabled inputs (#7620)
  813. elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
  814. if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
  815. return true;
  816. }
  817. this.mouseDelayMet = !this.options.delay;
  818. if (!this.mouseDelayMet) {
  819. this._mouseDelayTimer = setTimeout(function() {
  820. that.mouseDelayMet = true;
  821. }, this.options.delay);
  822. }
  823. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  824. this._mouseStarted = (this._mouseStart(event) !== false);
  825. if (!this._mouseStarted) {
  826. event.preventDefault();
  827. return true;
  828. }
  829. }
  830. // Click event may never have fired (Gecko & Opera)
  831. if (true === $.data(event.target, this.widgetName + '.preventClickEvent')) {
  832. $.removeData(event.target, this.widgetName + '.preventClickEvent');
  833. }
  834. // these delegates are required to keep context
  835. this._mouseMoveDelegate = function(event) {
  836. return that._mouseMove(event);
  837. };
  838. this._mouseUpDelegate = function(event) {
  839. return that._mouseUp(event);
  840. };
  841. $(document)
  842. .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  843. .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  844. event.preventDefault();
  845. mouseHandled = true;
  846. return true;
  847. },
  848. _mouseMove: function(event) {
  849. // IE mouseup check - mouseup happened when mouse was out of window
  850. if ($.ui.ie && !(document.documentMode >= 9) && !event.button) {
  851. return this._mouseUp(event);
  852. }
  853. if (this._mouseStarted) {
  854. this._mouseDrag(event);
  855. return event.preventDefault();
  856. }
  857. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  858. this._mouseStarted =
  859. (this._mouseStart(this._mouseDownEvent, event) !== false);
  860. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  861. }
  862. return !this._mouseStarted;
  863. },
  864. _mouseUp: function(event) {
  865. $(document)
  866. .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
  867. .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
  868. if (this._mouseStarted) {
  869. this._mouseStarted = false;
  870. if (event.target === this._mouseDownEvent.target) {
  871. $.data(event.target, this.widgetName + '.preventClickEvent', true);
  872. }
  873. this._mouseStop(event);
  874. }
  875. return false;
  876. },
  877. _mouseDistanceMet: function(event) {
  878. return (Math.max(
  879. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  880. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  881. ) >= this.options.distance
  882. );
  883. },
  884. _mouseDelayMet: function(event) {
  885. return this.mouseDelayMet;
  886. },
  887. // These are placeholder methods, to be overriden by extending plugin
  888. _mouseStart: function(event) {},
  889. _mouseDrag: function(event) {},
  890. _mouseStop: function(event) {},
  891. _mouseCapture: function(event) { return true; }
  892. });
  893. })(jQuery);
  894. (function( $, undefined ) {
  895. $.widget("ui.draggable", $.ui.mouse, {
  896. version: "1.9.2",
  897. widgetEventPrefix: "drag",
  898. options: {
  899. addClasses: true,
  900. appendTo: "parent",
  901. axis: false,
  902. connectToSortable: false,
  903. containment: false,
  904. cursor: "auto",
  905. cursorAt: false,
  906. grid: false,
  907. handle: false,
  908. helper: "original",
  909. iframeFix: false,
  910. opacity: false,
  911. refreshPositions: false,
  912. revert: false,
  913. revertDuration: 500,
  914. scope: "default",
  915. scroll: true,
  916. scrollSensitivity: 20,
  917. scrollSpeed: 20,
  918. snap: false,
  919. snapMode: "both",
  920. snapTolerance: 20,
  921. stack: false,
  922. zIndex: false
  923. },
  924. _create: function() {
  925. if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
  926. this.element[0].style.position = 'relative';
  927. (this.options.addClasses && this.element.addClass("ui-draggable"));
  928. (this.options.disabled && this.element.addClass("ui-draggable-disabled"));
  929. this._mouseInit();
  930. },
  931. _destroy: function() {
  932. this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" );
  933. this._mouseDestroy();
  934. },
  935. _mouseCapture: function(event) {
  936. var o = this.options;
  937. // among others, prevent a drag on a resizable-handle
  938. if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle'))
  939. return false;
  940. //Quit if we're not on a valid handle
  941. this.handle = this._getHandle(event);
  942. if (!this.handle)
  943. return false;
  944. $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
  945. $('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
  946. .css({
  947. width: this.offsetWidth+"px", height: this.offsetHeight+"px",
  948. position: "absolute", opacity: "0.001", zIndex: 1000
  949. })
  950. .css($(this).offset())
  951. .appendTo("body");
  952. });
  953. return true;
  954. },
  955. _mouseStart: function(event) {
  956. var o = this.options;
  957. //Create and append the visible helper
  958. this.helper = this._createHelper(event);
  959. this.helper.addClass("ui-draggable-dragging");
  960. //Cache the helper size
  961. this._cacheHelperProportions();
  962. //If ddmanager is used for droppables, set the global draggable
  963. if($.ui.ddmanager)
  964. $.ui.ddmanager.current = this;
  965. /*
  966. * - Position generation -
  967. * This block generates everything position related - it's the core of draggables.
  968. */
  969. //Cache the margins of the original element
  970. this._cacheMargins();
  971. //Store the helper's css position
  972. this.cssPosition = this.helper.css("position");
  973. this.scrollParent = this.helper.scrollParent();
  974. //The element's absolute position on the page minus margins
  975. this.offset = this.positionAbs = this.element.offset();
  976. this.offset = {
  977. top: this.offset.top - this.margins.top,
  978. left: this.offset.left - this.margins.left
  979. };
  980. $.extend(this.offset, {
  981. click: { //Where the click happened, relative to the element
  982. left: event.pageX - this.offset.left,
  983. top: event.pageY - this.offset.top
  984. },
  985. parent: this._getParentOffset(),
  986. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  987. });
  988. //Generate the original position
  989. this.originalPosition = this.position = this._generatePosition(event);
  990. this.originalPageX = event.pageX;
  991. this.originalPageY = event.pageY;
  992. //Adjust the mouse offset relative to the helper if 'cursorAt' is supplied
  993. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  994. //Set a containment if given in the options
  995. if(o.containment)
  996. this._setContainment();
  997. //Trigger event + callbacks
  998. if(this._trigger("start", event) === false) {
  999. this._clear();
  1000. return false;
  1001. }
  1002. //Recache the helper size
  1003. this._cacheHelperProportions();
  1004. //Prepare the droppable offsets
  1005. if ($.ui.ddmanager && !o.dropBehaviour)
  1006. $.ui.ddmanager.prepareOffsets(this, event);
  1007. this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  1008. //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
  1009. if ( $.ui.ddmanager ) $.ui.ddmanager.dragStart(this, event);
  1010. return true;
  1011. },
  1012. _mouseDrag: function(event, noPropagation) {
  1013. //Compute the helpers position
  1014. this.position = this._generatePosition(event);
  1015. this.positionAbs = this._convertPositionTo("absolute");
  1016. //Call plugins and callbacks and use the resulting position if something is returned
  1017. if (!noPropagation) {
  1018. var ui = this._uiHash();
  1019. if(this._trigger('drag', event, ui) === false) {
  1020. this._mouseUp({});
  1021. return false;
  1022. }
  1023. this.position = ui.position;
  1024. }
  1025. if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
  1026. if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
  1027. if($.ui.ddmanager) $.ui.ddmanager.drag(this, event);
  1028. return false;
  1029. },
  1030. _mouseStop: function(event) {
  1031. //If we are using droppables, inform the manager about the drop
  1032. var dropped = false;
  1033. if ($.ui.ddmanager && !this.options.dropBehaviour)
  1034. dropped = $.ui.ddmanager.drop(this, event);
  1035. //if a drop comes from outside (a sortable)
  1036. if(this.dropped) {
  1037. dropped = this.dropped;
  1038. this.dropped = false;
  1039. }
  1040. //if the original element is no longer in the DOM don't bother to continue (see #8269)
  1041. var element = this.element[0], elementInDom = false;
  1042. while ( element && (element = element.parentNode) ) {
  1043. if (element == document ) {
  1044. elementInDom = true;
  1045. }
  1046. }
  1047. if ( !elementInDom && this.options.helper === "original" )
  1048. return false;
  1049. if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || ($.isFunction(this.options.revert) && this.options.revert.call(this.element, dropped))) {
  1050. var that = this;
  1051. $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
  1052. if(that._trigger("stop", event) !== false) {
  1053. that._clear();
  1054. }
  1055. });
  1056. } else {
  1057. if(this._trigger("stop", event) !== false) {
  1058. this._clear();
  1059. }
  1060. }
  1061. return false;
  1062. },
  1063. _mouseUp: function(event) {
  1064. //Remove frame helpers
  1065. $("div.ui-draggable-iframeFix").each(function() {
  1066. this.parentNode.removeChild(this);
  1067. });
  1068. //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
  1069. if( $.ui.ddmanager ) $.ui.ddmanager.dragStop(this, event);
  1070. return $.ui.mouse.prototype._mouseUp.call(this, event);
  1071. },
  1072. cancel: function() {
  1073. if(this.helper.is(".ui-draggable-dragging")) {
  1074. this._mouseUp({});
  1075. } else {
  1076. this._clear();
  1077. }
  1078. return this;
  1079. },
  1080. _getHandle: function(event) {
  1081. var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
  1082. $(this.options.handle, this.element)
  1083. .find("*")
  1084. .andSelf()
  1085. .each(function() {
  1086. if(this == event.target) handle = true;
  1087. });
  1088. return handle;
  1089. },
  1090. _createHelper: function(event) {
  1091. var o = this.options;
  1092. var helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone().removeAttr('id') : this.element);
  1093. if(!helper.parents('body').length)
  1094. helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
  1095. if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position")))
  1096. helper.css("position", "absolute");
  1097. return helper;
  1098. },
  1099. _adjustOffsetFromHelper: function(obj) {
  1100. if (typeof obj == 'string') {
  1101. obj = obj.split(' ');
  1102. }
  1103. if ($.isArray(obj)) {
  1104. obj = {left: +obj[0], top: +obj[1] || 0};
  1105. }
  1106. if ('left' in obj) {
  1107. this.offset.click.left = obj.left + this.margins.left;
  1108. }
  1109. if ('right' in obj) {
  1110. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  1111. }
  1112. if ('top' in obj) {
  1113. this.offset.click.top = obj.top + this.margins.top;
  1114. }
  1115. if ('bottom' in obj) {
  1116. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  1117. }
  1118. },
  1119. _getParentOffset: function() {
  1120. //Get the offsetParent and cache its position
  1121. this.offsetParent = this.helper.offsetParent();
  1122. var po = this.offsetParent.offset();
  1123. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  1124. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  1125. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  1126. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  1127. if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  1128. po.left += this.scrollParent.scrollLeft();
  1129. po.top += this.scrollParent.scrollTop();
  1130. }
  1131. if((this.offsetParent[0] == document.body) //This needs to be actually done for all browsers, since pageX/pageY includes this information
  1132. || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.ui.ie)) //Ugly IE fix
  1133. po = { top: 0, left: 0 };
  1134. return {
  1135. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  1136. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  1137. };
  1138. },
  1139. _getRelativeOffset: function() {
  1140. if(this.cssPosition == "relative") {
  1141. var p = this.element.position();
  1142. return {
  1143. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  1144. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  1145. };
  1146. } else {
  1147. return { top: 0, left: 0 };
  1148. }
  1149. },
  1150. _cacheMargins: function() {
  1151. this.margins = {
  1152. left: (parseInt(this.element.css("marginLeft"),10) || 0),
  1153. top: (parseInt(this.element.css("marginTop"),10) || 0),
  1154. right: (parseInt(this.element.css("marginRight"),10) || 0),
  1155. bottom: (parseInt(this.element.css("marginBottom"),10) || 0)
  1156. };
  1157. },
  1158. _cacheHelperProportions: function() {
  1159. this.helperProportions = {
  1160. width: this.helper.outerWidth(),
  1161. height: this.helper.outerHeight()
  1162. };
  1163. },
  1164. _setContainment: function() {
  1165. var o = this.options;
  1166. if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
  1167. if(o.containment == 'document' || o.containment == 'window') this.containment = [
  1168. o.containment == 'document' ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
  1169. o.containment == 'document' ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
  1170. (o.containment == 'document' ? 0 : $(window).scrollLeft()) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left,
  1171. (o.containment == 'document' ? 0 : $(window).scrollTop()) + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  1172. ];
  1173. if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) {
  1174. var c = $(o.containment);
  1175. var ce = c[0]; if(!ce) return;
  1176. var co = c.offset();
  1177. var over = ($(ce).css("overflow") != 'hidden');
  1178. this.containment = [
  1179. (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
  1180. (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
  1181. (over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right,
  1182. (over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom
  1183. ];
  1184. this.relative_container = c;
  1185. } else if(o.containment.constructor == Array) {
  1186. this.containment = o.containment;
  1187. }
  1188. },
  1189. _convertPositionTo: function(d, pos) {
  1190. if(!pos) pos = this.position;
  1191. var mod = d == "absolute" ? 1 : -1;
  1192. var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  1193. return {
  1194. top: (
  1195. pos.top // The absolute mouse position
  1196. + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  1197. + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
  1198. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  1199. ),
  1200. left: (
  1201. pos.left // The absolute mouse position
  1202. + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
  1203. + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
  1204. - ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  1205. )
  1206. };
  1207. },
  1208. _generatePosition: function(event) {
  1209. var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  1210. var pageX = event.pageX;
  1211. var pageY = event.pageY;
  1212. /*
  1213. * - Position constraining -
  1214. * Constrain the position to a mix of grid, containment.
  1215. */
  1216. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  1217. var containment;
  1218. if(this.containment) {
  1219. if (this.relative_container){
  1220. var co = this.relative_container.offset();
  1221. containment = [ this.containment[0] + co.left,
  1222. this.containment[1] + co.top,
  1223. this.containment[2] + co.left,
  1224. this.containment[3] + co.top ];
  1225. }
  1226. else {
  1227. containment = this.containment;
  1228. }
  1229. if(event.pageX - this.offset.click.left < containment[0]) pageX = containment[0] + this.offset.click.left;
  1230. if(event.pageY - this.offset.click.top < containment[1]) pageY = containment[1] + this.offset.click.top;
  1231. if(event.pageX - this.offset.click.left > containment[2]) pageX = containment[2] + this.offset.click.left;
  1232. if(event.pageY - this.offset.click.top > containment[3]) pageY = containment[3] + this.offset.click.top;
  1233. }
  1234. if(o.grid) {
  1235. //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
  1236. var top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
  1237. pageY = containment ? (!(top - this.offset.click.top < containment[1] || top - this.offset.click.top > containment[3]) ? top : (!(top - this.offset.click.top < containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
  1238. var left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX;
  1239. pageX = containment ? (!(left - this.offset.click.left < containment[0] || left - this.offset.click.left > containment[2]) ? left : (!(left - this.offset.click.left < containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
  1240. }
  1241. }
  1242. return {
  1243. top: (
  1244. pageY // The absolute mouse position
  1245. - this.offset.click.top // Click offset (relative to the element)
  1246. - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
  1247. - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
  1248. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  1249. ),
  1250. left: (
  1251. pageX // The absolute mouse position
  1252. - this.offset.click.left // Click offset (relative to the element)
  1253. - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
  1254. - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
  1255. + ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  1256. )
  1257. };
  1258. },
  1259. _clear: function() {
  1260. this.helper.removeClass("ui-draggable-dragging");
  1261. if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove();
  1262. //if($.ui.ddmanager) $.ui.ddmanager.current = null;
  1263. this.helper = null;
  1264. this.cancelHelperRemoval = false;
  1265. },
  1266. // From now on bulk stuff - mainly helpers
  1267. _trigger: function(type, event, ui) {
  1268. ui = ui || this._uiHash();
  1269. $.ui.plugin.call(this, type, [event, ui]);
  1270. if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins
  1271. return $.Widget.prototype._trigger.call(this, type, event, ui);
  1272. },
  1273. plugins: {},
  1274. _uiHash: function(event) {
  1275. return {
  1276. helper: this.helper,
  1277. position: this.position,
  1278. originalPosition: this.originalPosition,
  1279. offset: this.positionAbs
  1280. };
  1281. }
  1282. });
  1283. $.ui.plugin.add("draggable", "connectToSortable", {
  1284. start: function(event, ui) {
  1285. var inst = $(this).data("draggable"), o = inst.options,
  1286. uiSortable = $.extend({}, ui, { item: inst.element });
  1287. inst.sortables = [];
  1288. $(o.connectToSortable).each(function() {
  1289. var sortable = $.data(this, 'sortable');
  1290. if (sortable && !sortable.options.disabled) {
  1291. inst.sortables.push({
  1292. instance: sortable,
  1293. shouldRevert: sortable.options.revert
  1294. });
  1295. sortable.refreshPositions(); // Call the sortable's refreshPositions at drag start to refresh the containerCache since the sortable container cache is used in drag and needs to be up to date (this will ensure it's initialised as well as being kept in step with any changes that might have happened on the page).
  1296. sortable._trigger("activate", event, uiSortable);
  1297. }
  1298. });
  1299. },
  1300. stop: function(event, ui) {
  1301. //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
  1302. var inst = $(this).data("draggable"),
  1303. uiSortable = $.extend({}, ui, { item: inst.element });
  1304. $.each(inst.sortables, function() {
  1305. if(this.instance.isOver) {
  1306. this.instance.isOver = 0;
  1307. inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
  1308. this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
  1309. //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid'
  1310. if(this.shouldRevert) this.instance.options.revert = true;
  1311. //Trigger the stop of the sortable
  1312. this.instance._mouseStop(event);
  1313. this.instance.options.helper = this.instance.options._helper;
  1314. //If the helper has been the original item, restore properties in the sortable
  1315. if(inst.options.helper == 'original')
  1316. this.instance.currentItem.css({ top: 'auto', left: 'auto' });
  1317. } else {
  1318. this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
  1319. this.instance._trigger("deactivate", event, uiSortable);
  1320. }
  1321. });
  1322. },
  1323. drag: function(event, ui) {
  1324. var inst = $(this).data("draggable"), that = this;
  1325. var checkPos = function(o) {
  1326. var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
  1327. var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
  1328. var itemHeight = o.height, itemWidth = o.width;
  1329. var itemTop = o.top, itemLeft = o.left;
  1330. return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
  1331. };
  1332. $.each(inst.sortables, function(i) {
  1333. var innermostIntersecting = false;
  1334. var thisSortable = this;
  1335. //Copy over some variables to allow calling the sortable's native _intersectsWith
  1336. this.instance.positionAbs = inst.positionAbs;
  1337. this.instance.helperProportions = inst.helperProportions;
  1338. this.instance.offset.click = inst.offset.click;
  1339. if(this.instance._intersectsWith(this.instance.containerCache)) {
  1340. innermostIntersecting = true;
  1341. $.each(inst.sortables, function () {
  1342. this.instance.positionAbs = inst.positionAbs;
  1343. this.instance.helperProportions = inst.helperProportions;
  1344. this.inst