ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.03k stars 1.2k forks source link

add_widget breaks internal gridmap if adding a tile that extends the gridmap rows #295

Open msvanvertloo opened 10 years ago

msvanvertloo commented 10 years ago

See fiddle: http://jsfiddle.net/ngEGa/

In this fiddle, the placement of the tiles is correct. However, the button checks if widget "5" can move up. The can_go_up method says that it can, even though it doesn't look like it should. In fact, if you drag widget "5" up a few pixels, it will drop on top of widget "3".

The cause of the problem: when adding tiles 4 and 5, the gridmap is extended by a few rows (as part of the add_to_gridmap call done by register_widget). After the call to register_widget, add_faux_rows extends the rows of the gridmap using the old row count, thereby clearing out some of the gridmap locations just reserved by add_to_gridmap. All of the collision functionality relies on a correct representation of the grid in the gridmap.