This repository has been archived by the owner on May 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
leafeon.min.js
1 lines (1 loc) · 4.19 KB
/
leafeon.min.js
1
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.leafeon=n():t.leafeon=n()}(this,function(){return function(t){function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}var e={};return n.m=t,n.c=e,n.i=function(t){return t},n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:o})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},n.p="",n(n.s=0)}([function(t,n,e){"use strict";var o=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var e in n)n.hasOwnProperty(e)&&(t[e]=n[e])};return function(n,e){function o(){this.constructor=n}t(n,e),n.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}}();Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function t(){var t=this;this.getURI=function(){return t.URI=t.formatPath(t.windowObj.location.hash)},this.setURI=function(n){t.windowObj.location.hash=n},this.formatPath=function(n){return""===n?"/":(n.match(/^(?:\/)?(?:\#)?(?:\/)?[a-zA-Z0-9\-_\/:]+/)[0]!==n&&t.exception("Path is not formated correctly."),n.replace(/^(?:\/)?(?:\#)?(?:\/)/,"/"))},this.exception=function(t){throw new TypeError(t)},this.windowListener=function(t){"undefined"!=typeof window&&(window.onhashchange=function(){t()})};var n={location:{href:"/#/",hash:"#/"}};this.windowObj="undefined"==typeof window?n:window,this.URI=this.getURI()}return t}(),a=function(t){function n(){var n=t.call(this)||this;return n.setErrorCallback=function(t){return n.notFoundCallback=t,n},n.notFoundException=function(){null!==n.notFoundCallback&&n.notFoundCallback.apply(null,[])},n.before=function(t,e){return n.beforeRouteMiddleware=t,n.beforeRouteMiddlewareFunc=e,n},n.add=function(t,e,o){var r=e.split("/"),a=!1,u=[];return r.forEach(function(t){":"===t.substr(0,1)&&(a=!0,u.push(t.substr(1,t.length)))}),n.paramsEnabled=a,e=e.split("#")[1]||e,n.routes.push({name:t,path:e,callback:o,paramsEnabled:a,params:u}),n},n.map=function(t,e,o){return o.forEach(function(o){n.add(t+o.name,e+n.formatPath(o.path),o.callback)}),n},n.fetchRoute=function(t,e){var o=n.routes.find(function(n){return n.name===t||n.path===t});if(void 0===o)return n.notFoundException();if(!o.paramsEnabled)return void n.setURI(o.path);e||n.exception('Error: route "'+t+'" requires some parameters. None specified.');var r=n.generateURL(o.path,e);n.setURI(r)},n.generateURL=function(t,n){var e=t;return Object.keys(n).forEach(function(o){var r=t.split("/").find(function(t){return t===":"+o});void 0!==r&&(e=e.replace(r,n[o]))}),e},n.setRoute=function(t,e){void 0===e&&(e=[]),n.route=t,n.routeCall=t.callback,n.params=e,n.notfound=!1},n.handle=function(t){var e=n.getURI();t.forEach(function(t){var o=t.path.split("/");if(e.split("/").length===o.length){var r=n.handlingParams(t.path);return r.RouteString===e&&n.notfound?n.setRoute(t,r.params):void 0}})},n.handlingParams=function(t){for(var e=n.getURI().split("/"),o=t.split("/"),r=[],a=0;a<o.length;a++)":"===o[a].substr(0,1)&&(""!==e[a]&&r.push(e[a]),o[a]=e[a]);return{params:r,RouteString:o.join("/")}},n.run=function(t){n.route=null,n.routeCall=null,n.params=[],n.notfound=!0;var e=n.getURI(),o=[];n.beforeMiddleware(n.beforeRouteMiddleware,n.beforeRouteMiddlewareFunc),n.routes.forEach(function(t){t.paramsEnabled?(o.push(t),n.handle(o)):t.path===e&&n.setRoute(t)}),n.notfound?n.notFoundException():n.routeCall.apply(null,n.params),null!=t?(n.afterRouteCallback=t,n.afterRouteCallback.apply(null,[])):null!=n.afterRouteCallback&&n.afterRouteCallback.apply(null,[])},n.beforeMiddleware=function(t,e){if(t=t.split("#")[1]||t,null!=e){if("*"===t)return e.apply(null,[]);if(t===n.getURI())return e.apply(null,[])}},n.notfound=!0,n.routes=[],n.paramsEnabled=!1,n.route=null,n.params=[],n.beforeRouteMiddleware="*",n.routeCall=null,n.beforeRouteMiddlewareFunc=null,n.afterRouteCallback=null,n.notFoundCallback=null,n.windowListener(n.run),n}return o(n,t),n}(r);n.Router=a}])});