From 6c9eaf067d19a494386d75a858e9be31989f22fe Mon Sep 17 00:00:00 2001 From: vieron Date: Sun, 12 Aug 2012 18:38:18 +0200 Subject: [PATCH] Fixes related to overlapping problems. Solve part of #4. Some fixes are about errors (seen in the link provided by @floflow in #16) produced by drag large blocks. --- src/jquery.gridster.js | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/jquery.gridster.js b/src/jquery.gridster.js index 26f32b6b2..e9f6208fb 100644 --- a/src/jquery.gridster.js +++ b/src/jquery.gridster.js @@ -849,7 +849,6 @@ return this; }; - /** * Determines if there is a widget in the row and col given. Or if the * HTMLElement passed as first argument is the player. @@ -877,7 +876,7 @@ * @return {Boolean} Returns true or false. */ fn.is_player_in = function(col, row) { - var c = this.cells_occupied_by_player; + var c = this.cells_occupied_by_player || {}; return $.inArray(col, c.cols) >= 0 && $.inArray(row, c.rows) >= 0; }; @@ -1125,6 +1124,13 @@ var upper_rows = []; var min_row = 10000; + if (widget_grid_data.col < this.player_grid_data.col && + (widget_grid_data.col + widget_grid_data.size_y - 1) > + (this.player_grid_data.col + this.player_grid_data.size_y - 1) + ) { + return false; + }; + /* generate an array with columns as index and array with upper rows * empty as value */ this.for_each_column_occupied(widget_grid_data, function(tcol) { @@ -1134,17 +1140,19 @@ var r = p_bottom_row + 1; while (--r > 0) { - if (this.is_occupied(tcol, r) && !this.is_player(tcol, r)) { - break; + if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) { + if (!grid_col[r].is(widget_grid_data.el)) { + break; + }; } if (!this.is_player(tcol, r) && - !this.is_placeholder_in(tcol, r) - ) { + !this.is_placeholder_in(tcol, r) && + !this.is_player_in(tcol, r)) { upper_rows[tcol].push(r); - } + }; - if (r < min_row ) { + if (r < min_row) { min_row = r; } } @@ -1186,7 +1194,7 @@ while (++r <= p_bottom_row ) { var common = true; $.each(upper_rows, function(col, rows) { - if (rows && $.inArray(r, rows) === -1) { + if ($.isArray(rows) && $.inArray(r, rows) === -1) { common = false; } }); @@ -1211,7 +1219,6 @@ } } - return new_row; }; @@ -1306,7 +1313,7 @@ * @return {HTMLElements} Returns a jQuery collection of HTMLElements. */ fn.on_stop_overlapping_column = function(col) { - this.set_player(); + this.set_player(col, false); var self = this; this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0], @@ -1324,7 +1331,7 @@ * @return {HTMLElements} Returns a jQuery collection of HTMLElements. */ fn.on_stop_overlapping_row = function(row) { - this.set_player(); + this.set_player(false, row); var self = this; var cols = this.cells_occupied_by_player.cols; @@ -1370,7 +1377,6 @@ var $w = $(widget); var wgd = $w.coords().grid; var can_go_up = self.can_go_widget_up(wgd); - if (can_go_up && can_go_up !== wgd.row) { self.move_widget_to($w, can_go_up); } @@ -1637,7 +1643,8 @@ var $w = this.is_widget(col, prev_row); if (this.is_occupied(col, prev_row) || this.is_player(col, prev_row) || - this.is_placeholder_in(col, prev_row) + this.is_placeholder_in(col, prev_row) || + this.is_player_in(col, prev_row) ) { result = false; return true; //break