Allow setting different type on scriptBlock

This commit is contained in:
Gilles Wittenberg 2013-05-18 20:25:19 +02:00
parent 28a3b73bdc
commit f19615a3be
2 changed files with 12 additions and 2 deletions

View file

@ -1067,6 +1067,16 @@ class HtmlHelperTest extends CakeTestCase {
);
$this->assertTags($result, $expected);
$result = $this->Html->scriptBlock('window.foo = 2;', array('type' => 'text/x-handlebars-template'));
$expected = array(
'script' => array('type' => 'text/x-handlebars-template'),
$this->cDataStart,
'window.foo = 2;',
$this->cDataEnd,
'/script',
);
$this->assertTags($result, $expected);
$result = $this->Html->scriptBlock('window.foo = 2;', array('safe' => false));
$expected = array(
'script' => array('type' => 'text/javascript'),

View file

@ -98,7 +98,7 @@ class HtmlHelper extends AppHelper {
'ol' => '<ol%s>%s</ol>',
'li' => '<li%s>%s</li>',
'error' => '<div%s>%s</div>',
'javascriptblock' => '<script type="text/javascript"%s>%s</script>',
'javascriptblock' => '<script%s>%s</script>',
'javascriptstart' => '<script type="text/javascript">',
'javascriptlink' => '<script type="text/javascript" src="%s"%s></script>',
'javascriptend' => '</script>'
@ -560,7 +560,7 @@ class HtmlHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#HtmlHelper::scriptBlock
*/
public function scriptBlock($script, $options = array()) {
$options += array('safe' => true, 'inline' => true);
$options += array('type' => 'text/javascript', 'safe' => true, 'inline' => true);
if ($options['safe']) {
$script = "\n" . '//<![CDATA[' . "\n" . $script . "\n" . '//]]>' . "\n";
}