diff --git a/core/includes/common.inc b/core/includes/common.inc index 4dda268..14880ba 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -3797,6 +3797,30 @@ function drupal_add_js($data = NULL, $options = NULL) { if (isset($data)) { switch ($options['type']) { case 'setting': + // If the setting array doesn't exists already, add defaults values. + if (!isset($javascript['settings'])) { + $javascript['settings'] = array( + 'type' => 'setting', + 'scope' => 'header', + 'group' => JS_SETTING, + 'every_page' => TRUE, + 'weight' => 0, + 'browsers' => array(), + ); + // url() generates the script and prefix using hook_url_outbound_alter(). + // Instead of running the hook_url_outbound_alter() again here, extract + // them from url(). + // @todo Make this less hacky: http://drupal.org/node/1547376. + $scriptPath = $GLOBALS['script_path']; + $pathPrefix = ''; + url('', array('script' => &$scriptPath, 'prefix' => &$pathPrefix)); + $javascript['settings']['data'][] = array( + 'basePath' => base_path(), + 'scriptPath' => $scriptPath, + 'pathPrefix' => $pathPrefix, + 'currentPath' => current_path(), + ); + } // All JavaScript settings are placed in the header of the page with // the library weight so that inline scripts appear afterwards. $javascript['settings']['data'][] = $data; diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 1289b08..c151ef0 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -1228,33 +1228,10 @@ function system_library_info() { ), ); - // url() generates the script and prefix using hook_url_outbound_alter(). - // Instead of running the hook_url_outbound_alter() again here, extract - // them from url(). - // @todo Make this less hacky: http://drupal.org/node/1547376. - $scriptPath = $GLOBALS['script_path']; - $pathPrefix = ''; - url('', array('script' => &$scriptPath, 'prefix' => &$pathPrefix)); // Drupal settings. $libraries['drupal.settings'] = array( 'title' => 'Drupal Settings', 'version' => VERSION, - 'js' => array( - array( - 'data' => array( - 'basePath' => base_path(), - 'scriptPath' => $scriptPath, - 'pathPrefix' => $pathPrefix, - 'currentPath' => current_path(), - ), - 'type' => 'setting', - 'scope' => 'header', - 'group' => JS_SETTING, - 'every_page' => TRUE, - 'weight' => 0, - 'browsers' => array(), - ), - ), 'dependencies' => array( array('system', 'jquery'), array('system', 'drupal'), @@ -2011,26 +1988,6 @@ function system_library_info() { } /** - * Implements hook_js_alter(). - */ -function system_js_alter(&$javascript) { - // 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', - 'scope' => 'header', - 'group' => JS_SETTING, - 'every_page' => TRUE, - 'weight' => 0, - 'browsers' => array(), - ); - } -} - -/** * Implements hook_stream_wrappers(). */ function system_stream_wrappers() {