|
2 | 2 | var focusableElementsSelector = "a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]"; |
3 | 3 |
|
4 | 4 | // Based on the incredible accessible modal dialog. |
5 | | - window.AccessibleDialog = function(modalDiv, $returnElement, dialogRole, isModal, title, $descDiv, closeButtonLabel, width, fullscreen, escapeHook) { |
| 5 | + window.AccessibleDialog = function( modalDiv, $returnElement, title, closeButtonLabel) { |
6 | 6 |
|
7 | 7 | this.title = title; |
8 | 8 | this.closeButtonLabel = closeButtonLabel; |
9 | 9 | this.focusedElementBeforeModal = $returnElement; |
10 | | - this.escapeHook = escapeHook; |
11 | 10 | this.baseId = $(modalDiv).attr('id') || Math.floor(Math.random() * 1000000000).toString(); |
12 | 11 | var thisObj = this; |
13 | 12 | var modal = modalDiv; |
14 | 13 | this.modal = modal; |
15 | | - if ( width ) { |
16 | | - modal.css({ |
17 | | - 'width': width |
18 | | - }); |
19 | | - } |
| 14 | + |
20 | 15 | modal.addClass('able-modal-dialog'); |
21 | 16 |
|
22 | | - if (!fullscreen) { |
23 | | - var closeButton = $('<button>',{ |
24 | | - 'class': 'modalCloseButton', |
25 | | - 'title': thisObj.closeButtonLabel, |
26 | | - 'aria-label': thisObj.closeButtonLabel |
27 | | - }).text('×'); |
28 | | - closeButton.on( 'keydown', function (e) { |
29 | | - if (e.key === ' ') { |
30 | | - thisObj.hide(); |
31 | | - } |
32 | | - }).on( 'click', function () { |
| 17 | + var closeButton = $('<button>',{ |
| 18 | + 'class': 'modalCloseButton', |
| 19 | + 'title': thisObj.closeButtonLabel, |
| 20 | + 'aria-label': thisObj.closeButtonLabel |
| 21 | + }).text('×'); |
| 22 | + closeButton.on( 'keydown', function (e) { |
| 23 | + if (e.key === ' ') { |
33 | 24 | thisObj.hide(); |
34 | | - }); |
| 25 | + } |
| 26 | + }).on( 'click', function () { |
| 27 | + thisObj.hide(); |
| 28 | + }); |
35 | 29 |
|
36 | | - var titleH1 = $('<h1></h1>'); |
37 | | - titleH1.attr('id', 'modalTitle-' + this.baseId); |
38 | | - titleH1.text(title); |
39 | | - this.titleH1 = titleH1; |
| 30 | + var titleH1 = $('<h1></h1>'); |
| 31 | + titleH1.attr('id', 'modalTitle-' + this.baseId); |
| 32 | + titleH1.text(title); |
| 33 | + this.titleH1 = titleH1; |
40 | 34 |
|
41 | | - modal.attr({ |
42 | | - 'aria-labelledby': 'modalTitle-' + this.baseId, |
43 | | - }); |
44 | | - var modalHeader = $( '<div>', { |
45 | | - 'class': 'able-modal-header' |
46 | | - }); |
47 | | - modalHeader.prepend(titleH1); |
48 | | - modalHeader.prepend(closeButton); |
49 | | - modal.prepend(modalHeader); |
50 | | - } |
| 35 | + modal.attr({ |
| 36 | + 'aria-labelledby': 'modalTitle-' + this.baseId, |
| 37 | + }); |
| 38 | + var modalHeader = $( '<div>', { |
| 39 | + 'class': 'able-modal-header' |
| 40 | + }); |
| 41 | + modalHeader.prepend(titleH1); |
| 42 | + modalHeader.prepend(closeButton); |
| 43 | + modal.prepend(modalHeader); |
51 | 44 |
|
52 | 45 | modal.attr({ |
53 | 46 | 'aria-hidden': 'true', |
54 | | - 'role': dialogRole, |
| 47 | + 'role': 'dialog', |
| 48 | + 'aria-modal': 'true' |
55 | 49 | }); |
56 | | - if (isModal) { |
57 | | - modal.attr('aria-modal','true'); |
58 | | - } |
59 | 50 |
|
60 | 51 | modal.on( 'keydown', function (e) { |
61 | 52 | if (e.key === 'Escape') { |
62 | | - if (thisObj.escapeHook) { |
63 | | - thisObj.escapeHook(e, this); |
64 | | - } else { |
65 | | - thisObj.hide(); |
66 | | - e.preventDefault(); |
67 | | - } |
| 53 | + thisObj.hide(); |
| 54 | + e.preventDefault(); |
68 | 55 | } else if (e.key === 'Tab') { |
69 | 56 | // Manually loop tab navigation inside the modal. |
70 | 57 | var parts = modal.find('*'); |
|
0 commit comments