summaryrefslogtreecommitdiff
path: root/modules/comment/comment.js
blob: bdd1c3b952a799fc034e06d0876e5fba7ecdb9f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// $Id$
(function ($) {

Drupal.behaviors.comment = {
  attach: function (context, settings) {
    $.each(['name', 'homepage', 'mail'], function () {
      var cookie = Drupal.comment.getCookie('comment_info_' + this);
      if (cookie) {
        $('#comment-form input[name=' + this + ']:not(.comment-processed)', context)
          .val(cookie)
          .addClass('comment-processed');
      }
    });
  }
};

Drupal.comment = {};

Drupal.comment.getCookie = function (name) {
  var search = name + '=';
  var returnValue = '';

  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      var end = document.cookie.indexOf(';', offset);
      if (end == -1) {
        end = document.cookie.length;
      }
      returnValue = decodeURIComponent(document.cookie.substring(offset, end).replace(/\+/g, '%20'));
    }
  }

  return returnValue;
};

})(jQuery);