mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge pull request #1289 from gilleswittenberg/master
Allow setting type attribute on script block tags
This commit is contained in:
commit
1357b00843
2 changed files with 27 additions and 3 deletions
|
@ -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'),
|
||||
|
@ -1140,6 +1150,20 @@ class HtmlHelperTest extends CakeTestCase {
|
|||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Html->scriptStart(array('safe' => true, 'type' => 'text/x-handlebars-template'));
|
||||
$this->assertNull($result);
|
||||
echo 'this is some template';
|
||||
|
||||
$result = $this->Html->scriptEnd();
|
||||
$expected = array(
|
||||
'script' => array('type' => 'text/x-handlebars-template'),
|
||||
$this->cDataStart,
|
||||
'this is some template',
|
||||
$this->cDataEnd,
|
||||
'/script'
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$this->View->expects($this->once())
|
||||
->method('append');
|
||||
$result = $this->Html->scriptStart(array('safe' => false, 'inline' => false));
|
||||
|
|
|
@ -98,8 +98,8 @@ 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>',
|
||||
'javascriptstart' => '<script type="text/javascript">',
|
||||
'javascriptblock' => '<script%s>%s</script>',
|
||||
'javascriptstart' => '<script>',
|
||||
'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";
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue