diff --git includes/common.inc includes/common.inc index 0b4f12a..2a54dfb 100644 --- includes/common.inc +++ includes/common.inc @@ -2735,7 +2735,7 @@ function drupal_get_css($css = NULL) { // browser-caching. The string changes on every update or full cache // flush, forcing browsers to load a new copy of the files, as the // URL changed. - $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1); + $default_query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1); // Allow modules to alter the css items. drupal_alter('css', $css); @@ -2771,6 +2771,12 @@ function drupal_get_css($css = NULL) { $external_css = ''; $preprocess_items = array(); foreach ($css as $data => $item) { + if (empty($item['version'])) { + $query_string = $default_query_string; + } + else { + $query_string = '?v=' . $item['version']; + } // Loop through each of the stylesheets, including them appropriately based // on their type. switch ($item['type']) { @@ -2789,6 +2795,12 @@ function drupal_get_css($css = NULL) { $rendered_css['preprocess'] = ''; } break; + case 'library': + $element = $css_element; + $element['#attributes']['media'] = $item['media']; + $element['#attributes']['href'] = file_create_url($item['data']) . $query_string; + $rendered_css[] = theme('html_tag', array('element' => $element)); + break; case 'inline': // Include inline stylesheets. $inline_css .= drupal_load_stylesheet_content($item['data'], $item['preprocess']); @@ -2809,7 +2821,7 @@ function drupal_get_css($css = NULL) { // starting with "ad*". $element = $css_element; $element['#attributes']['media'] = $media; - $filename = 'css_' . md5(serialize($items) . $query_string) . '.css'; + $filename = 'css_' . md5(serialize($items) . $default_query_string) . '.css'; $element['#attributes']['href'] = file_create_url(drupal_build_css_cache($items, $filename)); $rendered_css['preprocess'] .= theme('html_tag', array('element' => $element)); } @@ -3164,8 +3176,8 @@ function drupal_region_class($region) { * always pass the string 'setting' only. * - type * The type of JavaScript that is to be added to the page. Allowed - * values are 'file', 'inline', 'external' or 'setting'. Defaults - * to 'file'. + * values are 'library', 'file', 'inline', 'external' or 'setting'. + * Defaults to 'file'. Types 'library' is never aggregated. * - scope * The location in which you want to place the script. Possible values * are 'header' or 'footer'. If your theme implements different regions, @@ -3199,6 +3211,10 @@ function drupal_region_class($region) { * Aggregate the JavaScript if the JavaScript optimization setting has * been toggled in admin/config/development/performance. Note that * JavaScript of type 'external' is not aggregated. Defaults to TRUE. + * - version + * If not empty, the version is added as a query string insead of the + * incremental query string that changes on cache clearing. Primarily + * used for libraries. * @return * The constructed array of JavaScript files. * @see drupal_get_js() @@ -3263,7 +3279,7 @@ function drupal_add_js($data = NULL, $options = NULL) { $javascript[] = $options; break; - default: // 'file' and 'external' + default: // 'library', 'file' and 'external' // Local and external files must keep their name as the associative key // so the same JavaScript file is not be added twice. $javascript[$options['data']] = $options; @@ -3339,8 +3355,9 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { } $output = ''; - $preprocessed = ''; + $preprocessed = "\n"; $no_preprocess = "\n"; + $libraries = ''; $files = array(); $preprocess_js = (variable_get('preprocess_js', FALSE) && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update')); $directory = file_directory_path('public'); @@ -3352,7 +3369,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { // URL changed. Files that should not be cached (see drupal_add_js()) // get REQUEST_TIME as query-string instead, to enforce reload on every // page request. - $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1); + $default_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 @@ -3372,6 +3389,12 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { ), ); foreach ($items as $item) { + if (empty($item['version'])) { + $query_string = $default_query_string; + } + else { + $query_string = '?v=' . $item['version']; + } switch ($item['type']) { case 'setting': $js_element = $element; @@ -3406,6 +3429,16 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { } break; + case 'library': + $js_element = $element; + // Preprocessing for JavaScript libraries is ignored. + if ($item['defer']) { + $js_element['#attributes']['defer'] = 'defer'; + } + $js_element['#attributes']['src'] = file_create_url($item['data']) . $query_string; + $libraries .= theme('html_tag', array('element' => $js_element)); + break; + case 'external': $js_element = $element; // Preprocessing for external JavaScript files is ignored. @@ -3422,7 +3455,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { if ($is_writable && $preprocess_js && count($files) > 0) { // Prefix filename to prevent blocking by firewalls which reject files // starting with "ad*". - $filename = 'js_' . md5(serialize($files) . $query_string) . '.js'; + $filename = 'js_' . md5(serialize($files) . $default_query_string) . '.js'; $preprocess_file = file_create_url(drupal_build_js_cache($files, $filename)); $js_element = $element; $js_element['#attributes']['src'] = $preprocess_file; @@ -3431,7 +3464,7 @@ function drupal_get_js($scope = 'header', $javascript = NULL) { // Keep the order of JS files consistent as some are preprocessed and others are not. // Make sure any inline or JS setting variables appear last after libraries have loaded. - return $preprocessed . $no_preprocess . $output; + return $libraries . $preprocessed . $no_preprocess . $output; } /** @@ -3671,6 +3704,12 @@ function drupal_get_library($module, $name) { if (!empty($libraries[$module][$name]) && is_array($libraries[$module][$name])) { // Add default elements to allow for easier processing. $libraries[$module][$name] += array('dependencies' => array(), 'js' => array(), 'css' => array()); + foreach ($libraries[$module][$name]['js'] as $library => $options) { + $libraries[$module][$name]['js'][$library] += array('type' => 'library', 'version' => $libraries[$module][$name]['version']); + } + foreach ($libraries[$module][$name]['css'] as $library => $options) { + $libraries[$module][$name]['css'][$library] += array('type' => 'library', 'version' => $libraries[$module][$name]['version']); + } } else { $libraries[$module][$name] = FALSE; diff --git modules/system/system.module modules/system/system.module index 5c16f70..1e7adf7 100644 --- modules/system/system.module +++ modules/system/system.module @@ -1090,7 +1090,7 @@ function system_library() { 'website' => 'http://benalman.com/projects/jquery-bbq-plugin/', 'version' => '1.0.2', 'js' => array( - 'misc/jquery.ba-bbq.js', + 'misc/jquery.ba-bbq.js' => array(), ), );