Index: misc/form.js =================================================================== RCS file: /cvs/drupal/drupal/misc/form.js,v retrieving revision 1.11 diff -u -p -r1.11 form.js --- misc/form.js 31 Aug 2009 05:51:07 -0000 1.11 +++ misc/form.js 16 Oct 2009 06:13:20 -0000 @@ -68,7 +68,6 @@ Drupal.behaviors.multiselectSelector = { } }; - /** * Automatically display the guidelines of the selected text format. */ @@ -86,4 +85,22 @@ Drupal.behaviors.filterGuidelines = { } }; +/** + * Prepopulate form fields with information from the visitor cookie. + */ +Drupal.behaviors.formPrepopulateFromCookie = { + attach: function (context, settings) { + $('form.form-prepopulate-from-cookie').once('form-prepopulate-from-cookie', function () { + var formContext = this; + $.each(['name', 'mail', 'homepage'], function () { + var $element = $('[name=' + this + ']', formContext); + var cookie = $.cookie('Drupal.visitor.' + this); + if ($element.length && cookie) { + $element.val(cookie); + } + }); + }); + } +}; + })(jQuery); Index: modules/comment/comment.js =================================================================== RCS file: modules/comment/comment.js diff -N modules/comment/comment.js --- modules/comment/comment.js 9 Oct 2009 15:39:12 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,15 +0,0 @@ -// $Id: comment.js,v 1.13 2009/10/09 15:39:12 dries Exp $ -(function ($) { - -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); - } - }); - } -}; - -})(jQuery); Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.789 diff -u -p -r1.789 comment.module --- modules/comment/comment.module 16 Oct 2009 03:40:40 -0000 1.789 +++ modules/comment/comment.module 16 Oct 2009 06:13:20 -0000 @@ -1650,7 +1650,7 @@ function comment_form($form, &$form_stat if (!$user->uid && variable_get('comment_anonymous_' . $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) != COMMENT_ANONYMOUS_MAYNOT_CONTACT) { $form['#attached']['library'][] = array('system', 'cookie'); - $form['#attached']['js'][] = drupal_get_path('module', 'comment') . '/comment.js'; + $form['#attributes']['class'][] = 'form-prepopulate-from-cookie'; } $comment = (array) $comment; Index: modules/contact/contact.js =================================================================== RCS file: modules/contact/contact.js diff -N modules/contact/contact.js --- modules/contact/contact.js 11 Oct 2009 18:34:10 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,16 +0,0 @@ -// $Id: contact.js,v 1.2 2009/10/11 18:34:10 dries Exp $ -(function ($) { - -Drupal.behaviors.contact = { - attach: function(context) { - $.each(['name', 'mail'], function () { - var cookie = $.cookie('Drupal.visitor.' + this); - if (cookie) { - $('#contact-site-form input[name=' + this + ']', context).once('comment').val(cookie); - $('#contact-personal-form input[name=' + this + ']', context).once('comment').val(cookie); - } - }); - } -}; - -})(jQuery); Index: modules/contact/contact.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/contact/contact.pages.inc,v retrieving revision 1.32 diff -u -p -r1.32 contact.pages.inc --- modules/contact/contact.pages.inc 11 Oct 2009 18:34:10 -0000 1.32 +++ modules/contact/contact.pages.inc 16 Oct 2009 06:13:20 -0000 @@ -50,7 +50,7 @@ function contact_site_form($form, &$form if (!$user->uid) { $form['#attached']['library'][] = array('system', 'cookie'); - $form['#attached']['js'][] = drupal_get_path('module', 'contact') . '/contact.js'; + $form['#attributes']['class'][] = 'form-prepopulate-from-cookie'; } $form['#token'] = $user->uid ? $user->name . $user->mail : ''; @@ -178,7 +178,7 @@ function contact_personal_form($form, &$ if (!$user->uid) { $form['#attached']['library'][] = array('system', 'cookie'); - $form['#attached']['js'][] = drupal_get_path('module', 'contact') . '/contact.js'; + $form['#attributes']['class'][] = 'form-prepopulate-from-cookie'; } $form['#token'] = $user->uid ? $user->name . $user->mail : '';