Skip to content

Instantly share code, notes, and snippets.

@tamagokun
Last active August 29, 2015 14:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamagokun/95e76ee50f59a97696ce to your computer and use it in GitHub Desktop.
Save tamagokun/95e76ee50f59a97696ce to your computer and use it in GitHub Desktop.
bbf-sortable-list.js
Form.editors.SortableList = Form.editors.List.extend({
initialize: function() {
Form.editors.List.prototype.initialize.apply(this, arguments);
},
render: function() {
Form.editors.List.prototype.render.apply(this, arguments);
// sorting
if (!this.sortable) {
var self = this;
this.sortable = new Sortable(this.$list.get(0), {
draggable: 'li',
onUpdate: function(e) { self.updateSort(e); }
});
}
return this;
},
updateSort: function(sortable, e) {
var sorted = [];
_.each(this.items, function(item) {
var index = item.$el.index(this.$list);
sorted[index] = item;
});
this.items = sorted;
},
});
@tamagokun
Copy link
Author

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