-
-
Notifications
You must be signed in to change notification settings - Fork 461
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
Callback support for acceptFrom #646
base: master
Are you sure you want to change the base?
Changes from all commits
2a0efe9
ce0a3b1
c21c9cd
8f4b73e
06fd283
379a3cd
d98c689
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,6 +244,19 @@ In the example the current list `.sortable` allows items within it to be sorted | |
|
||
If you want to be able to move items between to sortables, the `acceptFrom` option must be present on both of them. | ||
|
||
Can also accept a callback function with `destinationSortable` and `draggedElement` as paramaters, This function should return `true` or `false`: | ||
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. Can you please change this to: You can also provide a function for the |
||
|
||
``` javascript | ||
sortable('.sortable', { | ||
acceptFrom: function(destinationSortable, draggedElement){ | ||
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. Can you please change this to use a fat arrow function and change it to the below: (destinationSortable, draggedElement) => {
// your custom function
if (draggedElement.classList.contains('canDrop')) {
return true
} else {
return false
}
} |
||
if(draggedElement.classList.contains('canDrop')){ | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
}); | ||
|
||
### placeholder | ||
Use the `placeholder` option to specify the markup of the placeholder: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,33 @@ import store from './store' | |
/** | ||
* Check if curList accepts items from destList | ||
* @param {sortable} destination the container an item is move to | ||
* @param {sortable} origin the container an item comes from | ||
* @param {sortable} dom node currently being dragged | ||
*/ | ||
export default (destination: sortable, origin: sortable) => { | ||
export default (destination: sortable, dragging: node) => { | ||
// check if valid sortable | ||
if (destination.isSortable === true) { | ||
const acceptFrom = store(destination).getConfig('acceptFrom') | ||
// check if acceptFrom is valid | ||
if (acceptFrom !== null && acceptFrom !== false && typeof acceptFrom !== 'string') { | ||
if (acceptFrom !== null && acceptFrom !== false && typeof acceptFrom !== 'string' && typeof acceptFrom !== 'function') { | ||
throw new Error('HTML5Sortable: Wrong argument, "acceptFrom" must be "null", "false", or a valid selector 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. @mike16889 please change this to: 'HTML5Sortable:` Wrong argument, "acceptFrom" must be "null", "false", a function returning a boolean, or a valid selector string.' |
||
} | ||
|
||
if (acceptFrom !== null) { | ||
return acceptFrom !== false && acceptFrom.split(',').filter(function (sel) { | ||
return sel.length > 0 && origin.matches(sel) | ||
}).length > 0 | ||
if (typeof acceptFrom === 'function') { | ||
return acceptFrom(destination, dragging); | ||
} else { | ||
return acceptFrom !== false && acceptFrom.split(',').filter(function (sel) { | ||
return sel.length > 0 && dragging.parentElement.matches(sel) | ||
}).length > 0 | ||
} | ||
} | ||
// drop in same list | ||
if (destination === origin) { | ||
if (destination === dragging.parentElement) { | ||
return true | ||
} | ||
// check if lists are connected with connectWith | ||
if (store(destination).getConfig('connectWith') !== undefined && store(destination).getConfig('connectWith') !== null) { | ||
return store(destination).getConfig('connectWith') === store(origin).getConfig('connectWith') | ||
if ((store(destination).getConfig('connectWith') !== undefined && store(destination).getConfig('connectWith') !== null) && store(dragging.parentElement).getConfig('connectWith') !== undefined && store(dragging.parentElement).getConfig('connectWith') !== null) { | ||
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. @mike16889 why dod you add this check for the parent? I think this may create an issue if you have a place that does not accept, but only provide items to drag. |
||
return store(destination).getConfig('connectWith') === store(dragging.parentElement).getConfig('connectWith') | ||
} | ||
} | ||
return false | ||
|
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.
I know this is not you, but if you change it in any case, can you fix the typo