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

Function SwapPlugin

Sortable.js:2694–2760  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

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…