/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This Source Code Form is "Incompatible With Secondary Licenses", as
* defined by the Mozilla Public License, v. 2.0. */
var inline_history = {
_ccDivs: null,
_hasAttachmentFlags: false,
_hasBugFlags: false,
init: function() {
Dom = YAHOO.util.Dom;
var reDuplicate = /^\*\*\* \S+ \d+ has been marked as a duplicate of this/;
var reBugId = /show_bug\.cgi\?id=(\d+)/;
var reHours = /Additional hours worked: \d+\.\d+/;
var comments = Dom.getElementsByClassName("bz_comment", 'div', 'comments');
for (var i = 1, il = comments.length; i < il; i++) {
// remove 'has been marked as a duplicate of this bug' comments
var textDiv = Dom.getElementsByClassName('bz_comment_text', 'pre', comments[i]);
if (textDiv) {
var match = reDuplicate.exec(textDiv[0].textContent || textDiv[0].innerText);
if (match) {
// grab the comment and bug number from the element
var comment = comments[i];
var number = comment.id.substr(1);
var time = this.trim(Dom.getElementsByClassName('bz_comment_time', 'span', comment)[0].innerHTML);
var dupeId = 0;
match = reBugId.exec(Dom.get('comment_text_' + number).innerHTML);
if (match)
dupeId = match[1];
// remove the element
comment.parentNode.removeChild(comment);
comments[i] = false;
// update the html for the history item to include the comment number
if (dupeId == 0)
continue;
for (var j = 0, jl = ih_activity.length; j < jl; j++) {
var item = ih_activity[j];
if (item[5] == dupeId && item[1] == time) {
// insert comment number and link into the header
item[3] = item[3].substr(0, item[3].length - 6) // remove trailing
// add comment number
+ ''
+ 'Comment ' + number + ''
+ ''
+ '';
break;
}
}
}
}
if (!comments[i])
continue;
// remove 'Additional hours worked: ' comments
var commentNodes = comments[i].childNodes;
for (var j = 0, jl = commentNodes.length; j < jl; j++) {
if (reHours.exec(commentNodes[j].textContent)) {
comments[i].removeChild(commentNodes[j]);
// Remove the
before it
comments[i].removeChild(commentNodes[j-1]);
break;
}
}
}
// remove deleted comments
for (var i = 0; i < comments.length; i++) {
if (!comments[i]) {
comments.splice(i, 1);
i--;
}
}
// ensure new items are placed immediately after the last comment
if (!comments.length) return;
var lastCommentDiv = comments[comments.length - 1];
// insert activity into the correct location
var commentTimes = Dom.getElementsByClassName('bz_comment_time', 'span', 'comments');
for (var i = 0, il = ih_activity.length; i < il; i++) {
var item = ih_activity[i];
// item[0] : who
// item[1] : when
// item[2] : change html
// item[3] : header html
// item[4] : bool; cc-only
// item[5] : int; dupe bug id (or 0)
// item[6] : bool; is flag
var user = item[0];
var time = item[1];
var reachedEnd = false;
var start_index = (ih_activity_sort_order == 'newest_to_oldest_desc_first' && commentTimes.length > 1) ? 1 : 0;
for (var j = start_index, jl = commentTimes.length; j < jl; j++) {
var commentHead = commentTimes[j].parentNode;
var mainUser = Dom.getElementsByClassName('email', 'a', commentHead)[0].href.substr(7);
var text = commentTimes[j].textContent || commentTimes[j].innerText;
var mainTime = this.trim(text);
if (ih_activity_sort_order == 'oldest_to_newest' ? time > mainTime : time < mainTime) {
if (j < commentTimes.length - 1) {
continue;
} else {
reachedEnd = true;
}
}
var inline = (mainUser == user && time == mainTime);
var currentDiv = document.createElement("div");
// place ih_cc class on parent container if it's the only child
var containerClass = '';
if (item[4]) {
item[2] = item[2].replace('"ih_cc"', '""');
containerClass = 'ih_cc';
}
if (inline) {
// assume that the change was made by the same user
commentHead.parentNode.appendChild(currentDiv);
currentDiv.innerHTML = item[2];
Dom.addClass(currentDiv, 'ih_inlinehistory');
Dom.addClass(currentDiv, containerClass);
if (item[6])
this.setFlagChangeID(item, commentHead.parentNode.id);
} else {
// the change was made by another user
if (!reachedEnd) {
var parentDiv = commentHead.parentNode;
var previous = this.previousElementSibling(parentDiv);
if (previous && previous.className.indexOf("ih_history") >= 0) {
currentDiv = this.previousElementSibling(parentDiv);
} else {
if (commentTimes.length == 1) {
parentDiv.parentNode.insertBefore(currentDiv, parentDiv.nextSibling);
} else {
parentDiv.parentNode.insertBefore(currentDiv, parentDiv);
}
}
} else {
var parentDiv = commentHead.parentNode;
var next = this.nextElementSibling(parentDiv);
if (next && next.className.indexOf("ih_history") >= 0) {
currentDiv = this.nextElementSibling(parentDiv);
} else {
lastCommentDiv.parentNode.insertBefore(currentDiv, lastCommentDiv.nextSibling);
}
}
var itemContainer = document.createElement('div');
itemContainer.className = 'ih_history_item ' + containerClass;
itemContainer.id = 'h' + i;
itemContainer.innerHTML = item[3] + '