<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>nwhite.net</title>
	<atom:link href="http://www.nwhite.net/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.nwhite.net</link>
	<description>Nathan White [ Web Developer ]</description>
	<pubDate>Wed, 01 Apr 2009 16:10:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>Javascript Obfuscation</title>
		<link>http://www.nwhite.net/?p=404</link>
		<comments>http://www.nwhite.net/?p=404#comments</comments>
		<pubDate>Wed, 01 Apr 2009 15:31:16 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=404</guid>
		<description><![CDATA[In recent weeks my plate has been full as I plan for a big move. When I get stressed I usually play a game of chess to help relax a bit. Last night I took a different approach. I created my own brain teaser.  I haven&#8217;t played golf with the following code yet, so [...]]]></description>
			<content:encoded><![CDATA[<p>In recent weeks my plate has been full as I plan for a big move. When I get stressed I usually play a game of chess to help relax a bit. Last night I took a different approach. I created my own brain teaser.  I haven&#8217;t played golf with the following code yet, so the code isn&#8217;t optimized and it could be greatly reduced. The code is in pure javascript, no libraries, but it does require a decent javascript engine to handle forEach, map etc. Sorry IE.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>a <span style="color: #339933;">==</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> t;
        isNaN<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        t <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>a.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/.{5}/g</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             <span style="color: #000066; font-weight: bold;">return</span> parseInt<span style="color: #009900;">&#40;</span>p<span style="color: #339933;">,</span> <span style="color: #CC0000;">33</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span>;
         	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/.{6}/g</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             	<span style="color: #000066; font-weight: bold;">return</span> parseInt<span style="color: #009900;">&#40;</span>p<span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">17</span><span style="color: #009900;">&#41;</span>;
         	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/.{4}/g</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">reverse</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             	<span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> p.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>;
             	<span style="color: #000066; font-weight: bold;">return</span> a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> a<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> a<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>;
         	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             	<span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> p.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/.{2}/g</span><span style="color: #009900;">&#41;</span>;
             	a.<span style="color: #660066;">forEach</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>c<span style="color: #339933;">,</span> i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> b<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
             	<span style="color: #000066; font-weight: bold;">return</span> b<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> b<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>;
         	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/.{2}/g</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             	<span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> p.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>;
             	<span style="color: #000066; font-weight: bold;">return</span> String.<span style="color: #660066;">fromCharCode</span><span style="color: #009900;">&#40;</span>parseInt<span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> x<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">17</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
         	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            d <span style="color: #339933;">=</span> a.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>; l <span style="color: #339933;">=</span> d.<span style="color: #660066;">length</span>; p <span style="color: #339933;">=</span> t.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>;
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>l <span style="color: #339933;">==</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> d.<span style="color: #660066;">forEach</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> p.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>; t <span style="color: #339933;">=</span> p.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>
	    	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> t <span style="color: #339933;">=</span> d.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> p<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>;<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> p.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000066; font-weight: bold;">return</span> arguments.<span style="color: #660066;">callee</span>;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> t <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> a<span style="color: #339933;">,</span> p<span style="color: #339933;">,</span> b <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>c<span style="color: #339933;">,</span>i<span style="color: #339933;">,</span>d<span style="color: #339933;">,</span>l;
    <span style="color: #000066; font-weight: bold;">return</span> r;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'sbuq1iunojjo8q7'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">165</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">12</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<h3>Spoiler:</h3>
<p><span id="more-404"></span></p>
<pre>

'sbuq1iunojjo8q7' // starting point base 33

split into 3 => sbuq1 iunoj jo8q7

33634624 22450546 23404564 // merge into single string

// create an array of two parts each

336346 242245 054623 404564 // base 7
c326    8g65    2d63    e067 // base 17

use shift:

    1 => 7,3,5,6
    3 => 6,6,6,2
    0 => 0,d,g,3
    2 => e,2,8,c

rows 1,3,0,2 (scrambling)

translate to =>

    0 7 e 6 d 3 2 6 g 5 8 6 3 6 c 2
    0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 // index from above

    07,e6,d3,26,g5,86,36,c2 => 07e6d326g58636c2

    07, e6, d3, 26, g5, 86, 36, c2

    0   1   2   3   4   5   6   7
    d3, 86, 07, 26, 36, e6, g5, c2  // pseudo reverse using % 3 (see below)

    0 => 07, 26, 36
    1 => e6, g5, c2
    2 => d3, 86

    i%3 = (0 => 0,3,6 ), (1 => 1,4,7), (2 => 2,5)

    2, 0, 1

    d3 86 07 26 36 e6 g5 c2

    //reverse each 2 characters
    0  1  2  3  4  5  6  7  // index
    3d 68 70 62 63 6e 5g 2c //base 17
    @  n  w  h  i  t  e  .
    // convert to base 10

    // convert to ascii

    // grab 1,6,5 and push
    // grab 1,2 and shift
    // done! final output my email address.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=404</wfw:commentRss>
		</item>
		<item>
		<title>MooDocs TextMate Command</title>
		<link>http://www.nwhite.net/?p=390</link>
		<comments>http://www.nwhite.net/?p=390#comments</comments>
		<pubDate>Fri, 06 Mar 2009 01:45:57 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Utilities]]></category>

		<category><![CDATA[Markdown]]></category>

		<category><![CDATA[Mootools]]></category>

		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=390</guid>
		<description><![CDATA[José Prado just released the MooDocs Coda plug-in . The plug-in allows Coda to parse MooTools Classes and generates a Markdown formatted template ready to fill in with details. I took his great work and modified it for TextMate.

I packaged it as a single command that installs into the Javascript bundle. I also assigned &#60;command&#62;-D [...]]]></description>
			<content:encoded><![CDATA[<p>José Prado just released the <a href="http://pradador.com/code/coda/moodocs.html">MooDocs Coda plug-in </a>. The plug-in allows Coda to parse MooTools Classes and generates a Markdown formatted template ready to fill in with details. I took his great work and modified it for TextMate.</p>
<p><a href="/dl/MooDocs.zip"><img src="/images/TM-Command.jpg" style="float:right;border:none;" /></a></p>
<p>I packaged it as a single command that installs into the Javascript bundle. I also assigned &lt;command&gt;-D to the command, for even quicker generation. One minor thing I fixed with the code was the parsing of the class name.  There were a few cases where classes are created without var and have a &#8216;dot&#8217; in the name. Like Fx.Morph or Drag.Move.</p>
<p>You are still required to end your classes like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> MyClass <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;<span style="color: #006600; font-style: italic;">//end</span></pre></div></div>

<h2><a href="/dl/MooDocs.zip">Download MooDocs for TextMate</a></h2>
<p><b>Update:</b></p>
<p>MooDocs for TextMate has been moved to a <a href="http://github.com/nw/moodocs-for-textmate/tree/master">github repo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=390</wfw:commentRss>
		</item>
		<item>
		<title>Lasso.Crop Preview</title>
		<link>http://www.nwhite.net/?p=328</link>
		<comments>http://www.nwhite.net/?p=328#comments</comments>
		<pubDate>Wed, 25 Feb 2009 20:37:25 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Image Manipulation]]></category>

		<category><![CDATA[Mootools]]></category>

		<category><![CDATA[lasso]]></category>

		<category><![CDATA[moocroop]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=328</guid>
		<description><![CDATA[After releasing the &#8220;magnetic poetry&#8221; demo I have been working hard trying to make the code more reusable for all. In the process there has been a name change from Rubberband to Lasso. The original Rubberband code has been a great source of inspiration, but not much is left of it. I have completely gutted [...]]]></description>
			<content:encoded><![CDATA[<p>After releasing the &#8220;magnetic poetry&#8221; demo I have been working hard trying to make the code more reusable for all. In the process there has been a name change from Rubberband to Lasso. The original Rubberband code has been a great source of inspiration, but not much is left of it. I have completely gutted it reworking a lot of the internal logic.</p>

<p>First, the eye candy <img src='http://www.nwhite.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<span id="more-328"></span>
<style type="text/css">
	#cropdemo {
/*		float: left;
		width: 700px; */
	}
	
	#controls {
		font-family: verdana;
		font-size: 10px;
		margin-left: 10px;
		padding-left: 10px;
	}

       #controls .c {
           width: 100px;
           margin: 8px 10px;
           float: left;
          border: 1px dotted #999;
       }
	
	#controls label{
		font-size: 12px;
		background: #ddd;
                display: block;
		border-bottom: 1px solid #999;
		color: #333;
		padding: 1px 2px 1px 2px;
		margin: 1px 0;
	}
	
	#controls input {
		font-size: 10px;
		width: 25px;
		height: 12px;
	}	
	
	#controls span {
		font-size: 9px;
		font-style: italic;
		padding-left: 4px;
	}
	
	#location {
               width: 550px;
		padding: 4px;
		text-align: center;
		font-size: 14px;
		color: #666;
		margin-bottom: 10px;
	}
	
	#location span {
		margin: 0 8px;
		display :  inline-block;
		width: 35px;
		padding: 2px;
		border: 1px solid #999;
	}
	
	#notes {
		font-size: 14px;
		color: #333;
	}

