Skip to content

Commit afd83fe

Browse files
author
floyd_hawkes
committed
fix(gridster): fixing drag limit issues when using autogrow_cols
1 parent 754b313 commit afd83fe

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

src/jquery.gridster.js

+22-9
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@
369369
this.set_dom_grid_width();
370370
this.set_dom_grid_height();
371371

372-
this.drag_api.set_limits(this.cols * this.min_widget_width);
372+
this.drag_api.set_limits((this.cols * this.min_widget_width) + ((this.cols + 1) * this.options.widget_margins[0]));
373373

374374
return $w.fadeIn();
375375
};
@@ -1233,7 +1233,7 @@
12331233
if (prcol >= this.cols - 1 && this.options.max_cols >= this.cols + 1) {
12341234
this.add_faux_cols(1);
12351235
this.set_dom_grid_width(this.cols + 1);
1236-
this.drag_api.set_limits(this.container_width);
1236+
this.drag_api.set_limits((this.cols * this.min_widget_width) + ((this.cols + 1) * this.options.widget_margins[0]));
12371237
}
12381238

12391239
this.collision_api.set_colliders(this.faux_grid);
@@ -1324,7 +1324,7 @@
13241324
this.set_dom_grid_width();
13251325

13261326
if (this.options.autogrow_cols) {
1327-
this.drag_api.set_limits(this.cols * this.min_widget_width);
1327+
this.drag_api.set_limits((this.cols * this.min_widget_width) + ((this.cols + 1) * this.options.widget_margins[0]));
13281328
}
13291329
};
13301330

@@ -2914,21 +2914,33 @@
29142914
};
29152915

29162916
/**
2917-
*
2917+
* Generates the width of the grid columns based on the width of the window.
29182918
* @returns {number}
29192919
*/
29202920
fn.get_responsive_col_width = function() {
29212921
var cols = this.cols || this.options.max_cols;
29222922
return (this.$el.width() - ((cols + 1) * this.options.widget_margins[0])) / cols;
29232923
};
29242924

2925+
/**
2926+
* Changes the minimum width of a widget based on the width of the window and the number of cols that can
2927+
* fit in it.
2928+
* @returns {Gridster}
2929+
*/
29252930
fn.resize_responsive_layout = function() {
29262931
this.min_widget_width = this.get_responsive_col_width();
29272932
this.generate_grid_and_stylesheet();
29282933
this.update_widgets_dimensions();
2929-
this.drag_api.set_limits((this.cols * this.min_widget_width) + ((this.cols) * this.options.widget_margins[0]));
2934+
this.drag_api.set_limits((this.cols * this.min_widget_width) + ((this.cols + 1) * this.options.widget_margins[0]));
2935+
return this;
29302936
};
29312937

2938+
/**
2939+
* Switches between collapsed widgets the span the full width when the responsive_breakpoint is triggered.
2940+
* @param collapse
2941+
* @param opts
2942+
* @returns {Gridster}
2943+
*/
29322944
fn.toggle_collapsed_grid = function(collapse, opts) {
29332945
if(collapse) {
29342946
this.$widgets.css({
@@ -2939,7 +2951,7 @@
29392951

29402952
this.$el.addClass('collapsed');
29412953

2942-
if(this.options.resize.enabled && this.resize_api) {
2954+
if(this.resize_api) {
29432955
this.disable_resize();
29442956
}
29452957

@@ -2953,18 +2965,19 @@
29532965
'min-height': 'auto'
29542966
});
29552967
this.$el.removeClass('collapsed');
2956-
if(this.options.resize.enabled && this.resize_api) {
2968+
if(this.resize_api) {
29572969
this.enable_resize();
29582970
}
29592971

29602972
if(this.drag_api) {
29612973
this.enable();
29622974
}
29632975
}
2964-
}
2976+
return this;
2977+
};
29652978

29662979
/**
2967-
* It generates the neccessary styles to position the widgets.
2980+
* It generates the necessary styles to position the widgets.
29682981
*
29692982
* @method generate_stylesheet
29702983
* @param {Number} rows Number of columns.

0 commit comments

Comments
 (0)