diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index 657b083a90..5e7c2dd86e 100644 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -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. *