Merge branch 'MDL-44868-master' of git://github.com/FMCorz/moodle

Conflicts:
	lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js
	lib/editor/atto/yui/build/moodle-editor_atto-plugin/moodle-editor_atto-plugin-min.js
This commit is contained in:
Dan Poltawski
2014-04-08 11:37:25 +08:00
8 changed files with 250 additions and 98 deletions
@@ -746,37 +746,51 @@ EditorToolbarNav.prototype = {
// Prevent the default browser behaviour.
e.preventDefault();
var buttons = this.toolbar.all('button');
// On cursor moves we loops through the buttons.
var found = false,
index = 0,
var buttons = this.toolbar.all('button'),
direction = 1,
checkCount = 0,
group,
button,
current = e.target.ancestor('button', true);
// Determine which button is currently selected.
while (!found && index < buttons.size()) {
if (buttons.item(index) === current) {
found = true;
} else {
index++;
}
}
if (!found) {
Y.log("Unable to find this button in the list of buttons", 'debug', LOGNAME);
return;
}
if (e.keyCode === 37) {
// Moving left so reverse the direction.
direction = -1;
}
// Try to find the next
do {
button = this._findFirstFocusable(buttons, current, direction);
if (button) {
button.focus();
} else {
Y.log("Unable to find a button to focus on", 'debug', LOGNAME);
}
},
/**
* Find the first focusable button.
*
* @param {NodeList} buttons A list of nodes.
* @param {Node} startAt The node in the list to start the search from.
* @param {Number} direction The direction in which to search (1 or -1).
* @return {Node | Undefined} The Node or undefined.
* @method _findFirstFocusable
* @private
*/
_findFirstFocusable: function(buttons, startAt, direction) {
var checkCount = 0,
group,
candidate,
button,
index;
// Determine which button to start the search from.
index = buttons.indexOf(startAt);
if (index < -1) {
Y.log("Unable to find the button in the list of buttons", 'debug', LOGNAME);
index = 0;
}
// Try to find the next.
while (checkCount < buttons.size()) {
index += direction;
if (index < 0) {
index = buttons.size() - 1;
@@ -784,21 +798,57 @@ 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;
}
return button;
},
/**
* Check the tab focus.
*
* When we disable or hide a button, we should call this method to ensure that the
* focus is not currently set on an inaccessible button, otherwise tabbing to the toolbar
* would be impossible.
*
* @method checkTabFocus
* @chainable
*/
checkTabFocus: function() {
if (this._tabFocus) {
if (this._tabFocus.hasAttribute('disabled') || this._tabFocus.hasAttribute('hidden')
|| this._tabFocus.ancestor('.atto_group').hasAttribute('hidden')) {
// Find first available button.
button = this._findFirstFocusable(this.toolbar.all('button'), this._tabFocus, -1);
if (button) {
if (this._tabFocus.compareTo(document.activeElement)) {
// We should also move the focus, because the inaccessible button also has the focus.
button.focus();
}
this._setTabFocus(button);
}
}
}
return this;
},
/**
File diff suppressed because one or more lines are too long
@@ -743,36 +743,49 @@ EditorToolbarNav.prototype = {
// Prevent the default browser behaviour.
e.preventDefault();
var buttons = this.toolbar.all('button');
// On cursor moves we loops through the buttons.
var found = false,
index = 0,
var buttons = this.toolbar.all('button'),
direction = 1,
checkCount = 0,
group,
button,
current = e.target.ancestor('button', true);
// Determine which button is currently selected.
while (!found && index < buttons.size()) {
if (buttons.item(index) === current) {
found = true;
} else {
index++;
}
}
if (!found) {
return;
}
if (e.keyCode === 37) {
// Moving left so reverse the direction.
direction = -1;
}
// Try to find the next
do {
button = this._findFirstFocusable(buttons, current, direction);
if (button) {
button.focus();
} else {
}
},
/**
* Find the first focusable button.
*
* @param {NodeList} buttons A list of nodes.
* @param {Node} startAt The node in the list to start the search from.
* @param {Number} direction The direction in which to search (1 or -1).
* @return {Node | Undefined} The Node or undefined.
* @method _findFirstFocusable
* @private
*/
_findFirstFocusable: function(buttons, startAt, direction) {
var checkCount = 0,
group,
candidate,
button,
index;
// Determine which button to start the search from.
index = buttons.indexOf(startAt);
if (index < -1) {
index = 0;
}
// Try to find the next.
while (checkCount < buttons.size()) {
index += direction;
if (index < 0) {
index = buttons.size() - 1;
@@ -780,21 +793,57 @@ 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;
}
return button;
},
/**
* Check the tab focus.
*
* When we disable or hide a button, we should call this method to ensure that the
* focus is not currently set on an inaccessible button, otherwise tabbing to the toolbar
* would be impossible.
*
* @method checkTabFocus
* @chainable
*/
checkTabFocus: function() {
if (this._tabFocus) {
if (this._tabFocus.hasAttribute('disabled') || this._tabFocus.hasAttribute('hidden')
|| this._tabFocus.ancestor('.atto_group').hasAttribute('hidden')) {
// Find first available button.
button = this._findFirstFocusable(this.toolbar.all('button'), this._tabFocus, -1);
if (button) {
if (this._tabFocus.compareTo(document.activeElement)) {
// We should also move the focus, because the inaccessible button also has the focus.
button.focus();
}
this._setTabFocus(button);
}
}
}
return this;
},
/**
@@ -882,6 +882,7 @@ EditorPluginButtons.prototype = {
}, this);
}
this.get('host').checkTabFocus();
return this;
},
File diff suppressed because one or more lines are too long
@@ -878,6 +878,7 @@ EditorPluginButtons.prototype = {
}, this);
}
this.get('host').checkTabFocus();
return this;
},
@@ -739,6 +739,7 @@ EditorPluginButtons.prototype = {
}, this);
}
this.get('host').checkTabFocus();
return this;
},
+82 -32
View File
@@ -70,37 +70,51 @@ EditorToolbarNav.prototype = {
// Prevent the default browser behaviour.
e.preventDefault();
var buttons = this.toolbar.all('button');
// On cursor moves we loops through the buttons.
var found = false,
index = 0,
var buttons = this.toolbar.all('button'),
direction = 1,
checkCount = 0,
group,
button,
current = e.target.ancestor('button', true);
// Determine which button is currently selected.
while (!found && index < buttons.size()) {
if (buttons.item(index) === current) {
found = true;
} else {
index++;
}
}
if (!found) {
Y.log("Unable to find this button in the list of buttons", 'debug', LOGNAME);
return;
}
if (e.keyCode === 37) {
// Moving left so reverse the direction.
direction = -1;
}
// Try to find the next
do {
button = this._findFirstFocusable(buttons, current, direction);
if (button) {
button.focus();
} else {
Y.log("Unable to find a button to focus on", 'debug', LOGNAME);
}
},
/**
* Find the first focusable button.
*
* @param {NodeList} buttons A list of nodes.
* @param {Node} startAt The node in the list to start the search from.
* @param {Number} direction The direction in which to search (1 or -1).
* @return {Node | Undefined} The Node or undefined.
* @method _findFirstFocusable
* @private
*/
_findFirstFocusable: function(buttons, startAt, direction) {
var checkCount = 0,
group,
candidate,
button,
index;
// Determine which button to start the search from.
index = buttons.indexOf(startAt);
if (index < -1) {
Y.log("Unable to find the button in the list of buttons", 'debug', LOGNAME);
index = 0;
}
// Try to find the next.
while (checkCount < buttons.size()) {
index += direction;
if (index < 0) {
index = buttons.size() - 1;
@@ -108,21 +122,57 @@ 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;
}
return button;
},
/**
* Check the tab focus.
*
* When we disable or hide a button, we should call this method to ensure that the
* focus is not currently set on an inaccessible button, otherwise tabbing to the toolbar
* would be impossible.
*
* @method checkTabFocus
* @chainable
*/
checkTabFocus: function() {
if (this._tabFocus) {
if (this._tabFocus.hasAttribute('disabled') || this._tabFocus.hasAttribute('hidden')
|| this._tabFocus.ancestor('.atto_group').hasAttribute('hidden')) {
// Find first available button.
button = this._findFirstFocusable(this.toolbar.all('button'), this._tabFocus, -1);
if (button) {
if (this._tabFocus.compareTo(document.activeElement)) {
// We should also move the focus, because the inaccessible button also has the focus.
button.focus();
}
this._setTabFocus(button);
}
}
}
return this;
},
/**