summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-10-27 00:48:33 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-10-27 00:48:33 +0200
commit9e8067ca4bb9e0d21a397f681fce376e9b28ef92 (patch)
tree1fa4f58ac0a732fa46d4991644b9ed8d66349ef2 /js
parentf2a3931c5f955bc2b26d3a6ee6e3fb55f6a27ee4 (diff)
downloadbugzilla-9e8067ca4bb9e0d21a397f681fce376e9b28ef92.tar.gz
bugzilla-9e8067ca4bb9e0d21a397f681fce376e9b28ef92.tar.xz
Bug 551468: Stop word-wrapping comments on the server
r=glob, a=mkanat
Diffstat (limited to 'js')
-rw-r--r--js/comments.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/js/comments.js b/js/comments.js
index 2f1a14406..d9c0f5033 100644
--- a/js/comments.js
+++ b/js/comments.js
@@ -18,6 +18,7 @@
* Contributor(s): Frédéric Buclin <LpSolit@gmail.com>
* Max Kanat-Alexander <mkanat@bugzilla.org>
* Edmund Wong <ewong@pw-wspx.org>
+ * Anthony Pipkin <a.pipkin@yahoo.com>
*/
function updateCommentPrivacy(checkbox, id) {
@@ -76,6 +77,53 @@ function expand_comment(link, comment) {
YAHOO.util.Dom.removeClass(comment, 'collapsed');
}
+function wrapReplyText(text) {
+ // This is -3 to account for "\n> "
+ var maxCol = BUGZILLA.constant.COMMENT_COLS - 3;
+ var text_lines = text.split("\n");
+ var wrapped_lines = new Array();
+
+ for (var i = 0; i < text_lines.length; i++) {
+ var paragraph = text_lines[i];
+ // Don't wrap already-quoted text.
+ if (paragraph.indexOf('>') == 0) {
+ wrapped_lines.push('> ' + paragraph);
+ continue;
+ }
+
+ var replace_lines = new Array();
+ while (paragraph.length > maxCol) {
+ var testLine = paragraph.substring(0, maxCol);
+ var pos = testLine.search(/\s\S*$/);
+
+ if (pos < 1) {
+ // Try to find some ASCII punctuation that's reasonable
+ // to break on.
+ var punct = '\\-\\./,!;:';
+ var punctRe = new RegExp('[' + punct + '][^' + punct + ']+$');
+ pos = testLine.search(punctRe) + 1;
+ // Try to find some CJK Punctuation that's reasonable
+ // to break on.
+ if (pos == 0)
+ pos = testLine.search(/[\u3000\u3001\u3002\u303E\u303F]/) + 1;
+ // If we can't find any break point, we simply break long
+ // words. This makes long, punctuation-less CJK text wrap,
+ // even if it wraps incorrectly.
+ if (pos == 0) pos = maxCol;
+ }
+
+ var wrapped_line = paragraph.substring(0, pos);
+ replace_lines.push(wrapped_line);
+ paragraph = paragraph.substring(pos);
+ // Strip whitespace from the start of the line
+ paragraph = paragraph.replace(/^\s+/, '');
+ }
+ replace_lines.push(paragraph);
+ wrapped_lines.push("> " + replace_lines.join("\n> "));
+ }
+ return wrapped_lines.join("\n");
+}
+
/* This way, we are sure that browsers which do not support JS
* won't display this link */