Last active
December 19, 2015 23:29
-
-
Save juuliaans/6034831 to your computer and use it in GitHub Desktop.
Revisions
-
juuliaans revised this gist
Jul 19, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,7 @@ resolveURL: function (route, params, appendRoot) { //matchs named parameters var regExpNamedParams = new RegExp("\\((/([^\\/]+):"+p+")\\)"); //this is if the parameter has any special way of encoding itself (such as a date could be enconded as text yy-mm-dd) //var value = router.encodeParameter(p, params[p]); var nameOptParam = href.match(regExpNamedParams); -
juuliaans created this gist
Jul 19, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ resolveURL: function (route, params, appendRoot) { var appendRoot = (appendRoot == false) ? false : true; var route, params; var href = ""; var regExpAllNormalParams = /(\(\?)?\/:\w+/g; var regExpAllOptionalParams = /\((.*?)\)/g; href = router.routes[route]; for (var p in params) { //matchs normal parameters var regExpNormal = new RegExp("(\\(\\?)?:"+ p); //matchs optional parameters var regExpOptional = new RegExp("\\((/:" + p + ")\\)"); //matchs named parameters var regExpNamedParams = new RegExp("\\((/([^\\/]+):"+p+")\\)"); //this is if the parameters has any special way of encoding itself (such as a date could be enconded as text yy-mm-dd) //var value = router.encodeParameter(p, params[p]); var nameOptParam = href.match(regExpNamedParams); if (nameOptParam != null) { href = href.replace(regExpNamedParams, "/" + ((nameOptParam[2]) ? nameOptParam[2] : "") + escape(value)); } href = href.replace(regExpOptional, "/" + escape(value)); href = href.replace(regExpNormal, escape(value)); } href = href.replace(regExpAllOptionalParams, ""); href = href.replace(regExpAllNormalParams, ""); //if the app has any root url //href = (appendRoot) ? app.root + href : href; return href; }