Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions BlazorSortableList.Lib/SortableList.razor.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
let debugMode = false;

/**
* Turns on verbose drag/drop tracing. Off by default so consumers get a quiet console.
* Matched strictly rather than by truthiness, so the string "false" does not switch logging on.
*/
export function setDebugMode(isEnabled) {
debugMode = isEnabled === true || isEnabled === 'true';
}

export function init(id, group, pull, put, sort, handle, filter, component, forceFallback, cssForSelection, multiDragKey, avoidImplicitDeselect, fallbackOnBody, swapThreshold) {

const DEBUG_MODE = true;
if (DEBUG_MODE) {
if (debugMode) {
console.log("Init for Id:", id, "swapThreshold:", swapThreshold);
}
let multiDrag = (typeof cssForSelection !== 'undefined');
Expand All @@ -17,7 +26,7 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
console.error("SortableList init failed: global Sortable not found. Make sure Sortable.js is loaded before this module.", id);
return;
}
if (DEBUG_MODE && SortableCtor.version) {
if (debugMode && SortableCtor.version) {
console.log("Sortable version:", SortableCtor.version);
}

Expand Down Expand Up @@ -70,7 +79,7 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
avoidImplicitDeselect: avoidImplicitDeselect,
swapThreshold: swapThreshold, //0.65,
onUpdate: (event) => {
if (DEBUG_MODE) {
if (debugMode) {
console.log("onUpdate:");
console.log(event);
}
Expand All @@ -96,7 +105,7 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
event.to.insertBefore(item.multiDragElement, event.to.childNodes[item.index]);
});
} else {
if (DEBUG_MODE) {
if (debugMode) {
//console.log("remove item for update:");
//console.log(event.item);
//console.log("insert it before:", event.to, event.oldIndex, event.to.childNodes, event.to.childNodes[event.oldIndex]);
Expand All @@ -111,7 +120,7 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
component.invokeMethodAsync('OnUpdateJS', oldIndex, newIndex, event.from.id);
},
onRemove: (event) => {
if (DEBUG_MODE) {
if (debugMode) {
console.log("onRemove:");
console.log(event);
}
Expand Down Expand Up @@ -150,14 +159,14 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
component.invokeMethodAsync('OnRemoveJS', oldIndex, newIndex, event.from.id, event.to.id);
},
onSelect: (event) => {
if (DEBUG_MODE) {
if (debugMode) {
console.log("onSelect:");
console.log(event);
}

let children = Array.from(event.from.children);
let index = children.indexOf(event.item);
if (DEBUG_MODE) {
if (debugMode) {
//console.log(children);
console.log(index);
}
Expand All @@ -166,22 +175,22 @@ export function init(id, group, pull, put, sort, handle, filter, component, forc
component.invokeMethodAsync('OnSelectJS', event.from.id, index);
},
onDeselect: (event) => {
if (DEBUG_MODE) {
if (debugMode) {
console.log("onDeselect:");
console.log(event);
}

let children = Array.from(event.to.children);
let index = children.indexOf(event.item);
if (DEBUG_MODE) {
if (debugMode) {
console.log(index);
}

// Notify .NET to update its model and re-render
component.invokeMethodAsync('OnDeselectJS', event.from.id, index);
},
onEnd:(event) => {
if (DEBUG_MODE) {
if (debugMode) {
console.log("onEnd:");
console.log(event);
}
Expand Down