diff --git a/core/includes/common.inc b/core/includes/common.inc index e975823..ae3f6ac 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -533,6 +533,35 @@ function drupal_get_destination() { } /** + * Utility method to get the normalized type of the current request. + * + * Fetches the ContentNegotiation and Request objects from the current container + * and returns the associated request content type. The normalized type is a + * short, lowercase version of the format, such as 'html', 'json' or 'atom'. + * + * @return string + * The request type + */ +function drupal_get_request_content_type() { + $type = &drupal_static(__FUNCTION__); + + if (isset($type)) { + return $type; + } + else { + $container = drupal_container(); + if ($container->has('request') && + $container->has('content_negotiation')) { + $type = $container->get('content_negotiation')->getContentType($container->get('request')); + } + else { + $type = FALSE; + } + } + return $type; +} + +/** * Parses a system URL string into an associative array suitable for url(). * * This function should only be used for URLs that have been generated by the @@ -3891,9 +3920,9 @@ function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALS if (!empty($items)) { // Sort the JavaScript files so that they appear in the correct order. uasort($items, 'drupal_sort_css_js'); - - // Don't add settings if there is no other JS on the page. - if (!empty($items['settings'])) { + // Don't add settings if there is no other JavaScript on the page, unless + // this is an ajax request. + if (!empty($items['settings']) || drupal_get_request_content_type() == 'ajax') { global $theme_key; // Provide the page with information about the theme that's used, so that a // later AJAX request can be rendered using the same theme. @@ -3910,12 +3939,14 @@ function drupal_get_js($scope = 'header', $javascript = NULL, $skip_alter = FALS unset($setting['ajaxPageState']['js']['settings']); // Provide the page with information about the individual CSS files used, - // information not otherwise available when CSS aggregation is enabled. The - // setting is attached later in this function, but is set here, so that CSS - // files removed below are still considered "used" and prevented from being - // added in a later AJAX request. - // Skip if no files were added to the page otherwise jQuery.extend() will overwrite - // the Drupal.settings.ajaxPageState.css object with an empty array. + // information not otherwise available when CSS aggregation is enabled. + // The setting is attached later in this function, but is set here, so + // that CSS files removed in drupal_process_attached() are still + // considered "used" and prevented from being added in a later AJAX + // request. + // Skip if no files were added to the page otherwise jQuery.extend() will + // overwrite the Drupal.settings.ajaxPageState.css object with an empty + // array. $css = drupal_add_css(); if (!empty($css)) { // Cast the array to an object to be on the safe side even if not empty. 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 d9e50db..cfb82f6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/JavaScriptTest.php @@ -509,7 +509,7 @@ class JavaScriptTest extends WebTestBase { $libraries = drupal_get_library('common_test'); $this->assertTrue(isset($libraries['jquery.farbtastic']), t('Retrieved all module libraries.')); // Retrieve all libraries for a module not implementing hook_library_info(). - // Note: This test installs tracker module. + // Note: This test installs language module. $libraries = drupal_get_library('language'); $this->assertEqual($libraries, array(), t('Retrieving libraries from a module not implementing hook_library_info() returns an emtpy array.')); diff --git a/core/modules/system/system.module b/core/modules/system/system.module index b13cf83..2adc714 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1212,7 +1212,7 @@ function _system_batch_theme() { * Implements hook_library_info(). */ function system_library_info() { - // Drupal specific javascript. + // Drupal specific JavaScript. $libraries['drupal'] = array( 'title' => 'Drupal', 'version' => VERSION, @@ -2010,7 +2010,10 @@ function system_library_info() { * Implements hook_js_alter(). */ function system_js_alter(&$javascript) { - // Add configuration only if there are settings added to the page. + // Add configuration only if there are settings added to the page. This is + // only necessary for JavaScript that is added through drupal_add_js(), + // JavaScript that is added as a library would nominate its dependency on + // drupal.settings. if (!empty($javascript['settings'])) { $javascript['settings'] += array( 'type' => 'setting', diff --git a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module index fc6da40..8e9545f 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module +++ b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module @@ -506,6 +506,7 @@ function ajax_forms_test_lazy_load_form($form, &$form_state) { function ajax_forms_test_lazy_load_form_submit($form, &$form_state) { if ($form_state['values']['add_files']) { drupal_add_library('system', 'drupal.system'); + drupal_add_css(drupal_get_path('module', 'system') . '/system.admin.css'); drupal_add_js(array('ajax_forms_test_lazy_load_form_submit' => 'executed'), 'setting'); } $form_state['rebuild'] = TRUE; diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 9eaa156..ce8b274 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -1704,9 +1704,9 @@ function taxonomy_entity_query_alter($query) { } } - /** - * Implements hook_library_info(). - */ +/** + * Implements hook_library_info(). + */ function taxonomy_library_info() { $libraries['drupal.taxonomy'] = array( 'title' => 'Taxonomy',