comments.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //requires jquery
  2. var CommentSystem = {
  3. email_user: "not set",
  4. email_domain: "not set",
  5. display_replyto_html: function(comment_content, article_slug, author) {return ''},
  6. cancelReply: function() {
  7. $('#pcs-comment-form-input-replyto').val("");
  8. $('#pcs-comment-form-display-replyto').hide();
  9. },
  10. setReply: function(slug, author) {
  11. slug = decodeURIComponent(slug);
  12. author = decodeURIComponent(author);
  13. $('html, body').animate({ scrollTop: $("#pcs-comment-form").offset().top }, 1000);
  14. $('#pcs-comment-form-input-replyto').val(slug);
  15. var jquery_escaped_id = slug.replace('.', '\\.')
  16. var commentContent = $('#comment-' + jquery_escaped_id + ' .pcs-comment-content:first').text().trim()
  17. $('#pcs-comment-form-display-replyto').html(this.display_replyto_html(commentContent, slug, author));
  18. $('#pcs-comment-form-display-replyto').show();
  19. },
  20. getMailtoLink: function(slug) {
  21. var subject = 'Comment for \'' + slug + '\'' ;
  22. var now = new Date();
  23. tzo = -now.getTimezoneOffset(),
  24. dif = tzo >= 0 ? '+' : '-',
  25. pad = function(num) {
  26. norm = Math.abs(Math.floor(num));
  27. return (norm < 10 ? '0' : '') + norm;
  28. };
  29. var body = ''
  30. + 'Hey,\nI posted a new comment on ' + document.URL + '\n\nGreetings ' + $("#pcs-comment-form-input-name").val() + '\n\n\n'
  31. + 'Raw comment data:\n'
  32. + '----------------------------------------\n'
  33. + 'email: \n' // just that I don't forget to write it down
  34. + 'date: ' + now.getFullYear()
  35. + '-' + pad(now.getMonth()+1)
  36. + '-' + pad(now.getDate())
  37. + 'T' + pad(now.getHours())
  38. + ':' + pad(now.getMinutes())
  39. + dif + pad(tzo / 60)
  40. + ':' + pad(tzo % 60) +'\n'
  41. + 'author: ' + $("#pcs-comment-form-input-name").val() + '\n';
  42. var replyto = $('#pcs-comment-form-input-replyto').val();
  43. if (replyto.length != 0)
  44. {
  45. body += 'replyto: ' + replyto + '\n'
  46. }
  47. var url = $("#pcs-comment-form-input-website").val();
  48. if (url.length != 0)
  49. {
  50. if(url.substr(0,7) != 'http://' && url.substr(0,8) != 'https://'){
  51. url = 'http://' + url;
  52. }
  53. body += 'website: ' + url + '\n';
  54. }
  55. body += '\n'
  56. + $("#pcs-comment-form-input-textarea").val() + '\n'
  57. + '----------------------------------------\n';
  58. var link = 'mailto:' + this.email_user + '@' + this.email_domain + '?subject='
  59. + encodeURIComponent(subject)
  60. + "&body="
  61. + encodeURIComponent(body.replace(/\r?\n/g, "\r\n"));
  62. console.log(link)
  63. return link;
  64. }
  65. }