Jump to content

Adding custom attributes to an element in TinyMCE


Sinmok
 Share

Recommended Posts

Greetings all,

Trying to figure out how I add extra attributes to an element in TinyMCE.

When I make a piece of text a link, I get the PW popup asking for the URL etc, but there's no way to specify custom attributes for this tag such as a title attribute or even a data-* attribute.

I've edited TinyMCE to allow the title attribute for <a> tags and they're not getting stripped out on save, but it is incredibly cumbersome to have to manually add these extra attributes to an element through the HTML source editor in TinyMCE.

I need this functionality as I am using the title attribute to display a tooltip on hover for the <a> tag.

Does anyone know of a plugin, module or anything really that would help resolve this issue?

Cheers.

Link to comment
Share on other sites

You could replace PW's link dialog with TinyMCE's native link dialog, as I believe it provides the option of more attributes. I think this can be done by replacing references to "pwlink" with "link" in the TinyMCE settings, though have not tried it recently. 

Link to comment
Share on other sites

  • 4 weeks later...

@Ryan

most of my clients require to have sites W3C validated and it is considered good practice anyways. Thus it is essential to have the title attribute in <a> tags.

Would you perhaps consider to make this standard for PW's link dialogue with TinyMCE (and CKEditor)?

I couldn't find instances of "pwlink" in the TinyMCE settings on both, 2.3 and 2.4 installs.

When I switch to CKEditor, there are references "PWLink" in CKEditor Toolbar settings and "pwlink" in Extra Plugins.

When I change PWLink to "Link" and remove the extra plugin pwlink, I get the standard CKEditor Link dialogue where I can enter a title attribute in the Advanced tab.

Cheers

Gerhard

Link to comment
Share on other sites

I would vote against making this standard. It isn't neccesary for w3c validation and actually, using title attributes on links is fairly problematic and i don't think good practice at all.

http://blog.paciellogroup.com/2013/01/using-the-html-title-attribute-updated/

http://www.rnib.org.uk/professionals/webaccessibility/wacblog/Lists/Posts/Post.aspx?id=38

  • Like 3
Link to comment
Share on other sites

I never get error free validation - css3 tends to fail all over the place. I was amused to notice that even stackoverflow is full of errors :)

Thankfully, none of my low value clients even know what wc3 is. 

Interesting blog posts, SiNNut

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...