2017-07-23 18:42:08 +00:00
|
|
|
<template>
|
|
|
|
<div class="preview">
|
2017-08-03 17:08:12 +00:00
|
|
|
<div class="preview__inner-1" @click="onClick" @scroll="onScroll">
|
|
|
|
<div class="preview__inner-2" :style="{padding: styles.previewPadding}">
|
|
|
|
</div>
|
2017-11-15 08:12:56 +00:00
|
|
|
<div class="gutter" :style="{left: styles.previewGutterLeft + 'px'}">
|
|
|
|
<comment-list v-if="styles.previewGutterWidth"></comment-list>
|
2018-03-12 00:45:54 +00:00
|
|
|
<preview-new-discussion-button v-if="!isCurrentTemp"></preview-new-discussion-button>
|
2017-11-15 08:12:56 +00:00
|
|
|
</div>
|
2017-08-03 17:08:12 +00:00
|
|
|
</div>
|
2017-11-15 08:12:56 +00:00
|
|
|
<div v-if="!styles.showEditor" class="preview__corner">
|
|
|
|
<button class="preview__button button" @click="toggleEditor(true)" v-title="'Edit file'">
|
2017-08-03 17:08:12 +00:00
|
|
|
<icon-pen></icon-pen>
|
2017-11-15 08:12:56 +00:00
|
|
|
</button>
|
2017-07-23 18:42:08 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2017-08-03 17:08:12 +00:00
|
|
|
import { mapGetters, mapActions } from 'vuex';
|
2017-11-15 08:12:56 +00:00
|
|
|
import CommentList from './gutters/CommentList';
|
|
|
|
import PreviewNewDiscussionButton from './gutters/PreviewNewDiscussionButton';
|
2017-07-23 18:42:08 +00:00
|
|
|
|
2017-12-17 15:08:52 +00:00
|
|
|
const appUri = `${location.protocol}//${location.host}`;
|
2017-07-23 18:42:08 +00:00
|
|
|
|
|
|
|
export default {
|
2017-11-10 23:39:51 +00:00
|
|
|
components: {
|
2017-11-15 08:12:56 +00:00
|
|
|
CommentList,
|
|
|
|
PreviewNewDiscussionButton,
|
2017-11-10 23:39:51 +00:00
|
|
|
},
|
2017-08-03 17:08:12 +00:00
|
|
|
data: () => ({
|
|
|
|
previewTop: true,
|
|
|
|
}),
|
2018-03-12 00:45:54 +00:00
|
|
|
computed: {
|
|
|
|
...mapGetters('file', [
|
|
|
|
'isCurrentTemp',
|
|
|
|
]),
|
|
|
|
...mapGetters('layout', [
|
|
|
|
'styles',
|
|
|
|
]),
|
|
|
|
},
|
2017-08-03 17:08:12 +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;
|
|
|
|
}
|
2017-08-03 17:08:12 +00:00
|
|
|
},
|
|
|
|
onScroll(evt) {
|
|
|
|
this.previewTop = evt.target.scrollTop < 10;
|
|
|
|
},
|
2017-07-23 18:42:08 +00:00
|
|
|
},
|
2017-11-10 23:39:51 +00:00
|
|
|
mounted() {
|
|
|
|
const previewElt = this.$el.querySelector('.preview__inner-2');
|
|
|
|
const onDiscussionEvt = cb => (evt) => {
|
|
|
|
let elt = evt.target;
|
|
|
|
while (elt && elt !== previewElt) {
|
|
|
|
if (elt.discussionId) {
|
|
|
|
cb(elt.discussionId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elt = elt.parentNode;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-11-15 08:12:56 +00:00
|
|
|
const classToggler = toggle => (discussionId) => {
|
|
|
|
previewElt.getElementsByClassName(`discussion-preview-highlighting--${discussionId}`)
|
|
|
|
.cl_each(elt => elt.classList.toggle('discussion-preview-highlighting--hover', toggle));
|
|
|
|
document.getElementsByClassName(`comment--discussion-${discussionId}`)
|
|
|
|
.cl_each(elt => elt.classList.toggle('comment--hover', toggle));
|
|
|
|
};
|
|
|
|
|
|
|
|
previewElt.addEventListener('mouseover', onDiscussionEvt(classToggler(true)));
|
|
|
|
previewElt.addEventListener('mouseout', onDiscussionEvt(classToggler(false)));
|
2017-11-10 23:39:51 +00:00
|
|
|
previewElt.addEventListener('click', onDiscussionEvt((discussionId) => {
|
|
|
|
this.$store.commit('discussion/setCurrentDiscussionId', discussionId);
|
|
|
|
}));
|
2017-11-15 08:12:56 +00:00
|
|
|
|
2017-11-10 23:39:51 +00:00
|
|
|
this.$watch(
|
|
|
|
() => this.$store.state.discussion.currentDiscussionId,
|
|
|
|
(discussionId, oldDiscussionId) => {
|
|
|
|
if (oldDiscussionId) {
|
2017-11-15 08:12:56 +00:00
|
|
|
previewElt.querySelectorAll(`.discussion-preview-highlighting--${oldDiscussionId}`)
|
2017-11-10 23:39:51 +00:00
|
|
|
.cl_each(elt => elt.classList.remove('discussion-preview-highlighting--selected'));
|
|
|
|
}
|
|
|
|
if (discussionId) {
|
2017-11-15 08:12:56 +00:00
|
|
|
previewElt.querySelectorAll(`.discussion-preview-highlighting--${discussionId}`)
|
2017-11-10 23:39:51 +00:00
|
|
|
.cl_each(elt => elt.classList.add('discussion-preview-highlighting--selected'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2017-07-23 18:42:08 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2017-08-03 17:08:12 +00:00
|
|
|
@import 'common/variables.scss';
|
|
|
|
|
|
|
|
.preview,
|
|
|
|
.preview__inner-1 {
|
2017-07-23 18:42:08 +00:00
|
|
|
position: absolute;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
2017-08-03 17:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.preview__inner-1 {
|
2017-07-23 18:42:08 +00:00
|
|
|
overflow: auto;
|
|
|
|
}
|
|
|
|
|
2017-08-03 17:08:12 +00:00
|
|
|
.preview__inner-2 {
|
2017-07-23 18:42:08 +00:00
|
|
|
margin: 0;
|
|
|
|
}
|
2017-07-31 09:04:01 +00:00
|
|
|
|
2017-08-03 17:08:12 +00:00
|
|
|
.preview__inner-2 > :first-child > :first-child {
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
|
2017-11-15 08:12:56 +00:00
|
|
|
$corner-size: 110px;
|
|
|
|
|
|
|
|
.preview__corner {
|
2017-08-03 17:08:12 +00:00
|
|
|
position: absolute;
|
2017-11-15 08:12:56 +00:00
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
&::before {
|
|
|
|
content: '';
|
|
|
|
position: absolute;
|
|
|
|
right: 0;
|
|
|
|
border-top: $corner-size solid rgba(0, 0, 0, 0.075);
|
|
|
|
border-left: $corner-size solid transparent;
|
|
|
|
pointer-events: none;
|
2018-01-14 16:27:06 +00:00
|
|
|
|
|
|
|
.app--dark & {
|
|
|
|
border-top-color: rgba(255, 255, 255, 0.075);
|
|
|
|
}
|
2017-11-15 08:12:56 +00:00
|
|
|
}
|
2017-08-03 17:08:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.preview__button {
|
2017-11-15 08:12:56 +00:00
|
|
|
position: absolute;
|
|
|
|
top: 15px;
|
|
|
|
right: 15px;
|
2017-08-03 17:08:12 +00:00
|
|
|
width: 40px;
|
|
|
|
height: 40px;
|
|
|
|
padding: 5px;
|
2017-11-15 08:12:56 +00:00
|
|
|
color: rgba(0, 0, 0, 0.25);
|
2017-08-03 17:08:12 +00:00
|
|
|
|
2018-01-14 16:27:06 +00:00
|
|
|
.app--dark & {
|
|
|
|
color: rgba(255, 255, 255, 0.25);
|
|
|
|
}
|
|
|
|
|
2017-11-15 08:12:56 +00:00
|
|
|
&:active,
|
|
|
|
&:focus,
|
2017-08-03 17:08:12 +00:00
|
|
|
&:hover {
|
2017-11-15 08:12:56 +00:00
|
|
|
color: rgba(0, 0, 0, 0.33);
|
|
|
|
background-color: transparent;
|
2018-01-14 16:27:06 +00:00
|
|
|
|
|
|
|
.app--dark & {
|
|
|
|
color: rgba(255, 255, 255, 0.33);
|
|
|
|
}
|
2017-07-31 09:04:01 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-23 18:42:08 +00:00
|
|
|
</style>
|