1 // ========================================================================== 2 // Project: The M-Project - Mobile HTML5 Application Framework 3 // Copyright: (c) 2010 M-Way Solutions GmbH. All rights reserved. 4 // (c) 2011 panacoda GmbH. All rights reserved. 5 // Creator: Dominik 6 // Date: 26.10.2010 7 // License: Dual licensed under the MIT or GPL Version 2 licenses. 8 // http://github.com/mwaylabs/The-M-Project/blob/master/MIT-LICENSE 9 // http://github.com/mwaylabs/The-M-Project/blob/master/GPL-LICENSE 10 // ========================================================================== 11 12 /** 13 * @namespace 14 * The The-M-Project namespace. 15 * 16 * All The-M-Project methods and functions are defined inside of this namespace. 17 */ 18 var M = M || {}; 19 20 /** 21 * The version of The-M-Project 22 */ 23 M.Version = '1.0'; 24 25 /** 26 * These command is used by the build tool to control the load order. 27 * It does nothing on the client side. 28 */ 29 var m_require = m_require || function require() {}; 30 31 /** 32 * global constant to write YES instead of true 33 */ 34 var YES = true; 35 /** 36 * global constant to write NO instead of false 37 */ 38 var NO = false; 39 40 M.LOCAL_STORAGE_PREFIX = '#m#'; 41 M.LOCAL_STORAGE_SUFFIX = '_'; 42 43 /* TODO: evaluate if the timestamp constants could be included in config file, for user's customization */ 44 /** 45 * constant that defines name of createdAt property and column name 46 */ 47 M.META_CREATED_AT = '_createdAt'; 48 /** 49 * constant that defines name of updatedAt property and column name 50 */ 51 M.META_UPDATED_AT = '_updatedAt'; 52 /** 53 * constant that defines name of m_id column name 54 */ 55 M.META_M_ID = '_m_id'; 56 57 /** 58 * Overwrites clear() of LocalStorage to clear only key-value pairs belonging to the application. If the previously existing, 59 * delivered clear shall be used, users have to pass 'f' as param to clear to force it. 60 * @param {String} param One character string. If it is 'f' (means 'force'), the existing clear() is used to clear the whole storage 61 * if param is undefined or another letter, the custom clear is used. 62 */ 63 Object.getPrototypeOf(localStorage).clear = function(param) { 64 /* Call localStorage.clear() with parameter 'f' to use system wide localStorage.clear() */ 65 var l = this.length; 66 if(param === 'f') { 67 var l = this.length; 68 for (var i = l - 1; i >= 0; i--){ 69 this.removeItem(this.key(i)); 70 } 71 } else { 72 for (var i = l - 1; i >= 0; i--){ 73 var k = this.key(i); 74 var regexResult = new RegExp('^' + M.LOCAL_STORAGE_PREFIX + M.Application.name + M.LOCAL_STORAGE_SUFFIX).exec(k); 75 if(regexResult) { 76 this.removeItem(k); 77 } 78 } 79 } 80 } 81