crossbrowdy
Version:
A Multimedia JavaScript framework to create real cross-platform and hybrid game engines, games, emulators, multimedia libraries and apps.
2 lines • 8.79 kB
JavaScript
/* localStorage - Version 2.0.1 - 25-09-2014 */
!function(a,b,c,d,e,f){"use strict";function g(){var a=this;a.body=b.body||b.getElementsByTagName("body")[0],a.protocol=c.protocol||b.protocol,a.domain=b.domain,a.oProto=Object.prototype,a.isUndefined=function(a){return a===e},a.isIE=function(){var c=!1;return c=new Function("return/*@cc_on!@*/!1")()||a.isNumber(b.documentMode)&&b.documentMode<=10},a.fixKey=function(a){var b=new RegExp("[!\"#$%&'()*+,/\\\\:;<=>?@[\\]^`{|}~]","g");return a.replace(/^d/,"___$&").replace(b,"___")},a.each=function(b,c){for(var d=b.length;d;)d-=1,a.isUndefined(b.key)?c.call(a,b[d],d):c.call(a,b.key(d),d)},a.forEach=function(b,c){var d=null;for(d in b)b.hasOwnProperty(d)&&c.call(a,b[d],d)},a.attribute=function(a,c,d){var e;a.setAttribute?a.setAttribute(c,d):a.attributes?a.attributes[c]=d:a.createAttribute?(e=b.createAttribute(c),e.value=d,a.setAttributeNode(e)):a[c]=d},a.swfURL=function(){var c=b.scripts||b.getElementsByTagName("script"),d=c[c.length-1].src.split("?"),e=null;return d[1]&&a.each(d[1].split("&"),function(a){var b=a.split("=");return"swfURL"===b[0]?e=decodeURIComponent(b[1].replace(/\+/g," ")):void 0}),e}(),a.appendChild=function(a,b){a.insertBefore(b,a.lastChild?a.lastChild.nextSibling:a.lastChild)},a.element=function(a){return b.createElement(a)},a.toInt=function(a){return parseInt(a,10)},a.hasFlash=function(){var a,b,c="application/x-shockwave-flash";try{return a=new ActiveXObject("ShockwaveFlash.ShockwaveFlash"),a&&(b=a.GetVariable("$version"),b&&j.toInt(b.split(" ")[1].split(",")[0])>=9)?!0:!1}catch(e){return j.isObject(d.plugins["Shockwave Flash"])&&!j.isUndefined(d.mimeTypes)&&!j.isUndefined(d.mimeTypes[c])&&(b=d.plugins["Shockwave Flash"].description,d.mimeTypes[c].enabledPlugin&&!j.isUndefined(b)&&(b=b.replace(/^.*\s+(\S+\s+\S+$)/,"$1"),j.toInt(b.replace(/^(.*)\..*$/,"$1"))>=9))?!0:!1}},a.isObject=function(a){return a===Object(a)},a.each.call(a,["String","Function","Number"],function(b){a["is"+b]=function(c){return typeof c===b.toLowerCase()||a.oProto.toString.call(c)==="[object "+b+"]"}})}function h(){}g.prototype.constructor=g;var i,j=new g,k=!1;h.extend=function(a){function b(){var a=this;return a instanceof b?void(arguments[0]!==h&&a.init&&a.init.apply(a,arguments)):new b(arguments[0])}var c=this,d=c.prototype,e=new c(h),f=function(){return function(a,b){return function(){var c,e=this.$super;return this.$super=d[a],c=b.apply(this,arguments),this.$super=e,c}}(arguments[0],arguments[1])};return j.forEach(a,function(a,b){e[b]=j.isFunction(a)&&j.isFunction(d[b])?f.call(c,b,a):a}),b.prototype=e,b.prototype.constructor=b,b.extend=c.extend,b};var l=h.extend({init:function(){var b=this;b.__storage__="localhost"===c.hostname?a.globalStorage["localhost.localdomain"]:a.globalStorage[c.hostname],b.length=b.__storage__.length},key:function(a){var b=this;return a+1>b.length||0>a?null:b.__storage__.key(a)},getItem:function(a){var b=this,c=b.__storage__.getItem(a);return j.isObject(c)?c.value:c},setItem:function(a,b){var c=this;c.__storage__.setItem(a,b),c.length=c.__storage__.length},removeItem:function(a){var b=this;b.__storage__.removeItem(a),b.length=b.__storage__.length},clear:function(){var a=this;j.each(a.__storage__,function(b){a.removeItem(b)})},isLoaded:function(){return!0}});l.prototype.constructor=l,a.GlobalStorage=l;var m=h.extend({init:function(){var b,c,d=this,e=function(){a.detachEvent("onunload",e),b=c=d.__storage__=null,j.isFunction(CollectGarbage)&&CollectGarbage()};try{b=new ActiveXObject("htmlfile"),b.open(),b.write("<html><head><title>"+f+'</title><script type="text/javascript">document.domain = \''+j.protocol+"//"+j.domain+"';</script></head><body></body></html>"),b.close(),c=b.body,d.__storage__=b.createElement("div"),a.attachEvent("unload",e)}catch(g){c=j.body,d.__storage__=j.element("div")}j.appendChild(c,d.__storage__),d.__storage__.style.display="none",d.__storage__.addBehavior("#default#userData"),d.__storage__.load(f+"_"+j.domain),d.__attributes__=d.__storage__.XMLDocument.documentElement.attributes,d.length=d.__attributes__.length},key:function(a){var b=this,c=null;try{c=a>=b.length?null:b.__attributes__[a].name}catch(d){}return c},getItem:function(a){var b=this;return b.__storage__.getAttribute(j.fixKey(a))},setItem:function(a,b){var c=this;try{c.__storage__.setAttribute(j.fixKey(a),b),c.__storage__.save(f+"_"+j.domain),c.length=c.__attributes__.length}catch(d){throw{name:"UserDataQuotaExceeded",message:"UserData is out of memory"}}},removeItem:function(a){var b=this;b.__storage__.removeAttribute(j.fixKey(a)),b.__storage__.save(f+"_"+j.domain),b.length=b.__attributes__.length},clear:function(){var a=this;j.each(a.__attributes__,function(b){a.removeItem(b.name)})},isLoaded:function(){return!0}});m.prototype.constructor=m,a.UserDataStorage=m;var n=h.extend({init:function(c){var d,e=this,g=j.swfURL?j.swfURL:f+".swf",h=2e3,i="",l="application/x-shockwave-flash",m={id:f,name:f,width:1,height:1},n={allowScriptAccess:"always",wmode:"transparent",flashvars:"readyFn=window._swfReady"},o=function(a,b,c){var d=null,f=null,g=function(){clearInterval(d),clearTimeout(f),f=d=null};d=setInterval(function(){(j.oProto.hasOwnProperty.call(a,"PercentLoaded")&&100===a.PercentLoaded()||k)&&(g.call(e),b.call(e))},10),f=setTimeout(function(){g.call(e),j.isFunction(c)&&c.call(e)},h)},p=function(){var b=null;a.detachEvent("onunload",p),d.style.display="none",b=setInterval(function(){4===d.readyState&&(clearInterval(b),j.each(d,function(a){j.isFunction(a)&&(a=null)}),d.parentNode.removeChild(d))},10)};a._swfReady=function(a){k=a};try{m.classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",n.movie=g,j.forEach(m,function(a,b){i+=b+'="'+a+'" '}),d=j.element("<object "+i+">"),j.forEach(n,function(a,b){var c=j.element("<param name='"+b+"' value='"+a+"'>");j.appendChild(d,c)}),a.attachEvent("onunload",p)}catch(q){j.isIE()||(delete m.classid,delete n.movie),d=j.element("object"),j.forEach(n,function(a,b){var c=j.element("param");j.attribute(c,"name",b),j.attribute(c,"value",a),j.appendChild(d,c)}),j.isIE()||(j.attribute(d,"type",l),j.attribute(d,"data",g)),j.forEach(m,function(a,b){j.attribute(d,b,a)})}j.appendChild(j.body,d),o.call(e,d,function(){e.__storage__=b[f]||b.getElementById(f)||b.embeds[f],e.length=e.__storage__.length(),e.key=function(a){return e.__storage__.key(a)},e.getItem=function(a){return e.__storage__.getItem(a)},e.setItem=function(a,b){if(!e.__storage__.setItem(a,b))throw{name:"FlashQuotaExceeded",message:"FlashStorage is out of memory"};e.length=e.__storage__.length()},e.removeItem=function(a){e.__storage__.removeItem(a),e.length=e.__storage__.length()},e.clear=function(){e.__storage__.clear(),e.length=e.__storage__.length()},e.isLoaded=function(){return!0}},c)},isLoaded:function(){return!1}});n.prototype.constructor=n,a.FlashStorage=n;var o=h.extend({length:function(){var a=b.cookie.match(/\=/g);return a&&a.length||0}(),key:function(c){var d=a.unescape(b.cookie.replace(/\s*\=(?:.(?!;))*$/,"").split(/\s*\=(?:[^;](?!;))*[^;]?;\s*/).sort()[c]);return""===d?null:d},getItem:function(c){var d=-1===b.cookie.indexOf(c+"=")?"":a.unescape(b.cookie.replace(new RegExp("(?:^|.*;\\s*)"+a.escape(c).replace(/[\-\.\+\*]/g,"\\$&")+"\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"),"$1"));return""===d?null:d},setItem:function(c,d){var e=this,f=0,g=a.escape(c)+"="+a.escape(d)+"; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/";if(g.length>4093)throw{name:"CookieQuotaExceeded",message:"CookieStorage is out of memory"};b.cookie=g,f=b.cookie.match(/\=/g),e.length=f&&f.length||0},removeItem:function(c){var d=this,e=0;b.cookie=a.escape(c)+"=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/",e=b.cookie.match(/\=/g),d.length=e&&e.length||0},clear:function(){var a=this;j.each(a,function(b){a.removeItem(b)})},isLoaded:function(){return!0}});o.prototype.constructor=o,a.CookieStorage=o;try{a.localStorage.setItem(f,f),a.localStorage.removeItem(f)}catch(p){a.globalStorage?i=l:b.documentElement&&b.documentElement.addBehavior?i=m:j.hasFlash()?i=n:d.cookieEnabled&&(i=o);var q=i.extend({key:function(a){var b=this;return j.isNumber(a)&&a<b.length&&a>=0?b.$super(a):null},getItem:function(a){var b=this;return j.isString(a)?b.$super(a):null},setItem:function(a,b){var c=this,d=j.isString(b)?b:null!==b&&!j.isUndefined(b)&&j.oProto.hasOwnProperty.call(b,"toString")?b.toString():j.oProto.toString.call(b);j.isString(a)&&c.$super(a,d)},removeItem:function(a){var b=this;j.isString(a)&&b.$super(a)},isLoaded:function(a){var b=this,c=null;if(j.isFunction(a))return b.$super()?a.call(b):void(c=setInterval(function(){b.$super()&&(clearInterval(c),c=null,a.call(b))},10))}});q.prototype.constructor=q,a.Storage=q,a.localStorage=new q(function(){a.localStorage=new o})}}(window,window.document,window.location,window.navigator,void 0,"localStorage");