Nestable
Nestable copied to clipboard
Implemented a destroy method
I needed to be able to activate and deactivate sorting for an ajax driven user action.
So I implemented a destroy action that removes all events and sets el.data('nestable', null);, so that reactivating works proper.
Nice idea, but there is an error.
If you add a button for e.g. to toggle / destroy the draggable class, the collapse buttons are added every time.
The easiest way to fix this would be to remove the buttons every time you disable the draggable, since the functionality is removed anyway.
You can implement this by adding the following to the begining of your destroy function (line 137)
$(this.options.expandBtnHTML).remove();
$(this.options.collapseBtnHTML).remove();
I got this working with some fixes. Add this to the init() function
var destroyNestable = function()
{
list.el.find("button[data-action]").remove();
if (hasTouch) {
list.el[0].removeEventListener('touchstart', onStartEvent, false);
window.removeEventListener('touchmove', onMoveEvent, false);
window.removeEventListener('touchend', onEndEvent, false);
window.removeEventListener('touchcancel', onEndEvent, false);
}
list.el.off('mousedown', onStartEvent);
list.w.off('mousemove', onMoveEvent);
list.w.off('mouseup', onEndEvent);
list.el.off('click');
list.el.unbind('destroy-nestable');
list.el.data("nestable", null);
};
list.el.bind('destroy-nestable', destroyNestable);
Then add this to the prototype
destroy: function () {
this.el.trigger('destroy-nestable');
}