diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/color/color.module | 2 | ||||
-rw-r--r-- | modules/locale/locale.module | 27 | ||||
-rw-r--r-- | modules/node/node.admin.inc | 2 | ||||
-rw-r--r-- | modules/simpletest/simpletest.module | 5 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 90 | ||||
-rw-r--r-- | modules/system/system.admin.inc | 4 | ||||
-rw-r--r-- | modules/user/user.admin.inc | 2 | ||||
-rw-r--r-- | modules/user/user.module | 2 |
8 files changed, 84 insertions, 50 deletions
diff --git a/modules/color/color.module b/modules/color/color.module index 51c894e51..3eb8cca24 100644 --- a/modules/color/color.module +++ b/modules/color/color.module @@ -154,7 +154,7 @@ function color_scheme_form(&$form_state, $theme) { // Add Farbtastic color picker. drupal_add_css('misc/farbtastic/farbtastic.css', array('preprocess' => FALSE)); - drupal_add_js('misc/farbtastic/farbtastic.js'); + drupal_add_js('misc/farbtastic/farbtastic.js', array('weight' => JS_LIBRARY)); // Add custom CSS and JS. drupal_add_css($base . '/color.css', array('preprocess' => FALSE)); diff --git a/modules/locale/locale.module b/modules/locale/locale.module index b7d862708..15629d3b8 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -522,20 +522,17 @@ function locale_update_js_files() { $javascript = drupal_add_js(); $files = $new_files = FALSE; - foreach ($javascript as $scope) { - foreach ($scope as $type => $data) { - if ($type != 'setting' && $type != 'inline') { - foreach ($data as $filepath => $info) { - $files = TRUE; - if (!in_array($filepath, $parsed)) { - // Don't parse our own translations files. - if (substr($filepath, 0, strlen($dir)) != $dir) { - locale_inc_callback('_locale_parse_js_file', $filepath); - watchdog('locale', 'Parsed JavaScript file %file.', array('%file' => $filepath)); - $parsed[] = $filepath; - $new_files = TRUE; - } - } + foreach ($javascript as $item) { + if ($item['type'] == 'file') { + $files = TRUE; + $filepath = $item['data']; + if (!in_array($filepath, $parsed)) { + // Don't parse our own translations files. + if (substr($filepath, 0, strlen($dir)) != $dir) { + locale_inc_callback('_locale_parse_js_file', $filepath); + watchdog('locale', 'Parsed JavaScript file %file.', array('%file' => $filepath)); + $parsed[] = $filepath; + $new_files = TRUE; } } } @@ -566,7 +563,7 @@ function locale_update_js_files() { // Add the translation JavaScript file to the page. if ($files && !empty($language->javascript)) { - drupal_add_js($dir . '/' . $language->language . '_' . $language->javascript . '.js', 'core'); + drupal_add_js($dir . '/' . $language->language . '_' . $language->javascript . '.js'); } } diff --git a/modules/node/node.admin.inc b/modules/node/node.admin.inc index 7076e5182..02606abd8 100644 --- a/modules/node/node.admin.inc +++ b/modules/node/node.admin.inc @@ -250,7 +250,7 @@ function node_filter_form() { $form['filters']['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset')); } - drupal_add_js('misc/form.js', 'core'); + drupal_add_js('misc/form.js'); return $form; } diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module index 5275afb67..71225ff5c 100644 --- a/modules/simpletest/simpletest.module +++ b/modules/simpletest/simpletest.module @@ -210,7 +210,10 @@ function simpletest_test_form() { function theme_simpletest_test_table($table) { drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css'); - drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', 'module'); + + // Since SimpleTest is a special use case for the table select, stick the + // SimpleTest JavaScript above the table select. + drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', array('weight' => JS_DEFAULT - 1)); // Create header for test selection table. $header = array( diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index b7ebac4ff..c2eaad4d3 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -307,6 +307,11 @@ class DrupalSetContentTestCase extends DrupalWebTestCase { */ class JavaScriptTestCase extends DrupalWebTestCase { /** + * Store configured value for JavaScript preprocessing. + */ + var $preprocess_js = NULL; + + /** * Implementation of getInfo(). */ function getInfo() { @@ -316,45 +321,58 @@ class JavaScriptTestCase extends DrupalWebTestCase { 'group' => t('System') ); } - + /** * Implementation of setUp(). */ function setUp() { - parent::setUp(); + // Enable locale in test environment. + parent::setUp('locale'); + + // Disable preprocessing + $this->preprocess_js = variable_get('preprocess_js', 0); + variable_set('preprocess_js', 0); + // Reset drupal_add_js() before each test. drupal_add_js(NULL, NULL, TRUE); } - + + /** + * Implementation of tearDown(). + */ + function tearDown() { + // Restore configured value for JavaScript preprocessing. + variable_set('preprocess_js', $this->preprocess_js); + parent::tearDown(); + } + /** * Test default JavaScript is empty. */ function testDefault() { $this->assertEqual(array(), drupal_add_js(), t('Default JavaScript is empty.')); } - + /** * Test adding a JavaScript file. */ function testAddFile() { - drupal_add_js('misc/collapse.js'); - $javascript = drupal_add_js(); - $this->assertTrue(array_key_exists('misc/jquery.js', $javascript['header']['core']), t('jQuery is added when a file is added.')); - $this->assertTrue(array_key_exists('misc/drupal.js', $javascript['header']['core']), t('Drupal.js is added when file is added.')); - $this->assertTrue(array_key_exists('misc/collapse.js', $javascript['header']['module']), t('JavaScript files are correctly added.')); - $this->assertEqual(base_path(), $javascript['header']['setting'][0]['basePath'], t('Base path JavaScript setting is correctly set.')); + $javascript = drupal_add_js('misc/collapse.js'); + $this->assertTrue(array_key_exists('misc/jquery.js', $javascript), t('jQuery is added when a file is added.')); + $this->assertTrue(array_key_exists('misc/drupal.js', $javascript), t('Drupal.js is added when file is added.')); + $this->assertTrue(array_key_exists('misc/collapse.js', $javascript), t('JavaScript files are correctly added.')); + $this->assertEqual(base_path(), $javascript['settings']['data'][0]['basePath'], t('Base path JavaScript setting is correctly set.')); } - + /** * Test adding settings. */ function testAddSetting() { - drupal_add_js(array('drupal' => 'rocks', 'dries' => 280342800), 'setting'); - $javascript = drupal_add_js(); - $this->assertEqual(280342800, $javascript['header']['setting'][1]['dries'], t('JavaScript setting is set correctly.')); - $this->assertEqual('rocks', $javascript['header']['setting'][1]['drupal'], t('The other JavaScript setting is set correctly.')); + $javascript = drupal_add_js(array('drupal' => 'rocks', 'dries' => 280342800), 'setting'); + $this->assertEqual(280342800, $javascript['settings']['data'][1]['dries'], t('JavaScript setting is set correctly.')); + $this->assertEqual('rocks', $javascript['settings']['data'][1]['drupal'], t('The other JavaScript setting is set correctly.')); } - + /** * Test drupal_get_js() for JavaScript settings. */ @@ -365,27 +383,27 @@ class JavaScriptTestCase extends DrupalWebTestCase { $this->assertTrue(strpos($javascript, 'testSetting') > 0, t('Rendered JavaScript header returns custom setting.')); $this->assertTrue(strpos($javascript, 'misc/jquery.js') > 0, t('Rendered JavaScript header includes jQuery.')); } - + /** * Test to see if resetting the JavaScript empties the cache. */ function testReset() { drupal_add_js('misc/collapse.js'); - drupal_add_js(NULL, NULL, TRUE); + drupal_add_js(NULL, NULL, TRUE); $this->assertEqual(array(), drupal_add_js(), t('Resetting the JavaScript correctly empties the cache.')); } - + /** * Test adding inline scripts. */ function testAddInline() { $inline = '$(document).ready(function(){});'; - drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer')); - $javascript = drupal_add_js(); - $this->assertTrue(array_key_exists('misc/jquery.js', $javascript['header']['core']), t('jQuery is added when inline scripts are added.')); - $this->assertEqual($inline, $javascript['footer']['inline'][0]['code'], t('Inline JavaScript is correctly added to the footer.')); + $javascript = drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer')); + $this->assertTrue(array_key_exists('misc/jquery.js', $javascript), t('jQuery is added when inline scripts are added.')); + $data = end($javascript); + $this->assertEqual($inline, $data['data'], t('Inline JavaScript is correctly added to the footer.')); } - + /** * Test drupal_get_js() with a footer scope. */ @@ -395,14 +413,30 @@ class JavaScriptTestCase extends DrupalWebTestCase { $javascript = drupal_get_js('footer'); $this->assertTrue(strpos($javascript, $inline) > 0, t('Rendered JavaScript footer returns the inline code.')); } - + /** * Test drupal_add_js() sets preproccess to false when cache is set to false. */ function testNoCache() { - drupal_add_js('misc/collapse.js', array('cache' => FALSE)); - $javascript = drupal_add_js(); - $this->assertTrue(!$javascript['header']['module']['misc/collapse.js']['preprocess'], t('Setting cache to FALSE sets proprocess to FALSE when adding JavaScript.')); + $javascript = drupal_add_js('misc/collapse.js', array('cache' => FALSE)); + $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 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.')); + } + + /** + * Test rendering the JavaScript with a file's weight above jQuery's. + */ + function testRenderDifferentWeight() { + drupal_add_js('misc/collapse.js', array('weight' => JS_LIBRARY - 10)); + $javascript = drupal_get_js(); + $this->assertTrue(strpos($javascript, 'misc/collapse.js') < strpos($javascript, 'misc/jquery.js'), t('Rendering a JavaScript file above jQuery.')); } } diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 48c901293..03db7b683 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -1528,7 +1528,7 @@ function system_rss_feeds_settings() { * @see system_date_time_settings_submit() */ function system_date_time_settings() { - drupal_add_js(drupal_get_path('module', 'system') . '/system.js', 'module'); + drupal_add_js(drupal_get_path('module', 'system') . '/system.js'); drupal_add_js(array('dateTime' => array('lookup' => url('admin/settings/date-time/lookup'))), 'setting'); // Date settings: @@ -1736,7 +1736,7 @@ function system_clean_url_settings() { if (!variable_get('clean_url', 0)) { if (strpos(request_uri(), '?q=') !== FALSE) { - drupal_add_js(drupal_get_path('module', 'system') . '/system.js', 'module'); + drupal_add_js(drupal_get_path('module', 'system') . '/system.js'); $form['clean_url']['#description'] .= ' <span>' . t('Before enabling clean URLs, you must perform a test to determine if your server is properly configured. If you are able to see this page again after clicking the "Run the clean URL test" link, the test has succeeded and the radio buttons above will be available. If instead you are directed to a "Page not found" error, you will need to change the configuration of your server. The <a href="@handbook">handbook page on Clean URLs</a> has additional troubleshooting information.', array('@handbook' => 'http://drupal.org/node/15365')) . '</span>'; diff --git a/modules/user/user.admin.inc b/modules/user/user.admin.inc index 33fea1827..c58cbb648 100644 --- a/modules/user/user.admin.inc +++ b/modules/user/user.admin.inc @@ -83,7 +83,7 @@ function user_filter_form() { ); } - drupal_add_js('misc/form.js', 'core'); + drupal_add_js('misc/form.js'); return $form; } diff --git a/modules/user/user.module b/modules/user/user.module index 9a42cfc21..84ba50441 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -2160,7 +2160,7 @@ function _user_password_dynamic_validation() { global $user; // Only need to do once per page. if (!$complete) { - drupal_add_js(drupal_get_path('module', 'user') . '/user.js', 'module'); + drupal_add_js(drupal_get_path('module', 'user') . '/user.js'); drupal_add_js(array( 'password' => array( |