<?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>Refactored scope &#187; javascript</title>
	<atom:link href="http://ominian.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://ominian.com</link>
	<description>PyMethius project notes</description>
	<lastBuildDate>Mon, 06 Feb 2012 17:56:10 +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>A web-console implemented in nodeJS</title>
		<link>http://ominian.com/2011/05/17/a-web-console-implemented-in-nodejs/</link>
		<comments>http://ominian.com/2011/05/17/a-web-console-implemented-in-nodejs/#comments</comments>
		<pubDate>Tue, 17 May 2011 16:44:47 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[NodeJS]]></category>
		<category><![CDATA[hacks]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=107</guid>
		<description><![CDATA[Reading over this ( http://gonzalo123.wordpress.com/2011/05/16/web-console-with-node-js/ ) , I felt this was a pretty good and relatively real world example of nodeJS&#8217;s capabilities. I did find one line near the end very poignant and reflective of my own opinions at the end of the show &#038; tell post I don’t know if node.js is the future <a href='http://ominian.com/2011/05/17/a-web-console-implemented-in-nodejs/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Reading over <a href="http://gonzalo123.wordpress.com/2011/05/16/web-console-with-node-js/">this</a> ( http://gonzalo123.wordpress.com/2011/05/16/web-console-with-node-js/ ) , I felt this was a pretty good and relatively real world example of nodeJS&#8217;s capabilities.  I did find one line near the end very poignant and reflective of my own opinions at the end of the show &#038; tell post </p>
<blockquote><p>I don’t know if node.js is the future or is just another hype, but it’s easy. And cool. Really cool.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/05/17/a-web-console-implemented-in-nodejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New language to the toolset: NodeJS</title>
		<link>http://ominian.com/2011/05/16/new-language-to-the-toolset-nodejs/</link>
		<comments>http://ominian.com/2011/05/16/new-language-to-the-toolset-nodejs/#comments</comments>
		<pubDate>Mon, 16 May 2011 21:35:01 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[NodeJS]]></category>
		<category><![CDATA[about]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[woot]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=104</guid>
		<description><![CDATA[I&#8217;ve started self-teaching myself NodeJS and not surprisingly there was a recent popular reddit link pointing to a not very short introduction to nodejs here ( http://anders.janmyr.com/2011/05/not-very-short-introduction-to-nodejs.html ) . At this point I haven&#8217;t found any good books for reference lookup&#8230; but hopefully in a week or so I&#8217;ll have gotten spooled up enough to <a href='http://ominian.com/2011/05/16/new-language-to-the-toolset-nodejs/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started self-teaching myself NodeJS and not surprisingly there was a recent popular reddit link pointing to a not very short introduction to nodejs <a href="http://anders.janmyr.com/2011/05/not-very-short-introduction-to-nodejs.html">here</a> ( http://anders.janmyr.com/2011/05/not-very-short-introduction-to-nodejs.html ) .  At this point I haven&#8217;t found any good books for reference lookup&#8230; but hopefully in a week or so I&#8217;ll have gotten spooled up enough to be able to report back.</p>
<p>In the meantime as I use Ubuntu for everything but games, this short article <a href="http://www.codediesel.com/linux/installing-node-js-on-ubuntu-10-04/">here</a> ( http://www.codediesel.com/linux/installing-node-js-on-ubuntu-10-04/ ) was enough to get a working environment running though I recommend using a pristine virtual machine instance to keep things simple.</p>
<p>Last point, a reliable friend &#038; peer of mine recommended I check out this MVC like framework for NodeJS ( http://expressjs.com/ ).  Preliminary it feels like a hybrid between Twistd and CherryPy in Python or Limonade PHP as far as style&#8230; aiming more for simplicity over feature/complexity.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/05/16/new-language-to-the-toolset-nodejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery dataTable plugin quick notes</title>
		<link>http://ominian.com/2011/03/31/jquery-datatable-plugin-quick-notes/</link>
		<comments>http://ominian.com/2011/03/31/jquery-datatable-plugin-quick-notes/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 16:09:34 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[educational]]></category>
		<category><![CDATA[oh_snap]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=97</guid>
		<description><![CDATA[Server-side processing To return the names of the columns you want, you need to use aoColumndefs and provided individual objects with the property sName. Below is most of the implementation for a jeditable Ajax driven dataTables, this is the Alpha version and still needs a lot of love in places, but the gist of it <a href='http://ominian.com/2011/03/31/jquery-datatable-plugin-quick-notes/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h2>Server-side processing</h2>
<p>
   To return the names of the columns you want, you need to use aoColumndefs and provided individual objects with the property sName.
</p>
<p>  Below is most of the implementation for a jeditable Ajax driven dataTables, this is the Alpha version and still needs a lot of love in places, but the gist of it is here</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> semesterTable <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#semesterViewTable&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dataTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                <span style="color: #3366CC;">&quot;bProcessing&quot;</span>   <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
            <span style="color: #339933;">,</span>   <span style="color: #3366CC;">&quot;bServerSide&quot;</span>   <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span>
            <span style="color: #339933;">,</span>   <span style="color: #3366CC;">&quot;sAjaxSource&quot;</span>   <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&lt;?php echo url_for(&quot;</span>roster<span style="color: #339933;">/</span>ajax<span style="color: #339933;">/</span><span style="color: #009900;">&#123;</span>$semester_id<span style="color: #009900;">&#125;</span><span style="color: #3366CC;">&quot;); ?&gt;&quot;</span>
            <span style="color: #339933;">,</span>   <span style="color: #3366CC;">&quot;fnRowCallback&quot;</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> nRow<span style="color: #339933;">,</span> aData<span style="color: #339933;">,</span> iDisplayIndex<span style="color: #339933;">,</span> iDisplayIndexFull <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                    <span style="color: #006600; font-style: italic;">//console.log(nRow, aData, iDisplayIndex, iDisplayIndexFull);</span>
                                    <span style="color: #003366; font-weight: bold;">var</span> recordId <span style="color: #339933;">=</span> aData<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td&quot;</span><span style="color: #339933;">,</span> nRow<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;recordId&quot;</span><span style="color: #339933;">,</span> recordId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                    <span style="color: #000066; font-weight: bold;">return</span> nRow<span style="color: #339933;">;</span>
                                <span style="color: #009900;">&#125;</span>
            <span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;fnDrawCallback&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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;td.editableMajor&quot;</span><span style="color: #009900;">&#41;</span>
                                        .<span style="color: #660066;">editable</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php echo url_for(&quot;</span>roster<span style="color: #339933;">/</span>edit_record<span style="color: #3366CC;">&quot;);?&gt;&quot;</span><span style="color: #339933;">,</span>
                                                    <span style="color: #009900;">&#123;</span>                                                        
                                                          loadurl<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;&lt;?php echo url_for(&quot;</span>roster<span style="color: #339933;">/</span>distinct<span style="color: #339933;">/</span>major<span style="color: #339933;">/</span><span style="color: #009900;">&#123;</span>$semester_id<span style="color: #009900;">&#125;</span><span style="color: #3366CC;">&quot;) ?&gt;&quot;</span>
                                                        <span style="color: #339933;">,</span> type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;select&quot;</span>
                                                        <span style="color: #339933;">,</span> submit<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;OK&quot;</span>
                                                        <span style="color: #339933;">,</span> method<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;post&quot;</span>
                                                        <span style="color: #339933;">,</span> submitdata<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>
                                                            console.<span style="color: #660066;">log</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: #339933;">;</span>
                                                            <span style="color: #003366; font-weight: bold;">var</span> $this <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                                                            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#123;</span>
                                                                    recordId<span style="color: #339933;">:</span> $this.<span style="color: #660066;">data</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;recordId&quot;</span><span style="color: #009900;">&#41;</span>
                                                                    <span style="color: #339933;">,</span> classes<span style="color: #339933;">:</span> $this.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;class&quot;</span><span style="color: #009900;">&#41;</span>
                                                                <span style="color: #009900;">&#125;</span>
                                                        <span style="color: #009900;">&#125;</span>
                                                    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                                <span style="color: #009900;">&#125;</span>
            <span style="color: #009966; font-style: italic;">/* Seriously a meta-generator for this would be nice */</span>
            <span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;aoColumnDefs&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;record_id&quot;</span><span style="color: #339933;">,</span>          aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>00<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> bSearchable<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> bVisible<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_date&quot;</span><span style="color: #339933;">,</span>         aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>01<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_date&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_name_both&quot;</span><span style="color: #339933;">,</span>    aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>02<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_name_both&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_student_id&quot;</span><span style="color: #339933;">,</span>   aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>03<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_student_id&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major1&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>04<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major1 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major2&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>05<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major2 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major3&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>06<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major3 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major4&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>07<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_major4 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_minor1&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>08<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_minor1 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
                <span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span> sName<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_minor2&quot;</span><span style="color: #339933;">,</span>       aTargets<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>09<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> sClass<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;roster_minor2 editableMajor&quot;</span><span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#93;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>  For the tbody, just put something like  </p>
<pre>
        &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;Chill the fuck out, it's loading&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;
</pre>
<h3>Server side data contract</h3>
<p>dataTables expects a JSON&#8217;ified construct like this</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$responseBody</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">&quot;sEcho&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$input</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sEcho'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;iTotalRecords&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$count</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;iTotalDisplayRecords&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">&quot;aaData&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$data</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<ul>
<li> sEcho is a security variable used by dataTables, basically just send it back and don&#8217;t worry about it</li>
<li>iTotalRecords &#8211; is the MAXIMUM # of records in the data set without any filtering</li>
<li>iTotalDisplayRecords &#8211; is the MAXIMUM # of records in the data set WITH filtering</li>
<li>An array of numerically indexed arrays, dataTables doesn&#8217;t like associative arrays</li>
</ul>
<h1>Total and Display total records</h1>
<p>   If the blink tag still worked reliably, I&#8217;d put a neon sign here.   Basically you need to do 3 queries per Ajax call&#8230; call 1 is to get a</p>
<pre>
   SELECT count(1) FROM sourceTABLE
</pre>
<p>call 2 is</p>
<pre> SELECT count(1) FROM sourceTable WHERE someCriteria </pre>
<p> and finally call 3 is</p>
<pre> SELECT yourColumnList FROM sourceTable WHERE someCriteria</pre>
<p>With memcache or such, I&#8217;d advise caching the total count but no matter what you unfortunately need to make these three SQL calls <img src='http://ominian.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/31/jquery-datatable-plugin-quick-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ping documentation in progress</title>
		<link>http://ominian.com/2011/03/27/ping-documentation-in-progress/</link>
		<comments>http://ominian.com/2011/03/27/ping-documentation-in-progress/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 23:27:57 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ping toolset]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[status]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=89</guid>
		<description><![CDATA[I&#8217;ve been writing class/method level documentation and ideally plan to make a step by step explanation of what the heck is going on inside the Ping toolset. Until then it&#8217;s pretty doubtful anyone will want to use it. Never mind everything is still in Alpha state and there is very little guarantees that something won&#8217;t <a href='http://ominian.com/2011/03/27/ping-documentation-in-progress/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing class/method level documentation and ideally plan to make a step by step explanation of what the heck is going on inside the Ping toolset.  Until then it&#8217;s pretty doubtful anyone will want to use it.  Never mind everything is still in Alpha state and there is very little guarantees that something won&#8217;t be written.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/27/ping-documentation-in-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Snake game prototype</title>
		<link>http://ominian.com/2011/03/27/snake-game-prototype/</link>
		<comments>http://ominian.com/2011/03/27/snake-game-prototype/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 21:22:03 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[about]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=87</guid>
		<description><![CDATA[Running live here User input is fed off the left &#038; right cursor keys. Ping additions included a formalized Quad tree library into the ping.Lib namespace but I want to fix up the factory function I wrote to take an instance of the Canvas rendering class instead of manually writing out the root dimensions. Otherwise <a href='http://ominian.com/2011/03/27/snake-game-prototype/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Running live <a href="http://ominian.com/examples/js/pinglib/snakes.html">here</a></p>
<p>User input is fed off the left &#038; right cursor keys.</p>
<p>Ping additions included a formalized Quad tree library into the ping.Lib namespace but I want to fix up the factory function I wrote to take an instance of the Canvas rendering class instead of manually writing out the root dimensions.  Otherwise collision checks are still a tad wonky&#8230; there&#8217;s a high propensity for near misses unfortunately <img src='http://ominian.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/27/snake-game-prototype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Canvas pixel collision detection</title>
		<link>http://ominian.com/2011/03/09/canvas-pixel-collision-detection/</link>
		<comments>http://ominian.com/2011/03/09/canvas-pixel-collision-detection/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 22:28:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[hacks]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=82</guid>
		<description><![CDATA[So&#8230; a fair number of people arrive here looking for how to detect when a pixel/object/thing has collided with something else. I&#8217;ll add more information in the future but in the interim, the quick and dirty advice I can provide: Given p = x, y where this is the point your trying to determine if <a href='http://ominian.com/2011/03/09/canvas-pixel-collision-detection/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>So&#8230; a fair number of people arrive here looking for how to detect when a pixel/object/thing has collided with something else.</p>
<p>I&#8217;ll add more information in the future but in the interim, the quick and dirty advice I can provide:</p>
<p>Given p = x, y where this is the point your trying to determine if it intersects another&#8230; the best place is to start with bounding box logic.  Regardless of what shape your object is, if wrap it in an invisible box boundry, it&#8217;s relatively trivial to do:</p>
<p>box upper left origin is bX, bY off size sizeX, sizeY.   If p.x greater then bX and p.x less then bX + sizeX AND p.y greater then bY and p.y less then bY + sizeY   you&#8217;re inside the bounding box and it&#8217;s highly likely your point has or will soon be colliding with an object.</p>
<p>That&#8217;s pretty much it and is perfect if you don&#8217;t mine lagging the crap out of whatever is running this logic.    To make these collision checks performant, you need to make the computer do less work.   For two dimensional space, my personnel research has led me to the Quad tree structure ( <a title="Quad Trees" href="http://en.wikipedia.org/wiki/Quadtree" target="_blank">wikipedia article</a> ).  I&#8217;ve got a brute force / naive implementation prototyped  @ <a href="https://github.com/devdave/Ping---canvas-helper-library/blob/master/mapping.js">here</a> &amp; <a href="https://github.com/devdave/Ping---canvas-helper-library/blob/master/mapping.html">here</a> but as of 2011 March 9th it is not finished and needs some more work.</p>
<p>Basically Quad tree&#8217;s provides a super quick way for you to determine if there is any other objects in relative space to an entity.  Doing a quick lookup, if there&#8217;s nothing nearby then you can skip the bounding box checks and then the stupidly expensive perimeter intersection checks.</p>
<p>Full library is <a href="https://github.com/devdave/Ping---canvas-helper-library">here</a> and like most of my pet projects is heavily undocumented and completely absent of unit-testing.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/09/canvas-pixel-collision-detection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deferreds for JQuery 1.5</title>
		<link>http://ominian.com/2011/03/06/deferreds-for-jquery-1-5/</link>
		<comments>http://ominian.com/2011/03/06/deferreds-for-jquery-1-5/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 20:32:53 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[about]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[utilities]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=76</guid>
		<description><![CDATA[Anyone familiar with async programming like Node.JS or Python&#8217;s twistd library will be familiar with deferreds. Its usually a simple nuisance to re-implement when needed, so it&#8217;s nice to hear that&#8217;s not an issue anymore with JQuery&#8217;s $.when &#038; $.then methods Really useful guide here What does this mean? Say you&#8217;ve got a compound action <a href='http://ominian.com/2011/03/06/deferreds-for-jquery-1-5/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Anyone familiar with async programming like Node.JS or Python&#8217;s <a href="http://twistedmatrix.com/documents/10.1.0/core/howto/defer.html">twistd library</a> will be familiar with deferreds.  Its usually a simple nuisance to re-implement when needed, so it&#8217;s nice to hear that&#8217;s not an issue anymore with JQuery&#8217;s $.when &#038; $.then methods </p>
<p>Really useful guide <a href="http://www.erichynds.com/jquery/using-deferreds-in-jquery/">here </a></p>
<h3>What does this mean?</h3>
<p>Say you&#8217;ve got a compound action you want to complete.  For example a user clicks on a leaf in a tree like directory<br />
menu.  Now you want to update both the menu to add any possible sub nodes of that leaf PLUS update a content panel and once its finished, maybe update the hash tag to the current page&#8217;s url.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
  $.<span style="color: #660066;">when</span><span style="color: #009900;">&#40;</span> updateMenu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> updateContent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
     .<span style="color: #660066;">success</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>
           console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Both menu &amp; content panel have been updated!&quot;</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: #660066;">fail</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>
           console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Oh noes, we didn't finish... try again?&quot;</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></pre></div></div>

<p> That&#8217;s pretty much the gist of deferreds in a nutshell.  Furthermore it appears that the author of this fantastic addition to jQuery really grokked the concept of deferreds because you can chain one deferred result to multiple child deferred&#8217;s allowing for cascading events to fire in response to one event.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/06/deferreds-for-jquery-1-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Return to canvas tag</title>
		<link>http://ominian.com/2011/03/03/return-to-canvas-tag/</link>
		<comments>http://ominian.com/2011/03/03/return-to-canvas-tag/#comments</comments>
		<pubDate>Thu, 03 Mar 2011 21:59:16 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[brain_dump]]></category>
		<category><![CDATA[utilities]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=74</guid>
		<description><![CDATA[Currently in between clients and waiting for the silent alpha of my delicious clone to wrap up&#8230;.so its back to experiments with the canvas tag. That means back to my unframework canvas library Ping. Some of the code still makes sense, but other bits are&#8230; well special. Currently there is an .ex object thats appended <a href='http://ominian.com/2011/03/03/return-to-canvas-tag/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>Currently in between clients and waiting for the silent alpha of my delicious clone to wrap up&#8230;.so its back to experiments with the canvas tag.</p>
<p>That means back to my unframework canvas library <a href="http://code.google.com/p/devdave/source/browse/#svn%2Ftrunk%2Fjavascript%2Fcanvastag%2Fping">Ping</a>.  Some of the code still makes sense, but other bits are&#8230; well special.  Currently there is an .ex object thats appended to the CanvasRenderingContext2D internal class and it works, but what I&#8217;m thinking of is re-working the code so that they&#8217;re added post-instantiation like a factory.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&nbsp;
canvasMaker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>elemId<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>elemId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> element.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;2d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//Here is where all the extension methods would be dynamically assigned to the 2d canvas instance</span>
    wrappedContext <span style="color: #339933;">=</span> wrapContext<span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//Maybe add a singleton check around the bulk of this that keys on the elemId</span>
    <span style="color: #000066; font-weight: bold;">return</span> wrappedContext<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>   The problem I&#8217;m trying to work around specifically is the need should ever arise to have n+1 managed tags on the same document.  Currently there is so many hardwired references that it would be impossible to have the two cooperate without collisions and undesirable behavior.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2011/03/03/return-to-canvas-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Canvas tag: Collision detection &amp; pixel decay</title>
		<link>http://ominian.com/2010/03/02/canvas-tag-collision-detection-pixel-decay/</link>
		<comments>http://ominian.com/2010/03/02/canvas-tag-collision-detection-pixel-decay/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 22:49:55 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[about]]></category>
		<category><![CDATA[utilities]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=13</guid>
		<description><![CDATA[UPDATED: March 14, 2011 here Continuing my tests/experiments with the Canvas tag has led to the Ping prototype. I had 3 minimal things I wanted to accomplish: Detecting the intersection of a 360 degree arc of ray/line segments to previously defined in map shapes; a visual decay/fade out of intersection points on the canvas, and <a href='http://ominian.com/2010/03/02/canvas-tag-collision-detection-pixel-decay/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>UPDATED: March 14, 2011 <a href="http://ominian.com/2011/03/09/canvas-pixel-collision-detection/" target="_blank">here</a></p>
<p>Continuing my tests/experiments with the Canvas tag has led to the <a href="http://ominian.com/examples/js/canvastag/ping">Ping prototype</a>.  I had 3 minimal things I wanted to accomplish:  Detecting the intersection of a 360 degree arc of ray/line segments to previously defined in map shapes; a visual decay/fade out of intersection points on the canvas, and lastly a test of performance.  In addition I decided to experiment with another approach to Javascript object construction in the hopes of getting a performance gain.<br />
<span id="more-13"></span><br />
<strong> performance</strong><br />
None of the code involved is optimized or really geared towards performance [ I am using JQuery.each(array|object, function() ) ] and a fairly inefficient pattern for determining intersection ( leveraging CPU with little or no caching ) but was mostly happy with the results when using Google Chrome on Ubuntu 9.10 and utterly surprised with Firefox 3.5 &amp; 3.6 on the same system.  It was literally a night and day difference with Chrome purring along and Firefox struggling to keep up.</p>
<p><strong>JS Objects</strong></p>
<p>Besides the canvas tag related stuff, I was experimenting with another approach to class construction that for the moment seems to goofy to be viable.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">appLib.<span style="color: #660066;">Point</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span> y<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;">x</span> <span style="color: #339933;">=</span> x<span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> y<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
app.<span style="color: #660066;">w</span><span style="color: #009900;">&#40;</span>appLib.<span style="color: #660066;">Point</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>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">dist</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> tX <span style="color: #339933;">=</span> Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> o.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">var</span> tY <span style="color: #339933;">=</span> Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> o.<span style="color: #660066;">y</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>tX<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>tY<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>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     *Bad design choice
     *@deprecated */</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">slope</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">-</span> o.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">-</span> o.<span style="color: #660066;">x</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</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>app.w( scope, anonymous) basically makes this in context of the anonymous function == scope.prototype.  Therefore making it easier to add prototypical methods to the final product.  My thought was to avoid closure based creation and rely on Function.prototype.method = function to make the objects leaner/faster.  I figured that Javascript engines have already been optimized to a degree to build an object from it&#8217;s prototype.   From my perspective, there didn&#8217;t seem to be a noticeable difference.</p>
<p><strong>Final thoughts</strong><br />
Ping functions as expected on Chrome but otherwise if not for my quad-core environment, I imagine it would be a rather abysmal user experience.  According to top and Chrome&#8217;s built in task manager, its devouring near 100% cpu time and has a semi-stable memory leak ( drifting up and down around 1,500 KB ever 30 seconds ) when in a resting state.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/03/02/canvas-tag-collision-detection-pixel-decay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A DRY abomination</title>
		<link>http://ominian.com/2010/01/30/a-dry-abomination/</link>
		<comments>http://ominian.com/2010/01/30/a-dry-abomination/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 06:48:36 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://ominian.com/?p=6</guid>
		<description><![CDATA[One of my habits when presented with a new framework/platform is to implement a problem I know like the back of my hand. Usually the user interface isn&#8217;t of concern so I haven&#8217;t done much to improve on the logic there. I decided to try something different with this implementation of Tic-Tac-Toe: Given the following <a href='http://ominian.com/2010/01/30/a-dry-abomination/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>   One of my habits when presented with a new framework/platform is to implement a problem I know like the back of my hand.   Usually the user interface isn&#8217;t of concern so I haven&#8217;t done much to improve on the logic there.   I decided to try something different with this implementation of Tic-Tac-Toe:</p>
<p>Given the following</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;height:100%; width:100%&quot;</span> &gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;x0&quot;</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y0&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y1&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y2&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;x1&quot;</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y0&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y1&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y2&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;x2&quot;</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y0&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y1&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;y2&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></div></div>

<p>I used the following logic to determine the coordinates from a user click</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> clickHandler <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;">//Recieves a plan/jQuery managed event object                    </span>
       <span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> e.<span style="color: #660066;">target</span><span style="color: #339933;">;</span>
       <span style="color: #003366; font-weight: bold;">var</span> parent  <span style="color: #339933;">=</span> element.<span style="color: #660066;">parentNode</span><span style="color: #339933;">;</span>                    
       <span style="color: #003366; font-weight: bold;">var</span> x<span style="color: #339933;">,</span>y<span style="color: #339933;">;</span>
       <span style="color: #006600; font-style: italic;">//Below is fine for 0-9 scenario's but will need to be refactored for more</span>
       <span style="color: #006600; font-style: italic;">//advanced/larger grids.</span>
       <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
            y <span style="color: #339933;">=</span> element.<span style="color: #660066;">classNames</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">detect</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>cls<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: #009966; font-style: italic;">/y\d/</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span>cls<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
            x <span style="color: #339933;">=</span> parent.<span style="color: #660066;">classNames</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">detect</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>cls<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: #009966; font-style: italic;">/x\d/</span>.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span>cls<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            console.<span style="color: #660066;">debug</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
         console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Coordinate &quot;</span> <span style="color: #339933;">+</span> x <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;,&quot;</span> <span style="color: #339933;">+</span> y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>    The cool thing about this, is that with jQuery I can do jQuery(&#8220;#myTable tr.x2 td.y0&#8243;) and get the exact cell I am looking for&#8230; or even crazier stuff like:<br />
&#8220;#myTable td.y0&#8243; to select vertically down a row<br />
OR<br />
&#8220;#myTable tr.x0&#8243; to select horizontally.</p>
]]></content:encoded>
			<wfw:commentRss>http://ominian.com/2010/01/30/a-dry-abomination/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

