<?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>Dark Crimson Blog &#187; HTML5</title>
	<atom:link href="http://blog.darkcrimson.com/tag/html5/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.darkcrimson.com</link>
	<description>The Blog of Ben Lister</description>
	<lastBuildDate>Fri, 13 Aug 2010 02:18:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HTML5 / jQuery Slideshow</title>
		<link>http://blog.darkcrimson.com/2010/08/html5-jquery-slideshow/</link>
		<comments>http://blog.darkcrimson.com/2010/08/html5-jquery-slideshow/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 02:11:00 +0000</pubDate>
		<dc:creator>Ben Lister</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[contenteditable]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[localStorage]]></category>

		<guid isPermaLink="false">http://blog.darkcrimson.com/?p=377</guid>
		<description><![CDATA[A few weeks ago, I wrote a jQuery slideshow app for a personal project. The slideshow ended up being more useful than I originally expected and I realized that it could be re-used in a many different applications with a little more work. Several days later, A List Apart launched &#8220;10K Apart: A contest to [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, I wrote a jQuery slideshow app for a personal project. The slideshow ended up being more useful than I originally expected and I realized that it could be re-used in a many different applications with a little more work. Several days later, <a href="http://alistapart.com" target="_blank">A List Apart</a> launched &#8220;<a href="http://10k.aneventapart.com/" target="_blank">10K Apart: A contest to inspire the web in under 10k.</a>&#8221; When I first read about the contest my slideshow app came to mind so I decided to look into ways to make it work for the concept.<span id="more-377"></span></p>
<p>Originally, the content of the slides were entered manually to the HTML file but with the help of HTML5&#8217;s very handy <code>localStorage</code> and <code>contentEditable</code> features, I added the ability to create the slide content within the browser, saving it as it&#8217;s typed. Most conventional desktop slideshows rely on the mouse to add content and navigate which is slow and often frustrating. To avoid this pitfall and improve the work flow, I added simple keyboard commands to easily navigate (up and down arrows) and add / remove slides (ctrl+A / ctrl+D).</p>
<p>I plan to release the full source of this project and do a code walk through soon but in the meantime, you can <em>view and vote for the project</em> on the 10K Apart website:</p>
<p><a href="http://10k.aneventapart.com/Entry/143" class="view_source" style="margin:0 auto;float: none;" target="_blank">View the Project</a></p>
<div style="clear:both"></div>
<h3 class="blog_ttl">Features</h3>
<dl class="arrows">
<dt>→</dt>
<dd>Fully editable slides</dd>
<dt>→</dt>
<dd>Ability to quickly and easily Add / Remove slides</dd>
<dt>→</dt>
<dd>Persistent content (saved &#8220;on the fly&#8221; with <code>localStorage</code>)</dd>
<dt>→</dt>
<dd>Arrow key navigation</dd>
<dt>→</dt>
<dd>Two themes</dd>
<dt>→</dt>
<dd>Light weight (under 10k not including jQuery)</dd>
</dl>
<p></p>
<h3 class="blog_ttl">Technologies used</h3>
<dl class="arrows">
<dt>→</dt>
<dd><code>localStorage</code></dd>
<dt>→</dt>
<dd><code>contentEditable</code></dd>
<dt>→</dt>
<dd>CSS3 Radial Gradients</dd>
<dt>→</dt>
<dd>RGBa</dd>
<dt>→</dt>
<dd>Border Radius</dd>
<dt>→</dt>
<dd>Box Shadow</dd>
<dt>→</dt>
<dd>Text shadow</dd>
</dl>
<div style="clear:both"></div>
<p><a href="http://10k.aneventapart.com/Entry/143" class="view_source" style="margin:0 auto;float: none;" target="_blank">View the Project</a></p>
<div style="clear:both"></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.darkcrimson.com/2010/08/html5-jquery-slideshow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting Started with HTML5 Local Databases</title>
		<link>http://blog.darkcrimson.com/2010/05/local-databases/</link>
		<comments>http://blog.darkcrimson.com/2010/05/local-databases/#comments</comments>
		<pubDate>Mon, 17 May 2010 02:00:57 +0000</pubDate>
		<dc:creator>Ben Lister</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[Webkit]]></category>

		<guid isPermaLink="false">http://blog.darkcrimson.com/?p=217</guid>
		<description><![CDATA[Starting with Safari 4, iPhone/iPad OS3, Chrome 5,  and Opera 10.5 (Desktop), HTML5 Local Databases are now supported. I&#8217;ve been reading about local databases for quite some time and decided to do a write up with some basic examples on how to get started.
Setting up the Database

function initDatabase() {
	try {
	    if [...]]]></description>
			<content:encoded><![CDATA[<p>Starting with Safari 4, iPhone/iPad OS3, Chrome 5,  and Opera 10.5 (Desktop), HTML5 Local Databases are now supported. I&#8217;ve been <a href="http://webkit.org/blog/126/webkit-does-html5-client-side-database-storage/" target="_blank">reading about local databases for quite some time</a> and decided to do a write up with some basic examples on how to get started.<span id="more-217"></span></p>
<h3 class="blog_ttl">Setting up the Database</h3>
<pre name="code" class="javascript">
function initDatabase() {
	try {
	    if (!window.openDatabase) {
	        alert('Databases are not supported in this browser.');
	    } else {
	        var shortName = 'DEMODB';
	        var version = '1.0';
	        var displayName = 'DEMO Database';
	        var maxSize = 100000; //  bytes
	        DEMODB = openDatabase(shortName, version, displayName, maxSize);
			createTables();
			selectAll();
	    }
	} catch(e) {

	    if (e == 2) {
	        // Version number mismatch.
	        console.log("Invalid database version.");
	    } else {
	        console.log("Unknown error "+e+".");
	    }
	    return;
	}
}
</pre>
<p>First we check if the browser supports the openDatabase method, is so we continue and define the database parameters:</p>
<ul class="in_post">
<li><code>shortName</code> is the DB name as it will be referred to by the browser and SQL</li>
<li><code>version</code> openDatabase version. 1.0 for this (<a href="http://developer.apple.com/safari/library/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/UsingtheJavascriptDatabase/UsingtheJavascriptDatabase.html#//apple_ref/doc/uid/TP40007256-CH3-XSW1" target="_blank">more on that here</a>) </li>
<li><code>displayName</code> The full display name / description of the database</li>
<li><code>maxSize</code> This is max size in bytes is the size you expect the database to reach. This is essential for memory management purposes.</li>
</ul>
<p>Next, we call the <code>createTables();</code> function where the table is defined and pre-populated with initial data (optional).</p>
<h3 class="blog_ttl">Building the Table</h3>
<pre name="code" class="javascript">
function createTables(){
	DEMODB.transaction(
        function (transaction) {
        	transaction.executeSql('CREATE TABLE IF NOT EXISTS page_settings(id INTEGER NOT NULL PRIMARY KEY, fname TEXT NOT NULL,bgcolor TEXT NOT NULL, font TEXT, favcar TEXT);', [], nullDataHandler, errorHandler);
        }
    );
	prePopulate();
}
</pre>
<p>This basic function executes the <code>executeSql</code> method which runs as the <code>CREATE TABLE</code> query. The SQL syntax is based on <a href="http://sqlite.org/" target="_blank">SQLite</a> so it should feel familiar to many Web &#038; Mobile developers. For this demo, we are going to pre-populate the newly created <code>page_settings</code> table with some initial data:</p>
<pre name="code" class="javascript">
function prePopulate(){
	DEMODB.transaction(
	    function (transaction) {
		//Optional Starter Data when page is initialized
		var data = ['1','none','#B3B4EF','Helvetica','Porsche 911 GT3'];
		transaction.executeSql("INSERT INTO page_settings(id, fname, bgcolor, font, favcar) VALUES (?, ?, ?, ?, ?)", [data[0], data[1], data[2], data[3], data[4]]);
	    }
	);
}
</pre>
<p><em>Note: although we don&#8217;t really need a <abbr title="Primary Key">PK</abbr> for such a basic demo it will be there for future extensions and advancements.</em></p>
<p>Now the database is initialized, a table has been created and we have a row of default data inserted. Since the data is stored, you can now reload or page or close and reopen it and the data will remain. To visualize this in Safari, go to <em> Develop > Show Web Inspector > Databases tab</em> where you can view the database and its contents as they are added or changed. </p>
<h3 class="blog_ttl">Select the data</h3>
<p>After the initial page load the data is stored and we run the <code>selectAll()</code> function to get the data:</p>
<pre name="code" class="javascript">
function selectAll(){
	DEMODB.transaction(
	    function (transaction) {
	        transaction.executeSql("SELECT * FROM page_settings;", [],
                dataSelectHandler, errorHandler);
	    }
	);
}
</pre>
<p><em>The demo consists of only one row so we use <code>*</code> to grab everything from the database but please optimize your queries if you decide to use this example for your own projects.<br />
</em></p>
<pre name="code" class="javascript">
function dataSelectHandler(transaction, results){

	// Handle the results
    for (var i=0; i<results.rows.length; i++) {

    	var row = results.rows.item(i);
        var newFeature = new Object();

    	newFeature.fname   = row['fname'];
        newFeature.bgcolor = row['bgcolor'];
        newFeature.font    = row['font'];
        newFeature.favcar  = row['favcar'];

        $('body').css('background-color',newFeature.bgcolor);
        $('body').css('font-family',newFeature.font);
        $('#content').html('
<h4 id="your_car">Your Favorite Car is a '+ newFeature.favcar +'</h4>

');

        if(newFeature.fname != 'none') {
       		$('#greeting').html('Howdy-ho, '+ newFeature.fname+'!');
       		$('#fname').val(newFeature.fname);
        } 

       $('select#font_selection').find('option[value='+newFeature.font+']').attr('selected','selected');
       $('select#bg_color').find('option[value='+newFeature.bgcolor+']').attr('selected','selected');
       $('select#fav_car').find('option[value='+newFeature.favcar+']').attr('selected','selected');
    }

}
</pre>
<p>This function loops through our data and uses a bit of jQuery to apply the specific values to CSS properties on the DOM. Going further, we set the HTML form defaults based on data with the help of jQuery. </p>
<h3 class="blog_ttl">Making updates</h3>
<p>This function reads the form values, validates the <code>text</code> input and updates the database</p>
<pre name="code" class="javascript">
function updateSetting(){
	DEMODB.transaction(
	    function (transaction) {
	    	if($('#fname').val() != '') {
	    		var fname = $('#fname').val();
	    	} else {
	    		var fname = 'none';
	    	}
			var bg    = $('#bg_color').val();
			var font  = $('#font_selection').val();
			var car   = $('#fav_car').val();
	    	transaction.executeSql("UPDATE page_settings SET fname=?, bgcolor=?, font=?, favcar=? WHERE id = 1", [fname, bg, font, car]);
	    }
	);
		selectAll();
}
</pre>
<h3 class="blog_ttl">Dropping the table</h3>
<p>We could simply remove the row with a <code>DELETE</code> query but since we already check for the presence of data, it makes more sense to <code>DROP</code> the table:</p>
<pre name="code" class="javascript">
function dropTables(){
	DEMODB.transaction(
	    function (transaction) {
	    	transaction.executeSql("DROP TABLE page_settings;", [], nullDataHandler, errorHandler);
	    }
	);
	location.reload();
}
</pre>
<p>After the table is dropped, the page is refreshed which triggers the initial database setup procedures defined earlier. </p>
<h3 class="blog_ttl">The demo:</h3>
<p><a href="http://blog.darkcrimson.com/samples/localdb/" class="view_demo ext">View Demo</a><a href="http://blog.darkcrimson.com/samples/localdb/darkcrimson_localdb_demo.zip" class="view_source">Download Source</a></p>
<div style="clear:both"></div>
<h3 class="blog_ttl">Why should you use Local Databases?</h3>
<dl class="arrows">
<dt>→</dt>
<dd> They are fast, flexible and never expire. Developers can define the maximum size of the database and since all of the queries are run via JavaScript, no external server calls are required and unlike cookies and sessions, they persist until manually removed.</dd>
<dt>→</dt>
<dd> Unlike cookies and sessions, which are created on the server side and then stored in the browser, the information stored in a local database is truly local. </dd>
<dt>→</dt>
<dd> Safari and Opera&#8217;s local databases are based on <a href="http://sqlite.org/" target="_blank">SQLite</a> and are <a href="http://www.sqlite.org/faq.html#q6">threadsafe</a> which prevents multiple instances of the data from being opened concurrently. </dd>
<dt>→</dt>
<dd> iPhone and iPad OS support local databases through their Mobile Safari browsers, making this storage platform ideal for mobile web apps.
</dd>
<dt>→</dt>
<dd> From the UX perspective, the possibility of storing user and page settings and options locally, instantly  and securely without the out the need to make external server or server side database calls is incredible. Since the HTML5 is <a href="http://www.findmebyip.com/litmus/#target-selector" target="_blank">widely supported</a> in Webkit and Opera, there are nearly limitless possibilities for HTML5-based games and web apps. <br class="clearall "><br class="clearall "><br class="clearall ">
</dd>
</dl>
<div style="clear:both"></div>
<h3 class="blog_ttl">Why should you NOT use Local Databases?</h3>
<p>Local databases are a great way for you to simplify and improve your projects but they have a few obvious drawbacks:</p>
<dl class="arrows">
<dt>→</dt>
<dd> Limited cross-browser support in the current form. At the time of this article, Safari 4, iPhone / iPad OS3, Chrome 5 and Opera 10.5 (Desktop) are the only mainstream browsers with support.</dd>
<dt>→</dt>
<dd> Not ideal for sensitive information. Sure, JavaScript can do <a href="http://www.webtoolkit.info/javascript-md5.html" target="_blank">MD5</a> and <a href="http://www.webtoolkit.info/javascript-sha1.html" target="_blank">SHA1</a> hashing but if <a href="http://www.youtube.com/watch?v=96fAX0beduE" target="_blank">these guys</a> can crack the code while listening to KoЯn, how safe do you feel?</dd>
<dt>→</dt>
<dd> Even though SQLite has been around for 10 years now, Webkit / Opera support is <a href="http://webkit.org/blog/126/webkit-does-html5-client-side-database-storage" target="_blank">much newer</a> and has consequently seen less vetting from those who would want to steal your data.<br class="clearall "><br class="clearall "><br class="clearall "></dd>
</dl>
<div style="clear:both"></div>
<h3 class="blog_ttl">What about FireFox, Chrome and IE? </h3>
<dl class="arrows">
<dt>→</dt>
<dd> <strong>Firefox</strong> introduced support for <a href="https://developer.mozilla.org/en/DOM/Storage#localStorage" target="_blank">localStorage</a> in version 3.5 in the <code>key-value</code> pair format (similar to cookies and sessions) but has so far (<a href="http://weblogs.mozillazine.org/roc/archives/2010/06/not_implementin.html" target="_blank">and for the foreseeable future</a>) stayed away from the  SQL Database Storage model. More about that  <a href="http://hacks.mozilla.org/2009/06/localstorage/" target="_blank">here</a>, <a href="http://hacks.mozilla.org/2010/01/offline-web-applications/#comments" target="_blank">here</a> and <a href="http://blog.vlad1.com/2009/04/06/html5-web-storage-and-sql/" target="_blank">here</a></dd>
<dt>→</dt>
<dd><strong>Internet Explorer</strong> has offered persistent storage support since IE5.5 which they&#8217;ve termed <a href="http://msdn.microsoft.com/en-us/library/ms531424%28VS.85%29.aspx" target="_blank">userData Behavior</a>. This technique is very limited in features and has a maximum storage size of 128k per page. IE local storage <a href="http://msdn.microsoft.com/en-us/library/cc197062%28VS.85%29.aspx#_global" target="_blank">improved in IE8 with the introduction of localStorage</a>. Both IE local storage formats are <code>key-value</code> and there is currently no native local database support in IE&mdash;maybe in <a href="http://ie.microsoft.com/testdrive/" target="_blank">IE9?</a><br class="clearall "><br class="clearall "><br class="clearall "></dd>
<dt>→</dt>
<dd><span style="color:#8F8F8F;opacity:0.6">Prior to version 4, local database storage support in <strong>Chrome</strong> was limited to implimentaiton via the <a href="http://code.google.com/apis/gears/upcoming/api_database.html" target="_blank">Google Gears API</a>. Gears offers a very similar SQLite-based local storage component that works across most browsers including IE6+, FireFox, Opera and Safari. The Gears platform was created to let developers create web applications that can be used offline and also offers support for other features such as  Canvas, Desktop support and Geolocation. The downside is that users must install the Google Gears browser extension on their machine before they can access these features. Additionally, Gears requires developers to include a JavaScript file in their application in order to use Gears which makes it a less than ideal choice for the low-bandwidth mobile web application world. More on the Google Gears Database API <a href="http://code.google.com/apis/gears/api_database.html" target="_blank">here</a>.</span> </p>
<p><em><strong>*UPDATE*</strong></em> As January 2010 <strong>Chrome</strong> now offers full local database storage support natively in effort to move to a more standards-based approach. Gears is still being supported in its current form (no new development or further platform compatibility, though) for the time being.  More information on this change can be found <a href="http://gearsblog.blogspot.com/2010/02/hello-html5.html" target="_blank">here</a>. <em>(Thanks for the correction, <a href="http://catcubed.com" target="_blank">Colin</a>)</em>  </dd>
</dl>
<div style="clear:both"></div>
<h3 class="blog_ttl">Resources</h3>
<ul class="in_post">
<li><a href="http://developer.apple.com/safari/library/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/UsingtheJavascriptDatabase/UsingtheJavascriptDatabase.html" target="_blank">Safari Reference Library: Using the JavaScript Database</a></li>
<li><a href="http://webkit.org/blog/126/webkit-does-html5-client-side-database-storage" target="_blank">WebKit Does HTML5 Client-side Database Storage</a></li>
<li><a href="http://weblogs.mozillazine.org/roc/archives/2010/06/not_implementin.html" target="_blank">MozillaZine Weblog: Not Implementing Features Is Hard</a></li>
</ul>
<p></p>
<ul class="in_post">
<li><a href="http://my.opera.com/core/blog/2010/03/03/persistent-client-side-storage-for-your-persistent-needs" target="_blank">Opera: Persistent client side storage for your persistent needs</a></li>
<li><a href="http://dev.opera.com/forums/topic/433221" target="_blank">Opera Web Storage: easier, more powerful client-side data storage</a></li>
</ul>
<p></p>
<ul class="in_post">
<li><a href="http://unlock.edina.ac.uk/mobile.html" target="_blank">Unlock data &#8211; mobile example</a></li>
<li><a href="http://girliemac.com/blog/2009/09/03/webkit-css-3d-local-db-demo/" target="_blank">Webkit CSS 3D + Local DB Demo </a></li>
<li><a href="http://webkit.org/demos/sticky-notes/index.html" target="_blank">Storage Notes Demo</a>
</ul>
<p><br class="clearall "><br class="clearall "></p>
<h3 class="blog_ttl">The demo:</h3>
<p><a href="http://blog.darkcrimson.com/samples/localdb/" class="view_demo ext">View Demo</a><a href="http://blog.darkcrimson.com/samples/localdb/darkcrimson_localdb_demo.zip" class="view_source">Download Source</a><br />
<br class="clearall "></p>
<p><br class="clearall "><br class="clearall "></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.darkcrimson.com/2010/05/local-databases/feed/</wfw:commentRss>
		<slash:comments>50</slash:comments>
		</item>
	</channel>
</rss>

