Skip to content

Instantly share code, notes, and snippets.

@n3rd
Created April 27, 2014 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n3rd/11342907 to your computer and use it in GitHub Desktop.
Save n3rd/11342907 to your computer and use it in GitHub Desktop.
Knockout BindingHandler for jQuery UI sortalble
ko.bindingHandlers.sortableList = {
init: function (element, valueAccessor, allBindings) {
var items = allBindings.get('items') || 'li';
var update = allBindings.get('update') || 'Index';
var disable = allBindings.get('disable') || false;
$(element).sortable({
items: items,
update: function ($e, $ui) {
$ui.item.parent().children(items).each(function (k, v) {
var data = ko.dataFor(v);
if (typeof data[update] === 'function') {
data[update](k);
} else {
data[update] = k;
}
});
}
}).sortable({ disabled: disable });
},
update: function (element, valueAccessor, allBindings) {
var disable = allBindings.get('disable') || false;
$(element).sortable({ disabled: disable });
}
};
@n3rd
Copy link
Author

n3rd commented Apr 27, 2014

demo @ JSFiddle: http://jsfiddle.net/mt3b4/2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment