Hello,
I already seen that a lot of people had this problem and I already tried solutions I've seen in other forum's threads as well in the page http://doc.silverstripe.org/doku.php?id=tinymce&s=tinymce the problem is that they don't seem to work for me.
I am going to use { insted of open square bracket and } insted of close square bracket (Otherwise it will be stripped by codeclock ;) ).
Ok. So, I go to cms/javscript/tinymce.template.js file that is the one that teorically should set the configuration for tinymce valid elements.
Inside this file over the line 43 you can see:
valid_elements : "+a{id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title|class},-strong/-b{class},-em/-i{class},-strike{class},-u{class},#p{id|dir|class|align},-ol{class},-ul{class},-li{class},br,img{id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align},-sub{class},-sup{class},-blockquote{dir|class},-table{border=0|cellspacing|cellpadding|width|height|class|align|summary|dir|id|style},-tr{id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style},tbody{id|class|style},thead{id|class|style},tfoot{id|class|style},-td{id|dir|class|colspan|rowspan|width|height|align|valign|scope|style} ,-th{id|dir|class|colspan|rowspan|width|height|align|valign|scope|style},caption{id|dir|class},-div{id|dir|class|align}, -span{class|align},-pre{class|align},address{class|align},-h1{id|dir|class|align},-h2{id|dir|class|align},-h3{id|dir|class|align},-h4{id|dir|class|align},-h5{id|dir|class|align},-h6{id|dir|class|align},hr{class},dd{id|class|title|dir}, dl{id|class|title|dir},dt{id|class|title|dir}",
extended_valid_elements : "img{class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name}"
Ok, what I exactly need is to add a onclick attribute to a link, my client asked me to know by their googleanalytics how many people has download a pdf file, and for that I need to add this code:
<a href="http://www.example.com/files/map.pdf" onClick="javascript: pageTracker._trackPageview('/downloads/map');">
The first thing I've tried is to add onclick into the +a{ stuff. It didn't work so then I search in google and find the tinymce page so I tried to change valid_elements: ... for valid_elements:*{*} theorically allowing all attributtes and html tags to be used in tinyMCE, but it didn't work.
I tried to to add invalid_elements: "", just to be sure that by default tiny disallow it but it didn't work.
The problem is that it does not strip the whole thing but just gives back: <a pageTracker._trackPageview('/downloads/map');" href="..." > changing the order also, I think there should be something wrong in how tiny strips the thing as well. I tried to to write onClick all in minus like onclick and it didn't solve it. I tried changing extended_valid_elements and all kind of combinations you can imagine between the three attributes I talked about.
I know I could try to keep it out from the editor by trying to make a special template, anyway I think it has no sense to make a special template just when I need a onClick, mainly because:
- What happen if I need it in more than one page, Do I have to make one template for each link?
- The link is in the middle of text, so should I create then 2 boxes one for previous and another for after text?
- What happen if in the future I have n links that needs onclick in one page, I have to make n+1 boxes for the text? Having multiple boxes may cause problems with tags as well.
- Is it really necessary to implement any class to handle this? In any case implementing it would be a hard implementation wich I think it should not be needed just for a onclick attribute.
So IMO it has no sense to do it as a new template when it is a attribute that html handles.
I would appreciate any kind of help or any tip anyone can give me.
Thank you in advance,
Daniel