kekrozsak/web/bundles/fosjsrouting/js/router.js

14 lines
3.9 KiB
JavaScript

/**
* Portions of this code are from the Google Closure Library,
* received from the Closure Authors under the Apache 2.0 license.
*
* All other code is (C) 2011 FriendsOfSymfony and subject to the MIT license.
*/
(function() {var g=this;function i(a,b){var c=a.split("."),d=g;!(c[0]in d)&&d.execScript&&d.execScript("var "+c[0]);for(var e;c.length&&(e=c.shift());)!c.length&&b!==void 0?d[e]=b:d=d[e]?d[e]:d[e]={}}
function k(a){var b=typeof a;if(b=="object")if(a){if(a instanceof Array)return"array";if(a instanceof Object)return b;var c=Object.prototype.toString.call(a);if(c=="[object Window]")return"object";if(c=="[object Array]"||typeof a.length=="number"&&typeof a.splice!="undefined"&&typeof a.propertyIsEnumerable!="undefined"&&!a.propertyIsEnumerable("splice"))return"array";if(c=="[object Function]"||typeof a.call!="undefined"&&typeof a.propertyIsEnumerable!="undefined"&&!a.propertyIsEnumerable("call"))return"function"}else return"null";
else if(b=="function"&&typeof a.call=="undefined")return"object";return b};var l=/^[a-zA-Z0-9\-_.!~*'()]*$/;function m(a){a=""+a;return!l.test(a)?encodeURIComponent(a):a};var n=Array.prototype,p=n.forEach?function(a,b,c){n.forEach.call(a,b,c)}:function(a,b,c){for(var d=a.length,e=typeof a=="string"?a.split(""):a,f=0;f<d;f++)f in e&&b.call(c,e[f],f,a)};function q(a){var b=0,c;for(c in a)b++;return b}function r(a){var b={},c;for(c in a)b[c]=a[c];return b};function s(a,b){this.b={};this.a=[];var c=arguments.length;if(c>1){if(c%2)throw Error("Uneven number of arguments");for(var d=0;d<c;d+=2)this.set(arguments[d],arguments[d+1])}else if(a){var e;if(a instanceof s){t(a);d=a.a.concat();t(a);e=[];for(c=0;c<a.a.length;c++)e.push(a.b[a.a[c]])}else{var c=[],f=0;for(d in a)c[f++]=d;d=c;c=[];f=0;for(e in a)c[f++]=a[e];e=c}for(c=0;c<d.length;c++)this.set(d[c],e[c])}}s.prototype.e=0;s.prototype.m=0;
function t(a){if(a.e!=a.a.length){for(var b=0,c=0;b<a.a.length;){var d=a.a[b];Object.prototype.hasOwnProperty.call(a.b,d)&&(a.a[c++]=d);b++}a.a.length=c}if(a.e!=a.a.length){for(var e={},c=b=0;b<a.a.length;)d=a.a[b],Object.prototype.hasOwnProperty.call(e,d)||(a.a[c++]=d,e[d]=1),b++;a.a.length=c}}s.prototype.get=function(a,b){return Object.prototype.hasOwnProperty.call(this.b,a)?this.b[a]:b};
s.prototype.set=function(a,b){Object.prototype.hasOwnProperty.call(this.b,a)||(this.e++,this.a.push(a),this.m++);this.b[a]=b};function u(a){if(a[1]){var b=a[0],c=b.indexOf("#");c>=0&&(a.push(b.substr(c)),a[0]=b=b.substr(0,c));c=b.indexOf("?");c<0?a[1]="?":c==b.length-1&&(a[1]=void 0)}return a.join("")}function v(a,b){for(var c in b){var d=c,e=b[c],f=a;if(k(e)=="array")for(var h=0;h<e.length;h++)f.push("&",d),e[h]!==""&&f.push("=",m(e[h]));else e!=null&&(f.push("&",d),e!==""&&f.push("=",m(e)))}return a};function w(a,b){this.d=a||{c:""};this.g(b||{})}(function(a){a.f=function(){return a.l||(a.l=new a)}})(w);w.prototype.g=function(a){this.h=new s(a)};w.prototype.i=function(a){this.d.c=a};w.prototype.k=function(){return this.d.c};
w.prototype.j=function(a,b){if(!Object.prototype.hasOwnProperty.call(this.h.b,a))throw Error('The route "'+a+'" does not exist.');var c=this.h.get(a),d=b||{},e=r(d),f="",h=!0;p(c.tokens,function(b){if("text"===b[0])f=b[1]+f,h=!1;else if("variable"===b[0]){if(!1===h||!(b[3]in c.defaults)||b[3]in d&&d[b[3]]!=c.defaults[b[3]]){var j;if(b[3]in d){j=d[b[3]];var o=b[3];o in e&&delete e[o]}else if(b[3]in c.defaults)j=c.defaults[b[3]];else{if(h)return;throw Error('The route "'+a+'" requires the parameter "'+
b[3]+'".');}if(!(!0===j||!1===j||""===j)||!h)f=b[1]+encodeURIComponent(j).replace(/%2F/g,"/")+f;h=!1}}else throw Error('The token type "'+b[0]+'" is not supported.');});f===""&&(f="/");q(e)>0&&(f=u(v([f],e)));return this.d.c+f};i("fos.Router",w);i("fos.Router.setData",function(a){var b=w.f();b.i(a.base_url);b.g(a.routes)});w.getInstance=w.f;w.prototype.setRoutes=w.prototype.g;w.prototype.setBaseUrl=w.prototype.i;w.prototype.getBaseUrl=w.prototype.k;w.prototype.generate=w.prototype.j;window.Routing=w.f();})();