1 /* Name: Storage Moduke 2 Date: April 2011 3 Description: Main module for the storage functionality (LocalStorage, Cache Manifest) 4 Dependencies: <none> 5 Children: <none> */ 6 7 /* Properties GET FROM JSLINT */ 8 9 /** 10 * Creates an instance of the Storage module 11 * 12 * @constructor 13 * @this {Storage} 14 * @see storage.js 15 */ 16 function Storage(){ 17 /** 18 * Check for HTML5 LocalStorage support. 19 * <i>Check for HTML5 LocalStorage from http://diveintohtml5.org/storage.html</i> 20 * @return {Boolean} Boolean denoting HTML5 LocalStorage support. 21 * @this {Storage} 22 */ 23 this.checkSupport = function() { 24 try { 25 return 'localStorage' in window && window['localStorage'] !== null; 26 } catch (e) { 27 return false; 28 } 29 } 30 31 /** 32 * Save key value pair to LocalStorage. 33 * 34 * @param {String} key Key to use for LocalStorage. 35 * @param {String} value Value to store in LocalStorage. 36 * @this {Storage} 37 */ 38 this.save = function(key,value){ 39 if (this.checkSupport){ 40 localStorage.setItem(key,value); 41 } 42 } 43 44 /** 45 * Load value from LocalStorage using key. 46 * 47 * @param {String} key Key to load from LocalStorage. 48 * @return {String} Value returned from LocalStorage. 49 * @this {Storage} 50 */ 51 this.load = function(key){ 52 if (this.checkSupport){ 53 return localStorage.getItem(key); 54 } 55 } 56 57 /** 58 * Remove item from LocalStorage. 59 * 60 * @param {String} key Key to delete from LocalStorage. 61 * @this {Storage} 62 */ 63 this.delete = function(key){ 64 if (this.checkSupport){ 65 localStorage.removeItem(key); 66 } 67 } 68 }