<?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>UXDriven &#187; dojo</title>
	<atom:link href="http://blog.uxdriven.com/tag/dojo/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.uxdriven.com</link>
	<description>Design. Build. Convert.</description>
	<lastBuildDate>Thu, 17 Sep 2009 18:58:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Making Your Own Growl Widget With Dojo</title>
		<link>http://blog.uxdriven.com/2009/09/08/making-your-own-growl-widget-with-dojo/</link>
		<comments>http://blog.uxdriven.com/2009/09/08/making-your-own-growl-widget-with-dojo/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 19:15:14 +0000</pubDate>
		<dc:creator>Eric</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.uxdriven.com/?p=14</guid>
		<description><![CDATA[Learn how to properly separate XHTML, CSS, and Javascript by creating
your own Growl Widget.

Demo


    
    
            // Since we're using CDN resources, we have to define any local
           [...]]]></description>
			<content:encoded><![CDATA[<p>Learn how to properly separate XHTML, CSS, and Javascript by creating
your own <a href="http://growl.info/screenshots.php">Growl</a> Widget.</p>

<h2>Demo</h2>

<div class="demo">
    <!-- Dojo Config -->
    <script type="text/javascript">
            // Since we're using CDN resources, we have to define any local
            // module paths first
            var djConfig = {
                // parseOnLoad: true,           // Look for dojo events/hooks
                // isDebug: true,               // Enable debugging
                baseUrl: "/static/js/uxdriven/dojo/",     // Base path for all modules
                modulePaths: {
                    demo: "demo"                // Path to "demo" namespace
                }
            };
    </script>

    <!-- Dojo Cross-Domain CDN (Dijits too!) -->
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js" type="text/javascript" charset="utf-8"></script>

    <!-- Include demo.ui.Error widget -->
    <link rel="stylesheet" href="/static/js/uxdriven/dojo/demo/ui/resources/Error.css" type="text/css" media="screen" charset="utf-8">
    <script type="text/javascript" charset="utf-8">
        dojo.require("demo.ui.Error");

        dojo.addOnLoad(function() {
            dojo.query('.demo form').connect('onsubmit', function(event) {
                event.preventDefault();

                new demo.ui.Error({
                    message: 'Please try your login again'
                });
            }).query('button').attr('innerHTML', 'Login')[0].removeAttribute('disabled');
        });
    </script>

    <form>
        <p>
            <em>Upon page load, this form no longer submits but displays a notification instead.</em>
        </p>

        <label>
            Username:
            <input type="text" name="username" value="uxdriven" />
        </label>

        <label>
            Password:
            <input type="password" name="password" value="password" />
        </label>

        <button type="submit" disabled="disabled">Waiting on Resources&#8230;</button>
    </form>
    
</div>

<p><span id="more-14"></span>
<a href="http://gist.github.com/183487">View Source</a></p>

<h2>Introduction</h2>

<p>Designing for code-reuse is one of the most important acquired skills
for a developer.  Unfortunately, Javascript widgets tend to contain
large amounts of embedded markup and styles.  I blame this primarily
on lackluster development &amp; deployment of client-side code, as well as
the fact that very few Javascript libraries are truly enterprise-ready
<!-- ([Javascript Frameworks in the Workplace][article]) -->.</p>

<p>In this tutorial, you&#8217;ll see some best-practices found in the <a href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js">Dojo Toolkit</a>
for name-spacing widgets and structuring resources.</p>

<h2><em>1</em> Requirements</h2>

<p>We want a growl widget that:</p>

<ul>
<li><strong>Will</strong> look good</li>
<li><strong>Will</strong> stack with other notifications</li>
<li><strong>Will</strong> disappear after a period of time</li>
<li><strong>Will</strong> close immediately of the user clicks it</li>
<li><strong>Will not</strong> disappear if the user hovers over it</li>
</ul>

<p><img src="http://blog.uxdriven.com/wp-content/uploads/2009/09/javascript_growl_screenshot.png" alt="Javascript Growl Screenshot" title="Javascript Growl Screenshot" /></p>

<h2><em>2</em> Marking it up</h2>

<p>The markup needed for the widget alone is simplistic; however, since we&#8217;re using
<a href="http://www.dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/writing-your-own-widget-class/template">dojo templating</a>, we need to add in just a little bit more code:</p>

<script src="http://gist.github.com/183202.js"></script>

<p>First, we&#8217;re tying mouse events <em>onMouseOver</em>, <em>onMouseOut</em> and <em>onClick</em> to the widget functions
<em>&#95;hoverOver</em>, <em>&#95;hoverOut</em> and <em>close</em>, respectively.</p>

<p>Second, we&#8217;re replacing our placeholder text with a template tag which will be replaced with the
variable <em>message</em> (more on this later).</p>

<h2><em>3</em> Styling the markup</h2>

<p>Since the markup is separate from the presentation, modifying the look-and-feel is a cinch.</p>

<script src="http://gist.github.com/183200.js"></script>

<h2><em>4</em> Scripting the widget</h2>

<script src="http://gist.github.com/183199.js"></script>

<h2><em>5</em> Calling the widget</h2>

<p>Include <a href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js">Dojo</a> and the script in your page:</p>

<pre><code>&lt;script src="/scripts/dojo/dojo.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;
&lt;script type="text/javascript" charset="utf-8"&gt;
    // Tell dojo where to find the "demo" namespace
    dojo.registerModulePath("demo", "/scripts/demo");

    // Require the notification script for this page
    dojo.require("demo.ui.Error");
&lt;/script&gt;
</code></pre>

<p>Now simply instantiate the class:</p>

<pre><code>new demo.ui.Error({
    message: "Howdy there!"
});
</code></pre>

<h2><em>6</em> Resources</h2>

<p>Here&#8217;s everything you need to get started:</p>

<ul>
<li><a href="http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojo/dojo.xd.js">Dojo Toolkit</a></li>
<li><a href="http://gist.github.com/183199">demo.error.ui.Error.js</a> (<a href="http://gist.github.com/183199/download">download</a>)</li>
<li><a href="http://gist.github.com/183202">demo.error.ui.templates.Error.html</a> (<a href="http://gist.github.com/183202/download">download</a>)</li>
<li><a href="http://gist.github.com/183200">demo.error.ui.resources.Error.css</a> (<a href="http://gist.github.com/183200/download">download</a>)</li>
<li><a href="http://gist.github.com/183487">Example</a> (<a href="http://gist.github.com/183487/download">download</a>)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.uxdriven.com/2009/09/08/making-your-own-growl-widget-with-dojo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
