<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean&#039;s Blog &#187; javascript</title>
	<atom:link href="http://seanbehan.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Link to jQuery Source from Google&#8217;s CDN</title>
		<link>http://seanbehan.com/front-end-development/link-to-jquery-source-from-googles-cdn/</link>
		<comments>http://seanbehan.com/front-end-development/link-to-jquery-source-from-googles-cdn/#comments</comments>
		<pubDate>Sat, 28 May 2011 17:09:44 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Front End Development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tips & snippets]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[cdn]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[page load]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1324</guid>
		<description><![CDATA[https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js That is the link to the jQuery source hosted by Google on their CDN. It&#8217;s probably already cached on client machines so it should be as fast as is possible! You can read more/use other Javascript libs from Google&#8217;s CDN here: http://code.google.com/apis/libraries/devguide.html#jquery]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Ffront-end-development%2Flink-to-jquery-source-from-googles-cdn%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Link to jQuery Source from Google&#8217;s CDN" data-url="http://seanbehan.com/front-end-development/link-to-jquery-source-from-googles-cdn/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js</p>
<p>That is the link to the jQuery source hosted by Google on their CDN. It&#8217;s probably already cached on client machines so it should be as fast as is possible! You can read more/use other Javascript libs from Google&#8217;s CDN here: <a href="http://code.google.com/apis/libraries/devguide.html#jquery">http://code.google.com/apis/libraries/devguide.html#jquery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/front-end-development/link-to-jquery-source-from-googles-cdn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Execute Javascript When Using Link_to_function To Include a Partial in Rails</title>
		<link>http://seanbehan.com/javascript/execute-javascript-when-using-link_to_function-to-include-a-partial-in-rails/</link>
		<comments>http://seanbehan.com/javascript/execute-javascript-when-using-link_to_function-to-include-a-partial-in-rails/#comments</comments>
		<pubDate>Sat, 02 Oct 2010 23:34:02 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[link_to_function]]></category>
		<category><![CDATA[partial]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[replace_html]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=1220</guid>
		<description><![CDATA[If you use the link_to_function to replace content in a div with content from a partial, any javascript that you include in the partial will not be executed. It is instead included, but will do nothing. Obviously, this isn&#8217;t the desired behavior. Why would we be taking the trouble to write the javascript in the [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fjavascript%2Fexecute-javascript-when-using-link_to_function-to-include-a-partial-in-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Execute Javascript When Using Link_to_function To Include a Partial in Rails" data-url="http://seanbehan.com/javascript/execute-javascript-when-using-link_to_function-to-include-a-partial-in-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>If you use the link_to_function to replace content in a div with content from a partial, any javascript that you include in the partial will not be executed. It is instead included, but will do nothing. Obviously, this isn&#8217;t the desired behavior. Why would we be taking the trouble to write the javascript in the partial? There is an easy fix. Instead of writing out the script tags, instead use the javascript_tag  method to wrap whatever javascript you would like executed when the partial is loaded.</p>
<pre class="wp-code-highlight prettyprint">&amp;lt;%=link_to_function &quot;say hello&quot; {|p| p.replace_html &quot;container&quot;, :partial =&amp;gt; &quot;say_hello&quot; }%&amp;gt;</pre>
<p>And now in my say_hello.erb file</p>
<pre class="wp-code-highlight prettyprint">&amp;lt;% javascript_tag do %&amp;gt;
  alert(&quot;Hello World&quot;);
&amp;lt;% end %&amp;gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/javascript/execute-javascript-when-using-link_to_function-to-include-a-partial-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Onchange Event Fired from Select Field in Rails Form</title>
		<link>http://seanbehan.com/javascript/onchange-event-fired-from-select-field-in-rails-form/</link>
		<comments>http://seanbehan.com/javascript/onchange-event-fired-from-select-field-in-rails-form/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 15:45:21 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[carmen]]></category>
		<category><![CDATA[countries]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[onchange]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[states]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=840</guid>
		<description><![CDATA[In the view there is a regular Rails form and a javascript function that will be triggered when the country select field is changed. The javascript function will make an ajax request to the country_select url with the country code passed as the id variable, e.g., /country_code/us for the United States. I&#8217;m also using the [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fjavascript%2Fonchange-event-fired-from-select-field-in-rails-form%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Onchange Event Fired from Select Field in Rails Form" data-url="http://seanbehan.com/javascript/onchange-event-fired-from-select-field-in-rails-form/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>In the view there is a regular Rails form and a javascript function that will be triggered when the country select field is changed. The javascript function will make an ajax request to the country_select url with the country code passed as the id variable, e.g., /country_code/us for the United States. I&#8217;m also using the Carmen plugin for this example which will provide a list of countries and their respective states/provinces. Not all countries are full supported. More information on Carmen can be found at <a href="http://autonomousmachine.com/2009/4/1/carmen-a-rails-plugin-for-geographic-names-and-abbreviations">http://autonomousmachine.com/2009/4/1/carmen-a-rails-plugin-for-geographic-names-and-abbreviations</a> and <a href="http://github.com/jim/carmen">http://github.com/jim/carmen</a></p>
<pre class="wp-code-highlight prettyprint">&amp;lt;%form_for(@model) do |f| %&amp;gt;
&amp;lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot;&amp;gt;
  function change_state_select(state_code)
 {
    new Ajax.Request('/country_select/'+state_code,
    {
      method: 'get',
      onSuccess: function(transport) {
        $('state_select').replace(transport.responseText);
      }
    });
  }
 &amp;lt;/script&amp;gt;
 &amp;lt;%= f.select :country,
   Carmen::COUNTRIES,
   {},
   { :onchange =&amp;gt; &quot;change_state_select(this.options[this.selectedIndex].value);&quot; }
%&amp;gt;
&amp;lt;div id='state_select'&amp;gt;&amp;lt;/div&amp;gt;</pre>
<p>***Note the : onchange should really be one word but an emoticon shows up otherwise :onchange :(***<br />
Since not all countries are supported I need to execute some conditional logic in the action country_select. If the country is supported I&#8217;ll return a snippet of html containing a select field that my form will use. If the country is not supported I&#8217;ll return a text field so that the user can write in their state/province.</p>
<pre class="wp-code-highlight prettyprint">class CountrySelectController &amp;lt; ApplicationController
  def country_selecet
      begin
         @states = Carmen::states(params[:id])
      rescue
         @states = nil
      end
      render :partial =&amp;gt; &quot;country_select/states&quot;
  end
end</pre>
<p>In the final partial that is rendered there is either a select field or a text field</p>
<pre class="wp-code-highlight prettyprint">&amp;lt;div id=&quot;state_select&quot;&amp;gt;
  &amp;lt;% if @states.nil? %&amp;gt;
    &amp;lt;%= text_field_tag :model, :state %&amp;gt;
  &amp;lt;% else %&amp;gt;
    &amp;lt;%= select :model, :state, @states%&amp;gt;
  &amp;lt;% end %&amp;gt;
&amp;lt;/div&amp;gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/javascript/onchange-event-fired-from-select-field-in-rails-form/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Accessing Links in Nested TD Cells with Prototype</title>
		<link>http://seanbehan.com/javascript/accessing-links-in-nested-td-cells-with-prototype/</link>
		<comments>http://seanbehan.com/javascript/accessing-links-in-nested-td-cells-with-prototype/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 21:59:42 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[$$]]></category>
		<category><![CDATA[code optimization]]></category>
		<category><![CDATA[nested]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[td]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=618</guid>
		<description><![CDATA[There must be a better way to do the following with PrototypeJS. I want to loop over nested links inside of table td cells and apply a class to the row that the link is in when the link is clicked. If a user clicks on another link the class will be removed and applied [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fjavascript%2Faccessing-links-in-nested-td-cells-with-prototype%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Accessing Links in Nested TD Cells with Prototype" data-url="http://seanbehan.com/javascript/accessing-links-in-nested-td-cells-with-prototype/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>There must be a better way to do the following with PrototypeJS. I want to loop over nested links inside of  table td cells and apply a class to the row that the link is in when the link is clicked. If a user clicks on another link the class will be removed and applied to the current table row.</p>
<p>The code below works but I think it seems hackish. Any thoughts on improving this code?</p>
<p>Here is the link to the pastie <a href="http://pastie.org/703316">http://pastie.org/703316</a></p>
<pre class="wp-code-highlight prettyprint">
# This is the table with haml markup
%table
  %tr
    %td
       info
    %td
      = link_to &quot;be clicked&quot;, remote_request_goes_here_path
</pre>
<p>And the Js</p>
<pre class="wp-code-highlight prettyprint">
	$$(&quot;td.filter_link &gt; a&quot;).each(function(element){
		Event.observe(element, &quot;click&quot;, function(event){
			$$(&quot;td.filter_link&quot;).each(function(el){
				if(el != this){
					el.up().removeClassName(&quot;turnwhite&quot;);
				}
			});
                       // apply the turnwhite class to the table row
			this.up().up().addClassName(&quot;turnwhite&quot;);
		});
	});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/javascript/accessing-links-in-nested-td-cells-with-prototype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

