<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Mellentine Design</title>
	
	<link>http://design.mellentine.com</link>
	<description>The maniacal musings of a pixel perfectionist</description>
	<pubDate>Thu, 11 Dec 2008 23:47:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/MellentineDesign" type="application/rss+xml" /><feedburner:emailServiceId>1825332</feedburner:emailServiceId><feedburner:feedburnerHostname>http://www.feedburner.com</feedburner:feedburnerHostname><item>
		<title>JAVASCRIPT: jQuery zoom event plugin</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/482128971/</link>
		<comments>http://design.mellentine.com/2008/12/11/javascript-jquery-zoom-event-plugin/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 23:35:08 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/?p=34</guid>
		<description><![CDATA[I don&#8217;t normally write code that I&#8217;m not ready to use, but I made an exception for this jQuery plugin.  It doesn&#8217;t really do all that I wanted it to do, but it&#8217;s good enough for a release.

Before I lose the ADD/ADHD folks: Demo.
The goal for this plugin was to create a event handler for [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t normally write code that I&#8217;m not ready to use, but I made an exception for this jQuery plugin.  It doesn&#8217;t really do all that I wanted it to do, but it&#8217;s good enough for a release.<br />
<span id="more-34"></span><br />
Before I lose the ADD/ADHD folks: <a href="/demos/jquery-zoom/" title="jQuery zoom() event demo">Demo</a>.</p>
<p>The goal for this plugin was to create a event handler for text and page zooming in a browser window.  While this can&#8217;t be accomplished entirely without some better event support in the browsers, I can watch for keyboard and mouse shortcuts that result in zooming.</p>
<p>This plugin itself doesn&#8217;t care if you zoomed in or out.  It just runs the callback function when you zoom.  Maybe at a later point, I&#8217;ll add that feature.</p>
<p>Without any further ado, here&#8217;s the plugin code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">zoom</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>fn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</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: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">case</span> jQuery.<span style="color: #660066;">browser</span>.<span style="color: #660066;">mozilla</span> || jQuery.<span style="color: #660066;">browser</span>.<span style="color: #660066;">msie</span> <span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">ctrlKey</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">187</span> ||
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">189</span> ||
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">107</span> ||
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">109</span> ||
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">96</span>  ||
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">48</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> fn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000066; font-weight: bold;">break</span>;
      <span style="color: #000066; font-weight: bold;">case</span> jQuery.<span style="color: #660066;">browser</span>.<span style="color: #660066;">opera</span> <span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">43</span> ||
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">45</span> ||
          e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">42</span> ||
          <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">ctrlKey</span> <span style="color: #339933;">&amp;&amp;</span> e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">48</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#41;</span> fn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000066; font-weight: bold;">break</span>;
      <span style="color: #000066; font-weight: bold;">case</span> jQuery.<span style="color: #660066;">browser</span>.<span style="color: #660066;">safari</span> <span style="color: #339933;">:</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">metaKey</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>
          e.<span style="color: #660066;">charCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">43</span> ||
          e.<span style="color: #660066;">charCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">45</span>
        <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> fn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
        <span style="color: #000066; font-weight: bold;">break</span>;
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">return</span>;
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
  jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mousewheel'</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">ctrlKey</span><span style="color: #009900;">&#41;</span> fn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
  jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'DOMMouseScroll'</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">ctrlKey</span><span style="color: #009900;">&#41;</span> fn<span style="color: #009900;">&#40;</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>;</pre></td></tr></table></div>

<p>Because we&#8217;re dealing with browser implementations of keyboard shortcuts, I decided to use jQuery.browser (which uses navigator.useragent) to deal with the browsers individually.  Much to my surprise (and delight), Internet Explorer and Firefox handle zooming identically.</p>
<p>Lines 2 - 30 deal with zooming through keyboard shortcuts.  The character codes are as follows:<br />
<strong>42</strong>: * (numpad)<br />
<strong>43</strong>: + (numpad)<br />
<strong>45</strong>: - (numpad)<br />
<strong>48</strong>: 0 (numpad in FF and IE)<br />
<strong>96</strong>: 0<br />
<strong>107</strong>: + (numpad in FF and IE)<br />
<strong>109</strong>: - (numpad in FF and IE)<br />
<strong>187</strong>: +<br />
<strong>189</strong>: -</p>
<p>Lines 32-38 deal with scrollwheel zooming in Firefox and IE.  Opera doesn&#8217;t run the callback function for the scrollwheel when the CTRL key is pressed (which is how scrollwheel zooming is done in Opera).  Safari 2 (which is what I have) doesn&#8217;t support scrollwheel zooming at all.</p>
<p>Further testing needs to be done in Safari 3, but this plugin works pretty well as is.  Here&#8217;s how you&#8217;d use it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">zoom</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'I zoomed'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>Here&#8217;s the <a href="/downloads/jquery.zoom.js" title="jQuery zoom() event plugin">download</a> and the <a href="/demos/jquery-zoom/" title="jQuery zoom() event demo">demo</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/12/11/javascript-jquery-zoom-event-plugin/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/12/11/javascript-jquery-zoom-event-plugin/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: The start of a jQuery zoom event handler</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/481322162/</link>
		<comments>http://design.mellentine.com/2008/12/11/javascript-the-start-of-a-jquery-zoom-event-handler/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 05:40:31 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[events]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/?p=31</guid>
		<description><![CDATA[After much research and very little code, I&#8217;ve come up with a basic start to a jQuery zoom event handler.  Don&#8217;t laugh.  This is very basic, but it handles zoom events based on keyboard shortcuts and fires the handler.

UPDATE: You can find the latest version of the plugin here.

1
2
3
4
5
jQuery.fn.zoom = function&#40;fn&#41; &#123;
	jQuery&#40;document&#41;.keypress&#40;function&#40;e&#41;&#123;
		if &#40;e.ctrlKey &#38;&#38; &#40;e.which [...]]]></description>
			<content:encoded><![CDATA[<p>After much research and very little code, I&#8217;ve come up with a basic start to a jQuery zoom event handler.  Don&#8217;t laugh.  This is very basic, but it handles zoom events based on keyboard shortcuts and fires the handler.<br />
<span id="more-31"></span></p>
<p><strong>UPDATE:</strong> You can find the latest version of the plugin <a href="http://design.mellentine.com/2008/12/11/javascript-jquery-zoom-event-plugin/">here</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">zoom</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>fn<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keypress</span><span style="color: #009900;">&#40;</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">ctrlKey</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">61</span> || e.<span style="color: #660066;">which</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">45</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> fn<span style="color: #009900;">&#40;</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>;</pre></td></tr></table></div>

<p>You could then assign a handler like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">zoom</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'zoom, zoom'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>So much more needs to be added to this and I&#8217;m not even sure I&#8217;m headed the right direction.  For example, I can address another way of zooming (CTRL-scrollwheel), but I doubt I can capture use of the menu in the browser.  Also, I could probably assign different keys to zoom.  I might have to come up with a different solution entirely.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/12/11/javascript-the-start-of-a-jquery-zoom-event-handler/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/12/11/javascript-the-start-of-a-jquery-zoom-event-handler/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Simple date conversion from SQL to readable</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/473032897/</link>
		<comments>http://design.mellentine.com/2008/12/02/javascript-simple-date-conversion-from-sql-to-readable/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 00:10:21 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/?p=29</guid>
		<description><![CDATA[I needed a simple date converter function from SQL dates (YYYY-MM-DD) to something readable (M/D/YYYY).  So I wrote this little function.  Maybe someone else will have some use for it.

1
2
3
var makeSQLDatePretty = function&#40;d&#41; &#123;
  return d.replace&#40;/([0-9]{4})-0?([0-9]{1,2})-0?([0-9]{1,2})/, '$2/$3/$1'&#41;;
&#125;;

Pass in a SQL date and the function trims leading zeros and returns a reformatted date.

1
2
var sqlDate = [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a simple date converter function from SQL dates (YYYY-MM-DD) to something readable (M/D/YYYY).  So I wrote this little function.  Maybe someone else will have some use for it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> makeSQLDatePretty <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> d.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/([0-9]{4})-0?([0-9]{1,2})-0?([0-9]{1,2})/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'$2/$3/$1'</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>;</pre></td></tr></table></div>

<p>Pass in a SQL date and the function trims leading zeros and returns a reformatted date.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> sqlDate <span style="color: #339933;">=</span> <span style="color: #3366CC;">'2008-12-02'</span>;
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>makeSQLDatePretty<span style="color: #009900;">&#40;</span>sqlDate<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>; <span style="color: #006600; font-style: italic;">// should alert '12/2/2008'</span></pre></td></tr></table></div>

<p>Crazy Europeans may want to change the replace regex with &#8216;$3/$2/$1&#8242;.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/12/02/javascript-simple-date-conversion-from-sql-to-readable/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/12/02/javascript-simple-date-conversion-from-sql-to-readable/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Smart, unobtrusive AJAX form submission with jQuery</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/400258615/</link>
		<comments>http://design.mellentine.com/2008/09/22/javascript-smart-unobtrusive-ajax-form-submission-with-jquery/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 23:44:22 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[mootools]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/?p=19</guid>
		<description><![CDATA[A former coworker was telling me recently about MooTools and how the AJAX functions are so easy to use.  He sent me the following example:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
function attachedToOnSubmitOfAForm&#40;&#41;&#123;
        sp = $&#40;&#34;someForm&#34;&#41;;
        sp.addClass&#40;'loader'&#41;;
&#160;
        sp.send&#40;&#123;
    [...]]]></description>
			<content:encoded><![CDATA[<p>A former coworker was telling me recently about MooTools and how the AJAX functions are so easy to use.  He sent me the following example:<br />
<span id="more-19"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> attachedToOnSubmitOfAForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        sp <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;someForm&quot;</span><span style="color: #009900;">&#41;</span>;
        sp.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'loader'</span><span style="color: #009900;">&#41;</span>;
&nbsp;
        sp.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</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: #339933;">,</span>
&nbsp;
                onFailure<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;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Great concept, right?  No need to tell it where to send the data or what fields to send, since the form already contains that info.  It&#8217;s mostly unobtrusive, so any browser that doesn&#8217;t have JS enabled would still be able to submit.</p>
<p>So my immediate response was, &#8220;Very cool.  I&#8217;m sure a jQuery plugin either exists or could be created pretty easily to handle that.&#8221;</p>
<p>I built the following plugin in maybe 30 minutes, and had it tested in another 15.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td 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>jQuery<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">send</span> <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;">return</span> <span style="color: #000066; font-weight: bold;">this</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><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		    <span style="color: #003366; font-weight: bold;">var</span> form <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>;
			jQuery<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;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit'</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>
				jQuery.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span>jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
					type     <span style="color: #339933;">:</span> form.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'method'</span><span style="color: #009900;">&#41;</span> || <span style="color: #3366CC;">'get'</span><span style="color: #339933;">,</span>
					url      <span style="color: #339933;">:</span> form.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'action'</span><span style="color: #009900;">&#41;</span> || window.<span style="color: #660066;">location</span>.<span style="color: #660066;">href</span><span style="color: #339933;">,</span>
					data     <span style="color: #339933;">:</span> form.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</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>;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>There are some of you that are wondering, &#8220;Why is this necessary? I can write my own jQuery.ajax() code every time.&#8221;  Yep, and that&#8217;s part the problem I&#8217;m trying to solve. The plugin is a shortcut for most of the jQuery.ajax() code you&#8217;d normally write and it makes unobtrusive form submission dead simple:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">jQuery<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>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		complete <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">responseText</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></td></tr></table></div>

<p>The function takes one parameter, an object that extends the <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options">jQuery.ajax method</a>.</p>
<p>Here&#8217;s a <a href="/demos/jquery-send">demo</a> and the <a href="/downloads/jquery.send.js">download</a>.</p>
<p><strong>2008-09-23</strong>: Updated <em>window.location</em> to <em>window.location.href</em> (Thanks Samori)</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/09/22/javascript-smart-unobtrusive-ajax-form-submission-with-jquery/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/09/22/javascript-smart-unobtrusive-ajax-form-submission-with-jquery/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Iterating through objects, the easy way</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/285844740/</link>
		<comments>http://design.mellentine.com/2008/05/08/javascript-iterating-through-objects-the-easy-way/#comments</comments>
		<pubDate>Thu, 08 May 2008 05:04:24 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[objects]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/?p=18</guid>
		<description><![CDATA[Objects in any ECMAScript language (Javascript, Actionscript, Jscript, etc) are very powerful for - among other things - storing data.  However, getting some information out of these objects can be a hassle sometimes.
I ran into this issue recently and wrote some cool little handlers for objects.  The following methods can be used to [...]]]></description>
			<content:encoded><![CDATA[<p>Objects in any ECMAScript language (Javascript, Actionscript, Jscript, etc) are very powerful for - among other things - storing data.  However, getting some information out of these objects can be a hassle sometimes.</p>
<p>I ran into this issue recently and wrote some cool little handlers for objects.  The following methods can be used to iterate through an array manually.  I wrote them for Actionscript, but they certainly work for Javascript - although I&#8217;d suggest one small modification (shown later).<span id="more-18"></span></p>
<p>Let&#8217;s get to the code.</p>
<p>In each of the &#8220;for in&#8221; loops below, I make sure to exclude any prototyped methods.  If I don&#8217;t, they&#8217;ll show up in the loop - which can be pretty bad.</p>
<p>The &#8216;first&#8217; method starts looping through the array, but returns the first item in the object as soon as it gets to it.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Object.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">first</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;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</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>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> s;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>The &#8216;last&#8217; method loops through the object, storing the current item in a variable.  When it finishes the loop, it returns that variable - the last item in the object.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Object.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">last</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;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</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>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> l <span style="color: #339933;">=</span> s;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> l;
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>The &#8216;previous&#8217; method loops through the object looking for the &#8217;subject&#8217; variable.  If it matches the variable with the current item, it returns the previous item - set after the if statement below (in the previous time through the loop).  If it never matches the variable or the previous item is never set, it will return the last item of the object.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Object.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">previous</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</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>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</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>s <span style="color: #339933;">==</span> subject <span style="color: #339933;">&amp;</span>amp;&amp;amp; l <span style="color: #339933;">!==</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">return</span> l;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #003366; font-weight: bold;">var</span> l <span style="color: #339933;">=</span> s;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">last</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>The &#8216;next&#8217; method loops through the object looking for the &#8217;subject&#8217; variable, as well.  However, when it matches the variable it sets a &#8216;found&#8217; flag.  The next time through the loop, the current item will be returned.  If it never matches the variable or the matched item is the last in the object, the first item will be returned.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">Object.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">next</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>subject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> f <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span>;
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</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>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</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>f<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">return</span> s;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s <span style="color: #339933;">==</span> subject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			f <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">first</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>;</pre></div></div>

<p>So let&#8217;s do some examples.  My test object has 3 items - one of which contains an array:</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> myObject <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	apple  <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
		<span style="color: #3366CC;">'fuji'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'gala'</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">'red delicious'</span>
	<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	banana <span style="color: #339933;">:</span> <span style="color: #3366CC;">'chiquita'</span><span style="color: #339933;">,</span>
	orange <span style="color: #339933;">:</span> <span style="color: #3366CC;">'navel'</span>
<span style="color: #009900;">&#125;</span>;
&nbsp;
myObject.<span style="color: #660066;">first</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>; <span style="color: #006600; font-style: italic;">// returns 'apple'</span>
myObject.<span style="color: #660066;">last</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;  <span style="color: #006600; font-style: italic;">// returns 'orange'</span>
myObject.<span style="color: #660066;">previous</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'apple'</span><span style="color: #009900;">&#41;</span>; <span style="color: #006600; font-style: italic;">// returns 'orange'</span>
myObject.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'apple'</span><span style="color: #009900;">&#41;</span>;     <span style="color: #006600; font-style: italic;">// returns 'banana'</span>
myObject.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'banana'</span><span style="color: #009900;">&#41;</span>;    <span style="color: #006600; font-style: italic;">// returns 'orange'</span>
myObject.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'orange'</span><span style="color: #009900;">&#41;</span>;    <span style="color: #006600; font-style: italic;">// returns 'apple'</span></pre></div></div>

<p>Simple as that.</p>
<p>The one change that I would recommend looking into for Javascript is better checking for the &#8220;for in&#8221; loops.</p>
<p>Instead of:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</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>Object.<span style="color: #660066;">prototype</span><span style="color: #009900;">&#91;</span>s<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

<p>The hasOwnProperty property is recommended:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> s <span style="color: #000066; font-weight: bold;">in</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/05/08/javascript-iterating-through-objects-the-easy-way/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/05/08/javascript-iterating-through-objects-the-easy-way/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: onerror image magic</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258352541/</link>
		<comments>http://design.mellentine.com/2008/03/26/javascript-onerror-image-magic/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 14:44:47 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[html]]></category>

		<category><![CDATA[img]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2008/03/26/javascript-onerror-image-magic/</guid>
		<description><![CDATA[HTML has a little-known event handler for &#60;img&#62; and &#60;body&#62; tags.  I&#8217;m going to focus on &#60;img&#62; tags and how you can use this to clean up some 404s.
First, just a quick note about this event handler.  You won&#8217;t find it in any W3C spec because it just isn&#8217;t there.  Why?  [...]]]></description>
			<content:encoded><![CDATA[<p>HTML has a little-known event handler for &lt;img&gt; and &lt;body&gt; tags.  I&#8217;m going to focus on &lt;img&gt; tags and how you can use this to clean up some 404s.<span id="more-17"></span></p>
<p>First, just a quick note about this event handler.  You won&#8217;t find it in any W3C spec because it just isn&#8217;t there.  Why?  I don&#8217;t know, but I do know that it&#8217;s supported by Firefox and Internet Explorer 6/7 - which is ~90% of the browser usage and possibly more (read: I need to fire up my Mac and test it).  Apparently, this event handler has been around for a long time - see this <a href="http://lists.w3.org/Archives/Public/www-html/2001Sep/0084.html" target="_blank">brief e-mail exchange</a> on the HTML users group.</p>
<p>Okay, let&#8217;s get started.  Recently, I was working with some external data where I didn&#8217;t know whether I would have an image with each item the data or not.  This is a simple problem that can be solved using server side code (since the data feed needed to be parsed into a database table anyway).  However, I found that the links to some of the images returned 404 errors.  I&#8217;m not a usability expert, but have broken images looks pretty bad, even if you use alt attributes.  The onerror event handler is perfect for this situation.  Here&#8217;s how it works:</p>
<p>You assign the attribute to the image tag with some sort of error handler:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;img src=&quot;badimage.jpg&quot; onerror=&quot;fixImage(this);&quot; /&gt;</pre></td></tr></table></div>

<p>Then, create your error handler function.  You could replace the image with a &#8220;No image&#8221; image (like I did):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> fixImage<span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  img.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'noimage.gif'</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Or you could just remove the image altogether:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> fixImage<span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  img.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span>img<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>If you want to read more about using onerror with &lt;body&gt; tags, <a href="http://developer.mozilla.org/" target="_blank">MDC</a> has some <a href="http://developer.mozilla.org/en/docs/DOM:window.onerror" target="_blank">documentation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/03/26/javascript-onerror-image-magic/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/03/26/javascript-onerror-image-magic/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Internet Explorer’s attachEvent breaks ‘this’</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332781/</link>
		<comments>http://design.mellentine.com/2008/02/25/javascript-internet-explorers-attachevent-breaks-this/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 18:27:47 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[DOM]]></category>

		<category><![CDATA[events]]></category>

		<category><![CDATA[Internet Explorer]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2008/02/25/javascript-internet-explorers-attachevent-breaks-this/</guid>
		<description><![CDATA[First of all, let me just say that I love jQuery.  It makes Javascript development so much faster.  I&#8217;m sure that Prototype is just as easy for those that use that daily, but I prefer jQuery.  And before you ask&#8230; Yes, I learned both.
That having been said, there are some applications where [...]]]></description>
			<content:encoded><![CDATA[<p>First of all, let me just say that I love <a href="http://jquery.com/" target="_blank">jQuery</a>.  It makes Javascript development so much faster.  I&#8217;m sure that <a href="http://www.prototypejs.org/" target="_blank">Prototype</a> is just as easy for those that use that daily, but I prefer jQuery.  And before you ask&#8230; Yes, I learned both.</p>
<p>That having been said, there are some applications where I cannot use a Javascript library and I need to use the (longer) Javascript methods.  There&#8217;s nothing wrong with this - in fact, I find that I always learn something new.  Such was the case today.<span id="more-13"></span></p>
<p>I decided that I would attach some events using the addEventListener function.  I had always either used the <a href="http://www.w3.org/TR/DOM-Level-2-Events/" target="_blank">older method</a> of attaching events or some helper library.  So I checked out <a href="http://developer.mozilla.org/en/docs/DOM:element.addEventListener" target="_blank">the spec</a> on <a href="http://developer.mozilla.org/" target="_blank">MDC</a> and saw that Internet Explorer had its own version of this function called <a href="http://msdn2.microsoft.com/en-us/library/ms536343.aspx" target="_blank">attachEvent</a>.  I hate how Internet Explorer does things like this.  There are standards for a reason, you know.</p>
<p>Anyway, I wrote a simple function that would apply the event, but it was not working in Internet Explorer.  So I started debugging the issue.</p>
<p>&#8220;Is the event being attached?&#8221; - Yes</p>
<p>Is the event being attached to the right object?&#8221; - Yes</p>
<p>Can I alert some text in the event function?&#8221; - Yes&#8230; odd.</p>
<p>Here&#8217;s my function:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">addEvent<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'mouseover'</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;">className</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'over'</span>; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
addEvent <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: #339933;">,</span> func<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>el.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    el.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> func<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>el.<span style="color: #660066;">attachEvent</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    el.<span style="color: #660066;">attachEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'on'</span><span style="color: #339933;">+</span>event<span style="color: #339933;">,</span> func<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>
    el<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'on'</span><span style="color: #339933;">+</span>event<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> func;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>;</pre></td></tr></table></div>

<p>It turns out that Internet Explorer doesn&#8217;t pass the &#8216;this&#8217; object to the event function.  &#8216;this&#8217; is this instance should be the object that had the event attached.</p>
<p>It&#8217;s no shock to people that know me that I hate Internet Explorer.  I even sell <a href="http://19352.spreadshirt.com/-/-/Shop/" target="_blank">T-shirts</a> declaring that fact.  But this is just stupid.</p>
<p>Why did Microsoft have to implement their own version of addEventListener?  Why did they have to implement it so horribly that it doesn&#8217;t return &#8216;this&#8217;?</p>
<p>I ended up writing a workaround that just used the older method of applying the event to the object.  Here&#8217;s the finished version:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">addEvent <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: #339933;">,</span> func<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>el.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    el.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> func<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</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>
    el<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'on'</span><span style="color: #339933;">+</span>event<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> func;
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>;</pre></td></tr></table></div>

<p>It&#8217;s really just adding insult to injury, since the only reason I had to write this function is because Internet Explorer doesn&#8217;t handle the CSS :hover pseudo-class for DIV elements.</p>
<p>Anyone want a <a href="http://19352.spreadshirt.com/-/-/Shop/" target="_blank">T-shirt</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/02/25/javascript-internet-explorers-attachevent-breaks-this/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/02/25/javascript-internet-explorers-attachevent-breaks-this/</feedburner:origLink></item>
		<item>
		<title>LEARNING: 2008 monthly plan updated</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332782/</link>
		<comments>http://design.mellentine.com/2008/02/25/learning-2008-monthly-plan-updated/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 17:56:43 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[learning]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2008/02/25/learning-2008-monthly-plan-updated/</guid>
		<description><![CDATA[The learning plan has been canceled for now.  Between work, side work and a new baby, I really don&#8217;t have time to learn as a separate task.  I guess I&#8217;ll just have to learn as I go along.
]]></description>
			<content:encoded><![CDATA[<p>The learning plan has been canceled for now.  Between work, side work and a new baby, I really don&#8217;t have time to learn as a separate task.  I guess I&#8217;ll just have to learn as I go along.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/02/25/learning-2008-monthly-plan-updated/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/02/25/learning-2008-monthly-plan-updated/</feedburner:origLink></item>
		<item>
		<title>LEARNING: 2008 monthly plan</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332783/</link>
		<comments>http://design.mellentine.com/2008/01/01/learning-2008-monthly-plan/#comments</comments>
		<pubDate>Tue, 01 Jan 2008 08:58:52 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[learning]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2008/01/01/learning-2008-monthly-plan/</guid>
		<description><![CDATA[Since it is the new year already, I&#8217;ve decided to plan my learning schedule for the next 12 months.  Here&#8217;s the plan so far (subject to change):

January: JavaServer Pages
February: Java
March: Java (continued)
April: MySQL 5
May: MySQL 5 (continued)
June: SQLite
July: Python
August: Python (continued)
September: Perl
October: Perl (continued)
November: Ext
December: Ruby

These should really push me out of my comfort [...]]]></description>
			<content:encoded><![CDATA[<p>Since it is the new year already, I&#8217;ve decided to plan my learning schedule for the next 12 months.  Here&#8217;s the plan so far (subject to change):</p>
<ul>
<li><strong>January</strong>: <a href="http://en.wikipedia.org/wiki/Javaserver_pages" target="_blank">JavaServer Pages</a></li>
<li><strong>February</strong>: <a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29" target="_blank">Java</a></li>
<li><strong>March</strong>: <a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29" target="_blank">Java</a> (continued)</li>
<li><strong>April</strong>: <a href="http://en.wikipedia.org/wiki/MySQL" target="_blank">MySQL</a> 5</li>
<li><strong>May</strong>: <a href="http://en.wikipedia.org/wiki/MySQL" target="_blank">MySQL</a> 5 (continued)</li>
<li><strong>June</strong>: <a href="http://en.wikipedia.org/wiki/Sqlite" target="_blank">SQLite</a></li>
<li><strong>July</strong>: <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" target="_blank">Python</a></li>
<li><strong>August</strong>: <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" target="_blank">Python</a> (continued)</li>
<li><strong>September</strong>: <a href="http://en.wikipedia.org/wiki/Perl" target="_blank">Perl</a></li>
<li><strong>October</strong>: <a href="http://en.wikipedia.org/wiki/Perl" target="_blank">Perl</a> (continued)</li>
<li><strong>November</strong>: <a href="http://en.wikipedia.org/wiki/Ext_%28javascript_library%29" target="_blank">Ext</a></li>
<li><strong>December</strong>: <a href="http://en.wikipedia.org/wiki/Ruby_programming_language" target="_blank">Ruby</a></li>
</ul>
<p>These should really push me out of my comfort zone.  I&#8217;ll try to share book info and progress and I go along.  Wish me luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2008/01/01/learning-2008-monthly-plan/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2008/01/01/learning-2008-monthly-plan/</feedburner:origLink></item>
		<item>
		<title>JAVASCRIPT: Method overloading</title>
		<link>http://feeds.feedburner.com/~r/MellentineDesign/~3/258332784/</link>
		<comments>http://design.mellentine.com/2007/12/04/javascript-method-overloading/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 04:20:08 +0000</pubDate>
		<dc:creator>Jared Mellentine</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[jquery]]></category>

		<category><![CDATA[OOP]]></category>

		<guid isPermaLink="false">http://design.mellentine.com/2007/12/04/javascript-method-overloading/</guid>
		<description><![CDATA[John Resig, one of my heroes and creator of the jQuery JavaScript library, wrote a great piece about overloading methods.  He created a dead simple function that shoulders most of the work.  Check it out:

1
2
3
4
5
6
7
8
9
function addMethod&#40;object, name, fn&#41;&#123;
  var old = object&#91; name &#93;;
  object&#91; name &#93; = function&#40;&#41;&#123;
   [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ejohn.org/" title="John Resig" target="_blank">John Resig</a>, one of my heroes and creator of the <a href="http://jquery.com/" title="jQuery" target="_blank">jQuery</a> JavaScript library, wrote a <a href="http://ejohn.org/blog/javascript-method-overloading/" title="JavaScript method overloading" target="_blank">great piece</a> about overloading methods.  He created a dead simple function that shoulders most of the work.  Check it out:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> addMethod<span style="color: #009900;">&#40;</span>object<span style="color: #339933;">,</span> <span style="color: #000066;">name</span><span style="color: #339933;">,</span> fn<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> old <span style="color: #339933;">=</span> object<span style="color: #009900;">&#91;</span> <span style="color: #000066;">name</span> <span style="color: #009900;">&#93;</span>;
  object<span style="color: #009900;">&#91;</span> <span style="color: #000066;">name</span> <span style="color: #009900;">&#93;</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;">if</span> <span style="color: #009900;">&#40;</span> fn.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> arguments.<span style="color: #660066;">length</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> fn.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments <span style="color: #009900;">&#41;</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> <span style="color: #000066; font-weight: bold;">typeof</span> old <span style="color: #339933;">==</span> <span style="color: #3366CC;">'function'</span> <span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> old.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments <span style="color: #009900;">&#41;</span>;
  <span style="color: #009900;">&#125;</span>;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here&#8217;s how you could use it to extend the User object that we <a href="http://design.mellentine.com/2007/12/01/javascript-creating-objects-and-methods/">created earlier</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript javascript" style="font-family:monospace;">addMethod<span style="color: #009900;">&#40;</span>User.<span style="color: #660066;">prototype</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;find&quot;</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;">// Find all users...</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
addMethod<span style="color: #009900;">&#40;</span>User.<span style="color: #660066;">prototype</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;find&quot;</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;">name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Find a user by name</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
addMethod<span style="color: #009900;">&#40;</span>User.<span style="color: #660066;">prototype</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;find&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>first<span style="color: #339933;">,</span> last<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Find a user by first and last name</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;</pre></td></tr></table></div>

<p>You can read more from John&#8217;s blog <a href="http://ejohn.org/blog/" title="John Resig blog" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://design.mellentine.com/2007/12/04/javascript-method-overloading/feed/</wfw:commentRss>
		<feedburner:origLink>http://design.mellentine.com/2007/12/04/javascript-method-overloading/</feedburner:origLink></item>
	</channel>
</rss>
