aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-05-01 07:47:10 +0100
committerStephen Blott2015-05-01 07:47:10 +0100
commitcc1aacdd24aecb2bf1bb6436553c0318bdc6658b (patch)
tree0f9191fb6da1bf0207e55ea3e2b630ac34b3bad2 /content_scripts
parent7dcee922623d9865d9b896a9d9531023bf544dc3 (diff)
parent1d7cc1e43ada7baf394f58e2f0e586a5c252f7b3 (diff)
downloadvimium-cc1aacdd24aecb2bf1bb6436553c0318bdc6658b.tar.bz2
Merge pull request #1622 from mrmr1993/reenable-grabBackFocus-on-js-transitions
Make GrabBackFocus work for javascript page transitions from links
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/vimium_frontend.coffee26
1 files changed, 26 insertions, 0 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 02e6c9ee..e1d7b581 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -133,6 +133,32 @@ class GrabBackFocus extends Mode
element.blur()
@suppressEvent
+# Pages can load new content dynamically and change the displayed URL using history.pushState. Since this can
+# often be indistinguishable from an actual new page load for the user, we should also re-start GrabBackFocus
+# for these as well. This fixes issue #1622.
+handlerStack.push
+ _name: "GrabBackFocus-pushState-monitor"
+ click: (event) ->
+ # If a focusable element is focused, the user must have clicked on it. Retain focus and bail.
+ return true if DomUtils.isFocusable document.activeElement
+
+ target = event.target
+ while target
+ # Often, a link which triggers a content load and url change with javascript will also have the new
+ # url as it's href attribute.
+ if target.tagName == "A" and
+ target.origin == document.location.origin and
+ # Clicking the link will change the url of this frame.
+ (target.pathName != document.location.pathName or
+ target.search != document.location.search) and
+ (target.target in ["", "_self"] or
+ (target.target == "_parent" and window.parent == window) or
+ (target.target == "_top" and window.top == window))
+ return new GrabBackFocus()
+ else
+ target = target.parentElement
+ true
+
# Only exported for tests.
window.initializeModes = ->
class NormalMode extends Mode