Skip to content

Commit

Permalink
fix ariatemplates#951 Enable back test.aria.templates.keyboardNavigat…
Browse files Browse the repository at this point in the history
…ion.TableNavTestCase on IE <= 8

This commit is a new fix for the issue that commit 8fcb182
tried to solve, and which was reverted in commit 82b8cbf.
  • Loading branch information
divdavem committed Feb 7, 2014
1 parent 7f4f296 commit 2c1141e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/aria/templates/TemplateCtxt.js
Expand Up @@ -1463,9 +1463,7 @@
* @implements aria.templates.ITemplate
*/
$focus : function (idArray) {
if (aria.core.Browser.isIE7 || aria.core.Browser.isIE8) {
Aria.$window.document.body.focus();
}
aria.utils.Delegate.ieFocusFix();
var idToFocus;
if (aria.utils.Type.isArray(idArray)) {
idArray = idArray.slice(0);
Expand Down
30 changes: 30 additions & 0 deletions src/aria/utils/Delegate.js
Expand Up @@ -37,6 +37,12 @@ Aria.classDefinition({
},
$constructor : function () {

/**
* This variable is set to true on IE 7 and 8 when the focused element was just removed from the DOM.
* @type Boolean
*/
this._focusedElementRemoved = false;

/**
* Number of level up to look delegated element. -1 will go to the top.
* @type Number
Expand Down Expand Up @@ -573,6 +579,7 @@ Aria.classDefinition({

// focus tracking
if (evt.type == "focus") {
this._focusedElementRemoved = false;
this._focusTracking = evt.target;
if (this._focusTracking && ATflag) {

Expand Down Expand Up @@ -625,6 +632,29 @@ Aria.classDefinition({
*/
getFocus : function () {
return this._focusTracking;
},

/**
* This method is intended to be called before focusing any DOM element to apply a work-around for an issue on
* IE 7 and 8. It gives the focus to document.body if the last focused element was removed from the DOM.<br>
* If the work-around is not applied, on IE 7 and 8, after removing from the DOM a focused element, the next
* call to the focus method on a DOM element does not work correctly.
*/
ieFocusFix : function () {
if (this._focusedElementRemoved) {
Aria.$window.document.body.focus();
this._focusedElementRemoved = false;
}
},

/**
* This method is intended to be called only on IE 7 and 8 in order notify this class that a focused element was
* removed from the DOM. Then, the next time the ieFocusFix method is called, a work-around is applied (which is
* to give the focus to document.body). This method is automatically called from aria.utils.Dom.replaceHTML when
* it is needed, so in most cases, there is no need to call it directly.
*/
ieRemovingFocusedElement : function () {
this._focusedElementRemoved = true;
}
}
});
9 changes: 9 additions & 0 deletions src/aria/utils/Dom.js
Expand Up @@ -219,6 +219,15 @@ Aria.classDefinition({
domElt = this.getElementById(domElt);
}
if (domElt) {
if ((aria.core.Browser.isIE7 || aria.core.Browser.isIE8) && aria.utils && aria.utils.Delegate) {
var activeElement = Aria.$window.document.activeElement;
if (activeElement && this.isAncestor(activeElement, domElt)) {
// On IE 7-8, there is an issue after removing from the DOM a focused element.
// We detect it here so that next time there is a need to focus an element, we focus the body
// first (which is the work-around for IE 7-8)
aria.utils.Delegate.ieRemovingFocusedElement();
}
}
// PROFILING // var msr2 = this.$startMeasure("RemoveHTML");
// TODO: check HTML for security (no script ...)
try {
Expand Down
3 changes: 0 additions & 3 deletions test/aria/templates/keyboardNavigation/TableNavTestCase.js
Expand Up @@ -39,9 +39,6 @@ Aria.classDefinition({
},
runTemplateTest : function () {

if (aria.core.Browser.isIE8 || aria.core.Browser.isIE7) {
this.notifyTemplateTestEnd(); // FIXME!! PTR 06248406
}
// clean what was before
this._disposeTestTemplate();

Expand Down

0 comments on commit 2c1141e

Please sign in to comment.