-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1 lines (1 loc) · 2.55 KB
/
index.js
1
"use strict";function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return r}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}!function(e,t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).QueryRouter=t()}(void 0,function(){function l(e,t){var r=document.getElementById(t).outerHTML,n=document.getElementById(e);return n.innerHTML="",n.innerHTML=r}return function(){var r=this;r.home=function(){},r.routes=[],r.get=function(e,t){return r.routes.push({uri:e,callback:t})},r.go=function(t){if(!(void 0===t||""===t||r.routes.every(function(e){return e.uri.toLowerCase()!==t.toLowerCase()}))){var e=function(e){for(var t=[],r=0,n=Object.entries(e);r<n.length;r++){var o=_slicedToArray(n[r],2),i=o[0],u=o[1];t.push(encodeURIComponent(i)+"="+encodeURIComponent(u))}return t.join("&")}({page:t});return window.location.search="?".concat(e)}},r.next=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:1;return window.history.go(e)},r.back=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:1;return window.history.go(-e)},r.init=function(){var t=function(e){if(window.URLSearchParams)return Object.fromEntries(new URLSearchParams(e));var t=e.slice(1).split("&"),r={};return t.forEach(function(e){e=e.split("="),r[e[0]]=decodeURIComponent(e[1]||"")}),JSON.parse(JSON.stringify(r))}(window.location.search).page;if(void 0===t||""===t||this.routes.every(function(e){return e.uri.toLowerCase()!==t.toLowerCase()})){var e={page:"/",use:l};return this.home.call(window,e)}var r=!0,n=!1,o=void 0;try{for(var i,u=this.routes[Symbol.iterator]();!(r=(i=u.next()).done);r=!0){var a=i.value,c=new RegExp("^".concat(a.uri.toLowerCase(),"$")),f={page:t,use:l};if(c.test(t.toLowerCase()))return a.callback.call(window,f)}}catch(e){n=!0,o=e}finally{try{r||null==u.return||u.return()}finally{if(n)throw o}}}}});