Skip to content

Commit

Permalink
Merge pull request #26 from zeroedin-bill/master
Browse files Browse the repository at this point in the history
Improved gridster destroy func
  • Loading branch information
dustmoo committed Sep 3, 2013
2 parents 931d096 + 50e3b5a commit c306335
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/jquery.draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@
this.disable();

this.$container.off('selectstart', this.proxied_on_select_start);
this.$container.off(pointer_events.start, this.proxied_drag_handler);
this.$container.off(pointer_events.start, this.options.items, this.proxied_drag_handler);
this.$body.off(pointer_events.end, this.proxied_pointer_events_end);
this.$body.off(pointer_events.move, this.on_pointer_events_move);
$(window).unbind('resize', this.on_window_resize);
Expand Down
30 changes: 15 additions & 15 deletions src/jquery.gridster.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
draggable: {
distance: 4,
items: ".gs_w:not(.static)"
}
},
style_tag_id_prefix: 'gridster-style-tags-'
};

var instanceCounter = 0;

/**
* @class Gridster
Expand Down Expand Up @@ -99,11 +101,10 @@
this.options.widget_base_dimensions[0];
this.min_widget_height = (this.options.widget_margins[1] * 2) +
this.options.widget_base_dimensions[1];
this.instanceId = instanceCounter++;
this.init();
}

Gridster.generated_stylesheets = [];

var fn = Gridster.prototype;

fn.init = function() {
Expand All @@ -112,9 +113,6 @@
this.set_dom_grid_height();
this.$wrapper.addClass('ready');
this.draggable();

$(window).bind(
'resize', throttle($.proxy(this.recalculate_faux_grid, this), 200));
};


Expand Down Expand Up @@ -2620,14 +2618,6 @@
opts.min_widget_height = (opts.widget_margins[1] * 2) +
opts.widget_base_dimensions[1];

// don't duplicate stylesheets for the same configuration
var serialized_opts = $.param(opts);
if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) {
return false;
}

Gridster.generated_stylesheets.push(serialized_opts);

/* generate CSS styles for cols */
for (i = opts.cols; i >= 0; i--) {
styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
Expand Down Expand Up @@ -2673,6 +2663,7 @@

d.getElementsByTagName('head')[0].appendChild(tag);
tag.setAttribute('type', 'text/css');
tag.setAttribute('id', this.options.style_tag_id_prefix + this.instanceId);

if (tag.styleSheet) {
tag.styleSheet.cssText = css;
Expand Down Expand Up @@ -2892,7 +2883,6 @@
fn.destroy = function(removeDOM){
if(this.drag_api){
this.drag_api.destroy();
delete this.drag_api;
}

this.remove_style_tag();
Expand All @@ -2903,6 +2893,16 @@
if(typeof removeDOM === 'undefined' || removeDOM === true)
this.$el.remove();
else {
//Clean up leftovers that may have been added to the wrapper or widget elements
// this will enable gridster to be reinitialized cleanly.
this.$el.removeData('drag');

this.$wrapper.removeClass("ready");

this.$widgets.each(function(index, element) {
$(element).removeData('coords').removeClass('player-revert').removeClass('gs_w').css('position', '');
});

this.$el.removeData('gridster');
}
};
Expand Down

0 comments on commit c306335

Please sign in to comment.