Skip to content

Commit

Permalink
fixes #519: ie8 bug with iframe & activeElement
Browse files Browse the repository at this point in the history
  • Loading branch information
amsul committed Oct 4, 2014
1 parent a797d46 commit b71f925
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {

// Confirm focus state, convert into text input to remove UA stylings,
// and set as readonly to prevent keyboard popup.
ELEMENT.autofocus = ELEMENT == document.activeElement
ELEMENT.autofocus = ELEMENT == getActiveElement()
ELEMENT.readOnly = !SETTINGS.editable
ELEMENT.id = ELEMENT.id || STATE.id
if ( ELEMENT.type != 'text' ) {
Expand Down Expand Up @@ -700,8 +700,8 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {

// * For IE, non-focusable elements can be active elements as well
// (http://stackoverflow.com/a/2684561).
activeElement = document.activeElement
activeElement = activeElement && ( activeElement.type || activeElement.href ) && activeElement
activeElement = getActiveElement()
activeElement = activeElement && ( activeElement.type || activeElement.href )

// If it’s disabled or nothing inside is actively focused, re-focus the element.
if ( targetDisabled || activeElement && !$.contains( P.$root[0], activeElement ) ) {
Expand Down Expand Up @@ -1103,6 +1103,13 @@ function ariaAttr(attribute, data) {
return data
}

// IE8 bug throws an error for activeElements within iframes.
function getActiveElement() {
try {
return document.activeElement
} catch ( err ) { }
}



// Expose the picker constructor.
Expand Down

0 comments on commit b71f925

Please sign in to comment.