Skip to content

Commit

Permalink
fix a NAN error that could occur if using center_widget if the grid w…
Browse files Browse the repository at this point in the history
…as 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
  • Loading branch information
David Morse committed Apr 7, 2015
1 parent ec430f8 commit 4783e6e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 51 deletions.
8 changes: 4 additions & 4 deletions dist/jquery.gridster.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! gridster.js - v0.6.5 - 2015-04-06
* http://gridster.net/
* Copyright (c) 2015 decksterteam; Licensed */

/*! gridster.js - v0.6.5 - 2015-04-06
* http://gridster.net/
* Copyright (c) 2015 decksterteam; Licensed */

.gridster {
position:relative;
}
Expand Down
40 changes: 22 additions & 18 deletions dist/jquery.gridster.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! gridster.js - v0.6.5 - 2015-04-06
* http://gridster.net/
* Copyright (c) 2015 decksterteam; Licensed */

/*! gridster.js - v0.6.5 - 2015-04-06
* http://gridster.net/
* Copyright (c) 2015 decksterteam; Licensed */

;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -119,7 +119,7 @@
return Coords;

}));


;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -354,7 +354,7 @@
return Collision;

}));


;(function(window, undefined) {

/* Delay, debounce and throttle functions taken from underscore.js
Expand Down Expand Up @@ -427,7 +427,7 @@
};

})(window);


;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -852,7 +852,7 @@
return Draggable;

}));


;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -1493,7 +1493,12 @@
*/
fn.center_widgets = debounce(function () {
var wrapper_width = this.$wrapper.width();
var col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
var col_size;
if (this.is_responsive()) {
col_size = this.get_responsive_col_width();
} else {
col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
}
var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2;

this.options.min_cols = col_count;
Expand Down Expand Up @@ -1554,11 +1559,11 @@
widgets_coords.each($.proxy(function(i, widget) {
var $widget = $(widget.el);
var wgd = $widget.coords().grid;
var col = parseInt($widget.attr("data-col"));
var col = parseInt($widget.attr('data-col'));

var new_grid_data = {
col: col + col_dif,
row: wgd.row,
col: Math.max(Math.round(col + col_dif), 1),
row: wgd.row,
size_x: wgd.size_x,
size_y: wgd.size_y
};
Expand Down Expand Up @@ -3885,17 +3890,16 @@
cols = this.get_highest_occupied_cell().col;
}

var max_cols = (this.options.autogrow_cols ? this.options.max_cols :
this.cols);
var max_cols = (this.options.autogrow_cols ? this.options.max_cols : this.cols);

cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
this.container_width = ((cols + 1) * this.options.widget_margins[0]) + (cols * this.min_widget_width);
this.$el.css('width', this.container_width);

if(this.is_responsive()) {
this.$el.css({'min-width': '100%', 'max-width': '100%'});
return this;
this.$el.css({'min-width': '100vw', 'max-width': '100vw'});
return this; //if we are responsive exit before setting the width of $el
}
this.$el.css('width', this.container_width);

return this;
};

Expand Down
2 changes: 1 addition & 1 deletion dist/jquery.gridster.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions dist/jquery.gridster.min.js

Large diffs are not rendered by default.

42 changes: 23 additions & 19 deletions dist/jquery.gridster.with-extras.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! gridster.js - v0.6.5 - 2015-04-06
* http://gridster.net/
* Copyright (c) 2015 decksterteam; Licensed */

/*! gridster.js - v0.6.5 - 2015-04-06
* http://gridster.net/
* Copyright (c) 2015 decksterteam; Licensed */

;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -119,7 +119,7 @@
return Coords;

}));


;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -354,7 +354,7 @@
return Collision;

}));


;(function(window, undefined) {

/* Delay, debounce and throttle functions taken from underscore.js
Expand Down Expand Up @@ -427,7 +427,7 @@
};

})(window);


;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -852,7 +852,7 @@
return Draggable;

}));


;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down Expand Up @@ -1493,7 +1493,12 @@
*/
fn.center_widgets = debounce(function () {
var wrapper_width = this.$wrapper.width();
var col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
var col_size;
if (this.is_responsive()) {
col_size = this.get_responsive_col_width();
} else {
col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
}
var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2;

this.options.min_cols = col_count;
Expand Down Expand Up @@ -1554,11 +1559,11 @@
widgets_coords.each($.proxy(function(i, widget) {
var $widget = $(widget.el);
var wgd = $widget.coords().grid;
var col = parseInt($widget.attr("data-col"));
var col = parseInt($widget.attr('data-col'));

var new_grid_data = {
col: col + col_dif,
row: wgd.row,
col: Math.max(Math.round(col + col_dif), 1),
row: wgd.row,
size_x: wgd.size_x,
size_y: wgd.size_y
};
Expand Down Expand Up @@ -3885,17 +3890,16 @@
cols = this.get_highest_occupied_cell().col;
}

var max_cols = (this.options.autogrow_cols ? this.options.max_cols :
this.cols);
var max_cols = (this.options.autogrow_cols ? this.options.max_cols : this.cols);

cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
this.container_width = ((cols + 1) * this.options.widget_margins[0]) + (cols * this.min_widget_width);
this.$el.css('width', this.container_width);

if(this.is_responsive()) {
this.$el.css({'min-width': '100%', 'max-width': '100%'});
return this;
this.$el.css({'min-width': '100vw', 'max-width': '100vw'});
return this; //if we are responsive exit before setting the width of $el
}
this.$el.css('width', this.container_width);

return this;
};

Expand Down Expand Up @@ -4379,7 +4383,7 @@
return Gridster;

}));


;(function(root, factory) {

if (typeof define === 'function' && define.amd) {
Expand Down
5 changes: 3 additions & 2 deletions dist/jquery.gridster.with-extras.min.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/jquery.gridster.js
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,12 @@
*/
fn.center_widgets = debounce(function () {
var wrapper_width = this.$wrapper.width();
var col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
var col_size;
if (this.is_responsive()) {
col_size = this.get_responsive_col_width();
} else {
col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
}
var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2;

this.options.min_cols = col_count;
Expand Down Expand Up @@ -707,11 +712,11 @@
widgets_coords.each($.proxy(function(i, widget) {
var $widget = $(widget.el);
var wgd = $widget.coords().grid;
var col = parseInt($widget.attr("data-col"));
var col = parseInt($widget.attr('data-col'));

var new_grid_data = {
col: col + col_dif,
row: wgd.row,
col: Math.max(Math.round(col + col_dif), 1),
row: wgd.row,
size_x: wgd.size_x,
size_y: wgd.size_y
};
Expand Down Expand Up @@ -3043,7 +3048,7 @@
cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
this.container_width = ((cols + 1) * this.options.widget_margins[0]) + (cols * this.min_widget_width);
if(this.is_responsive()) {
this.$el.css({'min-width': '100%', 'max-width': '100%'});
this.$el.css({'min-width': '100vw', 'max-width': '100vw'});
return this; //if we are responsive exit before setting the width of $el
}
this.$el.css('width', this.container_width);
Expand Down

0 comments on commit 4783e6e

Please sign in to comment.