forked from albertosarullo/Router.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrouter.min.js
2 lines (2 loc) · 1.02 KB
/
router.min.js
1
2
/* Router.js - by Alberto Sarullo | forked by Marco Colombo | forked by Daniele Messa - https://github.com/albertosarullo/Router.js */
;(function(q,l,m){q.Router=function(){var f,n,h,p="/Router.js",g=[{controller:"home",route:""}];return f={init:function(d){g=d||[];n=setInterval(function(){var e,b;if(l.location.hash!==p){e=l.location.hash;var a,c,d;for(b=0;b<g.length;b+=1)if(a=g[b].route,c=RegExp(a.replace(/:[^\s\/]+/ig,"([^\\s\\/]+)")),c.test(e)){c=e.match(c);e={};b=g[b].controller;if(c)for(c.shift(),d=a.match(/:[^\s\/]+/ig),a=0;a<c.length;a+=1)e[d[a].substr(1)]=c[a];h&&h(b,e);break}p=l.location.hash}},250);return f},deinit:function(){clearInterval(n); return f},onChange:function(d){h=d;return f},go:function(d,e){var b,a,c,f,h,k;d=""===d?"home":d;for(b=0;b<g.length;b+=1)if(g[b].controller===d){a=g[b].route;f=c=0;if(h=a.match(/:[^\s\/]+/ig))c=h.length;for(k in e)e.hasOwnProperty(k)&&-1!==a.indexOf(":"+k)&&(f+=1,a=a.replace(":"+k,e[k]));if(f===c)break;else a=m}a!==m&&setTimeout(function(){l.location.hash=a},0)}}}()})(window,document);