Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable attachment captions #434

Merged
merged 4 commits into from Aug 4, 2017
Merged

Configurable attachment captions #434

merged 4 commits into from Aug 4, 2017

Conversation

@javan
Copy link
Member

@javan javan commented Aug 4, 2017

Trix.config.attachments.preview.caption = { name: true, size: true } // The default

default

Trix.config.attachments.preview.caption = { name: true, size: false } 

no-size

Trix.config.attachments.preview.caption = { name: false, size: true }

no-name

Trix.config.attachments.preview.caption = { name: false, size: false }

blank

Fixes #87

@javan javan merged commit f2b7720 into master Aug 4, 2017
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@javan javan deleted the caption-config branch Aug 4, 2017
@toxin20
Copy link

@toxin20 toxin20 commented Aug 14, 2017

How can I override the configuration options for the caption?

I tried setting Trix.config.attachments.preview.caption but I get the following error because the attachment object in the config doesn't seem to be defined:
Uncaught TypeError: Cannot read property 'preview' of undefined

I tried to wrap the config change in a "trix-initialize" event listener but that didn't work either.

I'm not sure how & when to override config options since it hasn't really been featured in the documentation so far.
Would be awesome if you could point me in the right direction :).

@javan
Copy link
Member Author

@javan javan commented Aug 14, 2017

This feature hasn't shipped in an official release yet so the commits are only in master. I hope to cut a new release soon. In the meantime, you can check out Trix and build it from source if you'd like: https://github.com/basecamp/trix#building-from-source.

@toxin20
Copy link

@toxin20 toxin20 commented Aug 14, 2017

I checked out the master branch via yarn add basecamp/trix#master so the latest commit should be included, right? Or are the files in /dist/ not built from the latest commits?

Edit: Ah, I see. The files in /dist/ are built from the latest release version, not the master branch. I'll build it from source then.

@javan
Copy link
Member Author

@javan javan commented Aug 16, 2017

FYI these changes are in Trix 0.11.0 now. Released yesterday. https://github.com/basecamp/trix/releases/tag/0.11.0

@kylefox
Copy link

@kylefox kylefox commented Aug 17, 2017

This is awesome 👍

Any thoughts on adding the ability to turn off captions completely?

Related: #87: Make caption for previewable attachments optional

@javan
Copy link
Member Author

@javan javan commented Aug 18, 2017

@kylefox do you mean something different than Trix.config.attachments.preview.caption = { name: false, size: false }? That's what https://trix-editor.org/ has set, currently.

@kylefox
Copy link

@kylefox kylefox commented Aug 18, 2017

@javan Thanks — turns out I just made a silly mistake.

@therealrodk
Copy link

@therealrodk therealrodk commented Feb 23, 2019

Did this get broken somewhere along the way? Because when I use the above code and turn off the captions (either one or both), I can no longer add images to my Trix editor. My app is using Ruby 2.5.3 and Rails 5.2.2. It will only work if I leave the captions in, as is, which I find both visually offensive and very annoying. Someone suggested targeting figcaption with CSS and setting it to display: none, but that only hides the captions in the edit window. As soon as it gets saved, the code gets converted to an anchor tag with the image and text inside it, and no class to target.

@therealrodk
Copy link

@therealrodk therealrodk commented Feb 23, 2019

I was a little mistaken. The anchor tag and link were due to some javascript I added during the GoRails walkthrough. On save, the code gets saved as:

<img src="/uploads/store/eaef572b4c15a60f439fbbbff987f1ca.png" width="728" height="90">
"String of caption text"
<span class="size">3.41 KB</span>

The span.size can be targeted and hidden via CSS, but I'm still not sure how to hide the caption text.

@alessandromarchetti
Copy link

@alessandromarchetti alessandromarchetti commented Aug 27, 2019

I'm having problems when trying to use this feature with already existing attachments (the content is loaded from the input element, as per documentation, and it contains pictures without captions). I'm setting Trix.config.attachments.preview.caption = { name: false, size: false } but it fills the captions of the existing attachments with the default filnename and size; as soon as I do any kind of modification to the editor content, it resets them to the empty ones. I guess it's because trix is initializing the editor and the input as soon as it loads (please correct me if I'm wrong), before the configuration is modified. Is there a clean way to trigger a new initialization or simply an update of all editors? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

5 participants
You can’t perform that action at this time.