UNPKG

petjs

Version:

Router of ajax applications, HTML5 history API expansion for browsers who not supporting it

17 lines (15 loc) 21.1 kB
/**** petjs - router of ajax applications, HTML5 history API expansion for browsers who not supporting it * * @author Yaroslav Peteychuk <http://www.peteychuk.com/>, <peteychuk@gmail.com> * @homepage https://github.com/peteychuk/petjs * @copyright 2012-2014 by Peteychuk * @version 0.1.3 * @update 03-07-2014 * @includes HistoryAPI 4.0.2 (c) 2011-2013 by Dmitrii Pakhtinov * * Dual licensed under the MIT and GPL licenses: * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html * */ !function(window,True,False,Null,undefined){"use strict";var document=window.document,windowHistory=window.history||{},windowLocation=window.location,api=!!windowHistory.pushState,initialState=api&&windowHistory.state===undefined,initialFire=windowLocation.href,JSON=window.JSON||{},defineProp=Object.defineProperty,defineGetter=Object.prototype.__defineGetter__,defineSetter=Object.prototype.__defineSetter__,historyPushState=windowHistory.pushState,historyReplaceState=windowHistory.replaceState,sessionStorage=window.sessionStorage,hasOwnProperty=Object.prototype.hasOwnProperty,toString=Object.prototype.toString,msie=+((eval("/*@cc_on 1;@*/")&&/msie (\d+)/i.exec(navigator.userAgent)||[])[1]||0),libID=(new Date).getTime(),VBInc=(defineProp||defineGetter)&&(!msie||msie>8)?0:1,iframe=8>msie?document.createElement("iframe"):False,_a,_r,_d,eventPrefix="",addEvent=(_a="addEventListener",window[_a]||(_a="attachEvent",eventPrefix="on",window[_a])),removeEvent=(_r="removeEventListener",window[_r]||(_r="detachEvent",window[_r])),fireEvent=(_d="dispatchEvent",window[_d]||(_d="fireEvent",window[_d])),eventsListPopState=[],eventsListHashChange=[],skipHashChange=0,eventsList={onpopstate:eventsListPopState,popstate:eventsListPopState,onhashchange:eventsListHashChange,hashchange:eventsListHashChange},sets=function(){var a,b,c,d={basepath:"/",redirect:0,type:"/"},e=document.getElementsByTagName("SCRIPT");for(a=0;e[a];a++)if(b=/(.*)\/(?:history|spike)(?:-\d\.\d(?:\.\d)?\w?)?(?:\.min)?.js\?(.*)$/i.exec(e[a].src)||a===e.length-1&&2===(b=e[a].src.split("?")).length&&(b[2]=b[1])&&b){for(a=0,c=b[2].split("&");c[a];)b=c[a++].split("="),d[b[0]]="true"==b[1]?True:"false"==b[1]?False:b[1]||"";d.basepath=d.basepath||"/";break}return d}(),normalizeUrl=function(a){var b,c,d,e,f,g,h,i=new RegExp("^"+sets.basepath,"i");return function(j,k){if(j){if(!api){var l=normalizeUrl(),m=l._pathname,n=l._protocol;j=/^(?:[a-z]+\:)?\/\//.test(j)?0===j.indexOf("/")?n+j:j:n+"//"+l._host+(0===j.indexOf("/")?j:0===j.indexOf("?")?m+j:0===j.indexOf("#")?m+l._search+j:m.replace(/[^\/]+$/g,"")+j)}}else j=windowLocation.href,(!api||k)&&(j=windowLocation.protocol+"//"+windowLocation.host+sets.basepath+(j.replace(/^[^#]*/,"")||"#").replace(new RegExp("^#[/]?(?:"+sets.type+")?"),""));return b!==j&&(a.href=b=j,g=a.port,f=a.host,h=a.pathname,("http:"===a.protocol&&80==g||"https:"===a.protocol&&443==g)&&(f=a.hostname,g=""),h=0===h.indexOf("/")?h:"/"+h,c=h+a.search+a.hash,e=h.replace(i,sets.type)+a.search,d=e+a.hash),{_href:a.protocol+"//"+f+c,_protocol:a.protocol,_host:f,_hostname:a.hostname||windowLocation.hostname,_port:g||windowLocation.port,_pathname:h,_search:a.search,_hash:a.hash,_relative:c,_nohash:e,_special:d}}}(document.createElement("a")),History=VBInc?{back:windowHistory.back,forward:windowHistory.forward,go:windowHistory.go,pushState:Null,replaceState:Null,emulate:!api,toString:function(){return"[object History]"}}:windowHistory,HistoryAccessors={state:{get:function(){return iframe&&iframe.storage||historyStorage()[History.location.href]||Null}},length:{get:function(){return windowHistory.length}},location:{set:function(a){window.location=a},get:function(){return api?windowLocation:Location}}},Location={assign:function(a){windowLocation.assign(api||0!==a.indexOf("#")?a:"#"+normalizeUrl()._nohash+a)},reload:windowLocation.reload,replace:function(a){windowLocation.replace(api||0!==a.indexOf("#")?a:"#"+normalizeUrl()._nohash+a)},toString:function(){return this.href}},LocationAccessors={href:{set:function(a){windowLocation.href=a},get:function(){return normalizeUrl()._href}},protocol:{set:function(a){windowLocation.protocol=a},get:function(){return windowLocation.protocol}},host:{set:function(a){windowLocation.host=a},get:function(){return windowLocation.host}},hostname:{set:function(a){windowLocation.hostname=a},get:function(){return windowLocation.hostname}},port:{set:function(a){windowLocation.port=a},get:function(){return windowLocation.port}},pathname:{set:function(a){windowLocation.pathname=a},get:function(){return normalizeUrl()._pathname}},search:{set:function(a){windowLocation.search=a},get:function(){return normalizeUrl()._search}},hash:{set:function(a){var b=0===a.indexOf("#")?a:"#"+a,c=normalizeUrl();iframe?b!=c._hash&&(History.pushState(Null,Null,c._nohash+b),hashChanged({oldURL:c._href})):windowLocation.hash="#"+c._nohash+b},get:function(){return normalizeUrl()._hash}}},createStaticObject=function(a,b,c){var d,e=a,f=False;if(defineProp||defineGetter){for(d in b)if(hasOwnProperty.call(b,d))if(defineGetter)b[d].get&&defineGetter.call(a,d,b[d].get),b[d].set&&defineSetter.call(a,d,b[d].set);else if(defineProp)try{defineProp(a,d,b[d])}catch(g){if(c)return False;f=True;break}}else f=True;if(f&&VBInc){var h="StaticClass"+libID+VBInc++,i=["Class "+h];"execVB"in window||execScript("Function execVB(c) ExecuteGlobal(c) End Function","VBScript"),"VBCVal"in window||execScript("Function VBCVal(o,r) If IsObject(o) Then Set r=o Else r=o End If End Function","VBScript");for(d in a)i[i.length]="Public ["+d+"]";hasOwnProperty.call(a,"toString")&&(a.propertyIsEnumerable("toString")||(i[i.length]="Public [toString]"),b["(toString)"]={get:function(){return this.toString.call(this)}});for(d in b)hasOwnProperty.call(b,d)&&(b[d].get&&(a["get "+d]=b[d].get,i.push("Public [get "+d+"]","Public "+("(toString)"===d?"Default ":"")+"Property Get ["+d+"]","Call VBCVal(me.[get "+d+"].call(me),["+d+"])","End Property")),b[d].set&&(a["set "+d]=b[d].set,i.push("Public [set "+d+"]","Public Property Let ["+d+"](v)","Call me.[set "+d+"].call(me,v)","End Property","Public Property Set ["+d+"](v)","Call me.[set "+d+"].call(me,v)","End Property")));i.push("End Class","Function "+h+"Factory()","Set "+h+"Factory=New "+h,"End Function"),execVB(i.join("\n")),e=window[h+"Factory"]();for(d in a)e[d]=a[d];hasOwnProperty.call(a,"toString")&&(e.toString=a.toString)}return e},JSONStringify=JSON.stringify||function(a){function b(a){var b=/[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,c={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};return b.lastIndex=0,b.test(a)?'"'+a.replace(b,function(a){var b=c[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}var c=function(d){var e,f,g,h=(typeof d).charCodeAt(2);return 114===h?b(d):109===h?isFinite(d)?String(d):"null":111===h||108===h?String(d):106===h?function(){if(!d)return"null";if(e="[object Array]"===toString.apply(d),f=e?"[":"{",e)for(g=0;g<d.length;g++)f+=(0==g?"":",")+c(d[g]);else for(g in d)hasOwnProperty.call(d,g)&&d[g]!==a&&(f+=(1==f.length?"":",")+b(g)+":"+c(d[g]));return f+(e?"]":"}")}():a};return c}(),JSONParse=function(){var a=JSON.parse;return function(b){return b?a?a(b):new Function("return "+b)():Null}}(),historyStorage=function(a){return sessionStorage?a?sessionStorage.setItem("__hitoryapi__",JSONStringify(a)):JSONParse(sessionStorage.getItem("__hitoryapi__"))||{}:{}},fireStateChange=function(a,b,c){var d,e=2===a?window.onhashchange:window.onpopstate,f=2===a?"hashchange":"popstate",g=eventsList[f];document.createEvent?(d=document.createEvent("Events"),d.initEvent(f,False,False)):(d=document.createEventObject(),d.type=f),d.state=History.state,d.oldURL=b,d.newURL=c,e&&e.call(window,d);for(var h=0,i=g.length;i>h;h++)g[h].call(window,d)},hashChanged=function(){var a=window.onpopstate||Null,b=window.onhashchange||Null,c=0,d=Null,e=normalizeUrl(),f=e._href,g=(e._hash.replace(/^#/,""),function(){initialFire&&!(initialFire=0)&&e._relative!==sets.basepath&&(clearInterval(d),setTimeout(fireStateChange,10))}),h=function(a){var b=normalizeUrl();if(skipHashChange)return f=b._href,skipHashChange=0;var d=a.oldURL||f,e=f=a.newURL||b._href,g=d.replace(/^.*?(#|$)/,""),h=e.replace(/^.*?(#|$)/,"");d==e||c||fireStateChange(),c=0,initialFire=0,g!=h&&fireStateChange(2,d,e)};if(addEvent(eventPrefix+"hashchange",h,False),addEvent(eventPrefix+"popstate",function(){return initialFire===windowLocation.href?initialFire=0:(initialFire=0,void fireStateChange(c=1))},False),History.fixURL=function(a){return normalizeUrl(a)._relative},History=createStaticObject(History,VBInc?HistoryAccessors:windowHistory.state===undefined?{state:HistoryAccessors.state,location:HistoryAccessors.location}:{location:HistoryAccessors.location}),Location=createStaticObject(Location,LocationAccessors),window[_a]=function(a,b,c,d){eventsList[a]?(eventsList[a].push(b),api||eventsListPopState!==eventsList[a]||g()):addEvent(a,b,c,d)},window[_r]=function(a,b,c){var d=eventsList[a];if(d){for(var e=d.length;--e;)if(d[e]===b){d.splice(e,1);break}}else removeEvent(a,b,c)},window[_d]=function(a,b){var c=(a&&a.type||a,eventsList[a]),d=c===eventsListPopState?window.onpopstate:window.onhashchange;if(c){b=b||("string"==typeof a?window.event:a);try{b&&(b.target=window)}catch(e){try{b.srcElement=window}catch(e){}}d&&d.call(window,b);for(var f=0,g=c.length;g>f;f++)c[f].call(window,b);return True}return fireEvent(a,b)},VBInc&&execScript("Public history, onhashchange","VBScript"),(defineProp||defineGetter)&&createStaticObject(window,{onhashchange:{get:function(){return b},set:function(a){b=a||Null}},onpopstate:{get:function(){return a},set:function(b){(a=b||Null)&&!api&&g()}}},1)||api||(d=setInterval(function(){window.onpopstate&&g()},100)),sets.redirect&&window.top==window.self){var i=normalizeUrl(Null,True)._relative,j=windowLocation.search,k=windowLocation.pathname,l=sets.basepath;api?(i!=l&&new RegExp("^"+l+"$","i").test(k)&&(windowLocation.href=i),new RegExp("^"+l,"i").test(k)||(windowLocation.href=k.replace(/^\//,l)+j)):k!=l&&(windowLocation.href=l+"#"+k.replace(new RegExp("^"+l,"i"),sets.type)+j+windowLocation.hash)}return h}();History.pushState=function(a,b,c,d){var e=historyStorage(),f=normalizeUrl()._href,g=c&&normalizeUrl(c);initialFire=0,c=g?g._href:f,d&&e[f]&&delete e[f],(!api||initialState)&&sessionStorage&&a&&(e[c]=a,historyStorage(e),a=Null),historyPushState&&historyReplaceState?d?historyReplaceState.call(History,a,b,c):historyPushState.call(History,a,b,c):g&&g._relative!=normalizeUrl()._relative&&(skipHashChange=1,d?windowLocation.replace("#"+g._special):windowLocation.hash=g._special)},History.replaceState=function(a,b,c){History.pushState(a,b,c,1)},VBInc?(window.history=History,function(a,b){if(iframe){var c,d,e=function(){var a=normalizeUrl()._href;b!=a&&hashChanged({oldURL:b,newURL:b=a})};if(d=setInterval(e,100),iframe.src="javascript:true;",iframe=document.documentElement.firstChild.appendChild(iframe).contentWindow,History.pushState=c=function(a,f,g,h,i){var j=iframe.document,k=["<script>","lfirst=1;",,"storage="+JSONStringify(a)+";","</script>"],l=g&&normalizeUrl(g);return l?(i||clearInterval(d),h?iframe.lfirst?(history.back(),c(a,f,l._href,0,1)):(iframe.storage=a,windowLocation.replace("#"+l._special)):(l._href!=b||i)&&(iframe.lfirst||(iframe.lfirst=1,c(iframe.storage,f,b,0,1)),k[2]='parent.location.hash="'+l._special.replace(/"/g,'\\"')+'";',j.open(),j.write(k.join("")),j.close()),void(i||(b=normalizeUrl()._href,d=setInterval(e,100)))):void(iframe.storage=a)},addEvent(eventPrefix+"unload",function(){if(iframe.storage){var a={};a[normalizeUrl()._href]=iframe.storage,document.cookie="_historyAPI="+escape(JSONStringify(a))}clearInterval(d)},False),a.length>1){a=unescape(a.pop().split(";").shift());try{iframe.storage=JSONParse(a)[normalizeUrl()._href]}catch(f){}}JSON.parse||JSON.stringify||(JSON.parse=JSONParse,JSON.stringify=JSONStringify,window.JSON=JSON)}}(document.cookie.split("_historyAPI="),normalizeUrl()._href)):window.history.emulate=!api}(window,!0,!1,null),function(a){"use strict";var b=a.pet=function(){var c={},d={},e=d;return d.options={debug:!1,basePath:"/",collection404:!1},d.data={lastQuery:{},breakRequest:{lastLocation:"",breakTo:""},withControlPanel:!0},c.setSettings=function(a){b.extend(d.options,a)},c.getSettings=function(a){return e.options[a]},d.collection={},d.ready={options:{loaded:!1,readyList:[]},init:function(){var b=!1,c=function(){b||(b=!0,e.ready.loaded())};if(document.addEventListener)document.addEventListener("DOMContentLoaded",function(){c()},!1);else if(document.attachEvent){if(document.documentElement.doScroll&&a==a.top){var d=function(){if(!b&&document.body)try{document.documentElement.doScroll("left"),c()}catch(a){setTimeout(d,0)}};d()}document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&c()})}a.addEventListener?a.addEventListener("load",c,!1):a.attachEvent&&a.attachEvent("onload",c)},loaded:function(){if(history.emulate===!0&&a.location.pathname!=b.getSettings("basePath"))return void(a.location.href=b.getSettings("basePath")+"#"+a.location.pathname);e.setSettings();var c;b.ready(function(){e.nav.init()}),e.ready.options.loaded=!0;for(var d=0;d<e.ready.options.readyList.length;d++)(c=e.ready.options.readyList[d])()}},c.ready=function(a){return"function"==typeof a?e.ready.options.loaded?a():(e.ready.options.readyList.push(a),!0):void 0},d.nav={init:function(){e.router.ready(),a.onpopstate=function(){var b=a.history.location||a.location,c=b.pathname;return e.data.withControlPanel=!0,e.router.search(c,!1),!1}},setLoc:function(a,b){history.pushState(null,b,a)}},c.nav={go:function(b,c){if("undefined"!=typeof c&&"undefined"!=typeof c.which&&2===c.which)return!0;var d;if("object"==typeof b)d=b.href;else{if("string"!=typeof b)return!0;d=b}"undefined"!=typeof c&&c.preventDefault();var f=new RegExp("^(https?://"+a.location.host.replace(/([.?*+^$[\]\\(){}|-])/g,"\\$1")+")","i");return d=d.replace(f,""),0===d.search(/https?\:\/\//i)?(location.href=d,!1):(e.data.withControlPanel=!1,e.router.search(d,!0),"undefined"==typeof c?!1:void 0)},withControlPanel:function(){return e.data.withControlPanel?!0:!1}},d.router={options:{},search:function(a,c){if(e.data.breakRequest.lastLocation=b.router.getLocation(),e.data.lastQuery.finish===!1){e.data.lastQuery.aborted=!0,e.data.lastQuery.finish=!0,e.data.lastQuery.abort(),"function"==typeof e.data.lastQuery.abortOption&&e.data.lastQuery.abortOption();var d=e.getControl(e.data.breakRequest.breakTo);e.router.options.loc=e.data.breakRequest.breakTo,e.router.options.collection=d.collection,e.router.options.param=d.param,e.data.breakRequest.lastLocation=b.router.getLocation()}var d=e.getControl(a),f=d.collection,g=d.param;if(e.collection.hasOwnProperty(f))if(e.router.options.collection===f)if(a===b.router.getLocation())e.collection[f].refreshLocation();else{var h=e.router.options.param,i=e.router.options.loc;e.collection[f].beforeTryChangeLocation(),e.router.options.param=g,e.router.options.loc=a,e.collection[f].changeLocation(function(b){e.router.options.param=h,e.router.options.loc=i,e.collection[f].beforeChangeLocation(),e.router.options.param=g,e.router.options.loc=a,e.router.success(a,b,c)})}else{var h=e.router.options.param,i=e.router.options.loc,j=e.router.options.collection;e.collection[j].beforeTryAway(),e.router.options.param=g,e.router.options.loc=a,e.router.options.collection=f,e.collection[f].changeLocation(function(b){e.router.options.param=h,e.router.options.loc=i,e.router.options.collection=j,e.collection[e.router.options.collection].__destructor(),e.router.options.param=g,e.router.options.loc=a,e.router.options.collection=f,e.collection[e.router.options.collection].__constructor(),e.router.success(a,b,c)})}else if(e.options.collection404&&e.collection.hasOwnProperty(e.options.collection404)){var h=e.router.options.param,i=e.router.options.loc,j=e.router.options.collection;e.collection[j].beforeTryAway(),e.router.options.param=g,e.router.options.loc=a,e.router.options.collection=e.options.collection404,e.collection[e.options.collection404].changeLocation(function(b){e.router.options.param=h,e.router.options.loc=i,e.router.options.collection=j,e.collection[e.router.options.collection].__destructor(),e.router.options.param=g,e.router.options.loc=a,e.router.options.collection=e.options.collection404,e.collection[e.options.collection404].__constructor(),e.router.success(a,b,c)})}else location.href=a},ready:function(){e.collection.hasOwnProperty(e.router.options.collection)&&e.collection[e.router.options.collection].ready()},success:function(a,b,c){c&&e.nav.setLoc(a,b),document.title=b}},c.router={getSegment:function(a,b){return e.router.options.param[a]||b||!1},getSegments:function(){return e.router.options.param},getCollection:function(){return e.router.options.collection.toString()},getLocation:function(){return e.router.options.loc},getGet:function(){for(var b={},c=a.location.search.substring(1).split("&"),d=0;d<c.length;d++){var e=c[d].split("=");b[e[0]]="undefined"==typeof e[1]?"":e[1]}return b}},d.setSettings=function(){var a=document.location.pathname,b=e.getControl(a);e.router.options.loc=a,e.router.options.collection=b.collection,e.router.options.param=b.param},c.addCollection=function(a,c){var d={__constructor:function(){},__destructor:function(){},ready:function(){},beforeTryChangeLocation:function(){},beforeChangeLocation:function(){},beforeTryAway:function(){},changeLocation:function(a){a("Pet Framework by Peteychuk aka http://www.peteychuk.com/")},refreshLocation:function(){}};e.collection[a]=b.extend(d,c)},d.getControl=function(a){var b=a;b=b.replace(new RegExp("^("+e.options.basePath+")","gi"),""),b=b.replace(/^[\/]+/i,"").replace(/[\/]+$/i,"").replace(/\.html?$/i,"");var c="index",d=[];if(b.length>0){var f=b.split("/");c=f[0].replace(/^([a-z]+)*(.*)$/i,"$1").toLowerCase()||"index",d=f.slice(1,f.length)||[]}return{collection:c,param:d}},c.debug=function(b){e.options.debug===!0&&a.console&&a.console.log&&console.log(b)},c.ajax=function(a){return function(){var c,f,g=3e3,h=a.type?a.type.toUpperCase():"GET",i=a.url||!1,j=a.headers||[],k=a.data||!1,l=a.dataType||"txt",m=a.error||function(){},n=a.success||function(){},o=a.reConnect||function(){};if(!i)return!1;a.abort&&e.data.lastQuery.finish===!1&&(e.data.lastQuery.aborted=!0,e.data.lastQuery.finish=!0,e.data.lastQuery.abort(),"function"==typeof e.data.lastQuery.abortOption&&e.data.lastQuery.abortOption());try{c=new XMLHttpRequest}catch(p){try{c=new ActiveXObject("Msxml2.XMLHTTP")}catch(p){c=new ActiveXObject("Microsoft.XMLHTTP")}}try{var q=!1;if(c.onreadystatechange=function(){if(4==c.readyState){if(200!=c.status)return void(e.data.lastQuery.aborted!==!0&&(0==c.status?(q=!0,a.reConnect&&o(!1),setTimeout(function(){a.reConnect=!0,b.ajax(a)},g)):(q&&a.reConnect&&o(!0),b.debug("Ajax error status: "+c.status+"; URL: "+i),m(c,c.status,i))));q&&a.reConnect&&o(!0),a.abort&&(e.data.lastQuery.finish=!0),n("json"==l?e.parseJSON(c.responseText):c.responseText)}},c.open(h,i,!0),"GET"==h?f=null:(j.push(["Content-type","application/x-www-form-urlencoded; charset=utf-8"]),f=k?e.ajaxUrlEncodeData(k):null),(-1!=i.search(/^\//i)||0===i.search(new RegExp("^https?://"+location.host+"/","i")))&&j.push(["X-Requested-With","XMLHttpRequest"]),j.length)for(var r=0,s=j.length;s>r;r++)c.setRequestHeader(j[r][0],j[r][1]);c.send(f),"undefined"!=typeof a.abort&&(e.data.lastQuery=c,e.data.lastQuery.finish=!1,e.data.lastQuery.abortOption=a.abort,e.data.breakRequest.breakTo=e.data.breakRequest.lastLocation)}catch(p){if(d.options.debug)throw p;b.debug(p)}return c}()},d.ajaxUrlEncodeData=function(a){var b=[],c="";for(var d in a)"string"==typeof a[d]||"number"==typeof a[d]||"boolean"==typeof a[d]?b.push(d+"="+encodeURIComponent(a[d])):null!==a[d]&&a[d].length&&(c+=(c?"&":"")+urlEncodeData2tree(d,a[d]));return(b.length?b.join("&"):b[0])+(c?"&"+c:"")},d.ajaxUrlEncodeDataStep2=function(a,b){var c=[];for(var d in b)"string"==typeof b[d]||"number"==typeof b[d]||"boolean"==typeof b[d]?c.push(a+"["+d+"]="+encodeURIComponent(b[d])):b[d].length&&c.push(urlEncodeData2tree(a+"["+d+"]",b[d]));return c.length?c.join("&"):""},d.parseJSON=function(b){if("string"!=typeof b||!b||""==b)return null;if(b=b.replace(/^\s+/,""),b=b.replace(/\s+$/,""),a.JSON&&a.JSON.parse)return a.JSON.parse(b);var c=/^[\],:{}\s]*$/,d=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,e=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,f=/(?:^|:|,)(?:\s*\[)+/g;return c.test(b.replace(d,"@").replace(e,"]").replace(f,""))?new Function("return "+b)():void 0},c.extend=function(a,b){var c=function(){};c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a,a.superclass=b.prototype;for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);return a},function(){return history.emulate!==!0&&""!=a.location.hash?void(a.location.href=a.location.hash.replace("#","")):void e.ready.init()}(),c}()}(window);