diff --git a/dist/js/route.js b/dist/js/route.js index 18b8226d..07eb5ca7 100644 --- a/dist/js/route.js +++ b/dist/js/route.js @@ -265,10 +265,14 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var UrlBuilder = function () { function UrlBuilder(name, absolute) { + var route = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; + var customZiggy = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + _classCallCheck(this, UrlBuilder); this.name = name; - this.route = Ziggy.namedRoutes[this.name]; + this.ziggy = customZiggy ? customZiggy : Ziggy; + this.route = route ? route : this.ziggy.namedRoutes[this.name]; if (typeof this.name === 'undefined') { throw new Error('Ziggy Error: You must provide a route name'); @@ -286,13 +290,13 @@ var UrlBuilder = function () { value: function setDomain() { if (!this.absolute) return '/'; - if (!this.route.domain) return Ziggy.baseUrl.replace(/\/?$/, '/'); + if (!this.route.domain) return this.ziggy.baseUrl.replace(/\/?$/, '/'); - var host = (this.route.domain || Ziggy.baseDomain).replace(/\/+$/, ''); + var host = (this.route.domain || this.ziggy.baseDomain).replace(/\/+$/, ''); - if (Ziggy.basePort && host.replace(/\/+$/, '') === Ziggy.baseDomain.replace(/\/+$/, '')) host = Ziggy.baseDomain + ':' + Ziggy.basePort; + if (this.ziggy.basePort && host.replace(/\/+$/, '') === this.ziggy.baseDomain.replace(/\/+$/, '')) host = this.ziggy.baseDomain + ':' + this.ziggy.basePort; - return Ziggy.baseProtocol + '://' + host + '/'; + return this.ziggy.baseProtocol + '://' + host + '/'; } }, { key: 'construct', diff --git a/dist/js/route.min.js b/dist/js/route.min.js index 26715953..91b1da16 100644 --- a/dist/js/route.min.js +++ b/dist/js/route.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("route",[],t):"object"==typeof exports?exports.route=t():e.route=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t,r){return new f(e,t,r)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=a;var u=r(1),s=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:null,r=Object.keys(Ziggy.namedRoutes),n=r.filter(function(e){return new t(e).matchUrl()})[0];return e?e==n:n}},{key:"parse",value:function(){this.return=this.hydrateUrl()+this.constructQuery()}},{key:"url",value:function(){return this.parse(),this.return}},{key:"toString",value:function(){return this.url()}},{key:"valueOf",value:function(){return this.url()}}]),t}(String)},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:null,r=Object.keys(Ziggy.namedRoutes),n=r.filter(function(e){return new t(e).matchUrl()})[0];return e?e==n:n}},{key:"parse",value:function(){this.return=this.hydrateUrl()+this.constructQuery()}},{key:"url",value:function(){return this.parse(),this.return}},{key:"toString",value:function(){return this.url()}},{key:"valueOf",value:function(){return this.url()}}]),t}(String)},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r2&&void 0!==arguments[2]?arguments[2]:null,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;if(n(this,e),this.name=t,this.ziggy=i||Ziggy,this.route=o||this.ziggy.namedRoutes[this.name],void 0===this.name)throw new Error("Ziggy Error: You must provide a route name");if(void 0===this.route)throw new Error("Ziggy Error: route '"+this.name+"' is not found in the route list");this.absolute=void 0===r||r,this.domain=this.setDomain(),this.path=this.route.uri.replace(/^\//,"")}return o(e,[{key:"setDomain",value:function(){if(!this.absolute)return"/";if(!this.route.domain)return this.ziggy.baseUrl.replace(/\/?$/,"/");var e=(this.route.domain||this.ziggy.baseDomain).replace(/\/+$/,"");return this.ziggy.basePort&&e.replace(/\/+$/,"")===this.ziggy.baseDomain.replace(/\/+$/,"")&&(e=this.ziggy.baseDomain+":"+this.ziggy.basePort),this.ziggy.baseProtocol+"://"+e+"/"}},{key:"construct",value:function(){return this.domain+this.path}}]),e}();t.a=i}]).default}); \ No newline at end of file diff --git a/src/js/UrlBuilder.js b/src/js/UrlBuilder.js index 277259e9..c036fbc9 100644 --- a/src/js/UrlBuilder.js +++ b/src/js/UrlBuilder.js @@ -1,8 +1,9 @@ class UrlBuilder { - constructor(name, absolute) { + constructor(name, absolute, route = null, customZiggy = null) { - this.name = name; - this.route = Ziggy.namedRoutes[this.name]; + this.name = name; + this.ziggy = customZiggy ? customZiggy : Ziggy; + this.route = route ? route : this.ziggy.namedRoutes[this.name]; if (typeof this.name === 'undefined') { throw new Error('Ziggy Error: You must provide a route name'); @@ -10,24 +11,24 @@ class UrlBuilder { throw new Error(`Ziggy Error: route '${this.name}' is not found in the route list`); } - this.absolute = typeof absolute === 'undefined' ? true : absolute; - this.domain = this.setDomain(); - this.path = this.route.uri.replace(/^\//, ''); + this.absolute = typeof absolute === 'undefined' ? true : absolute; + this.domain = this.setDomain(); + this.path = this.route.uri.replace(/^\//, ''); } setDomain() { - if (! this.absolute) + if (!this.absolute) return '/'; if (!this.route.domain) - return Ziggy.baseUrl.replace(/\/?$/, '/'); + return this.ziggy.baseUrl.replace(/\/?$/, '/'); - let host = (this.route.domain || Ziggy.baseDomain).replace(/\/+$/, ''); + let host = (this.route.domain || this.ziggy.baseDomain).replace(/\/+$/, ''); - if (Ziggy.basePort && (host.replace(/\/+$/, '') === Ziggy.baseDomain.replace(/\/+$/, ''))) - host = Ziggy.baseDomain + ':' + Ziggy.basePort; + if (this.ziggy.basePort && (host.replace(/\/+$/, '') === this.ziggy.baseDomain.replace(/\/+$/, ''))) + host = this.ziggy.baseDomain + ':' + this.ziggy.basePort; - return Ziggy.baseProtocol + '://' + host + '/'; + return this.ziggy.baseProtocol + '://' + host + '/'; } construct() {