sonata_jqueryui_js_jquery.ui.sortable_8.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  1. /*!
  2. * jQuery UI Sortable 1.10.4
  3. * http://jqueryui.com
  4. *
  5. * Copyright 2014 jQuery Foundation and other contributors
  6. * Released under the MIT license.
  7. * http://jquery.org/license
  8. *
  9. * http://api.jqueryui.com/sortable/
  10. *
  11. * Depends:
  12. * jquery.ui.core.js
  13. * jquery.ui.mouse.js
  14. * jquery.ui.widget.js
  15. */
  16. (function( $, undefined ) {
  17. function isOverAxis( x, reference, size ) {
  18. return ( x > reference ) && ( x < ( reference + size ) );
  19. }
  20. function isFloating(item) {
  21. return (/left|right/).test(item.css("float")) || (/inline|table-cell/).test(item.css("display"));
  22. }
  23. $.widget("ui.sortable", $.ui.mouse, {
  24. version: "1.10.4",
  25. widgetEventPrefix: "sort",
  26. ready: false,
  27. options: {
  28. appendTo: "parent",
  29. axis: false,
  30. connectWith: false,
  31. containment: false,
  32. cursor: "auto",
  33. cursorAt: false,
  34. dropOnEmpty: true,
  35. forcePlaceholderSize: false,
  36. forceHelperSize: false,
  37. grid: false,
  38. handle: false,
  39. helper: "original",
  40. items: "> *",
  41. opacity: false,
  42. placeholder: false,
  43. revert: false,
  44. scroll: true,
  45. scrollSensitivity: 20,
  46. scrollSpeed: 20,
  47. scope: "default",
  48. tolerance: "intersect",
  49. zIndex: 1000,
  50. // callbacks
  51. activate: null,
  52. beforeStop: null,
  53. change: null,
  54. deactivate: null,
  55. out: null,
  56. over: null,
  57. receive: null,
  58. remove: null,
  59. sort: null,
  60. start: null,
  61. stop: null,
  62. update: null
  63. },
  64. _create: function() {
  65. var o = this.options;
  66. this.containerCache = {};
  67. this.element.addClass("ui-sortable");
  68. //Get the items
  69. this.refresh();
  70. //Let's determine if the items are being displayed horizontally
  71. this.floating = this.items.length ? o.axis === "x" || isFloating(this.items[0].item) : false;
  72. //Let's determine the parent's offset
  73. this.offset = this.element.offset();
  74. //Initialize mouse events for interaction
  75. this._mouseInit();
  76. //We're ready to go
  77. this.ready = true;
  78. },
  79. _destroy: function() {
  80. this.element
  81. .removeClass("ui-sortable ui-sortable-disabled");
  82. this._mouseDestroy();
  83. for ( var i = this.items.length - 1; i >= 0; i-- ) {
  84. this.items[i].item.removeData(this.widgetName + "-item");
  85. }
  86. return this;
  87. },
  88. _setOption: function(key, value){
  89. if ( key === "disabled" ) {
  90. this.options[ key ] = value;
  91. this.widget().toggleClass( "ui-sortable-disabled", !!value );
  92. } else {
  93. // Don't call widget base _setOption for disable as it adds ui-state-disabled class
  94. $.Widget.prototype._setOption.apply(this, arguments);
  95. }
  96. },
  97. _mouseCapture: function(event, overrideHandle) {
  98. var currentItem = null,
  99. validHandle = false,
  100. that = this;
  101. if (this.reverting) {
  102. return false;
  103. }
  104. if(this.options.disabled || this.options.type === "static") {
  105. return false;
  106. }
  107. //We have to refresh the items data once first
  108. this._refreshItems(event);
  109. //Find out if the clicked node (or one of its parents) is a actual item in this.items
  110. $(event.target).parents().each(function() {
  111. if($.data(this, that.widgetName + "-item") === that) {
  112. currentItem = $(this);
  113. return false;
  114. }
  115. });
  116. if($.data(event.target, that.widgetName + "-item") === that) {
  117. currentItem = $(event.target);
  118. }
  119. if(!currentItem) {
  120. return false;
  121. }
  122. if(this.options.handle && !overrideHandle) {
  123. $(this.options.handle, currentItem).find("*").addBack().each(function() {
  124. if(this === event.target) {
  125. validHandle = true;
  126. }
  127. });
  128. if(!validHandle) {
  129. return false;
  130. }
  131. }
  132. this.currentItem = currentItem;
  133. this._removeCurrentsFromItems();
  134. return true;
  135. },
  136. _mouseStart: function(event, overrideHandle, noActivation) {
  137. var i, body,
  138. o = this.options;
  139. this.currentContainer = this;
  140. //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
  141. this.refreshPositions();
  142. //Create and append the visible helper
  143. this.helper = this._createHelper(event);
  144. //Cache the helper size
  145. this._cacheHelperProportions();
  146. /*
  147. * - Position generation -
  148. * This block generates everything position related - it's the core of draggables.
  149. */
  150. //Cache the margins of the original element
  151. this._cacheMargins();
  152. //Get the next scrolling parent
  153. this.scrollParent = this.helper.scrollParent();
  154. //The element's absolute position on the page minus margins
  155. this.offset = this.currentItem.offset();
  156. this.offset = {
  157. top: this.offset.top - this.margins.top,
  158. left: this.offset.left - this.margins.left
  159. };
  160. $.extend(this.offset, {
  161. click: { //Where the click happened, relative to the element
  162. left: event.pageX - this.offset.left,
  163. top: event.pageY - this.offset.top
  164. },
  165. parent: this._getParentOffset(),
  166. relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
  167. });
  168. // Only after we got the offset, we can change the helper's position to absolute
  169. // TODO: Still need to figure out a way to make relative sorting possible
  170. this.helper.css("position", "absolute");
  171. this.cssPosition = this.helper.css("position");
  172. //Generate the original position
  173. this.originalPosition = this._generatePosition(event);
  174. this.originalPageX = event.pageX;
  175. this.originalPageY = event.pageY;
  176. //Adjust the mouse offset relative to the helper if "cursorAt" is supplied
  177. (o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));
  178. //Cache the former DOM position
  179. this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] };
  180. //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
  181. if(this.helper[0] !== this.currentItem[0]) {
  182. this.currentItem.hide();
  183. }
  184. //Create the placeholder
  185. this._createPlaceholder();
  186. //Set a containment if given in the options
  187. if(o.containment) {
  188. this._setContainment();
  189. }
  190. if( o.cursor && o.cursor !== "auto" ) { // cursor option
  191. body = this.document.find( "body" );
  192. // support: IE
  193. this.storedCursor = body.css( "cursor" );
  194. body.css( "cursor", o.cursor );
  195. this.storedStylesheet = $( "<style>*{ cursor: "+o.cursor+" !important; }</style>" ).appendTo( body );
  196. }
  197. if(o.opacity) { // opacity option
  198. if (this.helper.css("opacity")) {
  199. this._storedOpacity = this.helper.css("opacity");
  200. }
  201. this.helper.css("opacity", o.opacity);
  202. }
  203. if(o.zIndex) { // zIndex option
  204. if (this.helper.css("zIndex")) {
  205. this._storedZIndex = this.helper.css("zIndex");
  206. }
  207. this.helper.css("zIndex", o.zIndex);
  208. }
  209. //Prepare scrolling
  210. if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
  211. this.overflowOffset = this.scrollParent.offset();
  212. }
  213. //Call callbacks
  214. this._trigger("start", event, this._uiHash());
  215. //Recache the helper size
  216. if(!this._preserveHelperProportions) {
  217. this._cacheHelperProportions();
  218. }
  219. //Post "activate" events to possible containers
  220. if( !noActivation ) {
  221. for ( i = this.containers.length - 1; i >= 0; i-- ) {
  222. this.containers[ i ]._trigger( "activate", event, this._uiHash( this ) );
  223. }
  224. }
  225. //Prepare possible droppables
  226. if($.ui.ddmanager) {
  227. $.ui.ddmanager.current = this;
  228. }
  229. if ($.ui.ddmanager && !o.dropBehaviour) {
  230. $.ui.ddmanager.prepareOffsets(this, event);
  231. }
  232. this.dragging = true;
  233. this.helper.addClass("ui-sortable-helper");
  234. this._mouseDrag(event); //Execute the drag once - this causes the helper not to be visible before getting its correct position
  235. return true;
  236. },
  237. _mouseDrag: function(event) {
  238. var i, item, itemElement, intersection,
  239. o = this.options,
  240. scrolled = false;
  241. //Compute the helpers position
  242. this.position = this._generatePosition(event);
  243. this.positionAbs = this._convertPositionTo("absolute");
  244. if (!this.lastPositionAbs) {
  245. this.lastPositionAbs = this.positionAbs;
  246. }
  247. //Do scrolling
  248. if(this.options.scroll) {
  249. if(this.scrollParent[0] !== document && this.scrollParent[0].tagName !== "HTML") {
  250. if((this.overflowOffset.top + this.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) {
  251. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop + o.scrollSpeed;
  252. } else if(event.pageY - this.overflowOffset.top < o.scrollSensitivity) {
  253. this.scrollParent[0].scrollTop = scrolled = this.scrollParent[0].scrollTop - o.scrollSpeed;
  254. }
  255. if((this.overflowOffset.left + this.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) {
  256. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft + o.scrollSpeed;
  257. } else if(event.pageX - this.overflowOffset.left < o.scrollSensitivity) {
  258. this.scrollParent[0].scrollLeft = scrolled = this.scrollParent[0].scrollLeft - o.scrollSpeed;
  259. }
  260. } else {
  261. if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) {
  262. scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
  263. } else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) {
  264. scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
  265. }
  266. if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) {
  267. scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
  268. } else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) {
  269. scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
  270. }
  271. }
  272. if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) {
  273. $.ui.ddmanager.prepareOffsets(this, event);
  274. }
  275. }
  276. //Regenerate the absolute position used for position checks
  277. this.positionAbs = this._convertPositionTo("absolute");
  278. //Set the helper position
  279. if(!this.options.axis || this.options.axis !== "y") {
  280. this.helper[0].style.left = this.position.left+"px";
  281. }
  282. if(!this.options.axis || this.options.axis !== "x") {
  283. this.helper[0].style.top = this.position.top+"px";
  284. }
  285. //Rearrange
  286. for (i = this.items.length - 1; i >= 0; i--) {
  287. //Cache variables and intersection, continue if no intersection
  288. item = this.items[i];
  289. itemElement = item.item[0];
  290. intersection = this._intersectsWithPointer(item);
  291. if (!intersection) {
  292. continue;
  293. }
  294. // Only put the placeholder inside the current Container, skip all
  295. // items from other containers. This works because when moving
  296. // an item from one container to another the
  297. // currentContainer is switched before the placeholder is moved.
  298. //
  299. // Without this, moving items in "sub-sortables" can cause
  300. // the placeholder to jitter beetween the outer and inner container.
  301. if (item.instance !== this.currentContainer) {
  302. continue;
  303. }
  304. // cannot intersect with itself
  305. // no useless actions that have been done before
  306. // no action if the item moved is the parent of the item checked
  307. if (itemElement !== this.currentItem[0] &&
  308. this.placeholder[intersection === 1 ? "next" : "prev"]()[0] !== itemElement &&
  309. !$.contains(this.placeholder[0], itemElement) &&
  310. (this.options.type === "semi-dynamic" ? !$.contains(this.element[0], itemElement) : true)
  311. ) {
  312. this.direction = intersection === 1 ? "down" : "up";
  313. if (this.options.tolerance === "pointer" || this._intersectsWithSides(item)) {
  314. this._rearrange(event, item);
  315. } else {
  316. break;
  317. }
  318. this._trigger("change", event, this._uiHash());
  319. break;
  320. }
  321. }
  322. //Post events to containers
  323. this._contactContainers(event);
  324. //Interconnect with droppables
  325. if($.ui.ddmanager) {
  326. $.ui.ddmanager.drag(this, event);
  327. }
  328. //Call callbacks
  329. this._trigger("sort", event, this._uiHash());
  330. this.lastPositionAbs = this.positionAbs;
  331. return false;
  332. },
  333. _mouseStop: function(event, noPropagation) {
  334. if(!event) {
  335. return;
  336. }
  337. //If we are using droppables, inform the manager about the drop
  338. if ($.ui.ddmanager && !this.options.dropBehaviour) {
  339. $.ui.ddmanager.drop(this, event);
  340. }
  341. if(this.options.revert) {
  342. var that = this,
  343. cur = this.placeholder.offset(),
  344. axis = this.options.axis,
  345. animation = {};
  346. if ( !axis || axis === "x" ) {
  347. animation.left = cur.left - this.offset.parent.left - this.margins.left + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollLeft);
  348. }
  349. if ( !axis || axis === "y" ) {
  350. animation.top = cur.top - this.offset.parent.top - this.margins.top + (this.offsetParent[0] === document.body ? 0 : this.offsetParent[0].scrollTop);
  351. }
  352. this.reverting = true;
  353. $(this.helper).animate( animation, parseInt(this.options.revert, 10) || 500, function() {
  354. that._clear(event);
  355. });
  356. } else {
  357. this._clear(event, noPropagation);
  358. }
  359. return false;
  360. },
  361. cancel: function() {
  362. if(this.dragging) {
  363. this._mouseUp({ target: null });
  364. if(this.options.helper === "original") {
  365. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  366. } else {
  367. this.currentItem.show();
  368. }
  369. //Post deactivating events to containers
  370. for (var i = this.containers.length - 1; i >= 0; i--){
  371. this.containers[i]._trigger("deactivate", null, this._uiHash(this));
  372. if(this.containers[i].containerCache.over) {
  373. this.containers[i]._trigger("out", null, this._uiHash(this));
  374. this.containers[i].containerCache.over = 0;
  375. }
  376. }
  377. }
  378. if (this.placeholder) {
  379. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  380. if(this.placeholder[0].parentNode) {
  381. this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  382. }
  383. if(this.options.helper !== "original" && this.helper && this.helper[0].parentNode) {
  384. this.helper.remove();
  385. }
  386. $.extend(this, {
  387. helper: null,
  388. dragging: false,
  389. reverting: false,
  390. _noFinalSort: null
  391. });
  392. if(this.domPosition.prev) {
  393. $(this.domPosition.prev).after(this.currentItem);
  394. } else {
  395. $(this.domPosition.parent).prepend(this.currentItem);
  396. }
  397. }
  398. return this;
  399. },
  400. serialize: function(o) {
  401. var items = this._getItemsAsjQuery(o && o.connected),
  402. str = [];
  403. o = o || {};
  404. $(items).each(function() {
  405. var res = ($(o.item || this).attr(o.attribute || "id") || "").match(o.expression || (/(.+)[\-=_](.+)/));
  406. if (res) {
  407. str.push((o.key || res[1]+"[]")+"="+(o.key && o.expression ? res[1] : res[2]));
  408. }
  409. });
  410. if(!str.length && o.key) {
  411. str.push(o.key + "=");
  412. }
  413. return str.join("&");
  414. },
  415. toArray: function(o) {
  416. var items = this._getItemsAsjQuery(o && o.connected),
  417. ret = [];
  418. o = o || {};
  419. items.each(function() { ret.push($(o.item || this).attr(o.attribute || "id") || ""); });
  420. return ret;
  421. },
  422. /* Be careful with the following core functions */
  423. _intersectsWith: function(item) {
  424. var x1 = this.positionAbs.left,
  425. x2 = x1 + this.helperProportions.width,
  426. y1 = this.positionAbs.top,
  427. y2 = y1 + this.helperProportions.height,
  428. l = item.left,
  429. r = l + item.width,
  430. t = item.top,
  431. b = t + item.height,
  432. dyClick = this.offset.click.top,
  433. dxClick = this.offset.click.left,
  434. isOverElementHeight = ( this.options.axis === "x" ) || ( ( y1 + dyClick ) > t && ( y1 + dyClick ) < b ),
  435. isOverElementWidth = ( this.options.axis === "y" ) || ( ( x1 + dxClick ) > l && ( x1 + dxClick ) < r ),
  436. isOverElement = isOverElementHeight && isOverElementWidth;
  437. if ( this.options.tolerance === "pointer" ||
  438. this.options.forcePointerForContainers ||
  439. (this.options.tolerance !== "pointer" && this.helperProportions[this.floating ? "width" : "height"] > item[this.floating ? "width" : "height"])
  440. ) {
  441. return isOverElement;
  442. } else {
  443. return (l < x1 + (this.helperProportions.width / 2) && // Right Half
  444. x2 - (this.helperProportions.width / 2) < r && // Left Half
  445. t < y1 + (this.helperProportions.height / 2) && // Bottom Half
  446. y2 - (this.helperProportions.height / 2) < b ); // Top Half
  447. }
  448. },
  449. _intersectsWithPointer: function(item) {
  450. var isOverElementHeight = (this.options.axis === "x") || isOverAxis(this.positionAbs.top + this.offset.click.top, item.top, item.height),
  451. isOverElementWidth = (this.options.axis === "y") || isOverAxis(this.positionAbs.left + this.offset.click.left, item.left, item.width),
  452. isOverElement = isOverElementHeight && isOverElementWidth,
  453. verticalDirection = this._getDragVerticalDirection(),
  454. horizontalDirection = this._getDragHorizontalDirection();
  455. if (!isOverElement) {
  456. return false;
  457. }
  458. return this.floating ?
  459. ( ((horizontalDirection && horizontalDirection === "right") || verticalDirection === "down") ? 2 : 1 )
  460. : ( verticalDirection && (verticalDirection === "down" ? 2 : 1) );
  461. },
  462. _intersectsWithSides: function(item) {
  463. var isOverBottomHalf = isOverAxis(this.positionAbs.top + this.offset.click.top, item.top + (item.height/2), item.height),
  464. isOverRightHalf = isOverAxis(this.positionAbs.left + this.offset.click.left, item.left + (item.width/2), item.width),
  465. verticalDirection = this._getDragVerticalDirection(),
  466. horizontalDirection = this._getDragHorizontalDirection();
  467. if (this.floating && horizontalDirection) {
  468. return ((horizontalDirection === "right" && isOverRightHalf) || (horizontalDirection === "left" && !isOverRightHalf));
  469. } else {
  470. return verticalDirection && ((verticalDirection === "down" && isOverBottomHalf) || (verticalDirection === "up" && !isOverBottomHalf));
  471. }
  472. },
  473. _getDragVerticalDirection: function() {
  474. var delta = this.positionAbs.top - this.lastPositionAbs.top;
  475. return delta !== 0 && (delta > 0 ? "down" : "up");
  476. },
  477. _getDragHorizontalDirection: function() {
  478. var delta = this.positionAbs.left - this.lastPositionAbs.left;
  479. return delta !== 0 && (delta > 0 ? "right" : "left");
  480. },
  481. refresh: function(event) {
  482. this._refreshItems(event);
  483. this.refreshPositions();
  484. return this;
  485. },
  486. _connectWith: function() {
  487. var options = this.options;
  488. return options.connectWith.constructor === String ? [options.connectWith] : options.connectWith;
  489. },
  490. _getItemsAsjQuery: function(connected) {
  491. var i, j, cur, inst,
  492. items = [],
  493. queries = [],
  494. connectWith = this._connectWith();
  495. if(connectWith && connected) {
  496. for (i = connectWith.length - 1; i >= 0; i--){
  497. cur = $(connectWith[i]);
  498. for ( j = cur.length - 1; j >= 0; j--){
  499. inst = $.data(cur[j], this.widgetFullName);
  500. if(inst && inst !== this && !inst.options.disabled) {
  501. 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]);
  502. }
  503. }
  504. }
  505. }
  506. 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]);
  507. function addItems() {
  508. items.push( this );
  509. }
  510. for (i = queries.length - 1; i >= 0; i--){
  511. queries[i][0].each( addItems );
  512. }
  513. return $(items);
  514. },
  515. _removeCurrentsFromItems: function() {
  516. var list = this.currentItem.find(":data(" + this.widgetName + "-item)");
  517. this.items = $.grep(this.items, function (item) {
  518. for (var j=0; j < list.length; j++) {
  519. if(list[j] === item.item[0]) {
  520. return false;
  521. }
  522. }
  523. return true;
  524. });
  525. },
  526. _refreshItems: function(event) {
  527. this.items = [];
  528. this.containers = [this];
  529. var i, j, cur, inst, targetData, _queries, item, queriesLength,
  530. items = this.items,
  531. queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element[0], event, { item: this.currentItem }) : $(this.options.items, this.element), this]],
  532. connectWith = this._connectWith();
  533. if(connectWith && this.ready) { //Shouldn't be run the first time through due to massive slow-down
  534. for (i = connectWith.length - 1; i >= 0; i--){
  535. cur = $(connectWith[i]);
  536. for (j = cur.length - 1; j >= 0; j--){
  537. inst = $.data(cur[j], this.widgetFullName);
  538. if(inst && inst !== this && !inst.options.disabled) {
  539. queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element[0], event, { item: this.currentItem }) : $(inst.options.items, inst.element), inst]);
  540. this.containers.push(inst);
  541. }
  542. }
  543. }
  544. }
  545. for (i = queries.length - 1; i >= 0; i--) {
  546. targetData = queries[i][1];
  547. _queries = queries[i][0];
  548. for (j=0, queriesLength = _queries.length; j < queriesLength; j++) {
  549. item = $(_queries[j]);
  550. item.data(this.widgetName + "-item", targetData); // Data for target checking (mouse manager)
  551. items.push({
  552. item: item,
  553. instance: targetData,
  554. width: 0, height: 0,
  555. left: 0, top: 0
  556. });
  557. }
  558. }
  559. },
  560. refreshPositions: function(fast) {
  561. //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
  562. if(this.offsetParent && this.helper) {
  563. this.offset.parent = this._getParentOffset();
  564. }
  565. var i, item, t, p;
  566. for (i = this.items.length - 1; i >= 0; i--){
  567. item = this.items[i];
  568. //We ignore calculating positions of all connected containers when we're not over them
  569. if(item.instance !== this.currentContainer && this.currentContainer && item.item[0] !== this.currentItem[0]) {
  570. continue;
  571. }
  572. t = this.options.toleranceElement ? $(this.options.toleranceElement, item.item) : item.item;
  573. if (!fast) {
  574. item.width = t.outerWidth();
  575. item.height = t.outerHeight();
  576. }
  577. p = t.offset();
  578. item.left = p.left;
  579. item.top = p.top;
  580. }
  581. if(this.options.custom && this.options.custom.refreshContainers) {
  582. this.options.custom.refreshContainers.call(this);
  583. } else {
  584. for (i = this.containers.length - 1; i >= 0; i--){
  585. p = this.containers[i].element.offset();
  586. this.containers[i].containerCache.left = p.left;
  587. this.containers[i].containerCache.top = p.top;
  588. this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
  589. this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
  590. }
  591. }
  592. return this;
  593. },
  594. _createPlaceholder: function(that) {
  595. that = that || this;
  596. var className,
  597. o = that.options;
  598. if(!o.placeholder || o.placeholder.constructor === String) {
  599. className = o.placeholder;
  600. o.placeholder = {
  601. element: function() {
  602. var nodeName = that.currentItem[0].nodeName.toLowerCase(),
  603. element = $( "<" + nodeName + ">", that.document[0] )
  604. .addClass(className || that.currentItem[0].className+" ui-sortable-placeholder")
  605. .removeClass("ui-sortable-helper");
  606. if ( nodeName === "tr" ) {
  607. that.currentItem.children().each(function() {
  608. $( "<td>&#160;</td>", that.document[0] )
  609. .attr( "colspan", $( this ).attr( "colspan" ) || 1 )
  610. .appendTo( element );
  611. });
  612. } else if ( nodeName === "img" ) {
  613. element.attr( "src", that.currentItem.attr( "src" ) );
  614. }
  615. if ( !className ) {
  616. element.css( "visibility", "hidden" );
  617. }
  618. return element;
  619. },
  620. update: function(container, p) {
  621. // 1. If a className is set as 'placeholder option, we don't force sizes - the class is responsible for that
  622. // 2. The option 'forcePlaceholderSize can be enabled to force it even if a class name is specified
  623. if(className && !o.forcePlaceholderSize) {
  624. return;
  625. }
  626. //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
  627. if(!p.height()) { p.height(that.currentItem.innerHeight() - parseInt(that.currentItem.css("paddingTop")||0, 10) - parseInt(that.currentItem.css("paddingBottom")||0, 10)); }
  628. if(!p.width()) { p.width(that.currentItem.innerWidth() - parseInt(that.currentItem.css("paddingLeft")||0, 10) - parseInt(that.currentItem.css("paddingRight")||0, 10)); }
  629. }
  630. };
  631. }
  632. //Create the placeholder
  633. that.placeholder = $(o.placeholder.element.call(that.element, that.currentItem));
  634. //Append it after the actual current item
  635. that.currentItem.after(that.placeholder);
  636. //Update the size of the placeholder (TODO: Logic to fuzzy, see line 316/317)
  637. o.placeholder.update(that, that.placeholder);
  638. },
  639. _contactContainers: function(event) {
  640. var i, j, dist, itemWithLeastDistance, posProperty, sizeProperty, base, cur, nearBottom, floating,
  641. innermostContainer = null,
  642. innermostIndex = null;
  643. // get innermost container that intersects with item
  644. for (i = this.containers.length - 1; i >= 0; i--) {
  645. // never consider a container that's located within the item itself
  646. if($.contains(this.currentItem[0], this.containers[i].element[0])) {
  647. continue;
  648. }
  649. if(this._intersectsWith(this.containers[i].containerCache)) {
  650. // if we've already found a container and it's more "inner" than this, then continue
  651. if(innermostContainer && $.contains(this.containers[i].element[0], innermostContainer.element[0])) {
  652. continue;
  653. }
  654. innermostContainer = this.containers[i];
  655. innermostIndex = i;
  656. } else {
  657. // container doesn't intersect. trigger "out" event if necessary
  658. if(this.containers[i].containerCache.over) {
  659. this.containers[i]._trigger("out", event, this._uiHash(this));
  660. this.containers[i].containerCache.over = 0;
  661. }
  662. }
  663. }
  664. // if no intersecting containers found, return
  665. if(!innermostContainer) {
  666. return;
  667. }
  668. // move the item into the container if it's not there already
  669. if(this.containers.length === 1) {
  670. if (!this.containers[innermostIndex].containerCache.over) {
  671. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  672. this.containers[innermostIndex].containerCache.over = 1;
  673. }
  674. } else {
  675. //When entering a new container, we will find the item with the least distance and append our item near it
  676. dist = 10000;
  677. itemWithLeastDistance = null;
  678. floating = innermostContainer.floating || isFloating(this.currentItem);
  679. posProperty = floating ? "left" : "top";
  680. sizeProperty = floating ? "width" : "height";
  681. base = this.positionAbs[posProperty] + this.offset.click[posProperty];
  682. for (j = this.items.length - 1; j >= 0; j--) {
  683. if(!$.contains(this.containers[innermostIndex].element[0], this.items[j].item[0])) {
  684. continue;
  685. }
  686. if(this.items[j].item[0] === this.currentItem[0]) {
  687. continue;
  688. }
  689. if (floating && !isOverAxis(this.positionAbs.top + this.offset.click.top, this.items[j].top, this.items[j].height)) {
  690. continue;
  691. }
  692. cur = this.items[j].item.offset()[posProperty];
  693. nearBottom = false;
  694. if(Math.abs(cur - base) > Math.abs(cur + this.items[j][sizeProperty] - base)){
  695. nearBottom = true;
  696. cur += this.items[j][sizeProperty];
  697. }
  698. if(Math.abs(cur - base) < dist) {
  699. dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
  700. this.direction = nearBottom ? "up": "down";
  701. }
  702. }
  703. //Check if dropOnEmpty is enabled
  704. if(!itemWithLeastDistance && !this.options.dropOnEmpty) {
  705. return;
  706. }
  707. if(this.currentContainer === this.containers[innermostIndex]) {
  708. return;
  709. }
  710. itemWithLeastDistance ? this._rearrange(event, itemWithLeastDistance, null, true) : this._rearrange(event, null, this.containers[innermostIndex].element, true);
  711. this._trigger("change", event, this._uiHash());
  712. this.containers[innermostIndex]._trigger("change", event, this._uiHash(this));
  713. this.currentContainer = this.containers[innermostIndex];
  714. //Update the placeholder
  715. this.options.placeholder.update(this.currentContainer, this.placeholder);
  716. this.containers[innermostIndex]._trigger("over", event, this._uiHash(this));
  717. this.containers[innermostIndex].containerCache.over = 1;
  718. }
  719. },
  720. _createHelper: function(event) {
  721. var o = this.options,
  722. helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [event, this.currentItem])) : (o.helper === "clone" ? this.currentItem.clone() : this.currentItem);
  723. //Add the helper to the DOM if that didn't happen already
  724. if(!helper.parents("body").length) {
  725. $(o.appendTo !== "parent" ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(helper[0]);
  726. }
  727. if(helper[0] === this.currentItem[0]) {
  728. 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") };
  729. }
  730. if(!helper[0].style.width || o.forceHelperSize) {
  731. helper.width(this.currentItem.width());
  732. }
  733. if(!helper[0].style.height || o.forceHelperSize) {
  734. helper.height(this.currentItem.height());
  735. }
  736. return helper;
  737. },
  738. _adjustOffsetFromHelper: function(obj) {
  739. if (typeof obj === "string") {
  740. obj = obj.split(" ");
  741. }
  742. if ($.isArray(obj)) {
  743. obj = {left: +obj[0], top: +obj[1] || 0};
  744. }
  745. if ("left" in obj) {
  746. this.offset.click.left = obj.left + this.margins.left;
  747. }
  748. if ("right" in obj) {
  749. this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left;
  750. }
  751. if ("top" in obj) {
  752. this.offset.click.top = obj.top + this.margins.top;
  753. }
  754. if ("bottom" in obj) {
  755. this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top;
  756. }
  757. },
  758. _getParentOffset: function() {
  759. //Get the offsetParent and cache its position
  760. this.offsetParent = this.helper.offsetParent();
  761. var po = this.offsetParent.offset();
  762. // This is a special case where we need to modify a offset calculated on start, since the following happened:
  763. // 1. The position of the helper is absolute, so it's position is calculated based on the next positioned parent
  764. // 2. The actual offset parent is a child of the scroll parent, and the scroll parent isn't the document, which means that
  765. // the scroll is included in the initial calculation of the offset of the parent, and never recalculated upon drag
  766. if(this.cssPosition === "absolute" && this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) {
  767. po.left += this.scrollParent.scrollLeft();
  768. po.top += this.scrollParent.scrollTop();
  769. }
  770. // This needs to be actually done for all browsers, since pageX/pageY includes this information
  771. // with an ugly IE fix
  772. if( this.offsetParent[0] === document.body || (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() === "html" && $.ui.ie)) {
  773. po = { top: 0, left: 0 };
  774. }
  775. return {
  776. top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
  777. left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
  778. };
  779. },
  780. _getRelativeOffset: function() {
  781. if(this.cssPosition === "relative") {
  782. var p = this.currentItem.position();
  783. return {
  784. top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(),
  785. left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft()
  786. };
  787. } else {
  788. return { top: 0, left: 0 };
  789. }
  790. },
  791. _cacheMargins: function() {
  792. this.margins = {
  793. left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
  794. top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
  795. };
  796. },
  797. _cacheHelperProportions: function() {
  798. this.helperProportions = {
  799. width: this.helper.outerWidth(),
  800. height: this.helper.outerHeight()
  801. };
  802. },
  803. _setContainment: function() {
  804. var ce, co, over,
  805. o = this.options;
  806. if(o.containment === "parent") {
  807. o.containment = this.helper[0].parentNode;
  808. }
  809. if(o.containment === "document" || o.containment === "window") {
  810. this.containment = [
  811. 0 - this.offset.relative.left - this.offset.parent.left,
  812. 0 - this.offset.relative.top - this.offset.parent.top,
  813. $(o.containment === "document" ? document : window).width() - this.helperProportions.width - this.margins.left,
  814. ($(o.containment === "document" ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top
  815. ];
  816. }
  817. if(!(/^(document|window|parent)$/).test(o.containment)) {
  818. ce = $(o.containment)[0];
  819. co = $(o.containment).offset();
  820. over = ($(ce).css("overflow") !== "hidden");
  821. this.containment = [
  822. co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0) - this.margins.left,
  823. co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0) - this.margins.top,
  824. 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,
  825. 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
  826. ];
  827. }
  828. },
  829. _convertPositionTo: function(d, pos) {
  830. if(!pos) {
  831. pos = this.position;
  832. }
  833. var mod = d === "absolute" ? 1 : -1,
  834. scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent,
  835. scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
  836. return {
  837. top: (
  838. pos.top + // The absolute mouse position
  839. this.offset.relative.top * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  840. this.offset.parent.top * mod - // The offsetParent's offset without borders (offset + border)
  841. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod)
  842. ),
  843. left: (
  844. pos.left + // The absolute mouse position
  845. this.offset.relative.left * mod + // Only for relative positioned nodes: Relative offset from element to offset parent
  846. this.offset.parent.left * mod - // The offsetParent's offset without borders (offset + border)
  847. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod)
  848. )
  849. };
  850. },
  851. _generatePosition: function(event) {
  852. var top, left,
  853. o = this.options,
  854. pageX = event.pageX,
  855. pageY = event.pageY,
  856. 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);
  857. // This is another very weird special case that only happens for relative elements:
  858. // 1. If the css position is relative
  859. // 2. and the scroll parent is the document or similar to the offset parent
  860. // we have to refresh the relative offset during the scroll so there are no jumps
  861. if(this.cssPosition === "relative" && !(this.scrollParent[0] !== document && this.scrollParent[0] !== this.offsetParent[0])) {
  862. this.offset.relative = this._getRelativeOffset();
  863. }
  864. /*
  865. * - Position constraining -
  866. * Constrain the position to a mix of grid, containment.
  867. */
  868. if(this.originalPosition) { //If we are not dragging yet, we won't check for options
  869. if(this.containment) {
  870. if(event.pageX - this.offset.click.left < this.containment[0]) {
  871. pageX = this.containment[0] + this.offset.click.left;
  872. }
  873. if(event.pageY - this.offset.click.top < this.containment[1]) {
  874. pageY = this.containment[1] + this.offset.click.top;
  875. }
  876. if(event.pageX - this.offset.click.left > this.containment[2]) {
  877. pageX = this.containment[2] + this.offset.click.left;
  878. }
  879. if(event.pageY - this.offset.click.top > this.containment[3]) {
  880. pageY = this.containment[3] + this.offset.click.top;
  881. }
  882. }
  883. if(o.grid) {
  884. top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
  885. 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;
  886. left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
  887. 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;
  888. }
  889. }
  890. return {
  891. top: (
  892. pageY - // The absolute mouse position
  893. this.offset.click.top - // Click offset (relative to the element)
  894. this.offset.relative.top - // Only for relative positioned nodes: Relative offset from element to offset parent
  895. this.offset.parent.top + // The offsetParent's offset without borders (offset + border)
  896. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
  897. ),
  898. left: (
  899. pageX - // The absolute mouse position
  900. this.offset.click.left - // Click offset (relative to the element)
  901. this.offset.relative.left - // Only for relative positioned nodes: Relative offset from element to offset parent
  902. this.offset.parent.left + // The offsetParent's offset without borders (offset + border)
  903. ( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
  904. )
  905. };
  906. },
  907. _rearrange: function(event, i, a, hardRefresh) {
  908. 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));
  909. //Various things done here to improve the performance:
  910. // 1. we create a setTimeout, that calls refreshPositions
  911. // 2. on the instance, we have a counter variable, that get's higher after every append
  912. // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
  913. // 4. this lets only the last addition to the timeout stack through
  914. this.counter = this.counter ? ++this.counter : 1;
  915. var counter = this.counter;
  916. this._delay(function() {
  917. if(counter === this.counter) {
  918. this.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
  919. }
  920. });
  921. },
  922. _clear: function(event, noPropagation) {
  923. this.reverting = false;
  924. // We delay all events that have to be triggered to after the point where the placeholder has been removed and
  925. // everything else normalized again
  926. var i,
  927. delayedTriggers = [];
  928. // We first have to update the dom position of the actual currentItem
  929. // Note: don't do it if the current item is already removed (by a user), or it gets reappended (see #4088)
  930. if(!this._noFinalSort && this.currentItem.parent().length) {
  931. this.placeholder.before(this.currentItem);
  932. }
  933. this._noFinalSort = null;
  934. if(this.helper[0] === this.currentItem[0]) {
  935. for(i in this._storedCSS) {
  936. if(this._storedCSS[i] === "auto" || this._storedCSS[i] === "static") {
  937. this._storedCSS[i] = "";
  938. }
  939. }
  940. this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper");
  941. } else {
  942. this.currentItem.show();
  943. }
  944. if(this.fromOutside && !noPropagation) {
  945. delayedTriggers.push(function(event) { this._trigger("receive", event, this._uiHash(this.fromOutside)); });
  946. }
  947. if((this.fromOutside || this.domPosition.prev !== this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent !== this.currentItem.parent()[0]) && !noPropagation) {
  948. delayedTriggers.push(function(event) { this._trigger("update", event, this._uiHash()); }); //Trigger update callback if the DOM position has changed
  949. }
  950. // Check if the items Container has Changed and trigger appropriate
  951. // events.
  952. if (this !== this.currentContainer) {
  953. if(!noPropagation) {
  954. delayedTriggers.push(function(event) { this._trigger("remove", event, this._uiHash()); });
  955. delayedTriggers.push((function(c) { return function(event) { c._trigger("receive", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  956. delayedTriggers.push((function(c) { return function(event) { c._trigger("update", event, this._uiHash(this)); }; }).call(this, this.currentContainer));
  957. }
  958. }
  959. //Post events to containers
  960. function delayEvent( type, instance, container ) {
  961. return function( event ) {
  962. container._trigger( type, event, instance._uiHash( instance ) );
  963. };
  964. }
  965. for (i = this.containers.length - 1; i >= 0; i--){
  966. if (!noPropagation) {
  967. delayedTriggers.push( delayEvent( "deactivate", this, this.containers[ i ] ) );
  968. }
  969. if(this.containers[i].containerCache.over) {
  970. delayedTriggers.push( delayEvent( "out", this, this.containers[ i ] ) );
  971. this.containers[i].containerCache.over = 0;
  972. }
  973. }
  974. //Do what was originally in plugins
  975. if ( this.storedCursor ) {
  976. this.document.find( "body" ).css( "cursor", this.storedCursor );
  977. this.storedStylesheet.remove();
  978. }
  979. if(this._storedOpacity) {
  980. this.helper.css("opacity", this._storedOpacity);
  981. }
  982. if(this._storedZIndex) {
  983. this.helper.css("zIndex", this._storedZIndex === "auto" ? "" : this._storedZIndex);
  984. }
  985. this.dragging = false;
  986. if(this.cancelHelperRemoval) {
  987. if(!noPropagation) {
  988. this._trigger("beforeStop", event, this._uiHash());
  989. for (i=0; i < delayedTriggers.length; i++) {
  990. delayedTriggers[i].call(this, event);
  991. } //Trigger all delayed events
  992. this._trigger("stop", event, this._uiHash());
  993. }
  994. this.fromOutside = false;
  995. return false;
  996. }
  997. if(!noPropagation) {
  998. this._trigger("beforeStop", event, this._uiHash());
  999. }
  1000. //$(this.placeholder[0]).remove(); would have been the jQuery way - unfortunately, it unbinds ALL events from the original node!
  1001. this.placeholder[0].parentNode.removeChild(this.placeholder[0]);
  1002. if(this.helper[0] !== this.currentItem[0]) {
  1003. this.helper.remove();
  1004. }
  1005. this.helper = null;
  1006. if(!noPropagation) {
  1007. for (i=0; i < delayedTriggers.length; i++) {
  1008. delayedTriggers[i].call(this, event);
  1009. } //Trigger all delayed events
  1010. this._trigger("stop", event, this._uiHash());
  1011. }
  1012. this.fromOutside = false;
  1013. return true;
  1014. },
  1015. _trigger: function() {
  1016. if ($.Widget.prototype._trigger.apply(this, arguments) === false) {
  1017. this.cancel();
  1018. }
  1019. },
  1020. _uiHash: function(_inst) {
  1021. var inst = _inst || this;
  1022. return {
  1023. helper: inst.helper,
  1024. placeholder: inst.placeholder || $([]),
  1025. position: inst.position,
  1026. originalPosition: inst.originalPosition,
  1027. offset: inst.positionAbs,
  1028. item: inst.currentItem,
  1029. sender: _inst ? _inst.element : null
  1030. };
  1031. }
  1032. });
  1033. })(jQuery);