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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

modifying tinymce to allow SOME users to use javascript


Go to End


2 Posts   2308 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 doc.silverstripe.org/htmleditorconfig I would prefer not to turn off all validation.

Avatar
bummzack

Community Member, 904 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.