<?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>Jayway Team Blog &#187; javascript</title>
	<atom:link href="http://blog.jayway.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jayway.com</link>
	<description>Sharing Experience</description>
	<lastBuildDate>Sat, 28 Jan 2012 15:53:55 +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>Using JsViews + MVCHaack Prototype to update multiple records in ASP.NET MVC</title>
		<link>http://blog.jayway.com/2011/11/02/using-jsviews-mvchaack-prototype-to-update-multiple-records-in-asp-mvc/</link>
		<comments>http://blog.jayway.com/2011/11/02/using-jsviews-mvchaack-prototype-to-update-multiple-records-in-asp-mvc/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 09:25:23 +0000</pubDate>
		<dc:creator>Per Ökvist</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=10730</guid>
		<description><![CDATA[In this post we’ll take a look at two quite new things. JSViews and the MVCHaack prototype, in a simple scenario in which we’ll update multiple records in an mvc app. First what is what. Intro JsViews, is the next generation of jQuery templates and data link, divided in two parts JsRender and JsViews. On [...]]]></description>
			<content:encoded><![CDATA[<p>In this post we’ll take a look at two quite new things. JSViews and the MVCHaack prototype, in a simple scenario in which we’ll update multiple records in an mvc app.</p>
<p>First what is what.</p>
<h2>Intro</h2>
<p><strong>JsViews</strong>, is the next generation of jQuery templates and data link, divided in two parts JsRender and JsViews. On <a href="https://github.com/BorisMoore/jsviews">github</a> introduced as “<em>Interactive data-driven views, built on top of JsRender templates”. </em>For more info check out the blog <a href="http://www.borismoore.com/">Dancing with data</a> by Boris Moore.</p>
<p><strong>MvcHaack.Ajax</strong> is a <em>“proof-of-concept prototype” </em>by <a href="http://haacked.com/archive/2011/08/18/calling-asp-net-mvc-action-methods-from-javascript.aspx">Phil Haack</a><em>&#160;</em>to ease access to mvc actions from javascript. Available as a <a href="http://nuget.org/List/Packages/MvcHaack.Ajax">nuget package</a>. </p>
<h2>Demo</h2>
<p>To use this two in a update scenario we’re using a simple model of a Pizza.</p>
<pre class="brush: csharp;">    public class Pizza
    {
        public int Id { get; set; }

        [Required]
        public string Name { get; set; }

        public double Price { get; set; }

        public bool Available { get; set; }
    }</pre>
<p>We’ll scaffold the model, using <a href="http://nuget.org/List/Packages/MvcScaffolding">MvcScaffolding.</a></p>
<pre class="brush: csharp;">

Scaffold Controller Pizza –Repository

&#160;
</pre>
<p>So now we have the needed base to start using MvcHaack.Ajax.</p>
<p>We’ll edit the PizzaController to look like.</p>
<pre class="brush: csharp;">  public class PizzaController :  MvcHaack.Ajax.JsonController
    {
        private readonly IPizzaRepository pizzaRepository;

        public PizzaController(IPizzaRepository pizzaRepository)
        {
            this.pizzaRepository = pizzaRepository;
        }

        public IEnumerable&lt;Pizza&gt; List()
        {
            return this.pizzaRepository.All;
        }

        public object SaveList(List&lt;Pizza&gt; pizzas)
        {
            pizzas.ForEach(x =&gt; this.pizzaRepository.InsertOrUpdate(x));
            this.pizzaRepository.Save();

            return new { success = true, pizzas = pizzas };
        }

    }</pre>
<p>First thing to note is that we derive from a base controller from the MvcHaack library. Second we don’t return ActionResults. Other than that there isn’t much strange things going on. We’re using injection of IPizzaRepository here, if you like you could keep the instantiation of the repository generated by the scaffolding template.</p>
<p>Ok, now how do we put this to use and gain ease of access to this controller from jQuery ? </p>
<p>First we’ll need to add a special route (code shown using an area).</p>
<pre class="brush: csharp;">context.Routes.Add(new JsonRoute(&quot;json/{controller}&quot;));</pre>
<p>The we’re off to the client side! In our view we now add;</p>
<pre class="brush: csharp;">&lt;script src=&quot;/json/haack?json&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre>
<p>This is where the magic of MvcHaack comes in to play. This will generate an access point to our actions. Please take a look in the generated script. Its simple but as often with simple - useful.</p>
<p>This gives us the following access points to our actions. Neat!</p>
<pre class="brush: js;">

     $mvc.Pizza.List().success(function(data) {
                ....
     });


     $mvc.Pizza.SaveList(pizzasJson).success(function(data) {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ....&#160; &#160;&#160;&#160;&#160; });
</pre>
<p>Now we’ll switch over to put JsViews to use. First we’ll need some scripts for JsViews.</p>
<pre class="brush: js;">    &lt;script src=&quot;http://borismoore.github.com/jsviews/jsrender.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;http://borismoore.github.com/jsviews/jquery.observable.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;http://borismoore.github.com/jsviews/jquery.views.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;</pre>
<p>Then we’ll add a table to hold our pizzas and the a jQueryTemplate (JsRender) to display each pizza in edit mode. Then a save button.</p>
<pre class="brush: js;">&lt;button id=&quot;sendJson&quot;&gt;Send Json&lt;/button&gt;

&lt;table&gt;&lt;tbody id=&quot;editPizzaTable&quot;&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;script id=&quot;editRowTmpl&quot; type=&quot;text/x-jquery-tmpl&quot;&gt;
&lt;tr&gt;
    &lt;td data-getfrom=&quot;[Name]&quot; /&gt;
    &lt;td&gt;
        &lt;input data-getfrom=&quot;[Name]&quot; data-to=&quot;[Name]&quot; /&gt;
    &lt;/td&gt;
&lt;/tr&gt;
&lt;/script&gt;</pre>
<p>Ok, this ain’t an ordinary template. It contains some JsViews binding specific attributes. This from and to attributes lets you track changes to your json object that we bound to template. Note that I only show Name here, you could add the other properties too.</p>
<p>And now how do we bind to this template ? Simple;</p>
<pre class="brush: js;">$(&quot;#editPizzaTable&quot;).link(pizzas, &quot;#editRowTmpl&quot;);</pre>
<p>The magic lies in the link operator here, that tells JsViews to track changes to our pizzas. Interested or confused ? Check out <a href="http://borismoore.github.com/jsviews/demos/jQueryConfDemosOct2011/index.html">Booris samples</a> to get the whole picture.</p>
<p>So all we need to do is tie this two things together. My demo module looks like.</p>
<pre class="brush: js;">if (!Jayway) { var Jayway = {}; }
if (!Jayway.Demos) { Jayway.Demos = {}; }

Jayway.Demos = lib(function () {
    var app = {
        pizzas: null
    };
    return {
        // Public functions
        init: function() {

            $mvc.Pizza.List().success(function(data) {
                app.pizzas = data;
                _render();

            });

            $('#sendJson').click(function() {
                $mvc.Pizza.SaveList(app.pizzas).success(function(data) {
                    alert(data.success);
                });
            });
        }
    };

    //Private
    function _render() {
        $(&quot;#editPizzaTable&quot;).link(app.pizzas, &quot;#editRowTmpl&quot;);
    }
} ());</pre>
<h2>Conclusion</h2>
<p>We looked at JsViews in a context where often <a href="http://knockoutjs.com/">Knockout</a> or <a href="http://documentcloud.github.com/backbone/">Backbone</a> could be mentioned. I’ll hope you’ll follow the project to see in what scenarios this could be helpful for you.</p>
<p>MvcHaack.Ajax is a prototype with a question attached. Would you like to see something like this in ASP.NET MVC 4 ?</p>
<p>It’s simple and does not interfere with other library choices, so I think that it would be a neat addition.</p>
<p>Enjoy!&#160; </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/11/02/using-jsviews-mvchaack-prototype-to-update-multiple-records-in-asp-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Changes From 1.4.2 to 1.6</title>
		<link>http://blog.jayway.com/2011/08/09/jquery-changes-from-1-4-2-to-1-6/</link>
		<comments>http://blog.jayway.com/2011/08/09/jquery-changes-from-1-4-2-to-1-6/#comments</comments>
		<pubDate>Tue, 09 Aug 2011 12:32:13 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Dynamic languages]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=9163</guid>
		<description><![CDATA[jQuery is a powerful library and it is possible to get by without using any of the new features. That&#8217;s why many of us just upgrade to a new version assuming that it is mostly bug and performance fixes. This is not the case. jQuery 1.4.2 was released in February 2010 and it&#8217;s been one [...]]]></description>
			<content:encoded><![CDATA[
<p>jQuery is a powerful library and it is possible to get by without<br />
using any of the new features. That&rsquo;s why many of us<br />
just upgrade to a new version assuming that it is mostly bug and<br />
performance fixes. This is not the case. jQuery 1.4.2 was released in<br />
February 2010 and it&rsquo;s been one and a half years and a number of<br />
releases since then.</p>
<p>I was going to write about the changes in 1.5 and 1.6, but I have<br />
noticed that many people have missed some of the new features of the 1.4<br />
releases. And by the way, all examples are written in Coffeescript.</p>
<h2>Selected changes from 1.4.2+</h2>
<h3><code>delegate()</code></h3>
<p>Most people know about <code>live()</code> and how it can be used to attach<br />
listeners to elements that don&rsquo;t yet exist in the DOM. <code>live()</code> has<br />
a younger brother that was born in 1.4.2 and he is called <code>delegate()</code>.<br />
<code>delegate()</code> is more powerful. It gives you more precision in<br />
where to attach the listener.  </p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --> </p>
<pre><tt>$<font color="#990000">(</font><font color="#FF0000">'.main-content'</font><font color="#990000">).</font><b><font color="#000000">find</font></b><font color="#990000">(</font><font color="#FF0000">'section'</font><font color="#990000">).</font>delegate <font color="#FF0000">'p'</font><font color="#990000">,</font> <font color="#FF0000">'click'</font><font color="#990000">,</font> <font color="#990000">-&gt;</font>
  $<font color="#990000">(</font><b><font color="#0000FF">this</font></b><font color="#990000">).</font>addClass <font color="#FF0000">'highlight'</font>
</tt></pre>
<p>As you can see above, <code>delegate()</code>, unlike <code>live()</code>, can be chained like<br />
normal jQuery calls.</p>
<h3><code>jQuery.now()</code>, <code>jQuery.type()</code> and <code>jQuery.parseXML()</code></h3>
<p>Nothing special here, just some utilities that are good to know about.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --> </p>
<pre><tt>$<font color="#990000">.</font><b><font color="#000000">now</font></b><font color="#990000">()</font> <b><font color="#000000">is</font></b> <font color="#990000">(</font><b><font color="#0000FF">new</font></b> <b><font color="#000000">Date</font></b><font color="#990000">()).</font><b><font color="#000000">getTime</font></b><font color="#990000">()</font> 

$<font color="#990000">.</font><b><font color="#000000">type</font></b><font color="#990000">(</font><font color="#FF0000">'hello'</font><font color="#990000">)</font> is <font color="#FF0000">'string'</font> 

xml <font color="#990000">=</font> <font color="#FF0000">"""</font>
<font color="#FF0000">&lt;rss version='2.0'&gt;</font>
<font color="#FF0000">&lt;channel&gt;</font>
<font color="#FF0000">&lt;title&gt;RSS Title&lt;/title&gt;</font>
<font color="#FF0000">&lt;/channel&gt;</font>
<font color="#FF0000">&lt;/rss&gt;</font>
<font color="#FF0000">"""</font>
xmlDoc <font color="#990000">=</font> $<font color="#990000">.</font>parseXML xml
<font color="#990000">(</font>$<font color="#990000">(</font>xmlDoc<font color="#990000">).</font>find <font color="#FF0000">'title'</font><font color="#990000">).</font><b><font color="#000000">text</font></b><font color="#990000">()</font> is <font color="#FF0000">'RSS Title'</font>
</tt></pre>
<p>All these utilities are interesting, but the truly good thing that came<br />
out of jQuery-1.5+ is <code>Deferred()</code>.</p>
<h3><code>Deferred()</code></h3>
<p>With the release of jQuery 1.5 the internal implementation of <code>$.ajax</code><br />
was changed to use <code>Deferred()</code>, and, even better, the implementation<br />
was deemed so useful, that it became part of the public API.</p>
<p>Here is how you can use it via the <code>$.ajax</code> method.</p>
<p>Declare a function hex that calls the <code>/hex</code> url on the server, which<br />
will return a hex value between <strong>00</strong> and <strong>FF</strong>.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --> </p>
<pre><tt>  hex <font color="#990000">=</font> <font color="#990000">-&gt;</font>
    $<font color="#990000">.</font>ajax <font color="#FF0000">{</font> url<font color="#990000">:</font> <font color="#FF0000">'/hex'</font> <font color="#FF0000">}</font>
</tt></pre>
<p>Call the function multiple times, and you get a new <code>Deferred</code> back for<br />
each call. Notice the lack of handlers for the calls.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --> </p>
<pre><tt>  red <font color="#990000">=</font> <b><font color="#000000">hex</font></b><font color="#990000">()</font>
  green <font color="#990000">=</font> <b><font color="#000000">hex</font></b><font color="#990000">()</font>
  blue <font color="#990000">=</font> <b><font color="#000000">hex</font></b><font color="#990000">()</font>
</tt></pre>
<p>Attach handlers to each of the <code>Deferred</code>s to do something useful with<br />
the returned value. Notice the use of <code>done</code> instead of <code>success</code>.<br />
<code>success</code> is deprecated and will be removed in 1.8.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --> </p>
<pre><tt>  red<font color="#990000">.</font><b><font color="#000000">done</font></b> <font color="#990000">(</font>hh<font color="#990000">)-&gt;</font>
    $<font color="#990000">(</font><font color="#FF0000">"#r"</font><font color="#990000">).</font>css <font color="#FF0000">'background-color'</font><font color="#990000">,</font> <font color="#FF0000">"##{hh}0000"</font>
  green<font color="#990000">.</font><b><font color="#000000">done</font></b> <font color="#990000">(</font>hh<font color="#990000">)-&gt;</font>
    $<font color="#990000">(</font><font color="#FF0000">"#g"</font><font color="#990000">).</font>css <font color="#FF0000">'background-color'</font><font color="#990000">,</font> <font color="#FF0000">"#00#{hh}00"</font>
  blue<font color="#990000">.</font><b><font color="#000000">done</font></b> <font color="#990000">(</font>hh<font color="#990000">)-&gt;</font>
    $<font color="#990000">(</font><font color="#FF0000">"#b"</font><font color="#990000">).</font>css <font color="#FF0000">'background-color'</font><font color="#990000">,</font> <font color="#FF0000">"#0000#{hh}"</font>
</tt></pre>
<p>I am not limited to adding one handler, I can attach as many as I like.<br />
Here I attach another one for logging the success of the <code>red</code>-call.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --> </p>
<pre><tt>  red<font color="#990000">.</font><b><font color="#000000">done</font></b> <font color="#990000">(</font>hh<font color="#990000">)</font> <font color="#990000">-&gt;</font>
    console<font color="#990000">.</font><b><font color="#000000">log</font></b><font color="#990000">(</font>hh<font color="#990000">)</font>
</tt></pre>
<p>If this was all there was to it, I would be happy, but it is not by<br />
using the <code>$.when</code> method I get a new <code>Deferred</code> object that orchestrates<br />
multiple <code>Deferred</code>s in a very simple way. Let me create a color-<code>Deferred</code><br />
that waits for the others to return and then calls a new callback when<br />
they are all done.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --> </p>
<pre><tt>  color <font color="#990000">=</font> $<font color="#990000">.</font><b><font color="#000000">when</font></b><font color="#990000">(</font>red<font color="#990000">,</font> green<font color="#990000">,</font> blue<font color="#990000">)</font> 

  color<font color="#990000">.</font><b><font color="#000000">done</font></b> <font color="#990000">(</font>r<font color="#990000">,</font> g<font color="#990000">,</font> b<font color="#990000">)</font> <font color="#990000">-&gt;</font>
    $<font color="#990000">(</font><font color="#FF0000">"#color"</font><font color="#990000">).</font>css <font color="#FF0000">'background-color'</font><font color="#990000">,</font> <font color="#FF0000">"##{r[0]}#{g[0]}#{b[0]}"</font>
</tt></pre>
<p>The results from the requests are given in the same order as the<br />
<code>Deferred</code> objects are passed in. The results are given as an array with<br />
three arguments <code>[ data, &lsquo;success&rsquo; , deferred ]</code>.</p>
<p>You can see the example, a simple Sinatra app, in action on <a href="http://colors-deferred.herokuapp.com/">Heroku</a> and the source code can be found on <a href="https://github.com/andersjanmyr/colors">Github</a></p>
<p>Very nice! Apart from the examples I have shown, there are methods<br />
working with <code>Deferred</code>. Methods for creating, <code>jQuery.Deferred()</code>,<br />
resolving, <code>resolve(), resolveWith()</code>, and rejecting, <code>reject(),<br />
rejectWith()</code>.</p>
<p>To attach handlers to the events, you can use <code>done()</code> for resolve,<br />
<code>fail</code> for reject, <code>always()</code> for both resolve and reject. You can also<br />
use <code>then(doneCallback, failCallback)</code> to attach both a <code>done</code> and a<br />
<code>fail</code> handler with one call.</p>
<p><code>Deferred</code>s are really cool, check them out <a href="http://api.jquery.com/category/deferred-object/">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/08/09/jquery-changes-from-1-4-2-to-1-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;HTML5 &amp; MVC3&#8243; Debriefing</title>
		<link>http://blog.jayway.com/2011/05/28/html5-mvc3-debriefing/</link>
		<comments>http://blog.jayway.com/2011/05/28/html5-mvc3-debriefing/#comments</comments>
		<pubDate>Sat, 28 May 2011 13:55:03 +0000</pubDate>
		<dc:creator>Gustaf Nilsson Kotte</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Dynamic languages]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=8545</guid>
		<description><![CDATA[Recently, Jayway hosted the seminar "HTML5 &#38; MVC3" in Malmö and Stockholm. We also visited the SweNUG Linköping group and held our presentation there. In this post, we will give you links to some of the topics we covered. The presentation was first delivered on Techdays 2011, and we recommend you to look at that [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, Jayway hosted the seminar "HTML5 &amp; MVC3" in Malmö and Stockholm. We also visited the SweNUG Linköping group and held our presentation there. In this post, we will give you links to some of the topics we covered.</p>
<p>The presentation was first delivered on Techdays 2011, and we recommend you to look at <a href="http://blog.jayway.com/2011/03/30/techdays-2011-web-debriefing/">that blog post</a> first. Below, you'll find some additional links to topics covered during some of the presentation occations.</p>
<h2>The links</h2>
<p><a href="http://blogs.jetbrains.com/dotnet/2011/05/resharper-6-enhances-the-javascript-experience/">ReSharper 6</a><br />
Currently in "Early Access Program", with better IntelliSense and refactoring support for JavaScript and CSS in Visual Studio.</p>
<p><a href="http://www.youtube.com/watch?v=N8SS-rUEZPg">Chrome DevToolbar</a> (presentation at Google I/O)<br />
A lot is happening here and this tool is well worth to keep your eyes on.</p>
<p><a href="http://www.jslint.com/">JSLint</a><br />
Static code analysis for JavaScript</p>
<p><a href="http://wcf.codeplex.com/">WCF Web API</a><br />
We talked a bit about some of the features of WCF Web API, a.k.a." WCF Http"</p>
<p><a href="http://blog.paulbetts.org/index.php/2011/05/16/announcing-sassandcoffee-0-5/">SassAndCoffee</a><br />
This <a href="http://nuget.org/List/Packages/SassAndCoffee">NuGet package</a> makes it easier to get started with CoffeeScript and Sass in ASP.NET.</p>
<p><a href="http://msdn.microsoft.com/en-us/data/gg577609">Reactive Extensions (Rx) for JavaScript</a><br />
Compose asynchronous and event-based programs using observable collections and LINQ-style query operators.</p>
<p><a href="http://silk.codeplex.com/">Project Silk</a><br />
Web Application guidance from the Patterns &amp; Practices team at Microsoft.</p>
<p><a href="http://html5boilerplate.com/">HTML5 Boilerplate</a><br />
Gives you a good default when building HTML5 sites/apps. Also exists as a <a href="http://html5boilerplate.com/mobile/">mobile version</a>.<br />
<a href="http://knockoutjs.com/"></a></p>
<p><a href="http://knockoutjs.com/">Knockout<br />
</a>The MVVM pattern implemented in JavaScript.</p>
<p><a href="http://weblogs.asp.net/leftslipper/archive/2010/07/28/migrating-asp-net-mvc-2-applications-to-asp-net-mvc-3-preview-1.aspx">ASP.NET MVC Migration Tool<br />
</a>Help you with the migration between different versions of ASP.NET MVC.</p>
<p><a href="http://www.hanselman.com/blog/GlobalizationInternationalizationAndLocalizationInASPNETMVC3JavaScriptAndJQueryPart1.aspx">Localization</a><br />
Localization in the browser is harder than on the server. This blog post is a nice resource on the subject.</p>
<p><a href="http://andrescholten.net/track-site-speed-with-google-analytics-events/">Track site speed with Google Analytics</a><br />
When the "Network tab" is not enough. Lets you track the real loading time for your users.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/05/28/html5-mvc3-debriefing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CoffeeScript Goodies</title>
		<link>http://blog.jayway.com/2011/05/16/coffeescript-goodies/</link>
		<comments>http://blog.jayway.com/2011/05/16/coffeescript-goodies/#comments</comments>
		<pubDate>Mon, 16 May 2011 11:09:52 +0000</pubDate>
		<dc:creator>Gustaf Nilsson Kotte</dc:creator>
				<category><![CDATA[Dynamic languages]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=8363</guid>
		<description><![CDATA[A few weeks ago, it was announced that Ruby on Rails 3.1 will include jQuery, Sass (using SCSS) and CoffeeScript as default dependencies. Among these, CoffeeScript seems to be the controversial dependency, at least if you read the comments on the actual commit (check out the funny meme pictures). In this blog post, I'll try to [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, it was <a title="Rails 3.1 Adopts CoffeeScript, jQuery, Sass and.. Controversy" href="http://www.rubyinside.com/rails-3-1-adopts-coffeescript-jquery-sass-and-controversy-4669.html">announced</a> that Ruby on Rails 3.1 will include <a title="jQuery: The Write Less, Do More, JavaScript Library" href="http://jquery.com/">jQuery</a>, <a title="Sass - Syntactically Awesome Stylesheets" href="http://sass-lang.com/">Sass</a> (using SCSS) and <a title="CoffeeScript" href="http://jashkenas.github.com/coffee-script/">CoffeeScript</a> as default dependencies. Among these, CoffeeScript seems to be the controversial dependency, at least if you read the comments on the <a title="Commit 9f09aeb8273177fc2d09ebdafcc76ee8eb56fe33 to rails/rails - GitHub" href="https://github.com/rails/rails/commit/9f09aeb8273177fc2d09ebdafcc76ee8eb56fe33">actual commit</a> (check out the funny meme pictures).</p>
<p>In this blog post, I'll try to summarize my thoughts on CoffeeScript. The examples on the CoffeeScript homepage are excellent and this post should be seen as my comments to some of these examples. So far, I have only played around with CoffeeScript, to get a feel for the language, and I have enjoyed it a lot, to say the least. In short, CoffeeScript is basically just a thin layer of <a title="Syntactic sugar - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Syntactic_sugar">syntactic sugar</a> over JavaScript, removing JavaScript's C-inheritage and compiling to JavaScript code that would validate with <a title="JSLint,The JavaScript Code Quality Tool" href="http://www.jslint.com/">JSLint</a>. The CoffeeScript syntax feels like a good mix of Ruby, Python and JavaScript, with a little addition of C# and Haskell.</p>
<h2>What if I don't know JavaScript?</h2>
<p>"Do I need to learn JavaScript before CoffeeScript, if I don't know JavaScript?" In the end, you should definitely learn JavaScript if you don't know it, but I see no reason not to start with CoffeeScript and see how the generated JavaScript looks like, knowing that you have a knowledge gap in <em>why</em> the generated code looks like it does. Then, I think you should read <a title="Amazon.com: JavaScript: The Good Parts (9780596517748): Douglas Crockford: Books" href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742">JavaScript: the Good Parts</a> and start to write JavaScript that passes JSLint. I guess it all boils down to if you want to learn something through an abstraction or not, and I believe you have enough experience to know for yourself how you learn most effectively. Remember to iterate, though.</p>
<h2>Whitespace vs. semi-colons and curlies</h2>
<p>The first thing you notice about CoffeeScript is that it lacks curly braces and semi-colons. Instead, CoffeeScript uses significant whitespace to delimit blocks of code, just like <a title="Python Programming Language – Official Website" href="http://www.python.org/">Python</a>, <a title="Haskell - HaskellWiki" href="http://www.haskell.org/haskellwiki/Haskell">Haskell</a> and some <a title="Lightweight syntax option in F# 1.1.12.3 - Don Syme's WebLog on F# and Related Topics - Site Home - MSDN Blogs" href="http://blogs.msdn.com/b/dsyme/archive/2006/08/24/715626.aspx">other </a><a title="The Official YAML Web Site" href="http://www.yaml.org/">languages</a>. If you're not used to this, this feature of the language is going to bite you first.</p>
<h2>Functions</h2>
<p>Please notice how slick it is to define functions in CoffeeScript:</p>
<pre>add = (x, y) -&gt; x + y
square = (x) -&gt; x * x</pre>
<p>If you know C#, this syntax is very similar to C#'s lambda syntax:</p>
<pre>var add = (x, y) =&gt; x + y
var square = x =&gt; x * x</pre>
<p>(Note that writing parenthesis around the argument(s) is mandatory in CoffeeScript, which is not the case for single argument lambdas in C#.)</p>
<p>When calling a function, parentheses are optional and arguments are separated with commas (like Ruby):</p>
<pre>two = add 1, 1
four = square 2</pre>
<h2>A Y combinator example</h2>
<p>Since <a title="JavaScript: The World's Most Misunderstood Programming Language" href="http://javascript.crockford.com/javascript.html">JavaScript has more in common with Lisp or Scheme than it has with C or Java</a>, the lightweight syntax of function definition in CoffeeScript is a big win. Also, since almost everything is an expression in CoffeeScript, <em>return</em> is seen much more seldom in CoffeeScript code than in JavaScript code. This example may be extreme, but look at the difference between the <a title="The Little JavaScripter" href="http://javascript.crockford.com/little.html">Y combinator</a> (Crockford's version) written in both JavaScript and CoffeeScript:</p>
<pre>// Y combinator in JavaScript
function Y(le) {
    return (function (f) {
        return f(f);
    }(function (f) {
        return le(function (x) {
            return f(f)(x);
        });
    }));
}</pre>
<pre># Y combinator in CoffeeScript
Y = (le) -&gt; ((f) -&gt; f(f))((f) -&gt; le (x) -&gt; f(f) x)</pre>
<p>If needed, <em>\</em> could be inserted to make the code a little bit more readable.</p>
<pre>Y = (le) -&gt; ((f) -&gt; f(f))\
    ((f) -&gt; le((x) -&gt; f(f)(x)))</pre>
<p>(If we would have omitted the <em>\</em>, then we would have gotten an compiler error, since Y would have been defined as only the first line of code and then CoffeeScript would have found the second line as mis-indented. You could also play around with placing the parenthesis differently, if you don't like to use <em>\</em>.)</p>
<h2>Other features</h2>
<p>Another CoffeeScript feature worth mentioning is <em><a title="List comprehension - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Array_comprehension">array comprehensions</a></em>. An array comprehension that prints the square of all the even numbers looks like this:</p>
<pre>numbers = (num * num for num in [1..100] when num % 2 == 0)</pre>
<p>As I see it, array comprehensions could be useful if you have very long lists and don't want to take the penalty of calling a function on each item, as you would do in for example jQuery, underscore.js or the native Array.forEach (implemented in some browsers).</p>
<p>Other features that I like are the <em>do</em> keyword and the fat arrow (=&gt;). Briefly, <em>do</em> helps you create closures in a loop, avoiding <a title="loops - Doesn't JavaScript support closures with local variables? - Stack Overflow" href="http://stackoverflow.com/questions/643542/doesnt-javascript-support-closures-with-local-variables">this problem</a>. The fat arrow (=&gt;) binds the value of <em>this</em> to the context that defines the function and <em>not</em> the context that calls the function (see why this is needed <a title="javascript - JS: var self = this? - Stack Overflow" href="http://stackoverflow.com/questions/337878/js-var-self-this">here</a>).</p>
<h2>Considerations</h2>
<p>As mentioned in <a title="Interview: Jeremy Ashkenas Talks About CoffeeScript" href="http://www.readwriteweb.com/hack/2011/01/interview-coffeescript-jeremy-ashkenas.php">this interview</a> with Jeremy Ashkenas, the creator of CoffeeScript, the drawback of using CoffeeScript is that you introduce a compile step, which makes it harder to debug. Though, Mozilla is hoping to provide better support for languages that compile to JavaScript in the future. I hope the other browser vendors follow that initiative.</p>
<p>And, of course, if you choose to use CoffeeScript in a project, you have yet another language for a new member of the team to learn. For experienced web developers this may not be an issue, but for developers that don't have that much experience in web development I guess that it could be frightening at first sight.</p>
<h2>Summary</h2>
<p>I really like my first impressions of CoffeeScript and I'm eager to learn more about it. Please do as I did and try the <a title="CoffeeScript" href="http://jashkenas.github.com/coffee-script/">embedded CoffeeScript interpreter</a> (under the "Try CoffeeScript" link) after reading the first examples.</p>
<p>And remember to have fun! <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>/<a title="Gustaf Nilsson Kotte (gustaf_nk) on Twitter" href="http://twitter.com/gustaf_nk">@gustaf_nk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/05/16/coffeescript-goodies/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Editable lines in Google Maps using the Javascript v3 API</title>
		<link>http://blog.jayway.com/2011/04/28/editable-lines-in-google-maps-using-javascript-v3-api/</link>
		<comments>http://blog.jayway.com/2011/04/28/editable-lines-in-google-maps-using-javascript-v3-api/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 06:48:04 +0000</pubDate>
		<dc:creator>Tobias Södergren</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=8222</guid>
		<description><![CDATA[The Google Maps Javascript API v3 provides overlays for drawing shapes, such as Polygons, Circles, Polylines and Rectangles. The shapes are not implicitly interactive in the respect that you cannot tell the shape to be 'editable' as you could in the Javascript v2 API (here's an example). To simulate the behavior using functionality provided by [...]]]></description>
			<content:encoded><![CDATA[<p>The Google Maps Javascript API v3 provides overlays for drawing shapes, such as Polygons, Circles, Polylines and Rectangles. The shapes are not implicitly interactive in the respect that you cannot tell the shape to be 'editable' as you could in the Javascript v2 API (<a href="http://gmaps-samples.googlecode.com/svn/trunk/poly/mymapstoolbar.html">here's an example</a>).</p>
<p/>
To simulate the behavior using functionality provided by maps v3 API, you'll need to find an element that supports the <code>drag</code> event, such as the <code>Marker</code> object. A marker has a position, a shape and provides events such as <code>click</code>, <code>dragstart</code>, <code>drag</code> and <code>dragend</code>.</p>
<h2>The code</h2>
<p>First off, we need to load the google maps API and specify which version to use. The code uses some extra goodies to calculate the length of the line, which is provided in the <code>geometry</code> library and it looks like this is available in the v3.3 of the API. Here's how to do specify this:</p>
<p/>
<pre class="brush:javascript; gutter:false">
   &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false&v=3.3"&gt&lt;/script&gt;
</pre>
<p/>
The complete code looks like:</p>
<pre class="brush:javascript; gutter:false; highlight: [62]">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"/&gt;
    &lt;style type="text/css"&gt;
        html {
            height: 100%
        }

        body {
            height: 100%;
            margin: 0px;
            padding: 0px
        }

        #map_canvas {
            height: 100%
        }
    &lt;/style&gt;
    &lt;script type="text/javascript"
            src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false&v=3.3"&gt;
    &lt;/script&gt;
    &lt;script type="text/javascript"&gt;
        var g = google.maps;
        function initialize() {
            var latlng = new g.LatLng(62.397, 12.644);
            var myOptions = {
                zoom: 4,
                center: latlng,
                mapTypeId: g.MapTypeId.ROADMAP
            };
            var map = new g.Map(document.getElementById("map_canvas"), myOptions);
            registerMapDragHandler(map);
        }

        function registerMapDragHandler(aMap) {

            var map = aMap;

            g.event.addListener(map, 'click', function(event) {
                createLineBeingDragged(map, event.latLng);
            });

            function createLineBeingDragged(map, pos) {
                var line = new g.Polyline({map: map, path: [pos, pos]});
                g.event.addListener(map, 'mousemove', function(event) {
                    line.getPath().setAt(1, event.latLng);
                });
                g.event.addListener(line, 'click', function(event) {
                    g.event.clearListeners(map, 'mousemove');
                    g.event.clearListeners(line, 'click');
                    createMarkersForLine(map, line);
                });

                function createMarkersForLine(map, line) {
                    var startMarker = createMarker(line, 0);
                    var endMarker = createMarker(line, 1);
                    startMarker.nextMarker = endMarker;
                    endMarker.previousMarker = startMarker;
                }

                function createMarker(line, pathPos) {
                    var position = line.getPath().getAt(pathPos);
                    var marker = new g.Marker({map: map, position: position, visible: true, flat: true, draggable: true, raiseOnDrag: false});

                    // Marker functions
                    marker.getPathIndex = function() {
                        if (this.previousMarker != null) {
                            return this.previousMarker.getPathIndex() + 1;
                        } else {
                            return 0;
                        }
                    }

                    marker.startDrag = function(pos) {
                        if (!marker.previousMarker || !marker.nextMarker) {
                            line.getPath().insertAt(marker.getPathIndex(), pos);
                            var newMarker = createMarker(line, marker.getPathIndex());
                            if (marker.nextMarker) {
                                newMarker.previousMarker = marker;
                                newMarker.nextMarker = marker.nextMarker;
                                newMarker.nextMarker.previousMarker = newMarker;
                                marker.nextMarker = newMarker;
                            } else {
                                newMarker.nextMarker = marker;
                                newMarker.previousMarker = marker.previousMarker;
                                newMarker.previousMarker.nextMarker = newMarker;
                                marker.previousMarker = newMarker;
                            }
                        }
                    }

                    marker.beingDragged = function() {
                        line.getPath().setAt(marker.getPathIndex(), marker.getPosition());
                    }

                    // Listeners
                    g.event.addListener(marker, 'dragstart', function(event) {
                        marker.startDrag(event.latLng);
                    });

                    g.event.addListener(marker, 'drag', function(event) {
                        marker.beingDragged();
                    });

                    g.event.addListener(marker, 'click', function(event) {
                        var length = g.geometry.spherical.computeLength(line.getPath()) / 1000;
                        var infoWindow = new g.InfoWindow(
                        {
                            content: "&lt;ul&gt;&lt;li&gt;Line length: " + length.toFixed(2) + " km&lt;/li&gt;"+
                                    "&lt;li&gt;Latitude: " + marker.getPosition().lat().toFixed(6) + "&lt;/li&gt;"+
                                    "&lt;li&gt;Longitude: " + marker.getPosition().lng().toFixed(6) + "&lt;/ul&gt;"
                        });
                        infoWindow.open(map, marker);
                    });

                    return marker;
                }
            }
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body onload="initialize()"&gt;
&lt;div id="map_canvas" style="width:100%; height:100%"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>To start drawing, click on the map to specify the starting point and move the mouse to the end point.</p>
<p>
The highlighted function is the most interesting. It creates a marker representing one segment of the path of a <code>PolyLine</code>. The marker knows about the previous and next marker and calculates its position in the <code>MVCArray</code> of the path so that it updates the geo-position of the correct segment. This is done by the <code>getPathIndex()</code> function added to the marker.</p>
<p/>
The <code>Marker.dragStart()</code> function checks whether the marker is the first or last marker in the path. If it is, a segment is added to the <code>PolyLine</code> at the geo-position where the drag starts, and a new marker is created representing the new segment. This means that the line is extended when dragging the end markers.</p>
<p/>
The <code>Marker.beingDragged()</code> function updates the position of the segment for the <code>PolyLine</code> to the geo-position for the marker, which makes the segment 'editable'.</p>
<p/>
When clicking on a marker, the length of the line is computed using the <code>google.maps.geometry.spherical.computeLength()</code> function and an <code>InfoWindow</code> is shown displaying the length and the longitude/latitude for the selected marker.</p>
<h2>Conclusion</h2>
<p>It is possible to simulate the older Google Maps Javascript V2 functionality for editing shapes but it requires you to write your own editing functionality. The code above is just a proof-of-concept and needs a lot more love and caring to be useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/04/28/editable-lines-in-google-maps-using-javascript-v3-api/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>App Attack &#8211; three teams, three solutions</title>
		<link>http://blog.jayway.com/2011/04/15/app-attack-three-teams-three-solutions/</link>
		<comments>http://blog.jayway.com/2011/04/15/app-attack-three-teams-three-solutions/#comments</comments>
		<pubDate>Fri, 15 Apr 2011 07:07:49 +0000</pubDate>
		<dc:creator>Andreas Hallberg</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[windows phone 7]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=7934</guid>
		<description><![CDATA[What happens when you give three small teams ninety minutes, one loosely worded spec and no rules? Read on. We developers instinctively focus on the code. It must be testable, decoupled, beautiful, robust, and (here’s the thing) it should hopefully do what it supposed to do. Let’s create a situation where, for once, only the [...]]]></description>
			<content:encoded><![CDATA[<p>What happens when you give three small teams ninety minutes, one loosely worded spec and no rules? Read on.</p>
<p>We developers instinctively focus on the code. It must be testable, decoupled, beautiful, robust, and (here’s the thing) it should hopefully do what it supposed to do. Let’s create a situation where, for once, only the “do what it’s supposed to do” part matters.</p>
<h2>The Background</h2>
<p>I used to be a Swedish-Russian interpreter in the Swedish Army, where we had to learn fluent Russian from scratch in about 10 months. We got it done with no social life and the ever present threat of failure, which would have forced us to endure an extra twelve months of army fun in <a href="http://en.wikipedia.org/wiki/Lapland_(region)">Lapland</a> or somewhere equally miserable.</p>
<p>But. We also had a secret weapon. The <em>word slip:</em></p>
<p><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_05211.jpg"><img style="padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="IMG_0521" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_0521_thumb.jpg" border="0" alt="IMG_0521" width="244" height="184" /></a><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_05221.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="IMG_0522" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_0522_thumb.jpg" border="0" alt="IMG_0522" width="244" height="184" /></a></p>
<p>So simple, yet so powerful. Take a small piece of paper. Write the word in one language on one side, and the translation on the other side. A few hundred slips make a good sized stack. Flip through the stack, try to translate without cheating. Shuffle the stack. Gradually put aside the words you feel you know. Organize the slips as you wish. Repeat In Absurdum.</p>
<p>This seemed like the perfect little something that could be ported to the digital world in about 90 minutes by our red-hot coders… Or could it?</p>
<h2>The Spec</h2>
<p>Let’s put it on paper.</p>
<blockquote><p>As a user I want to be able to…</p>
<ul>
<li>
<div>Create/delete slips</div>
</li>
<li>
<div>Organize slips in stacks</div>
</li>
<li>
<div>Flip through a stack in both directions</div>
</li>
<li>
<div>Shuffle the stack</div>
</li>
</ul>
<p>… so that I can teach myself a crazy amount of words in the shortest time possible.</p>
<p>I don’t care which platform, technology or language you use. Just replace the paper slips with a digital equivalent, and make it work.</p>
<p>Tagging of stacks? Sharing stacks? Web backend, smart phone frontend? Go nuts, I don’t care.</p></blockquote>
<p>At one of our monthly competence development days I presented the challenge: "App Attack! Implement The Spec in ninety minutes!". Seven guys picked up the gauntlet. After having devoured The Spec, they formed into three teams of 2-2-3 persons. A (secret) prize was promised for the team coming up with the ‘best’ solution.</p>
<p>Now, ninety minutes in a swimming pool with poisonous jellyfish is an eternity, but ninety minutes trying to get something done in code is… perhaps too short. My helpful last-minute tips were greeted with the disdain only a manager can evoke. "You know, there's this thing called AppHarbor that..." "Yeah we're already running it on that now, thank you.".  "In case you were wondering, I... " "No, we're not. Go away.". Ah, those developers. Better leave them to it.</p>
<h2>The results</h2>
<p>It was time for the teams to strut their stuff.</p>
<h3>Team One</h3>
<p><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_05251.jpg"><img style="padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="IMG_0525" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_0525_thumb1.jpg" border="0" alt="IMG_0525" width="644" height="484" /></a></p>
<p>Sladjan explains his and <a href="http://blog.jayway.com/author/andreashammar/">Andreas</a>’s solution:<em> “The words are stored in xml-files together with the stack metadata, one file per stack. The idea was to be able to import words from your </em><a href="http://www.dropbox.com/"><em>Dropbox</em></a><em>; the phone app would read the files and show a list of all stacks.”</em></p>
<p>Now, the guys didn’t quite get the Dropbox-to-phone integration up and running and had to manually load the files into the phone. But they could present a WP7 app to flip through words with. They stressed the <em>“innovative design of the word presentation, with nice flip-animations”.</em> Yeah, don’t be shy.</p>
<p><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/SladAndyCards.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" title="SladAndyCards" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/SladAndyCards_thumb.png" border="0" alt="SladAndyCards" width="579" height="484" /></a></p>
<h3>Team Two</h3>
<p><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_0524.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="IMG_0524" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_0524_thumb.jpg" border="0" alt="IMG_0524" width="644" height="484" /></a></p>
<p>Johan and the other Andreas created a WPF client for the word input and, just as Team One, planned a Dropbox connection to a WP7 app. Alas, the Dropbox idea tripped up this team as well. With no connection between the input app and the phone, they too were forced to manually load the files into the phone.</p>
<p>Johan:<em> “We regretted not setting up a proper VCS repos, instead of just sharing files. It slowed us down.” </em></p>
<p><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/JohanAndAndreas.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="JohanAndAndreas" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/JohanAndAndreas_thumb.png" border="0" alt="JohanAndAndreas" width="260" height="484" /></a></p>
<p>A special feature of their WP7 app is to force the user to manually input the translation instead of trusting her with the ‘flip’. I guess they live by the “Trust is good, control is better” principle. Awesome.</p>
<h3>Team Three</h3>
<p><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_0515.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="IMG_0515" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_0515_thumb.jpg" border="0" alt="IMG_0515" width="364" height="484" /></a></p>
<p>The young guns, <a href="http://blog.jayway.com/author/petervonlochow/">Peter</a> and <a href="http://blog.jayway.com/author/gustafnilssonkotte/">Gustav</a>, with <a href="http://blog.jayway.com/author/perokvist/">Per</a> as the senior mentor, took quite a different approach than the other teams. Per: <em>“Our team set off to create the app building on plain HTML5 and JavaScript. Storing the data in local storage and having an animated UI via jQuery. With three code files and no compiling we had a neat setup, that quickly gave results.”</em></p>
<p>Venturing into JavaScript and HTML5 territory was a gutsy move, but would it work?</p>
<p>Here’s their modest UI. You’ll have to imagine the pink to green transition that (so realistically) mimics the ‘flip’:</p>
<p><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/app_attack_html5.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px; border-width: 0px;" title="app_attack_html5" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/app_attack_html5_thumb.png" border="0" alt="app_attack_html5" width="244" height="229" /></a></p>
<p>Besides the snafu of naming their app “App Attack!” (yeah, that’s like Roger Federer changing his name to "Wimbledon"), they got the job done quite nicely. The obvious drawback of their approach is the local storage, restricting the reading of words to the device (browser, really) in which they were created.</p>
<h2>And the Winner is…</h2>
<p>Well, there was only one team that got the thing working properly. Congratulations, Team Three! And don't eat all those candy bars before dinner now.</p>
<p><a rel="lightbox" href="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_05281.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="IMG_0528" src="http://blog.jayway.com/wordpress/wp-content/uploads/2011/04/IMG_0528_thumb.jpg" border="0" alt="IMG_0528" width="644" height="484" /></a></p>
<p>Good work guys!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/04/15/app-attack-three-teams-three-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TechDays 2011 Web Debriefing</title>
		<link>http://blog.jayway.com/2011/03/30/techdays-2011-web-debriefing/</link>
		<comments>http://blog.jayway.com/2011/03/30/techdays-2011-web-debriefing/#comments</comments>
		<pubDate>Wed, 30 Mar 2011 18:08:35 +0000</pubDate>
		<dc:creator>Gustaf Nilsson Kotte</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=7795</guid>
		<description><![CDATA[During the last two days of TechDays 2011 in Örebro, with the tagline 'the Cloud story', the term HTML5 was as frequently mentioned by speakers on some tracks as the word cloud was in other. Team .NET Web was represented by Gustaf (@gustaf_nk), Per (@per_okvist) and Karl (@herradriansson), with a session about our views on [...]]]></description>
			<content:encoded><![CDATA[<p>During the last two days of <a title="TechDays 2011" href="http://www.microsoft.com/sverige/techdays/" target="_blank">TechDays 2011</a> in Örebro, with the tagline 'the Cloud story', the term HTML5 was as frequently mentioned by speakers on some tracks as the word cloud was in other.</p>
<p>Team .NET Web was represented by Gustaf (<a title="@gustaf_nk" href="http://twitter.com/gustaf_nk" target="_blank">@gustaf_nk</a>), Per (<a title="@per_okvist" href="http://twitter.com/per_okvist" target="_blank">@per_okvist</a>) and Karl (<a title="@herradriansson" href="http://twitter.com/herradriansson" target="_blank">@herradriansson</a>), with a session about our views on modern web development. In this session we discussed HTML5, client architecture and ASP.NET MVC 3, among other related subjects.</p>
<p>In this post, as promised during the session, we will list and comment on some of the frameworks and utilities mentioned.</p>
<h2>Frameworks</h2>
<p>We touched on several server frameworks in addition to the usual suspects.</p>
<p><a title="WCF HTTP" href="http://wcf.codeplex.com/" target="_blank">WCF HTTP</a><br />
<a title="Fubu MVC" href="http://code.google.com/p/fubumvc/" target="_blank">Fubu MVC</a><br />
<a title="OpenRasta" href="http://openrasta.org/" target="_blank">OpenRasta</a><br />
<a title="Nancy" href="https://github.com/thecodejunkie/Nancy" target="_blank">Nancy</a></p>
<h2>HTML5 today</h2>
<p>Since the current features in HTML5 is implemented in different priorities browser to browser, we need some help of feature detection libraries and resources.</p>
<p><a title="Modernizr" href="http://www.modernizr.com/" target="_blank">Modernizr</a><br />
<a title="HTML5 Readiness" href="http://html5readiness.com/" target="_blank">HTML5 Readiness</a><br />
<a title="Graceful Degradation and Progressive Enhancement" href="http://www.graphicmania.net/graceful-degradation-and-progressive-enhancement/" target="_blank">Graceful Degradation and Progressive Enhancement</a></p>
<h2>JavaScript</h2>
<p>A good part of the session was spent on good practices about JavaScript architecture.</p>
<p><a title="yepnope.js" href="http://yepnopejs.com/" target="_blank">yepnope.js</a><br />
<a href="http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth">JavaScript Module Pattern: In-Depth</a><br />
<a href="http://stackoverflow.com/questions/4885366/javascript-module-pattern-with-jquery">Javascript Module Pattern with jQuery<br />
</a><a title="jQuery Templates" href="http://api.jquery.com/category/plugins/templates/" target="_blank">jQuery Templates</a><br />
<a title="An early look at jQuery UI Grid in ASP.NET" href="http://tpeczek.blogspot.com/2011/02/early-look-at-jquery-ui-grid-in-aspnet.html" target="_blank">An early look at jQuery UI Grid in ASP.NET</a><br />
<a title="JSON" href="https://github.com/douglascrockford/JSON-js" target="_blank">JSON</a></p>
<h2>NuGet</h2>
<p>Some of the frameworks used in the demo case was fetched using <a title="NuGet" href="http://nuget.org/" target="_blank">NuGet</a>.</p>
<p><a title="ASP.NET MVC HTML5 Helpers" href="http://mvchtml5.codeplex.com/" target="_blank">ASP.NET MVC HTML5 Helpers</a><br />
<a title="AutoFac" href="http://code.google.com/p/autofac/" target="_blank">AutoFac</a></p>
<h2>Compiled client code</h2>
<p>We discussed the possibilities with richer languages that compile to either CSS or JavaScript. Even though we didn't have time to show any usages of these during the session, we think that usages of such frameworks will increase in the near future.</p>
<p><a title="Sass" href="http://sass-lang.com/" target="_blank">Sass</a><br />
<a title="Compass" href="http://compass-style.org/" target="_blank">Compass</a><br />
<a title="LESS" href="http://lesscss.org/" target="_blank">LESS</a><br />
<a title="CoffeeScript" href="http://jashkenas.github.com/coffee-script/" target="_blank">CoffeeScript</a></p>
<h2>Finally</h2>
<p>Thank you for stopping by at our session and a big thank you to the TechDays staff for moving the session to a bigger room due to high demand.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2011/03/30/techdays-2011-web-debriefing/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Good Practices for Rich Web Applications</title>
		<link>http://blog.jayway.com/2010/08/16/good-practices-for-rich-web-applications/</link>
		<comments>http://blog.jayway.com/2010/08/16/good-practices-for-rich-web-applications/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 05:54:53 +0000</pubDate>
		<dc:creator>Anders Janmyr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=6046</guid>
		<description><![CDATA[Use jQuery jQuery is the best thing that has happened to Javascript since it got first class functions in version 1.2. The library is elegant, powerful and has exactly the right level of abstraction for working with the DOM. There is nothing more to say. Learn it and use it. Good resources are: the jQuery [...]]]></description>
			<content:encoded><![CDATA[<h2>Use jQuery</h2>
<p>jQuery is the best thing that has happened to Javascript since it got first class functions in version 1.2. The library is elegant, powerful and has exactly the right level of abstraction for working with the DOM. There is nothing more to say. Learn it and use it. Good resources are: <a href="http://api.jquery.com/l">the jQuery API</a>, <a href="http://dl.dropbox.com/u/7283184/jquery-api-1.4.2.html">my view of the jQuery API</a></p>
<h2>Learn Javascript</h2>
<p>Javascript is the <a href="http://oredev.org/2010/sessions/javascript-the-language-of-the-web">programming language of the web</a>. Learn it! Javascript is different from most other programming languages. It is dynamic, it has prototypical inheritance, and works more like Scheme than any of the languages that you are probably used to. If you want to learn Javascript you should get the following books, <a href="http://www.amazon.com/gp/product/0262560992?tag=thtasta-20">The Little Schemer</a>, <a href="http://www.amazon.com/gp/product/026256100X?tag=thtasta-20">The Seasoned Schemer</a>, <a href="http://www.amazon.com/gp/product/0596517742?tag=thtasta-20">Javascript, the Good Parts</a>, and possibly <a href="http://www.amazon.com/Performance-JavaScript-Faster-Application-Interfaces/dp/059680279X?tag=thtasta-20">High Performance Javascript</a></p>
<h2>Learn CSS</h2>
<p>Many programmers think that CSS is the language of designers and not programmers. This is not the case at all. If you are lucky enough to have a designer on your team (most people don't), CSS is the language with which you communicate. It is the interface between designers and programmers and as a programmer you should know it better than the designers. By knowing CSS well you will reduce the misunderstandings between you and your designer.</p>
<p>Unfortunately, many designers don't care about how code looks, as long as the design looks good on the surface. It will be up to you to make sure that the CSS doesn't get out out of hand. It will also be up to you to keep the HTML clean, and a good way to do this is to use semantic HTML, combined with CSS. You have no idea what the designers can come up with.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- </font></i>
<i><font color="#9A1900">  Old School rounded corners, invented by a GOOD designer. </font></i>
<i><font color="#9A1900">  All this code was actually needed to achieve the purpose.</font></i>
<i><font color="#9A1900">  --&gt;</font></i>
<b><font color="#0000FF">&lt;style&gt;</font></b>
<font color="#993399">.t</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">dot.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">repeat-x</font></i>; <font color="#0000FF">width:</font> <i><font color="#009900">20em</font></i><font color="#FF0000">}</font>
<font color="#993399">.b</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">dot.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">100%</font></i> <i><font color="#009900">repeat-x</font></i><font color="#FF0000">}</font>
<font color="#993399">.l</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">dot.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">repeat-y</font></i><font color="#FF0000">}</font>
<font color="#993399">.r</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">dot.gif</font></i>) <i><font color="#009900">100%</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">repeat-y</font></i><font color="#FF0000">}</font>
<font color="#993399">.bl</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">bl.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">100%</font></i> <i><font color="#009900">no-repeat</font></i><font color="#FF0000">}</font>
<font color="#993399">.br</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">br.gif</font></i>) <i><font color="#009900">100%</font></i> <i><font color="#009900">100%</font></i> <i><font color="#009900">no-repeat</font></i><font color="#FF0000">}</font>
<font color="#993399">.tl</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">tl.gif</font></i>) <i><font color="#009900">0</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">no-repeat</font></i><font color="#FF0000">}</font>
<font color="#993399">.tr</font> <font color="#FF0000">{</font><font color="#0000FF">background:</font> <i><font color="#009900">url</font></i>(<i><font color="#009900">tr.gif</font></i>) <i><font color="#009900">100%</font></i> <i><font color="#009900">0</font></i> <i><font color="#009900">no-repeat</font></i>; <font color="#0000FF">padding:</font><i><font color="#009900">10px</font></i><font color="#FF0000">}</font>
<b><font color="#0000FF">&lt;/style&gt;</font></b>
<b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"t"</font><b><font color="#0000FF">&gt;</font></b>
  <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"b"</font><b><font color="#0000FF">&gt;</font></b>
    <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"l"</font><b><font color="#0000FF">&gt;</font></b>
      <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"r"</font><b><font color="#0000FF">&gt;</font></b>
        <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"bl"</font><b><font color="#0000FF">&gt;</font></b>
          <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"br"</font><b><font color="#0000FF">&gt;</font></b>
            <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"tl"</font><b><font color="#0000FF">&gt;</font></b>
              <b><font color="#0000FF">&lt;div</font></b> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"tr"</font><b><font color="#0000FF">&gt;</font></b>
                Lorem ipsum dolor sit amet consectetur adipisicing elit
              <b><font color="#0000FF">&lt;/div&gt;</font></b>
            <b><font color="#0000FF">&lt;/div&gt;</font></b>
          <b><font color="#0000FF">&lt;/div&gt;</font></b>
        <b><font color="#0000FF">&lt;/div&gt;</font></b>
      <b><font color="#0000FF">&lt;/div&gt;</font></b>
    <b><font color="#0000FF">&lt;/div&gt;</font></b>
  <b><font color="#0000FF">&lt;/div&gt;</font></b>
<b><font color="#0000FF">&lt;/div&gt;</font></b>

</tt></pre>
<p>As an additional benefit you will become better at jQuery. Not only is CSS the query language of the browsers it is the query language of jQuery. Jariba!</p>
<p><a href="http://www.amazon.com/Bulletproof-Web-Design-flexibility-protecting/dp/0321509021?tag=thtasta-20">Bulletproof Web Design</a> is a good book web design, including CSS.</p>
<h2>Decide how "Rich" your application should be</h2>
<p>How rich should your application be? The scale varies from no Javascript to only Javascript, but you will probably want to land somewhere in between. Here are a few suggestions.</p>
<ul>
<li>No Javascript, everything is server generated.</li>
<li>Slightly enhanced pages, simple validations, but no Ajax.</li>
<li>Ajax enhanced pages, but every page still reloads frequently.</li>
<li>Single page per area, entire area is handled by Javascript.</li>
<li>Only Javascript, Ajax interaction with the server</li>
<li>Only Javascript, no interaction with the server.</li>
</ul>
<p>The important thing is to <em>make a decision</em>. If you don't make the decision, everyone will do different things on different parts of the application and you will loose consistency. In GUI, consistency is king. Make a decision and move on, you can always change your decision later.</p>
<h2>Organize your code</h2>
<h3>Javascript</h3>
<p>Make sure that all your Javascript code is namespaced properly. It is impolite to pollute the global namespace and it will bite you in the end. A simple variable declaration will do.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// Common namespace for your entire application</font></i>
<i><font color="#9A1900">// This declaration lets you split your code of multiple files.</font></i>
<i><font color="#9A1900">// If MyNamespace is defined use it, otherwise declare it.</font></i>
MyNamespace <font color="#990000">=</font> window.MyNamespace <font color="#990000">||</font> <font color="#FF0000">{}</font><font color="#990000">;</font>

</tt></pre>
<p>But, of course, it is also possible to get fancy and encapsulate the functions that you don't want to expose, if that is your cup of tea.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>MyNamespace <font color="#990000">=</font> window.MyNamespace <font color="#990000">||</font> <font color="#FF0000">{}</font><font color="#990000">;</font>

MyNamespace<font color="#990000">.</font>Tournament <font color="#990000">=</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
	<i><font color="#9A1900">// Private stuff</font></i>
	<b><font color="#0000FF">var</font></b> tournamentCount <font color="#990000">=</font> <font color="#993399">0</font><font color="#990000">;</font>
	<b><font color="#0000FF">function</font></b> <b><font color="#000000">addTournament</font></b><font color="#990000">(</font>tournament<font color="#990000">)</font> <font color="#FF0000">{</font>
		tournamentCount<font color="#990000">++;</font>
	<font color="#FF0000">}</font>

	<b><font color="#0000FF">return</font></b> <font color="#FF0000">{</font>
		<i><font color="#9A1900">//public stuff</font></i>
		numberOfTournaments<font color="#990000">:</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
			<b><font color="#0000FF">return</font></b> tournamentCount<font color="#990000">;</font>
		<font color="#FF0000">}</font>
	<font color="#FF0000">}</font>
<font color="#FF0000">}</font><font color="#990000">();</font>

</tt></pre>
<p>You should also separate your Javascript code into different files. The namespace idiom above helps to have the same namespace across multiple files. The same principles as with other type of code is valid with Javascript, organize the code by area, when it changes, where it is used, etc. Don't be afraid of the additional load time, splitting the files will give you. The files can easily be concatenated with tools  like <a href="http://rake.rubyforge.org/">Rake</a>, <a href="http://www.scons.org/">SCons</a>,  <a href="http://ant.apache.org/">Ant</a> or even a simple:</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt>$ cat file1<font color="#990000">.</font>js file2<font color="#990000">.</font>js file3<font color="#990000">.</font>js <font color="#990000">&gt;</font> all<font color="#990000">.</font>js

</tt></pre>
<p>They can also be compressed with <a href="http://www.crockford.com/javascript/jsmin.html">JSMin</a> or <a href="http://developer.yahoo.com/yui/compressor/">YUI Compressor</a>.</p>
<p><em>Optimize your environment for development, not for production!</em></p>
<h3>HTML</h3>
<p>HTML is code! Divide your pages into partials by responsibilities. It allows you to keep your pages DRY and readable. <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">The Single Responsibility Principle</a> applies to HTML too.</p>
<p>Make sure you keep the Javascript with the code that it manipulates. If you, for example, have a calendar partial that uses <a href="http://jqueryui.com/demos/datepicker/">jQuery DatePicker</a>, you have to make sure that the partial includes all the necessary Javascript to configure the calendar. Don't keep Javascript code in the page away from the partial. <a href="http://c2.com/cgi/wiki?CommonClosurePrinciple">Things that change together should be together</a>.</p>
<h3>CSS</h3>
<p>Stylesheets are code too. They should also be split into areas that allow you to easily find and navigate them. Use <a href="http://sass-lang.com/">Sass or SCCS</a> to keep your CSS files DRY. Sass is good for designers to. It gives them the ability to use variable names, mixins, etc. and simplifies their usage of semantic names such as <em>notice</em>, and <em>sidebar</em> instead of <em>yellow</em> and <em>left</em>.</p>
<p><em>Optimize your environment for development, not for production!</em></p>
<h2>Separate your Javascript from your HTML</h2>
<p>All too often I see generated HTML pages with Javascript code in them. Don't do it. Keep the HTML free from Javascript.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- DON'T DO THIS!  --&gt;</font></i>
<b><font color="#0000FF">&lt;button</font></b> <font color="#009900">id</font><font color="#990000">=</font><font color="#FF0000">'update-button'</font> <font color="#009900">onclick</font><font color="#990000">=</font><font color="#FF0000">"MyNamespace.updateList();"</font><b><font color="#0000FF">&gt;</font></b>Update List<b><font color="#0000FF">&lt;/button&gt;</font></b>

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// In the Javascript file for the page.</font></i>
MyNamespace<font color="#990000">.</font>updateList <font color="#990000">=</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font><font color="#990000">...</font><font color="#FF0000">}</font>

<font color="#990000">&lt;!--</font> DO THIS<font color="#990000">!</font> <font color="#990000">--&gt;</font>
<font color="#990000">&lt;</font>button id<font color="#990000">=</font><font color="#FF0000">'update-button'</font><font color="#990000">&gt;</font>Update List<font color="#990000">&lt;/</font>button<font color="#990000">&gt;</font>

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// In the Javascript file for the page.</font></i>
MyNamespace<font color="#990000">.</font>updateList <font color="#990000">=</font> <b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font><font color="#990000">...</font><font color="#FF0000">}</font>

$<font color="#990000">(</font><b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
  $<font color="#990000">(</font><font color="#FF0000">"#update-button"</font><font color="#990000">).</font><b><font color="#000000">click</font></b><font color="#990000">(</font><b><font color="#0000FF">function</font></b><font color="#990000">()</font> <font color="#FF0000">{</font>
    MyNamespace<font color="#990000">.</font><b><font color="#000000">updateList</font></b><font color="#990000">();</font>
  <font color="#FF0000">}</font><font color="#990000">);</font>
<font color="#FF0000">}</font><font color="#990000">);</font>

</tt></pre>
<p>It may seem like there is a lot more code in the good example, but notice the symmetry. The code that attaches the listener is in the same file as the code that uses the listener. This is good. Symmetry is good.</p>
<h3>Use clone()</h3>
<p>Separating the HTML and the Javascript goes both ways. Don't generate HTML code in Javascript. It doesn't matter that it is super simple to do it using <em>jQuery.html()</em>. Keep them separate, use <em>jQuery.clone()</em> instead.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// DON'T DO THIS</font></i>
$<font color="#990000">(</font><font color="#FF0000">"&lt;li data-id='123'&gt;My new item&lt;/li&gt;"</font><font color="#990000">).</font><b><font color="#000000">appendTo</font></b><font color="#990000">(</font><font color="#FF0000">"ul"</font><font color="#990000">);</font>
<i><font color="#9A1900">// OR THIS</font></i>
$<font color="#990000">(</font><font color="#FF0000">"ul"</font><font color="#990000">).</font><b><font color="#000000">append</font></b><font color="#990000">(</font><font color="#FF0000">"&lt;li data-id='123'&gt;My new item&lt;/li&gt;"</font><font color="#990000">);</font>

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- DO THIS --&gt;</font></i>
<b><font color="#0000FF">&lt;ul&gt;</font></b>
<b><font color="#0000FF">&lt;li</font></b> <font color="#009900">id</font><font color="#990000">=</font><font color="#FF0000">"list-template"</font> <font color="#009900">class</font><font color="#990000">=</font><font color="#FF0000">"template"</font><b><font color="#0000FF">&gt;</font></b>All .template are hidden (display: none) in the CSS<b><font color="#0000FF">&lt;/li&gt;</font></b>
<b><font color="#0000FF">&lt;/ul&gt;</font></b>

</tt></pre>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// AND THIS</font></i>
<b><font color="#0000FF">var</font></b> $clone <font color="#990000">=</font> $<font color="#990000">(</font><font color="#FF0000">"#list-template"</font><font color="#990000">).</font><b><font color="#000000">clone</font></b><font color="#990000">();</font>
$clone<font color="#990000">.</font><b><font color="#000000">attr</font></b><font color="#990000">(</font><font color="#FF0000">"data-id"</font><font color="#990000">,</font> <font color="#FF0000">"123"</font><font color="#990000">).</font><b><font color="#000000">text</font></b><font color="#990000">(</font><font color="#FF0000">"My new item"</font><font color="#990000">).</font><b><font color="#000000">removeClass</font></b><font color="#990000">(</font><font color="#FF0000">"template"</font><font color="#990000">);</font>
$<font color="#990000">(</font><font color="#FF0000">"ul"</font><font color="#990000">).</font><b><font color="#000000">append</font></b><font color="#990000">(</font>$clone<font color="#990000">);</font>

</tt></pre>
<p>The point of this is, again, to keep the HTML separate from the Javascript.</p>
<h2>Decide how content flows between, the page, Javascript and the Server.</h2>
<p>Once you have decided how rich your application should be, you have to decide on a method for moving the data between the HTML Page, Javascript and the Server. My preferred choice is to have every page that is served from the server include a <em>context object</em> with all the static data for the page and to have additional data that belongs to parts of the page be sent as <em>data-attributes</em> on the elements concerned.</p>
<p>The context object will contain all the data that is commonly needed in the page.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">// Sample context object that is generated with the page.</font></i>
MyNamespace <font color="#990000">=</font> MyNamespace <font color="#990000">||</font> <font color="#FF0000">{}</font><font color="#990000">;</font>
MyNamespace<font color="#990000">.</font>Context <font color="#990000">=</font> <font color="#FF0000">{</font>
  user<font color="#990000">:</font> <font color="#FF0000">{</font>
    id<font color="#990000">:</font> <font color="#FF0000">"28"</font><font color="#990000">,</font>
    name<font color="#990000">:</font> <font color="#FF0000">"Anders Janmyr"</font>
  <font color="#FF0000">}</font><font color="#990000">,</font>
  tournament<font color="#990000">:</font> <font color="#FF0000">{</font>
    id<font color="#990000">:</font> <font color="#FF0000">"78344"</font><font color="#990000">,</font>
    name<font color="#990000">:</font> <font color="#FF0000">"Fifa World Cup"</font>
  <font color="#FF0000">}</font>
<font color="#FF0000">}</font><font color="#990000">;</font>
</tt></pre>
<p>I use the context object(s) to keep state on the client to. If it is important that the page looks exactly the same, even if the user reloads the page, I make sure that the state I stick into my context object is synched back to the server. This can easily be done, asynchronously, with Ajax and does not affect performance noticeable.</p>
<p>Elements specific data is sent along with the element it defines.</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><i><font color="#9A1900">&lt;!-- Element specific data attached to the elements with data-attributes --&gt;</font></i>
<b><font color="#0000FF">&lt;ul</font></b> <font color="#009900">id</font><font color="#990000">=</font><font color="#FF0000">"tournament-menu"</font><b><font color="#0000FF">&gt;</font></b>
  <b><font color="#0000FF">&lt;li</font></b> <font color="#009900">data-id</font><font color="#990000">=</font><font color="#FF0000">"78344"</font> <font color="#009900">data-participant-count</font><font color="#990000">=</font><font color="#FF0000">"64"</font><b><font color="#0000FF">&gt;</font></b>Fifa World Cup<b><font color="#0000FF">&lt;/li&gt;</font></b>
  <b><font color="#0000FF">&lt;li</font></b> <font color="#009900">data-id</font><font color="#990000">=</font><font color="#FF0000">"666"</font>  <font color="#009900">data-participant-count</font><font color="#990000">=</font><font color="#FF0000">"44"</font><b><font color="#0000FF">&gt;</font></b>Americas Cup<b><font color="#0000FF">&lt;/li&gt;</font></b>
  <b><font color="#0000FF">&lt;li</font></b> <font color="#009900">data-id</font><font color="#990000">=</font><font color="#FF0000">"1464"</font> <font color="#009900">data-participant-count</font><font color="#990000">=</font><font color="#FF0000">"32"</font><b><font color="#0000FF">&gt;</font></b>Rugby World Cup<b><font color="#0000FF">&lt;/li&gt;</font></b>
<b><font color="#0000FF">&lt;/ul&gt;</font></b>

</tt></pre>
<p>The same argument as with the context object applies, as soon as I change an element in the GUI i need to feed that information back to the server. With elements I usually send the information to the server before updating the GUI, since element specific data is usually permanent data and not just session data.</p>
<p>An alternative solution to the <em>context object</em> above is to use the body element as the data-container, like this:</p>
<p><!-- Generator: GNU source-highlight 3.1.4<br />
by Lorenzo Bettini</p>
<p>http://www.lorenzobettini.it</p>
<p>http://www.gnu.org/software/src-highlite --></p>
<pre><tt><b><font color="#0000FF">&lt;body</font></b> <font color="#009900">data-user-id</font><font color="#990000">=</font><font color="#FF0000">"28"</font> <font color="#009900">data-user-name</font><font color="#990000">=</font><font color="#FF0000">"Anders Janmyr"</font> <font color="#009900">data-tournament-id</font><font color="#990000">=</font><font color="#FF0000">"78344"</font> <font color="#009900">data-tournament-name</font><font color="#990000">=</font><font color="#FF0000">"Fifa World Cup"</font><b><font color="#0000FF">&gt;</font></b>

</tt></pre>
<p>I tend to use the context object because I find it easier to add functionality to it than to the DOM element.</p>
<p>Only send the data that is needed to the client with the page. The rest of the data should be loaded on demand, with Ajax. Both JSON data and HTML templates can be loaded on demand. There is no need to deliver the entire page at once. Experiment and do what gives the best user experience.</p>
<h2>Use file watchers to speed up feedback</h2>
<p>If you compare the feedback cycle of Javascript and HTML development to Java and C# development, you are probably very happy with the short, tight feedback loop. This doesn't mean that you should be content. A feedback cycle cannot be too short.</p>
<p><a href="http://xrefresh.binaryage.com/">xrefresh</a> for Firefox and IE, and <a href="http://github.com/mockko/livereload">LiveReload</a> for Safari and Chrome, are a couple of tools that will tighten your feedback loop even more.</p>
<p>Both tools are file watchers that listen to changes for files and refresh the browser when they change. If you combine this with two screens, you will have one screen for the browser, that updates continuously, while you edit your code on the other screen. Fabulous!</p>
<h2>Conclusion</h2>
<p>Rich web applications are very close to the traditional client-server model. We have to keep state on the client side to give the user a good experience. At the same time the application state, and indeed the entire application, can be swept away by a click of a button or a page reload.</p>
<p>This puts new demands on us as developers. We have to realize that we are responsible for the entire application, not just the business logic, but the HTML and CSS too. More that anything, we have to realize that Javascript is a first class programming language with its own programming techniques, which we need to master to be able to develop good web applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2010/08/16/good-practices-for-rich-web-applications/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Creating a TinyMce plugin for a Wicket application</title>
		<link>http://blog.jayway.com/2009/10/07/creating-a-tinymce-plugin-for-a-wicket-application/</link>
		<comments>http://blog.jayway.com/2009/10/07/creating-a-tinymce-plugin-for-a-wicket-application/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 11:17:19 +0000</pubDate>
		<dc:creator>Rickard Nilsson</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tinymce]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=2009</guid>
		<description><![CDATA[I'm currently working on a web project based on Wicket. In this web project there was a request for a web based word processor. TinyMce fits the bill perfectly and as it happens is also integrated in Wicket. Lucky me! Another request required me to make my own plugin for TinyMce. Only, it turned out [...]]]></description>
			<content:encoded><![CDATA[<p>I'm currently working on a web project based on Wicket. In this web project there was a request for a web based word processor. TinyMce fits the bill perfectly and as it happens is also integrated in Wicket. Lucky me! </p>
<p>Another request required me to make my own plugin for TinyMce. Only, it turned out it's not the simplest thing to do, adding a plugin to TinyMce when it's integrated to Wicket. There is almost no help on how to do this so, after having fiddled with this for some time I thought I should help all other plugin creators out there.</p>
<p>Here we'll make a very redundant BoldMakerPlugin just because it's so easy to se it working. I'm assuming that you've got Wicket and also that you have managed to get TinyMce running, if you haven't it's just a matter of cut and paste from <a href="http://wicketstuff.org/confluence/display/STUFFWIKI/wicket-contrib-tinymce">WicketStuffs TinyMce page</a>. </p>
<p>To create a plugin you will need two files. Your plugin java file and an editor_plugin_src.js file. I placed my java file among the other wicket java files under src/main/java and named it BoldMakerPlugin.java. This is what it looks like.</p>
<p><code></p>
<pre class="java">&nbsp;
<span style="color: #a1a100;">import wicket.contrib.tinymce.settings.Plugin;</span>
<span style="color: #a1a100;">import wicket.contrib.tinymce.settings.PluginButton;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BoldMakerPlugin <span style="color: #000000; font-weight: bold;">extends</span> Plugin<span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> PluginButton boldMakerButton;
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> BoldMakerPlugin<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;boldmaker&quot;</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #808080; font-style: italic;">//decides which plugin folder to look in.</span>
		boldMakerButton = <span style="color: #000000; font-weight: bold;">new</span> PluginButton<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;boldmakerbutton&quot;</span>, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> PluginButton getBoldMakerButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> boldMakerButton;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p></code></p>
<p>Next I have to fool the TinyMce main script that my plugins JavaScript file is actually located in the same location as the other scripts. I do this by creating a package structure that is similar to what the TinyMce jar file uses. In this case I create a package called wicket.contrib.tinymce.tiny_mce.plugins.boldmaker and put it in src/main/resources. The last package should be similar to whatever you insert into your superclass from your java file.</p>
<p>In this location I put my editor_plugin_src.js file. Mine looks like this:</p>
<p><CODE></p>
<pre class="javascript">&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> DOM = tinymce.<span style="color: #006600;">DOM</span>;
&nbsp;
	tinymce.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'tinymce.plugins.BoldMakerPlugin'</span>, <span style="color: #66cc66;">&#123;</span>
		init : <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>ed, url<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> t = <span style="color: #000066; font-weight: bold;">this</span>, s = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;
&nbsp;
			t.<span style="color: #006600;">editor</span> = ed;
&nbsp;
			<span style="color: #009900; font-style: italic;">// Register commands</span>
			ed.<span style="color: #006600;">addCommand</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'mceBoldMaker'</span>, <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> win, de = DOM.<span style="color: #006600;">doc</span>.<span style="color: #006600;">documentElement</span>;
			<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #009900; font-style: italic;">// Register buttons</span>
			ed.<span style="color: #006600;">addButton</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'boldmakerbutton'</span>, <span style="color: #66cc66;">&#123;</span>title : <span style="color: #3366CC;">'Test'</span>, cmd : <span style="color: #3366CC;">'mceBoldMaker'</span>, image : url + <span style="color: #3366CC;">'/../test/img/example.gif'</span>,
         	   onclick: <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
         	   		ed.<span style="color: #006600;">selection</span>.<span style="color: #006600;">setContent</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;&lt;b&gt;&quot;</span> + ed.<span style="color: #006600;">selection</span>.<span style="color: #006600;">getContent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> + <span style="color: #3366CC;">&quot;&lt;/b&gt;&quot;</span><span style="color: #66cc66;">&#41;</span>;
            	<span style="color: #66cc66;">&#125;</span>
            <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #009900; font-style: italic;">// Register plugin</span>
	tinymce.<span style="color: #006600;">PluginManager</span>.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'boldmaker'</span>, tinymce.<span style="color: #006600;">plugins</span>.<span style="color: #006600;">BoldMakerPlugin</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p></CODE></p>
<p>Don't worry if you don't have a button image just yet, it'll be an invisible button with the plugin functionality.</p>
<p>After having done this you should compress it using some kind of JavaScript compressor. I used the one on <a href="http://javascriptcompressor.com/">http://javascriptcompressor.com/</a><br />
Create a new file, name it “editor_plugin.js” and paste your newly compressed JavaScript into it.</p>
<p>I'm adding my plugin in a InPlaceEditComponent instead of in a TextArea but the basics are the same. Add your plugin to the TinyMCESettings, add the settings to the component and then add your component to your page.</p>
<p><CODE></p>
<pre class="java">&nbsp;
InPlaceEditComponent component = <span style="color: #000000; font-weight: bold;">new</span> InPlaceEditComponent<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;editable&quot;</span>, <span style="color: #ff0000;">&quot;
&lt;h4 class='headline' style='color: black; font-weight: bold; font-family: sans-serif; font-size: 80%;'&gt;Insert headline here&lt;/h4&gt;
&nbsp;
&quot;</span> +
<span style="color: #ff0000;">&quot;&lt;span class='standardText' style='color: black; font-family: sans-serif; font-size: 80%;'&gt;Insert text here&lt;/span&gt;&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
TinyMCESettings settings=component.<span style="color: #006600;">getSettings</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
BoldMakerPlugin boldMakerPlugin=<span style="color: #000000; font-weight: bold;">new</span> BoldMakerPlugin<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
settings.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span>boldMakerPlugin.<span style="color: #006600;">getBoldMakerButton</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, Toolbar.<span style="color: #006600;">first</span>, <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3APosition+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">Position</span></a>.<span style="color: #006600;">before</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
component.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InPlaceEditBehavior<span style="color: #66cc66;">&#40;</span>settings, component<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
item.<span style="color: #006600;">add</span><span style="color: #66cc66;">&#40;</span>component<span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p></CODE></p>
<p>If you've done everything correctly you should now be able to run your application and get your very first plugin working.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2009/10/07/creating-a-tinymce-plugin-for-a-wicket-application/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wicket Javascript Internals dissected</title>
		<link>http://blog.jayway.com/2008/09/26/wicket-javascript-internals-dissected/</link>
		<comments>http://blog.jayway.com/2008/09/26/wicket-javascript-internals-dissected/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 13:20:25 +0000</pubDate>
		<dc:creator>Nino Martinez</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wicket]]></category>

		<guid isPermaLink="false">http://blog.jayway.com/?p=290</guid>
		<description><![CDATA[SO you need to do something special with a javascript and you want to integrate that with wicket. In my last article I looked at this from the wicket side and wrote about what you can do to push something out from wicket. But what if you want to interact? Then you will have to take a peek at wickets javascript internals. If you are working on an ajax component you get these wicket javascript source files included as default [...]]]></description>
			<content:encoded><![CDATA[<p>SO you need to do something special with a javascript and you want to integrate that with wicket. In my <a href="http://ninomartinez.wordpress.com/2008/09/09/apache-wicket-javascript-integration/">last article</a> I looked at this from the wicket side and wrote about what you can do to push something out from wicket. But what if you want to interact? Then you will have to take a peek at wickets javascript internals. If you are working on an ajax component you get these wicket javascript source files included as default:</p>
<ol>
<li>wicket-event.js</li>
<li>wicket-ajax.js</li>
</ol>
<h3>wicket-event.js</h3>
<p>This file contains everything Wicket needs for event handling, but also methods for detecting browser like Wicket.Browser.isIELessThan7() which could come in handy if youre doing your own script, no need to write it again.. </p>
<h3>wicket-ajax.js</h3>
<p>This file hold everything Wicket needs for doing ajax. So it's a big file containing a lot of interesting possibilities.</p>
<p>The most interesting method are wicketAjaxGet its the way to contact the server doing ajax. It's signature are this:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> wicketAjaxGet<span style="color: #66cc66;">&#40;</span>url, successHandler, failureHandler, precondition, channel<span style="color: #66cc66;">&#41;</span>
&nbsp;</pre>
<p>The first parameter are the url for wicketAjaxGet to call server side with, it usually gets generated from serverside, and you can add parameters to it and get them server side. Furthermore it takes 3 functions and a channel. Channel are also usually populated for you so dont think about that. The functions however are called either on sucess, failure or as a precondition. These supply very nice options for you if you need to do something special with the result of the wicketAjaxGet you can put in callbacks. Small example from the mooTip ajax integration:</p>
<pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> mootipAjaxtooltip022<span style="color: #66cc66;">&#40;</span>callback<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> content=<span style="color: #3366CC;">''</span>;wicketAjaxGet<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'?wicket:interface=:0:tooltip02::IBehaviorListener:1:'</span>,
 <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">var</span> tip=document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'mooTipContent'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">innerHTML</span>;
 <span style="color: #003366; font-weight: bold;">var</span> callbackInside=callback;
 <span style="color: #003366; font-weight: bold;">var</span> runCallback=  callbackInside.<span style="color: #006600;">pass</span><span style="color: #66cc66;">&#40;</span>tip<span style="color: #66cc66;">&#41;</span>;
 runCallback<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
, <span style="color: #003366; font-weight: bold;">null</span>,<span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre>
<p>As you can see, if you count the parameters, I put in a success method for wicket to call once the request has finished, in this case it sets up a tooltip and displays it, by a method thats passed along using the content of the dom element called 'mooTipContent'.</p>
<p>Theres also lighter methods like for example wicketHide and wicketshow. Methods for manipulating visibility of dom objects. Theres many more functions in there. But these should get you going.</p>
<h3>The complete package</h3>
<p>A small example that shows a invisible veil when a abstractajaxTimerEventBehavior is called:</p>
<pre class="javascript">&nbsp;
css/html:
#veil<span style="color: #66cc66;">&#123;</span>
position:absolute;top:<span style="color: #CC0000;">0</span>;left:<span style="color: #CC0000;">0</span>;
 width:<span style="color: #CC0000;">100</span>%;height:<span style="color: #CC0000;">100</span>%;
 z-index: <span style="color: #CC0000;">99</span>;
 <span style="color: #009900; font-style: italic;">/*cursor: wait;*/</span>
 <span style="color: #66cc66;">&#125;</span>
&lt;<span style="color: #3366CC;">&quot;p id=&quot;</span>veil<span style="color: #3366CC;">&quot; style='display: none;' &quot;</span>&gt;&lt;<span style="color: #3366CC;">&quot;/p&quot;</span>&gt;
Java:
		AbstractAjaxTimerBehavior ajaxTimerBehavior = <span style="color: #003366; font-weight: bold;">new</span> AbstractAjaxTimerBehavior<span style="color: #66cc66;">&#40;</span>
				Duration.<span style="color: #006600;">seconds</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			@Override
			<span style="color: #003366; font-weight: bold;">protected</span> CharSequence getCallbackScript<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// TODO Auto-generated method stub</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;wicketShow('veil');&quot;</span> + <span style="color: #003366; font-weight: bold;">super</span>.<span style="color: #006600;">getCallbackScript</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			@Override
			<span style="color: #003366; font-weight: bold;">protected</span> CharSequence getSuccessScript<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #009900; font-style: italic;">// TODO Auto-generated method stub</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;wicketHide('veil');&quot;</span> + <span style="color: #003366; font-weight: bold;">super</span>.<span style="color: #006600;">getSuccessScript</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
....
&nbsp;</pre>
<p>And thats it, now you should be ready to do your own stuff <img src='http://blog.jayway.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jayway.com/2008/09/26/wicket-javascript-internals-dissected/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

