Sortable.js 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365
  1. /**!
  2. * Sortable 1.15.1
  3. * @author RubaXa <trash@rubaxa.org>
  4. * @author owenm <owen23355@gmail.com>
  5. * @license MIT
  6. */
  7. (function (global, factory) {
  8. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  9. typeof define === 'function' && define.amd ? define(factory) :
  10. (global = global || self, global.Sortable = factory());
  11. }(this, (function () { 'use strict';
  12. function ownKeys(object, enumerableOnly) {
  13. var keys = Object.keys(object);
  14. if (Object.getOwnPropertySymbols) {
  15. var symbols = Object.getOwnPropertySymbols(object);
  16. if (enumerableOnly) {
  17. symbols = symbols.filter(function (sym) {
  18. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  19. });
  20. }
  21. keys.push.apply(keys, symbols);
  22. }
  23. return keys;
  24. }
  25. function _objectSpread2(target) {
  26. for (var i = 1; i < arguments.length; i++) {
  27. var source = arguments[i] != null ? arguments[i] : {};
  28. if (i % 2) {
  29. ownKeys(Object(source), true).forEach(function (key) {
  30. _defineProperty(target, key, source[key]);
  31. });
  32. } else if (Object.getOwnPropertyDescriptors) {
  33. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  34. } else {
  35. ownKeys(Object(source)).forEach(function (key) {
  36. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  37. });
  38. }
  39. }
  40. return target;
  41. }
  42. function _typeof(obj) {
  43. "@babel/helpers - typeof";
  44. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  45. _typeof = function (obj) {
  46. return typeof obj;
  47. };
  48. } else {
  49. _typeof = function (obj) {
  50. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  51. };
  52. }
  53. return _typeof(obj);
  54. }
  55. function _defineProperty(obj, key, value) {
  56. if (key in obj) {
  57. Object.defineProperty(obj, key, {
  58. value: value,
  59. enumerable: true,
  60. configurable: true,
  61. writable: true
  62. });
  63. } else {
  64. obj[key] = value;
  65. }
  66. return obj;
  67. }
  68. function _extends() {
  69. _extends = Object.assign || function (target) {
  70. for (var i = 1; i < arguments.length; i++) {
  71. var source = arguments[i];
  72. for (var key in source) {
  73. if (Object.prototype.hasOwnProperty.call(source, key)) {
  74. target[key] = source[key];
  75. }
  76. }
  77. }
  78. return target;
  79. };
  80. return _extends.apply(this, arguments);
  81. }
  82. function _objectWithoutPropertiesLoose(source, excluded) {
  83. if (source == null) return {};
  84. var target = {};
  85. var sourceKeys = Object.keys(source);
  86. var key, i;
  87. for (i = 0; i < sourceKeys.length; i++) {
  88. key = sourceKeys[i];
  89. if (excluded.indexOf(key) >= 0) continue;
  90. target[key] = source[key];
  91. }
  92. return target;
  93. }
  94. function _objectWithoutProperties(source, excluded) {
  95. if (source == null) return {};
  96. var target = _objectWithoutPropertiesLoose(source, excluded);
  97. var key, i;
  98. if (Object.getOwnPropertySymbols) {
  99. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  100. for (i = 0; i < sourceSymbolKeys.length; i++) {
  101. key = sourceSymbolKeys[i];
  102. if (excluded.indexOf(key) >= 0) continue;
  103. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  104. target[key] = source[key];
  105. }
  106. }
  107. return target;
  108. }
  109. function _toConsumableArray(arr) {
  110. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  111. }
  112. function _arrayWithoutHoles(arr) {
  113. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  114. }
  115. function _iterableToArray(iter) {
  116. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  117. }
  118. function _unsupportedIterableToArray(o, minLen) {
  119. if (!o) return;
  120. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  121. var n = Object.prototype.toString.call(o).slice(8, -1);
  122. if (n === "Object" && o.constructor) n = o.constructor.name;
  123. if (n === "Map" || n === "Set") return Array.from(o);
  124. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  125. }
  126. function _arrayLikeToArray(arr, len) {
  127. if (len == null || len > arr.length) len = arr.length;
  128. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  129. return arr2;
  130. }
  131. function _nonIterableSpread() {
  132. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  133. }
  134. var version = "1.15.1";
  135. function userAgent(pattern) {
  136. if (typeof window !== 'undefined' && window.navigator) {
  137. return !! /*@__PURE__*/navigator.userAgent.match(pattern);
  138. }
  139. }
  140. var IE11OrLess = userAgent(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i);
  141. var Edge = userAgent(/Edge/i);
  142. var FireFox = userAgent(/firefox/i);
  143. var Safari = userAgent(/safari/i) && !userAgent(/chrome/i) && !userAgent(/android/i);
  144. var IOS = userAgent(/iP(ad|od|hone)/i);
  145. var ChromeForAndroid = userAgent(/chrome/i) && userAgent(/android/i);
  146. var captureMode = {
  147. capture: false,
  148. passive: false
  149. };
  150. function on(el, event, fn) {
  151. el.addEventListener(event, fn, !IE11OrLess && captureMode);
  152. }
  153. function off(el, event, fn) {
  154. el.removeEventListener(event, fn, !IE11OrLess && captureMode);
  155. }
  156. function matches( /**HTMLElement*/el, /**String*/selector) {
  157. if (!selector) return;
  158. selector[0] === '>' && (selector = selector.substring(1));
  159. if (el) {
  160. try {
  161. if (el.matches) {
  162. return el.matches(selector);
  163. } else if (el.msMatchesSelector) {
  164. return el.msMatchesSelector(selector);
  165. } else if (el.webkitMatchesSelector) {
  166. return el.webkitMatchesSelector(selector);
  167. }
  168. } catch (_) {
  169. return false;
  170. }
  171. }
  172. return false;
  173. }
  174. function getParentOrHost(el) {
  175. return el.host && el !== document && el.host.nodeType ? el.host : el.parentNode;
  176. }
  177. function closest( /**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx, includeCTX) {
  178. if (el) {
  179. ctx = ctx || document;
  180. do {
  181. if (selector != null && (selector[0] === '>' ? el.parentNode === ctx && matches(el, selector) : matches(el, selector)) || includeCTX && el === ctx) {
  182. return el;
  183. }
  184. if (el === ctx) break;
  185. /* jshint boss:true */
  186. } while (el = getParentOrHost(el));
  187. }
  188. return null;
  189. }
  190. var R_SPACE = /\s+/g;
  191. function toggleClass(el, name, state) {
  192. if (el && name) {
  193. if (el.classList) {
  194. el.classList[state ? 'add' : 'remove'](name);
  195. } else {
  196. var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + name + ' ', ' ');
  197. el.className = (className + (state ? ' ' + name : '')).replace(R_SPACE, ' ');
  198. }
  199. }
  200. }
  201. function css(el, prop, val) {
  202. var style = el && el.style;
  203. if (style) {
  204. if (val === void 0) {
  205. if (document.defaultView && document.defaultView.getComputedStyle) {
  206. val = document.defaultView.getComputedStyle(el, '');
  207. } else if (el.currentStyle) {
  208. val = el.currentStyle;
  209. }
  210. return prop === void 0 ? val : val[prop];
  211. } else {
  212. if (!(prop in style) && prop.indexOf('webkit') === -1) {
  213. prop = '-webkit-' + prop;
  214. }
  215. style[prop] = val + (typeof val === 'string' ? '' : 'px');
  216. }
  217. }
  218. }
  219. function matrix(el, selfOnly) {
  220. var appliedTransforms = '';
  221. if (typeof el === 'string') {
  222. appliedTransforms = el;
  223. } else {
  224. do {
  225. var transform = css(el, 'transform');
  226. if (transform && transform !== 'none') {
  227. appliedTransforms = transform + ' ' + appliedTransforms;
  228. }
  229. /* jshint boss:true */
  230. } while (!selfOnly && (el = el.parentNode));
  231. }
  232. var matrixFn = window.DOMMatrix || window.WebKitCSSMatrix || window.CSSMatrix || window.MSCSSMatrix;
  233. /*jshint -W056 */
  234. return matrixFn && new matrixFn(appliedTransforms);
  235. }
  236. function find(ctx, tagName, iterator) {
  237. if (ctx) {
  238. var list = ctx.getElementsByTagName(tagName),
  239. i = 0,
  240. n = list.length;
  241. if (iterator) {
  242. for (; i < n; i++) {
  243. iterator(list[i], i);
  244. }
  245. }
  246. return list;
  247. }
  248. return [];
  249. }
  250. function getWindowScrollingElement() {
  251. var scrollingElement = document.scrollingElement;
  252. if (scrollingElement) {
  253. return scrollingElement;
  254. } else {
  255. return document.documentElement;
  256. }
  257. }
  258. /**
  259. * Returns the "bounding client rect" of given element
  260. * @param {HTMLElement} el The element whose boundingClientRect is wanted
  261. * @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container
  262. * @param {[Boolean]} relativeToNonStaticParent Whether the rect should be relative to the relative parent of (including) the contaienr
  263. * @param {[Boolean]} undoScale Whether the container's scale() should be undone
  264. * @param {[HTMLElement]} container The parent the element will be placed in
  265. * @return {Object} The boundingClientRect of el, with specified adjustments
  266. */
  267. function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) {
  268. if (!el.getBoundingClientRect && el !== window) return;
  269. var elRect, top, left, bottom, right, height, width;
  270. if (el !== window && el.parentNode && el !== getWindowScrollingElement()) {
  271. elRect = el.getBoundingClientRect();
  272. top = elRect.top;
  273. left = elRect.left;
  274. bottom = elRect.bottom;
  275. right = elRect.right;
  276. height = elRect.height;
  277. width = elRect.width;
  278. } else {
  279. top = 0;
  280. left = 0;
  281. bottom = window.innerHeight;
  282. right = window.innerWidth;
  283. height = window.innerHeight;
  284. width = window.innerWidth;
  285. }
  286. if ((relativeToContainingBlock || relativeToNonStaticParent) && el !== window) {
  287. // Adjust for translate()
  288. container = container || el.parentNode;
  289. // solves #1123 (see: https://stackoverflow.com/a/37953806/6088312)
  290. // Not needed on <= IE11
  291. if (!IE11OrLess) {
  292. do {
  293. if (container && container.getBoundingClientRect && (css(container, 'transform') !== 'none' || relativeToNonStaticParent && css(container, 'position') !== 'static')) {
  294. var containerRect = container.getBoundingClientRect();
  295. // Set relative to edges of padding box of container
  296. top -= containerRect.top + parseInt(css(container, 'border-top-width'));
  297. left -= containerRect.left + parseInt(css(container, 'border-left-width'));
  298. bottom = top + elRect.height;
  299. right = left + elRect.width;
  300. break;
  301. }
  302. /* jshint boss:true */
  303. } while (container = container.parentNode);
  304. }
  305. }
  306. if (undoScale && el !== window) {
  307. // Adjust for scale()
  308. var elMatrix = matrix(container || el),
  309. scaleX = elMatrix && elMatrix.a,
  310. scaleY = elMatrix && elMatrix.d;
  311. if (elMatrix) {
  312. top /= scaleY;
  313. left /= scaleX;
  314. width /= scaleX;
  315. height /= scaleY;
  316. bottom = top + height;
  317. right = left + width;
  318. }
  319. }
  320. return {
  321. top: top,
  322. left: left,
  323. bottom: bottom,
  324. right: right,
  325. width: width,
  326. height: height
  327. };
  328. }
  329. /**
  330. * Returns the content rect of the element (bounding rect minus border and padding)
  331. * @param {HTMLElement} el
  332. */
  333. function getContentRect(el) {
  334. var rect = getRect(el);
  335. var paddingLeft = parseInt(css(el, 'padding-left')),
  336. paddingTop = parseInt(css(el, 'padding-top')),
  337. paddingRight = parseInt(css(el, 'padding-right')),
  338. paddingBottom = parseInt(css(el, 'padding-bottom'));
  339. rect.top += paddingTop + parseInt(css(el, 'border-top-width'));
  340. rect.left += paddingLeft + parseInt(css(el, 'border-left-width'));
  341. // Client Width/Height includes padding only
  342. rect.width = el.clientWidth - paddingLeft - paddingRight;
  343. rect.height = el.clientHeight - paddingTop - paddingBottom;
  344. rect.bottom = rect.top + rect.height;
  345. rect.right = rect.left + rect.width;
  346. return rect;
  347. }
  348. /**
  349. * Checks if a side of an element is scrolled past a side of its parents
  350. * @param {HTMLElement} el The element who's side being scrolled out of view is in question
  351. * @param {String} elSide Side of the element in question ('top', 'left', 'right', 'bottom')
  352. * @param {String} parentSide Side of the parent in question ('top', 'left', 'right', 'bottom')
  353. * @return {HTMLElement} The parent scroll element that the el's side is scrolled past, or null if there is no such element
  354. */
  355. function isScrolledPast(el, elSide, parentSide) {
  356. var parent = getParentAutoScrollElement(el, true),
  357. elSideVal = getRect(el)[elSide];
  358. /* jshint boss:true */
  359. while (parent) {
  360. var parentSideVal = getRect(parent)[parentSide],
  361. visible = void 0;
  362. if (parentSide === 'top' || parentSide === 'left') {
  363. visible = elSideVal >= parentSideVal;
  364. } else {
  365. visible = elSideVal <= parentSideVal;
  366. }
  367. if (!visible) return parent;
  368. if (parent === getWindowScrollingElement()) break;
  369. parent = getParentAutoScrollElement(parent, false);
  370. }
  371. return false;
  372. }
  373. /**
  374. * Gets nth child of el, ignoring hidden children, sortable's elements (does not ignore clone if it's visible)
  375. * and non-draggable elements
  376. * @param {HTMLElement} el The parent element
  377. * @param {Number} childNum The index of the child
  378. * @param {Object} options Parent Sortable's options
  379. * @return {HTMLElement} The child at index childNum, or null if not found
  380. */
  381. function getChild(el, childNum, options, includeDragEl) {
  382. var currentChild = 0,
  383. i = 0,
  384. children = el.children;
  385. while (i < children.length) {
  386. if (children[i].style.display !== 'none' && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false)) {
  387. if (currentChild === childNum) {
  388. return children[i];
  389. }
  390. currentChild++;
  391. }
  392. i++;
  393. }
  394. return null;
  395. }
  396. /**
  397. * Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
  398. * @param {HTMLElement} el Parent element
  399. * @param {selector} selector Any other elements that should be ignored
  400. * @return {HTMLElement} The last child, ignoring ghostEl
  401. */
  402. function lastChild(el, selector) {
  403. var last = el.lastElementChild;
  404. while (last && (last === Sortable.ghost || css(last, 'display') === 'none' || selector && !matches(last, selector))) {
  405. last = last.previousElementSibling;
  406. }
  407. return last || null;
  408. }
  409. /**
  410. * Returns the index of an element within its parent for a selected set of
  411. * elements
  412. * @param {HTMLElement} el
  413. * @param {selector} selector
  414. * @return {number}
  415. */
  416. function index(el, selector) {
  417. var index = 0;
  418. if (!el || !el.parentNode) {
  419. return -1;
  420. }
  421. /* jshint boss:true */
  422. while (el = el.previousElementSibling) {
  423. if (el.nodeName.toUpperCase() !== 'TEMPLATE' && el !== Sortable.clone && (!selector || matches(el, selector))) {
  424. index++;
  425. }
  426. }
  427. return index;
  428. }
  429. /**
  430. * Returns the scroll offset of the given element, added with all the scroll offsets of parent elements.
  431. * The value is returned in real pixels.
  432. * @param {HTMLElement} el
  433. * @return {Array} Offsets in the format of [left, top]
  434. */
  435. function getRelativeScrollOffset(el) {
  436. var offsetLeft = 0,
  437. offsetTop = 0,
  438. winScroller = getWindowScrollingElement();
  439. if (el) {
  440. do {
  441. var elMatrix = matrix(el),
  442. scaleX = elMatrix.a,
  443. scaleY = elMatrix.d;
  444. offsetLeft += el.scrollLeft * scaleX;
  445. offsetTop += el.scrollTop * scaleY;
  446. } while (el !== winScroller && (el = el.parentNode));
  447. }
  448. return [offsetLeft, offsetTop];
  449. }
  450. /**
  451. * Returns the index of the object within the given array
  452. * @param {Array} arr Array that may or may not hold the object
  453. * @param {Object} obj An object that has a key-value pair unique to and identical to a key-value pair in the object you want to find
  454. * @return {Number} The index of the object in the array, or -1
  455. */
  456. function indexOfObject(arr, obj) {
  457. for (var i in arr) {
  458. if (!arr.hasOwnProperty(i)) continue;
  459. for (var key in obj) {
  460. if (obj.hasOwnProperty(key) && obj[key] === arr[i][key]) return Number(i);
  461. }
  462. }
  463. return -1;
  464. }
  465. function getParentAutoScrollElement(el, includeSelf) {
  466. // skip to window
  467. if (!el || !el.getBoundingClientRect) return getWindowScrollingElement();
  468. var elem = el;
  469. var gotSelf = false;
  470. do {
  471. // we don't need to get elem css if it isn't even overflowing in the first place (performance)
  472. if (elem.clientWidth < elem.scrollWidth || elem.clientHeight < elem.scrollHeight) {
  473. var elemCSS = css(elem);
  474. if (elem.clientWidth < elem.scrollWidth && (elemCSS.overflowX == 'auto' || elemCSS.overflowX == 'scroll') || elem.clientHeight < elem.scrollHeight && (elemCSS.overflowY == 'auto' || elemCSS.overflowY == 'scroll')) {
  475. if (!elem.getBoundingClientRect || elem === document.body) return getWindowScrollingElement();
  476. if (gotSelf || includeSelf) return elem;
  477. gotSelf = true;
  478. }
  479. }
  480. /* jshint boss:true */
  481. } while (elem = elem.parentNode);
  482. return getWindowScrollingElement();
  483. }
  484. function extend(dst, src) {
  485. if (dst && src) {
  486. for (var key in src) {
  487. if (src.hasOwnProperty(key)) {
  488. dst[key] = src[key];
  489. }
  490. }
  491. }
  492. return dst;
  493. }
  494. function isRectEqual(rect1, rect2) {
  495. return Math.round(rect1.top) === Math.round(rect2.top) && Math.round(rect1.left) === Math.round(rect2.left) && Math.round(rect1.height) === Math.round(rect2.height) && Math.round(rect1.width) === Math.round(rect2.width);
  496. }
  497. var _throttleTimeout;
  498. function throttle(callback, ms) {
  499. return function () {
  500. if (!_throttleTimeout) {
  501. var args = arguments,
  502. _this = this;
  503. if (args.length === 1) {
  504. callback.call(_this, args[0]);
  505. } else {
  506. callback.apply(_this, args);
  507. }
  508. _throttleTimeout = setTimeout(function () {
  509. _throttleTimeout = void 0;
  510. }, ms);
  511. }
  512. };
  513. }
  514. function cancelThrottle() {
  515. clearTimeout(_throttleTimeout);
  516. _throttleTimeout = void 0;
  517. }
  518. function scrollBy(el, x, y) {
  519. el.scrollLeft += x;
  520. el.scrollTop += y;
  521. }
  522. function clone(el) {
  523. var Polymer = window.Polymer;
  524. var $ = window.jQuery || window.Zepto;
  525. if (Polymer && Polymer.dom) {
  526. return Polymer.dom(el).cloneNode(true);
  527. } else if ($) {
  528. return $(el).clone(true)[0];
  529. } else {
  530. return el.cloneNode(true);
  531. }
  532. }
  533. function setRect(el, rect) {
  534. css(el, 'position', 'absolute');
  535. css(el, 'top', rect.top);
  536. css(el, 'left', rect.left);
  537. css(el, 'width', rect.width);
  538. css(el, 'height', rect.height);
  539. }
  540. function unsetRect(el) {
  541. css(el, 'position', '');
  542. css(el, 'top', '');
  543. css(el, 'left', '');
  544. css(el, 'width', '');
  545. css(el, 'height', '');
  546. }
  547. var expando = 'Sortable' + new Date().getTime();
  548. function AnimationStateManager() {
  549. var animationStates = [],
  550. animationCallbackId;
  551. return {
  552. captureAnimationState: function captureAnimationState() {
  553. animationStates = [];
  554. if (!this.options.animation) return;
  555. var children = [].slice.call(this.el.children);
  556. children.forEach(function (child) {
  557. if (css(child, 'display') === 'none' || child === Sortable.ghost) return;
  558. animationStates.push({
  559. target: child,
  560. rect: getRect(child)
  561. });
  562. var fromRect = _objectSpread2({}, animationStates[animationStates.length - 1].rect);
  563. // If animating: compensate for current animation
  564. if (child.thisAnimationDuration) {
  565. var childMatrix = matrix(child, true);
  566. if (childMatrix) {
  567. fromRect.top -= childMatrix.f;
  568. fromRect.left -= childMatrix.e;
  569. }
  570. }
  571. child.fromRect = fromRect;
  572. });
  573. },
  574. addAnimationState: function addAnimationState(state) {
  575. animationStates.push(state);
  576. },
  577. removeAnimationState: function removeAnimationState(target) {
  578. animationStates.splice(indexOfObject(animationStates, {
  579. target: target
  580. }), 1);
  581. },
  582. animateAll: function animateAll(callback) {
  583. var _this = this;
  584. if (!this.options.animation) {
  585. clearTimeout(animationCallbackId);
  586. if (typeof callback === 'function') callback();
  587. return;
  588. }
  589. var animating = false,
  590. animationTime = 0;
  591. animationStates.forEach(function (state) {
  592. var time = 0,
  593. target = state.target,
  594. fromRect = target.fromRect,
  595. toRect = getRect(target),
  596. prevFromRect = target.prevFromRect,
  597. prevToRect = target.prevToRect,
  598. animatingRect = state.rect,
  599. targetMatrix = matrix(target, true);
  600. if (targetMatrix) {
  601. // Compensate for current animation
  602. toRect.top -= targetMatrix.f;
  603. toRect.left -= targetMatrix.e;
  604. }
  605. target.toRect = toRect;
  606. if (target.thisAnimationDuration) {
  607. // Could also check if animatingRect is between fromRect and toRect
  608. if (isRectEqual(prevFromRect, toRect) && !isRectEqual(fromRect, toRect) &&
  609. // Make sure animatingRect is on line between toRect & fromRect
  610. (animatingRect.top - toRect.top) / (animatingRect.left - toRect.left) === (fromRect.top - toRect.top) / (fromRect.left - toRect.left)) {
  611. // If returning to same place as started from animation and on same axis
  612. time = calculateRealTime(animatingRect, prevFromRect, prevToRect, _this.options);
  613. }
  614. }
  615. // if fromRect != toRect: animate
  616. if (!isRectEqual(toRect, fromRect)) {
  617. target.prevFromRect = fromRect;
  618. target.prevToRect = toRect;
  619. if (!time) {
  620. time = _this.options.animation;
  621. }
  622. _this.animate(target, animatingRect, toRect, time);
  623. }
  624. if (time) {
  625. animating = true;
  626. animationTime = Math.max(animationTime, time);
  627. clearTimeout(target.animationResetTimer);
  628. target.animationResetTimer = setTimeout(function () {
  629. target.animationTime = 0;
  630. target.prevFromRect = null;
  631. target.fromRect = null;
  632. target.prevToRect = null;
  633. target.thisAnimationDuration = null;
  634. }, time);
  635. target.thisAnimationDuration = time;
  636. }
  637. });
  638. clearTimeout(animationCallbackId);
  639. if (!animating) {
  640. if (typeof callback === 'function') callback();
  641. } else {
  642. animationCallbackId = setTimeout(function () {
  643. if (typeof callback === 'function') callback();
  644. }, animationTime);
  645. }
  646. animationStates = [];
  647. },
  648. animate: function animate(target, currentRect, toRect, duration) {
  649. if (duration) {
  650. css(target, 'transition', '');
  651. css(target, 'transform', '');
  652. var elMatrix = matrix(this.el),
  653. scaleX = elMatrix && elMatrix.a,
  654. scaleY = elMatrix && elMatrix.d,
  655. translateX = (currentRect.left - toRect.left) / (scaleX || 1),
  656. translateY = (currentRect.top - toRect.top) / (scaleY || 1);
  657. target.animatingX = !!translateX;
  658. target.animatingY = !!translateY;
  659. css(target, 'transform', 'translate3d(' + translateX + 'px,' + translateY + 'px,0)');
  660. this.forRepaintDummy = repaint(target); // repaint
  661. css(target, 'transition', 'transform ' + duration + 'ms' + (this.options.easing ? ' ' + this.options.easing : ''));
  662. css(target, 'transform', 'translate3d(0,0,0)');
  663. typeof target.animated === 'number' && clearTimeout(target.animated);
  664. target.animated = setTimeout(function () {
  665. css(target, 'transition', '');
  666. css(target, 'transform', '');
  667. target.animated = false;
  668. target.animatingX = false;
  669. target.animatingY = false;
  670. }, duration);
  671. }
  672. }
  673. };
  674. }
  675. function repaint(target) {
  676. return target.offsetWidth;
  677. }
  678. function calculateRealTime(animatingRect, fromRect, toRect, options) {
  679. return Math.sqrt(Math.pow(fromRect.top - animatingRect.top, 2) + Math.pow(fromRect.left - animatingRect.left, 2)) / Math.sqrt(Math.pow(fromRect.top - toRect.top, 2) + Math.pow(fromRect.left - toRect.left, 2)) * options.animation;
  680. }
  681. var plugins = [];
  682. var defaults = {
  683. initializeByDefault: true
  684. };
  685. var PluginManager = {
  686. mount: function mount(plugin) {
  687. // Set default static properties
  688. for (var option in defaults) {
  689. if (defaults.hasOwnProperty(option) && !(option in plugin)) {
  690. plugin[option] = defaults[option];
  691. }
  692. }
  693. plugins.forEach(function (p) {
  694. if (p.pluginName === plugin.pluginName) {
  695. throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
  696. }
  697. });
  698. plugins.push(plugin);
  699. },
  700. pluginEvent: function pluginEvent(eventName, sortable, evt) {
  701. var _this = this;
  702. this.eventCanceled = false;
  703. evt.cancel = function () {
  704. _this.eventCanceled = true;
  705. };
  706. var eventNameGlobal = eventName + 'Global';
  707. plugins.forEach(function (plugin) {
  708. if (!sortable[plugin.pluginName]) return;
  709. // Fire global events if it exists in this sortable
  710. if (sortable[plugin.pluginName][eventNameGlobal]) {
  711. sortable[plugin.pluginName][eventNameGlobal](_objectSpread2({
  712. sortable: sortable
  713. }, evt));
  714. }
  715. // Only fire plugin event if plugin is enabled in this sortable,
  716. // and plugin has event defined
  717. if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) {
  718. sortable[plugin.pluginName][eventName](_objectSpread2({
  719. sortable: sortable
  720. }, evt));
  721. }
  722. });
  723. },
  724. initializePlugins: function initializePlugins(sortable, el, defaults, options) {
  725. plugins.forEach(function (plugin) {
  726. var pluginName = plugin.pluginName;
  727. if (!sortable.options[pluginName] && !plugin.initializeByDefault) return;
  728. var initialized = new plugin(sortable, el, sortable.options);
  729. initialized.sortable = sortable;
  730. initialized.options = sortable.options;
  731. sortable[pluginName] = initialized;
  732. // Add default options from plugin
  733. _extends(defaults, initialized.defaults);
  734. });
  735. for (var option in sortable.options) {
  736. if (!sortable.options.hasOwnProperty(option)) continue;
  737. var modified = this.modifyOption(sortable, option, sortable.options[option]);
  738. if (typeof modified !== 'undefined') {
  739. sortable.options[option] = modified;
  740. }
  741. }
  742. },
  743. getEventProperties: function getEventProperties(name, sortable) {
  744. var eventProperties = {};
  745. plugins.forEach(function (plugin) {
  746. if (typeof plugin.eventProperties !== 'function') return;
  747. _extends(eventProperties, plugin.eventProperties.call(sortable[plugin.pluginName], name));
  748. });
  749. return eventProperties;
  750. },
  751. modifyOption: function modifyOption(sortable, name, value) {
  752. var modifiedValue;
  753. plugins.forEach(function (plugin) {
  754. // Plugin must exist on the Sortable
  755. if (!sortable[plugin.pluginName]) return;
  756. // If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
  757. if (plugin.optionListeners && typeof plugin.optionListeners[name] === 'function') {
  758. modifiedValue = plugin.optionListeners[name].call(sortable[plugin.pluginName], value);
  759. }
  760. });
  761. return modifiedValue;
  762. }
  763. };
  764. function dispatchEvent(_ref) {
  765. var sortable = _ref.sortable,
  766. rootEl = _ref.rootEl,
  767. name = _ref.name,
  768. targetEl = _ref.targetEl,
  769. cloneEl = _ref.cloneEl,
  770. toEl = _ref.toEl,
  771. fromEl = _ref.fromEl,
  772. oldIndex = _ref.oldIndex,
  773. newIndex = _ref.newIndex,
  774. oldDraggableIndex = _ref.oldDraggableIndex,
  775. newDraggableIndex = _ref.newDraggableIndex,
  776. originalEvent = _ref.originalEvent,
  777. putSortable = _ref.putSortable,
  778. extraEventProperties = _ref.extraEventProperties;
  779. sortable = sortable || rootEl && rootEl[expando];
  780. if (!sortable) return;
  781. var evt,
  782. options = sortable.options,
  783. onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
  784. // Support for new CustomEvent feature
  785. if (window.CustomEvent && !IE11OrLess && !Edge) {
  786. evt = new CustomEvent(name, {
  787. bubbles: true,
  788. cancelable: true
  789. });
  790. } else {
  791. evt = document.createEvent('Event');
  792. evt.initEvent(name, true, true);
  793. }
  794. evt.to = toEl || rootEl;
  795. evt.from = fromEl || rootEl;
  796. evt.item = targetEl || rootEl;
  797. evt.clone = cloneEl;
  798. evt.oldIndex = oldIndex;
  799. evt.newIndex = newIndex;
  800. evt.oldDraggableIndex = oldDraggableIndex;
  801. evt.newDraggableIndex = newDraggableIndex;
  802. evt.originalEvent = originalEvent;
  803. evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
  804. var allEventProperties = _objectSpread2(_objectSpread2({}, extraEventProperties), PluginManager.getEventProperties(name, sortable));
  805. for (var option in allEventProperties) {
  806. evt[option] = allEventProperties[option];
  807. }
  808. if (rootEl) {
  809. rootEl.dispatchEvent(evt);
  810. }
  811. if (options[onName]) {
  812. options[onName].call(sortable, evt);
  813. }
  814. }
  815. var _excluded = ["evt"];
  816. var pluginEvent = function pluginEvent(eventName, sortable) {
  817. var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
  818. originalEvent = _ref.evt,
  819. data = _objectWithoutProperties(_ref, _excluded);
  820. PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread2({
  821. dragEl: dragEl,
  822. parentEl: parentEl,
  823. ghostEl: ghostEl,
  824. rootEl: rootEl,
  825. nextEl: nextEl,
  826. lastDownEl: lastDownEl,
  827. cloneEl: cloneEl,
  828. cloneHidden: cloneHidden,
  829. dragStarted: moved,
  830. putSortable: putSortable,
  831. activeSortable: Sortable.active,
  832. originalEvent: originalEvent,
  833. oldIndex: oldIndex,
  834. oldDraggableIndex: oldDraggableIndex,
  835. newIndex: newIndex,
  836. newDraggableIndex: newDraggableIndex,
  837. hideGhostForTarget: _hideGhostForTarget,
  838. unhideGhostForTarget: _unhideGhostForTarget,
  839. cloneNowHidden: function cloneNowHidden() {
  840. cloneHidden = true;
  841. },
  842. cloneNowShown: function cloneNowShown() {
  843. cloneHidden = false;
  844. },
  845. dispatchSortableEvent: function dispatchSortableEvent(name) {
  846. _dispatchEvent({
  847. sortable: sortable,
  848. name: name,
  849. originalEvent: originalEvent
  850. });
  851. }
  852. }, data));
  853. };
  854. function _dispatchEvent(info) {
  855. dispatchEvent(_objectSpread2({
  856. putSortable: putSortable,
  857. cloneEl: cloneEl,
  858. targetEl: dragEl,
  859. rootEl: rootEl,
  860. oldIndex: oldIndex,
  861. oldDraggableIndex: oldDraggableIndex,
  862. newIndex: newIndex,
  863. newDraggableIndex: newDraggableIndex
  864. }, info));
  865. }
  866. var dragEl,
  867. parentEl,
  868. ghostEl,
  869. rootEl,
  870. nextEl,
  871. lastDownEl,
  872. cloneEl,
  873. cloneHidden,
  874. oldIndex,
  875. newIndex,
  876. oldDraggableIndex,
  877. newDraggableIndex,
  878. activeGroup,
  879. putSortable,
  880. awaitingDragStarted = false,
  881. ignoreNextClick = false,
  882. sortables = [],
  883. tapEvt,
  884. touchEvt,
  885. lastDx,
  886. lastDy,
  887. tapDistanceLeft,
  888. tapDistanceTop,
  889. moved,
  890. lastTarget,
  891. lastDirection,
  892. pastFirstInvertThresh = false,
  893. isCircumstantialInvert = false,
  894. targetMoveDistance,
  895. // For positioning ghost absolutely
  896. ghostRelativeParent,
  897. ghostRelativeParentInitialScroll = [],
  898. // (left, top)
  899. _silent = false,
  900. savedInputChecked = [];
  901. /** @const */
  902. var documentExists = typeof document !== 'undefined',
  903. PositionGhostAbsolutely = IOS,
  904. CSSFloatProperty = Edge || IE11OrLess ? 'cssFloat' : 'float',
  905. // This will not pass for IE9, because IE9 DnD only works on anchors
  906. supportDraggable = documentExists && !ChromeForAndroid && !IOS && 'draggable' in document.createElement('div'),
  907. supportCssPointerEvents = function () {
  908. if (!documentExists) return;
  909. // false when <= IE11
  910. if (IE11OrLess) {
  911. return false;
  912. }
  913. var el = document.createElement('x');
  914. el.style.cssText = 'pointer-events:auto';
  915. return el.style.pointerEvents === 'auto';
  916. }(),
  917. _detectDirection = function _detectDirection(el, options) {
  918. var elCSS = css(el),
  919. elWidth = parseInt(elCSS.width) - parseInt(elCSS.paddingLeft) - parseInt(elCSS.paddingRight) - parseInt(elCSS.borderLeftWidth) - parseInt(elCSS.borderRightWidth),
  920. child1 = getChild(el, 0, options),
  921. child2 = getChild(el, 1, options),
  922. firstChildCSS = child1 && css(child1),
  923. secondChildCSS = child2 && css(child2),
  924. firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + getRect(child1).width,
  925. secondChildWidth = secondChildCSS && parseInt(secondChildCSS.marginLeft) + parseInt(secondChildCSS.marginRight) + getRect(child2).width;
  926. if (elCSS.display === 'flex') {
  927. return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse' ? 'vertical' : 'horizontal';
  928. }
  929. if (elCSS.display === 'grid') {
  930. return elCSS.gridTemplateColumns.split(' ').length <= 1 ? 'vertical' : 'horizontal';
  931. }
  932. if (child1 && firstChildCSS["float"] && firstChildCSS["float"] !== 'none') {
  933. var touchingSideChild2 = firstChildCSS["float"] === 'left' ? 'left' : 'right';
  934. return child2 && (secondChildCSS.clear === 'both' || secondChildCSS.clear === touchingSideChild2) ? 'vertical' : 'horizontal';
  935. }
  936. return child1 && (firstChildCSS.display === 'block' || firstChildCSS.display === 'flex' || firstChildCSS.display === 'table' || firstChildCSS.display === 'grid' || firstChildWidth >= elWidth && elCSS[CSSFloatProperty] === 'none' || child2 && elCSS[CSSFloatProperty] === 'none' && firstChildWidth + secondChildWidth > elWidth) ? 'vertical' : 'horizontal';
  937. },
  938. _dragElInRowColumn = function _dragElInRowColumn(dragRect, targetRect, vertical) {
  939. var dragElS1Opp = vertical ? dragRect.left : dragRect.top,
  940. dragElS2Opp = vertical ? dragRect.right : dragRect.bottom,
  941. dragElOppLength = vertical ? dragRect.width : dragRect.height,
  942. targetS1Opp = vertical ? targetRect.left : targetRect.top,
  943. targetS2Opp = vertical ? targetRect.right : targetRect.bottom,
  944. targetOppLength = vertical ? targetRect.width : targetRect.height;
  945. return dragElS1Opp === targetS1Opp || dragElS2Opp === targetS2Opp || dragElS1Opp + dragElOppLength / 2 === targetS1Opp + targetOppLength / 2;
  946. },
  947. /**
  948. * Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
  949. * @param {Number} x X position
  950. * @param {Number} y Y position
  951. * @return {HTMLElement} Element of the first found nearest Sortable
  952. */
  953. _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
  954. var ret;
  955. sortables.some(function (sortable) {
  956. var threshold = sortable[expando].options.emptyInsertThreshold;
  957. if (!threshold || lastChild(sortable)) return;
  958. var rect = getRect(sortable),
  959. insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold,
  960. insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold;
  961. if (insideHorizontally && insideVertically) {
  962. return ret = sortable;
  963. }
  964. });
  965. return ret;
  966. },
  967. _prepareGroup = function _prepareGroup(options) {
  968. function toFn(value, pull) {
  969. return function (to, from, dragEl, evt) {
  970. var sameGroup = to.options.group.name && from.options.group.name && to.options.group.name === from.options.group.name;
  971. if (value == null && (pull || sameGroup)) {
  972. // Default pull value
  973. // Default pull and put value if same group
  974. return true;
  975. } else if (value == null || value === false) {
  976. return false;
  977. } else if (pull && value === 'clone') {
  978. return value;
  979. } else if (typeof value === 'function') {
  980. return toFn(value(to, from, dragEl, evt), pull)(to, from, dragEl, evt);
  981. } else {
  982. var otherGroup = (pull ? to : from).options.group.name;
  983. return value === true || typeof value === 'string' && value === otherGroup || value.join && value.indexOf(otherGroup) > -1;
  984. }
  985. };
  986. }
  987. var group = {};
  988. var originalGroup = options.group;
  989. if (!originalGroup || _typeof(originalGroup) != 'object') {
  990. originalGroup = {
  991. name: originalGroup
  992. };
  993. }
  994. group.name = originalGroup.name;
  995. group.checkPull = toFn(originalGroup.pull, true);
  996. group.checkPut = toFn(originalGroup.put);
  997. group.revertClone = originalGroup.revertClone;
  998. options.group = group;
  999. },
  1000. _hideGhostForTarget = function _hideGhostForTarget() {
  1001. if (!supportCssPointerEvents && ghostEl) {
  1002. css(ghostEl, 'display', 'none');
  1003. }
  1004. },
  1005. _unhideGhostForTarget = function _unhideGhostForTarget() {
  1006. if (!supportCssPointerEvents && ghostEl) {
  1007. css(ghostEl, 'display', '');
  1008. }
  1009. };
  1010. // #1184 fix - Prevent click event on fallback if dragged but item not changed position
  1011. if (documentExists && !ChromeForAndroid) {
  1012. document.addEventListener('click', function (evt) {
  1013. if (ignoreNextClick) {
  1014. evt.preventDefault();
  1015. evt.stopPropagation && evt.stopPropagation();
  1016. evt.stopImmediatePropagation && evt.stopImmediatePropagation();
  1017. ignoreNextClick = false;
  1018. return false;
  1019. }
  1020. }, true);
  1021. }
  1022. var nearestEmptyInsertDetectEvent = function nearestEmptyInsertDetectEvent(evt) {
  1023. if (dragEl) {
  1024. evt = evt.touches ? evt.touches[0] : evt;
  1025. var nearest = _detectNearestEmptySortable(evt.clientX, evt.clientY);
  1026. if (nearest) {
  1027. // Create imitation event
  1028. var event = {};
  1029. for (var i in evt) {
  1030. if (evt.hasOwnProperty(i)) {
  1031. event[i] = evt[i];
  1032. }
  1033. }
  1034. event.target = event.rootEl = nearest;
  1035. event.preventDefault = void 0;
  1036. event.stopPropagation = void 0;
  1037. nearest[expando]._onDragOver(event);
  1038. }
  1039. }
  1040. };
  1041. var _checkOutsideTargetEl = function _checkOutsideTargetEl(evt) {
  1042. if (dragEl) {
  1043. dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
  1044. }
  1045. };
  1046. /**
  1047. * @class Sortable
  1048. * @param {HTMLElement} el
  1049. * @param {Object} [options]
  1050. */
  1051. function Sortable(el, options) {
  1052. if (!(el && el.nodeType && el.nodeType === 1)) {
  1053. throw "Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(el));
  1054. }
  1055. this.el = el; // root element
  1056. this.options = options = _extends({}, options);
  1057. // Export instance
  1058. el[expando] = this;
  1059. var defaults = {
  1060. group: null,
  1061. sort: true,
  1062. disabled: false,
  1063. store: null,
  1064. handle: null,
  1065. draggable: /^[uo]l$/i.test(el.nodeName) ? '>li' : '>*',
  1066. swapThreshold: 1,
  1067. // percentage; 0 <= x <= 1
  1068. invertSwap: false,
  1069. // invert always
  1070. invertedSwapThreshold: null,
  1071. // will be set to same as swapThreshold if default
  1072. removeCloneOnHide: true,
  1073. direction: function direction() {
  1074. return _detectDirection(el, this.options);
  1075. },
  1076. ghostClass: 'sortable-ghost',
  1077. chosenClass: 'sortable-chosen',
  1078. dragClass: 'sortable-drag',
  1079. ignore: 'a, img',
  1080. filter: null,
  1081. preventOnFilter: true,
  1082. animation: 0,
  1083. easing: null,
  1084. setData: function setData(dataTransfer, dragEl) {
  1085. dataTransfer.setData('Text', dragEl.textContent);
  1086. },
  1087. dropBubble: false,
  1088. dragoverBubble: false,
  1089. dataIdAttr: 'data-id',
  1090. delay: 0,
  1091. delayOnTouchOnly: false,
  1092. touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
  1093. forceFallback: false,
  1094. fallbackClass: 'sortable-fallback',
  1095. fallbackOnBody: false,
  1096. fallbackTolerance: 0,
  1097. fallbackOffset: {
  1098. x: 0,
  1099. y: 0
  1100. },
  1101. supportPointer: Sortable.supportPointer !== false && 'PointerEvent' in window && !Safari,
  1102. emptyInsertThreshold: 5
  1103. };
  1104. PluginManager.initializePlugins(this, el, defaults);
  1105. // Set default options
  1106. for (var name in defaults) {
  1107. !(name in options) && (options[name] = defaults[name]);
  1108. }
  1109. _prepareGroup(options);
  1110. // Bind all private methods
  1111. for (var fn in this) {
  1112. if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
  1113. this[fn] = this[fn].bind(this);
  1114. }
  1115. }
  1116. // Setup drag mode
  1117. this.nativeDraggable = options.forceFallback ? false : supportDraggable;
  1118. if (this.nativeDraggable) {
  1119. // Touch start threshold cannot be greater than the native dragstart threshold
  1120. this.options.touchStartThreshold = 1;
  1121. }
  1122. // Bind events
  1123. if (options.supportPointer) {
  1124. on(el, 'pointerdown', this._onTapStart);
  1125. } else {
  1126. on(el, 'mousedown', this._onTapStart);
  1127. on(el, 'touchstart', this._onTapStart);
  1128. }
  1129. if (this.nativeDraggable) {
  1130. on(el, 'dragover', this);
  1131. on(el, 'dragenter', this);
  1132. }
  1133. sortables.push(this.el);
  1134. // Restore sorting
  1135. options.store && options.store.get && this.sort(options.store.get(this) || []);
  1136. // Add animation state manager
  1137. _extends(this, AnimationStateManager());
  1138. }
  1139. Sortable.prototype = /** @lends Sortable.prototype */{
  1140. constructor: Sortable,
  1141. _isOutsideThisEl: function _isOutsideThisEl(target) {
  1142. if (!this.el.contains(target) && target !== this.el) {
  1143. lastTarget = null;
  1144. }
  1145. },
  1146. _getDirection: function _getDirection(evt, target) {
  1147. return typeof this.options.direction === 'function' ? this.options.direction.call(this, evt, target, dragEl) : this.options.direction;
  1148. },
  1149. _onTapStart: function _onTapStart( /** Event|TouchEvent */evt) {
  1150. if (!evt.cancelable) return;
  1151. var _this = this,
  1152. el = this.el,
  1153. options = this.options,
  1154. preventOnFilter = options.preventOnFilter,
  1155. type = evt.type,
  1156. touch = evt.touches && evt.touches[0] || evt.pointerType && evt.pointerType === 'touch' && evt,
  1157. target = (touch || evt).target,
  1158. originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0] || evt.composedPath && evt.composedPath()[0]) || target,
  1159. filter = options.filter;
  1160. _saveInputCheckedState(el);
  1161. // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
  1162. if (dragEl) {
  1163. return;
  1164. }
  1165. if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
  1166. return; // only left button and enabled
  1167. }
  1168. // cancel dnd if original target is content editable
  1169. if (originalTarget.isContentEditable) {
  1170. return;
  1171. }
  1172. // Safari ignores further event handling after mousedown
  1173. if (!this.nativeDraggable && Safari && target && target.tagName.toUpperCase() === 'SELECT') {
  1174. return;
  1175. }
  1176. target = closest(target, options.draggable, el, false);
  1177. if (target && target.animated) {
  1178. return;
  1179. }
  1180. if (lastDownEl === target) {
  1181. // Ignoring duplicate `down`
  1182. return;
  1183. }
  1184. // Get the index of the dragged element within its parent
  1185. oldIndex = index(target);
  1186. oldDraggableIndex = index(target, options.draggable);
  1187. // Check filter
  1188. if (typeof filter === 'function') {
  1189. if (filter.call(this, evt, target, this)) {
  1190. _dispatchEvent({
  1191. sortable: _this,
  1192. rootEl: originalTarget,
  1193. name: 'filter',
  1194. targetEl: target,
  1195. toEl: el,
  1196. fromEl: el
  1197. });
  1198. pluginEvent('filter', _this, {
  1199. evt: evt
  1200. });
  1201. preventOnFilter && evt.cancelable && evt.preventDefault();
  1202. return; // cancel dnd
  1203. }
  1204. } else if (filter) {
  1205. filter = filter.split(',').some(function (criteria) {
  1206. criteria = closest(originalTarget, criteria.trim(), el, false);
  1207. if (criteria) {
  1208. _dispatchEvent({
  1209. sortable: _this,
  1210. rootEl: criteria,
  1211. name: 'filter',
  1212. targetEl: target,
  1213. fromEl: el,
  1214. toEl: el
  1215. });
  1216. pluginEvent('filter', _this, {
  1217. evt: evt
  1218. });
  1219. return true;
  1220. }
  1221. });
  1222. if (filter) {
  1223. preventOnFilter && evt.cancelable && evt.preventDefault();
  1224. return; // cancel dnd
  1225. }
  1226. }
  1227. if (options.handle && !closest(originalTarget, options.handle, el, false)) {
  1228. return;
  1229. }
  1230. // Prepare `dragstart`
  1231. this._prepareDragStart(evt, touch, target);
  1232. },
  1233. _prepareDragStart: function _prepareDragStart( /** Event */evt, /** Touch */touch, /** HTMLElement */target) {
  1234. var _this = this,
  1235. el = _this.el,
  1236. options = _this.options,
  1237. ownerDocument = el.ownerDocument,
  1238. dragStartFn;
  1239. if (target && !dragEl && target.parentNode === el) {
  1240. var dragRect = getRect(target);
  1241. rootEl = el;
  1242. dragEl = target;
  1243. parentEl = dragEl.parentNode;
  1244. nextEl = dragEl.nextSibling;
  1245. lastDownEl = target;
  1246. activeGroup = options.group;
  1247. Sortable.dragged = dragEl;
  1248. tapEvt = {
  1249. target: dragEl,
  1250. clientX: (touch || evt).clientX,
  1251. clientY: (touch || evt).clientY
  1252. };
  1253. tapDistanceLeft = tapEvt.clientX - dragRect.left;
  1254. tapDistanceTop = tapEvt.clientY - dragRect.top;
  1255. this._lastX = (touch || evt).clientX;
  1256. this._lastY = (touch || evt).clientY;
  1257. dragEl.style['will-change'] = 'all';
  1258. dragStartFn = function dragStartFn() {
  1259. pluginEvent('delayEnded', _this, {
  1260. evt: evt
  1261. });
  1262. if (Sortable.eventCanceled) {
  1263. _this._onDrop();
  1264. return;
  1265. }
  1266. // Delayed drag has been triggered
  1267. // we can re-enable the events: touchmove/mousemove
  1268. _this._disableDelayedDragEvents();
  1269. if (!FireFox && _this.nativeDraggable) {
  1270. dragEl.draggable = true;
  1271. }
  1272. // Bind the events: dragstart/dragend
  1273. _this._triggerDragStart(evt, touch);
  1274. // Drag start event
  1275. _dispatchEvent({
  1276. sortable: _this,
  1277. name: 'choose',
  1278. originalEvent: evt
  1279. });
  1280. // Chosen item
  1281. toggleClass(dragEl, options.chosenClass, true);
  1282. };
  1283. // Disable "draggable"
  1284. options.ignore.split(',').forEach(function (criteria) {
  1285. find(dragEl, criteria.trim(), _disableDraggable);
  1286. });
  1287. on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
  1288. on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
  1289. on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
  1290. on(ownerDocument, 'mouseup', _this._onDrop);
  1291. on(ownerDocument, 'touchend', _this._onDrop);
  1292. on(ownerDocument, 'touchcancel', _this._onDrop);
  1293. // Make dragEl draggable (must be before delay for FireFox)
  1294. if (FireFox && this.nativeDraggable) {
  1295. this.options.touchStartThreshold = 4;
  1296. dragEl.draggable = true;
  1297. }
  1298. pluginEvent('delayStart', this, {
  1299. evt: evt
  1300. });
  1301. // Delay is impossible for native DnD in Edge or IE
  1302. if (options.delay && (!options.delayOnTouchOnly || touch) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
  1303. if (Sortable.eventCanceled) {
  1304. this._onDrop();
  1305. return;
  1306. }
  1307. // If the user moves the pointer or let go the click or touch
  1308. // before the delay has been reached:
  1309. // disable the delayed drag
  1310. on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
  1311. on(ownerDocument, 'touchend', _this._disableDelayedDrag);
  1312. on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
  1313. on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
  1314. on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
  1315. options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
  1316. _this._dragStartTimer = setTimeout(dragStartFn, options.delay);
  1317. } else {
  1318. dragStartFn();
  1319. }
  1320. }
  1321. },
  1322. _delayedDragTouchMoveHandler: function _delayedDragTouchMoveHandler( /** TouchEvent|PointerEvent **/e) {
  1323. var touch = e.touches ? e.touches[0] : e;
  1324. if (Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) >= Math.floor(this.options.touchStartThreshold / (this.nativeDraggable && window.devicePixelRatio || 1))) {
  1325. this._disableDelayedDrag();
  1326. }
  1327. },
  1328. _disableDelayedDrag: function _disableDelayedDrag() {
  1329. dragEl && _disableDraggable(dragEl);
  1330. clearTimeout(this._dragStartTimer);
  1331. this._disableDelayedDragEvents();
  1332. },
  1333. _disableDelayedDragEvents: function _disableDelayedDragEvents() {
  1334. var ownerDocument = this.el.ownerDocument;
  1335. off(ownerDocument, 'mouseup', this._disableDelayedDrag);
  1336. off(ownerDocument, 'touchend', this._disableDelayedDrag);
  1337. off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
  1338. off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
  1339. off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
  1340. off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
  1341. },
  1342. _triggerDragStart: function _triggerDragStart( /** Event */evt, /** Touch */touch) {
  1343. touch = touch || evt.pointerType == 'touch' && evt;
  1344. if (!this.nativeDraggable || touch) {
  1345. if (this.options.supportPointer) {
  1346. on(document, 'pointermove', this._onTouchMove);
  1347. } else if (touch) {
  1348. on(document, 'touchmove', this._onTouchMove);
  1349. } else {
  1350. on(document, 'mousemove', this._onTouchMove);
  1351. }
  1352. } else {
  1353. on(dragEl, 'dragend', this);
  1354. on(rootEl, 'dragstart', this._onDragStart);
  1355. }
  1356. try {
  1357. if (document.selection) {
  1358. // Timeout neccessary for IE9
  1359. _nextTick(function () {
  1360. document.selection.empty();
  1361. });
  1362. } else {
  1363. window.getSelection().removeAllRanges();
  1364. }
  1365. } catch (err) {}
  1366. },
  1367. _dragStarted: function _dragStarted(fallback, evt) {
  1368. awaitingDragStarted = false;
  1369. if (rootEl && dragEl) {
  1370. pluginEvent('dragStarted', this, {
  1371. evt: evt
  1372. });
  1373. if (this.nativeDraggable) {
  1374. on(document, 'dragover', _checkOutsideTargetEl);
  1375. }
  1376. var options = this.options;
  1377. // Apply effect
  1378. !fallback && toggleClass(dragEl, options.dragClass, false);
  1379. toggleClass(dragEl, options.ghostClass, true);
  1380. Sortable.active = this;
  1381. fallback && this._appendGhost();
  1382. // Drag start event
  1383. _dispatchEvent({
  1384. sortable: this,
  1385. name: 'start',
  1386. originalEvent: evt
  1387. });
  1388. } else {
  1389. this._nulling();
  1390. }
  1391. },
  1392. _emulateDragOver: function _emulateDragOver() {
  1393. if (touchEvt) {
  1394. this._lastX = touchEvt.clientX;
  1395. this._lastY = touchEvt.clientY;
  1396. _hideGhostForTarget();
  1397. var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
  1398. var parent = target;
  1399. while (target && target.shadowRoot) {
  1400. target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
  1401. if (target === parent) break;
  1402. parent = target;
  1403. }
  1404. dragEl.parentNode[expando]._isOutsideThisEl(target);
  1405. if (parent) {
  1406. do {
  1407. if (parent[expando]) {
  1408. var inserted = void 0;
  1409. inserted = parent[expando]._onDragOver({
  1410. clientX: touchEvt.clientX,
  1411. clientY: touchEvt.clientY,
  1412. target: target,
  1413. rootEl: parent
  1414. });
  1415. if (inserted && !this.options.dragoverBubble) {
  1416. break;
  1417. }
  1418. }
  1419. target = parent; // store last element
  1420. }
  1421. /* jshint boss:true */ while (parent = parent.parentNode);
  1422. }
  1423. _unhideGhostForTarget();
  1424. }
  1425. },
  1426. _onTouchMove: function _onTouchMove( /**TouchEvent*/evt) {
  1427. if (tapEvt) {
  1428. var options = this.options,
  1429. fallbackTolerance = options.fallbackTolerance,
  1430. fallbackOffset = options.fallbackOffset,
  1431. touch = evt.touches ? evt.touches[0] : evt,
  1432. ghostMatrix = ghostEl && matrix(ghostEl, true),
  1433. scaleX = ghostEl && ghostMatrix && ghostMatrix.a,
  1434. scaleY = ghostEl && ghostMatrix && ghostMatrix.d,
  1435. relativeScrollOffset = PositionGhostAbsolutely && ghostRelativeParent && getRelativeScrollOffset(ghostRelativeParent),
  1436. dx = (touch.clientX - tapEvt.clientX + fallbackOffset.x) / (scaleX || 1) + (relativeScrollOffset ? relativeScrollOffset[0] - ghostRelativeParentInitialScroll[0] : 0) / (scaleX || 1),
  1437. dy = (touch.clientY - tapEvt.clientY + fallbackOffset.y) / (scaleY || 1) + (relativeScrollOffset ? relativeScrollOffset[1] - ghostRelativeParentInitialScroll[1] : 0) / (scaleY || 1);
  1438. // only set the status to dragging, when we are actually dragging
  1439. if (!Sortable.active && !awaitingDragStarted) {
  1440. if (fallbackTolerance && Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) < fallbackTolerance) {
  1441. return;
  1442. }
  1443. this._onDragStart(evt, true);
  1444. }
  1445. if (ghostEl) {
  1446. if (ghostMatrix) {
  1447. ghostMatrix.e += dx - (lastDx || 0);
  1448. ghostMatrix.f += dy - (lastDy || 0);
  1449. } else {
  1450. ghostMatrix = {
  1451. a: 1,
  1452. b: 0,
  1453. c: 0,
  1454. d: 1,
  1455. e: dx,
  1456. f: dy
  1457. };
  1458. }
  1459. var cssMatrix = "matrix(".concat(ghostMatrix.a, ",").concat(ghostMatrix.b, ",").concat(ghostMatrix.c, ",").concat(ghostMatrix.d, ",").concat(ghostMatrix.e, ",").concat(ghostMatrix.f, ")");
  1460. css(ghostEl, 'webkitTransform', cssMatrix);
  1461. css(ghostEl, 'mozTransform', cssMatrix);
  1462. css(ghostEl, 'msTransform', cssMatrix);
  1463. css(ghostEl, 'transform', cssMatrix);
  1464. lastDx = dx;
  1465. lastDy = dy;
  1466. touchEvt = touch;
  1467. }
  1468. evt.cancelable && evt.preventDefault();
  1469. }
  1470. },
  1471. _appendGhost: function _appendGhost() {
  1472. // Bug if using scale(): https://stackoverflow.com/questions/2637058
  1473. // Not being adjusted for
  1474. if (!ghostEl) {
  1475. var container = this.options.fallbackOnBody ? document.body : rootEl,
  1476. rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container),
  1477. options = this.options;
  1478. // Position absolutely
  1479. if (PositionGhostAbsolutely) {
  1480. // Get relatively positioned parent
  1481. ghostRelativeParent = container;
  1482. while (css(ghostRelativeParent, 'position') === 'static' && css(ghostRelativeParent, 'transform') === 'none' && ghostRelativeParent !== document) {
  1483. ghostRelativeParent = ghostRelativeParent.parentNode;
  1484. }
  1485. if (ghostRelativeParent !== document.body && ghostRelativeParent !== document.documentElement) {
  1486. if (ghostRelativeParent === document) ghostRelativeParent = getWindowScrollingElement();
  1487. rect.top += ghostRelativeParent.scrollTop;
  1488. rect.left += ghostRelativeParent.scrollLeft;
  1489. } else {
  1490. ghostRelativeParent = getWindowScrollingElement();
  1491. }
  1492. ghostRelativeParentInitialScroll = getRelativeScrollOffset(ghostRelativeParent);
  1493. }
  1494. ghostEl = dragEl.cloneNode(true);
  1495. toggleClass(ghostEl, options.ghostClass, false);
  1496. toggleClass(ghostEl, options.fallbackClass, true);
  1497. toggleClass(ghostEl, options.dragClass, true);
  1498. css(ghostEl, 'transition', '');
  1499. css(ghostEl, 'transform', '');
  1500. css(ghostEl, 'box-sizing', 'border-box');
  1501. css(ghostEl, 'margin', 0);
  1502. css(ghostEl, 'top', rect.top);
  1503. css(ghostEl, 'left', rect.left);
  1504. css(ghostEl, 'width', rect.width);
  1505. css(ghostEl, 'height', rect.height);
  1506. css(ghostEl, 'opacity', '0.8');
  1507. css(ghostEl, 'position', PositionGhostAbsolutely ? 'absolute' : 'fixed');
  1508. css(ghostEl, 'zIndex', '100000');
  1509. css(ghostEl, 'pointerEvents', 'none');
  1510. Sortable.ghost = ghostEl;
  1511. container.appendChild(ghostEl);
  1512. // Set transform-origin
  1513. css(ghostEl, 'transform-origin', tapDistanceLeft / parseInt(ghostEl.style.width) * 100 + '% ' + tapDistanceTop / parseInt(ghostEl.style.height) * 100 + '%');
  1514. }
  1515. },
  1516. _onDragStart: function _onDragStart( /**Event*/evt, /**boolean*/fallback) {
  1517. var _this = this;
  1518. var dataTransfer = evt.dataTransfer;
  1519. var options = _this.options;
  1520. pluginEvent('dragStart', this, {
  1521. evt: evt
  1522. });
  1523. if (Sortable.eventCanceled) {
  1524. this._onDrop();
  1525. return;
  1526. }
  1527. pluginEvent('setupClone', this);
  1528. if (!Sortable.eventCanceled) {
  1529. cloneEl = clone(dragEl);
  1530. cloneEl.removeAttribute("id");
  1531. cloneEl.draggable = false;
  1532. cloneEl.style['will-change'] = '';
  1533. this._hideClone();
  1534. toggleClass(cloneEl, this.options.chosenClass, false);
  1535. Sortable.clone = cloneEl;
  1536. }
  1537. // #1143: IFrame support workaround
  1538. _this.cloneId = _nextTick(function () {
  1539. pluginEvent('clone', _this);
  1540. if (Sortable.eventCanceled) return;
  1541. if (!_this.options.removeCloneOnHide) {
  1542. rootEl.insertBefore(cloneEl, dragEl);
  1543. }
  1544. _this._hideClone();
  1545. _dispatchEvent({
  1546. sortable: _this,
  1547. name: 'clone'
  1548. });
  1549. });
  1550. !fallback && toggleClass(dragEl, options.dragClass, true);
  1551. // Set proper drop events
  1552. if (fallback) {
  1553. ignoreNextClick = true;
  1554. _this._loopId = setInterval(_this._emulateDragOver, 50);
  1555. } else {
  1556. // Undo what was set in _prepareDragStart before drag started
  1557. off(document, 'mouseup', _this._onDrop);
  1558. off(document, 'touchend', _this._onDrop);
  1559. off(document, 'touchcancel', _this._onDrop);
  1560. if (dataTransfer) {
  1561. dataTransfer.effectAllowed = 'move';
  1562. options.setData && options.setData.call(_this, dataTransfer, dragEl);
  1563. }
  1564. on(document, 'drop', _this);
  1565. // #1276 fix:
  1566. css(dragEl, 'transform', 'translateZ(0)');
  1567. }
  1568. awaitingDragStarted = true;
  1569. _this._dragStartId = _nextTick(_this._dragStarted.bind(_this, fallback, evt));
  1570. on(document, 'selectstart', _this);
  1571. moved = true;
  1572. if (Safari) {
  1573. css(document.body, 'user-select', 'none');
  1574. }
  1575. },
  1576. // Returns true - if no further action is needed (either inserted or another condition)
  1577. _onDragOver: function _onDragOver( /**Event*/evt) {
  1578. var el = this.el,
  1579. target = evt.target,
  1580. dragRect,
  1581. targetRect,
  1582. revert,
  1583. options = this.options,
  1584. group = options.group,
  1585. activeSortable = Sortable.active,
  1586. isOwner = activeGroup === group,
  1587. canSort = options.sort,
  1588. fromSortable = putSortable || activeSortable,
  1589. vertical,
  1590. _this = this,
  1591. completedFired = false;
  1592. if (_silent) return;
  1593. function dragOverEvent(name, extra) {
  1594. pluginEvent(name, _this, _objectSpread2({
  1595. evt: evt,
  1596. isOwner: isOwner,
  1597. axis: vertical ? 'vertical' : 'horizontal',
  1598. revert: revert,
  1599. dragRect: dragRect,
  1600. targetRect: targetRect,
  1601. canSort: canSort,
  1602. fromSortable: fromSortable,
  1603. target: target,
  1604. completed: completed,
  1605. onMove: function onMove(target, after) {
  1606. return _onMove(rootEl, el, dragEl, dragRect, target, getRect(target), evt, after);
  1607. },
  1608. changed: changed
  1609. }, extra));
  1610. }
  1611. // Capture animation state
  1612. function capture() {
  1613. dragOverEvent('dragOverAnimationCapture');
  1614. _this.captureAnimationState();
  1615. if (_this !== fromSortable) {
  1616. fromSortable.captureAnimationState();
  1617. }
  1618. }
  1619. // Return invocation when dragEl is inserted (or completed)
  1620. function completed(insertion) {
  1621. dragOverEvent('dragOverCompleted', {
  1622. insertion: insertion
  1623. });
  1624. if (insertion) {
  1625. // Clones must be hidden before folding animation to capture dragRectAbsolute properly
  1626. if (isOwner) {
  1627. activeSortable._hideClone();
  1628. } else {
  1629. activeSortable._showClone(_this);
  1630. }
  1631. if (_this !== fromSortable) {
  1632. // Set ghost class to new sortable's ghost class
  1633. toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
  1634. toggleClass(dragEl, options.ghostClass, true);
  1635. }
  1636. if (putSortable !== _this && _this !== Sortable.active) {
  1637. putSortable = _this;
  1638. } else if (_this === Sortable.active && putSortable) {
  1639. putSortable = null;
  1640. }
  1641. // Animation
  1642. if (fromSortable === _this) {
  1643. _this._ignoreWhileAnimating = target;
  1644. }
  1645. _this.animateAll(function () {
  1646. dragOverEvent('dragOverAnimationComplete');
  1647. _this._ignoreWhileAnimating = null;
  1648. });
  1649. if (_this !== fromSortable) {
  1650. fromSortable.animateAll();
  1651. fromSortable._ignoreWhileAnimating = null;
  1652. }
  1653. }
  1654. // Null lastTarget if it is not inside a previously swapped element
  1655. if (target === dragEl && !dragEl.animated || target === el && !target.animated) {
  1656. lastTarget = null;
  1657. }
  1658. // no bubbling and not fallback
  1659. if (!options.dragoverBubble && !evt.rootEl && target !== document) {
  1660. dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
  1661. // Do not detect for empty insert if already inserted
  1662. !insertion && nearestEmptyInsertDetectEvent(evt);
  1663. }
  1664. !options.dragoverBubble && evt.stopPropagation && evt.stopPropagation();
  1665. return completedFired = true;
  1666. }
  1667. // Call when dragEl has been inserted
  1668. function changed() {
  1669. newIndex = index(dragEl);
  1670. newDraggableIndex = index(dragEl, options.draggable);
  1671. _dispatchEvent({
  1672. sortable: _this,
  1673. name: 'change',
  1674. toEl: el,
  1675. newIndex: newIndex,
  1676. newDraggableIndex: newDraggableIndex,
  1677. originalEvent: evt
  1678. });
  1679. }
  1680. if (evt.preventDefault !== void 0) {
  1681. evt.cancelable && evt.preventDefault();
  1682. }
  1683. target = closest(target, options.draggable, el, true);
  1684. dragOverEvent('dragOver');
  1685. if (Sortable.eventCanceled) return completedFired;
  1686. if (dragEl.contains(evt.target) || target.animated && target.animatingX && target.animatingY || _this._ignoreWhileAnimating === target) {
  1687. return completed(false);
  1688. }
  1689. ignoreNextClick = false;
  1690. if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list
  1691. : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) {
  1692. vertical = this._getDirection(evt, target) === 'vertical';
  1693. dragRect = getRect(dragEl);
  1694. dragOverEvent('dragOverValid');
  1695. if (Sortable.eventCanceled) return completedFired;
  1696. if (revert) {
  1697. parentEl = rootEl; // actualization
  1698. capture();
  1699. this._hideClone();
  1700. dragOverEvent('revert');
  1701. if (!Sortable.eventCanceled) {
  1702. if (nextEl) {
  1703. rootEl.insertBefore(dragEl, nextEl);
  1704. } else {
  1705. rootEl.appendChild(dragEl);
  1706. }
  1707. }
  1708. return completed(true);
  1709. }
  1710. var elLastChild = lastChild(el, options.draggable);
  1711. if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
  1712. // Insert to end of list
  1713. // If already at end of list: Do not insert
  1714. if (elLastChild === dragEl) {
  1715. return completed(false);
  1716. }
  1717. // if there is a last element, it is the target
  1718. if (elLastChild && el === evt.target) {
  1719. target = elLastChild;
  1720. }
  1721. if (target) {
  1722. targetRect = getRect(target);
  1723. }
  1724. if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
  1725. capture();
  1726. if (elLastChild && elLastChild.nextSibling) {
  1727. // the last draggable element is not the last node
  1728. el.insertBefore(dragEl, elLastChild.nextSibling);
  1729. } else {
  1730. el.appendChild(dragEl);
  1731. }
  1732. parentEl = el; // actualization
  1733. changed();
  1734. return completed(true);
  1735. }
  1736. } else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
  1737. // Insert to start of list
  1738. var firstChild = getChild(el, 0, options, true);
  1739. if (firstChild === dragEl) {
  1740. return completed(false);
  1741. }
  1742. target = firstChild;
  1743. targetRect = getRect(target);
  1744. if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, false) !== false) {
  1745. capture();
  1746. el.insertBefore(dragEl, firstChild);
  1747. parentEl = el; // actualization
  1748. changed();
  1749. return completed(true);
  1750. }
  1751. } else if (target.parentNode === el) {
  1752. targetRect = getRect(target);
  1753. var direction = 0,
  1754. targetBeforeFirstSwap,
  1755. differentLevel = dragEl.parentNode !== el,
  1756. differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target.animated && target.toRect || targetRect, vertical),
  1757. side1 = vertical ? 'top' : 'left',
  1758. scrolledPastTop = isScrolledPast(target, 'top', 'top') || isScrolledPast(dragEl, 'top', 'top'),
  1759. scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
  1760. if (lastTarget !== target) {
  1761. targetBeforeFirstSwap = targetRect[side1];
  1762. pastFirstInvertThresh = false;
  1763. isCircumstantialInvert = !differentRowCol && options.invertSwap || differentLevel;
  1764. }
  1765. direction = _getSwapDirection(evt, target, targetRect, vertical, differentRowCol ? 1 : options.swapThreshold, options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold, isCircumstantialInvert, lastTarget === target);
  1766. var sibling;
  1767. if (direction !== 0) {
  1768. // Check if target is beside dragEl in respective direction (ignoring hidden elements)
  1769. var dragIndex = index(dragEl);
  1770. do {
  1771. dragIndex -= direction;
  1772. sibling = parentEl.children[dragIndex];
  1773. } while (sibling && (css(sibling, 'display') === 'none' || sibling === ghostEl));
  1774. }
  1775. // If dragEl is already beside target: Do not insert
  1776. if (direction === 0 || sibling === target) {
  1777. return completed(false);
  1778. }
  1779. lastTarget = target;
  1780. lastDirection = direction;
  1781. var nextSibling = target.nextElementSibling,
  1782. after = false;
  1783. after = direction === 1;
  1784. var moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, after);
  1785. if (moveVector !== false) {
  1786. if (moveVector === 1 || moveVector === -1) {
  1787. after = moveVector === 1;
  1788. }
  1789. _silent = true;
  1790. setTimeout(_unsilent, 30);
  1791. capture();
  1792. if (after && !nextSibling) {
  1793. el.appendChild(dragEl);
  1794. } else {
  1795. target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
  1796. }
  1797. // Undo chrome's scroll adjustment (has no effect on other browsers)
  1798. if (scrolledPastTop) {
  1799. scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
  1800. }
  1801. parentEl = dragEl.parentNode; // actualization
  1802. // must be done before animation
  1803. if (targetBeforeFirstSwap !== undefined && !isCircumstantialInvert) {
  1804. targetMoveDistance = Math.abs(targetBeforeFirstSwap - getRect(target)[side1]);
  1805. }
  1806. changed();
  1807. return completed(true);
  1808. }
  1809. }
  1810. if (el.contains(dragEl)) {
  1811. return completed(false);
  1812. }
  1813. }
  1814. return false;
  1815. },
  1816. _ignoreWhileAnimating: null,
  1817. _offMoveEvents: function _offMoveEvents() {
  1818. off(document, 'mousemove', this._onTouchMove);
  1819. off(document, 'touchmove', this._onTouchMove);
  1820. off(document, 'pointermove', this._onTouchMove);
  1821. off(document, 'dragover', nearestEmptyInsertDetectEvent);
  1822. off(document, 'mousemove', nearestEmptyInsertDetectEvent);
  1823. off(document, 'touchmove', nearestEmptyInsertDetectEvent);
  1824. },
  1825. _offUpEvents: function _offUpEvents() {
  1826. var ownerDocument = this.el.ownerDocument;
  1827. off(ownerDocument, 'mouseup', this._onDrop);
  1828. off(ownerDocument, 'touchend', this._onDrop);
  1829. off(ownerDocument, 'pointerup', this._onDrop);
  1830. off(ownerDocument, 'touchcancel', this._onDrop);
  1831. off(document, 'selectstart', this);
  1832. },
  1833. _onDrop: function _onDrop( /**Event*/evt) {
  1834. var el = this.el,
  1835. options = this.options;
  1836. // Get the index of the dragged element within its parent
  1837. newIndex = index(dragEl);
  1838. newDraggableIndex = index(dragEl, options.draggable);
  1839. pluginEvent('drop', this, {
  1840. evt: evt
  1841. });
  1842. parentEl = dragEl && dragEl.parentNode;
  1843. // Get again after plugin event
  1844. newIndex = index(dragEl);
  1845. newDraggableIndex = index(dragEl, options.draggable);
  1846. if (Sortable.eventCanceled) {
  1847. this._nulling();
  1848. return;
  1849. }
  1850. awaitingDragStarted = false;
  1851. isCircumstantialInvert = false;
  1852. pastFirstInvertThresh = false;
  1853. clearInterval(this._loopId);
  1854. clearTimeout(this._dragStartTimer);
  1855. _cancelNextTick(this.cloneId);
  1856. _cancelNextTick(this._dragStartId);
  1857. // Unbind events
  1858. if (this.nativeDraggable) {
  1859. off(document, 'drop', this);
  1860. off(el, 'dragstart', this._onDragStart);
  1861. }
  1862. this._offMoveEvents();
  1863. this._offUpEvents();
  1864. if (Safari) {
  1865. css(document.body, 'user-select', '');
  1866. }
  1867. css(dragEl, 'transform', '');
  1868. if (evt) {
  1869. if (moved) {
  1870. evt.cancelable && evt.preventDefault();
  1871. !options.dropBubble && evt.stopPropagation();
  1872. }
  1873. ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
  1874. if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
  1875. // Remove clone(s)
  1876. cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
  1877. }
  1878. if (dragEl) {
  1879. if (this.nativeDraggable) {
  1880. off(dragEl, 'dragend', this);
  1881. }
  1882. _disableDraggable(dragEl);
  1883. dragEl.style['will-change'] = '';
  1884. // Remove classes
  1885. // ghostClass is added in dragStarted
  1886. if (moved && !awaitingDragStarted) {
  1887. toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : this.options.ghostClass, false);
  1888. }
  1889. toggleClass(dragEl, this.options.chosenClass, false);
  1890. // Drag stop event
  1891. _dispatchEvent({
  1892. sortable: this,
  1893. name: 'unchoose',
  1894. toEl: parentEl,
  1895. newIndex: null,
  1896. newDraggableIndex: null,
  1897. originalEvent: evt
  1898. });
  1899. if (rootEl !== parentEl) {
  1900. if (newIndex >= 0) {
  1901. // Add event
  1902. _dispatchEvent({
  1903. rootEl: parentEl,
  1904. name: 'add',
  1905. toEl: parentEl,
  1906. fromEl: rootEl,
  1907. originalEvent: evt
  1908. });
  1909. // Remove event
  1910. _dispatchEvent({
  1911. sortable: this,
  1912. name: 'remove',
  1913. toEl: parentEl,
  1914. originalEvent: evt
  1915. });
  1916. // drag from one list and drop into another
  1917. _dispatchEvent({
  1918. rootEl: parentEl,
  1919. name: 'sort',
  1920. toEl: parentEl,
  1921. fromEl: rootEl,
  1922. originalEvent: evt
  1923. });
  1924. _dispatchEvent({
  1925. sortable: this,
  1926. name: 'sort',
  1927. toEl: parentEl,
  1928. originalEvent: evt
  1929. });
  1930. }
  1931. putSortable && putSortable.save();
  1932. } else {
  1933. if (newIndex !== oldIndex) {
  1934. if (newIndex >= 0) {
  1935. // drag & drop within the same list
  1936. _dispatchEvent({
  1937. sortable: this,
  1938. name: 'update',
  1939. toEl: parentEl,
  1940. originalEvent: evt
  1941. });
  1942. _dispatchEvent({
  1943. sortable: this,
  1944. name: 'sort',
  1945. toEl: parentEl,
  1946. originalEvent: evt
  1947. });
  1948. }
  1949. }
  1950. }
  1951. if (Sortable.active) {
  1952. /* jshint eqnull:true */
  1953. if (newIndex == null || newIndex === -1) {
  1954. newIndex = oldIndex;
  1955. newDraggableIndex = oldDraggableIndex;
  1956. }
  1957. _dispatchEvent({
  1958. sortable: this,
  1959. name: 'end',
  1960. toEl: parentEl,
  1961. originalEvent: evt
  1962. });
  1963. // Save sorting
  1964. this.save();
  1965. }
  1966. }
  1967. }
  1968. this._nulling();
  1969. },
  1970. _nulling: function _nulling() {
  1971. pluginEvent('nulling', this);
  1972. rootEl = dragEl = parentEl = ghostEl = nextEl = cloneEl = lastDownEl = cloneHidden = tapEvt = touchEvt = moved = newIndex = newDraggableIndex = oldIndex = oldDraggableIndex = lastTarget = lastDirection = putSortable = activeGroup = Sortable.dragged = Sortable.ghost = Sortable.clone = Sortable.active = null;
  1973. savedInputChecked.forEach(function (el) {
  1974. el.checked = true;
  1975. });
  1976. savedInputChecked.length = lastDx = lastDy = 0;
  1977. },
  1978. handleEvent: function handleEvent( /**Event*/evt) {
  1979. switch (evt.type) {
  1980. case 'drop':
  1981. case 'dragend':
  1982. this._onDrop(evt);
  1983. break;
  1984. case 'dragenter':
  1985. case 'dragover':
  1986. if (dragEl) {
  1987. this._onDragOver(evt);
  1988. _globalDragOver(evt);
  1989. }
  1990. break;
  1991. case 'selectstart':
  1992. evt.preventDefault();
  1993. break;
  1994. }
  1995. },
  1996. /**
  1997. * Serializes the item into an array of string.
  1998. * @returns {String[]}
  1999. */
  2000. toArray: function toArray() {
  2001. var order = [],
  2002. el,
  2003. children = this.el.children,
  2004. i = 0,
  2005. n = children.length,
  2006. options = this.options;
  2007. for (; i < n; i++) {
  2008. el = children[i];
  2009. if (closest(el, options.draggable, this.el, false)) {
  2010. order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
  2011. }
  2012. }
  2013. return order;
  2014. },
  2015. /**
  2016. * Sorts the elements according to the array.
  2017. * @param {String[]} order order of the items
  2018. */
  2019. sort: function sort(order, useAnimation) {
  2020. var items = {},
  2021. rootEl = this.el;
  2022. this.toArray().forEach(function (id, i) {
  2023. var el = rootEl.children[i];
  2024. if (closest(el, this.options.draggable, rootEl, false)) {
  2025. items[id] = el;
  2026. }
  2027. }, this);
  2028. useAnimation && this.captureAnimationState();
  2029. order.forEach(function (id) {
  2030. if (items[id]) {
  2031. rootEl.removeChild(items[id]);
  2032. rootEl.appendChild(items[id]);
  2033. }
  2034. });
  2035. useAnimation && this.animateAll();
  2036. },
  2037. /**
  2038. * Save the current sorting
  2039. */
  2040. save: function save() {
  2041. var store = this.options.store;
  2042. store && store.set && store.set(this);
  2043. },
  2044. /**
  2045. * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
  2046. * @param {HTMLElement} el
  2047. * @param {String} [selector] default: `options.draggable`
  2048. * @returns {HTMLElement|null}
  2049. */
  2050. closest: function closest$1(el, selector) {
  2051. return closest(el, selector || this.options.draggable, this.el, false);
  2052. },
  2053. /**
  2054. * Set/get option
  2055. * @param {string} name
  2056. * @param {*} [value]
  2057. * @returns {*}
  2058. */
  2059. option: function option(name, value) {
  2060. var options = this.options;
  2061. if (value === void 0) {
  2062. return options[name];
  2063. } else {
  2064. var modifiedValue = PluginManager.modifyOption(this, name, value);
  2065. if (typeof modifiedValue !== 'undefined') {
  2066. options[name] = modifiedValue;
  2067. } else {
  2068. options[name] = value;
  2069. }
  2070. if (name === 'group') {
  2071. _prepareGroup(options);
  2072. }
  2073. }
  2074. },
  2075. /**
  2076. * Destroy
  2077. */
  2078. destroy: function destroy() {
  2079. pluginEvent('destroy', this);
  2080. var el = this.el;
  2081. el[expando] = null;
  2082. off(el, 'mousedown', this._onTapStart);
  2083. off(el, 'touchstart', this._onTapStart);
  2084. off(el, 'pointerdown', this._onTapStart);
  2085. if (this.nativeDraggable) {
  2086. off(el, 'dragover', this);
  2087. off(el, 'dragenter', this);
  2088. }
  2089. // Remove draggable attributes
  2090. Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {
  2091. el.removeAttribute('draggable');
  2092. });
  2093. this._onDrop();
  2094. this._disableDelayedDragEvents();
  2095. sortables.splice(sortables.indexOf(this.el), 1);
  2096. this.el = el = null;
  2097. },
  2098. _hideClone: function _hideClone() {
  2099. if (!cloneHidden) {
  2100. pluginEvent('hideClone', this);
  2101. if (Sortable.eventCanceled) return;
  2102. css(cloneEl, 'display', 'none');
  2103. if (this.options.removeCloneOnHide && cloneEl.parentNode) {
  2104. cloneEl.parentNode.removeChild(cloneEl);
  2105. }
  2106. cloneHidden = true;
  2107. }
  2108. },
  2109. _showClone: function _showClone(putSortable) {
  2110. if (putSortable.lastPutMode !== 'clone') {
  2111. this._hideClone();
  2112. return;
  2113. }
  2114. if (cloneHidden) {
  2115. pluginEvent('showClone', this);
  2116. if (Sortable.eventCanceled) return;
  2117. // show clone at dragEl or original position
  2118. if (dragEl.parentNode == rootEl && !this.options.group.revertClone) {
  2119. rootEl.insertBefore(cloneEl, dragEl);
  2120. } else if (nextEl) {
  2121. rootEl.insertBefore(cloneEl, nextEl);
  2122. } else {
  2123. rootEl.appendChild(cloneEl);
  2124. }
  2125. if (this.options.group.revertClone) {
  2126. this.animate(dragEl, cloneEl);
  2127. }
  2128. css(cloneEl, 'display', '');
  2129. cloneHidden = false;
  2130. }
  2131. }
  2132. };
  2133. function _globalDragOver( /**Event*/evt) {
  2134. if (evt.dataTransfer) {
  2135. evt.dataTransfer.dropEffect = 'move';
  2136. }
  2137. evt.cancelable && evt.preventDefault();
  2138. }
  2139. function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvent, willInsertAfter) {
  2140. var evt,
  2141. sortable = fromEl[expando],
  2142. onMoveFn = sortable.options.onMove,
  2143. retVal;
  2144. // Support for new CustomEvent feature
  2145. if (window.CustomEvent && !IE11OrLess && !Edge) {
  2146. evt = new CustomEvent('move', {
  2147. bubbles: true,
  2148. cancelable: true
  2149. });
  2150. } else {
  2151. evt = document.createEvent('Event');
  2152. evt.initEvent('move', true, true);
  2153. }
  2154. evt.to = toEl;
  2155. evt.from = fromEl;
  2156. evt.dragged = dragEl;
  2157. evt.draggedRect = dragRect;
  2158. evt.related = targetEl || toEl;
  2159. evt.relatedRect = targetRect || getRect(toEl);
  2160. evt.willInsertAfter = willInsertAfter;
  2161. evt.originalEvent = originalEvent;
  2162. fromEl.dispatchEvent(evt);
  2163. if (onMoveFn) {
  2164. retVal = onMoveFn.call(sortable, evt, originalEvent);
  2165. }
  2166. return retVal;
  2167. }
  2168. function _disableDraggable(el) {
  2169. el.draggable = false;
  2170. }
  2171. function _unsilent() {
  2172. _silent = false;
  2173. }
  2174. function _ghostIsFirst(evt, vertical, sortable) {
  2175. var firstElRect = getRect(getChild(sortable.el, 0, sortable.options, true));
  2176. var sortableContentRect = getContentRect(sortable.el);
  2177. var spacer = 10;
  2178. return vertical ? evt.clientX < sortableContentRect.left - spacer || evt.clientY < firstElRect.top && evt.clientX < firstElRect.right : evt.clientY < sortableContentRect.top - spacer || evt.clientY < firstElRect.bottom && evt.clientX < firstElRect.left;
  2179. }
  2180. function _ghostIsLast(evt, vertical, sortable) {
  2181. var lastElRect = getRect(lastChild(sortable.el, sortable.options.draggable));
  2182. var sortableContentRect = getContentRect(sortable.el);
  2183. var spacer = 10;
  2184. return vertical ? evt.clientX > sortableContentRect.right + spacer || evt.clientY > lastElRect.bottom && evt.clientX > lastElRect.left : evt.clientY > sortableContentRect.bottom + spacer || evt.clientX > lastElRect.right && evt.clientY > lastElRect.top;
  2185. }
  2186. function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget) {
  2187. var mouseOnAxis = vertical ? evt.clientY : evt.clientX,
  2188. targetLength = vertical ? targetRect.height : targetRect.width,
  2189. targetS1 = vertical ? targetRect.top : targetRect.left,
  2190. targetS2 = vertical ? targetRect.bottom : targetRect.right,
  2191. invert = false;
  2192. if (!invertSwap) {
  2193. // Never invert or create dragEl shadow when target movemenet causes mouse to move past the end of regular swapThreshold
  2194. if (isLastTarget && targetMoveDistance < targetLength * swapThreshold) {
  2195. // multiplied only by swapThreshold because mouse will already be inside target by (1 - threshold) * targetLength / 2
  2196. // check if past first invert threshold on side opposite of lastDirection
  2197. if (!pastFirstInvertThresh && (lastDirection === 1 ? mouseOnAxis > targetS1 + targetLength * invertedSwapThreshold / 2 : mouseOnAxis < targetS2 - targetLength * invertedSwapThreshold / 2)) {
  2198. // past first invert threshold, do not restrict inverted threshold to dragEl shadow
  2199. pastFirstInvertThresh = true;
  2200. }
  2201. if (!pastFirstInvertThresh) {
  2202. // dragEl shadow (target move distance shadow)
  2203. if (lastDirection === 1 ? mouseOnAxis < targetS1 + targetMoveDistance // over dragEl shadow
  2204. : mouseOnAxis > targetS2 - targetMoveDistance) {
  2205. return -lastDirection;
  2206. }
  2207. } else {
  2208. invert = true;
  2209. }
  2210. } else {
  2211. // Regular
  2212. if (mouseOnAxis > targetS1 + targetLength * (1 - swapThreshold) / 2 && mouseOnAxis < targetS2 - targetLength * (1 - swapThreshold) / 2) {
  2213. return _getInsertDirection(target);
  2214. }
  2215. }
  2216. }
  2217. invert = invert || invertSwap;
  2218. if (invert) {
  2219. // Invert of regular
  2220. if (mouseOnAxis < targetS1 + targetLength * invertedSwapThreshold / 2 || mouseOnAxis > targetS2 - targetLength * invertedSwapThreshold / 2) {
  2221. return mouseOnAxis > targetS1 + targetLength / 2 ? 1 : -1;
  2222. }
  2223. }
  2224. return 0;
  2225. }
  2226. /**
  2227. * Gets the direction dragEl must be swapped relative to target in order to make it
  2228. * seem that dragEl has been "inserted" into that element's position
  2229. * @param {HTMLElement} target The target whose position dragEl is being inserted at
  2230. * @return {Number} Direction dragEl must be swapped
  2231. */
  2232. function _getInsertDirection(target) {
  2233. if (index(dragEl) < index(target)) {
  2234. return 1;
  2235. } else {
  2236. return -1;
  2237. }
  2238. }
  2239. /**
  2240. * Generate id
  2241. * @param {HTMLElement} el
  2242. * @returns {String}
  2243. * @private
  2244. */
  2245. function _generateId(el) {
  2246. var str = el.tagName + el.className + el.src + el.href + el.textContent,
  2247. i = str.length,
  2248. sum = 0;
  2249. while (i--) {
  2250. sum += str.charCodeAt(i);
  2251. }
  2252. return sum.toString(36);
  2253. }
  2254. function _saveInputCheckedState(root) {
  2255. savedInputChecked.length = 0;
  2256. var inputs = root.getElementsByTagName('input');
  2257. var idx = inputs.length;
  2258. while (idx--) {
  2259. var el = inputs[idx];
  2260. el.checked && savedInputChecked.push(el);
  2261. }
  2262. }
  2263. function _nextTick(fn) {
  2264. return setTimeout(fn, 0);
  2265. }
  2266. function _cancelNextTick(id) {
  2267. return clearTimeout(id);
  2268. }
  2269. // Fixed #973:
  2270. if (documentExists) {
  2271. on(document, 'touchmove', function (evt) {
  2272. if ((Sortable.active || awaitingDragStarted) && evt.cancelable) {
  2273. evt.preventDefault();
  2274. }
  2275. });
  2276. }
  2277. // Export utils
  2278. Sortable.utils = {
  2279. on: on,
  2280. off: off,
  2281. css: css,
  2282. find: find,
  2283. is: function is(el, selector) {
  2284. return !!closest(el, selector, el, false);
  2285. },
  2286. extend: extend,
  2287. throttle: throttle,
  2288. closest: closest,
  2289. toggleClass: toggleClass,
  2290. clone: clone,
  2291. index: index,
  2292. nextTick: _nextTick,
  2293. cancelNextTick: _cancelNextTick,
  2294. detectDirection: _detectDirection,
  2295. getChild: getChild
  2296. };
  2297. /**
  2298. * Get the Sortable instance of an element
  2299. * @param {HTMLElement} element The element
  2300. * @return {Sortable|undefined} The instance of Sortable
  2301. */
  2302. Sortable.get = function (element) {
  2303. return element[expando];
  2304. };
  2305. /**
  2306. * Mount a plugin to Sortable
  2307. * @param {...SortablePlugin|SortablePlugin[]} plugins Plugins being mounted
  2308. */
  2309. Sortable.mount = function () {
  2310. for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
  2311. plugins[_key] = arguments[_key];
  2312. }
  2313. if (plugins[0].constructor === Array) plugins = plugins[0];
  2314. plugins.forEach(function (plugin) {
  2315. if (!plugin.prototype || !plugin.prototype.constructor) {
  2316. throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin));
  2317. }
  2318. if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils);
  2319. PluginManager.mount(plugin);
  2320. });
  2321. };
  2322. /**
  2323. * Create sortable instance
  2324. * @param {HTMLElement} el
  2325. * @param {Object} [options]
  2326. */
  2327. Sortable.create = function (el, options) {
  2328. return new Sortable(el, options);
  2329. };
  2330. // Export
  2331. Sortable.version = version;
  2332. var autoScrolls = [],
  2333. scrollEl,
  2334. scrollRootEl,
  2335. scrolling = false,
  2336. lastAutoScrollX,
  2337. lastAutoScrollY,
  2338. touchEvt$1,
  2339. pointerElemChangedInterval;
  2340. function AutoScrollPlugin() {
  2341. function AutoScroll() {
  2342. this.defaults = {
  2343. scroll: true,
  2344. forceAutoScrollFallback: false,
  2345. scrollSensitivity: 30,
  2346. scrollSpeed: 10,
  2347. bubbleScroll: true
  2348. };
  2349. // Bind all private methods
  2350. for (var fn in this) {
  2351. if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
  2352. this[fn] = this[fn].bind(this);
  2353. }
  2354. }
  2355. }
  2356. AutoScroll.prototype = {
  2357. dragStarted: function dragStarted(_ref) {
  2358. var originalEvent = _ref.originalEvent;
  2359. if (this.sortable.nativeDraggable) {
  2360. on(document, 'dragover', this._handleAutoScroll);
  2361. } else {
  2362. if (this.options.supportPointer) {
  2363. on(document, 'pointermove', this._handleFallbackAutoScroll);
  2364. } else if (originalEvent.touches) {
  2365. on(document, 'touchmove', this._handleFallbackAutoScroll);
  2366. } else {
  2367. on(document, 'mousemove', this._handleFallbackAutoScroll);
  2368. }
  2369. }
  2370. },
  2371. dragOverCompleted: function dragOverCompleted(_ref2) {
  2372. var originalEvent = _ref2.originalEvent;
  2373. // For when bubbling is canceled and using fallback (fallback 'touchmove' always reached)
  2374. if (!this.options.dragOverBubble && !originalEvent.rootEl) {
  2375. this._handleAutoScroll(originalEvent);
  2376. }
  2377. },
  2378. drop: function drop() {
  2379. if (this.sortable.nativeDraggable) {
  2380. off(document, 'dragover', this._handleAutoScroll);
  2381. } else {
  2382. off(document, 'pointermove', this._handleFallbackAutoScroll);
  2383. off(document, 'touchmove', this._handleFallbackAutoScroll);
  2384. off(document, 'mousemove', this._handleFallbackAutoScroll);
  2385. }
  2386. clearPointerElemChangedInterval();
  2387. clearAutoScrolls();
  2388. cancelThrottle();
  2389. },
  2390. nulling: function nulling() {
  2391. touchEvt$1 = scrollRootEl = scrollEl = scrolling = pointerElemChangedInterval = lastAutoScrollX = lastAutoScrollY = null;
  2392. autoScrolls.length = 0;
  2393. },
  2394. _handleFallbackAutoScroll: function _handleFallbackAutoScroll(evt) {
  2395. this._handleAutoScroll(evt, true);
  2396. },
  2397. _handleAutoScroll: function _handleAutoScroll(evt, fallback) {
  2398. var _this = this;
  2399. var x = (evt.touches ? evt.touches[0] : evt).clientX,
  2400. y = (evt.touches ? evt.touches[0] : evt).clientY,
  2401. elem = document.elementFromPoint(x, y);
  2402. touchEvt$1 = evt;
  2403. // IE does not seem to have native autoscroll,
  2404. // Edge's autoscroll seems too conditional,
  2405. // MACOS Safari does not have autoscroll,
  2406. // Firefox and Chrome are good
  2407. if (fallback || this.options.forceAutoScrollFallback || Edge || IE11OrLess || Safari) {
  2408. autoScroll(evt, this.options, elem, fallback);
  2409. // Listener for pointer element change
  2410. var ogElemScroller = getParentAutoScrollElement(elem, true);
  2411. if (scrolling && (!pointerElemChangedInterval || x !== lastAutoScrollX || y !== lastAutoScrollY)) {
  2412. pointerElemChangedInterval && clearPointerElemChangedInterval();
  2413. // Detect for pointer elem change, emulating native DnD behaviour
  2414. pointerElemChangedInterval = setInterval(function () {
  2415. var newElem = getParentAutoScrollElement(document.elementFromPoint(x, y), true);
  2416. if (newElem !== ogElemScroller) {
  2417. ogElemScroller = newElem;
  2418. clearAutoScrolls();
  2419. }
  2420. autoScroll(evt, _this.options, newElem, fallback);
  2421. }, 10);
  2422. lastAutoScrollX = x;
  2423. lastAutoScrollY = y;
  2424. }
  2425. } else {
  2426. // if DnD is enabled (and browser has good autoscrolling), first autoscroll will already scroll, so get parent autoscroll of first autoscroll
  2427. if (!this.options.bubbleScroll || getParentAutoScrollElement(elem, true) === getWindowScrollingElement()) {
  2428. clearAutoScrolls();
  2429. return;
  2430. }
  2431. autoScroll(evt, this.options, getParentAutoScrollElement(elem, false), false);
  2432. }
  2433. }
  2434. };
  2435. return _extends(AutoScroll, {
  2436. pluginName: 'scroll',
  2437. initializeByDefault: true
  2438. });
  2439. }
  2440. function clearAutoScrolls() {
  2441. autoScrolls.forEach(function (autoScroll) {
  2442. clearInterval(autoScroll.pid);
  2443. });
  2444. autoScrolls = [];
  2445. }
  2446. function clearPointerElemChangedInterval() {
  2447. clearInterval(pointerElemChangedInterval);
  2448. }
  2449. var autoScroll = throttle(function (evt, options, rootEl, isFallback) {
  2450. // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
  2451. if (!options.scroll) return;
  2452. var x = (evt.touches ? evt.touches[0] : evt).clientX,
  2453. y = (evt.touches ? evt.touches[0] : evt).clientY,
  2454. sens = options.scrollSensitivity,
  2455. speed = options.scrollSpeed,
  2456. winScroller = getWindowScrollingElement();
  2457. var scrollThisInstance = false,
  2458. scrollCustomFn;
  2459. // New scroll root, set scrollEl
  2460. if (scrollRootEl !== rootEl) {
  2461. scrollRootEl = rootEl;
  2462. clearAutoScrolls();
  2463. scrollEl = options.scroll;
  2464. scrollCustomFn = options.scrollFn;
  2465. if (scrollEl === true) {
  2466. scrollEl = getParentAutoScrollElement(rootEl, true);
  2467. }
  2468. }
  2469. var layersOut = 0;
  2470. var currentParent = scrollEl;
  2471. do {
  2472. var el = currentParent,
  2473. rect = getRect(el),
  2474. top = rect.top,
  2475. bottom = rect.bottom,
  2476. left = rect.left,
  2477. right = rect.right,
  2478. width = rect.width,
  2479. height = rect.height,
  2480. canScrollX = void 0,
  2481. canScrollY = void 0,
  2482. scrollWidth = el.scrollWidth,
  2483. scrollHeight = el.scrollHeight,
  2484. elCSS = css(el),
  2485. scrollPosX = el.scrollLeft,
  2486. scrollPosY = el.scrollTop;
  2487. if (el === winScroller) {
  2488. canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll' || elCSS.overflowX === 'visible');
  2489. canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll' || elCSS.overflowY === 'visible');
  2490. } else {
  2491. canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll');
  2492. canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll');
  2493. }
  2494. var vx = canScrollX && (Math.abs(right - x) <= sens && scrollPosX + width < scrollWidth) - (Math.abs(left - x) <= sens && !!scrollPosX);
  2495. var vy = canScrollY && (Math.abs(bottom - y) <= sens && scrollPosY + height < scrollHeight) - (Math.abs(top - y) <= sens && !!scrollPosY);
  2496. if (!autoScrolls[layersOut]) {
  2497. for (var i = 0; i <= layersOut; i++) {
  2498. if (!autoScrolls[i]) {
  2499. autoScrolls[i] = {};
  2500. }
  2501. }
  2502. }
  2503. if (autoScrolls[layersOut].vx != vx || autoScrolls[layersOut].vy != vy || autoScrolls[layersOut].el !== el) {
  2504. autoScrolls[layersOut].el = el;
  2505. autoScrolls[layersOut].vx = vx;
  2506. autoScrolls[layersOut].vy = vy;
  2507. clearInterval(autoScrolls[layersOut].pid);
  2508. if (vx != 0 || vy != 0) {
  2509. scrollThisInstance = true;
  2510. /* jshint loopfunc:true */
  2511. autoScrolls[layersOut].pid = setInterval(function () {
  2512. // emulate drag over during autoscroll (fallback), emulating native DnD behaviour
  2513. if (isFallback && this.layer === 0) {
  2514. Sortable.active._onTouchMove(touchEvt$1); // To move ghost if it is positioned absolutely
  2515. }
  2516. var scrollOffsetY = autoScrolls[this.layer].vy ? autoScrolls[this.layer].vy * speed : 0;
  2517. var scrollOffsetX = autoScrolls[this.layer].vx ? autoScrolls[this.layer].vx * speed : 0;
  2518. if (typeof scrollCustomFn === 'function') {
  2519. if (scrollCustomFn.call(Sortable.dragged.parentNode[expando], scrollOffsetX, scrollOffsetY, evt, touchEvt$1, autoScrolls[this.layer].el) !== 'continue') {
  2520. return;
  2521. }
  2522. }
  2523. scrollBy(autoScrolls[this.layer].el, scrollOffsetX, scrollOffsetY);
  2524. }.bind({
  2525. layer: layersOut
  2526. }), 24);
  2527. }
  2528. }
  2529. layersOut++;
  2530. } while (options.bubbleScroll && currentParent !== winScroller && (currentParent = getParentAutoScrollElement(currentParent, false)));
  2531. scrolling = scrollThisInstance; // in case another function catches scrolling as false in between when it is not
  2532. }, 30);
  2533. var drop = function drop(_ref) {
  2534. var originalEvent = _ref.originalEvent,
  2535. putSortable = _ref.putSortable,
  2536. dragEl = _ref.dragEl,
  2537. activeSortable = _ref.activeSortable,
  2538. dispatchSortableEvent = _ref.dispatchSortableEvent,
  2539. hideGhostForTarget = _ref.hideGhostForTarget,
  2540. unhideGhostForTarget = _ref.unhideGhostForTarget;
  2541. if (!originalEvent) return;
  2542. var toSortable = putSortable || activeSortable;
  2543. hideGhostForTarget();
  2544. var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
  2545. var target = document.elementFromPoint(touch.clientX, touch.clientY);
  2546. unhideGhostForTarget();
  2547. if (toSortable && !toSortable.el.contains(target)) {
  2548. dispatchSortableEvent('spill');
  2549. this.onSpill({
  2550. dragEl: dragEl,
  2551. putSortable: putSortable
  2552. });
  2553. }
  2554. };
  2555. function Revert() {}
  2556. Revert.prototype = {
  2557. startIndex: null,
  2558. dragStart: function dragStart(_ref2) {
  2559. var oldDraggableIndex = _ref2.oldDraggableIndex;
  2560. this.startIndex = oldDraggableIndex;
  2561. },
  2562. onSpill: function onSpill(_ref3) {
  2563. var dragEl = _ref3.dragEl,
  2564. putSortable = _ref3.putSortable;
  2565. this.sortable.captureAnimationState();
  2566. if (putSortable) {
  2567. putSortable.captureAnimationState();
  2568. }
  2569. var nextSibling = getChild(this.sortable.el, this.startIndex, this.options);
  2570. if (nextSibling) {
  2571. this.sortable.el.insertBefore(dragEl, nextSibling);
  2572. } else {
  2573. this.sortable.el.appendChild(dragEl);
  2574. }
  2575. this.sortable.animateAll();
  2576. if (putSortable) {
  2577. putSortable.animateAll();
  2578. }
  2579. },
  2580. drop: drop
  2581. };
  2582. _extends(Revert, {
  2583. pluginName: 'revertOnSpill'
  2584. });
  2585. function Remove() {}
  2586. Remove.prototype = {
  2587. onSpill: function onSpill(_ref4) {
  2588. var dragEl = _ref4.dragEl,
  2589. putSortable = _ref4.putSortable;
  2590. var parentSortable = putSortable || this.sortable;
  2591. parentSortable.captureAnimationState();
  2592. dragEl.parentNode && dragEl.parentNode.removeChild(dragEl);
  2593. parentSortable.animateAll();
  2594. },
  2595. drop: drop
  2596. };
  2597. _extends(Remove, {
  2598. pluginName: 'removeOnSpill'
  2599. });
  2600. var lastSwapEl;
  2601. function SwapPlugin() {
  2602. function Swap() {
  2603. this.defaults = {
  2604. swapClass: 'sortable-swap-highlight'
  2605. };
  2606. }
  2607. Swap.prototype = {
  2608. dragStart: function dragStart(_ref) {
  2609. var dragEl = _ref.dragEl;
  2610. lastSwapEl = dragEl;
  2611. },
  2612. dragOverValid: function dragOverValid(_ref2) {
  2613. var completed = _ref2.completed,
  2614. target = _ref2.target,
  2615. onMove = _ref2.onMove,
  2616. activeSortable = _ref2.activeSortable,
  2617. changed = _ref2.changed,
  2618. cancel = _ref2.cancel;
  2619. if (!activeSortable.options.swap) return;
  2620. var el = this.sortable.el,
  2621. options = this.options;
  2622. if (target && target !== el) {
  2623. var prevSwapEl = lastSwapEl;
  2624. if (onMove(target) !== false) {
  2625. toggleClass(target, options.swapClass, true);
  2626. lastSwapEl = target;
  2627. } else {
  2628. lastSwapEl = null;
  2629. }
  2630. if (prevSwapEl && prevSwapEl !== lastSwapEl) {
  2631. toggleClass(prevSwapEl, options.swapClass, false);
  2632. }
  2633. }
  2634. changed();
  2635. completed(true);
  2636. cancel();
  2637. },
  2638. drop: function drop(_ref3) {
  2639. var activeSortable = _ref3.activeSortable,
  2640. putSortable = _ref3.putSortable,
  2641. dragEl = _ref3.dragEl;
  2642. var toSortable = putSortable || this.sortable;
  2643. var options = this.options;
  2644. lastSwapEl && toggleClass(lastSwapEl, options.swapClass, false);
  2645. if (lastSwapEl && (options.swap || putSortable && putSortable.options.swap)) {
  2646. if (dragEl !== lastSwapEl) {
  2647. toSortable.captureAnimationState();
  2648. if (toSortable !== activeSortable) activeSortable.captureAnimationState();
  2649. swapNodes(dragEl, lastSwapEl);
  2650. toSortable.animateAll();
  2651. if (toSortable !== activeSortable) activeSortable.animateAll();
  2652. }
  2653. }
  2654. },
  2655. nulling: function nulling() {
  2656. lastSwapEl = null;
  2657. }
  2658. };
  2659. return _extends(Swap, {
  2660. pluginName: 'swap',
  2661. eventProperties: function eventProperties() {
  2662. return {
  2663. swapItem: lastSwapEl
  2664. };
  2665. }
  2666. });
  2667. }
  2668. function swapNodes(n1, n2) {
  2669. var p1 = n1.parentNode,
  2670. p2 = n2.parentNode,
  2671. i1,
  2672. i2;
  2673. if (!p1 || !p2 || p1.isEqualNode(n2) || p2.isEqualNode(n1)) return;
  2674. i1 = index(n1);
  2675. i2 = index(n2);
  2676. if (p1.isEqualNode(p2) && i1 < i2) {
  2677. i2++;
  2678. }
  2679. p1.insertBefore(n2, p1.children[i1]);
  2680. p2.insertBefore(n1, p2.children[i2]);
  2681. }
  2682. var multiDragElements = [],
  2683. multiDragClones = [],
  2684. lastMultiDragSelect,
  2685. // for selection with modifier key down (SHIFT)
  2686. multiDragSortable,
  2687. initialFolding = false,
  2688. // Initial multi-drag fold when drag started
  2689. folding = false,
  2690. // Folding any other time
  2691. dragStarted = false,
  2692. dragEl$1,
  2693. clonesFromRect,
  2694. clonesHidden;
  2695. function MultiDragPlugin() {
  2696. function MultiDrag(sortable) {
  2697. // Bind all private methods
  2698. for (var fn in this) {
  2699. if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
  2700. this[fn] = this[fn].bind(this);
  2701. }
  2702. }
  2703. if (!sortable.options.avoidImplicitDeselect) {
  2704. if (sortable.options.supportPointer) {
  2705. on(document, 'pointerup', this._deselectMultiDrag);
  2706. } else {
  2707. on(document, 'mouseup', this._deselectMultiDrag);
  2708. on(document, 'touchend', this._deselectMultiDrag);
  2709. }
  2710. }
  2711. on(document, 'keydown', this._checkKeyDown);
  2712. on(document, 'keyup', this._checkKeyUp);
  2713. this.defaults = {
  2714. selectedClass: 'sortable-selected',
  2715. multiDragKey: null,
  2716. avoidImplicitDeselect: false,
  2717. setData: function setData(dataTransfer, dragEl) {
  2718. var data = '';
  2719. if (multiDragElements.length && multiDragSortable === sortable) {
  2720. multiDragElements.forEach(function (multiDragElement, i) {
  2721. data += (!i ? '' : ', ') + multiDragElement.textContent;
  2722. });
  2723. } else {
  2724. data = dragEl.textContent;
  2725. }
  2726. dataTransfer.setData('Text', data);
  2727. }
  2728. };
  2729. }
  2730. MultiDrag.prototype = {
  2731. multiDragKeyDown: false,
  2732. isMultiDrag: false,
  2733. delayStartGlobal: function delayStartGlobal(_ref) {
  2734. var dragged = _ref.dragEl;
  2735. dragEl$1 = dragged;
  2736. },
  2737. delayEnded: function delayEnded() {
  2738. this.isMultiDrag = ~multiDragElements.indexOf(dragEl$1);
  2739. },
  2740. setupClone: function setupClone(_ref2) {
  2741. var sortable = _ref2.sortable,
  2742. cancel = _ref2.cancel;
  2743. if (!this.isMultiDrag) return;
  2744. for (var i = 0; i < multiDragElements.length; i++) {
  2745. multiDragClones.push(clone(multiDragElements[i]));
  2746. multiDragClones[i].sortableIndex = multiDragElements[i].sortableIndex;
  2747. multiDragClones[i].draggable = false;
  2748. multiDragClones[i].style['will-change'] = '';
  2749. toggleClass(multiDragClones[i], this.options.selectedClass, false);
  2750. multiDragElements[i] === dragEl$1 && toggleClass(multiDragClones[i], this.options.chosenClass, false);
  2751. }
  2752. sortable._hideClone();
  2753. cancel();
  2754. },
  2755. clone: function clone(_ref3) {
  2756. var sortable = _ref3.sortable,
  2757. rootEl = _ref3.rootEl,
  2758. dispatchSortableEvent = _ref3.dispatchSortableEvent,
  2759. cancel = _ref3.cancel;
  2760. if (!this.isMultiDrag) return;
  2761. if (!this.options.removeCloneOnHide) {
  2762. if (multiDragElements.length && multiDragSortable === sortable) {
  2763. insertMultiDragClones(true, rootEl);
  2764. dispatchSortableEvent('clone');
  2765. cancel();
  2766. }
  2767. }
  2768. },
  2769. showClone: function showClone(_ref4) {
  2770. var cloneNowShown = _ref4.cloneNowShown,
  2771. rootEl = _ref4.rootEl,
  2772. cancel = _ref4.cancel;
  2773. if (!this.isMultiDrag) return;
  2774. insertMultiDragClones(false, rootEl);
  2775. multiDragClones.forEach(function (clone) {
  2776. css(clone, 'display', '');
  2777. });
  2778. cloneNowShown();
  2779. clonesHidden = false;
  2780. cancel();
  2781. },
  2782. hideClone: function hideClone(_ref5) {
  2783. var _this = this;
  2784. var sortable = _ref5.sortable,
  2785. cloneNowHidden = _ref5.cloneNowHidden,
  2786. cancel = _ref5.cancel;
  2787. if (!this.isMultiDrag) return;
  2788. multiDragClones.forEach(function (clone) {
  2789. css(clone, 'display', 'none');
  2790. if (_this.options.removeCloneOnHide && clone.parentNode) {
  2791. clone.parentNode.removeChild(clone);
  2792. }
  2793. });
  2794. cloneNowHidden();
  2795. clonesHidden = true;
  2796. cancel();
  2797. },
  2798. dragStartGlobal: function dragStartGlobal(_ref6) {
  2799. var sortable = _ref6.sortable;
  2800. if (!this.isMultiDrag && multiDragSortable) {
  2801. multiDragSortable.multiDrag._deselectMultiDrag();
  2802. }
  2803. multiDragElements.forEach(function (multiDragElement) {
  2804. multiDragElement.sortableIndex = index(multiDragElement);
  2805. });
  2806. // Sort multi-drag elements
  2807. multiDragElements = multiDragElements.sort(function (a, b) {
  2808. return a.sortableIndex - b.sortableIndex;
  2809. });
  2810. dragStarted = true;
  2811. },
  2812. dragStarted: function dragStarted(_ref7) {
  2813. var _this2 = this;
  2814. var sortable = _ref7.sortable;
  2815. if (!this.isMultiDrag) return;
  2816. if (this.options.sort) {
  2817. // Capture rects,
  2818. // hide multi drag elements (by positioning them absolute),
  2819. // set multi drag elements rects to dragRect,
  2820. // show multi drag elements,
  2821. // animate to rects,
  2822. // unset rects & remove from DOM
  2823. sortable.captureAnimationState();
  2824. if (this.options.animation) {
  2825. multiDragElements.forEach(function (multiDragElement) {
  2826. if (multiDragElement === dragEl$1) return;
  2827. css(multiDragElement, 'position', 'absolute');
  2828. });
  2829. var dragRect = getRect(dragEl$1, false, true, true);
  2830. multiDragElements.forEach(function (multiDragElement) {
  2831. if (multiDragElement === dragEl$1) return;
  2832. setRect(multiDragElement, dragRect);
  2833. });
  2834. folding = true;
  2835. initialFolding = true;
  2836. }
  2837. }
  2838. sortable.animateAll(function () {
  2839. folding = false;
  2840. initialFolding = false;
  2841. if (_this2.options.animation) {
  2842. multiDragElements.forEach(function (multiDragElement) {
  2843. unsetRect(multiDragElement);
  2844. });
  2845. }
  2846. // Remove all auxiliary multidrag items from el, if sorting enabled
  2847. if (_this2.options.sort) {
  2848. removeMultiDragElements();
  2849. }
  2850. });
  2851. },
  2852. dragOver: function dragOver(_ref8) {
  2853. var target = _ref8.target,
  2854. completed = _ref8.completed,
  2855. cancel = _ref8.cancel;
  2856. if (folding && ~multiDragElements.indexOf(target)) {
  2857. completed(false);
  2858. cancel();
  2859. }
  2860. },
  2861. revert: function revert(_ref9) {
  2862. var fromSortable = _ref9.fromSortable,
  2863. rootEl = _ref9.rootEl,
  2864. sortable = _ref9.sortable,
  2865. dragRect = _ref9.dragRect;
  2866. if (multiDragElements.length > 1) {
  2867. // Setup unfold animation
  2868. multiDragElements.forEach(function (multiDragElement) {
  2869. sortable.addAnimationState({
  2870. target: multiDragElement,
  2871. rect: folding ? getRect(multiDragElement) : dragRect
  2872. });
  2873. unsetRect(multiDragElement);
  2874. multiDragElement.fromRect = dragRect;
  2875. fromSortable.removeAnimationState(multiDragElement);
  2876. });
  2877. folding = false;
  2878. insertMultiDragElements(!this.options.removeCloneOnHide, rootEl);
  2879. }
  2880. },
  2881. dragOverCompleted: function dragOverCompleted(_ref10) {
  2882. var sortable = _ref10.sortable,
  2883. isOwner = _ref10.isOwner,
  2884. insertion = _ref10.insertion,
  2885. activeSortable = _ref10.activeSortable,
  2886. parentEl = _ref10.parentEl,
  2887. putSortable = _ref10.putSortable;
  2888. var options = this.options;
  2889. if (insertion) {
  2890. // Clones must be hidden before folding animation to capture dragRectAbsolute properly
  2891. if (isOwner) {
  2892. activeSortable._hideClone();
  2893. }
  2894. initialFolding = false;
  2895. // If leaving sort:false root, or already folding - Fold to new location
  2896. if (options.animation && multiDragElements.length > 1 && (folding || !isOwner && !activeSortable.options.sort && !putSortable)) {
  2897. // Fold: Set all multi drag elements's rects to dragEl's rect when multi-drag elements are invisible
  2898. var dragRectAbsolute = getRect(dragEl$1, false, true, true);
  2899. multiDragElements.forEach(function (multiDragElement) {
  2900. if (multiDragElement === dragEl$1) return;
  2901. setRect(multiDragElement, dragRectAbsolute);
  2902. // Move element(s) to end of parentEl so that it does not interfere with multi-drag clones insertion if they are inserted
  2903. // while folding, and so that we can capture them again because old sortable will no longer be fromSortable
  2904. parentEl.appendChild(multiDragElement);
  2905. });
  2906. folding = true;
  2907. }
  2908. // Clones must be shown (and check to remove multi drags) after folding when interfering multiDragElements are moved out
  2909. if (!isOwner) {
  2910. // Only remove if not folding (folding will remove them anyways)
  2911. if (!folding) {
  2912. removeMultiDragElements();
  2913. }
  2914. if (multiDragElements.length > 1) {
  2915. var clonesHiddenBefore = clonesHidden;
  2916. activeSortable._showClone(sortable);
  2917. // Unfold animation for clones if showing from hidden
  2918. if (activeSortable.options.animation && !clonesHidden && clonesHiddenBefore) {
  2919. multiDragClones.forEach(function (clone) {
  2920. activeSortable.addAnimationState({
  2921. target: clone,
  2922. rect: clonesFromRect
  2923. });
  2924. clone.fromRect = clonesFromRect;
  2925. clone.thisAnimationDuration = null;
  2926. });
  2927. }
  2928. } else {
  2929. activeSortable._showClone(sortable);
  2930. }
  2931. }
  2932. }
  2933. },
  2934. dragOverAnimationCapture: function dragOverAnimationCapture(_ref11) {
  2935. var dragRect = _ref11.dragRect,
  2936. isOwner = _ref11.isOwner,
  2937. activeSortable = _ref11.activeSortable;
  2938. multiDragElements.forEach(function (multiDragElement) {
  2939. multiDragElement.thisAnimationDuration = null;
  2940. });
  2941. if (activeSortable.options.animation && !isOwner && activeSortable.multiDrag.isMultiDrag) {
  2942. clonesFromRect = _extends({}, dragRect);
  2943. var dragMatrix = matrix(dragEl$1, true);
  2944. clonesFromRect.top -= dragMatrix.f;
  2945. clonesFromRect.left -= dragMatrix.e;
  2946. }
  2947. },
  2948. dragOverAnimationComplete: function dragOverAnimationComplete() {
  2949. if (folding) {
  2950. folding = false;
  2951. removeMultiDragElements();
  2952. }
  2953. },
  2954. drop: function drop(_ref12) {
  2955. var evt = _ref12.originalEvent,
  2956. rootEl = _ref12.rootEl,
  2957. parentEl = _ref12.parentEl,
  2958. sortable = _ref12.sortable,
  2959. dispatchSortableEvent = _ref12.dispatchSortableEvent,
  2960. oldIndex = _ref12.oldIndex,
  2961. putSortable = _ref12.putSortable;
  2962. var toSortable = putSortable || this.sortable;
  2963. if (!evt) return;
  2964. var options = this.options,
  2965. children = parentEl.children;
  2966. // Multi-drag selection
  2967. if (!dragStarted) {
  2968. if (options.multiDragKey && !this.multiDragKeyDown) {
  2969. this._deselectMultiDrag();
  2970. }
  2971. toggleClass(dragEl$1, options.selectedClass, !~multiDragElements.indexOf(dragEl$1));
  2972. if (!~multiDragElements.indexOf(dragEl$1)) {
  2973. multiDragElements.push(dragEl$1);
  2974. dispatchEvent({
  2975. sortable: sortable,
  2976. rootEl: rootEl,
  2977. name: 'select',
  2978. targetEl: dragEl$1,
  2979. originalEvent: evt
  2980. });
  2981. // Modifier activated, select from last to dragEl
  2982. if (evt.shiftKey && lastMultiDragSelect && sortable.el.contains(lastMultiDragSelect)) {
  2983. var lastIndex = index(lastMultiDragSelect),
  2984. currentIndex = index(dragEl$1);
  2985. if (~lastIndex && ~currentIndex && lastIndex !== currentIndex) {
  2986. // Must include lastMultiDragSelect (select it), in case modified selection from no selection
  2987. // (but previous selection existed)
  2988. var n, i;
  2989. if (currentIndex > lastIndex) {
  2990. i = lastIndex;
  2991. n = currentIndex;
  2992. } else {
  2993. i = currentIndex;
  2994. n = lastIndex + 1;
  2995. }
  2996. for (; i < n; i++) {
  2997. if (~multiDragElements.indexOf(children[i])) continue;
  2998. toggleClass(children[i], options.selectedClass, true);
  2999. multiDragElements.push(children[i]);
  3000. dispatchEvent({
  3001. sortable: sortable,
  3002. rootEl: rootEl,
  3003. name: 'select',
  3004. targetEl: children[i],
  3005. originalEvent: evt
  3006. });
  3007. }
  3008. }
  3009. } else {
  3010. lastMultiDragSelect = dragEl$1;
  3011. }
  3012. multiDragSortable = toSortable;
  3013. } else {
  3014. multiDragElements.splice(multiDragElements.indexOf(dragEl$1), 1);
  3015. lastMultiDragSelect = null;
  3016. dispatchEvent({
  3017. sortable: sortable,
  3018. rootEl: rootEl,
  3019. name: 'deselect',
  3020. targetEl: dragEl$1,
  3021. originalEvent: evt
  3022. });
  3023. }
  3024. }
  3025. // Multi-drag drop
  3026. if (dragStarted && this.isMultiDrag) {
  3027. folding = false;
  3028. // Do not "unfold" after around dragEl if reverted
  3029. if ((parentEl[expando].options.sort || parentEl !== rootEl) && multiDragElements.length > 1) {
  3030. var dragRect = getRect(dragEl$1),
  3031. multiDragIndex = index(dragEl$1, ':not(.' + this.options.selectedClass + ')');
  3032. if (!initialFolding && options.animation) dragEl$1.thisAnimationDuration = null;
  3033. toSortable.captureAnimationState();
  3034. if (!initialFolding) {
  3035. if (options.animation) {
  3036. dragEl$1.fromRect = dragRect;
  3037. multiDragElements.forEach(function (multiDragElement) {
  3038. multiDragElement.thisAnimationDuration = null;
  3039. if (multiDragElement !== dragEl$1) {
  3040. var rect = folding ? getRect(multiDragElement) : dragRect;
  3041. multiDragElement.fromRect = rect;
  3042. // Prepare unfold animation
  3043. toSortable.addAnimationState({
  3044. target: multiDragElement,
  3045. rect: rect
  3046. });
  3047. }
  3048. });
  3049. }
  3050. // Multi drag elements are not necessarily removed from the DOM on drop, so to reinsert
  3051. // properly they must all be removed
  3052. removeMultiDragElements();
  3053. multiDragElements.forEach(function (multiDragElement) {
  3054. if (children[multiDragIndex]) {
  3055. parentEl.insertBefore(multiDragElement, children[multiDragIndex]);
  3056. } else {
  3057. parentEl.appendChild(multiDragElement);
  3058. }
  3059. multiDragIndex++;
  3060. });
  3061. // If initial folding is done, the elements may have changed position because they are now
  3062. // unfolding around dragEl, even though dragEl may not have his index changed, so update event
  3063. // must be fired here as Sortable will not.
  3064. if (oldIndex === index(dragEl$1)) {
  3065. var update = false;
  3066. multiDragElements.forEach(function (multiDragElement) {
  3067. if (multiDragElement.sortableIndex !== index(multiDragElement)) {
  3068. update = true;
  3069. return;
  3070. }
  3071. });
  3072. if (update) {
  3073. dispatchSortableEvent('update');
  3074. dispatchSortableEvent('sort');
  3075. }
  3076. }
  3077. }
  3078. // Must be done after capturing individual rects (scroll bar)
  3079. multiDragElements.forEach(function (multiDragElement) {
  3080. unsetRect(multiDragElement);
  3081. });
  3082. toSortable.animateAll();
  3083. }
  3084. multiDragSortable = toSortable;
  3085. }
  3086. // Remove clones if necessary
  3087. if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
  3088. multiDragClones.forEach(function (clone) {
  3089. clone.parentNode && clone.parentNode.removeChild(clone);
  3090. });
  3091. }
  3092. },
  3093. nullingGlobal: function nullingGlobal() {
  3094. this.isMultiDrag = dragStarted = false;
  3095. multiDragClones.length = 0;
  3096. },
  3097. destroyGlobal: function destroyGlobal() {
  3098. this._deselectMultiDrag();
  3099. off(document, 'pointerup', this._deselectMultiDrag);
  3100. off(document, 'mouseup', this._deselectMultiDrag);
  3101. off(document, 'touchend', this._deselectMultiDrag);
  3102. off(document, 'keydown', this._checkKeyDown);
  3103. off(document, 'keyup', this._checkKeyUp);
  3104. },
  3105. _deselectMultiDrag: function _deselectMultiDrag(evt) {
  3106. if (typeof dragStarted !== "undefined" && dragStarted) return;
  3107. // Only deselect if selection is in this sortable
  3108. if (multiDragSortable !== this.sortable) return;
  3109. // Only deselect if target is not item in this sortable
  3110. if (evt && closest(evt.target, this.options.draggable, this.sortable.el, false)) return;
  3111. // Only deselect if left click
  3112. if (evt && evt.button !== 0) return;
  3113. while (multiDragElements.length) {
  3114. var el = multiDragElements[0];
  3115. toggleClass(el, this.options.selectedClass, false);
  3116. multiDragElements.shift();
  3117. dispatchEvent({
  3118. sortable: this.sortable,
  3119. rootEl: this.sortable.el,
  3120. name: 'deselect',
  3121. targetEl: el,
  3122. originalEvent: evt
  3123. });
  3124. }
  3125. },
  3126. _checkKeyDown: function _checkKeyDown(evt) {
  3127. if (evt.key === this.options.multiDragKey) {
  3128. this.multiDragKeyDown = true;
  3129. }
  3130. },
  3131. _checkKeyUp: function _checkKeyUp(evt) {
  3132. if (evt.key === this.options.multiDragKey) {
  3133. this.multiDragKeyDown = false;
  3134. }
  3135. }
  3136. };
  3137. return _extends(MultiDrag, {
  3138. // Static methods & properties
  3139. pluginName: 'multiDrag',
  3140. utils: {
  3141. /**
  3142. * Selects the provided multi-drag item
  3143. * @param {HTMLElement} el The element to be selected
  3144. */
  3145. select: function select(el) {
  3146. var sortable = el.parentNode[expando];
  3147. if (!sortable || !sortable.options.multiDrag || ~multiDragElements.indexOf(el)) return;
  3148. if (multiDragSortable && multiDragSortable !== sortable) {
  3149. multiDragSortable.multiDrag._deselectMultiDrag();
  3150. multiDragSortable = sortable;
  3151. }
  3152. toggleClass(el, sortable.options.selectedClass, true);
  3153. multiDragElements.push(el);
  3154. },
  3155. /**
  3156. * Deselects the provided multi-drag item
  3157. * @param {HTMLElement} el The element to be deselected
  3158. */
  3159. deselect: function deselect(el) {
  3160. var sortable = el.parentNode[expando],
  3161. index = multiDragElements.indexOf(el);
  3162. if (!sortable || !sortable.options.multiDrag || !~index) return;
  3163. toggleClass(el, sortable.options.selectedClass, false);
  3164. multiDragElements.splice(index, 1);
  3165. }
  3166. },
  3167. eventProperties: function eventProperties() {
  3168. var _this3 = this;
  3169. var oldIndicies = [],
  3170. newIndicies = [];
  3171. multiDragElements.forEach(function (multiDragElement) {
  3172. oldIndicies.push({
  3173. multiDragElement: multiDragElement,
  3174. index: multiDragElement.sortableIndex
  3175. });
  3176. // multiDragElements will already be sorted if folding
  3177. var newIndex;
  3178. if (folding && multiDragElement !== dragEl$1) {
  3179. newIndex = -1;
  3180. } else if (folding) {
  3181. newIndex = index(multiDragElement, ':not(.' + _this3.options.selectedClass + ')');
  3182. } else {
  3183. newIndex = index(multiDragElement);
  3184. }
  3185. newIndicies.push({
  3186. multiDragElement: multiDragElement,
  3187. index: newIndex
  3188. });
  3189. });
  3190. return {
  3191. items: _toConsumableArray(multiDragElements),
  3192. clones: [].concat(multiDragClones),
  3193. oldIndicies: oldIndicies,
  3194. newIndicies: newIndicies
  3195. };
  3196. },
  3197. optionListeners: {
  3198. multiDragKey: function multiDragKey(key) {
  3199. key = key.toLowerCase();
  3200. if (key === 'ctrl') {
  3201. key = 'Control';
  3202. } else if (key.length > 1) {
  3203. key = key.charAt(0).toUpperCase() + key.substr(1);
  3204. }
  3205. return key;
  3206. }
  3207. }
  3208. });
  3209. }
  3210. function insertMultiDragElements(clonesInserted, rootEl) {
  3211. multiDragElements.forEach(function (multiDragElement, i) {
  3212. var target = rootEl.children[multiDragElement.sortableIndex + (clonesInserted ? Number(i) : 0)];
  3213. if (target) {
  3214. rootEl.insertBefore(multiDragElement, target);
  3215. } else {
  3216. rootEl.appendChild(multiDragElement);
  3217. }
  3218. });
  3219. }
  3220. /**
  3221. * Insert multi-drag clones
  3222. * @param {[Boolean]} elementsInserted Whether the multi-drag elements are inserted
  3223. * @param {HTMLElement} rootEl
  3224. */
  3225. function insertMultiDragClones(elementsInserted, rootEl) {
  3226. multiDragClones.forEach(function (clone, i) {
  3227. var target = rootEl.children[clone.sortableIndex + (elementsInserted ? Number(i) : 0)];
  3228. if (target) {
  3229. rootEl.insertBefore(clone, target);
  3230. } else {
  3231. rootEl.appendChild(clone);
  3232. }
  3233. });
  3234. }
  3235. function removeMultiDragElements() {
  3236. multiDragElements.forEach(function (multiDragElement) {
  3237. if (multiDragElement === dragEl$1) return;
  3238. multiDragElement.parentNode && multiDragElement.parentNode.removeChild(multiDragElement);
  3239. });
  3240. }
  3241. Sortable.mount(new AutoScrollPlugin());
  3242. Sortable.mount(Remove, Revert);
  3243. Sortable.mount(new SwapPlugin());
  3244. Sortable.mount(new MultiDragPlugin());
  3245. return Sortable;
  3246. })));