-
Notifications
You must be signed in to change notification settings - Fork 5
/
routeManager.min.js
1 lines (1 loc) · 1.95 KB
/
routeManager.min.js
1
!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define("Route",[],b):a.Route=b()}(this,function(){var a;return a=function(){function a(){}return a.prototype.getRe=function(a){var b;return b="",null!=a.parent&&(b=this.getRe(a.parent)),b+a.re},a.prototype.is=function(a,b){return a.name===b},a.prototype.isSonOf=function(a,b){return this.is(a,b)?!0:null!=a.parent?this.isSonOf(a.parent,b):!1},a.prototype.analizeRoute=function(a){var b,c,d,e;for(a._fullRe=this.getRe(a),a._parameters=[],d=/:(\w+)(?:\(([^\(]+)\))?/g,e=[];b=d.exec(a._fullRe);)c={name:b[1]},null!=b[2]&&(c.regexp=new RegExp("^"+b[2]+"$")),e.push(a._parameters.push(c));return e},a.prototype.getParameters=function(a){return null==a._parameters&&this.analizeRoute(a),a._parameters},a.prototype.getLink=function(a,b){var c,d,e,f,g,h;for(null==a._parameters&&this.analizeRoute(a),c=a._fullRe,e=/:(\w+)(?:\(([^\(]+)\))?/,h=a._parameters,f=0,g=h.length;g>f;f++){if(d=h[f],null==b[d.name])return null;if(null!=d.regexp&&!d.regexp.test(b[d.name]))return null;c=c.replace(e,b[d.name])}return c},a}()}),function(a,b){"object"==typeof exports?module.exports=b(require("Route")):"function"==typeof define&&define.amd?define("RouteManager",["Route"],b):a.RouteManager=b(a.Route)}(this,function(a){var b;return b=function(){function b(b){this.routeMap=b,this.route=new a}return b.prototype.getRoute=function(a){if("object"==typeof a)return a;if(null==this.routeMap[a])throw new Error("route not found");return this.routeMap[a]},b.prototype.is=function(a,b){var c;return c=this.getRoute(a),this.route.is(c,b)},b.prototype.isSonOf=function(a,b){var c;return c=this.getRoute(a),this.route.isSonOf(c,b)},b.prototype.getLink=function(a,b){var c;return null==b&&(b={}),c=this.getRoute(a),this.route.getLink(c,b)},b.prototype.getRe=function(a){var b;return b=this.getRoute(a),this.route.getRe(b)},b.prototype.getParameters=function(a){var b;return b=this.getRoute(a),this.route.getParameters(b)},b}()});