diff options
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.   */ | 
