From 195a45e8a52a5663cc9678ae295a279712544f36 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 26 Apr 2011 14:26:19 -0400 Subject: Correct the attachment linkification based on the changes in Bugzilla 4.0 --- data/js/bug-page-mod.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'data') diff --git a/data/js/bug-page-mod.js b/data/js/bug-page-mod.js index 561dda8..596e2c7 100644 --- a/data/js/bug-page-mod.js +++ b/data/js/bug-page-mod.js @@ -630,11 +630,18 @@ AttachmentFlagHandlerCtor.prototype = { if (!(attachmentID in this._interestingFlags)) { this._interestingFlags[attachmentID] = []; } + var text = ""; + var previousText = ""; + var previousEl = null; for (var el = item[1].firstChild; el.nextSibling; el = el.nextSibling) { - if (el.nodeType != el.TEXT_NODE) - continue; - var text = trimContent(el).replace('\u2011', '-', 'g'); - if (!text) + var thisText = trimContent(el).replace('\u2011', '-', 'g'); + text += thisText; + if (this._reParsePartToLinkify.test(thisText)) { + previousText = thisText; + previousEl = el; + } + if (el.nodeType != el.ELEMENT_NODE || + el.localName.toLowerCase() != "br") continue; match = this._reParseInterestingFlag.exec(text); if (match) { @@ -666,22 +673,25 @@ AttachmentFlagHandlerCtor.prototype = { // try to put the flag name and type part in a span which we will // use in setupLinks to inject links into. - match = this._reLinkifyInterestingFlag.exec(text); + match = this._reLinkifyInterestingFlag.exec(previousText); if (match) { - el.textContent = match[1]; + previousEl.textContent = match[1]; if (match[3]) { var textNode = doc.createTextNode(match[3]); - el.parentNode.insertBefore(textNode, el.nextSibling); + previousEl.parentNode.insertBefore(textNode, previousEl.nextSibling); } var span = doc.createElement("span"); span.textContent = match[2]; - el.parentNode.insertBefore(span, el.nextSibling); + previousEl.parentNode.insertBefore(span, previousEl.nextSibling); flag.placeholder = span; } this._interestingFlags[attachmentID].push(new AttachmentFlag(flag)); } + text = ""; + previousText = ""; + previousEl = null; } } } @@ -756,8 +766,9 @@ AttachmentFlagHandlerCtor.prototype = { return "attachflag" + this._counter; }, _reParseRequest: /^(.+)([\?\-\+])(\((.+)@.+\))?$/, + _reParsePartToLinkify: /^\s*:\s+.+[\-\+\?](\s*\()?\s*$/, _reParseInterestingFlag: /^(.+):\s+(.+)(([\-\+])|\?(\s+(\((.+)\)))?)$/, - _reLinkifyInterestingFlag: /^(.+:\s+)(.+[\-\+\?])(\s+\(.+\))?$/, + _reLinkifyInterestingFlag: /^(\s*:\s+)(.+[\-\+\?])(\s*\(\s*)?$/, _reAttachmentHref: /attachment\.cgi\?id=(\d+)$/i, _reAttachmentFlagName: /^Attachment\s+#(\d+)\s+Flags$/i }; -- cgit