<?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:danwebb.net,2011:mephisto/</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://danwebb.net/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://danwebb.net/" rel="alternate" type="text/html"/>
  <updated>2011-05-29T04:40:43Z</updated>
  <entry xml:base="http://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:danwebb.net,2011-05-28:7593</id>
    <published>2011-05-28T22:21:00Z</published>
    <updated>2011-05-29T04:40:43Z</updated>
    <category term="JavaScript"/>
    <category term="hashbangs"/>
    <category term="javascript"/>
    <category term="pushstate"/>
    <category term="urls"/>
    <link href="http://danwebb.net/2011/5/28/it-is-about-the-hashbangs" rel="alternate" type="text/html"/>
    <title>It's About The Hashbangs</title>
<content type="html">
            &lt;p&gt;Before I get started here&#8217;s the disclaimer: The opinions expressed in this rant are my own personal opinions on web development and do not represent the views of my employer, its engineering organisation or any other employees.&lt;/p&gt;


	&lt;p&gt;A few months back there was a &lt;a href=&quot;http://isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs&quot;&gt;flurry&lt;/a&gt; of &lt;a href=&quot;http://intertwingly.net/blog/2011/02/09/Breaking-the-Web-with-hash-bangs&quot;&gt;blog&lt;/a&gt; &lt;a href=&quot;http://www.adequatelygood.com/2011/2/Thoughts-on-the-Hashbang&quot;&gt;posts&lt;/a&gt; and conversations over Twitter both for and against the now fairly common practice of using hashbang urls (&lt;a href=&quot;http://2011.jsconf.us/#!/schedule&quot;&gt;example&lt;/a&gt;) and JavaScript routing in favor of traditional URLs and full page loads.  There is also growing interest around &lt;a href=&quot;http://sammyjs.org/&quot;&gt;several&lt;/a&gt; &lt;a href=&quot;http://documentcloud.github.com/backbone/&quot;&gt;JavaScript&lt;/a&gt; MVC frameworks that are make heavy use of this technique. Since people started doing this kind of thing I&#8217;ve been pretty squeamish about the idea.  At the time that this discussion erupted across the web I really wanted to comment on it but until recently, although I was almost certain that hashbang URLs were destructive, I found myself unable to put in definite terms why.&lt;/p&gt;


	&lt;p&gt;As you probably know if you&#8217;ve been reading this blog for a while, I have for a long time been an avid proponent of progressive enhancement and as many people correctly pointed out many of the arguments against hashbang URLs seemed to fold this philosophy in which clouded the issue quite a lot.  In a &lt;a href=&quot;http://www.adequatelygood.com/2011/2/Thoughts-on-the-Hashbang&quot;&gt;well reasoned post&lt;/a&gt;, my colleague, Ben Cherry pointed this out and expressed that it wasn&#8217;t really hashbangs that were the problem and that they were merely a temporary work around until we get pushState support.  As he put it, &#8220;It&#8217;s Not About The Hashbang&#8221;.&lt;/p&gt;


	&lt;p&gt;After quite a lot of thought and some attention to some of the issues that surround web apps that use hashbang URLs I&#8217;ve come to conclusion that it most definitely &lt;em&gt;is&lt;/em&gt; about the hashbangs.  This technique, on its own, is destructive to the web.  The implementation is inappropriate, even as a temporary measure or as a downgrade experience.&lt;/p&gt;


	&lt;p&gt;Let me explain.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;URLs are important&lt;/strong&gt;. The reason the web is so powerful is that it is a web of information.  Any piece of content can reference any other piece of content directly. Our information is no longer siloed into various disconnected libraries, now all our data is linked together.  The web is much better at doing this than as a platform for delivering applications but yeah, that&#8217;s a whole other blog post. The means by which one piece of data is linked with another piece of data is via a &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt;.  That makes the &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; possibly the most important part of the web. If you are working on a web app I assume you value its content.  If you value the content that a web app holds then you need to value it&#8217;s URLs even more. Directly addressable content is what makes web apps better than desktop apps.  It&#8217;s certainly not the UIs.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;URLs are forever&lt;/strong&gt;. The web has a pretty long memory.  Techniques and technology may change but content published to the web gets indexed, archived and otherwise preserved as do the URLs that they link to.  There&#8217;s no such thing as a temporary fix when it comes to URLs.  If you introduce a change to your &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; scheme you are stuck with it for the forseeable future.  You may internally change your links to fit your new &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; scheme but you have no control over the rest of the web that links to your content.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Cool URLs don&#8217;t change&lt;/strong&gt;. For this and other reasons, Tim Berners-Lee wrote a classic article, &lt;a href=&quot;http://www.w3.org/Provider/Style/URI.html&quot;&gt;Cool URLs don&#8217;t change&lt;/a&gt; in which he explains how to make future proof URLs and why that is important.  If you change your URLs you sever links with from the rest of the web.  You&#8217;ve just turned your web app into a data silo.  Your content has just become a lot less useful.  However, as much as we try it&#8217;s pretty impossible not to introduce change from time to time, sometimes data does need to be deleted, sometimes you need to move to a new domain name, sometimes you just need to reorganise.&lt;/p&gt;


	&lt;p&gt;Luckily, &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; gives us the tools to handle this gracefully.  If content is deleted we can tell the web it&#8217;s no longer there with a 410 (thanks Nick!), if it&#8217;s moved to a different place on the web we can tell the world its new location with a 301 or a 302.  &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; gives us the ability to manage change.  Further to that, it&#8217;s years old, fairly well specified and most importantly understood by not just browsers but all devices that can access the web including search engines and other spiders.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Going under the radar&lt;/strong&gt;. So, you&#8217;ve implemented hashbang URLs. This means that the part of the &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; after the #, the identifies the specific content, is not even sent in the &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; request.  It&#8217;s completely invisible to your server.  As far as your server is concerned it&#8217;s receiving requests for the root document and sending it with a 200 success code no matter what.  It no longer has the ability to determine if the &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt; has moved to a different location or even if the content being requested exists at all.  This entire job is left up to some JavaScript that happens to be running on that page.  Sure, your javascript can examine the hash portion of the &lt;span class=&quot;caps&quot;&gt;URL&lt;/span&gt;, show the relevant content or if it&#8217;s missing show a &#8216;Content not found&#8217; message.  It can even redirect to different locations internal and external to the web app.&lt;/p&gt;


	&lt;p&gt;The important difference is that this is entirely opaque to anything that hasn&#8217;t got a JavaScript runtime and a document object model.  Spiders and search indexers can and do sometimes implement JavaScript runtimes.  However, even in this case there&#8217;s no well recognised way to say &#8216;this is a redirect&#8217; or &#8216;this content is not found&#8217; in a way that non-humans will understand.  You&#8217;ve just rendered your content invisible to everything apart from people running certain browsers. The hashbang itself is an &lt;a href=&quot;http://code.google.com/web/ajaxcrawling/docs/getting-started.html&quot;&gt;attempt to address this&lt;/a&gt; by Google but it&#8217;s quite a painful thing to implement and why get yourself into a situation where you are creating a fix for something you just broke.  Just don&#8217;t break it in the first place.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Once you hashbang, you can&#8217;t go back&lt;/strong&gt;. This is probably the stickiest issue. Ben&#8217;s post put forward the point that when pushState is more widely adopted then we can leave hashbangs behind and return to traditional URLs.  Well, fact is, you can&#8217;t.  Earlier I stated that URLs are forever, they get indexed and archived and generally kept around.  To add to that, cool URLs don&#8217;t change.  We don&#8217;t want to disconnect ourselves from all the valuable links to our content.  If you&#8217;ve implemented hashbang URLs at any point then want to change them without breaking links the &lt;em&gt;only&lt;/em&gt; way you can do it is by running some JavaScript on the root document of your domain. Forever.  It&#8217;s in no way temporary, you are stuck with it.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;It&#8217;s not all doom and gloom&lt;/strong&gt;.  For the web apps that have made the jump already it&#8217;s too late but I urge you to think really hard about making the jump to hashbang URLs when creating new content or considering a switch from traditional URLs.  There is a path forward in the not too distant future.  pushState is coming to browsers at quite a rate and, as &lt;a href=&quot;http://warpspire.com/&quot;&gt;Kyle Neath&lt;/a&gt; said to me in a bar last week, is probably the most important innovation in web development since Firebug.  You can implement, as &lt;a href=&quot;https://github.com/blog/760-the-tree-slider&quot;&gt;Github have done&lt;/a&gt;, pushState for browsers that support it but by all means fall back to traditional URLs &lt;em&gt;rather than&lt;/em&gt; hashbang URLs.  Even if some users are getting hashbang URLs they will be publishing content linking to them, tweeting them and bookmarking them and you&#8217;ll be stuck with supporting them all the same.&lt;/p&gt;


	&lt;p&gt;Can we all agree to let it go the way of flash intros, please?&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag:danwebb.net,2011-02-10:7578</id>
    <published>2011-02-10T05:51:00Z</published>
    <updated>2011-02-10T05:53:35Z</updated>
    <category term="JavaScript"/>
    <category term="Rails"/>
    <category term="design"/>
    <category term="javascript"/>
    <category term="metaprogramming"/>
    <category term="programming"/>
    <link href="http://danwebb.net/2011/2/10/writing-a-new-library-sketch-it-out-first" rel="alternate" type="text/html"/>
    <title>Writing a new library? Sketch it out first</title>
