| 1 |
// $Id: comment_info.js,v 1.1.2.1 2007/02/23 20:20:50 mfer Exp $ |
// $Id: comment_info.js,v 1.1.2.2 2007/03/20 23:33:38 mfer Exp $ |
| 2 |
|
|
| 3 |
Drupal.comment_info = {}; |
Drupal.comment_info = {}; |
| 4 |
|
|
| 5 |
Drupal.comment_info.cookie = function(name, value, options) { |
Drupal.comment_info.autoAttach = function () { |
| 6 |
if (typeof value != 'undefined') { // name and value given, set cookie |
var parts = new Array("name", "homepage", "mail"); |
| 7 |
options = options || {}; |
var cookie = ''; |
| 8 |
var expires = ''; |
for (i=0;i<3;i++) { |
| 9 |
if (options.expires && (typeof options.expires == 'number' || options.expires.toGMTString)) { |
cookie = Drupal.comment_info.getCookie('comment_info_' + parts[i]); |
| 10 |
var date; |
if (cookie != '') { |
| 11 |
if (typeof options.expires == 'number') { |
$("#comment-form input[@name=" + parts[i] + "]:not(.comment-processed)") |
| 12 |
date = new Date(); |
.val(cookie) |
| 13 |
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); |
.addClass('comment-processed'); |
|
} else { |
|
|
date = options.expires; |
|
|
} |
|
|
expires = '; expires=' + date.toGMTString(); // use expires attribute, max-age is not supported by IE |
|
|
} |
|
|
var path = options.path ? '; path=' + options.path : ''; |
|
|
var domain = options.domain ? '; domain=' + options.domain : ''; |
|
|
var secure = options.secure ? '; secure' : ''; |
|
|
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); |
|
|
} else { // only name given, get cookie |
|
|
var cookieValue = null; |
|
|
if (document.cookie && document.cookie != '') { |
|
|
var cookies = document.cookie.split(';'); |
|
|
for (var i = 0; i < cookies.length; i++) { |
|
|
var cookie = jQuery.trim(cookies[i]); |
|
|
// Does this cookie string begin with the name we want? |
|
|
if (cookie.substring(0, name.length + 1) == (name + '=')) { |
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); |
|
|
break; |
|
|
} |
|
|
} |
|
| 14 |
} |
} |
|
return cookieValue; |
|
| 15 |
} |
} |
| 16 |
}; |
}; |
| 17 |
|
|
| 18 |
Drupal.comment_info.autoAttach = function() { |
Drupal.comment_info.getCookie = function(name) { |
| 19 |
var comment_info_x = false; |
var search = name + '='; |
| 20 |
$("#comment-form input[@name=optin]").show(); |
var returnValue = ''; |
| 21 |
var comment_info_option = Drupal.comment_info.cookie('comment_info_option'); |
|
| 22 |
if (comment_info_option=='true') { |
if (document.cookie.length > 0) { |
| 23 |
$("#comment-form input[@name=name]").val(Drupal.comment_info.cookie('comment_info_name')); |
offset = document.cookie.indexOf(search); |
| 24 |
$("#comment-form input[@name=mail]").val(Drupal.comment_info.cookie('comment_info_email')); |
if (offset != -1) { |
| 25 |
$("#comment-form input[@name=homepage]").val(Drupal.comment_info.cookie('comment_info_homepage')); |
offset += search.length; |
| 26 |
$("#comment-form input[@name=optin]").each( function() { |
var end = document.cookie.indexOf(';', offset); |
| 27 |
this.checked = true; |
if (end == -1) { |
| 28 |
}); |
end = document.cookie.length; |
|
} |
|
|
$("form#comment-form input[@type=submit]").each( function() { |
|
|
$(this).click(function() { |
|
|
$("#comment-form input[@name=optin]").each( function() { |
|
|
comment_info_x = this.checked; |
|
|
}); |
|
|
if(comment_info_x) { |
|
|
Drupal.comment_info.cookie('comment_info_option', 'true', { expires: 120 }); |
|
|
Drupal.comment_info.cookie('comment_info_name', $("#comment-form input[@name=name]").val(), { expires: 120 }); |
|
|
Drupal.comment_info.cookie('comment_info_email', $("#comment-form input[@name=mail]").val(), { expires: 120 }); |
|
|
Drupal.comment_info.cookie('comment_info_homepage', $("#comment-form input[@name=homepage]").val(), { expires: 120 }); |
|
|
} |
|
|
else { |
|
|
Drupal.comment_info.cookie('comment_info_option', 'false', { expires: -1 }); |
|
|
Drupal.comment_info.cookie('comment_info_name', '', { expires: -1 }); |
|
|
Drupal.comment_info.cookie('comment_info_email', '', { expires: -1 }); |
|
|
Drupal.comment_info.cookie('comment_info_homepage', '', { expires: -1 }); |
|
| 29 |
} |
} |
| 30 |
}); |
returnValue = decodeURIComponent(document.cookie.substring(offset, end).replace(/\+/g, '%20')); |
| 31 |
}); |
} |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
return returnValue; |
| 35 |
}; |
}; |
| 36 |
|
|
| 37 |
if (Drupal.jsEnabled) { |
if (Drupal.jsEnabled) { |
| 38 |
$(document).ready(Drupal.comment_info.autoAttach); |
$(document).ready(Drupal.comment_info.autoAttach); |
| 39 |
} |
}; |