diff --git a/core/includes/common.inc b/core/includes/common.inc index d21b9ce..f217588 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() @@ -4038,7 +4038,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..627e264 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, drupalSettings) { "use strict"; +// Populate Drupal.settings with the drupalSettings variable. +Drupal.settings = drupalSettings; + /** * Custom error type thrown after attach/detach if one or more behaviors failed. * @@ -71,7 +74,7 @@ DrupalBehaviorError.prototype = new Error(); */ Drupal.attachBehaviors = function (context, settings) { context = context || document; - settings = settings || Drupal.settings; + settings = settings || drupalSettings; var i, errors = [], behaviors = Drupal.behaviors; // Execute all of them. for (i in behaviors) { @@ -133,7 +136,7 @@ Drupal.attachBehaviors = function (context, settings) { */ Drupal.detachBehaviors = function (context, settings, trigger) { context = context || document; - settings = settings || Drupal.settings; + settings = settings || drupalSettings; trigger = trigger || 'unload'; var i, errors = [], behaviors = Drupal.behaviors; // Execute all of them. @@ -159,7 +162,7 @@ Drupal.detachBehaviors = function (context, settings, trigger) { * @todo Temporary solution for the mobile initiative. */ Drupal.checkWidthBreakpoint = function (width) { - width = width || Drupal.settings.widthBreakpoint || 640; + width = width || drupalSettings.widthBreakpoint || 640; return (document.documentElement.clientWidth > width); }; @@ -259,7 +262,7 @@ Drupal.t = function (str, args, options) { * Returns the URL to a Drupal page. */ Drupal.url = function (path) { - return Drupal.settings.basePath + Drupal.settings.scriptPath + path; + return drupalSettings.basePath + drupalSettings.scriptPath + path; }; /** @@ -434,7 +437,7 @@ $('html').addClass('js'); //Attach all behaviors. $(function () { - Drupal.attachBehaviors(document, Drupal.settings); + Drupal.attachBehaviors(document, drupalSettings); }); /** @@ -455,4 +458,4 @@ $.extend(Drupal.theme, { } }); -})(jQuery, Drupal, this, this.document); +})(jQuery, Drupal, window.drupalSettings); diff --git a/core/modules/color/color.module b/core/modules/color/color.module index d4ca6ca..56c04cf 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -771,7 +771,7 @@ function color_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', 'drupalSettings'), array('system', 'jquery.once'), ), ); diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index bde3f35..02757cc 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -397,7 +397,7 @@ function field_ui_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', 'drupalSettings'), array('system', 'jquery.once'), ), ); diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 53dc798..b3681f9 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1713,7 +1713,7 @@ function file_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', 'drupalSettings'), ), ); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 39febca..bf02e6f 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -466,7 +466,7 @@ function locale_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', 'drupalSettings'), ), ); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index bfba2fd..b3756f5 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -4057,7 +4057,7 @@ function node_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', 'drupalSettings'), array('system', 'drupal.form'), ), ); diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index e03c032..3ae575c 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -213,7 +213,7 @@ function overlay_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', 'drupalSettings'), array('system', 'jquery.ui.core'), array('system', 'jquery.bbq'), ), @@ -232,7 +232,7 @@ function overlay_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', 'drupalSettings'), array('system', 'jquery.once'), ), ); diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 10501d0..ea347b4 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -1985,7 +1985,7 @@ abstract class WebTestBase extends TestBase { $this->plainTextContent = FALSE; $this->elements = FALSE; $this->drupalSettings = array(); - if (preg_match('/jQuery\.extend\(Drupal\.settings, (.*?)\);/', $content, $matches)) { + if (preg_match('/var drupalSettings = (.*?);/', $content, $matches)) { $this->drupalSettings = drupal_json_decode($matches[1]); } } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index f216339..dd5ee4d 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -551,7 +551,7 @@ function simpletest_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', 'drupalSettings'), array('system', 'jquery.once'), array('system', 'drupal.tableselect'), ), diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index c07a1c8..f90eee4 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -474,7 +474,7 @@ function statistics_library_info() { 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), - array('system', 'drupal.settings'), + array('system', '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..48a6365 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php @@ -76,7 +76,7 @@ class JavaScriptTest extends WebTestBase { */ function testAddSetting() { // Add a file in order to test default settings. - drupal_add_library('system', 'drupal.settings'); + drupal_add_library('system', 'drupalSettings'); $javascript = drupal_add_js(); $last_settings = reset($javascript['settings']['data']); $this->assertTrue($last_settings['currentPath'], 'The current path JavaScript setting is set correctly.'); @@ -136,15 +136,13 @@ class JavaScriptTest extends WebTestBase { * Test drupal_get_js() for JavaScript settings. */ function testHeaderSetting() { - drupal_add_library('system', 'drupal.settings'); + drupal_add_library('system', 'drupalSettings'); $javascript = drupal_get_js('header'); $this->assertTrue(strpos($javascript, 'basePath') > 0, 'Rendered JavaScript header returns basePath setting.'); $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('@