MDL-44868 editor_atto: Toolbar navigation ignores disabled buttons

This commit is contained in:
Frederic Massart
2014-03-31 16:40:29 +08:00
parent adb2473a2b
commit af31595b4b
4 changed files with 79 additions and 35 deletions
@@ -748,6 +748,8 @@ EditorToolbarNav.prototype = {
direction = 1,
checkCount = 0,
group,
candidate,
button,
current = e.target.ancestor('button', true);
// Determine which button is currently selected.
@@ -770,7 +772,7 @@ EditorToolbarNav.prototype = {
}
// Try to find the next
do {
while (checkCount < buttons.size()) {
index += direction;
if (index < 0) {
index = buttons.size() - 1;
@@ -778,20 +780,33 @@ EditorToolbarNav.prototype = {
// Handle wrapping.
index = 0;
}
next = buttons.item(index);
group = next.ancestor('.atto_group');
candidate = buttons.item(index);
// Add a counter to ensure we don't get stuck in a loop if there's only one visible menu item.
checkCount++;
// Loop while:
// * we are not in a loop and have not already checked every button; and
// * we are on a different button; and
// * both the next button and the group it is in are not hidden.
} while (checkCount < buttons.size() && next !== current && (next.hasAttribute('hidden') || group.hasAttribute('hidden')));
if (next) {
next.focus();
this._setTabFocus(next);
// Loop while:
// * we haven't checked every button;
// * the button is hidden or disabled;
// * the group is hidden.
if (candidate.hasAttribute('hidden') || candidate.hasAttribute('disabled')) {
continue;
}
group = candidate.ancestor('.atto_group');
if (group.hasAttribute('hidden')) {
continue;
}
button = candidate;
break;
}
if (button) {
button.focus();
this._setTabFocus(button);
} else {
Y.log("Unable to find a button to focus on", 'debug', LOGNAME);
}
},
File diff suppressed because one or more lines are too long
@@ -745,6 +745,8 @@ EditorToolbarNav.prototype = {
direction = 1,
checkCount = 0,
group,
candidate,
button,
current = e.target.ancestor('button', true);
// Determine which button is currently selected.
@@ -766,7 +768,7 @@ EditorToolbarNav.prototype = {
}
// Try to find the next
do {
while (checkCount < buttons.size()) {
index += direction;
if (index < 0) {
index = buttons.size() - 1;
@@ -774,20 +776,32 @@ EditorToolbarNav.prototype = {
// Handle wrapping.
index = 0;
}
next = buttons.item(index);
group = next.ancestor('.atto_group');
candidate = buttons.item(index);
// Add a counter to ensure we don't get stuck in a loop if there's only one visible menu item.
checkCount++;
// Loop while:
// * we are not in a loop and have not already checked every button; and
// * we are on a different button; and
// * both the next button and the group it is in are not hidden.
} while (checkCount < buttons.size() && next !== current && (next.hasAttribute('hidden') || group.hasAttribute('hidden')));
if (next) {
next.focus();
this._setTabFocus(next);
// Loop while:
// * we haven't checked every button;
// * the button is hidden or disabled;
// * the group is hidden.
if (candidate.hasAttribute('hidden') || candidate.hasAttribute('disabled')) {
continue;
}
group = candidate.ancestor('.atto_group');
if (group.hasAttribute('hidden')) {
continue;
}
button = candidate;
break;
}
if (button) {
button.focus();
this._setTabFocus(button);
} else {
}
},
+26 -11
View File
@@ -78,6 +78,8 @@ EditorToolbarNav.prototype = {
direction = 1,
checkCount = 0,
group,
candidate,
button,
current = e.target.ancestor('button', true);
// Determine which button is currently selected.
@@ -100,7 +102,7 @@ EditorToolbarNav.prototype = {
}
// Try to find the next
do {
while (checkCount < buttons.size()) {
index += direction;
if (index < 0) {
index = buttons.size() - 1;
@@ -108,20 +110,33 @@ EditorToolbarNav.prototype = {
// Handle wrapping.
index = 0;
}
next = buttons.item(index);
group = next.ancestor('.atto_group');
candidate = buttons.item(index);
// Add a counter to ensure we don't get stuck in a loop if there's only one visible menu item.
checkCount++;
// Loop while:
// * we are not in a loop and have not already checked every button; and
// * we are on a different button; and
// * both the next button and the group it is in are not hidden.
} while (checkCount < buttons.size() && next !== current && (next.hasAttribute('hidden') || group.hasAttribute('hidden')));
if (next) {
next.focus();
this._setTabFocus(next);
// Loop while:
// * we haven't checked every button;
// * the button is hidden or disabled;
// * the group is hidden.
if (candidate.hasAttribute('hidden') || candidate.hasAttribute('disabled')) {
continue;
}
group = candidate.ancestor('.atto_group');
if (group.hasAttribute('hidden')) {
continue;
}
button = candidate;
break;
}
if (button) {
button.focus();
this._setTabFocus(button);
} else {
Y.log("Unable to find a button to focus on", 'debug', LOGNAME);
}
},