<?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>Barryvan &#187; MooTools</title>
	<atom:link href="http://www.barryvan.com.au/category/programming/javascript/mootools/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barryvan.com.au</link>
	<description>Music, Programming, Design</description>
	<lastBuildDate>Wed, 23 Jun 2010 04:18:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Generative Music</title>
		<link>http://www.barryvan.com.au/2010/03/generative-music/</link>
		<comments>http://www.barryvan.com.au/2010/03/generative-music/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 08:08:11 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Ambient]]></category>
		<category><![CDATA[Chillout]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Music]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=443</guid>
		<description><![CDATA[Continuing my HTML5 and canvas experiments, I&#8217;ve put together a generative music system. Essentially, a series of particles move across a field, occasionally triggering sounds &#8212; the sound triggered depends on their location in the field. There is, of course, a little bit more to it than that. Under the hood, I&#8217;ve got a series [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing my HTML5 and canvas experiments, I&#8217;ve put together a generative music system. Essentially, a series of particles move across a field, occasionally triggering sounds &#8212; the sound triggered depends on their location in the field.</p>
<p>There is, of course, a little bit more to it than that. Under the hood, I&#8217;ve got a series of HTML5 Audio objects that are used to provide polyphonic audio using a simple round-robin algorithm (I encoded the audio in OGG, so you&#8217;ll need to use an OGG-friendly browser, like <a href="http://www.getfirefox.com">Firefox</a>). The particles are much simpler than those in my <a href="/2010/03/canvas-swarms/">previous canvas dalliance</a>, in that they don&#8217;t swarm, and their motion is more linear.</p>
<div class="screenshots">
<a href="/demos/generative.html"><br/><br />
<img alt="Generative Audio Screenshot" src="/wp-content/uploads/2010/03/generative.png" class="aligncenter size-full"/><br/><br />
View (and hear!) it live<br/><br />
</a>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2010/03/generative-music/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Canvas Swarms</title>
		<link>http://www.barryvan.com.au/2010/03/canvas-swarms/</link>
		<comments>http://www.barryvan.com.au/2010/03/canvas-swarms/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 00:27:18 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Processing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=440</guid>
		<description><![CDATA[I&#8217;ve been meaning to start playing with the HTML5 &#60;canvas&#62; element for a while now, and yesterday I took the opportunity. I translated a Processing sketch I made a while ago into JavaScript (with a few minor enhancements). View it live Essentially, 1 to 3 swarms of particles move around the canvas, reproducing when the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been meaning to start playing with the HTML5 &lt;canvas&gt; element for a while now, and yesterday I took the opportunity. I translated a Processing sketch I made a while ago into JavaScript (with a few minor enhancements).</p>
<div class="screenshots">
<a href="/demos/swarms/swarms.html"><br />
<img class="aligncenter size-full" src="/demos/swarms/swarms.png" alt="Swarms Screenshot"/><br />
View it live<br />
</a>
</div>
<p>Essentially, 1 to 3 swarms of particles move around the canvas, reproducing when the conditions are just right, and dying of old age. Quite simple, but the patterns produced can be really quite pretty.</p>
<p>One interesting thing that I discovered whilst doing this is that you can&#8217;t pass around a canvas&#8217; context at the instantiation of a MooTools class &#8212; it complains about wrapped natives. That&#8217;s why, if you like in the source JavaScript, you&#8217;ll see me pass the actual context around to various functions. I&#8217;d be interested in hearing if anyone has a workaround for this, because this is, well, a bit clunky.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2010/03/canvas-swarms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Javascript: Print a single element</title>
		<link>http://www.barryvan.com.au/2010/02/javascript-print-a-single-element/</link>
		<comments>http://www.barryvan.com.au/2010/02/javascript-print-a-single-element/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 08:18:47 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=434</guid>
		<description><![CDATA[Sometimes, you&#8217;ll want to allow users the ability to print only a part of your page; for example, a table but not the various links around the page. It&#8217;s possible to use a printing stylesheet, but this can cause severe headaches when you need different parts printed at different times. Really, we want to be [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, you&#8217;ll want to allow users the ability to print only a part of your page; for example, a table but not the various links around the page. It&#8217;s possible to use a printing stylesheet, but this can cause severe headaches when you need different parts printed at different times. Really, we want to be able to just say <strong>element.printElement()</strong>, and have it just work. That&#8217;s what the MooTools function below does. It&#8217;s loosely based around the concepts outlined at <a href="http://www.bennadel.com/blog/1591-Ask-Ben-Print-Part-Of-A-Web-Page-With-jQuery.htm">this website</a>.</p>
<pre class="brush: javascript">Element.implement({
	printElement: function() {
		var strName = &#039;printer-&#039; + (new Date()).getTime(),
		styles = $$(&#039;link[type=text/css]&#039;).clone(),
		title = document.title,
		that = this,
		iframe = new IFrame({
			name: strName,
			styles: {
				width: 1,
				height: 1,
				position: &#039;absolute&#039;,
				left: -9999
			},
			events: {
				load: function() {
					var doc = this.contentDocument || window.frames[strName].document;
					doc.title = title;
					$(doc.body).adopt(styles, that.clone());
					this.contentWindow.focus(); // IE requires us to focus before printing, or the parent prints.
					this.contentWindow.print();
				}
			}
		}).inject($(document.body));
		iframe.dispose.delay(15000); // Destroy the iframe in 15s so that it doesn&#039;t hang around.
	}
});</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2010/02/javascript-print-a-single-element/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Limiting the contents of a string via RegEx</title>
		<link>http://www.barryvan.com.au/2009/12/limiting-the-contents-of-a-string-via-regex/</link>
		<comments>http://www.barryvan.com.au/2009/12/limiting-the-contents-of-a-string-via-regex/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 08:10:49 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=332</guid>
		<description><![CDATA[Often, you will need to prevent users from entering data that doesn&#8217;t conform to a specific pattern. For example, you may want to allow users to enter only numbers or only valid email addresses. To this end, I&#8217;ve written a little utility function that returns the &#8220;standardised&#8221; version of a string, according to the regex [...]]]></description>
			<content:encoded><![CDATA[<p>Often, you will need to prevent users from entering data that doesn&#8217;t conform to a specific pattern. For example, you may want to allow users to enter only numbers or only valid email addresses. To this end, I&#8217;ve written a little utility function that returns the &#8220;standardised&#8221; version of a string, according to the regex you supply.</p>
<pre class="brush: javascript">String.implement({
	limitContent: function(allowedRegex) {
		return $splat(this.match(allowedRegex)).join(&#039;&#039;);
	}
});</pre>
<p>Basically, the function takes the result of evaluating the regular expression on the string, converts it into an array if it isn&#8217;t one, and then joins the array&#8217;s elements together with an empty string.</p>
<h2>Examples:</h2>
<pre class="brush: javascript">console.log(&quot;12345&quot;.limitContent(/.{4}/)); // Only allow four characters
console.log(&quot;joe@mail.com&quot;.limitContent(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/)); // Only allow email addresses
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/12/limiting-the-contents-of-a-string-via-regex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MooTools object messaging</title>
		<link>http://www.barryvan.com.au/2009/10/mootools-object-messaging/</link>
		<comments>http://www.barryvan.com.au/2009/10/mootools-object-messaging/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 08:19:08 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=280</guid>
		<description><![CDATA[Events In JavaScript, we often tend to use events all over the place. In MooTools, the custom &#8216;domready&#8217; event is particularly prevalent. However, events suffer from a few drawbacks: You can&#8217;t attach events to non-existent objects. Pretty self-explanatory, really. What this means in practice, though, is that you can&#8217;t easily let object A know when [...]]]></description>
			<content:encoded><![CDATA[<h2>Events</h2>
<p>In JavaScript, we often tend to use events all over the place. In MooTools, the custom &#8216;domready&#8217; event is particularly prevalent. However, events suffer from a few drawbacks:</p>
<h3>You can&#8217;t attach events to non-existent objects.</h3>
<p>Pretty self-explanatory, really. What this means in practice, though, is that you can&#8217;t easily let object A know when object B exists.</p>
<h3>If an object starts to listen for an event after it&#8217;s already fired, it&#8217;ll never hear it.</h3>
<p>Because content on the web isn&#8217;t always delivered in perfect order (especially when you&#8217;re loading scripts synchronously), it&#8217;s possible for an object to try to listen for an event after it&#8217;s already been fired. Obviously, this means that your listener object will never run the code that&#8217;s dependent on that event, which could be Bad Thing™.</p>
<h3>It&#8217;s not particularly easy to know which object is listening for which events.</h3>
<p>There are ways around this, but you can&#8217;t just dir() the listeners in Firebug.</p>
<h2>A messaging system</h2>
<p>For all of these reasons (and probably a few more that I&#8217;ve forgotten about), a messaging system can be an invaluable addition to your arsenal when writing JavaScript. How does a messaging system work? Well, interested objects &#8216;register&#8217; themselves as listeners for particular message &#8216;handles&#8217;, and other objects can send messages using those &#8216;handles&#8217;. Below is a very simple MooTools messaging system that I knocked up, which has a few cool features, including:</p>
<ul>
<li>When you register() a listener, you can have its callback immediately fire if that message has ever been sent before.
<li>
<li>You can very easily see which callbacks are associated with which messages by simply dir()-ing the &#8216;listeners&#8217; member.</li>
<li>You can unregister() a listener at any time (provided you&#8217;ve got a reference to the function and the handle).</li>
<li>Handles can be any valid JavaScript type &#8212; Strings, Numbers, even Objects.</li>
</ul>
<p>Feel free to use and extend this system &#8212; as I mentioned, this is a <strong>very</strong> simple system. If you do extend it, let me know in the comments!</p>
<p>Let me know what you think about this system in the comments.</p>
<pre class="brush: javascript">
barryvan.base.Messaging = new Class({
	listeners: $H(),
	sentMessages: [],

	initialize: function() {

	},

	/**
	 * Register a listener for a particular handle.
	 * handle [String]: The message &#039;handle&#039; to listen for.
	 * callback [Function]: The function to be called when the handle is sent a message. The contents of the messages will be included in the function call.
	 * dontCheck [Boolean]: If falsey and the handle has had a message sent to it, immediately call the callback function (without contents), and continue to add the listener as normal.
	 */
	register: function(handle, callback, dontCheck) {
		if ($type(callback) !== &#039;function&#039;) return;

		if (!dontCheck &amp;&amp; this.sentMessages[handle]) {
			callback();
		}

		if (!this.listeners.has(handle)) this.listeners[handle] = [];
		this.listeners[handle].push(callback);
	},

	/**
	 * Unregister a listener for a particular handle.
	 * handle [String]: The message &#039;handle&#039; to cease listening for.
	 * callback [Function]: The function which was earlier assigned as the callback for the messages.
	 */
	unregister: function(handle, callback) {
		if (this.listeners.has(handle)) {
			this.listeners[handle].erase(callback);
		}
	},

	/**
	 * Send a message to the given handle with the given contents -- send the contents to all the registered listeners for that handle.
	 * handle [String]: The message &#039;handle&#039; to transmit to.
	 * contents [Mixed]: The contents to be sent to the listeners.
	 */
	send: function(handle, contents) {
		this.sentMessages.include(handle);
		if (this.listeners.has(handle)) {
			this.listeners[handle].each(function(callback) {
				callback(contents);
			});
		}
	}
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/10/mootools-object-messaging/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quicksort an array of objects</title>
		<link>http://www.barryvan.com.au/2009/08/quicksort-an-array-of-objects/</link>
		<comments>http://www.barryvan.com.au/2009/08/quicksort-an-array-of-objects/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 07:14:51 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=225</guid>
		<description><![CDATA[Often, you will need to sort an array of objects in Javascript. The inbuilt sort() function can&#8217;t do this, but here is a Quicksort implementation for doing just this. Parameters array The array to be sorted. (See below for an implementation on the Array Native itself, which makes this variable unnecessary). key The key to [...]]]></description>
			<content:encoded><![CDATA[<p>Often, you will need to sort an array of objects in Javascript. The inbuilt <em>sort()</em> function can&#8217;t do this, but here is a Quicksort implementation for doing just this.</p>
<h2>Parameters</h2>
<p><strong>array</strong> The array to be sorted. (See below for an implementation on the Array Native itself, which makes this variable unnecessary).</p>
<p><strong>key</strong> The key to sort by. Make sure every object in your array has this key.</p>
<h2>Examples</h2>
<pre class="brush: javascript">
var objs = [
	{fruit:&quot;cherry&quot;},
	{fruit:&quot;apple&quot;},
	{fruit:&quot;banana&quot;}
];

console.log(objs.sortObjects(&#039;fruit&#039;));
// Logs [{fruit:&quot;apple&quot;},{fruit:&quot;banana&quot;},{fruit:&quot;cherry&quot;}] to the console
</pre>
<h2>The code</h2>
<pre class="brush: javascript">
sortObjects: function(array, key) {
	for (var i = 0; i &lt; array.length; i++) {
		var currVal = array[i][key];
		var currElem = array[i];
		var j = i - 1;
		while ((j &gt;= 0) &amp;&amp; (array[j][key] &gt; currVal)) {
			array[j + 1] = array[j];
			j--;
		}
		array[j + 1] = currElem;
	}
}
</pre>
<h3>Implemented on the Array native:</h3>
<pre class="brush: javascript">
Array.implement({
	sortObjects: function(key) {
		for (var i = 0; i &lt; this.length; i++) {
			var currVal = this[i][key];
			var currElem = this[i];
			var j = i - 1;
			while ((j &gt;= 0) &amp;&amp; (this[j][key] &gt; currVal)) {
				this[j + 1] = this[j];
				j--;
			}
			this[j + 1] = currElem;
		}
	}
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/08/quicksort-an-array-of-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javascript string ellipsising</title>
		<link>http://www.barryvan.com.au/2009/08/javascript-string-ellipsising/</link>
		<comments>http://www.barryvan.com.au/2009/08/javascript-string-ellipsising/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 07:03:17 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[string manipulation]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=217</guid>
		<description><![CDATA[Putting ellipses into strings that are too long has been around for a very long time. Unfortunately, Javascript doesn&#8217;t offer a native method of doing this, so below is a little function that&#8217;ll do it for you. This function returns a copy of the string it&#8217;s called on, ellipsised, and takes three parameters: toLength (required) [...]]]></description>
			<content:encoded><![CDATA[<p>Putting ellipses into strings that are too long has been around for a very long time. Unfortunately, Javascript doesn&#8217;t offer a native method of doing this, so below is a little function that&#8217;ll do it for you.</p>
<p>This function returns a copy of the string it&#8217;s called on, ellipsised, and takes three parameters:</p>
<p><strong>toLength</strong> (required) The number of characters to truncate the string to (or 0 to disable ellipsising)</p>
<p><strong>where</strong> (optional, default &#8216;end&#8217;) A string representing where the ellipsis should be placed &#8212; &#8216;front&#8217;, &#8216;middle&#8217;, or &#8216;end&#8217;</p>
<p><strong>ellipsis</strong> (option, default &#8216;\u2026&#8242;) A string to be used as the ellipsis.</p>
<h2>Examples</h2>
<pre class="brush: javascript">
// Our clichéd string
var s = &#039;Jackdaws love my great big sphinx of quartz&#039;;

alert(s.ellipsise(10));
// Alerts &quot;Jackdaws l…&quot;

alert(s.ellipsise(10, &#039;front&#039;));
// Alerts &quot;… of quartz&quot;

alert(s.ellipsise(10, &#039;middle&#039;, &#039;pony&#039;));
// Alerts &quot;Jackdponyuartz&quot;</pre>
<h2>The code</h2>
<pre class="brush: javascript">String.implement({
	ellipsise: function(toLength, where, ellipsis) { // Where is one of [&#039;front&#039;,&#039;middle&#039;,&#039;end&#039;] -- default is &#039;end&#039;
		if (toLength &lt; 1) return this;
		ellipsis = ellipsis || &#039;\u2026&#039;;
		if (this.length &lt; toLength) return this;
		switch (where) {
			case &#039;front&#039;:
				return ellipsis + this.substr(this.length - toLength);
				break;
			case &#039;middle&#039;:
				return this.substr(0, toLength / 2) + ellipsis + this.substr(this.length - toLength / 2)
				break;
			case &#039;end&#039;:
			default:
				return this.substr(0, toLength) + ellipsis;
				break;
		}
	}
});</pre>
<p>If you&#8217;re not using MooTools, you can use this variant instead:</p>
<pre class="brush: javascript">String.prototype.ellipsise = function(toLength, where, ellipsis) { // Where is one of [&#039;front&#039;,&#039;middle&#039;,&#039;end&#039;] -- default is &#039;end&#039;
	if (toLength &lt; 1) return this;
	ellipsis = ellipsis || &#039;\u2026&#039;;
	if (this.length &lt; toLength) return this;
	switch (where) {
		case &#039;front&#039;:
			return ellipsis + this.substr(this.length - toLength);
			break;
		case &#039;middle&#039;:
			return this.substr(0, toLength / 2) + ellipsis + this.substr(this.length - toLength / 2)
			break;
		case &#039;end&#039;:
		default:
			return this.substr(0, toLength) + ellipsis;
			break;
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/08/javascript-string-ellipsising/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript-generated tables and rowspan</title>
		<link>http://www.barryvan.com.au/2009/04/javascript-generated-tables-and-rowspan/</link>
		<comments>http://www.barryvan.com.au/2009/04/javascript-generated-tables-and-rowspan/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 10:24:43 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=130</guid>
		<description><![CDATA[At work, I&#8217;ve recently been putting together a nice little calendar-like utility using Javascript. Basically, it has to generate a table consisting of cells which may span multiple rows. Surely the solution is simple enough: just set the rowspan on each td as we create it. Unfortunately, that doesn&#8217;t work, at least not in Firefox. [...]]]></description>
			<content:encoded><![CDATA[<p>At work, I&#8217;ve recently been putting together a nice little calendar-like utility using Javascript. Basically, it has to generate a table consisting of cells which may span multiple rows. Surely the solution is simple enough: just set the <em>rowspan</em> on each <em>td</em> as we create it. Unfortunately, that doesn&#8217;t work, at least not in Firefox.</p>
<p>It appears that in Firefox, if you create a <em>td</em> and set its <em>rowspan</em> to some value <strong>when there are no rows for it to expand into</strong>, the attribute will be completely ignored, <strong>even if you add rows afterwards</strong>! Needless to say, this is very annoying. The solution? Build your table backwards.</p>
<p>The code I have now is something like this (note that I&#8217;m developing using the Mootools framework):</p>
<pre class="brush: javascript">var tbl = new Element(&#039;table&#039;);
var trs = new Array();

for (var i = 0; i &lt; 4; i++) {
  var tr = new Element(&#039;tr&#039;);
  tr.grab(new Element(&#039;td&#039;, {
    &#039;html&#039;: &#039;Cell &#039; + i
  }));
  if (i % 2 == 0) {
    tr.grab(new Element(&#039;td&#039;, {
      &#039;rowspan&#039;: 2,
      &#039;html&#039;: &#039;Span &#039; + (i / 2)
    }));
  }
  trs.push(tr);
}

for (var i = trs.length - 1; i &gt;= 0; i--) {
  tbl.grab(trs[i], &#039;top&#039;);
}</pre>
<p>What does this code do? Well basically, we&#8217;re creating a table with ten rows and two columns; the cells in the right-hand column each occupy two rows. The result will be something like this:</p>
<table style="border:solid 1px blue;width:50%;">
<tr>
<td style="border:solid 1px black;">Cell 1</td>
<td rowspan="2" style="border:solid 1px red;">Span 1</td>
</tr>
<tr>
<td style="border:solid 1px black;">Cell 2</td>
</tr>
<tr>
<td style="border:solid 1px black;">Cell 3</td>
<td rowspan="2" style="border:solid 1px red;">Span 2</td>
</tr>
<tr>
<td style="border:solid 1px black;">Cell 4</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/04/javascript-generated-tables-and-rowspan/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MooTools and OO Javascript development</title>
		<link>http://www.barryvan.com.au/2009/04/mootools-and-oo-javascript-development/</link>
		<comments>http://www.barryvan.com.au/2009/04/mootools-and-oo-javascript-development/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 10:26:43 +0000</pubDate>
		<dc:creator>Barry van Oudtshoorn</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">http://www.barryvan.com.au/?p=124</guid>
		<description><![CDATA[I&#8217;ve started work on a new project at my job &#8212; a fairly complex AJAX application for the education sector. For this project, I&#8217;ve been allowed to essentially choose my own direction, and I&#8217;ve chosen to implement the clientside Javascript using the MooTools framework. I&#8217;ll say it right here: I&#8217;m absolutely loving it. What I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started work on a new project at my job &#8212; a fairly complex AJAX application for the education sector. For this project, I&#8217;ve been allowed to essentially choose my own direction, and I&#8217;ve chosen to implement the clientside Javascript using the <a title="MooTools Homepage" href="http://mootools.net/">MooTools</a> framework. I&#8217;ll say it right here: I&#8217;m absolutely loving it.</p>
<p>What I&#8217;m really enjoying about <a title="MooTools Homepage" href="http://mootools.net/">MooTools</a> is the object-orientedness it brings to development. Although syntactically it&#8217;s a little bit weird at first, the ability to create, extend, and implement classes makes my development progress much more quickly, and in a more efficient way. Add to that the plethora of utilities (like the <em>.each</em> prototype for arrays) and shorthand functions (like <em>$ </em>to replace <em>document.getElementById</em>), and all of a sudden Javascript development becomes a bit more, well, flexible.</p>
<p>I&#8217;m not saying that you can&#8217;t accomplish cool things in Javascript outside of MooTools (or other frameworks, for that matter); my point is that I believe you can accomplish cool things in Javascript <em>more quickly</em> using a good framework, which should really come as no surprise. Perhaps the reason I&#8217;m so enjoying this type of development, to the point of blogging about it, is that up till now, I&#8217;ve been stuck working in a non-frameworked, very non-OO Javascript development paradigm.</p>
<p>I mentioned the curious syntax that accompanies MooTools.  To create a new class, for example, you would probably write something like this:</p>
<pre class="brush: javascript">var myClass = new Class({
  Implements: Options,
  options: {
    optionA: &#039;monkey&#039;,
    optionB: &#039;pony&#039;
  },
  initializer: function(options) {
    this.setOptions(options);
    this.doSomeStuff();
  },
  doSomeStuff: function() {
    alert(this.options.optionA + &#039; eats &#039; + this.options.optionsB);
  }
});</pre>
<p>And then you would initialise it like this:</p>
<pre class="brush: javascript">var myInstance = new myClass({
  optionA: &#039;Big Pony&#039;
});</pre>
<p>Although it looks a bit weird, it&#8217;s actually not too bad. There are really only two problems I have with it:</p>
<ol>
<li>Remembering to put commas in all the right spots.</li>
<li><a title="The Geany Homepage" href="http://www.geany.org">Geany</a>, my preferred IDE (<a title="Also see my blog entry on a dark colour scheme for Geany using the Tango palette" href="2009/01/geany-ide-tango-dark-colour-scheme/">cf. Geany IDE: Tango dark colour scheme</a>) can&#8217;t pick up classes and members properly (actually, at all) in this style.</li>
</ol>
<p>Other than that, though, I&#8217;m really enjoying it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryvan.com.au/2009/04/mootools-and-oo-javascript-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
