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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

TinyMCE strips my code


Reply


27 Posts   12577 Views

Avatar
banal

Community Member, 901 Posts

10 April 2009 at 4:39am

Edited: 10/04/2009 4:41am

Umm. It's actually quite common to wrap javascript statements in comment tags, it's even preferred. That's just to prevent them from showing up as plain text in browsers that don't recognize the <script> tag. These commands will be executed anyways...
Try entering this in your html code and open the page in your browser:

<script type="text/javascript">
<!--
alert("HAHA, comments can't do me any harm!");
//-->
</script>

Avatar
cob-web

Community Member, 5 Posts

10 April 2009 at 7:15am

Hi banal,

thanks very much for your help!
Your

<script type="text/javascript">
<!--
alert("HAHA, comments can't do me any harm!");
//-->
</script>


works fine :-)

My script unfortunately doesn't work in SS. (it works in a simple html file though)
I'll have a deeper view into this later.
Or do you know a better way to embed javascript into SS?
The point is that my player has to appear in the middle of the content page.

Cheers,
Tomas

Avatar
banal

Community Member, 901 Posts

10 April 2009 at 7:42am

Edited: 10/04/2009 7:45am

Directly including a flash player inside your content can get messy... as you already noticed it's not even supported by SilverStripe without messing with the TinyMCE implementation.
I'd probably work with some kind of placeholder that will later be replaced with the real player code. Something like this:

<div class="flashplayer {playlist : 'playlist.xml'}">

You would then use jQuery/swfobject to replace the div with the actual flash-player code. The only varying parameter is probably the playlist and can be passed to jQuery using the rather neat "metadata" Plugin: http://plugins.jquery.com/project/metadata Using that, you could pass in even more parameters, depending on your needs.

In the CMS / Content Editor view, I'd probably style the flashplayer element to something visible (a plain div isn't visible), just that you know where in your content the player is actually located.

Avatar
cob-web

Community Member, 5 Posts

11 April 2009 at 2:32am

Hi banal,

now I got the flash player working.
I used a workaround without javascript using the following code :

<div id="player">
<object height="220" width="267" data="assets/Flash/player.swf" type="application/x-shockwave-flash">
<param name="flashvars" value="file=assets/Flash/playlist.xml&amp;autostart=false&amp;controlbar=bottom&amp;displayclick=play&amp;frontcolor=193264&amp;lightcolor=333333&amp;backcolor=E9E9E9" />
<param name="src" value="assets/Flash/player.swf" />
<param name="allowfullscreen" value="false" />
<param name="wmode" value="opaque" />
</object>
</div>

It works great now :-)

Thanks a lot for your hints & Happy Easter ;-)
Tomas

Avatar
ramos

Community Member, 4 Posts

21 April 2009 at 3:47am

Hi banal,

Your help has been really appreciated, thank you very much for your help.

I didn't want to, but I had to do the jquery solution, since to do the other one is needed to change some javascript file from the core and I don't want to touch any of the core files unless configuration stuff, so I can upload new versions without problems in the future.

Anyway, I think is not right/good to be adding javascript hacks to solve things that should be implemented in a configuration file, it only can bring new problems and misunderstandings, lowering the quality of my code and making it far way less smart ;)

In my point of view it has no sense to be adding one jquery line for each time I have to use some event, I keep thinking there is a problem that should be fixed in the core to make this posible only changing the tinymce template file, of course it's just one opinion.

In any case, thank you very much again for helping us!!

Regards!

Avatar
banal

Community Member, 901 Posts

21 April 2009 at 4:16am

Well, you can't have *everything* customizable without modifying core files. Probably you could even solve your issue only by subclassing or decorating core files (that would leave core untouched and updateable), but I'm not 100% sure about that.

I wouldn't describe the jQuery approach as a hack. The JavaScript required for the tracking isn't part of the "presentation" and doesn't belong to the html markup imho.
I'd prefer the jQuery approach any day. Why? Imagine you'll switch from Google-Analytics to some other tracking software. Or you just want some other commands to be issued along with your tracking call. Or you want to remove the tracking of files completely...
Using the "onclick" attribute in your content will force you to change all of your pages to reflect the new behavior, while when using jQuery (or any other scripted approach for that matter) you just change a few lines in your JavaScript file.
It does not only degrade nicely, it's also easier to update and maintain. In my opinion that would be an increase in code quality.

Avatar
ramos

Community Member, 4 Posts

21 April 2009 at 7:47pm

Well, we just have diferent points of view ^^
In my opinion the onclick event is a HTML attribute and should be set directly in the markup not in javascript.
Thank you again for your help :)

Avatar
Victor

Community Member, 128 Posts

21 April 2009 at 10:35pm

In order to paste html (including js, but not php) code without mutilation by TMCE I just create HTMLText field and paste here whatever I want

Victor