Skip to content

Commit

Permalink
Check for addEventListener before tying to use to support IE 8
Browse files Browse the repository at this point in the history
  • Loading branch information
amccloud committed Feb 16, 2015
1 parent 6fd8456 commit c464368
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions lib/helpers/focusManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,26 @@ exports.returnFocus = function() {

exports.setupScopedFocus = function(element) {
modalElement = element;
window.addEventListener('blur', handleBlur, false);
document.addEventListener('focus', handleFocus, true);

if (window.addEventListener) {
window.addEventListener('blur', handleBlur, false);
document.addEventListener('focus', handleFocus, true);
} else {
window.attachEvent('onBlur', handleBlur);
document.attachEvent('onFocus', handleFocus);
}
};

exports.teardownScopedFocus = function() {
modalElement = null;
window.removeEventListener('blur', handleBlur);
document.removeEventListener('focus', handleFocus);

if (window.addEventListener) {
window.removeEventListener('blur', handleBlur);
document.removeEventListener('focus', handleFocus);
} else {
window.detachEvent('onBlur', handleBlur);
document.detachEvent('onFocus', handleFocus);
}
};


0 comments on commit c464368

Please sign in to comment.