-
-
Notifications
You must be signed in to change notification settings - Fork 457
Add keep css class option #854
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -482,6 +482,10 @@ export default function sortable (sortableElements, options: configuration|objec | |
dragging.style.display = dragging.oldDisplay | ||
delete dragging.oldDisplay | ||
} | ||
// We need to reset placeholder if any css class were added. | ||
options.keepCssClass.forEach(className => { | ||
store(sortableElement).placeholder.classList.remove(className) | ||
}); | ||
} else { | ||
// set the dropped value to 'false' to delete copied dragging at the time of 'dragend' | ||
data(dragging, 'dropped', 'false') | ||
|
@@ -552,6 +556,13 @@ export default function sortable (sortableElements, options: configuration|objec | |
store(sortableElement).placeholder.style.height = draggingHeight + 'px' | ||
store(sortableElement).placeholder.style.width = draggingWidth + 'px' | ||
} | ||
// Keep some CSS class fo the dragged element, to keep style. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fo = for in comment |
||
// Usefull if sortable elements have different dimensions according class. | ||
options.keepCssClass.forEach(className => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think from a performance point of view you should first get the elements you want to add. Maybe use filter to get the elements that are in both arrays. Afterwards just like with remove, you can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry you lost me in the first sentence. |
||
if (element.classList.contains(className)) { | ||
store(sortableElement).placeholder.classList.add(className) | ||
} | ||
}); | ||
// if element the draggedItem is dragged onto is within the array of all elements in list | ||
// (not only items, but also disabled, etc.) | ||
if (Array.from(sortableElement.children).indexOf(element) > -1) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
interface configuration { | ||
items?: string, | ||
handle?: string, | ||
forcePlaceholderSize?:boolean; | ||
forcePlaceholderSize?: boolean, | ||
keepCssClass?: Array<string>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename this to |
||
connectWith?: string, | ||
acceptFrom?: void, | ||
placeholder?: void, | ||
|
@@ -12,9 +13,9 @@ interface configuration { | |
copy?: boolean, | ||
itemSerializer?: (serializedItem: serializedItem, sortableContainer: HTMLElement) => serializedItem, | ||
containerSerializer?: (serializedContainer: object) => object, | ||
customDragImage?:void, | ||
customDragImage?: void, | ||
disableIEFix?: boolean, | ||
debounce?: number, | ||
throttleTime?: number, | ||
orientation?: 'vertical'|'horizontal' | ||
orientation?: 'vertical' | 'horizontal' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done in one step https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/remove sot that all classes are provided at once.
I think this should work:
remove(...options.keepCssClass)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I will change that.