<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>danwebb.net - Home</title>
  <id>tag:www.danwebb.net,2010:mephisto/</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://www.danwebb.net/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.danwebb.net/" rel="alternate" type="text/html"/>
  <updated>2010-05-26T13:25:10Z</updated>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2010-05-26:3501</id>
    <published>2010-05-26T06:37:00Z</published>
    <updated>2010-05-26T13:25:10Z</updated>
    <category term="JavaScript"/>
    <category term="Projects"/>
    <category term="Rails"/>
    <category term="experiments"/>
    <category term="javascript"/>
    <category term="oembed"/>
    <category term="rails"/>
    <category term="twaudio"/>
    <link href="http://www.danwebb.net/2010/5/26/added-oembed-and-embeddable-player-to-twaud-io" rel="alternate" type="text/html"/>
    <title>Added OEmbed and Embeddable Player to twaud.io</title>
<content type="html">
            &lt;p&gt;I&#8217;ve just added &lt;a href=&quot;http://oembed.org&quot;&gt;OEmbed&lt;/a&gt; to &lt;a href=&quot;http://twaud.io&quot;&gt;twaud.io&lt;/a&gt; for fun and profit.  I&#8217;d not really looked into it until &lt;a href=&quot;http://dustindiaz.com&quot;&gt;Dustin&lt;/a&gt; and &lt;a href=&quot;http://twitter.com/dsa&quot;&gt;Russ&lt;/a&gt; pointed out and I really like the idea although it seems a bit under done at the moment (You can only have &#8216;image&#8217;, &#8216;video&#8217; or &#8216;rich&#8217; as media types.  What about audio?).  I&#8217;ve been meaning to implement an embeddable player for twaud.io for a long time so I decided to add them in.&lt;/p&gt;


	&lt;p&gt;The OEmbed endpoint is:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;http://twaud.io/oembed.{format}&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;It supports &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt;, XML and &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt;-P (if you provide a callback parameter to a json request).  For example:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;http://twaud.io/oembed.json?url=http%3A%2F%2Ftwaud.io%2FYf&#38;callback=myCallback&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;Returns this:&lt;/p&gt;


&lt;code&gt;&lt;pre&gt;myCallback({
  &quot;height&quot;:&quot;65&quot;,
  &quot;provider_url&quot;:&quot;http://twaud.io&quot;,
  &quot;title&quot;:&quot;Little mix of all the dubstep tunes I've been listening to lately: WRONG BEAT&quot;,
  &quot;type&quot;:&quot;rich&quot;,
  &quot;html&quot;:&quot;&amp;lt;iframe allowtransparency='true' frameborder='0' scrolling='no' src='http://twaud.io/embed/Yf' style='width: 395px;  height: 65px; border: none;'&amp;gt;&amp;lt;/iframe&amp;gt;\n&quot;,
  &quot;audio_type&quot;:&quot;audio/mpeg&quot;,
  &quot;audio_url&quot;:&quot;http://twaud.io/audio/Yf&quot;,
  &quot;width&quot;:&quot;395&quot;,
  &quot;author_name&quot;:&quot;danwrong&quot;,
  &quot;version&quot;:&quot;1.0&quot;,
  &quot;author_url&quot;:&quot;http://twitter.com/danwrong&quot;,
  &quot;provider_name&quot;:&quot;twaud.io&quot; 
});&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;The &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; property contains a snippet of &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; that renders the player:&lt;/p&gt;


&lt;p&gt;&amp;lt;iframe src=&quot;http://twaud.io/embed/Yf&quot;&gt;&amp;lt;/iframe&gt;&lt;/p&gt;

	&lt;p&gt;All very beta at the moment but give it a try.  Also, check the short dubstep mix I did a while back.  Will post a longer one soon.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2010-01-27:3441</id>
    <published>2010-01-27T14:55:00Z</published>
    <updated>2010-01-27T15:10:50Z</updated>
    <category term="JavaScript"/>
    <category term="html"/>
    <category term="html5"/>
    <category term="javascript"/>
    <link href="http://www.danwebb.net/2010/1/27/put-that-data-attribute-away-son-you-might-hurt-someone" rel="alternate" type="text/html"/>
    <title>Put that data-* attribute away, son...You might hurt someone</title>
<content type="html">
            &lt;p&gt;&lt;span class=&quot;caps&quot;&gt;HTML 5&lt;/span&gt; data-* attributes allow us to add &lt;a href=&quot;http://www.w3.org/TR/2009/WD-html5-20090825/dom.html#embedding-custom-non-visible-data&quot;&gt;custom attributes&lt;/a&gt; to elements as long as they are prefixed with &#8216;data-&#8217; and since this was first discussed on &lt;a href=&quot;http://ejohn.org/blog/html-5-data-attributes/&quot;&gt;John Resig&#8217;s blog&lt;/a&gt; I&#8217;ve been interested in how people will use and abuse this feature.  I greeted the feature with mixed feelings.  It&#8217;s definitely a simple way to enrich the semantic value of &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; pages as well as helping to improve some of the more &lt;a href=&quot;http://microformats.org/wiki/abbr-design-pattern&quot;&gt;toxic parts&lt;/a&gt; of Microformats.  &lt;span class=&quot;caps&quot;&gt;XML&lt;/span&gt; namespaces are definitely a more complete solution but this is a simple and immeadiately adoptable means to add invisible semantic data to &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; documents.&lt;/p&gt;


	&lt;p&gt;However, as John hinted in his post, there&#8217;s an enormous temptation for JavaScript authors to use this to embed configuration data for their scripts directly into &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;.  Many developers have been itching for an excuse to do this for a long time.  Some just added &lt;a href=&quot;http://alex.dojotoolkit.org/2007/09/slides-from-my-standards-heresy-talk/&quot;&gt;attributes willy-nilly&lt;/a&gt; like crazy web standards bandits, some would love to do add arbiturary configuration into their &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; but felt a bit squeamish about moving away from the &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; specs and opted to abuse the class attribute from within the standard.  For the record, I&#8217;d tend to side with the former.  If it works and there&#8217;s a good reason for it then I say do it.  However, back then I explained &lt;a href=&quot;http://www.danwebb.net/2007/10/7/custom-attributes-and-class-names&quot;&gt;why there is no good reason to add unsemantic configuration data into your &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;&lt;/a&gt; and now that we have standards-approved carte-blanche to do this I&#8217;d like to reiterate that it&#8217;s still not the way forward.  If you&#8217;ve not read that article then its worth a quick read before you go on.&lt;/p&gt;


	&lt;p&gt;By all means, use data-* attributes to add semantically valuable data to your &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; but if you are just using it to prop up a script you are writing &lt;strong&gt;think again&lt;/strong&gt;.&lt;/p&gt;


	&lt;h3&gt;An Example&lt;/h3&gt;


	&lt;p&gt;If you&#8217;ve not already watched it go now and watch &lt;a href=&quot;http://jquery14.com/day-11&quot;&gt;Yehuda&#8217;s Screencast on evented programming with jQuery&lt;/a&gt;.  The ideas in here represent a massive progression in client-side scripting.  It&#8217;s nothing short of essential viewing.  However, it also happens to be the latest example I&#8217;ve come across of needless use of data-* attributes and, while not wanting to take away from how progressive and clever the content is as a whole, I feel the need to use it as my counter-example for this article.&lt;/p&gt;


	&lt;p&gt;In the screencast, Yehuda is creating a tab interface.  The markup he proposes is something like this:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;ul class=&amp;quot;tabs&amp;quot;&amp;gt;
  &amp;lt;li data-content=&amp;quot;first&amp;quot;&amp;gt;First&amp;lt;/li&amp;gt;
  &amp;lt;li data-content=&amp;quot;second&amp;quot;&amp;gt;Second&amp;lt;/li&amp;gt;
  &amp;lt;li data-content=&amp;quot;third&amp;quot;&amp;gt;Third&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;