</style>
<h4>Lasso.Crop</h4>
<div id="cropdemo" style="overflow:auto;clear:both;">
<img src="/images/bee.jpg" id="bee" />
    <div id="location">
	 x:<span id="locx"></span> 
	 y:<span id="locy"></span> 
	 w:<span id="locw"></span>
	 h:<span id="loch"></span>
	</div>
</div>
<div id="controls">
      <div class="c">
	<label>Ratio</label>
		<select id="control-ratio" name="ratio">
			<option value="false" SELECTED>off</option>
			<option value="16:9">16:9</option>
			<option value="4:3">4:3</option>
			<option value="1:1">1:1</option>
		</select>
        </div>
        <div class="c">
	<label>Preset</label>
		<select id="control-default" name="default">
			<option value="false">off</option>
			<option value="0" SELECTED>default 1</option>
			<option value="1">default 2</option>
		</select>
         </div>
         <div class="c">
	<label>Min W &amp; H</label>
		x: <input type="text" name="minx" id="control-minx" value="50" />
		&nbsp;y: <input type="text" name="miny" id="control-miny" value="50" />
        </div>
        <div class="c">
	<label>Max W &amp; H</label>
		x: <input type="text" name="maxx" id="control-maxx" value="" />
		&nbsp;y: <input type="text" name="maxy" id="control-maxy" value="" />
        </div>
        <div class="c" style="clear:left;">
	<label>Handle Size</label>
		<select id="control-handleSize" name="handleSize">
			<option value="6">6</option>
			<option value="8" SELECTED>8</option>
			<option value="10">10</option>
		</select>
        </div>
        <div class="c">
	<label>Mask Color</label>
		<select id="control-maskColor" name="color">
			<option value="#7389AE" SELECTED>Default</option>
			<option value="#000">Black</option>
			<option value="#FFF">White</option>
		</select>
        </div>
        <div class="c">
	<label>Mask Opacity</label>
		<select id="control-opacity" name="opacity">
			<option value=".1">10%</option>
			<option value=".2">20%</option>
			<option value=".3">30%</option>
			<option value=".4">40%</option>
			<option value=".5">50%</option>
			<option value=".6" SELECTED>60%</option>
			<option value=".7">70%</option>
			<option value=".8">80%</option>
			<option value=".9">90%</option>
		</select>
        </div>
        <div class="c">
	<label>Marching Ants</label>
		<select id="control-ants" name="ants">
			<option value="/images/crop.gif" SELECTED>animated</option>
			<option value="#000">black (static)</option>
			<option value="#F00">red (static)</option>
		</select>
         </div>
</div>
<div id="notes"></div>
<div style="clear:both;height:10px;">&nbsp;</div>

<p>So far I have tested this in FF, Safari, Opera, IE6 &#038; 7 and things look good. It doesn&#8217;t require anything but Core!</p>

<b>Things to note:</b>


<ul>
<li>you can click anywhere outside of the crop area to start a new crop</li>
<li>if the handlers disappear then the crop is invalid (too small)</li>
<li>if min and max are the same the handlers are removed</li>
<li>N,S,E,W handlers are removed for ratio constraints</li>
<li>Marching ants requires a single 8&#215;8 image. Default is &#8216;1px dashed #999&#8242;</li>
<li>Preset option was added to help with usability, visual clue to communicate that you can crop</li>
</ul>


