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!");
}
August 21st, 2008 at 11:26 am
Nice tip! Keep em coming!
August 29th, 2008 at 6:22 pm
Excellent! Much appreciated!
August 29th, 2008 at 6:24 pm
Really good solution. Not even RedDot tech support people know this
September 13th, 2008 at 6:50 pm
[...] 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 [...]