Skip to content

Commit

Permalink
Modal Dialog Example: IE polyfill for remove and checks for focus (pull
Browse files Browse the repository at this point in the history
#343)

To fix IE issues raised by @accdc in issue #321, added polyfill for remove and checks for focus.
  • Loading branch information
tatermelon authored and mcking65 committed Mar 23, 2017
1 parent 0899241 commit 7862b13
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
8 changes: 6 additions & 2 deletions examples/dialog-modal/js/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ aria.Utils = aria.Utils || {};
* true if element is focused.
*/
aria.Utils.attemptFocus = function (element) {
if (!aria.Utils.isFocusable(element)) {
return false;
}

aria.Utils.IgnoreUtilFocusChanges = true;
try {
element.focus();
Expand Down Expand Up @@ -197,8 +201,8 @@ aria.Utils = aria.Utils || {};
aria.Dialog.prototype.close = function () {
aria.OpenDialogList.pop();
this.removeListeners();
this.preNode.remove();
this.postNode.remove();
aria.Utils.remove(this.preNode);
aria.Utils.remove(this.postNode);
this.dialogNode.className = 'hidden';
this.focusAfterClosed.focus();

Expand Down
35 changes: 35 additions & 0 deletions examples/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,41 @@ aria.Utils.matches = function (element, selector) {
return element.matches(selector);
};

aria.Utils.remove = function (item) {
if (item.remove && typeof item.remove === 'function') {
return item.remove();
}
if (item.parentNode
&& item.parentNode.removeChild
&& typeof item.parentNode.removeChild === 'function') {
return item.parentNode.removeChild(item);
}
return false;
};

aria.Utils.isFocusable = function (element) {
if (element.tabIndex > 0 || (element.tabIndex === 0 && element.getAttribute('tabIndex') !== null)) {
return true;
}

if (element.disabled) {
return false;
}

switch (element.nodeName) {
case 'A':
return !!element.href && element.rel != 'ignore';
case 'INPUT':
return element.type != 'hidden' && element.type != 'file';
case 'BUTTON':
case 'SELECT':
case 'TEXTAREA':
return true;
default:
return false;
}
};

aria.Utils.getAncestorBySelector = function (element, selector) {
if (!aria.Utils.matches(element, selector + ' ' + element.tagName)) {
// Element is not inside an element that matches selector
Expand Down

0 comments on commit 7862b13

Please sign in to comment.