mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
gridster: new method remove_all_widgets
Remove multiple widgets without chaining callbacks was not possible so I've added a new argument to remove_widget method named `silent` which if it's value is true, widgets below the removed will not move up. Also added the method remove_all_widgets. Fixes #63
This commit is contained in:
@@ -433,12 +433,21 @@
|
|||||||
*
|
*
|
||||||
* @method remove_widget
|
* @method remove_widget
|
||||||
* @param {HTMLElement} el The jQuery wrapped HTMLElement you want to remove.
|
* @param {HTMLElement} el The jQuery wrapped HTMLElement you want to remove.
|
||||||
|
* @param {Boolean|Function} silent If true, widgets below the removed one
|
||||||
|
* will not move up. If a Function is passed it will be used as callback.
|
||||||
|
* @param {Function} callback Function executed when the widget is removed.
|
||||||
* @return {Class} Returns the instance of the Gridster Class.
|
* @return {Class} Returns the instance of the Gridster Class.
|
||||||
*/
|
*/
|
||||||
fn.remove_widget = function(el, callback) {
|
fn.remove_widget = function(el, silent, callback) {
|
||||||
var $el = el instanceof jQuery ? el : $(el);
|
var $el = el instanceof jQuery ? el : $(el);
|
||||||
var wgd = $el.coords().grid;
|
var wgd = $el.coords().grid;
|
||||||
|
|
||||||
|
// if silent is a function assume it's a callback
|
||||||
|
if ($.isFunction(silent)) {
|
||||||
|
callback = silent;
|
||||||
|
silent = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.cells_occupied_by_placeholder = {};
|
this.cells_occupied_by_placeholder = {};
|
||||||
this.$widgets = this.$widgets.not($el);
|
this.$widgets = this.$widgets.not($el);
|
||||||
|
|
||||||
@@ -449,9 +458,11 @@
|
|||||||
$el.fadeOut($.proxy(function() {
|
$el.fadeOut($.proxy(function() {
|
||||||
$el.remove();
|
$el.remove();
|
||||||
|
|
||||||
$nexts.each($.proxy(function(i, widget) {
|
if (!silent) {
|
||||||
this.move_widget_up( $(widget), wgd.size_y );
|
$nexts.each($.proxy(function(i, widget) {
|
||||||
}, this));
|
this.move_widget_up( $(widget), wgd.size_y );
|
||||||
|
}, this));
|
||||||
|
}
|
||||||
|
|
||||||
this.set_dom_grid_height();
|
this.set_dom_grid_height();
|
||||||
|
|
||||||
@@ -462,6 +473,22 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all widgets from the grid.
|
||||||
|
*
|
||||||
|
* @method remove_all_widgets
|
||||||
|
* @param {Function} callback Function executed for each widget removed.
|
||||||
|
* @return {Class} Returns the instance of the Gridster Class.
|
||||||
|
*/
|
||||||
|
fn.remove_all_widgets = function(callback) {
|
||||||
|
this.$widgets.each($.proxy(function(i, el){
|
||||||
|
this.remove_widget(el, true, callback);
|
||||||
|
}, this));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a serialized array of the widgets in the grid.
|
* Returns a serialized array of the widgets in the grid.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user