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:
vieron
2012-10-20 01:37:41 +02:00
parent c75db76f4e
commit 55edd11ef8

View File

@ -433,12 +433,21 @@
*
* @method remove_widget
* @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.
*/
fn.remove_widget = function(el, callback) {
fn.remove_widget = function(el, silent, callback) {
var $el = el instanceof jQuery ? el : $(el);
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.$widgets = this.$widgets.not($el);
@ -449,9 +458,11 @@
$el.fadeOut($.proxy(function() {
$el.remove();
$nexts.each($.proxy(function(i, widget) {
this.move_widget_up( $(widget), wgd.size_y );
}, this));
if (!silent) {
$nexts.each($.proxy(function(i, widget) {
this.move_widget_up( $(widget), wgd.size_y );
}, this));
}
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.
*