RedDot CMS, SmartEdit and Javascript

If you have Javascript in your website, and have implemented your Javascript files as templates in RedDot CMS (version 7.5), linked in to your HTML page via an anchor placeholder, you will most likely have come across this issue - your Javascript doesn’t work in SmartEdit!

The reason? RedDot CMS in SmartEdit mode does some mucking around with your template which causes Javascript errors. Take the simple Javascript template below:

function helloWorld() {
  alert("Hello World!");
}

In SmartEdit, this becomes:

<HTML><HEAD></HEAD><BODY ONLOAD="CheckAllTargets();" ><SCRIPT language="javascript" src="ioEditElement.js"></SCRIPT><SCRIPT language=javascript src="RDCleanHtml.js"></SCRIPT>
<SCRIPT language="javascript">var sInvertDirectEdit="0";var sRemoveFontSettings="1";var sRemoveStyleSettings="1";var sAllowedStyleAttributes="";</SCRIPT>
function helloWorld() {
  alert("Hello World!");
}

As you might expect - this isn’t valid Javascript, and basically the Javascript processing stops at the top of the file. We can eliminate this with a single line of code to our original Javascript file:

<!IoRangeRedDotMode>/* <body>RedDot decoy</body> */<!/IoRangeRedDotMode>
function helloWorld() {
  alert("Hello World!");
}

Now, when RedDot CMS renders the Javascript in SmartEdit, it will be conveniently fooled by our decoy HTML body tags (as shown below) and all will be well!

<!IoRangeRedDotMode>/* <body ONLOAD="CheckAllTargets();" ><SCRIPT language="javascript" src="ioEditElement.js"></SCRIPT><SCRIPT language=javascript src="RDCleanHtml.js"></SCRIPT>
<SCRIPT language="javascript">var sInvertDirectEdit="0";var sRemoveFontSettings="";var sRemoveStyleSettings="";var sAllowedStyleAttributes="";</SCRIPT>RedDot decoy</body> */<!/IoRangeRedDotMode>
function helloWorld() {
  alert("Hello World!");
}

4 Responses to “RedDot CMS, SmartEdit and Javascript”

  1. Phil Says:

    Nice tip! Keep em coming!

  2. Julio Canadas Says:

    Excellent! Much appreciated!

  3. Byron Says:

    Really good solution. Not even RedDot tech support people know this ;)

  4. Adrian Mateljan » Blog Archive » RedDot CMS, SmartEdit and Lightbox Says:

    [...] my previous article on RedDot CMS, SmartEdit and Javascript is just not enough - for example, integrating Lightbox (in this case, version 1). Now, there is [...]

Leave a Reply