I have a piece of code that "waits" for body onload. Every 30ms, it tests $(''body''). Seems that isn''t always good enough. I''ve hit situations where the DOM is "partially" loaded somehow. I fixed matters by setting a global flag... <body onload="bodyLoaded=true;"> which provides a better test... of course I could always <body onload="myEventHandler();"> but I had wanted to keep my HTML markup JS free... Is there a reliable way to test for body loaded and not include an onload handler in the HTML markup? Sam _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
check out http://bennolan.com/behaviour/ ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com On 16-Jun-06, at 1:10 PM, Sam wrote:> I have a piece of code that "waits" for body onload. Every 30ms, > it tests $(''body''). > > Seems that isn''t always good enough. I''ve hit situations where the > DOM is "partially" loaded somehow. > > I fixed matters by setting a global flag... > > <body onload="bodyLoaded=true;"> > > which provides a better test... of course I could always > > <body onload="myEventHandler();"> > > but I had wanted to keep my HTML markup JS free... Is there a > reliable way to test for body loaded and not include an onload > handler in the HTML markup? > > Sam > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Or, in script (assuming you''re using prototype) Event.observe(window, "load", myHandler); Using the behavior lib raises other issues as far as keeping handles on your event handlers for when you need to clear them (if you ever start dealing with full blown componentized UI based applications and have to deal with memory management issues) -- On 6/16/06, Alex Duffield <alex-GLL9njBnHiGqPKKiFzS5XxZCeNDtXRbv@public.gmane.org> wrote:> > check out > http://bennolan.com/behaviour/ > > ______________________________________________________________________ > > *Alex Duffield* *.* *Principal* *.* *InControl Solutions* *.* * > http://www.incontrolsolutions.com* <http://www.incontrolsolutions.com/> > > > > > On 16-Jun-06, at 1:10 PM, Sam wrote: > > I have a piece of code that "waits" for body onload. Every 30ms, it tests > $(''body''). > > Seems that isn''t always good enough. I''ve hit situations where the DOM is > "partially" loaded somehow. > > I fixed matters by setting a global flag... > > <body onload="bodyLoaded=true;"> > > which provides a better test... of course I could always > > <body onload="myEventHandler();"> > > but I had wanted to keep my HTML markup JS free... Is there a > reliable way to test for body loaded and not include an onload handler in > the HTML markup? > > Sam > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> Or, in script (assuming you''re using prototype)> Event.observe(window, "load", myHandler); I wasn''t aware that window load did the job. I''ll look into it. Did I read somewhere that window load waits for all images on the page to be loaded? Sam _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
No idea, and to be honest not even sure if window load will work :-)... but if not, body will, or document... my point was just that Event.observe is what you want. On 6/16/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote:> > > Or, in script (assuming you''re using prototype) > > > Event.observe(window, "load", myHandler); > > I wasn''t aware that window load did the job. I''ll look into it. > > Did I read somewhere that window load waits for all images on the page to > be loaded? > > Sam > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 6/16/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote:> > > > Or, in script (assuming you''re using prototype) > > > Event.observe(window, "load", myHandler); > > > I wasn''t aware that window load did the job. I''ll look into it. > > Did I read somewhere that window load waits for all images on the page to be > loaded?Yes, you did... Conveniently, Dean Edwards just posted this: http://dean.edwards.name/weblog/2006/06/again/ Dave -- Dave Goodlad dgoodlad-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or dave-eHfbeeWWzZOw5LPnMra/2Q@public.gmane.org http://david.goodlad.ca/
Ha, seems that Thomas just blogged on this yesterday... http://mir.aculo.us/articles/2006/06/15/solving-the-onload-woe ______________________________________________________________________ Alex Duffield . Principal . InControl Solutions . http:// www.incontrolsolutions.com On 16-Jun-06, at 1:27 PM, Ryan Gahl wrote:> No idea, and to be honest not even sure if window load will > work :-)... but if not, body will, or document... my point was just > that Event.observe is what you want. > > On 6/16/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote: > > Or, in script (assuming you''re using prototype) > > > Event.observe(window, "load", myHandler); > > I wasn''t aware that window load did the job. I''ll look into it. > > Did I read somewhere that window load waits for all images on the > page to be loaded? > > Sam > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> Ha, seems that Thomas just blogged on this yesterday...<http://mir.aculo.us/articles/2006/06/15/solving-the-onload-woe> > http://mir.aculo.us/articles/2006/06/15/solving-the-onload-woe Following this link, I came to this: <http://agileweb.org/articles/2006/06/16/speeding-up-onload> http://agileweb.org/articles/2006/06/16/speeding-up-onload which has a link: http://dev.rubyonrails.org/ticket/5414 indicating a patch is supplied for prototype.js for "faster" onLoad handling. Anyone have an idea when the beta of this copy of prototype.js will be available? Sam _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
When Dead Edwards had written his first post about this I made a quick prototype class for it. And I''ve updated it since: http://tetlaw.id.au/view/blog/prototype-class-fastinit/ On 17/06/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote:> > > > Ha, seems that Thomas just blogged on this yesterday... > > > > > http://mir.aculo.us/articles/2006/06/15/solving-the-onload-woe > > > Following this link, I came to this: > > http://agileweb.org/articles/2006/06/16/speeding-up-onload > > which has a link: > > http://dev.rubyonrails.org/ticket/5414 > > indicating a patch is supplied for prototype.js for "faster" onLoad > handling. > > Anyone have an idea when the beta of this copy of prototype.js will be > available? > > Sam > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >-- Andrew Tetlaw htp://tetlaw.id.au
Hi Andrew, That seems to be a very clean implementation. as you implemented it as an external script (not part of prototype) i understand, that you created a new class (FastInit). But i would prefer to add this functionality to the Event Class: new Event.OnDOMContentLoaded(f1, f2, f3); Event.addOnDOMContentLoaded(f); OnDOMContentLoaded ... is not the shortest name, but it is the standards name, onDomLoad, onDocumentLoaded, etc.. is also ok and: why did you choose : http://creativecommons.org/licenses/by-sa/2.5/ instead of the prototype license (bsd) matthias Andrew Tetlaw schrieb:> When Dead Edwards had written his first post about this I made a quick > prototype class for it. And I''ve updated it since: > > http://tetlaw.id.au/view/blog/prototype-class-fastinit/ > > On 17/06/06, Sam <sam.google-Uc2IQQBAS6sAvxtiuMwx3w@public.gmane.org> wrote: >> >> >> > Ha, seems that Thomas just blogged on this yesterday... >> >> >> > >> http://mir.aculo.us/articles/2006/06/15/solving-the-onload-woe >> >> >> Following this link, I came to this: >> >> http://agileweb.org/articles/2006/06/16/speeding-up-onload >> >> which has a link: >> >> http://dev.rubyonrails.org/ticket/5414 >> >> indicating a patch is supplied for prototype.js for "faster" onLoad >> handling. >> >> Anyone have an idea when the beta of this copy of prototype.js will be >> available? >> >> Sam >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >> >> >> > >-- Matthias Platzer Geschäftsführer ------------------------------------------- knallgrau new media solutions gmbh pezzlgasse 7|1, A-1170 wien phone: +43 - 1 - 522 76 37 fax: +43 - 1 - 522 76 38 mobil: +43 - 699 - 1134 0946 http://www.knallgrau.at weitere News im Knallgrau Weblog: http://www.knallgrau.at/company/weblog
Hi Matthias, the license is just the default for my website. If you'd like it the same as prototype then consider it done! http://tetlaw.id.au/view/blog/prototype-class-fastinit/ On 19/06/06, Matthias Platzer <matthias@knallgrau.at> wrote:> Hi Andrew, > > That seems to be a very clean implementation. > > as you implemented it as an external script (not part of prototype) i > understand, that you created a new class (FastInit). But i would prefer > to add this functionality to the Event Class: > > new Event.OnDOMContentLoaded(f1, f2, f3); > Event.addOnDOMContentLoaded(f); > > OnDOMContentLoaded ... is not the shortest name, > but it is the standards name, > onDomLoad, onDocumentLoaded, etc.. is also ok > > and: > why did you choose : > http://creativecommons.org/licenses/by-sa/2.5/ > > instead of the prototype license (bsd) > > matthias > > Andrew Tetlaw schrieb: > > When Dead Edwards had written his first post about this I made a quick > > prototype class for it. And I've updated it since: > > > > http://tetlaw.id.au/view/blog/prototype-class-fastinit/ > > > > On 17/06/06, Sam <sam.google@iness.com> wrote: > >> > >> > >> > Ha, seems that Thomas just blogged on this yesterday... > >> > >> > >> > > >> http://mir.aculo.us/articles/2006/06/15/solving-the-onload-woe > >> > >> > >> Following this link, I came to this: > >> > >> http://agileweb.org/articles/2006/06/16/speeding-up-onload > >> > >> which has a link: > >> > >> http://dev.rubyonrails.org/ticket/5414 > >> > >> indicating a patch is supplied for prototype.js for "faster" onLoad > >> handling. > >> > >> Anyone have an idea when the beta of this copy of prototype.js will be > >> available? > >> > >> Sam > >> _______________________________________________ > >> Rails-spinoffs mailing list > >> Rails-spinoffs@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > >> > >> > >> > > > > > > > -- > Matthias Platzer > Geschäftsführer > ------------------------------------------- > knallgrau new media solutions gmbh > pezzlgasse 7|1, A-1170 wien > phone: +43 - 1 - 522 76 37 > fax: +43 - 1 - 522 76 38 > mobil: +43 - 699 - 1134 0946 > http://www.knallgrau.at > > weitere News im Knallgrau Weblog: http://www.knallgrau.at/company/weblog > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Andrew Tetlaw htp://tetlaw.id.au _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
I''ve been following the body Onload discussion with interest. Not having had access to this solution when developing my application, I resorted to building a scheduler class:"Executive" which fielded the HTML-coded events from <body onload="oExecutive.bodyOnload()" onUnload="oExecutive.bodyUnload()">>From there, it''s easy to imagine that the Executive class handles thedispatching of events to other Classes waiting for body Onload and Unload events. I have confidence that these events fire correctly in all browsers when the DOM is loaded and the images are still in-download-progress, providing a "fast" javascript initialization. This is the only event-markup on my page(s), and it seems a reasonable trade-off. So... I have a couple of questions: How much better is it to have a class to handle event dispatching Onload rather than hardcoding the event? Second - are there any (significant) unresolved cross-browser issues with the class FastInit ? Sam