Skip to content

Commit ec430f8

Browse files
author
David Morse
committed
2 parents 3ec0c6f + d5bf56c commit ec430f8

12 files changed

+209
-153
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<a name="v0.6.5"></a>
2+
### v0.6.5 (2015-04-06)
3+
4+
5+
#### Bug Fixes
6+
7+
* **gridster:** fixed bugs in centering_widgets (widgets were getting smushed when being resized ([86053f8b](http://github.com/DecksterTeam/gridster.js/commit/86053f8be3d73a9db3d7eabc595324123dbcff13))
8+
19
<a name="v0.6.4"></a>
210
### v0.6.4 (2015-03-19)
311

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ module.exports = function(grunt) {
133133

134134
bump: {
135135
options: {
136-
files: ['package.json'],
136+
files: ['package.json', 'bower.json'],
137137
updateConfigs: ['pkg'],
138138
commit: true,
139139
commitMessage: 'Release v%VERSION%',
140-
commitFiles: ['package.json', 'CHANGELOG.md', 'dist/'], // '-a' for all files
140+
commitFiles: ['package.json', 'bower.json', 'CHANGELOG.md', 'dist/'], // '-a' for all files
141141
createTag: true,
142142
tagName: 'v%VERSION%',
143143
tagMessage: 'Version %VERSION%',

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gridster",
33
"homepage": "https://github.com/DecksterTeam/gridster.js",
4-
"version": "0.6.3",
4+
"version": "0.6.5",
55
"dependencies": {
66
"jquery": "~1.11.2"
77
},

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.4 - 2015-04-04
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: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
/*! gridster.js - v0.6.4 - 2015-04-04
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) {
@@ -845,14 +845,14 @@
845845
};
846846

847847
//jQuery adapter
848-
$.fn.drag = function ( options ) {
848+
$.fn.gridDraggable = function ( options ) {
849849
return new Draggable(this, options);
850850
};
851851

852852
return Draggable;
853853

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

858858
if (typeof define === 'function' && define.amd) {
@@ -1106,6 +1106,12 @@
11061106
this.draggable();
11071107
this.options.resize.enabled && this.resizable();
11081108

1109+
if (this.options.center_widgets) {
1110+
setTimeout($.proxy(function () {
1111+
this.center_widgets();
1112+
}, this), 0);
1113+
}
1114+
11091115
$(window).bind('resize.gridster', throttle(
11101116
$.proxy(this.recalculate_faux_grid, this), 200));
11111117
};
@@ -1222,6 +1228,12 @@
12221228

12231229
this.drag_api.set_limits((this.cols * this.min_widget_width) + ((this.cols + 1) * this.options.widget_margins[0]));
12241230

1231+
if (this.options.center_widgets) {
1232+
setTimeout($.proxy(function () {
1233+
this.center_widgets();
1234+
}, this), 0);
1235+
}
1236+
12251237
return $w.fadeIn({complete: function () { if(callback) callback.call(this); }});
12261238
};
12271239

@@ -1297,23 +1309,32 @@
12971309
* @param {Number} size_x The number of columns that will occupy the widget.
12981310
* By default <code>size_x</code> is limited to the space available from
12991311
* the column where the widget begins, until the last column to the right.
1312+
* @param {Boolean} [reposition] Set to false to not move the widget to
1313+
* the left if there is insufficient space on the right.
13001314
* @param {Number} size_y The number of rows that will occupy the widget.
13011315
* @param {Function} [callback] Function executed when the widget is removed.
13021316
* @return {HTMLElement} Returns $widget.
13031317
*/
1304-
fn.resize_widget = function($widget, size_x, size_y, callback) {
1318+
fn.resize_widget = function($widget, size_x, size_y, reposition, callback) {
13051319
var wgd = $widget.coords().grid;
13061320
var col = wgd.col;
13071321
var max_cols = this.options.max_cols;
1322+
reposition !== false && (reposition = true);
13081323
var old_size_y = wgd.size_y;
13091324
var old_col = wgd.col;
13101325
var new_col = old_col;
13111326

13121327
size_x || (size_x = wgd.size_x);
13131328
size_y || (size_y = wgd.size_y);
13141329

1315-
if (max_cols !== Infinity) {
1316-
size_x = Math.min(size_x, max_cols - col + 1);
1330+
//if (max_cols !== Infinity) {
1331+
// size_x = Math.min(size_x, max_cols - col + 1);
1332+
//}
1333+
1334+
if (reposition && old_col + size_x - 1 > this.cols) {
1335+
var diff = old_col + (size_x - 1) - this.cols;
1336+
var c = old_col - diff;
1337+
new_col = Math.max(1, c);
13171338
}
13181339

13191340
if (size_y > old_size_y) {
@@ -1352,10 +1373,11 @@
13521373
* representing the widget.
13531374
* @param {Number} size_x The number of cols that will occupy the widget.
13541375
* @param {Number} size_y The number of rows that will occupy the widget.
1376+
* @param {Number} col The column to resize the widget from.
13551377
* @param {Function} [callback] Function executed when the widget is expanded.
13561378
* @return {HTMLElement} Returns $widget.
13571379
*/
1358-
fn.expand_widget = function($widget, size_x, size_y, callback) {
1380+
fn.expand_widget = function($widget, size_x, size_y, col, callback) {
13591381
var wgd = $widget.coords().grid;
13601382
var max_size_x = Math.floor(($(window).width() - this.options.widget_margins[0] * 2) / this.min_widget_width);
13611383
size_x = size_x || Math.min(max_size_x, this.cols);
@@ -1365,7 +1387,7 @@
13651387
$widget.attr('pre_expand_col', wgd.col);
13661388
$widget.attr('pre_expand_sizex', wgd.size_x);
13671389
$widget.attr('pre_expand_sizey', wgd.size_y);
1368-
var new_col = 1;
1390+
var new_col = col || 1;
13691391

13701392
if (size_y > old_size_y) {
13711393
this.add_faux_rows(Math.max(size_y - old_size_y, 0));
@@ -1470,15 +1492,16 @@
14701492
* @method center_widgets
14711493
*/
14721494
fn.center_widgets = debounce(function () {
1473-
var window_width = $(window).width();
1495+
var wrapper_width = this.$wrapper.width();
14741496
var col_size = this.options.widget_base_dimensions[0] + (2 * this.options.widget_margins[0]);
1475-
var col_count = Math.floor(Math.max(Math.floor(window_width / col_size), this.min_col_count) / 2) * 2;
1497+
var col_count = Math.floor(Math.max(Math.floor(wrapper_width / col_size), this.min_col_count) / 2) * 2;
14761498

14771499
this.options.min_cols = col_count;
14781500
this.options.max_cols = col_count;
14791501
this.options.extra_cols = 0;
14801502
this.options.max_size_x = col_count;
14811503
this.set_dom_grid_width(col_count);
1504+
this.cols = col_count;
14821505

14831506
var col_dif = (col_count - this.prev_col_count) / 2;
14841507

@@ -1515,28 +1538,30 @@
15151538

15161539

15171540
fn.get_min_col = function () {
1518-
var min_col = this.min_col_count;
1519-
this.$widgets.each($.proxy(function(i, widget) {
1520-
var $widget = $(widget);
1521-
var value = parseInt($widget.attr("data-col"));
1522-
min_col = Math.min(min_col, value);
1523-
}, this));
1524-
return min_col;
1541+
return Math.min.apply(Math, this.$widgets.map($.proxy(function (key, widget) {
1542+
return this.get_cells_occupied($(widget).coords().grid).cols;
1543+
}, this)).get());
15251544
};
15261545

15271546

15281547
fn.shift_cols = function (col_dif) {
1529-
this.$widgets.each($.proxy(function(i, widget) {
1530-
var $widget = $(widget);
1548+
var widgets_coords = this.$widgets.map($.proxy(function(i, widget) {
1549+
var $w = $(widget);
1550+
return this.dom_to_coords($w);
1551+
}, this));
1552+
widgets_coords = Gridster.sort_by_row_and_col_asc(widgets_coords);
1553+
1554+
widgets_coords.each($.proxy(function(i, widget) {
1555+
var $widget = $(widget.el);
15311556
var wgd = $widget.coords().grid;
1532-
var value = parseInt($widget.attr("data-col"));
1557+
var col = parseInt($widget.attr("data-col"));
1558+
15331559
var new_grid_data = {
1534-
col: Math.round(value + col_dif),
1560+
col: col + col_dif,
15351561
row: wgd.row,
15361562
size_x: wgd.size_x,
15371563
size_y: wgd.size_y
15381564
};
1539-
15401565
setTimeout($.proxy(function () {
15411566
this.mutate_widget_in_gridmap($widget, wgd, new_grid_data);
15421567
}, this), 0);
@@ -1925,12 +1950,6 @@
19251950

19261951
this.options.resize.enabled && this.add_resize_handle($el);
19271952

1928-
if (this.options.center_widgets) {
1929-
setTimeout($.proxy(function () {
1930-
this.center_widgets();
1931-
}, this), 0);
1932-
}
1933-
19341953
return posChanged;
19351954
};
19361955

@@ -2066,7 +2085,7 @@
20662085
}, 60)
20672086
});
20682087

2069-
this.drag_api = this.$el.drag(draggable_options);
2088+
this.drag_api = this.$el.gridDraggable(draggable_options);
20702089
return this;
20712090
};
20722091

@@ -2078,7 +2097,7 @@
20782097
* @return {Class} Returns instance of gridster Class.
20792098
*/
20802099
fn.resizable = function() {
2081-
this.resize_api = this.$el.drag({
2100+
this.resize_api = this.$el.gridDraggable({
20822101
items: '.' + this.options.resize.handle_class,
20832102
offset_left: this.options.widget_margins[0],
20842103
container_width: this.container_width,
@@ -2480,7 +2499,7 @@
24802499
if (size_x !== this.resize_last_sizex ||
24812500
size_y !== this.resize_last_sizey) {
24822501

2483-
this.resize_widget(this.$resized_widget, size_x, size_y);
2502+
this.resize_widget(this.$resized_widget, size_x, size_y, false);
24842503
this.set_dom_grid_width(this.cols);
24852504

24862505
this.$resize_preview_holder.css({
@@ -3866,16 +3885,17 @@
38663885
cols = this.get_highest_occupied_cell().col;
38673886
}
38683887

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

38713891
cols = Math.min(max_cols, Math.max(cols, this.options.min_cols));
38723892
this.container_width = ((cols + 1) * this.options.widget_margins[0]) + (cols * this.min_widget_width);
3873-
if(this.is_responsive()) {
3874-
this.$el.css({'min-width': '100%', 'max-width': '100%'});
3875-
return this; //if we are responsive exit before setting the width of $el
3876-
}
38773893
this.$el.css('width', this.container_width);
38783894

3895+
if(this.is_responsive()) {
3896+
this.$el.css({'min-width': '100%', 'max-width': '100%'});
3897+
return this;
3898+
}
38793899
return this;
38803900
};
38813901

@@ -3973,16 +3993,13 @@
39733993
opts.widget_base_dimensions ||
39743994
(opts.widget_base_dimensions = this.options.widget_base_dimensions);
39753995

3996+
opts.widget_margins || (opts.widget_margins = this.options.widget_margins);
39763997

39773998
if(this.is_responsive()) {
3978-
opts.widget_base_dimensions = [this.get_responsive_col_width(), opts.widget_base_dimensions[1]];
3999+
opts.widget_base_dimensions = [this.get_responsive_col_width(), opts.widget_base_dimensions[1]];
4000+
this.toggle_collapsed_grid(full_width, opts);
39794001
}
39804002

3981-
opts.widget_margins || (opts.widget_margins = this.options.widget_margins);
3982-
3983-
3984-
this.toggle_collapsed_grid(full_width, opts);
3985-
39864003
// don't duplicate stylesheets for the same configuration
39874004
var serialized_opts = $.param(opts);
39884005
if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) {
@@ -4267,11 +4284,11 @@
42674284
*
42684285
* @param wrapper
42694286
*/
4270-
fn.set_num_columns = function (wrapper) {
4287+
fn.set_num_columns = function (wrapper_width) {
42714288

42724289
var max_cols = this.options.max_cols;
42734290

4274-
var cols = Math.floor(wrapper / (this.min_widget_width + this.options.widget_margins[0])) +
4291+
var cols = Math.floor(wrapper_width / (this.min_widget_width + this.options.widget_margins[0])) +
42754292
this.options.extra_cols;
42764293

42774294
var actual_cols = this.$widgets.map(function() {

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: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)