<content type="html">
            &lt;p&gt;So you&#8217;re embarking on writing a new library. You might dive right in to the code and work straight on solving the problem or you might take a more considered approach and start thinking about how to model the problem, what classes and methods you need to create, how they interact and so on.  However, rather than doing that why not start with sketching out not how the library works but how you would like it to be used.  I think you&#8217;ll see pretty positive results if you try it.&lt;/p&gt;


	&lt;p&gt;Usability isn&#8217;t just for designers.  If you want your co-workers or other developers to use and be productive with this code your creating its got to be as simple and fun to use as your user interfaces.  Your library&#8217;s &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; &lt;em&gt;is&lt;/em&gt; a user interface.  History has shown that libraries and open source projects that put their &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; design up front are far more successful than their competitors.  Take jQuery for instance, you can bet that when &lt;a href=&quot;http://ejohn.org&quot;&gt;John&lt;/a&gt; sat down to create jQuery he wasn&#8217;t thinking &#8220;How do I animate &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt; style?&#8221; or &#8220;How do I create and event system?&#8221; his main concern was how he wanted jQuery to be used.  At least initially, the internals of jQuery were a mish mash of various libraries that came before it.  What actually powered the explose growth of jQuery was the revolutionary &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; concepts it introduced: Method chaining, Selector-focussed &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;, simple plug in interface and so on.  Other success stories like Ruby on Rails shared a similar focus on &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; design.&lt;/p&gt;


	&lt;p&gt;So, how do you write your code in such a way that it will make programmers happy and propell you into internet stardom? When you start out writing a new library or feature, start with a sketch.  Cast aside any ideas that you might have already have about the implementation details and try to also cast aside any technical constraints and just start writing how you&#8217;d like your code to be used.  Let&#8217;s take a &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; builder, for example.  Mashing strings (or indeed using the terribly designed &lt;span class=&quot;caps&quot;&gt;W3C DOM API&lt;/span&gt;) is no fun in JavaScript.  If you were taking an implementation first approach you might start with an &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt;-style data structure describing your &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; fragment or maybe even consider a set of objects that map to the various types of elements and this may well be how you implement it under the hood but put that aside for now. How would your code look when using the library?  Here&#8217;s my first pass:&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;var fragment = build(
  div({ id: 'contact' },
    ul(
      li('Email: whatever@thing.com'),
      li('Twitter: ', a({ href: 'http://twitter.com/danwrong' }, '@danwrong')) 
    ) 
  )
);&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Come up with the simplest, most aesthetically pleasing &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; you can and keep itterating on it until you&#8217;ve weeded out all the complexity you can.  If certain arguments are optional or have a sensible defaults then make sure that the developer doesn&#8217;t have to worry about them unless they need to, is your library similar to any other library?  If it is maybe its worth adopting the conventions of that library so it acts in a way that other developers expect it to.  Developers dislike like reading documentation as much as your site&#8217;s users dislike read help pages.  Strive for an &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; so simple that you can describe it in a few sentences.&lt;/p&gt;


	&lt;p&gt;Once you are happy with your sketch start building it out. You might need a little meta programming magic to realise the UI you are going for and that&#8217;s fine but use with caution.  You need to weigh up whether the magic you are adding is going to make your code act in a way that is unpredictable to developers used to working with the language in question or if it will prevent developers from using their existing knowledge of the language to solve problems with your code.  If you smell badness then leave the magic behind. In our example above we need to do quite a bit of work with the function arguments in order to support variable amounts of child nodes and to allow optional attribute hashes. In this case I&#8217;d make the call that this doesn&#8217;t add any extra confusion to the code so I&#8217;m happy to go with that.&lt;/p&gt;


	&lt;p&gt;Also, at this point consider how the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; you are trying to design will impact real world pratical issues.  For instance, in the example above it I would need to create functions for all &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; tags on the global namespace.  Am I happy with my library a defining a global function called a()?  No. Time to scale back on that idea a little.&lt;/p&gt;


	&lt;p&gt;Finally, when it comes to the implementation ensure that the architecture is sound and don&#8217;t try to couple the under the hood implementation with the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; design to a degree that it&#8217;ll make the quality of the library suffer.  I often view the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; as a simple, pretty veneer over the top of a well crafted solution.  Don&#8217;t hide the raw internals, make them accessable alongside the simple &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;.  That way if the developer is on the beaten track they get a simple &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; but if they have specific needs they can delve right in and get stuff done.&lt;/p&gt;


	&lt;p&gt;So yeah, next time you write some code.  Think about sketching out the &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; first rather than leaving it as an after thought.  Your colleagues will thank you.&lt;/p&gt;


	&lt;p&gt;I&#8217;d love to speak more about this at &lt;a href=&quot;http://2011.jsconf.us&quot;&gt;JSConf&lt;/a&gt;.  The competition is very hot but here&#8217;s &lt;a href=&quot;http://2011.jsconf.us/#/proposal/c7bf7fec8a0afceeabf584d143d16862&quot;&gt;my proposal&lt;/a&gt; if your interested. If it&#8217;s picked I&#8217;ll go in to detail on some great and poor examples of &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; design and also show off some nice techniques for bringing your &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; sketches to life.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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://danwebb.net">
    <author>
      <name>dan</name>
    </author>
    <id>tag: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://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>
</feed>

