diff --git a/dist/js/route.js b/dist/js/route.js index 07eb5ca7..ff5116ac 100644 --- a/dist/js/route.js +++ b/dist/js/route.js @@ -99,13 +99,16 @@ var Router = function (_String) { _inherits(Router, _String); function Router(name, params, absolute) { + var customZiggy = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; + _classCallCheck(this, Router); var _this = _possibleConstructorReturn(this, (Router.__proto__ || Object.getPrototypeOf(Router)).call(this)); _this.name = name; _this.absolute = absolute; - _this.template = _this.name ? new __WEBPACK_IMPORTED_MODULE_0__UrlBuilder__["a" /* default */](name, absolute).construct() : '', _this.urlParams = _this.normalizeParams(params); + _this.ziggy = customZiggy ? customZiggy : Ziggy; + _this.template = _this.name ? new __WEBPACK_IMPORTED_MODULE_0__UrlBuilder__["a" /* default */](name, absolute, _this.ziggy).construct() : '', _this.urlParams = _this.normalizeParams(params); _this.queryParams = _this.normalizeParams(params); return _this; } @@ -250,8 +253,8 @@ var Router = function (_String) { return Router; }(String); -function route(name, params, absolute) { - return new Router(name, params, absolute); +function route(name, params, absolute, customZiggy) { + return new Router(name, params, absolute, customZiggy); }; /***/ }), @@ -264,15 +267,12 @@ var _createClass = function () { function defineProperties(target, props) { for function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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; - + function UrlBuilder(name, absolute, ziggyObject) { _classCallCheck(this, UrlBuilder); this.name = name; - this.ziggy = customZiggy ? customZiggy : Ziggy; - this.route = route ? route : this.ziggy.namedRoutes[this.name]; + this.ziggy = ziggyObject; + this.route = this.ziggy.namedRoutes[this.name]; if (typeof this.name === 'undefined') { throw new Error('Ziggy Error: You must provide a route name'); diff --git a/dist/js/route.min.js b/dist/js/route.min.js index 91b1da16..3fd12a52 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;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 +!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,n){return new f(e,t,r,n)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=a;var u=r(1),s=Object.assign||function(e){for(var t=1;t3&&void 0!==arguments[3]?arguments[3]:null;n(this,t);var s=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return s.name=e,s.absolute=i,s.ziggy=a||Ziggy,s.template=s.name?new u.a(e,i,s.ziggy).construct():"",s.urlParams=s.normalizeParams(r),s.queryParams=s.normalizeParams(r),s}return i(t,e),l(t,[{key:"normalizeParams",value:function(e){return void 0===e?{}:(e="object"!==(void 0===e?"undefined":c(e))?[e]:e,e.hasOwnProperty("id")&&-1==this.template.indexOf("{id}")&&(e=[e.id]),this.numericParamIndices=Array.isArray(e),s({},e))}},{key:"with",value:function(e){return this.urlParams=this.normalizeParams(e),this}},{key:"withQuery",value:function(e){return s(this.queryParams,e),this}},{key:"hydrateUrl",value:function(){var e=this,t=this.urlParams,r=0,n=this.template.match(/{([^}]+)}/gi),o=!1;return n&&n.length!=Object.keys(t).length&&(o=!0),this.template.replace(/{([^}]+)}/gi,function(n,i){var a=n.replace(/\{|\}/gi,"").replace(/\?$/,""),u=e.numericParamIndices?r:a,s=Ziggy.defaultParameters[a];if(s&&o&&(e.numericParamIndices?(t=Object.values(t),t.splice(u,0,s)):t[u]=s),r++,void 0!==t[u])return delete e.queryParams[u],t[u].id||encodeURIComponent(t[u]);if(-1===n.indexOf("?"))throw new Error("Ziggy Error: '"+a+"' key is required for route '"+e.name+"'");return""})}},{key:"matchUrl",value:function(){var e=(this.urlParams,window.location.hostname+(window.location.port?":"+window.location.port:"")+window.location.pathname),t=this.template.replace(/(\{[^\}]*\})/gi,"[^/?]+").split("://")[1],r=e.replace(/\/?$/,"/");return new RegExp("^"+t+"/$").test(r)}},{key:"constructQuery",value:function(){if(0===Object.keys(this.queryParams).length)return"";var e="?";return Object.keys(this.queryParams).forEach(function(t,r){this.queryParams[t]&&(e=0===r?e:e+"&",e+=t+"="+encodeURIComponent(this.queryParams[t]))}.bind(this)),e}},{key:"current",value:function(){var e=arguments.length>0&&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;r