diff options
author | ThibG <thib@sitedethib.com> | 2019-06-08 17:40:59 +0200 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-11-19 16:48:13 -0600 |
commit | 117686fd0022f7efaadf5317b0e56566ccd1c0d5 (patch) | |
tree | 5a21b50bb5c1db2864c91530df4b5b42063ee53f /app/javascript | |
parent | 9dcf02b3e08cafe44f1f2a6c093786be76a1fb87 (diff) |
Put poll options behind content warnings (#10983)
* Put poll options behind CWs in WebUI * Put polls behind CWs on public pages * Add poll icon to public pages CWs * Revert to not showing an icon in the CW button
Diffstat (limited to 'app/javascript')
-rw-r--r-- | app/javascript/mastodon/components/status.js | 5 | ||||
-rw-r--r-- | app/javascript/mastodon/components/status_content.js | 19 | ||||
-rw-r--r-- | app/javascript/mastodon/features/status/components/detailed_status.js | 5 | ||||
-rw-r--r-- | app/javascript/packs/public.js | 137 |
4 files changed, 155 insertions, 11 deletions
diff --git a/app/javascript/mastodon/components/status.js b/app/javascript/mastodon/components/status.js index 3c3ef2c7a..f74e2acce 100644 --- a/app/javascript/mastodon/components/status.js +++ b/app/javascript/mastodon/components/status.js @@ -16,7 +16,6 @@ import { MediaGallery, Video } from '../features/ui/util/async-components'; import { HotKeys } from 'react-hotkeys'; import classNames from 'classnames'; import Icon from 'mastodon/components/icon'; -import PollContainer from 'mastodon/containers/poll_container'; import { displayMedia } from '../initial_state'; // We use the component (and not the container) since we do not want @@ -320,9 +319,7 @@ class Status extends ImmutablePureComponent { status = status.get('reblog'); } - if (status.get('poll')) { - media = <PollContainer pollId={status.get('poll')} />; - } else if (status.get('media_attachments').size > 0) { + if (status.get('media_attachments').size > 0) { if (this.props.muted) { media = ( <AttachmentList diff --git a/app/javascript/mastodon/components/status_content.js b/app/javascript/mastodon/components/status_content.js index fa8901386..01b4351be 100644 --- a/app/javascript/mastodon/components/status_content.js +++ b/app/javascript/mastodon/components/status_content.js @@ -5,6 +5,7 @@ import { isRtl } from '../rtl'; import { FormattedMessage } from 'react-intl'; import Permalink from './permalink'; import classnames from 'classnames'; +import PollContainer from 'mastodon/containers/poll_container'; import Icon from 'mastodon/components/icon'; const MAX_HEIGHT = 642; // 20px * 32 (+ 2px padding at the top) @@ -191,6 +192,8 @@ export default class StatusContent extends React.PureComponent { {mentionsPlaceholder} <div tabIndex={!hidden ? 0 : null} className={`status__content__text ${!hidden ? 'status__content__text--visible' : ''}`} style={directionStyle} dangerouslySetInnerHTML={content} lang={status.get('language')} /> + + {!hidden && !!status.get('poll') && <PollContainer pollId={status.get('poll')} />} </div> ); } else if (this.props.onClick) { @@ -212,9 +215,13 @@ export default class StatusContent extends React.PureComponent { output.push(readMoreButton); } + if (status.get('poll')) { + output.push(<PollContainer pollId={status.get('poll')} />); + } + return output; } else { - return ( + const output = [ <div tabIndex='0' ref={this.setRef} @@ -222,8 +229,14 @@ export default class StatusContent extends React.PureComponent { style={directionStyle} dangerouslySetInnerHTML={content} lang={status.get('language')} - /> - ); + />, + ]; + + if (status.get('poll')) { + output.push(<PollContainer pollId={status.get('poll')} />); + } + + return output; } } diff --git a/app/javascript/mastodon/features/status/components/detailed_status.js b/app/javascript/mastodon/features/status/components/detailed_status.js index c6682b767..7c9b3a01c 100644 --- a/app/javascript/mastodon/features/status/components/detailed_status.js +++ b/app/javascript/mastodon/features/status/components/detailed_status.js @@ -13,7 +13,6 @@ import Video from '../../video'; import scheduleIdleTask from '../../ui/util/schedule_idle_task'; import classNames from 'classnames'; import Icon from 'mastodon/components/icon'; -import PollContainer from 'mastodon/containers/poll_container'; export default class DetailedStatus extends ImmutablePureComponent { @@ -107,9 +106,7 @@ export default class DetailedStatus extends ImmutablePureComponent { outerStyle.height = `${this.state.height}px`; } - if (status.get('poll')) { - media = <PollContainer pollId={status.get('poll')} />; - } else if (status.get('media_attachments').size > 0) { + if (status.get('media_attachments').size > 0) { if (status.getIn(['media_attachments', 0, 'type']) === 'video') { const video = status.getIn(['media_attachments', 0]); diff --git a/app/javascript/packs/public.js b/app/javascript/packs/public.js index 69e6ba0ec..3135636cf 100644 --- a/app/javascript/packs/public.js +++ b/app/javascript/packs/public.js @@ -1,9 +1,26 @@ +import escapeTextContentForBrowser from 'escape-html'; import loadPolyfills from '../mastodon/load_polyfills'; import ready from '../mastodon/ready'; import { start } from '../mastodon/common'; start(); +window.addEventListener('message', e => { + const data = e.data || {}; + + if (!window.parent || data.type !== 'setHeight') { + return; + } + + ready(() => { + window.parent.postMessage({ + type: 'setHeight', + id: data.id, + height: document.getElementsByTagName('html')[0].scrollHeight, + }, '*'); + }); +}); + function main() { const IntlMessageFormat = require('intl-messageformat').default; const { timeAgoString } = require('../mastodon/components/relative_timestamp'); @@ -100,6 +117,126 @@ function main() { scrollbarWidthStyle.sheet.insertRule(`body.with-modals--active { margin-right: ${scrollbarWidth}px; }`, 0); } }); + + delegate(document, '.webapp-btn', 'click', ({ target, button }) => { + if (button !== 0) { + return true; + } + window.location.href = target.href; + return false; + }); + + delegate(document, '.status__content__spoiler-link', 'click', function() { + const contentEl = this.parentNode.parentNode.querySelector('.e-content'); + + if (contentEl.style.display === 'block') { + contentEl.style.display = 'none'; + this.parentNode.style.marginBottom = 0; + } else { + contentEl.style.display = 'block'; + this.parentNode.style.marginBottom = null; + } + + return false; + }); + + delegate(document, '.modal-button', 'click', e => { + e.preventDefault(); + + let href; + + if (e.target.nodeName !== 'A') { + href = e.target.parentNode.href; + } else { + href = e.target.href; + } + + window.open(href, 'mastodon-intent', 'width=445,height=600,resizable=no,menubar=no,status=no,scrollbars=yes'); + }); + + delegate(document, '#account_display_name', 'input', ({ target }) => { + const name = document.querySelector('.card .display-name strong'); + if (name) { + if (target.value) { + name.innerHTML = emojify(escapeTextContentForBrowser(target.value)); + } else { + name.textContent = document.querySelector('#default_account_display_name').textContent; + } + } + }); + + delegate(document, '#account_avatar', 'change', ({ target }) => { + const avatar = document.querySelector('.card .avatar img'); + const [file] = target.files || []; + const url = file ? URL.createObjectURL(file) : avatar.dataset.originalSrc; + + avatar.src = url; + }); + + const getProfileAvatarAnimationHandler = (swapTo) => { + //animate avatar gifs on the profile page when moused over + return ({ target }) => { + const swapSrc = target.getAttribute(swapTo); + //only change the img source if autoplay is off and the image src is actually different + if(target.getAttribute('data-autoplay') === 'false' && target.src !== swapSrc) { + target.src = swapSrc; + } + }; + }; + + delegate(document, 'img#profile_page_avatar', 'mouseover', getProfileAvatarAnimationHandler('data-original')); + + delegate(document, 'img#profile_page_avatar', 'mouseout', getProfileAvatarAnimationHandler('data-static')); + + delegate(document, '#account_header', 'change', ({ target }) => { + const header = document.querySelector('.card .card__img img'); + const [file] = target.files || []; + const url = file ? URL.createObjectURL(file) : header.dataset.originalSrc; + + header.src = url; + }); + + delegate(document, '#account_locked', 'change', ({ target }) => { + const lock = document.querySelector('.card .display-name i'); + + if (target.checked) { + lock.style.display = 'inline'; + } else { + lock.style.display = 'none'; + } + }); + + delegate(document, '.input-copy input', 'click', ({ target }) => { + target.focus(); + target.select(); + target.setSelectionRange(0, target.value.length); + }); + + delegate(document, '.input-copy button', 'click', ({ target }) => { + const input = target.parentNode.querySelector('.input-copy__wrapper input'); + + const oldReadOnly = input.readonly; + + input.readonly = false; + input.focus(); + input.select(); + input.setSelectionRange(0, input.value.length); + + try { + if (document.execCommand('copy')) { + input.blur(); + target.parentNode.classList.add('copied'); + + setTimeout(() => { + target.parentNode.classList.remove('copied'); + }, 700); + } + } catch (err) { + console.error(err); + } + + input.readonly = oldReadOnly; + }); } loadPolyfills().then(main).catch(error => { |