Hi everyone, I''ve seen prototype being featured on many sites/blogs, books, and I''m happy to give it a try. I believe it''s a great JS framework. Thanks to all contributors:) Now, my problem is, I''m trying to attach an even when my window loads, to an element inside my page. The code goes like this: <script> Event.observe(window, ''load'', function() { Event.observe(''element_id'', ''mouseout'', function() { foo(''element_id''); bar(''element_id''); }); } </script> The problem is, I am declaring the foo() and bar() functions way before calling this window.onload observer, but still when I hover my mouse over the ''element_id'' before my remote JS script loads, I get an error (Firefox) saying foo() function doesn''t exist. On the other hand, if everything loads on the page, the error doesn''t show up anymore. I know there has to be a solution out there, and it''s just a simple workaround, but I didn''t find it so far. The other thing that makes me think it''s a strange problem, is the fact that: - functions are declared before this event - if the error shows up, it means the event has been attached to the page So, based on this info, why I can''t get the mouseout effect over the divs until the remote JS file loads? As a workaround, I was thinking to show a "loading" image with a text saying "please wait... your page is loading". When everything is loaded (css/js files) this message dissapears, and the page is shown, however, this isn''t what I''m looking for. Thanks, Vladimir Ghetau http://www.Vladimirated.com --~--~---------~--~----~------------~-------~--~----~ 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 Nov 14, 12:18 pm, Vladimir Ghetau <vladi...-JO9vGbjvMkWBB+qDyBTWOgC/G2K4zDHf@public.gmane.org> wrote:> Hi everyone, > > I''ve seen prototype being featured on many sites/blogs, books, and I''m > happy to give it a try. I believe it''s a great JS framework. Thanks to > all contributors:) > > Now, my problem is, I''m trying to attach an even when my window loads, > to an element inside my page. > > The code goes like this: > > <script> > Event.observe(window, ''load'', function() { > > Event.observe(''element_id'', ''mouseout'', function() { > foo(''element_id''); > bar(''element_id''); > });}Firebug reports: "missing ) after argument list" which is spot on: you need to close the arguement list - add a final closing bracket ")".> > </script> > > The problem is, I am declaring the foo() and bar() functions way > before calling this window.onload observer,Which is irrelevant: for a given script element, declarations are processed before any code is executed, so you can declare functions as late as you like provided they are in the same script element.> but still when I hover my > mouse over the ''element_id'' before my remote JS script loads, I get an > error (Firefox) saying foo() function doesn''t exist.Which sounds to me like the code you posted is not the code that is erroring, the posted code doesn''t run at all because of the previously mentioned syntax error. And when that is fixed, it runs just fine (provided foo and bar are defined appropriately, see below).> On the other hand, if everything loads on the page, the error doesn''t > show up anymore.So is your real question "why do I have to wait for everything to load before attaching handlers"?> I know there has to be a solution out there, and it''s just a simple > workaround, but I didn''t find it so far.No doubt, once you work out what the question is.> The other thing that makes me think it''s a strange problem, is the > fact that: > - functions are declared before this event > - if the error shows up, it means the event has been attached to the > page > > So, based on this info, why I can''t get the mouseout effect over the > divs until the remote JS file loads?It seems that you''ve defined the functions in a separate file that file hasn''t loaded when you attach the handler. The code: Event.observe(''element_id'', ''mouseout'', function() { foo(''element_id''); bar(''element_id''); }); is run when the page finishes loading. It will evaluate (but not execute) the code inside the anonymous function and attempt to resolve the identifiers foo and bar. If the file in which foo and bar are defined hasn''t be loaded or evaluated yet, then their value at that point will be undefined, so that is what the handler on your elements has. And the error you''d get in Firebug is "foo is not defined", which is more or less what you reported above.> As a workaround, I was thinking to show a "loading" image with a text > saying "please wait... your page is loading". When everything is > loaded (css/js files) this message dissapears, and the page is shown, > however, this isn''t what I''m looking for.If you want handlers to be active when the elements are loaded and not wait for the full page to load, put them in-line. It can be done on the server using code that is equivalent to what you are doing here client-side. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andreas Franke
2007-Nov-14 09:31 UTC
AW: [Rails-spinoffs] Event.observe(window, ''load'', function) issue
Trie this, I think it schould work: Event.observe( window, "load", function(){ Event.observe ( ''element_id'', ''mouseout'', function(){ foo(''element_id''); bar(''element_id''); } ).bindAsEventListener(this); } ).bindAsEventListener(this); There where some trouble with your braces in the code you posted. An your main-Prob of your code was the "scope"-thing, I think. Andreas -----Ursprüngliche Nachricht----- Von: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] Im Auftrag von Vladimir Ghetau Gesendet: Mittwoch, 14. November 2007 03:18 An: Ruby on Rails: Spinoffs Betreff: [Rails-spinoffs] Event.observe(window, ''load'', function) issue Hi everyone, I''ve seen prototype being featured on many sites/blogs, books, and I''m happy to give it a try. I believe it''s a great JS framework. Thanks to all contributors:) Now, my problem is, I''m trying to attach an even when my window loads, to an element inside my page. The code goes like this: <script> Event.observe(window, ''load'', function() { Event.observe(''element_id'', ''mouseout'', function() { foo(''element_id''); bar(''element_id''); }); } </script> The problem is, I am declaring the foo() and bar() functions way before calling this window.onload observer, but still when I hover my mouse over the ''element_id'' before my remote JS script loads, I get an error (Firefox) saying foo() function doesn''t exist. On the other hand, if everything loads on the page, the error doesn''t show up anymore. I know there has to be a solution out there, and it''s just a simple workaround, but I didn''t find it so far. The other thing that makes me think it''s a strange problem, is the fact that: - functions are declared before this event - if the error shows up, it means the event has been attached to the page So, based on this info, why I can''t get the mouseout effect over the divs until the remote JS file loads? As a workaround, I was thinking to show a "loading" image with a text saying "please wait... your page is loading". When everything is loaded (css/js files) this message dissapears, and the page is shown, however, this isn''t what I''m looking for. Thanks, Vladimir Ghetau http://www.Vladimirated.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey guys, Thanks for stopping by, and checking out my problem. The idea was generally speaking , sorry about the braketing issue. Imagine that function would really work. To reword the issue: - I am attaching the event to the *active* window of the browser, right? - The file that contains the script, is remotelly accessed by the browser, it''s a JS file. The code I attached was an example, of how the behaviour, should look. Let''s ignore those sintax errors for now, my point was: why isn''t the script attaching the event, even if there''s a proof that the JS file has been loaded (the fact that when hovering the element is calling the foo function) until the page loads completely all its elements (images/css files/extra JS files). So, if I let the page load completely, everything works, the foo/bar was an abstract example. If the page is not loaded, the observers are still "sticked" to the active page, however, the called functions aren''t recognized, even if they are stored inside the same file which triggers the "onload" event. That''s the quick story, any opinions? Thanks, Vladimir Ghetau http://www.Vladimirated.com On Nov 14, 9:31 am, "Andreas Franke" <i...-8Zvurif+njuzQB+pC5nmwQ@public.gmane.org> wrote:> Trie this, I think it schould work: > > Event.observe( window, > "load", > function(){ > Event.observe ( > ''element_id'', > ''mouseout'', > function(){ > foo(''element_id''); > bar(''element_id''); > } > ).bindAsEventListener(this); > } > ).bindAsEventListener(this); > > There where some trouble with your braces in the code you posted. > An your main-Prob of your code was the "scope"-thing, I think. > > Andreas > > -----Ursprüngliche Nachricht----- > Von: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] Im Auftrag von Vladimir > Ghetau > Gesendet: Mittwoch, 14. November 2007 03:18 > An: Ruby on Rails: Spinoffs > Betreff: [Rails-spinoffs] Event.observe(window, ''load'', function) issue > > Hi everyone, > > I''ve seen prototype being featured on many sites/blogs, books, and I''m > happy to give it a try. I believe it''s a great JS framework. Thanks to > all contributors:) > > Now, my problem is, I''m trying to attach an even when my window loads, > to an element inside my page. > > The code goes like this: > > <script> > Event.observe(window, ''load'', function() { > > Event.observe(''element_id'', ''mouseout'', function() { > foo(''element_id''); > bar(''element_id''); > });} > > </script> > > The problem is, I am declaring the foo() and bar() functions way > before calling this window.onload observer, but still when I hover my > mouse over the ''element_id'' before my remote JS script loads, I get an > error (Firefox) saying foo() function doesn''t exist. > > On the other hand, if everything loads on the page, the error doesn''t > show up anymore. > > I know there has to be a solution out there, and it''s just a simple > workaround, but I didn''t find it so far. > > The other thing that makes me think it''s a strange problem, is the > fact that: > - functions are declared before this event > - if the error shows up, it means the event has been attached to the > page > > So, based on this info, why I can''t get the mouseout effect over the > divs until the remote JS file loads? > > As a workaround, I was thinking to show a "loading" image with a text > saying "please wait... your page is loading". When everything is > loaded (css/js files) this message dissapears, and the page is shown, > however, this isn''t what I''m looking for. > > Thanks, > > Vladimir Ghetauhttp://www.Vladimirated.com--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Julio Carlos Menéndez
2007-Nov-14 12:48 UTC
Re: Event.observe(window, ''load'', function) issue
Hi, I use it like this: function foo(id) { alert($(id).innerHTML); } function bar(id) { alert($(id)); } Event.observe(window, ''load'', function() { Event.observe(''element_id'', ''mouseout'', function() { foo(''element_id''); bar(''element_id''); }); }); I have tested this code and it works great, also it looks like yours. Hope it works for you too. On Wed, 14 Nov 2007 03:18:49 -0800 Vladimir Ghetau <vladimir-JO9vGbjvMkWBB+qDyBTWOgC/G2K4zDHf@public.gmane.org> wrote:> > Hey guys, > > > Thanks for stopping by, and checking out my problem. > > The idea was generally speaking , sorry about the braketing issue. > Imagine that function would really work. > > To reword the issue: > > - I am attaching the event to the *active* window of the browser, > right? > - The file that contains the script, is remotelly accessed by the > browser, it''s a JS file. > > The code I attached was an example, of how the behaviour, should look. > Let''s ignore those sintax errors for now, my point was: why isn''t the > script attaching the event, even if there''s a proof that the JS file > has been loaded (the fact that when hovering the element is calling > the foo function) until the page loads completely all its elements > (images/css files/extra JS files). > > So, if I let the page load completely, everything works, the foo/bar > was an abstract example. If the page is not loaded, the observers are > still "sticked" to the active page, however, the called functions > aren''t recognized, even if they are stored inside the same file which > triggers the "onload" event. > > That''s the quick story, any opinions? > > Thanks, > Vladimir Ghetau > http://www.Vladimirated.com > > On Nov 14, 9:31 am, "Andreas Franke" <i...-8Zvurif+njuzQB+pC5nmwQ@public.gmane.org> wrote: > > Trie this, I think it schould work: > > > > Event.observe( window, > > "load", > > function(){ > > Event.observe ( > > ''element_id'', > > ''mouseout'', > > function(){ > > foo(''element_id''); > > bar(''element_id''); > > } > > ).bindAsEventListener(this); > > } > > ).bindAsEventListener(this); > > > > There where some trouble with your braces in the code you posted. > > An your main-Prob of your code was the "scope"-thing, I think. > > > > Andreas > > > > -----Ursprüngliche Nachricht----- > > Von: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] Im Auftrag von > > Vladimir Ghetau > > Gesendet: Mittwoch, 14. November 2007 03:18 > > An: Ruby on Rails: Spinoffs > > Betreff: [Rails-spinoffs] Event.observe(window, ''load'', function) > > issue > > > > Hi everyone, > > > > I''ve seen prototype being featured on many sites/blogs, books, and > > I''m happy to give it a try. I believe it''s a great JS framework. > > Thanks to all contributors:) > > > > Now, my problem is, I''m trying to attach an even when my window > > loads, to an element inside my page. > > > > The code goes like this: > > > > <script> > > Event.observe(window, ''load'', function() { > > > > Event.observe(''element_id'', ''mouseout'', function() { > > foo(''element_id''); > > bar(''element_id''); > > });} > > > > </script> > > > > The problem is, I am declaring the foo() and bar() functions way > > before calling this window.onload observer, but still when I hover > > my mouse over the ''element_id'' before my remote JS script loads, I > > get an error (Firefox) saying foo() function doesn''t exist. > > > > On the other hand, if everything loads on the page, the error > > doesn''t show up anymore. > > > > I know there has to be a solution out there, and it''s just a simple > > workaround, but I didn''t find it so far. > > > > The other thing that makes me think it''s a strange problem, is the > > fact that: > > - functions are declared before this event > > - if the error shows up, it means the event has been attached to the > > page > > > > So, based on this info, why I can''t get the mouseout effect over the > > divs until the remote JS file loads? > > > > As a workaround, I was thinking to show a "loading" image with a > > text saying "please wait... your page is loading". When everything > > is loaded (css/js files) this message dissapears, and the page is > > shown, however, this isn''t what I''m looking for. > > > > Thanks, > > > > Vladimir Ghetauhttp://www.Vladimirated.com > > > --~--~---------~--~----~------------~-------~--~----~ > 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 > -~----------~----~----~----~------~----~------~--~--- >-- Julio Carlos Menéndez GNU/Linux User #403551 http://deltha.uh.cu/~juliocarlos
Andreas Franke
2007-Nov-14 12:54 UTC
AW: [Rails-spinoffs] Re: Event.observe(window, ''load'', function) issue
Is this what you are searching for? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /> <script type="text/javascript" src="/MyPath2Prototype/prototype.js"> </script> <script> Event.observe( window,''load'', function(){ Event.observe($("myelement"),"mousedown", function(element){ alert("foo1 says: "+element); }) } ); }); </script> </head> <body id="mybody"> <div id="myelement">Raum für den Inhalt von id "element_id"</div> </body> </html> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yeah, Andreas is right, same thing I''m using, it works, but not until everything on the page loads, and I tried to test everything through trial & error, and still nothing. I''ve even tested the javascript files inclusion position inside the HTML page (e.g. putting prototype.js first in the queue, and so on). No hope until the page''s content loads completely. I''ve tried the binding version of Andres, and it doesn''t help either. If I''ll find a solution to these, I''ll check back, and post it. Cheers. Vladimir Ghetau http://www.Vladimirated.com On Nov 14, 12:54 pm, "Andreas Franke" <i...-8Zvurif+njuzQB+pC5nmwQ@public.gmane.org> wrote:> Is this what you are searching for? > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /> > <script type="text/javascript" src="/MyPath2Prototype/prototype.js"> > </script> > <script> > Event.observe( window,''load'', function(){ > > Event.observe($("myelement"),"mousedown", function(element){ > > alert("foo1 says: "+element); > > }) > > } > > ); > > }); > > </script> > </head> > > <body id="mybody"> > <div id="myelement">Raum für den Inhalt von id "element_id"</div> > </body> > </html>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You should try using document.observe(''dom:loaded'', function() { / * ... */ }); Best, Tobie On Nov 16, 3:44 am, Vladimir Ghetau <vladi...-JO9vGbjvMkWBB+qDyBTWOgC/G2K4zDHf@public.gmane.org> wrote:> Yeah, > > Andreas is right, same thing I''m using, it works, but not until > everything on the page loads, and I tried to test everything through > trial & error, and still nothing. I''ve even tested the javascript > files inclusion position inside the HTML page (e.g. putting > prototype.js first in the queue, and so on). No hope until the page''s > content loads completely. > > I''ve tried the binding version of Andres, and it doesn''t help either. > > If I''ll find a solution to these, I''ll check back, and post it. > > Cheers. > > Vladimir Ghetauhttp://www.Vladimirated.com > > On Nov 14, 12:54 pm, "Andreas Franke" <i...-8Zvurif+njuzQB+pC5nmwQ@public.gmane.org> wrote: > > > Is this what you are searching for? > > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > > <html xmlns="http://www.w3.org/1999/xhtml"> > > <head> > > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /> > > <script type="text/javascript" src="/MyPath2Prototype/prototype.js"> > > </script> > > <script> > > Event.observe( window,''load'', function(){ > > > Event.observe($("myelement"),"mousedown", function(element){ > > > alert("foo1 says: "+element); > > > }) > > > } > > > ); > > > }); > > > </script> > > </head> > > > <body id="mybody"> > > <div id="myelement">Raum für den Inhalt von id "element_id"</div> > > </body> > > </html>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---