Advertisement
Guest User

jQuery ui right click mod

a guest
Apr 1st, 2013
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 161.50 KB | None | 0 0
  1. /*! jQuery UI - v1.10.2 - 2013-03-30
  2. * http://jqueryui.com
  3. * Includes: jquery.ui.core.js, jquery.ui.widget.js, jquery.ui.mouse.js, jquery.ui.position.js, jquery.ui.draggable.js, jquery.ui.droppable.js, jquery.ui.resizable.js, jquery.ui.selectable.js, jquery.ui.sortable.js
  4. * Copyright 2013 jQuery Foundation and other contributors Licensed MIT */
  5.  
  6. (function( $, undefined ) {
  7.  
  8. var uuid = 0,
  9. runiqueId = /^ui-id-\d+$/;
  10.  
  11. // $.ui might exist from components with no dependencies, e.g., $.ui.position
  12. $.ui = $.ui || {};
  13.  
  14. $.extend( $.ui, {
  15. version: "1.10.2",
  16.  
  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.  
  43. // plugins
  44. $.fn.extend({
  45. focus: (function( orig ) {
  46. return function( delay, fn ) {
  47. return typeof delay === "number" ?
  48. this.each(function() {
  49. var elem = this;
  50. setTimeout(function() {
  51. $( elem ).focus();
  52. if ( fn ) {
  53. fn.call( elem );
  54. }
  55. }, delay );
  56. }) :
  57. orig.apply( this, arguments );
  58. };
  59. })( $.fn.focus ),
  60.  
  61. scrollParent: function() {
  62. var scrollParent;
  63. if (($.ui.ie && (/(static|relative)/).test(this.css("position"))) || (/absolute/).test(this.css("position"))) {
  64. scrollParent = this.parents().filter(function() {
  65. return (/(relative|absolute|fixed)/).test($.css(this,"position")) && (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
  66. }).eq(0);
  67. } else {
  68. scrollParent = this.parents().filter(function() {
  69. return (/(auto|scroll)/).test($.css(this,"overflow")+$.css(this,"overflow-y")+$.css(this,"overflow-x"));
  70. }).eq(0);
  71. }
  72.  
  73. return (/fixed/).test(this.css("position")) || !scrollParent.length ? $(document) : scrollParent;
  74. },
  75.  
  76. zIndex: function( zIndex ) {
  77. if ( zIndex !== undefined ) {
  78. return this.css( "zIndex", zIndex );
  79. }
  80.  
  81. if ( this.length ) {
  82. var elem = $( this[ 0 ] ), position, value;
  83. while ( elem.length && elem[ 0 ] !== document ) {
  84. // Ignore z-index if position is set to a value where z-index is ignored by the browser
  85. // This makes behavior of this function consistent across browsers
  86. // WebKit always returns auto if the element is positioned
  87. position = elem.css( "position" );
  88. if ( position === "absolute" || position === "relative" || position === "fixed" ) {
  89. // IE returns 0 when zIndex is not specified
  90. // other browsers return a string
  91. // we ignore the case of nested elements with an explicit value of 0
  92. // <div style="z-index: -10;"><div style="z-index: 0;"></div></div>
  93. value = parseInt( elem.css( "zIndex" ), 10 );
  94. if ( !isNaN( value ) && value !== 0 ) {
  95. return value;
  96. }
  97. }
  98. elem = elem.parent();
  99. }
  100. }
  101.  
  102. return 0;
  103. },
  104.  
  105. uniqueId: function() {
  106. return this.each(function() {
  107. if ( !this.id ) {
  108. this.id = "ui-id-" + (++uuid);
  109. }
  110. });
  111. },
  112.  
  113. removeUniqueId: function() {
  114. return this.each(function() {
  115. if ( runiqueId.test( this.id ) ) {
  116. $( this ).removeAttr( "id" );
  117. }
  118. });
  119. }
  120. });
  121.  
  122. // selectors
  123. function focusable( element, isTabIndexNotNaN ) {
  124. var map, mapName, img,
  125. nodeName = element.nodeName.toLowerCase();
  126. if ( "area" === nodeName ) {
  127. map = element.parentNode;
  128. mapName = map.name;
  129. if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) {
  130. return false;
  131. }
  132. img = $( "img[usemap=#" + mapName + "]" )[0];
  133. return !!img && visible( img );
  134. }
  135. return ( /input|select|textarea|button|object/.test( nodeName ) ?
  136. !element.disabled :
  137. "a" === nodeName ?
  138. element.href || isTabIndexNotNaN :
  139. isTabIndexNotNaN) &&
  140. // the element and all of its ancestors must be visible
  141. visible( element );
  142. }
  143.  
  144. function visible( element ) {
  145. return $.expr.filters.visible( element ) &&
  146. !$( element ).parents().addBack().filter(function() {
  147. return $.css( this, "visibility" ) === "hidden";
  148. }).length;
  149. }
  150.  
  151. $.extend( $.expr[ ":" ], {
  152. data: $.expr.createPseudo ?
  153. $.expr.createPseudo(function( dataName ) {
  154. return function( elem ) {
  155. return !!$.data( elem, dataName );
  156. };
  157. }) :
  158. // support: jQuery <1.8
  159. function( elem, i, match ) {
  160. return !!$.data( elem, match[ 3 ] );
  161. },
  162.  
  163. focusable: function( element ) {
  164. return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) );
  165. },
  166.  
  167. tabbable: function( element ) {
  168. var tabIndex = $.attr( element, "tabindex" ),
  169. isTabIndexNaN = isNaN( tabIndex );
  170. return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN );
  171. }
  172. });
  173.  
  174. // support: jQuery <1.8
  175. if ( !$( "<a>" ).outerWidth( 1 ).jquery ) {
  176. $.each( [ "Width", "Height" ], function( i, name ) {
  177. var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ],
  178. type = name.toLowerCase(),
  179. orig = {
  180. innerWidth: $.fn.innerWidth,
  181. innerHeight: $.fn.innerHeight,
  182. outerWidth: $.fn.outerWidth,
  183. outerHeight: $.fn.outerHeight
  184. };
  185.  
  186. function reduce( elem, size, border, margin ) {
  187. $.each( side, function() {
  188. size -= parseFloat( $.css( elem, "padding" + this ) ) || 0;
  189. if ( border ) {
  190. size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0;
  191. }
  192. if ( margin ) {
  193. size -= parseFloat( $.css( elem, "margin" + this ) ) || 0;
  194. }
  195. });
  196. return size;
  197. }
  198.  
  199. $.fn[ "inner" + name ] = function( size ) {
  200. if ( size === undefined ) {
  201. return orig[ "inner" + name ].call( this );
  202. }
  203.  
  204. return this.each(function() {
  205. $( this ).css( type, reduce( this, size ) + "px" );
  206. });
  207. };
  208.  
  209. $.fn[ "outer" + name] = function( size, margin ) {
  210. if ( typeof size !== "number" ) {
  211. return orig[ "outer" + name ].call( this, size );
  212. }
  213.  
  214. return this.each(function() {
  215. $( this).css( type, reduce( this, size, true, margin ) + "px" );
  216. });
  217. };
  218. });
  219. }
  220.  
  221. // support: jQuery <1.8
  222. if ( !$.fn.addBack ) {
  223. $.fn.addBack = function( selector ) {
  224. return this.add( selector == null ?
  225. this.prevObject : this.prevObject.filter( selector )
  226. );
  227. };
  228. }
  229.  
  230. // support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413)
  231. if ( $( "<a>" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) {
  232. $.fn.removeData = (function( removeData ) {
  233. return function( key ) {
  234. if ( arguments.length ) {
  235. return removeData.call( this, $.camelCase( key ) );
  236. } else {
  237. return removeData.call( this );
  238. }
  239. };
  240. })( $.fn.removeData );
  241. }
  242.  
  243.  
  244.  
  245.  
  246.  
  247. // deprecated
  248. $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
  249.  
  250. $.support.selectstart = "onselectstart" in document.createElement( "div" );
  251. $.fn.extend({
  252. disableSelection: function() {
  253. return this.bind( ( $.support.selectstart ? "selectstart" : "mousedown" ) +
  254. ".ui-disableSelection", function( event ) {
  255. event.preventDefault();
  256. });
  257. },
  258.  
  259. enableSelection: function() {
  260. return this.unbind( ".ui-disableSelection" );
  261. }
  262. });
  263.  
  264. $.extend( $.ui, {
  265. // $.ui.plugin is deprecated. Use the proxy pattern instead.
  266. plugin: {
  267. add: function( module, option, set ) {
  268. var i,
  269. proto = $.ui[ module ].prototype;
  270. for ( i in set ) {
  271. proto.plugins[ i ] = proto.plugins[ i ] || [];
  272. proto.plugins[ i ].push( [ option, set[ i ] ] );
  273. }
  274. },
  275. call: function( instance, name, args ) {
  276. var i,
  277. set = instance.plugins[ name ];
  278. if ( !set || !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) {
  279. return;
  280. }
  281.  
  282. for ( i = 0; i < set.length; i++ ) {
  283. if ( instance.options[ set[ i ][ 0 ] ] ) {
  284. set[ i ][ 1 ].apply( instance.element, args );
  285. }
  286. }
  287. }
  288. },
  289.  
  290. // only used by resizable
  291. hasScroll: function( el, a ) {
  292.  
  293. //If overflow is hidden, the element might have extra content, but the user wants to hide it
  294. if ( $( el ).css( "overflow" ) === "hidden") {
  295. return false;
  296. }
  297.  
  298. var scroll = ( a && a === "left" ) ? "scrollLeft" : "scrollTop",
  299. has = false;
  300.  
  301. if ( el[ scroll ] > 0 ) {
  302. return true;
  303. }
  304.  
  305. // TODO: determine which cases actually cause this to happen
  306. // if the element doesn't have the scroll set, see if it's possible to
  307. // set the scroll
  308. el[ scroll ] = 1;
  309. has = ( el[ scroll ] > 0 );
  310. el[ scroll ] = 0;
  311. return has;
  312. }
  313. });
  314.  
  315. })( jQuery );
  316. (function( $, undefined ) {
  317.  
  318. var uuid = 0,
  319. slice = Array.prototype.slice,
  320. _cleanData = $.cleanData;
  321. $.cleanData = function( elems ) {
  322. for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
  323. try {
  324. $( elem ).triggerHandler( "remove" );
  325. // http://bugs.jquery.com/ticket/8235
  326. } catch( e ) {}
  327. }
  328. _cleanData( elems );
  329. };
  330.  
  331. $.widget = function( name, base, prototype ) {
  332. var fullName, existingConstructor, constructor, basePrototype,
  333. // proxiedPrototype allows the provided prototype to remain unmodified
  334. // so that it can be used as a mixin for multiple widgets (#8876)
  335. proxiedPrototype = {},
  336. namespace = name.split( "." )[ 0 ];
  337.  
  338. name = name.split( "." )[ 1 ];
  339. fullName = namespace + "-" + name;
  340.  
  341. if ( !prototype ) {
  342. prototype = base;
  343. base = $.Widget;
  344. }
  345.  
  346. // create selector for plugin
  347. $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
  348. return !!$.data( elem, fullName );
  349. };
  350.  
  351. $[ namespace ] = $[ namespace ] || {};
  352. existingConstructor = $[ namespace ][ name ];
  353. constructor = $[ namespace ][ name ] = function( options, element ) {
  354. // allow instantiation without "new" keyword
  355. if ( !this._createWidget ) {
  356. return new constructor( options, element );
  357. }
  358.  
  359. // allow instantiation without initializing for simple inheritance
  360. // must use "new" keyword (the code above always passes args)
  361. if ( arguments.length ) {
  362. this._createWidget( options, element );
  363. }
  364. };
  365. // extend with the existing constructor to carry over any static properties
  366. $.extend( constructor, existingConstructor, {
  367. version: prototype.version,
  368. // copy the object used to create the prototype in case we need to
  369. // redefine the widget later
  370. _proto: $.extend( {}, prototype ),
  371. // track widgets that inherit from this widget in case this widget is
  372. // redefined after a widget inherits from it
  373. _childConstructors: []
  374. });
  375.  
  376. basePrototype = new base();
  377. // we need to make the options hash a property directly on the new instance
  378. // otherwise we'll modify the options hash on the prototype that we're
  379. // inheriting from
  380. basePrototype.options = $.widget.extend( {}, basePrototype.options );
  381. $.each( prototype, function( prop, value ) {
  382. if ( !$.isFunction( value ) ) {
  383. proxiedPrototype[ prop ] = value;
  384. return;
  385. }
  386. proxiedPrototype[ prop ] = (function() {
  387. var _super = function() {
  388. return base.prototype[ prop ].apply( this, arguments );
  389. },
  390. _superApply = function( args ) {
  391. return base.prototype[ prop ].apply( this, args );
  392. };
  393. return function() {
  394. var __super = this._super,
  395. __superApply = this._superApply,
  396. returnValue;
  397.  
  398. this._super = _super;
  399. this._superApply = _superApply;
  400.  
  401. returnValue = value.apply( this, arguments );
  402.  
  403. this._super = __super;
  404. this._superApply = __superApply;
  405.  
  406. return returnValue;
  407. };
  408. })();
  409. });
  410. constructor.prototype = $.widget.extend( basePrototype, {
  411. // TODO: remove support for widgetEventPrefix
  412. // always use the name + a colon as the prefix, e.g., draggable:start
  413. // don't prefix for widgets that aren't DOM-based
  414. widgetEventPrefix: existingConstructor ? basePrototype.widgetEventPrefix : name
  415. }, proxiedPrototype, {
  416. constructor: constructor,
  417. namespace: namespace,
  418. widgetName: name,
  419. widgetFullName: fullName
  420. });
  421.  
  422. // If this widget is being redefined then we need to find all widgets that
  423. // are inheriting from it and redefine all of them so that they inherit from
  424. // the new version of this widget. We're essentially trying to replace one
  425. // level in the prototype chain.
  426. if ( existingConstructor ) {
  427. $.each( existingConstructor._childConstructors, function( i, child ) {
  428. var childPrototype = child.prototype;
  429.  
  430. // redefine the child widget using the same prototype that was
  431. // originally used, but inherit from the new version of the base
  432. $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
  433. });
  434. // remove the list of existing child constructors from the old constructor
  435. // so the old child constructors can be garbage collected
  436. delete existingConstructor._childConstructors;
  437. } else {
  438. base._childConstructors.push( constructor );
  439. }
  440.  
  441. $.widget.bridge( name, constructor );
  442. };
  443.  
  444. $.widget.extend = function( target ) {
  445. var input = slice.call( arguments, 1 ),
  446. inputIndex = 0,
  447. inputLength = input.length,
  448. key,
  449. value;
  450. for ( ; inputIndex < inputLength; inputIndex++ ) {
  451. for ( key in input[ inputIndex ] ) {
  452. value = input[ inputIndex ][ key ];
  453. if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
  454. // Clone objects
  455. if ( $.isPlainObject( value ) ) {
  456. target[ key ] = $.isPlainObject( target[ key ] ) ?
  457. $.widget.extend( {}, target[ key ], value ) :
  458. // Don't extend strings, arrays, etc. with objects
  459. $.widget.extend( {}, value );
  460. // Copy everything else by reference
  461. } else {
  462. target[ key ] = value;
  463. }
  464. }
  465. }
  466. }
  467. return target;
  468. };
  469.  
  470. $.widget.bridge = function( name, object ) {
  471. var fullName = object.prototype.widgetFullName || name;
  472. $.fn[ name ] = function( options ) {
  473. var isMethodCall = typeof options === "string",
  474. args = slice.call( arguments, 1 ),
  475. returnValue = this;
  476.  
  477. // allow multiple hashes to be passed on init
  478. options = !isMethodCall && args.length ?
  479. $.widget.extend.apply( null, [ options ].concat(args) ) :
  480. options;
  481.  
  482. if ( isMethodCall ) {
  483. this.each(function() {
  484. var methodValue,
  485. instance = $.data( this, fullName );
  486. if ( !instance ) {
  487. return $.error( "cannot call methods on " + name + " prior to initialization; " +
  488. "attempted to call method '" + options + "'" );
  489. }
  490. if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
  491. return $.error( "no such method '" + options + "' for " + name + " widget instance" );
  492. }
  493. methodValue = instance[ options ].apply( instance, args );
  494. if ( methodValue !== instance && methodValue !== undefined ) {
  495. returnValue = methodValue && methodValue.jquery ?
  496. returnValue.pushStack( methodValue.get() ) :
  497. methodValue;
  498. return false;
  499. }
  500. });
  501. } else {
  502. this.each(function() {
  503. var instance = $.data( this, fullName );
  504. if ( instance ) {
  505. instance.option( options || {} )._init();
  506. } else {
  507. $.data( this, fullName, new object( options, this ) );
  508. }
  509. });
  510. }
  511.  
  512. return returnValue;
  513. };
  514. };
  515.  
  516. $.Widget = function( /* options, element */ ) {};
  517. $.Widget._childConstructors = [];
  518.  
  519. $.Widget.prototype = {
  520. widgetName: "widget",
  521. widgetEventPrefix: "",
  522. defaultElement: "<div>",
  523. options: {
  524. disabled: false,
  525.  
  526. // callbacks
  527. create: null
  528. },
  529. _createWidget: function( options, element ) {
  530. element = $( element || this.defaultElement || this )[ 0 ];
  531. this.element = $( element );
  532. this.uuid = uuid++;
  533. this.eventNamespace = "." + this.widgetName + this.uuid;
  534. this.options = $.widget.extend( {},
  535. this.options,
  536. this._getCreateOptions(),
  537. options );
  538.  
  539. this.bindings = $();
  540. this.hoverable = $();
  541. this.focusable = $();
  542.  
  543. if ( element !== this ) {
  544. $.data( element, this.widgetFullName, this );
  545. this._on( true, this.element, {
  546. remove: function( event ) {
  547. if ( event.target === element ) {
  548. this.destroy();
  549. }
  550. }
  551. });
  552. this.document = $( element.style ?
  553. // element within the document
  554. element.ownerDocument :
  555. // element is window or document
  556. element.document || element );
  557. this.window = $( this.document[0].defaultView || this.document[0].parentWindow );
  558. }
  559.  
  560. this._create();
  561. this._trigger( "create", null, this._getCreateEventData() );
  562. this._init();
  563. },
  564. _getCreateOptions: $.noop,
  565. _getCreateEventData: $.noop,
  566. _create: $.noop,
  567. _init: $.noop,
  568.  
  569. destroy: function() {
  570. this._destroy();
  571. // we can probably remove the unbind calls in 2.0
  572. // all event bindings should go through this._on()
  573. this.element
  574. .unbind( this.eventNamespace )
  575. // 1.9 BC for #7810
  576. // TODO remove dual storage
  577. .removeData( this.widgetName )
  578. .removeData( this.widgetFullName )
  579. // support: jquery <1.6.3
  580. // http://bugs.jquery.com/ticket/9413
  581. .removeData( $.camelCase( this.widgetFullName ) );
  582. this.widget()
  583. .unbind( this.eventNamespace )
  584. .removeAttr( "aria-disabled" )
  585. .removeClass(
  586. this.widgetFullName + "-disabled " +
  587. "ui-state-disabled" );
  588.  
  589. // clean up events and states
  590. this.bindings.unbind( this.eventNamespace );
  591. this.hoverable.removeClass( "ui-state-hover" );
  592. this.focusable.removeClass( "ui-state-focus" );
  593. },
  594. _destroy: $.noop,
  595.  
  596. widget: function() {
  597. return this.element;
  598. },
  599.  
  600. option: function( key, value ) {
  601. var options = key,
  602. parts,
  603. curOption,
  604. i;
  605.  
  606. if ( arguments.length === 0 ) {
  607. // don't return a reference to the internal hash
  608. return $.widget.extend( {}, this.options );
  609. }
  610.  
  611. if ( typeof key === "string" ) {
  612. // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
  613. options = {};
  614. parts = key.split( "." );
  615. key = parts.shift();
  616. if ( parts.length ) {
  617. curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] );
  618. for ( i = 0; i < parts.length - 1; i++ ) {
  619. curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {};
  620. curOption = curOption[ parts[ i ] ];
  621. }
  622. key = parts.pop();
  623. if ( value === undefined ) {
  624. return curOption[ key ] === undefined ? null : curOption[ key ];
  625. }
  626. curOption[ key ] = value;
  627. } else {
  628. if ( value === undefined ) {
  629. return this.options[ key ] === undefined ? null : this.options[ key ];
  630. }
  631. options[ key ] = value;
  632. }
  633. }
  634.  
  635. this._setOptions( options );
  636.  
  637. return this;
  638. },
  639. _setOptions: function( options ) {
  640. var key;
  641.  
  642. for ( key in options ) {
  643. this._setOption( key, options[ key ] );
  644. }
  645.  
  646. return this;
  647. },
  648. _setOption: function( key, value ) {
  649. this.options[ key ] = value;
  650.  
  651. if ( key === "disabled" ) {
  652. this.widget()
  653. .toggleClass( this.widgetFullName + "-disabled ui-state-disabled", !!value )
  654. .attr( "aria-disabled", value );
  655. this.hoverable.removeClass( "ui-state-hover" );
  656. this.focusable.removeClass( "ui-state-focus" );
  657. }
  658.  
  659. return this;
  660. },
  661.  
  662. enable: function() {
  663. return this._setOption( "disabled", false );
  664. },
  665. disable: function() {
  666. return this._setOption( "disabled", true );
  667. },
  668.  
  669. _on: function( suppressDisabledCheck, element, handlers ) {
  670. var delegateElement,
  671. instance = this;
  672.  
  673. // no suppressDisabledCheck flag, shuffle arguments
  674. if ( typeof suppressDisabledCheck !== "boolean" ) {
  675. handlers = element;
  676. element = suppressDisabledCheck;
  677. suppressDisabledCheck = false;
  678. }
  679.  
  680. // no element argument, shuffle and use this.element
  681. if ( !handlers ) {
  682. handlers = element;
  683. element = this.element;
  684. delegateElement = this.widget();
  685. } else {
  686. // accept selectors, DOM elements
  687. element = delegateElement = $( element );
  688. this.bindings = this.bindings.add( element );
  689. }
  690.  
  691. $.each( handlers, function( event, handler ) {
  692. function handlerProxy() {
  693. // allow widgets to customize the disabled handling
  694. // - disabled as an array instead of boolean
  695. // - disabled class as method for disabling individual parts
  696. if ( !suppressDisabledCheck &&
  697. ( instance.options.disabled === true ||
  698. $( this ).hasClass( "ui-state-disabled" ) ) ) {
  699. return;
  700. }
  701. return ( typeof handler === "string" ? instance[ handler ] : handler )
  702. .apply( instance, arguments );
  703. }
  704.  
  705. // copy the guid so direct unbinding works
  706. if ( typeof handler !== "string" ) {
  707. handlerProxy.guid = handler.guid =
  708. handler.guid || handlerProxy.guid || $.guid++;
  709. }
  710.  
  711. var match = event.match( /^(\w+)\s*(.*)$/ ),
  712. eventName = match[1] + instance.eventNamespace,
  713. selector = match[2];
  714. if ( selector ) {
  715. delegateElement.delegate( selector, eventName, handlerProxy );
  716. } else {
  717. element.bind( eventName, handlerProxy );
  718. }
  719. });
  720. },
  721.  
  722. _off: function( element, eventName ) {
  723. eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + this.eventNamespace;
  724. element.unbind( eventName ).undelegate( eventName );
  725. },
  726.  
  727. _delay: function( handler, delay ) {
  728. function handlerProxy() {
  729. return ( typeof handler === "string" ? instance[ handler ] : handler )
  730. .apply( instance, arguments );
  731. }
  732. var instance = this;
  733. return setTimeout( handlerProxy, delay || 0 );
  734. },
  735.  
  736. _hoverable: function( element ) {
  737. this.hoverable = this.hoverable.add( element );
  738. this._on( element, {
  739. mouseenter: function( event ) {
  740. $( event.currentTarget ).addClass( "ui-state-hover" );
  741. },
  742. mouseleave: function( event ) {
  743. $( event.currentTarget ).removeClass( "ui-state-hover" );
  744. }
  745. });
  746. },
  747.  
  748. _focusable: function( element ) {
  749. this.focusable = this.focusable.add( element );
  750. this._on( element, {
  751. focusin: function( event ) {
  752. $( event.currentTarget ).addClass( "ui-state-focus" );
  753. },
  754. focusout: function( event ) {
  755. $( event.currentTarget ).removeClass( "ui-state-focus" );
  756. }
  757. });
  758. },
  759.  
  760. _trigger: function( type, event, data ) {
  761. var prop, orig,
  762. callback = this.options[ type ];
  763.  
  764. data = data || {};
  765. event = $.Event( event );
  766. event.type = ( type === this.widgetEventPrefix ?
  767. type :
  768. this.widgetEventPrefix + type ).toLowerCase();
  769. // the original event may come from any element
  770. // so we need to reset the target on the new event
  771. event.target = this.element[ 0 ];
  772.  
  773. // copy original event properties over to the new event
  774. orig = event.originalEvent;
  775. if ( orig ) {
  776. for ( prop in orig ) {
  777. if ( !( prop in event ) ) {
  778. event[ prop ] = orig[ prop ];
  779. }
  780. }
  781. }
  782.  
  783. this.element.trigger( event, data );
  784. return !( $.isFunction( callback ) &&
  785. callback.apply( this.element[0], [ event ].concat( data ) ) === false ||
  786. event.isDefaultPrevented() );
  787. }
  788. };
  789.  
  790. $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
  791. $.Widget.prototype[ "_" + method ] = function( element, options, callback ) {
  792. if ( typeof options === "string" ) {
  793. options = { effect: options };
  794. }
  795. var hasOptions,
  796. effectName = !options ?
  797. method :
  798. options === true || typeof options === "number" ?
  799. defaultEffect :
  800. options.effect || defaultEffect;
  801. options = options || {};
  802. if ( typeof options === "number" ) {
  803. options = { duration: options };
  804. }
  805. hasOptions = !$.isEmptyObject( options );
  806. options.complete = callback;
  807. if ( options.delay ) {
  808. element.delay( options.delay );
  809. }
  810. if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
  811. element[ method ]( options );
  812. } else if ( effectName !== method && element[ effectName ] ) {
  813. element[ effectName ]( options.duration, options.easing, callback );
  814. } else {
  815. element.queue(function( next ) {
  816. $( this )[ method ]();
  817. if ( callback ) {
  818. callback.call( element[ 0 ] );
  819. }
  820. next();
  821. });
  822. }
  823. };
  824. });
  825.  
  826. })( jQuery );
  827. (function( $, undefined ) {
  828.  
  829. var mouseHandled = false;
  830. $( document ).mouseup( function() {
  831. mouseHandled = false;
  832. });
  833.  
  834. $.widget("ui.mouse", {
  835. version: "1.10.2",
  836. options: {
  837. cancel: "input,textarea,button,select,option",
  838. distance: 1,
  839. delay: 0,
  840. which:1
  841. },
  842. _mouseInit: function() {
  843. var that = this;
  844.  
  845. this.element
  846. .bind("mousedown."+this.widgetName, function(event) {
  847. return that._mouseDown(event);
  848. })
  849. .bind("click."+this.widgetName, function(event) {
  850. if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
  851. $.removeData(event.target, that.widgetName + ".preventClickEvent");
  852. event.stopImmediatePropagation();
  853. return false;
  854. }
  855. });
  856.  
  857. this.started = false;
  858. },
  859.  
  860. // TODO: make sure destroying one instance of mouse doesn't mess with
  861. // other instances of mouse
  862. _mouseDestroy: function() {
  863. this.element.unbind("."+this.widgetName);
  864. if ( this._mouseMoveDelegate ) {
  865. $(document)
  866. .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
  867. .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
  868. }
  869. },
  870.  
  871. _mouseDown: function(event) {
  872. // don't let more than one widget handle mouseStart
  873. if( mouseHandled ) { return; }
  874.  
  875. // we may have missed mouseup (out of window)
  876. (this._mouseStarted && this._mouseUp(event));
  877.  
  878. this._mouseDownEvent = event;
  879.  
  880. var that = this,
  881. btnIsLeft = (event.which === this.options.which),
  882. // event.target.nodeName works around a bug in IE 8 with
  883. // disabled inputs (#7620)
  884. elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
  885. if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
  886. return true;
  887. }
  888.  
  889. this.mouseDelayMet = !this.options.delay;
  890. if (!this.mouseDelayMet) {
  891. this._mouseDelayTimer = setTimeout(function() {
  892. that.mouseDelayMet = true;
  893. }, this.options.delay);
  894. }
  895.  
  896. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  897. this._mouseStarted = (this._mouseStart(event) !== false);
  898. if (!this._mouseStarted) {
  899. event.preventDefault();
  900. return true;
  901. }
  902. }
  903.  
  904. // Click event may never have fired (Gecko & Opera)
  905. if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
  906. $.removeData(event.target, this.widgetName + ".preventClickEvent");
  907. }
  908.  
  909. // these delegates are required to keep context
  910. this._mouseMoveDelegate = function(event) {
  911. return that._mouseMove(event);
  912. };
  913. this._mouseUpDelegate = function(event) {
  914. return that._mouseUp(event);
  915. };
  916. $(document)
  917. .bind("mousemove."+this.widgetName, this._mouseMoveDelegate)
  918. .bind("mouseup."+this.widgetName, this._mouseUpDelegate);
  919.  
  920. event.preventDefault();
  921.  
  922. mouseHandled = true;
  923. return true;
  924. },
  925.  
  926. _mouseMove: function(event) {
  927. // IE mouseup check - mouseup happened when mouse was out of window
  928. if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
  929. return this._mouseUp(event);
  930. }
  931.  
  932. if (this._mouseStarted) {
  933. this._mouseDrag(event);
  934. return event.preventDefault();
  935. }
  936.  
  937. if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
  938. this._mouseStarted =
  939. (this._mouseStart(this._mouseDownEvent, event) !== false);
  940. (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
  941. }
  942.  
  943. return !this._mouseStarted;
  944. },
  945.  
  946. _mouseUp: function(event) {
  947. $(document)
  948. .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
  949. .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
  950.  
  951. if (this._mouseStarted) {
  952. this._mouseStarted = false;
  953.  
  954. if (event.target === this._mouseDownEvent.target) {
  955. $.data(event.target, this.widgetName + ".preventClickEvent", true);
  956. }
  957.  
  958. this._mouseStop(event);
  959. }
  960.  
  961. return false;
  962. },
  963.  
  964. _mouseDistanceMet: function(event) {
  965. return (Math.max(
  966. Math.abs(this._mouseDownEvent.pageX - event.pageX),
  967. Math.abs(this._mouseDownEvent.pageY - event.pageY)
  968. ) >= this.options.distance
  969. );
  970. },
  971.  
  972. _mouseDelayMet: function(/* event */) {
  973. return this.mouseDelayMet;
  974. },
  975.  
  976. // These are placeholder methods, to be overriden by extending plugin
  977. _mouseStart: function(/* event */) {},
  978. _mouseDrag: function(/* event */) {},
  979. _mouseStop: function(/* event */) {},
  980. _mouseCapture: function(/* event */) { return true; }
  981. });
  982.  
  983. })(jQuery);
  984. (function( $, undefined ) {
  985.  
  986. $.ui = $.ui || {};
  987.  
  988. var cachedScrollbarWidth,
  989. max = Math.max,
  990. abs = Math.abs,
  991. round = Math.round,
  992. rhorizontal = /left|center|right/,
  993. rvertical = /top|center|bottom/,
  994. roffset = /[\+\-]\d+(\.[\d]+)?%?/,
  995. rposition = /^\w+/,
  996. rpercent = /%$/,
  997. _position = $.fn.position;
  998.  
  999. function getOffsets( offsets, width, height ) {
  1000. return [
  1001. parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
  1002. parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
  1003. ];
  1004. }
  1005.  
  1006. function parseCss( element, property ) {
  1007. return parseInt( $.css( element, property ), 10 ) || 0;
  1008. }
  1009.  
  1010. function getDimensions( elem ) {
  1011. var raw = elem[0];
  1012. if ( raw.nodeType === 9 ) {
  1013. return {
  1014. width: elem.width(),
  1015. height: elem.height(),
  1016. offset: { top: 0, left: 0 }
  1017. };
  1018. }
  1019. if ( $.isWindow( raw ) ) {
  1020. return {
  1021. width: elem.width(),
  1022. height: elem.height(),
  1023. offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
  1024. };
  1025. }
  1026. if ( raw.preventDefault ) {
  1027. return {
  1028. width: 0,
  1029. height: 0,
  1030. offset: { top: raw.pageY, left: raw.pageX }
  1031. };
  1032. }
  1033. return {
  1034. width: elem.outerWidth(),
  1035. height: elem.outerHeight(),
  1036. offset: elem.offset()
  1037. };
  1038. }
  1039.  
  1040. $.position = {
  1041. scrollbarWidth: function() {
  1042. if ( cachedScrollbarWidth !== undefined ) {
  1043. return cachedScrollbarWidth;
  1044. }
  1045. var w1, w2,
  1046. div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
  1047. innerDiv = div.children()[0];
  1048.  
  1049. $( "body" ).append( div );
  1050. w1 = innerDiv.offsetWidth;
  1051. div.css( "overflow", "scroll" );
  1052.  
  1053. w2 = innerDiv.offsetWidth;
  1054.  
  1055. if ( w1 === w2 ) {
  1056. w2 = div[0].clientWidth;
  1057. }
  1058.  
  1059. div.remove();
  1060.  
  1061. return (cachedScrollbarWidth = w1 - w2);
  1062. },
  1063. getScrollInfo: function( within ) {
  1064. var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ),
  1065. overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ),
  1066. hasOverflowX = overflowX === "scroll" ||
  1067. ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
  1068. hasOverflowY = overflowY === "scroll" ||
  1069. ( overflowY === "auto" && within.height < within.element[0].scrollHeight );
  1070. return {
  1071. width: hasOverflowY ? $.position.scrollbarWidth() : 0,
  1072. height: hasOverflowX ? $.position.scrollbarWidth() : 0
  1073. };
  1074. },
  1075. getWithinInfo: function( element ) {
  1076. var withinElement = $( element || window ),
  1077. isWindow = $.isWindow( withinElement[0] );
  1078. return {
  1079. element: withinElement,
  1080. isWindow: isWindow,
  1081. offset: withinElement.offset() || { left: 0, top: 0 },
  1082. scrollLeft: withinElement.scrollLeft(),
  1083. scrollTop: withinElement.scrollTop(),
  1084. width: isWindow ? withinElement.width() : withinElement.outerWidth(),
  1085. height: isWindow ? withinElement.height() : withinElement.outerHeight()
  1086. };
  1087. }
  1088. };
  1089.  
  1090. $.fn.position = function( options ) {
  1091. if ( !options || !options.of ) {
  1092. return _position.apply( this, arguments );
  1093. }
  1094.  
  1095. // make a copy, we don't want to modify arguments
  1096. options = $.extend( {}, options );
  1097.  
  1098. var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
  1099. target = $( options.of ),
  1100. within = $.position.getWithinInfo( options.within ),
  1101. scrollInfo = $.position.getScrollInfo( within ),
  1102. collision = ( options.collision || "flip" ).split( " " ),
  1103. offsets = {};
  1104.  
  1105. dimensions = getDimensions( target );
  1106. if ( target[0].preventDefault ) {
  1107. // force left top to allow flipping
  1108. options.at = "left top";
  1109. }
  1110. targetWidth = dimensions.width;
  1111. targetHeight = dimensions.height;
  1112. targetOffset = dimensions.offset;
  1113. // clone to reuse original targetOffset later
  1114. basePosition = $.extend( {}, targetOffset );
  1115.  
  1116. // force my and at to have valid horizontal and vertical positions
  1117. // if a value is missing or invalid, it will be converted to center
  1118. $.each( [ "my", "at" ], function() {
  1119. var pos = ( options[ this ] || "" ).split( " " ),
  1120. horizontalOffset,
  1121. verticalOffset;
  1122.  
  1123. if ( pos.length === 1) {
  1124. pos = rhorizontal.test( pos[ 0 ] ) ?
  1125. pos.concat( [ "center" ] ) :
  1126. rvertical.test( pos[ 0 ] ) ?
  1127. [ "center" ].concat( pos ) :
  1128. [ "center", "center" ];
  1129. }
  1130. pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
  1131. pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
  1132.  
  1133. // calculate offsets
  1134. horizontalOffset = roffset.exec( pos[ 0 ] );
  1135. verticalOffset = roffset.exec( pos[ 1 ] );
  1136. offsets[ this ] = [
  1137. horizontalOffset ? horizontalOffset[ 0 ] : 0,
  1138. verticalOffset ? verticalOffset[ 0 ] : 0
  1139. ];
  1140.  
  1141. // reduce to just the positions without the offsets
  1142. options[ this ] = [
  1143. rposition.exec( pos[ 0 ] )[ 0 ],
  1144. rposition.exec( pos[ 1 ] )[ 0 ]
  1145. ];
  1146. });
  1147.  
  1148. // normalize collision option
  1149. if ( collision.length === 1 ) {
  1150. collision[ 1 ] = collision[ 0 ];
  1151. }
  1152.  
  1153. if ( options.at[ 0 ] === "right" ) {
  1154. basePosition.left += targetWidth;
  1155. } else if ( options.at[ 0 ] === "center" ) {
  1156. basePosition.left += targetWidth / 2;
  1157. }
  1158.  
  1159. if ( options.at[ 1 ] === "bottom" ) {
  1160. basePosition.top += targetHeight;
  1161. } else if ( options.at[ 1 ] === "center" ) {
  1162. basePosition.top += targetHeight / 2;
  1163. }
  1164.  
  1165. atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
  1166. basePosition.left += atOffset[ 0 ];
  1167. basePosition.top += atOffset[ 1 ];
  1168.  
  1169. return this.each(function() {
  1170. var collisionPosition, using,
  1171. elem = $( this ),
  1172. elemWidth = elem.outerWidth(),
  1173. elemHeight = elem.outerHeight(),
  1174. marginLeft = parseCss( this, "marginLeft" ),
  1175. marginTop = parseCss( this, "marginTop" ),
  1176. collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
  1177. collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
  1178. position = $.extend( {}, basePosition ),
  1179. myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
  1180.  
  1181. if ( options.my[ 0 ] === "right" ) {
  1182. position.left -= elemWidth;
  1183. } else if ( options.my[ 0 ] === "center" ) {
  1184. position.left -= elemWidth / 2;
  1185. }
  1186.  
  1187. if ( options.my[ 1 ] === "bottom" ) {
  1188. position.top -= elemHeight;
  1189. } else if ( options.my[ 1 ] === "center" ) {
  1190. position.top -= elemHeight / 2;
  1191. }
  1192.  
  1193. position.left += myOffset[ 0 ];
  1194. position.top += myOffset[ 1 ];
  1195.  
  1196. // if the browser doesn't support fractions, then round for consistent results
  1197. if ( !$.support.offsetFractions ) {
  1198. position.left = round( position.left );
  1199. position.top = round( position.top );
  1200. }
  1201.  
  1202. collisionPosition = {
  1203. marginLeft: marginLeft,
  1204. marginTop: marginTop
  1205. };
  1206.  
  1207. $.each( [ "left", "top" ], function( i, dir ) {
  1208. if ( $.ui.position[ collision[ i ] ] ) {
  1209. $.ui.position[ collision[ i ] ][ dir ]( position, {
  1210. targetWidth: targetWidth,
  1211. targetHeight: targetHeight,
  1212. elemWidth: elemWidth,
  1213. elemHeight: elemHeight,
  1214. collisionPosition: collisionPosition,
  1215. collisionWidth: collisionWidth,
  1216. collisionHeight: collisionHeight,
  1217. offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
  1218. my: options.my,
  1219. at: options.at,
  1220. within: within,
  1221. elem : elem
  1222. });
  1223. }
  1224. });
  1225.  
  1226. if ( options.using ) {
  1227. // adds feedback as second argument to using callback, if present
  1228. using = function( props ) {
  1229. var left = targetOffset.left - position.left,
  1230. right = left + targetWidth - elemWidth,
  1231. top = targetOffset.top - position.top,
  1232. bottom = top + targetHeight - elemHeight,
  1233. feedback = {
  1234. target: {
  1235. element: target,
  1236. left: targetOffset.left,
  1237. top: targetOffset.top,
  1238. width: targetWidth,
  1239. height: targetHeight
  1240. },
  1241. element: {
  1242. element: elem,
  1243. left: position.left,
  1244. top: position.top,
  1245. width: elemWidth,
  1246. height: elemHeight
  1247. },
  1248. horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
  1249. vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
  1250. };
  1251. if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
  1252. feedback.horizontal = "center";
  1253. }
  1254. if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
  1255. feedback.vertical = "middle";
  1256. }
  1257. if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
  1258. feedback.important = "horizontal";
  1259. } else {
  1260. feedback.important = "vertical";
  1261. }
  1262. options.using.call( this, props, feedback );
  1263. };
  1264. }
  1265.  
  1266. elem.offset( $.extend( position, { using: using } ) );
  1267. });
  1268. };
  1269.  
  1270. $.ui.position = {
  1271. fit: {
  1272. left: function( position, data ) {
  1273. var within = data.within,
  1274. withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
  1275. outerWidth = within.width,
  1276. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  1277. overLeft = withinOffset - collisionPosLeft,
  1278. overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
  1279. newOverRight;
  1280.  
  1281. // element is wider than within
  1282. if ( data.collisionWidth > outerWidth ) {
  1283. // element is initially over the left side of within
  1284. if ( overLeft > 0 && overRight <= 0 ) {
  1285. newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
  1286. position.left += overLeft - newOverRight;
  1287. // element is initially over right side of within
  1288. } else if ( overRight > 0 && overLeft <= 0 ) {
  1289. position.left = withinOffset;
  1290. // element is initially over both left and right sides of within
  1291. } else {
  1292. if ( overLeft > overRight ) {
  1293. position.left = withinOffset + outerWidth - data.collisionWidth;
  1294. } else {
  1295. position.left = withinOffset;
  1296. }
  1297. }
  1298. // too far left -> align with left edge
  1299. } else if ( overLeft > 0 ) {
  1300. position.left += overLeft;
  1301. // too far right -> align with right edge
  1302. } else if ( overRight > 0 ) {
  1303. position.left -= overRight;
  1304. // adjust based on position and margin
  1305. } else {
  1306. position.left = max( position.left - collisionPosLeft, position.left );
  1307. }
  1308. },
  1309. top: function( position, data ) {
  1310. var within = data.within,
  1311. withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
  1312. outerHeight = data.within.height,
  1313. collisionPosTop = position.top - data.collisionPosition.marginTop,
  1314. overTop = withinOffset - collisionPosTop,
  1315. overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
  1316. newOverBottom;
  1317.  
  1318. // element is taller than within
  1319. if ( data.collisionHeight > outerHeight ) {
  1320. // element is initially over the top of within
  1321. if ( overTop > 0 && overBottom <= 0 ) {
  1322. newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
  1323. position.top += overTop - newOverBottom;
  1324. // element is initially over bottom of within
  1325. } else if ( overBottom > 0 && overTop <= 0 ) {
  1326. position.top = withinOffset;
  1327. // element is initially over both top and bottom of within
  1328. } else {
  1329. if ( overTop > overBottom ) {
  1330. position.top = withinOffset + outerHeight - data.collisionHeight;
  1331. } else {
  1332. position.top = withinOffset;
  1333. }
  1334. }
  1335. // too far up -> align with top
  1336. } else if ( overTop > 0 ) {
  1337. position.top += overTop;
  1338. // too far down -> align with bottom edge
  1339. } else if ( overBottom > 0 ) {
  1340. position.top -= overBottom;
  1341. // adjust based on position and margin
  1342. } else {
  1343. position.top = max( position.top - collisionPosTop, position.top );
  1344. }
  1345. }
  1346. },
  1347. flip: {
  1348. left: function( position, data ) {
  1349. var within = data.within,
  1350. withinOffset = within.offset.left + within.scrollLeft,
  1351. outerWidth = within.width,
  1352. offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
  1353. collisionPosLeft = position.left - data.collisionPosition.marginLeft,
  1354. overLeft = collisionPosLeft - offsetLeft,
  1355. overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
  1356. myOffset = data.my[ 0 ] === "left" ?
  1357. -data.elemWidth :
  1358. data.my[ 0 ] === "right" ?
  1359. data.elemWidth :
  1360. 0,
  1361. atOffset = data.at[ 0 ] === "left" ?
  1362. data.targetWidth :
  1363. data.at[ 0 ] === "right" ?
  1364. -data.targetWidth :
  1365. 0,
  1366. offset = -2 * data.offset[ 0 ],
  1367. newOverRight,
  1368. newOverLeft;
  1369.  
  1370. if ( overLeft < 0 ) {
  1371. newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
  1372. if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
  1373. position.left += myOffset + atOffset + offset;
  1374. }
  1375. }
  1376. else if ( overRight > 0 ) {
  1377. newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
  1378. if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
  1379. position.left += myOffset + atOffset + offset;
  1380. }
  1381. }
  1382. },
  1383. top: function( position, data ) {
  1384. var within = data.within,
  1385. withinOffset = within.offset.top + within.scrollTop,
  1386. outerHeight = within.height,
  1387. offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
  1388. collisionPosTop = position.top - data.collisionPosition.marginTop,
  1389. overTop = collisionPosTop - offsetTop,
  1390. overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
  1391. top = data.my[ 1 ] === "top",
  1392. myOffset = top ?
  1393. -data.elemHeight :
  1394. data.my[ 1 ] === "bottom" ?
  1395. data.elemHeight :
  1396. 0,
  1397. atOffset = data.at[ 1 ] === "top" ?
  1398. data.targetHeight :
  1399. data.at[ 1 ] === "bottom" ?
  1400. -data.targetHeight :
  1401. 0,
  1402. offset = -2 * data.offset[ 1 ],
  1403. newOverTop,
  1404. newOverBottom;
  1405. if ( overTop < 0 ) {
  1406. newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
  1407. if ( ( position.top + myOffset + atOffset + offset) > overTop && ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) ) {
  1408. position.top += myOffset + atOffset + offset;
  1409. }
  1410. }
  1411. else if ( overBottom > 0 ) {
  1412. newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
  1413. if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || abs( newOverTop ) < overBottom ) ) {
  1414. position.top += myOffset + atOffset + offset;
  1415. }
  1416. }
  1417. }
  1418. },
  1419. flipfit: {
  1420. left: function() {
  1421. $.ui.position.flip.left.apply( this, arguments );
  1422. $.ui.position.fit.left.apply( this, arguments );
  1423. },
  1424. top: function() {
  1425. $.ui.position.flip.top.apply( this, arguments );
  1426. $.ui.position.fit.top.apply( this, arguments );
  1427. }
  1428. }
  1429. };
  1430.  
  1431. // fraction support test
  1432. (function () {
  1433. var testElement, testElementParent, testElementStyle, offsetLeft, i,
  1434. body = document.getElementsByTagName( "body" )[ 0 ],
  1435. div = document.createElement( "div" );
  1436.  
  1437. //Create a "fake body" for testing based on method used in jQuery.support
  1438. testElement = document.createElement( body ? "div" : "body" );
  1439. testElementStyle = {
  1440. visibility: "hidden",
  1441. width: 0,
  1442. height: 0,
  1443. border: 0,
  1444. margin: 0,
  1445. background: "none"
  1446. };
  1447. if ( body ) {
  1448. $.extend( testElementStyle, {
  1449. position: "absolute",
  1450. left: "-1000px",
  1451. top: "-1000px"
  1452. });
  1453. }
  1454. for ( i in testElementStyle ) {
  1455. testElement.style[ i ] = testElementStyle[ i ];
  1456. }
  1457. testElement.appendChild( div );
  1458. testElementParent = body || document.documentElement;
  1459. testElementParent.insertBefore( testElement, testElementParent.firstChild );
  1460.  
  1461. div.style.cssText = "position: absolute; left: 10.7432222px;";
  1462.  
  1463. offsetLeft = $( div ).offset().left;
  1464. $.support.offsetFractions = offsetLeft > 10 && offsetLeft < 11;
  1465.  
  1466. testElement.innerHTML = "";
  1467. testElementParent.removeChild( testElement );
  1468. })();
  1469.  
  1470. }( jQuery ) );
  1471. (function( $, undefined ) {
  1472.  
  1473. $.widget("ui.draggable", $.ui.mouse, {
  1474. version: "1.10.2",
  1475. widgetEventPrefix: "drag",
  1476. options: {
  1477. addClasses: true,
  1478. appendTo: "parent",
  1479. axis: false,
  1480. connectToSortable: false,
  1481. containment: false,
  1482. cursor: "auto",
  1483. cursorAt: false,
  1484. grid: false,
  1485. handle: false,
  1486. helper: "original",
  1487. iframeFix: false,
  1488. opacity: false,
  1489. refreshPositions: false,
  1490. revert: false,
  1491. revertDuration: 500,
  1492. scope: "default",
  1493. scroll: true,
  1494. scrollSensitivity: 20,
  1495. scrollSpeed: 20,
  1496. snap: false,
  1497. snapMode: "both",
  1498. snapTolerance: 20,
  1499. stack: false,
  1500. zIndex: false,
  1501.  
  1502. // callbacks
  1503. drag: null,
  1504. start: null,
  1505. stop: null
  1506. },
  1507. _create: function() {
  1508.  
  1509. if (this.options.helper === "original" && !(/^(?:r|a|f)/).test(this.element.css("position"))) {
  1510. this.element[0].style.position = "relative";
  1511. }
  1512. if (this.options.addClasses){
  1513. this.element.addClass("ui-draggable");
  1514. }
  1515. if (this.options.disabled){
  1516. this.element.addClass("ui-draggable-disabled");
  1517. }
  1518.  
  1519. this._mouseInit();
  1520.  
  1521. },
  1522.  
  1523. _destroy: function() {
  1524. this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" );
  1525. this._mouseDestroy();
  1526. },
  1527.  
  1528. _mouseCapture: function(event) {
  1529.  
  1530. var o = this.options;
  1531.  
  1532. // among others, prevent a drag on a resizable-handle
  1533. if (this.helper || o.disabled || $(event.target).closest(".ui-resizable-handle").length > 0) {
  1534. return false;
  1535. }
  1536.  
  1537. //Quit if we're not on a valid handle
  1538. this.handle = this._getHandle(event);
  1539. if (!this.handle) {
  1540. return false;
  1541. }
  1542.  
  1543. $(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() {
  1544. $("<div class='ui-draggable-iframeFix' style='background: #fff;'></div>")
  1545. .css({
  1546. width: this.offsetWidth+"px", height: this.offsetHeight+"px",
  1547. position: "absolute", opacity: "0.001", zIndex: 1000
  1548. })
  1549. .css($(this).offset())
  1550. .appendTo("body");
  1551. });
  1552.  
  1553. return true;
  1554.  
  1555. },
  1556.  
  1557. _mouseStart: function(event) {
  1558.  
  1559. var o = this.options;
  1560.  
  1561. //Create and append the visible helper
  1562. this.helper = this._createHelper(event);
  1563.  
  1564. this.helper.addClass("ui-draggable-dragging");
  1565.  
  1566. //Cache the helper size
  1567. this._cacheHelperProportions();
  1568.  
  1569. //If ddmanager is used for droppables, set the global draggable
  1570. if($.ui.ddmanager) {
  1571. $.ui.ddmanager.current = this;
  1572. }
  1573.  
  1574. /*
  1575. * - Position generation -
  1576. * This block generates everything position related - it's the core of draggables.
  1577. */
  1578.  
  1579. //Cache the margins of the original element
  1580. this._cacheMargins();
  1581.  
  1582. //Store the helper's css position
  1583. this.cssPosition = this.helper.css("position");
  1584. this.scrollParent = this.helper.scrollParent();
  1585.  
  1586. //The element's absolute position on the page minus margins
  1587. this.offset = this.positionAbs = this.element.offset();
  1588. this.offset = {
  1589. top: this.offset.top - this.margins.top,
  1590. left: this.offset.left - this.margins.left
  1591. };
  1592.  
  1593. $.extend(this.offset, {
  1594. click: { //Where the click happened, relative to the element
  1595. left: event.pageX - this.offset.left,
  1596. top: event.pageY - this.offset.top
  1597. },
  1598. parent: this._getParentOffset(),
  1599. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  1600. });
  1601.  
  1602. //Generate the original position
  1603. this.originalPosition = this.position = this._generatePosition(event);
  1604. this.originalPageX = event.pageX;
  1605. this.originalPageY = event.pageY;
  1606.  
  1607. //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
  1608. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  1609.  
  1610. //Set a containment if given in the options
  1611. if(o.containment) {
  1612. this._setContainment();
  1613. }
  1614.  
  1615. //Trigger event + callbacks
  1616. if(this._trigger("start", event) === false) {
  1617. this._clear();
  1618. return false;
  1619. }
  1620.  
  1621. //Recache the helper size
  1622. this._cacheHelperProportions();
  1623.  
  1624. //Prepare the droppable offsets
  1625. if ($.ui.ddmanager && !o.dropBehaviour) {
  1626. $.ui.ddmanager.prepareOffsets(this, event);
  1627. }
  1628.  
  1629.  
  1630. this._mouseDrag(event, true); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  1631.  
  1632. //If the ddmanager is used for droppables, inform the manager that dragging has started (see #5003)
  1633. if ( $.ui.ddmanager ) {
  1634. $.ui.ddmanager.dragStart(this, event);
  1635. }
  1636.  
  1637. return true;
  1638. },
  1639.  
  1640. _mouseDrag: function(event, noPropagation) {
  1641.  
  1642. //Compute the helpers position
  1643. this.position = this._generatePosition(event);
  1644. this.positionAbs = this._convertPositionTo("absolute");
  1645.  
  1646. //Call plugins and callbacks and use the resulting position if something is returned
  1647. if (!noPropagation) {
  1648. var ui = this._uiHash();
  1649. if(this._trigger("drag", event, ui) === false) {
  1650. this._mouseUp({});
  1651. return false;
  1652. }
  1653. this.position = ui.position;
  1654. }
  1655.  
  1656. if(!this.options.axis || this.options.axis !== "y") {
  1657. this.helper[0].style.left = this.position.left+"px";
  1658. }
  1659. if(!this.options.axis || this.options.axis !== "x") {
  1660. this.helper[0].style.top = this.position.top+"px";
  1661. }
  1662. if($.ui.ddmanager) {
  1663. $.ui.ddmanager.drag(this, event);
  1664. }
  1665.  
  1666. return false;
  1667. },
  1668.  
  1669. _mouseStop: function(event) {
  1670.  
  1671. //If we are using droppables, inform the manager about the drop
  1672. var element,
  1673. that = this,
  1674. elementInDom = false,
  1675. dropped = false;
  1676. if ($.ui.ddmanager && !this.options.dropBehaviour) {
  1677. dropped = $.ui.ddmanager.drop(this, event);
  1678. }
  1679.  
  1680. //if a drop comes from outside (a sortable)
  1681. if(this.dropped) {
  1682. dropped = this.dropped;
  1683. this.dropped = false;
  1684. }
  1685.  
  1686. //if the original element is no longer in the DOM don't bother to continue (see #8269)
  1687. element = this.element[0];
  1688. while ( element && (element = element.parentNode) ) {
  1689. if (element === document ) {
  1690. elementInDom = true;
  1691. }
  1692. }
  1693. if ( !elementInDom && this.options.helper === "original" ) {
  1694. return false;
  1695. }
  1696.  
  1697. 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))) {
  1698. $(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() {
  1699. if(that._trigger("stop", event) !== false) {
  1700. that._clear();
  1701. }
  1702. });
  1703. } else {
  1704. if(this._trigger("stop", event) !== false) {
  1705. this._clear();
  1706. }
  1707. }
  1708.  
  1709. return false;
  1710. },
  1711.  
  1712. _mouseUp: function(event) {
  1713. //Remove frame helpers
  1714. $("div.ui-draggable-iframeFix").each(function() {
  1715. this.parentNode.removeChild(this);
  1716. });
  1717.  
  1718. //If the ddmanager is used for droppables, inform the manager that dragging has stopped (see #5003)
  1719. if( $.ui.ddmanager ) {
  1720. $.ui.ddmanager.dragStop(this, event);
  1721. }
  1722.  
  1723. return $.ui.mouse.prototype._mouseUp.call(this, event);
  1724. },
  1725.  
  1726. cancel: function() {
  1727.  
  1728. if(this.helper.is(".ui-draggable-dragging")) {
  1729. this._mouseUp({});
  1730. } else {
  1731. this._clear();
  1732. }
  1733.  
  1734. return this;
  1735.  
  1736. },
  1737.  
  1738. _getHandle: function(event) {
  1739. return this.options.handle ?
  1740. !!$( event.target ).closest( this.element.find( this.options.handle ) ).length :
  1741. true;
  1742. },
  1743.  
  1744. _createHelper: function(event) {
  1745.  
  1746. var o = this.options,
  1747. helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event])) : (o.helper === "clone" ? this.element.clone().removeAttr("id") : this.element);
  1748.  
  1749. if(!helper.parents("body").length) {
  1750. helper.appendTo((o.appendTo === "parent" ? this.element[0].parentNode : o.appendTo));
  1751. }
  1752.  
  1753. if(helper[0] !== this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) {
  1754. helper.css("position", "absolute");
  1755. }
  1756.  
  1757. return helper;
  1758.  
  1759. },
  1760.  
  1761. _adjustOffsetFromHelper: function(obj) {
  1762. if (typeof obj === "string") {
  1763. obj = obj.split(" ");
  1764. }
  1765. if ($.isArray(obj)) {
  1766. obj = {left: +obj[0], top: +obj[1] || 0};
  1767. }
  1768. if ("left" in obj) {
  1769. this.offset.click.left = obj.left + this.margins.left;
  1770. }
  1771. if ("right" in obj) {
  1772. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  1773. }
  1774. if ("top" in obj) {
  1775. this.offset.click.top = obj.top + this.margins.top;
  1776. }
  1777. if ("bottom" in obj) {
  1778. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  1779. }
  1780. },
  1781.  
  1782. _getParentOffset: function() {
  1783.  
  1784. //Get the offsetParent and cache its position
  1785. this.offsetParent = this.helper.offsetParent();
  1786. var po = this.offsetParent.offset();
  1787.  
  1788. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  1789. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  1790. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  1791. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  1792. if(this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  1793. po.left += this.scrollParent.scrollLeft();
  1794. po.top += this.scrollParent.scrollTop();
  1795. }
  1796.  
  1797. //This needs to be actually done for all browsers, since pageX/pageY includes this information
  1798. //Ugly IE fix
  1799. if((this.offsetParent[0] === document.body) ||
  1800. (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
  1801. po = { top: 0, left: 0 };
  1802. }
  1803.  
  1804. return {
  1805. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  1806. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  1807. };
  1808.  
  1809. },
  1810.  
  1811. _getRelativeOffset: function() {
  1812.  
  1813. if(this.cssPosition === "relative") {
  1814. var p = this.element.position();
  1815. return {
  1816. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  1817. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  1818. };
  1819. } else {
  1820. return { top: 0, left: 0 };
  1821. }
  1822.  
  1823. },
  1824.  
  1825. _cacheMargins: function() {
  1826. this.margins = {
  1827. left: (parseInt(this.element.css("marginLeft"),10) || 0),
  1828. top: (parseInt(this.element.css("marginTop"),10) || 0),
  1829. right: (parseInt(this.element.css("marginRight"),10) || 0),
  1830. bottom: (parseInt(this.element.css("marginBottom"),10) || 0)
  1831. };
  1832. },
  1833.  
  1834. _cacheHelperProportions: function() {
  1835. this.helperProportions = {
  1836. width: this.helper.outerWidth(),
  1837. height: this.helper.outerHeight()
  1838. };
  1839. },
  1840.  
  1841. _setContainment: function() {
  1842.  
  1843. var over, c, ce,
  1844. o = this.options;
  1845.  
  1846. if(o.containment === "parent") {
  1847. o.containment = this.helper[0].parentNode;
  1848. }
  1849. if(o.containment === "document" || o.containment === "window") {
  1850. this.containment = [
  1851. o.containment === "document" ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left,
  1852. o.containment === "document" ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top,
  1853. (o.containment === "document" ? 0 : $(window).scrollLeft()) + $(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,
  1854. (o.containment === "document" ? 0 : $(window).scrollTop()) + ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  1855. ];
  1856. }
  1857.  
  1858. if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor !== Array) {
  1859. c = $(o.containment);
  1860. ce = c[0];
  1861.  
  1862. if(!ce) {
  1863. return;
  1864. }
  1865.  
  1866. over = ($(ce).css("overflow") !== "hidden");
  1867.  
  1868. this.containment = [
  1869. (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0),
  1870. (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0),
  1871. (over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderRightWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right,
  1872. (over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderBottomWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom
  1873. ];
  1874. this.relative_container = c;
  1875.  
  1876. } else if(o.containment.constructor === Array) {
  1877. this.containment = o.containment;
  1878. }
  1879.  
  1880. },
  1881.  
  1882. _convertPositionTo: function(d, pos) {
  1883.  
  1884. if(!pos) {
  1885. pos = this.position;
  1886. }
  1887.  
  1888. var mod = d === "absolute" ? 1 : -1,
  1889. 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);
  1890.  
  1891. return {
  1892. top: (
  1893. pos.top + // The absolute mouse position
  1894. this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  1895. this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
  1896. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  1897. ),
  1898. left: (
  1899. pos.left + // The absolute mouse position
  1900. this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  1901. this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
  1902. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  1903. )
  1904. };
  1905.  
  1906. },
  1907.  
  1908. _generatePosition: function(event) {
  1909.  
  1910. var containment, co, top, left,
  1911. o = this.options,
  1912. scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
  1913. scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName),
  1914. pageX = event.pageX,
  1915. pageY = event.pageY;
  1916.  
  1917. /*
  1918. * - Position constraining -
  1919. * Constrain the position to a mix of grid, containment.
  1920. */
  1921.  
  1922. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  1923. if(this.containment) {
  1924. if (this.relative_container){
  1925. co = this.relative_container.offset();
  1926. containment = [ this.containment[0] + co.left,
  1927. this.containment[1] + co.top,
  1928. this.containment[2] + co.left,
  1929. this.containment[3] + co.top ];
  1930. }
  1931. else {
  1932. containment = this.containment;
  1933. }
  1934.  
  1935. if(event.pageX - this.offset.click.left < containment[0]) {
  1936. pageX = containment[0] + this.offset.click.left;
  1937. }
  1938. if(event.pageY - this.offset.click.top < containment[1]) {
  1939. pageY = containment[1] + this.offset.click.top;
  1940. }
  1941. if(event.pageX - this.offset.click.left > containment[2]) {
  1942. pageX = containment[2] + this.offset.click.left;
  1943. }
  1944. if(event.pageY - this.offset.click.top > containment[3]) {
  1945. pageY = containment[3] + this.offset.click.top;
  1946. }
  1947. }
  1948.  
  1949. if(o.grid) {
  1950. //Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
  1951. top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
  1952. 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;
  1953.  
  1954. left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX;
  1955. 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;
  1956. }
  1957.  
  1958. }
  1959.  
  1960. return {
  1961. top: (
  1962. pageY - // The absolute mouse position
  1963. this.offset.click.top - // Click offset (relative to the element)
  1964. this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
  1965. this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
  1966. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  1967. ),
  1968. left: (
  1969. pageX - // The absolute mouse position
  1970. this.offset.click.left - // Click offset (relative to the element)
  1971. this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
  1972. this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
  1973. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  1974. )
  1975. };
  1976.  
  1977. },
  1978.  
  1979. _clear: function() {
  1980. this.helper.removeClass("ui-draggable-dragging");
  1981. if(this.helper[0] !== this.element[0] && !this.cancelHelperRemoval) {
  1982. this.helper.remove();
  1983. }
  1984. this.helper = null;
  1985. this.cancelHelperRemoval = false;
  1986. },
  1987.  
  1988. // From now on bulk stuff - mainly helpers
  1989.  
  1990. _trigger: function(type, event, ui) {
  1991. ui = ui || this._uiHash();
  1992. $.ui.plugin.call(this, type, [event, ui]);
  1993. //The absolute position has to be recalculated after plugins
  1994. if(type === "drag") {
  1995. this.positionAbs = this._convertPositionTo("absolute");
  1996. }
  1997. return $.Widget.prototype._trigger.call(this, type, event, ui);
  1998. },
  1999.  
  2000. plugins: {},
  2001.  
  2002. _uiHash: function() {
  2003. return {
  2004. helper: this.helper,
  2005. position: this.position,
  2006. originalPosition: this.originalPosition,
  2007. offset: this.positionAbs
  2008. };
  2009. }
  2010.  
  2011. });
  2012.  
  2013. $.ui.plugin.add("draggable", "connectToSortable", {
  2014. start: function(event, ui) {
  2015.  
  2016. var inst = $(this).data("ui-draggable"), o = inst.options,
  2017. uiSortable = $.extend({}, ui, { item: inst.element });
  2018. inst.sortables = [];
  2019. $(o.connectToSortable).each(function() {
  2020. var sortable = $.data(this, "ui-sortable");
  2021. if (sortable && !sortable.options.disabled) {
  2022. inst.sortables.push({
  2023. instance: sortable,
  2024. shouldRevert: sortable.options.revert
  2025. });
  2026. 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).
  2027. sortable._trigger("activate", event, uiSortable);
  2028. }
  2029. });
  2030.  
  2031. },
  2032. stop: function(event, ui) {
  2033.  
  2034. //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
  2035. var inst = $(this).data("ui-draggable"),
  2036. uiSortable = $.extend({}, ui, { item: inst.element });
  2037.  
  2038. $.each(inst.sortables, function() {
  2039. if(this.instance.isOver) {
  2040.  
  2041. this.instance.isOver = 0;
  2042.  
  2043. inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
  2044. this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
  2045.  
  2046. //The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: "valid/invalid"
  2047. if(this.shouldRevert) {
  2048. this.instance.options.revert = this.shouldRevert;
  2049. }
  2050.  
  2051. //Trigger the stop of the sortable
  2052. this.instance._mouseStop(event);
  2053.  
  2054. this.instance.options.helper = this.instance.options._helper;
  2055.  
  2056. //If the helper has been the original item, restore properties in the sortable
  2057. if(inst.options.helper === "original") {
  2058. this.instance.currentItem.css({ top: "auto", left: "auto" });
  2059. }
  2060.  
  2061. } else {
  2062. this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
  2063. this.instance._trigger("deactivate", event, uiSortable);
  2064. }
  2065.  
  2066. });
  2067.  
  2068. },
  2069. drag: function(event, ui) {
  2070.  
  2071. var inst = $(this).data("ui-draggable"), that = this;
  2072.  
  2073. $.each(inst.sortables, function() {
  2074.  
  2075. var innermostIntersecting = false,
  2076. thisSortable = this;
  2077.  
  2078. //Copy over some variables to allow calling the sortable's native _intersectsWith
  2079. this.instance.positionAbs = inst.positionAbs;
  2080. this.instance.helperProportions = inst.helperProportions;
  2081. this.instance.offset.click = inst.offset.click;
  2082.  
  2083. if(this.instance._intersectsWith(this.instance.containerCache)) {
  2084. innermostIntersecting = true;
  2085. $.each(inst.sortables, function () {
  2086. this.instance.positionAbs = inst.positionAbs;
  2087. this.instance.helperProportions = inst.helperProportions;
  2088. this.instance.offset.click = inst.offset.click;
  2089. if (this !== thisSortable &&
  2090. this.instance._intersectsWith(this.instance.containerCache) &&
  2091. $.contains(thisSortable.instance.element[0], this.instance.element[0])
  2092. ) {
  2093. innermostIntersecting = false;
  2094. }
  2095. return innermostIntersecting;
  2096. });
  2097. }
  2098.  
  2099.  
  2100. if(innermostIntersecting) {
  2101. //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
  2102. if(!this.instance.isOver) {
  2103.  
  2104. this.instance.isOver = 1;
  2105. //Now we fake the start of dragging for the sortable instance,
  2106. //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
  2107. //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)
  2108. this.instance.currentItem = $(that).clone().removeAttr("id").appendTo(this.instance.element).data("ui-sortable-item", true);
  2109. this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
  2110. this.instance.options.helper = function() { return ui.helper[0]; };
  2111.  
  2112. event.target = this.instance.currentItem[0];
  2113. this.instance._mouseCapture(event, true);
  2114. this.instance._mouseStart(event, true, true);
  2115.  
  2116. //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
  2117. this.instance.offset.click.top = inst.offset.click.top;
  2118. this.instance.offset.click.left = inst.offset.click.left;
  2119. this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
  2120. this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
  2121.  
  2122. inst._trigger("toSortable", event);
  2123. inst.dropped = this.instance.element; //draggable revert needs that
  2124. //hack so receive/update callbacks work (mostly)
  2125. inst.currentItem = inst.element;
  2126. this.instance.fromOutside = inst;
  2127.  
  2128. }
  2129.  
  2130. //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
  2131. if(this.instance.currentItem) {
  2132. this.instance._mouseDrag(event);
  2133. }
  2134.  
  2135. } else {
  2136.  
  2137. //If it doesn't intersect with the sortable, and it intersected before,
  2138. //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
  2139. if(this.instance.isOver) {
  2140.  
  2141. this.instance.isOver = 0;
  2142. this.instance.cancelHelperRemoval = true;
  2143.  
  2144. //Prevent reverting on this forced stop
  2145. this.instance.options.revert = false;
  2146.  
  2147. // The out event needs to be triggered independently
  2148. this.instance._trigger("out", event, this.instance._uiHash(this.instance));
  2149.  
  2150. this.instance._mouseStop(event, true);
  2151. this.instance.options.helper = this.instance.options._helper;
  2152.  
  2153. //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
  2154. this.instance.currentItem.remove();
  2155. if(this.instance.placeholder) {
  2156. this.instance.placeholder.remove();
  2157. }
  2158.  
  2159. inst._trigger("fromSortable", event);
  2160. inst.dropped = false; //draggable revert needs that
  2161. }
  2162.  
  2163. }
  2164.  
  2165. });
  2166.  
  2167. }
  2168. });
  2169.  
  2170. $.ui.plugin.add("draggable", "cursor", {
  2171. start: function() {
  2172. var t = $("body"), o = $(this).data("ui-draggable").options;
  2173. if (t.css("cursor")) {
  2174. o._cursor = t.css("cursor");
  2175. }
  2176. t.css("cursor", o.cursor);
  2177. },
  2178. stop: function() {
  2179. var o = $(this).data("ui-draggable").options;
  2180. if (o._cursor) {
  2181. $("body").css("cursor", o._cursor);
  2182. }
  2183. }
  2184. });
  2185.  
  2186. $.ui.plugin.add("draggable", "opacity", {
  2187. start: function(event, ui) {
  2188. var t = $(ui.helper), o = $(this).data("ui-draggable").options;
  2189. if(t.css("opacity")) {
  2190. o._opacity = t.css("opacity");
  2191. }
  2192. t.css("opacity", o.opacity);
  2193. },
  2194. stop: function(event, ui) {
  2195. var o = $(this).data("ui-draggable").options;
  2196. if(o._opacity) {
  2197. $(ui.helper).css("opacity", o._opacity);
  2198. }
  2199. }
  2200. });
  2201.  
  2202. $.ui.plugin.add("draggable", "scroll", {
  2203. start: function() {
  2204. var i = $(this).data("ui-draggable");
  2205. if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
  2206. i.overflowOffset = i.scrollParent.offset();
  2207. }
  2208. },
  2209. drag: function( event ) {
  2210.  
  2211. var i = $(this).data("ui-draggable"), o = i.options, scrolled = false;
  2212.  
  2213. if(i.scrollParent[0] !== document && i.scrollParent[0].tagName !== "HTML") {
  2214.  
  2215. if(!o.axis || o.axis !== "x") {
  2216. if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
  2217. i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed;
  2218. } else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) {
  2219. i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed;
  2220. }
  2221. }
  2222.  
  2223. if(!o.axis || o.axis !== "y") {
  2224. if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
  2225. i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed;
  2226. } else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) {
  2227. i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed;
  2228. }
  2229. }
  2230.  
  2231. } else {
  2232.  
  2233. if(!o.axis || o.axis !== "x") {
  2234. if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
  2235. scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
  2236. } else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
  2237. scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
  2238. }
  2239. }
  2240.  
  2241. if(!o.axis || o.axis !== "y") {
  2242. if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
  2243. scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
  2244. } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
  2245. scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
  2246. }
  2247. }
  2248.  
  2249. }
  2250.  
  2251. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
  2252. $.ui.ddmanager.prepareOffsets(i, event);
  2253. }
  2254.  
  2255. }
  2256. });
  2257.  
  2258. $.ui.plugin.add("draggable", "snap", {
  2259. start: function() {
  2260.  
  2261. var i = $(this).data("ui-draggable"),
  2262. o = i.options;
  2263.  
  2264. i.snapElements = [];
  2265.  
  2266. $(o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap).each(function() {
  2267. var $t = $(this),
  2268. $o = $t.offset();
  2269. if(this !== i.element[0]) {
  2270. i.snapElements.push({
  2271. item: this,
  2272. width: $t.outerWidth(), height: $t.outerHeight(),
  2273. top: $o.top, left: $o.left
  2274. });
  2275. }
  2276. });
  2277.  
  2278. },
  2279. drag: function(event, ui) {
  2280.  
  2281. var ts, bs, ls, rs, l, r, t, b, i, first,
  2282. inst = $(this).data("ui-draggable"),
  2283. o = inst.options,
  2284. d = o.snapTolerance,
  2285. x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
  2286. y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
  2287.  
  2288. for (i = inst.snapElements.length - 1; i >= 0; i--){
  2289.  
  2290. l = inst.snapElements[i].left;
  2291. r = l + inst.snapElements[i].width;
  2292. t = inst.snapElements[i].top;
  2293. b = t + inst.snapElements[i].height;
  2294.  
  2295. //Yes, I know, this is insane ;)
  2296. 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))) {
  2297. if(inst.snapElements[i].snapping) {
  2298. (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
  2299. }
  2300. inst.snapElements[i].snapping = false;
  2301. continue;
  2302. }
  2303.  
  2304. if(o.snapMode !== "inner") {
  2305. ts = Math.abs(t - y2) <= d;
  2306. bs = Math.abs(b - y1) <= d;
  2307. ls = Math.abs(l - x2) <= d;
  2308. rs = Math.abs(r - x1) <= d;
  2309. if(ts) {
  2310. ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
  2311. }
  2312. if(bs) {
  2313. ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
  2314. }
  2315. if(ls) {
  2316. ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
  2317. }
  2318. if(rs) {
  2319. ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
  2320. }
  2321. }
  2322.  
  2323. first = (ts || bs || ls || rs);
  2324.  
  2325. if(o.snapMode !== "outer") {
  2326. ts = Math.abs(t - y1) <= d;
  2327. bs = Math.abs(b - y2) <= d;
  2328. ls = Math.abs(l - x1) <= d;
  2329. rs = Math.abs(r - x2) <= d;
  2330. if(ts) {
  2331. ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top;
  2332. }
  2333. if(bs) {
  2334. ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
  2335. }
  2336. if(ls) {
  2337. ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
  2338. }
  2339. if(rs) {
  2340. ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
  2341. }
  2342. }
  2343.  
  2344. if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) {
  2345. (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
  2346. }
  2347. inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
  2348.  
  2349. }
  2350.  
  2351. }
  2352. });
  2353.  
  2354. $.ui.plugin.add("draggable", "stack", {
  2355. start: function() {
  2356. var min,
  2357. o = this.data("ui-draggable").options,
  2358. group = $.makeArray($(o.stack)).sort(function(a,b) {
  2359. return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0);
  2360. });
  2361.  
  2362. if (!group.length) { return; }
  2363.  
  2364. min = parseInt($(group[0]).css("zIndex"), 10) || 0;
  2365. $(group).each(function(i) {
  2366. $(this).css("zIndex", min + i);
  2367. });
  2368. this.css("zIndex", (min + group.length));
  2369. }
  2370. });
  2371.  
  2372. $.ui.plugin.add("draggable", "zIndex", {
  2373. start: function(event, ui) {
  2374. var t = $(ui.helper), o = $(this).data("ui-draggable").options;
  2375. if(t.css("zIndex")) {
  2376. o._zIndex = t.css("zIndex");
  2377. }
  2378. t.css("zIndex", o.zIndex);
  2379. },
  2380. stop: function(event, ui) {
  2381. var o = $(this).data("ui-draggable").options;
  2382. if(o._zIndex) {
  2383. $(ui.helper).css("zIndex", o._zIndex);
  2384. }
  2385. }
  2386. });
  2387.  
  2388. })(jQuery);
  2389. (function( $, undefined ) {
  2390.  
  2391. function isOverAxis( x, reference, size ) {
  2392. return ( x > reference ) && ( x < ( reference + size ) );
  2393. }
  2394.  
  2395. $.widget("ui.droppable", {
  2396. version: "1.10.2",
  2397. widgetEventPrefix: "drop",
  2398. options: {
  2399. accept: "*",
  2400. activeClass: false,
  2401. addClasses: true,
  2402. greedy: false,
  2403. hoverClass: false,
  2404. scope: "default",
  2405. tolerance: "intersect",
  2406.  
  2407. // callbacks
  2408. activate: null,
  2409. deactivate: null,
  2410. drop: null,
  2411. out: null,
  2412. over: null
  2413. },
  2414. _create: function() {
  2415.  
  2416. var o = this.options,
  2417. accept = o.accept;
  2418.  
  2419. this.isover = false;
  2420. this.isout = true;
  2421.  
  2422. this.accept = $.isFunction(accept) ? accept : function(d) {
  2423. return d.is(accept);
  2424. };
  2425.  
  2426. //Store the droppable's proportions
  2427. this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
  2428.  
  2429. // Add the reference and positions to the manager
  2430. $.ui.ddmanager.droppables[o.scope] = $.ui.ddmanager.droppables[o.scope] || [];
  2431. $.ui.ddmanager.droppables[o.scope].push(this);
  2432.  
  2433. (o.addClasses && this.element.addClass("ui-droppable"));
  2434.  
  2435. },
  2436.  
  2437. _destroy: function() {
  2438. var i = 0,
  2439. drop = $.ui.ddmanager.droppables[this.options.scope];
  2440.  
  2441. for ( ; i < drop.length; i++ ) {
  2442. if ( drop[i] === this ) {
  2443. drop.splice(i, 1);
  2444. }
  2445. }
  2446.  
  2447. this.element.removeClass("ui-droppable ui-droppable-disabled");
  2448. },
  2449.  
  2450. _setOption: function(key, value) {
  2451.  
  2452. if(key === "accept") {
  2453. this.accept = $.isFunction(value) ? value : function(d) {
  2454. return d.is(value);
  2455. };
  2456. }
  2457. $.Widget.prototype._setOption.apply(this, arguments);
  2458. },
  2459.  
  2460. _activate: function(event) {
  2461. var draggable = $.ui.ddmanager.current;
  2462. if(this.options.activeClass) {
  2463. this.element.addClass(this.options.activeClass);
  2464. }
  2465. if(draggable){
  2466. this._trigger("activate", event, this.ui(draggable));
  2467. }
  2468. },
  2469.  
  2470. _deactivate: function(event) {
  2471. var draggable = $.ui.ddmanager.current;
  2472. if(this.options.activeClass) {
  2473. this.element.removeClass(this.options.activeClass);
  2474. }
  2475. if(draggable){
  2476. this._trigger("deactivate", event, this.ui(draggable));
  2477. }
  2478. },
  2479.  
  2480. _over: function(event) {
  2481.  
  2482. var draggable = $.ui.ddmanager.current;
  2483.  
  2484. // Bail if draggable and droppable are same element
  2485. if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
  2486. return;
  2487. }
  2488.  
  2489. if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  2490. if(this.options.hoverClass) {
  2491. this.element.addClass(this.options.hoverClass);
  2492. }
  2493. this._trigger("over", event, this.ui(draggable));
  2494. }
  2495.  
  2496. },
  2497.  
  2498. _out: function(event) {
  2499.  
  2500. var draggable = $.ui.ddmanager.current;
  2501.  
  2502. // Bail if draggable and droppable are same element
  2503. if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
  2504. return;
  2505. }
  2506.  
  2507. if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  2508. if(this.options.hoverClass) {
  2509. this.element.removeClass(this.options.hoverClass);
  2510. }
  2511. this._trigger("out", event, this.ui(draggable));
  2512. }
  2513.  
  2514. },
  2515.  
  2516. _drop: function(event,custom) {
  2517.  
  2518. var draggable = custom || $.ui.ddmanager.current,
  2519. childrenIntersection = false;
  2520.  
  2521. // Bail if draggable and droppable are same element
  2522. if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
  2523. return false;
  2524. }
  2525.  
  2526. this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function() {
  2527. var inst = $.data(this, "ui-droppable");
  2528. if(
  2529. inst.options.greedy &&
  2530. !inst.options.disabled &&
  2531. inst.options.scope === draggable.options.scope &&
  2532. inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element)) &&
  2533. $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
  2534. ) { childrenIntersection = true; return false; }
  2535. });
  2536. if(childrenIntersection) {
  2537. return false;
  2538. }
  2539.  
  2540. if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  2541. if(this.options.activeClass) {
  2542. this.element.removeClass(this.options.activeClass);
  2543. }
  2544. if(this.options.hoverClass) {
  2545. this.element.removeClass(this.options.hoverClass);
  2546. }
  2547. this._trigger("drop", event, this.ui(draggable));
  2548. return this.element;
  2549. }
  2550.  
  2551. return false;
  2552.  
  2553. },
  2554.  
  2555. ui: function(c) {
  2556. return {
  2557. draggable: (c.currentItem || c.element),
  2558. helper: c.helper,
  2559. position: c.position,
  2560. offset: c.positionAbs
  2561. };
  2562. }
  2563.  
  2564. });
  2565.  
  2566. $.ui.intersect = function(draggable, droppable, toleranceMode) {
  2567.  
  2568. if (!droppable.offset) {
  2569. return false;
  2570. }
  2571.  
  2572. var draggableLeft, draggableTop,
  2573. x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
  2574. y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height,
  2575. l = droppable.offset.left, r = l + droppable.proportions.width,
  2576. t = droppable.offset.top, b = t + droppable.proportions.height;
  2577.  
  2578. switch (toleranceMode) {
  2579. case "fit":
  2580. return (l <= x1 && x2 <= r && t <= y1 && y2 <= b);
  2581. case "intersect":
  2582. return (l < x1 + (draggable.helperProportions.width / 2) && // Right Half
  2583. x2 - (draggable.helperProportions.width / 2) < r && // Left Half
  2584. t < y1 + (draggable.helperProportions.height / 2) && // Bottom Half
  2585. y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
  2586. case "pointer":
  2587. draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left);
  2588. draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top);
  2589. return isOverAxis( draggableTop, t, droppable.proportions.height ) && isOverAxis( draggableLeft, l, droppable.proportions.width );
  2590. case "touch":
  2591. return (
  2592. (y1 >= t && y1 <= b) || // Top edge touching
  2593. (y2 >= t && y2 <= b) || // Bottom edge touching
  2594. (y1 < t && y2 > b) // Surrounded vertically
  2595. ) && (
  2596. (x1 >= l && x1 <= r) || // Left edge touching
  2597. (x2 >= l && x2 <= r) || // Right edge touching
  2598. (x1 < l && x2 > r) // Surrounded horizontally
  2599. );
  2600. default:
  2601. return false;
  2602. }
  2603.  
  2604. };
  2605.  
  2606. /*
  2607. This manager tracks offsets of draggables and droppables
  2608. */
  2609. $.ui.ddmanager = {
  2610. current: null,
  2611. droppables: { "default": [] },
  2612. prepareOffsets: function(t, event) {
  2613.  
  2614. var i, j,
  2615. m = $.ui.ddmanager.droppables[t.options.scope] || [],
  2616. type = event ? event.type : null, // workaround for #2317
  2617. list = (t.currentItem || t.element).find(":data(ui-droppable)").addBack();
  2618.  
  2619. droppablesLoop: for (i = 0; i < m.length; i++) {
  2620.  
  2621. //No disabled and non-accepted
  2622. if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) {
  2623. continue;
  2624. }
  2625.  
  2626. // Filter out elements in the current dragged item
  2627. for (j=0; j < list.length; j++) {
  2628. if(list[j] === m[i].element[0]) {
  2629. m[i].proportions.height = 0;
  2630. continue droppablesLoop;
  2631. }
  2632. }
  2633.  
  2634. m[i].visible = m[i].element.css("display") !== "none";
  2635. if(!m[i].visible) {
  2636. continue;
  2637. }
  2638.  
  2639. //Activate the droppable if used directly from draggables
  2640. if(type === "mousedown") {
  2641. m[i]._activate.call(m[i], event);
  2642. }
  2643.  
  2644. m[i].offset = m[i].element.offset();
  2645. m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
  2646.  
  2647. }
  2648.  
  2649. },
  2650. drop: function(draggable, event) {
  2651.  
  2652. var dropped = false;
  2653. // Create a copy of the droppables in case the list changes during the drop (#9116)
  2654. $.each(($.ui.ddmanager.droppables[draggable.options.scope] || []).slice(), function() {
  2655.  
  2656. if(!this.options) {
  2657. return;
  2658. }
  2659. if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) {
  2660. dropped = this._drop.call(this, event) || dropped;
  2661. }
  2662.  
  2663. if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
  2664. this.isout = true;
  2665. this.isover = false;
  2666. this._deactivate.call(this, event);
  2667. }
  2668.  
  2669. });
  2670. return dropped;
  2671.  
  2672. },
  2673. dragStart: function( draggable, event ) {
  2674. //Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003)
  2675. draggable.element.parentsUntil( "body" ).bind( "scroll.droppable", function() {
  2676. if( !draggable.options.refreshPositions ) {
  2677. $.ui.ddmanager.prepareOffsets( draggable, event );
  2678. }
  2679. });
  2680. },
  2681. drag: function(draggable, event) {
  2682.  
  2683. //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
  2684. if(draggable.options.refreshPositions) {
  2685. $.ui.ddmanager.prepareOffsets(draggable, event);
  2686. }
  2687.  
  2688. //Run through all droppables and check their positions based on specific tolerance options
  2689. $.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
  2690.  
  2691. if(this.options.disabled || this.greedyChild || !this.visible) {
  2692. return;
  2693. }
  2694.  
  2695. var parentInstance, scope, parent,
  2696. intersects = $.ui.intersect(draggable, this, this.options.tolerance),
  2697. c = !intersects && this.isover ? "isout" : (intersects && !this.isover ? "isover" : null);
  2698. if(!c) {
  2699. return;
  2700. }
  2701.  
  2702. if (this.options.greedy) {
  2703. // find droppable parents with same scope
  2704. scope = this.options.scope;
  2705. parent = this.element.parents(":data(ui-droppable)").filter(function () {
  2706. return $.data(this, "ui-droppable").options.scope === scope;
  2707. });
  2708.  
  2709. if (parent.length) {
  2710. parentInstance = $.data(parent[0], "ui-droppable");
  2711. parentInstance.greedyChild = (c === "isover");
  2712. }
  2713. }
  2714.  
  2715. // we just moved into a greedy child
  2716. if (parentInstance && c === "isover") {
  2717. parentInstance.isover = false;
  2718. parentInstance.isout = true;
  2719. parentInstance._out.call(parentInstance, event);
  2720. }
  2721.  
  2722. this[c] = true;
  2723. this[c === "isout" ? "isover" : "isout"] = false;
  2724. this[c === "isover" ? "_over" : "_out"].call(this, event);
  2725.  
  2726. // we just moved out of a greedy child
  2727. if (parentInstance && c === "isout") {
  2728. parentInstance.isout = false;
  2729. parentInstance.isover = true;
  2730. parentInstance._over.call(parentInstance, event);
  2731. }
  2732. });
  2733.  
  2734. },
  2735. dragStop: function( draggable, event ) {
  2736. draggable.element.parentsUntil( "body" ).unbind( "scroll.droppable" );
  2737. //Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003)
  2738. if( !draggable.options.refreshPositions ) {
  2739. $.ui.ddmanager.prepareOffsets( draggable, event );
  2740. }
  2741. }
  2742. };
  2743.  
  2744. })(jQuery);
  2745. (function( $, undefined ) {
  2746.  
  2747. function num(v) {
  2748. return parseInt(v, 10) || 0;
  2749. }
  2750.  
  2751. function isNumber(value) {
  2752. return !isNaN(parseInt(value, 10));
  2753. }
  2754.  
  2755. $.widget("ui.resizable", $.ui.mouse, {
  2756. version: "1.10.2",
  2757. widgetEventPrefix: "resize",
  2758. options: {
  2759. alsoResize: false,
  2760. animate: false,
  2761. animateDuration: "slow",
  2762. animateEasing: "swing",
  2763. aspectRatio: false,
  2764. autoHide: false,
  2765. containment: false,
  2766. ghost: false,
  2767. grid: false,
  2768. handles: "e,s,se",
  2769. helper: false,
  2770. maxHeight: null,
  2771. maxWidth: null,
  2772. minHeight: 10,
  2773. minWidth: 10,
  2774. // See #7960
  2775. zIndex: 90,
  2776.  
  2777. // callbacks
  2778. resize: null,
  2779. start: null,
  2780. stop: null
  2781. },
  2782. _create: function() {
  2783.  
  2784. var n, i, handle, axis, hname,
  2785. that = this,
  2786. o = this.options;
  2787. this.element.addClass("ui-resizable");
  2788.  
  2789. $.extend(this, {
  2790. _aspectRatio: !!(o.aspectRatio),
  2791. aspectRatio: o.aspectRatio,
  2792. originalElement: this.element,
  2793. _proportionallyResizeElements: [],
  2794. _helper: o.helper || o.ghost || o.animate ? o.helper || "ui-resizable-helper" : null
  2795. });
  2796.  
  2797. //Wrap the element if it cannot hold child nodes
  2798. if(this.element[0].nodeName.match(/canvas|textarea|input|select|button|img/i)) {
  2799.  
  2800. //Create a wrapper element and set the wrapper to the new current internal element
  2801. this.element.wrap(
  2802. $("<div class='ui-wrapper' style='overflow: hidden;'></div>").css({
  2803. position: this.element.css("position"),
  2804. width: this.element.outerWidth(),
  2805. height: this.element.outerHeight(),
  2806. top: this.element.css("top"),
  2807. left: this.element.css("left")
  2808. })
  2809. );
  2810.  
  2811. //Overwrite the original this.element
  2812. this.element = this.element.parent().data(
  2813. "ui-resizable", this.element.data("ui-resizable")
  2814. );
  2815.  
  2816. this.elementIsWrapper = true;
  2817.  
  2818. //Move margins to the wrapper
  2819. this.element.css({ marginLeft: this.originalElement.css("marginLeft"), marginTop: this.originalElement.css("marginTop"), marginRight: this.originalElement.css("marginRight"), marginBottom: this.originalElement.css("marginBottom") });
  2820. this.originalElement.css({ marginLeft: 0, marginTop: 0, marginRight: 0, marginBottom: 0});
  2821.  
  2822. //Prevent Safari textarea resize
  2823. this.originalResizeStyle = this.originalElement.css("resize");
  2824. this.originalElement.css("resize", "none");
  2825.  
  2826. //Push the actual element to our proportionallyResize internal array
  2827. this._proportionallyResizeElements.push(this.originalElement.css({ position: "static", zoom: 1, display: "block" }));
  2828.  
  2829. // avoid IE jump (hard set the margin)
  2830. this.originalElement.css({ margin: this.originalElement.css("margin") });
  2831.  
  2832. // fix handlers offset
  2833. this._proportionallyResize();
  2834.  
  2835. }
  2836.  
  2837. 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" });
  2838. if(this.handles.constructor === String) {
  2839.  
  2840. if ( this.handles === "all") {
  2841. this.handles = "n,e,s,w,se,sw,ne,nw";
  2842. }
  2843.  
  2844. n = this.handles.split(",");
  2845. this.handles = {};
  2846.  
  2847. for(i = 0; i < n.length; i++) {
  2848.  
  2849. handle = $.trim(n[i]);
  2850. hname = "ui-resizable-"+handle;
  2851. axis = $("<div class='ui-resizable-handle " + hname + "'></div>");
  2852.  
  2853. // Apply zIndex to all handles - see #7960
  2854. axis.css({ zIndex: o.zIndex });
  2855.  
  2856. //TODO : What's going on here?
  2857. if ("se" === handle) {
  2858. axis.addClass("ui-icon ui-icon-gripsmall-diagonal-se");
  2859. }
  2860.  
  2861. //Insert into internal handles object and append to element
  2862. this.handles[handle] = ".ui-resizable-"+handle;
  2863. this.element.append(axis);
  2864. }
  2865.  
  2866. }
  2867.  
  2868. this._renderAxis = function(target) {
  2869.  
  2870. var i, axis, padPos, padWrapper;
  2871.  
  2872. target = target || this.element;
  2873.  
  2874. for(i in this.handles) {
  2875.  
  2876. if(this.handles[i].constructor === String) {
  2877. this.handles[i] = $(this.handles[i], this.element).show();
  2878. }
  2879.  
  2880. //Apply pad to wrapper element, needed to fix axis position (textarea, inputs, scrolls)
  2881. if (this.elementIsWrapper && this.originalElement[0].nodeName.match(/textarea|input|select|button/i)) {
  2882.  
  2883. axis = $(this.handles[i], this.element);
  2884.  
  2885. //Checking the correct pad and border
  2886. padWrapper = /sw|ne|nw|se|n|s/.test(i) ? axis.outerHeight() : axis.outerWidth();
  2887.  
  2888. //The padding type i have to apply...
  2889. padPos = [ "padding",
  2890. /ne|nw|n/.test(i) ? "Top" :
  2891. /se|sw|s/.test(i) ? "Bottom" :
  2892. /^e$/.test(i) ? "Right" : "Left" ].join("");
  2893.  
  2894. target.css(padPos, padWrapper);
  2895.  
  2896. this._proportionallyResize();
  2897.  
  2898. }
  2899.  
  2900. //TODO: What's that good for? There's not anything to be executed left
  2901. if(!$(this.handles[i]).length) {
  2902. continue;
  2903. }
  2904. }
  2905. };
  2906.  
  2907. //TODO: make renderAxis a prototype function
  2908. this._renderAxis(this.element);
  2909.  
  2910. this._handles = $(".ui-resizable-handle", this.element)
  2911. .disableSelection();
  2912.  
  2913. //Matching axis name
  2914. this._handles.mouseover(function() {
  2915. if (!that.resizing) {
  2916. if (this.className) {
  2917. axis = this.className.match(/ui-resizable-(se|sw|ne|nw|n|e|s|w)/i);
  2918. }
  2919. //Axis, default = se
  2920. that.axis = axis && axis[1] ? axis[1] : "se";
  2921. }
  2922. });
  2923.  
  2924. //If we want to auto hide the elements
  2925. if (o.autoHide) {
  2926. this._handles.hide();
  2927. $(this.element)
  2928. .addClass("ui-resizable-autohide")
  2929. .mouseenter(function() {
  2930. if (o.disabled) {
  2931. return;
  2932. }
  2933. $(this).removeClass("ui-resizable-autohide");
  2934. that._handles.show();
  2935. })
  2936. .mouseleave(function(){
  2937. if (o.disabled) {
  2938. return;
  2939. }
  2940. if (!that.resizing) {
  2941. $(this).addClass("ui-resizable-autohide");
  2942. that._handles.hide();
  2943. }
  2944. });
  2945. }
  2946.  
  2947. //Initialize the mouse interaction
  2948. this._mouseInit();
  2949.  
  2950. },
  2951.  
  2952. _destroy: function() {
  2953.  
  2954. this._mouseDestroy();
  2955.  
  2956. var wrapper,
  2957. _destroy = function(exp) {
  2958. $(exp).removeClass("ui-resizable ui-resizable-disabled ui-resizable-resizing")
  2959. .removeData("resizable").removeData("ui-resizable").unbind(".resizable").find(".ui-resizable-handle").remove();
  2960. };
  2961.  
  2962. //TODO: Unwrap at same DOM position
  2963. if (this.elementIsWrapper) {
  2964. _destroy(this.element);
  2965. wrapper = this.element;
  2966. this.originalElement.css({
  2967. position: wrapper.css("position"),
  2968. width: wrapper.outerWidth(),
  2969. height: wrapper.outerHeight(),
  2970. top: wrapper.css("top"),
  2971. left: wrapper.css("left")
  2972. }).insertAfter( wrapper );
  2973. wrapper.remove();
  2974. }
  2975.  
  2976. this.originalElement.css("resize", this.originalResizeStyle);
  2977. _destroy(this.originalElement);
  2978.  
  2979. return this;
  2980. },
  2981.  
  2982. _mouseCapture: function(event) {
  2983. var i, handle,
  2984. capture = false;
  2985.  
  2986. for (i in this.handles) {
  2987. handle = $(this.handles[i])[0];
  2988. if (handle === event.target || $.contains(handle, event.target)) {
  2989. capture = true;
  2990. }
  2991. }
  2992.  
  2993. return !this.options.disabled && capture;
  2994. },
  2995.  
  2996. _mouseStart: function(event) {
  2997.  
  2998. var curleft, curtop, cursor,
  2999. o = this.options,
  3000. iniPos = this.element.position(),
  3001. el = this.element;
  3002.  
  3003. this.resizing = true;
  3004.  
  3005. // bugfix for http://dev.jquery.com/ticket/1749
  3006. if ( (/absolute/).test( el.css("position") ) ) {
  3007. el.css({ position: "absolute", top: el.css("top"), left: el.css("left") });
  3008. } else if (el.is(".ui-draggable")) {
  3009. el.css({ position: "absolute", top: iniPos.top, left: iniPos.left });
  3010. }
  3011.  
  3012. this._renderProxy();
  3013.  
  3014. curleft = num(this.helper.css("left"));
  3015. curtop = num(this.helper.css("top"));
  3016.  
  3017. if (o.containment) {
  3018. curleft += $(o.containment).scrollLeft() || 0;
  3019. curtop += $(o.containment).scrollTop() || 0;
  3020. }
  3021.  
  3022. //Store needed variables
  3023. this.offset = this.helper.offset();
  3024. this.position = { left: curleft, top: curtop };
  3025. this.size = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  3026. this.originalSize = this._helper ? { width: el.outerWidth(), height: el.outerHeight() } : { width: el.width(), height: el.height() };
  3027. this.originalPosition = { left: curleft, top: curtop };
  3028. this.sizeDiff = { width: el.outerWidth() - el.width(), height: el.outerHeight() - el.height() };
  3029. this.originalMousePosition = { left: event.pageX, top: event.pageY };
  3030.  
  3031. //Aspect Ratio
  3032. this.aspectRatio = (typeof o.aspectRatio === "number") ? o.aspectRatio : ((this.originalSize.width / this.originalSize.height) || 1);
  3033.  
  3034. cursor = $(".ui-resizable-" + this.axis).css("cursor");
  3035. $("body").css("cursor", cursor === "auto" ? this.axis + "-resize" : cursor);
  3036.  
  3037. el.addClass("ui-resizable-resizing");
  3038. this._propagate("start", event);
  3039. return true;
  3040. },
  3041.  
  3042. _mouseDrag: function(event) {
  3043.  
  3044. //Increase performance, avoid regex
  3045. var data,
  3046. el = this.helper, props = {},
  3047. smp = this.originalMousePosition,
  3048. a = this.axis,
  3049. prevTop = this.position.top,
  3050. prevLeft = this.position.left,
  3051. prevWidth = this.size.width,
  3052. prevHeight = this.size.height,
  3053. dx = (event.pageX-smp.left)||0,
  3054. dy = (event.pageY-smp.top)||0,
  3055. trigger = this._change[a];
  3056.  
  3057. if (!trigger) {
  3058. return false;
  3059. }
  3060.  
  3061. // Calculate the attrs that will be change
  3062. data = trigger.apply(this, [event, dx, dy]);
  3063.  
  3064. // Put this in the mouseDrag handler since the user can start pressing shift while resizing
  3065. this._updateVirtualBoundaries(event.shiftKey);
  3066. if (this._aspectRatio || event.shiftKey) {
  3067. data = this._updateRatio(data, event);
  3068. }
  3069.  
  3070. data = this._respectSize(data, event);
  3071.  
  3072. this._updateCache(data);
  3073.  
  3074. // plugins callbacks need to be called first
  3075. this._propagate("resize", event);
  3076.  
  3077. if (this.position.top !== prevTop) {
  3078. props.top = this.position.top + "px";
  3079. }
  3080. if (this.position.left !== prevLeft) {
  3081. props.left = this.position.left + "px";
  3082. }
  3083. if (this.size.width !== prevWidth) {
  3084. props.width = this.size.width + "px";
  3085. }
  3086. if (this.size.height !== prevHeight) {
  3087. props.height = this.size.height + "px";
  3088. }
  3089. el.css(props);
  3090.  
  3091. if (!this._helper && this._proportionallyResizeElements.length) {
  3092. this._proportionallyResize();
  3093. }
  3094.  
  3095. // Call the user callback if the element was resized
  3096. if ( ! $.isEmptyObject(props) ) {
  3097. this._trigger("resize", event, this.ui());
  3098. }
  3099.  
  3100. return false;
  3101. },
  3102.  
  3103. _mouseStop: function(event) {
  3104.  
  3105. this.resizing = false;
  3106. var pr, ista, soffseth, soffsetw, s, left, top,
  3107. o = this.options, that = this;
  3108.  
  3109. if(this._helper) {
  3110.  
  3111. pr = this._proportionallyResizeElements;
  3112. ista = pr.length && (/textarea/i).test(pr[0].nodeName);
  3113. soffseth = ista && $.ui.hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height;
  3114. soffsetw = ista ? 0 : that.sizeDiff.width;
  3115.  
  3116. s = { width: (that.helper.width() - soffsetw), height: (that.helper.height() - soffseth) };
  3117. left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null;
  3118. top = (parseInt(that.element.css("top"), 10) + (that.position.top - that.originalPosition.top)) || null;
  3119.  
  3120. if (!o.animate) {
  3121. this.element.css($.extend(s, { top: top, left: left }));
  3122. }
  3123.  
  3124. that.helper.height(that.size.height);
  3125. that.helper.width(that.size.width);
  3126.  
  3127. if (this._helper && !o.animate) {
  3128. this._proportionallyResize();
  3129. }
  3130. }
  3131.  
  3132. $("body").css("cursor", "auto");
  3133.  
  3134. this.element.removeClass("ui-resizable-resizing");
  3135.  
  3136. this._propagate("stop", event);
  3137.  
  3138. if (this._helper) {
  3139. this.helper.remove();
  3140. }
  3141.  
  3142. return false;
  3143.  
  3144. },
  3145.  
  3146. _updateVirtualBoundaries: function(forceAspectRatio) {
  3147. var pMinWidth, pMaxWidth, pMinHeight, pMaxHeight, b,
  3148. o = this.options;
  3149.  
  3150. b = {
  3151. minWidth: isNumber(o.minWidth) ? o.minWidth : 0,
  3152. maxWidth: isNumber(o.maxWidth) ? o.maxWidth : Infinity,
  3153. minHeight: isNumber(o.minHeight) ? o.minHeight : 0,
  3154. maxHeight: isNumber(o.maxHeight) ? o.maxHeight : Infinity
  3155. };
  3156.  
  3157. if(this._aspectRatio || forceAspectRatio) {
  3158. // We want to create an enclosing box whose aspect ration is the requested one
  3159. // First, compute the "projected" size for each dimension based on the aspect ratio and other dimension
  3160. pMinWidth = b.minHeight * this.aspectRatio;
  3161. pMinHeight = b.minWidth / this.aspectRatio;
  3162. pMaxWidth = b.maxHeight * this.aspectRatio;
  3163. pMaxHeight = b.maxWidth / this.aspectRatio;
  3164.  
  3165. if(pMinWidth > b.minWidth) {
  3166. b.minWidth = pMinWidth;
  3167. }
  3168. if(pMinHeight > b.minHeight) {
  3169. b.minHeight = pMinHeight;
  3170. }
  3171. if(pMaxWidth < b.maxWidth) {
  3172. b.maxWidth = pMaxWidth;
  3173. }
  3174. if(pMaxHeight < b.maxHeight) {
  3175. b.maxHeight = pMaxHeight;
  3176. }
  3177. }
  3178. this._vBoundaries = b;
  3179. },
  3180.  
  3181. _updateCache: function(data) {
  3182. this.offset = this.helper.offset();
  3183. if (isNumber(data.left)) {
  3184. this.position.left = data.left;
  3185. }
  3186. if (isNumber(data.top)) {
  3187. this.position.top = data.top;
  3188. }
  3189. if (isNumber(data.height)) {
  3190. this.size.height = data.height;
  3191. }
  3192. if (isNumber(data.width)) {
  3193. this.size.width = data.width;
  3194. }
  3195. },
  3196.  
  3197. _updateRatio: function( data ) {
  3198.  
  3199. var cpos = this.position,
  3200. csize = this.size,
  3201. a = this.axis;
  3202.  
  3203. if (isNumber(data.height)) {
  3204. data.width = (data.height * this.aspectRatio);
  3205. } else if (isNumber(data.width)) {
  3206. data.height = (data.width / this.aspectRatio);
  3207. }
  3208.  
  3209. if (a === "sw") {
  3210. data.left = cpos.left + (csize.width - data.width);
  3211. data.top = null;
  3212. }
  3213. if (a === "nw") {
  3214. data.top = cpos.top + (csize.height - data.height);
  3215. data.left = cpos.left + (csize.width - data.width);
  3216. }
  3217.  
  3218. return data;
  3219. },
  3220.  
  3221. _respectSize: function( data ) {
  3222.  
  3223. var o = this._vBoundaries,
  3224. a = this.axis,
  3225. ismaxw = isNumber(data.width) && o.maxWidth && (o.maxWidth < data.width), ismaxh = isNumber(data.height) && o.maxHeight && (o.maxHeight < data.height),
  3226. isminw = isNumber(data.width) && o.minWidth && (o.minWidth > data.width), isminh = isNumber(data.height) && o.minHeight && (o.minHeight > data.height),
  3227. dw = this.originalPosition.left + this.originalSize.width,
  3228. dh = this.position.top + this.size.height,
  3229. cw = /sw|nw|w/.test(a), ch = /nw|ne|n/.test(a);
  3230. if (isminw) {
  3231. data.width = o.minWidth;
  3232. }
  3233. if (isminh) {
  3234. data.height = o.minHeight;
  3235. }
  3236. if (ismaxw) {
  3237. data.width = o.maxWidth;
  3238. }
  3239. if (ismaxh) {
  3240. data.height = o.maxHeight;
  3241. }
  3242.  
  3243. if (isminw && cw) {
  3244. data.left = dw - o.minWidth;
  3245. }
  3246. if (ismaxw && cw) {
  3247. data.left = dw - o.maxWidth;
  3248. }
  3249. if (isminh && ch) {
  3250. data.top = dh - o.minHeight;
  3251. }
  3252. if (ismaxh && ch) {
  3253. data.top = dh - o.maxHeight;
  3254. }
  3255.  
  3256. // fixing jump error on top/left - bug #2330
  3257. if (!data.width && !data.height && !data.left && data.top) {
  3258. data.top = null;
  3259. } else if (!data.width && !data.height && !data.top && data.left) {
  3260. data.left = null;
  3261. }
  3262.  
  3263. return data;
  3264. },
  3265.  
  3266. _proportionallyResize: function() {
  3267.  
  3268. if (!this._proportionallyResizeElements.length) {
  3269. return;
  3270. }
  3271.  
  3272. var i, j, borders, paddings, prel,
  3273. element = this.helper || this.element;
  3274.  
  3275. for ( i=0; i < this._proportionallyResizeElements.length; i++) {
  3276.  
  3277. prel = this._proportionallyResizeElements[i];
  3278.  
  3279. if (!this.borderDif) {
  3280. this.borderDif = [];
  3281. borders = [prel.css("borderTopWidth"), prel.css("borderRightWidth"), prel.css("borderBottomWidth"), prel.css("borderLeftWidth")];
  3282. paddings = [prel.css("paddingTop"), prel.css("paddingRight"), prel.css("paddingBottom"), prel.css("paddingLeft")];
  3283.  
  3284. for ( j = 0; j < borders.length; j++ ) {
  3285. this.borderDif[ j ] = ( parseInt( borders[ j ], 10 ) || 0 ) + ( parseInt( paddings[ j ], 10 ) || 0 );
  3286. }
  3287. }
  3288.  
  3289. prel.css({
  3290. height: (element.height() - this.borderDif[0] - this.borderDif[2]) || 0,
  3291. width: (element.width() - this.borderDif[1] - this.borderDif[3]) || 0
  3292. });
  3293.  
  3294. }
  3295.  
  3296. },
  3297.  
  3298. _renderProxy: function() {
  3299.  
  3300. var el = this.element, o = this.options;
  3301. this.elementOffset = el.offset();
  3302.  
  3303. if(this._helper) {
  3304.  
  3305. this.helper = this.helper || $("<div style='overflow:hidden;'></div>");
  3306.  
  3307. this.helper.addClass(this._helper).css({
  3308. width: this.element.outerWidth() - 1,
  3309. height: this.element.outerHeight() - 1,
  3310. position: "absolute",
  3311. left: this.elementOffset.left +"px",
  3312. top: this.elementOffset.top +"px",
  3313. zIndex: ++o.zIndex //TODO: Don't modify option
  3314. });
  3315.  
  3316. this.helper
  3317. .appendTo("body")
  3318. .disableSelection();
  3319.  
  3320. } else {
  3321. this.helper = this.element;
  3322. }
  3323.  
  3324. },
  3325.  
  3326. _change: {
  3327. e: function(event, dx) {
  3328. return { width: this.originalSize.width + dx };
  3329. },
  3330. w: function(event, dx) {
  3331. var cs = this.originalSize, sp = this.originalPosition;
  3332. return { left: sp.left + dx, width: cs.width - dx };
  3333. },
  3334. n: function(event, dx, dy) {
  3335. var cs = this.originalSize, sp = this.originalPosition;
  3336. return { top: sp.top + dy, height: cs.height - dy };
  3337. },
  3338. s: function(event, dx, dy) {
  3339. return { height: this.originalSize.height + dy };
  3340. },
  3341. se: function(event, dx, dy) {
  3342. return $.extend(this._change.s.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  3343. },
  3344. sw: function(event, dx, dy) {
  3345. return $.extend(this._change.s.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  3346. },
  3347. ne: function(event, dx, dy) {
  3348. return $.extend(this._change.n.apply(this, arguments), this._change.e.apply(this, [event, dx, dy]));
  3349. },
  3350. nw: function(event, dx, dy) {
  3351. return $.extend(this._change.n.apply(this, arguments), this._change.w.apply(this, [event, dx, dy]));
  3352. }
  3353. },
  3354.  
  3355. _propagate: function(n, event) {
  3356. $.ui.plugin.call(this, n, [event, this.ui()]);
  3357. (n !== "resize" && this._trigger(n, event, this.ui()));
  3358. },
  3359.  
  3360. plugins: {},
  3361.  
  3362. ui: function() {
  3363. return {
  3364. originalElement: this.originalElement,
  3365. element: this.element,
  3366. helper: this.helper,
  3367. position: this.position,
  3368. size: this.size,
  3369. originalSize: this.originalSize,
  3370. originalPosition: this.originalPosition
  3371. };
  3372. }
  3373.  
  3374. });
  3375.  
  3376. /*
  3377. * Resizable Extensions
  3378. */
  3379.  
  3380. $.ui.plugin.add("resizable", "animate", {
  3381.  
  3382. stop: function( event ) {
  3383. var that = $(this).data("ui-resizable"),
  3384. o = that.options,
  3385. pr = that._proportionallyResizeElements,
  3386. ista = pr.length && (/textarea/i).test(pr[0].nodeName),
  3387. soffseth = ista && $.ui.hasScroll(pr[0], "left") /* TODO - jump height */ ? 0 : that.sizeDiff.height,
  3388. soffsetw = ista ? 0 : that.sizeDiff.width,
  3389. style = { width: (that.size.width - soffsetw), height: (that.size.height - soffseth) },
  3390. left = (parseInt(that.element.css("left"), 10) + (that.position.left - that.originalPosition.left)) || null,
  3391. top = (parseInt(that.element.css("top"), 10) + (that.position.top - that.originalPosition.top)) || null;
  3392.  
  3393. that.element.animate(
  3394. $.extend(style, top && left ? { top: top, left: left } : {}), {
  3395. duration: o.animateDuration,
  3396. easing: o.animateEasing,
  3397. step: function() {
  3398.  
  3399. var data = {
  3400. width: parseInt(that.element.css("width"), 10),
  3401. height: parseInt(that.element.css("height"), 10),
  3402. top: parseInt(that.element.css("top"), 10),
  3403. left: parseInt(that.element.css("left"), 10)
  3404. };
  3405.  
  3406. if (pr && pr.length) {
  3407. $(pr[0]).css({ width: data.width, height: data.height });
  3408. }
  3409.  
  3410. // propagating resize, and updating values for each animation step
  3411. that._updateCache(data);
  3412. that._propagate("resize", event);
  3413.  
  3414. }
  3415. }
  3416. );
  3417. }
  3418.  
  3419. });
  3420.  
  3421. $.ui.plugin.add("resizable", "containment", {
  3422.  
  3423. start: function() {
  3424. var element, p, co, ch, cw, width, height,
  3425. that = $(this).data("ui-resizable"),
  3426. o = that.options,
  3427. el = that.element,
  3428. oc = o.containment,
  3429. ce = (oc instanceof $) ? oc.get(0) : (/parent/.test(oc)) ? el.parent().get(0) : oc;
  3430.  
  3431. if (!ce) {
  3432. return;
  3433. }
  3434.  
  3435. that.containerElement = $(ce);
  3436.  
  3437. if (/document/.test(oc) || oc === document) {
  3438. that.containerOffset = { left: 0, top: 0 };
  3439. that.containerPosition = { left: 0, top: 0 };
  3440.  
  3441. that.parentData = {
  3442. element: $(document), left: 0, top: 0,
  3443. width: $(document).width(), height: $(document).height() || document.body.parentNode.scrollHeight
  3444. };
  3445. }
  3446.  
  3447. // i'm a node, so compute top, left, right, bottom
  3448. else {
  3449. element = $(ce);
  3450. p = [];
  3451. $([ "Top", "Right", "Left", "Bottom" ]).each(function(i, name) { p[i] = num(element.css("padding" + name)); });
  3452.  
  3453. that.containerOffset = element.offset();
  3454. that.containerPosition = element.position();
  3455. that.containerSize = { height: (element.innerHeight() - p[3]), width: (element.innerWidth() - p[1]) };
  3456.  
  3457. co = that.containerOffset;
  3458. ch = that.containerSize.height;
  3459. cw = that.containerSize.width;
  3460. width = ($.ui.hasScroll(ce, "left") ? ce.scrollWidth : cw );
  3461. height = ($.ui.hasScroll(ce) ? ce.scrollHeight : ch);
  3462.  
  3463. that.parentData = {
  3464. element: ce, left: co.left, top: co.top, width: width, height: height
  3465. };
  3466. }
  3467. },
  3468.  
  3469. resize: function( event ) {
  3470. var woset, hoset, isParent, isOffsetRelative,
  3471. that = $(this).data("ui-resizable"),
  3472. o = that.options,
  3473. co = that.containerOffset, cp = that.position,
  3474. pRatio = that._aspectRatio || event.shiftKey,
  3475. cop = { top:0, left:0 }, ce = that.containerElement;
  3476.  
  3477. if (ce[0] !== document && (/static/).test(ce.css("position"))) {
  3478. cop = co;
  3479. }
  3480.  
  3481. if (cp.left < (that._helper ? co.left : 0)) {
  3482. that.size.width = that.size.width + (that._helper ? (that.position.left - co.left) : (that.position.left - cop.left));
  3483. if (pRatio) {
  3484. that.size.height = that.size.width / that.aspectRatio;
  3485. }
  3486. that.position.left = o.helper ? co.left : 0;
  3487. }
  3488.  
  3489. if (cp.top < (that._helper ? co.top : 0)) {
  3490. that.size.height = that.size.height + (that._helper ? (that.position.top - co.top) : that.position.top);
  3491. if (pRatio) {
  3492. that.size.width = that.size.height * that.aspectRatio;
  3493. }
  3494. that.position.top = that._helper ? co.top : 0;
  3495. }
  3496.  
  3497. that.offset.left = that.parentData.left+that.position.left;
  3498. that.offset.top = that.parentData.top+that.position.top;
  3499.  
  3500. woset = Math.abs( (that._helper ? that.offset.left - cop.left : (that.offset.left - cop.left)) + that.sizeDiff.width );
  3501. hoset = Math.abs( (that._helper ? that.offset.top - cop.top : (that.offset.top - co.top)) + that.sizeDiff.height );
  3502.  
  3503. isParent = that.containerElement.get(0) === that.element.parent().get(0);
  3504. isOffsetRelative = /relative|absolute/.test(that.containerElement.css("position"));
  3505.  
  3506. if(isParent && isOffsetRelative) {
  3507. woset -= that.parentData.left;
  3508. }
  3509.  
  3510. if (woset + that.size.width >= that.parentData.width) {
  3511. that.size.width = that.parentData.width - woset;
  3512. if (pRatio) {
  3513. that.size.height = that.size.width / that.aspectRatio;
  3514. }
  3515. }
  3516.  
  3517. if (hoset + that.size.height >= that.parentData.height) {
  3518. that.size.height = that.parentData.height - hoset;
  3519. if (pRatio) {
  3520. that.size.width = that.size.height * that.aspectRatio;
  3521. }
  3522. }
  3523. },
  3524.  
  3525. stop: function(){
  3526. var that = $(this).data("ui-resizable"),
  3527. o = that.options,
  3528. co = that.containerOffset,
  3529. cop = that.containerPosition,
  3530. ce = that.containerElement,
  3531. helper = $(that.helper),
  3532. ho = helper.offset(),
  3533. w = helper.outerWidth() - that.sizeDiff.width,
  3534. h = helper.outerHeight() - that.sizeDiff.height;
  3535.  
  3536. if (that._helper && !o.animate && (/relative/).test(ce.css("position"))) {
  3537. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  3538. }
  3539.  
  3540. if (that._helper && !o.animate && (/static/).test(ce.css("position"))) {
  3541. $(this).css({ left: ho.left - cop.left - co.left, width: w, height: h });
  3542. }
  3543.  
  3544. }
  3545. });
  3546.  
  3547. $.ui.plugin.add("resizable", "alsoResize", {
  3548.  
  3549. start: function () {
  3550. var that = $(this).data("ui-resizable"),
  3551. o = that.options,
  3552. _store = function (exp) {
  3553. $(exp).each(function() {
  3554. var el = $(this);
  3555. el.data("ui-resizable-alsoresize", {
  3556. width: parseInt(el.width(), 10), height: parseInt(el.height(), 10),
  3557. left: parseInt(el.css("left"), 10), top: parseInt(el.css("top"), 10)
  3558. });
  3559. });
  3560. };
  3561.  
  3562. if (typeof(o.alsoResize) === "object" && !o.alsoResize.parentNode) {
  3563. if (o.alsoResize.length) { o.alsoResize = o.alsoResize[0]; _store(o.alsoResize); }
  3564. else { $.each(o.alsoResize, function (exp) { _store(exp); }); }
  3565. }else{
  3566. _store(o.alsoResize);
  3567. }
  3568. },
  3569.  
  3570. resize: function (event, ui) {
  3571. var that = $(this).data("ui-resizable"),
  3572. o = that.options,
  3573. os = that.originalSize,
  3574. op = that.originalPosition,
  3575. delta = {
  3576. height: (that.size.height - os.height) || 0, width: (that.size.width - os.width) || 0,
  3577. top: (that.position.top - op.top) || 0, left: (that.position.left - op.left) || 0
  3578. },
  3579.  
  3580. _alsoResize = function (exp, c) {
  3581. $(exp).each(function() {
  3582. var el = $(this), start = $(this).data("ui-resizable-alsoresize"), style = {},
  3583. css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ["width", "height"] : ["width", "height", "top", "left"];
  3584.  
  3585. $.each(css, function (i, prop) {
  3586. var sum = (start[prop]||0) + (delta[prop]||0);
  3587. if (sum && sum >= 0) {
  3588. style[prop] = sum || null;
  3589. }
  3590. });
  3591.  
  3592. el.css(style);
  3593. });
  3594. };
  3595.  
  3596. if (typeof(o.alsoResize) === "object" && !o.alsoResize.nodeType) {
  3597. $.each(o.alsoResize, function (exp, c) { _alsoResize(exp, c); });
  3598. }else{
  3599. _alsoResize(o.alsoResize);
  3600. }
  3601. },
  3602.  
  3603. stop: function () {
  3604. $(this).removeData("resizable-alsoresize");
  3605. }
  3606. });
  3607.  
  3608. $.ui.plugin.add("resizable", "ghost", {
  3609.  
  3610. start: function() {
  3611.  
  3612. var that = $(this).data("ui-resizable"), o = that.options, cs = that.size;
  3613.  
  3614. that.ghost = that.originalElement.clone();
  3615. that.ghost
  3616. .css({ opacity: 0.25, display: "block", position: "relative", height: cs.height, width: cs.width, margin: 0, left: 0, top: 0 })
  3617. .addClass("ui-resizable-ghost")
  3618. .addClass(typeof o.ghost === "string" ? o.ghost : "");
  3619.  
  3620. that.ghost.appendTo(that.helper);
  3621.  
  3622. },
  3623.  
  3624. resize: function(){
  3625. var that = $(this).data("ui-resizable");
  3626. if (that.ghost) {
  3627. that.ghost.css({ position: "relative", height: that.size.height, width: that.size.width });
  3628. }
  3629. },
  3630.  
  3631. stop: function() {
  3632. var that = $(this).data("ui-resizable");
  3633. if (that.ghost && that.helper) {
  3634. that.helper.get(0).removeChild(that.ghost.get(0));
  3635. }
  3636. }
  3637.  
  3638. });
  3639.  
  3640. $.ui.plugin.add("resizable", "grid", {
  3641.  
  3642. resize: function() {
  3643. var that = $(this).data("ui-resizable"),
  3644. o = that.options,
  3645. cs = that.size,
  3646. os = that.originalSize,
  3647. op = that.originalPosition,
  3648. a = that.axis,
  3649. grid = typeof o.grid === "number" ? [o.grid, o.grid] : o.grid,
  3650. gridX = (grid[0]||1),
  3651. gridY = (grid[1]||1),
  3652. ox = Math.round((cs.width - os.width) / gridX) * gridX,
  3653. oy = Math.round((cs.height - os.height) / gridY) * gridY,
  3654. newWidth = os.width + ox,
  3655. newHeight = os.height + oy,
  3656. isMaxWidth = o.maxWidth && (o.maxWidth < newWidth),
  3657. isMaxHeight = o.maxHeight && (o.maxHeight < newHeight),
  3658. isMinWidth = o.minWidth && (o.minWidth > newWidth),
  3659. isMinHeight = o.minHeight && (o.minHeight > newHeight);
  3660.  
  3661. o.grid = grid;
  3662.  
  3663. if (isMinWidth) {
  3664. newWidth = newWidth + gridX;
  3665. }
  3666. if (isMinHeight) {
  3667. newHeight = newHeight + gridY;
  3668. }
  3669. if (isMaxWidth) {
  3670. newWidth = newWidth - gridX;
  3671. }
  3672. if (isMaxHeight) {
  3673. newHeight = newHeight - gridY;
  3674. }
  3675.  
  3676. if (/^(se|s|e)$/.test(a)) {
  3677. that.size.width = newWidth;
  3678. that.size.height = newHeight;
  3679. } else if (/^(ne)$/.test(a)) {
  3680. that.size.width = newWidth;
  3681. that.size.height = newHeight;
  3682. that.position.top = op.top - oy;
  3683. } else if (/^(sw)$/.test(a)) {
  3684. that.size.width = newWidth;
  3685. that.size.height = newHeight;
  3686. that.position.left = op.left - ox;
  3687. } else {
  3688. that.size.width = newWidth;
  3689. that.size.height = newHeight;
  3690. that.position.top = op.top - oy;
  3691. that.position.left = op.left - ox;
  3692. }
  3693. }
  3694.  
  3695. });
  3696.  
  3697. })(jQuery);
  3698. (function( $, undefined ) {
  3699.  
  3700. $.widget("ui.selectable", $.ui.mouse, {
  3701. version: "1.10.2",
  3702. options: {
  3703. appendTo: "body",
  3704. autoRefresh: true,
  3705. distance: 0,
  3706. filter: "*",
  3707. tolerance: "touch",
  3708.  
  3709. // callbacks
  3710. selected: null,
  3711. selecting: null,
  3712. start: null,
  3713. stop: null,
  3714. unselected: null,
  3715. unselecting: null
  3716. },
  3717. _create: function() {
  3718. var selectees,
  3719. that = this;
  3720.  
  3721. this.element.addClass("ui-selectable");
  3722.  
  3723. this.dragged = false;
  3724.  
  3725. // cache selectee children based on filter
  3726. this.refresh = function() {
  3727. selectees = $(that.options.filter, that.element[0]);
  3728. selectees.addClass("ui-selectee");
  3729. selectees.each(function() {
  3730. var $this = $(this),
  3731. pos = $this.offset();
  3732. $.data(this, "selectable-item", {
  3733. element: this,
  3734. $element: $this,
  3735. left: pos.left,
  3736. top: pos.top,
  3737. right: pos.left + $this.outerWidth(),
  3738. bottom: pos.top + $this.outerHeight(),
  3739. startselected: false,
  3740. selected: $this.hasClass("ui-selected"),
  3741. selecting: $this.hasClass("ui-selecting"),
  3742. unselecting: $this.hasClass("ui-unselecting")
  3743. });
  3744. });
  3745. };
  3746. this.refresh();
  3747.  
  3748. this.selectees = selectees.addClass("ui-selectee");
  3749.  
  3750. this._mouseInit();
  3751.  
  3752. this.helper = $("<div class='ui-selectable-helper'></div>");
  3753. },
  3754.  
  3755. _destroy: function() {
  3756. this.selectees
  3757. .removeClass("ui-selectee")
  3758. .removeData("selectable-item");
  3759. this.element
  3760. .removeClass("ui-selectable ui-selectable-disabled");
  3761. this._mouseDestroy();
  3762. },
  3763.  
  3764. _mouseStart: function(event) {
  3765. var that = this,
  3766. options = this.options;
  3767.  
  3768. this.opos = [event.pageX, event.pageY];
  3769.  
  3770. if (this.options.disabled) {
  3771. return;
  3772. }
  3773.  
  3774. this.selectees = $(options.filter, this.element[0]);
  3775.  
  3776. this._trigger("start", event);
  3777.  
  3778. $(options.appendTo).append(this.helper);
  3779. // position helper (lasso)
  3780. this.helper.css({
  3781. "left": event.pageX,
  3782. "top": event.pageY,
  3783. "width": 0,
  3784. "height": 0
  3785. });
  3786.  
  3787. if (options.autoRefresh) {
  3788. this.refresh();
  3789. }
  3790.  
  3791. this.selectees.filter(".ui-selected").each(function() {
  3792. var selectee = $.data(this, "selectable-item");
  3793. selectee.startselected = true;
  3794. if (!event.metaKey && !event.ctrlKey) {
  3795. selectee.$element.removeClass("ui-selected");
  3796. selectee.selected = false;
  3797. selectee.$element.addClass("ui-unselecting");
  3798. selectee.unselecting = true;
  3799. // selectable UNSELECTING callback
  3800. that._trigger("unselecting", event, {
  3801. unselecting: selectee.element
  3802. });
  3803. }
  3804. });
  3805.  
  3806. $(event.target).parents().addBack().each(function() {
  3807. var doSelect,
  3808. selectee = $.data(this, "selectable-item");
  3809. if (selectee) {
  3810. doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass("ui-selected");
  3811. selectee.$element
  3812. .removeClass(doSelect ? "ui-unselecting" : "ui-selected")
  3813. .addClass(doSelect ? "ui-selecting" : "ui-unselecting");
  3814. selectee.unselecting = !doSelect;
  3815. selectee.selecting = doSelect;
  3816. selectee.selected = doSelect;
  3817. // selectable (UN)SELECTING callback
  3818. if (doSelect) {
  3819. that._trigger("selecting", event, {
  3820. selecting: selectee.element
  3821. });
  3822. } else {
  3823. that._trigger("unselecting", event, {
  3824. unselecting: selectee.element
  3825. });
  3826. }
  3827. return false;
  3828. }
  3829. });
  3830.  
  3831. },
  3832.  
  3833. _mouseDrag: function(event) {
  3834.  
  3835. this.dragged = true;
  3836.  
  3837. if (this.options.disabled) {
  3838. return;
  3839. }
  3840.  
  3841. var tmp,
  3842. that = this,
  3843. options = this.options,
  3844. x1 = this.opos[0],
  3845. y1 = this.opos[1],
  3846. x2 = event.pageX,
  3847. y2 = event.pageY;
  3848.  
  3849. if (x1 > x2) { tmp = x2; x2 = x1; x1 = tmp; }
  3850. if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; }
  3851. this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1});
  3852.  
  3853. this.selectees.each(function() {
  3854. var selectee = $.data(this, "selectable-item"),
  3855. hit = false;
  3856.  
  3857. //prevent helper from being selected if appendTo: selectable
  3858. if (!selectee || selectee.element === that.element[0]) {
  3859. return;
  3860. }
  3861.  
  3862. if (options.tolerance === "touch") {
  3863. hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) );
  3864. } else if (options.tolerance === "fit") {
  3865. hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2);
  3866. }
  3867.  
  3868. if (hit) {
  3869. // SELECT
  3870. if (selectee.selected) {
  3871. selectee.$element.removeClass("ui-selected");
  3872. selectee.selected = false;
  3873. }
  3874. if (selectee.unselecting) {
  3875. selectee.$element.removeClass("ui-unselecting");
  3876. selectee.unselecting = false;
  3877. }
  3878. if (!selectee.selecting) {
  3879. selectee.$element.addClass("ui-selecting");
  3880. selectee.selecting = true;
  3881. // selectable SELECTING callback
  3882. that._trigger("selecting", event, {
  3883. selecting: selectee.element
  3884. });
  3885. }
  3886. } else {
  3887. // UNSELECT
  3888. if (selectee.selecting) {
  3889. if ((event.metaKey || event.ctrlKey) && selectee.startselected) {
  3890. selectee.$element.removeClass("ui-selecting");
  3891. selectee.selecting = false;
  3892. selectee.$element.addClass("ui-selected");
  3893. selectee.selected = true;
  3894. } else {
  3895. selectee.$element.removeClass("ui-selecting");
  3896. selectee.selecting = false;
  3897. if (selectee.startselected) {
  3898. selectee.$element.addClass("ui-unselecting");
  3899. selectee.unselecting = true;
  3900. }
  3901. // selectable UNSELECTING callback
  3902. that._trigger("unselecting", event, {
  3903. unselecting: selectee.element
  3904. });
  3905. }
  3906. }
  3907. if (selectee.selected) {
  3908. if (!event.metaKey && !event.ctrlKey && !selectee.startselected) {
  3909. selectee.$element.removeClass("ui-selected");
  3910. selectee.selected = false;
  3911.  
  3912. selectee.$element.addClass("ui-unselecting");
  3913. selectee.unselecting = true;
  3914. // selectable UNSELECTING callback
  3915. that._trigger("unselecting", event, {
  3916. unselecting: selectee.element
  3917. });
  3918. }
  3919. }
  3920. }
  3921. });
  3922.  
  3923. return false;
  3924. },
  3925.  
  3926. _mouseStop: function(event) {
  3927. var that = this;
  3928.  
  3929. this.dragged = false;
  3930.  
  3931. $(".ui-unselecting", this.element[0]).each(function() {
  3932. var selectee = $.data(this, "selectable-item");
  3933. selectee.$element.removeClass("ui-unselecting");
  3934. selectee.unselecting = false;
  3935. selectee.startselected = false;
  3936. that._trigger("unselected", event, {
  3937. unselected: selectee.element
  3938. });
  3939. });
  3940. $(".ui-selecting", this.element[0]).each(function() {
  3941. var selectee = $.data(this, "selectable-item");
  3942. selectee.$element.removeClass("ui-selecting").addClass("ui-selected");
  3943. selectee.selecting = false;
  3944. selectee.selected = true;
  3945. selectee.startselected = true;
  3946. that._trigger("selected", event, {
  3947. selected: selectee.element
  3948. });
  3949. });
  3950. this._trigger("stop", event);
  3951.  
  3952. this.helper.remove();
  3953.  
  3954. return false;
  3955. }
  3956.  
  3957. });
  3958.  
  3959. })(jQuery);
  3960. (function( $, undefined ) {
  3961.  
  3962. /*jshint loopfunc: true */
  3963.  
  3964. function isOverAxis( x, reference, size ) {
  3965. return ( x > reference ) && ( x < ( reference + size ) );
  3966. }
  3967.  
  3968. function isFloating(item) {
  3969. return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
  3970. }
  3971.  
  3972. $.widget("ui.sortable", $.ui.mouse, {
  3973. version: "1.10.2",
  3974. widgetEventPrefix: "sort",
  3975. ready: false,
  3976. options: {
  3977. appendTo: "parent",
  3978. axis: false,
  3979. connectWith: false,
  3980. containment: false,
  3981. cursor: "auto",
  3982. cursorAt: false,
  3983. dropOnEmpty: true,
  3984. forcePlaceholderSize: false,
  3985. forceHelperSize: false,
  3986. grid: false,
  3987. handle: false,
  3988. helper: "original",
  3989. items: "> *",
  3990. opacity: false,
  3991. placeholder: false,
  3992. revert: false,
  3993. scroll: true,
  3994. scrollSensitivity: 20,
  3995. scrollSpeed: 20,
  3996. scope: "default",
  3997. tolerance: "intersect",
  3998. zIndex: 1000,
  3999.  
  4000. // callbacks
  4001. activate: null,
  4002. beforeStop: null,
  4003. change: null,
  4004. deactivate: null,
  4005. out: null,
  4006. over: null,
  4007. receive: null,
  4008. remove: null,
  4009. sort: null,
  4010. start: null,
  4011. stop: null,
  4012. update: null
  4013. },
  4014. _create: function() {
  4015.  
  4016. var o = this.options;
  4017. this.containerCache = {};
  4018. this.element.addClass("ui-sortable");
  4019.  
  4020. //Get the items
  4021. this.refresh();
  4022.  
  4023. //Let's determine if the items are being displayed horizontally
  4024. this.floating = this.items.length ? o.axis === "x" || isFloating(this.items[0].item) : false;
  4025.  
  4026. //Let's determine the parent's offset
  4027. this.offset = this.element.offset();
  4028.  
  4029. //Initialize mouse events for interaction
  4030. this._mouseInit();
  4031.  
  4032. //We're ready to go
  4033. this.ready = true;
  4034.  
  4035. },
  4036.  
  4037. _destroy: function() {
  4038. this.element
  4039. .removeClass("ui-sortable ui-sortable-disabled");
  4040. this._mouseDestroy();
  4041.  
  4042. for ( var i = this.items.length - 1; i >= 0; i-- ) {
  4043. this.items[i].item.removeData(this.widgetName + "-item");
  4044. }
  4045.  
  4046. return this;
  4047. },
  4048.  
  4049. _setOption: function(key, value){
  4050. if ( key === "disabled" ) {
  4051. this.options[ key ] = value;
  4052.  
  4053. this.widget().toggleClass( "ui-sortable-disabled", !!value );
  4054. } else {
  4055. // Don't call widget base _setOption for disable as it adds ui-state-disabled class
  4056. $.Widget.prototype._setOption.apply(this, arguments);
  4057. }
  4058. },
  4059.  
  4060. _mouseCapture: function(event, overrideHandle) {
  4061. var currentItem = null,
  4062. validHandle = false,
  4063. that = this;
  4064.  
  4065. if (this.reverting) {
  4066. return false;
  4067. }
  4068.  
  4069. if(this.options.disabled || this.options.type === "static") {
  4070. return false;
  4071. }
  4072.  
  4073. //We have to refresh the items data once first
  4074. this._refreshItems(event);
  4075.  
  4076. //Find out if the clicked node (or one of its parents) is a actual item in this.items
  4077. $(event.target).parents().each(function() {
  4078. if($.data(this, that.widgetName + "-item") === that) {
  4079. currentItem = $(this);
  4080. return false;
  4081. }
  4082. });
  4083. if($.data(event.target, that.widgetName + "-item") === that) {
  4084. currentItem = $(event.target);
  4085. }
  4086.  
  4087. if(!currentItem) {
  4088. return false;
  4089. }
  4090. if(this.options.handle && !overrideHandle) {
  4091. $(this.options.handle, currentItem).find("*").addBack().each(function() {
  4092. if(this === event.target) {
  4093. validHandle = true;
  4094. }
  4095. });
  4096. if(!validHandle) {
  4097. return false;
  4098. }
  4099. }
  4100.  
  4101. this.currentItem = currentItem;
  4102. this._removeCurrentsFromItems();
  4103. return true;
  4104.  
  4105. },
  4106.  
  4107. _mouseStart: function(event, overrideHandle, noActivation) {
  4108.  
  4109. var i, body,
  4110. o = this.options;
  4111.  
  4112. this.currentContainer = this;
  4113.  
  4114. //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
  4115. this.refreshPositions();
  4116.  
  4117. //Create and append the visible helper
  4118. this.helper = this._createHelper(event);
  4119.  
  4120. //Cache the helper size
  4121. this._cacheHelperProportions();
  4122.  
  4123. /*
  4124. * - Position generation -
  4125. * This block generates everything position related - it's the core of draggables.
  4126. */
  4127.  
  4128. //Cache the margins of the original element
  4129. this._cacheMargins();
  4130.  
  4131. //Get the next scrolling parent
  4132. this.scrollParent = this.helper.scrollParent();
  4133.  
  4134. //The element's absolute position on the page minus margins
  4135. this.offset = this.currentItem.offset();
  4136. this.offset = {
  4137. top: this.offset.top - this.margins.top,
  4138. left: this.offset.left - this.margins.left
  4139. };
  4140.  
  4141. $.extend(this.offset, {
  4142. click: { //Where the click happened, relative to the element
  4143. left: event.pageX - this.offset.left,
  4144. top: event.pageY - this.offset.top
  4145. },
  4146. parent: this._getParentOffset(),
  4147. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  4148. });
  4149.  
  4150. // Only after we got the offset, we can change the helper's position to absolute
  4151. // TODO: Still need to figure out a way to make relative sorting possible
  4152. this.helper.css("position", "absolute");
  4153. this.cssPosition = this.helper.css("position");
  4154.  
  4155. //Generate the original position
  4156. this.originalPosition = this._generatePosition(event);
  4157. this.originalPageX = event.pageX;
  4158. this.originalPageY = event.pageY;
  4159.  
  4160. //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
  4161. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  4162.  
  4163. //Cache the former DOM position
  4164. this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
  4165.  
  4166. //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
  4167. if(this.helper[0] !== this.currentItem[0]) {
  4168. this.currentItem.hide();
  4169. }
  4170.  
  4171. //Create the placeholder
  4172. this._createPlaceholder();
  4173.  
  4174. //Set a containment if given in the options
  4175. if(o.containment) {
  4176. this._setContainment();
  4177. }
  4178.  
  4179. if( o.cursor && o.cursor !== "auto" ) { // cursor option
  4180. body = this.document.find( "body" );
  4181.  
  4182. // support: IE
  4183. this.storedCursor = body.css( "cursor" );
  4184. body.css( "cursor", o.cursor );
  4185.  
  4186. this.storedStylesheet = $( "<style>*{ cursor: "+o.cursor+" !important; }</style>" ).appendTo( body );
  4187. }
  4188.  
  4189. if(o.opacity) { // opacity option
  4190. if (this.helper.css("opacity")) {
  4191. this._storedOpacity = this.helper.css("opacity");
  4192. }
  4193. this.helper.css("opacity", o.opacity);
  4194. }
  4195.  
  4196. if(o.zIndex) { // zIndex option
  4197. if (this.helper.css("zIndex")) {
  4198. this._storedZIndex = this.helper.css("zIndex");
  4199. }
  4200. this.helper.css("zIndex", o.zIndex);
  4201. }
  4202.  
  4203. //Prepare scrolling
  4204. if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
  4205. this.overflowOffset = this.scrollParent.offset();
  4206. }
  4207.  
  4208. //Call callbacks
  4209. this._trigger("start", event, this._uiHash());
  4210.  
  4211. //Recache the helper size
  4212. if(!this._preserveHelperProportions) {
  4213. this._cacheHelperProportions();
  4214. }
  4215.  
  4216.  
  4217. //Post "activate" events to possible containers
  4218. if( !noActivation ) {
  4219. for ( i = this.containers.length - 1; i >= 0; i-- ) {
  4220. this.containers[ i ]._trigger( "activate", event, this._uiHash( this ) );
  4221. }
  4222. }
  4223.  
  4224. //Prepare possible droppables
  4225. if($.ui.ddmanager) {
  4226. $.ui.ddmanager.current = this;
  4227. }
  4228.  
  4229. if ($.ui.ddmanager && !o.dropBehaviour) {
  4230. $.ui.ddmanager.prepareOffsets(this, event);
  4231. }
  4232.  
  4233. this.dragging = true;
  4234.  
  4235. this.helper.addClass("ui-sortable-helper");
  4236. this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  4237. return true;
  4238.  
  4239. },
  4240.  
  4241. _mouseDrag: function(event) {
  4242. var i, item, itemElement, intersection,
  4243. o = this.options,
  4244. scrolled = false;
  4245.  
  4246. //Compute the helpers position
  4247. this.position = this._generatePosition(event);
  4248. this.positionAbs = this._convertPositionTo("absolute");
  4249.  
  4250. if (!this.lastPositionAbs) {
  4251. this.lastPositionAbs = this.positionAbs;
  4252. }
  4253.  
  4254. //Do scrolling
  4255. if(this.options.scroll) {
  4256. if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
  4257.  
  4258. if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
  4259. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
  4260. } else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) {
  4261. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
  4262. }
  4263.  
  4264. if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
  4265. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
  4266. } else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
  4267. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
  4268. }
  4269.  
  4270. } else {
  4271.  
  4272. if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
  4273. scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
  4274. } else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
  4275. scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
  4276. }
  4277.  
  4278. if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
  4279. scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
  4280. } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
  4281. scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
  4282. }
  4283.  
  4284. }
  4285.  
  4286. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
  4287. $.ui.ddmanager.prepareOffsets(this, event);
  4288. }
  4289. }
  4290.  
  4291. //Regenerate the absolute position used for position checks
  4292. this.positionAbs = this._convertPositionTo("absolute");
  4293.  
  4294. //Set the helper position
  4295. if(!this.options.axis || this.options.axis !== "y") {
  4296. this.helper[0].style.left = this.position.left+"px";
  4297. }
  4298. if(!this.options.axis || this.options.axis !== "x") {
  4299. this.helper[0].style.top = this.position.top+"px";
  4300. }
  4301.  
  4302. //Rearrange
  4303. for (i = this.items.length - 1; i >= 0; i--) {
  4304.  
  4305. //Cache variables and intersection, continue if no intersection
  4306. item = this.items[i];
  4307. itemElement = item.item[0];
  4308. intersection = this._intersectsWithPointer(item);
  4309. if (!intersection) {
  4310. continue;
  4311. }
  4312.  
  4313. // Only put the placeholder inside the current Container, skip all
  4314. // items form other containers. This works because when moving
  4315. // an item from one container to another the
  4316. // currentContainer is switched before the placeholder is moved.
  4317. //
  4318. // Without this moving items in "sub-sortables" can cause the placeholder to jitter
  4319. // beetween the outer and inner container.
  4320. if (item.instance !== this.currentContainer) {
  4321. continue;
  4322. }
  4323.  
  4324. // cannot intersect with itself
  4325. // no useless actions that have been done before
  4326. // no action if the item moved is the parent of the item checked
  4327. if (itemElement !== this.currentItem[0] &&
  4328. this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement &&
  4329. !$.contains(this.placeholder[0], itemElement) &&
  4330. (this.options.type === "semi-dynamic" ? !$.contains(this.element[0], itemElement) : true)
  4331. ) {
  4332.  
  4333. this.direction = intersection === 1 ? "down" : "up";
  4334.  
  4335. if (this.options.tolerance === "pointer" || this._intersectsWithSides(item)) {
  4336. this._rearrange(event, item);
  4337. } else {
  4338. break;
  4339. }
  4340.  
  4341. this._trigger("change", event, this._uiHash());
  4342. break;
  4343. }
  4344. }
  4345.  
  4346. //Post events to containers
  4347. this._contactContainers(event);
  4348.  
  4349. //Interconnect with droppables
  4350. if($.ui.ddmanager) {
  4351. $.ui.ddmanager.drag(this, event);
  4352. }
  4353.  
  4354. //Call callbacks
  4355. this._trigger("sort", event, this._uiHash());
  4356.  
  4357. this.lastPositionAbs = this.positionAbs;
  4358. return false;
  4359.  
  4360. },
  4361.  
  4362. _mouseStop: function(event, noPropagation) {
  4363.  
  4364. if(!event) {
  4365. return;
  4366. }
  4367.  
  4368. //If we are using droppables, inform the manager about the drop
  4369. if ($.ui.ddmanager && !this.options.dropBehaviour) {
  4370. $.ui.ddmanager.drop(this, event);
  4371. }
  4372.  
  4373. if(this.options.revert) {
  4374. var that = this,
  4375. cur = this.placeholder.offset(),
  4376. axis = this.options.axis,
  4377. animation = {};
  4378.  
  4379. if ( !axis || axis === "x" ) {
  4380. animation.left = cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollLeft);
  4381. }
  4382. if ( !axis || axis === "y" ) {
  4383. animation.top = cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollTop);
  4384. }
  4385. this.reverting = true;
  4386. $(this.helper).animate( animation, parseInt(this.options.revert, 10) || 500, function() {
  4387. that._clear(event);
  4388. });
  4389. } else {
  4390. this._clear(event, noPropagation);
  4391. }
  4392.  
  4393. return false;
  4394.  
  4395. },
  4396.  
  4397. cancel: function() {
  4398.  
  4399. if(this.dragging) {
  4400.  
  4401. this._mouseUp({ target: null });
  4402.  
  4403. if(this.options.helper === "original") {
  4404. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  4405. } else {
  4406. this.currentItem.show();
  4407. }
  4408.  
  4409. //Post deactivating events to containers
  4410. for (var i = this.containers.length - 1; i >= 0; i--){
  4411. this.containers[i]._trigger("deactivate", null, this._uiHash(this));
  4412. if(this.containers[i].containerCache.over) {
  4413. this.containers[i]._trigger("out", null, this._uiHash(this));
  4414. this.containers[i].containerCache.over = 0;
  4415. }
  4416. }
  4417.  
  4418. }
  4419.  
  4420. if (this.placeholder) {
  4421. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  4422. if(this.placeholder[0].parentNode) {
  4423. this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  4424. }
  4425. if(this.options.helper !== "original" && this.helper && this.helper[0].parentNode) {
  4426. this.helper.remove();
  4427. }
  4428.  
  4429. $.extend(this, {
  4430. helper: null,
  4431. dragging: false,
  4432. reverting: false,
  4433. _noFinalSort: null
  4434. });
  4435.  
  4436. if(this.domPosition.prev) {
  4437. $(this.domPosition.prev).after(this.currentItem);
  4438. } else {
  4439. $(this.domPosition.parent).prepend(this.currentItem);
  4440. }
  4441. }
  4442.  
  4443. return this;
  4444.  
  4445. },
  4446.  
  4447. serialize: function(o) {
  4448.  
  4449. var items = this._getItemsAsjQuery(o && o.connected),
  4450. str = [];
  4451. o = o || {};
  4452.  
  4453. $(items).each(function() {
  4454. var res = ($(o.item || this).attr(o.attribute || "id") || "").match(o.expression || (/(.+)[\-=_](.+)/));
  4455. if (res) {
  4456. str.push((o.key || res[1]+"[]")+"="+(o.key && o.expression ? res[1] : res[2]));
  4457. }
  4458. });
  4459.  
  4460. if(!str.length && o.key) {
  4461. str.push(o.key + "=");
  4462. }
  4463.  
  4464. return str.join("&");
  4465.  
  4466. },
  4467.  
  4468. toArray: function(o) {
  4469.  
  4470. var items = this._getItemsAsjQuery(o && o.connected),
  4471. ret = [];
  4472.  
  4473. o = o || {};
  4474.  
  4475. items.each(function() { ret.push($(o.item || this).attr(o.attribute || "id") || ""); });
  4476. return ret;
  4477.  
  4478. },
  4479.  
  4480. /* Be careful with the following core functions */
  4481. _intersectsWith: function(item) {
  4482.  
  4483. var x1 = this.positionAbs.left,
  4484. x2 = x1 + this.helperProportions.width,
  4485. y1 = this.positionAbs.top,
  4486. y2 = y1 + this.helperProportions.height,
  4487. l = item.left,
  4488. r = l + item.width,
  4489. t = item.top,
  4490. b = t + item.height,
  4491. dyClick = this.offset.click.top,
  4492. dxClick = this.offset.click.left,
  4493. isOverElement = (y1 + dyClick) > t && (y1 + dyClick) < b && (x1 + dxClick) > l && (x1 + dxClick) < r;
  4494.  
  4495. if ( this.options.tolerance === "pointer" ||
  4496. this.options.forcePointerForContainers ||
  4497. (this.options.tolerance !== "pointer" && this.helperProportions[this.floating ? "width" : "height"] > item[this.floating ? "width" : "height"])
  4498. ) {
  4499. return isOverElement;
  4500. } else {
  4501.  
  4502. return (l < x1 + (this.helperProportions.width / 2) && // Right Half
  4503. x2 - (this.helperProportions.width / 2) < r && // Left Half
  4504. t < y1 + (this.helperProportions.height / 2) && // Bottom Half
  4505. y2 - (this.helperProportions.height / 2) < b ); // Top Half
  4506.  
  4507. }
  4508. },
  4509.  
  4510. _intersectsWithPointer: function(item) {
  4511.  
  4512. var isOverElementHeight = (this.options.axis === "x") || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
  4513. isOverElementWidth = (this.options.axis === "y") || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
  4514. isOverElement = isOverElementHeight && isOverElementWidth,
  4515. verticalDirection = this._getDragVerticalDirection(),
  4516. horizontalDirection = this._getDragHorizontalDirection();
  4517.  
  4518. if (!isOverElement) {
  4519. return false;
  4520. }
  4521.  
  4522. return this.floating ?
  4523. ( ((horizontalDirection && horizontalDirection === "right") || verticalDirection === "down") ? 2 : 1 )
  4524. : ( verticalDirection && (verticalDirection === "down" ? 2 : 1) );
  4525.  
  4526. },
  4527.  
  4528. _intersectsWithSides: function(item) {
  4529.  
  4530. var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
  4531. isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
  4532. verticalDirection = this._getDragVerticalDirection(),
  4533. horizontalDirection = this._getDragHorizontalDirection();
  4534.  
  4535. if (this.floating && horizontalDirection) {
  4536. return ((horizontalDirection === "right" && isOverRightHalf) || (horizontalDirection === "left" && !isOverRightHalf));
  4537. } else {
  4538. return verticalDirection && ((verticalDirection === "down" && isOverBottomHalf) || (verticalDirection === "up" && !isOverBottomHalf));
  4539. }
  4540.  
  4541. },
  4542.  
  4543. _getDragVerticalDirection: function() {
  4544. var delta = this.positionAbs.top - this.lastPositionAbs.top;
  4545. return delta !== 0 && (delta > 0 ? "down" : "up");
  4546. },
  4547.  
  4548. _getDragHorizontalDirection: function() {
  4549. var delta = this.positionAbs.left - this.lastPositionAbs.left;
  4550. return delta !== 0 && (delta > 0 ? "right" : "left");
  4551. },
  4552.  
  4553. refresh: function(event) {
  4554. this._refreshItems(event);
  4555. this.refreshPositions();
  4556. return this;
  4557. },
  4558.  
  4559. _connectWith: function() {
  4560. var options = this.options;
  4561. return options.connectWith.constructor === String ? [options.connectWith] : options.connectWith;
  4562. },
  4563.  
  4564. _getItemsAsjQuery: function(connected) {
  4565.  
  4566. var i, j, cur, inst,
  4567. items = [],
  4568. queries = [],
  4569. connectWith = this._connectWith();
  4570.  
  4571. if(connectWith && connected) {
  4572. for (i = connectWith.length - 1; i >= 0; i--){
  4573. cur = $(connectWith[i]);
  4574. for ( j = cur.length - 1; j >= 0; j--){
  4575. inst = $.data(cur[j], this.widgetFullName);
  4576. if(inst && inst !== this && !inst.options.disabled) {
  4577. 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]);
  4578. }
  4579. }
  4580. }
  4581. }
  4582.  
  4583. 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]);
  4584.  
  4585. for (i = queries.length - 1; i >= 0; i--){
  4586. queries[i][0].each(function() {
  4587. items.push(this);
  4588. });
  4589. }
  4590.  
  4591. return $(items);
  4592.  
  4593. },
  4594.  
  4595. _removeCurrentsFromItems: function() {
  4596.  
  4597. var list = this.currentItem.find(":data(" + this.widgetName + "-item)");
  4598.  
  4599. this.items = $.grep(this.items, function (item) {
  4600. for (var j=0; j < list.length; j++) {
  4601. if(list[j] === item.item[0]) {
  4602. return false;
  4603. }
  4604. }
  4605. return true;
  4606. });
  4607.  
  4608. },
  4609.  
  4610. _refreshItems: function(event) {
  4611.  
  4612. this.items = [];
  4613. this.containers = [this];
  4614.  
  4615. var i, j, cur, inst, targetData, _queries, item, queriesLength,
  4616. items = this.items,
  4617. queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]],
  4618. connectWith = this._connectWith();
  4619.  
  4620. if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
  4621. for (i = connectWith.length - 1; i >= 0; i--){
  4622. cur = $(connectWith[i]);
  4623. for (j = cur.length - 1; j >= 0; j--){
  4624. inst = $.data(cur[j], this.widgetFullName);
  4625. if(inst && inst !== this && !inst.options.disabled) {
  4626. queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
  4627. this.containers.push(inst);
  4628. }
  4629. }
  4630. }
  4631. }
  4632.  
  4633. for (i = queries.length - 1; i >= 0; i--) {
  4634. targetData = queries[i][1];
  4635. _queries = queries[i][0];
  4636.  
  4637. for (j=0, queriesLength = _queries.length; j < queriesLength; j++) {
  4638. item = $(_queries[j]);
  4639.  
  4640. item.data(this.widgetName + "-item", targetData); // Data for target checking (mouse manager)
  4641.  
  4642. items.push({
  4643. item: item,
  4644. instance: targetData,
  4645. width: 0, height: 0,
  4646. left: 0, top: 0
  4647. });
  4648. }
  4649. }
  4650.  
  4651. },
  4652.  
  4653. refreshPositions: function(fast) {
  4654.  
  4655. //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
  4656. if(this.offsetParent && this.helper) {
  4657. this.offset.parent = this._getParentOffset();
  4658. }
  4659.  
  4660. var i, item, t, p;
  4661.  
  4662. for (i = this.items.length - 1; i >= 0; i--){
  4663. item = this.items[i];
  4664.  
  4665. //We ignore calculating positions of all connected containers when we're not over them
  4666. if(item.instance !== this.currentContainer && this.currentContainer && item.item[0] !== this.currentItem[0]) {
  4667. continue;
  4668. }
  4669.  
  4670. t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
  4671.  
  4672. if (!fast) {
  4673. item.width = t.outerWidth();
  4674. item.height = t.outerHeight();
  4675. }
  4676.  
  4677. p = t.offset();
  4678. item.left = p.left;
  4679. item.top = p.top;
  4680. }
  4681.  
  4682. if(this.options.custom && this.options.custom.refreshContainers) {
  4683. this.options.custom.refreshContainers.call(this);
  4684. } else {
  4685. for (i = this.containers.length - 1; i >= 0; i--){
  4686. p = this.containers[i].element.offset();
  4687. this.containers[i].containerCache.left = p.left;
  4688. this.containers[i].containerCache.top = p.top;
  4689. this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
  4690. this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
  4691. }
  4692. }
  4693.  
  4694. return this;
  4695. },
  4696.  
  4697. _createPlaceholder: function(that) {
  4698. that = that || this;
  4699. var className,
  4700. o = that.options;
  4701.  
  4702. if(!o.placeholder || o.placeholder.constructor === String) {
  4703. className = o.placeholder;
  4704. o.placeholder = {
  4705. element: function() {
  4706.  
  4707. var nodeName = that.currentItem[0].nodeName.toLowerCase(),
  4708. element = $( that.document[0].createElement( nodeName ) )
  4709. .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
  4710. .removeClass("ui-sortable-helper");
  4711.  
  4712. if ( nodeName === "tr" ) {
  4713. // Use a high colspan to force the td to expand the full
  4714. // width of the table (browsers are smart enough to
  4715. // handle this properly)
  4716. element.append( "<td colspan='99'>&#160;</td>" );
  4717. } else if ( nodeName === "img" ) {
  4718. element.attr( "src", that.currentItem.attr( "src" ) );
  4719. }
  4720.  
  4721. if ( !className ) {
  4722. element.css( "visibility", "hidden" );
  4723. }
  4724.  
  4725. return element;
  4726. },
  4727. update: function(container, p) {
  4728.  
  4729. // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that
  4730. // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified
  4731. if(className && !o.forcePlaceholderSize) {
  4732. return;
  4733. }
  4734.  
  4735. //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
  4736. if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css("paddingTop")||0, 10) - parseInt(that.currentItem.css("paddingBottom")||0, 10)); }
  4737. if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css("paddingLeft")||0, 10) - parseInt(that.currentItem.css("paddingRight")||0, 10)); }
  4738. }
  4739. };
  4740. }
  4741.  
  4742. //Create the placeholder
  4743. that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));
  4744.  
  4745. //Append it after the actual current item
  4746. that.currentItem.after(that.placeholder);
  4747.  
  4748. //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
  4749. o.placeholder.update(that, that.placeholder);
  4750.  
  4751. },
  4752.  
  4753. _contactContainers: function(event) {
  4754. var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom, floating,
  4755. innermostContainer = null,
  4756. innermostIndex = null;
  4757.  
  4758. // get innermost container that intersects with item
  4759. for (i = this.containers.length - 1; i >= 0; i--) {
  4760.  
  4761. // never consider a container that's located within the item itself
  4762. if($.contains(this.currentItem[0], this.containers[i].element[0])) {
  4763. continue;
  4764. }
  4765.  
  4766. if(this._intersectsWith(this.containers[i].containerCache)) {
  4767.  
  4768. // if we've already found a container and it's more "inner" than this, then continue
  4769. if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0])) {
  4770. continue;
  4771. }
  4772.  
  4773. innermostContainer = this.containers[i];
  4774. innermostIndex = i;
  4775.  
  4776. } else {
  4777. // container doesn't intersect. trigger "out" event if necessary
  4778. if(this.containers[i].containerCache.over) {
  4779. this.containers[i]._trigger("out", event, this._uiHash(this));
  4780. this.containers[i].containerCache.over = 0;
  4781. }
  4782. }
  4783.  
  4784. }
  4785.  
  4786. // if no intersecting containers found, return
  4787. if(!innermostContainer) {
  4788. return;
  4789. }
  4790.  
  4791. // move the item into the container if it's not there already
  4792. if(this.containers.length === 1) {
  4793. if (!this.containers[innermostIndex].containerCache.over) {
  4794. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  4795. this.containers[innermostIndex].containerCache.over = 1;
  4796. }
  4797. } else {
  4798.  
  4799. //When entering a new container, we will find the item with the least distance and append our item near it
  4800. dist = 10000;
  4801. itemWithLeastDistance = null;
  4802. floating = innermostContainer.floating || isFloating(this.currentItem);
  4803. posProperty = floating ? "left" : "top";
  4804. sizeProperty = floating ? "width" : "height";
  4805. base = this.positionAbs[posProperty] + this.offset.click[posProperty];
  4806. for (j = this.items.length - 1; j >= 0; j--) {
  4807. if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) {
  4808. continue;
  4809. }
  4810. if(this.items[j].item[0] === this.currentItem[0]) {
  4811. continue;
  4812. }
  4813. if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
  4814. continue;
  4815. }
  4816. cur = this.items[j].item.offset()[posProperty];
  4817. nearBottom = false;
  4818. if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
  4819. nearBottom = true;
  4820. cur += this.items[j][sizeProperty];
  4821. }
  4822.  
  4823. if(Math.abs(cur - base) < dist) {
  4824. dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
  4825. this.direction = nearBottom ? "up": "down";
  4826. }
  4827. }
  4828.  
  4829. //Check if dropOnEmpty is enabled
  4830. if(!itemWithLeastDistance && !this.options.dropOnEmpty) {
  4831. return;
  4832. }
  4833.  
  4834. if(this.currentContainer === this.containers[innermostIndex]) {
  4835. return;
  4836. }
  4837.  
  4838. itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
  4839. this._trigger("change", event, this._uiHash());
  4840. this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
  4841. this.currentContainer = this.containers[innermostIndex];
  4842.  
  4843. //Update the placeholder
  4844. this.options.placeholder.update(this.currentContainer, this.placeholder);
  4845.  
  4846. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  4847. this.containers[innermostIndex].containerCache.over = 1;
  4848. }
  4849.  
  4850.  
  4851. },
  4852.  
  4853. _createHelper: function(event) {
  4854.  
  4855. var o = this.options,
  4856. helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper === "clone" ? this.currentItem.clone() : this.currentItem);
  4857.  
  4858. //Add the helper to the DOM if that didn't happen already
  4859. if(!helper.parents("body").length) {
  4860. $(o.appendTo !== "parent" ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
  4861. }
  4862.  
  4863. if(helper[0] === this.currentItem[0]) {
  4864. 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") };
  4865. }
  4866.  
  4867. if(!helper[0].style.width || o.forceHelperSize) {
  4868. helper.width(this.currentItem.width());
  4869. }
  4870. if(!helper[0].style.height || o.forceHelperSize) {
  4871. helper.height(this.currentItem.height());
  4872. }
  4873.  
  4874. return helper;
  4875.  
  4876. },
  4877.  
  4878. _adjustOffsetFromHelper: function(obj) {
  4879. if (typeof obj === "string") {
  4880. obj = obj.split(" ");
  4881. }
  4882. if ($.isArray(obj)) {
  4883. obj = {left: +obj[0], top: +obj[1] || 0};
  4884. }
  4885. if ("left" in obj) {
  4886. this.offset.click.left = obj.left + this.margins.left;
  4887. }
  4888. if ("right" in obj) {
  4889. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  4890. }
  4891. if ("top" in obj) {
  4892. this.offset.click.top = obj.top + this.margins.top;
  4893. }
  4894. if ("bottom" in obj) {
  4895. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  4896. }
  4897. },
  4898.  
  4899. _getParentOffset: function() {
  4900.  
  4901.  
  4902. //Get the offsetParent and cache its position
  4903. this.offsetParent = this.helper.offsetParent();
  4904. var po = this.offsetParent.offset();
  4905.  
  4906. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  4907. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  4908. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  4909. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  4910. if(this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  4911. po.left += this.scrollParent.scrollLeft();
  4912. po.top += this.scrollParent.scrollTop();
  4913. }
  4914.  
  4915. // This needs to be actually done for all browsers, since pageX/pageY includes this information
  4916. // with an ugly IE fix
  4917. if( this.offsetParent[0] === document.body || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
  4918. po = { top: 0, left: 0 };
  4919. }
  4920.  
  4921. return {
  4922. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  4923. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  4924. };
  4925.  
  4926. },
  4927.  
  4928. _getRelativeOffset: function() {
  4929.  
  4930. if(this.cssPosition === "relative") {
  4931. var p = this.currentItem.position();
  4932. return {
  4933. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  4934. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  4935. };
  4936. } else {
  4937. return { top: 0, left: 0 };
  4938. }
  4939.  
  4940. },
  4941.  
  4942. _cacheMargins: function() {
  4943. this.margins = {
  4944. left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
  4945. top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
  4946. };
  4947. },
  4948.  
  4949. _cacheHelperProportions: function() {
  4950. this.helperProportions = {
  4951. width: this.helper.outerWidth(),
  4952. height: this.helper.outerHeight()
  4953. };
  4954. },
  4955.  
  4956. _setContainment: function() {
  4957.  
  4958. var ce, co, over,
  4959. o = this.options;
  4960. if(o.containment === "parent") {
  4961. o.containment = this.helper[0].parentNode;
  4962. }
  4963. if(o.containment === "document" || o.containment === "window") {
  4964. this.containment = [
  4965. 0 - this.offset.relative.left - this.offset.parent.left,
  4966. 0 - this.offset.relative.top - this.offset.parent.top,
  4967. $(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,
  4968. ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  4969. ];
  4970. }
  4971.  
  4972. if(!(/^(document|window|parent)$/).test(o.containment)) {
  4973. ce = $(o.containment)[0];
  4974. co = $(o.containment).offset();
  4975. over = ($(ce).css("overflow") !== "hidden");
  4976.  
  4977. this.containment = [
  4978. co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left,
  4979. co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top,
  4980. 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,
  4981. 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
  4982. ];
  4983. }
  4984.  
  4985. },
  4986.  
  4987. _convertPositionTo: function(d, pos) {
  4988.  
  4989. if(!pos) {
  4990. pos = this.position;
  4991. }
  4992. var mod = d === "absolute" ? 1 : -1,
  4993. scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
  4994. scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  4995.  
  4996. return {
  4997. top: (
  4998. pos.top + // The absolute mouse position
  4999. this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  5000. this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
  5001. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  5002. ),
  5003. left: (
  5004. pos.left + // The absolute mouse position
  5005. this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  5006. this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
  5007. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  5008. )
  5009. };
  5010.  
  5011. },
  5012.  
  5013. _generatePosition: function(event) {
  5014.  
  5015. var top, left,
  5016. o = this.options,
  5017. pageX = event.pageX,
  5018. pageY = event.pageY,
  5019. 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);
  5020.  
  5021. // This is another very weird special case that only happens for relative elements:
  5022. // 1. If the css position is relative
  5023. // 2. and the scroll parent is the document or similar to the offset parent
  5024. // we have to refresh the relative offset during the scroll so there are no jumps
  5025. if(this.cssPosition === "relative" && !(this.scrollParent[0] !== document && this.scrollParent[0] !== this.offsetParent[0])) {
  5026. this.offset.relative = this._getRelativeOffset();
  5027. }
  5028.  
  5029. /*
  5030. * - Position constraining -
  5031. * Constrain the position to a mix of grid, containment.
  5032. */
  5033.  
  5034. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  5035.  
  5036. if(this.containment) {
  5037. if(event.pageX - this.offset.click.left < this.containment[0]) {
  5038. pageX = this.containment[0] + this.offset.click.left;
  5039. }
  5040. if(event.pageY - this.offset.click.top < this.containment[1]) {
  5041. pageY = this.containment[1] + this.offset.click.top;
  5042. }
  5043. if(event.pageX - this.offset.click.left > this.containment[2]) {
  5044. pageX = this.containment[2] + this.offset.click.left;
  5045. }
  5046. if(event.pageY - this.offset.click.top > this.containment[3]) {
  5047. pageY = this.containment[3] + this.offset.click.top;
  5048. }
  5049. }
  5050.  
  5051. if(o.grid) {
  5052. top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
  5053. 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;
  5054.  
  5055. left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
  5056. 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;
  5057. }
  5058.  
  5059. }
  5060.  
  5061. return {
  5062. top: (
  5063. pageY - // The absolute mouse position
  5064. this.offset.click.top - // Click offset (relative to the element)
  5065. this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
  5066. this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
  5067. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  5068. ),
  5069. left: (
  5070. pageX - // The absolute mouse position
  5071. this.offset.click.left - // Click offset (relative to the element)
  5072. this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
  5073. this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
  5074. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  5075. )
  5076. };
  5077.  
  5078. },
  5079.  
  5080. _rearrange: function(event, i, a, hardRefresh) {
  5081.  
  5082. 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));
  5083.  
  5084. //Various things done here to improve the performance:
  5085. // 1. we create a setTimeout, that calls refreshPositions
  5086. // 2. on the instance, we have a counter variable, that get's higher after every append
  5087. // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
  5088. // 4. this lets only the last addition to the timeout stack through
  5089. this.counter = this.counter ? ++this.counter : 1;
  5090. var counter = this.counter;
  5091.  
  5092. this._delay(function() {
  5093. if(counter === this.counter) {
  5094. this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
  5095. }
  5096. });
  5097.  
  5098. },
  5099.  
  5100. _clear: function(event, noPropagation) {
  5101.  
  5102. this.reverting = false;
  5103. // We delay all events that have to be triggered to after the point where the placeholder has been removed and
  5104. // everything else normalized again
  5105. var i,
  5106. delayedTriggers = [];
  5107.  
  5108. // We first have to update the dom position of the actual currentItem
  5109. // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
  5110. if(!this._noFinalSort && this.currentItem.parent().length) {
  5111. this.placeholder.before(this.currentItem);
  5112. }
  5113. this._noFinalSort = null;
  5114.  
  5115. if(this.helper[0] === this.currentItem[0]) {
  5116. for(i in this._storedCSS) {
  5117. if(this._storedCSS[i] === "auto" || this._storedCSS[i] === "static") {
  5118. this._storedCSS[i] = "";
  5119. }
  5120. }
  5121. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  5122. } else {
  5123. this.currentItem.show();
  5124. }
  5125.  
  5126. if(this.fromOutside && !noPropagation) {
  5127. delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
  5128. }
  5129. if((this.fromOutside || this.domPosition.prev !== this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent !== this.currentItem.parent()[0]) && !noPropagation) {
  5130. delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
  5131. }
  5132.  
  5133. // Check if the items Container has Changed and trigger appropriate
  5134. // events.
  5135. if (this !== this.currentContainer) {
  5136. if(!noPropagation) {
  5137. delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); });
  5138. delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  5139. delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  5140. }
  5141. }
  5142.  
  5143.  
  5144. //Post events to containers
  5145. for (i = this.containers.length - 1; i >= 0; i--){
  5146. if(!noPropagation) {
  5147. delayedTriggers.push((function(c) { return function(event) { c._trigger("deactivate", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
  5148. }
  5149. if(this.containers[i].containerCache.over) {
  5150. delayedTriggers.push((function(c) { return function(event) { c._trigger("out", event, this._uiHash(this)); }; }).call(this, this.containers[i]));
  5151. this.containers[i].containerCache.over = 0;
  5152. }
  5153. }
  5154.  
  5155. //Do what was originally in plugins
  5156. if ( this.storedCursor ) {
  5157. this.document.find( "body" ).css( "cursor", this.storedCursor );
  5158. this.storedStylesheet.remove();
  5159. }
  5160. if(this._storedOpacity) {
  5161. this.helper.css("opacity", this._storedOpacity);
  5162. }
  5163. if(this._storedZIndex) {
  5164. this.helper.css("zIndex", this._storedZIndex === "auto" ? "" : this._storedZIndex);
  5165. }
  5166.  
  5167. this.dragging = false;
  5168. if(this.cancelHelperRemoval) {
  5169. if(!noPropagation) {
  5170. this._trigger("beforeStop", event, this._uiHash());
  5171. for (i=0; i < delayedTriggers.length; i++) {
  5172. delayedTriggers[i].call(this, event);
  5173. } //Trigger all delayed events
  5174. this._trigger("stop", event, this._uiHash());
  5175. }
  5176.  
  5177. this.fromOutside = false;
  5178. return false;
  5179. }
  5180.  
  5181. if(!noPropagation) {
  5182. this._trigger("beforeStop", event, this._uiHash());
  5183. }
  5184.  
  5185. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  5186. this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  5187.  
  5188. if(this.helper[0] !== this.currentItem[0]) {
  5189. this.helper.remove();
  5190. }
  5191. this.helper = null;
  5192.  
  5193. if(!noPropagation) {
  5194. for (i=0; i < delayedTriggers.length; i++) {
  5195. delayedTriggers[i].call(this, event);
  5196. } //Trigger all delayed events
  5197. this._trigger("stop", event, this._uiHash());
  5198. }
  5199.  
  5200. this.fromOutside = false;
  5201. return true;
  5202.  
  5203. },
  5204.  
  5205. _trigger: function() {
  5206. if ($.Widget.prototype._trigger.apply(this, arguments) === false) {
  5207. this.cancel();
  5208. }
  5209. },
  5210.  
  5211. _uiHash: function(_inst) {
  5212. var inst = _inst || this;
  5213. return {
  5214. helper: inst.helper,
  5215. placeholder: inst.placeholder || $([]),
  5216. position: inst.position,
  5217. originalPosition: inst.originalPosition,
  5218. offset: inst.positionAbs,
  5219. item: inst.currentItem,
  5220. sender: _inst ? _inst.element : null
  5221. };
  5222. }
  5223.  
  5224. });
  5225.  
  5226. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement