Only blur element if it's contained by one of the selectors

Previously, Pjax would blur (remove focus) from the active element
regardless of where it was on the page. This restricts that to
happen only if the active element is contained by one of the
elements represented by options.selectors, because only those are
affected by Pjax.

Fixes #4
This commit is contained in:
Behind The Math
2018-01-24 20:18:41 -05:00
parent e3df2b1c3d
commit fa05e94f07
3 changed files with 30 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ var forEachEls = require("./lib/foreach-els.js")
var newUid = require("./lib/uniqueid.js")
var noop = require("./lib/util/noop")
var contains = require("./lib/util/contains.js")
var on = require("./lib/events/on.js")
// var off = require("./lib/events/on.js")
@@ -129,7 +130,7 @@ Pjax.prototype = {
// Clear out any focused controls before inserting new page contents.
// we clear focus on non form elements
if (document.activeElement && !document.activeElement.value) {
if (document.activeElement && !document.activeElement.value && contains(this.options.selectors, document.activeElement)) {
try {
document.activeElement.blur()
} catch (e) { }