Sortable.js 121 KB

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