Would somebody know that why if the 1st and 2nd line is swapped, then Firefox 2 and IE 7 will not run... Firefox shows "ShowMe is not defined"... and Safari runs it without any problem. also, I thought it is said that to guarantee that node.getWidth() can return something, it needs to be $(node).getWidth() so that node becomes the "extended element"... but it is not needed in the code and it still runs? How can prototype make it extended element automatically? Also related is that... does someone know how come offsetWidth is well documented in the Definitive Javascript book while clientWidth and scrollWidth are not? even though all 3 works in all Firefox, IE, and Safari. Thanks very much! <script src="prototype.js"></script> <a href="http://www.google.com"><img id="theimg" src="http:// www.sanrio.co.jp/english/characters/w_chara/pocha180.gif" onload="showMe(this)"></a> <script> function showMe(node) { document.getElementById("display").innerHTML = "Offset " + node.offsetWidth + " x " + node.offsetHeight + "<br>" + "Client " + node.clientWidth + " x " + node.clientHeight + "<br>" + "Scroll " + node.scrollWidth + " x " + node.scrollHeight + "<br>" + "Prototype " + node.getWidth() + " x " + node.getHeight() } </script> <div id="display"></div> --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
If the onload event for the image fires fast enough, then this will *always* causes errors since you aren''t defining the ShowMe function until later in the document. Why don''t you put your JS code in the header, to alleviate this problem? -justin --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> Would somebody know that why if the 1st and 2nd line is swapped, then > Firefox 2 and IE 7 will not run...As Justin said, if it loads fast enough (such as from cache), the event will get fired before your doc has been fully loaded and before the script exists. Remember that unless you use a load handler (either window.onload or Prototype''s own "dom:loaded" events), things early in the page can happen before the page as a whole exists in the browser.> also, I thought it is said that to guarantee that node.getWidth() can > return something, it needs to be $(node).getWidth() so that node > becomes the "extended element"... but it is not needed in the code > and it still runs?Depends on what browser you''re using. The joy of documentation: http://www.prototypejs.org/learn/extensions Hope this helps, -- T.J. Crowder tj / crowder software / com On Apr 25, 6:42 pm, liketofindoutwhy <liketofindout...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Would somebody know that why if the 1st and 2nd line is swapped, then > Firefox 2 and IE 7 will not run... Firefox shows "ShowMe is not > defined"... and Safari runs it without any problem. > > also, I thought it is said that to guarantee that node.getWidth() can > return something, it needs to be $(node).getWidth() so that node > becomes the "extended element"... but it is not needed in the code > and it still runs? How can prototype make it extended element > automatically? > > Also related is that... does someone know how come offsetWidth is well > documented in the Definitive Javascript book while clientWidth and > scrollWidth are not? even though all 3 works in all Firefox, IE, and > Safari. Thanks very much! > > <script src="prototype.js"></script> > > <a href="http://www.google.com"><img id="theimg" src="http://www.sanrio.co.jp/english/characters/w_chara/pocha180.gif" > onload="showMe(this)"></a> > > <script> > function showMe(node) { > document.getElementById("display").innerHTML = "Offset " + > node.offsetWidth + " x " + node.offsetHeight + "<br>" + > "Client " + node.clientWidth + " x " + node.clientHeight + > "<br>" + > "Scroll " + node.scrollWidth + " x " + node.scrollHeight + > "<br>" + > "Prototype " + node.getWidth() + " x " + node.getHeight() > > } > > </script> > > <div id="display"></div>--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 25, 2:58 pm, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Would somebody know that why if the 1st and 2nd line is swapped, then > > Firefox 2 and IE 7 will not run... > > As Justin said, if it loads fast enough (such as from cache), the > event will get fired before your doc has been fully loaded and before > the script exists. Remember that unless you use a load handler > (either window.onload or Prototype''s own "dom:loaded" events), things > early in the page can happen before the page as a whole exists in the > browser.Thanks very much. When the pic loads fast enough, and say the javascript code is at the beginning, it could fire off showMe() and then the function will use the element with id="display". There is also a chance that the element id="display" is not loaded yet... so in that case, will i need to move the element above the showMe() code? that probably is not a good idea to rearrange element according to javascript... by the way, so only <img> and <body> can have onload? can''t I have a <div> and use an onload to mean when everything inside of it gets rendered, such as text and img. Thank you guys. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I do think rather than trying to jig around with the order of the various things in the file, you''d be better off using a dom:loaded handler to hook up your events, rather than using DOM0-style "onload=" statements in the tags. Not only is this a better separation of concerns, but it will tend to be more reliable as you don''t have to worry about the order of things. For instance, I''m not sure what your showImage() function does, but you can do something like this (untested, probably over-verbose): * * * * document.observe("dom:loaded", hookThingsUp); function hookThingsUp() { showImageWhenReady(''theimg''); } function showImageWhenReady(imgid) { var img; img = $(imgid); img.observe(''loaded'', imageReadyHandler); showImageIfReady(img); } function showImageIfReady(img) { if (img.complete && !img._shown) { img._shown = true; img.stopObserving(''loaded'', imageReadyHandler); showImage(img); } } function onImageReadyHandler(evt) { showImageIfReady(evt.element()); } * * * * That looks like a lot of code (and I wouldn''t be surprised if it could be shortened), but the basic points are: * Hook up the event once the DOM is loaded, none of this DOM0 stuff. * Since at that point the image may _already_ be ready, check for that. * Disconnect the event when the image is complete and you show it. * Be aware of the race condition when hooking up the event handler, and handle it (by explicitly calling showImageIfReady and flagging whether we''ve shown it). Hope this helps, -- T.J. Crowder tj / crowder software / com On Apr 25, 11:28 pm, liketofindoutwhy <liketofindout...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 25, 2:58 pm, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Would somebody know that why if the 1st and 2nd line is swapped, then > > > Firefox 2 and IE 7 will not run... > > > As Justin said, if it loads fast enough (such as from cache), the > > event will get fired before your doc has been fully loaded and before > > the script exists. Remember that unless you use a load handler > > (either window.onload or Prototype''s own "dom:loaded" events), things > > early in the page can happen before the page as a whole exists in the > > browser. > > Thanks very much. When the pic loads fast enough, and say the > javascript code is at the beginning, it could fire off showMe() and > then the function will use the element with id="display". There is > also a chance that the element id="display" is not loaded yet... so > in that case, will i need to move the element above the showMe() > code? that probably is not a good idea to rearrange element according > to javascript... > > by the way, so only <img> and <body> can have onload? can''t I have a > <div> and use an onload to mean when everything inside of it gets > rendered, such as text and img. > > Thank you guys.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---