From c0f6699f82fc8a7849021f5eaec259306c2317af Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Mon, 17 Aug 2020 04:38:49 -0500 Subject: [Accessibility] Show media descriptions as captions --- .../flavours/glitch/components/media_gallery.js | 61 ++++++++++++++++++++++ .../styles/monsterfork/components/status.scss | 6 +++ app/javascript/mastodon/locales/en-MP.json | 2 + 3 files changed, 69 insertions(+) (limited to 'app/javascript') diff --git a/app/javascript/flavours/glitch/components/media_gallery.js b/app/javascript/flavours/glitch/components/media_gallery.js index 96042f07a..1ab9a6adb 100644 --- a/app/javascript/flavours/glitch/components/media_gallery.js +++ b/app/javascript/flavours/glitch/components/media_gallery.js @@ -384,6 +384,66 @@ class MediaGallery extends React.PureComponent { ); } + let parts = {}; + + media.map( + (attachment, i) => { + if (attachment.get('description')) { + if (attachment.get('description') in parts) { + parts[attachment.get('description')].push([i, attachment.get('url'), attachment.get('id')]); + } else { + parts[attachment.get('description')] = [[i, attachment.get('url'), attachment.get('id')]]; + } + } + }, + ); + + let descriptions = Object.entries(parts).map( + part => { + const [desc, idx] = part; + if (idx.length === 1) { + const url = idx[0][1]; + return ( +

+ + + + + + {desc} +

+ ); + } else if (idx.length !== 0) { + const indexes = ( + + { + idx.map((i, c) => { + const url = i[1]; + return ({c === 0 ? ' ' : ', '}#{1+i[0]}); + }) + } + + ); + return ( +

+ + + + {desc} +

+ ); + } else { + return null; + } + }, + ); + + let description_wrapper = visible && ( +
+ {descriptions} +
+ ); + return (
@@ -396,6 +456,7 @@ class MediaGallery extends React.PureComponent {
{children} + {description_wrapper}
); } diff --git a/app/javascript/flavours/glitch/styles/monsterfork/components/status.scss b/app/javascript/flavours/glitch/styles/monsterfork/components/status.scss index 73f883db1..948fcecf0 100644 --- a/app/javascript/flavours/glitch/styles/monsterfork/components/status.scss +++ b/app/javascript/flavours/glitch/styles/monsterfork/components/status.scss @@ -143,6 +143,12 @@ div[data-nest-deep="true"] { } div.media-caption { + background: $ui-base-color; + + strong { + font-weight: bold; + } + p { font-size: 12px !important; margin-bottom: 0; diff --git a/app/javascript/mastodon/locales/en-MP.json b/app/javascript/mastodon/locales/en-MP.json index ec331be2c..b135f817c 100644 --- a/app/javascript/mastodon/locales/en-MP.json +++ b/app/javascript/mastodon/locales/en-MP.json @@ -135,6 +135,8 @@ "status.in_reply_to": "This roar is a reply", "status.is_poll": "This roar is a poll", "status.local_only": "Monsterpit-only", + "status.media.description": "Attachment #{index}: ", + "status.media.descriptions": "Attachments {list}: ", "status.open": "Open this roar", "status.permissions.title": "Show extended permissions...", "status.permissions.visibility.account": "{visibility} 🡲 {domain}", -- cgit