Run eslint autofixer on /common
This commit is contained in:
@@ -36,90 +36,89 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
var focusedElementBeforeModal;
|
||||
|
||||
var accessible_modal = function(trigger, closeButtonId, modalId, mainPageId) {
|
||||
|
||||
// Modifies a lean modal to optimize focus management.
|
||||
// "trigger" is the selector for the link element that triggers the modal.
|
||||
// "closeButtonId" is the selector for the button that closes out the modal.
|
||||
// "modalId" is the selector for the modal being managed
|
||||
// "mainPageId" is the selector for the main part of the page
|
||||
//
|
||||
//
|
||||
// based on http://accessibility.oit.ncsu.edu/training/aria/modal-window/modal-window.js
|
||||
//
|
||||
//
|
||||
// see http://accessibility.oit.ncsu.edu/blog/2013/09/13/the-incredible-accessible-modal-dialog/
|
||||
// for more information on managing modals
|
||||
//
|
||||
var focusableElementsString = "a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]";
|
||||
//
|
||||
var focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]';
|
||||
|
||||
$(trigger).click(function(){
|
||||
focusedElementBeforeModal = $(trigger);
|
||||
$(trigger).click(function() {
|
||||
focusedElementBeforeModal = $(trigger);
|
||||
|
||||
// when modal is opened, adjust tabindexes and aria-hidden attributes
|
||||
$(mainPageId).attr("aria-hidden", "true");
|
||||
$(modalId).attr("aria-hidden", "false");
|
||||
|
||||
var focusableItems = $(modalId).find("*").filter(focusableElementsString).filter(':visible');
|
||||
|
||||
focusableItems.attr("tabindex", "2");
|
||||
$(closeButtonId).attr("tabindex", "1");
|
||||
$(closeButtonId).focus()
|
||||
$(mainPageId).attr('aria-hidden', 'true');
|
||||
$(modalId).attr('aria-hidden', 'false');
|
||||
|
||||
var focusableItems = $(modalId).find('*').filter(focusableElementsString).filter(':visible');
|
||||
|
||||
focusableItems.attr('tabindex', '2');
|
||||
$(closeButtonId).attr('tabindex', '1');
|
||||
$(closeButtonId).focus();
|
||||
|
||||
// define the last tabbable element to complete tab cycle
|
||||
var last;
|
||||
if (focusableItems.length !== 0) {
|
||||
last = focusableItems.last();
|
||||
} else {
|
||||
last = $(closeButtonId);
|
||||
};
|
||||
var last;
|
||||
if (focusableItems.length !== 0) {
|
||||
last = focusableItems.last();
|
||||
} else {
|
||||
last = $(closeButtonId);
|
||||
}
|
||||
|
||||
// tab on last element in modal returns to the first one
|
||||
last.on('keydown', function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
last.on('keydown', function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
// 9 is the js keycode for tab
|
||||
if (!e.shiftKey && keyCode === 9) {
|
||||
e.preventDefault();
|
||||
$(closeButtonId).focus();
|
||||
}
|
||||
});
|
||||
if (!e.shiftKey && keyCode === 9) {
|
||||
e.preventDefault();
|
||||
$(closeButtonId).focus();
|
||||
}
|
||||
});
|
||||
|
||||
// shift+tab on first element in modal returns to the last one
|
||||
$(closeButtonId).on('keydown', function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
$(closeButtonId).on('keydown', function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
// 9 is the js keycode for tab
|
||||
if (e.shiftKey && keyCode == 9) {
|
||||
e.preventDefault();
|
||||
last.focus();
|
||||
}
|
||||
});
|
||||
if (e.shiftKey && keyCode == 9) {
|
||||
e.preventDefault();
|
||||
last.focus();
|
||||
}
|
||||
});
|
||||
|
||||
// manage aria-hidden attrs, return focus to trigger on close
|
||||
$("#lean_overlay, " + closeButtonId).click(function(){
|
||||
$(mainPageId).attr("aria-hidden", "false");
|
||||
$(modalId).attr("aria-hidden", "true");
|
||||
focusedElementBeforeModal.focus();
|
||||
});
|
||||
$('#lean_overlay, ' + closeButtonId).click(function() {
|
||||
$(mainPageId).attr('aria-hidden', 'false');
|
||||
$(modalId).attr('aria-hidden', 'true');
|
||||
focusedElementBeforeModal.focus();
|
||||
});
|
||||
|
||||
// get modal to exit on escape key
|
||||
$(".modal").on("keydown", function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
$('.modal').on('keydown', function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
// 27 is the javascript keycode for the ESC key
|
||||
if (keyCode === 27) {
|
||||
e.preventDefault();
|
||||
$(closeButtonId).click();
|
||||
}
|
||||
});
|
||||
if (keyCode === 27) {
|
||||
e.preventDefault();
|
||||
$(closeButtonId).click();
|
||||
}
|
||||
});
|
||||
|
||||
// In IE, focus shifts to iframes when they load.
|
||||
// These lines ensure that focus is shifted back to the close button
|
||||
// in the case that a modal that contains an iframe is opened in IE.
|
||||
// see http://stackoverflow.com/questions/15792620/how-to-get-focus-back-for-parent-window-from-an-iframe-programmatically-in-javas
|
||||
var initialFocus = true
|
||||
$(modalId).find("iframe").on("focus", function() {
|
||||
if (initialFocus) {
|
||||
$(closeButtonId).focus();
|
||||
initialFocus = false;
|
||||
};
|
||||
var initialFocus = true;
|
||||
$(modalId).find('iframe').on('focus', function() {
|
||||
if (initialFocus) {
|
||||
$(closeButtonId).focus();
|
||||
initialFocus = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// NOTE: This is a gross hack to make the skip links work for Webkit browsers
|
||||
@@ -128,49 +127,47 @@ var accessible_modal = function(trigger, closeButtonId, modalId, mainPageId) {
|
||||
// handle things properly for clicks
|
||||
$('.nav-skip').click(function() {
|
||||
var href = $(this).attr('href');
|
||||
if(href) {
|
||||
if (href) {
|
||||
$(href).attr('tabIndex', -1).focus();
|
||||
}
|
||||
});
|
||||
// and for the enter key
|
||||
$('.nav-skip').keypress(function(e) {
|
||||
if(e.which == 13) {
|
||||
if (e.which == 13) {
|
||||
var href = $(this).attr('href');
|
||||
if(href) {
|
||||
if (href) {
|
||||
$(href).attr('tabIndex', -1).focus();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Creates a window level SR object that can be used for giving audible feedback to screen readers.
|
||||
$(function(){
|
||||
$(function() {
|
||||
var SRAlert;
|
||||
|
||||
SRAlert = (function() {
|
||||
function SRAlert() {
|
||||
$('body').append('<div id="reader-feedback" class="sr" style="display:none" aria-hidden="false" aria-atomic="true" aria-live="assertive"></div>');
|
||||
this.el = $('#reader-feedback');
|
||||
}
|
||||
|
||||
function SRAlert() {
|
||||
$('body').append('<div id="reader-feedback" class="sr" style="display:none" aria-hidden="false" aria-atomic="true" aria-live="assertive"></div>');
|
||||
this.el = $('#reader-feedback');
|
||||
}
|
||||
SRAlert.prototype.clear = function() {
|
||||
return this.el.html(' ');
|
||||
};
|
||||
|
||||
SRAlert.prototype.clear = function() {
|
||||
return this.el.html(' ');
|
||||
};
|
||||
SRAlert.prototype.readElts = function(elts) {
|
||||
var feedback = '';
|
||||
$.each(elts, function(idx, value) {
|
||||
return feedback += '<p>' + $(value).html() + '</p>\n';
|
||||
});
|
||||
return this.el.html(feedback);
|
||||
};
|
||||
|
||||
SRAlert.prototype.readElts = function(elts) {
|
||||
var feedback = '';
|
||||
$.each(elts, function(idx, value) {
|
||||
return feedback += '<p>' + $(value).html() + '</p>\n';
|
||||
});
|
||||
return this.el.html(feedback);
|
||||
};
|
||||
|
||||
SRAlert.prototype.readText = function(text) {
|
||||
return this.el.text(text);
|
||||
};
|
||||
|
||||
return SRAlert;
|
||||
SRAlert.prototype.readText = function(text) {
|
||||
return this.el.text(text);
|
||||
};
|
||||
|
||||
return SRAlert;
|
||||
})();
|
||||
|
||||
window.SR = new SRAlert;
|
||||
|
||||
Reference in New Issue
Block a user