cowboy / jquery-resize

A resize event for ALL your jQueries!

Home Page:http://benalman.com/projects/jquery-resize-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unbinding later bound event in earlier bound trigger fails

plaidhatter opened this issue · comments

Great plugin. I've used it a bunch. I found a bug though that will completely disable the plugin.
The gist is that within a resize trigger, when you unbind a resize event for a later bound resize event, loopy still try's to check the unbound one and it no longer has the needed data.
I've fixed the code (just check that data exists before accessing it) on my machine and have included it here:

  function loopy() {

    // Start the polling loop, asynchronously.
    timeout_id = window[ str_setTimeout ](function(){

      // Iterate over all elements to which the 'resize' event is bound.
      elems.each(function(){
        var elem = $(this),
          width = elem.width(),
          height = elem.height(),
          data = $.data( this, str_data );

        // If element size has changed since the last time, update the element
        // data store and trigger the 'resize' event.
        if (data && ( width !== data.w || height !== data.h ) ) {
          elem.trigger( str_resize, [ data.w = width, data.h = height ] );
        }

      });

      // Loop.
      loopy();

    }, jq_resize[ str_delay ] );

  };