igor-alexandrov/wiselinks

View on GitHub
build/wiselinks-1.2.2.min.js

Summary

Maintainability
A
0 mins
Test Coverage
/*
 2012-2014 Igor Alexandrov, Alexey Solilin, Julia Egorova, Alexandr Borisov
 @preserve https://github.com/igor-alexandrov/wiselinks
 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
 @license New BSD License <http://creativecommons.org/licenses/BSD/>
 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
 @license New BSD License <http://creativecommons.org/licenses/BSD/>
 Public Domain
 @author Benjamin Arthur Lupton <contact@balupton.com>
 @author James Padolsey <https://gist.github.com/527683>
 Public Domain
 @author Benjamin Arthur Lupton <contact@balupton.com>
 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
 @license New BSD License <http://creativecommons.org/licenses/BSD/>
*/
(function(){var f;f=function(){function d(){}d.prototype.parse=function(b){return this._get_parser()(b)};d.prototype._get_parser=function(){return null!=this._document_parser?this._document_parser:this._document_parser=this._parser_factory()};d.prototype._parser_factory=function(){var b,e,c,g,l;e=function(c){return(new d).parseFromString(c,"text/html")};b=function(c){var b;b=document.implementation.createHTMLDocument("");b.documentElement.innerHTML=c;return b};c=function(c){var b;b=document.implementation.createHTMLDocument("");
b.open("replace");b.write(c);b.close();return b};try{if(window.DOMParser)return g=e("<html><body><p>test"),e}catch(f){return g=b("<html><body><p>test"),b}finally{if(1!==(null!=g?null!=(l=g.body)?l.childNodes.length:void 0:void 0))return c}};return d}();null==window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.DOMParser=f;f=function(){function d(b,e){this.page=b;this.$form=e}d.prototype.process=function(){var b;b=this;return b._include_blank_url_params()?b.page.load(b._url(),b._target(),b._type()):
b._without_blank_url_params(function(){return b.page.load(b._url(),b._target(),b._type())})};d.prototype._without_blank_url_params=function(b){var e;e=this.$form.find("select:not(:disabled),input:not(:disabled)").filter(function(){return!$(this).val()});e.attr("disabled",!0);b();return e.attr("disabled",!1)};d.prototype._params=function(){var b,e,c,g,d,f;b={};f=this.$form.serializeArray();g=0;for(d=f.length;g<d;g++)e=f[g],"utf8"!==e.name&&(c=-1!==e.name.indexOf("[]",e.name.length-2)?e.name.substr(0,
e.name.length-2):e.name,b[c]=null!=b[c]?b[c]+(","+e.value):e.value);return b};d.prototype._include_blank_url_params=function(){return!0===this.$form.data("include-blank-url-params")};d.prototype._optimize_url_params=function(){return!1!==this.$form.data("optimize-url-params")};d.prototype._type=function(){return"partial"===this.$form.data("push")?"partial":"template"};d.prototype._target=function(){return this.$form.data("target")};d.prototype._url=function(){var b,e,c;var g;if(this._optimize_url_params()){e=
[];g=this._params();for(b in g)c=g[b],e.push(""+b+"="+encodeURIComponent(c).replace(/%2C/g,","));b=e.join("&")}else b=this.$form.serialize();e=this.$form.attr("action").replace(/\?.*$/,"");0<b.length&&(e+="?"+b);return e};return d}();null==window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.Form=f;f=function(){function d(b,e){this.page=b;this.$link=e}d.prototype.allows_process=function(b){return!(this._cross_origin_link(b.currentTarget)||this._non_standard_click(b))};d.prototype.process=function(){var b;
b="partial"===this.$link.data("push")?"partial":"template";return this.page.load(this.$link.attr("href"),this.$link.data("target"),b)};d.prototype._cross_origin_link=function(b){return this._different_protocol(b)||this._different_host(b)||this._different_port(b)};d.prototype._different_protocol=function(b){return":"===b.protocol||""===b.protocol?!1:location.protocol!==b.protocol};d.prototype._different_host=function(b){return""===b.host?!1:location.host.split(":")[0]!==b.host.split(":")[0]};d.prototype._different_port=
function(b){return!(location.port===b.port||""===location.port&&("80"===b.port||"443"===b.port))};d.prototype._non_standard_click=function(b){return b.metaKey||b.ctrlKey||b.shiftKey||b.altKey};return d}();void 0===window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.Link=f;f=function(){function d(b,e){var c;this.$target=b;this.options=e;c=this;this.template_id=(new Date).getTime();this.request_manager=new _Wiselinks.RequestManager(this.options);this.$target=c._wrap(this.$target);c._try_target(this.$target);
History.emulated.pushState&&!0===this.options.html4&&(-1===window.location.href.indexOf("#.")&&!0===this.options.html4_normalize_path&&window.location.pathname!==this.options.html4_root_path)&&(window.location.href=""+window.location.protocol+"//"+window.location.host+this.options.html4_root_path+"#."+window.location.pathname);History.Adapter.bind(window,"statechange",function(b,e){var d;d=History.getState();return c._template_id_changed(d)?c._call(c._reset_state(d)):c._call(d)});$(document).on("click",
"a[data-push], a[data-replace]",function(b){var e;if((e=new _Wiselinks.Link(c,$(this))).allows_process(b))return b.preventDefault(),e.process(),!1});$(document).on("submit","form[data-push], form[data-replace]",function(b){var e;if(e=new _Wiselinks.Form(c,$(this)))return b.preventDefault(),e.process(),!1})}d.prototype.load=function(b,e,c){var g;null==c&&(c="template");"partial"!==c&&(this.template_id=(new Date).getTime());e=null!=e?(g=this._wrap(e),this._try_target(g),g.selector):void 0;return History.pushState({timestamp:(new Date).getTime(),
template_id:this.template_id,render:c,target:e,referer:window.location.href},document.title,b)};d.prototype.reload=function(){return History.replaceState({timestamp:(new Date).getTime(),template_id:this.template_id,render:"template",referer:window.location.href},document.title,History.getState().url)};d.prototype._call=function(b){var e;e=null!=b.data.target?$(b.data.target):this.$target;return this.request_manager.call(e,b)};d.prototype._template_id_changed=function(b){return null==b.data.template_id||
b.data.template_id!==this.template_id};d.prototype._make_state=function(b,e,c,g){null==c&&(c="template");return{url:b,data:{target:e,render:c,referer:g}}};d.prototype._reset_state=function(b){null==b.data&&(b.data={});b.data.target=null;b.data.render="template";return b};d.prototype._try_target=function(b){if(0===b.length&&"exception"===this.options.target_missing)throw Error("[Wiselinks] Target missing: `"+b.selector+"`");};d.prototype._wrap=function(b){return $(b)};return d}();void 0===window._Wiselinks&&
(window._Wiselinks={});window._Wiselinks.Page=f;f=function(){function d(b){this.options=null!=b?b:{}}d.prototype.call=function(b,e){var c;c=this;if(null!=this.redirected)this.redirected=null;else return c._loading(b,e),$.ajax({url:e.url,headers:{"X-Wiselinks":e.data.render,"X-Wiselinks-Referer":e.data.referer},dataType:"html"}).done(function(g,e,d){return c._html_loaded(b,g,e,d)}).fail(function(g,d,f){return c._fail(b,d,e,f,g.status,g.responseText)}).always(function(g,d,f){return c._always(b,d,e)})};
d.prototype._normalize=function(b){if(null!=b)return b=b.replace(/\/+$/,"")};d.prototype._assets_changed=function(b){return null!=this.options.assets_digest&&this.options.assets_digest!==b};d.prototype._redirect_to=function(b,e,c,g){g&&4>g.readyState&&(g.onreadystatechange=$.noop,g.abort());this.redirected=!0;$(document).trigger("page:redirected",[e,c.data.render,b]);return History.replaceState(c.data,document.title,b)};d.prototype._loading=function(b,e){return $(document).trigger("page:loading",
[b,e.data.render,decodeURI(e.url)])};d.prototype._done=function(b,e,c,g){return $(document).trigger("page:done",[b,e,decodeURI(c.url),g])};d.prototype._html_loaded=function(b,e,c,g){var d,f,h;d=new window._Wiselinks.Response(e,g,b);h=this._normalize(d.url());e=d.assets_digest();if(this._assets_changed(e))return window.location.reload(!0);f=History.getState();null!=h&&h!==this._normalize(f.url)&&this._redirect_to(h,b,f,g);return b.html(d.content()).promise().done(function(e){return function(){e._title(d.title());
e._description(d.description());e._canonical(d.canonical());e._robots(d.robots());e._link_rel_prev(d.link_rel_prev());e._link_rel_next(d.link_rel_next());return e._done(b,c,f,d.content())}}(this))};d.prototype._fail=function(b,e,c,d,f,m){return $(document).trigger("page:fail",[b,e,decodeURI(c.url),d,f,m])};d.prototype._always=function(b,e,c){return $(document).trigger("page:always",[b,e,decodeURI(c.url)])};d.prototype._title=function(b){if(null!=b)return $(document).trigger("page:title",decodeURI(b)),
document.title=decodeURI(b)};d.prototype._description=function(b){if(null!=b)return $(document).trigger("page:description",decodeURI(b)),$('meta[name="description"]').attr("content",decodeURI(b))};d.prototype._canonical=function(b){if(null!=b)return $(document).trigger("page:canonical",decodeURI(b)),$('link[rel="canonical"]').attr("href",decodeURI(b))};d.prototype._robots=function(b){if(null!=b)return $(document).trigger("page:robots",decodeURI(b)),$('meta[name="robots"]').attr("content",decodeURI(b))};
d.prototype._link_rel_prev=function(b){if(null!=b)return $(document).trigger("page:link_rel_prev",decodeURI(b)),$('link[rel="prev"]').attr("href",decodeURI(b))};d.prototype._link_rel_next=function(b){if(null!=b)return $(document).trigger("page:link_rel_next",decodeURI(b)),$('link[rel="next"]').attr("href",decodeURI(b))};return d}();void 0===window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.RequestManager=f;f=function(){function d(b,e,c){this.html=b;this.xhr=e;this.$target=c}d._document_parser=
null;d._get_document_parser=function(){return null!=d._document_parser?d._document_parser:d._document_parser=new window._Wiselinks.DOMParser};d.prototype.url=function(){return this.xhr.getResponseHeader("X-Wiselinks-Url")};d.prototype.assets_digest=function(){return this._is_full_document_response()?$('meta[name="assets-digest"]',this._get_doc()).attr("content"):this.xhr.getResponseHeader("X-Wiselinks-Assets-Digest")};d.prototype.content=function(){return null!=this._content?this._content:this._content=
this._extract_content()};d.prototype.title=function(){return null!=this._title?this._title:this._title=this._extract_title()};d.prototype._extract_title=function(){return this._is_full_document_response()?$("title",this._get_doc()).text():this.xhr.getResponseHeader("X-Wiselinks-Title")};d.prototype.description=function(){return null!=this._description?this._description:this._description=this._extract_description()};d.prototype._extract_description=function(){return this._is_full_document_response()?
$('meta[name="description"]',this._get_doc()).text():this.xhr.getResponseHeader("X-Wiselinks-Description")};d.prototype.canonical=function(){return null!=this._canonical?this._canonical:this._canonical=this._extract_canonical()};d.prototype._extract_canonical=function(){return this._is_full_document_response()?$('link[rel="canonical"]',this._get_doc()).text():this.xhr.getResponseHeader("X-Wiselinks-Canonical")};d.prototype.robots=function(){return null!=this._robots?this._robots:this._robots=this._extract_robots()};
d.prototype._extract_robots=function(){return this._is_full_document_response()?$('meta[name="robots"]',this._get_doc()).text():this.xhr.getResponseHeader("X-Wiselinks-Robots")};d.prototype.link_rel_prev=function(){return null!=this._link_rel_prev?this._link_rel_prev:this._link_rel_prev=this._extract_link_rel_prev()};d.prototype._extract_link_rel_prev=function(){return this._is_full_document_response()?$('link[rel="prev"]',this._get_doc()).text():this.xhr.getResponseHeader("X-Wiselinks-LinkRelPrev")};
d.prototype.link_rel_next=function(){return null!=this._link_rel_next?this._link_rel_next:this._link_rel_next=this._extract_link_rel_next()};d.prototype._extract_link_rel_next=function(){return this._is_full_document_response()?$('link[rel="next"]',this._get_doc()).text():this.xhr.getResponseHeader("X-Wiselinks-LinkRelNext")};d.prototype._extract_content=function(){return this._is_full_document_response()?this._get_doc_target_node().html():this.html};d.prototype._is_full_document_response=function(){return 1===
this._get_doc_target_node().length};d.prototype._get_doc_target_node=function(){return null!=this.$doc_target_node?this.$doc_target_node:this.$doc_target_node=$(this.$target.selector,this._get_doc())};d.prototype._get_doc=function(){return null!=this._doc?this._doc:this._doc=d._get_document_parser().parse(this.html)};return d}();null==window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.Response=f;f=function(){function d(b,e){null==b&&(b=$("body"));this.options=null!=e?e:{};this._try_jquery();
this.options=$.extend(this._defaults(),this.options);this.enabled()&&(this.options.disable_suid&&(History.options.disableSuid=!0),this.page=new _Wiselinks.Page(b,this.options))}d.prototype.enabled=function(){return!History.emulated.pushState||!0===this.options.html4};d.prototype.load=function(b,e,c){null==c&&(c="template");return this.page.load(b,e,c)};d.prototype.reload=function(){return this.page.reload()};d.prototype._defaults=function(){return{disable_suid:!0,html4:!0,html4_root_path:"/",html4_normalize_path:!0,
target_missing:null,assets_digest:$("meta[name='assets-digest']").attr("content")}};d.prototype._try_jquery=function(){if(null==window.jQuery)throw Error("[Wiselinks] jQuery is not loaded");};return d}();window.Wiselinks=f}).call(this);"object"!==typeof JSON&&(JSON={});
(function(){function f(c){return 10>c?"0"+c:c}function d(b){c.lastIndex=0;return c.test(b)?'"'+b.replace(c,function(c){var b=m[c];return"string"===typeof b?b:"\\u"+("0000"+c.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+b+'"'}function b(c,e){var f,a,m,u,t=g,q,k=e[c];k&&("object"===typeof k&&"function"===typeof k.toJSON)&&(k=k.toJSON(c));"function"===typeof h&&(k=h.call(e,c,k));switch(typeof k){case "string":return d(k);case "number":return isFinite(k)?String(k):"null";case "boolean":case "null":return String(k);
case "object":if(!k)return"null";g+=l;q=[];if("[object Array]"===Object.prototype.toString.apply(k)){u=k.length;for(f=0;f<u;f+=1)q[f]=b(f,k)||"null";m=0===q.length?"[]":g?"[\n"+g+q.join(",\n"+g)+"\n"+t+"]":"["+q.join(",")+"]";g=t;return m}if(h&&"object"===typeof h)for(u=h.length,f=0;f<u;f+=1)"string"===typeof h[f]&&(a=h[f],(m=b(a,k))&&q.push(d(a)+(g?": ":":")+m));else for(a in k)Object.prototype.hasOwnProperty.call(k,a)&&(m=b(a,k))&&q.push(d(a)+(g?": ":":")+m);m=0===q.length?"{}":g?"{\n"+g+q.join(",\n"+
g)+"\n"+t+"}":"{"+q.join(",")+"}";g=t;return m}}"function"!==typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(c){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(c){return this.valueOf()});var e=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
c=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,g,l,m={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},h;"function"!==typeof JSON.stringify&&(JSON.stringify=function(c,e,d){var a;l=g="";if("number"===typeof d)for(a=0;a<d;a+=1)l+=" ";else"string"===typeof d&&(l=d);if((h=e)&&"function"!==typeof e&&("object"!==typeof e||"number"!==typeof e.length))throw Error("JSON.stringify");return b("",{"":c})});
"function"!==typeof JSON.parse&&(JSON.parse=function(c,b){function d(a,c){var e,g,k=a[c];if(k&&"object"===typeof k)for(e in k)Object.prototype.hasOwnProperty.call(k,e)&&(g=d(k,e),void 0!==g?k[e]=g:delete k[e]);return b.call(a,c,k)}var a;c=String(c);e.lastIndex=0;e.test(c)&&(c=c.replace(e,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(c.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return a=eval("("+c+")"),"function"===typeof b?d({"":a},""):a;throw new SyntaxError("JSON.parse");})})();
(function(f,d){var b=f.History=f.History||{};if("undefined"!==typeof b.Adapter)throw Error("History.js Adapter has already been loaded...");b.Adapter={handlers:{},_uid:1,uid:function(e){return e._uid||(e._uid=b.Adapter._uid++)},bind:function(e,c,d){var f=b.Adapter.uid(e);b.Adapter.handlers[f]=b.Adapter.handlers[f]||{};b.Adapter.handlers[f][c]=b.Adapter.handlers[f][c]||[];b.Adapter.handlers[f][c].push(d);e["on"+c]=function(c,e){return function(d){b.Adapter.trigger(c,e,d)}}(e,c)},trigger:function(e,
c,d){d=d||{};e=b.Adapter.uid(e);var f,m;b.Adapter.handlers[e]=b.Adapter.handlers[e]||{};b.Adapter.handlers[e][c]=b.Adapter.handlers[e][c]||[];f=0;for(m=b.Adapter.handlers[e][c].length;f<m;++f)b.Adapter.handlers[e][c][f].apply(this,[d])},extractEventData:function(b,c){return c&&c[b]||d},onDomLoad:function(b){var c=f.setTimeout(function(){b()},2E3);f.onload=function(){clearTimeout(c);b()}}};"undefined"!==typeof b.init&&b.init()})(window);
(function(f,d){var b=f.document,e=f.setInterval||e,c=f.History=f.History||{};if("undefined"!==typeof c.initHtml4)throw Error("History.js HTML4 Support has already been loaded...");c.initHtml4=function(){if("undefined"!==typeof c.initHtml4.initialized)return!1;c.initHtml4.initialized=!0;c.enabled=!0;c.savedHashes=[];c.isLastHash=function(b){var d=c.getHashByIndex();return b===d};c.isHashEqual=function(c,b){c=encodeURIComponent(c).replace(/%25/g,"%");b=encodeURIComponent(b).replace(/%25/g,"%");return c===
b};c.saveHash=function(b){if(c.isLastHash(b))return!1;c.savedHashes.push(b);return!0};c.getHashByIndex=function(b){var d=null;return d="undefined"===typeof b?c.savedHashes[c.savedHashes.length-1]:0>b?c.savedHashes[c.savedHashes.length+b]:c.savedHashes[b]};c.discardedHashes={};c.discardedStates={};c.discardState=function(b,d,e){var f=c.getHashByState(b);c.discardedStates[f]={discardedState:b,backState:e,forwardState:d};return!0};c.discardHash=function(b,d,e){c.discardedHashes[b]={discardedHash:b,backState:e,
forwardState:d};return!0};c.discardedState=function(b){b=c.getHashByState(b);return c.discardedStates[b]||!1};c.discardedHash=function(b){return c.discardedHashes[b]||!1};c.recycleState=function(b){var d=c.getHashByState(b);c.discardedState(b)&&delete c.discardedStates[d];return!0};c.emulated.hashChange&&(c.hashChangeInit=function(){c.checkerFunction=null;var d="",l,m,h,n=Boolean(c.getHash());c.isInternetExplorer()?(l=b.createElement("iframe"),l.setAttribute("id","historyjs-iframe"),l.setAttribute("src",
"#"),l.style.display="none",b.body.appendChild(l),l.contentWindow.document.open(),l.contentWindow.document.close(),m="",h=!1,c.checkerFunction=function(){if(h)return!1;h=!0;var b=c.getHash(),e=c.getHash(l.contentWindow.document);b!==d?(d=b,e!==b&&(m=b,l.contentWindow.document.open(),l.contentWindow.document.close(),l.contentWindow.document.location.hash=c.escapeHash(b)),c.Adapter.trigger(f,"hashchange")):e!==m&&(m=e,n&&""===e?c.back():c.setHash(e,!1));h=!1;return!0}):c.checkerFunction=function(){var b=
c.getHash()||"";b!==d&&(d=b,c.Adapter.trigger(f,"hashchange"));return!0};c.intervalList.push(e(c.checkerFunction,c.options.hashChangeInterval));return!0},c.Adapter.onDomLoad(c.hashChangeInit));c.emulated.pushState&&(c.onHashChange=function(b){b=b&&b.newURL||c.getLocationHref();var d=c.getHashByUrl(b);b=null;if(c.isLastHash(d))return c.busy(!1),!1;c.doubleCheckComplete();c.saveHash(d);if(d&&c.isTraditionalAnchor(d))return c.Adapter.trigger(f,"anchorchange"),c.busy(!1),!1;b=c.extractState(c.getFullUrl(d||
c.getLocationHref()),!0);if(c.isLastSavedState(b))return c.busy(!1),!1;c.getHashByState(b);if(d=c.discardedState(b))return c.getHashByIndex(-2)===c.getHashByState(d.forwardState)?c.back(!1):c.forward(!1),!1;c.pushState(b.data,b.title,encodeURI(b.url),!1);return!0},c.Adapter.bind(f,"hashchange",c.onHashChange),c.pushState=function(b,d,e,h){e=encodeURI(e).replace(/%25/g,"%");if(c.getHashByUrl(e))throw Error("History.js does not support states with fragment-identifiers (hashes/anchors).");if(!1!==h&&
c.busy())return c.pushQueue({scope:c,callback:c.pushState,args:arguments,queue:h}),!1;c.busy(!0);var n=c.createStateObject(b,d,e),p=c.getHashByState(n),r=c.getState(!1),r=c.getHashByState(r),a=c.getHash(),s=c.expectedStateId==n.id;c.storeState(n);c.expectedStateId=n.id;c.recycleState(n);c.setTitle(n);if(p===r)return c.busy(!1),!1;c.saveState(n);s||c.Adapter.trigger(f,"statechange");c.isHashEqual(p,a)||c.isHashEqual(p,c.getShortUrl(c.getLocationHref()))||c.setHash(p,!1);c.busy(!1);return!0},c.replaceState=
function(b,d,e,h){e=encodeURI(e).replace(/%25/g,"%");if(c.getHashByUrl(e))throw Error("History.js does not support states with fragment-identifiers (hashes/anchors).");if(!1!==h&&c.busy())return c.pushQueue({scope:c,callback:c.replaceState,args:arguments,queue:h}),!1;c.busy(!0);var n=c.createStateObject(b,d,e),p=c.getHashByState(n),r=c.getState(!1),a=c.getHashByState(r),s=c.getStateByIndex(-2);c.discardState(r,n,s);p===a?(c.storeState(n),c.expectedStateId=n.id,c.recycleState(n),c.setTitle(n),c.saveState(n),
c.Adapter.trigger(f,"statechange"),c.busy(!1)):c.pushState(n.data,n.title,n.url,!1);return!0});if(c.emulated.pushState&&c.getHash()&&!c.emulated.hashChange)c.Adapter.onDomLoad(function(){c.Adapter.trigger(f,"hashchange")})};"undefined"!==typeof c.init&&c.init()})(window);
(function(f,d){var b=f.console||d,e=f.document,c=f.navigator,g=f.sessionStorage||!1,l=f.setTimeout,m=f.clearTimeout,h=f.setInterval,n=f.clearInterval,p=f.JSON,r=f.alert,a=f.History=f.History||{},s=f.history;try{g.setItem("TEST","1"),g.removeItem("TEST")}catch(u){g=!1}p.stringify=p.stringify||p.encode;p.parse=p.parse||p.decode;if("undefined"!==typeof a.init)throw Error("History.js Core has already been loaded...");a.init=function(b){if("undefined"===typeof a.Adapter)return!1;"undefined"!==typeof a.initCore&&
a.initCore();"undefined"!==typeof a.initHtml4&&a.initHtml4();return!0};a.initCore=function(t){if("undefined"!==typeof a.initCore.initialized)return!1;a.initCore.initialized=!0;a.options=a.options||{};a.options.hashChangeInterval=a.options.hashChangeInterval||100;a.options.safariPollInterval=a.options.safariPollInterval||500;a.options.doubleCheckInterval=a.options.doubleCheckInterval||500;a.options.disableSuid=a.options.disableSuid||!1;a.options.storeInterval=a.options.storeInterval||1E3;a.options.busyDelay=
a.options.busyDelay||250;a.options.debug=a.options.debug||!1;a.options.initialTitle=a.options.initialTitle||e.title;a.options.html4Mode=a.options.html4Mode||!1;a.options.delayInit=a.options.delayInit||!1;a.intervalList=[];a.clearAllIntervals=function(){var b,c=a.intervalList;if("undefined"!==typeof c&&null!==c){for(b=0;b<c.length;b++)n(c[b]);a.intervalList=null}};a.debug=function(){a.options.debug&&a.log.apply(a,arguments)};a.log=function(){var a=!("undefined"===typeof b||"undefined"===typeof b.log||
"undefined"===typeof b.log.apply),c=e.getElementById("log"),d,f,g,h;a?(f=Array.prototype.slice.call(arguments),d=f.shift(),"undefined"!==typeof b.debug?b.debug.apply(b,[d,f]):b.log.apply(b,[d,f])):d="\n"+arguments[0]+"\n";f=1;for(g=arguments.length;f<g;++f){h=arguments[f];if("object"===typeof h&&"undefined"!==typeof p)try{h=p.stringify(h)}catch(l){}d+="\n"+h+"\n"}c?(c.value+=d+"\n-----\n",c.scrollTop=c.scrollHeight-c.clientHeight):a||r(d);return!0};a.getInternetExplorerMajorVersion=function(){var b=
a.getInternetExplorerMajorVersion,c;if("undefined"!==typeof a.getInternetExplorerMajorVersion.cached)c=a.getInternetExplorerMajorVersion.cached;else{c=3;for(var d=e.createElement("div"),f=d.getElementsByTagName("i");(d.innerHTML="\x3c!--[if gt IE "+ ++c+"]><i></i><![endif]--\x3e")&&f[0];);c=4<c?c:!1}return b.cached=c};a.isInternetExplorer=function(){return a.isInternetExplorer.cached="undefined"!==typeof a.isInternetExplorer.cached?a.isInternetExplorer.cached:Boolean(a.getInternetExplorerMajorVersion())};
a.emulated=a.options.html4Mode?{pushState:!0,hashChange:!0}:{pushState:!Boolean(f.history&&f.history.pushState&&f.history.replaceState&&!(/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(c.userAgent)||/AppleWebKit\/5([0-2]|3[0-2])/i.test(c.userAgent))),hashChange:Boolean(!("onhashchange"in f||"onhashchange"in e)||a.isInternetExplorer()&&8>a.getInternetExplorerMajorVersion())};a.enabled=!a.emulated.pushState;a.bugs={setHash:Boolean(!a.emulated.pushState&&"Apple Computer, Inc."===c.vendor&&/AppleWebKit\/5([0-2]|3[0-3])/.test(c.userAgent)),
safariPoll:Boolean(!a.emulated.pushState&&"Apple Computer, Inc."===c.vendor&&/AppleWebKit\/5([0-2]|3[0-3])/.test(c.userAgent)),ieDoubleCheck:Boolean(a.isInternetExplorer()&&8>a.getInternetExplorerMajorVersion()),hashEscape:Boolean(a.isInternetExplorer()&&7>a.getInternetExplorerMajorVersion())};a.isEmptyObject=function(a){for(var b in a)if(a.hasOwnProperty(b))return!1;return!0};a.cloneObject=function(a){a?(a=p.stringify(a),a=p.parse(a)):a={};return a};a.getRootUrl=function(){var a=e.location.protocol+
"//"+(e.location.hostname||e.location.host);e.location.port&&(a+=":"+e.location.port);return a+"/"};a.getBaseHref=function(){var a=e.getElementsByTagName("base"),b=null,b="";1===a.length&&(b=a[0],b=b.href.replace(/[^\/]+$/,""));(b=b.replace(/\/+$/,""))&&(b+="/");return b};a.getBaseUrl=function(){return a.getBaseHref()||a.getBasePageUrl()||a.getRootUrl()};a.getPageUrl=function(){return((a.getState(!1,!1)||{}).url||a.getLocationHref()).replace(/\/+$/,"").replace(/[^\/]+$/,function(a,b,c){return/\./.test(a)?
a:a+"/"})};a.getBasePageUrl=function(){return a.getLocationHref().replace(/[#\?].*/,"").replace(/[^\/]+$/,function(a,b,c){return/[^\/]$/.test(a)?"":a}).replace(/\/+$/,"")+"/"};a.getFullUrl=function(b,c){var d=b,e=b.substring(0,1);c="undefined"===typeof c?!0:c;/[a-z]+\:\/\//.test(b)||(d="/"===e?a.getRootUrl()+b.replace(/^\/+/,""):"#"===e?a.getPageUrl().replace(/#.*/,"")+b:"?"===e?a.getPageUrl().replace(/[\?#].*/,"")+b:c?a.getBaseUrl()+b.replace(/^(\.\/)+/,""):a.getBasePageUrl()+b.replace(/^(\.\/)+/,
""));return d.replace(/\#$/,"")};a.getShortUrl=function(b){var c=a.getBaseUrl(),d=a.getRootUrl();a.emulated.pushState&&(b=b.replace(c,""));b=b.replace(d,"/");return b=("./"+b).replace(/^(\.\/)+/g,"./").replace(/\#$/,"")};a.getLocationHref=function(a){a=a||e;return a.URL===a.location.href?a.location.href:a.location.href===decodeURIComponent(a.URL)?a.URL:a.location.hash&&decodeURIComponent(a.location.href.replace(/^[^#]+/,""))===a.location.hash||-1==a.URL.indexOf("#")&&-1!=a.location.href.indexOf("#")?
a.location.href:a.URL||a.location.href};a.store={};a.idToState=a.idToState||{};a.stateToId=a.stateToId||{};a.urlToId=a.urlToId||{};a.storedStates=a.storedStates||[];a.savedStates=a.savedStates||[];a.normalizeStore=function(){a.store.idToState=a.store.idToState||{};a.store.urlToId=a.store.urlToId||{};a.store.stateToId=a.store.stateToId||{}};a.getState=function(b,c){"undefined"===typeof b&&(b=!0);"undefined"===typeof c&&(c=!0);var d=a.getLastSavedState();!d&&c&&(d=a.createStateObject());b&&(d=a.cloneObject(d),
d.url=d.cleanUrl||d.url);return d};a.getIdByState=function(b){var c=a.extractId(b.url),d;if(!c)if(d=a.getStateString(b),"undefined"!==typeof a.stateToId[d])c=a.stateToId[d];else if("undefined"!==typeof a.store.stateToId[d])c=a.store.stateToId[d];else{for(;c=(new Date).getTime()+String(Math.random()).replace(/\D/g,""),"undefined"!==typeof a.idToState[c]||"undefined"!==typeof a.store.idToState[c];);a.stateToId[d]=c;a.idToState[c]=b}return c};a.normalizeState=function(b){var c;b&&"object"===typeof b||
(b={});if("undefined"!==typeof b.normalized)return b;b.data&&"object"===typeof b.data||(b.data={});c={normalized:!0};c.title=b.title||"";c.url=a.getFullUrl(b.url?b.url:a.getLocationHref());c.hash=a.getShortUrl(c.url);c.data=a.cloneObject(b.data);c.id=a.getIdByState(c);c.cleanUrl=c.url.replace(/\??\&_suid.*/,"");c.url=c.cleanUrl;b=!a.isEmptyObject(c.data);(c.title||b)&&!0!==a.options.disableSuid&&(c.hash=a.getShortUrl(c.url).replace(/\??\&_suid.*/,""),/\?/.test(c.hash)||(c.hash+="?"),c.hash+="&_suid="+
c.id);c.hashedUrl=a.getFullUrl(c.hash);(a.emulated.pushState||a.bugs.safariPoll)&&a.hasUrlDuplicate(c)&&(c.url=c.hashedUrl);return c};a.createStateObject=function(b,c,d){b={data:b,title:c,url:d};return b=a.normalizeState(b)};a.getStateById=function(b){b=String(b);return a.idToState[b]||a.store.idToState[b]||d};a.getStateString=function(b){b={data:a.normalizeState(b).data,title:b.title,url:b.url};return p.stringify(b)};a.getStateId=function(b){return a.normalizeState(b).id};a.getHashByState=function(b){return a.normalizeState(b).hash};
a.extractId=function(a){a=-1!=a.indexOf("#")?a.split("#")[0]:a;return((a=/(.*)\&_suid=([0-9]+)$/.exec(a))?String(a[2]||""):"")||!1};a.isTraditionalAnchor=function(a){return!/[\/\\.]/.test(a)};a.extractState=function(b,c){var d=null,e,f;c=c||!1;(e=a.extractId(b))&&(d=a.getStateById(e));d||(f=a.getFullUrl(b),(e=a.getIdByUrl(f)||!1)&&(d=a.getStateById(e)),d||(!c||a.isTraditionalAnchor(b))||(d=a.createStateObject(null,null,f)));return d};a.getIdByUrl=function(b){return a.urlToId[b]||a.store.urlToId[b]||
d};a.getLastSavedState=function(){return a.savedStates[a.savedStates.length-1]||d};a.getLastStoredState=function(){return a.storedStates[a.storedStates.length-1]||d};a.hasUrlDuplicate=function(b){var c=!1;return c=(c=a.extractState(b.url))&&c.id!==b.id};a.storeState=function(b){a.urlToId[b.url]=b.id;a.storedStates.push(a.cloneObject(b));return b};a.isLastSavedState=function(b){var c=!1;a.savedStates.length&&(b=b.id,c=a.getLastSavedState(),c=c.id,c=b===c);return c};a.saveState=function(b){if(a.isLastSavedState(b))return!1;
a.savedStates.push(a.cloneObject(b));return!0};a.getStateByIndex=function(b){var c=null;return c="undefined"===typeof b?a.savedStates[a.savedStates.length-1]:0>b?a.savedStates[a.savedStates.length+b]:a.savedStates[b]};a.getCurrentIndex=function(){var b=null;return b=1>a.savedStates.length?0:a.savedStates.length-1};a.getHash=function(b){b=a.getLocationHref(b);return a.getHashByUrl(b)};a.unescapeHash=function(b){b=a.normalizeHash(b);return b=decodeURIComponent(b)};a.normalizeHash=function(a){return a.replace(/[^#]*#/,
"").replace(/#.*/,"")};a.setHash=function(b,c){var d;if(!1!==c&&a.busy())return a.pushQueue({scope:a,callback:a.setHash,args:arguments,queue:c}),!1;a.busy(!0);(d=a.extractState(b,!0))&&!a.emulated.pushState?a.pushState(d.data,d.title,d.url,!1):a.getHash()!==b&&(a.bugs.setHash?(d=a.getPageUrl(),a.pushState(null,null,d+"#"+b,!1)):e.location.hash=b);return a};a.escapeHash=function(b){b=a.normalizeHash(b);b=f.encodeURIComponent(b);a.bugs.hashEscape||(b=b.replace(/\%21/g,"!").replace(/\%26/g,"&").replace(/\%3D/g,
"=").replace(/\%3F/g,"?"));return b};a.getHashByUrl=function(b){b=String(b).replace(/([^#]*)#?([^#]*)#?(.*)/,"$2");return b=a.unescapeHash(b)};a.setTitle=function(b){var c=b.title,d;c||(d=a.getStateByIndex(0))&&d.url===b.url&&(c=d.title||a.options.initialTitle);try{e.getElementsByTagName("title")[0].innerHTML=c.replace("<","&lt;").replace(">","&gt;").replace(" & "," &amp; ")}catch(f){}e.title=c;return a};a.queues=[];a.busy=function(b){"undefined"!==typeof b?a.busy.flag=b:"undefined"===typeof a.busy.flag&&
(a.busy.flag=!1);if(!a.busy.flag){m(a.busy.timeout);var c=function(){var b,d;if(!a.busy.flag)for(b=a.queues.length-1;0<=b;--b)d=a.queues[b],0!==d.length&&(d=d.shift(),a.fireQueueItem(d),a.busy.timeout=l(c,a.options.busyDelay))};a.busy.timeout=l(c,a.options.busyDelay)}return a.busy.flag};a.busy.flag=!1;a.fireQueueItem=function(b){return b.callback.apply(b.scope||a,b.args||[])};a.pushQueue=function(b){a.queues[b.queue||0]=a.queues[b.queue||0]||[];a.queues[b.queue||0].push(b);return a};a.queue=function(b,
c){"function"===typeof b&&(b={callback:b});"undefined"!==typeof c&&(b.queue=c);a.busy()?a.pushQueue(b):a.fireQueueItem(b);return a};a.clearQueue=function(){a.busy.flag=!1;a.queues=[];return a};a.stateChanged=!1;a.doubleChecker=!1;a.doubleCheckComplete=function(){a.stateChanged=!0;a.doubleCheckClear();return a};a.doubleCheckClear=function(){a.doubleChecker&&(m(a.doubleChecker),a.doubleChecker=!1);return a};a.doubleCheck=function(b){a.stateChanged=!1;a.doubleCheckClear();a.bugs.ieDoubleCheck&&(a.doubleChecker=
l(function(){a.doubleCheckClear();a.stateChanged||b();return!0},a.options.doubleCheckInterval));return a};a.safariStatePoll=function(){var b=a.extractState(a.getLocationHref());if(!a.isLastSavedState(b))return b||a.createStateObject(),a.Adapter.trigger(f,"popstate"),a};a.back=function(b){if(!1!==b&&a.busy())return a.pushQueue({scope:a,callback:a.back,args:arguments,queue:b}),!1;a.busy(!0);a.doubleCheck(function(){a.back(!1)});s.go(-1);return!0};a.forward=function(b){if(!1!==b&&a.busy())return a.pushQueue({scope:a,
callback:a.forward,args:arguments,queue:b}),!1;a.busy(!0);a.doubleCheck(function(){a.forward(!1)});s.go(1);return!0};a.go=function(b,c){var d;if(0<b)for(d=1;d<=b;++d)a.forward(c);else if(0>b)for(d=-1;d>=b;--d)a.back(c);else throw Error("History.go: History.go requires a positive or negative integer passed.");return a};a.emulated.pushState?(t=function(){},a.pushState=a.pushState||t,a.replaceState=a.replaceState||t):(a.onPopState=function(b,c){var d=!1,d=!1;a.doubleCheckComplete();if(d=a.getHash())return(d=
a.extractState(d||a.getLocationHref(),!0))?a.replaceState(d.data,d.title,d.url,!1):(a.Adapter.trigger(f,"anchorchange"),a.busy(!1)),a.expectedStateId=!1;(d=(d=a.Adapter.extractEventData("state",b,c)||!1)?a.getStateById(d):a.expectedStateId?a.getStateById(a.expectedStateId):a.extractState(a.getLocationHref()))||(d=a.createStateObject(null,null,a.getLocationHref()));a.expectedStateId=!1;if(a.isLastSavedState(d))return a.busy(!1),!1;a.storeState(d);a.saveState(d);a.setTitle(d);a.Adapter.trigger(f,"statechange");
a.busy(!1);return!0},a.Adapter.bind(f,"popstate",a.onPopState),a.pushState=function(b,c,d,e){if(a.getHashByUrl(d)&&a.emulated.pushState)throw Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(!1!==e&&a.busy())return a.pushQueue({scope:a,callback:a.pushState,args:arguments,queue:e}),!1;a.busy(!0);var g=a.createStateObject(b,c,d);a.isLastSavedState(g)?a.busy(!1):(a.storeState(g),a.expectedStateId=g.id,s.pushState(g.id,g.title,g.url),a.Adapter.trigger(f,"popstate"));
return!0},a.replaceState=function(b,c,d,e){if(a.getHashByUrl(d)&&a.emulated.pushState)throw Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(!1!==e&&a.busy())return a.pushQueue({scope:a,callback:a.replaceState,args:arguments,queue:e}),!1;a.busy(!0);var g=a.createStateObject(b,c,d);a.isLastSavedState(g)?a.busy(!1):(a.storeState(g),a.expectedStateId=g.id,s.replaceState(g.id,g.title,g.url),a.Adapter.trigger(f,"popstate"));return!0});if(g)try{a.store=p.parse(g.getItem("History.store"))||
{}}catch(q){a.store={}}else a.store={};a.normalizeStore();a.Adapter.bind(f,"unload",a.clearAllIntervals);a.saveState(a.storeState(a.extractState(a.getLocationHref(),!0)));g&&(a.onUnload=function(){var b,c;try{b=p.parse(g.getItem("History.store"))||{}}catch(d){b={}}b.idToState=b.idToState||{};b.urlToId=b.urlToId||{};b.stateToId=b.stateToId||{};for(c in a.idToState)a.idToState.hasOwnProperty(c)&&(b.idToState[c]=a.idToState[c]);for(c in a.urlToId)a.urlToId.hasOwnProperty(c)&&(b.urlToId[c]=a.urlToId[c]);
for(c in a.stateToId)a.stateToId.hasOwnProperty(c)&&(b.stateToId[c]=a.stateToId[c]);a.store=b;a.normalizeStore();b=p.stringify(b);try{g.setItem("History.store",b)}catch(e){if(e.code===DOMException.QUOTA_EXCEEDED_ERR)g.length&&(g.removeItem("History.store"),g.setItem("History.store",b));else throw e;}},a.intervalList.push(h(a.onUnload,a.options.storeInterval)),a.Adapter.bind(f,"beforeunload",a.onUnload),a.Adapter.bind(f,"unload",a.onUnload));if(!a.emulated.pushState&&(a.bugs.safariPoll&&a.intervalList.push(h(a.safariStatePoll,
a.options.safariPollInterval)),"Apple Computer, Inc."===c.vendor||"Mozilla"===(c.appCodeName||""))&&(a.Adapter.bind(f,"hashchange",function(){a.Adapter.trigger(f,"popstate")}),a.getHash()))a.Adapter.onDomLoad(function(){a.Adapter.trigger(f,"hashchange")})};a.options&&a.options.delayInit||a.init()})(window);