Skip to content

Commit 4783e6e

Browse files
author
David Morse
committed
fix a NAN error that could occur if using center_widget if the grid was in responsive mode.
Error check the shift cols, to ensure they can't move left past col 1 make a change from 100% to 100VW for better browser support of min-width
1 parent ec430f8 commit 4783e6e

7 files changed

+66
-51
lines changed

dist/jquery.gridster.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! gridster.js - v0.6.5 - 2015-04-06
2-
* http://gridster.net/
3-
* Copyright (c) 2015 decksterteam; Licensed */
4-
1+
/*! gridster.js - v0.6.5 - 2015-04-06
2+
* http://gridster.net/
3+
* Copyright (c) 2015 decksterteam; Licensed */
4+
55
.gridster {
66
position:relative;
77
}

dist/jquery.gridster.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! gridster.js - v0.6.5 - 2015-04-06
2-
* http://gridster.net/
3-
* Copyright (c) 2015 decksterteam; Licensed */
4-
1+
/*! gridster.js - v0.6.5 - 2015-04-06
2+
* http://gridster.net/
3+
* Copyright (c) 2015 decksterteam; Licensed */
4+
55
;(function(root, factory) {
66

77
if (typeof define === 'function' && define.amd) {
@@ -119,7 +119,7 @@
119119
return Coords;
120120

121121
}));
122-
122+
123123
;(function(root, factory) {
124124

125125
if (typeof define === 'function' && define.amd) {
@@ -354,7 +354,7 @@
354354
return Collision;
355355

356356
}));
357-
357+
358358
;(function(window, undefined) {
359359

360360
/* Delay, debounce and throttle functions taken from underscore.js
@@ -427,7 +427,7 @@
427427
};
428428

429429
})(window);
430-
430+
431431
;(function(root, factory) {
432432

433433
if (typeof define === 'function' && define.amd) {
@@ -852,7 +852,7 @@
852852
return Draggable;
853853

854854
}));
855-
855+
856856
;(function(root, factory) {
857857

858858
if (typeof define === 'function' && define.amd) {
@@ -1493,7 +1493,12 @@
14931493
*/
14941494
fn.center_widgets = debounce(function () {
14951495
var wrapper_width = this.$wrapper.width();
1496-
var col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
1496+
var col_size;
1497+
if (this.is_responsive()) {
1498+
col_size = this.get_responsive_col_width();
1499+
} else {
1500+
col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
1501+
}
14971502
var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2;
14981503

14991504
this.options.min_cols = col_count;
@@ -1554,11 +1559,11 @@
15541559
widgets_coords.each($.proxy(function(i, widget) {
15551560
var $widget = $(widget.el);
15561561
var wgd = $widget.coords().grid;
1557-
var col = parseInt($widget.attr("data-col"));
1562+
var col = parseInt($widget.attr('data-col'));
15581563

15591564
var new_grid_data = {
1560-
col: col + col_dif,
1561-
row: wgd.row,
1565+
col: Math.max(Math.round(col + col_dif), 1),
1566+
row: wgd.row,
15621567
size_x: wgd.size_x,
15631568
size_y: wgd.size_y
15641569
};
@@ -3885,17 +3890,16 @@
38853890
cols = this.get_highest_occupied_cell().col;
38863891
}
38873892

3888-
var max_cols = (this.options.autogrow_cols ? this.options.max_cols :
3889-
this.cols);
3893+
var max_cols = (this.options.autogrow_cols ? this.options.max_cols : this.cols);
38903894

38913895
cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
38923896
this.container_width = ((cols + 1) * this.options.widget_margins[0]) + (cols * this.min_widget_width);
3893-
this.$el.css('width', this.container_width);
3894-
38953897
if(this.is_responsive()) {
3896-
this.$el.css({'min-width': '100%', 'max-width': '100%'});
3897-
return this;
3898+
this.$el.css({'min-width': '100vw', 'max-width': '100vw'});
3899+
return this; //if we are responsive exit before setting the width of $el
38983900
}
3901+
this.$el.css('width', this.container_width);
3902+
38993903
return this;
39003904
};
39013905

dist/jquery.gridster.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.gridster.min.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jquery.gridster.with-extras.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! gridster.js - v0.6.5 - 2015-04-06
2-
* http://gridster.net/
3-
* Copyright (c) 2015 decksterteam; Licensed */
4-
1+
/*! gridster.js - v0.6.5 - 2015-04-06
2+
* http://gridster.net/
3+
* Copyright (c) 2015 decksterteam; Licensed */
4+
55
;(function(root, factory) {
66

77
if (typeof define === 'function' && define.amd) {
@@ -119,7 +119,7 @@
119119
return Coords;
120120

121121
}));
122-
122+
123123
;(function(root, factory) {
124124

125125
if (typeof define === 'function' && define.amd) {
@@ -354,7 +354,7 @@
354354
return Collision;
355355

356356
}));
357-
357+
358358
;(function(window, undefined) {
359359

360360
/* Delay, debounce and throttle functions taken from underscore.js
@@ -427,7 +427,7 @@
427427
};
428428

429429
})(window);
430-
430+
431431
;(function(root, factory) {
432432

433433
if (typeof define === 'function' && define.amd) {
@@ -852,7 +852,7 @@
852852
return Draggable;
853853

854854
}));
855-
855+
856856
;(function(root, factory) {
857857

858858
if (typeof define === 'function' && define.amd) {
@@ -1493,7 +1493,12 @@
14931493
*/
14941494
fn.center_widgets = debounce(function () {
14951495
var wrapper_width = this.$wrapper.width();
1496-
var col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
1496+
var col_size;
1497+
if (this.is_responsive()) {
1498+
col_size = this.get_responsive_col_width();
1499+
} else {
1500+
col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
1501+
}
14971502
var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2;
14981503

14991504
this.options.min_cols = col_count;
@@ -1554,11 +1559,11 @@
15541559
widgets_coords.each($.proxy(function(i, widget) {
15551560
var $widget = $(widget.el);
15561561
var wgd = $widget.coords().grid;
1557-
var col = parseInt($widget.attr("data-col"));
1562+
var col = parseInt($widget.attr('data-col'));
15581563

15591564
var new_grid_data = {
1560-
col: col + col_dif,
1561-
row: wgd.row,
1565+
col: Math.max(Math.round(col + col_dif), 1),
1566+
row: wgd.row,
15621567
size_x: wgd.size_x,
15631568
size_y: wgd.size_y
15641569
};
@@ -3885,17 +3890,16 @@
38853890
cols = this.get_highest_occupied_cell().col;
38863891
}
38873892

3888-
var max_cols = (this.options.autogrow_cols ? this.options.max_cols :
3889-
this.cols);
3893+
var max_cols = (this.options.autogrow_cols ? this.options.max_cols : this.cols);
38903894

38913895
cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
38923896
this.container_width = ((cols + 1) * this.options.widget_margins[0]) + (cols * this.min_widget_width);
3893-
this.$el.css('width', this.container_width);
3894-
38953897
if(this.is_responsive()) {
3896-
this.$el.css({'min-width': '100%', 'max-width': '100%'});
3897-
return this;
3898+
this.$el.css({'min-width': '100vw', 'max-width': '100vw'});
3899+
return this; //if we are responsive exit before setting the width of $el
38983900
}
3901+
this.$el.css('width', this.container_width);
3902+
38993903
return this;
39003904
};
39013905

@@ -4379,7 +4383,7 @@
43794383
return Gridster;
43804384

43814385
}));
4382-
4386+
43834387
;(function(root, factory) {
43844388

43854389
if (typeof define === 'function' && define.amd) {

dist/jquery.gridster.with-extras.min.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jquery.gridster.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,12 @@
646646
*/
647647
fn.center_widgets = debounce(function () {
648648
var wrapper_width = this.$wrapper.width();
649-
var col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
649+
var col_size;
650+
if (this.is_responsive()) {
651+
col_size = this.get_responsive_col_width();
652+
} else {
653+
col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
654+
}
650655
var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2;
651656

652657
this.options.min_cols = col_count;
@@ -707,11 +712,11 @@
707712
widgets_coords.each($.proxy(function(i, widget) {
708713
var $widget = $(widget.el);
709714
var wgd = $widget.coords().grid;
710-
var col = parseInt($widget.attr("data-col"));
715+
var col = parseInt($widget.attr('data-col'));
711716

712717
var new_grid_data = {
713-
col: col + col_dif,
714-
row: wgd.row,
718+
col: Math.max(Math.round(col + col_dif), 1),
719+
row: wgd.row,
715720
size_x: wgd.size_x,
716721
size_y: wgd.size_y
717722
};
@@ -3043,7 +3048,7 @@
30433048
cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
30443049
this.container_width = ((cols + 1) * this.options.widget_margins[0]) + (cols * this.min_widget_width);
30453050
if(this.is_responsive()) {
3046-
this.$el.css({'min-width': '100%', 'max-width': '100%'});
3051+
this.$el.css({'min-width': '100vw', 'max-width': '100vw'});
30473052
return this; //if we are responsive exit before setting the width of $el
30483053
}
30493054
this.$el.css('width', this.container_width);

0 commit comments

Comments
 (0)