Adding $safe param to JavascriptHelper::codeBlock() to wrap JS code in comment and CDATA tags for compatibility with older browsers and XHTML (Ticket #1072)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3194 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-06-29 05:30:56 +00:00
parent 0dec0353b1
commit baf2364c83

View file

@ -42,19 +42,33 @@ class JavascriptHelper extends Helper{
var $_cacheToFile = false;
var $_cacheAll = false;
var $_rules = array();
var $safe = false;
/**
* Returns a JavaScript script tag.
*
* @param string $script The JavaScript to be wrapped in SCRIPT tags.
* @param boolean $allowCache Allows the script to be cached if non-event caching is active
* @param boolean $safe Wraps the script in an HTML comment and a CDATA block
* @return string The full SCRIPT element, with the JavaScript inside it.
*/
function codeBlock($script, $allowCache = true) {
if ($this->_cacheEvents && $this->_cacheAll && $allowCache) {
function codeBlock($script = null, $allowCache = true, $safe = false) {
if ($this->_cacheEvents && $this->_cacheAll && $allowCache && $script !== null) {
$this->_cachedEvents[] = $script;
} else {
return sprintf($this->tags['javascriptblock'], $script);
$block = ($script !== null);
if ($safe || $this->safe) {
$script = "\n" . '<!--//--><![CDATA[//><!--' . "\n" . $script;
if ($block) {
$script .= "\n" . '//--><!]]>' . "\n";
}
}
if ($block) {
return sprintf($this->tags['javascriptblock'], $script);
} else {
return sprintf($this->tags['javascriptstart'], $script);
}
}
}
/**