I prefer to use the this implementation written by Andrea Giammarchi. It
work with SSL too. Check it out in action
http://www.3site.eu/jstests/onContent/final.html
function onContent(f){//from
http://www.3site.eu/jstests/onContent/final.html
var a,b=navigator.userAgent,d=document,w=window,
c="__onContent__",e="addEventListener",o="opera",r="readyState",
s="<scr".concat("ipt defer src='//:'
on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild
(this);",c,"()}'></scr","ipt>");
w[c]=(function(o){return function(){w[c]=function(){};for(a=arguments.callee
;!a.done;a.done=1)f(o?o():o)}})(w[c]);
if(d[e])d[e]("DOMContentLoaded",w[c],false);
if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))
(function(){/loaded|complete/.test(d[r])?w[c]():setTimeout(arguments.callee
,1)})();
else if(/MSIE/i.test(b))d.write(s);
};
//example
onContent(function(){
foo(); //called on dom ready
})
On 2/12/07, Martinez, Andrew <[EMAIL PROTECTED]> wrote:
>
>
> I know that this has been brought up before, but Is prototype going to
> support the on DOM ready state ability?
>
>
>
>
> I know that is far from cross-browser compatible and implementing it is on
> the night side of hackish, but I think it would be possible. The probability
> of more browsers supporting this even in the future is quite high in my
> opinion.
>
> Mozilla/Opera have a proper events, which register cleanly. For IE there
> is a script defer hack and for Opera an interval timer that polls
> document.readyState variable.
>
> To get around these glaring differences JQuery, another library where this
> "event" is implemented, binds their own function to the ready state test and
> then executes a member array of function pointers to give the same effect as
> a real event firing.
>
> From JQuery:
>
> ------------------------------
>
>
> // If Mozilla is used
> if ( jQuery.browser.mozilla || jQuery.browser.opera )
> // Use the handy event callback
> document.addEventListener( "DOMContentLoaded",
> jQuery.ready, false );
>
> // If IE is used, use the excellent hack by Matthias Miller
> //
> http://www.outofhanwell.com/blog/index.php?title=the_window_onload_problem_revisited
> else if ( jQuery.browser.msie ) {
>
> // Only works if you document.write() it
> document.write("<scr" + "ipt id=__ie_init defer=true " +
> "src=//:><\/script>");
>
> // Use the defer script hack
> var script = document.getElementById("__ie_init");
>
> // script does not exist if jQuery is loaded dynamically
> if ( script )
> script.onreadystatechange = function() {
> if ( this.readyState != "complete" )
> return;
> this.parentNode.removeChild( this );
> jQuery.ready();
> };
>
> // Clear from memory
> script = null;
>
> // If Safari is used
> } else if ( jQuery.browser.safari )
> // Continually check to see if the document.readyState is
> valid
> jQuery.safariTimer = setInterval(function(){
> // loaded and complete are both valid states
> if ( document.readyState == "loaded" ||
> document.readyState == "complete" ) {
>
> // If either one are found, remove the
> timer
> clearInterval( jQuery.safariTimer );
> jQuery.safariTimer = null;
>
> // and execute any waiting functions
> jQuery.ready();
> }
> }, 10);
>
> // A fallback to window.onload, that will always work
> jQuery.event.add( window, "load", jQuery.ready );
>
>
>
>
> -----------------------------------------
> { ...
> ready: function() {
> // Make sure that the DOM is not already loaded
> if ( !jQuery.isReady ) {
> // Remember that the DOM is ready
> jQuery.isReady = true;
>
> // If there are functions bound, to execute
> if ( jQuery.readyList ) {
> // Execute all of them
> jQuery.each( jQuery.readyList, function(){
> this.apply( document );
> });
>
> // Reset the list of functions
> jQuery.readyList = null;
> }
> // Remove event lisenter to avoid memory leak
> if ( jQuery.browser.mozilla ||
> jQuery.browser.opera )
> document.removeEventListener(
> "DOMContentLoaded", jQuery.ready, false );
> }
> }
>
> }
>
>
>
>
>
> -----------------------------
>
> -Andrew Martinez
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---