sparkartgroup-archive / sparkart.js

Easily interact with Sparkart's APIs via Javascript.
1 stars 0 forks source link

Load event does not trigger on window load #1

Closed pushred closed 11 years ago

pushred commented 11 years ago

The following callback isn't being executed when I use $(window).load() vs. $(document).ready()

fightclub.on('load', function(){
    ...
});
Fauntleroy commented 11 years ago

Can I have more code to evaluate this problem with? This is very unclear at the moment.

pushred commented 11 years ago
$(function(){
    fightclub.on('load', function(){
        ...
    });
});

… works.

$(window).load(function() {
    fightclub.on('load', function(){
        ...
    });
});

… does not work. I am trying to manage load order in this case so that's why I'm using this method.

Fauntleroy commented 11 years ago

This is probably due to the Fanclub's load event firing before window load. Since the binding happens after the fanclub has loaded, it is never fired.

pushred commented 11 years ago

Ok, would you recommend checking for the instantiated customer object then rather than using this event? Can I be sure that the fan club will be loaded when $(window).load is triggered?

Fauntleroy commented 11 years ago

Since I'm such a nice guy, here's what I'll do:

load should only ever fire once, since each instantiated fanclub only loads once. This means I can internally set a flag that tells me if it's loaded or not. Then if you try to bind to the load event after it's fired, I can just immediately fire your callback.