Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Add on ready functionality similar to $(document).ready(function(){}); #11

Closed
cayasso opened this issue Oct 19, 2010 · 1 comment
Closed

Comments

@cayasso
Copy link

cayasso commented Oct 19, 2010

Hi thank you for such a great plug-in I am using it at my company. Can you add a onready function that would be used in a similar way as we use document ready in jQuery something like


$LAB.ready(function(){
// do stuff...
});

This will allow inline scripting if needed at any point without having to be at the bottom of the page in a wait() function.

I created this temporary function for my company since they use a lot of inline JavaScript this because of the CMS architecture, and the many different pages that needs to be maintained


(function(llb){   
    var api = {     
        events: [],     
        registerEvent: function(e){
            api.events.push(e);
        },      
        executeAllEvents: function(){           
            var length = api.events.length;         
            for(var i = 0; i < length; i++){         
                if ( typeof api.events[i] === 'function' ) 
                    api.events[i]();
            }
        }
    }
    llb.ready = api.registerEvent;
    llb.run = api.executeAllEvents;
    window.llb = llb;   
})($LAB);

Then in the html I have this, where I run llb.run() at the bottom to execute the registered events


llb
.script("/includes/js/llbean/jquery.min.js").wait()
.script("/includes/js/llbean/jquery.cookie.min.js").wait(llb.run());

And now I can use something like this in any section of any page.


llb.ready(function(){
    alert($('#mio').attr('id'));
});

This was a very quick attempt to resolve some dependency issues on different pages (more than 1000 pages). I know you may come up with a better piece of code but the idea is that one can use a ready function that is triggered when javascript files are loaded and doesnt need to use the wait() function always.

I hope I am making any sense.

Thank you and thanks for contributing making the web faster. ;-)

JB

@cayasso
Copy link
Author

cayasso commented Nov 3, 2010

Hi Kyle, any thoughts about this suggestion?

JB

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant