Index: misc/drupal.js =================================================================== RCS file: /cvs/drupal/drupal/misc/drupal.js,v retrieving revision 1.58 diff -u -p -r1.58 drupal.js --- misc/drupal.js 31 Aug 2009 05:51:07 -0000 1.58 +++ misc/drupal.js 10 Oct 2009 19:36:15 -0000 @@ -109,6 +109,21 @@ Drupal.checkPlain = function (str) { }; /** + * Prefill form fields with information from the visitor cookie informaiton. + */ +Drupal.addVisitorCookieInfo = function (form_id) { + $('form#' + form_id).once('addVisitorCookieInfo', function () { + $.each(['name', 'mail', 'homepage'], function () { + var element = $('form#' + form_id + ' [name=' + this + ']'); + var cookie = $.cookie('Drupal.visitor.' + this); + if (element.length && cookie) { + element.val(cookie); + } + }); + }); +} + +/** * Translate strings to the page language or a given language. * * See the documentation of the server-side t() function for further details. Index: modules/comment/comment.js =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.js,v retrieving revision 1.13 diff -u -p -r1.13 comment.js --- modules/comment/comment.js 9 Oct 2009 15:39:12 -0000 1.13 +++ modules/comment/comment.js 10 Oct 2009 19:36:16 -0000 @@ -3,12 +3,7 @@ Drupal.behaviors.comment = { attach: function (context, settings) { - $.each(['name', 'homepage', 'mail'], function () { - var cookie = $.cookie('Drupal.visitor.' + this); - if (cookie) { - $('#comment-form input[name=' + this + ']', context).once('comment').val(cookie); - } - }); + Drupal.addVisitorCookieInfo('comment-form'); } }; Index: modules/contact/contact.js =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.js,v retrieving revision 1.1 diff -u -p -r1.1 contact.js --- modules/contact/contact.js 9 Oct 2009 15:39:12 -0000 1.1 +++ modules/contact/contact.js 10 Oct 2009 19:36:16 -0000 @@ -2,13 +2,8 @@ (function ($) { Drupal.behaviors.contact = { - attach: function(context) { - $.each(['name', 'mail'], function () { - var cookie = $.cookie('Drupal.user.' + this); - if (cookie) { - $('#contact-site-form input[name=' + this + ']', context).once('comment').val(cookie); - } - }); + attach: function (context, settings) { + Drupal.addVisitorCookieInfo('contact-site-form'); } }; Index: modules/user/user.js =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.js,v retrieving revision 1.18 diff -u -p -r1.18 user.js --- modules/user/user.js 21 Sep 2009 08:52:41 -0000 1.18 +++ modules/user/user.js 10 Oct 2009 19:36:16 -0000 @@ -188,4 +188,10 @@ Drupal.behaviors.userSettings = { } }; +Drupal.behaviors.userRegistration = { + attach: function (context, settings) { + Drupal.addVisitorCookieInfo('user-register'); + } +}; + })(jQuery); Index: modules/user/user.module =================================================================== RCS file: /cvs/drupal/drupal/modules/user/user.module,v retrieving revision 1.1060 diff -u -p -r1.1060 user.module --- modules/user/user.module 10 Oct 2009 16:48:39 -0000 1.1060 +++ modules/user/user.module 10 Oct 2009 19:36:17 -0000 @@ -3080,6 +3080,9 @@ function user_register_form($form, &$for $form['account']['#type'] = 'markup'; } + $form['#attached']['library'][] = array('system', 'cookie'); + $form['#attached']['js'][] = drupal_get_path('module', 'user') . '/user.js'; + $form['submit'] = array( '#type' => 'submit', '#value' => t('Create new account'),