<?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>techrageo.us &#187; Programming</title>
	<atom:link href="http://techrageo.us/taxonomy/categories/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://techrageo.us</link>
	<description>insight on technology</description>
	<lastBuildDate>Sun, 30 May 2010 14:29:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Wildcard Namespaces In XPath</title>
		<link>http://techrageo.us/2008/11/01/wildcard-namespaces-in-xpath/</link>
		<comments>http://techrageo.us/2008/11/01/wildcard-namespaces-in-xpath/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 20:43:07 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://techrageo.us/2008/11/01/wildcard-namespaces-in-xpath/</guid>
		<description><![CDATA[Select namespaced elements in XPath without specifying the namespace. Every once in a while you need to get to an XML element that is tucked within some namespace or another, but you really are not in the mood to deal with namespaces. You really don&#8217;t want to mess with XmlNamespaceManager or its ilk; or maybe [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Select namespaced elements in XPath without specifying the namespace.</strong></p>
<p>Every once in a while you need to get to an XML element that is tucked within some namespace or another, but you really are not in the mood to deal with namespaces. You really don&#8217;t want to mess with XmlNamespaceManager or its ilk; or maybe you only have XPath to work with.</p>
<p>When this comes up, it usually takes me a few moments to remember, but the magic is the local-name() function.</p>
<p><strong>XML</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:bookstore</span> <span style="color: #000066;">xmlns:gw</span>=<span style="color: #ff0000;">&quot;http://www.moonbats.com/gw&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Warming Up To The New Ice Age<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>A. Nother Lemming<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>The Sky Is Falling<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Chicken Little<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Glaciers Will Burn Us All<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Chicken Little<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Data: A Cookbook<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gw:author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Grant Me Money<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:author<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gw:bookstore<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>XPath</strong></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">//*[local-name()='title']</pre></div></div>

<p>This basically says to select any element where the local name, i.e. the element name minus the namespace, is equal to &#8216;title&#8217;.</p>
<p>This can be extended with other XPath functions. In the following example we want to get the titles of books by Chicken Little.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">//*[ local-name() = 'title' and (../*[local-name() = 'author'
	and contains( text(), 'Chicken Little' ) ]) ]</pre></div></div>

