Commit 9cec02e4 authored by Dries's avatar Dries

- Patch #158992 by sun, quicksketch, zeta ζ, bangpound, Dries et al: inline...

- Patch #158992 by sun, quicksketch, zeta ζ, bangpound, Dries et al: inline Javascript could generate invalid XHTML.
parent a859eb36
...@@ -2063,17 +2063,22 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { ...@@ -2063,17 +2063,22 @@ function drupal_get_js($scope = 'header', $javascript = NULL) {
// page request. // page request.
$query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1); $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1);
// For inline Javascript to validate as XHTML, all Javascript containing
// XHTML needs to be wrapped in CDATA. To make that backwards compatible
// with HTML 4, we need to comment out the CDATA-tag.
$embed_prefix = "\n<!--//--><![CDATA[//><!--\n";
$embed_suffix = "\n//--><!]]>\n";
foreach ($javascript as $type => $data) { foreach ($javascript as $type => $data) {
if (!$data) continue; if (!$data) continue;
switch ($type) { switch ($type) {
case 'setting': case 'setting':
$output .= '<script type="text/javascript">jQuery.extend(Drupal.settings, ' . drupal_to_js(call_user_func_array('array_merge_recursive', $data)) . ");</script>\n"; $output .= '<script type="text/javascript">' . $embed_prefix . 'jQuery.extend(Drupal.settings, ' . drupal_to_js(call_user_func_array('array_merge_recursive', $data)) . ");" . $embed_suffix . "</script>\n";
break; break;
case 'inline': case 'inline':
foreach ($data as $info) { foreach ($data as $info) {
$output .= '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . '>' . $info['code'] . "</script>\n"; $output .= '<script type="text/javascript"' . ($info['defer'] ? ' defer="defer"' : '') . '>' . $embed_prefix . $info['code'] . $embed_suffix . "</script>\n";
} }
break; break;
default: default:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment