<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ajax Bestiary &#187; Tutorial</title>
	<atom:link href="http://www.ajaxbestiary.com/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ajaxbestiary.com</link>
	<description>AJAX Development, News, Techniques &#38; More</description>
	<lastBuildDate>Wed, 01 Feb 2012 12:46:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Full Screen API embiggens the lowliest of web apps</title>
		<link>http://www.ajaxbestiary.com/2012/01/11/full-screen-api-embiggens-the-lowliest-of-web-apps/</link>
		<comments>http://www.ajaxbestiary.com/2012/01/11/full-screen-api-embiggens-the-lowliest-of-web-apps/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 12:00:49 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[full screen]]></category>
		<category><![CDATA[fullscreen]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=605</guid>
		<description><![CDATA[Please forgive the Simpsons reference in the title, but let&#8217;s face it, browsers eat up an enormous amount of screen real estate with menu bars, super bars, status bars, toolbars, scrollbars. And that&#8217;s all before you get to the white space and toolbars and menus your own app requires. Sure, you can press F11 today [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Please forgive the Simpsons reference in the title, but let&#8217;s face it, browsers eat up an enormous amount of screen real estate with menu bars, super bars, status bars, toolbars, scrollbars. And that&#8217;s all before you get to the white space and toolbars and menus your own app requires.</p>
<p>Sure, you can press F11 today in pretty much every browser and achieve that end, but how many of us actually do that? If we&#8217;re the power users and we don&#8217;t do that, what hope do we have for our users?</p>
<p>The <a href="http://dvcs.w3.org/hg/fullscreen/raw-file/tip/Overview.html">Full Screen API</a> will make it easy to do automatically. Better still, pre-release versions of this API are already supported in Firefox 9 and Chrome 15 (though disabled by default in Firefox 9).</p>
<p>To get you started, the Mozilla Developer Network has released its own <a href="https://developer.mozilla.org/en/DOM/Using_full-screen_mode">guide to the interface</a>.</p>
<p>In brief, there are a few key requirements:</p>
<ol>
<li>The calling object for <code>requestFullScreen()</code> must be a DOM node</li>
<li>The DOM node may not be the child or parent of a plugin</li>
<li>If the DOM node is an IFRAME (or is the parent or child of one), the IFRAME must have an <code>allowfullscreen=&quot;true&quot;</code> attribute</li>
</ol>
<p>So what does real-world code look like? Let&#8217;s take a look at Mozilla&#8217;s own example:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> toggleFullScreen<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;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">fullScreenElement</span> <span style="color: #339933;">&amp;&amp;</span> document.<span style="color: #660066;">fullScreenElement</span> <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span>    <span style="color: #006600; font-style: italic;">// alternative standard method</span>
      <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>document.<span style="color: #660066;">mozFullScreen</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>document.<span style="color: #660066;">webkitIsFullScreen</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>               <span style="color: #006600; font-style: italic;">// current working methods</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>videoElement.<span style="color: #660066;">requestFullScreen</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      videoElement.<span style="color: #660066;">requestFullScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>elem.<span style="color: #660066;">mozRequestFullScreen</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      videoElement.<span style="color: #660066;">mozRequestFullScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>elem.<span style="color: #660066;">webkitRequestFullScreen</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      videoElement.<span style="color: #660066;">webkitRequestFullScreen</span><span style="color: #009900;">&#40;</span>Element.<span style="color: #660066;">ALLOW_KEYBOARD_INPUT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">cancelFullScreen</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      document.<span style="color: #660066;">cancelFullScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">mozCancelFullScreen</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      document.<span style="color: #660066;">mozCancelFullScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">webkitCancelFullScreen</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      document.<span style="color: #660066;">webkitCancelFullScreen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></code></p>
<p>As you can see, the naming conventions aren&#8217;t quite there yet. Further, neither Firefox nor Chrome quite apply the CSS expectations of the developing standard.</p>
<p>When the calls fire successfully, either fullscreenchange, mozfullscreenchange or webkitfullscreenchange events will fire. Likewise, when it fails, either fullscreenerror, mozfullscreenerror or webkitfullscreenerror events fire.</p>
<p>Note also that in Firefox 9, you cannot use a form in fullscreen mode; pressing any key inside of an input seems to take you out of Full Screen mode. The browser provides no instructions for exiting fullscreen mode, so you will need to provide them yourself.</p>
<p>Confusingly, the ALLOW_KEYBOARD_INPUT parameter in the webkitRequestFullScreen() call seems to block the keystroke handler in the MDN sample, though forms once again work. It also provides instructions for exiting Full Screen mode, though it neglects to mention that Esc will do it as well, instead referring to Command + Shift + F on my Mac.</p>
<p>Still, Firefox 10 is expected to support the API out of the box, so we can start to see the development of true browser application environments. The possibilities for kiosk environments are also exciting.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2012/01/11/full-screen-api-embiggens-the-lowliest-of-web-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grids a la CANVAS</title>
		<link>http://www.ajaxbestiary.com/2011/12/29/grids-a-la-canvas/</link>
		<comments>http://www.ajaxbestiary.com/2011/12/29/grids-a-la-canvas/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 12:00:14 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=556</guid>
		<description><![CDATA[There are lots of grid libraries out there. Naturally, this means we need to reinvent the wheel. With HTML5, we have a fantastic new tool called the CANVAS tag which frees us from the limitations of CSS. The canvas tag is beautifully documented and supported on most modern browsers. Further, aside from IE 6-8, the [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>There are lots of <a href="http://gridr.atomeye.com/">grid</a> <a href="http://twitter.github.com/bootstrap/">libraries</a> <a href="http://blueprintcss.org/">out</a> <a href="http://developer.yahoo.com/yui/grids/">there</a>. Naturally, this means we need to reinvent the wheel. With HTML5, we have a fantastic new tool called the CANVAS tag which frees us from the limitations of CSS.</p>
<p>The canvas tag is <a href="http://blog.nihilogic.dk/2009/02/html5-canvas-cheat-sheet.html">beautifully documented</a> and <a href="http://en.wikipedia.org/wiki/Canvas_element#Support">supported on most modern browsers</a>. Further, aside from IE 6-8, the vast majority of the browsers support the element <strong>as it is defined</strong>, which means we don&#8217;t need wrapping libraries to deal with browser quirks.</p>
<p>Using all of these libraries as baselines, there are a few essential pieces of functionality:<br />
We must be dimension agnostic. Whether our space is 480px or 2560px wide, it should work well<br />
We must support any number of columns<br />
We must support <em>n</em>-wide columns<br />
We must support arbitrary gutter sizes<br />
We must get results consistent with those other libraries</p>
<p>To that end, I present the grid() function. It returns an object with an array of offsets, as well as plenty of other information that facilitates writing still more content to the canvas (or advanced features like simulating sub-columns). It has no library dependencies, although it currently does not gracefully handle older browsers.</p>
<p>Basic usage is simple:<br />
<code>
<pre>result = AB.grid(canvas, 16, 20);</pre>
<p></code></p>
<p>This one line takes the canvas element specified in the first parameter and divides it into 16 columns separated by 20 pixel gutters. The function returns an object that looks like this:</p>
<p><code>
<pre>
{
   cols: 16,
   element: canvas#tutorial,
   gutter: 20,
   offsets: [0, 60, 120, ..., 900],
   width: 40
}
</pre>
<p></code></p>
<p>You can also pass arrays:<br />
<code>
<pre>result = AB.grid(canvas, [1, 3, 1], 10);</pre>
<p></code></p>
<p>This divides the element into a 20% panel on the left and right and 60% in the middle. Now our response looks like this:</p>
<p><code>
<pre>
{
   cols: 3,
   element: canvas#tutorial,
   gutter: 20,
   offsets: [0, 194, 756],
   width: 186
}
</pre>
<p></code></p>
<p>Let&#8217;s go changing the colors:<br />
<code>
<pre>result = AB.grid(canvas, [1, 4], 10, { foreground: '#CCC', background: '#EEE' });</pre>
<p></code></p>
<p>Need to pad the outer margins as well?<br />
<code>
<pre>result = AB.grid(canvas, [1, 4], 10, { includeOuter: true });</pre>
<p></code></p>
<p>Maybe we just want to simulate the arithmetic, without drawing anything?<br />
<code>
<pre>result = AB.grid(canvas.width, [1, 4], 10);</pre>
<p></code></p>
<p>This would also work:<br />
<code>
<pre>result = AB.grid(canvas, [1, 4], 10, { overrideWidth: canvas.width });</pre>
<p></code></p>
<p>Now you&#8217;re probably saying that this is all well and good, but why bother when we are already using a CSS layout library for the site in general? Aside from making it easier to construct graphs, we can also use this to generate perfectly sized images within the client.</p>
<p>The following three lines will create an image tag from a canvas and do it faster than the human eye can detect:</p>
<p><code>
<pre>
var img = document.createElement('img');
img.setAttribute('src', canvas.toDataURL());
document.getElementsByTagName('body')[0].appendChild(img);
</pre>
<p></code></p>
<p>You could almost as easily assign it as a background image (here I am finally employing jQuery):<br />
<code>
<pre>
$('body').css('background', 'url(' + canvas.toDataURL() + ')');
</pre>
<p></code></p>
<p>Note that you must wrap the image data in the strings <code>url(</code> and <code>)</code> for this to work.</p>
<p>Check out the code on <a href="https://github.com/ajaxbestiary/ajaxbestiary.github.com">GitHub</a>.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/12/29/grids-a-la-canvas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to: Detect display density</title>
		<link>http://www.ajaxbestiary.com/2011/12/09/how-to-detect-display-density/</link>
		<comments>http://www.ajaxbestiary.com/2011/12/09/how-to-detect-display-density/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 13:30:24 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[density]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[display density]]></category>
		<category><![CDATA[pixel density]]></category>
		<category><![CDATA[resolution]]></category>
		<category><![CDATA[screen density]]></category>
		<category><![CDATA[screen resolution]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=535</guid>
		<description><![CDATA[In some of my past projects, I&#8217;ve had a strong desire to know the pixel density of the display device. In traditional desktop environments, we could reasonably trust that an assumption of 72dpi would work well, but on mobile devices this is not the case. The iPhone 4 packs twice as many pixels in an [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>In some of my past projects, I&#8217;ve had a strong desire to know the pixel density of the display device. In traditional desktop environments, we could reasonably trust that an assumption of 72dpi would work well, but on mobile devices this is not the case. The iPhone 4 packs twice as many pixels in an inch as the 3GS and Android devices vary wildly, while it sometimes feels like you can visually distinguish the individual pixels on older Blackberry devices.</p>
<p>Meanwhile, you still need everything to fit as close to pixel-perfect as possible. On the server-side, this requires a massive database, like <a href="http://dbapi.scientiamobile.com/">Tera-WURFL</a>, but on the client-side, we can use a fast and simple script.</p>
<p>For the purposes of this post, I will use jQuery, but you can use the framework of your choice to achieve the same end.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 test.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;1 inch&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;1 inch&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #003366; font-weight: bold;">var</span> yDensity <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>test.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #003366; font-weight: bold;">var</span> xDensity <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>test.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 test.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>First, I create a DIV with some minimal level of content, since mobile browsers like to collapse (or even ignore!) empty DOM nodes to improve performance.</p>
<p>Then I set its dimensions. I tried setting the dimensions as part of the style, but curiously, Firefox chose to ignore it so I didn&#8217;t even bother testing this behavior in Safari.</p>
<p>Now I can use the height() and width() methods in jQuery, which return an integer representing the number of pixels. Note that I have to round this figure, because those listed pixel densities are sometimes approximate. You&#8217;ll definitely get a float if you use metric units, of course.</p>
<p>Finally, I remove the node, as we no longer require it. Note that we never attached it to the DOM, so we never influenced rendering of the actual page.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/12/09/how-to-detect-display-density/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Event-driven development with Backbone</title>
		<link>http://www.ajaxbestiary.com/2011/12/05/event-driven-development-with-backbone/</link>
		<comments>http://www.ajaxbestiary.com/2011/12/05/event-driven-development-with-backbone/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 15:00:06 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Javascript Frameworks]]></category>
		<category><![CDATA[Misc Toolkits]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=527</guid>
		<description><![CDATA[Do you really care if the user clicks an option inside of a SELECT? In most cases, it&#8217;s only a means to the end of getting the new value. So why is your change event handler sending data to the server and modifying the DOM? This leads to spaghetti code, violation of DRY and ever [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Do you really care if the user clicks an option inside of a SELECT? In most cases, it&#8217;s only a means to the end of getting the new value. So why is your change event handler sending data to the server and modifying the DOM? This leads to spaghetti code, violation of DRY and ever more expensive maintenance costs as your app&#8217;s interface evolves.</p>
<p>Thus was born Backbone, an extension of <a href="http://www.ajaxbestiary.com/2011/09/23/underscore-js-jquery-without-the-dom/" title="Underscore.js: jQuery without the DOM">underscore</a>, with default support for jQuery, and with a bit of editing, support for <a href="https://github.com/gaustin/backbone-mootools">MooTools</a>.</p>
<p>So let&#8217;s say you&#8217;re Amazon and you&#8217;re trying to find a way to comply with the legal requirements in some states that say affiliate sold items are subject to sales tax. This is complex and you probably only want to get the most relevant data as late in the process as possible. Backbone makes it surprisingly easy.</p>
<p>Bind to a change event on our data object:<br />
<code>
<pre>
var destination = new Backbone.Model();

_.extend(destination, {state: null});

var order = {
  subtotal: 100,
  tax: 0,
  total: 100
};

//underscore makes it easy to pseudo-subclass
_.extend(order, new Backbone.View());

destination.bind( "change", function() {
  //Pass null in the first parameter to save all model properties
  destination.save(null, {
    success: function(model, reps, xhr){
      //Apply the tax rate
      order.total = order.subtotal + order.subtotal * xhr.taxrate;

      //Update display. Note that this is a no-op by default and
      //you should define it as needed elsewhere.
      order.render();
    }
  } );
} );
</pre>
<p></code></p>
<p>Now for our event handler on the SELECT. Note that I&#8217;m using jQuery, but you could use any library (or none at all).</p>
<p><code>
<pre>
$("#state").change( function() {
  //Do whatever pre-processing is required
  var v = $(this).val();

  //This could be generalized very easily
  destination.set({
    state: v
  });
} );
</pre>
<p></code></p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/12/05/event-driven-development-with-backbone/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Why you should care about MooTools</title>
		<link>http://www.ajaxbestiary.com/2011/06/09/why-you-should-care-about-mootools/</link>
		<comments>http://www.ajaxbestiary.com/2011/06/09/why-you-should-care-about-mootools/#comments</comments>
		<pubDate>Fri, 10 Jun 2011 01:26:19 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[Javascript Frameworks]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[js framework]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=422</guid>
		<description><![CDATA[Let me start by saying that I love jQuery. Most of the time, it makes it very easy to write sane code. Sometimes, however, it just feels weird. For example, let&#8217;s say we need to insert a link at the beginning of a div. You might write something like: $&#40;'#myDiv'&#41;.prepend&#40;'&#60;a href=&#34;http://my.host/path&#34; title=&#34;This is a cool [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Let me start by saying that I love jQuery. Most of the time, it makes it very easy to write sane code. Sometimes, however, it just feels weird.</p>
<p>For example, let&#8217;s say we need to insert a link at the beginning of a div. You might write something like:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#myDiv'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prepend</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a href=&quot;http://my.host/path&quot; title=&quot;This is a cool link!&quot;&gt;Click here&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>-or-</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a href=&quot;http://my.host/path&quot; title=&quot;This is a cool link!&quot;&gt;Click here&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prependTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#myDiv'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It seems fairly straightforward, but it&#8217;s a maintenance nightmare, because you now have raw HTML buried inside of your Javascript. If it&#8217;s complicated HTML that is being dynamically constructed, it&#8217;s all too easy to introduce hard to find browser parser errors.</p>
<p><a href="http://mootools.net/">MooTools</a>, on the other hand, gives you a powerful alternative with its Element class.</p>
<p>To create a new DOM element you literally call a constructor and pass the tag name and attributes to it. So, for example, that same link would be built with:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myLink <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
 href<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http://my.host/path&quot;</span><span style="color: #339933;">,</span>
 title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;This is a cool link!&quot;</span><span style="color: #339933;">,</span>
 text<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Click here&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>At the price of a handful of few extra bytes, you get clear, legible code. The equivalent of .prepend() is thus:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#myDiv'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">grab</span><span style="color: #009900;">&#40;</span>myLink<span style="color: #339933;">,</span> <span style="color: #3366CC;">'top'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>While this might at first seem less intuitive, you can use the same method call to insert that link before or after the selected element. Sure, you could do that with .before() or .after() in jQuery, but imagine if you needed to make the insertion point variable!</p>
<p>There are also a slew of additional benefits, like ECMAScript 5 array methods, support for <a href="http://www.anup.info/2010/07/12/mootools-class-methods-and-inheritance/">multiple inheritance</a>, and event handlers that make it easy to detect if the user is pressing Alt while right clicking.</p>
<p>Give MooTools a try, but before you do, I strongly urge you to read Sean McArthur&#8217;s excellent post, <a href="http://mootools.net/blog/2010/03/19/a-better-way-to-use-elements/">A Better Way to use Elements</a>, on the difference between $() and $$(). If you come from a background of using Prototype, it will seem perfectly natural, but jQuery users can be caught by surprise.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/06/09/why-you-should-care-about-mootools/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Getting Started With Chrome Frame</title>
		<link>http://www.ajaxbestiary.com/2011/06/06/getting-started-with-chrome-frame/</link>
		<comments>http://www.ajaxbestiary.com/2011/06/06/getting-started-with-chrome-frame/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 02:47:24 +0000</pubDate>
		<dc:creator>Don Albrecht</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Chrome frame]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Trident]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=416</guid>
		<description><![CDATA[As a follow up to my last post, I thought I&#8217;d put out an instruction on actually creating a Google Chrome retreat. Step 1: Add a Chrome Frame header to your site. Add this to the head of the Chrome Frame dependent pages: &#60;meta http-equiv="X-UA-Compatible" content="chrome=1"&#62;. If this isn&#8217;t practical, You can also configure your [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>As a follow up to my last post, I thought I&#8217;d put out an instruction on actually creating a Google Chrome retreat.</p>
<h3>Step 1: Add a Chrome Frame header to your site.</h3>
<p>Add this to the head of the Chrome Frame dependent pages:</p>
<p><code>&lt;meta</code> <code>http-equiv</code><code>=</code><code>"X-UA-Compatible"</code> <code>content</code><code>=</code><code>"chrome=1"</code><code>&gt;. </code></p>
<p>If this isn&#8217;t practical, You can also configure your server to send an HTTP header of</p>
<p><code>X-UA-Compatible: </code><code>chrome=1</code></p>
<p>I advise against this approach, however because server configs won&#8217;t be immediately available to other users on a site.  By its nature, a Chrome Frame retreat should be considered a reasonably unique event.  It&#8217;s good to clearly document this dependency for anyone else who may need to debug things later.  Once you&#8217;ve started to retreat, make sure you&#8217;re applying the header to every page of the site.  The two engines render things differently and you may create an inconsistent experience for your users if they are transitioning between Chrome Frame and Trident environments frequently.  In my experience, border-radius and drop shadow toggling on and off is a pretty strong &#8220;It&#8217;s Broken&#8221; signal for end users.</p>
<p>Step 2: Identify your Dependency Wall.</p>
<ol>
<li>Identify the range of pages / screens in your web app that you can&#8217;t support in IE.</li>
<li>Identify the navigation routes to those pages.</li>
<li>Leverage the routes to find natural locations for gatekeepers.
<ol>
<li>
<ol>
<li>Login Screens (the perfect location)</li>
<li>Tutorial Screens (A natural context fit for users)</li>
<li>An Advanced Mode (Similar to the &#8220;enriched mode&#8221; Microsoft uses for ActiveX requiring cloud apps).</li>
</ol>
</li>
</ol>
<ul>
<li>If you&#8217;re lucky, this will be a screen somewhere beyond your conversion pipeline.</li>
</ul>
</li>
<li>Create an interception event for IE users.  You can bake this into your app, but the easy way is with conditional comments.
<ol>
<li>Identify the Dom Nodes in your layout that must be presented to the user for them to progress.</li>
<li>&lt;div id=&#8217;loginbox&#8217;&gt;&#8230;&lt;/div&gt;</li>
<li>Create a conditional comment to hide the nodes and prompt the user to install Chrome Frame.</li>
</ol>
<ol>
<li>Be careful of z-index.  The chrome install iframe doesn&#8217;t work well if IE is floating some other content node on top of the install button.</li>
<li>UN-INSTALL chrome frame once you&#8217;ve tested your retreat perimeter.  This is a big deal for ongoing development as you won&#8217;t be testing in IE otherwise.</li>
<li>Becareful about your conversion pipeline.  Your key selling points may be behind the perimeter, but the act of demanding Chrome Frame is a pretty severe barrier to forward movement.</li>
</ol>
</li>
<p><code>&lt;html&gt;<br />
&lt;body&gt; &lt;div id='prompt'&gt;&lt;/div&gt;</code><code> &lt;!--[if IE]&gt;</code><br />
<code> &lt;script</code> <code>type</code><code>=</code><code>"text/javascript"</code><br />
<code> src</code><code>=</code><code>"http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"</code><code>&gt;</code><code>&lt;/script&gt;</code><br />
<code> &lt;style&gt;<br />
#loginBox{<br />
display:none;<br />
}<br />
&lt;/style&gt; </code><span style="color: #351c75;"></span><br />
<code> &lt;script&gt; </code></p>
<p><code> window.attachEvent("onload", function() {</code><br />
<code> </code><code>CFInstall</code><code>.</code><code>check</code><code>({</code><br />
<code> mode: </code><code>"inline"</code><code>, </code><br />
<code> </code><code>}); </code> });<br />
<code> &lt;/script&gt; </code><code> &lt;![endif]--&gt;</code><br />
<code>&lt;/body&gt;<br />
&lt;/html&gt;</code></p>
<h3>Other Lessons Learned</h3>
<p>Here&#8217;s a few lessons learned from deploying this.</p>
<p>&nbsp;</ol>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2011/06/06/getting-started-with-chrome-frame/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting and setting values for jQuery widgets</title>
		<link>http://www.ajaxbestiary.com/2009/12/11/getting-and-setting-values-for-jquery-widgets/</link>
		<comments>http://www.ajaxbestiary.com/2009/12/11/getting-and-setting-values-for-jquery-widgets/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 22:30:34 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Widget]]></category>
		<category><![CDATA[Widgets]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=397</guid>
		<description><![CDATA[If you come from an OOP background you’re likely used to defining class variables like this: class MyClass &#123; var internalValue1; var internalValue2; function constructor&#40;&#41; &#123; … &#125; &#125; The values which are to be stored in your object are simple, straightforward, likely to be typed, and the compiler will detect typos in the variable [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>If you come from an OOP background you’re likely used to defining class variables like this:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">class</span> MyClass <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> internalValue1<span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> internalValue2<span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">function</span> constructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  … <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p></code></p>
<p>The values which are to be stored in your object are simple, straightforward, likely to be typed, and the compiler will detect typos in the variable names. JavaScript, as a loosely types language which treats its objects more like collections than discrete objects, can’t really offer us those protections. Conversely, that also means that we have a great deal of flexibility.</p>
<p>In essence, we can dynamically subclass our objects, which you have to admit is a neat trick.</p>
<p>So, for jQuery.UI widgets, the variables stored within our widget are not defined until we assign them. The act of assignment defines the variable name, which can then be called upon at will.</p>
<p>Assignment is simply:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>._setData<span style="color: #009900;">&#40;</span>‘variablename’<span style="color: #339933;">,</span> variablevalue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p>Retrieval of this value is similarly straightforward:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">this</span>._getData<span style="color: #009900;">&#40;</span>‘variablename’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p>This does mean that the old problem of misnamed variables is alive and well. It also means that you need to be prepared to handle an undefined response to the _getData call.</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2009/12/11/getting-and-setting-values-for-jquery-widgets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Constraining a numeric value to a range</title>
		<link>http://www.ajaxbestiary.com/2009/12/09/constraining-a-numeric-value-to-a-range/</link>
		<comments>http://www.ajaxbestiary.com/2009/12/09/constraining-a-numeric-value-to-a-range/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 18:00:55 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=393</guid>
		<description><![CDATA[Okay, so this doesn’t strictly have anything to do with any JavaScript library, but it’s a handy little snippet of code to keep in your arsenal. val = Math.max&#40;cMin, Math.min&#40;val, cMax&#41;&#41;; In one line of code, we’ve automatically constrained val between cMin and cMax. Note that if cMax and cMin are reversed (cMax is less [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Okay, so this doesn’t strictly have anything to do with <em>any</em> JavaScript library, but it’s a handy little snippet of code to keep in your arsenal.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">val <span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>cMin<span style="color: #339933;">,</span> Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span>val<span style="color: #339933;">,</span> cMax<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p>In one line of code, we’ve automatically constrained val between cMin and cMax. Note that if cMax and cMin are reversed (cMax is less than cMin) val will immediately be set to cMin (the higher of the values).</p>
<p>We can, of course, rectify this when cMin and cMax are assigned values by calling</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">cMin <span style="color: #339933;">=</span> Math.<span style="color: #660066;">min</span><span style="color: #009900;">&#40;</span>cMin<span style="color: #339933;">,</span> cMax<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
cMax <span style="color: #339933;">=</span> Math.<span style="color: #660066;">max</span><span style="color: #009900;">&#40;</span>cmin<span style="color: #339933;">,</span> cMax<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2009/12/09/constraining-a-numeric-value-to-a-range/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Event handling in jQuery widgets</title>
		<link>http://www.ajaxbestiary.com/2009/12/08/event-handling-in-jquery-widgets/</link>
		<comments>http://www.ajaxbestiary.com/2009/12/08/event-handling-in-jquery-widgets/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 18:00:57 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Widget]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=390</guid>
		<description><![CDATA[This is simple – provided you understand that the reference the keyword this refers to changes depending on when it is called. When called during initialization, this refers to the widget you’re initializing. When the event itself is triggered, this refers to the DOM node node and not the widget. As such, we need to [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>This is simple – provided you understand that the reference the keyword <strong>this</strong> refers to changes depending on when it is called.</p>
<p>When called during initialization, <strong>this</strong> refers to the widget you’re initializing. When the event itself is triggered, <strong>this</strong> refers to the DOM node node and not the widget.</p>
<p>As such, we need to introduce a new variable during initialization which the jQuery.UI library calls <strong>self</strong> which is, of course, equal to the initialization <strong>this</strong>, not triggered <strong>this</strong>. (Those of you familiar with Object Oriented Programming and by-reference calls should have no issue with this concept).</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>$.<span style="color: #660066;">widget</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ui.clicker&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
   _init<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>
      self <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">element</span>.<span style="color: #660066;">click</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>
         self.<span style="color: #660066;">increment</span><span style="color: #009900;">&#40;</span>self<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         self.<span style="color: #660066;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</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;">render</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
   increment<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      target.<span style="color: #660066;">value</span><span style="color: #009900;">&#40;</span>target.<span style="color: #660066;">value</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #006600; font-style: italic;">//The exact handling of target.value will be shown another day</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
   render<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;">element</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
   value<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>val<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><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p>You’ll note that we have to pass <strong>self</strong> to the increment method or the widget won’t actually be able to find itself, but the render method, which was called during initialization, is henceforth always able to correctly reference <strong>this</strong> (the widget)!</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2009/12/08/event-handling-in-jquery-widgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Customized context menu handling with jQuery</title>
		<link>http://www.ajaxbestiary.com/2009/12/07/customized-context-menu-handling-with-jquery/</link>
		<comments>http://www.ajaxbestiary.com/2009/12/07/customized-context-menu-handling-with-jquery/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 22:26:33 +0000</pubDate>
		<dc:creator>Dave Mahon</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[context menu]]></category>
		<category><![CDATA[right click]]></category>

		<guid isPermaLink="false">http://www.ajaxbestiary.com/?p=384</guid>
		<description><![CDATA[Can you think of some times you might want to disable the right click context menu? Or better still, insert your own behavior or application specific context menu? This is a simple and useful trick: element.bind&#40;'contextmenu',function&#40;e&#41;&#123; //Optional customized handling here return false; &#125;&#41;; If you don’t return false, the normal context menu will appear, which [...]]]></description>
			<content:encoded><![CDATA[
<!-- google_ad_section_start -->
<p>Can you think of some times you might want to disable the right click context menu? Or better still, insert your own behavior or application specific context menu?</p>
<p>This is a simple and useful trick:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">element.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'contextmenu'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Optional customized handling here</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p>If you don’t return false, the normal context menu will appear, which could actually be desirable, depending on what exactly you want it to do (say, exiting a field and recording it as dirty).</p>
<p><img src="http://www.ajaxbestiary.com/?voyeur=1"></p>
<!-- google_ad_section_end -->
]]></content:encoded>
			<wfw:commentRss>http://www.ajaxbestiary.com/2009/12/07/customized-context-menu-handling-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

