Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot set property 'w' of undefined #1

Open
fluxsaas opened this issue Feb 8, 2011 · 11 comments
Open

Uncaught TypeError: Cannot set property 'w' of undefined #1

fluxsaas opened this issue Feb 8, 2011 · 11 comments

Comments

@fluxsaas
Copy link

fluxsaas commented Feb 8, 2011

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
Copy link
Author

fluxsaas commented Feb 8, 2011

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...

@betalb
Copy link

betalb commented Apr 11, 2011

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.

@MikeAmy
Copy link

MikeAmy commented Aug 11, 2011

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
Copy link

MikeAmy commented Aug 11, 2011

My script was included after jquery but not immediately after.

@MikeAmy
Copy link

MikeAmy commented Aug 11, 2011

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 );
      };

@orangewarp
Copy link

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.

@tobiaz
Copy link

tobiaz commented Jul 9, 2012

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.

@adanarchila
Copy link

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

@thecountofzero
Copy link

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

@roelvanduijnhoven
Copy link

@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.

@killa1218
Copy link

MikeAmy's solution is useful. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants