diff --git a/includes/common.inc b/includes/common.inc index f6171cf..87912e7 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -4155,7 +4155,18 @@ function drupal_add_js($data = NULL, $options = NULL) { case 'setting': // 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; + if ($options['once']) { + foreach ($javascript['settings']['data'] as $setting) { + foreach (array_keys($setting) as $key) { + if (isset($data[$key])) { + unset($data[$key]); + } + } + } + } + if (!empty($data)) { + $javascript['settings']['data'][] = $data; + } break; case 'inline': @@ -4192,6 +4203,7 @@ function drupal_js_defaults($data = NULL) { 'preprocess' => TRUE, 'version' => NULL, 'data' => $data, + 'once' => FALSE, ); } diff --git a/modules/user/user.module b/modules/user/user.module index c1c7ec2..f1f772e 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -3577,11 +3577,7 @@ function user_form_process_password_confirm($element) { $element['#attached']['js'][] = drupal_get_path('module', 'user') . '/user.js'; // Ensure settings are only added once per page. - static $already_added = FALSE; - if (!$already_added) { - $already_added = TRUE; - $element['#attached']['js'][] = array('data' => $js_settings, 'type' => 'setting'); - } + $element['#attached']['js'][] = array('data' => $js_settings, 'type' => 'setting', 'once' => TRUE); return $element; }