<?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>The Accidental Developer &#187; Javascript</title>
	<atom:link href="http://osric.com/chris/accidental-developer/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://osric.com/chris/accidental-developer</link>
	<description>What if Gregor Samsa awoke a computer programmer?</description>
	<lastBuildDate>Tue, 25 May 2010 20:21:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating a Javascript Game (WordLock)</title>
		<link>http://osric.com/chris/accidental-developer/2010/05/creating-a-javascript-game-wordlock/</link>
		<comments>http://osric.com/chris/accidental-developer/2010/05/creating-a-javascript-game-wordlock/#comments</comments>
		<pubDate>Tue, 25 May 2010 20:17:32 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[games]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=273</guid>
		<description><![CDATA[I recently created a simple word game (<a href="http://osric.com/wordlock/">WordLock</a>) using Javascript, which presented certain challenges. The game displays 3 random letters to the player, who must then attempt to create a dictionary word in as few moves as possible by shifting the letters up or down in the alphabet.

There were several programming decisions or challenges that came up during the game's creation, which I discuss in the full post.]]></description>
			<content:encoded><![CDATA[<p><img src="http://osric.com/chris/portfolio/images/wordlock200x150.png" alt="WordLock - A Word Game" style="border:solid 1px #999" /><br />
<a href="http://osric.com/wordlock/">osric.com/wordlock</a></p>
<p>I recently created a simple word game using Javascript, which presented certain challenges. The game displays 3 random letters to the player, who must then attempt to create a dictionary word in as few moves as possible by shifting the letters up or down in the alphabet.</p>
<p>There were several programming decisions or challenges that came up during the game&#8217;s creation, for which I was able to apply some of the things I learned in my recent computer science classes.</p>
<p><span id="more-273"></span></p>
<p>The first challenge was how to include the dictionary. The source list I used for 3-letter words (from a Scrabble dictionary) includes 1012 entries. Although I could have developed a server-side solution to check words via AJAX, I wanted the game to be as quick and responsive as possible, and 1012 3-letter words is not all that prohibitive. First, I created an array of all the words; however, that took a lot of extra bytes for all the quotes and commas. In fact, it doubled the space required. I looked at using a prefix scheme (&#8220;A&#8221; followed by all the two-letter sequences that begin with &#8220;A&#8221;) to save a few bytes, but the savings was not as great as I had initially anticipated. In the end, I just included the dictionary as a long, unbroken string: since we know that each word is 3 characters, it is easy to access any given word. </p>
<p>The next challenge was how to look up the user&#8217;s 3-letter sequence to see if the sequence is in our dictionary. The brute-force approach is to compare it to every word in the dictionary, which would take 1012 comparisons for a sequence that isn&#8217;t present. 1012 comparisons isn&#8217;t all that bad, but there are certainly more efficient ways, and I was thinking about the implications of expanding to a 4-letter or 5-letter game. Here are some of the look-up options I considered:</p>
<ul>
<li><strong>Binary search.</strong> Because we are dealing with an alphabetized dictionary, we can start in the middle of the dictionary and immediately eliminate half as possible matches, and then perform the same binary search recursively. Now we need only 10 comparisons for a sequence that isn&#8217;t present.</li>
<li><strong>Hash table.</strong> Although we would have to create the hash table at the beginning of the game, this only took 3 comparisons for a sequence that wasn&#8217;t present (based on empirical observation).</li>
<li><strong>Bucket array.</strong> I&#8217;m not sure what else to call it, but I created a large array (17,576) that could accommodate every conceivable combination of letters. A sequence not in the dictionary remains null, and a sequence in the dictionary gets assigned a 1. This method has larger memory requirements&#8211;not extraordinary for 3-letter sequences, but would grow quickly for longer sequences. Now we only need one comparison to determine is a sequence is a dictionary word.</li>
</ul>
<p>I picked the binary search for its simplicity.</p>
<p>The last major challenge was creating the &#8220;fewest moves&#8221; algorithm. The game currently tells the user the fewest number of moves it takes to convert the random sequence to a dictionary word. I struggled with this at first, until I realized that the problem is basically just a <a href="http://en.wikipedia.org/wiki/Breadth-first_search">Breadth-First Search</a> or shortest-path algorithm. I enqueue the initial sequence. For each possible one-move combination, I check it against the dictionary, and enqueue that sequence. (I enqueue an impossible dummy sequence&#8211;&#8221;###&#8221;&#8211;to indicate that we need to increment the fewest moves.)</p>
<p>One problem with this is that if it enqueues every one-move combination, it will enqueue many duplicates. Before I checked for duplicates, I found that the fewest moves algorithm often checked more than the 17,576 unique 3-letter sequences. For letter combinations where the nearest dictionary word was 8 or more moves away, Javascript would become unresponsive (or the browser would crash). Since the already-checked sequences were in no particular order, I used the hash table (instead of the binary search) to perform look-ups (although a brute force approach would probably have been sufficient).</p>
<p>Another problem with the fewest-moves algorithm is that my first approach was to use a recursive function. However, Javascript apparently does not always perform well with recursion; Firefox would throw &#8220;too much recursion&#8221; errors. I changed the function to use a while loop (continue processing while the queue is not empty), which solved that issue.</p>
<p>Although many of these optimizations were not strictly necessary and the brute-force approach would have worked suitably in many cases, I think the optimizations will help the game scale to handle 4-and-5-letter words (although the dictionaries may become too heavy for 5-letter words).</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2010/05/creating-a-javascript-game-wordlock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hunt the Wumpus</title>
		<link>http://osric.com/chris/accidental-developer/2010/01/javascript-hunt-the-wumpus/</link>
		<comments>http://osric.com/chris/accidental-developer/2010/01/javascript-hunt-the-wumpus/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 00:09:10 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[wumpus]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=263</guid>
		<description><![CDATA[I am taking a course in discrete mathematics this semester, and the professor suggested we take a look at a game called Hunt the Wumpus.
Hunt the Wumpus was originally created in the 1970s, and unfortunately, most of the versions you can find on the web today are easier and less interesting that the original. The [...]]]></description>
			<content:encoded><![CDATA[<p>I am taking a course in discrete mathematics this semester, and the professor suggested we take a look at a game called Hunt the Wumpus.</p>
<p>Hunt the Wumpus was originally created in the 1970s, and unfortunately, most of the versions you can find on the web today are easier and less interesting that the original. The original eschewed a square grid for the game board and instead used a &#8220;squashed&#8221; dodecahedron, where each game space was one of the vertices.</p>
<p>It is also noteworthy for introducing the <em>superbat</em>, a feature of other games (including Zork) that followed Hunt the Wumpus, and for the humorous feedback (e.g. &#8220;ZAP&#8211;Superbat Snatch! Elsewhereville for you!&#8221;) that many of my favorite games adopted.</p>
<p>At any rate, I decided to recreate a version of the easier and less interesting grid-based game in Javascript:<br />
<a href="http://osric.com/wumpus/">Hunt the Wumpus</a></p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2010/01/javascript-hunt-the-wumpus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript insertAfter()</title>
		<link>http://osric.com/chris/accidental-developer/2009/08/javascript-insertafter/</link>
		<comments>http://osric.com/chris/accidental-developer/2009/08/javascript-insertafter/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 23:12:47 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[insertAfter]]></category>
		<category><![CDATA[insertBefore]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=217</guid>
		<description><![CDATA[Although Javascript doesn't contain a DOM function for Node.insertAfter(), you can easily emulate it using Node.insertBefore -- and even call it via Node.insertAfter()]]></description>
			<content:encoded><![CDATA[<p>There is no <em>Node.insertAfter()</em> DOM function in Javascript, but it is clearly something that developers would like.</p>
<p>As the <a href="https://developer.mozilla.org/en/Gecko_DOM_Reference">Gecko DOM Reference</a> for <a href="https://developer.mozilla.org/En/DOM/Node.insertBefore">Node.insertBefore()</a> points out, this can easily be achieved with<br />
<code>parentDiv.insertBefore(nodeToInsert, nodeToInsertAfter.nextSibling);</code></p>
<p>If <em>nodeToInsertAfter</em> doesn&#8217;t have a next sibling, a NULL value will be returned and <em>nodeToInsert</em> will be inserted as the last child of <em>parentDiv</em>.</p>
<p>If you find it frustrating to type <em>insertBefore</em> when you want to <em>insertAfter</em>, that&#8217;s OK: you can add that function to the Object object:<br />
<code>Object.prototype.insertAfter = function (newNode) { this.parentNode.insertBefore(newNode, this.nextSibling); }</code></p>
<p>Now you can type:<br />
<code>nodeToInsertAfter.insertAfter(nodeToInsert)</code></p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2009/08/javascript-insertafter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery is AWESOME</title>
		<link>http://osric.com/chris/accidental-developer/2009/01/jquery-is-awsome/</link>
		<comments>http://osric.com/chris/accidental-developer/2009/01/jquery-is-awsome/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 22:53:12 +0000</pubDate>
		<dc:creator>giblfiz</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=135</guid>
		<description><![CDATA[I just took (and finished) a small project to add some ajax and javascript whiz-bang to a website. (actually it was the home page for a web development company you would think that they would keep that in house) and I decided to try out jQuery.
It blew my socks off. I&#8217;m really really impressed with [...]]]></description>
			<content:encoded><![CDATA[<p>I just took (and finished) a small project to add some ajax and javascript whiz-bang to a website. (actually it was the home page for a web development company you would think that they would keep that in house) and I decided to try out jQuery.</p>
<p>It blew my socks off. I&#8217;m really really impressed with jQuery, and I&#8217;m looking forward to using it a lot more. It took me an hour or two to really get a handle on how a few parts of it work, but man is it a powerhouse. If your website needs to sing and dance&#8230;. jQuery is the way!</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2009/01/jquery-is-awsome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript textarea counter</title>
		<link>http://osric.com/chris/accidental-developer/2008/11/javascript-textarea-counter/</link>
		<comments>http://osric.com/chris/accidental-developer/2008/11/javascript-textarea-counter/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 19:33:26 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[User Interface]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[textarea]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=109</guid>
		<description><![CDATA[I&#8217;ve been thinking more about the textarea counter issue that I mentioned in my previous post (&#8220;Users Paste Differently&#8220;).
First of all, I noticed that some of the textarea counter scripts date back to at least 2000, so this has been a problem that developers have been looking to solve for 8 years. I checked the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking more about the textarea counter issue that I mentioned in my previous post (&#8220;<a href="http://osric.com/chris/accidental-developer/?p=103">Users Paste Differently</a>&#8220;).</p>
<p>First of all, I noticed that some of the textarea counter scripts date back to at least 2000, so this has been a problem that developers have been looking to solve for 8 years. I checked the <a href="http://www.w3.org/html/wg/html5/">HTML 5 specification</a> and found that in HTML 5, the <a href="http://www.w3.org/html/wg/html5/#the-textarea-element">textarea element has a maxlength attribute</a>. Presumably user agents will build in the most elegant solution.</p>
<p>But what is the current most elegant solution?<span id="more-109"></span><br />
I checked a couple sites that I know use textarea counters well: <a href="http://delicious.com/">Delicious</a> and <a href="http://twitter.com/">Twitter</a>.</p>
<p><strong>Delicious</strong><br />
<div id="attachment_118" class="wp-caption alignnone" style="width: 420px"><a href="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/11/delicious-textarea-counters.png"><img src="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/11/delicious-textarea-counters.png" alt="Textarea counters on Delicious.com" title="delicious-textarea-counters" width="410" height="66" class="size-full wp-image-118" /></a><p class="wp-caption-text">Textarea counters on Delicious.com</p></div></p>
<p><strong>Twitter</strong><br />
<div id="attachment_120" class="wp-caption alignnone" style="width: 394px"><a href="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/11/twitter-textarea-counters.png"><img src="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/11/twitter-textarea-counters.png" alt="Textarea counters on Twitter.com" title="twitter-textarea-counters" width="384" height="80" class="size-full wp-image-120" /></a><p class="wp-caption-text">Textarea counters on Twitter.com</p></div></p>
<p>I like how prominent the character count is in Twitter, although perhaps too terse, but if Javascript is disabled it displays nothing at all. On the other hand, in Delicious displays &#8220;1000 characters max&#8221; if Javascript is off (instead of &#8220;1000 characters left&#8221;), which is still useful information. (I would avoid using the abbreviation <em>max</em>, though, and use <em>maximum</em> or <em>limit</em> instead, which might be better understood by those for whom English is a second language.)</p>
<p>I like Twitter&#8217;s &#8220;warning track&#8221; that lets the user know they need to keep it concise and wrap it up, although I find it confusing that they used bright red to denote both the &#8220;dangerously close to&#8221; as well as &#8220;over&#8221; the limit. The positive bright red numbers could easily be misconstrued as over the limit, since red is a color we frequently use to denote errors.</p>
<p>Twitter&#8217;s counter responds to onBlur and onChange, whereas the counter in Delicious is triggered by neither.</p>
<p>Both get one thing right that I think most other textarea counters get wrong: they don&#8217;t truncate the user&#8217;s text. Deleting something that the user has typed (or pasted) is definitely a bad idea for at least two reasons: the user may not realize the input was truncated and may submit incomplete info, and that the user, upon discovering that the input requires editing, may choose to cut text from someplace other than the end. Instead, both versions alert the user that they are over the limit and provide information on how many characters need to be cut to stay within the limit.</p>
<p>(As an aside, one thing I find curious is that both count an <em>Enter</em> keystroke as one character. I&#8217;ve run into issues with this before because a line break on a Windows-based system should insert 2 ASCII characters: a Carriage Return (CR) and a Line Feed (LF). *nix systems, including OS X, will insert a Line Feed (LF). However, I haven&#8217;t been able to reproduce this issue with recent testing. If it is still an issue, I imagine they handle this on the back-end by converting the CRLF to LF before inserting it into the database?)</p>
<p>In short, my recommendations are:</p>
<ul>
<li>Don&#8217;t truncate the user&#8217;s input; let the user correct it</li>
<li>Let the user know how far over the limit he or she is</li>
<li>Provide guidelines even if Javascript is disabled</li>
<li>onBlur and onChange should also trigger the counter, in case the user is pasting text</li>
<li>Keep the counter message simple and clear</li>
</ul>
<p>Another idea I had for a visual counter:<br />
<div id="attachment_116" class="wp-caption alignnone" style="width: 260px"><a href="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/11/counter-bar.png"><img src="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/11/counter-bar.png" alt="Counter - characters remaining" title="counter-bar" width="250" height="20" class="size-full wp-image-116" /></a><p class="wp-caption-text">Counter - characters remaining</p></div><br />
Aside from turning red once past the limit, though I&#8217;m not sure how it would visually convey to the user by how much the text exceeds the limits.</p>
<p><strong>How can a counter be implemented programatically?</strong><br />
I would like to set something up so that the appropriate event handlers are attached to textarea elements automatically. I found a <a href="http://jquery.com/">jQuery</a> plugin, <a href="http://plugins.jquery.com/project/CharLimit">Char Limit</a>, but in addition to not meeting the recommendations I made above, I don&#8217;t like how the developer has to specify the character limit in the Javascript (and apply the same limit for all textarea elements).</p>
<p>I think a clever, although imperfect, solution would be to have jQuery (or any Javascript of your choice) turn any static character limit messages (like the one that Delicious provides if Javascript is disabled) into dynamic character counters. For example, with the following code, the Javascript could find any elements with id attributes matching *_counter, take the numeric part as the limit, and build a character counter:<br />
<code>&lt;textarea name="example" id="example"&gt;&lt;/textarea&gt;<br />
&lt;div id="example_counter"&gt;300 characters maximum&lt;/div&gt;</code></p>
<p>It&#8217;s problematic for several reasons: another element on the page could have an id that matches *_counter, the non-Javascript message could  contain more than one numeric part, and the developers would have be consistent in naming the textareas and accompanying divs. But I think it is in many ways an improvement over the inline Javascript I&#8217;ve seen in some oft-used solutions.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2008/11/javascript-textarea-counter/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Users Paste Differently</title>
		<link>http://osric.com/chris/accidental-developer/2008/11/users-paste-differently/</link>
		<comments>http://osric.com/chris/accidental-developer/2008/11/users-paste-differently/#comments</comments>
		<pubDate>Mon, 10 Nov 2008 20:52:50 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[textarea]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=103</guid>
		<description><![CDATA[ I&#8217;ve been using a relatively generic Javascript textarea counter for several years to restrict the input length on form textareas. I&#8217;m not sure where the specific version I&#8217;m using came from, but you can find dozens like it on Google.
Almost all of them rely on the onKeyDown and onKeyUp events to trigger the script. [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_104" class="wp-caption alignleft" style="width: 110px"><a href="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/11/paste.jpg"><img src="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/11/paste.jpg" alt="Paste" title="paste" width="100" height="177" class="size-full wp-image-104" /></a><p class="wp-caption-text">Paste!</p></div> I&#8217;ve been using a relatively generic Javascript textarea counter for several years to restrict the input length on form textareas. I&#8217;m not sure where the specific version I&#8217;m using came from, but you can <a href="http://www.google.com/search?q=textarea+counter">find dozens like it on Google</a>.</p>
<p>Almost all of them rely on the <em>onKeyDown</em> and <em>onKeyUp</em> events to trigger the script. However, some users still manage to submit text that exceeded the limits, even though the application required Javascript. I could not for the life of me reproduce this issue&#8230;until today.<br />
<span id="more-103"></span><br />
Naturally, when I tried to enter text into the textarea, I just typed it there. But that&#8217;s not always what users do. Can you imagine, some users might actually compose text in, say, Microsoft Word and then paste it into a textarea? Maybe they are taking advantage of the spell-checker or grammar-checker. Maybe it&#8217;s text that they have composed once, but are submitting to several different sites. Or maybe it&#8217;s some reason I can&#8217;t even fathom!</p>
<p>When I copy-and-paste text, I highlight it, hit CTRL-c, put my cursor at the destination, and hit CTRL-v. But that&#8217;s not always what users do either. And as it turns out, if you right-click and select Paste, neither <em>onKeyDown</em> or <em>onKeyUp</em> are triggered. Adding <em>onBlur</em> and <em>onChange</em> seem to do the trick, though.</p>
<p>Of course, this discovery hasn&#8217;t exactly solved the problem: the script we are using simply truncates text that is too long. In Firefox, if your textarea has a scrollbar, it could show the user just the top portion of his or her pasted text. Everything would look OK, and the character count displayed would show, for example, 500 of 500 characters.</p>
<p>I haven&#8217;t written a replacement script yet, but something clearly needs to alert the user that text has been truncated. At least, however, I have identified the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2008/11/users-paste-differently/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>javascript&#8217;s parseInt is pretty evil</title>
		<link>http://osric.com/chris/accidental-developer/2008/10/javascripts-parseint-is-pretty-evil/</link>
		<comments>http://osric.com/chris/accidental-developer/2008/10/javascripts-parseint-is-pretty-evil/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 02:29:21 +0000</pubDate>
		<dc:creator>giblfiz</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[parseint]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=86</guid>
		<description><![CDATA[Javascript uses the + symbol for both addition and concatenation. This means that if you want to add a numeric value to data pulled from a user, you need to cast it to being a numeric type, like for instance an Int. Makes sense, so I use the parseInt function to cast with. OK, that&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript uses the + symbol for both addition and concatenation. This means that if you want to add a numeric value to data pulled from a user, you need to cast it to being a numeric type, like for instance an Int. Makes sense, so I use the parseInt function to cast with. OK, that&#8217;s fine so here is the kicker, if you pass it &#8220;09&#8243; it generates the value 0, not 9. </p>
<p>Hrmm, well that&#8217;s odd. If you pass in &#8220;9&#8243; it returns 9, but if you pass in &#8220;09&#8243; you get 0. I&#8217;m lucky I caught that in testing. It turns out that if you lead with a 0 then parseInt interprates as the value as an octal number. There is a way to deal with it though, you can pass in a second variable telling it what base the numbers it should be reading are. </p>
<p>So really you want parseInt(var, 10) not parseInt(var)</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2008/10/javascripts-parseint-is-pretty-evil/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why Doesn&#8217;t TinyMCE load in IE?</title>
		<link>http://osric.com/chris/accidental-developer/2008/09/why-doesnt-tinymce-load-in-ie/</link>
		<comments>http://osric.com/chris/accidental-developer/2008/09/why-doesnt-tinymce-load-in-ie/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 21:19:32 +0000</pubDate>
		<dc:creator>giblfiz</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[tinymce]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=65</guid>
		<description><![CDATA[looks like it is all due to the insertAdjacentHTML call being used in another library. In my case, wz_tooltip. Oh wow did this hurt me. So that horror of a project that keeps on poking its head up sent in another small request&#8230; put tinyMCE or FCKeditor into one page on the website. Offered 5 [...]]]></description>
			<content:encoded><![CDATA[<p><img style="max-width: 800px;" src="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/09/ie7.jpg" align="right" height="200" width="200" />looks like it is all due to the insertAdjacentHTML call being used in another library. In my case, wz_tooltip. Oh wow did this hurt me. So that horror of a project that keeps on poking its head up sent in another small request&#8230; put <a href="http://tinymce.moxiecode.com/">tinyMCE</a> or <a href="http://www.fckeditor.net/">FCKeditor</a> into one page on the website. Offered 5 hours. Well TinyMCE is already installed, so I figured this was a chance to recoup a <i>little</i> of my loss on this project. Sure enough, I activated TinyMCE with about 5 lines of code, checked that it worked in Firefox, and billed my money. </p>
<p>Next morning I get a call. The thing doesn&#8217;t work in IE. So I try a few quick and obvious things, move around where it gets loaded, try a few different load orders. No luck. Grr. I was going to type out my whole damn process, but I realized that&#8217;s not what people want to read&#8230;</p>
<p>Short version is: the <a href="http://www.walterzorn.com/tooltip/tooltip_e.htm">wz_tooltip.js</a> library conflicts with the <a href="http://tinymce.moxiecode.com/">TinyMCE</a> library ONLY in Internet Explorer. This is because of a call to <a href="http://www.faqts.com/knowledge_base/view.phtml/aid/7184/fid/53">insertAdjacentHTML</a> which is an IE-only javascript call (thanks again for embrace and extend M$). As a workaround, you can modify the wz_tooltip file by commenting out from line 397 (inclusive) (thats: <font face="Courier New">   if(wztt_body.insertAdjacentHTML)</font> ) down to line 400 inclusive (thats : <font face="Courier New">else if(typeof wztt_body.innerHTML != wztt_u &&amp; document.createElement &&amp; wztt_body.appendChild)</font> ) And now I&#8217;m off to submit bug reports.</p>
<p>What a waste of a morning. </p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2008/09/why-doesnt-tinymce-load-in-ie/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Javascript Dollar Sign ($) Function</title>
		<link>http://osric.com/chris/accidental-developer/2008/04/the-javascript-dollar-sign-function/</link>
		<comments>http://osric.com/chris/accidental-developer/2008/04/the-javascript-dollar-sign-function/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 14:31:05 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=17</guid>
		<description><![CDATA[Recently, I&#8217;ve been seeing a lot of Javascript functions prefixed with a dollar sign ($) or simply named $. I thought, what sort of magical property does the dollar sign have in Javascript? What sort of esotericism had I uncovered?

I checked the O&#8217;Reilly Rhinoceros book, and found that the dollar sign has no special properties.
However, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;ve been seeing a lot of Javascript functions prefixed with a dollar sign ($) or simply named $. I thought, what sort of magical property does the dollar sign have in Javascript? What sort of esotericism had I uncovered?</p>
<p style="text-align: center"><img src="http://osric.com/chris/accidental-developer/wp-content/uploads/2008/04/dollar-sign-magician.gif" alt="The Dollar Sign Magician" /></p>
<p>I checked the <a href="http://www.oreilly.com/catalog/jscript5/index.html" title="JavaScript: The Definitive Guide">O&#8217;Reilly Rhinoceros book</a>, and found that <em>the dollar sign has no special properties</em>.</p>
<p>However, I have come to discover that dollar sign function has become the more-or-less de facto shortcut to document.getElementById(). Let&#8217;s face it, we all use document.getElementById() a lot. Not only does it take time to type, but it adds bytes to your code as well.</p>
<p>Here&#8217;s the version from <a href="http://www.prototypejs.org/" title="Prototype Javascript framework">prototype.js</a>, which can return more than just a single element:</p>
<pre>function $(element) {
  if (arguments.length &gt; 1) {
    for (var i = 0, elements = [], length = arguments.length; i &lt; length; i++)
      elements.push($(arguments[i]));
    return elements;
  }
  if (Object.isString(element))
    element = document.getElementById(element);
  return Element.extend(element);
}</pre>
<pre></pre>
<p>Because it has become a common shortcut to document.getElementById(), it means that various Javascript libraries should play nicely together: if the dollar sign function in one .js file is overwritten by the same dollar sign function in another .js file, everything should still work. That also means that creating your own dollar sign function that does something different is probably not a good idea.</p>
<p>In case you were wondering, the underscore has no special properties either. But let&#8217;s face it, $(&#8216;myVal&#8217;) looks more like programming than _(&#8216;myVal&#8217;).</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2008/04/the-javascript-dollar-sign-function/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Strange Projects on the Horizon</title>
		<link>http://osric.com/chris/accidental-developer/2008/03/strange-projects-on-the-horizon/</link>
		<comments>http://osric.com/chris/accidental-developer/2008/03/strange-projects-on-the-horizon/#comments</comments>
		<pubDate>Mon, 24 Mar 2008 17:09:07 +0000</pubDate>
		<dc:creator>giblfiz</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=12</guid>
		<description><![CDATA[On Friday I was approached to work on one of the oddest and probably most ill-conceived projects I  have ever encountered, and I might just take it anyway. Basically a company has a very good, very modular framework built for them in C# using .Net by a bunch of Russians who they hired remotely. [...]]]></description>
			<content:encoded><![CDATA[<p>On Friday I was approached to work on one of the oddest and probably most ill-conceived projects I  have ever encountered, and I might just take it anyway. Basically a company has a very good, very modular framework built for them in C# using .Net by a bunch of Russians who they hired remotely. I can tell by looking at the output that the code is quite modular, if it might be a little unclean. It looks like it would actually be some pretty good code to support.</p>
<p>They have been selling boiler plate instillations of this framework, with just some simple skinning done, and selling them hand over fist, apparently they are making a mint. </p>
<p>So anyway, For some reason they want to hire one of my companies, (and hence me) to do the occasional &#8220;special project&#8221; for clients who need something that is just slightly more custom than what they have. There are a few basic problems with this. <br />1) I don&#8217;t know C# <br />2) I don&#8217;t know Russian <br />3) I don&#8217;t think I even get access to the code base at all!</p>
<p>It seems that each part of the site that the framework builds can be loaded as a &#8220;section&#8221; which can easily be included on sites other than the primary site. (that is to say you can throw a little javascript or something into your own website, and have it display, say the friends list from the primary site, and it was built to have this work). For some reason they think it&#8217;s a good idea to have me build a second site, in php, that covers their additional functionality, and then have it load each of the bits of the primary site and display them. This seems bizzaro to me, but hey, I&#8217;m willing to do it because I bet I can learn something cool and they would still be paying me.</p>
<p>What I&#8217;m really hoping is that this is NOT actually what they expect me to do, and that there is a SOAP interface to what the Russians built.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2008/03/strange-projects-on-the-horizon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
