1
|
1 |
/* |
|
2 |
Author: mg12 |
|
3 |
Update: 2008/05/05 |
|
4 |
Author URI: http://www.neoease.com/ |
|
5 |
*/ |
|
6 |
(function() { |
|
7 |
|
|
8 |
function reply(authorId, commentId, commentBox) { |
|
9 |
var author = MGJS.$(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 = MGJS.$(authorId).innerHTML; |
|
17 |
var comment = MGJS.$(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(MGJS.$(commentBox) && MGJS.$(commentBox).type == 'textarea') { |
|
29 |
field = MGJS.$(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(MGJS.$(commentBox) && MGJS.$(commentBox).type == 'textarea') { |
|
51 |
field = MGJS.$(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 |
window['MGJS_CMT'] = {}; |
|
83 |
window['MGJS_CMT']['reply'] = reply; |
|
84 |
window['MGJS_CMT']['quote'] = quote; |
|
85 |
|
|
86 |
})(); |