<?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>Brain Lint &#187; Javascript</title>
	<atom:link href="http://www.monkeyatlarge.com/archives/category/programming/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.monkeyatlarge.com</link>
	<description>Random musings on life, technology and other miscellany.</description>
	<lastBuildDate>Wed, 07 Apr 2010 01:50:30 +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>Plotting Game by Game Winning Percentages</title>
		<link>http://www.monkeyatlarge.com/archives/2010/04/06/plotting-game-by-game-winning-percentages/</link>
		<comments>http://www.monkeyatlarge.com/archives/2010/04/06/plotting-game-by-game-winning-percentages/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 01:49:53 +0000</pubDate>
		<dc:creator>James Kebinger</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://www.monkeyatlarge.com/?p=353</guid>
		<description><![CDATA[Another baseball season is upon us, and fans are quick to project the results of their favorite team from the first few games. I wondered if many teams tend to arrive at a winning percentage near their whole-season results, and then oscillate around a little, versus having early results that differ substantially from the final [...]]]></description>
			<content:encoded><![CDATA[<p>Another baseball season is upon us, and fans are quick to project the results of their favorite team from the first few games. I wondered if many teams tend to arrive at a winning percentage near their whole-season results, and then oscillate around a little, versus having early results that differ substantially from the final winning percentage.</p>
<p>I created an interactive plot to look at the results for the 2009 season, team by team.</p>
<p>Take Boston. Seen below, Boston started slow, but pretty quickly arrived at their ultimate winning level.<br />
<img src="http://www.monkeyatlarge.com/blog/wp-content/uploads/2010/04/bos-chart3.png" alt="" title="bos-chart" width="499" height="248" class="aligncenter size-full wp-image-359" /></p>
<p>On the other hand, the Yankees started even slower, and in fact didn&#8217;t reach their ultimate winning level until very late in the season.<br />
<img src="http://www.monkeyatlarge.com/blog/wp-content/uploads/2010/04/nyy-chart.png.png" alt="" title="nyy-chart.png" width="498" height="249" class="aligncenter size-full wp-image-357" /></p>
<p>See the results for the other teams <a href="http://www.monkeyatlarge.com/projects/baseball-game-winning-pct/">on the visualization page</a>.</p>
<p>The visualization was created using Javascript and the <a href="http://raphaeljs.com/">Raphaël JS </a> library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.monkeyatlarge.com/archives/2010/04/06/plotting-game-by-game-winning-percentages/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Livepipe UI controls for JS</title>
		<link>http://www.monkeyatlarge.com/archives/2008/08/21/livepipe-ui-controls-for-js/</link>
		<comments>http://www.monkeyatlarge.com/archives/2008/08/21/livepipe-ui-controls-for-js/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 01:43:02 +0000</pubDate>
		<dc:creator>James Kebinger</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.monkeyatlarge.com/?p=294</guid>
		<description><![CDATA[I&#8217;ve been pretty pleased so far with the popup window control from LivePipe. It plays nice with Prototype and is easy to style with regular CSS. We had considered using Prototype Window but I was put off that all their default styles looks like operating system windows and restyling their windows required a table and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been pretty pleased so far with the <a href="http://livepipe.net/control/window">popup window control</a> from <a href="http://livepipe.net/">LivePipe</a>. It plays nice with Prototype and is easy to style with regular CSS. We had considered using <a href="http://prototype-window.xilinus.com/">Prototype Window</a> but I was put off that all their default styles looks like operating system windows and restyling their windows required a table and 9 images.</p>
<p>I&#8217;d recommend anyone looking for a popup window solution at least consider Livepipe. There are downsides however, chiefly that the project is pretty immature &#8211; technically I suppose this is an alpha release since Beta One is being worked on, so the community remains small. While there are some folks already submitting patches, progress on merging the patches is alarmingly slow, as one can see from their <a href="http://livepipe.lighthouseapp.com/projects/11811-livepipe-ui/overview">lighthouse page</a>.</p>
<p>If you&#8217;re doing RESTful stuff in Rails however, you will need the contents of <a href="http://livepipe.lighthouseapp.com/projects/11811/tickets/10-control-window-s-default-request-method#ticket-10-1">ticket #10</a> which modifies the popup window to accept an option to use different HTTP verbs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.monkeyatlarge.com/archives/2008/08/21/livepipe-ui-controls-for-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scriptaculous docs</title>
		<link>http://www.monkeyatlarge.com/archives/2008/08/21/scriptaculous-docs/</link>
		<comments>http://www.monkeyatlarge.com/archives/2008/08/21/scriptaculous-docs/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 01:29:27 +0000</pubDate>
		<dc:creator>James Kebinger</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.monkeyatlarge.com/?p=290</guid>
		<description><![CDATA[For all the complaining I often do about the poor documentation of the scriptaculous project, I finally did something to help that today, creating (very thin) documentation for their new (if released in January is new) Effect.Tween function here on their github wiki.
I was creating a method to scroll the viewport so that the contents [...]]]></description>
			<content:encoded><![CDATA[<p>For all the complaining I often do about the poor documentation of the <a href="http://script.aculo.us/">scriptaculous</a> project, I finally did something to help that today, creating (very thin) documentation for their new (if released in January is new) Effect.Tween function <a href="http://github.com/madrobby/scriptaculous/wikis/effecttween">here</a> on their github wiki.</p>
<p>I was creating a method to scroll the viewport so that the contents of an AJAX-loaded div would be fully visible on the screen &#8211; the (still undocumented) Effect.ScrollTo doesn&#8217;t quite do it because it doesn&#8217;t consider the height of the element it scrolls to, but in doing so I stumbled over Tween in the code. Once the math to figure out how much scrolling is needed, its easy to use Effect.Tween to smoothly scroll the window by repeatedly calling window.scrollBy();</p>
<p>This certainly isn&#8217;t rocket science, but here&#8217;s an outline of how to do it (this code only deals with downward vertical scrolling):</p>
<pre style="padding-left: 30px;">var elementHeight = element.getHeight();
var screenHeight = document.viewport.getHeight();
var elementScreenPos =element.viewportOffset()[1];
var amountToScroll = elementHeight - (screenHeight - elementScreenPos);
if (amountToScroll &gt; 0){
var scrollPos = document.viewport.getScrollOffsets().top;
new Effect.Tween(null,scrollPos,scrollPos+amountToScroll,{},function(n) { window.scrollTo(0,n);});
}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.monkeyatlarge.com/archives/2008/08/21/scriptaculous-docs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Select part of the text in a textbox with javascript</title>
		<link>http://www.monkeyatlarge.com/archives/2007/03/29/select-part-of-the-text-in-a-textbox-with-javascript/</link>
		<comments>http://www.monkeyatlarge.com/archives/2007/03/29/select-part-of-the-text-in-a-textbox-with-javascript/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 01:08:25 +0000</pubDate>
		<dc:creator>James Kebinger</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.monkeyatlarge.com/archives/2007/03/29/select-part-of-the-text-in-a-textbox-with-javascript/</guid>
		<description><![CDATA[There was a brief discussion on the Tracks mailing list over the way its autocomplete works (the project uses Scriptaculous&#8217;s nice Autocomplete widget in local mode): should it automatically fill in the entire word once enough text is entered to match one of the choices (annoying if you have to backspace because the guess was [...]]]></description>
			<content:encoded><![CDATA[<p>There was a brief discussion on the <a href="http://www.rousette.org.uk/projects/">Tracks</a> mailing list over the way its autocomplete works (the project uses Scriptaculous&#8217;s nice Autocomplete widget in local mode): should it automatically fill in the entire word once enough text is entered to match one of the choices (annoying if you have to backspace because the guess was wrong) or make you hit tab or enter to fill in the suggestion. To make a long story short, I suggested a third approach &#8211; fill in the remainder of the match selected, so if its wrong, the user can type over it, like this:</p>
<p><img src='http://www.monkeyatlarge.com/blog/wp-content/uploads/2007/03/textpartialselect.png' alt='textpartialselect.png' /></p>
<p>This isn&#8217;t rocket science and has been done forever, but I didn&#8217;t find a single good reference on how to select just part of the text in a text box. <a href="http://script.aculo.us/">Scriptaculous</a> and <a href="http://www.prototypejs.org/">prototype</a> don&#8217;t support it at the present time, and like anything good in browser-land, there&#8217;s at least two different ways to skin this cat. The IE way, and everyone else&#8217;s way (actually I don&#8217;t know which way safari and opera work, but the code here does work for them too). </p>
<p>I saw one of the <a href="http://developer.yahoo.com/yui/">YUI</a> widgets supported &#8220;typeahead&#8221; so I looked through its code to find the relevent javascript calls &#8211; for IE its &#8220;createTextRange&#8221; and for firefox its &#8220;setSelectionRange&#8221;. Combine those and you get the following, which I&#8217;ve tested as working on IE 6 (or was it 7?), Firefox (mac), opera (mac) and safari.</p>
<pre>
function selectSomeText(element,begin,end)
{
	if (element.setSelectionRange)
	{
		element.setSelectionRange(begin,end);
	}
	else if (element.createTextRange)
	{
		var range = element.createTextRange();
		range.moveStart("character",begin);
		range.moveEnd("character",end);
		range.select();
	}
}
</pre>
<p>One of these days I&#8217;ll refactor the code I wrote to test this with scriptactulous and throw that up here as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.monkeyatlarge.com/archives/2007/03/29/select-part-of-the-text-in-a-textbox-with-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
