I am working with the Yahoo Maps API and I''d like to only include the Yahoo javascript library on demand. I have a link_to_remote that shows a Yahoo Map. Rather than <script src> the Yahoo library on every page it seems more efficient to load this as part of my RJS partial ("on demand"). Is this possible? It doesn''t seem like it. Can <script src> be honored by a browser when returned from an AJAX call? When I load the Yahoo js library as part of the regular HTTP page it works fine. Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Carl Johnson wrote:> Is this possible? It doesn''t seem like it. Can <script src> be honored > by a browser when returned from an AJAX call?Don''t see why that wouldn''t work. Just pass back something like: script = document.createElement(''script''); script.id = ''newScript''; script.type = ''text/javascript''; script.src = ''yahoo_stuffs.js''; document.getElementsByTagName(''head'')[0].appendChild(script); or the shorter prototype way: new Insertion.Bottom(''id_of_place_u_want_it'', script) or the RJS way: insert RJS way here... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dave Coleman wrote:> or the shorter prototype way: > new Insertion.Bottom(''id_of_place_u_want_it'', script)guess thats really not shorter :-) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> or the RJS way: > > insert RJS way here...I''m using RJS. It''s quite simple actually... I have my Yahoo Map stuff all in a partial, so with RJS I simply have: def ymap render :update do |page| page.replace_html ''map'', :partial => ''ymap'', :locals => {:place => Place.find(params[:id])} end end The javascript include <script src> stuff is at the top of the partial. The browser doesn''t seem to be obeying it though. I''ll try some different methods such as what you suggested. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dave Coleman wrote:> Don''t see why that wouldn''t work. Just pass back something like: > > script = document.createElement(''script''); > script.id = ''newScript''; > script.type = ''text/javascript''; > script.src = ''yahoo_stuffs.js''; > document.getElementsByTagName(''head'')[0].appendChild(script);This does not seem to work. For one thing I can''t find any reference to "type" or "src" methods for DOM elements.> or the shorter prototype way: > > new Insertion.Bottom(''id_of_place_u_want_it'', script)This does not work either. Apparently prototype doesn''t support external scripts. There''s a patch for it but Rails/Prototype don''t seem to be interested: http://dev.rubyonrails.org/ticket/6722 It does work fine when I include the javascript on the original page whether a map is ever loaded or not, but there''s a noticeable hit on the page loading times. :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Carl Johnson wrote:> This does not seem to work. For one thing I can''t find any reference to > "type" or "src" methods for DOM elements.This works just fine. If you have firefox developer toolbar installed, go to the view source tab, then "view generated source" and it will show you that the <script> tag was appended to the bottom of the <head> tag. <html> <head> </head> <body> <script type="text/javascript"> script = document.createElement(''script''); script.id = ''newScript''; script.type = ''text/javascript''; script.src = ''yahoo_stuffs.js''; document.getElementsByTagName(''head'')[0].appendChild(script); </script> </body> </html> You are creating a new page element and assigning it to the variable script. id, type and src are attributes you''re setting on that page element object. you could do: script.madeupcrap = "stuff"; and it would write out an attribute like: <script type="text/javascript" madeupcrap="stuff"></script> Copy and paste the code into just an html doc and run it in your browser. If you''re scripts aren''t being eval-ed on return of your link_to_remote call, that might be the issue. Set your RJS return to do an alert or something to let you know the request was sent back: alert(''i worked, yay!''); or something. Also, the Firebug plugin for Firefox is great to debug ajax requests with. Shows you what happened round trip. Hope u get it working :-) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dave Coleman wrote:> Carl Johnson wrote: >> This does not seem to work. For one thing I can''t find any reference to >> "type" or "src" methods for DOM elements. > > > This works just fine. If you have firefox developer toolbar installed, > go to the view source tab, then "view generated source" and it will show > you that the <script> tag was appended to the bottom of the <head> tag.Yeah, it actually sort of works... but not with Safari. I found a couple threads on a Prototype mailing list discussing it. At any rate, I may just leave it in the original page. It should be cached I believe, so I''m now wondering if it''s worth all the trouble... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---