mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Reverting some changes in commit 6302b98
Check to avoid generation of duplicated stylesheet-tags shouldn't have been removed from Gridster. It's useful when calling multiple times `generate_stylesheet` method once Gridster is initializated. We use it at ducksboard to generate a TVmode version of the grid with bigger widgets. Refactored the way stylesheet tags are removed. When created I push them to a jQuery collection which is removed when `destroy` method is executed.
This commit is contained in:
@@ -31,12 +31,9 @@
|
|||||||
collision: {},
|
collision: {},
|
||||||
draggable: {
|
draggable: {
|
||||||
distance: 4
|
distance: 4
|
||||||
},
|
}
|
||||||
style_tag_id_prefix: 'gridster-style-tags-'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var instanceCounter = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class Gridster
|
* @class Gridster
|
||||||
* @uses Draggable
|
* @uses Draggable
|
||||||
@@ -97,10 +94,14 @@
|
|||||||
this.options.widget_base_dimensions[0];
|
this.options.widget_base_dimensions[0];
|
||||||
this.min_widget_height = (this.options.widget_margins[1] * 2) +
|
this.min_widget_height = (this.options.widget_margins[1] * 2) +
|
||||||
this.options.widget_base_dimensions[1];
|
this.options.widget_base_dimensions[1];
|
||||||
this.instanceId = instanceCounter++;
|
|
||||||
|
this.$style_tags = $([]);
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gridster.generated_stylesheets = [];
|
||||||
|
|
||||||
var fn = Gridster.prototype;
|
var fn = Gridster.prototype;
|
||||||
|
|
||||||
fn.init = function() {
|
fn.init = function() {
|
||||||
@@ -2280,6 +2281,14 @@
|
|||||||
opts.min_widget_height = (opts.widget_margins[1] * 2) +
|
opts.min_widget_height = (opts.widget_margins[1] * 2) +
|
||||||
opts.widget_base_dimensions[1];
|
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 */
|
/* generate CSS styles for cols */
|
||||||
for (i = opts.cols; i >= 0; i--) {
|
for (i = opts.cols; i >= 0; i--) {
|
||||||
styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
|
styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
|
||||||
@@ -2325,13 +2334,15 @@
|
|||||||
|
|
||||||
d.getElementsByTagName('head')[0].appendChild(tag);
|
d.getElementsByTagName('head')[0].appendChild(tag);
|
||||||
tag.setAttribute('type', 'text/css');
|
tag.setAttribute('type', 'text/css');
|
||||||
tag.setAttribute('id', this.options.style_tag_id_prefix + this.instanceId);
|
|
||||||
|
|
||||||
if (tag.styleSheet) {
|
if (tag.styleSheet) {
|
||||||
tag.styleSheet.cssText = css;
|
tag.styleSheet.cssText = css;
|
||||||
}else{
|
}else{
|
||||||
tag.appendChild(document.createTextNode(css));
|
tag.appendChild(document.createTextNode(css));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.$style_tags = this.$style_tags.add(tag);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -2342,8 +2353,8 @@
|
|||||||
* @method remove_style_tag
|
* @method remove_style_tag
|
||||||
* @return {Object} Returns the instance of the Gridster class.
|
* @return {Object} Returns the instance of the Gridster class.
|
||||||
*/
|
*/
|
||||||
fn.remove_style_tag = function() {
|
fn.remove_style_tags = function() {
|
||||||
$('#' + this.options.style_tag_id_prefix + this.instanceId).remove();
|
this.$style_tags.remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -2558,12 +2569,14 @@
|
|||||||
this.drag_api.destroy();
|
this.drag_api.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.remove_style_tag();
|
this.remove_style_tags();
|
||||||
|
|
||||||
// lastly, remove gridster element
|
// lastly, remove gridster element
|
||||||
// this will additionally cause any data associated to this element to be removed, including this
|
// this will additionally cause any data associated to this element to be removed, including this
|
||||||
// very gridster instance
|
// very gridster instance
|
||||||
this.$el.remove();
|
this.$el.remove();
|
||||||
|
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user