Stackedit/src/components/Preview.vue

94 lines
1.8 KiB
Vue
Raw Normal View History

2017-07-23 18:42:08 +00:00
<template>
<div class="preview">
<div class="preview__inner-1" @click="onClick" @scroll="onScroll">
<div class="preview__inner-2" :style="{padding: styles.previewPadding}">
</div>
</div>
<div v-if="!styles.showEditor" class="preview__button-bar">
<div class="preview__button" @click="toggleEditor(true)">
<icon-pen></icon-pen>
</div>
2017-07-23 18:42:08 +00:00
</div>
</div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
2017-07-23 18:42:08 +00:00
const appUri = `${window.location.protocol}//${window.location.host}`;
export default {
data: () => ({
previewTop: true,
}),
2017-07-31 09:04:01 +00:00
computed: mapGetters('layout', [
'styles',
2017-07-23 18:42:08 +00:00
]),
methods: {
...mapActions('data', [
'toggleEditor',
]),
onClick(evt) {
2017-07-23 18:42:08 +00:00
let elt = evt.target;
while (elt !== this.$el) {
if (elt.href && elt.href.match(/^https?:\/\//)
&& (!elt.hash || elt.href.slice(0, appUri.length) !== appUri)) {
evt.preventDefault();
const wnd = window.open(elt.href, '_blank');
wnd.focus();
return;
}
elt = elt.parentNode;
}
},
onScroll(evt) {
this.previewTop = evt.target.scrollTop < 10;
},
2017-07-23 18:42:08 +00:00
},
};
</script>
<style lang="scss">
@import 'common/variables.scss';
.preview,
.preview__inner-1 {
2017-07-23 18:42:08 +00:00
position: absolute;
width: 100%;
height: 100%;
}
.preview__inner-1 {
2017-07-23 18:42:08 +00:00
overflow: auto;
}
.preview__inner-2 {
2017-07-23 18:42:08 +00:00
margin: 0;
}
2017-07-31 09:04:01 +00:00
.preview__inner-2 > :first-child > :first-child {
margin-top: 0;
}
.preview__button-bar {
position: absolute;
top: 10px;
right: 26px;
}
.preview__button {
cursor: pointer;
color: rgba(0, 0, 0, 0.25);
width: 40px;
height: 40px;
padding: 5px;
border-radius: $border-radius-base;
&:hover {
background-color: rgba(0, 0, 0, 0.1);
color: rgba(0, 0, 0, 0.75);
2017-07-31 09:04:01 +00:00
}
}
2017-07-23 18:42:08 +00:00
</style>