[bugzilla-gnome-org-extensions] Fix pre-formatted text for IE



commit 5422db417b6a330619f70e25550a2c4c75f74493
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Sat Oct 10 23:08:11 2009 -0400

    Fix pre-formatted text for IE
    
    * Split preformatted text into lines ourselves to avoid
      dealing with the fact that IE only accepts \r\n and not
      \n and to get consistent cross-browser behavior.
    
    * Add a CSS workaround for the lack of white-space: pre-wrap
      in IE <= 7.

 js/splinter.js   |   27 +++++++++++++++++++++++----
 web/splinter.css |   14 ++++++++++----
 2 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/js/splinter.js b/js/splinter.js
index 63b3c15..4ccd6c5 100644
--- a/js/splinter.js
+++ b/js/splinter.js
@@ -361,7 +361,7 @@ function addCommentDisplay(commentArea, comment) {
       + "</div>"
       + "</div>"
       + "</div>")
-        .find(".comment-text").text(comment.comment).end()
+        .find(".comment-text").preWrapLines(comment.comment).end()
         .addClass(getTypeClass(comment.type))
         .addClass(getReviewerClass(review))
         .appendTo(commentArea)
@@ -714,7 +714,7 @@ function appendReviewComment(comment, parentDiv) {
             .appendTo(commentDiv);
 
         $("<div class='review-patch-comment-text'></div>")
-            .text(comment.comment)
+            .preWrapLines(comment.comment)
             .appendTo(commentDiv);
     } else {
         var hunk = comment.getHunk();
@@ -731,7 +731,7 @@ function appendReviewComment(comment, parentDiv) {
           + "<td></td>"
           + "<td class='review-patch-comment-text'></td>"
           + "</tr>")
-            .find('.review-patch-comment-text').text(comment.comment).end()
+            .find('.review-patch-comment-text').preWrapLines(comment.comment).end()
             .appendTo(tbody);
     }
 
@@ -851,7 +851,7 @@ function start(xml) {
         $("#attachmentStatusSpan").hide();
 
     if (thePatch.intro)
-        $("#patchIntro").text(thePatch.intro);
+        $("#patchIntro").preWrapLines(thePatch.intro);
     else
         $("#patchIntro").hide();
 
@@ -1112,6 +1112,25 @@ function showChooseAttachment() {
     $("#chooseAttachment").show();
 }
 
+
+// This is basically a workaround for IE which doesn't treat \n as a
+// line-break in white-space: pre, but only \r\n; we could normalize
+// line endings, but we take an alternate approach of just putting
+// each line into a separate div. We omit a trailing empty line
+// after the last line break.
+const LINE_RE = /(?!$)([^\r\n]*)(?:\r\n|\r|\n|$)/g;
+
+jQuery.fn.preWrapLines = function(text) {
+    return this.each(function() {
+        while ((m = LINE_RE.exec(text)) != null) {
+            var div = document.createElement("div");
+            div.className = "pre-wrap";
+            div.appendChild(document.createTextNode(m[1].length == 0 ? " " : m[1]));
+            this.appendChild(div);
+        }
+    });
+};
+
 function init() {
     var params = getQueryParams();
     var bugId;
diff --git a/web/splinter.css b/web/splinter.css
index 346297d..3dc8ba5 100644
--- a/web/splinter.css
+++ b/web/splinter.css
@@ -100,14 +100,11 @@ textarea:focus {
     border: 1px solid #888888;
     font-size: 90%;
     margin-bottom: 1em;
-    white-space: pre;
     padding: 0.5em;
 }
 
-
 .reviewer-box {
     padding: 0.5em;
-    white-space: pre-wrap;
 }
 
 .reviewer-0 .reviewer-box {
@@ -168,7 +165,6 @@ textarea:focus {
     margin-top: 0.5em;
     margin-bottom: 0.5em;
     cursor: pointer;
-    white-space: pre-wrap;
 }
 
 .review-patch-comment:hover {
@@ -239,6 +235,16 @@ div.review-patch-comment-text {
     clear: both;
 }
 
+/* Used for IE <= 7, overridden for modern browsers */
+.pre-wrap {
+    white-space: pre;
+    word-wrap: break-word;
+}
+
+.pre-wrap {
+    white-space: pre-wrap;
+}
+
 #files {
    position: relative;
    margin-top: 0.5em;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]