wiselinks 0.7.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +16 -16
- data/README.md +36 -37
- data/lib/assets/javascripts/_link.js.coffee +19 -4
- data/lib/assets/javascripts/_page.js.coffee +2 -6
- data/lib/assets/javascripts/_request_manager.js.coffee +11 -12
- data/lib/assets/javascripts/lib/native.history.js +3337 -0
- data/lib/assets/javascripts/wiselinks.js.coffee +4 -1
- data/lib/wiselinks/version.rb +3 -3
- data/wiselinks.gemspec +3 -3
- metadata +80 -45
- checksums.yaml +0 -7
- data/build/wiselinks-0.7.3.js +0 -3541
- data/build/wiselinks-0.7.3.min.js +0 -72
- data/build/wiselinks-0.7.3.min.js.gz +0 -0
- data/lib/assets/javascripts/lib/_history.adapter.jquery.js +0 -76
- data/lib/assets/javascripts/lib/_history.html4.js +0 -621
- data/lib/assets/javascripts/lib/_history.js +0 -1946
- data/lib/assets/javascripts/lib/_json2.js +0 -486
- data/lib/wiselinks/builder.rb +0 -104
@@ -1,72 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
2012-2013 Igor Alexandrov, Alexey Solilin, Julia Egorova, Alexandr Borisov
|
3
|
-
@preserve https://github.com/igor-alexandrov/wiselinks
|
4
|
-
2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
-
@license New BSD License <http://creativecommons.org/licenses/BSD/>
|
6
|
-
2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
7
|
-
@license New BSD License <http://creativecommons.org/licenses/BSD/>
|
8
|
-
Public Domain
|
9
|
-
@author Benjamin Arthur Lupton <contact@balupton.com>
|
10
|
-
@author James Padolsey <https://gist.github.com/527683>
|
11
|
-
Public Domain
|
12
|
-
@author Benjamin Arthur Lupton <contact@balupton.com>
|
13
|
-
2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
14
|
-
@license New BSD License <http://creativecommons.org/licenses/BSD/>
|
15
|
-
*/
|
16
|
-
(function(){var c;c=function(){function c(d,e){this.page=d;this.$form=e}c.prototype.process=function(){var d;d=this;return d._include_blank_url_params()?d.page.load(d._url(),d._target(),d._type()):d._without_blank_url_params(function(){return d.page.load(d._url(),d._target(),d._type())})};c.prototype._without_blank_url_params=function(d){var e;e=this.$form.find("select:not(:disabled),input:not(:disabled)").filter(function(){return!$(this).val()});e.attr("disabled",!0);d();return e.attr("disabled",
|
17
|
-
!1)};c.prototype._params=function(){var d,e,b,f,c,q;d={};q=this.$form.serializeArray();f=0;for(c=q.length;f<c;f++)e=q[f],"utf8"!==e.name&&(b=-1!==e.name.indexOf("[]",e.name.length-2)?e.name.substr(0,e.name.length-2):e.name,d[b]=null!=d[b]?d[b]+(","+e.value):e.value);return d};c.prototype._include_blank_url_params=function(){return!0===this.$form.data("include-blank-url-params")};c.prototype._optimize_url_params=function(){return!1!==this.$form.data("optimize-url-params")};c.prototype._type=function(){return"partial"===
|
18
|
-
this.$form.data("push")?"partial":"template"};c.prototype._target=function(){return this.$form.data("target")};c.prototype._url=function(){var d,e,b;var f;if(this._optimize_url_params()){e=[];f=this._params();for(d in f)b=f[d],e.push(""+d+"="+encodeURIComponent(b));d=e.join("&")}else d=this.$form.serialize();e=this.$form.attr("action");0<d.length&&(e+="?"+d);return e};return c}();null==window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.Form=c;c=function(){function c(d,e){this.page=d;this.$link=
|
19
|
-
e}c.prototype.allows_process=function(d){return!(this._cross_origin_link(d.currentTarget)||this._non_standard_click(d))};c.prototype.process=function(){var d;d="partial"===this.$link.data("push")?"partial":"template";return this.page.load(this.$link.attr("href"),this.$link.data("target"),d)};c.prototype._cross_origin_link=function(d){return location.protocol!==d.protocol||location.port!==d.port||location.host.split(":")[0]!==d.host.split(":")[0]};c.prototype._non_standard_click=function(d){return d.metaKey||
|
20
|
-
d.ctrlKey||d.shiftKey||d.altKey};return c}();void 0===window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.Link=c;c=function(){function c(d,e){var b;this.$target=d;this.options=e;b=this;this.template_id=(new Date).getTime();this.request_manager=new _Wiselinks.RequestManager(this.options);b._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)&&
|
21
|
-
(window.location.href=""+window.location.protocol+"//"+window.location.host+this.options.html4_root_path+"#!"+window.location.pathname),-1!==window.location.hash.indexOf("#!")&&b._call(b._make_state(window.location.hash.substring(2))));History.Adapter.bind(window,"statechange",function(d,e){var c;c=History.getState();return b._template_id_changed(c)?b._call(b._reset_state(c)):b._call(c)});$(document).on("click","a[data-push], a[data-replace]",function(d){var e;if((e=new _Wiselinks.Link(b,$(this))).allows_process(d))return d.preventDefault(),
|
22
|
-
e.process(),!1});$(document).on("submit","form[data-push], form[data-replace]",function(d){var e;if(e=new _Wiselinks.Form(b,$(this)))return d.preventDefault(),e.process(),!1})}c.prototype.load=function(d,e,b){null==b&&(b="template");"partial"!==b&&(this.template_id=(new Date).getTime());null!=e&&this._try_target($(e));return History.pushState({timestamp:(new Date).getTime(),template_id:this.template_id,render:b,target:e,referer:window.location.href},document.title,d)};c.prototype.reload=function(){return History.replaceState({timestamp:(new Date).getTime(),
|
23
|
-
template_id:this.template_id,render:"template",referer:window.location.href},document.title,History.getState().url)};c.prototype._call=function(d){var e;e=null!=d.data.target?$(d.data.target):this.$target;return this.request_manager.call(e,d)};c.prototype._template_id_changed=function(d){return null==d.data.template_id||d.data.template_id!==this.template_id};c.prototype._make_state=function(d,e,b,f){null==b&&(b="template");return{url:d,data:{target:e,render:b,referer:f}}};c.prototype._reset_state=
|
24
|
-
function(d){null==d.data&&(d.data={});d.data.target=null;d.data.render="template";return d};c.prototype._try_target=function(d){if(0===d.length&&"exception"===this.options.target_missing)throw Error("[Wiselinks] Target missing: `"+d.selector+"`");};return c}();void 0===window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.Page=c;c=function(){function c(d){this.options=null!=d?d:{}}c.prototype.call=function(d,c){var b;b=this;if(null!=this.redirected)this.redirected=null;else return b._loading(d,
|
25
|
-
c),$.ajax({url:c.url,headers:{"X-Wiselinks":c.data.render,"X-Wiselinks-Referer":c.data.referer},dataType:"html"}).done(function(f,g,k){var l,h;h=b._normalize(k.getResponseHeader("X-Wiselinks-Url"));l=k.getResponseHeader("X-Wiselinks-Assets-Digest");if(b._assets_changed(l))return window.location.reload(!0);c=History.getState();null!=h&&h!==b._normalize(window.location.href)&&b._redirect_to(h,d,c,k);d.html(f);b._title(k.getResponseHeader("X-Wiselinks-Title"));return b._done(d,g,c.url,f)}).fail(function(f,
|
26
|
-
g,k){return b._fail(d,g,c.url,k)}).always(function(f,g,k){return b._always(d,g,c.url)})};c.prototype._normalize=function(d){if(null!=d)return d=d.replace(/\/+$/,"")};c.prototype._assets_changed=function(d){return null!=this.options.assets_digest&&this.options.assets_digest!==d};c.prototype._redirect_to=function(d,c,b,f){f&&4>f.readyState&&(f.onreadystatechange=$.noop,f.abort());this.redirected=!0;$(document).trigger("page:redirected",[c,b.data.render,d]);return History.replaceState(b.data,document.title,
|
27
|
-
d)};c.prototype._loading=function(d,c){return $(document).trigger("page:loading",[d,c.data.render,c.url])};c.prototype._done=function(d,c,b,f){return $(document).trigger("page:done",[d,c,b,f])};c.prototype._fail=function(d,c,b,f){return $(document).trigger("page:fail",[d,c,b,f])};c.prototype._always=function(d,c,b){return $(document).trigger("page:always",[d,c,b])};c.prototype._title=function(d){if(null!=d)return $(document).trigger("page:title",decodeURI(d)),document.title=decodeURI(d)};return c}();
|
28
|
-
void 0===window._Wiselinks&&(window._Wiselinks={});window._Wiselinks.RequestManager=c;c=function(){function c(d,e){null==d&&(d=$("body"));this.options=null!=e?e:{};this._try_jquery();this.options=$.extend(this._defaults(),this.options);this.enabled()&&(this.page=new _Wiselinks.Page(d,this.options))}c.prototype.enabled=function(){return!History.emulated.pushState||!0===this.options.html4};c.prototype.load=function(c,e,b){null==b&&(b="template");return this.page.load(c,e,b)};c.prototype.reload=function(){return this.page.reload()};
|
29
|
-
c.prototype._defaults=function(){return{html4:!0,html4_root_path:"/",html4_normalize_path:!0,target_missing:null,assets_digest:$("meta[name='assets-digest']").attr("content")}};c.prototype._try_jquery=function(){if(null==window.jQuery)throw Error("[Wiselinks] jQuery is not loaded");};return c}();window.Wiselinks=c}).call(this);
|
30
|
-
(function(c,q){var d=c.History=c.History||{},e=c.jQuery;if("undefined"!==typeof d.Adapter)throw Error("History.js Adapter has already been loaded...");d.Adapter={bind:function(b,c,d){e(b).bind(c,d)},trigger:function(b,c,d){e(b).trigger(c,d)},extractEventData:function(b,c,d){return c&&c.originalEvent&&c.originalEvent[b]||d&&d[b]||q},onDomLoad:function(b){e(b)}};"undefined"!==typeof d.init&&d.init()})(window);
|
31
|
-
(function(c,q){var d=c.document,e=c.setInterval||e,b=c.History=c.History||{};if("undefined"!==typeof b.initHtml4)throw Error("History.js HTML4 Support has already been loaded...");b.initHtml4=function(){if("undefined"!==typeof b.initHtml4.initialized)return!1;b.initHtml4.initialized=!0;b.enabled=!0;b.savedHashes=[];b.isLastHash=function(c){var d=b.getHashByIndex();return c===d};b.saveHash=function(c){if(b.isLastHash(c))return!1;b.savedHashes.push(c);return!0};b.getHashByIndex=function(c){var d=null;
|
32
|
-
return d="undefined"===typeof c?b.savedHashes[b.savedHashes.length-1]:0>c?b.savedHashes[b.savedHashes.length+c]:b.savedHashes[c]};b.discardedHashes={};b.discardedStates={};b.discardState=function(c,d,e){var l=b.getHashByState(c);b.discardedStates[l]={discardedState:c,backState:e,forwardState:d};return!0};b.discardHash=function(c,d,e){b.discardedHashes[c]={discardedHash:c,backState:e,forwardState:d};return!0};b.discardedState=function(c){c=b.getHashByState(c);return b.discardedStates[c]||!1};b.discardedHash=
|
33
|
-
function(c){return b.discardedHashes[c]||!1};b.recycleState=function(c){var d=b.getHashByState(c);b.discardedState(c)&&delete b.discardedStates[d];return!0};b.emulated.hashChange&&(b.hashChangeInit=function(){b.checkerFunction=null;var f="",g,k,l;b.isInternetExplorer()?(g=d.createElement("iframe"),g.setAttribute("id","historyjs-iframe"),g.style.display="none",d.body.appendChild(g),g.contentWindow.document.open(),g.contentWindow.document.close(),k="",l=!1,b.checkerFunction=function(){if(l)return!1;
|
34
|
-
l=!0;var d=b.getHash()||"",e=b.unescapeHash(g.contentWindow.document.location.hash)||"";d!==f?(f=d,e!==d&&(k=d,g.contentWindow.document.open(),g.contentWindow.document.close(),g.contentWindow.document.location.hash=b.escapeHash(d)),b.Adapter.trigger(c,"hashchange")):e!==k&&(k=e,b.setHash(e,!1));l=!1;return!0}):b.checkerFunction=function(){var d=b.getHash();d!==f&&(f=d,b.Adapter.trigger(c,"hashchange"));return!0};b.intervalList.push(e(b.checkerFunction,b.options.hashChangeInterval));return!0},b.Adapter.onDomLoad(b.hashChangeInit));
|
35
|
-
b.emulated.pushState&&(b.onHashChange=function(e){var g=b.getHashByUrl(e&&e.newURL||d.location.href);e=null;if(b.isLastHash(g))return b.busy(!1),!1;b.doubleCheckComplete();b.saveHash(g);if(g&&b.isTraditionalAnchor(g))return b.Adapter.trigger(c,"anchorchange"),b.busy(!1),!1;e=b.extractState(b.getFullUrl(g||d.location.href,!1),!0);if(b.isLastSavedState(e))return b.busy(!1),!1;b.getHashByState(e);if(g=b.discardedState(e))return b.getHashByIndex(-2)===b.getHashByState(g.forwardState)?b.back(!1):b.forward(!1),
|
36
|
-
!1;b.pushState(e.data,e.title,e.url,!1);return!0},b.Adapter.bind(c,"hashchange",b.onHashChange),b.pushState=function(e,g,k,l){if(b.getHashByUrl(k))throw Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(!1!==l&&b.busy())return b.pushQueue({scope:b,callback:b.pushState,args:arguments,queue:l}),!1;b.busy(!0);var h=b.createStateObject(e,g,k),m=b.getHashByState(h),r=b.getState(!1),r=b.getHashByState(r),a=b.getHash();b.storeState(h);b.expectedStateId=h.id;b.recycleState(h);
|
37
|
-
if(m===r)return b.busy(!1),!1;if(m!==a&&m!==b.getShortUrl(d.location.href))return b.setHash(m,!1),!1;b.saveState(h);b.Adapter.trigger(c,"statechange");b.busy(!1);return!0},b.replaceState=function(c,d,e,l){if(b.getHashByUrl(e))throw Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(!1!==l&&b.busy())return b.pushQueue({scope:b,callback:b.replaceState,args:arguments,queue:l}),!1;b.busy(!0);var h=b.createStateObject(c,d,e),m=b.getState(!1),r=b.getStateByIndex(-2);
|
38
|
-
b.discardState(m,h,r);b.pushState(h.data,h.title,h.url,!1);return!0});if(b.emulated.pushState&&b.getHash()&&!b.emulated.hashChange)b.Adapter.onDomLoad(function(){b.Adapter.trigger(c,"hashchange")})};"undefined"!==typeof b.init&&b.init()})(window);
|
39
|
-
(function(c,q){var d=c.console||q,e=c.document,b=c.navigator,f=c.sessionStorage||!1,g=c.setTimeout,k=c.clearTimeout,l=c.setInterval,h=c.clearInterval,m=c.JSON,r=c.alert,a=c.History=c.History||{},u=c.history;m.stringify=m.stringify||m.encode;m.parse=m.parse||m.decode;if("undefined"!==typeof a.init)throw Error("History.js Core has already been loaded...");a.init=function(){if("undefined"===typeof a.Adapter)return!1;"undefined"!==typeof a.initCore&&a.initCore();"undefined"!==typeof a.initHtml4&&a.initHtml4();
|
40
|
-
return!0};a.initCore=function(){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.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||
|
41
|
-
e.title;a.intervalList=[];a.clearAllIntervals=function(){var p,b=a.intervalList;if("undefined"!==typeof b&&null!==b){for(p=0;p<b.length;p++)h(b[p]);a.intervalList=null}};a.debug=function(){a.options.debug&&a.log.apply(a,arguments)};a.log=function(){var a=!("undefined"===typeof d||"undefined"===typeof d.log||"undefined"===typeof d.log.apply),b=e.getElementById("log"),c,f,h,g;a?(f=Array.prototype.slice.call(arguments),c=f.shift(),"undefined"!==typeof d.debug?d.debug.apply(d,[c,f]):d.log.apply(d,[c,
|
42
|
-
f])):c="\n"+arguments[0]+"\n";f=1;for(h=arguments.length;f<h;++f){g=arguments[f];if("object"===typeof g&&"undefined"!==typeof m)try{g=m.stringify(g)}catch(l){}c+="\n"+g+"\n"}b?(b.value+=c+"\n-----\n",b.scrollTop=b.scrollHeight-b.clientHeight):a||r(c);return!0};a.getInternetExplorerMajorVersion=function(){var p=a.getInternetExplorerMajorVersion,b;if("undefined"!==typeof a.getInternetExplorerMajorVersion.cached)b=a.getInternetExplorerMajorVersion.cached;else{b=3;for(var c=e.createElement("div"),d=c.getElementsByTagName("i");(c.innerHTML=
|
43
|
-
"\x3c!--[if gt IE "+ ++b+"]><i></i><![endif]--\x3e")&&d[0];);b=4<b?b:!1}return p.cached=b};a.isInternetExplorer=function(){return a.isInternetExplorer.cached="undefined"!==typeof a.isInternetExplorer.cached?a.isInternetExplorer.cached:Boolean(a.getInternetExplorerMajorVersion())};a.emulated={pushState:!Boolean(c.history&&c.history.pushState&&c.history.replaceState&&!(/ Mobile\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))/i.test(b.userAgent)||/AppleWebKit\/5([0-2]|3[0-2])/i.test(b.userAgent))),hashChange:Boolean(!("onhashchange"in
|
44
|
-
c||"onhashchange"in e)||a.isInternetExplorer()&&8>a.getInternetExplorerMajorVersion())};a.enabled=!a.emulated.pushState;a.bugs={setHash:Boolean(!a.emulated.pushState&&"Apple Computer, Inc."===b.vendor&&/AppleWebKit\/5([0-2]|3[0-3])/.test(b.userAgent)),safariPoll:Boolean(!a.emulated.pushState&&"Apple Computer, Inc."===b.vendor&&/AppleWebKit\/5([0-2]|3[0-3])/.test(b.userAgent)),ieDoubleCheck:Boolean(a.isInternetExplorer()&&8>a.getInternetExplorerMajorVersion()),hashEscape:Boolean(a.isInternetExplorer()&&
|
45
|
-
7>a.getInternetExplorerMajorVersion())};a.isEmptyObject=function(a){for(var b in a)return!1;return!0};a.cloneObject=function(a){a?(a=m.stringify(a),a=m.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=
|
46
|
-
function(){return a.getBaseHref()||a.getBasePageUrl()||a.getRootUrl()};a.getPageUrl=function(){return((a.getState(!1,!1)||{}).url||e.location.href).replace(/\/+$/,"").replace(/[^\/]+$/,function(a,b,c){return/\!/.test(a)?a:a+"/"})};a.getBasePageUrl=function(){return e.location.href.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=
|
47
|
-
"/"===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.store={};a.idToState=a.idToState||{};a.stateToId=a.stateToId||
|
48
|
-
{};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=
|
49
|
-
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={});
|
50
|
-
c={normalized:!0};c.title=b.title||"";c.url=a.getFullUrl(a.unescapeString(b.url||e.location.href));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);if(c.title||b)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);
|
51
|
-
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]||q};a.getStateString=function(b){b={data:a.normalizeState(b).data,title:b.title,url:b.url};return m.stringify(b)};a.getStateId=function(b){return a.normalizeState(b).id};a.getHashByState=function(b){return a.normalizeState(b).hash};a.extractId=function(a){return((a=/(.*)\&_suid=([0-9]+)$/.exec(a))?String(a[2]||""):"")||
|
52
|
-
!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]||q};a.getLastSavedState=function(){return a.savedStates[a.savedStates.length-1]||q};a.getLastStoredState=function(){return a.storedStates[a.storedStates.length-
|
53
|
-
1]||q};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-
|
54
|
-
1]:0>b?a.savedStates[a.savedStates.length+b]:a.savedStates[b]};a.getHash=function(){return a.unescapeHash(e.location.hash)};a.unescapeString=function(a){for(var b;;){b=c.decodeURI(a);if(b===a)break;a=b}return a};a.unescapeHash=function(b){b=a.normalizeHash(b);return b=a.unescapeString(b)};a.normalizeHash=function(a){return a.replace(/[^#]*#/,"").replace(/#!*/,"")};a.setHash=function(b,c){var d,f;if(!1!==c&&a.busy())return a.pushQueue({scope:a,callback:a.setHash,args:arguments,queue:c}),!1;d=a.escapeHash(b);
|
55
|
-
a.busy(!0);(f=a.extractState(b,!0))&&!a.emulated.pushState?a.pushState(f.data,f.title,f.url,!1):e.location.hash!==d&&(a.bugs.setHash?(f=a.getPageUrl(),a.pushState(null,null,f+"#"+d,!1)):e.location.hash=d);return a};a.escapeHash=function(b){b=a.normalizeHash(b);b=c.encodeURI(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)};
|
56
|
-
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("<","<").replace(">",">").replace(" & "," & ")}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){k(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],
|
57
|
-
0!==d.length&&(d=d.shift(),a.fireQueueItem(d),a.busy.timeout=g(c,a.options.busyDelay))};a.busy.timeout=g(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=
|
58
|
-
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&&(k(a.doubleChecker),a.doubleChecker=!1);return a};a.doubleCheck=function(b){a.stateChanged=!1;a.doubleCheckClear();a.bugs.ieDoubleCheck&&(a.doubleChecker=g(function(){a.doubleCheckClear();a.stateChanged||b();return!0},a.options.doubleCheckInterval));return a};a.safariStatePoll=function(){var b=
|
59
|
-
a.extractState(e.location.href);if(!a.isLastSavedState(b))return b||a.createStateObject(),a.Adapter.trigger(c,"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)});u.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)});u.go(1);return!0};a.go=function(b,
|
60
|
-
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};if(a.emulated.pushState){var s=function(){};a.pushState=a.pushState||s;a.replaceState=a.replaceState||s}else a.onPopState=function(b,d){var f=!1,f=!1;a.doubleCheckComplete();if(f=a.getHash())return(f=a.extractState(f||e.location.href,!0))?a.replaceState(f.data,f.title,f.url,!1):(a.Adapter.trigger(c,"anchorchange"),
|
61
|
-
a.busy(!1)),a.expectedStateId=!1;(f=(f=a.Adapter.extractEventData("state",b,d)||!1)?a.getStateById(f):a.expectedStateId?a.getStateById(a.expectedStateId):a.extractState(e.location.href))||(f=a.createStateObject(null,null,e.location.href));a.expectedStateId=!1;if(a.isLastSavedState(f))return a.busy(!1),!1;a.storeState(f);a.saveState(f);a.setTitle(f);a.Adapter.trigger(c,"statechange");a.busy(!1);return!0},a.Adapter.bind(c,"popstate",a.onPopState),a.pushState=function(b,d,e,f){if(a.getHashByUrl(e)&&
|
62
|
-
a.emulated.pushState)throw Error("History.js does not support states with fragement-identifiers (hashes/anchors).");if(!1!==f&&a.busy())return a.pushQueue({scope:a,callback:a.pushState,args:arguments,queue:f}),!1;a.busy(!0);var h=a.createStateObject(b,d,e);a.isLastSavedState(h)?a.busy(!1):(a.storeState(h),a.expectedStateId=h.id,u.pushState(h.id,h.title,h.url),a.Adapter.trigger(c,"popstate"));return!0},a.replaceState=function(b,d,e,f){if(a.getHashByUrl(e)&&a.emulated.pushState)throw Error("History.js does not support states with fragement-identifiers (hashes/anchors).");
|
63
|
-
if(!1!==f&&a.busy())return a.pushQueue({scope:a,callback:a.replaceState,args:arguments,queue:f}),!1;a.busy(!0);var h=a.createStateObject(b,d,e);a.isLastSavedState(h)?a.busy(!1):(a.storeState(h),a.expectedStateId=h.id,u.replaceState(h.id,h.title,h.url),a.Adapter.trigger(c,"popstate"));return!0};if(f)try{a.store=m.parse(f.getItem("History.store"))||{}}catch(t){a.store={}}else a.store={};a.normalizeStore();a.Adapter.bind(c,"beforeunload",a.clearAllIntervals);a.Adapter.bind(c,"unload",a.clearAllIntervals);
|
64
|
-
a.saveState(a.storeState(a.extractState(e.location.href,!0)));f&&(a.onUnload=function(){var b,c;try{b=m.parse(f.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();
|
65
|
-
f.setItem("History.store",m.stringify(b))},a.intervalList.push(l(a.onUnload,a.options.storeInterval)),a.Adapter.bind(c,"beforeunload",a.onUnload),a.Adapter.bind(c,"unload",a.onUnload));if(!a.emulated.pushState&&(a.bugs.safariPoll&&a.intervalList.push(l(a.safariStatePoll,a.options.safariPollInterval)),"Apple Computer, Inc."===b.vendor||"Mozilla"===(b.appCodeName||""))&&(a.Adapter.bind(c,"hashchange",function(){a.Adapter.trigger(c,"popstate")}),a.getHash()))a.Adapter.onDomLoad(function(){a.Adapter.trigger(c,
|
66
|
-
"hashchange")})};a.init()})(window);"object"!==typeof JSON&&(JSON={});
|
67
|
-
(function(){function c(b){return 10>b?"0"+b:b}function q(c){b.lastIndex=0;return b.test(c)?'"'+c.replace(b,function(b){var c=k[b];return"string"===typeof c?c:"\\u"+("0000"+b.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+c+'"'}function d(b,c){var e,a,k,s,t=f,p,n=c[b];n&&("object"===typeof n&&"function"===typeof n.toJSON)&&(n=n.toJSON(b));"function"===typeof l&&(n=l.call(c,b,n));switch(typeof n){case "string":return q(n);case "number":return isFinite(n)?String(n):"null";case "boolean":case "null":return String(n);
|
68
|
-
case "object":if(!n)return"null";f+=g;p=[];if("[object Array]"===Object.prototype.toString.apply(n)){s=n.length;for(e=0;e<s;e+=1)p[e]=d(e,n)||"null";k=0===p.length?"[]":f?"[\n"+f+p.join(",\n"+f)+"\n"+t+"]":"["+p.join(",")+"]";f=t;return k}if(l&&"object"===typeof l)for(s=l.length,e=0;e<s;e+=1)"string"===typeof l[e]&&(a=l[e],(k=d(a,n))&&p.push(q(a)+(f?": ":":")+k));else for(a in n)Object.prototype.hasOwnProperty.call(n,a)&&(k=d(a,n))&&p.push(q(a)+(f?": ":":")+k);k=0===p.length?"{}":f?"{\n"+f+p.join(",\n"+
|
69
|
-
f)+"\n"+t+"}":"{"+p.join(",")+"}";f=t;return k}}"function"!==typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(b){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+c(this.getUTCMonth()+1)+"-"+c(this.getUTCDate())+"T"+c(this.getUTCHours())+":"+c(this.getUTCMinutes())+":"+c(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(b){return this.valueOf()});var e=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
70
|
-
b=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,f,g,k={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},l;"function"!==typeof JSON.stringify&&(JSON.stringify=function(b,c,e){var a;g=f="";if("number"===typeof e)for(a=0;a<e;a+=1)g+=" ";else"string"===typeof e&&(g=e);if((l=c)&&"function"!==typeof c&&("object"!==typeof c||"number"!==typeof c.length))throw Error("JSON.stringify");return d("",{"":b})});
|
71
|
-
"function"!==typeof JSON.parse&&(JSON.parse=function(b,c){function d(a,b){var e,f,g=a[b];if(g&&"object"===typeof g)for(e in g)Object.prototype.hasOwnProperty.call(g,e)&&(f=d(g,e),void 0!==f?g[e]=f:delete g[e]);return c.call(a,b,g)}var a;b=String(b);e.lastIndex=0;e.test(b)&&(b=b.replace(e,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(b.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
|
72
|
-
"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return a=eval("("+b+")"),"function"===typeof c?d({"":a},""):a;throw new SyntaxError("JSON.parse");})})();
|
Binary file
|
@@ -1,76 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* History.js jQuery Adapter
|
3
|
-
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
4
|
-
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
-
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
6
|
-
*/
|
7
|
-
|
8
|
-
// Closure
|
9
|
-
(function(window,undefined){
|
10
|
-
"use strict";
|
11
|
-
|
12
|
-
// Localise Globals
|
13
|
-
var
|
14
|
-
History = window.History = window.History||{},
|
15
|
-
jQuery = window.jQuery;
|
16
|
-
|
17
|
-
// Check Existence
|
18
|
-
if ( typeof History.Adapter !== 'undefined' ) {
|
19
|
-
throw new Error('History.js Adapter has already been loaded...');
|
20
|
-
}
|
21
|
-
|
22
|
-
// Add the Adapter
|
23
|
-
History.Adapter = {
|
24
|
-
/**
|
25
|
-
* History.Adapter.bind(el,event,callback)
|
26
|
-
* @param {Element|string} el
|
27
|
-
* @param {string} event - custom and standard events
|
28
|
-
* @param {function} callback
|
29
|
-
* @return {void}
|
30
|
-
*/
|
31
|
-
bind: function(el,event,callback){
|
32
|
-
jQuery(el).bind(event,callback);
|
33
|
-
},
|
34
|
-
|
35
|
-
/**
|
36
|
-
* History.Adapter.trigger(el,event)
|
37
|
-
* @param {Element|string} el
|
38
|
-
* @param {string} event - custom and standard events
|
39
|
-
* @param {Object=} extra - a object of extra event data (optional)
|
40
|
-
* @return {void}
|
41
|
-
*/
|
42
|
-
trigger: function(el,event,extra){
|
43
|
-
jQuery(el).trigger(event,extra);
|
44
|
-
},
|
45
|
-
|
46
|
-
/**
|
47
|
-
* History.Adapter.extractEventData(key,event,extra)
|
48
|
-
* @param {string} key - key for the event data to extract
|
49
|
-
* @param {string} event - custom and standard events
|
50
|
-
* @param {Object=} extra - a object of extra event data (optional)
|
51
|
-
* @return {mixed}
|
52
|
-
*/
|
53
|
-
extractEventData: function(key,event,extra){
|
54
|
-
// jQuery Native then jQuery Custom
|
55
|
-
var result = (event && event.originalEvent && event.originalEvent[key]) || (extra && extra[key]) || undefined;
|
56
|
-
|
57
|
-
// Return
|
58
|
-
return result;
|
59
|
-
},
|
60
|
-
|
61
|
-
/**
|
62
|
-
* History.Adapter.onDomLoad(callback)
|
63
|
-
* @param {function} callback
|
64
|
-
* @return {void}
|
65
|
-
*/
|
66
|
-
onDomLoad: function(callback) {
|
67
|
-
jQuery(callback);
|
68
|
-
}
|
69
|
-
};
|
70
|
-
|
71
|
-
// Try and Initialise History
|
72
|
-
if ( typeof History.init !== 'undefined' ) {
|
73
|
-
History.init();
|
74
|
-
}
|
75
|
-
|
76
|
-
})(window);
|
@@ -1,621 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* History.js HTML4 Support
|
3
|
-
* Depends on the HTML5 Support
|
4
|
-
* @author Benjamin Arthur Lupton <contact@balupton.com>
|
5
|
-
* @copyright 2010-2011 Benjamin Arthur Lupton <contact@balupton.com>
|
6
|
-
* @license New BSD License <http://creativecommons.org/licenses/BSD/>
|
7
|
-
*/
|
8
|
-
|
9
|
-
(function(window,undefined){
|
10
|
-
"use strict";
|
11
|
-
|
12
|
-
// ========================================================================
|
13
|
-
// Initialise
|
14
|
-
|
15
|
-
// Localise Globals
|
16
|
-
var
|
17
|
-
document = window.document, // Make sure we are using the correct document
|
18
|
-
setTimeout = window.setTimeout||setTimeout,
|
19
|
-
clearTimeout = window.clearTimeout||clearTimeout,
|
20
|
-
setInterval = window.setInterval||setInterval,
|
21
|
-
History = window.History = window.History||{}; // Public History Object
|
22
|
-
|
23
|
-
// Check Existence
|
24
|
-
if ( typeof History.initHtml4 !== 'undefined' ) {
|
25
|
-
throw new Error('History.js HTML4 Support has already been loaded...');
|
26
|
-
}
|
27
|
-
|
28
|
-
|
29
|
-
// ========================================================================
|
30
|
-
// Initialise HTML4 Support
|
31
|
-
|
32
|
-
// Initialise HTML4 Support
|
33
|
-
History.initHtml4 = function(){
|
34
|
-
// Initialise
|
35
|
-
if ( typeof History.initHtml4.initialized !== 'undefined' ) {
|
36
|
-
// Already Loaded
|
37
|
-
return false;
|
38
|
-
}
|
39
|
-
else {
|
40
|
-
History.initHtml4.initialized = true;
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
// ====================================================================
|
45
|
-
// Properties
|
46
|
-
|
47
|
-
/**
|
48
|
-
* History.enabled
|
49
|
-
* Is History enabled?
|
50
|
-
*/
|
51
|
-
History.enabled = true;
|
52
|
-
|
53
|
-
|
54
|
-
// ====================================================================
|
55
|
-
// Hash Storage
|
56
|
-
|
57
|
-
/**
|
58
|
-
* History.savedHashes
|
59
|
-
* Store the hashes in an array
|
60
|
-
*/
|
61
|
-
History.savedHashes = [];
|
62
|
-
|
63
|
-
/**
|
64
|
-
* History.isLastHash(newHash)
|
65
|
-
* Checks if the hash is the last hash
|
66
|
-
* @param {string} newHash
|
67
|
-
* @return {boolean} true
|
68
|
-
*/
|
69
|
-
History.isLastHash = function(newHash){
|
70
|
-
// Prepare
|
71
|
-
var oldHash = History.getHashByIndex(),
|
72
|
-
isLast;
|
73
|
-
|
74
|
-
// Check
|
75
|
-
isLast = newHash === oldHash;
|
76
|
-
|
77
|
-
// Return isLast
|
78
|
-
return isLast;
|
79
|
-
};
|
80
|
-
|
81
|
-
/**
|
82
|
-
* History.saveHash(newHash)
|
83
|
-
* Push a Hash
|
84
|
-
* @param {string} newHash
|
85
|
-
* @return {boolean} true
|
86
|
-
*/
|
87
|
-
History.saveHash = function(newHash){
|
88
|
-
// Check Hash
|
89
|
-
if ( History.isLastHash(newHash) ) {
|
90
|
-
return false;
|
91
|
-
}
|
92
|
-
|
93
|
-
// Push the Hash
|
94
|
-
History.savedHashes.push(newHash);
|
95
|
-
|
96
|
-
// Return true
|
97
|
-
return true;
|
98
|
-
};
|
99
|
-
|
100
|
-
/**
|
101
|
-
* History.getHashByIndex()
|
102
|
-
* Gets a hash by the index
|
103
|
-
* @param {integer} index
|
104
|
-
* @return {string}
|
105
|
-
*/
|
106
|
-
History.getHashByIndex = function(index){
|
107
|
-
// Prepare
|
108
|
-
var hash = null;
|
109
|
-
|
110
|
-
// Handle
|
111
|
-
if ( typeof index === 'undefined' ) {
|
112
|
-
// Get the last inserted
|
113
|
-
hash = History.savedHashes[History.savedHashes.length-1];
|
114
|
-
}
|
115
|
-
else if ( index < 0 ) {
|
116
|
-
// Get from the end
|
117
|
-
hash = History.savedHashes[History.savedHashes.length+index];
|
118
|
-
}
|
119
|
-
else {
|
120
|
-
// Get from the beginning
|
121
|
-
hash = History.savedHashes[index];
|
122
|
-
}
|
123
|
-
|
124
|
-
// Return hash
|
125
|
-
return hash;
|
126
|
-
};
|
127
|
-
|
128
|
-
|
129
|
-
// ====================================================================
|
130
|
-
// Discarded States
|
131
|
-
|
132
|
-
/**
|
133
|
-
* History.discardedHashes
|
134
|
-
* A hashed array of discarded hashes
|
135
|
-
*/
|
136
|
-
History.discardedHashes = {};
|
137
|
-
|
138
|
-
/**
|
139
|
-
* History.discardedStates
|
140
|
-
* A hashed array of discarded states
|
141
|
-
*/
|
142
|
-
History.discardedStates = {};
|
143
|
-
|
144
|
-
/**
|
145
|
-
* History.discardState(State)
|
146
|
-
* Discards the state by ignoring it through History
|
147
|
-
* @param {object} State
|
148
|
-
* @return {true}
|
149
|
-
*/
|
150
|
-
History.discardState = function(discardedState,forwardState,backState){
|
151
|
-
//History.debug('History.discardState', arguments);
|
152
|
-
// Prepare
|
153
|
-
var discardedStateHash = History.getHashByState(discardedState),
|
154
|
-
discardObject;
|
155
|
-
|
156
|
-
// Create Discard Object
|
157
|
-
discardObject = {
|
158
|
-
'discardedState': discardedState,
|
159
|
-
'backState': backState,
|
160
|
-
'forwardState': forwardState
|
161
|
-
};
|
162
|
-
|
163
|
-
// Add to DiscardedStates
|
164
|
-
History.discardedStates[discardedStateHash] = discardObject;
|
165
|
-
|
166
|
-
// Return true
|
167
|
-
return true;
|
168
|
-
};
|
169
|
-
|
170
|
-
/**
|
171
|
-
* History.discardHash(hash)
|
172
|
-
* Discards the hash by ignoring it through History
|
173
|
-
* @param {string} hash
|
174
|
-
* @return {true}
|
175
|
-
*/
|
176
|
-
History.discardHash = function(discardedHash,forwardState,backState){
|
177
|
-
//History.debug('History.discardState', arguments);
|
178
|
-
// Create Discard Object
|
179
|
-
var discardObject = {
|
180
|
-
'discardedHash': discardedHash,
|
181
|
-
'backState': backState,
|
182
|
-
'forwardState': forwardState
|
183
|
-
};
|
184
|
-
|
185
|
-
// Add to discardedHash
|
186
|
-
History.discardedHashes[discardedHash] = discardObject;
|
187
|
-
|
188
|
-
// Return true
|
189
|
-
return true;
|
190
|
-
};
|
191
|
-
|
192
|
-
/**
|
193
|
-
* History.discardState(State)
|
194
|
-
* Checks to see if the state is discarded
|
195
|
-
* @param {object} State
|
196
|
-
* @return {bool}
|
197
|
-
*/
|
198
|
-
History.discardedState = function(State){
|
199
|
-
// Prepare
|
200
|
-
var StateHash = History.getHashByState(State),
|
201
|
-
discarded;
|
202
|
-
|
203
|
-
// Check
|
204
|
-
discarded = History.discardedStates[StateHash]||false;
|
205
|
-
|
206
|
-
// Return true
|
207
|
-
return discarded;
|
208
|
-
};
|
209
|
-
|
210
|
-
/**
|
211
|
-
* History.discardedHash(hash)
|
212
|
-
* Checks to see if the state is discarded
|
213
|
-
* @param {string} State
|
214
|
-
* @return {bool}
|
215
|
-
*/
|
216
|
-
History.discardedHash = function(hash){
|
217
|
-
// Check
|
218
|
-
var discarded = History.discardedHashes[hash]||false;
|
219
|
-
|
220
|
-
// Return true
|
221
|
-
return discarded;
|
222
|
-
};
|
223
|
-
|
224
|
-
/**
|
225
|
-
* History.recycleState(State)
|
226
|
-
* Allows a discarded state to be used again
|
227
|
-
* @param {object} data
|
228
|
-
* @param {string} title
|
229
|
-
* @param {string} url
|
230
|
-
* @return {true}
|
231
|
-
*/
|
232
|
-
History.recycleState = function(State){
|
233
|
-
//History.debug('History.recycleState', arguments);
|
234
|
-
// Prepare
|
235
|
-
var StateHash = History.getHashByState(State);
|
236
|
-
|
237
|
-
// Remove from DiscardedStates
|
238
|
-
if ( History.discardedState(State) ) {
|
239
|
-
delete History.discardedStates[StateHash];
|
240
|
-
}
|
241
|
-
|
242
|
-
// Return true
|
243
|
-
return true;
|
244
|
-
};
|
245
|
-
|
246
|
-
|
247
|
-
// ====================================================================
|
248
|
-
// HTML4 HashChange Support
|
249
|
-
|
250
|
-
if ( History.emulated.hashChange ) {
|
251
|
-
/*
|
252
|
-
* We must emulate the HTML4 HashChange Support by manually checking for hash changes
|
253
|
-
*/
|
254
|
-
|
255
|
-
/**
|
256
|
-
* History.hashChangeInit()
|
257
|
-
* Init the HashChange Emulation
|
258
|
-
*/
|
259
|
-
History.hashChangeInit = function(){
|
260
|
-
// Define our Checker Function
|
261
|
-
History.checkerFunction = null;
|
262
|
-
|
263
|
-
// Define some variables that will help in our checker function
|
264
|
-
var lastDocumentHash = '',
|
265
|
-
iframeId, iframe,
|
266
|
-
lastIframeHash, checkerRunning;
|
267
|
-
|
268
|
-
// Handle depending on the browser
|
269
|
-
if ( History.isInternetExplorer() ) {
|
270
|
-
// IE6 and IE7
|
271
|
-
// We need to use an iframe to emulate the back and forward buttons
|
272
|
-
|
273
|
-
// Create iFrame
|
274
|
-
iframeId = 'historyjs-iframe';
|
275
|
-
iframe = document.createElement('iframe');
|
276
|
-
|
277
|
-
// Adjust iFarme
|
278
|
-
iframe.setAttribute('id', iframeId);
|
279
|
-
iframe.style.display = 'none';
|
280
|
-
|
281
|
-
// Append iFrame
|
282
|
-
document.body.appendChild(iframe);
|
283
|
-
|
284
|
-
// Create initial history entry
|
285
|
-
iframe.contentWindow.document.open();
|
286
|
-
iframe.contentWindow.document.close();
|
287
|
-
|
288
|
-
// Define some variables that will help in our checker function
|
289
|
-
lastIframeHash = '';
|
290
|
-
checkerRunning = false;
|
291
|
-
|
292
|
-
// Define the checker function
|
293
|
-
History.checkerFunction = function(){
|
294
|
-
// Check Running
|
295
|
-
if ( checkerRunning ) {
|
296
|
-
return false;
|
297
|
-
}
|
298
|
-
|
299
|
-
// Update Running
|
300
|
-
checkerRunning = true;
|
301
|
-
|
302
|
-
// Fetch
|
303
|
-
var documentHash = History.getHash()||'',
|
304
|
-
iframeHash = History.unescapeHash(iframe.contentWindow.document.location.hash)||'';
|
305
|
-
|
306
|
-
// The Document Hash has changed (application caused)
|
307
|
-
if ( documentHash !== lastDocumentHash ) {
|
308
|
-
// Equalise
|
309
|
-
lastDocumentHash = documentHash;
|
310
|
-
|
311
|
-
// Create a history entry in the iframe
|
312
|
-
if ( iframeHash !== documentHash ) {
|
313
|
-
//History.debug('hashchange.checker: iframe hash change', 'documentHash (new):', documentHash, 'iframeHash (old):', iframeHash);
|
314
|
-
|
315
|
-
// Equalise
|
316
|
-
lastIframeHash = iframeHash = documentHash;
|
317
|
-
|
318
|
-
// Create History Entry
|
319
|
-
iframe.contentWindow.document.open();
|
320
|
-
iframe.contentWindow.document.close();
|
321
|
-
|
322
|
-
// Update the iframe's hash
|
323
|
-
iframe.contentWindow.document.location.hash = History.escapeHash(documentHash);
|
324
|
-
}
|
325
|
-
|
326
|
-
// Trigger Hashchange Event
|
327
|
-
History.Adapter.trigger(window,'hashchange');
|
328
|
-
}
|
329
|
-
|
330
|
-
// The iFrame Hash has changed (back button caused)
|
331
|
-
else if ( iframeHash !== lastIframeHash ) {
|
332
|
-
//History.debug('hashchange.checker: iframe hash out of sync', 'iframeHash (new):', iframeHash, 'documentHash (old):', documentHash);
|
333
|
-
|
334
|
-
// Equalise
|
335
|
-
lastIframeHash = iframeHash;
|
336
|
-
|
337
|
-
// Update the Hash
|
338
|
-
History.setHash(iframeHash,false);
|
339
|
-
}
|
340
|
-
|
341
|
-
// Reset Running
|
342
|
-
checkerRunning = false;
|
343
|
-
|
344
|
-
// Return true
|
345
|
-
return true;
|
346
|
-
};
|
347
|
-
}
|
348
|
-
else {
|
349
|
-
// We are not IE
|
350
|
-
// Firefox 1 or 2, Opera
|
351
|
-
|
352
|
-
// Define the checker function
|
353
|
-
History.checkerFunction = function(){
|
354
|
-
// Prepare
|
355
|
-
var documentHash = History.getHash();
|
356
|
-
|
357
|
-
// The Document Hash has changed (application caused)
|
358
|
-
if ( documentHash !== lastDocumentHash ) {
|
359
|
-
// Equalise
|
360
|
-
lastDocumentHash = documentHash;
|
361
|
-
|
362
|
-
// Trigger Hashchange Event
|
363
|
-
History.Adapter.trigger(window,'hashchange');
|
364
|
-
}
|
365
|
-
|
366
|
-
// Return true
|
367
|
-
return true;
|
368
|
-
};
|
369
|
-
}
|
370
|
-
|
371
|
-
// Apply the checker function
|
372
|
-
History.intervalList.push(setInterval(History.checkerFunction, History.options.hashChangeInterval));
|
373
|
-
|
374
|
-
// Done
|
375
|
-
return true;
|
376
|
-
}; // History.hashChangeInit
|
377
|
-
|
378
|
-
// Bind hashChangeInit
|
379
|
-
History.Adapter.onDomLoad(History.hashChangeInit);
|
380
|
-
|
381
|
-
} // History.emulated.hashChange
|
382
|
-
|
383
|
-
|
384
|
-
// ====================================================================
|
385
|
-
// HTML5 State Support
|
386
|
-
|
387
|
-
// Non-Native pushState Implementation
|
388
|
-
if ( History.emulated.pushState ) {
|
389
|
-
/*
|
390
|
-
* We must emulate the HTML5 State Management by using HTML4 HashChange
|
391
|
-
*/
|
392
|
-
|
393
|
-
/**
|
394
|
-
* History.onHashChange(event)
|
395
|
-
* Trigger HTML5's window.onpopstate via HTML4 HashChange Support
|
396
|
-
*/
|
397
|
-
History.onHashChange = function(event){
|
398
|
-
//History.debug('History.onHashChange', arguments);
|
399
|
-
|
400
|
-
// Prepare
|
401
|
-
var currentUrl = ((event && event.newURL) || document.location.href),
|
402
|
-
currentHash = History.getHashByUrl(currentUrl),
|
403
|
-
currentState = null,
|
404
|
-
currentStateHash = null,
|
405
|
-
currentStateHashExits = null,
|
406
|
-
discardObject;
|
407
|
-
|
408
|
-
// Check if we are the same state
|
409
|
-
if ( History.isLastHash(currentHash) ) {
|
410
|
-
// There has been no change (just the page's hash has finally propagated)
|
411
|
-
//History.debug('History.onHashChange: no change');
|
412
|
-
History.busy(false);
|
413
|
-
return false;
|
414
|
-
}
|
415
|
-
|
416
|
-
// Reset the double check
|
417
|
-
History.doubleCheckComplete();
|
418
|
-
|
419
|
-
// Store our location for use in detecting back/forward direction
|
420
|
-
History.saveHash(currentHash);
|
421
|
-
|
422
|
-
// Expand Hash
|
423
|
-
if ( currentHash && History.isTraditionalAnchor(currentHash) ) {
|
424
|
-
//History.debug('History.onHashChange: traditional anchor', currentHash);
|
425
|
-
// Traditional Anchor Hash
|
426
|
-
History.Adapter.trigger(window,'anchorchange');
|
427
|
-
History.busy(false);
|
428
|
-
return false;
|
429
|
-
}
|
430
|
-
|
431
|
-
// Create State
|
432
|
-
currentState = History.extractState(History.getFullUrl(currentHash||document.location.href,false),true);
|
433
|
-
|
434
|
-
// Check if we are the same state
|
435
|
-
if ( History.isLastSavedState(currentState) ) {
|
436
|
-
//History.debug('History.onHashChange: no change');
|
437
|
-
// There has been no change (just the page's hash has finally propagated)
|
438
|
-
History.busy(false);
|
439
|
-
return false;
|
440
|
-
}
|
441
|
-
|
442
|
-
// Create the state Hash
|
443
|
-
currentStateHash = History.getHashByState(currentState);
|
444
|
-
|
445
|
-
// Check if we are DiscardedState
|
446
|
-
discardObject = History.discardedState(currentState);
|
447
|
-
if ( discardObject ) {
|
448
|
-
// Ignore this state as it has been discarded and go back to the state before it
|
449
|
-
if ( History.getHashByIndex(-2) === History.getHashByState(discardObject.forwardState) ) {
|
450
|
-
// We are going backwards
|
451
|
-
//History.debug('History.onHashChange: go backwards');
|
452
|
-
History.back(false);
|
453
|
-
} else {
|
454
|
-
// We are going forwards
|
455
|
-
//History.debug('History.onHashChange: go forwards');
|
456
|
-
History.forward(false);
|
457
|
-
}
|
458
|
-
return false;
|
459
|
-
}
|
460
|
-
|
461
|
-
// Push the new HTML5 State
|
462
|
-
//History.debug('History.onHashChange: success hashchange');
|
463
|
-
History.pushState(currentState.data,currentState.title,currentState.url,false);
|
464
|
-
|
465
|
-
// End onHashChange closure
|
466
|
-
return true;
|
467
|
-
};
|
468
|
-
History.Adapter.bind(window,'hashchange',History.onHashChange);
|
469
|
-
|
470
|
-
/**
|
471
|
-
* History.pushState(data,title,url)
|
472
|
-
* Add a new State to the history object, become it, and trigger onpopstate
|
473
|
-
* We have to trigger for HTML4 compatibility
|
474
|
-
* @param {object} data
|
475
|
-
* @param {string} title
|
476
|
-
* @param {string} url
|
477
|
-
* @return {true}
|
478
|
-
*/
|
479
|
-
History.pushState = function(data,title,url,queue){
|
480
|
-
//History.debug('History.pushState: called', arguments);
|
481
|
-
|
482
|
-
// Check the State
|
483
|
-
if ( History.getHashByUrl(url) ) {
|
484
|
-
throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).');
|
485
|
-
}
|
486
|
-
|
487
|
-
// Handle Queueing
|
488
|
-
if ( queue !== false && History.busy() ) {
|
489
|
-
// Wait + Push to Queue
|
490
|
-
//History.debug('History.pushState: we must wait', arguments);
|
491
|
-
History.pushQueue({
|
492
|
-
scope: History,
|
493
|
-
callback: History.pushState,
|
494
|
-
args: arguments,
|
495
|
-
queue: queue
|
496
|
-
});
|
497
|
-
return false;
|
498
|
-
}
|
499
|
-
|
500
|
-
// Make Busy
|
501
|
-
History.busy(true);
|
502
|
-
|
503
|
-
// Fetch the State Object
|
504
|
-
var newState = History.createStateObject(data,title,url),
|
505
|
-
newStateHash = History.getHashByState(newState),
|
506
|
-
oldState = History.getState(false),
|
507
|
-
oldStateHash = History.getHashByState(oldState),
|
508
|
-
html4Hash = History.getHash();
|
509
|
-
|
510
|
-
// Store the newState
|
511
|
-
History.storeState(newState);
|
512
|
-
History.expectedStateId = newState.id;
|
513
|
-
|
514
|
-
// Recycle the State
|
515
|
-
History.recycleState(newState);
|
516
|
-
|
517
|
-
// Force update of the title
|
518
|
-
// History.setTitle(newState);
|
519
|
-
|
520
|
-
// Check if we are the same State
|
521
|
-
if ( newStateHash === oldStateHash ) {
|
522
|
-
//History.debug('History.pushState: no change', newStateHash);
|
523
|
-
History.busy(false);
|
524
|
-
return false;
|
525
|
-
}
|
526
|
-
|
527
|
-
// Update HTML4 Hash
|
528
|
-
if ( newStateHash !== html4Hash && newStateHash !== History.getShortUrl(document.location.href) ) {
|
529
|
-
//History.debug('History.pushState: update hash', newStateHash, html4Hash);
|
530
|
-
History.setHash(newStateHash,false);
|
531
|
-
return false;
|
532
|
-
}
|
533
|
-
|
534
|
-
// Update HTML5 State
|
535
|
-
History.saveState(newState);
|
536
|
-
|
537
|
-
// Fire HTML5 Event
|
538
|
-
//History.debug('History.pushState: trigger popstate');
|
539
|
-
History.Adapter.trigger(window,'statechange');
|
540
|
-
History.busy(false);
|
541
|
-
|
542
|
-
// End pushState closure
|
543
|
-
return true;
|
544
|
-
};
|
545
|
-
|
546
|
-
/**
|
547
|
-
* History.replaceState(data,title,url)
|
548
|
-
* Replace the State and trigger onpopstate
|
549
|
-
* We have to trigger for HTML4 compatibility
|
550
|
-
* @param {object} data
|
551
|
-
* @param {string} title
|
552
|
-
* @param {string} url
|
553
|
-
* @return {true}
|
554
|
-
*/
|
555
|
-
History.replaceState = function(data,title,url,queue){
|
556
|
-
//History.debug('History.replaceState: called', arguments);
|
557
|
-
|
558
|
-
// Check the State
|
559
|
-
if ( History.getHashByUrl(url) ) {
|
560
|
-
throw new Error('History.js does not support states with fragement-identifiers (hashes/anchors).');
|
561
|
-
}
|
562
|
-
|
563
|
-
// Handle Queueing
|
564
|
-
if ( queue !== false && History.busy() ) {
|
565
|
-
// Wait + Push to Queue
|
566
|
-
//History.debug('History.replaceState: we must wait', arguments);
|
567
|
-
History.pushQueue({
|
568
|
-
scope: History,
|
569
|
-
callback: History.replaceState,
|
570
|
-
args: arguments,
|
571
|
-
queue: queue
|
572
|
-
});
|
573
|
-
return false;
|
574
|
-
}
|
575
|
-
|
576
|
-
// Make Busy
|
577
|
-
History.busy(true);
|
578
|
-
|
579
|
-
// Fetch the State Objects
|
580
|
-
var newState = History.createStateObject(data,title,url),
|
581
|
-
oldState = History.getState(false),
|
582
|
-
previousState = History.getStateByIndex(-2);
|
583
|
-
|
584
|
-
// Discard Old State
|
585
|
-
History.discardState(oldState,newState,previousState);
|
586
|
-
|
587
|
-
// Alias to PushState
|
588
|
-
History.pushState(newState.data,newState.title,newState.url,false);
|
589
|
-
|
590
|
-
// End replaceState closure
|
591
|
-
return true;
|
592
|
-
};
|
593
|
-
|
594
|
-
} // History.emulated.pushState
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
// ====================================================================
|
599
|
-
// Initialise
|
600
|
-
|
601
|
-
// Non-Native pushState Implementation
|
602
|
-
if ( History.emulated.pushState ) {
|
603
|
-
/**
|
604
|
-
* Ensure initial state is handled correctly
|
605
|
-
*/
|
606
|
-
if ( History.getHash() && !History.emulated.hashChange ) {
|
607
|
-
History.Adapter.onDomLoad(function(){
|
608
|
-
History.Adapter.trigger(window,'hashchange');
|
609
|
-
});
|
610
|
-
}
|
611
|
-
|
612
|
-
} // History.emulated.pushState
|
613
|
-
|
614
|
-
}; // History.initHtml4
|
615
|
-
|
616
|
-
// Try and Initialise History
|
617
|
-
if ( typeof History.init !== 'undefined' ) {
|
618
|
-
History.init();
|
619
|
-
}
|
620
|
-
|
621
|
-
})(window);
|