&amp;lt;div class=&amp;quot;pane&amp;quot; id=&amp;quot;first&amp;quot;&amp;gt;Some content&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;pane&amp;quot; id=&amp;quot;second&amp;quot;&amp;gt;Some content&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;pane&amp;quot; id=&amp;quot;third&amp;quot; class=&amp;quot;selected&amp;quot;&amp;gt;Some content&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The idea being that when the tab &amp;lt;li&amp;gt; is clicked the script then interrogates data-content to decide which div to show.  However, without the JavaScript operating on this the &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; has no semantical value.  The &amp;lt;li&amp;gt;s are just list elements (and will be read as such by assistive technologies).  In fact, the browser doesn&#8217;t know that those list elements are in anyway associated with &amp;lt;div&amp;gt;s below.  Here&#8217;s how I think it should be marked up:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;ul class=&amp;quot;section-nav&amp;quot;&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;#first&amp;quot;&amp;gt;First&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;#second&amp;quot;&amp;gt;Second&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;&amp;lt;a href=&amp;quot;#third&amp;quot;&amp;gt;Third&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;

&amp;lt;div class=&amp;quot;section&amp;quot; id=&amp;quot;first&amp;quot;&amp;gt;Some content&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;section&amp;quot; id=&amp;quot;second&amp;quot;&amp;gt;Some content&amp;lt;/div&amp;gt;
&amp;lt;div class=&amp;quot;section&amp;quot; id=&amp;quot;third&amp;quot;&amp;gt;Some content&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now, before we even add JavaScript we have links that we can click that will jump you to the specified content.  If you click the back button you will jump back to the previous tab&#8217;s content.  With this in place you could even make tabs work solely by using &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt; and the :target pseudo-selector.  If you wanted to go &lt;span class=&quot;caps&quot;&gt;HTML 5&lt;/span&gt; crazy you could even use &amp;lt;nav&amp;gt; and &amp;lt;section&amp;gt; elements which would further enhance the semantics of the document.  By correctly associating the tab link and the tab content we can take advantage of the browsers facilities to navigate this type of content even before we get out the old JavaScript crowbar.&lt;/p&gt;


	&lt;p&gt;With this markup as a base it&#8217;s then just as trivial to hook in the script but instead of interogatting data-content we just look at the anchor of the link.  Because we are now using anchors, users can deep link into a particular tab, it would be trivial to support the back button and assistive technologies will make better sense of it, amoung other things.&lt;/p&gt;


	&lt;h3&gt;Leave Yehuda Alone!&lt;/h3&gt;


	&lt;p&gt;Of course, I&#8217;m picking apart what was a very simple and purposefully contrived example, but as usage of data-* attributes picks up, it&#8217;s important to not abuse this facility and to continue find as many semantic hooks for your scripts as possible.  It may now be a &#8220;standard&#8221; but it doesn&#8217;t mean that its a good solution.  When looking for hooks for my scripts, this is the process I follow:&lt;/p&gt;


	&lt;p&gt;1. Build up your markup to be as meaningful as possible.  If it submits a request it should be a &amp;lt;form&amp;gt;, if its linking to another piece of content it&#8217;s an &amp;lt;a&amp;gt;.  Even if you&#8217;re building a very complex piece of UI seek to build as much of it as you can into your document (while keeping the semantics intact) before you go anywhere near your JavaScript.&lt;/p&gt;


	&lt;p&gt;2. Write your script to take advantage of the semantics your &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; document has to offer.  This will get you a long way in many cases, however, you may well find that there is still configuration information you need to pass into your script.  Rather than turn to data-* attributes its best to consider inferring this information via context in the same way that &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt; does.  This way you can assert things like &#8220;all &amp;lt;input&amp;gt;s with type &#8216;slider&#8217; and a class &#8216;day&#8217; have a min of 1 and a max of 31&#8221; then you can change this in one place rather than visiting each element&#8217;s data-* attributes individually.    &lt;a href=&quot;http://www.danwebb.net/2007/10/7/custom-attributes-and-class-names&quot;&gt;Read this article for more detail on how to do that&lt;/a&gt;. We don&#8217;t need to change the heading colour in every single heading element in our site now we have &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt;, let&#8217;s not start doing that kind of thing again now we have data-* attributes.&lt;/p&gt;


	&lt;p&gt;I welcome the data-* attribute.  It&#8217;s a simple and immediately useful method to add custom semantic data to &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; documents.  Just avoid using it to litter implementation-specific crap into your documents :)&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2009-07-02:3373</id>
    <published>2009-07-02T11:22:00Z</published>
    <updated>2009-07-02T11:32:57Z</updated>
    <category term="JavaScript"/>
    <category term="Low Pro"/>
    <category term="firefox"/>
    <category term="fix"/>
    <category term="javascript"/>
    <category term="lowpro"/>
    <link href="http://www.danwebb.net/2009/7/2/low-pro-for-prototype-and-firefox-3-5" rel="alternate" type="text/html"/>
    <title>Low Pro for Prototype and Firefox 3.5</title>
<content type="html">
            &lt;p&gt;Just a quick note for those googling for a solution to this.  Older versions of Low Pro for Protoype will be experiencing problems with behaviors in Firefox 3.5.  This issue has been fixed so pick up the latest version &lt;a href=&quot;http://github.com/danwrong/low-pro/raw/2f47a651ab1143b2e067de7d2381f615c389a14e/dist/lowpro.js&quot;&gt;from GitHub&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;An interesting upshot of this is that I found out something pretty nice which is kind of obvious but had never occurred to me before.  If you create a function in a closure then that function can refer to itself because it has access to that closure&#8217;s variables.  I normally use arguments.callee to get a reference to a function from within its body but there&#8217;s never really any need to do that:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;(function() {
  var aFunction = function() {
    aFunction.thing = 47;
  };

  aFunction();

  alert(aFunction.thing); //=&amp;gt; 47;
})();&lt;/code&gt;&lt;/pre&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2009-05-20:3360</id>
    <published>2009-05-20T13:29:00Z</published>
    <updated>2009-05-20T14:04:45Z</updated>
    <category term="Projects"/>
    <category term="Rails"/>
    <category term="massive robot"/>
    <category term="oauth"/>
    <category term="rails"/>
    <category term="twaudio"/>
    <category term="twitter"/>
    <link href="http://www.danwebb.net/2009/5/20/massive-robot-launches-twaud-io" rel="alternate" type="text/html"/>
    <title>Massive Robot launches twaud.io</title>
<content type="html">
            &lt;p&gt;Well, it&#8217;s been a bloody long while again since I&#8217;ve posted here and I suppose you&#8217;ve all unsubscribed me now.  To be honest, I wouldn&#8217;t blame you.&lt;/p&gt;


	&lt;p&gt;However, silence here does not mean that I&#8217;ve been sitting on my arse doing nothing.  In fact, the reality is very much to the contrary.  Loads of stuff has been going on but there are two new pieces of news.  Firstly, I&#8217;ve renamed and rebranded my company.  We are now &lt;a href=&quot;http://www.massiverobot.co.uk&quot;&gt;Massive Robot&lt;/a&gt; and we are available for consultancy and development work so if you have anything in mind then please contact us.  &lt;a href=&quot;http://josephmckernan.co.uk&quot;&gt;Joe&lt;/a&gt; has done the branding and it&#8217;s something I&#8217;m really pleased with.&lt;/p&gt;


	&lt;p&gt;Check the business cards&#8230;&lt;/p&gt;


	&lt;p&gt;&lt;img title=&quot;Massive Robot Business Cards&quot; src=&quot;http://www.danwebb.net/assets/2009/5/20/6640430.jpg&quot; alt=&quot;Massive Robot Business Cards&quot; /&gt;&lt;/p&gt;


&lt;p&gt;Along with those is a &lt;a href=&quot;http://massiverobot.co.uk&quot;&gt;new site&lt;/a&gt; and a T-shirt.  The final and most important Massive Robot branding will be the kicks.  I&#8217;m working on those at the moment.&lt;/p&gt;

	&lt;p&gt;&lt;img title=&quot;twaud.io&quot; src=&quot;http://twaud.io/images/logo.png?1242825321&quot; alt=&quot;twaud.io&quot; /&gt;&lt;/p&gt;