<p>Here we&#8217;re selecting elements with a local name of &#8216;title&#8217; and a sibling element named author and where that sibling&#8217;s value contains &#8216;Chicken Little&#8217;.</p>
<p>This syntax is not as convenient as something like <tt>/*:title</tt>, but at least it does the trick.</p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2008/11/01/wildcard-namespaces-in-xpath/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ESV Bible Via REST</title>
		<link>http://techrageo.us/2008/03/07/esv-bible-via-rest/</link>
		<comments>http://techrageo.us/2008/03/07/esv-bible-via-rest/#comments</comments>
		<pubDate>Fri, 07 Mar 2008 21:50:34 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://techrageo.us/2008/03/07/esv-bible-via-rest/</guid>
		<description><![CDATA[The ESV Bible REST Web Service The English Standard Version (ESV) of the Bible is a literal word-for-word translation from Crossway Bibles, who have made it available via a REST web service. There is no charge for non-commercial applications, such as on a personal or church website, though use is limited to 500 verses per [...]]]></description>
			<content:encoded><![CDATA[<h3>The ESV Bible REST Web Service</h3>
<p><img style="float:right;padding:.5em;border:1px solid #ddd;" src="/images/esvapi01sm.jpg"/>The <a href="http://www.gnpcb.org/home/esv/">English Standard Version</a> (ESV) of the Bible is a literal word-for-word translation from Crossway Bibles, who have made it available via a <a href="http://www.esvapi.org/">REST web service</a>. There is no charge for non-commercial applications, such as on a personal or church website, though use is limited to 500 verses per query and 5000 queries per day.</p>
<p>The ESV API is a nice rich interface to the Bible. The basic queries include the following:</p>
<ul>
<li><strong>passageQuery</strong> &#8211; takes a verse reference (or range) and returns the text.</li>
<li><strong>query</strong> &#8211; performs a word search or passage lookup on the search criteria and returns the results.</li>
<li><strong>readingPlanQuery</strong> &#8211; given a date, starting date, and reading plan, such as one-year-tract or chronological, this returns the passage(s) for the date.</li>
</ul>
<p>There are a lot of options, result formats, etc. so be sure to visit the <a href="http://www.esvapi.org/api">API page</a> for more details.</p>
<h3>Notes On Making This Work</h3>
<p>Getting the examples below to work presented some challenges or required some work-arounds or otherwise might be an interesting bit.</p>
<p><strong>Cross-site Ajax</strong> requires the use of a proxy. In this case, I&#8217;ve got a PHP proxy using Curl to make the actual web service call to the ESV API. The PHP is something along the lines of the following pseudo code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> geturl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// typical curl get url code</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> request_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">604800</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Cache code, modified from yahoo developer code</span>
	<span style="color: #666666; font-style: italic;">//   http://developer.yahoo.com/php/howto-cacheRestPhp.html</span>
	<span style="color: #666666; font-style: italic;">// Essentially, looks for cached requests and returns them</span>
	<span style="color: #666666; font-style: italic;">//  Otherwise, make the request (then cache it)</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$apikey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;IP&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// use your own ESV API key here</span>
<span style="color: #666666; font-style: italic;">// build $cache_fullpath</span>
<span style="color: #666666; font-style: italic;">// build $v cache file name</span>
<span style="color: #666666; font-style: italic;">// init $options to default</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// find $cmd and build $options key=value string</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.esvapi.org/v2/rest/<span style="color: #006699; font-weight: bold;">$cmd</span>?key=<span style="color: #006699; font-weight: bold;">$apikey</span>&amp;<span style="color: #006699; font-weight: bold;">$options</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$cache_timeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">604800</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// one week, in seconds</span>
<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> request_cache<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cache_fullpath</span> <span style="color: #339933;">.</span>
	<span style="color: #0000ff;">&quot;__&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$v</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cache_timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Request failed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Caching of requests</strong> is also a good idea in this case, and handled by the PHP proxy. This speeds things up a fair bit and reduces load on the ESV API site, but also helps to keep us below the daily request limit of 5000. It&#8217;s probably too short, but I&#8217;m caching these requests for a week. If you&#8217;re interested, I modified some <a href="http://developer.yahoo.com/php/howto-cacheRestPhp.html">code I found at Yahoo&#8217;s developer center</a>. See above for pseudo code integration with PHP proxy.</p>
<p><strong>Embedded link twiddling</strong> is accomplished in the some jQuery Javascript embedded in this post. The ESV API takes a link-url parameter that it uses to build links into the query method results, but since I didn&#8217;t want to go to the trouble in this example of building a full ESV search facility, I&#8217;m pointing the urls back to the ESV site. The code below is part of the success handler for the query .ajax() call. The first line dumps the HTML result into the #esvtext2 div, then the second line executes the inline function for each anchor tag within the results, monkeying with the href.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#esvtext2&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span> data <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#esvtext2 a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #339933;">,</span> link.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;/esv/search/?&quot;</span><span style="color: #339933;">,</span>
		<span style="color: #3366CC;">&quot;http://www.esvapi.org/v2/rest/query?&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
		String.<span style="color: #660066;">fromCharCode</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">38</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;key=IP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Dealing with ampersands in WordPress</strong> was causing severe headaches. Their online support insists that encoding them as &amp; or &#038; makes for perfectly wonderful URLs, but the ESV REST API did not agree and simply hated the resultant URLs I was sending its way. That is, until I used String.fromCharCode(38) to inject them into the URL string (see above).</p>
<p><strong>Styling Scripture</strong> returned from the API was handled with a CSS style element embedded within this post. One of the things I really appreciate about the ESV API is that the results are so richly-styled. Footnotes (.footnote and .footnotes), chapter and verse numbers (.chapter-num and .verse-num), search results (.search-result), and the words of Christ (.woc) and all easily styled into something that looks pretty decent. (Yes, my CSS is a little junky. Any suggestions are welcome.)</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
<span style="color: #cc00cc;">#esvtext1</span><span style="color: #00AA00;">,</span><span style="color: #cc00cc;">#esvtext2</span><span style="color: #00AA00;">,</span><span style="color: #cc00cc;">#esvtext3</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">1em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> <span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Georgia</span><span style="color: #00AA00;">,</span><span style="color: #993333;">serif</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.3em</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> h3 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.1em</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> <span style="color: #6666ff;">.woc</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv-text</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.chapter-num</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.2em</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.verse-num</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span><span style="color: #933;">1.1em</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> <span style="color: #6666ff;">.search-result</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">dashed</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> <span style="color: #6666ff;">.search-result-text-heading</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> <span style="color: #6666ff;">.search-term-1</span><span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#cc9</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> <span style="color: #6666ff;">.footnote</span> a<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>font-<span style="color: #000000; font-weight: bold;">size</span><span style="color: #00AA00;">:</span><span style="color: #933;">.8em</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#777</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.esv</span> <span style="color: #6666ff;">.footnotes</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">.8em</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></div></div>

<p><strong>Scrolling the demos</strong> after the Ajax call was complete involved using the <a href="http://flesler.blogspot.com/2007/10/jqueryscrollto.html">scrollTo jQuery plugin</a> and simply doing a $.scrollTo( &#8220;#demo1&#8243;, 500 ) in the Ajax success handler, after sticking the results in the demo results div. This scrolls the corresponding demo intro to the top of the page. Nice.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">      success<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#esvtext2,#esvtext3&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#esvtext1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span> data <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#demo1&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></pre></div></div>

<p><strong>Cleaning up results</strong> of previous requests is accomplished with an easy jQuery line. In the success handler for each Ajax call, the first thing that happens is setting the results div for each of the other two demos to an empty string. The code above is the Ajax success handler for the first demo.</p>
<style type="text/css">
#esvtext1,#esvtext2,#esvtext3 { border:1px solid #ddd; padding:1em; margin-bottom:1em;}
.esv * { font-family:Georgia,serif;margin:0;padding:0; }
.esv h2 { font-size:1.3em;margin:0;padding:0; }
.esv h3 { font-size:1.1em;margin:0;padding:0; }
.esv .woc { color:red; }
.esv-text { font-size:1em; }
.chapter-num{font-weight:bold;font-size:1.2em;}
.verse-num{font-weight:bold;font-size:1.1em;}
.esv .search-result{border-top:1px dashed #ccc;}
.esv .search-result-text-heading{font-weight:bold;}
.esv .search-term-1{background-color:#ffa;}
.esv .footnote a{ vertical-align:top;font-size:.8em;color:#777; }
.esv .footnotes { font-size:.8em; }
</style>
<h3>Examples</h3>
<p>The examples below are three forms and an empty div. The three forms are bound to some jQuery (of course), which submits Ajax requests to a PHP proxy, then sticks the results in the empty div. For search results, embedded relative links are changed to point to the ESV site.</p>
<div id="demo1">Demo 1: <strong>passageQuery</strong></div>
<p>The sample below simply requests the passage from the ESV REST interface via the PHP proxy and pops the results into the results div. In the absence of specifying otherwise, we get it back in default format (HTML) with default options. The basic format for a passage is <strong>Book Verse:Chapter</strong>, but the API supports multiple passages, such as John 14:1-10,gen 1,is 2.</p>
<form id="esvpqform">
Verse:<br />
<input id="pqverse" name="pqverse" type="text" size="20"/> (ex: John 14:1-10)<br/></p>
<input type="submit"/>
</form>
<p><strong>Results</strong></p>
<div id="esvtext1">
</div>
<div id="demo2">Demo 2: <strong>query</strong></div>
<p>The sample below is similar to the passageQuery except that you can send either a passage or a query word such as Messiah or fisher and get back the results. Paging is supported by the API (though not in this demo), so if the results span multiple pages you can request arbitrary pages as well (page=3, etc.). Other available options include sending your own search URL base for embedded links, number of results per page, and more.</p>
<form id="esvqform">
Search terms:<br />
<input id="qverse" name="qverse" type="text" size="20"/> (ex: John 14:1-10, or samaritan, or dragon)<br/></p>
<input type="submit"/>
</form>
<p><strong>Results</strong></p>
<div id="esvtext2">
</div>
<div id="demo3">Demo 3: <strong>readingPlanQuery</strong></div>
<p>The readingPlanQuery sample simply allows you to select from a few different plans and sends the request. The default date is today, and the default start date is January 1st, so we&#8217;ll just use those.</p>
<form id="esvrpform">
Plan:<br />
<select id="rpplan" name="rpplan" >
<option value="one-year-tract">one-year-tract</option>
<option value="every-day-in-the-word">every-day-in-the-word</option>
<option value="chronological">chronological</option>
<option value="bcp">bcp (book of common prayer)</option>
</select>
<input type="submit"/>
</form>
<p><strong>Results</strong></p>
<div id="esvtext3">
</div>
<p><script>
$(document).ready(function()
{
  $("#esvpqform").submit(function(){
    var verse = $("#pqverse").val();
    var furl = "/code/esvapi.php";
    $.ajax({
      url:furl,
      data:{ passage:verse,
        cmd:"passageQuery"
      },
      dataType:"html",
      success:function(data){
        $("#esvtext2,#esvtext3").html("");
        $("#esvtext1").html( data );
        $.scrollTo( "#demo1", 500 );
      },
      error:function(xhr,err,e){ alert( "Error: " + err ); }
    });
    return false;
  });
  $("#esvqform").submit(function(){
    var verse = $("#qverse").val();
    var furl = "/code/esvapi.php";
    $.ajax({
      url:furl,
      data:{
        q:verse,
        cmd:"query"
      },
      dataType:"html",
      success:function(data){
         $("#esvtext1,#esvtext3").html("");
         $("#esvtext2").html( data );
         $("#esvtext2 a").each( function(){
            var link = $(this).attr("href");
            $(this).attr("href", link.replace("/esv/search/?","http://www.esvapi.org/v2/rest/query?") +
                 String.fromCharCode(38) + "key=IP");
         });
         $.scrollTo( "#demo2", 500 );
      },
      error:function(xhr,err,e){ alert( "Error: " + err ); }
    });
    return false;
  });
  $("#esvrpform").submit(function(){
    var plan = $("#rpplan").val();
    var furl = "/code/esvapi.php";
    $.ajax({
      url:furl,
      data:{ reading_plan:plan,
        cmd:"readingPlanQuery"
      },
      dataType:"html",
      success:function(data){
        $("#esvtext1,#esvtext2").html("");
        $("#esvtext3").html( data );
         $.scrollTo( "#demo3", 500 );
      },
      error:function(xhr,err,e){ alert( "Error: " + err ); }
    });
    return false;
  });
});
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2008/03/07/esv-bible-via-rest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery For Firebug</title>
		<link>http://techrageo.us/2008/03/05/jquery-for-firebug/</link>
		<comments>http://techrageo.us/2008/03/05/jquery-for-firebug/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 01:00:43 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://techrageo.us/2008/03/05/jquery-for-firebug/</guid>
		<description><![CDATA[Load jQuery in a Firebug session. When debugging or poking around in sites where jQuery is not already used, I had been pasting the following code into the multi-line FireBug console and hitting Run. This makes jQuery available for debugging, etc. j=document.createElement&#40;&#34;SCRIPT&#34;&#41;; j.src=&#34;http://code.jquery.com/jquery-latest.pack.js&#34;; document.getElementsByTagName&#40;&#34;HEAD&#34;&#41;&#91;0&#93;.appendChild&#40;j&#41;; If you use Firebug, this is a handy way to make [...]]]></description>
			<content:encoded><![CDATA[<h3>Load jQuery in a Firebug session.</h3>
<p>When debugging or poking around in sites where jQuery is not already used, I had been pasting the following code into the multi-line <a href="http://www.getfirebug.com/">FireBug</a> console and hitting Run. This makes jQuery available for debugging, etc.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">j<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SCRIPT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
j.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://code.jquery.com/jquery-latest.pack.js&quot;</span><span style="color: #339933;">;</span>
document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;HEAD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you use Firebug, this is a handy way to make it even <em>more</em> powerful.</p>
<p><strong>Make it a bookmarklet.</strong></p>
<p>Of course, that whole process got old fast, so I created a bookmarklet to do the same thing, but save me from having to paste and run it in Firebug.</p>
<p>Drag this link: <a href='javascript:void((function(){j=document.createElement("SCRIPT");j.src="http://code.jquery.com/jquery-latest.pack.js";document.getElementsByTagName("HEAD")[0].appendChild(j);})())'>Load jQuery</a> to your Firefox bookmark toolbar, then just click it to inject jQuery into a page.</p>
<p>The bookmarklet code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>j<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SCRIPT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> j.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://code.jquery.com/jquery-latest.pack.js&quot;</span><span style="color: #339933;">;</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;HEAD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>And nicely formatted:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  j<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;SCRIPT&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  j.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://code.jquery.com/jquery-latest.pack.js&quot;</span><span style="color: #339933;">;</span>
  document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;HEAD&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>j<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Then in Firebug, you can use jQuery selectors and so forth to debug the page. Obviously you&#8217;ll have to re-inject each time the page (or a new page) is loaded.</p>
<p><strong>Great, I&#8217;ve reinvented the wheel.</strong></p>
<p>Of course, a bit of searching revealed that John Resig himself posted a bookmarklet called <a href="http://ejohn.org/blog/hacking-digg-with-firebug-and-jquery/">jQuerify</a>&#8211;almost identical to this one&#8211;linked in <a href="http://ajaxian.com/archives/hacking-digg-with-firebug-and-jquery">this Ajaxian article</a>.</p>
<p>The bookmarklet envelopes are different, but both do a simple script injection into the DOM.</p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2008/03/05/jquery-for-firebug/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Conditionally-Colored Flex Charts</title>
		<link>http://techrageo.us/2008/02/20/conditionally-colored-flex-charts/</link>
		<comments>http://techrageo.us/2008/02/20/conditionally-colored-flex-charts/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 00:55:06 +0000</pubDate>
		<dc:creator>grant</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Free]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[chart coloring]]></category>
		<category><![CDATA[conditional coloring]]></category>
		<category><![CDATA[flash graph]]></category>
		<category><![CDATA[Flex Charting]]></category>
		<category><![CDATA[Graphing]]></category>
		<category><![CDATA[Graphs]]></category>

		<guid isPermaLink="false">http://techrageo.us/2008/02/20/conditionally-colored-flex-charts/</guid>
		<description><![CDATA[The charting in Flex is a pretty good tool, but there are a few small features that it would be really nice if it had. One of these would be the ability to have a chart series that changed colors depending on it&#8217;s value. Conditionally colored charts are something that a lot of us (and [...]]]></description>
			<content:encoded><![CDATA[<p>The charting in Flex is a pretty good tool, but there are a few small features that it would be really nice if it had.  One of these would be the ability to have a chart series that changed colors depending on it&#8217;s value.  Conditionally colored charts are something that a lot of us (and our customers) have grown accustomed to and we shouldn&#8217;t have to give it up with Flex.  If you are like me you have probably been &#8220;googling&#8221; every variation of &#8220;flex colored charts&#8221; that you can think of.  I couldn&#8217;t find an answer anywhere, but hopefully your search will end right here.</p>
<p>I wanted the ability to color charts based on their value, giving them red/yellow/green colors based on if they were lower/equal to/higher than a given value.  The ability to use gradients instead of solid colors was also a requirement.  I basically wanted to do something like this:</p>
<div style="width: 490px">
<object width="490" height="490" codebase="http://active.macromedia.com/flash7/cabs/ swflash.cab#version=9,0,0,0"><param name="src" value="http://www.techrageo.us/code/ColorColumnChart.swf"><param name="quality" value="high"><embed src="http://www.techrageo.us/code/ColorColumnChart.swf" width="490" height="490" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>
</div>
<p>The columns below the line are red, on the line are yellow, and above the line are green.  The need might arise to do more colors than this, so the code should be flexible</p>
<p>But almost as important as the final look of the graph itself was the ability to re-use the code without having to rewrite parts of it for each implementation.  And I wanted to be able to use it in a flex application using only mxml, but still be able to use it in ActionScript if needed.</p>
<p>In the end I wanted to be able to define the threshold or goal as part of the data that the graph used and the code would color the columns based on that data (if it was greater than/less than/equal to). So the code to use the &#8220;coloring object&#8221; would look something like this (where we define High/Mid/Low colors):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:ColumnSeries</span> <span style="color: #000066;">xField</span>=<span style="color: #ff0000;">&quot;Month&quot;</span> <span style="color: #000066;">yField</span>=<span style="color: #ff0000;">&quot;Income&quot;</span> <span style="color: #000066;">displayName</span>=<span style="color: #ff0000;">&quot;Income2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:itemRenderer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;utils:ColoredSeriesItemRenderer</span> <span style="color: #000066;">valueField</span>=<span style="color: #ff0000;">&quot;Income&quot;</span> <span style="color: #000066;">thresholdField</span>=<span style="color: #ff0000;">&quot;Goal&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;utils:thresholdGradients<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:High<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;mx:Object</span> <span style="color: #000066;">gradient</span>=<span style="color: #ff0000;">&quot;[0x55dd55,0x005500]&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/mx:High<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Mid<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;mx:Object</span> <span style="color: #000066;">gradient</span>=<span style="color: #ff0000;">&quot;[0xdddd55,0x555500]&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/mx:Mid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Low<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;mx:Object</span> <span style="color: #000066;">gradient</span>=<span style="color: #ff0000;">&quot;[0xdd5555,0x550000]&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/mx:Low<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/utils:thresholdGradients<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/utils:ColoredSeriesItemRenderer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:itemRenderer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:ColumnSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:LineSeries</span> <span style="color: #000066;">xField</span>=<span style="color: #ff0000;">&quot;Month&quot;</span> <span style="color: #000066;">yField</span>=<span style="color: #ff0000;">&quot;Goal&quot;</span> <span style="color: #000066;">displayName</span>=<span style="color: #ff0000;">&quot;Goal&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>But to be flexible I also wanted to be able to define the goal in the code, where I could give it as many ranges with associated colors as I wanted.  This code would look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:ColumnSeries</span>  <span style="color: #000066;">xField</span>=<span style="color: #ff0000;">&quot;Month&quot;</span> <span style="color: #000066;">yField</span>=<span style="color: #ff0000;">&quot;Income&quot;</span> <span style="color: #000066;">displayName</span>=<span style="color: #ff0000;">&quot;Income1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:itemRenderer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;utils:ColoredSeriesItemRenderer</span> <span style="color: #000066;">valueField</span>=<span style="color: #ff0000;">&quot;Income&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;utils:ranges<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Object</span> <span style="color: #000066;">lowerLimit</span>=<span style="color: #ff0000;">&quot;280&quot;</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;0xFF0000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Object</span> <span style="color: #000066;">lowerLimit</span>=<span style="color: #ff0000;">&quot;240&quot;</span> <span style="color: #000066;">upperLimit</span>=<span style="color: #ff0000;">&quot;280&quot;</span> <span style="color: #000066;">gradient</span>=<span style="color: #ff0000;">&quot;[0xFFFF00,0x55FF55]&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Object</span> <span style="color: #000066;">lowerLimit</span>=<span style="color: #ff0000;">&quot;220&quot;</span> <span style="color: #000066;">upperLimit</span>=<span style="color: #ff0000;">&quot;240&quot;</span> <span style="color: #000066;">gradient</span>=<span style="color: #ff0000;">&quot;[0x5555FF,0x000099]&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Object</span> <span style="color: #000066;">lowerLimit</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">upperLimit</span>=<span style="color: #ff0000;">&quot;220&quot;</span> <span style="color: #000066;">gradient</span>=<span style="color: #ff0000;">&quot;[0x0000FF,0x00FF00,0xFF0000]&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Object</span> <span style="color: #000066;">upperLimit</span>=<span style="color: #ff0000;">&quot;200&quot;</span> <span style="color: #000066;">color</span>=<span style="color: #ff0000;">&quot;0xFFFF00&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/utils:ranges<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/utils:ColoredSeriesItemRenderer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Component<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:itemRenderer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:ColumnSeries<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Creating a custom item renderer allowed me (and now you too) to change the colors of the columns as they were being created.  This works so much better than other solutions I saw (laying a filter on top of the columns) because it automatically changes when the column changes.</p>
<p>I created a new object out of it so you can just drop it in the directory where you keep your other library files (and change the package name if needed) and start using it.  I have included it along with some sample files in a handy zip file for you&#8230; <img src='http://techrageo.us/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I hope this saves you all the time it could have saved me (if I would have found something similar).</p>
<p>Download the <a href="http://techrageo.us/code/ColumnColorChartSource.zip">ColoredSeriesItemRenderer.as object</a> with two full examples that you can compile and try in a handy zip file.</p>
<p><em>If you are not familiar with including custom made objects into an mxml file then you&#8217;ll need to know about packages.  In the sample code I used a package name of &#8220;utils&#8221;, which means that the actionscript object is defined with an &#8220;utils&#8221; package declaration and is in an &#8220;utils&#8221; subdirectory.  Also, the example files will require you to define the xml namespace in the Application tag.  This is done by adding something like this: <strong>xmlns:utils=&#8221;utils.*&#8221;</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2008/02/20/conditionally-colored-flex-charts/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Show Password Fields</title>
		<link>http://techrageo.us/2007/11/21/show-password-fields/</link>
		<comments>http://techrageo.us/2007/11/21/show-password-fields/#comments</comments>
		<pubDate>Wed, 21 Nov 2007 04:48:52 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Bookmarklets]]></category>

		<guid isPermaLink="false">http://techrageo.us/2007/11/21/show-password-fields/</guid>
		<description><![CDATA[A simple Javascript bookmarklet shows password field values. In form fields where a password is entered, it is usually obscured by asterisks or bullets to prevent someone from seeing what you type. This is a great feature but where a long password is being typed or a remembered password is filled in by the browser, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>A simple Javascript bookmarklet shows password field values.</strong></p>
<p>In form fields where a password is entered, it is usually obscured by asterisks or bullets to prevent someone from seeing what you type. This is a great feature but where a long password is being typed or a remembered password is filled in by the browser, you might want to actually see the actual password itself.</p>
<h3>Show Password Bookmarklet</h3>
<p>Here is a bookmarklet (a snippet of Javascript that can be pasted into the address bar of your web browser), that will show any passwords on a page that contain password form fields.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #003366; font-weight: bold;">var</span> s<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span> F<span style="color: #339933;">=</span>document.<span style="color: #660066;">forms</span><span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>f<span style="color: #339933;">,</span>i<span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>f.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>j<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> f <span style="color: #339933;">=</span> F<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span> f.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">type</span> <span style="color: #339933;">&amp;&amp;</span> f<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">type</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span> s <span style="color: #339933;">+=</span> f<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Password fields:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;No password fields on this page.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Just paste the above javascript into the address bar of your browser and press Enter, or create a bookmarklet link with the javascript as the URL. On this page you&#8217;ll see the password for the mock sign on form below.</p>
<table style="margin-bottom:20px;">
<form action="javascript:return false;">
<tr>
<td>User Name:</td>
<td>
<input type="text" value="myusername"/></td>
</tr>
<tr>
<td>Password:</td>
<td>
<input type="password" value="topsecret"/></td>
</tr>
</form>
</table>
<p><strong>This is nothing new.</strong></p>
<p>This or similar javascript has been around for a while. This particular one was on <a href="http://www.raymond.cc/blog/archives/2007/07/13/easily-show-the-contents-of-password-fields/">raymond.cc</a> (via <a href="http://www.fortysomething.ca/mt/etc/archives/007062.php">etc.</a>), but it needed to be fixed for some forms where fields have a null type property (an example is the sign on form for <a href="http://LinkedIn.com">LinkedIn</a>). The fix was adding <tt>f[i].type &#038;&#038;</tt> to the if statement inside the inner for loop.</p>
<h3>Formatted Javascript Code</h3>
<p>If you&#8217;re interested in what is happening to make this work the formatted code is below.</p>
<p>Essentially, the variable F is set to the collection of forms on the page, which is looped through, examining every input field in each form testing if it&#8217;s of type &#8220;password.&#8221; If it is a &#8220;password&#8221; field, its value is appended to the string variable s. Once all the input fields in all the forms on the page have been sniffed, the string value is displayed in an alert.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> s<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span> F<span style="color: #339933;">=</span>document.<span style="color: #660066;">forms</span><span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>f<span style="color: #339933;">,</span>i<span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> j<span style="color: #339933;">&lt;</span>f.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>j<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     f <span style="color: #339933;">=</span> F<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span> f.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>f<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">type</span> <span style="color: #339933;">&amp;&amp;</span> f<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">type</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;password&quot;</span><span style="color: #009900;">&#41;</span>
         s <span style="color: #339933;">+=</span> f<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span>
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Password fields:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;">+</span> s<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">else</span>
     <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;No password fields on this page.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>But Firefox already&#8230;</strong></p>
<p>And yes, we know Firefox will show you passwords in the clear with Tools/Options/Security/Show Passwords.</p>
<p>This javascript, however, is easier to access if you have created a bookmarklet for it, plus it works in other browsers.</p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2007/11/21/show-password-fields/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>jQuery 1.2</title>
		<link>http://techrageo.us/2007/10/04/jquery-12/</link>
		<comments>http://techrageo.us/2007/10/04/jquery-12/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 09:32:35 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://techrageo.us/2007/10/04/jquery-12/</guid>
		<description><![CDATA[Major Updates To jQuery John Resig and the jQuery team have been busy releasing jQuery 1.2 and a bugfix version 1.2.1. jQuery Version 1.2 Version 1.2 is a major update to the popular Javascript library. Many new features were added and a few were removed, so updating existing code may be required to use the [...]]]></description>
			<content:encoded><![CDATA[<h3>Major Updates To jQuery</h3>
<p>John Resig and the jQuery team have been busy releasing jQuery 1.2 and a bugfix  version 1.2.1.</p>
<h3>jQuery Version 1.2</h3>
<p>Version 1.2 is a major update to the popular Javascript library. Many new features were added and a few were removed, so updating existing code may be required to use the new release.</p>
<p><strong>Features Removed</strong></p>
<p>The jQuery team tries to keep the library as small as possible. Unfortunately that means some things have been deprecated or moved into plugins.</p>
<p>A backwards compatibility plugin is available to assist or delay any changes needed to use the new version.</p>
<p>Several XPath selector features were removed, including Descendant (ex. $(&#8220;div//p&#8221;) ), Child (ex. $(&#8220;div/p&#8221;) ), Parent (ex. $(&#8220;p/../div&#8221;) ), Contains Predicate (ex. $(&#8220;div[p]&#8220;) ), and Attribute (ex. $(&#8220;a[@href]&#8220;) ). It is recommended that instead of these selectors, the corresponding CSS or other selectors be used. Or use the <a href="http://jquery.com/plugins/project/xpath">XPath Compatibility Plugin</a>.</p>
<p>The parametized clone() method (ex. $(&#8220;div&#8221;).clone(false) ) has been deprecated. .clone() is still supported, but instead of using the false argument, use .clone().empty() instead.</p>
<p>DOM Traversal methods .eq(), .lt(), .gt(), and .contains() have been deprecated in favor of using .slice() and .filter(). <strong>Note that 1.2.1 brings back .eq().</strong></p>
<p>The Ajax methods .loadIfModifed() and .getIfModifed() are deprecated. You should use the $.ajax() method with the &#8220;ifModified:true&#8221; option instead. Also, $.ajaxTimeout is now deprecated in favor of $.ajaxSetup(). .evalScripts() has been removed as it is no longer necessary; all scripts in HTML strings are automatically evaluated when injected into the document.</p>
<p><strong>Features Added</strong></p>
<p>Now for the good stuff.</p>
<p>Besides the new XPath Compatibility Plugin mentioned above, the core now supports :has(selector), :header, and :animated.</p>
<p>New DOM traversal methods include .map(), .prevAll() and .nextAll(), .slice(), .hasClass(), .andSelf(), and .contents().</p>
<p>New DOM manipulation methods include .wrapInner() and .wrapAll(), .replaceWith() and .replaceAll(), and .clone(true) Event Cloning.</p>
<p>New .offset(), .height() and .width() CSS methods were added.</p>
<p>Ajax support was improved with support for partial .load(), Cross-Domain getScript(), JSONP, and disabling caching. Also .serialize() has been reworked.</p>
<p>New effects features support .stop(), % and em animations, color animations, relative animations, queue control, the :animated selector, and custom animation types with the step Function.</p>
<p>Namespaced Events and .triggerHandler() are also new.</p>
<p><strong>jQuery.UI</strong></p>
<p><a href="http://ui.jquery.com/">jQuery now has its own UI</a>, including draggables, droppables, resizables, shadows, sliders, sortables, tabs, accordians, selectables, trees, and modals.</p>
<p>Well, it has a few bugs, but it really is nice. And, of course, they&#8217;re hard at work squashing the bugs as fast as possible.</p>
<h3>jQuery Version 1.2.1</h3>
<p>A bugfix release on September 16th <a href="http://dev.jquery.com/report/17">fixes some bugs</a> and adjusts the API in two places.</p>
<p>Due to overwhelming demand, .eq() has returned in version 1.2.1. Also, a problem with the relative animation API has been fixed.</p>
<h3>Excellent Upgrade</h3>
<p>This is a major step forward for jQuery. The loss of XPath and a few features in the core is a slightly bitter pill, but plugins help with this. The additional features are great, and the new UI library is welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2007/10/04/jquery-12/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery 1.1.4 Released</title>
		<link>http://techrageo.us/2007/08/25/jquery-114-released/</link>
		<comments>http://techrageo.us/2007/08/25/jquery-114-released/#comments</comments>
		<pubDate>Sat, 25 Aug 2007 18:37:01 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://techrageo.us/2007/08/25/jquery-114-released/</guid>
		<description><![CDATA[John Resig and the jQuery team have released jQuery 1.1.4. This release addresses bugs, improves performance, adds some functionality, and deprecates some functionality in anticipation of changes upcoming in jQuery version 1.2. Both standard and packed .js files are available at code.jquery.com. jQuery Bugfixes This latest release addresses 53 problem tickets (including those fixed in [...]]]></description>
			<content:encoded><![CDATA[<p>John Resig and the jQuery team have <a href="http://jquery.com/blog/2007/08/24/jquery-114-faster-more-tests-ready-for-12/">released jQuery 1.1.4</a>.</p>
<p>This release addresses bugs, improves performance, adds some functionality, and deprecates some functionality in anticipation of changes upcoming in jQuery version 1.2.</p>
<p>Both <a href="http://code.jquery.com/jquery-1.1.4.js">standard</a> and <a href="http://code.jquery.com/jquery-1.1.4.pack.js">packed</a> .js files are available at code.jquery.com.</p>
<h3>jQuery Bugfixes</h3>
<p>This latest release addresses 53 problem tickets (including those fixed in the 1.1.3.1 emergency release), improving computed styles in Safari, HTML script evaluation, and Ajax settings issues.</p>
<h3>jQuery Library Improvements</h3>
<p>Besides bugfixes, you can now rename jQuery. This allows multiple instances of jQuery to be included, side-by-side. Further, it allows you to use jQuery within the namespace of another library, such as the Yahoo! UI toolkit.</p>
<p>The new release also includes speed improvements over version 1.1.3 in id and element selectors, and with each() operations.</p>
<h3>jQuery New Features</h3>
<p>jQuery version 1.1.4 introduces some new functionality as well.</p>
<p>.slice() allows you to grab a &#8220;slice&#8221; of a selector result vector, and operates like the Javascript array slice method.</p>
<p>:has() allows you to further qualify a selector, as in $(&#8220;a:has(img)&#8221;) to select all anchors that contain an image element.</p>
<p>Deep .extend() allows objects to be merged without overwriting internal objects.</p>
<h3>Deprecations</h3>
<p>In preparation for jQuery 1.2, some items are deprecated in version 1.1.4.</p>
<p>Some XPath selectors are being dropped. An XPath plugin is being introduced with 1.2, and in the meantime CSS selector formats must suffice. For example, instead of using the XPath child selector $(&#8220;div/p&#8221;), you now use the CSS selector $(&#8220;div > p&#8221;).</p>
<p>The parameterized .clone() method is now deprecated.</p>
<p>DOM traversal methods .eq(), .lt(), and .gt() are deprecated, replaced by the new .slice() method.</p>
<p>Ajax methods .loadIfmodified() and .getIfModified() are deprecated and replaced by the long form .ajax() method. .ajaxTimeout() is deprecated as the long-form .ajaxSetup() will suffice. .evalScripts() is no longer needed since all scripts are evaluated are now automatically evaluated upon injection.</p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2007/08/25/jquery-114-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Makes Ajax Easy, Part 1</title>
		<link>http://techrageo.us/2007/08/03/jquery-makes-ajax-easy-part-1/</link>
		<comments>http://techrageo.us/2007/08/03/jquery-makes-ajax-easy-part-1/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 04:35:36 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://techrageo.us/2007/08/03/jquery-makes-ajax-easy-part-1/</guid>
		<description><![CDATA[jQuery Ajax jQuery, John Resig&#8217;s Javascript library, makes Ajax easy for beginners and professionals alike. This article dives into using the various jQuery Ajax methods. Ajax Basics Asynchronous JavaScript and XML, or Ajax, has become a catch-all term for client-initiated communications with a server. Specifically, Ajax usually refers to requests sent from a web browser [...]]]></description>
			<content:encoded><![CDATA[<h3>jQuery Ajax</h3>
<p><a href="http://jquery.com"><br />
jQuery</a>, John Resig&#8217;s Javascript library, makes Ajax easy for beginners and professionals alike. This article dives into using the various jQuery Ajax methods.</p>
<h3>Ajax Basics</h3>
<p><a href="http://en.wikipedia.org/wiki/Ajax_(programming)">Asynchronous JavaScript and XML</a>, or <strong>Ajax</strong>, has become a catch-all term for client-initiated communications with a server. Specifically, Ajax usually refers to requests sent from a web browser to a server. It is even used to refer to non-XML communications, such as <a href="http://microformats.org/wiki/rest/ahah">Asynchronous HTML and HTTP</a> &#8212; <strong>AHAH</strong>. The rationale being that the first H in AHAH really means XHTML. I think someone just wanted another clever-sounding acronym; it really should be AJAH since it still uses Javascript. But I digress.</p>
<p>Simply put, Ajax allows you to execute a POST or GET request from the browser back to your server to fetch data, save data, execute a method, or what have you, without requiring a refresh of the web page.</p>
<h3>jQuery Ajax Methods</h3>
<p>jQuery provides several methods to assist with Ajax programming: load, get, post, and ajax.</p>
<p><strong>load()</strong> takes a url, parameters, and a callback function. It executes a GET request of the URL and inserts the returned data into the DOM at a location you select. The parameters and callback function are optional. A typical usage would be something like <tt>$("address").load( url, {name:"John",id:"100"}, function(){ alert("Ajax call complete.");})</tt>.</p>
<p><strong>get()</strong> takes a url, parameters, and a callback function. It executes a GET request of the URL and returns the XMLHttpRequest. The parameters and callback function are optional. A typical usage would be something like <tt>$.get( url, {name:"John",id:"100"}, function(data){ $("address").html( data ); alert("Ajax call complete.");})</tt>.</p>
<p><strong>post()</strong> takes a url, parameters, and a callback function. It sends a POST request to the URL and returns the XMLHttpRequest. The parameters and callback function are optional. A typical usage would be something like <tt>$.post( url, {name:"John",id:"100"}, function(data){ $("address").html( data ); alert("Ajax call complete.");})</tt>.</p>
<p><strong>ajax()</strong> takes a set of request properties specified in key-value pairs. It sends the specified request and returns the XMLHttpRequest. The ajax() method is complex but offers much more control over the request than any of the other methods. A typical usage would be something like <tt>$.ajax({ type:"GET", url:url, datatype:"html", data:{name:"John",id:"100"}, complete:function( data ) { $("address").html( data ); alert( "Ajax call complete.")}})</tt>.</p>
<h3>Get Data From A URL</h3>
<p>This example is taken from the <a title="Introduction To jQuery Programming" href="http://techrageo.us/2007/07/05/jquery-introduction/">jQuery Introduction</a> posted here about a month ago. Technically, this is AJAH, since we&#8217;re not fetching XML, but the technique is the same.</p>
<p><strong>We need a proxy to fetch data from another domain.</strong></p>
<p>In the diagram below, you can see that the web page in your browser needs to fetch from the same domain from which it was loaded, in this case techrageo.us. From there it can go anywhere. In this example we&#8217;re fetching from Yahoo.com.</p>
<p><img alt="Ajax needs a URL proxy" src="/images/ajax.gif"/></p>
<p>Ajax is usually limited to connections back to the same domain from which the web page was loaded. To fetch data from another domain, such as from the Yahoo quote server, we need to create a simple URL proxy. The PHP code is below. Basically it takes a URL, fetches it with curl, and returns the output.</p>
<p>Note: due to server restrictions, the curl_exec string below had to be tweaked to get it into this article. Just remove the spaces and you&#8217;re good to go.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// don't cache this page</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Cache-Control: no-cache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> geturl<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span> <span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// make this curl_exec, no spaces</span>
  <span style="color: #000088;">$results</span> <span style="color: #339933;">=</span> c u r l _ e x e c <span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$results</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// get the specified url from the querystring</span>
<span style="color: #000088;">$theurl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// decode it</span>
<span style="color: #000088;">$theurl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$theurl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// decode forgets the ampersand</span>
<span style="color: #000088;">$theurl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;&amp;#038;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&amp;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$theurl</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// fetch the url</span>
<span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> geturl<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$theurl</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// spit out the results</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$v</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Enter a stock ticker symbol, such as IBM or SBUX, and click Submit. When you do the span with id=&#8221;lasttrade&#8221; is loaded with data returned from geturl.php?http://finance.yahoo.com/d/quotes.csv?f=l1&#038;s=IBM (assuming you entered IBM).</p>
<p><em>Update: Yahoo has changed their quote URLs to something like this http://download.finance.yahoo.com/d/quotes.csv?f=l1&#038;s=IBM </em></p>
<form id="stockform">
Ticker Symbol:<br />
<input id="sym" name="sym" type="text" size="10"/>
<input type="submit"/></form>
<p>Last Trade: <span id="lasttrade"></span></p>
<p><strong>We&#8217;re using .load() for this simple example.</strong></p>
<p>The jQuery code is below. As you can see an anonymous function is attached to the submit handler of the form with an id of stockform. The function gets the value of the input field with an id of sym, then appends it to the URL of the Yahoo csv quote server with format specified to return the last trade price. That URL is then escaped and appended to geturl.php?url=, which is a simple PHP proxy that resides here at <a href="http://techrageo.us">techrageo.us</a>. The submit handler function then returns false to prevent the browser from trying to continue submitting the form.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// wait till the DOM is loaded</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// attach a submit handler to the form</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form#stockform&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// get the ticker symbol and build URL</span>
    <span style="color: #003366; font-weight: bold;">var</span> sym <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#sym&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> yurl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://download.finance.yahoo.com/d/quotes.csv?f=l1&amp;s=&quot;</span><span style="color: #339933;">+</span>sym<span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">//old: &quot;http://finance.yahoo.com/d/quotes.csv?f=l1&amp;s=&quot;+sym;</span>
    <span style="color: #003366; font-weight: bold;">var</span> furl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;geturl.php&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// load last trade price from Yahoo and</span>
    <span style="color: #006600; font-style: italic;">// stick it in the #lasttrade span</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;span#lasttrade&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span> furl<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span>escape<span style="color: #009900;">&#40;</span>yurl<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Now let&#8217;s modify the example to use $.get().</strong></p>
<p>jQuery&#8217;s $.get() method can be used to send a GET request. For example, the example above can be written as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// wait till the DOM is loaded</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// attach a submit handler to the form</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form#stockform&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// get the ticker symbol and build URL</span>
    <span style="color: #003366; font-weight: bold;">var</span> sym <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#sym&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> yurl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://download.finance.yahoo.com/d/quotes.csv?f=l1&amp;s=&quot;</span><span style="color: #339933;">+</span>sym<span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">//old: &quot;http://finance.yahoo.com/d/quotes.csv?f=l1&amp;s=&quot;+sym;</span>
    <span style="color: #003366; font-weight: bold;">var</span> furl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;/code/geturl.php&quot;</span><span style="color: #339933;">;</span>
    $.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span> furl<span style="color: #339933;">,</span>
      <span style="color: #009900;">&#123;</span>url<span style="color: #339933;">:</span>escape<span style="color: #009900;">&#40;</span>yurl<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;span#lasttrade&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span> data <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>Now let&#8217;s modify the example to use $.ajax() for more control.</strong></p>
<p>jQuery&#8217;s $.ajax() method can also be used to send a GET request. For example, the example above can be written as follows.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// wait till the DOM is loaded</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// attach a submit handler to the form</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form#stockform&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// get the ticker symbol and build URL</span>
    <span style="color: #003366; font-weight: bold;">var</span> sym <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#sym&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> yurl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://download.finance.yahoo.com/d/quotes.csv?f=l1&amp;s=&quot;</span><span style="color: #339933;">+</span>sym<span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">//old: &quot;http://finance.yahoo.com/d/quotes.csv?f=l1&amp;s=&quot;+sym;</span>
    <span style="color: #003366; font-weight: bold;">var</span> furl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;/code/geturl.php&quot;</span><span style="color: #339933;">;</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
      url<span style="color: #339933;">:</span>furl<span style="color: #339933;">,</span>
      data<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span> url<span style="color: #339933;">:</span>escape<span style="color: #009900;">&#40;</span>yurl<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      dataType<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;html&quot;</span><span style="color: #339933;">,</span>
      success<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;span#lasttrade&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span> data <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      error<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>xhr<span style="color: #339933;">,</span>err<span style="color: #339933;">,</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;Error: &quot;</span> <span style="color: #339933;">+</span> err <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// $.ajax()</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// .submit()</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In part 2 we&#8217;ll look at POST requests and other dataTypes.</p>
<p><script>
$(document).ready(function()
{
//  $("form#stockform").submit(function(){
//    var sym = $("input#sym").val();
//    var yurl = "http://finance.yahoo.com/d/quotes.csv?f=l1&#038;s="+sym;
//    var furl = "http://techrageo.us/code/geturl.php?url=" + escape(yurl);
//    $("span#lasttrade").load( furl );
//    return false;
//  });
//  $("form#stockform").submit(function(){
//    var sym = $("input#sym").val();
//    var yurl = "http://finance.yahoo.com/d/quotes.csv?f=l1&#038;s="+sym;
//    var furl = "/code/geturl.php";
//    $.get( furl,
//      {url:escape(yurl)},
//      function(data){
//        $("span#lasttrade").html( data );
//      });
//    return false;
//  });
  $("form#stockform").submit(function(){
    // get the ticker symbol and build URL
    var sym = $("input#sym").val();
    var yurl = "http://download.finance.yahoo.com/d/quotes.csv?f=l1&#038;s="+sym;
        //old: "http://finance.yahoo.com/d/quotes.csv?f=l1&#038;s="+sym;
    var furl = "/code/geturl.php";
    $.ajax({
      url:furl,
      data:{ url:escape(yurl) },
      dataType:"html",
      success:function(data){ $("span#lasttrade").html( data );},
      error:function(xhr,err,e){ alert( "Error: " + err ); }
    }); // $.ajax()
    return false;
  }); // .submit()
});
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2007/08/03/jquery-makes-ajax-easy-part-1/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>jQuery Introduction</title>
		<link>http://techrageo.us/2007/07/05/jquery-introduction/</link>
		<comments>http://techrageo.us/2007/07/05/jquery-introduction/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 10:32:58 +0000</pubDate>
		<dc:creator>bill</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://techrageo.us/2007/07/05/jquery-introduction/</guid>
		<description><![CDATA[Javascript Frameworks Abound Do we really need another Javascript framework? There&#8217;s the Dojo Toolkit. It&#8217;s mature and includes the kitchen sink. Then there&#8217;s Prototype. It&#8217;s wildly popular and several popular UI layers are built on top of it, including script.aculo.us, Rico, and others. Of course, you can&#8217;t leave out mootools. It&#8217;s UI library, moo.fx, can [...]]]></description>
			<content:encoded><![CDATA[<div id="jqueryintro">
<h3>Javascript Frameworks Abound</h3>
<p><strong>Do we really need another Javascript framework?</strong></p>
<p>There&#8217;s the <a href="http://dojotoolkit.org/">Dojo Toolkit</a>. It&#8217;s mature and includes the kitchen sink. Then there&#8217;s <a href="http://www.prototypejs.org/">Prototype</a>. It&#8217;s wildly popular and several popular UI layers are built on top of it, including <a href="http://script.aculo.us/">script.aculo.us</a>, <a href="http://openrico.org/">Rico</a>, and others. Of course, you can&#8217;t leave out <a href="http://mootools.net/">mootools</a>. It&#8217;s UI library, <a href="http://moofx.mad4milk.net/">moo.fx</a>, can also sit on top of Prototype if you so desire. There&#8217;s <a href="http://developer.yahoo.com/yui/">Y!UI, the Yahoo! User Interface library</a>. And we&#8217;ve got <a href="http://extjs.com/">ExtJs</a>, a robust interface framework that can leverage Y!UI, Prototype, or jQuery.</p>
<h3>jQuery</h3>
<p>Which brings us to&#8230; <a href="http://jquery.com">jQuery</a>. Yep, it is yet another Javascript framework (YAJF). jQuery, though, is arguably the fastest and the most elegant of the lot. It supports CSS3, browser detection, method chaining, plugins, Ajax (gotta have that to be cool), flexible selectors, and basic UI effects. All in under 20K.</p>
<h4>Simple July 4th jQuery Demo</h4>
<p>Okay, so by way of introduction, here&#8217;s a simple little jQuery demonstration.</p>
<p><a id="redwhiteblue" href="#">Click this link to turn this article red white and blue and get the lyrics to &#8220;God Bless America,&#8221; then click again to return to normal.</a></p>
<p class="Godblessamerica" style="display:none;border:2px solid #aaa;padding:1em;">
God Bless America,<br />
Land that I love.<br />
Stand beside her, and guide her<br />
Thru the night with a light from above.<br />
From the mountains, to the prairies,<br />
To the oceans, white with foam<br />
God bless America, My home sweet home.
</p>
<p>The code is below, and is doing this: to the anchor tag (&#8220;a&#8221;) with an id of &#8220;redwhiteblue&#8221;, toggle between two functions on each click event; the first function loops through all the paragraph elements within divs of class &#8220;entry&#8221; and assigns a css color style based on the index mod 3 (iteratively assign from an array of red, white, and blue); the second function simply assigns a css color style of black to all paragraphs within divs of class &#8220;entry&#8221;; both functions return false to short-circuit the link.</p>
<p><em><strong>Update:</strong> The commented section below is replaced by the three lines that follow it, suggested by jQuery&#8217;s creator, John Resig (thanks, John). What I was doing with a clumsy <code>for</code> loop, iterating through each paragraph I selected with a cobbled-together XPath, is better done with the <code>each</code> method, applying a simple function along the selected vector. It goes to show just how slick the library really is.</em></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">var</span> rwb<span style="color: #339933;">=</span>Array<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#f00&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;#aaa&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;#00f&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a#redwhiteblue&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p.Godblessamerica&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//    for(i=0;i&lt;$(&quot;div#jqueryintro p&quot;).length;i++){</span>
<span style="color: #006600; font-style: italic;">//      $(&quot;div#jqueryintro p:nth(&quot; + i + &quot;)&quot;).css({color:rwb[i % 3]});</span>
<span style="color: #006600; font-style: italic;">//    } return false;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div#jqueryintro p&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span>rwb<span style="color: #009900;">&#91;</span>i <span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p.Godblessamerica&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div#jqueryintro p&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#000&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>More jQuery Demos</h3>
<p>Here are a few other little demos I fiddled up along the way.</p>
<h4>Toggle Red Demo</h4>
<p><a class="togglered" href="#">Click this link to toggle the following paragraph between black and red text.</a></p>
<p class="redtarget">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis adipiscing purus eu elit. Quisque feugiat malesuada lectus. Suspendisse potenti. Donec viverra, nisi et lobortis sollicitudin, erat quam condimentum sapien, at volutpat ipsum neque tristique lorem.
</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a.togglered&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p.redtarget&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#AA0000&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p.redtarget&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>color<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;#000&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h4>Toggle Visibility</h4>
<p>Okay <a class="intro" href="#">click this link</a> to reveal a DIV with some text. Then, click again to re-hide the text.</p>
<div class="introtarget" style="display:none;background-color:#eee;color:#37a;padding:.8em;margin-bottom:1em;border:1px solid #777;">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis adipiscing purus eu elit. Quisque feugiat malesuada lectus. Suspendisse potenti. Donec viverra, nisi et lobortis sollicitudin, erat quam condimentum sapien, at volutpat ipsum neque tristique lorem.
</div>
<p>That&#8217;s a toggle tacked onto the DIV. Here&#8217;s the code to make that happen.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a.intro&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div.introtarget&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>return <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Translated into English, that means &#8220;select <code>A</code> tags of class <code>intro</code>, then handle click events by executing a function that finds divs of class introtarget and attach a toggle of speed 100 to them; then return false.&#8221;</p>
<h4>Get Stock Quote With Ajax</h4>
<p>Of course, jQuery supports Ajax. Here&#8217;s a simple demo that calls a PHP file that merely takes the URL passed in, fetches it, then echos the results.</p>
<p>The jQuery Javascript code takes the output (in this case just a number), and sticks it into the lasttrade span.</p>
<form id="stockform">Ticker Symbol:<br />
<input id="sym" name="sym" type="text" size="10"/>
<input type="submit"/></form>
<p>Last Trade: <span id="lasttrade"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;form#stockform&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> sym <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input#sym&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> yurl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://finance.yahoo.com/d/quotes.csv?&quot;</span> <span style="color: #339933;">+</span>
       <span style="color: #3366CC;">&quot;f=l1&amp;s=&quot;</span><span style="color: #339933;">+</span>sym<span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> furl <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;geturl.php?url=&quot;</span> <span style="color: #339933;">+</span> escape<span style="color: #009900;">&#40;</span>yurl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;span#lasttrade&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span> furl <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Shortest jQuery Tutorial Ever</h3>
<p>Hey! Learn jQuery now. Here&#8217;s what you do to get your feet wet with jQuery.</p>
<ol>
<li>Start with a basic HTML file.

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Here is <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clickme&quot;</span>&gt;</span>a link<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lorem&quot;</span>&gt;</span>Lorem ipsum dolor sit amet,
    consectetuer adipiscing elit.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>This text is here to stay.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lorem&quot;</span>&gt;</span>Phasellus luctus. Suspendisse nisi
  	neque, feugiat eget, ullamcorper at, feugiat ut,
  	tellus.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

</li>
<li>Link in the jQuery library. You can do this by referencing the code at code.jquery.com or by downloading jquery.js and linking to it.
<p>Below I&#8217;m linking to the packed version of jQuery 1.1.3.1 (the latest at the time of this update).</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://code.jquery.com/jquery-1.1.3.1.pack.js&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span></pre></div></div>

</li>
<li>Add the standard jQuery document ready state handler function. This is a pattern used for most jQuery work, wherein your jQuery code resides.

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// your code here</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

</li>
<li>Flesh it out with some jQuery scripting. See above for examples; the code snippets in the examples can be dropped into the ready function, provided you add the proper elements to the HTML as well.

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a#clickme&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;p.lorem&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>return <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

</li>
</ol>
<h3>Update and Wrapping Up</h3>
<p>Since publishing this article I&#8217;ve made a few updates. First was to incorporate John Resig&#8217;s suggestion for the July 4th demo. Using <code>each</code> had crossed my mind but I was looking at it wrong and ended up patching an XPath together to get what I wanted.</p>
<p>The second update was to add some additional comments to the <strong>Shortest jQuery Tutorial Ever</strong> section.</p>
<p>And last, I incorporated <a href="http://jquery.com/blog/2007/07/05/jquery-1131/">today&#8217;s update to jQuery itself, now at version 1.1.3.1</a>. Interestingly enough, though the tutorial had you link in version 1.1.3, I had been loading an older (pre-1.1.3) version on this site and was a little disappointed that the demos were a little sluggish. Linking to 1.1.3.1 provided a significant and very noticeable boost to performance. They said <a href="http://jquery.com/blog/2007/07/01/jquery-113-800-faster-still-20kb/">1.1.3 was 800% faster than 1.1.2</a>, and I mostly believed them &#8212; but come on, everyone claims they&#8217;re latest release of whatever is 800% faster. It&#8217;s like marketing boilerplate. I think they make rubber stamps that say that. But I can vouch that the latest release of jQuery is at least, technically speaking, a whole bunch faster.</p>
</div>
<p> <!-- jquery introduction --></p>
<p><script>
$(document).ready(function()
{
   $("a.togglered").toggle(function(){
     $("p.redtarget").css({color:"#AA0000"});
   },function(){
     $("p.redtarget").css({color:"#000"});
   });
  $("a.intro").click( function() {
    $("div.introtarget").toggle(100);return false;
  });
  $("form#stockform").submit(function(){
    var sym = $("input#sym").val();
    var yurl = "http://finance.yahoo.com/d/quotes.csv?f=l1&#038;s="+sym;
    var furl = "http://techrageo.us/code/geturl.php?url=" + escape(yurl);
    $("span#lasttrade").load( furl );
    return false;
  });
  var rwb=Array("#f00","#aaa","#00f");
  $("a#redwhiteblue").toggle( function() {
    $("p.Godblessamerica").slideDown(300);
    $("div#jqueryintro p").each(function(i){
      $(this).css({color:rwb[i % 3]});
    }); return false;
  },
  function(){
    $("p.Godblessamerica").slideUp(300);
    $("div#jqueryintro p").css({color:"#000"});
    return false;
  });
});
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2007/07/05/jquery-introduction/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Communicating Charts with Flex</title>
		<link>http://techrageo.us/2007/06/19/communicating-charts-with-flex/</link>
		<comments>http://techrageo.us/2007/06/19/communicating-charts-with-flex/#comments</comments>
		<pubDate>Tue, 19 Jun 2007 08:59:46 +0000</pubDate>
		<dc:creator>grant</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Free]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://techrageo.us/2007/06/19/communicating-charts-with-flex/</guid>
		<description><![CDATA[Getting started Creating graphs with Adobe&#8217;s Flex 2 is a pretty simple task, just throw together some short XML and you&#8217;re done. But like most &#8220;easy&#8221; technologies things get a little more difficult when you want to do more advanced things like making sections of the graphs stand out or keeping multiple graphs in sync [...]]]></description>
			<content:encoded><![CDATA[<h3>Getting started</h3>
<p>Creating graphs with <a href="http://www.adobe.com/products/flex/">Adobe&#8217;s Flex 2</a> is a pretty simple task, just throw together some short XML and you&#8217;re done.  But like most &#8220;easy&#8221; technologies things get a little more difficult when you want to do more advanced things like making sections of the graphs stand out or keeping multiple graphs in sync with one another.  In this tutorial I will take you through how to give your graphs a little more &#8220;flash&#8221; and how to make things happen in one graph when you click on another graph.</p>
<p>If you haven&#8217;t already you can <a href="http://www.adobe.com/products/flex/">download the free Flex 2 SDK from Adobe</a>. And you can <a href="http://www.adobe.com/products/flex/charting/">download a free trial of the Flex 2 charting library</a>.</p>
<p>In your favorite text editor (<a href="http://www.eclipse.org/">Eclipse</a> anyone?) start a new file and start with some basic code:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Application</span> <span style="color: #000066;">xmlns:mx</span>=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;*&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">xmlns:local</span>=<span style="color: #ff0000;">&quot;*&quot;</span> <span style="color: #000066;">xmlns:view</span>=<span style="color: #ff0000;">&quot;view.*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #339933;">&lt;![CDATA[</span>
<span style="color: #339933;">    import mx.collections.ArrayCollection;</span>
&nbsp;
<span style="color: #339933;">    [Bindable]</span>
<span style="color: #339933;">    private var profitPeriods:ArrayCollection = new ArrayCollection( [</span>
<span style="color: #339933;">    { period: &quot;Qtr1 2006&quot;, profit: 32 },</span>
<span style="color: #339933;">    { period: &quot;Qtr2 2006&quot;, profit: 47 },</span>
<span style="color: #339933;">    { period: &quot;Qtr3 2006&quot;, profit: 62 },</span>
<span style="color: #339933;">    { period: &quot;Qtr4 2006&quot;, profit: 35 },</span>
<span style="color: #339933;">    { period: &quot;Qtr1 2007&quot;, profit: 25 },</span>
<span style="color: #339933;">    { period: &quot;Qtr2 2007&quot;, profit: 55 } ]);</span>
<span style="color: #339933;">  ]]&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:Panel</span> <span style="color: #000066;">x</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">y</span>=<span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Profit By Period&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:PieChart</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;profitPie&quot;</span> <span style="color: #000066;">dataProvider</span>=<span style="color: #ff0000;">&quot;{profitPeriods}&quot;</span> <span style="color: #000066;">showDataTips</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mx:PieSeries</span> <span style="color: #000066;">field</span>=<span style="color: #ff0000;">&quot;profit&quot;</span> <span style="color: #000066;">nameField</span>=<span style="color: #ff0000;">&quot;period&quot;</span> <span style="color: #000066;">labelPosition</span>=<span style="color: #ff0000;">&quot;callout&quot;</span> <span style="color: #000066;">showDataEffect</span>=<span style="color: #ff0000;">&quot;{interpolate}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:series<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:PieChart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Panel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mx:Application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>Getting more advanced</h3>
<p>This code basically creates a sample dataset and a pie chart to display it.  Nothing fancy and if we were using an XML feed we wouldn&#8217;t have any need for ActionScript at all, since we are only using it to create the data in this example.</p>
<p>Now let&#8217;s say that your customer (or boss) wants to have the data shown in multiple ways.  For our example let&#8217;s say that he wants to see a pie graph, a bar graph and a data grid.  So he can see the data in whatever way he wants to.  No problem there, throwing another chart and grid on the page is just a few more lines of xml, but what if they are to interact?  Say your boss wants to be able to click on a piece of the pie chart and have the same record highlighted in the pie chart, the column chart and the data grid.  Now we&#8217;re going to have to whip out the ActionScript.</p>
<p>We are going to need three methods, one to highlight the pie graph, one for the column chart and a final one for the data grid.  Then we can call all three of these methods whenever a chart or grid is clicked on.  We are using three methods instead of just one giant method in case we ever want to use them again, in a different circumstance.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;  <span style="color: #808080; font-style: italic;">//The items in the column chart are DisplayObjects</span>
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> prevSelectedColumn:DisplayObject;
<span style="color: #808080; font-style: italic;">/*
We want to be able to &quot;unhighlight&quot; whatever column we highlighted last time, so
we'll create a variable to keep it simple. If you are using a graph with
multiple datasets then you'll obviously want to loop through them and reset them
that way instead of using this method.
*/</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
* This function will highlight a column/bar in a column/bar chart
* @param barName  The name/id of the bar/column chart
* @param barIndex The position of the column you want to highlight
*/</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> barHighlight<span style="color: #66cc66;">&#40;</span> barName:<span style="color: #0066CC;">String</span>, barIndex:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>prevSelectedColumn<span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">//If we selected something before, unselect it:</span>
  <span style="color: #66cc66;">&#123;</span>
    prevSelectedColumn.<span style="color: #006600;">alpha</span> = .8;
    prevSelectedColumn.<span style="color: #006600;">filters</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;  <span style="color: #808080; font-style: italic;">//remove the filters</span>
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">//This gets the individual column that we are looking for</span>
  prevSelectedColumn = <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span>barName<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">series</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">getChildAt</span><span style="color: #66cc66;">&#40;</span> barIndex <span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>prevSelectedColumn<span style="color: #66cc66;">&#41;</span>  <span style="color: #808080; font-style: italic;">//highlight the new column:</span>
  <span style="color: #66cc66;">&#123;</span>
    prevSelectedColumn.<span style="color: #006600;">alpha</span> = <span style="color: #cc66cc;">1</span>;
    prevSelectedColumn.<span style="color: #006600;">filters</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #000000; font-weight: bold;">new</span> GlowFilter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #000000; font-weight: bold;">new</span> DropShadowFilter<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;
  <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
