ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.03k stars 1.2k forks source link

Enhancement: clean destroy #218

Open rochejul opened 11 years ago

rochejul commented 11 years ago

Hi,

I have a case where I need to reinstanciate the gridster (on window resize). But I cannot use the destroy method, because it delete the DOM elements.

And we have to clean properly on destroy, because the reinstanciation can inject some problems (drag / drop not managed ...).

If you want, I produce a function to resolve that:

fn.destroy = function(removeDOM) { $(window).unbind('.gridster');

if (this.drag_api) {
    this.drag_api.destroy();
    this.$el.removeData('drag');
}

this.remove_style_tags();
this.removeData('gridster');

if(removeDOM === undefined || removeDOM === true) {
    this.$el.remove();
}

return this;

};

Cheers

Julien Roche

egorgrushin commented 9 years ago

SUPER! IT Resolved my problems! Very thx to you!

KamilPesek commented 7 years ago

This works for me: V0.7.0

 var gridster = $(".gridster ul").gridster({
                ... options
 });

gridster.removeData('drag');
gridster.data('gridster').destroy();