jquery-resize icon indicating copy to clipboard operation
jquery-resize copied to clipboard

Uncaught TypeError: Cannot set property 'w' of undefined

Open fluxsaas opened this issue 14 years ago • 11 comments

i get the following error in chrome/firefoxIE8

    jquery.ba-resize.js:198 Uncaught TypeError: Cannot set property 'w' of undefined

    Uncaught TypeError: Cannot set property 'w' of undefined
    new_handlerjquery.ba-resize.js:198
    jQuery.event.handlejquery.js:2260
    jQuery.event.add.elemData.handle.eventHandlejquery.js:1891
    jQuery.each.jQuery.fnjquery.js:7151
    new_handlerjquery.ba-resize.js:198
    jQuery.event.handlejquery.js:2260
    jQuery.event.add.elemData.handle.eventHandlejquery.js:1891

my implementation:

$(".container").resize(function(e){ setTimeout(function() { console.log('resize') }, 10); });

fluxsaas avatar Feb 08 '11 10:02 fluxsaas

and the solution seems to be:

- public/javascripts/lib/jquery.js
- public/javascripts/lib/jquery-ui.js
- public/javascripts/plugins/jquery.ba-resize.js

embedding the plugin right after jquery. previously i had it at the end of my plugin list... not sure if it is still a bug...

fluxsaas avatar Feb 08 '11 10:02 fluxsaas

It happens if you bind resize events before ba-resize is loaded, so this event won't get data In my case this happend when I binded first resize event to window object before ba-resize was loaded.

betalb avatar Apr 11 '11 14:04 betalb

I had changed new_handler but this is probably hacky...

    ...
    function new_handler( e, w, h ) {
        var elem = $(this),
          data = $.data( this, str_data );
          // added this bit
          if (!data) {
              data = $.data( this, str_data, { w: elem.width(), h: elem.height() })
          }
          else {

            // If called from the polling loop, w and h will be passed in as
            // arguments. If called manually, via .trigger( 'resize' ) or .resize(),
            // those values will need to be computed.
            if (w !== undefined) {
                data.w = w
            }
            else {
                data.w = elem.width();
            }
            data.h = h !== undefined ? h : elem.height();
          }

        old_handler.apply( this, arguments );
      };

MikeAmy avatar Aug 11 '11 11:08 MikeAmy

My script was included after jquery but not immediately after.

MikeAmy avatar Aug 11 '11 11:08 MikeAmy

Maybe this would be better:

function new_handler( e, w, h ) {
        var elem = $(this),
          data = $.data( this, str_data );
          if (!data) {
              data = $.data( this, str_data, {})
          }

          // If called from the polling loop, w and h will be passed in as
          // arguments. If called manually, via .trigger( 'resize' ) or .resize(),
          // those values will need to be computed.
          data.w = w !== undefined ? w : elem.width();
          data.h = h !== undefined ? h : elem.height();

        old_handler.apply( this, arguments );
      };

MikeAmy avatar Aug 11 '11 12:08 MikeAmy

I had a similar issue but it wasn't because the plugin wasn't loaded. (Using require.js) The above patch by MikeAmy seems to have fixed my problem.

orangewarp avatar Mar 14 '12 03:03 orangewarp

MikeAmy's solution above also fixed my issue of "data" being undefined. Insert the if block:

if (!data) {
              data = $.data( this, str_data, {})
          }

after line 193 in jquery.ba-resize.js.

tobiaz avatar Jul 09 '12 04:07 tobiaz

MikeAmy's solution it's still working pretty good, thanks!

adanarchila avatar Aug 27 '12 02:08 adanarchila

What is the status of this issue? I am seeing the same error.

thecountofzero avatar Apr 11 '13 05:04 thecountofzero

@tobiaz fix also fixes my problems.

But I just found out that the last commit to this repo was 4 years ago: so I am abonding it.

roelvanduijnhoven avatar Oct 22 '13 13:10 roelvanduijnhoven

MikeAmy's solution is useful. Thank you.

killa1218 avatar Feb 24 '15 02:02 killa1218