This project is archived and is in readonly mode.

#87 ✓invalid
abhai2k (at gmail)

Assets.javascript

Reported by abhai2k (at gmail) | July 9th, 2009 @ 08:09 AM

Hi,
I tried using assets.javascript to load javascript dynamically (after loading mootools and moomore).
If i simply let it load it does not work. However if i insert an alert statement it works. Example

new Asset.javascript('Modal.js', {id: 'ModBox'});
new ModalBox($('someelement'));

This does not work, But this works:-
new Asset.javascript('Modal.js', {id: 'ModBox'});
alert('test');
new ModalBox($('someelement'));

Also when i sent onload, in the option it comes in both cases. Am i doing something wrong???

Thanks

Comments and changes to this ticket

  • abhai2k (at gmail)

    abhai2k (at gmail) July 9th, 2009 @ 08:16 AM

    Edit, works fine in ie8, does not work in FF, Chrome, opera.
    Also tried using loading and running after domready. No use...

  • seanmonstar

    seanmonstar July 29th, 2009 @ 12:55 AM

    The reason it was likely working when you used alert, is that the script had finished loading before you clicked OK in the Alert and continued processing Javascript.

    Asset.javascript's second parameter is properties, of which one can be an onload event. If you're going to lazy-load some Javascript, you'll want to include an onload event handler that runs the code dependent on the script.

    Example:

    Asset.javascript('Modal.js',{

    onload: function() {
        new ModalBox($('someelement'));
    }
    

    });

  • Fábio M. Costa

    Fábio M. Costa August 3rd, 2009 @ 08:10 PM

    • Assigned user set to “Aaron Newton”

    this can be closed as invalid.

  • Aaron Newton

    Aaron Newton October 8th, 2009 @ 06:57 AM

    • State changed from “new” to “invalid”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The MooTools Extensions

People watching this ticket

Pages