<?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>Sentia &#124; Sydney IT Consultancy, Software Development, Ruby on Rails, Web Application Development, Rails Development, Test Driven Development, Microsoft.Net, Asp.Net , Agile, Continuous Integration Training, iPhone development &#187; javascript</title>
	<atom:link href="http://www.sentia.com.au/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sentia.com.au</link>
	<description>Sentia company website and blog about all things development, Ruby on Rails, Microsoft .Net, ASP.Net, C#.Net, Agile web development, Test Driven Development</description>
	<lastBuildDate>Thu, 02 Feb 2012 07:16:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Getting JQuery and Prototype to place nice</title>
		<link>http://www.sentia.com.au/2009/05/getting-jquery-and-prototype-to-place-nice/</link>
		<comments>http://www.sentia.com.au/2009/05/getting-jquery-and-prototype-to-place-nice/#comments</comments>
		<pubDate>Fri, 29 May 2009 05:11:02 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=274</guid>
		<description><![CDATA[If you want to use JQuery in your rails application &#8230; <a href="http://www.sentia.com.au/2009/05/getting-jquery-and-prototype-to-place-nice/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want to use JQuery in your rails application but still want prototype working as well there is a simple way to make sure they play nice and work side by side. All you have to do after you include your JQuery includes code is have the following</p>
<pre class="brush: ruby; title: ; notranslate">
  &lt;script&gt;
   var $j = jQuery.noConflict();
  &lt;/script&gt;
</pre>
<p>Now all you have to do to use jquery is use &#8220;$j&#8221; instead of just &#8220;$&#8221; and your good to go. To use just the standard prototype library is still just &#8220;$&#8221;. Simple isn&#8217;t it</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/05/getting-jquery-and-prototype-to-place-nice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open source flash charts like google analytics</title>
		<link>http://www.sentia.com.au/2009/03/open-source-flash-charts-like-google-analytics/</link>
		<comments>http://www.sentia.com.au/2009/03/open-source-flash-charts-like-google-analytics/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 22:02:48 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[charting]]></category>
		<category><![CDATA[flash charts]]></category>
		<category><![CDATA[google charts]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=187</guid>
		<description><![CDATA[We all want our charts to look like the ones &#8230; <a href="http://www.sentia.com.au/2009/03/open-source-flash-charts-like-google-analytics/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We all want our charts to look like the ones in google analytics. Well know there is a way the &#8220;Open Flash Chart&#8221; project. The guys over at <a href="http://pullmonkey.com">pull monkey</a> have released a plugin for rails that helps you get in these great charts. Ill be testing this plugin very soon and ill put up my experience and a little walk through. In the mean time if you want to check out the project have a look <a href="http://pullmonkey.com/projects/open_flash_chart2">here</a></p>
<p>Here is an example of what the charts look like</p>
<p><center><img src="http://sentia.com.au/wp-content/uploads/2009/03/picture-3.png" alt="picture 3 Open source flash charts like google analytics" title="Flash Chart" /></center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/03/open-source-flash-charts-like-google-analytics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Javascript Code for RJS Instead of IDs</title>
		<link>http://www.sentia.com.au/2009/03/using-javascript-code-for-rjs-instead-of-ids/</link>
		<comments>http://www.sentia.com.au/2009/03/using-javascript-code-for-rjs-instead-of-ids/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 11:47:24 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rjs]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=175</guid>
		<description><![CDATA[UPDATE: JavascriptGenerator has a method name literal that will do &#8230; <a href="http://www.sentia.com.au/2009/03/using-javascript-code-for-rjs-instead-of-ids/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p> UPDATE: JavascriptGenerator has a method name literal that will do the exact same thing, so the code below should do the trick:</p>
<pre class="brush: ruby; title: ; notranslate">
 page.insert_html :bottom, page.literal(&quot;$$('p.welcome b').first()&quot;), &quot;Some item&quot;
</pre>
<p>Bill Burhcam over at <a href="http://www.meme-rocket.com/2007/04/10/fight-id-proliferation-and-update-any-element-you-want/">Meme Rocket</a> made a post that *almost* solved a problem for me the other day. We&#8217;re currently doing some work that ends up creating html. Pretty standard stuff, but for a few reasons that aren&#8217;t really worth going into we can&#8217;t easily rely on our element ids being unique. The prototype functions &#8216;up&#8217; and &#8216;down&#8217; are perfect for this situation though.</p>
<p>So our problem basically boils down to this &#8211; RJS converts this code:</p>
<pre class="brush: ruby; title: ; notranslate">
page.insert_html :bottom, &quot;$$('p.welcome b').first()&quot;, &quot;Some item&quot;
</pre>
<p>into this javascript:</p>
<pre class="brush: jscript; title: ; notranslate">
 new Insertion.Bottom(&quot;$$('p.welcome b').first()&quot;, &quot;Some item&quot;
</pre>
<p>Because the $$(&#8216;p&#8230;&#8217;) is in quotes, Insertion.Bottom just looks for an element with that id. Which isn&#8217;t what we really wanted.</p>
<p>After digging around in the ActionView source for a while I found JavascriptGenerator::GeneratorMethods and its javascript_object_for method. It turns out that if you pass in a ActiveSupport::JSON::Variable then insert_html will behave how we want. So for the example above, the code below will work as expected.</p>
<pre class="brush: ruby; title: ; notranslate">
 js_literal = &quot;$$('p.welcome b').first()&quot; js_literal = ActiveSupport::JSON::Variable.new(js_literal) page.insert_html :bottom, js_literal, &quot;Some item&quot;
</pre>
<p>will output:</p>
<pre class="brush: ruby; title: ; notranslate">
 new Insertion.Bottom($$('p.welcome b').first(), &quot;Some item&quot;
</pre>
<p>Thank you open source. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/03/using-javascript-code-for-rjs-instead-of-ids/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ajax.Updater and javascript</title>
		<link>http://www.sentia.com.au/2009/03/ajaxupdater-and-javascript/</link>
		<comments>http://www.sentia.com.au/2009/03/ajaxupdater-and-javascript/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 10:33:35 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://sentia.com.au/?p=123</guid>
		<description><![CDATA[Ran into a little problem today which made me think &#8230; <a href="http://www.sentia.com.au/2009/03/ajaxupdater-and-javascript/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ran into a little problem today which made me think for a second. I have a Javascript function that runs once a calendar control is closed. It just passes a parameter to a action which renders a view nothing fancy.</p>
<p>So my onClose function looks like so</p>
<pre class="brush: jscript; title: ; notranslate">
function onClose(cal) {
	var p = cal.params;
	new Ajax.Updater('overlapping', '/visits/new', {
	  parameters: { start_date:  p.inputField.value; },
	  evalScripts: true
	});
	cal.hide();
};
</pre>
<p>This will fire once the calendar is closed. <strong>&#8216;Overlapping&#8217;</strong> is the ID of the Div ill be updating and <strong>&#8216;/visits/new&#8217;</strong> is the path of the action in your controller. This will then pass the start date param to the action which can then be used in the view. The problem l had is that l had some javascript on the partial that was not executing. Had to think for a minute and then it turned out that evalScripts is false by default thus the javascript was not executing.</p>
<p>So its as simple as having the following as a param in your Ajax.updater</p>
<pre class="brush: jscript; title: ; notranslate">
 evalScripts: true
</pre>
<p>Once you have done that your good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/03/ajaxupdater-and-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fixing the enter key in ASP.NET with jQuery</title>
		<link>http://www.sentia.com.au/2009/03/fixing-the-enter-key-in-aspnet-with-jquery/</link>
		<comments>http://www.sentia.com.au/2009/03/fixing-the-enter-key-in-aspnet-with-jquery/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 22:44:31 +0000</pubDate>
		<dc:creator>Michael Cindric</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.sentia.com.au/?p=100</guid>
		<description><![CDATA[One of the fundamental problems with ASP.NET WebForms is the &#8230; <a href="http://www.sentia.com.au/2009/03/fixing-the-enter-key-in-aspnet-with-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the fundamental problems with ASP.NET WebForms is the fact that you can only have one form per page. This jumps up and bites you when you have a set of fields and a button and you want the enter key to submit the form.</p>
<p>In ASP.NET 2.0 they came out with a &#8220;fix&#8221; for this. You can wrap your fields in a Panel and set the default button:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Panel ID=&quot;_pnlLogin&quot; DefaultButton=&quot;_btnLogin&quot; runat=&quot;server&quot;&gt;
    UserName: &lt;asp:TextBox ID=&quot;_txtUserName&quot; runat=&quot;server&quot; /&gt;
    Password: &lt;asp:TextBox ID=&quot;_txtPassword&quot; runat=&quot;server&quot; /&gt;
    &lt;asp:LinkButton ID=&quot;_btnLogin&quot; Text=&quot;Login&quot; runat=&quot;server&quot;/&gt;
&lt;/asp:Panel&gt;
</pre>
<p>Some of you will know limitation here. This works with a Button, but not a LinkButton. Let&#8217;s see why.<br />
Here is the resulting HTML:
</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div id=&quot;_pnlLogin&quot; onkeypress=&quot;javascript:return WebForm_FireDefaultButton(event, &amp;amp;#x27;_btnLogin&amp;amp;#x27;)&quot;&gt;
    UserName: &lt;input name=&quot;_txtUsername&quot; type=&quot;text&quot; id=&quot;_txtUsername&quot; /&gt;
    Password: &lt;input name=&quot;ctl00$mainContent$_txtPassword&quot; type=&quot;text&quot; id=&quot;_txtPassword&quot; /&gt;
    &lt;a id=&quot;_btnLogin&quot; href=&quot;javascript:__doPostBack('_btnLogin','')&quot;&gt;Login&lt;/a&gt;
&lt;/div&gt;
</pre>
<p><br/>The Panel renders as a div, and on any key pressed will call WebForm_FireDefaultButton: </p>
<pre class="brush: jscript; title: ; notranslate">
function WebForm_FireDefaultButton(event, target) {
    if (!__defaultFired &amp;amp;&amp;amp; event.keyCode == 13 &amp;amp;&amp;amp; !(event.srcElement &amp;amp;&amp;amp; (event.srcElement.tagName.toLowerCase() == &quot;textarea&quot;))) {
        var defaultButton;
        if (__nonMSDOMBrowser) {
            defaultButton = document.getElementById(target);
        } else {
            defaultButton = document.all[target];
        }
        if (defaultButton &amp;amp;&amp;amp; typeof(defaultButton.click) != &quot;undefined&quot;) {
            __defaultFired = true;
            defaultButton.click();
            event.cancelBubble = true;
        if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}
</pre>
<p><br/>This method checks for the enter key and then calls click on the default button. All good except for one thing: the LinkButton renders as an &#8220;a&#8221; tag.  Anchor tags don&#8217;t have a click() method unfortunately. At least not in Firefox.</p>
<p>So let&#8217;s fix it! I&#8217;ve recently been reading <a href="http://www.learningjquery.com/" title="Learning jQuery">&#8220;Learning jQuery&#8221;</a><br />
  which is a great book on this <a href="http://jquery.com/">cool javascript library</a>. I&#8217;ll use jQuery instead of straight javascript as it is much easier to write cross browser code and it&#8217;s a lot more concise. Plus there are heaps of plugins for it, and it&#8217;s a pretty small download for your page.</p>
<p>I want to improve the markup of my page at the same time so I&#8217;ll try to minimise the amount of server controls I use and get rid of that inline javascript call. My new aspx looks like this:</p>
<pre class="brush: xml; title: ; notranslate">&lt;div class=&quot;form&quot;&gt;
    UserName: &lt;asp:TextBox ID=&quot;_txtUsername&quot; runat=&quot;server&quot; /&gt;
    Password: &lt;asp:TextBox ID=&quot;_txtPassword&quot; runat=&quot;server&quot; /&gt;
    &lt;asp:LinkButton ID=&quot;_btnLogin&quot; Text=&quot;Login&quot; runat=&quot;server&quot; CssClass=&quot;form_submit&quot;/&gt;
&lt;/div&gt;
</pre>
<p><br/>So if I have a div with the class &#8220;form&#8221;, the default submit button is the first element with the &#8220;form_submit&#8221; class. Nice, simple and unobtrusive.</p>
<p>Here&#8217;s the javascript I ended up with:</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
    var $btn = $('.form_submit');
    var $form = $btn.parents('.form');

    $form.keypress(function(e){
        if (e.which == 13 &amp;amp;&amp;amp; e.target.type != 'textarea') {
            if ($btn[0].type == 'submit')
                $btn[0].click();
            else
                eval($btn[0].href);
            return false;
        }
    });
});
</pre>
<p>Basically it&#8217;s going to find any .form_submit elements, find a parent form, and add a keypress handler for the form. When the keypress is triggered, if it&#8217;s the enter key and we&#8217;re not in a textarea, we&#8217;ll click the default submit button if it IS a button, if it&#8217;s a link we&#8217;ll Eval the href attribute, which is going to be our javascript postback call.</p>
<p>Cool, I can keep it tucked away in an js file include, and i&#8217;ve improved my markup.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sentia.com.au/2009/03/fixing-the-enter-key-in-aspnet-with-jquery/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

