From d3b1a4f3a2758062a0537ebd0c40a676a8a00b66 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sun, 30 May 2010 20:47:18 -0400 Subject: Switch to using the context-menu API --- lib/main.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'lib/main.js') diff --git a/lib/main.js b/lib/main.js index cd4de54..cb1da69 100644 --- a/lib/main.js +++ b/lib/main.js @@ -70,24 +70,19 @@ function tweakBugzilla(d) { d.getElementsByTagName("head")[0].appendChild(style); // Allow toggling of CC event displays using a context menu entry - jetpack.menu.beforeShow = function (menu, context) { - var style = context.document.getElementById("bztw_cc"); - menu.reset(); - menu.add({ - label: (style.disabled ? "Hide CC History" : "Show CC History"), - command: function() style.disabled = !style.disabled - }); - if (CheckinComment.isValid()) { - var message = context.document.getElementById("__bz_tw_checkin_comment"); - if (message) { - message = message.textContent; - menu.add({ - label: "Copy Check-in Comment", - command: function() jetpack.clipboard.set(message) - }); - } + var contextMenu = require("context-menu"); + function getCCMenuItemLabel(d) { + var style = d.getElementById("bztw_cc"); + return (style.disabled ? "Hide CC History" : "Show CC History"); + } + var ccMenuItem = contextMenu.Item({ + label: getCCMenuItemLabel(d), + onClick: function(context, item) { + style.disabled = !style.disabled; + item.label = getCCMenuItemLabel(context.document); } - }; + }); + contextMenu.add(ccMenuItem); var userNameCache = {}; function getUserName(email) { @@ -159,6 +154,17 @@ function tweakBugzilla(d) { var CheckinComment = new CheckinCommentCtor(); CheckinComment.initialize(d, AttachmentFlagHandler._interestingFlags); + if (CheckinComment.isValid()) { + var message = d.getElementById("__bz_tw_checkin_comment"); + if (message) { + message = message.textContent; + var copyCheckinCommentItem = contextMenu.Item({ + label: "Copy Check-in Comment", + onClick: function() jetpack.clipboard.set(message) + }); + contextMenu.add(copyCheckinCommentItem); + } + } var iframe = d.createElement('iframe'); iframe.src = historyLink.href; -- cgit