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

Skip to content

Commit 6c9eaf0

Browse files
committed
Fixes related to overlapping problems. Solve part of ducksboard#4.
Some fixes are about errors (seen in the link provided by @Floflow in ducksboard#16) produced by drag large blocks.
1 parent c047153 commit 6c9eaf0

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/jquery.gridster.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,6 @@
849849
return this;
850850
};
851851

852-
853852
/**
854853
* Determines if there is a widget in the row and col given. Or if the
855854
* HTMLElement passed as first argument is the player.
@@ -877,7 +876,7 @@
877876
* @return {Boolean} Returns true or false.
878877
*/
879878
fn.is_player_in = function(col, row) {
880-
var c = this.cells_occupied_by_player;
879+
var c = this.cells_occupied_by_player || {};
881880
return $.inArray(col, c.cols) >= 0 && $.inArray(row, c.rows) >= 0;
882881
};
883882

@@ -1125,6 +1124,13 @@
11251124
var upper_rows = [];
11261125
var min_row = 10000;
11271126

1127+
if (widget_grid_data.col < this.player_grid_data.col &&
1128+
(widget_grid_data.col + widget_grid_data.size_y - 1) >
1129+
(this.player_grid_data.col + this.player_grid_data.size_y - 1)
1130+
) {
1131+
return false;
1132+
};
1133+
11281134
/* generate an array with columns as index and array with upper rows
11291135
* empty as value */
11301136
this.for_each_column_occupied(widget_grid_data, function(tcol) {
@@ -1134,17 +1140,19 @@
11341140
var r = p_bottom_row + 1;
11351141

11361142
while (--r > 0) {
1137-
if (this.is_occupied(tcol, r) && !this.is_player(tcol, r)) {
1138-
break;
1143+
if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) {
1144+
if (!grid_col[r].is(widget_grid_data.el)) {
1145+
break;
1146+
};
11391147
}
11401148

11411149
if (!this.is_player(tcol, r) &&
1142-
!this.is_placeholder_in(tcol, r)
1143-
) {
1150+
!this.is_placeholder_in(tcol, r) &&
1151+
!this.is_player_in(tcol, r)) {
11441152
upper_rows[tcol].push(r);
1145-
}
1153+
};
11461154

1147-
if (r < min_row ) {
1155+
if (r < min_row) {
11481156
min_row = r;
11491157
}
11501158
}
@@ -1186,7 +1194,7 @@
11861194
while (++r <= p_bottom_row ) {
11871195
var common = true;
11881196
$.each(upper_rows, function(col, rows) {
1189-
if (rows && $.inArray(r, rows) === -1) {
1197+
if ($.isArray(rows) && $.inArray(r, rows) === -1) {
11901198
common = false;
11911199
}
11921200
});
@@ -1211,7 +1219,6 @@
12111219
}
12121220
}
12131221

1214-
12151222
return new_row;
12161223
};
12171224

@@ -1306,7 +1313,7 @@
13061313
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
13071314
*/
13081315
fn.on_stop_overlapping_column = function(col) {
1309-
this.set_player();
1316+
this.set_player(col, false);
13101317

13111318
var self = this;
13121319
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
@@ -1324,7 +1331,7 @@
13241331
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
13251332
*/
13261333
fn.on_stop_overlapping_row = function(row) {
1327-
this.set_player();
1334+
this.set_player(false, row);
13281335

13291336
var self = this;
13301337
var cols = this.cells_occupied_by_player.cols;
@@ -1370,7 +1377,6 @@
13701377
var $w = $(widget);
13711378
var wgd = $w.coords().grid;
13721379
var can_go_up = self.can_go_widget_up(wgd);
1373-
13741380
if (can_go_up && can_go_up !== wgd.row) {
13751381
self.move_widget_to($w, can_go_up);
13761382
}
@@ -1637,7 +1643,8 @@
16371643
var $w = this.is_widget(col, prev_row);
16381644
if (this.is_occupied(col, prev_row) ||
16391645
this.is_player(col, prev_row) ||
1640-
this.is_placeholder_in(col, prev_row)
1646+
this.is_placeholder_in(col, prev_row) ||
1647+
this.is_player_in(col, prev_row)
16411648
) {
16421649
result = false;
16431650
return true; //break

0 commit comments

Comments
 (0)