mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
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:
parent
0dec0353b1
commit
baf2364c83
1 changed files with 17 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue