Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.852 diff -u -r1.852 common.inc --- includes/common.inc 20 Jan 2009 03:18:40 -0000 1.852 +++ includes/common.inc 22 Jan 2009 03:44:48 -0000 @@ -1984,13 +1984,17 @@ * file added to the list, if exists in the same directory. This CSS file * should contain overrides for properties which should be reversed or * otherwise different in a right-to-left display. + * + * Note that if $options or $options['type'] is 'reset', then $path will be + * ignored. * @param $options * (optional) A string defining the type of CSS that is being added in the * $path parameter ('module' or 'theme'), or an associative array of * additional options, with the following keys: * - 'type' - * The type of stylesheet that is being added. Types are: module or - * theme. Defaults to 'module'. + * The type of stylesheet that is being added. Types are: 'module', + * 'theme', or 'reset'. Defaults to 'module'. If the type is 'reset', + * then the CSS will be reset, ignoring $path and other $options. * - 'media' * The media type for the stylesheet, e.g., all, print, screen. Defaults * to 'all'. @@ -2017,32 +2021,31 @@ * * Typical candidates for caching are for example styles for nodes across * the site, or used in the theme. - * @param $reset - * (optional) Resets the currently loaded cascading stylesheets. * @return * An array of CSS files. */ -function drupal_add_css($path = NULL, $options = NULL, $reset = FALSE) { +function drupal_add_css($path = NULL, $options = NULL) { static $css = array(); global $language; + // Construct the options, taking the defaults into consideration. + if (isset($options)) { + if (!is_array($options)) { + $options = array('type' => $options); + } + } + else { + $options = array(); + } + // Request made to reset the CSS added so far. - if ($reset) { - $css = array(); + if (isset($options['type']) && $options['type'] == 'reset') { + return $css = array(); } // Create an array of CSS files for each media type first, since each type needs to be served // to the browser differently. if (isset($path)) { - // Construct the options, taking the defaults into consideration. - if (isset($options)) { - if (!is_array($options)) { - $options = array('type' => $options); - } - } - else { - $options = array(); - } $options += array( 'type' => 'module', 'media' => 'all', @@ -2344,6 +2347,8 @@ * array is directly placed in Drupal.settings. All modules should wrap * their actual configuration settings in another variable to prevent * the pollution of the Drupal.settings namespace. + * - 'reset': Anything in $data will be ignored and the JavaScript added so + * far will be reset. * @param $options * (optional) A string defining the type of JavaScript that is being added * in the $data parameter ('file'/'setting'/'inline'), or an array which @@ -2351,7 +2356,10 @@ * always pass the string 'setting' only. * - type * The type of JavaScript that is to be added to the page. Allowed - * values are 'file', 'inline' or 'setting'. Defaults to 'file'. + * values are 'file', 'inline', 'setting', or 'reset'. Defaults to + * 'file'. Note that if type is 'reset', then $data and all other + * $options will be ignored and the JavaScript added so far will be + * reset. * - scope * The location in which you want to place the script. Possible values * are 'header' or 'footer'. If your theme implements different regions, @@ -2384,13 +2392,11 @@ * - preprocess * Aggregate the JavaScript if the JavaScript optimization setting has * been toggled in admin/settings/performance. Defaults to TRUE. - * @param $reset - * (optional) Resets the currently loaded JavaScript. * @return * The contructed array of JavaScript files. * @see drupal_get_js() */ -function drupal_add_js($data = NULL, $options = NULL, $reset = FALSE) { +function drupal_add_js($data = NULL, $options = NULL) { static $javascript = array(); // Construct the options, taking the defaults into consideration. @@ -2404,14 +2410,14 @@ } $options += drupal_js_defaults($data); + if ($options['type'] == 'reset') { + // Request made to reset the JavaScript added so far + return $javascript = array(); + } + // Preprocess can only be set if caching is enabled. $options['preprocess'] = $options['cache'] ? $options['preprocess'] : FALSE; - // Request made to reset the JavaScript added so far. - if ($reset) { - $javascript = array(); - } - if (isset($data)) { // Add jquery.js and drupal.js, as well as the basePath setting, the // first time a Javascript file is added. Index: modules/simpletest/tests/common.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v retrieving revision 1.22 diff -u -r1.22 common.test --- modules/simpletest/tests/common.test 21 Jan 2009 14:22:32 -0000 1.22 +++ modules/simpletest/tests/common.test 22 Jan 2009 03:44:52 -0000 @@ -170,7 +170,7 @@ function setUp() { parent::setUp(); // Reset drupal_add_css() before each test. - drupal_add_css(NULL, NULL, TRUE); + drupal_add_css(NULL, 'reset'); } /** @@ -190,6 +190,14 @@ } /** + * Makes sure that reseting the CSS empties the cache. + */ + function testReset() { + drupal_add_css(NULL, 'reset'); + $this->assertEqual(array(), drupal_add_css(), t('Resetting the CSS empties the cache.')); + } + + /** * Tests rendering the stylesheets. */ function testRenderFile() { @@ -352,7 +360,7 @@ variable_set('preprocess_js', 0); // Reset drupal_add_js() before each test. - drupal_add_js(NULL, NULL, TRUE); + drupal_add_js(NULL, 'reset'); } function tearDown() { @@ -404,7 +412,7 @@ */ function testReset() { drupal_add_js('misc/collapse.js'); - drupal_add_js(NULL, NULL, TRUE); + drupal_add_js(NULL, 'reset'); $this->assertEqual(array(), drupal_add_js(), t('Resetting the JavaScript correctly empties the cache.')); }