<?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>Borgar.net &#187; javascript</title>
	<atom:link href="http://borgar.net/tagged/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://borgar.net</link>
	<description>All the wisdom of the rainbow.</description>
	<lastBuildDate>Tue, 23 Mar 2010 23:12:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0-RC1-15022</generator>
		<item>
		<title>Orðavinda</title>
		<link>http://borgar.net/s/2010/03/ordavinda/</link>
		<comments>http://borgar.net/s/2010/03/ordavinda/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 22:23:35 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[icelandic]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://borgar.net/?p=1472</guid>
		<description><![CDATA[Framlag mitt til keppninar Þú átt orðið var tölvuleikurinn Orðavinda. Hann byggir á þekktri hugmynd og reyndar langri sögu orðaleikja. Það kom mér skemmtilega á óvart að leikurinn hreppti fyrstu verðlaun í keppninni og að því er virðist af viðbrögðunum hefur mér tekist að stöðva skrifstofuvinnu á Íslandi. Leikurinn er búinn til í HTML og [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://borgar.net/programs/ordavinda/thumbnail.png" align="right" alt="Orðavinda" /></p>
<p>Framlag mitt til keppninar <a href="http://ordid.is/">Þú átt orðið</a> var tölvuleikurinn <a href="http://borgar.net/programs/ordavinda/">Orðavinda</a>. Hann byggir á þekktri hugmynd og reyndar <a href="http://en.wikipedia.org/wiki/Word_game">langri sögu orðaleikja</a>.  Það kom mér skemmtilega á óvart að leikurinn hreppti fyrstu verðlaun í keppninni og að því er virðist af viðbrögðunum hefur mér tekist að stöðva skrifstofuvinnu á Íslandi. </p>
<p>Leikurinn er búinn til í <acronym title="HyperText Markup Language">HTML</acronym> og JavaScript en notar Flash til þess að spila hljóð fyrir þá sem hafa það. Þeim sem eru forvitnir um innviðina er bent á <a href="http://github.com/borgar/ordavinda" title="Orðavinda á GitHub">heimili leiksins á GitHub</a> en leikurinn er útgefinn sem frjáls hugbúnaður undir skilmálum <a href="http://gplv3.fsf.org/"><acronym title="GNU General Public License">GPL</acronym></a> hugbúnaðarleyfisins.</p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2010/03/ordavinda/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS :target</title>
		<link>http://borgar.net/s/2009/08/css-target/</link>
		<comments>http://borgar.net/s/2009/08/css-target/#comments</comments>
		<pubDate>Wed, 05 Aug 2009 23:24:23 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://borgar.net/?p=1455</guid>
		<description><![CDATA[jQuery (or Sizzle) supports :target in browsers where it runs querySelectorAll to handle the work. In older browsers, it doesn&#8217;t offer fallback support. I guess that this is simply because :target is such an uncommon selector? I have no idea why you would want to use it, but because I have this selector extension and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://docs.jquery.com/Selectors">jQuery</a> (or <a href="http://sizzlejs.com/">Sizzle</a>) supports <code>:target</code> in browsers where it runs <a href="http://www.w3.org/TR/selectors-api/">querySelectorAll</a> to handle the work. In older browsers, it doesn&#8217;t offer fallback support. I guess that this is simply because <code>:target</code> is such an uncommon selector?</p>
<p>I have no idea why you would want to use it, but because I have this selector extension and nowhere to put it, here it is:</p>
<pre><code>jQuery.expr[':'].target = function ( a, h ) {
  return (a.id &#038;&#038; (h = document.location.hash) &#038;&#038; h === '#' + a.id)
};</pre>
<p></code></p>
<p>Updated 6. aug. 2009: <a href="http://twitter.com/maranomynet/status/3156396467">Optimized by @maranomynet</a></p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2009/08/css-target/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sōkoban</title>
		<link>http://borgar.net/s/2009/07/sokoban/</link>
		<comments>http://borgar.net/s/2009/07/sokoban/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 22:57:14 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[release]]></category>

		<guid isPermaLink="false">http://borgar.net/?p=1427</guid>
		<description><![CDATA[A few days without internet do strange things to a computer addict. In my case I start to rummage frenetically though old projects to see if there is anything I can finish, polish, or do something with that doesn&#8217;t require internet access. So I found my old Sokoban game. Originally a Windows application, I though [...]]]></description>
			<content:encoded><![CDATA[<p>A few days without internet do strange things to a computer addict. In my case I start to rummage frenetically though old projects to see if there is anything I can finish, polish, or do something with that doesn&#8217;t require internet access.</p>
<p><img title="Sokoban for windows" src="http://borgar.net/wp-content/uploads/sokoban.png" alt="sokoban" align="right" width="210" height="178" /></p>
<p>So I found my old Sokoban game. Originally a Windows application, I though it could be fun to try to remake it in JavaScript. <a title="Sokoban in jQuery" href="http://borgar.net/programs/sokoban/">So that&#8217;s what I did.</a></p>
<p>I wrote the bulk of it in about an evening, and spent a few more evenings applying spit and polish until I was satisfied that it worked the way I wanted. The <a href="http://borgar.net/programs/sokoban/js/sokoban.js">whole thing</a> is about  300 lines of mostly uncommented code running on top of jQuery &mdash; well, actually as a jQuery plugin.</p>
<h3>The interresting bits</h3>
<p>There are a few characteristics that make this implementation interesting. The first is that the game uses progressive enhancement methodology. The script runs through marked items on the webpage and makes valid Sokoban levels playable. If you don&#8217;t have JavaScript you can still read the level codes, which are normally written in a standard like this:</p>
<pre>####
# .#
#  ###
#*@  #
#  $ #
#  ###
####</pre>
<p>The <code>@</code> is the worker, <code>#</code> are walls, <code>.</code> are docks, <code>$</code> are boxes, and so on&#8230; </p>
<p>The symbols are image-replaced with <acronym title="Cascading Style Sheets">CSS</acronym> when the level is live, but the whole thing works without <acronym title="Cascading Style Sheets">CSS</acronym>. You can disable the styles if you desire to play the levels in pure ASCII.</p>
<p>This also means that the game is printable. At any moment in gameplay you can grab a hardcopy of your status and frame it. I am hard pressed to think of other printable games. Copying the level onto the clipboard also works just as it would any other text. Not really useful features for a game, but interesting side-effects nonetheless.</p>
<p>Because parsing all the levels immediately as the game loads up &mdash; especially on level collections that have very many levels &mdash; is quite labour intensive, I am applying a recent jQuery plugin of mine, <a href="http://borgar.net/svn/public/trunk/javascript/jquery.processEach/jquery.processEach.js">.processEach()</a>, to prevent the browser from locking up. In short, it works like <em>.each()</em> but yields the process every iteration to allow the browser some time to do other things. It&#8217;s perhaps a subject of another entry.</p>
<h3>Have fun</h3>
<p>Have fun with <a href="http://borgar.net/programs/sokoban/">the game</a> and the source (which are released under the <acronym title="GNU General Public License">GPL</acronym> v3). I suspect that it might one day be exactly what a Sokoban level blog is looking for, but for now it mostly remains a curiosity rather than a spectacular reproduction of the game, </p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2009/07/sokoban/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Node members or Node attributes</title>
		<link>http://borgar.net/s/2008/05/node-members-or-node-attributes/</link>
		<comments>http://borgar.net/s/2008/05/node-members-or-node-attributes/#comments</comments>
		<pubDate>Thu, 29 May 2008 23:22:17 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://borgar.undraland.com/?p=1013</guid>
		<description><![CDATA[Having given it a bit of thought I think that this problem stems from a slight confusion as to how DOM nodes&#8217; attributes work. You would expect javascript code to execute when you apply it to an attribute: someNode.onclick = "alert('foo');"; And you expect this to work because this is exactly what you do in [...]]]></description>
			<content:encoded><![CDATA[<p>Having given it a bit of thought I think that <a href="http://meyerweb.com/eric/thoughts/2008/05/29/need-help-with-table-row-events/">this problem</a> stems from a slight confusion as to how <acronym title="Document Object Model">DOM</acronym> nodes&#8217; attributes work.</p>
<p>You would expect javascript code to execute when you apply it to an attribute:</p>
<pre><code>someNode.onclick = "alert('foo');";</code></pre>
<p>And you expect this to work because <em>this is exactly what you do in your <acronym title="HyperText Markup Language">HTML</acronym></em>. And in some browsers it does. <strong>Some</strong> browsers.</p>
<p>I don&#8217;t know another way to say it, maybe there is someone who can fix my terminology but here&#8217;s the thing: Element attributes are different from node members.</p>
<p>I remember all to well the grief this caused me when I started working with DOMnodes in Javascript. Sooner or later, you will run into these inconsistencies. The browsers also try their best at blurring the difference between attributes and members. Which is helpful when you know how it works.</p>
<p>Consider this <acronym title="Cascading Style Sheets">CSS</acronym>:</p>
<pre><code>input[type="text"][value=""] { background: teal; }</code></pre>
<p>It colors an empty input field. But why doesn&#8217;t the field update when you type text in the box? <code>theInput.value</code> gives you whatever you typed in there.</p>
<p>This is because <code>.value</code> is a node member that contains what is displayed in the box, while the actual attribute contents are exposed on <code>.defaultValue</code>, which incidentally is what <code>[value]</code> is examining (and what is copied to <code>.value</code> should the inputs form be reset).</p>
<p>With onclick, the node has a <code>.onclick</code> member that is a <em>reference to</em> a function (or <code>null</code>). When the <acronym title="HyperText Markup Language">HTML</acronym> is parsed into a <acronym title="Document Object Model">DOM</acronym> tree, any code in onclick attributes is turned into an anonymous function and a reference to it is placed on the onclick member of the node.</p>
<p>So why does the following code fail in <acronym title="Microsoft Internet Explorer">MSIE</acronym>?</p>
<pre><code>someNode.onclick = "alert('foo');";</code></pre>
<p>Because <acronym title="Microsoft Internet Explorer">MSIE</acronym> doesn&#8217;t evaluate the string as it is placed on the member. The onclick becomes a reference to a string and if the event occurs <acronym title="Microsoft Internet Explorer">MSIE</acronym> will complain because effectively we&#8217;ve just tried to do this:</p>
<pre><code>"alert('foo');"();</code></pre>
<p>Does this make any more sense, or did things suddenly get more complicated?</p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2008/05/node-members-or-node-attributes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is the column index of a table cell</title>
		<link>http://borgar.net/s/2008/02/table-cell-column-index/</link>
		<comments>http://borgar.net/s/2008/02/table-cell-column-index/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 00:36:25 +0000</pubDate>
		<dc:creator>Borgar</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://borgar.undraland.com/s/2008/02/what-is-the-column-index-of-a-table-cell/</guid>
		<description><![CDATA[A peculiar but fascinating problem presented itself to me today. It was one of those; &#8220;oh yeah, I&#8217;d better look at that&#8221; kind of problems that you think you&#8217;ll solve in a few minutes but eventually grow to take hours. Given a cell in a HTML table, what is it&#8217;s column index? This seems like [...]]]></description>
			<content:encoded><![CDATA[<p>A peculiar but fascinating problem presented itself to me today. It was one of those; &#8220;oh yeah, I&#8217;d better look at that&#8221; kind of problems that you think you&#8217;ll solve in a few minutes but eventually grow to take hours.</p>
<p><strong>Given a cell in a <acronym title="HyperText Markup Language">HTML</acronym> table, what is it&#8217;s column index?</strong></p>
<p>This seems like it&#8217;s simple. You just count the cells preceding it. Fine. Works for 99% of cases. But what if the table looks like this?:</p>
<table cellspacing="4" cellpadding="8" border="1" width="100%">
<tbody>
<tr>
<td rowspan="4">cell 1</td>
<td>cell 2</td>
<td colspan="2">cell 3</td>
<td rowspan="4">cell 4</td>
<td rowspan="2">cell 5</td>
<td id="last">cell 6</td>
</tr>
<tr>
<td>cell 7</td>
<td rowspan="3">cell 8</td>
<td rowspan="2" id="">cell 9</td>
<td>cell 10</td>
</tr>
<tr>
<td rowspan="2">cell 11</td>
<td>cell 12</td>
<td rowspan="2">cell 13</td>
</tr>
<tr>
<td><b title="What is cell 14's index">My index?</b></td>
<td>cell 15</td>
</tr>
</tbody>
</table>
<p>Suddenly things are very complicated again. The last row really only contains two cells and the browser reports cell indexes 0 and 1 on those, respectively. Not the 3 and 4 I was hoping for.</p>
<p>My first thought was simply adding up the number of cells preceding this one which had a greater <em>row index</em> + <em>row span</em> than the <em>row index</em> of my subject cell. This doesn&#8217;t work because of cells like #4 &#038; #13.</p>
<p>Eventually I simply ended up with a brute force method that does the job. But is unfortunately neither fast nor elegant. But then, what code of mine is?</p>
<p>It&#8217;s presented here in case anyone else needs to solve the same annoying problem. Or if anyone can suggest a nicer (or preferably a faster) method of doing this.</p>
<p><a href="/programs/cell-offset/">View demo and code</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://borgar.net/s/2008/02/table-cell-column-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
