Fix for not removing stylesheets on destroy

This commit is contained in:
Ryan Fink
2013-04-09 12:27:04 +00:00
parent b58f1454a5
commit 6302b988d1
6 changed files with 66 additions and 45 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
/*! gridster.js - v0.1.0 - 2013-02-15
/*! gridster.js - v0.1.0 - 2013-04-09
* http://gridster.net/
* Copyright (c) 2013 ducksboard; Licensed MIT */
+21 -14
View File
@@ -1,4 +1,4 @@
/*! gridster.js - v0.1.0 - 2013-02-15
/*! gridster.js - v0.1.0 - 2013-04-09
* http://gridster.net/
* Copyright (c) 2013 ducksboard; Licensed MIT */
@@ -274,7 +274,7 @@
if (self.options.on_overlap_stop || self.options.on_overlap_start) {
this.manage_colliders_start_stop(colliders_coords,
self.options.on_overlap_stop, self.options.on_overlap_start);
self.options.on_overlap_start, self.options.on_overlap_stop);
}
this.last_colliders_coords = colliders_coords;
@@ -737,9 +737,11 @@
collision: {},
draggable: {
distance: 4
}
},
style_tag_id_prefix: 'gridster-style-tags-'
};
var instanceCounter = 0;
/**
* @class Gridster
@@ -799,11 +801,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() {
@@ -2977,14 +2978,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:' +
@@ -3030,6 +3023,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;
@@ -3040,6 +3034,17 @@
};
/**
* Remove the style tag with the associated id from the head of the document
*
* @method remove_style_tag
* @return {Object} Returns the instance of the Gridster class.
*/
fn.remove_style_tag = function() {
$('#' + this.options.style_tag_id_prefix + this.instanceId).remove();
};
/**
* Generates a faux grid to collide with it when a widget is dragged and
* detect row or column that we want to go.
@@ -3241,7 +3246,9 @@
if(this.drag_api){
this.drag_api.destroy();
}
this.remove_style_tag();
// lastly, remove gridster element
// this will additionally cause any data associated to this element to be removed, including this
// very gridster instance
+2 -2
View File
File diff suppressed because one or more lines are too long
+21 -14
View File
@@ -1,4 +1,4 @@
/*! gridster.js - v0.1.0 - 2013-02-15
/*! gridster.js - v0.1.0 - 2013-04-09
* http://gridster.net/
* Copyright (c) 2013 ducksboard; Licensed MIT */
@@ -274,7 +274,7 @@
if (self.options.on_overlap_stop || self.options.on_overlap_start) {
this.manage_colliders_start_stop(colliders_coords,
self.options.on_overlap_stop, self.options.on_overlap_start);
self.options.on_overlap_start, self.options.on_overlap_stop);
}
this.last_colliders_coords = colliders_coords;
@@ -737,9 +737,11 @@
collision: {},
draggable: {
distance: 4
}
},
style_tag_id_prefix: 'gridster-style-tags-'
};
var instanceCounter = 0;
/**
* @class Gridster
@@ -799,11 +801,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() {
@@ -2977,14 +2978,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:' +
@@ -3030,6 +3023,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;
@@ -3040,6 +3034,17 @@
};
/**
* Remove the style tag with the associated id from the head of the document
*
* @method remove_style_tag
* @return {Object} Returns the instance of the Gridster class.
*/
fn.remove_style_tag = function() {
$('#' + this.options.style_tag_id_prefix + this.instanceId).remove();
};
/**
* Generates a faux grid to collide with it when a widget is dragged and
* detect row or column that we want to go.
@@ -3241,7 +3246,9 @@
if(this.drag_api){
this.drag_api.destroy();
}
this.remove_style_tag();
// lastly, remove gridster element
// this will additionally cause any data associated to this element to be removed, including this
// very gridster instance
File diff suppressed because one or more lines are too long
+19 -12
View File
@@ -30,9 +30,11 @@
collision: {},
draggable: {
distance: 4
}
},
style_tag_id_prefix: 'gridster-style-tags-'
};
var instanceCounter = 0;
/**
* @class Gridster
@@ -92,11 +94,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() {
@@ -2270,14 +2271,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:' +
@@ -2323,6 +2316,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;
@@ -2333,6 +2327,17 @@
};
/**
* Remove the style tag with the associated id from the head of the document
*
* @method remove_style_tag
* @return {Object} Returns the instance of the Gridster class.
*/
fn.remove_style_tag = function() {
$('#' + this.options.style_tag_id_prefix + this.instanceId).remove();
};
/**
* Generates a faux grid to collide with it when a widget is dragged and
* detect row or column that we want to go.
@@ -2534,7 +2539,9 @@
if(this.drag_api){
this.drag_api.destroy();
}
this.remove_style_tag();
// lastly, remove gridster element
// this will additionally cause any data associated to this element to be removed, including this
// very gridster instance