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

Function SwapPlugin

modular/sortable.core.esm.js:2689–2755  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

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…