comment.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. Author: mg12
  3. Update: 2008/05/05
  4. Author URI: http://www.neoease.com/
  5. */
  6. (function() {
  7. function reply(authorId, commentId, commentBox) {
  8. var author = MGJS.$(authorId).innerHTML;
  9. var insertStr = '<a href="#' + commentId + '">@' + author.replace(/\t|\n|\r\n/g, "") + ' </a> \n';
  10. appendReply(insertStr, commentBox);
  11. }
  12. function quote(authorId, commentId, commentBodyId, commentBox) {
  13. var author = MGJS.$(authorId).innerHTML;
  14. var comment = MGJS.$(commentBodyId).innerHTML;
  15. var insertStr = '<blockquote cite="#' + commentBodyId + '">';
  16. insertStr += '\n<strong><a href="#' + commentId + '">' + author.replace(/\t|\n|\r\n/g, "") + '</a> :</strong>';
  17. insertStr += comment.replace(/\t/g, "");
  18. insertStr += '</blockquote>\n';
  19. insertQuote(insertStr, commentBox);
  20. }
  21. function appendReply(insertStr, commentBox) {
  22. if(MGJS.$(commentBox) && MGJS.$(commentBox).type == 'textarea') {
  23. field = MGJS.$(commentBox);
  24. } else {
  25. alert("The comment box does not exist!");
  26. return false;
  27. }
  28. if (field.value.indexOf(insertStr) > -1) {
  29. alert("You've already appended this reply!");
  30. return false;
  31. }
  32. if (field.value.replace(/\s|\t|\n/g, "") == '') {
  33. field.value = insertStr;
  34. } else {
  35. field.value = field.value.replace(/[\n]*$/g, "") + '\n\n' + insertStr;
  36. }
  37. field.focus();
  38. }
  39. function insertQuote(insertStr, commentBox) {
  40. if(MGJS.$(commentBox) && MGJS.$(commentBox).type == 'textarea') {
  41. field = MGJS.$(commentBox);
  42. } else {
  43. alert("The comment box does not exist!");
  44. return false;
  45. }
  46. if(document.selection) {
  47. field.focus();
  48. sel = document.selection.createRange();
  49. sel.text = insertStr;
  50. field.focus();
  51. } else if (field.selectionStart || field.selectionStart == '0') {
  52. var startPos = field.selectionStart;
  53. var endPos = field.selectionEnd;
  54. var cursorPos = startPos;
  55. field.value = field.value.substring(0, startPos)
  56. + insertStr
  57. + field.value.substring(endPos, field.value.length);
  58. cursorPos += insertStr.length;
  59. field.focus();
  60. field.selectionStart = cursorPos;
  61. field.selectionEnd = cursorPos;
  62. } else {
  63. field.value += insertStr;
  64. field.focus();
  65. }
  66. }
  67. window['MGJS_CMT'] = {};
  68. window['MGJS_CMT']['reply'] = reply;
  69. window['MGJS_CMT']['quote'] = quote;
  70. })();