Skip to content

Commit

Permalink
Only blur/refocus elements if they are within the PJAX container.
Browse files Browse the repository at this point in the history
This can be useful if using PJAX to reload the contents of a search page, for instance.

See defunkt#377
  • Loading branch information
Stephen Gutekanst committed Jul 21, 2015
1 parent c70ffe2 commit ebaf920
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,15 @@ function pjax(options) {
window.history.replaceState(pjax.state, container.title, container.url)
}

// Only blur the focus if the focused element is within the container.
var blurFocus = $.contains(options.container, document.activeElement)

// Clear out any focused controls before inserting new page contents.
try {
document.activeElement.blur()
} catch (e) { }
if (blurFocus) {
try {
document.activeElement.blur()
} catch (e) { }
}

if (container.title) document.title = container.title

Expand Down

0 comments on commit ebaf920

Please sign in to comment.