Pinafore-Web-Client-Frontend/src/routes/_components/status/StatusContent.html

155 lines
4.4 KiB
HTML
Raw Normal View History

<div class={computedClass} ref:node>
{@html massagedContent}
2018-02-04 19:35:24 +01:00
</div>
<style>
.status-content {
margin: 10px 10px 10px 5px;
2018-02-10 05:07:48 +01:00
grid-area: content;
2018-02-04 19:35:24 +01:00
word-wrap: break-word;
overflow: hidden;
white-space: pre-wrap;
font-size: 0.9em;
display: none;
2018-02-04 19:35:24 +01:00
}
2018-02-04 21:10:02 +01:00
.status-content.status-in-own-thread {
2018-02-04 19:35:24 +01:00
font-size: 1.3em;
margin: 20px 10px 20px 5px;
}
.status-content.shown {
display: block;
}
:global(.status-content li) {
font-size: 1.3em;
}
:global(
.status-content p,
.status-content blockquote,
.status-content ul,
.status-content ol) {
2018-02-04 19:35:24 +01:00
margin: 0 0 20px;
}
:global(
.status-content p:first-child,
.status-content blockquote:first-child,
.status-content ul:first-child,
.status-content ol:first-child) {
2018-02-04 19:35:24 +01:00
margin: 0 0 20px;
}
:global(
.status-content p:last-child,
.status-content blockquote:last-child,
.status-content ul:last-child,
.status-content ol:last-child) {
2018-02-04 19:35:24 +01:00
margin: 0;
}
2018-02-04 21:49:42 +01:00
:global(.status-content blockquote) {
padding-left: 1.5rem;
border-left: 5px solid var(--body-bg);
color: var(--very-deemphasized-text-color);
font-style: italic;
}
:global(.status-content ul, .status-content ol) {
padding-left: 2rem;
}
2018-02-04 21:49:42 +01:00
.status-content.status-in-notification {
color: var(--very-deemphasized-text-color);
}
:global(.status-content.status-in-notification a, .status-content.status-in-notification a:hover) {
color: var(--very-deemphasized-link-color);
}
2018-02-10 23:30:09 +01:00
:global(.status-content .invisible) {
/* copied from Mastodon */
font-size: 0;
line-height: 0;
display: inline-block;
width: 0;
height: 0;
position: absolute;
}
2019-01-26 22:50:45 +01:00
:global(.underline-links .status-content a) {
text-decoration: underline;
}
2018-02-04 19:35:24 +01:00
</style>
<script>
import { mark, stop } from '../../_utils/marks'
import { store } from '../../_store/store'
import { classname } from '../../_utils/classname'
import { massageUserText } from '../../_utils/massageUserText'
2018-02-04 19:35:24 +01:00
export default {
2018-04-20 06:38:01 +02:00
oncreate () {
2018-02-04 19:35:24 +01:00
this.hydrateContent()
},
store: () => store,
computed: {
computedClass: ({ isStatusInOwnThread, isStatusInNotification, shown }) => {
return classname(
'status-content',
isStatusInOwnThread && 'status-in-own-thread',
isStatusInNotification && 'status-in-notification',
shown && 'shown'
)
},
content: ({ originalStatus }) => (originalStatus.content || ''),
massagedContent: ({ content, originalStatusEmojis, $autoplayGifs }) => (
massageUserText(content, originalStatusEmojis, $autoplayGifs)
)
2018-02-04 19:35:24 +01:00
},
methods: {
2018-04-20 06:38:01 +02:00
hydrateContent () {
mark('hydrateContent')
let node = this.refs.node
let { originalStatus, uuid } = this.get()
let { mentions, tags } = originalStatus
let count = 0
let anchors = Array.from(node.getElementsByTagName('A'))
for (let anchor of anchors) {
// hydrate hashtag
if (tags && anchor.classList.contains('hashtag')) {
for (let tag of tags) {
if (anchor.getAttribute('href').endsWith(`/tags/${tag.name}`)) {
anchor.setAttribute('href', `/tags/${tag.name}`)
anchor.setAttribute('id', `status-content-link-${uuid}-${++count}`)
anchor.removeAttribute('target')
anchor.removeAttribute('rel')
2018-02-04 19:35:24 +01:00
}
}
// hydrate mention
} else if (mentions && anchor.classList.contains('mention')) {
for (let mention of mentions) {
if (anchor.getAttribute('href') === mention.url) {
anchor.setAttribute('href', `/accounts/${mention.id}`)
anchor.setAttribute('title', `@${mention.acct}`)
anchor.setAttribute('id', `status-content-link-${uuid}-${++count}`)
anchor.removeAttribute('target')
anchor.removeAttribute('rel')
2018-02-04 19:35:24 +01:00
}
}
}
// hydrate external links
let href = anchor.getAttribute('href')
if (new URL(href, location.href).origin !== location.origin) {
anchor.setAttribute('title', href)
anchor.setAttribute('target', '_blank')
anchor.setAttribute('rel', 'nofollow noopener')
}
2018-02-04 19:35:24 +01:00
}
stop('hydrateContent')
}
}
}
</script>