&lt;p&gt;This week launched &lt;a href=&quot;http://twaud.io&quot;&gt;twaud.io&lt;/a&gt;, Massive Robot&#8217;s new service.  The idea is simple &#8211; it&#8217;s like &lt;a href=&quot;http://twitpic.com&quot;&gt;twitpic&lt;/a&gt; but for audio.  Go to the site or use the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; to upload your audio and you get a page with a short &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; and a player for your followers to listen to it.  This is just the start and we are working on a whole load of new features for it so follow &lt;a href=&quot;http://twitter.com/twaudio&quot;&gt;@twaudio&lt;/a&gt; to keep up to date.&lt;/p&gt;

	&lt;p&gt;The build of twaud.io has been an interesting and fun experience.  I was able to use Twitter&#8217;s new OAuth based login process via &lt;a href=&quot;http://github.com/mbleigh/twitter-auth/tree/master&quot;&gt;twitter_auth&lt;/a&gt; which I&#8217;d recommend wholeheartedly for as a foundation for Twitter applications, although I have hacked to allow for both OAuth (for the site) and username/password based (for the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;) authentication where normally you must choose one or the other.  It also uses S3&#8217;s direct uploading facility via &lt;a href=&quot;http://swfupload.org&quot;&gt;SWFUpload&lt;/a&gt; which was not easy to get going but has provided a really scalable system as the application stays completely out of the loop of the bulky upload process. I love the direction web development is moving in at the moment.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2008-06-23:3342</id>
    <published>2008-06-23T22:56:00Z</published>
    <updated>2008-06-24T00:24:12Z</updated>
    <category term="Events"/>
    <category term="JavaScript"/>
    <category term="Low Pro"/>
    <category term="Misc"/>
    <category term="Rails"/>
    <category term="boring"/>
    <category term="bullshit"/>
    <category term="chitchat"/>
    <category term="donotread"/>
    <category term="events"/>
    <category term="general"/>
    <category term="lowpro"/>
    <category term="prattle"/>
    <category term="rack"/>
    <category term="rails"/>
    <category term="reproduction"/>
    <category term="speaking"/>
    <category term="work"/>
    <link href="http://www.danwebb.net/2008/6/23/it-s-been-a-long-time" rel="alternate" type="text/html"/>
    <title>It's Been A Long Time...</title>
<content type="html">
            &lt;p&gt;But I&#8217;ve not just been sitting on my arse playing &lt;span class=&quot;caps&quot;&gt;GTA IV&lt;/span&gt;, oh no.  Well, not all the time anyway.  The reason I&#8217;ve not posted anything (or been particularly active on the web in general) is that I&#8217;ve been damn busy.  Most importantly, Catherine kindly gave birth to our first son, &lt;a href=&quot;http://flickr.com/photos/danwebb/2361976989/&quot;&gt;Max&lt;/a&gt;, back in March which has been quite a change and sapped a lot of my hacking time.  I have to say though, despite the horror stories that many veteran parents like to feed you, our experience has only been good.  In fact, not good, great.  I recommend this reproducing lark.&lt;/p&gt;


	&lt;p&gt;Secondly, I&#8217;ve been hacking away nearly full time on one of my favourite projects to date, &lt;a href=&quot;http://peoplesmusicstore.com&quot;&gt;Peoples Music Store&lt;/a&gt; with &lt;span class=&quot;caps&quot;&gt;LRUG&lt;/span&gt; stalwart and renowned anarchist, &lt;a href=&quot;http://abscond.org&quot;&gt;James &#8216;Bringing London To Its Very Knees&#8217; Darling&lt;/a&gt; which is maturing nicely under private beta as we speak.  Peoples Music Store is a great idea from some of the guys behind &lt;a href=&quot;http://bleep.com&quot;&gt;bleep.com&lt;/a&gt; whereby users can construct and customise their very own download store from the music they love then get free music themselves if people buy from their store.  It&#8217;s a great way to both promote and show off you&#8217;re own music taste or in depth genre knowledge and find new music from stores you trust while getting some free digital swag along the way.  I&#8217;m probably not explaining it well so just drop me a line if you want and invite and the site will explain itself.  Public launch is coming in a month or so.&lt;/p&gt;


	&lt;p&gt;Building Peoples Music Store has been a great learning experience.  We run the site on a cloud computing platform and from content ingestion to audio preview delivery to application servers to download packaging and delivery everything has been designed to scale horizontally &#8211; and I&#8217;m pretty proud of it.  Thin, Rack, Sphinx, God, Starling and a whole load more cool open source gear is all running in there. I really need to get to blogging some of what I&#8217;ve discovered about working with &lt;a href=&quot;http://rack.rubyforge.org/&quot;&gt;Rack&lt;/a&gt;.  It simply is the dog&#8217;s bollocks.&lt;/p&gt;


	&lt;p&gt;So, enough of the excuses.  What&#8217;s on the horizon?&lt;/p&gt;


	&lt;h3&gt;Speaking and Conferences&lt;/h3&gt;


	&lt;p&gt;I&#8217;ve taken some time of speaking and conferencing in general so as to spend lots of time with Catherine and Max but come September I&#8217;m restarting the conference trail.  Firstly, I&#8217;m doing a presentation and a tutorial (with &lt;a href=&quot;http://jlaine.net&quot;&gt;Jarkko Laine&lt;/a&gt;) at RailsConf Europe all about JavaScript related Rails stuff and I&#8217;m likely to have a slot at &lt;a href=&quot;http://vivabit.com/atmediaajax&quot;&gt;@media Ajax&lt;/a&gt; as well.  Also, I&#8217;ll be heading to &lt;a href=&quot;http://2008.dconstruct.org&quot;&gt;dConstruct&lt;/a&gt; as is the tradition.&lt;/p&gt;


	&lt;h3&gt;Hacking and Open Source Business&lt;/h3&gt;


	&lt;p&gt;Although I&#8217;ve not commited to Low Pro or Low Pro JQ for a good while now they are both very much alive.  I&#8217;ve simply not come across anything that I&#8217;ve felt the need to add for a while.  If you have any suggestions or patches do let me know.  I&#8217;ve actually got time to commit them at the moment.  Another little project that I&#8217;m hoping to get off the ground is called &lt;strong&gt;Evil&lt;/strong&gt; which is going to contain lots of Merb/Rack goodness.  The first by-product of which is the &lt;a href=&quot;http://github.com/danwrong/merb_openid&quot;&gt;merb_openid&lt;/a&gt; gem for consuming OpenID in Merb apps (it&#8217;s still not quite production ready though so don&#8217;t go using it just yet).  I&#8217;ll let you know what Evil actually does when (or if) I actually get something working.&lt;/p&gt;


	&lt;p&gt;So, that&#8217;s all for now.  Just a bit of a status report.  I promise I&#8217;ll get some useful content written that you actually care about very soon.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2008-02-08:3047</id>
    <published>2008-02-08T13:10:00Z</published>
    <updated>2008-03-07T21:06:20Z</updated>
    <category term="Low Pro"/>
    <category term="javascript"/>
    <category term="jquery"/>
    <category term="lowpro"/>
    <link href="http://www.danwebb.net/2008/2/8/event-delegation-made-easy-in-jquery" rel="alternate" type="text/html"/>
    <title>Event Delegation Made Easy</title>
