sortable.js 42 KB

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