Commit facc5810 authored by Dries's avatar Dries

- Patch #769226 by Owen Barton, sun, effulgentsia, alanburke, bleen18, mfer:...

- Patch #769226 by Owen Barton, sun, effulgentsia, alanburke, bleen18, mfer: optimize JS/CSS aggregation for front-end performance and DX.
parent 0614a785
......@@ -565,7 +565,7 @@ function ajax_process_form($element, &$form_state) {
// Attach JavaScript settings to the element.
if (isset($element['#ajax']['event'])) {
$element['#attached']['library'][] = array('system', 'form');
$element['#attached']['js']['misc/ajax.js'] = array('weight' => JS_LIBRARY + 2);
$element['#attached']['js']['misc/ajax.js'] = array('group' => JS_LIBRARY, 'weight' => 2);
$settings = $element['#ajax'];
......
This diff is collapsed.
......@@ -3061,7 +3061,7 @@ function form_process_fieldset(&$element, &$form_state) {
}
// Contains form element summary functionalities.
$element['#attached']['js']['misc/form.js'] = array('weight' => JS_LIBRARY + 1);
$element['#attached']['js']['misc/form.js'] = array('group' => JS_LIBRARY, 'weight' => 1);
// The .form-wrapper class is required for #states to treat fieldsets like
// containers.
......
......@@ -173,7 +173,7 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb
// And now add the stylesheets properly
foreach ($final_stylesheets as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet) {
drupal_add_css($stylesheet, array('weight' => CSS_THEME, 'media' => $media, 'preprocess' => TRUE));
drupal_add_css($stylesheet, array('group' => CSS_THEME, 'every_page' => TRUE, 'media' => $media));
}
}
......@@ -198,7 +198,7 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb
// Add scripts used by this theme.
foreach ($final_scripts as $script) {
drupal_add_js($script, array('weight' => JS_THEME, 'preprocess' => TRUE));
drupal_add_js($script, array('group' => JS_THEME, 'every_page' => TRUE));
}
$theme_engine = NULL;
......
......@@ -247,7 +247,7 @@ function theme_color_scheme_form($variables) {
$preview_js_path = isset($info['preview_js']) ? $path . $info['preview_js'] : drupal_get_path('module', 'color') . '/' . 'preview.js';
// Add the JS at a weight below color.js.
drupal_add_js($preview_js_path, array('weight' => JS_DEFAULT - 1));
drupal_add_js($preview_js_path, array('weight' => -1));
$output = '';
$output .= '<div class="color-form clearfix">';
......
......@@ -880,7 +880,7 @@ function locale_library_alter(&$libraries, $module) {
global $language;
if ($module == 'system' && isset($libraries['system']['ui.datepicker'])) {
$datepicker = drupal_get_path('module', 'locale') . '/locale.datepicker.js';
$libraries['system']['ui.datepicker']['js'][$datepicker] = array('weight' => JS_THEME);
$libraries['system']['ui.datepicker']['js'][$datepicker] = array('group' => JS_THEME);
$libraries['system']['ui.datepicker']['js'][] = array(
'data' => array(
'jqueryuidatepicker' => array(
......
......@@ -655,7 +655,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
function testRenderInlinePreprocess() {
$css = 'body { padding: 0px; }';
$css_preprocessed = '<style type="text/css" media="all">' . drupal_load_stylesheet_content($css, TRUE) . '</style>';
drupal_add_css($css, array('type' => 'inline', 'preprocess' => TRUE));
drupal_add_css($css, array('type' => 'inline'));
$styles = drupal_get_css();
$this->assertEqual(trim($styles), $css_preprocessed, t('Rendering preprocessed inline CSS adds it to the page.'));
}
......@@ -665,7 +665,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
*/
function testRenderInlineNoPreprocess() {
$css = 'body { padding: 0px; }';
drupal_add_css($css, array('type' => 'inline'));
drupal_add_css($css, array('type' => 'inline', 'preprocess' => FALSE));
$styles = drupal_get_css();
$this->assertTrue(strpos($styles, $css) > 0, t('Rendering non-preprocessed inline CSS adds it to the page.'));
}
......@@ -675,7 +675,9 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
*/
function testRenderInlineFullPage() {
$css = 'body { font-size: 254px; }';
$expected = $css;
// Inline CSS is minified unless 'preprocess' => FALSE is passed as a
// drupal_add_css() option.
$expected = 'body{font-size:254px;}';
// Create a node, using the PHP filter that tests drupal_add_css().
$php_format_id = db_query_range('SELECT format FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField();
......@@ -706,9 +708,9 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css');
// A few system CSS files, ordered in a strange way.
$system_path = drupal_get_path('module', 'system');
drupal_add_css($system_path . '/system.menus.css', array('weight' => CSS_SYSTEM));
drupal_add_css($system_path . '/system.base.css', array('weight' => CSS_SYSTEM - 10));
drupal_add_css($system_path . '/system.theme.css', array('weight' => CSS_SYSTEM));
drupal_add_css($system_path . '/system.menus.css', array('group' => CSS_SYSTEM));
drupal_add_css($system_path . '/system.base.css', array('group' => CSS_SYSTEM, 'weight' => -10));
drupal_add_css($system_path . '/system.theme.css', array('group' => CSS_SYSTEM));
$expected = array(
$system_path . '/system.base.css',
......@@ -1241,12 +1243,20 @@ class JavaScriptTestCase extends DrupalWebTestCase {
$this->assertFalse($javascript['misc/collapse.js']['preprocess'], t('Setting cache to FALSE sets proprocess to FALSE when adding JavaScript.'));
}
/**
* Test adding a JavaScript file with a different group.
*/
function testDifferentGroup() {
$javascript = drupal_add_js('misc/collapse.js', array('group' => JS_THEME));
$this->assertEqual($javascript['misc/collapse.js']['group'], JS_THEME, t('Adding a JavaScript file with a different group caches the given group.'));
}
/**
* Test adding a JavaScript file with a different weight.
*/
function testDifferentWeight() {
$javascript = drupal_add_js('misc/collapse.js', array('weight' => JS_THEME));
$this->assertEqual($javascript['misc/collapse.js']['weight'], JS_THEME, t('Adding a JavaScript file with a different weight caches the given weight.'));
$javascript = drupal_add_js('misc/collapse.js', array('weight' => 2));
$this->assertEqual($javascript['misc/collapse.js']['weight'], 2, t('Adding a JavaScript file with a different weight caches the given weight.'));
}
/**
......@@ -1295,7 +1305,10 @@ class JavaScriptTestCase extends DrupalWebTestCase {
* Test rendering the JavaScript with a file's weight above jQuery's.
*/
function testRenderDifferentWeight() {
drupal_add_js('misc/collapse.js', array('weight' => JS_LIBRARY - 21));
// JavaScript files are sorted first by group, then by the 'every_page'
// flag, then by weight (see drupal_sort_css_js()), so to test the effect of
// weight, we need the other two options to be the same.
drupal_add_js('misc/collapse.js', array('group' => JS_LIBRARY, 'every_page' => TRUE, 'weight' => -21));
$javascript = drupal_get_js();
$this->assertTrue(strpos($javascript, 'misc/collapse.js') < strpos($javascript, 'misc/jquery.js'), t('Rendering a JavaScript file above jQuery.'));
}
......@@ -1308,7 +1321,7 @@ class JavaScriptTestCase extends DrupalWebTestCase {
function testAlter() {
// Add both tableselect.js and simpletest.js, with a larger weight on SimpleTest.
drupal_add_js('misc/tableselect.js');
drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', array('weight' => JS_THEME));
drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', array('weight' => 9999));
// Render the JavaScript, testing if simpletest.js was altered to be before
// tableselect.js. See simpletest_js_alter() to see where this alteration
......
......@@ -1066,7 +1066,7 @@ function system_library() {
'website' => 'http://jquery.com',
'version' => '1.4.2',
'js' => array(
'misc/jquery.js' => array('weight' => JS_LIBRARY - 20, 'preprocess' => TRUE),
'misc/jquery.js' => array('group' => JS_LIBRARY, 'weight' => -20),
),
);
......@@ -1076,7 +1076,7 @@ function system_library() {
'website' => 'http://plugins.jquery.com/project/once',
'version' => '1.2',
'js' => array(
'misc/jquery.once.js' => array('weight' => JS_LIBRARY - 19, 'preprocess' => TRUE),
'misc/jquery.once.js' => array('group' => JS_LIBRARY, 'weight' => -19),
),
);
......@@ -1142,7 +1142,7 @@ function system_library() {
'website' => 'http://jqueryui.com',
'version' => '1.8',
'js' => array(
'misc/ui/jquery.ui.core.min.js' => array('weight' => JS_LIBRARY - 11),
'misc/ui/jquery.ui.core.min.js' => array('group' => JS_LIBRARY, 'weight' => -11),
),
'css' => array(
'misc/ui/jquery.ui.core.css' => array(),
......@@ -1359,7 +1359,7 @@ function system_library() {
'website' => 'http://docs.jquery.com/UI/Widget',
'version' => '1.8',
'js' => array(
'misc/ui/jquery.ui.widget.min.js' => array('weight' => JS_LIBRARY - 10),
'misc/ui/jquery.ui.widget.min.js' => array('group' => JS_LIBRARY, 'weight' => -10),
),
'dependencies' => array(
array('system', 'ui'),
......@@ -1370,7 +1370,7 @@ function system_library() {
'website' => 'http://jqueryui.com/demos/effect/',
'version' => '1.8',
'js' => array(
'misc/ui/jquery.effects.core.min.js' => array('weight' => JS_LIBRARY - 9),
'misc/ui/jquery.effects.core.min.js' => array('group' => JS_LIBRARY, 'weight' => -9),
),
);
$libraries['effects.blind'] = array(
......@@ -1819,14 +1819,15 @@ function _system_filetransfer_backend_form_common() {
*/
function system_init() {
$path = drupal_get_path('module', 'system');
// Add the CSS for this module.
drupal_add_css($path . '/system.base.css', array('weight' => CSS_SYSTEM, 'preprocess' => TRUE));
// Add the CSS for this module. These aren't in system.info, because they
// need to be in the CSS_SYSTEM group rather than the CSS_DEFAULT group.
drupal_add_css($path . '/system.base.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit' || arg(2) == 'delete'))) {
drupal_add_css($path . '/system.admin.css', array('weight' => CSS_SYSTEM));
drupal_add_css($path . '/system.admin.css', array('group' => CSS_SYSTEM));
}
drupal_add_css($path . '/system.menus.css', array('weight' => CSS_SYSTEM, 'preprocess' => TRUE));
drupal_add_css($path . '/system.messages.css', array('weight' => CSS_SYSTEM, 'preprocess' => TRUE));
drupal_add_css($path . '/system.theme.css', array('weight' => CSS_SYSTEM, 'preprocess' => TRUE));
drupal_add_css($path . '/system.menus.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
drupal_add_css($path . '/system.messages.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
drupal_add_css($path . '/system.theme.css', array('group' => CSS_SYSTEM, 'every_page' => TRUE));
// Ignore slave database servers for this request.
//
......@@ -1862,13 +1863,13 @@ function system_add_module_assets() {
if (!empty($info['stylesheets'])) {
foreach ($info['stylesheets'] as $media => $stylesheets) {
foreach ($stylesheets as $stylesheet) {
drupal_add_css($stylesheet, array('media' => $media, 'preprocess' => TRUE));
drupal_add_css($stylesheet, array('every_page' => TRUE, 'media' => $media));
}
}
}
if (!empty($info['scripts'])) {
foreach ($info['scripts'] as $script) {
drupal_add_js($script, array('preprocess' => TRUE));
drupal_add_js($script, array('every_page' => TRUE));
}
}
}
......
......@@ -188,7 +188,7 @@ function toolbar_view() {
'#attached'=> array(
'js' => array(
$module_path . '/toolbar.js',
array('data' => 'misc/jquery.cookie.js', 'weight' => JS_LIBRARY + 2),
array('data' => 'misc/jquery.cookie.js', 'group' => JS_LIBRARY, 'weight' => 2),
array(
'data' => array('tableHeaderOffset' => 'Drupal.toolbar.height'),
'type' => 'setting'
......
......@@ -23,8 +23,8 @@ function bartik_preprocess_html(&$variables) {
}
// Add conditional stylesheets for IE
drupal_add_css(path_to_theme() . '/css/ie.css', array('weight' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE)));
drupal_add_css(path_to_theme() . '/css/ie6.css', array('weight' => CSS_THEME, 'browsers' => array('IE' => 'IE 6', '!IE' => FALSE)));
drupal_add_css(path_to_theme() . '/css/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
drupal_add_css(path_to_theme() . '/css/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'IE 6', '!IE' => FALSE), 'preprocess' => FALSE));
}
/**
......
......@@ -42,7 +42,7 @@ function garland_preprocess_html(&$vars) {
$vars['classes_array'][] = 'fluid-width';
}
// Add conditional CSS for IE6.
drupal_add_css(path_to_theme() . '/fix-ie.css', array('weight' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE)));
drupal_add_css(path_to_theme() . '/fix-ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
}
/**
......
......@@ -18,9 +18,9 @@ function seven_preprocess_maintenance_page(&$vars) {
*/
function seven_preprocess_html(&$vars) {
// Add conditional CSS for IE8 and below.
drupal_add_css(path_to_theme() . '/ie.css', array('weight' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE)));
drupal_add_css(path_to_theme() . '/ie.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'preprocess' => FALSE));
// Add conditional CSS for IE6.
drupal_add_css(path_to_theme() . '/ie6.css', array('weight' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE)));
drupal_add_css(path_to_theme() . '/ie6.css', array('group' => CSS_THEME, 'browsers' => array('IE' => 'lt IE 7', '!IE' => FALSE), 'preprocess' => FALSE));
}
/**
......
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