1 /**************************************************************************** 2 3 http://www.cocos2d-html5.org 4 http://www.cocos2d-iphone.org 5 http://www.cocos2d-x.org 6 7 Permission is hereby granted, free of charge, to any person obtaining a copy 8 of this software and associated documentation files (the "Software"), to deal 9 in the Software without restriction, including without limitation the rights 10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 copies of the Software, and to permit persons to whom the Software is 12 furnished to do so, subject to the following conditions: 13 14 The above copyright notice and this permission notice shall be included in 15 all copies or substantial portions of the Software. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 THE SOFTWARE. 24 ****************************************************************************/ 25 26 var sys = sys || {}; 27 28 /** LocalStorage is a local storage component. 29 */ 30 try{ 31 sys.localStorage = window.localStorage; 32 window.localStorage.setItem("storage", ""); 33 window.localStorage.removeItem("storage"); 34 35 }catch(e){ 36 37 if( e.name === "SECURITY_ERR" || e.name === "QuotaExceededError" ) { 38 console.log("Warning: localStorage isn't enabled. Please confirm browser cookie or privacy option"); 39 } 40 sys.localStorage = function(){}; 41 } 42 43 /** Capabilities 44 */ 45 Object.defineProperties(sys, 46 { 47 capabilities : { 48 get : function(){ 49 var capabilities = {"canvas":true}; 50 51 // if (window.DeviceOrientationEvent!==undefined || window.OrientationEvent!==undefined) 52 // capabilities["accelerometer"] = true; 53 if(cc.Browser.supportWebGL) 54 capabilities["opengl"] = true; 55 56 if( document.documentElement['ontouchstart'] !== undefined || window.navigator.msPointerEnabled) 57 capabilities["touches"] = true; 58 59 else if( document.documentElement['onmouseup'] !== undefined ) 60 capabilities["mouse"] = true; 61 62 if( document.documentElement['onkeyup'] !== undefined ) 63 capabilities["keyboard"] = true; 64 65 if(window.DeviceMotionEvent || window.DeviceOrientationEvent) 66 capabilities["accelerometer"] = true; 67 68 return capabilities; 69 }, 70 enumerable : true, 71 configurable : true 72 }, 73 os : { 74 get : function() { 75 var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/i) ? true : false ); 76 var isAndroid = navigator.userAgent.match(/android/i) || navigator.platform.match(/android/i) ? true : false; 77 var OSName=navigator.appVersion; 78 if (navigator.appVersion.indexOf("Win")!=-1) 79 OSName="Windows"; 80 else if( iOS ) 81 OSName = "iOS"; 82 else if (navigator.appVersion.indexOf("Mac")!=-1) 83 OSName="OS X"; 84 else if (navigator.appVersion.indexOf("X11")!=-1) 85 OSName="UNIX"; 86 else if (navigator.appVersion.indexOf("Linux")!=-1) 87 OSName="Linux"; 88 else if( isAndroid ) 89 OSName = "Android"; 90 return OSName; 91 }, 92 enumerable : true, 93 configurable : true 94 }, 95 platform : { 96 get : function(){ 97 return "browser"; 98 }, 99 enumerable : true, 100 configurable : true 101 }, 102 version : { 103 get : function(){ 104 return cc.ENGINE_VERSION; 105 }, 106 enumerable : true, 107 configurable : true 108 } 109 }); 110 111 // Forces the garbage collector 112 sys.garbageCollect = function() { 113 // N/A in cocos2d-html5 114 }; 115 116 // Dumps rooted objects 117 sys.dumpRoot = function() { 118 // N/A in cocos2d-html5 119 }; 120 121 // restarts the JS VM 122 sys.restartVM = function() { 123 // N/A in cocos2d-html5 124 }; 125