diff --git a/quote-comments.js b/quote-comments.js index 33138f3..bb7d3b0 100755 --- a/quote-comments.js +++ b/quote-comments.js @@ -5,23 +5,14 @@ function jsEncode(str){ - // ugly hack - str = " " + str; - - var aStr = str.split(''), i = aStr.length, aRet = []; + str = str.toString(); + str = str.replace(/&/g, '&'); + str = str.replace(//g, '>'); + str = str.replace(/'/g, '''); + str = str.replace(/"/g, '"'); + + return str; - while (--i) { - var iC = aStr[i].charCodeAt(); - - if (iC < 65 || iC > 127 || (iC>90 && iC<97)) { - aRet.push(''+iC+';'); - } else { - aRet.push(aStr[i]); - } - } - - return aRet.reverse().join(''); - } @@ -50,10 +41,11 @@ function quote(postid, author, commentarea, commentID, mce) { return true; } + posttext = posttext.toString(); + if (posttext=='') { // quoting entire comment - // quoteing the entire thing - var selection = false; + // quoting the entire thing var commentID = commentID.split("div-comment-")[1]; // quote entire comment as html @@ -94,6 +86,10 @@ function quote(postid, author, commentarea, commentID, mce) { } + // trim + var posttext = posttext.replace(/^\s+/, ""); + var posttext = posttext.replace(/\s+$/, ""); + // build quote if (author) { @@ -104,7 +100,7 @@ function quote(postid, author, commentarea, commentID, mce) { } else { - var quote='\n
\n\n'+posttext+'\n'; + var quote='
\n'+posttext+'\n\n'; } @@ -141,7 +137,7 @@ function inlinereply(postid, author, commentarea, commentID, mce) { author = jsEncode(author); // build quote - var quote='\n'+unescape(author)+', \n\n'; + var quote=''+unescape(author)+', \n\n'; // send quoted content diff --git a/quote-comments.php b/quote-comments.php index 2d8d111..20ac19b 100755 --- a/quote-comments.php +++ b/quote-comments.php @@ -177,7 +177,7 @@ function add_quote_button_filter($output) { } else { - return($output . $button); + return $output; }