* This function will highlight a row in a data grid
* @param dataGridName The name of the data grid that contains the row to highlight
* @param rowIndex   The position of the row in the grid to highlight
*/</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> rowHighlight<span style="color: #66cc66;">&#40;</span> dataGridName:<span style="color: #0066CC;">String</span>, rowIndex:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>: <span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span>dataGridName<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">selectedIndex</span> = rowIndex;  <span style="color: #808080; font-style: italic;">//the easy one...</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*
* This function &quot;explodes&quot; a piece of pie from a pie chart
* @param pieName  The name of the pie chart that is to be modified
* @param pieIndex The index of the pie piece that is to be modified
*/</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> pieHighlight<span style="color: #66cc66;">&#40;</span> pieName:<span style="color: #0066CC;">String</span>, pieIndex:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> explodeData:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>;  <span style="color: #808080; font-style: italic;">//create an empty array</span>
  explodeData<span style="color: #66cc66;">&#91;</span> pieIndex <span style="color: #66cc66;">&#93;</span> = <span style="color: #cc66cc;">0.15</span>; <span style="color: #808080; font-style: italic;">//Set the index of our pie piece to &gt; 0</span>
  <span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#91;</span>pieName<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">series</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">perWedgeExplodeRadius</span> = explodeData;
  <span style="color: #808080; font-style: italic;">/*
  The pie's wedges can be &quot;exploded&quot; outward to highlight them. The amount is
  controlled by an array, so we just create a empty array (which would set
  everything to no padding) and add padding for the index that is to be
  highlighted. This has the added bonus of un-highlighting the piece that was last
  highlighted (if any). Sweet!
  */</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>Adding events</h3>
