diff --git a/build/tarantino.js b/build/tarantino.js index 3d66609..b6d5dbd 100644 --- a/build/tarantino.js +++ b/build/tarantino.js @@ -881,14 +881,7 @@ var listener = { || document.documentMode > 7)) { // At least for now HTML5 history is available for 'modern' browsers only if (this.history === true) { - // There is an old bug in Chrome that causes onpopstate to fire even - // upon initial page load. Since the handler is run manually in init(), - // this would cause Chrome to run it twise. Currently the only - // workaround seems to be to set the handler after the initial page load - // http://code.google.com/p/chromium/issues/detail?id=63040 - setTimeout(function() { - window.onpopstate = onchange; - }, 500); + window.onpopstate = onchange; } else { window.onhashchange = onchange; diff --git a/build/tarantino.min.js b/build/tarantino.min.js index ae9eb4f..fcbe806 100644 --- a/build/tarantino.min.js +++ b/build/tarantino.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define("tarantino",["exports"],e):e(t.tarantino=t.tarantino||{})}(this,function(t){"use strict";function e(t,e){return e={exports:{}},t(e,e.exports),e.exports}function r(){return""===h.hash||"#"===h.hash}function i(t){return this instanceof i?(Object.assign(this,o.prototype),this.params={},this.routes={},this.methods=["on","once","after","before"],this.scope=[],this._methods={},this._insert=this.insert,this.insert=this.insertEx,this.historySupport=null!=(null!=window.history?window.history.pushState:null),this.configure(),void this.mount(t||{})):new i(t)}var n=e(function(t,e){function r(t){for(var e=[],r=0,i=t.length;ra.indexOf(i,o)||~a.indexOf(r,o)&&!~a.indexOf(i,o)||!~a.indexOf(r,o)&&~a.indexOf(i,o)){if(s=a.indexOf(r,o),h=a.indexOf(i,o),~s&&!~h||!~s&&~h){var c=t.slice(0,(n||1)+1).join(e);t=[c].concat(t.slice((n||1)+1))}o=(h>s?h:s)+1,n=0}else o=0}return t}var a=/\?.*/,c=e.Router=function(t){this.params={},this.routes={},this.methods=["on","after","before"],this.scope=[],this._methods={},this.configure(),this.mount(t||{})};c.prototype.configure=function(t){t=t||{};for(var e=0;e0&&h?(this.async?this.invoke(n,this,i):(this.invoke(n,this),i()),!0):(i(),!0)):(this.last=[],"function"==typeof this.notfound&&this.invoke([this.notfound],{method:t,path:e},r),!1)},c.prototype.runlist=function(t){var e=this.every&&this.every.before?[this.every.before].concat(r(t)):r(t);return this.every&&this.every.on&&e.push(this.every.on),e.captures=t.captures,e.source=t.source,e},c.prototype.invoke=function(t,e,r){var o,s=this;this.async?(o=function(r,i){return Array.isArray(r)?n(r,o,i):void("function"==typeof r&&r.apply(e,(t.captures||[]).concat(i)))},n(t,o,function(){r&&r.apply(e,arguments)})):(o=function(r){return Array.isArray(r)?i(r,o):"function"==typeof r?r.apply(e,t.captures||[]):void("string"==typeof r&&s.resource&&s.resource[r].apply(e,t.captures||[]))},i(t,o))},c.prototype.traverse=function(t,e,r,i,n){function o(t){function e(t){for(var r=[],i=0;i=0;e--)Array.isArray(t[e])?(r(t[e]),0===t[e].length&&t.splice(e,1)):n(t[e])||t.splice(e,1)}if(!n)return t;var i=e(t);return i.matched=t.matched,i.captures=t.captures,i.after=t.after.filter(n),r(i),i}var s,h,a,c,u=[];if(e===this.delimiter&&r[t])return c=[[r.before,r[t]].filter(Boolean)],c.after=[r.after].filter(Boolean),c.matched=!0,c.captures=[],o(c);for(var f in r)if(r.hasOwnProperty(f)&&(!this._methods[f]||this._methods[f]&&"object"==typeof r[f]&&!Array.isArray(r[f]))){if(s=h=i+this.delimiter+f,this.strict||(h+="["+this.delimiter+"]?"),a=e.match(new RegExp("^"+h)),!a)continue;if(a[0]&&a[0]==e&&r[f][t])return c=[[r[f].before,r[f][t]].filter(Boolean)],c.after=[r[f].after].filter(Boolean),c.matched=!0,c.captures=a.slice(1),this.recurse&&r===this.routes&&(c.push([r.before,r.on].filter(Boolean)),c.after=c.after.concat([r.after].filter(Boolean))),o(c);if(c=this.traverse(t,e,r[f],s),c.matched)return c.length>0&&(u=u.concat(c)),this.recurse&&(u.push([r[f].before,r[f][t]].filter(Boolean)),c.after=c.after.concat([r[f].after].filter(Boolean)),r===this.routes&&(u.push([r.before,r.on].filter(Boolean)),c.after=c.after.concat([r.after].filter(Boolean)))),u.matched=!0,u.captures=c.captures,u.after=c.after,o(u)}return!1},c.prototype.insert=function(t,e,r,i){var n,o,h,a,c;if(e=e.filter(function(t){return t&&t.length>0}),i=i||this.routes,c=e.shift(),/\:|\*/.test(c)&&!/\\d|\\w/.test(c)&&(c=s(c,this.params)),e.length>0)return i[c]=i[c]||{},this.insert(t,e,r,i[c]);if(c||e.length||i!==this.routes){if(o=typeof i[c],h=Array.isArray(i[c]),i[c]&&!h&&"object"==o)switch(n=typeof i[c][t]){case"function":return void(i[c][t]=[i[c][t],r]);case"object":return void i[c][t].push(r);case"undefined":return void(i[c][t]=r)}else if("undefined"==o)return a={},a[t]=r,void(i[c]=a);throw new Error("Invalid route context: "+o)}switch(n=typeof i[t]){case"function":return void(i[t]=[i[t],r]);case"object":return void i[t].push(r);case"undefined":return void(i[t]=r)}},c.prototype.extend=function(t){function e(t){i._methods[t]=!0,i[t]=function(){var e=1===arguments.length?[t,""]:[t];i.on.apply(i,e.concat(Array.prototype.slice.call(arguments)))}}var r,i=this,n=t.length;for(r=0;r7))this.history===!0?setTimeout(function(){window.onpopstate=r},500):window.onhashchange=r,this.mode="modern";else{var o=document.createElement("iframe");o.id="state-frame",o.style.display="none",document.body.appendChild(o),this.writeFrame(""),"onpropertychange"in document&&"attachEvent"in document&&document.attachEvent("onpropertychange",function(){"location"===event.propertyName&&n.check()}),window.setInterval(function(){n.check()},50),this.onHashChanged=r,this.mode="legacy"}return i.listeners.push(t),this.mode},destroy:function(t){if(i&&i.listeners)for(var e=i.listeners,r=e.length-1;r>=0;r--)e[r]===t&&e.splice(r,1)},setHash:function(t){return"legacy"===this.mode&&this.writeFrame(t),this.history===!0?(window.history.pushState({},document.title,t),this.fire()):h.hash="/"===t[0]?t:"/"+t,this},writeFrame:function(t){var e=document.getElementById("state-frame"),r=e.contentDocument||e.contentWindow.document;r.open(),r.write("