Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. var navigo = require('navigo');
  3. },{"navigo":2}],2:[function(require,module,exports){
  4. (function webpackUniversalModuleDefinition(root, factory) {
  5.     if(typeof exports === 'object' && typeof module === 'object')
  6.         module.exports = factory();
  7.     else if(typeof define === 'function' && define.amd)
  8.         define("Navigo", [], factory);
  9.     else if(typeof exports === 'object')
  10.         exports["Navigo"] = factory();
  11.     else
  12.         root["Navigo"] = factory();
  13. })(this, function() {
  14. return /******/ (function(modules) { // webpackBootstrap
  15. /******/    // The module cache
  16. /******/    var installedModules = {};
  17. /******/
  18. /******/    // The require function
  19. /******/    function __webpack_require__(moduleId) {
  20. /******/
  21. /******/        // Check if module is in cache
  22. /******/        if(installedModules[moduleId])
  23. /******/            return installedModules[moduleId].exports;
  24. /******/
  25. /******/        // Create a new module (and put it into the cache)
  26. /******/        var module = installedModules[moduleId] = {
  27. /******/            exports: {},
  28. /******/            id: moduleId,
  29. /******/            loaded: false
  30. /******/        };
  31. /******/
  32. /******/        // Execute the module function
  33. /******/        modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  34. /******/
  35. /******/        // Flag the module as loaded
  36. /******/        module.loaded = true;
  37. /******/
  38. /******/        // Return the exports of the module
  39. /******/        return module.exports;
  40. /******/    }
  41. /******/
  42. /******/
  43. /******/    // expose the modules object (__webpack_modules__)
  44. /******/    __webpack_require__.m = modules;
  45. /******/
  46. /******/    // expose the module cache
  47. /******/    __webpack_require__.c = installedModules;
  48. /******/
  49. /******/    // __webpack_public_path__
  50. /******/    __webpack_require__.p = "";
  51. /******/
  52. /******/    // Load entry module and return exports
  53. /******/    return __webpack_require__(0);
  54. /******/ })
  55. /************************************************************************/
  56. /******/ ([
  57. /* 0 */
  58. /***/ function(module, exports) {
  59.  
  60.     'use strict';
  61.    
  62.     Object.defineProperty(exports, "__esModule", {
  63.       value: true
  64.     });
  65.    
  66.     var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  67.    
  68.     function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  69.    
  70.     function _toArray(arr) { return Array.isArray(arr) ? arr : Array.from(arr); }
  71.    
  72.     var PARAMETER_REGEXP = /([:*])(\w+)/g;
  73.     var WILDCARD_REGEXP = /\*/g;
  74.     var REPLACE_VARIABLE_REGEXP = '([^\/]+)';
  75.     var REPLACE_WILDCARD = '(?:.*)';
  76.     var FOLLOWED_BY_SLASH_REGEXP = '(?:\/$|$)';
  77.    
  78.     function clean(s) {
  79.       if (s instanceof RegExp) return s;
  80.       return s.replace(/\/+$/, '').replace(/^\/+/, '/');
  81.     }
  82.    
  83.     function regExpResultToParams(match, names) {
  84.       if (names.length === 0) return null;
  85.       if (!match) return null;
  86.       return match.slice(1, match.length).reduce(function (params, value, index) {
  87.         if (params === null) params = {};
  88.         params[names[index]] = value;
  89.         return params;
  90.       }, null);
  91.     }
  92.    
  93.     function replaceDynamicURLParts(route) {
  94.       var paramNames = [],
  95.           regexp;
  96.    
  97.       if (route instanceof RegExp) {
  98.         regexp = route;
  99.       } else {
  100.         regexp = new RegExp(clean(route).replace(PARAMETER_REGEXP, function (full, dots, name) {
  101.           paramNames.push(name);
  102.           return REPLACE_VARIABLE_REGEXP;
  103.         }).replace(WILDCARD_REGEXP, REPLACE_WILDCARD) + FOLLOWED_BY_SLASH_REGEXP);
  104.       }
  105.       return { regexp: regexp, paramNames: paramNames };
  106.     }
  107.    
  108.     function getUrlDepth(url) {
  109.       return url.replace(/\/$/, '').split('/').length;
  110.     }
  111.    
  112.     function compareUrlDepth(urlA, urlB) {
  113.       return getUrlDepth(urlB) - getUrlDepth(urlA);
  114.     }
  115.    
  116.     function findMatchedRoutes(url) {
  117.       var routes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  118.    
  119.       return routes.map(function (route) {
  120.         var _replaceDynamicURLPar = replaceDynamicURLParts(route.route),
  121.             regexp = _replaceDynamicURLPar.regexp,
  122.             paramNames = _replaceDynamicURLPar.paramNames;
  123.    
  124.         var match = url.match(regexp);
  125.         var params = regExpResultToParams(match, paramNames);
  126.    
  127.         return match ? { match: match, route: route, params: params } : false;
  128.       }).filter(function (m) {
  129.         return m;
  130.       });
  131.     }
  132.    
  133.     function match(url, routes) {
  134.       return findMatchedRoutes(url, routes)[0] || false;
  135.     }
  136.    
  137.     function root(url, routes) {
  138.       var matched = findMatchedRoutes(url, routes.filter(function (route) {
  139.         var u = clean(route.route);
  140.    
  141.         return u !== '' && u !== '*';
  142.       }));
  143.       var fallbackURL = clean(url);
  144.    
  145.       if (matched.length > 0) {
  146.         return matched.map(function (m) {
  147.           return clean(url.substr(0, m.match.index));
  148.         }).reduce(function (root, current) {
  149.           return current.length < root.length ? current : root;
  150.         }, fallbackURL);
  151.       }
  152.       return fallbackURL;
  153.     }
  154.    
  155.     function isPushStateAvailable() {
  156.       return !!(typeof window !== 'undefined' && window.history && window.history.pushState);
  157.     }
  158.    
  159.     function isHashChangeAPIAvailable() {
  160.       return !!(typeof window !== 'undefined' && 'onhashchange' in window);
  161.     }
  162.    
  163.     function extractGETParameters(url, useHash) {
  164.       var _url$split = url.split(/\?(.*)?$/),
  165.           _url$split2 = _toArray(_url$split),
  166.           onlyURL = _url$split2[0],
  167.           query = _url$split2.slice(1);
  168.    
  169.       if (!useHash) {
  170.         onlyURL = onlyURL.split('#')[0];
  171.       }
  172.       return { onlyURL: onlyURL, GETParameters: query.join('') };
  173.     }
  174.    
  175.     function manageHooks(handler, route) {
  176.       if (route && route.hooks && _typeof(route.hooks) === 'object') {
  177.         if (route.hooks.before) {
  178.           route.hooks.before(function () {
  179.             var shouldRoute = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  180.    
  181.             if (!shouldRoute) return;
  182.             handler();
  183.             route.hooks.after && route.hooks.after();
  184.           });
  185.         } else if (route.hooks.after) {
  186.           handler();
  187.           route.hooks.after && route.hooks.after();
  188.         }
  189.         return;
  190.       }
  191.       handler();
  192.     };
  193.    
  194.     function Navigo(r, useHash) {
  195.       this.root = null;
  196.       this._routes = [];
  197.       this._useHash = useHash;
  198.       this._paused = false;
  199.       this._destroyed = false;
  200.       this._lastRouteResolved = null;
  201.       this._notFoundHandler = null;
  202.       this._defaultHandler = null;
  203.       this._usePushState = !useHash && isPushStateAvailable();
  204.    
  205.       if (r) {
  206.         this.root = r.replace(/\/$/, '/#');
  207.       } else if (useHash) {
  208.         this.root = this._cLoc().split('#')[0].replace(/\/$/, '/#');
  209.       }
  210.    
  211.       this._listen();
  212.       this.updatePageLinks();
  213.     }
  214.    
  215.     Navigo.prototype = {
  216.       helpers: {
  217.         match: match,
  218.         root: root,
  219.         clean: clean
  220.       },
  221.       navigate: function navigate(path, absolute) {
  222.         var to;
  223.    
  224.         path = path || '';
  225.         if (this._usePushState) {
  226.           to = (!absolute ? this._getRoot() + '/' : '') + path.replace(/^\/+/, '/');
  227.           to = to.replace(/([^:])(\/{2,})/g, '$1/');
  228.           history[this._paused ? 'replaceState' : 'pushState']({}, '', to);
  229.           this.resolve();
  230.         } else if (typeof window !== 'undefined') {
  231.           window.location.href = window.location.href.replace(/#(.*)$/, '') + '#' + path;
  232.         }
  233.         return this;
  234.       },
  235.       on: function on() {
  236.         var _this = this;
  237.    
  238.         for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  239.           args[_key] = arguments[_key];
  240.         }
  241.    
  242.         if (typeof args[0] === 'function') {
  243.           this._defaultHandler = { handler: args[0], hooks: args[1] };
  244.         } else if (args.length >= 2) {
  245.           if (args[0] === '/') {
  246.             this._defaultHandler = { handler: args[1], hooks: args[2] };
  247.           } else {
  248.             this._add(args[0], args[1], args[2]);
  249.           }
  250.         } else if (_typeof(args[0]) === 'object') {
  251.           var orderedRoutes = Object.keys(args[0]).sort(compareUrlDepth);
  252.    
  253.           orderedRoutes.forEach(function (route) {
  254.             _this._add(route, args[0][route]);
  255.           });
  256.         }
  257.         return this;
  258.       },
  259.       notFound: function notFound(handler, hooks) {
  260.         this._notFoundHandler = { handler: handler, hooks: hooks };
  261.         return this;
  262.       },
  263.       resolve: function resolve(current) {
  264.         var _this2 = this;
  265.    
  266.         var handler, m;
  267.         var url = (current || this._cLoc()).replace(this._getRoot(), '');
  268.    
  269.         if (this._useHash) {
  270.           url = url.replace(/^\/#/, '/');
  271.         }
  272.    
  273.         var _extractGETParameters = extractGETParameters(url, this._useHash),
  274.             onlyURL = _extractGETParameters.onlyURL,
  275.             GETParameters = _extractGETParameters.GETParameters;
  276.    
  277.         if (this._paused || this._lastRouteResolved && onlyURL === this._lastRouteResolved.url && GETParameters === this._lastRouteResolved.query) {
  278.           return false;
  279.         }
  280.    
  281.         m = match(onlyURL, this._routes);
  282.    
  283.         if (m) {
  284.           this._lastRouteResolved = { url: onlyURL, query: GETParameters };
  285.           handler = m.route.handler;
  286.           manageHooks(function () {
  287.             m.route.route instanceof RegExp ? handler.apply(undefined, _toConsumableArray(m.match.slice(1, m.match.length))) : handler(m.params, GETParameters);
  288.           }, m.route);
  289.           return m;
  290.         } else if (this._defaultHandler && (onlyURL === '' || onlyURL === '/' || onlyURL === '#')) {
  291.           manageHooks(function () {
  292.             _this2._lastRouteResolved = { url: onlyURL, query: GETParameters };
  293.             _this2._defaultHandler.handler(GETParameters);
  294.           }, this._defaultHandler);
  295.           return true;
  296.         } else if (this._notFoundHandler) {
  297.           manageHooks(function () {
  298.             _this2._lastRouteResolved = { url: onlyURL, query: GETParameters };
  299.             _this2._notFoundHandler.handler(GETParameters);
  300.           }, this._notFoundHandler);
  301.         }
  302.         return false;
  303.       },
  304.       destroy: function destroy() {
  305.         this._routes = [];
  306.         this._destroyed = true;
  307.         clearTimeout(this._listenningInterval);
  308.         typeof window !== 'undefined' ? window.onpopstate = null : null;
  309.       },
  310.       updatePageLinks: function updatePageLinks() {
  311.         var self = this;
  312.    
  313.         if (typeof document === 'undefined') return;
  314.    
  315.         this._findLinks().forEach(function (link) {
  316.           if (!link.hasListenerAttached) {
  317.             link.addEventListener('click', function (e) {
  318.               var location = link.getAttribute('href');
  319.    
  320.               if (!self._destroyed) {
  321.                 e.preventDefault();
  322.                 self.navigate(clean(location));
  323.               }
  324.             });
  325.             link.hasListenerAttached = true;
  326.           }
  327.         });
  328.       },
  329.       generate: function generate(name) {
  330.         var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  331.    
  332.         var result = this._routes.reduce(function (result, route) {
  333.           var key;
  334.    
  335.           if (route.name === name) {
  336.             result = route.route;
  337.             for (key in data) {
  338.               result = result.replace(':' + key, data[key]);
  339.             }
  340.           }
  341.           return result;
  342.         }, '');
  343.    
  344.         return this._useHash ? '#' + result : result;
  345.       },
  346.       link: function link(path) {
  347.         return this._getRoot() + path;
  348.       },
  349.       pause: function pause() {
  350.         var status = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  351.    
  352.         this._paused = status;
  353.       },
  354.       resume: function resume() {
  355.         this.pause(false);
  356.       },
  357.       disableIfAPINotAvailable: function disableIfAPINotAvailable() {
  358.         if (!isPushStateAvailable()) {
  359.           this.destroy();
  360.         }
  361.       },
  362.       _add: function _add(route) {
  363.         var handler = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  364.         var hooks = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  365.    
  366.         if ((typeof handler === 'undefined' ? 'undefined' : _typeof(handler)) === 'object') {
  367.           this._routes.push({
  368.             route: route,
  369.             handler: handler.uses,
  370.             name: handler.as,
  371.             hooks: hooks || handler.hooks
  372.           });
  373.         } else {
  374.           this._routes.push({ route: route, handler: handler, hooks: hooks });
  375.         }
  376.         return this._add;
  377.       },
  378.       _getRoot: function _getRoot() {
  379.         if (this.root !== null) return this.root;
  380.         this.root = root(this._cLoc(), this._routes);
  381.         return this.root;
  382.       },
  383.       _listen: function _listen() {
  384.         var _this3 = this;
  385.    
  386.         if (this._usePushState) {
  387.           window.onpopstate = function () {
  388.             _this3.resolve();
  389.           };
  390.         } else if (isHashChangeAPIAvailable()) {
  391.           window.onhashchange = function () {
  392.             _this3.resolve();
  393.           };
  394.         } else {
  395.           (function () {
  396.             var cached = _this3._cLoc(),
  397.                 current = void 0,
  398.                 _check = void 0;
  399.    
  400.             _check = function check() {
  401.               current = _this3._cLoc();
  402.               if (cached !== current) {
  403.                 cached = current;
  404.                 _this3.resolve();
  405.               }
  406.               _this3._listenningInterval = setTimeout(_check, 200);
  407.             };
  408.             _check();
  409.           })();
  410.         }
  411.       },
  412.       _cLoc: function _cLoc() {
  413.         if (typeof window !== 'undefined') {
  414.           return clean(window.location.href);
  415.         }
  416.         return '';
  417.       },
  418.       _findLinks: function _findLinks() {
  419.         return [].slice.call(document.querySelectorAll('[data-navigo]'));
  420.       }
  421.     };
  422.    
  423.     exports.default = Navigo;
  424.     module.exports = exports['default'];
  425.  
  426. /***/ }
  427. /******/ ])
  428. });
  429. ;
  430.  
  431. },{}]},{},[1]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement