jquery.ui.sortable.js 42 KB

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