Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow groups of attributes to be set via a toolbar dialog#1197

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
brendon wants to merge10 commits intobasecamp:main
base:main
Choose a base branch
Loading
frombrendon:target-blank

Conversation

@brendon
Copy link

The main point of this PR is to allow one to settarget="_blank" on links on an optional basis (as in the dialog allows the user to tick a box to set that attribute. You'd use the following toolbar dialog:

<div data-trix-dialogs>  <div data-trix-dialog="href" data-trix-dialog-attributes="href target">    <div>      <input type="url" name="href" placeholder="${lang.urlPlaceholder}" aria-label="${lang.url}" required data-trix-input>            <input type="checkbox" value="_blank" name="href[target]" data-trix-input>      <label for="href_target">Open in a New Tab?</label>            <div>        <input type="button" value="${lang.link}" data-trix-method="setAttribute">        <input type="button" value="${lang.unlink}" data-trix-method="removeAttribute">      </div>    </div>  </div></div>

In addition, the ActionText configuration should probably be updated to allowtarget as an attribute:

ActionText::ContentHelper.allowed_attributes.add 'target'

The Problem

This mostly works except for some reason I can't sniff out where some sanitisation is occurring. If I hard code a link in the database content with atarget="_blank" and load it into trix, it strips the target attribute in the HTML it displays in the editor but all of the toolbar tools work just fine. The underlying document model still keeps track of thetarget attribute and the tick box ticks and unticks for a particular link depending on if thetarget="_blank" attribute exists, it's just rendered to the HTML and thus gets lost when serialising too.

I'm hoping for some help in solving this last piece of the puzzle and then I'll write some tests to make this PR legit.

#286
#55

To be clear, I'm not arguing for this to be included in the default interface, but it should still be possible to achieve with a custom toolbar and dialog. The aim is to make this change non-breaking (thus the aliased methods).

…a groupTagThe only flaw would be that it will fixate on the first matching groupTag so the order attributes are listed in the toolbar dialog data attribute is important.
@brendon
Copy link
Author

Ok, so I figured out the issue with not being able to set more than one attribute on agroupTag and it's to do with howcreateContainerElement() worked. It would stop at the first attribute that had agroupTagName configuration and then create an element with that tag and just the attribute that had thegroupTagName. I've modified that so that it keeps going through the other elements to see if there are any other attributes with the samegroupTagName and it'll add those attributes when the new element is made.

To be honest, it feels like the configuration needs more of an overhaul to cope with this scenario. Ideally acceptablesiblingAttributes should be defined on thehref configuration but we also need to change code that tries to identify if an attribute is a text or block attribute.

Not sure what your future plans are for configuration but the way it's currently done just isn't flexible enough.

Let me know your thoughts. The code now works at least. You can set and unset the target via a checkbox.

@brendon
Copy link
Author

The test suite as it stands now runs green. I'm keen to add some tests to test the new functionality but would like some feedback on the overall PR before I begin that if that's ok? If I've made a mistake in my assumptions then it'd be good to fix that before beginning tests.

@brendon
Copy link
Author

Any chance I could get some feedback? Even if it's just a "yes, good, write some tests" or "think about it this other way".

@brendon
Copy link
Author

@seanpdoyle, I'd love to get some feedback on this PR. I'm not sure where it fits within your greater ambitions but it would be helpful to modify more than one attribute via a dialog.

@brendon
Copy link
Author

Still keen to get some feedback on this.

@brendon
Copy link
Author

@brunoprietog, I'd love a review of this PR.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

@brendon

[8]ページ先頭

©2009-2025 Movatter.jp