MCPcopy Index your code
hub / github.com/SortableJS/Sortable / SwapPlugin

Function SwapPlugin

modular/sortable.esm.js:2688–2754  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2686
2687var lastSwapEl;
2688function SwapPlugin() {
2689 function Swap() {
2690 this.defaults = {
2691 swapClass: 'sortable-swap-highlight'
2692 };
2693 }
2694 Swap.prototype = {
2695 dragStart: function dragStart(_ref) {
2696 var dragEl = _ref.dragEl;
2697 lastSwapEl = dragEl;
2698 },
2699 dragOverValid: function dragOverValid(_ref2) {
2700 var completed = _ref2.completed,
2701 target = _ref2.target,
2702 onMove = _ref2.onMove,
2703 activeSortable = _ref2.activeSortable,
2704 changed = _ref2.changed,
2705 cancel = _ref2.cancel;
2706 if (!activeSortable.options.swap) return;
2707 var el = this.sortable.el,
2708 options = this.options;
2709 if (target && target !== el) {
2710 var prevSwapEl = lastSwapEl;
2711 if (onMove(target) !== false) {
2712 toggleClass(target, options.swapClass, true);
2713 lastSwapEl = target;
2714 } else {
2715 lastSwapEl = null;
2716 }
2717 if (prevSwapEl && prevSwapEl !== lastSwapEl) {
2718 toggleClass(prevSwapEl, options.swapClass, false);
2719 }
2720 }
2721 changed();
2722 completed(true);
2723 cancel();
2724 },
2725 drop: function drop(_ref3) {
2726 var activeSortable = _ref3.activeSortable,
2727 putSortable = _ref3.putSortable,
2728 dragEl = _ref3.dragEl;
2729 var toSortable = putSortable || this.sortable;
2730 var options = this.options;
2731 lastSwapEl && toggleClass(lastSwapEl, options.swapClass, false);
2732 if (lastSwapEl && (options.swap || putSortable && putSortable.options.swap)) {
2733 if (dragEl !== lastSwapEl) {
2734 toSortable.captureAnimationState();
2735 if (toSortable !== activeSortable) activeSortable.captureAnimationState();
2736 swapNodes(dragEl, lastSwapEl);
2737 toSortable.animateAll();
2738 if (toSortable !== activeSortable) activeSortable.animateAll();
2739 }
2740 }
2741 },
2742 nulling: function nulling() {
2743 lastSwapEl = null;
2744 }
2745 };

Callers

nothing calls this directly

Calls 6

onMoveFunction · 0.85
toggleClassFunction · 0.70
changedFunction · 0.70
completedFunction · 0.70
swapNodesFunction · 0.70
_extendsFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…