<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Rails Forum - Ruby on Rails Help and Discussion Forum - Javascript widgets on external websites]]></title>
		<link>http://railsforum.com/viewtopic.php?id=16125</link>
		<description><![CDATA[The most recent posts in Javascript widgets on external websites.]]></description>
		<lastBuildDate>Wed, 29 Sep 2010 05:32:36 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Javascript widgets on external websites]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=131411#p131411</link>
			<description><![CDATA[<p>Really the solution was a lot barer than I believed. I didn&#039;t make that all I had to do was essentially spell code but using Javascript.</p>]]></description>
			<author><![CDATA[dummy@example.com (cyresjones)]]></author>
			<pubDate>Wed, 29 Sep 2010 05:32:36 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=131411#p131411</guid>
		</item>
		<item>
			<title><![CDATA[Re: Javascript widgets on external websites]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=98240#p98240</link>
			<description><![CDATA[<p>i&#039;m also trying to add a widget to external websites that will allows partners to add one line of html on to a website page to include the widget. using jonathanpg&#039;s basic concept, i am able to get the widget to show up on the external webpage. (right now i&#039;m actually this on localhost, but the idea stays the same)</p><p>this is the one-line of code inserted to the external webpage (technically, it&#039;s not 1 line, since i include some js libraries too).<br /><pre name="code" class="ruby:nogutter">&lt;script src=&#039;http://localhost:3000/browse/bar/1&#039; type=&#039;text/javascript&#039;&gt;&lt;/script&gt;</pre><br />there&#039;s some business logic processing, but here are the lines in the controller action browse/bar that adds the js to the external page.<br /><pre name="code" class="ruby:nogutter">a = escape_javascript(render_to_string(:partial =&gt; &#039;browse/restaurant_bar&#039;).delete!(&quot;\n&quot;))<br />render(:text =&gt; &quot;document.write(&#039;&quot; + a + &quot;&#039;);&quot;)</pre><br />where it fails, however, is when i use the widget to go back to the server and retrieve new information. at this point, i&#039;m just trying to get a &lt;div id=&quot;results&quot;&gt; tag to be updated when the form_remote_tag is submitted. here is the code from the restaurant_bar partial that i&#039;m inserting into the external webpage:<br /><pre name="code" class="ruby:nogutter">&lt;div id=&quot;results&quot;&gt;<br />&nbsp; Replace me<br />&lt;/div&gt;<br />&lt;% form_remote_tag :url =&gt; &#039;http://localhost:3000/browse/update/1&#039; do %&gt;<br />&nbsp; Fill in your info: <br />&nbsp; Date: &lt;%= select_month @r.datetime.month %&gt; &lt;%= select_day @reservation.datetime.day %&gt;<br />&nbsp; Time: &lt;%= select_hour @reservation.datetime.hour %&gt;<br />&nbsp; &lt;p&gt;&lt;%= submit_tag &#039;Check&#039;&nbsp; %&gt;&lt;/p&gt;&nbsp; &nbsp; <br />&lt;% end %&gt;</pre><br />all that browse/update doesn&#039;t do anything right now, though i have tried sticking in an explicit rendering of the rjs call:</p><p>here is the update.rjs template:<br /><pre name="code" class="ruby:nogutter">page.replace_html &#039;results&#039;, &#039;&lt;b&gt;f you&lt;/b&gt;&#039;</pre><br />when i submit from the form_remote_tag that i inserted into the external page, i get redirected to browse/update and this is displayed (as html).<br /><pre name="code" class="ruby:nogutter">try { Element.update(&quot;res_search_results&quot;, &quot;&lt;b&gt;f you&lt;/b&gt;&quot;); } <br />catch (e) { alert(&#039;RJS error:\n\n&#039; + e.toString()); alert(&#039;Element.update(\&quot;res_search_results\&quot;, \&quot;&lt;b&gt;f you&lt;/b&gt;\&quot;);&#039;); throw e }</pre><br />everything works fine if i just make the partial into a regular view and then submit the form_remote_tag from there. that leads me to believe that there&#039;s something going on with the javascript that&#039;s inserted into the browser. i used firebug to compare the ajax request form that was generated and it looks identical to what is generated when i copy the partial into a view. what am i not understanding?</p><p>sorry, for the long post. any help would be greatly appreciated.</p><p>-h</p>]]></description>
			<author><![CDATA[dummy@example.com (huberto)]]></author>
			<pubDate>Wed, 20 May 2009 20:08:51 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=98240#p98240</guid>
		</item>
		<item>
			<title><![CDATA[Re: Javascript widgets on external websites]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=75313#p75313</link>
			<description><![CDATA[<p>Actually the solution was a lot simpler than I thought. I didn&#039;t realise that all I had to do was basically write code but using Javascript.</p><p>So widget.js could read</p><p><pre name="code" class="javascript:nogutter">(function(){<br />document.write(&#039;Hello word&#039;)<br />})</pre><br />But obviously to use my apps data it needs to be slightly more advanced</p>]]></description>
			<author><![CDATA[dummy@example.com (fonziguy)]]></author>
			<pubDate>Wed, 17 Sep 2008 17:49:00 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=75313#p75313</guid>
		</item>
		<item>
			<title><![CDATA[Re: Javascript widgets on external websites]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=59401#p59401</link>
			<description><![CDATA[<p>I&#039;ve done something like this using a &lt;script src=&#039;widget_url&#039; type=&#039;text/javascript&#039;&gt;&lt;/script&gt; tag on the website.&nbsp; The controller method then uses <br /><pre name="code" class="ruby:nogutter">a = render_to_string(:partial =&gt; &#039;_partial_name&#039;).delete!(&quot;\n&quot;)<br />render(:text =&gt; &quot;document.write(&#039;&quot; + a + &quot;&#039;);&quot;)</pre><br />to render whatever partial is necessary and wrap it in the document.write() call.&nbsp; If there is javascript in the partial it may need to be escaped with escape_javascript().&nbsp; Styles can be written in &lt;style&gt;&lt;/style&gt; tags in the partial or can be &#039;included&#039; by loading the style document in the method: <br /><pre name="code" class="ruby:nogutter">@css = IO.readlines(File.join(RAILS_ROOT, &#039;app&#039;,&#039;views&#039;,&#039;path&#039;,&#039;to&#039;,&#039;styles.css&#039;)).join</pre><br />and then outputting it in the partial:<br /><pre name="code" class="ruby:nogutter">&lt;style&gt;<br />&lt;%= @css %&gt;<br />&lt;/style&gt;</pre><br />Actually, the javascript can be &#039;included&#039; in the same way in the partial.</p><p>I guess that was a quick &amp; dirty explanation of our method but hopefully it puts you on the right track.</p>]]></description>
			<author><![CDATA[dummy@example.com (jonathanpg)]]></author>
			<pubDate>Thu, 10 Apr 2008 16:33:54 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=59401#p59401</guid>
		</item>
		<item>
			<title><![CDATA[Javascript widgets on external websites]]></title>
			<link>http://railsforum.com/viewtopic.php?pid=55891#p55891</link>
			<description><![CDATA[<p>I&#039;m looking for a way of allowing users to add a Javascript widget to their website. This widget would ideally retrieve a value from a model of mine, based on the id entered. It would then generate the necessary CSS and HTML on the user&#039;s site to display the necessary content. (an example would be the &#039;Digg this&#039; widget)</p><p>Does anyone know of any good tutorials to do something like this?</p><p>Cheers</p>]]></description>
			<author><![CDATA[dummy@example.com (fonziguy)]]></author>
			<pubDate>Sat, 01 Mar 2008 15:45:36 +0000</pubDate>
			<guid>http://railsforum.com/viewtopic.php?pid=55891#p55891</guid>
		</item>
	</channel>
</rss>
