gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

resizestop event issue

Open lopezcjf opened this issue 11 years ago • 9 comments

Hi,

After resizing an element I need to catch the new width / height. For that purpose I'm using the resizestop event but I couldn't find the new values in here (only the old ones)

It seems to be that the values are updated somewhere after this event , and I only can get the new values on the next resize event (which of course is not suitable)

Thanks

lopezcjf avatar May 08 '15 18:05 lopezcjf

Why don't you use onchange event? An onchange handler receives all affected items.

troolee avatar May 15 '15 16:05 troolee

This seems to have changed between 0.2.2 and the current 0.2.3-dev. Formerly, the new values were accessible, now the old values are returned.

Using onchange is cumbersome as it contains details about all items that changed because of a resize, rather than just the one of interest.

m5n avatar May 15 '15 19:05 m5n

I guess I agree with m5c in this. It is good to support each event type with it's relevant data, specially for complex scenarios.

lopezcjf avatar May 15 '15 19:05 lopezcjf

I played with 0.2.3-dev a bit more, and I was wrong, the new values do get sent. (I have some other code that has a different outcome from 0.2.2, still investigating that.)

The "ui" object contains the originalSize and size properties that give you what you need:

$('.grid-stack').on('resizestop', function (event, ui) { ... }

m5n avatar May 15 '15 20:05 m5n

I swear I examined both objects and found the old values in both. But mistakes can happen! I will re-check that tonight ;)

lopezcjf avatar May 15 '15 20:05 lopezcjf

It could probably be because of animation. Please check it with and without.

troolee avatar May 15 '15 20:05 troolee

I can confirm what lopezcjf is saying.

$('.grid-stack').on('resizestop', function (event, ui) {
console.debug(ui.element[0].attributes.getNamedItem("data-gs-width"));
console.debug(ui.element[0].attributes.getNamedItem("data-gs-width").value);
});

first console output is: data-gs-width="1" second console output is: 12

First console output is the actual new width of widget and second is the old value. I am not using animation.

mkez00 avatar Jul 17 '15 15:07 mkez00

See also issue #159, where there is a fix for this posted.

derekm avatar Aug 07 '15 21:08 derekm

Closing, as @derekm's code has been merged. @lopezcjf please reopen if you're having a problem still.

radiolips avatar Feb 20 '16 01:02 radiolips