Created
July 24, 2015 19:55
-
-
Save iCodeForBananas/77db7ae8510d7cb31517 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*! | |
| * vue-router v0.1.0 | |
| * (c) 2015 Evan You | |
| * Released under the MIT License. | |
| */ | |
| !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):"object"==typeof exports?exports.VueRouter=e():t.VueRouter=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function r(t){if(!o)throw new Error("Please install the Router with Vue.use() before creating an instance.");t=t||{},this.app=null,this._children=[],this._recognizer=new a,this._guardRecognizer=new a,this._started=!1,this._currentRoute={path:"/"},this._hasPushState="undefined"!=typeof history&&history.pushState,this._notFoundHandler=t.notFound||null,this._beforeEachHook=t.beforeEach||null,this._afterEachHook=t.afterEach||null,this._hashbang=t.hashbang!==!1,this._history=!(!this._hasPushState||!t.history),this._saveScrollPosition=!!t.saveScrollPosition,this._linkActiveClass=t.linkActiveClass||"v-link-active";var e=t&&t.root;e?("/"!==e.charAt(0)&&(e="/"+e),this._root=e.replace(/\/$/,"")):this._root=null}var i=n(1),a=n(2),o=!1;r.install=function(t){return o?void i.warn("already installed."):(n(5)(t,r),n(6)(t,r),n(8)(t),n(10)(t),n(11)(t,r),void(o=!0))},window.Vue&&r.install(window.Vue),t.exports=r},function(t,e){function n(t){return t&&"function"==typeof t.then}e.warn=function(t,e){window.console&&(console.warn("[vue-router] "+t),e&&console.warn(e.stack))},e.setHash=function(t,e){if(e){var n=location.href.length-location.hash.length,r=location.href.slice(0,n)+"#"+t;location.replace(r)}else location.hash=t},e.resolvePath=function(t,e){var n=t.match(/(\?.*)$/);if(n&&(n=n[1],t=t.slice(0,-n.length)),"?"===e.charAt(0))return t+e;var r=t.split("/");r.pop();for(var i=e.split("/"),a=0;a<i.length;a++){var o=i[a];"."!==o&&(".."===o?r.pop():r.push(o))}return""!==r[0]&&r.unshift(""),r.join("/")},e.callAsyncFn=function(t,e){var r=e.args||[],i=e.onResolve,a=e.onReject;r.push(i,a);var o=t.apply(null,r);n(o)?o.then(i,a):o===!0?i():o===!1&&a()}},function(t,e,n){var r;(function(t){(function(){"use strict";function i(t,e,n){this.path=t,this.matcher=e,this.delegate=n}function a(t){this.routes={},this.children={},this.target=t}function o(t,e,n){return function(r,a){var s=t+r;return a?void a(o(s,e,n)):new i(t+r,e,n)}}function s(t,e,n){for(var r=0,i=0,a=t.length;a>i;i++)r+=t[i].path.length;e=e.substr(r);var o={path:e,handler:n};t.push(o)}function h(t,e,n,r){var i=e.routes;for(var a in i)if(i.hasOwnProperty(a)){var o=t.slice();s(o,a,i[a]),e.children[a]?h(o,e.children[a],n,r):n.call(r,o)}}function c(t){return"[object Array]"===Object.prototype.toString.call(t)}function u(t){this.string=t}function l(t){this.name=t}function f(t){this.name=t}function d(){}function p(t,e,n){"/"===t.charAt(0)&&(t=t.substr(1));var r=t.split("/"),i=[];n.val="";for(var a=0,o=r.length;o>a;a++){var s,h=r[a];(s=h.match(/^:([^\/]+)$/))?(i.push(new l(s[1])),e.push(s[1]),n.val+="3"):(s=h.match(/^\*([^\/]+)$/))?(i.push(new f(s[1])),n.val+="2",e.push(s[1])):""===h?(i.push(new d),n.val+="1"):(i.push(new u(h)),n.val+="4")}return n.val=+n.val,i}function v(t){this.charSpec=t,this.nextStates=[]}function g(t){return t.sort(function(t,e){return e.specificity.val-t.specificity.val})}function m(t,e){for(var n=[],r=0,i=t.length;i>r;r++){var a=t[r];n=n.concat(a.match(e))}return n}function _(t){this.queryParams=t||{}}function y(t,e,n){for(var r=t.handlers,i=t.regex,a=e.match(i),o=1,s=new _(n),h=0,c=r.length;c>h;h++){for(var u=r[h],l=u.names,f={},d=0,p=l.length;p>d;d++)f[l[d]]=a[o++];s.push({handler:u.handler,params:f,isDynamic:!!l.length})}return s}function w(t,e){return e.eachChar(function(e){t=t.put(e)}),t}function R(t){return t=t.replace(/\+/gm,"%20"),decodeURIComponent(t)}i.prototype={to:function(t,e){var n=this.delegate;if(n&&n.willAddRoute&&(t=n.willAddRoute(this.matcher.target,t)),this.matcher.add(this.path,t),e){if(0===e.length)throw new Error("You must have an argument in the function passed to `to`");this.matcher.addChild(this.path,t,e,this.delegate)}return this}},a.prototype={add:function(t,e){this.routes[t]=e},addChild:function(t,e,n,r){var i=new a(e);this.children[t]=i;var s=o(t,i,r);r&&r.contextEntered&&r.contextEntered(e,s),n(s)}};var C=function(t,e){var n=new a;t(o("",n,this.delegate)),h([],n,function(t){e?e(this,t):this.add(t)},this)},x=["/",".","*","+","?","|","(",")","[","]","{","}","\\"],b=new RegExp("(\\"+x.join("|\\")+")","g");u.prototype={eachChar:function(t){for(var e,n=this.string,r=0,i=n.length;i>r;r++)e=n.charAt(r),t({validChars:e})},regex:function(){return this.string.replace(b,"\\$1")},generate:function(){return this.string}},l.prototype={eachChar:function(t){t({invalidChars:"/",repeat:!0})},regex:function(){return"([^/]+)"},generate:function(t){return t[this.name]}},f.prototype={eachChar:function(t){t({invalidChars:"",repeat:!0})},regex:function(){return"(.+)"},generate:function(t){return t[this.name]}},d.prototype={eachChar:function(){},regex:function(){return""},generate:function(){return""}},v.prototype={get:function(t){for(var e=this.nextStates,n=0,r=e.length;r>n;n++){var i=e[n],a=i.charSpec.validChars===t.validChars;if(a=a&&i.charSpec.invalidChars===t.invalidChars)return i}},put:function(t){var e;return(e=this.get(t))?e:(e=new v(t),this.nextStates.push(e),t.repeat&&e.nextStates.push(e),e)},match:function(t){for(var e,n,r,i=this.nextStates,a=[],o=0,s=i.length;s>o;o++)e=i[o],n=e.charSpec,"undefined"!=typeof(r=n.validChars)?-1!==r.indexOf(t)&&a.push(e):"undefined"!=typeof(r=n.invalidChars)&&-1===r.indexOf(t)&&a.push(e);return a}};var A=Object.create||function(t){function e(){}return e.prototype=t,new e};_.prototype=A({splice:Array.prototype.splice,slice:Array.prototype.slice,push:Array.prototype.push,length:0,queryParams:null});var S=function(){this.rootState=new v,this.names={}};S.prototype={add:function(t,e){for(var n,r=this.rootState,i="^",a={},o=[],s=[],h=!0,c=0,u=t.length;u>c;c++){var l=t[c],f=[],v=p(l.path,f,a);s=s.concat(v);for(var g=0,m=v.length;m>g;g++){var _=v[g];_ instanceof d||(h=!1,r=r.put({validChars:"/"}),i+="/",r=w(r,_),i+=_.regex())}var y={handler:l.handler,names:f};o.push(y)}h&&(r=r.put({validChars:"/"}),i+="/"),r.handlers=o,r.regex=new RegExp(i+"$"),r.specificity=a,(n=e&&e.as)&&(this.names[n]={segments:s,handlers:o})},handlersFor:function(t){var e=this.names[t],n=[];if(!e)throw new Error("There is no route named "+t);for(var r=0,i=e.handlers.length;i>r;r++)n.push(e.handlers[r]);return n},hasRoute:function(t){return!!this.names[t]},generate:function(t,e){var n=this.names[t],r="";if(!n)throw new Error("There is no route named "+t);for(var i=n.segments,a=0,o=i.length;o>a;a++){var s=i[a];s instanceof d||(r+="/",r+=s.generate(e))}return"/"!==r.charAt(0)&&(r="/"+r),e&&e.queryParams&&(r+=this.generateQueryString(e.queryParams,n.handlers)),r},generateQueryString:function(t,e){var n=[],r=[];for(var i in t)t.hasOwnProperty(i)&&r.push(i);r.sort();for(var a=0,o=r.length;o>a;a++){i=r[a];var s=t[i];if(null!=s){var h=encodeURIComponent(i);if(c(s))for(var u=0,l=s.length;l>u;u++){var f=i+"[]="+encodeURIComponent(s[u]);n.push(f)}else h+="="+encodeURIComponent(s),n.push(h)}}return 0===n.length?"":"?"+n.join("&")},parseQueryString:function(t){for(var e=t.split("&"),n={},r=0;r<e.length;r++){var i,a=e[r].split("="),o=R(a[0]),s=o.length,h=!1;1===a.length?i="true":(s>2&&"[]"===o.slice(s-2)&&(h=!0,o=o.slice(0,s-2),n[o]||(n[o]=[])),i=a[1]?R(a[1]):""),h?n[o].push(i):n[o]=i}return n},recognize:function(t){var e,n,r,i,a=[this.rootState],o={},s=!1;if(i=t.indexOf("?"),-1!==i){var h=t.substr(i+1,t.length);t=t.substr(0,i),o=this.parseQueryString(h)}for(t=decodeURI(t),"/"!==t.charAt(0)&&(t="/"+t),e=t.length,e>1&&"/"===t.charAt(e-1)&&(t=t.substr(0,e-1),s=!0),n=0,r=t.length;r>n&&(a=m(a,t.charAt(n)),a.length);n++);var c=[];for(n=0,r=a.length;r>n;n++)a[n].handlers&&c.push(a[n]);a=g(c);var u=c[0];return u&&u.handlers?(s&&"(.+)$"===u.regex.source.slice(-5)&&(t+="/"),y(u,t,o)):void 0}},S.prototype.map=C,S.VERSION="0.1.9";var E=S;n(4).amd?(r=function(){return E}.call(e,n,e,t),!(void 0!==r&&(t.exports=r))):"undefined"!=typeof t&&t.exports?t.exports=E:"undefined"!=typeof this&&(this.RouteRecognizer=E)}).call(this)}).call(e,n(3)(t))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children=[],t.webpackPolyfill=1),t}},function(t,e){t.exports=function(){throw new Error("define cannot be used indirect")}},function(t,e,n){var r=n(1);t.exports=function(t,e){var n=e.prototype;n.map=function(t){for(var e in t)this.on(e,t[e])},n.on=function(t,e){"*"===t?this._notFound(e):this._addRoute(t,e,[])},n.redirect=function(t){for(var e in t)this._addRedirect(e,t[e])},n.alias=function(t){for(var e in t)this._addAlias(e,t[e])},n.beforeEach=function(t){this._beforeEachHook=t},n.afterEach=function(t){this._afterEachHook=t},n.go=function(e,n){var i,a,o=n&&n.replace;if(this._hasPushState){if(this._history){i=this._formatPath(e),e=i.replace(/#.*$/,"");var s=i.match(/#.*$/);a=s&&s[0].slice(1)}else i=this._formatHashPath(e),e=i.replace(/^#!?/,"");if(o)history.replaceState({},"",i);else{var h={x:window.pageXOffset,y:window.pageYOffset};history.replaceState({pos:h},"",location.href),history.pushState({},"",i)}this._match(e),a&&t.nextTick(function(){var t=document.getElementById(a);t&&window.scrollTo(window.scrollX,t.offsetTop)})}else r.setHash(this._formatHashPath(e),o)},n.replace=function(t){this.go(t,{replace:!0})},n.start=function(e,n){if(this._started)return void r.warn("already started.");if(this._started=!0,!this.app){if(!e||!n)throw new Error("Must start vue-router with a component and a root container.");this._appContainer=n,this._appConstructor="function"==typeof e?e:t.extend(e)}this._hasPushState?this._initHistoryMode():this._initHashMode()},n.stop=function(){var t=this._history?"popstate":"hashchange";window.removeEventListener(t,this._onRouteChange),this._started=!1}}},function(t,e,n){var r=n(1),i=n(7);t.exports=function(t,e){function n(t,e,n){var r=new RegExp(":"+n+"(\\/|$)"),i=e.params[n];return t.replace(r,function(t){return"/"===t.charAt(t.length-1)?i+"/":i})}function a(e){var n=e.component,i=typeof n;if("string"!==i){if("function"!==i&&(n=t.extend(n)),!n.cid)return r.warn("invalid router component: "+n),void(e.component=null);var a="router-view-"+n.cid;t.component(a)||t.component(a,n),e.component=a}}var o=e.prototype;o._initHistoryMode=function(){var e=this;this._onRouteChange=function(n){var r=location.pathname+location.search;if(e._history){r=decodeURI(r);var i=document.querySelector("base");i&&(r=r.replace(i.getAttribute("href"),"")),e._match(r)}else e.replace(decodeURI(location.hash));var a=n&&n.state&&n.state.pos;a&&e._saveScrollPosition&&t.nextTick(function(){window.scrollTo(a.x,a.y)})},window.addEventListener("popstate",this._onRouteChange),this._onRouteChange()},o._initHashMode=function(){var t=this;this._onRouteChange=function(){var e=location.hash;if(t._hashbang&&e&&"!"!==e.charAt(1))return void r.setHash("!"+e.slice(1),!0);if(!t._hashbang&&e&&"!"===e.charAt(1))return void r.setHash(e.slice(2),!0);e=e.replace(/^#!?/,"");var n=e+location.search;n=decodeURI(n),t._match(n)},window.addEventListener("hashchange",this._onRouteChange),this._onRouteChange()},o._addRoute=function(t,e,n){if(a(e),n.push({path:t,handler:e}),this._recognizer.add(n),e.subRoutes)for(var r in e.subRoutes)if("*"!==r)this._addRoute(r,e.subRoutes[r],n.slice());else{var i=e.subRoutes[r];a(i),e.defaultChildHandler=i}},o._notFound=function(t){a(t),this._notFoundHandler=[{handler:t}]},o._addRedirect=function(t,e){this._addGuard(t,e,this.replace)},o._addAlias=function(t,e){this._addGuard(t,e,this._match)},o._addGuard=function(t,e,r){var i=this;this._guardRecognizer.add([{path:t,handler:function(t){var a=e;if(t.isDynamic)for(var o in t.params)a=n(a,t,o);r.call(i,a)}}])},o._checkGuard=function(t){var e=this._guardRecognizer.recognize(t);return e?(e[0].handler(e[0]),!0):void 0},o._match=function(t){var e=this;if(!this._checkGuard(t)){var n=this._currentRoute;if(!this.app||t!==n.path){this._history&&this._root&&0===t.indexOf(this._root)&&(t=t.slice(this._root.length));var a=new i(t,this);this.app||(this.app=new this._appConstructor({el:this._appContainer,data:{route:a}}));var o=this._beforeEachHook;o?r.callAsyncFn(o,{args:[a,n],onResolve:function(){e._transition(a,n)},onReject:function(){e.replace(n.path)}}):e._transition(a,n)}}},o._transition=function(t,e){this.app.route!==t&&(this.app.route=t,this._children.forEach(function(e){e.route=t})),this._afterEachHook&&this._afterEachHook.call(null,t,e),this._currentRoute=t},o._formatPath=function(t){return"/"===t.charAt(0)?this._root?this._root+"/"+t.replace(/^\//,""):t:r.resolvePath(location.pathname,t)},o._formatHashPath=function(t){t=t.replace(/^#!?/,"");var e="#"+(this._hashbang?"!":"");return"/"===t.charAt(0)?e+t:e+r.resolvePath(location.hash.replace(/^#!?/,""),t)}}},function(t,e){function n(t,e){this.path=t;var n=e._recognizer.recognize(t);this.query=n?n.queryParams:{},this.params=n?[].reduce.call(n,function(t,e){if(e.params)for(var n in e.params)t[n]=e.params[n];return t},{}):{},r(this,"_matched",n||e._notFoundHandler),r(this,"_router",e),Object.freeze(this)}function r(t,e,n){Object.defineProperty(t,e,{value:n,enumerable:!1})}t.exports=n},function(t,e,n){var r=n(1);t.exports=function(t){function e(t){for(var e=0;t.$parent;)t.$options._isRouterView&&e++,t=t.$parent;return e}n(9)("router-view{display:block;}");var i=t.util,a=t.directive("_component"),o=i.extend({},a);i.extend(o,{_isRouterView:!0,bind:function(){this.currentRoute=null,this.currentComponentId=null,this.unwatch=this.vm.$watch("route",i.bind(this.onRouteChange,this),{user:!1}),this._isDynamicLiteral=!0,a.bind.call(this),this.vm.route&&this.onRouteChange(this.vm.route)},onRouteChange:function(t){function n(){a.switchView(t,o,s)}function i(){var e=o?o.path:"/";t._router.replace(e)}var a=this,o=this.currentRoute;if(this.currentRoute=t,!t._matched)return this.invalidate();var s,h=e(this.vm),c=t._matched[h];if(c)s=c.handler;else{var u=t._matched[h-1];if(!u||!u.handler.defaultChildHandler)return this.invalidate();s=u.handler.defaultChildHandler}var l=o&&o.path;t.path!==l&&(s.before?r.callAsyncFn(s.before,{args:[t,o],onResolve:n,onReject:i}):n())},switchView:function(t,e,n){function i(t){return function(){s.vm&&s.transitionSymbol===h&&t.apply(this,arguments)}}function a(e){r.warn("failed to load data for route: "+t.path,e)}function o(t){a(t),c()}var s=this,h=this.transitionSymbol={},c=i(function(t){s.setComponent(n.component,t,null,u)}),u=i(function(){n.after&&n.after(t,e)}),l=i(function(t,e){for(var n in e)t.$set(n,e[n]);t.loading=!1});if(!this.childVM||n.alwaysRefresh||n.component!==this.currentComponentId)if(this.currentComponentId=n.component,n.data)if(n.waitOnData)r.callAsyncFn(n.data,{args:[t],onResolve:c,onReject:o});else{var f,d;r.callAsyncFn(n.data,{args:[t],onResolve:function(t){d?l(d,t):f=t},onReject:o}),this.setComponent(n.component,{loading:!0},function(t){f?l(t,f):d=t},u)}else c();else if(n.data){var p=this.childVM;p.loading=!0,r.callAsyncFn(n.data,{args:[t],onResolve:function(t){l(p,t),p.loading=!1,n.waitOnData&&u()},onReject:a}),n.waitOnData||u()}else u()},invalidate:function(){this.currentRoute=this.currentComponentId=this.transitionSymbol=null,this.setComponent(null)},unbind:function(){this.unwatch(),a.unbind.call(this)}}),t.elementDirective("router-view",o)}},function(t,e){var n={};t.exports=function(t,e){if(!n[t]){n[t]=!0;var r=document.createElement("style");r.setAttribute("type","text/css"),"textContent"in r?r.textContent=t:r.styleSheet.cssText=t;var i=document.getElementsByTagName("head")[0];e&&e.prepend?i.insertBefore(r,i.childNodes[0]):i.appendChild(r)}}},function(t,e){t.exports=function(t){var e=t.util;t.directive("link",{isLiteral:!0,bind:function(){var t=this.vm;if(!t.route&&e.warn)return void e.warn("v-link can only be used inside a router-enabled app.");var n=this,r=t.route._router;this.handler=function(t){0===t.button&&(t.preventDefault(),null!=n.destination&&r.go(n.destination))},this.el.addEventListener("click",this.handler),this._isDynamicLiteral||this.update(this.expression),this.unwatch=t.$watch("route.path",e.bind(this.updateClasses,this))},updateClasses:function(t){var n=this.el,r=this.destination,i=this.vm.route._router,a=i._linkActiveClass,o=a+"-exact";0===t.indexOf(r)?e.addClass(n,a):e.removeClass(n,a),t===r?e.addClass(n,o):e.removeClass(n,o)},update:function(t){this.destination=t,this.updateClasses(this.vm.route.path),t=t||"";var e=this.vm.route._router,n=e._history?"/"===t.charAt(0)?e._formatPath(t):t:e._formatHashPath(t);"A"===this.el.tagName&&(n?this.el.href=n:this.el.removeAttribute("href"))},unbind:function(){this.el.removeEventListener("click",this.handler),this.unwatch&&this.unwatch()}})}},function(t,e){t.exports=function(t,e){var n=t.prototype.$addChild;t.prototype.$addChild=function(t,r){var i=this.route,a=i&&i._router,o=a instanceof e;if(o){t=t||{};var s=t.data=t.data||{};s.route=i,t._isRouterView&&(s.loading=s.loading||!1)}var h=n.call(this,t,r);return o&&(a._children.push(h),h.$on("hook:beforeDestroy",function(){a._children.$remove(h)})),h}}}])}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment