forked from aaronlord/laroute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaroute.min.js
1 lines (1 loc) · 1.94 KB
/
laroute.min.js
1
(()=>{let t=(()=>{let t={absolute:$ABSOLUTE$,rootUrl:"$ROOTURL$",routes:$ROUTES$,prefix:"$PREFIX$",route:function(t,e,r){return(r=r||this.getByName(t))?this.toRoute(r,e):void 0},url:function(t,e){let r=0===Object.keys(e).length&&e.constructor===Object,n=!e||r?t:t.concat("/"+e.join("/"));return this.getCorrectUrl(n)},toRoute:function(t,e){let r=this.replaceNamedParameters(t.uri,e),n=this.getRouteQueryString(e);return this.absolute&&this.isOtherHost(t)?"//"+t.host+"/"+r+n:this.getCorrectUrl(r+n)},isOtherHost:function(t){return t.host&&t.host!==window.location.hostname},replaceNamedParameters:function(t,e){return(t=t.replace(/{(.*?)\??}/g,function(t,r){if(e.hasOwnProperty(r)){let t=e[r];return delete e[r],t}return t})).replace(/\/{.*?\?}/g,"")},getRouteQueryString:function(t){let e=[];for(let r in t)t.hasOwnProperty(r)&&e.push(r+"="+t[r]);return e.length<1?"":"?"+e.join("&")},getByName:function(t){for(let e in this.routes)if(this.routes.hasOwnProperty(e)&&this.routes[e].name===t)return this.routes[e]},getByAction:function(t){for(let e in this.routes)if(this.routes.hasOwnProperty(e)&&this.routes[e].action===t)return this.routes[e]},getCorrectUrl:function(t){let e=this.prefix+"/"+t.replace(/^\/?/,"");return this.absolute?this.rootUrl.replace("//?$/","")+e:e}},e=function(t,e,r){return e=e||t,'<a href="'+t+'" '+function(t){if(!t)return"";let e=[];for(let r in t)t.hasOwnProperty(r)&&e.push(r+'="'+t[r]+'"');return e.join(" ")}(r)+">"+e+"</a>"};return{action:function(e,r){return t.route(e,r||{},t.getByAction(e))},route:function(e,r){return t.route(e,r||{})},url:function(e,r){return t.url(e,r||{})},link_to:function(t,r,n){return e(this.url(t),r,n)},link_to_route:function(t,r,n,o){return e(this.route(t,n),r,o)},link_to_action:function(t,r,n,o){return e(this.action(t,n),r,o)}}}).call(this);"function"==typeof define&&define.amd&&!tests?define(function(){return t}):"object"==typeof module&&module.exports&&!tests?module.exports=t:window.$NAMESPACE$=t}).call(this);