<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Norburn&#039;s Blog</title>
	<atom:link href="http://norburn.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://norburn.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Fri, 10 Jul 2009 14:10:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='norburn.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Norburn&#039;s Blog</title>
		<link>http://norburn.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://norburn.wordpress.com/osd.xml" title="Norburn&#039;s Blog" />
	<atom:link rel='hub' href='http://norburn.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Google Book Preview: Some Javascript to determine if the book is scanned before rendering the page.</title>
		<link>http://norburn.wordpress.com/2009/07/09/google-book-preview-determine-if-the-book-is-scanned-before-rendering-the-page/</link>
		<comments>http://norburn.wordpress.com/2009/07/09/google-book-preview-determine-if-the-book-is-scanned-before-rendering-the-page/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 09:52:00 +0000</pubDate>
		<dc:creator>cnorburn</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[google book preview]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[prototypejs]]></category>

		<guid isPermaLink="false">http://norburn.wordpress.com/?p=5</guid>
		<description><![CDATA[My first post&#8230;. I&#8217;ll make it a relatively short one, so here goes. I&#8217;ve been doing some work on a publishers website, so of course they want to use the Google Book Preview on their product pages. Google have designed their API to be as easy to use as possible, they even let you run [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=norburn.wordpress.com&amp;blog=8494621&amp;post=5&amp;subd=norburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My first post&#8230;.</p>
<p>I&#8217;ll make it a relatively short one, so here goes.</p>
<p>I&#8217;ve been doing some work on a publishers website, so of course they want to use the Google Book Preview on their product pages.</p>
<p>Google have designed their API to be as easy to use as possible, they even let you run a wizard on its <a title="Google Book Preview Wizard" href="http://code.google.com/apis/books/docs/preview-wizard.html" target="_blank">page.</a></p>
<p>This is all well and good if you just want to plonk their graphic link to a scanned book on your page somewhere, with it not showing if the book not available.</p>
<p>But what if you want to use your own graphical link? And you don&#8217;t want the link visible if the book not available? This link might even form part of a navigation control&#8230;.</p>
<p>So, after reading the documentation, I realised I would have to write my own Javascript method to show/hide the link.</p>
<p>The first function, displayGoogle, is called from the page initialise and builds up a <a title="JSON" href="http://www.json.org/" target="_blank">JSON</a> script, with the books isbn, appends and therefore executes it</p>
<p><code>function displayGoogle(isbn){<br />
<span class="_indent2">var script = document.createElement("script");</span><br />
<span class="_indent2">script.setAttribute("id", "jsonScript");</span><br />
<span class="_indent2">script.setAttribute("src",    "http://books.google.com/books?bibkeys=" + escape(isbn)</span> <span class="_indent2">    +  "&amp;jscmd=viewapi&amp;callback=<span>bookExists</span>");</span><br />
<span class="_indent2">script.setAttribute("type", "text/javascript");</span><br />
<span class="_indent2">document.documentElement.firstChild.appendChild(script);</span><br />
}</code></p>
<p style="text-align:left;"><span style="color:#000000;">The</span> key command to note here is the callback value, bookExists. This is the function that will be called, with a book object, on completion.</p>
<p><code><br />
function bookExists(booksInfo){<br />
<span class="_indent2">for (i in booksInfo){</span><br />
<span class="_indent3">if(booksInfo[i].preview != "noview") $("_google").show();</span><br />
<span class="_indent2">}</span><br />
}</code></p>
<p>Now all we have to do is iterate the returned book object, booksInfo, and if it&#8217;s preview flag is not set to <a title="Google API Dynamic Links" href="http://code.google.com/apis/books/docs/dynamic-links.html" target="_blank">noview</a>, go ahead and show the link. In the example I&#8217;m using <a title="Prototype JS" href="http://www.prototypejs.org/" target="_blank">prototypes</a> api to show the google element, <span style="color:#808080;">$(&#8220;_google&#8221;).show()<span style="color:#000000;">, more on this later.</span></span></p>
<p>That&#8217;s it, hope it helps you.</p>
<p><span style="color:#808080;"><span style="color:#000000;"><br />
</span></span><ins datetime="2009-07-09T09:29:07+00:00"></ins></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/norburn.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/norburn.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/norburn.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/norburn.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/norburn.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/norburn.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/norburn.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/norburn.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/norburn.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/norburn.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/norburn.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/norburn.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/norburn.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/norburn.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=norburn.wordpress.com&amp;blog=8494621&amp;post=5&amp;subd=norburn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://norburn.wordpress.com/2009/07/09/google-book-preview-determine-if-the-book-is-scanned-before-rendering-the-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/4cc889148dc356b7d75ef685cd8bcfd7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cnorburn</media:title>
		</media:content>
	</item>
	</channel>
</rss>
