All user data for FoundryVTT. Includes worlds, systems, modules, and any asset in the "foundryuserdata" directory. Does NOT include the FoundryVTT installation itself.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

465 lines
15 KiB

1 year ago
  1. //Jquery Sortable
  2. //Created by Jonas von Andrian.
  3. //jquery-sortable.js is released under the Modified BSD License.
  4. //License http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5
  5. !(function (d, B, m, f) {
  6. function v(a, b) {
  7. var c = Math.max(0, a[0] - b[0], b[0] - a[1]),
  8. e = Math.max(0, a[2] - b[1], b[1] - a[3]);
  9. return c + e;
  10. }
  11. function w(a, b, c, e) {
  12. var k = a.length;
  13. e = e ? "offset" : "position";
  14. for (c = c || 0; k--; ) {
  15. var g = a[k].el ? a[k].el : d(a[k]),
  16. l = g[e]();
  17. l.left += parseInt(g.css("margin-left"), 10);
  18. l.top += parseInt(g.css("margin-top"), 10);
  19. b[k] = [
  20. l.left - c,
  21. l.left + g.outerWidth() + c,
  22. l.top - c,
  23. l.top + g.outerHeight() + c,
  24. ];
  25. }
  26. }
  27. function p(a, b) {
  28. var c = b.offset();
  29. return { left: a.left - c.left, top: a.top - c.top };
  30. }
  31. function x(a, b, c) {
  32. b = [b.left, b.top];
  33. c = c && [c.left, c.top];
  34. for (var e, k = a.length, d = []; k--; )
  35. (e = a[k]), (d[k] = [k, v(e, b), c && v(e, c)]);
  36. return (d = d.sort(function (a, b) {
  37. return b[1] - a[1] || b[2] - a[2] || b[0] - a[0];
  38. }));
  39. }
  40. function q(a) {
  41. this.options = d.extend({}, n, a);
  42. this.containers = [];
  43. this.options.rootGroup ||
  44. ((this.scrollProxy = d.proxy(this.scroll, this)),
  45. (this.dragProxy = d.proxy(this.drag, this)),
  46. (this.dropProxy = d.proxy(this.drop, this)),
  47. (this.placeholder = d(this.options.placeholder)),
  48. a.isValidTarget || (this.options.isValidTarget = f));
  49. }
  50. function s(a, b) {
  51. this.el = a;
  52. this.options = d.extend({}, z, b);
  53. this.group = q.get(this.options);
  54. this.rootGroup = this.options.rootGroup || this.group;
  55. this.handle =
  56. this.rootGroup.options.handle || this.rootGroup.options.itemSelector;
  57. var c = this.rootGroup.options.itemPath;
  58. this.target = c ? this.el.find(c) : this.el;
  59. this.target.on(t.start, this.handle, d.proxy(this.dragInit, this));
  60. this.options.drop && this.group.containers.push(this);
  61. }
  62. var z = { drag: !0, drop: !0, exclude: "", nested: !0, vertical: !0 },
  63. n = {
  64. afterMove: function (a, b, c) {},
  65. containerPath: "",
  66. containerSelector: "ol, ul",
  67. distance: 0,
  68. delay: 0,
  69. handle: "",
  70. itemPath: "",
  71. itemSelector: "li",
  72. bodyClass: "dragging",
  73. draggedClass: "dragged",
  74. isValidTarget: function (a, b) {
  75. return !0;
  76. },
  77. onCancel: function (a, b, c, e) {},
  78. onDrag: function (a, b, c, e) {
  79. a.css(b);
  80. },
  81. onDragStart: function (a, b, c, e) {
  82. a.css({ height: a.outerHeight(), width: a.outerWidth() });
  83. a.addClass(b.group.options.draggedClass);
  84. d("body").addClass(b.group.options.bodyClass);
  85. },
  86. onDrop: function (a, b, c, e) {
  87. a.removeClass(b.group.options.draggedClass).removeAttr("style");
  88. d("body").removeClass(b.group.options.bodyClass);
  89. },
  90. onMousedown: function (a, b, c) {
  91. if (!c.target.nodeName.match(/^(input|select|textarea)$/i))
  92. return c.preventDefault(), !0;
  93. },
  94. placeholderClass: "placeholder",
  95. placeholder: '<li class="placeholder"></li>',
  96. pullPlaceholder: !0,
  97. serialize: function (a, b, c) {
  98. a = d.extend({}, a.data());
  99. if (c) return [b];
  100. b[0] && (a.children = b);
  101. delete a.subContainers;
  102. delete a.sortable;
  103. return a;
  104. },
  105. tolerance: 0,
  106. },
  107. r = {},
  108. y = 0,
  109. A = { left: 0, top: 0, bottom: 0, right: 0 },
  110. t = {
  111. start: "touchstart.sortable mousedown.sortable",
  112. drop: "touchend.sortable touchcancel.sortable mouseup.sortable",
  113. drag: "touchmove.sortable mousemove.sortable",
  114. scroll: "scroll.sortable",
  115. };
  116. q.get = function (a) {
  117. r[a.group] || (a.group === f && (a.group = y++), (r[a.group] = new q(a)));
  118. return r[a.group];
  119. };
  120. q.prototype = {
  121. dragInit: function (a, b) {
  122. this.$document = d(b.el[0].ownerDocument);
  123. var c = d(a.target).closest(this.options.itemSelector);
  124. c.length &&
  125. ((this.item = c),
  126. (this.itemContainer = b),
  127. !this.item.is(this.options.exclude) &&
  128. this.options.onMousedown(this.item, n.onMousedown, a) &&
  129. (this.setPointer(a),
  130. this.toggleListeners("on"),
  131. this.setupDelayTimer(),
  132. (this.dragInitDone = !0)));
  133. },
  134. drag: function (a) {
  135. if (!this.dragging) {
  136. if (!this.distanceMet(a) || !this.delayMet) return;
  137. this.options.onDragStart(
  138. this.item,
  139. this.itemContainer,
  140. n.onDragStart,
  141. a
  142. );
  143. this.item.before(this.placeholder);
  144. this.dragging = !0;
  145. }
  146. this.setPointer(a);
  147. this.options.onDrag(
  148. this.item,
  149. p(this.pointer, this.item.offsetParent()),
  150. n.onDrag,
  151. a
  152. );
  153. a = this.getPointer(a);
  154. var b = this.sameResultBox,
  155. c = this.options.tolerance;
  156. (!b ||
  157. b.top - c > a.top ||
  158. b.bottom + c < a.top ||
  159. b.left - c > a.left ||
  160. b.right + c < a.left) &&
  161. !this.searchValidTarget() &&
  162. (this.placeholder.detach(), (this.lastAppendedItem = f));
  163. },
  164. drop: function (a) {
  165. this.toggleListeners("off");
  166. this.dragInitDone = !1;
  167. if (this.dragging) {
  168. if (this.placeholder.closest("html")[0])
  169. this.placeholder.before(this.item).detach();
  170. else
  171. this.options.onCancel(this.item, this.itemContainer, n.onCancel, a);
  172. this.options.onDrop(
  173. this.item,
  174. this.getContainer(this.item),
  175. n.onDrop,
  176. a
  177. );
  178. this.clearDimensions();
  179. this.clearOffsetParent();
  180. this.lastAppendedItem = this.sameResultBox = f;
  181. this.dragging = !1;
  182. }
  183. },
  184. searchValidTarget: function (a, b) {
  185. a ||
  186. ((a = this.relativePointer || this.pointer),
  187. (b = this.lastRelativePointer || this.lastPointer));
  188. for (
  189. var c = x(this.getContainerDimensions(), a, b), e = c.length;
  190. e--;
  191. ) {
  192. var d = c[e][0];
  193. if (!c[e][1] || this.options.pullPlaceholder)
  194. if (((d = this.containers[d]), !d.disabled)) {
  195. if (!this.$getOffsetParent()) {
  196. var g = d.getItemOffsetParent();
  197. a = p(a, g);
  198. b = p(b, g);
  199. }
  200. if (d.searchValidTarget(a, b)) return !0;
  201. }
  202. }
  203. this.sameResultBox && (this.sameResultBox = f);
  204. },
  205. movePlaceholder: function (a, b, c, e) {
  206. var d = this.lastAppendedItem;
  207. if (e || !d || d[0] !== b[0])
  208. b[c](this.placeholder),
  209. (this.lastAppendedItem = b),
  210. (this.sameResultBox = e),
  211. this.options.afterMove(this.placeholder, a, b);
  212. },
  213. getContainerDimensions: function () {
  214. this.containerDimensions ||
  215. w(
  216. this.containers,
  217. (this.containerDimensions = []),
  218. this.options.tolerance,
  219. !this.$getOffsetParent()
  220. );
  221. return this.containerDimensions;
  222. },
  223. getContainer: function (a) {
  224. return a.closest(this.options.containerSelector).data(m);
  225. },
  226. $getOffsetParent: function () {
  227. if (this.offsetParent === f) {
  228. var a = this.containers.length - 1,
  229. b = this.containers[a].getItemOffsetParent();
  230. if (!this.options.rootGroup)
  231. for (; a--; )
  232. if (b[0] != this.containers[a].getItemOffsetParent()[0]) {
  233. b = !1;
  234. break;
  235. }
  236. this.offsetParent = b;
  237. }
  238. return this.offsetParent;
  239. },
  240. setPointer: function (a) {
  241. a = this.getPointer(a);
  242. if (this.$getOffsetParent()) {
  243. var b = p(a, this.$getOffsetParent());
  244. this.lastRelativePointer = this.relativePointer;
  245. this.relativePointer = b;
  246. }
  247. this.lastPointer = this.pointer;
  248. this.pointer = a;
  249. },
  250. distanceMet: function (a) {
  251. a = this.getPointer(a);
  252. return (
  253. Math.max(
  254. Math.abs(this.pointer.left - a.left),
  255. Math.abs(this.pointer.top - a.top)
  256. ) >= this.options.distance
  257. );
  258. },
  259. getPointer: function (a) {
  260. var b =
  261. a.originalEvent ||
  262. (a.originalEvent.touches && a.originalEvent.touches[0]);
  263. return { left: a.pageX || b.pageX, top: a.pageY || b.pageY };
  264. },
  265. setupDelayTimer: function () {
  266. var a = this;
  267. this.delayMet = !this.options.delay;
  268. this.delayMet ||
  269. (clearTimeout(this._mouseDelayTimer),
  270. (this._mouseDelayTimer = setTimeout(function () {
  271. a.delayMet = !0;
  272. }, this.options.delay)));
  273. },
  274. scroll: function (a) {
  275. this.clearDimensions();
  276. this.clearOffsetParent();
  277. },
  278. toggleListeners: function (a) {
  279. var b = this;
  280. d.each(["drag", "drop", "scroll"], function (c, e) {
  281. b.$document[a](t[e], b[e + "Proxy"]);
  282. });
  283. },
  284. clearOffsetParent: function () {
  285. this.offsetParent = f;
  286. },
  287. clearDimensions: function () {
  288. this.traverse(function (a) {
  289. a._clearDimensions();
  290. });
  291. },
  292. traverse: function (a) {
  293. a(this);
  294. for (var b = this.containers.length; b--; )
  295. this.containers[b].traverse(a);
  296. },
  297. _clearDimensions: function () {
  298. this.containerDimensions = f;
  299. },
  300. _destroy: function () {
  301. r[this.options.group] = f;
  302. },
  303. };
  304. s.prototype = {
  305. dragInit: function (a) {
  306. var b = this.rootGroup;
  307. !this.disabled &&
  308. !b.dragInitDone &&
  309. this.options.drag &&
  310. this.isValidDrag(a) &&
  311. b.dragInit(a, this);
  312. },
  313. isValidDrag: function (a) {
  314. return (
  315. 1 == a.which ||
  316. ("touchstart" == a.type && 1 == a.originalEvent.touches.length)
  317. );
  318. },
  319. searchValidTarget: function (a, b) {
  320. var c = x(this.getItemDimensions(), a, b),
  321. e = c.length,
  322. d = this.rootGroup,
  323. g = !d.options.isValidTarget || d.options.isValidTarget(d.item, this);
  324. if (!e && g) return d.movePlaceholder(this, this.target, "append"), !0;
  325. for (; e--; )
  326. if (((d = c[e][0]), !c[e][1] && this.hasChildGroup(d))) {
  327. if (this.getContainerGroup(d).searchValidTarget(a, b)) return !0;
  328. } else if (g) return this.movePlaceholder(d, a), !0;
  329. },
  330. movePlaceholder: function (a, b) {
  331. var c = d(this.items[a]),
  332. e = this.itemDimensions[a],
  333. k = "after",
  334. g = c.outerWidth(),
  335. f = c.outerHeight(),
  336. h = c.offset(),
  337. h = { left: h.left, right: h.left + g, top: h.top, bottom: h.top + f };
  338. this.options.vertical
  339. ? b.top <= (e[2] + e[3]) / 2
  340. ? ((k = "before"), (h.bottom -= f / 2))
  341. : (h.top += f / 2)
  342. : b.left <= (e[0] + e[1]) / 2
  343. ? ((k = "before"), (h.right -= g / 2))
  344. : (h.left += g / 2);
  345. this.hasChildGroup(a) && (h = A);
  346. this.rootGroup.movePlaceholder(this, c, k, h);
  347. },
  348. getItemDimensions: function () {
  349. this.itemDimensions ||
  350. ((this.items = this.$getChildren(this.el, "item")
  351. .filter(
  352. ":not(." +
  353. this.group.options.placeholderClass +
  354. ", ." +
  355. this.group.options.draggedClass +
  356. ")"
  357. )
  358. .get()),
  359. w(this.items, (this.itemDimensions = []), this.options.tolerance));
  360. return this.itemDimensions;
  361. },
  362. getItemOffsetParent: function () {
  363. var a = this.el;
  364. return "relative" === a.css("position") ||
  365. "absolute" === a.css("position") ||
  366. "fixed" === a.css("position")
  367. ? a
  368. : a.offsetParent();
  369. },
  370. hasChildGroup: function (a) {
  371. return this.options.nested && this.getContainerGroup(a);
  372. },
  373. getContainerGroup: function (a) {
  374. var b = d.data(this.items[a], "subContainers");
  375. if (b === f) {
  376. var c = this.$getChildren(this.items[a], "container"),
  377. b = !1;
  378. c[0] &&
  379. ((b = d.extend({}, this.options, {
  380. rootGroup: this.rootGroup,
  381. group: y++,
  382. })),
  383. (b = c[m](b).data(m).group));
  384. d.data(this.items[a], "subContainers", b);
  385. }
  386. return b;
  387. },
  388. $getChildren: function (a, b) {
  389. var c = this.rootGroup.options,
  390. e = c[b + "Path"],
  391. c = c[b + "Selector"];
  392. a = d(a);
  393. e && (a = a.find(e));
  394. return a.children(c);
  395. },
  396. _serialize: function (a, b) {
  397. var c = this,
  398. e = this.$getChildren(a, b ? "item" : "container")
  399. .not(this.options.exclude)
  400. .map(function () {
  401. return c._serialize(d(this), !b);
  402. })
  403. .get();
  404. return this.rootGroup.options.serialize(a, e, b);
  405. },
  406. traverse: function (a) {
  407. d.each(this.items || [], function (b) {
  408. (b = d.data(this, "subContainers")) && b.traverse(a);
  409. });
  410. a(this);
  411. },
  412. _clearDimensions: function () {
  413. this.itemDimensions = f;
  414. },
  415. _destroy: function () {
  416. var a = this;
  417. this.target.off(t.start, this.handle);
  418. this.el.removeData(m);
  419. this.options.drop &&
  420. (this.group.containers = d.grep(this.group.containers, function (b) {
  421. return b != a;
  422. }));
  423. d.each(this.items || [], function () {
  424. d.removeData(this, "subContainers");
  425. });
  426. },
  427. };
  428. var u = {
  429. enable: function () {
  430. this.traverse(function (a) {
  431. a.disabled = !1;
  432. });
  433. },
  434. disable: function () {
  435. this.traverse(function (a) {
  436. a.disabled = !0;
  437. });
  438. },
  439. serialize: function () {
  440. return this._serialize(this.el, !0);
  441. },
  442. refresh: function () {
  443. this.traverse(function (a) {
  444. a._clearDimensions();
  445. });
  446. },
  447. destroy: function () {
  448. this.traverse(function (a) {
  449. a._destroy();
  450. });
  451. },
  452. };
  453. d.extend(s.prototype, u);
  454. d.fn[m] = function (a) {
  455. var b = Array.prototype.slice.call(arguments, 1);
  456. return this.map(function () {
  457. var c = d(this),
  458. e = c.data(m);
  459. if (e && u[a]) return u[a].apply(e, b) || this;
  460. e || (a !== f && "object" !== typeof a) || c.data(m, new s(c, a));
  461. return this;
  462. });
  463. };
  464. })(jQuery, window, "sortable");