Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: chrome/background.js

Issue 5589897452716032: Implemented ext.contextMenus for Safari (Closed)
Patch Set: Created Jan. 18, 2014, 10:29 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « block.js ('k') | include.postload.js » ('j') | safari/background.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/background.js
===================================================================
--- a/chrome/background.js
+++ b/chrome/background.js
@@ -370,10 +370,12 @@
handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged
};
+ var contextMenuItems = [];
+ var isContextMenuHidden = true;
ext.contextMenus = {
- create: function(title, contexts, onclick)
+ addMenuItem: function(title, contexts, onclick)
{
- chrome.contextMenus.create({
+ contextMenuItems.push({
title: title,
contexts: contexts,
onclick: function(info, tab)
@@ -381,10 +383,39 @@
onclick(info.srcUrl, new Tab(tab));
}
});
+ this.showMenuItems();
},
- removeAll: function(callback)
+ removeMenuItems: function()
{
- chrome.contextMenus.removeAll(callback);
+ contextMenuItems = [];
+ this.hideMenuItems();
+ },
+ showMenuItems: function()
+ {
+ if (!isContextMenuHidden)
+ return;
+
+ chrome.contextMenus.removeAll(function()
+ {
+ for (var i = 0; i < contextMenuItems.length; i++)
+ {
+ var item = contextMenuItems[i];
+ chrome.contextMenus.create({
+ title: item.title,
+ contexts: item.contexts,
+ onclick: item.onclick
+ });
+ }
+ });
+ isContextMenuHidden = false;
+ },
+ hideMenuItems: function()
+ {
+ if (isContextMenuHidden)
+ return;
+
+ chrome.contextMenus.removeAll();
+ isContextMenuHidden = true;
}
};
})();
« no previous file with comments | « block.js ('k') | include.postload.js » ('j') | safari/background.js » ('J')

Powered by Google App Engine
This is Rietveld