I’m trying to insert the following javascript into the head of a document with the $modx->regClientStartupScript(); function. I’ve got a few of these calls in a snippet to add css and js files into a single document. Others work. This one doesn’t.
$readyFunction = "<script type='text/javascript'>
//<![CDATA[
$(document).ready(function() {
$('#container-1').tabs();
$('#container-2').tabs({on: 2});
$('#container-3').tabs({fxSlide: true});
$('#container-4').tabs({fxFade: true, fxSpeed: 'fast'});
$('#container-5').tabs({fxSlide: true, fxFade: true, fxSpeed: 'fast'});
$('#container-6').tabs({fxFade: true, fxSpeed: 'fast', callback: function(newTab, oldTab) {
alert('New tab: ' + newTab.id + ', old tab: ' + oldTab.id);
}});
$('#container-7').tabs({fxAutoheight: true});
$('#trigger-tab').after('<p><a href="#" onclick="$(\'#container-1\').triggerTab(3); return false;">Activate third tab</a></p>');
$('#custom-tab-by-hash').title('New window').click(function() {
var win = window.open(this.href, '', 'directories,location,menubar,resizable,scrollbars,status,toolbar');
win.focus();
});
});//]]>
</script>";
$modx->regClientStartupScript($readyFunction);
I get
Parse error: syntax error, unexpected '$' in /manager/includes/document.parser.class.inc.php(705) : eval()'d code on line 20
(ignore line number. code above is cut from snippet)
I was operating on the assumption that anything inside the CDATA tags would not be parsed. I guess I was wrong. How can I tell the document parser class to simply mind it’s own business and pay no attention to anything between CDATA tags?