<p>Of course, this is using inline ActionScript.  If you want to separate it into another file you&#8217;ll have to use &#8220;Application.application&#8221; instead of &#8220;this&#8221; (see the downloadable GraphHighlighting.as file below).  That should give us a snazzy little effect every time we click on an item in any of the charts or in the grid.   But they won&#8217;t be doing any effects unless we add event handlers to our objects.  Let&#8217;s do that now.</p>
<p>So change the xml for your pie chart and add this to the PieChart tag:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">itemClick=<span style="color: #ff0000;">&quot;pieChartClick(event, 'profitGrid', 'profitBar');&quot;</span></pre></div></div>

<p>And then you can add the ActionScript to handle that event (which, of course, will call our handy three functions):</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
* This is run when the pie chart is clicked on
* @param event    The click event
* @param dataGridName The string name of the data grid that should be highlighted
* @param barName  The string name of the column chart that should be highlighted
*/</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> pieChartClick<span style="color: #66cc66;">&#40;</span> event:ChartItemEvent, dataGridName:<span style="color: #0066CC;">String</span>, barName:<span style="color: #0066CC;">String</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
  pieHighlight<span style="color: #66cc66;">&#40;</span> event.<span style="color: #006600;">currentTarget</span>.<span style="color: #006600;">id</span> , event.<span style="color: #006600;">hitData</span>.<span style="color: #006600;">chartItem</span>.<span style="color: #0066CC;">index</span> <span style="color: #66cc66;">&#41;</span>;
  rowHighlight<span style="color: #66cc66;">&#40;</span> dataGridName, event.<span style="color: #006600;">hitData</span>.<span style="color: #006600;">chartItem</span>.<span style="color: #0066CC;">index</span><span style="color: #66cc66;">&#41;</span>;
  barHighlight<span style="color: #66cc66;">&#40;</span> barName, event.<span style="color: #006600;">hitData</span>.<span style="color: #006600;">chartItem</span>.<span style="color: #0066CC;">index</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Then do this for the other chart and the datagrid and you&#8217;ll be set.</p>
