Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

modifying tinymce to allow SOME users to use javascript


Reply


2 Posts   1480 Views

Avatar
JohnHughes

Community Member, 8 Posts

30 August 2010 at 2:40pm

I'm new to SS.

I've got 2.4.1 installed.

Two questions:

1. Can I have different tinymce settings for different roles? (If yes, how is that accomplished?)

2. What do I need to change in order to get tinymce to allow the following code:

<a href="http://www.google.com/recaptcha/mailhide/d?k=01iEAR52Ac2Nww-Kte4m_RHQ==&amp;c=40xscf07XuDYgxvFJrVEdOiQ2jC_KyA2dbtJh-WOJIs=" onclick="window.open('http://www.google.com/recaptcha/mailhide/d?k\07501iEAR52Ac2Nww-Kte4m_RHQ\75\75\46c\07540xscf07XuDYgxvFJrVEdOiQ2jC_KyA2dbtJh-WOJIs\075', '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300'); return false;" title="Reveal this e-mail address">email me</a>

The tinymce filter strips the onclick=window.open portion of the code.

I've reviewed the instructions at [url]doc.silverstripe.org/htmleditorconfig[/url] I would prefer not to turn off all validation.

Avatar
banal

Community Member, 901 Posts

30 August 2010 at 7:28pm

Hi and welcome to SilverStripe

1) I also tried this once. This thread might help you: http://ssorg.bigbird.silverstripe.com/general-questions/show/280243

2) I strongly discourage from using any JavaScript in the WYSIWYG Editor. It doesn't belong there. And since these Scripts are invisible in the Editor, another person can easily remove them by accident.

There are several ways around that issue though.
A) Create a custom shortcode for popup-windows. The user can then enter the URL and the desired window-size. These docs can help you getting started with sortcodes: http://doc.silverstripe.org/shortcodes, http://ssbits.com/2-4-using-short-codes-to-embed-a-youtube-video/

B) Use jQuery to open some links in a popup window. You could create a special CSS class (eg. "popup") in typography.css which you can then assign in the WYSWYG Editor. Load jQuery in your page and the following Script, and you're set:

;(function($) {
   $(function(){
      $("a.popup").click(function(event){
         event.preventDefault();
         window.open(
            $(this).attr("href"), "",
            "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=300"
         );
         return false;
      });
   });
})(jQuery);

All links that have the "popup" class applied will then open in a popup.