Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b71b872

Browse files
committed
gridster: moving down widgets under placeholder. Related to ducksboard#4.
This solves the overlapping-blocks seen in the screencast provided by @daniel-nelson. I've captured another one trying to reproduce the same movements with this commit applied: http://www.screenr.com/g7J8
1 parent dc61567 commit b71b872

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/jquery.gridster.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,13 +1218,14 @@
12181218

12191219

12201220
/**
1221-
* Get widgets overlapping with the player.
1221+
* Get widgets overlapping with the player or with the object passed
1222+
* representing the grid cells.
12221223
*
12231224
* @method get_widgets_under_player
12241225
* @return {HTMLElement} Returns a jQuery collection of HTMLElements
12251226
*/
1226-
fn.get_widgets_under_player = function() {
1227-
var cells = this.cells_occupied_by_player || {cols: [], rows: []};
1227+
fn.get_widgets_under_player = function(cells) {
1228+
cells || (cells = this.cells_occupied_by_player || {cols: [], rows: []});
12281229
var $widgets = $([]);
12291230

12301231
$.each(cells.cols, $.proxy(function(i, col) {
@@ -1258,7 +1259,7 @@
12581259
size_x: phgd.size_x
12591260
});
12601261

1261-
//Prevents widgets go out of the grid
1262+
// Prevents widgets go out of the grid
12621263
var right_col = (col + phgd.size_x - 1);
12631264
if (right_col > this.cols) {
12641265
col = col - (right_col - col);
@@ -1285,6 +1286,16 @@
12851286
}, this));
12861287
}
12871288

1289+
1290+
var $widgets_under_ph = this.get_widgets_under_player(this.cells_occupied_by_placeholder);
1291+
if ($widgets_under_ph.length) {
1292+
$widgets_under_ph.each($.proxy(function(i, widget) {
1293+
var $w = $(widget);
1294+
this.move_widget_down(
1295+
$w, row + phgd.size_y - $w.data('coords').grid.row);
1296+
}, this));
1297+
};
1298+
12881299
};
12891300

12901301

@@ -1352,21 +1363,14 @@
13521363
var upper_rows = [];
13531364
var min_row = 10000;
13541365

1355-
if (widget_grid_data.col < this.player_grid_data.col &&
1356-
(widget_grid_data.col + widget_grid_data.size_y - 1) >
1357-
(this.player_grid_data.col + this.player_grid_data.size_y - 1)
1358-
) {
1359-
return false;
1360-
};
1361-
1362-
/* generate an array with columns as index and array with upper rows
1366+
/* generate an array with columns as index and array with topmost rows
13631367
* empty as value */
13641368
this.for_each_column_occupied(widget_grid_data, function(tcol) {
13651369
var grid_col = this.gridmap[tcol];
13661370
upper_rows[tcol] = [];
13671371

13681372
var r = p_bottom_row + 1;
1369-
1373+
// iterate over each row
13701374
while (--r > 0) {
13711375
if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) {
13721376
if (!grid_col[r].is(widget_grid_data.el)) {

0 commit comments

Comments
 (0)