<h2><a href="/js/Lasso.js">Download Lasso.js</a></h2>
<h2><a href="/js/Lasso.Crop.js">Download Lasso.Crop.js</a></h2>

<h1 style="font-size:24px;">Lasso.Crop</h1>
<h3>Example</h3>
<div class="content">
<p>HTML</p>


<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;mootools.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;Lasso.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;Lasso.Crop.js&quot;&gt;&lt;/script&gt;</pre></div></div>





<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;/images/bee.jpg&quot; id=&quot;bee&quot; /&gt;</pre></div></div>



<p>Javascript</p>


<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Lasso.<span style="color: #660066;">Crop</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'bee'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
	ratio <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
	preset <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">235</span><span style="color: #339933;">,</span><span style="color: #CC0000;">140</span><span style="color: #339933;">,</span><span style="color: #CC0000;">505</span><span style="color: #339933;">,</span><span style="color: #CC0000;">340</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	min <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">50</span><span style="color: #339933;">,</span><span style="color: #CC0000;">50</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	handleSize <span style="color: #339933;">:</span> <span style="color: #CC0000;">8</span><span style="color: #339933;">,</span>
	opacity <span style="color: #339933;">:</span> .6<span style="color: #339933;">,</span>
	color <span style="color: #339933;">:</span> <span style="color: #3366CC;">'#7389AE'</span><span style="color: #339933;">,</span>
	border <span style="color: #339933;">:</span> <span style="color: #3366CC;">'/images/crop.gif'</span><span style="color: #339933;">,</span>
	<span style="color: #000066;">onResize</span> <span style="color: #339933;">:</span> updateCoords
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>



