UNPKG

2.18 kBJavaScriptView Raw
1!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e=e||self).CuriVue={},e.Vue)}(this,function(e,n){"use strict";function r(e,t){return!e.defaultPrevented&&!t&&void 0!==e.button&&0===e.button&&!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}n=n&&n.hasOwnProperty("default")?n.default:n;var a={name:"curi-link",props:["name","params","hash","query","state","click"],computed:{url:function(){return this.$router.url({name:this.name,params:this.params,hash:this.hash,query:this.query})}},methods:{clickHandler:function(e){this.click&&this.click(e),r(e)&&(e.preventDefault(),this.$router.navigate({url:this.url,state:this.state}))}},render:function(e){return e("a",{attrs:{href:this.url},on:{click:this.clickHandler}},this.$slots.default)}},u={name:"curi-async-link",props:["name","params","hash","query","state","click"],computed:{url:function(){return this.$router.url({name:this.name,params:this.params,hash:this.hash,query:this.query})}},data:function(){return{navigating:!1}},methods:{clickHandler:function(e){var t=this;if(this.click&&this.click(e),r(e)){e.preventDefault();var n,i;n=i=function(){t.navigating=!1},this.navigating=!0,this.$router.navigate({url:this.url,state:this.state,cancelled:n,finished:i})}}},render:function(e){return e("a",{attrs:{href:this.url},on:{click:this.clickHandler}},this.$scopedSlots.default({navigating:this.navigating}))}};function i(e,t){var n=t.preserve,i=void 0!==n&&n,r=t.preventScroll,a=void 0!==r&&r;i&&e.contains(document.activeElement)||setTimeout(function(){e.focus({preventScroll:a})})}var s={inserted:function(e,t){i(e,t.value)},update:function(e,t){t.value.key!==t.oldValue.key&&i(e,t.value)}},t={install:function(e,t){e.component(a.name,a),e.component(u.name,u),e.directive("curi-focus",s);var i=new n({data:t.router.current()});t.router.observe(function(e){var t=e.response,n=e.navigation;i.response=t,i.navigation=n}),e.mixin({beforeCreate:function(){this.$curi=i}}),Object.defineProperty(e.prototype,"$router",{get:function(){return t.router}})}};e.CuriPlugin=t,Object.defineProperty(e,"__esModule",{value:!0})});