Sys.js 3.7 KB

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