CDATA and addScriptDeclaration method

117 views
Skip to first unread message

grisoni77

unread,
Jul 7, 2009, 3:47:18 AM7/7/09
to Joomla! General Development
Hi all,

JDocument::addScriptDeclaration method appends js code to a class
property.
When rendering the page the proper renderer (JDocumentRendererHead)
wraps the added code in one single script tag.
I noticed that CDATA notation is only applied when content-type is
different from 'text/html':

// Generate script declarations
foreach ($document->_script as $type => $content)
{
$strHtml .= $tab.'<script type="'.$type.'">'.$lnEnd;

// This is for full XHTML support.
if ($document->_mime != 'text/html' ) {
$strHtml .= $tab.$tab.'<![CDATA['.$lnEnd;
}

$strHtml .= $content.$lnEnd;

// See above note
if ($document->_mime != 'text/html' ) {
$strHtml .= $tab.$tab.'// ]]>'.$lnEnd;
}
$strHtml .= $tab.'</script>'.$lnEnd;
}

My questions are:
1) shouldnt this be added always for old browser compatibility?(http://
javascript.about.com/library/blxhtml.htm)
2) it seems to me that the correct notation is :
<script type="text/javascript">
/* <![CDATA[ */
// content of your Javascript goes here
/* ]]> */
</script>
and thus it should be changed..

What are your thoughts?

Thanks,
Cristiano
Reply all
Reply to author
Forward
0 new messages