| 1 |
|
// $Id: comment_info.js,v 1.0 2007/01/29 03:51:25 mfer Exp $ |
| 2 |
|
|
| 3 |
|
Drupal.comment_info = {}; |
| 4 |
|
|
| 5 |
|
Drupal.comment_info.cookie = function(name, value, options) { |
| 6 |
|
if (typeof value != 'undefined') { // name and value given, set cookie |
| 7 |
|
options = options || {}; |
| 8 |
|
var expires = ''; |
| 9 |
|
if (options.expires && (typeof options.expires == 'number' || options.expires.toGMTString)) { |
| 10 |
|
var date; |
| 11 |
|
if (typeof options.expires == 'number') { |
| 12 |
|
date = new Date(); |
| 13 |
|
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); |
| 14 |
|
} else { |
| 15 |
|
date = options.expires; |
| 16 |
|
} |
| 17 |
|
expires = '; expires=' + date.toGMTString(); // use expires attribute, max-age is not supported by IE |
| 18 |
|
} |
| 19 |
|
var path = options.path ? '; path=' + options.path : ''; |
| 20 |
|
var domain = options.domain ? '; domain=' + options.domain : ''; |
| 21 |
|
var secure = options.secure ? '; secure' : ''; |
| 22 |
|
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); |
| 23 |
|
} else { // only name given, get cookie |
| 24 |
|
var cookieValue = null; |
| 25 |
|
if (document.cookie && document.cookie != '') { |
| 26 |
|
var cookies = document.cookie.split(';'); |
| 27 |
|
for (var i = 0; i < cookies.length; i++) { |
| 28 |
|
var cookie = jQuery.trim(cookies[i]); |
| 29 |
|
// Does this cookie string begin with the name we want? |
| 30 |
|
if (cookie.substring(0, name.length + 1) == (name + '=')) { |
| 31 |
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); |
| 32 |
|
break; |
| 33 |
|
} |
| 34 |
|
} |
| 35 |
|
} |
| 36 |
|
return cookieValue; |
| 37 |
|
} |
| 38 |
|
}; |
| 39 |
|
|
| 40 |
|
Drupal.comment_info.autoAttach = function() { |
| 41 |
|
$('#comment_info').prepend('<div class="form-item"><label class="option"><input type="checkbox" name="optin" id="comment_info_checkbox" value="1" class="form-checkbox" /> Save my Comment Information for next time.</label></div>'); |
| 42 |
|
var comment_info_option = Drupal.comment_info.cookie('comment_info_option'); |
| 43 |
|
if (comment_info_option=='true') { |
| 44 |
|
$("#comment-form input[@name=name]").val(Drupal.comment_info.cookie('comment_info_name')); |
| 45 |
|
$("#comment-form input[@name=mail]").val(Drupal.comment_info.cookie('comment_info_email')); |
| 46 |
|
$("#comment-form input[@name=homepage]").val(Drupal.comment_info.cookie('comment_info_homepage')); |
| 47 |
|
document.getElementById("comment_info_checkbox").checked=true; |
| 48 |
|
} |
| 49 |
|
$("form#comment-form input[@type=submit]").each( function() { |
| 50 |
|
$(this).click(function() { |
| 51 |
|
var x=document.getElementById("comment_info_checkbox") |
| 52 |
|
if(x.checked) { |
| 53 |
|
Drupal.comment_info.cookie('comment_info_option', 'true', { expires: 120 }); |
| 54 |
|
Drupal.comment_info.cookie('comment_info_name', $("#comment-form input[@name=name]").val(), { expires: 120 }); |
| 55 |
|
Drupal.comment_info.cookie('comment_info_email', $("#comment-form input[@name=mail]").val(), { expires: 120 }); |
| 56 |
|
Drupal.comment_info.cookie('comment_info_homepage', $("#comment-form input[@name=homepage]").val(), { expires: 120 }); |
| 57 |
|
} |
| 58 |
|
else { |
| 59 |
|
Drupal.comment_info.cookie('comment_info_option', 'false', { expires: -1 }); |
| 60 |
|
Drupal.comment_info.cookie('comment_info_name', '', { expires: -1 }); |
| 61 |
|
Drupal.comment_info.cookie('comment_info_email', '', { expires: -1 }); |
| 62 |
|
Drupal.comment_info.cookie('comment_info_homepage', '', { expires: -1 }); |
| 63 |
|
} |
| 64 |
|
}); |
| 65 |
|
}); |
| 66 |
|
}; |
| 67 |
|
|
| 68 |
|
if (Drupal.jsEnabled) { |
| 69 |
|
$(document).ready(Drupal.comment_info.autoAttach); |
| 70 |
|
} |