Sortable.js 118 KB

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