Skip to content

Commit

Permalink
Update UI integration code to sync with github markup changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozala committed Sep 13, 2012
1 parent e053ba3 commit 3c78a33
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions data/tweaks.js
@@ -1,5 +1,5 @@
var BGZ_URL = 'https://bugzilla.mozilla.org/show_bug.cgi?id='; var BGZ_URL = 'https://bugzilla.mozilla.org/show_bug.cgi?id=';
var list = document.getElementsByClassName("js-hard-tabs smalltabs")[0]; var list = document.getElementsByClassName("tabnav-tabs")[0];


if (list) { if (list) {
var bug = getBugNumber(document.title); var bug = getBugNumber(document.title);
Expand All @@ -15,22 +15,18 @@ if (list) {
} }
} }
console.log("BUG #: " + bug); console.log("BUG #: " + bug);
var li = document.createElement("li");


if (bug) var li = makeButton(list, bug);
li.innerHTML = "<a href='#'>Attach to Bug " + bug + "</a>"; li.addEventListener("click", function(event) {
else
li.innerHTML = "<a href='#'>Attach to a New Bug</a>";

li.addEventListener("click", function() {
send(bug, document.location.toString()); send(bug, document.location.toString());
}, false); event.stopPropagation();
}, true);


list.appendChild(li); list.appendChild(li);
} }


function send(bugNumber, pullRequestURL) { function send(bugNumber, pullRequestURL) {
postMessage({bug: bugNumber, url: pullRequestURL}); self.postMessage({ bug: bugNumber, url: pullRequestURL});
} }


// Search for a bug number in a string starting with: "bug ######" // Search for a bug number in a string starting with: "bug ######"
Expand All @@ -50,10 +46,20 @@ function getBugNumber(str) {
// Converts 'bug ######' string in pull request title to a link to that // Converts 'bug ######' string in pull request title to a link to that
// bug. // bug.
function linkify() { function linkify() {
var title = document.querySelector('.starting-comment .content-title'); var title = document.querySelector('.discussion-topic-title');
if (title) { if (title) {
title.innerHTML = title.innerHTML =
title.innerHTML. title.innerHTML.
replace(/(bug\s*([0-9]{6}))/i, '<a href="' + BGZ_URL + '$2">$1</a>'); replace(/(bug\s*([0-9]{6}))/i, '<a href="' + BGZ_URL + '$2">$1</a>');
} }
} }

function makeButton(containerNode, bug) {
// Use second node since firs one is selected.
var buttonNode = containerNode.children[1].cloneNode();
var linkNode = buttonNode.querySelector('a');
linkNode.setAttribute('href', '#attch-to-bugzilla');
linkNode.textContent = bug ? "Attach to Bug " + bug :
"Submit Bug";
return buttonNode;
}

0 comments on commit 3c78a33

Please sign in to comment.