<h3>Conclusion and downloads</h3>
<p>So, if you did your calculations correctly, remembered to carry the one and crossed your fingers you probably ended up with something like this:</p>
<div style="width: 490px">
<object width="480" height="480" codebase="http://active.macromedia.com/flash7/cabs/ swflash.cab#version=9,0,0,0"><param name="src" value="http://www.techrageo.us/code/communicateflex/Chart.swf"><param name="quality" value="high"><embed src="http://www.techrageo.us/code/communicateflex/Chart.swf" width="480" height="480" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></embed></object>
</div>
<p>Actually, it probably won&#8217;t look like that, but the sample code download does (see below).</p>
<p>It is more likely that you&#8217;ll probably be making the charts communicate using different data (click on one part of a chart and get detailed information in another chart), but this should at least get you started in the right direction.</p>
<p>Download the <a href="http://techrageo.us/code/communicateflex/Chart.mxml">complete inline ActionScript example</a>: This file is the complete example and you should be able to save it and compile it with the mxml compiler that came with the Flex 2 SDK (assuming you have the charting library, or the charting trial library).</p>
<p>Download the <a href="http://techrageo.us/code/communicateflex/GraphHighlighting.as">&#8220;external&#8221; ActionScript methods</a>: This file is what you can use if you want to keep these functions in your library for future use.  I put this in the FlexAS.GraphHighlighting package, so if you don&#8217;t change the package name you should put this into a &#8220;FlexAS/GraphHighlighting/&#8221; subfolder off of your main flex directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://techrageo.us/2007/06/19/communicating-charts-with-flex/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>
