aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts
diff options
context:
space:
mode:
authormrmr19932015-04-30 21:58:04 +0100
committermrmr19932015-04-30 21:58:04 +0100
commit19b33fed06ecf7d6dc6260e3f623a4190c059285 (patch)
treedc904f71452309dbf7968e096ccea8d525ac14a4 /content_scripts
parentf5a7f83f06d39bda32883c6c527ae76f16395063 (diff)
downloadvimium-19b33fed06ecf7d6dc6260e3f623a4190c059285.tar.bz2
Make GrabBackFocus work for javascript page transitions from links
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/vimium_frontend.coffee22
1 files changed, 22 insertions, 0 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 02e6c9ee..c1a205f2 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -133,6 +133,28 @@ 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.
+handlerStack.push
+ click: (event) ->
+ 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