diff --git a/core/includes/common.inc b/core/includes/common.inc index dece539..b953600 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -77,6 +77,11 @@ const CSS_DEFAULT = 0; const CSS_THEME = 100; /** + * The default group for JavaScript settings added to the page. + */ +const JS_SETTING = -200; + +/** * The default group for JavaScript and jQuery libraries added to the page. */ const JS_LIBRARY = -100; @@ -92,11 +97,6 @@ const JS_DEFAULT = 0; const JS_THEME = 100; /** - * The default group for JavaScript settings added to the page. - */ -const JS_SETTING = 200; - -/** * Error code indicating that the request exceeded the specified timeout. * * @see drupal_http_request() @@ -4067,7 +4067,7 @@ function drupal_pre_render_scripts($elements) { switch ($item['type']) { case 'setting': $element['#value_prefix'] = $embed_prefix; - $element['#value'] = 'jQuery.extend(Drupal.settings, ' . drupal_json_encode(drupal_array_merge_deep_array($item['data'])) . ");"; + $element['#value'] = 'var drupalSettings = ' . drupal_json_encode(drupal_array_merge_deep_array($item['data'])) . ";"; $element['#value_suffix'] = $embed_suffix; break; diff --git a/core/misc/drupal.js b/core/misc/drupal.js index 8bbddc2..2485183 100644 --- a/core/misc/drupal.js +++ b/core/misc/drupal.js @@ -1,14 +1,17 @@ -var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'locale': {} }; +var Drupal = Drupal || { 'behaviors': {}, 'locale': {} }; // Allow other JavaScript libraries to use $. jQuery.noConflict(); // JavaScript should be made compatible with libraries other than jQuery by // wrapping it in an anonymous closure. -(function ($, Drupal, window, document, undefined) { +(function ($, Drupal, settings) { "use strict"; +// Populate Drupal.settings with the drupalSettings variable. +Drupal.settings = settings; + /** * Custom error type thrown after attach/detach if one or more behaviors failed. * @@ -455,4 +458,4 @@ $.extend(Drupal.theme, { } }); -})(jQuery, Drupal, this, this.document); +})(jQuery, Drupal, window.drupalSettings); diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php index ba7a48b..9d486ae 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php @@ -143,8 +143,6 @@ class JavaScriptTest extends WebTestBase { $this->assertTrue(strpos($javascript, 'scriptPath') > 0, 'Rendered JavaScript header returns scriptPath setting.'); $this->assertTrue(strpos($javascript, 'pathPrefix') > 0, 'Rendered JavaScript header returns pathPrefix setting.'); $this->assertTrue(strpos($javascript, 'currentPath') > 0, 'Rendered JavaScript header returns currentPath setting.'); - $this->assertTrue(strpos($javascript, 'core/misc/drupal.js') > 0, 'Rendered JavaScript header includes Drupal.js.'); - $this->assertTrue(strpos($javascript, 'core/misc/jquery.js') > 0, 'Rendered JavaScript header includes jQuery.'); // Only the second of these two entries should appear in Drupal.settings. drupal_add_js(array('commonTest' => 'commonTestShouldNotAppear'), 'setting'); @@ -173,11 +171,11 @@ class JavaScriptTest extends WebTestBase { $this->assertTrue($associative_array_override, t('drupal_add_js() correctly overrides settings within an associative array.')); // Check in a rendered page. $this->drupalGet('common-test/query-string'); - $this->assertPattern('@