diff options
| author | ilya | 2009-11-04 23:29:16 -0800 |
|---|---|---|
| committer | ilya | 2009-11-04 23:29:16 -0800 |
| commit | e0d5fbd038d17b362f3db00b35450ba2c2a18166 (patch) | |
| tree | 39fadeb22a730679303c486ed14466124ac03c85 /background_page.html | |
| parent | 3997d2a904c07cc98281972f0c852aa9c3b3baea (diff) | |
| download | vimium-e0d5fbd038d17b362f3db00b35450ba2c2a18166.tar.bz2 | |
Some cleanup.
Diffstat (limited to 'background_page.html')
| -rw-r--r-- | background_page.html | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/background_page.html b/background_page.html index d4b5f4fb..5d252305 100644 --- a/background_page.html +++ b/background_page.html @@ -1,20 +1,22 @@ <html> <head> <script type="text/javascript" charset="utf-8"> - var tabQueue = []; + var tabQueue = []; // Queue of tabs to restore with scroll info + var keyQueue = ""; // Queue of keys typed + + // Port handler mapping + var portHandlers = { "keyDown": handleKeyDown, + "returnScrollPosition": handleReturnScrollPosition }; + + // Event handlers var selectionChangedHandlers = []; var getScrollPositionHandlers = {}; // tabId -> function (tab, scrollTop, scrollLeft) var tabLoadedHandlers = {}; // tabId -> function () - var keyQueue = ""; chrome.extension.onConnect.addListener(function(port, name) { - if (port.name == "keyDown") - { - port.onMessage.addListener(handleKeyDown); - } - else if (port.name == "returnScrollPosition") + if (portHandlers[port.name]) { - port.onMessage.addListener(handleReturnScrollPosition); + port.onMessage.addListener(portHandlers[port.name]); } }); @@ -28,14 +30,6 @@ } } - // TODO(ilya): Move this handler over to a dictionary like below. - chrome.tabs.onSelectionChanged.addListener(function (tabId, selectionInfo) { - if (selectionChangedHandlers.length > 0) - { - selectionChangedHandlers.pop().call(); - } - }); - chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) { if (changeInfo.status == "complete" && tabLoadedHandlers[tabId]) { @@ -46,9 +40,9 @@ } }); - function registerSelectionChangedHandler(handler) { - selectionChangedHandlers.push(handler); - } + chrome.tabs.onSelectionChanged.addListener(function (tabId, selectionInfo) { + if (selectionChangedHandlers.length > 0) { selectionChangedHandlers.pop().call(); } + }); function repeatFunction(func, totalCount, currentCount) { if (currentCount < totalCount) @@ -79,7 +73,7 @@ chrome.tabs.remove(tab.id); // We can't just call the callback here because we actually need to wait // for the selection to change to consider this action done. - registerSelectionChangedHandler(callback); + selectionChangedHandlers.push(callback); }); } |
