Hi is it possible to use the Ajax.Updater to add a js file to the head of my page? Any examples? I have previously tried with some dynamically loading with createElement and appendChild it works - but unfortunately I have multiple js references and some needs to be loaded before the other - but when I load them dynamically they don''t wait to get loaded - so sometimes I get an error :( - I have some dependencies in the js files - so from what I have read on other sites I should use some xmlhttp to add them - anybody have some suggestions how I can do this? Thanks in advance Regards Thomas K. Nielsen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
First, can you explain / demonstrate why you need to load JS dynamically, and can''t just use the HTML head as normal? There may be an entirely different way to architect what you want to do, avoiding the whole issue entirely. On Jun 1, 7:38 pm, "Thomas K. Nielsen" <thoni...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi is it possible to use the Ajax.Updater to add a js file to the head > of my page? Any examples? > > I have previously tried with some dynamically loading with > createElement and appendChild it works - but unfortunately I have > multiple js references and some needs to be loaded before the other - > but when I load them dynamically they don''t wait to get loaded - so > sometimes I get an error :( - I have some dependencies in the js files > - so from what I have read on other sites I should use some xmlhttp to > add them - anybody have some suggestions how I can do this? > > Thanks in advance > Regards > Thomas K. Nielsen--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> First, can you explain / demonstrate why you need to load JS > dynamically, and can''t just use the HTML head as normal? There may be > an entirely different way to architect what you want to do, avoiding > the whole issue entirely.I have a range of different widgets - that all have their own js file - but they are not used all of them immediately. It''s something we use in a learning environment. I have a master js file that i include on all pages and I want that master file to control what is beeing added. It takes care of including both the correct js files and css files depending on some values in arrays - but yes maybe I should give more thought in my structure and see if I need it. Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Although possible it''s rather unorthodox to do this via Javascript. If you''re writing pages in a dynamic language like PHP then you can include script tags conditionally depending on the page. Even if it''s just static HTML most servers support SSI or something similar. That solution is more simple and more maintainable, IMO. On 6/1/07, Thomas K. Nielsen <thoni.dk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > First, can you explain / demonstrate why you need to load JS > > dynamically, and can''t just use the HTML head as normal? There may be > > an entirely different way to architect what you want to do, avoiding > > the whole issue entirely. > > I have a range of different widgets - that all have their own js file > - but they are not used all of them immediately. > It''s something we use in a learning environment. I have a master js > file that i include on all pages and I want that > master file to control what is beeing added. It takes care of > including both the correct js files and css files depending on some > values in arrays - but yes maybe I should give more thought in my > structure and see if I need it. Thanks > > > > >-- Jesse E.I. Farmer e: jesse-h8Qh2m8E5SHQT0dZR+AlfA@public.gmane.org w: http://20bits.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 -~----------~----~----~----~------~----~------~--~---
I agree, doing it with PHP or what-have-you is a lot easier. I use PHP to control the building of the AnyLink Drop Down Menu on a site i am working on right now. It works great to build the menu depending on if its a guest user, registered user or an admin user - all while having less code and maintaining the look of the menu. On 6/1/07, Jesse Farmer <farmerje-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Although possible it''s rather unorthodox to do this via Javascript. > If you''re writing pages in a dynamic language like PHP then you can > include script tags conditionally depending on the page. Even if it''s > just static HTML most servers support SSI or something similar. > > That solution is more simple and more maintainable, IMO. > > On 6/1/07, Thomas K. Nielsen <thoni.dk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > First, can you explain / demonstrate why you need to load JS > > > dynamically, and can''t just use the HTML head as normal? There may be > > > an entirely different way to architect what you want to do, avoiding > > > the whole issue entirely. > > > > I have a range of different widgets - that all have their own js file > > - but they are not used all of them immediately. > > It''s something we use in a learning environment. I have a master js > > file that i include on all pages and I want that > > master file to control what is beeing added. It takes care of > > including both the correct js files and css files depending on some > > values in arrays - but yes maybe I should give more thought in my > > structure and see if I need it. Thanks > > > > > > > > > > > > -- > Jesse E.I. Farmer > e: jesse-h8Qh2m8E5SHQT0dZR+AlfA@public.gmane.org > w: http://20bits.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 -~----------~----~----~----~------~----~------~--~---
If you absolutely, positively, must do it with Javascript, check to see how Scriptaculous does it. (It''s in the scriptaculous.js file.) http://script.aculo.us/ On Jun 1, 2007, at 3:41 PM, Jesse Farmer wrote:> > Although possible it''s rather unorthodox to do this via Javascript. > If you''re writing pages in a dynamic language like PHP then you can > include script tags conditionally depending on the page. Even if it''s > just static HTML most servers support SSI or something similar. > > That solution is more simple and more maintainable, IMO. > > On 6/1/07, Thomas K. Nielsen <thoni.dk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> First, can you explain / demonstrate why you need to load JS >>> dynamically, and can''t just use the HTML head as normal? There >>> may be >>> an entirely different way to architect what you want to do, avoiding >>> the whole issue entirely. >> >> I have a range of different widgets - that all have their own js file >> - but they are not used all of them immediately. >> It''s something we use in a learning environment. I have a master js >> file that i include on all pages and I want that >> master file to control what is beeing added. It takes care of >> including both the correct js files and css files depending on some >> values in arrays - but yes maybe I should give more thought in my >> structure and see if I need it. Thanks >> >> >>> >> > > > -- > Jesse E.I. Farmer > e: jesse-h8Qh2m8E5SHQT0dZR+AlfA@public.gmane.org > w: http://20bits.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 -~----------~----~----~----~------~----~------~--~---
Her is the function I use to load JS files dynamically It uses a script tag with the id "loadScript" Each time a new script is loaded it replaces the last one. I made this for a web app that loaded up new modules via Ajax. function LoadJS(file){ var head = document.getElementsByTagName(''head'').item(0) var scriptTag = $(''loadScript''); if(scriptTag) head.removeChild(scriptTag); script = document.createElement(''script''); script.src = file; script.type = ''text/javascript''; script.id = ''loadScript''; head.appendChild(script) } ______________________________________________________________________ Alex Duffield ❖ Principal ❖ InControl Solutions . http:// www.incontrolsolutions.com On 1-Jun-07, at 11:38 AM, Thomas K. Nielsen wrote:> > Hi is it possible to use the Ajax.Updater to add a js file to the head > of my page? Any examples? > > I have previously tried with some dynamically loading with > createElement and appendChild it works - but unfortunately I have > multiple js references and some needs to be loaded before the other - > but when I load them dynamically they don''t wait to get loaded - so > sometimes I get an error :( - I have some dependencies in the js files > - so from what I have read on other sites I should use some xmlhttp to > add them - anybody have some suggestions how I can do this? > > Thanks in advance > Regards > Thomas K. Nielsen > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
...that's really cool. Going to keep this in mind... thanks! On 6/1/07, Alex Duffield <Alex@incontrolsolutions.com> wrote:> > Her is the function I use to load JS files dynamically > It uses a script tag with the id "loadScript" Each time a new script is > loaded it replaces the last one. > > I made this for a web app that loaded up new modules via Ajax. > > > function LoadJS(file){ > var head = document.getElementsByTagName('head').item(0) > var scriptTag = $('loadScript'); > if(scriptTag) head.removeChild(scriptTag); > script = document.createElement('script'); > script.src = file; > script.type = 'text/javascript'; > script.id = 'loadScript'; > head.appendChild(script) > } > > > ______________________________________________________________________ > > *Alex Duffield* *❖* *Principal* *❖* *InControl Solutions* *.* * > http://www.incontrolsolutions.com* <http://www.incontrolsolutions.com/> > > > > > On 1-Jun-07, at 11:38 AM, Thomas K. Nielsen wrote: > > > Hi is it possible to use the Ajax.Updater to add a js file to the head > of my page? Any examples? > > I have previously tried with some dynamically loading with > createElement and appendChild it works - but unfortunately I have > multiple js references and some needs to be loaded before the other - > but when I load them dynamically they don't wait to get loaded - so > sometimes I get an error :( - I have some dependencies in the js files > - so from what I have read on other sites I should use some xmlhttp to > add them - anybody have some suggestions how I can do this? > > Thanks in advance > Regards > Thomas K. Nielsen > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> function LoadJS(file){ > var head = document.getElementsByTagName(''head'').item(0) > var scriptTag = $(''loadScript''); > if(scriptTag) head.removeChild(scriptTag); > script = document.createElement(''script''); > script.src = file; > script.type = ''text/javascript''; > script.id = ''loadScript''; > head.appendChild(script) > }Thanks for the suggestions guys. I used a similar approach as this - not calling it the same however - but the problem with that - at least for me was that I have multiple js files and some are dependent on each other - so I need to be sure that they are avilable and ready to be used once they are used. I actually did try it with the Ajax.Updater - and I could load the files (or at least the javascript) - it''s getting loaded immediately and is accessible, but I''m not sure it''s a good solution - it''s getting hard to keep track of what is loaded :) if I go through it with the debugger - I only see it as evalcode. So I think I will keep away from that approach. To the guys that suggested that I handle it on the server - that''s not an option - I have to do it clientside - or hardcode the files into the head section of each page. Thanks for the input - much appreciated --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes, I was concerned about having to much stuff resident in memory as would be the case with continually loading via ajax.updater and using eval scripts... You could use unique IDs for each of your required JS files and then one for the "Modules" or "Widgets" in your case.. you could then call this like LoadJS(file, scriptid) --- // you would need to modify the function of coarse... That way you could be loading more than just one file per call and you could load the dependent files as the first lines of the widget.js Does that make any sense?? You could get more fancy and look at each script tag and see if the dependent file is already loaded based on the src, if not load it. . That way you get rid of the ID all together. It would be an equivalent to PHPs require_once() function. ______________________________________________________________________ Alex Duffield ❖ Principal ❖ InControl Solutions . http:// www.incontrolsolutions.com On 2-Jun-07, at 1:54 AM, Thomas K. Nielsen wrote:> >> function LoadJS(file){ >> var head = document.getElementsByTagName(''head'').item(0) >> var scriptTag = $(''loadScript''); >> if(scriptTag) head.removeChild(scriptTag); >> script = document.createElement(''script''); >> script.src = file; >> script.type = ''text/javascript''; >> script.id = ''loadScript''; >> head.appendChild(script) >> } > > Thanks for the suggestions guys. > I used a similar approach as this - not calling it the same however - > but the problem with that - at least for me was that I have multiple > js files and some are dependent on each other - so I need to be sure > that they are avilable and ready to be used once they are used. > > I actually did try it with the Ajax.Updater - and I could load the > files (or at least the javascript) - it''s getting loaded immediately > and is accessible, but I''m not sure it''s a good solution - it''s > getting hard to keep track of what is loaded :) if I go through it > with the debugger - I only see it as evalcode. So I think I will keep > away from that approach. > > To the guys that suggested that I handle it on the server - that''s not > an option - I have to do it clientside - or hardcode the files into > the head section of each page. > > Thanks for the input - much appreciated > > > >--~--~---------~--~----~------------~-------~--~----~ 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 could use unique IDs for each of your required JS files and then > one for the "Modules" or "Widgets" in your case.. > > you could then call this like LoadJS(file, scriptid) --- // you would > need to modify the function of coarse... > > That way you could be loading more than just one file per call and > you could load the dependent files as the first lines of the widget.js > > Does that make any sense??Sure it makes sense :) Thanks I will take a look at that. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Check out: http://design-noir.de/webdev/JS/loadScript/ His loadScript function works perfectly with all browsers. I have encapsolated his logic into my own classes, and it has worked great. On Jun 2, 12:32 pm, "Thomas K. Nielsen" <thoni...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > You could use unique IDs for each of your required JS files and then > > one for the "Modules" or "Widgets" in your case.. > > > you could then call this like LoadJS(file, scriptid) --- // you would > > need to modify the function of coarse... > > > That way you could be loading more than just one file per call and > > you could load the dependent files as the first lines of the widget.js > > > Does that make any sense?? > > Sure it makes sense :) > Thanks I will take a look at that.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
very cool. ...another function he has on there, ''whenDOMReady'', looks pretty slick as well: http://design-noir.de/webdev/JS/whenDOMReady/ On 6/4/07, Steve Loeppky <loeppky-vV1OtcyAfmbQT0dZR+AlfA@public.gmane.org> wrote:> > > Check out: http://design-noir.de/webdev/JS/loadScript/ > > His loadScript function works perfectly with all browsers. I have > encapsolated his logic into my own classes, and it has worked great. > > On Jun 2, 12:32 pm, "Thomas K. Nielsen" <thoni...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > You could use unique IDs for each of your required JS files and then > > > one for the "Modules" or "Widgets" in your case.. > > > > > you could then call this like LoadJS(file, scriptid) --- // you would > > > need to modify the function of coarse... > > > > > That way you could be loading more than just one file per call and > > > you could load the dependent files as the first lines of the widget.js > > > > > Does that make any sense?? > > > > Sure it makes sense :) > > Thanks I will take a look at that. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---