Last active
August 29, 2015 14:03
-
-
Save tamagokun/95e76ee50f59a97696ce to your computer and use it in GitHub Desktop.
bbf-sortable-list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses https://github.com/RubaXa/Sortable