diff options
| author | Ilya Sukhar | 2010-09-23 23:27:56 -0700 |
|---|---|---|
| committer | Ilya Sukhar | 2010-09-23 23:34:54 -0700 |
| commit | 64b550a4a7fa4af1d9c0996d6f66715dc479ccb5 (patch) | |
| tree | 97b9a995a70c725c2168eb9eb27e75f6ed204e82 /vimiumFrontend.js | |
| parent | f377565c3b5c3731623c24da96c8623860cec3f2 (diff) | |
| download | vimium-64b550a4a7fa4af1d9c0996d6f66715dc479ccb5.tar.bz2 | |
A bunch of changes having to do with the frame support patch:
- Focus the largest frame by default
- Change the border styling to match link hints
- Clean up framesForTab when tab is closed
- Don't cycle through parent. This may break some sites. Needs more testing.
- Fixed some naming and style
- Added seven1m to CREDITS
- Updated README
Diffstat (limited to 'vimiumFrontend.js')
| -rw-r--r-- | vimiumFrontend.js | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js index 685e121f..ac7d366a 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -26,6 +26,11 @@ var linkHintCss; // TODO(philc): This should be pulled from the extension's storage when the page loads. var currentZoomLevel = 100; +/* + * Give this frame a unique id. + */ +frameId = Math.floor(Math.random()*999999999) + var hasModifiersRegex = /^<([amc]-)+.>/; function getSetting(key) { @@ -69,7 +74,7 @@ function initializePreDomReady() { showHelpDialog(request.dialogHtml, request.frameId); else if (request.name == "focusFrame") if(frameId == request.frameId) - focusThisFrame(); + focusThisFrame(request.highlight); else if (request.name == "refreshCompletionKeys") refreshCompletionKeys(request.completionKeys); sendResponse({}); // Free up the resources used by this open connection. @@ -137,30 +142,22 @@ function initializeWhenEnabled() { enterInsertModeIfElementIsFocused(); } -/* - * Give this frame a unique id and register with the backend. - */ -frameId = Math.floor(Math.random()*999999999) -if(window.top == window.self) - chrome.extension.sendRequest({handler: "registerFrame", frameId: frameId, top: true}); -else - chrome.extension.sendRequest({handler: "registerFrame", frameId: frameId}); /* * The backend needs to know which frame has focus. */ window.addEventListener("focus", function(e){ - chrome.extension.sendRequest({handler: "focusFrame", frameId: frameId}); + chrome.extension.sendRequest({handler: "frameFocused", frameId: frameId}); }); /* * Called from the backend in order to change frame focus. */ -function focusThisFrame() { +function focusThisFrame(shouldHighlight) { window.focus(); - if(document.body) { + if (document.body && shouldHighlight) { var borderWas = document.body.style.border; - document.body.style.border = '1px solid red'; + document.body.style.border = '5px solid yellow'; setTimeout(function(){document.body.style.border = borderWas}, 200); } } @@ -169,6 +166,11 @@ function focusThisFrame() { * Initialization tasks that must wait for the document to be ready. */ function initializeOnDomReady() { + if (window.top == window.self) + chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, top: true, total: frames.length }); + else + registerFrameIfSizeAvailable(); + if (isEnabledForUrl) enterInsertModeIfElementIsFocused(); @@ -176,6 +178,14 @@ function initializeOnDomReady() { chrome.extension.connect({ name: "domReady" }); }; +// This is a little hacky but sometimes the size wasn't available on domReady? +function registerFrameIfSizeAvailable () { + if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0) + chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, area: innerWidth * innerHeight }); + else + setTimeout(registerFrameIfSizeAvailable, 100); +} + /* * Checks the currently focused element of the document and will enter insert mode if that element is focusable. */ |
