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.04k stars 1.2k forks source link

resize_widget is only working ~50% of the time #453

Closed MaxwellRebo closed 9 years ago

MaxwellRebo commented 9 years ago

On: jQuery 1.8.3 Gridster 0.5.6

resize_widget produces two results with variability: some of the time it works normally, the widget is resized and other widgets move accordingly. About half of the time, though (with no apparent indication as to why), the widget resizes with some odd behavior: the widgets in another column entirely will move, and/or the widgets below the 'resized' widget don't move and overlaps occur.

On a previous Gridster version, was throwing an error "Cannot read property 'width' of undefined", originating from the coords plugin. Once I upgraded to Gridster 0.5.6 the error messages stopped but the behavior persisted, meaning it is now failing silently.

I am utterly baffled by this. I'm not doing anything exotic, and am using the library in a straightforward way. Has anybody encountered this?

Thank you!

NOTE: Any help is appreciated, but this is corporate code, so please do not ask me to share too much code as I am not permitted to do so. I will attempt to give the gist of the problem and see if others have encountered it.

MaxwellRebo commented 9 years ago

More clarity:

Browser: All browsers, meaning all recent versions of Firefox, Chrome, Safari. IE 9 had same problem last checked. OS: Tested OS X and Windows 7. Other libraries on page: Underscore.js, Moment.js, D3.js Number of widgets in gridster instance: 4-20

MaxwellRebo commented 9 years ago

After a bit more research, I find it is breaking here on line 58:

https://github.com/ducksboard/gridster.js/blob/master/src/jquery.coords.js

'Cannot set property 'width' of undefined' tells me nothing is returning from el.offset(). On line 57, 'this.data' must be undefined.

MaxwellRebo commented 9 years ago

Update on this issue: was able to verify that during a call to resize_widget, el.offset on line 57 in https://github.com/ducksboard/gridster.js/blob/master/src/jquery.coords.js is returning undefined. Attempting to isolate cause. jsFiddle coming.

markd-opmantek commented 9 years ago

I've had problems that sound like what you describe and the problem wound up being that the sizes I was passing into resize_widget were not being treated as numbers.

Adding the bottom two lines solved my problem, I've been meaning to contribute this back but haven't found the time yet:

fn.resize_widget = function($widget, size_x, size_y, callback) {
    size_x = parseInt(size_x);
    size_y = parseInt(size_y);
MaxwellRebo commented 9 years ago

That seems like an alright place to have that responsibility for converting to ints. Will look it over at some point.

Thanks for answering. I ended up resolving this issue in another way which I now cannot remember, haha.