</div>
<h3>Documentation</h3>
<div class="content">
<p class="header">Arguments</p>
<p class="entry"><small>options</small> an object. see options below.</p>
<p class="header">Options</p>
<p class="entry"><small>min</small> [w,h]/false sets the min width and height defaults to false</p>
<p class="entry"><small>max</small> [w,h]/false sets the max width and height defaults to false</p>
<p class="entry"><small>ratio</small> [16,9]/false sets the ratio constraints defaults false</p>
<p class="entry"><small>contain</small> element/false if set lasso will be contained within element, default false</p>
<p class="entry"><small>border</small> hex color or image path, sets the border of the lasso. Default &#8216;#999&#8242;</p>
<p class="entry"><small>color</small> masking color default &#8216;#7389AE&#8217;</p>
<p class="entry"><small>opacity</small> opacity of mask default .3</p>
<p class="entry"><small>zindex</small> used to make sure lasso is above all elements default 10000</p>
<p class="header">Methods</p>
<p class="entry"><small>attach</small>Attaches listeners</p>
<p class="entry"><small>detach</small>Detaches all listeners</p>
<p class="header">Events</p>
<p class="entry"><small>start</small>Event fired when lasso begins</p>
<p class="entry"><small>resize</small>Event fired during every mousemove while lasso active returns { x, y, w, h } if &#8216;contain&#8217; is set, positions are relative to container</p>
<p class="entry"><small>complete</small>Event fired on mouseup. returns { x, y, w, h} if &#8216;contain&#8217; is set, positions are relative to container</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=328</wfw:commentRss>
		</item>
		<item>
		<title>Writing Mootool Classes. Things I&#8217;ve learned.</title>
		<link>http://www.nwhite.net/?p=307</link>
		<comments>http://www.nwhite.net/?p=307#comments</comments>
		<pubDate>Tue, 17 Feb 2009 17:04:25 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Mootools]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=307</guid>
		<description><![CDATA[With the release of my demo last week I have had many requests to make a public API. In the process of doing so I have run into a lot of things with classes that I haven&#8217;t encountered before. This has led to quite a bit of frustration because of my lack of understanding in [...]]]></description>
			<content:encoded><![CDATA[<p>With the release of my demo last week I have had many requests to make a public API. In the process of doing so I have run into a lot of things with classes that I haven&#8217;t encountered before. This has led to quite a bit of frustration because of my lack of understanding in properly using the framework. In hopes to save someone else time, below is a list of tips that may help you from making the same mistakes as I did. This list mainly applies to developers that are trying to create reusable classes. If you&#8217;re developing classes that wrap application behavior most of these gotchas don&#8217;t apply.</p>
<p>1) Using <a href="http://blog.kassens.net/binds-class-mutator">Jan&#8217;s Binds mutator</a> can save a ton of time. When dealing with Classes that extend other classes execution order becomes critical. Binds can take a lot of this worry away.</p>
<p>2) When developing an abstract class that other classes can Implement even if it has options do not include &#8216;options&#8217; in the class. When Implemented it will blow away your previously set options. Fun times.</p>
<p>3) Extends and Implements do not play well together when the base class, extended class and the implemented class all have initialize functions. I might be doing something wrong here but it looks like the Implement class always wins, and you loose access to &#8216;this.parent()&#8217;.</p>
<p>4) Keep track of your events! Make sure you have the ability to detach them. Again Jan&#8217;s Binds can help with this.</p>
<p>Update:</p>
<p>Jan&#8217;s version of bind doesn&#8217;t work in 1.2 Check out <a href="http://www.clientcide.com/code-releases/classbinds-for-mootols-is-back/">Aaron&#8217;s</a> which does.</p>
<p>Aaron write:</p>
<blockquote><p>
The key to Implements is to think of them as add-ons, not inheritance. It would be like having a mixin for your car that adds wheels. If your car had wheels, you wouldn&#8217;t need it. So &#8220;Implements: Wheels&#8221; adds wheels. Classes that are meant to be mixins shouldn&#8217;t have any members that are already in use (like options or initialize). This is different than Extends. Extends in our car analogy would be the Model T followed by the 57 Corvette. Corvette inherits from Model T numerous things and adds additional items and can refer to elements in its inheritance chain. But Model T, Corvette, and Ferrari all Implements: Wheels. If you Implements: Wheels onto Model T, you don&#8217;t need to do it to Corvette and Ferrari, because they inherit from Model T.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=307</wfw:commentRss>
		</item>
		<item>
		<title>Visual Sorting Explained</title>
		<link>http://www.nwhite.net/?p=291</link>
		<comments>http://www.nwhite.net/?p=291#comments</comments>
		<pubDate>Fri, 13 Feb 2009 21:42:43 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Mootools]]></category>

		<category><![CDATA[Utilities]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[sorting]]></category>

		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=291</guid>
		<description><![CDATA[I am getting the impression that my previous post was a bit esoteric. It has some valid uses and I want to help visualize how you might use the &#8216;visualSort&#8217; method on Elements.
Lets first take a look at the demo I put up.

In the above image we have selected 5 elements. As you can see [...]]]></description>
			<content:encoded><![CDATA[<p>I am getting the impression that my <a href="http://www.nwhite.net/2009/02/13/visual-sorting/">previous post</a> was a bit esoteric. It has some valid uses and I want to help visualize how you might use the &#8216;visualSort&#8217; method on Elements.</p>
<p>Lets first take a look at the <a href="http://www.nwhite.net/2009/02/09/advanced-ui-component-using-rubberband-and-draggroup/">demo</a> I put up.</p>
<p><img src="/images/vsort_example1.jpg" /></p>
<p>In the above image we have selected 5 elements. As you can see none of them are aligned and they actually overlap. However, the human eye discerns that there are 2 lines of elements. 3 on the top row, 2 on the bottom. The &#8216;visualSort&#8217; method allows you to see elements like a users would in your code.</p>
<p>How visualSort solves this problem is two fold. First, it takes all the elements and sorts them by the &#8216;top&#8217; coordinate. Once this sort is complete a second sort is performed. The first element is grabbed and an index is made based off the &#8216;tolerance&#8217; (defaults to .5 or 50%). What this means is the height of the element is taken and multiplied by the &#8216;tolerance&#8217;.  This result is added to the to the top value to get a tolerance range. </p>
<p>For example if chocolate had a top of 10px and was 20px in height. The tolerance would be within 10-20px.  Any following element that has a top pixel within this range will be added to the same row. As an element is added to a row they are sorted by the left pixel to make sure they are in the correct order. If an element is not within that range a new row is created along with a new tolerance. The cycle repeats until all elements have been processed.</p>
<p><span id="more-291"></span><br />
Using the illustration above, this is how the code would work.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
$$<span style="color: #009900;">&#40;</span>selected_elements<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">visualSort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">// returns [ [ 'chocolate', 'triumph', 'wisdom' ] , [ 'cataclysmic', 'love' ] ]</span>
&nbsp;
$$<span style="color: #009900;">&#40;</span>selected_elements<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">visualSort</span><span style="color: #009900;">&#40;</span>.5<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">// returns $$([ 'chocolate', 'triumph', 'wisdom', 'cataclysmic','love' ])</span></pre></div></div>

<p>Note: for illustrative purposes I returned the html value of each node. In reality visual sort returns the elements.</p>
<p>Things to consider when using this method. This method will perform very well if all elements are the same height. If there is a considerable difference in the height of the elements there could be some undesired results. Some of this can be remedied with the tolerance parameter. In order to handle a large degree of varying heights more logic would need to be added to the sort routine.</p>
<p>I see this piece of code being of use in drag and drop interfaces. I will be providing more code soon doing just that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=291</wfw:commentRss>
		</item>
		<item>
		<title>Visual Sorting</title>
		<link>http://www.nwhite.net/?p=279</link>
		<comments>http://www.nwhite.net/?p=279#comments</comments>
		<pubDate>Fri, 13 Feb 2009 17:29:56 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Mootools]]></category>

		<category><![CDATA[Utilities]]></category>

		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[sorting]]></category>

		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=279</guid>
		<description><![CDATA[As promised I have been cleaning up the code to my most recent demo. I will be releasing a much more polished API along with documentation in the near future. Stay tuned.
I just completed one of the biggest headaches. Visual sorting. This allows DOM elements to be sorted in the same way humans would visually. [...]]]></description>
			<content:encoded><![CDATA[<p>As promised I have been cleaning up the code to my most recent <a href="http://www.nwhite.net/2009/02/09/advanced-ui-component-using-rubberband-and-draggroup/">demo</a>. I will be releasing a much more polished API along with documentation in the near future. Stay tuned.</p>
<p>I just completed one of the biggest headaches. Visual sorting. This allows DOM elements to be sorted in the same way humans would visually. I tried to make this as simple as possible to use.</p>
<p>I extended &#8216;Elements&#8217; with a new method &#8216;visualSort&#8217;. The tricky part with a visual sort is the fuzzy logic needed to handle elements being offset. If you play with the demo you will get a feel for what I am talking about. In the demo, there is no need for pixel perfect alignment of elements to be considered on the same row. To require this would make the UI completely useless. To have this kind of fuzzy range matching &#8216;visualSort&#8217; has a tolerance parameter. This allows you to define how much elements can be offset before it is considered a new &#8216;row&#8217;. Currently, tolerance defaults to .5 (50%). I also established a second parameter &#8216;flatten&#8217;. If set to true the sorted list will be flattened and returned as an Elements object. Currently &#8216;visualSort&#8217; defaults to false which returns a multidimensional array. </p>
<p>In writing this code I tried to optimize the sorting as much as possible. I see a few places that can be tweaked but overall it should be fast. I didn&#8217;t use any sort() methods. I handle all my own sorting as I iterate through the elements.  Feel free to ask questions about the logic or code.</p>
<p>Enjoy! My Brain still hurts.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">&nbsp;
Elements.<span style="color: #660066;">implement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	visualSort <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>tolerance<span style="color: #339933;">,</span>flatten<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> tolerance <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>tolerance<span style="color: #009900;">&#41;</span> || .5;
		<span style="color: #003366; font-weight: bold;">var</span> idx <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> el<span style="color: #339933;">,</span> c1<span style="color: #339933;">,</span> c2<span style="color: #339933;">,</span> placed;
&nbsp;
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> 0<span style="color: #339933;">,</span> l <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">length</span>; i <span style="color: #339933;">&lt;</span> l; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			el <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>; c1 <span style="color: #339933;">=</span> el.<span style="color: #660066;">getCoordinates</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>i<span style="color: #009900;">&#41;</span> idx<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>el<span style="color: #339933;">,</span> c1<span style="color: #009900;">&#93;</span>;
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				j <span style="color: #339933;">=</span> 0; placed <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span>;
				<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>j <span style="color: #339933;">&lt;</span> i <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>placed <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					c2 <span style="color: #339933;">=</span> idx<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>;
					<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>c1.<span style="color: #660066;">top</span> <span style="color: #339933;">&lt;</span> c2.<span style="color: #660066;">top</span><span style="color: #009900;">&#41;</span> placed <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;
					<span style="color: #000066; font-weight: bold;">else</span> j++;
				<span style="color: #009900;">&#125;</span>
				idx.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">,</span>0<span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span>el<span style="color: #339933;">,</span>c1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> rows <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> row <span style="color: #339933;">=</span> 0<span style="color: #339933;">,</span> sorted <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> slen<span style="color: #339933;">,</span> threshold;
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> 0; i <span style="color: #339933;">&lt;</span> l; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			c1 <span style="color: #339933;">=</span> idx<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				rows<span style="color: #009900;">&#91;</span>row<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>c1.<span style="color: #660066;">top</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span>c1.<span style="color: #660066;">top</span> <span style="color: #339933;">+</span> c1.<span style="color: #660066;">height</span><span style="color: #339933;">*</span>tolerance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>;
				sorted<span style="color: #009900;">&#91;</span>row<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span> idx<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#93;</span>;
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				threshold <span style="color: #339933;">=</span> rows<span style="color: #009900;">&#91;</span>row<span style="color: #009900;">&#93;</span>;
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>threshold<span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&lt;=</span> c1.<span style="color: #660066;">top</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>c1.<span style="color: #660066;">top</span> <span style="color: #339933;">&lt;=</span> threshold<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					j <span style="color: #339933;">=</span> 0; placed <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span>; slen <span style="color: #339933;">=</span> sorted<span style="color: #009900;">&#91;</span>row<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">length</span>;
					<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>j <span style="color: #339933;">&lt;</span> slen <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>placed<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						c2 <span style="color: #339933;">=</span> sorted<span style="color: #009900;">&#91;</span>row<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span>;
						<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>c1.<span style="color: #660066;">left</span> <span style="color: #339933;">&lt;</span> c2.<span style="color: #660066;">left</span><span style="color: #009900;">&#41;</span> placed <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;
						<span style="color: #000066; font-weight: bold;">else</span> j<span style="color: #339933;">++</span>
					<span style="color: #009900;">&#125;</span>
					sorted<span style="color: #009900;">&#91;</span>row<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">,</span>0<span style="color: #339933;">,</span>idx<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
				<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
					row++;
					rows<span style="color: #009900;">&#91;</span>row<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>c1.<span style="color: #660066;">top</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span>c1.<span style="color: #660066;">top</span> <span style="color: #339933;">+</span> c1.<span style="color: #660066;">height</span><span style="color: #339933;">*</span>tolerance<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span>;
					sorted<span style="color: #009900;">&#91;</span>row<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span>;
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> result <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>;
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> 0<span style="color: #339933;">,</span> l <span style="color: #339933;">=</span> sorted.<span style="color: #660066;">length</span>; i <span style="color: #339933;">&lt;</span> l; i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			result<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>;
			<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>j <span style="color: #339933;">=</span> 0<span style="color: #339933;">,</span> len <span style="color: #339933;">=</span> sorted<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">length</span>; j <span style="color: #339933;">&lt;</span> len; j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				result<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> sorted<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span>;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>flatten<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> $$<span style="color: #009900;">&#40;</span>result.<span style="color: #660066;">flatten</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">return</span> result;
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Example Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sorted <span style="color: #339933;">=</span> $$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'your selector'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">visualSort</span><span style="color: #009900;">&#40;</span>.7<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>I believe the value of this will be seen in Drag and Drop interfaces and layout managers. It could have some potential use for serializing specific components.  If you find a use for it please share.</p>
<p>The demo has been updated with this code, it works in IE now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=279</wfw:commentRss>
		</item>
		<item>
		<title>Advanced UI component using Rubberband and Drag.Group</title>
		<link>http://www.nwhite.net/?p=270</link>
		<comments>http://www.nwhite.net/?p=270#comments</comments>
		<pubDate>Mon, 09 Feb 2009 20:46:18 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Mootools]]></category>

		<category><![CDATA[Drag n Drop]]></category>

		<category><![CDATA[rubberband]]></category>

		<category><![CDATA[UI]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=270</guid>
		<description><![CDATA[I knew after posting Drag.Group I needed to get a demo up quickly. The code is not completely refined yet so use at your own risk. I will be making updates over the next couple of days and will keep you posted.
A while back ago I posted an update to the Rubberband class. Its hard [...]]]></description>
			<content:encoded><![CDATA[<p>I knew after posting <a href="http://www.nwhite.net/2009/02/09/draggroup/">Drag.Group</a> I needed to get a demo up quickly. The code is not completely refined yet so use at your own risk. I will be making updates over the next couple of days and will keep you posted.</p>
<p>A while back ago I posted an update to the <a href="http://www.nwhite.net/2008/10/01/rubberband-select/">Rubberband</a> class. Its hard to understand the class unless you actually use it. One of the limitations that I found was the use of draggable elements. The coordinate locations were not updated and as a result the rubberband feature didn’t work.</p>
<p>I have made steps to add this functionality in place, currently the API is a bit broken and I am cleaning up how the coordinates are stored. In the meantime, I am providing a proof of concept.</p>
<p>Enjoy the demo!<br />
<span id="more-270"></span></p>
<p>Things to try:</p>
<ul>
<li>click and drag outside of any item and drag a rubberband select</li>
<li>drag the group of selected items by dragging any selected item</li>
<li>try dragging the items into the container boundary and out again</li>
<li>shift click works for select items as well</li>
<li>The save button works when multiple elements are selected, its a demo of my work in progress on visualized sorting</li>
</ul>
<h5>Update:</h5>
<p>Several bugs have come to my attention. I am resolving these and will have a much more solid version up soon. The sorting output <strike>doesn&#8217;t</strike> work in IE. </p>
<div id="board">
</div>
<div id="poem">
</div>
<p><i>The creative choice of words was supplied by the ever so talented <a href="http://www.designfrenzy.com">April Magley</a></i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=270</wfw:commentRss>
		</item>
		<item>
		<title>Drag.Group for Mootools</title>
		<link>http://www.nwhite.net/?p=266</link>
		<comments>http://www.nwhite.net/?p=266#comments</comments>
		<pubDate>Mon, 09 Feb 2009 17:08:04 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Utilities]]></category>

		<category><![CDATA[Mootools]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=266</guid>
		<description><![CDATA[Drag.Group class for Mootools that allows you to drag and drop multiple items at once.]]></description>
			<content:encoded><![CDATA[<h5>Update</h5>
<p>Check out the <a href="http://www.nwhite.net/2009/02/09/advanced-ui-component-using-rubberband-and-draggroup/">demo</a>.</p>
<p>I have been playing around with creating more advanced UI components recently. I ran into the need to be able to drag multiple items at a time. I created the following classes to solve my problem. It is important to know that this code is still in alpha stages and is just a proof of concept for now. I will posting a bit later how I use this to create a UI component.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Drag.<span style="color: #660066;">Group</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	Implements <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>Options<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
&nbsp;
	options <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">'active'</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'store'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'drag-group-item'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'filter'</span> <span style="color: #339933;">:</span> $lambda<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'drag'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	elements <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
&nbsp;
	initialize <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setOptions</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	add <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> drag <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Drag.<span style="color: #660066;">Group</span>.<span style="color: #000066; font-weight: bold;">Item</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> $merge<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">drag</span><span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		el.<span style="color: #660066;">store</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">store</span><span style="color: #339933;">,</span> drag <span style="color: #009900;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">return</span> drag;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	start <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">active</span> || <span style="color: #339933;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
			el.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">store</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">filter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>match<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				match.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">store</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
Drag.<span style="color: #660066;">Group</span>.<span style="color: #000066; font-weight: bold;">Item</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">Extends</span> <span style="color: #339933;">:</span> Drag.<span style="color: #660066;">Move</span><span style="color: #339933;">,</span>
&nbsp;
	initialize <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span>group<span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">group</span> <span style="color: #339933;">=</span> group;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	start <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span>alerted<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>alerted<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">group</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">element</span><span style="color: #339933;">,</span>event<span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Drag.Group has the following options:</p>
<ul>
<li>active : boolean ( if active grouping behavior is performed, else default Drag.Move)</li>
<li>store : string ( used to store the custom drag obj on the element )</li>
<li>filter : function ( takes one parameter (element). return true or false if it is part of the active drag group</li>
<li>drag : object ( default drag options for newly created items see Drag )</li>
</ul>
<p>Usage :</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> drag_group <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Drag.<span style="color: #660066;">Group</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">'filter'</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'active'</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
drag_group.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>The &#8216;add&#8217; method takes an optional second parameter which is a &#8216;Drag.Move&#8217; options object. This allows for overriding the drag behavior on a single element. &#8216;add&#8217; is currently limited to only taking one element at a time. I will add array support later.</p>
<p>My biggest concern with the current interface is the number of &#8216;document&#8217; events that get created. I haven&#8217;t noticed any real issues in testing.</p>
<p>I will be following up with demos and extensions soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=266</wfw:commentRss>
		</item>
		<item>
		<title>Insights from Link Nudging</title>
		<link>http://www.nwhite.net/?p=258</link>
		<comments>http://www.nwhite.net/?p=258#comments</comments>
		<pubDate>Sun, 08 Feb 2009 00:41:08 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Mootools]]></category>

		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=258</guid>
		<description><![CDATA[Someone recently posted the question &#8220;Mootools link nudging?&#8221;. I honestly wasn&#8217;t familar with the term, at first I thought it was an SEO trick. I fired up google and quickly learned it was a css padding animation trick. I saw that David Walsh did a version in 
jquery

$&#40;'a.nudge'&#41;.hover&#40;function&#40;&#41; &#123; //mouse in  
	$&#40;this&#41;.animate&#40;&#123; paddingLeft: '20px' [...]]]></description>
			<content:encoded><![CDATA[<p>Someone recently posted the question &#8220;Mootools link nudging?&#8221;. I honestly wasn&#8217;t familar with the term, at first I thought it was an SEO trick. I fired up google and quickly learned it was a css padding animation trick. I saw that <a href="http://davidwalsh.name/">David Walsh</a> did a version in </p>
<p><a href="http://davidwalsh.name/jquery-link-nudging" rel="nofollow">jquery</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.nudge'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//mouse in  </span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> paddingLeft<span style="color: #339933;">:</span> <span style="color: #3366CC;">'20px'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span>;  
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//mouse out  </span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> paddingLeft<span style="color: #339933;">:</span> 0 <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">400</span><span style="color: #009900;">&#41;</span>;  
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>and <a href="http://davidwalsh.name/mootools-link-nudging" rel="nofollow">mootools</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.nudge'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>    
	<span style="color: #003366; font-weight: bold;">var</span> fx <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Fx.<span style="color: #660066;">Morph</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> duration<span style="color: #339933;">:</span><span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> link<span style="color: #339933;">:</span><span style="color: #3366CC;">'cancel'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;  
	el.<span style="color: #660066;">addEvents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>  
		<span style="color: #3366CC;">'mouseenter'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> fx.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'padding-left'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">20</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>  
		<span style="color: #3366CC;">'mouseleave'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> fx.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'padding-left'</span><span style="color: #339933;">:</span> 0 <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>  
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;  
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>I first noticed that the mootools code could be more &#8220;moo&#8221;.</p>
<blockquote><p>&#8216;$$&#8217; returns an &#8216;Elements&#8217; object. Elements acts like an array but extended with &#8216;$&#8217; (&#8217;Element&#8217;). Mootools has the generic &#8217;set&#8217; function for setting a multitude of things on each element. The &#8217;set&#8217; properties can be customized or added by extending &#8216;Element.Properties&#8217;.</p></blockquote>
<p><span id="more-258"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.nudge'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #3366CC;">'morph'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> duration<span style="color: #339933;">:</span> <span style="color: #CC0000;">400</span><span style="color: #339933;">,</span> link <span style="color: #339933;">:</span> <span style="color: #3366CC;">'cancel'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">'events'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">'mouseenter'</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">morph</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'padding-left'</span> <span style="color: #339933;">:</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'mouseleave'</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">morph</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'padding-left'</span> <span style="color: #339933;">:</span> 0<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
<span style="color: #006600; font-style: italic;">// or</span>
$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.nudge'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #3366CC;">'tween'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'property'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'padding-left'</span><span style="color: #339933;">,</span> duration<span style="color: #339933;">:</span> <span style="color: #CC0000;">400</span><span style="color: #339933;">,</span> link <span style="color: #339933;">:</span> <span style="color: #3366CC;">'cancel'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	<span style="color: #3366CC;">'events'</span> <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">'mouseenter'</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">tween</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'mouseleave'</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">tween</span><span style="color: #009900;">&#40;</span>0<span style="color: #009900;">&#41;</span>; <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p><a href="http://www.clientcide.com/code-snippets/visual-effects/link-nudging/">Aaron</a> points out in the comments that this method does have one drawback.</p>
<blockquote><p>The only issue here is that this instance of Fx.Morph could be accessed and altered by using the .morph shortcut again. If your work had any chance of morphing that object again you might want to segregate the instances. Still, a pretty rare edge case. I’d probably write it as you have it above.</p></blockquote>
<p><b>Update:</b><br />
As suggested below it should be in a class. Here you go.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> Nudger <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	Implements <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>Options<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
&nbsp;
	options <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		transition <span style="color: #339933;">:</span> Fx.<span style="color: #660066;">Transitions</span>.<span style="color: #660066;">linear</span><span style="color: #339933;">,</span>
		duration <span style="color: #339933;">:</span> <span style="color: #CC0000;">400</span><span style="color: #339933;">,</span>
		amount <span style="color: #339933;">:</span> <span style="color: #CC0000;">20</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	initialize <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>selector<span style="color: #339933;">,</span>options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setOptions</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span>;
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span> <span style="color: #339933;">=</span> $$<span style="color: #009900;">&#40;</span>selector<span style="color: #009900;">&#41;</span>;
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> nudge <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #3366CC;">'fx'</span> <span style="color: #339933;">:</span>  <span style="color: #003366; font-weight: bold;">new</span> Fx.<span style="color: #660066;">Morph</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> 
							duration<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">duration</span><span style="color: #339933;">,</span>  
							transition<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">transition</span><span style="color: #339933;">,</span>
							link<span style="color: #339933;">:</span><span style="color: #3366CC;">'cancel'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				<span style="color: #3366CC;">'enter'</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">enter</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span>el<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				<span style="color: #3366CC;">'leave'</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">leave</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span>el<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#125;</span>;
&nbsp;
			el.<span style="color: #660066;">addEvents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #3366CC;">'mouseenter'</span> <span style="color: #339933;">:</span> nudge.<span style="color: #660066;">enter</span><span style="color: #339933;">,</span>
				<span style="color: #3366CC;">'mouseleave'</span> <span style="color: #339933;">:</span> nudge.<span style="color: #660066;">leave</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
			el.<span style="color: #660066;">store</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'nudge'</span><span style="color: #339933;">,</span>nudge<span style="color: #009900;">&#41;</span>;
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	enter <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		el.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'nudge'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fx</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'padding-left'</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">amount</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	leave <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		el.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'nudge'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fx</span>.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'padding-left'</span> <span style="color: #339933;">:</span> 0<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	destroy <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">elements</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> nudge <span style="color: #339933;">=</span> el.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'nudge'</span><span style="color: #009900;">&#41;</span>;
			el.<span style="color: #660066;">removeEvents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #3366CC;">'mouseenter'</span> <span style="color: #339933;">:</span> nudge.<span style="color: #660066;">enter</span><span style="color: #339933;">,</span>
				<span style="color: #3366CC;">'mouseleave'</span> <span style="color: #339933;">:</span> nudge.<span style="color: #660066;">leave</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">/*
Default options:
   transition: Fx.Transitions.linear. // easing transition 
   duration: 400. // duration of effect
   amount : 20 // amount of pixels to move
&nbsp;
Usage:
&nbsp;
var nudger = new Nudger('a.nudge');
&nbsp;
// with amount changed
&nbsp;
var nudger = new Nudger('a.nudge',{amount : 40 });
&nbsp;
*/</span></pre></div></div>

<p>The class has the advantage of easily changing the transition effect, the duration and the amount the padding-left is moved. In addition I added a method to destroy the function. This will remove the functionality from the elements.</p>
<p>I shifted my attention toward the jquery example and immediately the code looked more cryptic. If the comments were removed the code would be even harder to follow. What is hover? I like speaking similar language as the DOM interface. I like frameworks but when you start to get unexpected results its good to be able to search for generic solutions, the high level abstraction in jquery makes this harder.  $ working as an array and a single value variable seems to me that it would make debugging harder in some cases. Also, what does that 400 do? Mootools passes objects as parameters, oh duration : 400. I have to know that &#8216;hover&#8217; takes two functions and the order. Again more time debugging subtle errors. Even code syntax gets harder with a bunch of anonymous functions and commas. </p>
<p>Walsh did something in his Mootools code that he didn&#8217;t do in jquery. The animation stops whenever the effect changes. This helps to create smooth transitions if you move in and out of the link. I discovered that the jquery code didn&#8217;t have this advantage. <a href="http://www.lateralcode.com/2008/12/link-nudging-with-jquery/">Lateral Code</a> had the solution:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span>
            paddingLeft<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;30px&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span>
            paddingLeft<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;0&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span>;
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>The problem solved with chaining the stop() method in. This code is pretty easy to maintain at the moment. While this is just a taste. From my point of view the scaling ability of the two sets of code is considerably different. </p>
<p>Your thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=258</wfw:commentRss>
		</item>
		<item>
		<title>Compressed JSON Requests</title>
		<link>http://www.nwhite.net/?p=242</link>
		<comments>http://www.nwhite.net/?p=242#comments</comments>
		<pubDate>Thu, 18 Dec 2008 22:49:01 +0000</pubDate>
		<dc:creator>nwhite</dc:creator>
		
		<category><![CDATA[Utilities]]></category>

		<category><![CDATA[compression]]></category>

		<category><![CDATA[JSON]]></category>

		<category><![CDATA[Mootools]]></category>

		<guid isPermaLink="false">http://www.nwhite.net/?p=242</guid>
		<description><![CDATA[I rarely find myself in a place where I am writing javascript applications that use AJAX in its pure form. I have long abandoned the &#8216;X&#8217; and replaced it with &#8216;J&#8217; (JSON).  When working with Javascript, it just makes sense to return JSON. Smaller footprint, easier parsing and an easier structure are all advantages [...]]]></description>
			<content:encoded><![CDATA[<p>I rarely find myself in a place where I am writing javascript applications that use AJAX in its pure form. I have long abandoned the &#8216;X&#8217; and replaced it with &#8216;J&#8217; (JSON).  When working with Javascript, it just makes sense to return JSON. Smaller footprint, easier parsing and an easier structure are all advantages I have gained since using JSON. </p>
<p>In a recent project I found myself unhappy with the large size of my result sets. The data I was returning was tabular data, in the form of objects for each row. I was returning a result set of 50, with 19 fields each. What I realized is if I augment my result set I could get a form of compression.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// uncompressed</span>
JSON <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
  data <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
     <span style="color: #009900;">&#123;</span> field1 <span style="color: #339933;">:</span> <span style="color: #3366CC;">'data1'</span><span style="color: #339933;">,</span> field2 <span style="color: #339933;">:</span> <span style="color: #3366CC;">'data2'</span><span style="color: #339933;">,</span> field3 <span style="color: #339933;">:</span> <span style="color: #3366CC;">'data3'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
     <span style="color: #009900;">&#123;</span> field1 <span style="color: #339933;">:</span> <span style="color: #3366CC;">'data4'</span><span style="color: #339933;">,</span> field2 <span style="color: #339933;">:</span> <span style="color: #3366CC;">'data5'</span><span style="color: #339933;">,</span> field3 <span style="color: #339933;">:</span> <span style="color: #3366CC;">'data6'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
     .....
  <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>;
&nbsp;
<span style="color: #006600; font-style: italic;">//compressed</span>
JSON <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    data <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'data1'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'data2'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'data3'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'data4'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'data5'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'data6'</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
    keys <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'field1'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'field2'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'field3'</span> <span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p> I merged all my values into a single array and store all my fields in a separate array. Returning a key value pair for each result cost me 8800 byte (8.6kb). Ripping the fields out and putting them in a separate array cost me 186 bytes. Total savings 8.4kb.</p>
<p>Now I have a much more compressed JSON file, but the structure is different and now harder to work with. So I implement a solution in Mootools to make the decompression transparent.<br />
<span id="more-242"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Request.<span style="color: #660066;">JSON</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	options <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		inflate <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
&nbsp;
Request.<span style="color: #660066;">JSON</span>.<span style="color: #660066;">implement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	success <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">response</span>.<span style="color: #660066;">json</span> <span style="color: #339933;">=</span> JSON.<span style="color: #660066;">decode</span><span style="color: #009900;">&#40;</span>text<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">secure</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">inflate</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">inflate</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>rule<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #003366; font-weight: bold;">var</span> ret <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>$defined<span style="color: #009900;">&#40;</span>rule.<span style="color: #660066;">store</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">response</span>.<span style="color: #660066;">json</span><span style="color: #009900;">&#91;</span>rule.<span style="color: #660066;">store</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">response</span>.<span style="color: #660066;">json</span><span style="color: #009900;">&#91;</span>rule.<span style="color: #660066;">data</span><span style="color: #009900;">&#93;</span>;
				ret <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">expandData</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">response</span>.<span style="color: #660066;">json</span><span style="color: #009900;">&#91;</span>rule.<span style="color: #660066;">data</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">response</span>.<span style="color: #660066;">json</span><span style="color: #009900;">&#91;</span>rule.<span style="color: #660066;">keys</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>;
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">onSuccess</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">response</span>.<span style="color: #660066;">json</span><span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	expandData <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span>keys<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>;
		<span style="color: #003366; font-weight: bold;">var</span> len <span style="color: #339933;">=</span> data.<span style="color: #660066;">length</span>; <span style="color: #003366; font-weight: bold;">var</span> klen <span style="color: #339933;">=</span> keys.<span style="color: #660066;">length</span>;
		<span style="color: #003366; font-weight: bold;">var</span> start <span style="color: #339933;">=</span> 0; <span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">stop</span> <span style="color: #339933;">=</span> klen;
		<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">stop</span> <span style="color: #339933;">&lt;</span> len<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			arr.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> data.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span>start<span style="color: #339933;">,</span><span style="color: #000066;">stop</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">associate</span><span style="color: #009900;">&#40;</span>keys<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>;
			start <span style="color: #339933;">=</span> <span style="color: #000066;">stop</span>; <span style="color: #000066;">stop</span> <span style="color: #339933;">+=</span> klen;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">return</span> arr;
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Request.JSON now has an inflate option. You can inflate multiple segments of your JSON object if you so desire.</p>
<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">new</span> Request.<span style="color: #660066;">JSON</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
       url <span style="color: #339933;">:</span> <span style="color: #3366CC;">'url'</span><span style="color: #339933;">,</span>
       inflate <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'keys'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'fields'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'data'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'data'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
       onComplete <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>json<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Pass as many inflate objects as you like to the option inflate array. It has an optional property called &#8217;store&#8217; If set the inflated data set will be stored in that key instead.</p>
<p>The &#8216;keys&#8217; and &#8216;fields&#8217; expect strings to match a location in the root of your JSON object.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nwhite.net/?feed=rss2&amp;p=242</wfw:commentRss>
		</item>
	</channel>
</rss>
