From 7fe912fa35bb2b902f80ec887f10fe12ad6b711a Mon Sep 17 00:00:00 2001 From: Hannes Rosenbauer Date: Tue, 1 Apr 2014 18:30:53 +0200 Subject: [PATCH 1/4] add resize_widget_dimension() resize widgets after initialization --- src/jquery.gridster.js | 64 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index 95c4b6d00..287a34f84 100644 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -386,6 +386,46 @@ }; + /** + * Change the dimensions of widgets. + * + * @method resize_widget_dimensions + * @param {Object} [options] An Object with all options you want to + * overwrite: + * @param {Array} [options.widget_margins] Margin between widgets. + * The first index for the horizontal margin (left, right) and + * the second for the vertical margin (top, bottom). + * @param {Array} [options.widget_base_dimensions] Base widget dimensions + * in pixels. The first index for the width and the second for the + * height. + * @return {Class} Returns the instance of the Gridster Class. + */ + fn.resize_widget_dimensions = function(options) { + if (options.widget_margins) { + this.options.widget_margins = options.widget_margins; + } + + if (options.widget_base_dimensions) { + this.options.widget_base_dimensions = options.widget_base_dimensions; + } + + this.min_widget_width = (this.options.widget_margins[0] * 2) + this.options.widget_base_dimensions[0]; + this.min_widget_height = (this.options.widget_margins[1] * 2) + this.options.widget_base_dimensions[1]; + + var serializedGrid = this.serialize(); + this.$widgets.each($.proxy(function(i, widget) { + var $widget = $(widget); + this.resize_widget($widget); + }, this)); + + this.generate_grid_and_stylesheet(); + this.get_widgets_from_DOM(); + this.set_dom_grid_height(); + + return this; + }; + + /** * Mutate widget dimensions and position in the grid map. * @@ -2807,21 +2847,23 @@ * @return {Object} Returns the instance of the Gridster class. */ fn.add_style_tag = function(css) { - var d = document; - var tag = d.createElement('style'); + var d = document; + var tag = d.createElement('style'); - d.getElementsByTagName('head')[0].appendChild(tag); - tag.setAttribute('type', 'text/css'); + d.getElementsByTagName('head')[0].appendChild(tag); + tag.setAttribute('type', 'text/css'); - if (tag.styleSheet) { - tag.styleSheet.cssText = css; - }else{ - tag.appendChild(document.createTextNode(css)); - } + if (tag.styleSheet) { + tag.styleSheet.cssText = css; + } + else{ + tag.appendChild(document.createTextNode(css)); + } - this.$style_tags = this.$style_tags.add(tag); + this.remove_style_tags(); + this.$style_tags = this.$style_tags.add(tag); - return this; + return this; }; From 6554499a9349e1b189c007dcbf88b20412dd9153 Mon Sep 17 00:00:00 2001 From: Hannes Rosenbauer Date: Tue, 8 Apr 2014 15:08:50 +0200 Subject: [PATCH 2/4] fix min-width and min-height after resize remove min-width and min-height after stopping resize --- src/jquery.gridster.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index 287a34f84..d2a75efa7 100644 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -1192,7 +1192,9 @@ .removeClass('resizing') .css({ 'width': '', - 'height': '' + 'height': '', + 'min-width': '', + 'min-height': '' }); delay($.proxy(function() { From c0bc1b9e5d70d706346c6816bdcfe1ae76c63b82 Mon Sep 17 00:00:00 2001 From: Hannes Rosenbauer Date: Tue, 1 Apr 2014 18:30:53 +0200 Subject: [PATCH 3/4] add resize_widget_dimension() resize widgets after initialization Conflicts: src/jquery.gridster.js --- src/jquery.gridster.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index c9ddcb3b4..bb5c95b81 100755 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -493,6 +493,46 @@ }; + /** + * Change the dimensions of widgets. + * + * @method resize_widget_dimensions + * @param {Object} [options] An Object with all options you want to + * overwrite: + * @param {Array} [options.widget_margins] Margin between widgets. + * The first index for the horizontal margin (left, right) and + * the second for the vertical margin (top, bottom). + * @param {Array} [options.widget_base_dimensions] Base widget dimensions + * in pixels. The first index for the width and the second for the + * height. + * @return {Class} Returns the instance of the Gridster Class. + */ + fn.resize_widget_dimensions = function(options) { + if (options.widget_margins) { + this.options.widget_margins = options.widget_margins; + } + + if (options.widget_base_dimensions) { + this.options.widget_base_dimensions = options.widget_base_dimensions; + } + + this.min_widget_width = (this.options.widget_margins[0] * 2) + this.options.widget_base_dimensions[0]; + this.min_widget_height = (this.options.widget_margins[1] * 2) + this.options.widget_base_dimensions[1]; + + var serializedGrid = this.serialize(); + this.$widgets.each($.proxy(function(i, widget) { + var $widget = $(widget); + this.resize_widget($widget); + }, this)); + + this.generate_grid_and_stylesheet(); + this.get_widgets_from_DOM(); + this.set_dom_grid_height(); + + return this; + }; + + /** * Mutate widget dimensions and position in the grid map. * From c9ecfdb1c3e35a9d72a4e5336cca92562a8435e8 Mon Sep 17 00:00:00 2001 From: Hannes Rosenbauer Date: Tue, 8 Apr 2014 15:08:50 +0200 Subject: [PATCH 4/4] fix min-width and min-height after resize remove min-width and min-height after stopping resize --- src/jquery.gridster.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index bb5c95b81..0b732dc2c 100755 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -1324,7 +1324,9 @@ .removeClass('resizing') .css({ 'width': '', - 'height': '' + 'height': '', + 'min-width': '', + 'min-height': '' }); delay($.proxy(function() {