Skip to content

Commit e7d7b55

Browse files
author
David S Morse
committed
Merge pull request #43 from M0nter0/master
fix bug with sticky position widgets
2 parents bb529d4 + 44ce33a commit e7d7b55

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/jquery.gridster.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,13 +1536,23 @@
15361536

15371537
this.$changed = this.$changed.add(this.$player);
15381538

1539-
// move the cells down if there is an overlap and we are in static mode
1540-
if (this.options.collision.wait_for_mouseup) {
1541-
this.for_each_cell_occupied(this.placeholder_grid_data, function (tcol, trow) {
1542-
if (this.is_widget(tcol, trow)) {
1543-
this.move_widget_down(this.is_widget(tcol, trow), this.placeholder_grid_data.size_y);
1544-
}
1545-
});
1539+
//If widget has new position, clean previous grid
1540+
if (this.placeholder_grid_data.el.coords().grid.col !== this.placeholder_grid_data.col ||
1541+
this.placeholder_grid_data.el.coords().grid.row !== this.placeholder_grid_data.row) {
1542+
this.update_widget_position(this.placeholder_grid_data.el.coords().grid, false);
1543+
1544+
// move the cells down if there is an overlap and we are in static mode
1545+
if (this.options.collision.wait_for_mouseup) {
1546+
this.for_each_cell_occupied(this.placeholder_grid_data, function (tcol, trow) {
1547+
if (this.is_widget(tcol, trow)) {
1548+
// get number of cells to move
1549+
var destinyRow = this.placeholder_grid_data.row + this.placeholder_grid_data.size_y;
1550+
var currentOverlappedRow = parseInt(this.gridmap[tcol][trow][0].getAttribute('data-row'));
1551+
var cellsToMove = destinyRow - currentOverlappedRow;
1552+
this.move_widget_down(this.is_widget(tcol, trow), cellsToMove);
1553+
}
1554+
});
1555+
}
15461556
}
15471557

15481558
this.cells_occupied_by_player = this.get_cells_occupied(this.placeholder_grid_data);
@@ -1872,9 +1882,6 @@
18721882
fn.set_player = function (col, row, no_player) {
18731883
var self = this;
18741884
var swap = false;
1875-
if (!no_player) {
1876-
this.empty_cells_player_occupies();
1877-
}
18781885
var cell = !no_player ? self.colliders_data[0].el.data : {col: col};
18791886
var to_col = cell.col;
18801887
var to_row = cell.row || row;

0 commit comments

Comments
 (0)