|
1 /* |
|
2 Author: mg12 |
|
3 Update: 2008/08/13 |
|
4 Author URI: http://www.neoease.com/ |
|
5 */ |
|
6 (function() { |
|
7 |
|
8 function reply(authorId, commentId, commentBox) { |
|
9 var author = document.getElementById(authorId).innerHTML; |
|
10 var insertStr = '<a href="#' + commentId + '">@' + author.replace(/\t|\n|\r\n/g, "") + ' </a> \n'; |
|
11 |
|
12 appendReply(insertStr, commentBox); |
|
13 } |
|
14 |
|
15 function quote(authorId, commentId, commentBodyId, commentBox) { |
|
16 var author = document.getElementById(authorId).innerHTML; |
|
17 var comment = document.getElementById(commentBodyId).innerHTML; |
|
18 |
|
19 var insertStr = '<blockquote cite="#' + commentBodyId + '">'; |
|
20 insertStr += '\n<strong><a href="#' + commentId + '">' + author.replace(/\t|\n|\r\n/g, "") + '</a> :</strong>'; |
|
21 insertStr += comment.replace(/\t/g, ""); |
|
22 insertStr += '</blockquote>\n'; |
|
23 |
|
24 insertQuote(insertStr, commentBox); |
|
25 } |
|
26 |
|
27 function appendReply(insertStr, commentBox) { |
|
28 if(document.getElementById(commentBox) && document.getElementById(commentBox).type == 'textarea') { |
|
29 field = document.getElementById(commentBox); |
|
30 |
|
31 } else { |
|
32 alert("The comment box does not exist!"); |
|
33 return false; |
|
34 } |
|
35 |
|
36 if (field.value.indexOf(insertStr) > -1) { |
|
37 alert("You've already appended this reply!"); |
|
38 return false; |
|
39 } |
|
40 |
|
41 if (field.value.replace(/\s|\t|\n/g, "") == '') { |
|
42 field.value = insertStr; |
|
43 } else { |
|
44 field.value = field.value.replace(/[\n]*$/g, "") + '\n\n' + insertStr; |
|
45 } |
|
46 field.focus(); |
|
47 } |
|
48 |
|
49 function insertQuote(insertStr, commentBox) { |
|
50 if(document.getElementById(commentBox) && document.getElementById(commentBox).type == 'textarea') { |
|
51 field = document.getElementById(commentBox); |
|
52 |
|
53 } else { |
|
54 alert("The comment box does not exist!"); |
|
55 return false; |
|
56 } |
|
57 |
|
58 if(document.selection) { |
|
59 field.focus(); |
|
60 sel = document.selection.createRange(); |
|
61 sel.text = insertStr; |
|
62 field.focus(); |
|
63 |
|
64 } else if (field.selectionStart || field.selectionStart == '0') { |
|
65 var startPos = field.selectionStart; |
|
66 var endPos = field.selectionEnd; |
|
67 var cursorPos = startPos; |
|
68 field.value = field.value.substring(0, startPos) |
|
69 + insertStr |
|
70 + field.value.substring(endPos, field.value.length); |
|
71 cursorPos += insertStr.length; |
|
72 field.focus(); |
|
73 field.selectionStart = cursorPos; |
|
74 field.selectionEnd = cursorPos; |
|
75 |
|
76 } else { |
|
77 field.value += insertStr; |
|
78 field.focus(); |
|
79 } |
|
80 } |
|
81 |
|
82 function loadCommentShortcut(frm, submitbnt, desc) { |
|
83 document.getElementById(frm).onkeydown = function (moz_ev) { |
|
84 var ev = null; |
|
85 ev = window.event ? window.event : moz_ev; |
|
86 if (ev != null && ev.ctrlKey && ev.keyCode == 13) { |
|
87 document.getElementById(submitbnt).click(); |
|
88 } |
|
89 }; |
|
90 document.getElementById(submitbnt).value += desc; |
|
91 } |
|
92 |
|
93 window['CMT'] = {}; |
|
94 window['CMT']['reply'] = reply; |
|
95 window['CMT']['quote'] = quote; |
|
96 window['CMT']['loadCommentShortcut'] = loadCommentShortcut; |
|
97 |
|
98 })(); |