File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -261,8 +261,22 @@ function pjax(options) {
261261 window . history . replaceState ( pjax . state , container . title , container . url )
262262 }
263263
264+ // Clear out any focused controls before inserting new page contents.
265+ document . activeElement . blur ( )
266+
264267 if ( container . title ) document . title = container . title
265268 context . html ( container . contents )
269+
270+ // FF bug: Won't autofocus fields that are inserted via JS.
271+ // This behavior is incorrect. So if theres no current focus, autofocus
272+ // the last field.
273+ //
274+ // http://www.w3.org/html/wg/drafts/html/master/forms.html
275+ var autofocusEl = context . find ( 'input[autofocus], textarea[autofocus]' ) . last ( ) [ 0 ]
276+ if ( autofocusEl && document . activeElement !== autofocusEl ) {
277+ autofocusEl . focus ( ) ;
278+ }
279+
266280 executeScriptTags ( container . scripts )
267281
268282 // Scroll to top by default
You can’t perform that action at this time.
0 commit comments