<content type="html">
            &lt;p&gt;I&#8217;m having a lot of fun poking around jQuery at the moment and came up with a cool little thing that&#8217;s going into Low Pro for jQuery but is a nice stand-alone little snippet for implementing event delegation.  Since the &lt;a href=&quot;http://icant.co.uk/sandbox/eventdelegation/&quot;&gt;Christian and the guys at &lt;span class=&quot;caps&quot;&gt;YUI&lt;/span&gt; started talking about it&lt;/a&gt; event delegation has gone from being something that I&#8217;d use occasionally to the way I do nearly all my event handling.  If you aren&#8217;t familiar with the technique go and click that previous link and read Christian&#8217;s article now &#8211; it&#8217;s important.&lt;/p&gt;


	&lt;p&gt;In most instances I end up writing a lot of event handlers that look like this:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;$('#thing').click(function(e) {
  var target = $(e.target);

  if (target.hasClass('quit') return doQuitStuff();
  if (target.hasClass('edit') return doEditStuff();
  // and so on...
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Obviously, writing a lot of the same kind of code is a warning sign that something needs refactoring but I&#8217;ve never come up with a nice way to abstract this.  But with a little bit of functional magic I&#8217;ve just found with something I really like.  Here&#8217;s what I came up with:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;jQuery.delegate = function(rules) {
  return function(e) {
    var target = $(e.target);
    for (var selector in rules)
      if (target.is(selector)) return rules[selector].apply(this, $.makeArray(arguments));
  }
}&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Using it is simple:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;$('#thing').click($.delegate({
  '.quit': function() { /* do quit stuff */ },
  '.edit': function() { /* do edit stuff */ }
}));&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The function simple runs through the rules checking if the element that fired the event belongs to that selector then calls the corresponding handler passing the original event object through.  The great thing about it is that you can use it in Low Pro behavior classes:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;DateSelector = $.klass({
  onclick: $.delegate({
    '.close': function() { this.close() },
   '.day': function(e) { this.selectDate(e.target) }
  }),
  selectDate: function(dayElement) {
    // code ...
  },
  close: function() {
    // code ...
  }
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;I&#8217;m not sure of the performance implications of using is() so heavily but some form of caching could be added if it was a problem.  Still, it&#8217;s a really nice little bit of syntactic sugar that&#8217;s going into Low Pro for jQuery and I&#8217;ll be using it a lot.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;UPDATE&lt;/span&gt;&lt;/strong&gt;: I should have added that there&#8217;s a version of this in Low Pro for Prototype. In case you want to use it on its own:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Event.delegate = function(rules) {
  return function(e) {
      var element = $(e.element());
      for (var selector in rules)
        if (element.match(selector)) return rules[selector].apply(this, $A(arguments));
    }
}&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Meanwhile, you might want to take a look at &lt;a href=&quot;http://peter.michaux.ca/article/3752&quot;&gt;the patch&lt;/a&gt; by &lt;a href=&quot;http://peter.michaux.ca/&quot;&gt;Peter Michaux&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2008-02-03:3002</id>
    <published>2008-02-03T16:00:00Z</published>
    <updated>2008-02-04T00:28:00Z</updated>
    <category term="JavaScript"/>
    <category term="Low Pro"/>
    <category term="javascript"/>
    <category term="jquery"/>
    <category term="lowpro"/>
    <link href="http://www.danwebb.net/2008/2/3/how-to-use-low-pro-for-jquery" rel="alternate" type="text/html"/>
    <title>How To Use Low Pro For jQuery</title>
<summary type="html">&lt;p&gt;It seems that my initial version of &lt;a href=&quot;http://github.com/danwrong/low-pro-for-jquery/tree/master/src/lowpro.jquery.js?raw=true&quot;&gt;Low Pro for jQuery&lt;/a&gt; has gotten enough interest to continue
with it but, as always, my previous post was extremely lacking in actual detail about how to use
the damn thing.  So without further ado here we go.  It&#8217;s pretty simple really and, as its a port
of a subset of Low Pro for Prototype, anything that goes for that also goes for jLow.&lt;/p&gt;


	&lt;p&gt;Heh, let&#8217;s not call it that again.  Bad.&lt;/p&gt;


	&lt;p&gt;Anyway, on with the show&#8230;&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;It seems that my initial version of &lt;a href=&quot;http://github.com/danwrong/low-pro-for-jquery/tree/master/src/lowpro.jquery.js?raw=true&quot;&gt;Low Pro for jQuery&lt;/a&gt; has gotten enough interest to continue
with it but, as always, my previous post was extremely lacking in actual detail about how to use
the damn thing.  So without further ado here we go.  It&#8217;s pretty simple really and, as its a port
of a subset of Low Pro for Prototype, anything that goes for that also goes for jLow.&lt;/p&gt;


	&lt;p&gt;Heh, let&#8217;s not call it that again.  Bad.&lt;/p&gt;


	&lt;p&gt;Anyway, on with the show&#8230;&lt;/p&gt;
&lt;h3&gt;Class-based OO&lt;/h3&gt;


	&lt;p&gt;In order for Low Pro behavior classes to work with jQuery we need a class implementation.  The
one I&#8217;ve based this on is the version from Prototype originally based on Alex Arnell&#8217;s work. This
is detailed in &lt;a href=&quot;http://prototypejs.org/learn/class-inheritance&quot;&gt;this article on the prototype site&lt;/a&gt;. The
only difference is that instead of using Class.create you use $.klass:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Draggable = $.klass({
  initialize: function(options) { },
  onmousedown: function() {}
});

GhostedDraggable = $.klass(Draggable, {
  onmousedown: function($super) {
    // do extra stuff here then call original method...
    $super();
  }
});&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Attaching the behavior class to elements&lt;/h3&gt;


	&lt;p&gt;To attach the behavior class to some 
elements you can use the attach method:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;$('div.product').attach(GhostedDraggable, { anOption: thing });&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;attach&lt;/code&gt; creates a new instance of the given behavior class for each element in the collection and
attaches them to these elements.  Any subsequent arguments are passed to the class&#8217;s &lt;code&gt;initialize&lt;/code&gt; function.  
A few magic things happen here.  First, &lt;code&gt;this.element&lt;/code&gt; in the 
behavior instance is set to a dollared version of the element it&#8217;s attached to.  Secondly, every 
method beginning with on (eg. onclick, onsubmit etc) gets bound as an event handler on the attached
element.  However, in the event handler functions themselves, &lt;code&gt;this&lt;/code&gt; points to the behavior instance
rather than the element so you can call it&#8217;s other methods.  You can obviously get to the element
by using &lt;code&gt;this.element&lt;/code&gt; if you need to though.&lt;/p&gt;

	&lt;h3&gt; And for the bonus round&#8230;&lt;/h3&gt;


	&lt;p&gt;So, that&#8217;s about all there is to it.  One added bonus is that if you are using &lt;a href=&quot;http://brandonaaron.net/docs/livequery/&quot;&gt;livequery&lt;/a&gt; then Low
Pro will automatically use it to attach any new behaviors after the &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; is changed without you needing to worry about it.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s a super simple example behavior that simply adds and removes a &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt; class name when it is
hovered over.  It&#8217;s about as bare bones as you can get while showing off most of the features:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Hover = $.klass({
  initialize: function(hoverClass) {
    this.hoverClass = hoverClass;
  },
  onmouseover: function() {
    this.element.addClass(this.hoverClass);
  },
  onmouseout: function() {
    this.element.removeClass(this.hoverClass);
  }
});

jQuery(function($) {
  $('span.name').attach(Hover, 'myClassName');
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;For more information about how you might use behavior classes take a look at &lt;a href=&quot;/2007/7/18/low-pro-behaviours-101-part-2&quot;&gt;this article.&lt;/a&gt; ANother good point of reference is the built-in Remote.Link and Remote.Form
behaviors that are built in to Low Pro.  Take a look at the &lt;a href=&quot;http://github.com/danwrong/low-pro-for-jquery/tree/master/src/lowpro.jquery.js?raw=true&quot;&gt;source&lt;/a&gt;
Also a Low Pro site is on its way shortly. As I use it more myself I&#8217;ll post more real examples but you can post any questions to the &lt;a href=&quot;http://groups.google.co.uk/group/low-pro&quot;&gt;Low Pro list&lt;/a&gt;.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2008-01-31:2971</id>
    <published>2008-01-31T00:56:00Z</published>
    <updated>2008-01-31T14:43:25Z</updated>
    <category term="JavaScript"/>
    <category term="Low Pro"/>
    <category term="experiments"/>
    <category term="javascript"/>
    <category term="jquery"/>
    <category term="lowpro"/>
    <link href="http://www.danwebb.net/2008/1/31/low-pro-for-jquery" rel="alternate" type="text/html"/>
    <title>Low Pro For jQuery?</title>
<summary type="html">&lt;p&gt;A few days ago &lt;a href=&quot;http://groups.google.co.uk/group/low-pro/browse_thread/thread/29b96e32fb68f45e&quot;&gt;a discussion started about porting Low Pro over to jQuery&lt;/a&gt;.  It&#8217;s been on my mind 
for a while (especially since &lt;a href=&quot;http://meme-rocket.com/2007/09/07/agnostic-unobtrusive-javascript/&quot;&gt;Bill blogged about agnostic &lt;span class=&quot;caps&quot;&gt;UJS&lt;/span&gt;&lt;/a&gt;) but I&#8217;d hesitated in doing this for a few
reasons.  Firstly, of course, jQuery is the mortal enemy of Prototype and only one library shall
remain come The Quickening. Aside from this completely rational reason, I wondered whether jQuery
really needed anything like Low Pro at all.  After all, jQuery has always been designed with
&#8216;unobtrusiveness&#8217; in mind and was written with most of what Low Pro originally intended to fix 
in Prototype implemented from the start.  There was no need for something like Event.addBehavior 
because essentially that&#8217;s what jQuery is:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Event.addBehavior({
  'a.external:click': function() { //...code...// },
  'div.product:mouseover': function() { //...code...// }
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Can be achieved in jQuery like this:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;jQuery(function($) {
  $('a.external').click(function() { //...code...// });
  $('div.product').mouseover(function() { //...code...// });
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;And rather than ever going near inline event handlers this unobtrusive style was the de-facto
method of working for the jQuery crowd.  The angel on your scripting shoulder.  However, as you
can probably tell from reading this blog, I&#8217;ve never really adopted jQuery as my main library
and this was due to one big reason (and a bundle of small ones but I&#8217;ll leave them out)...&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;A few days ago &lt;a href=&quot;http://groups.google.co.uk/group/low-pro/browse_thread/thread/29b96e32fb68f45e&quot;&gt;a discussion started about porting Low Pro over to jQuery&lt;/a&gt;.  It&#8217;s been on my mind 
for a while (especially since &lt;a href=&quot;http://meme-rocket.com/2007/09/07/agnostic-unobtrusive-javascript/&quot;&gt;Bill blogged about agnostic &lt;span class=&quot;caps&quot;&gt;UJS&lt;/span&gt;&lt;/a&gt;) but I&#8217;d hesitated in doing this for a few
reasons.  Firstly, of course, jQuery is the mortal enemy of Prototype and only one library shall
remain come The Quickening. Aside from this completely rational reason, I wondered whether jQuery
really needed anything like Low Pro at all.  After all, jQuery has always been designed with
&#8216;unobtrusiveness&#8217; in mind and was written with most of what Low Pro originally intended to fix 
in Prototype implemented from the start.  There was no need for something like Event.addBehavior 
because essentially that&#8217;s what jQuery is:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Event.addBehavior({
  'a.external:click': function() { //...code...// },
  'div.product:mouseover': function() { //...code...// }
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Can be achieved in jQuery like this:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;jQuery(function($) {
  $('a.external').click(function() { //...code...// });
  $('div.product').mouseover(function() { //...code...// });
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;And rather than ever going near inline event handlers this unobtrusive style was the de-facto
method of working for the jQuery crowd.  The angel on your scripting shoulder.  However, as you
can probably tell from reading this blog, I&#8217;ve never really adopted jQuery as my main library
and this was due to one big reason (and a bundle of small ones but I&#8217;ll leave them out)...&lt;/p&gt;
&lt;p&gt;The one big reason was that, while jQuery was super simple and concise when working on smaller
projects, it offered no help in structuring larger applications.  All you get in jQuery, aside from
Ajax methods and a handful of utilities, is the ability to select nodes then doing something 
with them. On the other hand Prototype is much rounder in scope.  It generally plumps out JavaScript 
as a language adding lots of useful methods to built-ins, a host of functional programming tools 
and recently a full Class-based OO system with inheritance and the whole shebang which has formed
the back bone of Low Pro&#8217;s behavior classes.&lt;/p&gt;


	&lt;p&gt;Low Pro&#8217;s behavior classes have become my favourite solution to the problem of structuring complex
Ajax applications in a simple and maintainable way. Even hugely complex applications can be separated
up into a number of groups of elements with attached behaviors.  These behaviors maintain their
own state, respond to events and can also expose there own public methods.  They are linked to an
element but the element doesn&#8217;t know about them which eliminates the need for expandos on elements and
also most of the reasons for having element references in closures which is good for keeping memory usage
at bay.  For instance, a click on
a TabBar instance can call the loadContent method of a ContentPanel.  The result is more than a
set of widgets, its a way of splitting up huge complicated interfaces into a collection of small,
loosely joined parts each simple in its own right and totally responsible for its part of the interface.
This approach becomes incredibly useful when you introduce server-side requests and responses into
the mix but that&#8217;s a whole other article.&lt;/p&gt;


	&lt;p&gt;In jQuery land this kind of effect can be achieved via plugins.  You&#8217;ll find a ton of widgets
in the repository that have this kind of UI:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;$('#example4').draggable({ helper: 'clone', revert: true });&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The plugin architecture is one of jQuery&#8217;s many strong points but this kind of approach has a couple
of disadvantages.  Firstly, the plugin is created within a closure which means usually if you want to
change the behavior of the plugin you literally need to pop open the source and change it.  The second
and related disadvantage is that because of the difficulty in changing plugins they tend to have
a whole raft of options to allow you to configure how it works.  The problem with this is that
individual widgets can end up pretty monolithic.  Wouldn&#8217;t it be be better if you could just take
the basic draggable behavior and just augment it to your liking?&lt;/p&gt;


	&lt;p&gt;Well, in Low Pro behaviors are classes so we can do this by simply subclassing another behavior
and overriding or adding what we need.  For example, we can create GhostedDraggable as a subclass
of Draggable.  No need to hack any existing code at all.  As well as having the power and convenience
of jQuery&#8217;s &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; manipulation we can have a simple and powerful way to structure larger, more
complex applications.  I can have my jQuery cake and eat it.&lt;/p&gt;


	&lt;p&gt;So, I&#8217;ve started experimenting with &lt;a href=&quot;http://github.com/danwrong/low-pro-for-jquery/tree/master/src/lowpro.jquery.js?raw=true&quot;&gt;Low Pro for jQuery.&lt;/a&gt;
Here&#8217;s a preview:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Hover = $.klass({
  initialize: function(hoverClass) {
    this.hoverClass = hoverClass;
  },
  onmouseover: function() {
    this.element.addClass(this.hoverClass);
  },
  onmouseout: function() {
    this.element.removeClass(this.hoverClass);
  }
});

$('div.products').attach(Hover);&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;If you want to leave feeedback or abuse &lt;a href=&quot;http://groups.google.co.uk/group/low-pro&quot;&gt;jump on the Low Pro list.&lt;/a&gt;
Do you think it has a place in the jQuery landscape?  How do you currently structure complex applications
in jQuery?&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;&lt;span class=&quot;caps&quot;&gt;UPDATE&lt;/span&gt;&lt;/strong&gt;: Thanks to Chris of &lt;a href=&quot;http://errtheblog.com&quot;&gt;Err The Blog&lt;/a&gt; Low Pro JQ is &lt;a href=&quot;http://github.com/danwrong/low-pro-for-jquery/tree/master/&quot;&gt;rocking on GitHub&lt;/a&gt;.  Fork away.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2008-01-02:2869</id>
    <published>2008-01-02T12:35:00Z</published>
    <updated>2008-01-02T14:07:11Z</updated>
    <category term="Rails"/>
    <category term="argh"/>
    <category term="ruby"/>
    <category term="stupid"/>
    <link href="http://www.danwebb.net/2008/1/2/how-good-is-this" rel="alternate" type="text/html"/>
    <title>How Good Is This?</title>
<content type="html">
            &lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&amp;gt;&amp;gt; a = 79.99 * 100
=&amp;gt; 7999.0
&amp;gt;&amp;gt; a.floor
=&amp;gt; 7998
&amp;gt;&amp;gt; b = 7999.0
=&amp;gt; 7999.0
&amp;gt;&amp;gt; b.floor
=&amp;gt; 7999&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;I&#8217;ll tell you.  &lt;strong&gt;It&#8217;s not good.&lt;/strong&gt;  I hate floating point calculations.  Happy new year!&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2007-12-25:2771</id>
    <published>2007-12-25T16:36:00Z</published>
    <updated>2007-12-25T16:50:26Z</updated>
    <category term="Misc"/>
    <category term="sneakers"/>
    <category term="trainers"/>
    <category term="xmas"/>
    <link href="http://www.danwebb.net/2007/12/25/danwebb-net-dunk-low" rel="alternate" type="text/html"/>
    <title>danwebb.net Dunk Low</title>
<content type="html">
            &lt;p&gt;&lt;img title=&quot;danwebb.net Dunks&quot; src=&quot;/assets/2007/12/25/-1.png&quot; alt=&quot;danwebb.net Dunks&quot; /&gt;&lt;/p&gt;


&lt;p class=&quot;caption&quot;&gt;Thanks Catherine!  The real things are on there way in a couple of weeks.  Happy Christmas, Peeps.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2007-12-12:2558</id>
    <published>2007-12-12T00:23:00Z</published>
    <updated>2007-12-13T17:49:59Z</updated>
    <category term="JavaScript"/>
    <category term="Low Pro"/>
    <category term="javascript"/>
    <category term="lowpro"/>
    <category term="release"/>
    <link href="http://www.danwebb.net/2007/12/12/low-pro-0-5-now-compatible-with-prototype-1-6" rel="alternate" type="text/html"/>
    <title>Low Pro 0.5: Now Compatible With Prototype 1.6</title>
<content type="html">
            &lt;p&gt;Today I &lt;a href=&quot;http://svn.danwebb.net/external/lowpro/tags/rel_0.5/&quot;&gt;tagged Low Pro 0.5&lt;/a&gt; for release which now works with Prototype 1.6.  There are a number of things about this release that are worth mentioning aside from the compatibility.  Firstly, it&#8217;s gotten a little smaller as Prototype core now includes most of the functionality Low Pro used to add (DOM Ready support, inserting using &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; nodes and a lot more).  It&#8217;s also got a couple of new features so here&#8217;s a rundown:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;&lt;strong&gt;Event.onReady delegates to the new dom:loaded event&lt;/strong&gt;: Except that as before if functions are added after the &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; is loaded they fire immediately.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;DOMBuilder now delegates to Prototype&#8217;s new Element&lt;/strong&gt;: Now difference in usage here though, just less code.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Low Pro&#8217;s &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; methods are now gone&lt;/strong&gt;: Prototype core does everything you should need now.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Behavior.create() works just like the new Class.create()&lt;/strong&gt;: Yes, you can now create behavior classes that inherit from other behaviors (or indeed any other class).  &lt;a href=&quot;http://prototypejs.org/learn/class-inheritance&quot;&gt;See the Prototype&#8217;s site for more information.&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;New core behaviors&lt;/strong&gt;: The Remote and Observed behaviors are now included in the core so you can now turn normal links and forms into Ajaxy links and forms even more easily.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Event.addBehavior.reassignAfterAjax is now false by default&lt;/strong&gt;:  Normally, if you are relying on this behavior it&#8217;s much more efficient to move to a solution using event delegation.  However, if you do want your behaviors reassigned to new content after Ajax calls then go ahead and set it back to true again.  Another solution is to manually call Event.addBehavior.reload();&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;So that&#8217;s about it.  As you can see, it&#8217;s getting smaller as Prototype fills the gaps and graduating into more of a pure behavior framework.  I&#8217;d be interested in adding more core behaviors for other common tasks as well as possibly getting together some kind of behavior library.  I know I&#8217;m building up a fair few and I&#8217;d love to see what everyone else is doing (in fact I&#8217;ve already seen some great stuff) so suggestions are more than welcome&#8230;as are bug reports and patches.  For both of these and general assistance try &lt;a href=&quot;http://groups.google.co.uk/group/low-pro&quot;&gt;the Google Group&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;a href=&quot;http://svn.danwebb.net/external/lowpro/tags/rel_0.5/dist/lowpro.js&quot;&gt;Grab the new version&lt;/a&gt; and have a play.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2007-11-22:2502</id>
    <published>2007-11-22T10:09:00Z</published>
    <updated>2007-11-22T10:23:05Z</updated>
    <category term="Events"/>
    <category term="JavaScript"/>
    <category term="atmedia"/>
    <category term="atmediaajax"/>
    <category term="event"/>
    <category term="javascript"/>
    <category term="lowpro"/>
    <category term="metaprogramming"/>
    <category term="presentation"/>
    <link href="http://www.danwebb.net/2007/11/22/media-ajax" rel="alternate" type="text/html"/>
    <title>@media Ajax</title>
<content type="html">
            &lt;p&gt;Well, that turned out rather nicely I must say.  Really high quality presentations and great attendees &#8211; I really hope that Patrick makes it happen again.  Here are the slides from my presentation:  Metaprogramming JavaScript.&lt;/p&gt;


&lt;div&gt;&amp;lt;object height=&quot;355&quot; width=&quot;425&quot;&gt;&amp;lt;param /&gt;&amp;lt;param /&gt;&amp;lt;param /&gt;&amp;lt;embed src=&quot;http://static.slideshare.net/swf/ssplayer2.swf?doc=metaprogramming-javascript-1195638729182448-3&quot; height=&quot;355&quot; width=&quot;425&quot;&gt;&amp;lt;/embed&gt;&amp;lt;/object&gt;&lt;div&gt;&lt;a href=&quot;http://www.slideshare.net/?src=embed&quot;&gt;&lt;img src=&quot;http://static.slideshare.net/swf/logo_embd.png&quot; alt=&quot;SlideShare&quot; /&gt;&lt;/a&gt; | &lt;a href=&quot;http://www.slideshare.net/danwrong/metaprogramming-javascript&quot; title=&quot;View 'Metaprogramming  JavaScript' on SlideShare&quot;&gt;View&lt;/a&gt; | &lt;a href=&quot;http://www.slideshare.net/upload&quot;&gt;Upload your own&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;

	&lt;p&gt;In other news, Low Pro 0.5 is nearly ready to rock.  The new version is quite a lot smaller as Prototype 1.6 has solved so many of the things I used to fix with Low Pro.  It does however have a few nice new features.  Watch this space.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2007-10-07:2436</id>
    <published>2007-10-07T23:38:00Z</published>
    <updated>2007-12-21T23:41:28Z</updated>
    <category term="JavaScript"/>
    <category term="Low Pro"/>
    <category term="customattributes"/>
    <category term="dojo"/>
    <category term="javascript"/>
    <category term="lowpro"/>
    <link href="http://www.danwebb.net/2007/10/7/custom-attributes-and-class-names" rel="alternate" type="text/html"/>
    <title>Custom Attributes And Class Names</title>
<summary type="html">&lt;p&gt;At the Rich Web Experience, Alex Russell did a presentation entitled &lt;a href=&quot;http://alex.dojotoolkit.org/?p=622&quot;&gt;Standards Heresy&lt;/a&gt;, In the presentation, which I didn&#8217;t attend so forgive me if I&#8217;ve gotten the wrong end of the stick, he spoke about how Dojo has been forced to abandon web standards in some cases in order to get the job done.  The conversation was furthered by &lt;a href=&quot;http://www.easy-reader.net/archives/2007/09/10/alex-russell-is-not-a-heretic/&quot;&gt;Aaron Gustafson&#8217;s response&lt;/a&gt; and is a really interesting discussion.  However, I&#8217;m not going to comment on the politics of the &lt;span class=&quot;caps&quot;&gt;W3C&lt;/span&gt; further as I know nothing about that at all.  One example in the presentation reminded me of something I&#8217;ve wanted to comment on for a while now.  Here&#8217;s that example:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;div dojoType=&amp;quot;dijit.form.HorizontalSlider&amp;quot;
     name=&amp;quot;horizontal1&amp;quot;
     onChange=&amp;quot;dojo.byId('slider1input').value=arguments[0];&amp;quot;
     value=&amp;quot;10&amp;quot;
     maximum=&amp;quot;100&amp;quot;
     minimum=&amp;quot;0&amp;quot;
     showButtons=&amp;quot;false&amp;quot;
     intermediateChanges=&amp;quot;true&amp;quot;
     style=&amp;quot;width:50%; height: 20px;&amp;quot;
     id=&amp;quot;slider1&amp;quot;&amp;gt;
  ...
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;</summary><content type="html">
            &lt;p&gt;At the Rich Web Experience, Alex Russell did a presentation entitled &lt;a href=&quot;http://alex.dojotoolkit.org/?p=622&quot;&gt;Standards Heresy&lt;/a&gt;, In the presentation, which I didn&#8217;t attend so forgive me if I&#8217;ve gotten the wrong end of the stick, he spoke about how Dojo has been forced to abandon web standards in some cases in order to get the job done.  The conversation was furthered by &lt;a href=&quot;http://www.easy-reader.net/archives/2007/09/10/alex-russell-is-not-a-heretic/&quot;&gt;Aaron Gustafson&#8217;s response&lt;/a&gt; and is a really interesting discussion.  However, I&#8217;m not going to comment on the politics of the &lt;span class=&quot;caps&quot;&gt;W3C&lt;/span&gt; further as I know nothing about that at all.  One example in the presentation reminded me of something I&#8217;ve wanted to comment on for a while now.  Here&#8217;s that example:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;div dojoType=&amp;quot;dijit.form.HorizontalSlider&amp;quot;
     name=&amp;quot;horizontal1&amp;quot;
     onChange=&amp;quot;dojo.byId('slider1input').value=arguments[0];&amp;quot;
     value=&amp;quot;10&amp;quot;
     maximum=&amp;quot;100&amp;quot;
     minimum=&amp;quot;0&amp;quot;
     showButtons=&amp;quot;false&amp;quot;
     intermediateChanges=&amp;quot;true&amp;quot;
     style=&amp;quot;width:50%; height: 20px;&amp;quot;
     id=&amp;quot;slider1&amp;quot;&amp;gt;
  ...
&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is a snippet of code showing how Dojo is going off the standards rails by adding custom attributes that are &#8216;needed&#8217; to configure a slider widget.  This is a really good example of a case where you definitely shouldn&#8217;t add custom attributes to &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;.  While the &lt;span class=&quot;caps&quot;&gt;W3C&lt;/span&gt;/browser vendors/whipping boy of choice might be letting us down what the web standards movement taught us (most importantly in my mind) is that semantic &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; is critically important.  Having a &amp;lt;div&amp;gt; with custom attributes that tell Dojo it&#8217;s a slider widget is of no use to anything apart from as a crutch to Dojo.  It has no semantic value at all.  Outside of the context of Dojo it&#8217;s just an useless lump of markup.&lt;/p&gt;


	&lt;p&gt;Although &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; is a pretty limited vocabulary which is very document centric we can still go much further than this in attempting to describe what this is semantically. It&#8217;s an input so use an input or a select box as the base element.  How browsers and assistive technologies deal with these elements is a lot closer to what we want than a meaningless &amp;lt;div&amp;gt;.  Secondly, there&#8217;s custom attributes &#8211; having attributes containing behavioural information like showButtons and intermediateChanges are equally as semantically useless as the old presentational attributes like bgcolor and border and we&#8217;ve all learnt the disadvantages of mixing content and presentation and discarded those&#8230;hopefully.  There&#8217;s got to be a better way.&lt;/p&gt;


	&lt;p&gt;So we want our semantic &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; and to keep our behaviour data out of our document.  Take a leaf out of &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt;&#8217;s book.  We can name and classify objects and use these as our hooks to attach our JavaScript powered behaviour.  Eureka! Not quite:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;html&quot;&gt;&amp;lt;!-- Created with http://cow.neondragon.net/stuff/reflection/reflectomatic.html  --&amp;gt;
&amp;lt;img src=&amp;quot;/reflection/photos/giraffe.jpg&amp;quot; width=&amp;quot;132&amp;quot; alt=&amp;quot;&amp;quot; class=&amp;quot;reflect ropacity71&amp;quot; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The above code is from a nice little JavaScript effects library called &lt;a href=&quot;http://cow.neondragon.net/stuff/reflection/&quot;&gt;reflection.js&lt;/a&gt; which uses
class names to hook in it&#8217;s behaviour unobtrusively.  However, take a closer look at the class names.  They aren&#8217;t classifying things as such, they are embedding configuration into directly into the class names.  In a similar way it&#8217;s not a generally thought of as a good idea to give elements class names like &#8216;bigred&#8217; or &#8216;width40&#8217; although, depressingly, I&#8217;ve seen it done!  This is definitely an abuse of class names &#8211; its not a &#8216;bigred&#8217; its a &#8216;price&#8217; and so on.  This is seen not just in reflection.js but a large amount of &#8216;unobtrusive&#8217; libraries.&lt;/p&gt;


	&lt;p&gt;So how can we improve on this? We need to provide configuration information to our JavaScript but neither custom attributes or embedding info are looking good.  The answer is pretty simple &#8211; add another link to the chain and this is were (plug imminent :) projects like &lt;a href=&quot;http://www.bennolan.com/behaviour/&quot;&gt;behaviour.js&lt;/a&gt; and &lt;a href=&quot;/lowpro&quot;&gt;Low Pro&lt;/a&gt; come in.  They add that other link to the chain.  We can say that all inputs with the class &#8216;date&#8217; should have a date selector attached to them or that selects with the class &#8216;rating&#8217; should be replaced with a slider that&#8217;s range is 0-10 and so on.  Here&#8217;s a snippet using Low Pro to illustrate this:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Event.addBehavior({
  'select.rating': Slider({ min: 0, max: 10, intermediateValues: true }),
  'input.date': DateSelector
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;In this way we are able to maintain semantic &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt;, avoid adding custom attributes and maintain a very loose coupling between our document and it&#8217;s behaviour.  This, we&#8217;ve seen from &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt;, is vitally important to maintainability and a real advantage.  Via this method you can apply configuration to single items or as a group.  If you decided that &#8216;rating&#8217; selects should in fact all be vertical sliders instead of horizontal then that&#8217;s no problem either.  It gives you ultimate flexibility.&lt;/p&gt;


	&lt;p&gt;This methodology is right at the core of Low Pro and I&#8217;ve been getting incredible results from it.  It&#8217;s made what could be really complex JavaScript implementations a breeze.  Instead of a huge, fearsome application everything becomes a &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; document with many loosely, coupled smaller components attached to it.  If you don&#8217;t use Prototype/Low Pro don&#8217;t let that stop you from working this way.  &lt;a href=&quot;http://www.meme-rocket.com/2007/09/07/agnostic-unobtrusive-javascript/&quot;&gt;Bill Burcham wonders whether this can be library agnostic&lt;/a&gt;.  Well, as an idea, in a sense it already is. All you need is the ability to select by &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt; selectors.  Dojo and dijit are in fact very well suited.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2007-08-21:2395</id>
    <published>2007-08-21T10:50:00Z</published>
    <updated>2007-08-21T11:14:20Z</updated>
    <category term="Events"/>
    <category term="JavaScript"/>
    <category term="dojo"/>
    <category term="events"/>
    <category term="javascript"/>
    <category term="jquery"/>
    <category term="prototype"/>
    <category term="yui"/>
    <link href="http://www.danwebb.net/2007/8/21/media-ajax-is-scarily-good" rel="alternate" type="text/html"/>
    <title>@media Ajax Is Scarily Good</title>
<content type="html">
            &lt;p&gt;&lt;img title=&quot;@media Ajax&quot; src=&quot;/assets/2007/6/10/amx_button.gif&quot; alt=&quot;@media Ajax&quot; /&gt; It seems that the &lt;a href=&quot;http://www.vivabit.com/atmediaAjax/&quot;&gt;@media Ajax site&lt;/a&gt; has just been updated.  I was looking forward to it before but more speakers have been added including Brendan Eich who, according the &lt;a href=&quot;http://www.vivabit.com/atmediaAjax/sessions/#javascript&quot;&gt;abstract,&lt;/a&gt; will be demonstrating a working version of Tamarin in Firefox!&lt;/p&gt;


	&lt;p&gt;Also, Dojo&#8217;s Alex Russell, jQuery&#8217;s John Resig, &lt;span class=&quot;caps&quot;&gt;YUI&lt;/span&gt;&#8217;s Douglas Crockford and Prototype&#8217;s erm, me will be representing the major libraries and then there&#8217;s the Ajaxians, Ben and Dion stepping up for a keynote.  Finally, Mr Jeremy Keith will be hosting the hot topics panel in the traditional @media style &#8211; Hot Topics panel + JavaScript people should be quite explosive.  As it was put in the Prototype Core Campfire the other day, &#8220;The JavaScript community is not so much of a community, more of a debating society&#8221;  It&#8217;s going to be excellent.  Of course, as it&#8217;s in London town you know we&#8217;ll be sinking a good few pints after.  It will be a rare chance to get together with fellow scriptie types this side of the pond and the only pub conversation you&#8217;ll ever be allowed to mention closures in&#8230;.surely that&#8217;s a good thing?&lt;/p&gt;


	&lt;p&gt;There are still early bird tickets left until the end of august so &lt;a href=&quot;http://www.vivabit.com/atmediaAjax/register/&quot;&gt;get your arse down to the site and sign up.&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;My presentation, &lt;a href=&quot;http://www.vivabit.com/atmediaAjax/sessions/#metaprogramming&quot;&gt;Metaprogramming JavaScript,&lt;/a&gt; is for all those people who moan that they never learn things at conferences.  It&#8217;s journey into the deep innards of JavaScript and I&#8217;ll be explaining the some of the metaprogramming techniques used in &lt;span class=&quot;caps&quot;&gt;YUI&lt;/span&gt;, Prototype and Low Pro along with really getting into advanced JavaScript concepts like prototype inheritance, functional programming and closures.  I defy you to turn up and not learn something new.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:www.danwebb.net,2007-07-18:2328</id>
    <published>2007-07-18T14:30:00Z</published>
    <updated>2007-07-18T14:32:45Z</updated>
    <category term="JavaScript"/>
    <category term="Low Pro"/>
    <category term="javascript"/>
    <category term="lowpro"/>
    <category term="prototype"/>
    <category term="tutorial"/>
    <link href="http://www.danwebb.net/2007/7/18/low-pro-behaviours-101-part-2" rel="alternate" type="text/html"/>
    <title>Low Pro Behaviours 101: Part 2</title>
<summary type="html">&lt;p&gt;In the first post I briefly explained how to use pre-made Low Pro behaviours but, although I&#8217;m in the process of &lt;a href=&quot;http://svn.danwebb.net/external/lowpro/trunk/behaviours/&quot;&gt;writing a few myself&lt;/a&gt;, Low Pro is not going to be a widget library &#8211; what it is is a great framework to write your own components with.  So, in this post, I&#8217;m going to go into a little detail about how to  write your own behaviours.  If the idea of that doesn&#8217;t bore your rigid then read on&#8230;&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;In the first post I briefly explained how to use pre-made Low Pro behaviours but, although I&#8217;m in the process of &lt;a href=&quot;http://svn.danwebb.net/external/lowpro/trunk/behaviours/&quot;&gt;writing a few myself&lt;/a&gt;, Low Pro is not going to be a widget library &#8211; what it is is a great framework to write your own components with.  So, in this post, I&#8217;m going to go into a little detail about how to  write your own behaviours.  If the idea of that doesn&#8217;t bore your rigid then read on&#8230;&lt;/p&gt;
&lt;h3&gt;Creating a behaviour&lt;/h3&gt;


	&lt;p&gt;As discussed in the last post behaviours are actually just specialised constructor functions.  So, to create our behaviour we use Behavior.create in a very similar way to Class.create:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;var Hover = Behavior.create();&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Adding methods and properties&lt;/h3&gt;


	&lt;p&gt;This creates an empty behaviour much the same as Class.create gives us an empty class. Now we add our methods on to the prototype of the constructor that we&#8217;ve created.  This example is a super simple behaviour, Hover, that will add/remove a class name (which you can specify) on mouse over/out:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Object.extend(Hover.prototype, {
  initialize: function(className) {
    this.className = className || 'over';
  },
  onmouseover: function() {
    this.element.addClassName(this.className);
  },
  onmouseout: function() {
    this.element.removeClassName(this.className);
  }
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Any on* methods are bound as event handlers to the element when the behavior is attached to the element.  The scope of these methods is &#8216;corrected&#8217; automatically so that this will always refer to the behaviour instance.  The behaviour instance also has a magic property, this.element, which points to the element it is attached to.  The final thing you need to know is that the initialize method is called as soon as the &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; is ready (as soon as the element is available).  We can now use this behaviour in the manner discussed in the last post:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Event.addBehavior({
  '.dongle': Hover('hover')
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Aside from these special cases behaviour constructors are identical to any regular JavaScript &#8216;class&#8217;.  You can add methods and properties as you see fit.  Note that each element that has the behaviour attached to it gets its own instance of the behaviour so you can maintain the state of each behaviour independently without having to resort to setting expandos on the element, using closures or any other method which is messy and prone to causing those nasty circular references that cause memory leaks.  As an alternative you can just pass your methods straight into the Behavior.create call so the following is equivilent to the above code:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;var Hover = Behavior.create({
  initialize: function(className) {
    this.className = className || 'over';
  },
  onmouseover: function() {
    this.element.addClassName(this.className);
  },
  onmouseout: function() {
    this.element.removeClassName(this.className);
  }
});&lt;/code&gt;&lt;/pre&gt;

	&lt;h3&gt;Working with multiple elements&lt;/h3&gt;


	&lt;p&gt;Now this is all good for dealing with behaviours that work on a single element but in many cases we want a behaviour to operate on a number of elements.  For example, you would want to be able to attach a Sortable behaviour to a list element but the behaviour itself would also need to deal with all the list element inside it.  There are a number of ways to approach writing these kind of behaviours, all of which are demonstrated in the various test behaviours I&#8217;ve written.&lt;/p&gt;


	&lt;h4&gt;Event delegation with behaviours&lt;/h4&gt;


	&lt;p&gt;The first technique, and normally the best is using event delegation to capture all the events on elements inside the attached element with your behaviour and process them.  The process is pretty simple&#8230;here&#8217;s part of the &lt;a href=&quot;http://svn.danwebb.net/external/lowpro/trunk/behaviours/date_selector.js&quot;&gt;Calendar&lt;/a&gt; behaviour:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;var Calendar = Behavior.create({
  // other methods hidden for clarity
  onclick : function(e) {
    var source = Event.element(e);
    Event.stop(e);

    if ($(source.parentNode).hasClassName('day')) return this._setDate(source);
    if ($(source.parentNode).hasClassName('back')) return this._backMonth();
    if ($(source.parentNode).hasClassName('forward')) return this._forwardMonth();
  }
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Here, we define a single onclick method which will capture clicks on all the elements inside the calendar &#8211; Forward and back arrows, and the dates themselves.  Firstly, we use Event.element to grab the source element, the element that was actually clicked, then we can just examine this element to work out what needs to happen to the calendar and call the relevent method.  In this case, and in most cases, the most convenient way is to look at what class names the element has.  In the calendar, each day has the class &#8216;day&#8217; and the forward/back arrows have the classes &#8216;forward&#8217; and &#8216;back&#8217;.  This method is really nice for a number of reasons, firstly, we avoid attaching lots of event handlers for each sub element and secondly we have this central point where we can handle and dispatch events &#8211; a really pleasant way to work with complex interactions. Of course, event delegation isn&#8217;t always a good fit so&#8230;&lt;/p&gt;


	&lt;h4&gt;Linking behaviours&lt;/h4&gt;


	&lt;p&gt;In more complex cases when the sub elements of your behaviour need to maintain their own state or handle events in a more complex way you can have your main behaviour attach sub-behaviours to inner elements during initialisation and maintain a link between the two.  An example of this can be seen in the &lt;a href=&quot;http://svn.danwebb.net/external/lowpro/trunk/behaviours/draggable.js&quot;&gt;Draggable&lt;/a&gt; behaviour:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;Draggable = Behavior.create({
  initialize : function(options) {
    // code hidden for clarity
    this.handle = this.options.handle || this.element;
    new Draggable.Handle(this.handle, this);
  }
  // code hidden for clarity
});

Draggable.Handle = Behavior.create({
  initialize : function(draggable) {
    this.draggable = draggable;
  },
  onmousedown : function(e) {
        // code hidden for clarity
  }
});&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Here, the initialize method of Draggable finds the element that it wants to be the &#8216;drag handle&#8217; and attaches another behaviour, Draggable.Handle, to it.  At this point we pass a reference to the Draggable instance to the Draggable.Handle instance so the drag handle can refer back to and control the main draggable behaviour.  You can of course, if necessary, build up a complex component by building a number of linked behaviours that all comunicate back to the main behaviour.&lt;/p&gt;


	&lt;h3&gt;Get it? Got it? Good&lt;/h3&gt;


	&lt;p&gt;So that&#8217;s all for now.  Any questions just drop me a comment and I&#8217;ll get back to you &lt;span class=&quot;caps&quot;&gt;ASAP&lt;/span&gt;.  At this point, if you are interested in writing your own behaviours then it would be worth referring to the &lt;a href=&quot;http://svn.danwebb.net/external/lowpro/trunk/behaviours/&quot;&gt;behaviours in &lt;span class=&quot;caps&quot;&gt;SVN&lt;/span&gt;&lt;/a&gt;.  However, I&#8217;m just feeling this out for myself and I&#8217;m sure I&#8217;ve not explored any near all of the possibilities of working with behaviours so if you have any brain waves be sure to post a comment also.  If there&#8217;s enough interest I might include a behaviours repository on the upcoming Low Pro site.&lt;/p&gt;
          </content>  </entry>
</feed>
