Hi, I would like to load scriptaculous.js after someone clicks on a link. I have tried to use <head> <script type="text/javascript" src="javascript/prototype.js"></script> <script type="text/javascript"> <!-- function loadContent(file){ var head = document.getElementsByTagName(''head'').item(0) var scriptTag = document.getElementById(''loadScript''); if(scriptTag) head.removeChild(scriptTag); script = document.createElement(''script''); script.src = file; script.type = ''text/javascript''; script.id = ''loadScript''; head.appendChild(script) } //--> </script> </head> and on page <a href="javascript: loadContent(''javascript/ scriptaculous.js'');">test</a> but It created a lot of errors like that prototype does not exist etc.. and i did not work. Can you help me please? I do not want to load scriptaculous on page load since it is quite big... --~--~---------~--~----~------------~-------~--~----~ 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 13/09/2007, czechboy <oldrich.svec-aRb0bU7PRFPrBKCeMvbIDA@public.gmane.org> wrote:> > Hi, > I would like to load scriptaculous.js after someone clicks on a link. > I have tried to use > > <head> > <script type="text/javascript" src="javascript/prototype.js"></script> > <script type="text/javascript"> > <!-- > function loadContent(file){ > var head = document.getElementsByTagName(''head'').item(0) > var scriptTag = document.getElementById(''loadScript''); > if(scriptTag) head.removeChild(scriptTag); > script = document.createElement(''script''); > script.src = file; > script.type = ''text/javascript''; > script.id = ''loadScript''; > head.appendChild(script) > } > //--> > </script> > </head> > > and on page > <a href="javascript: loadContent(''javascript/ > scriptaculous.js'');">test</a> > > but It created a lot of errors like that prototype does not exist > etc.. and i did not work. > Can you help me please? I do not want to load scriptaculous on page > load since it is quite big...I would use a document.write() as this is how Scriptaculous already works to load the other elements. So, your link needs to run ... function loadScriptaculous() { if (typeof Scriptaculous=''undefined'') { document.write(''<script type="text/javascript" src="/scriptaculous.js"></script>''); } } -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 13/09/2007, Richard Quadling <rquadling-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 13/09/2007, czechboy <oldrich.svec-aRb0bU7PRFPrBKCeMvbIDA@public.gmane.org> wrote: > > > > Hi, > > I would like to load scriptaculous.js after someone clicks on a link. > > I have tried to use > > > > <head> > > <script type="text/javascript" src="javascript/prototype.js"></script> > > <script type="text/javascript"> > > <!-- > > function loadContent(file){ > > var head = document.getElementsByTagName(''head'').item(0) > > var scriptTag = document.getElementById(''loadScript''); > > if(scriptTag) head.removeChild(scriptTag); > > script = document.createElement(''script''); > > script.src = file; > > script.type = ''text/javascript''; > > script.id = ''loadScript''; > > head.appendChild(script) > > } > > //--> > > </script> > > </head> > > > > and on page > > <a href="javascript: loadContent(''javascript/ > > scriptaculous.js'');">test</a> > > > > but It created a lot of errors like that prototype does not exist > > etc.. and i did not work. > > Can you help me please? I do not want to load scriptaculous on page > > load since it is quite big... > > I would use a document.write() as this is how Scriptaculous already > works to load the other elements. > > So, your link needs to run ... > > function loadScriptaculous() { > if (typeof Scriptaculous=''undefined'') { > document.write(''<script type="text/javascript" > src="/scriptaculous.js"></script>''); > } > }Alternatively / additionally, I would take a look at http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files I use this (with a few mods) and the js code is loaded once per browser cache. This has made a significant difference, so much so, I put all my own JS code through it too. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>{APP_TITLE}</title> <script src="/global/combine.php?type=javascript&files=firebug/firebugx.js,prototype/prototype.js,raq/raq.js,raq/additionalJS.js,raq/enhanced_date.js,raq/enhanced_element.js,raq/enhanced_event.js,raq/enhanced_math.js,raq/enhanced_string.js" type="text/javascript"></script> </head> ... sort of thing. -- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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, thanks a lot. I could not use the php script, but I joined all js to one file and packed it by gzip and now it loads perfectly ;) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I now realise I only pass data around in JSON, not raw code, though an object definition could be passed I believe. So if you had a framework to handle a particular object which had code ... On 13/09/2007, czechboy <oldrich.svec-aRb0bU7PRFPrBKCeMvbIDA@public.gmane.org> wrote:> > Hi, > thanks a lot. I could not use the php script, but I joined all js to > one file and packed it by gzip and now it loads perfectly ;) > > > > >-- ----- Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731 "Standing on the shoulders of some very clever giants!" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---