Nestable icon indicating copy to clipboard operation
Nestable copied to clipboard

Implemented a destroy method

Open jkempff opened this issue 12 years ago • 3 comments

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.

jkempff avatar Oct 31 '13 14:10 jkempff

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.

lukasoppermann avatar Dec 07 '13 13:12 lukasoppermann

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();

CHeil402 avatar Mar 06 '14 00:03 CHeil402

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');
        }

zepernick avatar Jan 19 '17 14:01 zepernick