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
jQuery compatibility? #151
Comments
why don't you write $("#foo")[0] ? |
Because it returns an instance, so it is not clear what to do in collection hang at first element or all? |
The jQuery convention is to preserve method chaining, so the entire collection should be processed, and the resulting Sortable objects should be returned in an array. |
This is not correct behavior for Correctly will make, ex. so: if (typeof jQuery !== 'undefined') {
jQuery.fn.sortable = function (options) {
return this.each(function () {
var $el = $(this);
var sortable = $el.data('sortable');
if (!sortable && options instanceof Object) {
sortable = new Sortable(this, options);
$el.data('sortable', sortable);
}
if (sortable && (options in sortable)) {
sortable[sortable].apply(sortable, [].slice.call(arguments, 1));
}
})
};
} |
That looks much better. |
👍 Would be great to have some jQuery support to make things a bit tidier if already using jQuery in a project |
Tested and working great for my limited usage. I see you updated Sortable.min.js - was this supposed to include the jquery bindings? |
No. |
@njh + |
Fantastic! |
I found myself writing, out of habit,
new Sortable($('#foo'))
.Would it be bad if Sortable supported jQuery? The change would be small, I think. Something like this wrapping the constructor:
The text was updated successfully, but these errors were encountered: