mourningdove/htdocs/js/skins/jquery.focus-on-reveal.js

25 lines
755 B
JavaScript
Raw Permalink Normal View History

2026-05-24 01:03:05 +00:00
jQuery(document).ready(function($) {
// save previously focused item when we open
$(document).on('open.fndtn.reveal', '[data-reveal]', function () {
var $modal = $(this);
$modal.data( "previously_focused", $( ":focus" ) );
});
// focus on the first input, for keyboard users
$(document).on('opened.fndtn.reveal', '[data-reveal]', function () {
var $modal = $(this);
$modal.data( "previously_focused", $( ":focus" ) );
$modal.find( "input:visible:first" ).focus();
});
// switch back focus
$(document).on('closed.fndtn.reveal', '[data-reveal]', function () {
var $modal = $(this);
var focused = $modal.data( "previously_focused" );
$(focused).focus();
} );
});