mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
MDL-51983 actionmenu: stop event propagation
Stop event propagation on keyboard events that have been successfully handled by the action menu code.
This commit is contained in:
parent
4cef723c22
commit
4456c306df
@ -317,18 +317,22 @@ ACTIONMENU.prototype = {
|
||||
*/
|
||||
handleKeyboardEvent: function(e) {
|
||||
var next;
|
||||
var markEventHandled = function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
// Handle when the menu is still selected.
|
||||
if (e.currentTarget.ancestor(SELECTOR.TOGGLE, true)) {
|
||||
if ((e.keyCode === 40 || (e.keyCode === 9 && !e.shiftKey)) && this.firstMenuChild) {
|
||||
this.firstMenuChild.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.keyCode === 38 && this.lastMenuChild) {
|
||||
this.lastMenuChild.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.keyCode === 9 && e.shiftKey) {
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -336,11 +340,11 @@ ACTIONMENU.prototype = {
|
||||
if (e.keyCode === 27) {
|
||||
// The escape key was pressed so close the menu.
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
|
||||
} else if (e.keyCode === 32) {
|
||||
// The space bar was pressed. Trigger a click.
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
e.currentTarget.simulate('click');
|
||||
} else if (e.keyCode === 9) {
|
||||
// The tab key was pressed. Tab moves forwards, Shift + Tab moves backwards through the menu options.
|
||||
@ -348,13 +352,14 @@ ACTIONMENU.prototype = {
|
||||
// focus is moved to.
|
||||
if (e.target === this.firstMenuChild && e.shiftKey) {
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.target === this.lastMenuChild && !e.shiftKey) {
|
||||
if (this.hideMenu(e)) {
|
||||
// Determine the next selector and focus on it.
|
||||
next = this.menulink.next(SELECTOR.CAN_RECEIVE_FOCUS_SELECTOR);
|
||||
if (next) {
|
||||
next.focus();
|
||||
markEventHandled(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -403,7 +408,7 @@ ACTIONMENU.prototype = {
|
||||
|
||||
if (next) {
|
||||
next.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
File diff suppressed because one or more lines are too long
@ -315,18 +315,22 @@ ACTIONMENU.prototype = {
|
||||
*/
|
||||
handleKeyboardEvent: function(e) {
|
||||
var next;
|
||||
var markEventHandled = function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
// Handle when the menu is still selected.
|
||||
if (e.currentTarget.ancestor(SELECTOR.TOGGLE, true)) {
|
||||
if ((e.keyCode === 40 || (e.keyCode === 9 && !e.shiftKey)) && this.firstMenuChild) {
|
||||
this.firstMenuChild.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.keyCode === 38 && this.lastMenuChild) {
|
||||
this.lastMenuChild.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.keyCode === 9 && e.shiftKey) {
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -334,11 +338,11 @@ ACTIONMENU.prototype = {
|
||||
if (e.keyCode === 27) {
|
||||
// The escape key was pressed so close the menu.
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
|
||||
} else if (e.keyCode === 32) {
|
||||
// The space bar was pressed. Trigger a click.
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
e.currentTarget.simulate('click');
|
||||
} else if (e.keyCode === 9) {
|
||||
// The tab key was pressed. Tab moves forwards, Shift + Tab moves backwards through the menu options.
|
||||
@ -346,13 +350,14 @@ ACTIONMENU.prototype = {
|
||||
// focus is moved to.
|
||||
if (e.target === this.firstMenuChild && e.shiftKey) {
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.target === this.lastMenuChild && !e.shiftKey) {
|
||||
if (this.hideMenu(e)) {
|
||||
// Determine the next selector and focus on it.
|
||||
next = this.menulink.next(SELECTOR.CAN_RECEIVE_FOCUS_SELECTOR);
|
||||
if (next) {
|
||||
next.focus();
|
||||
markEventHandled(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -400,7 +405,7 @@ ACTIONMENU.prototype = {
|
||||
|
||||
if (next) {
|
||||
next.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
19
lib/yui/src/actionmenu/js/actionmenu.js
vendored
19
lib/yui/src/actionmenu/js/actionmenu.js
vendored
@ -315,18 +315,22 @@ ACTIONMENU.prototype = {
|
||||
*/
|
||||
handleKeyboardEvent: function(e) {
|
||||
var next;
|
||||
var markEventHandled = function(e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
};
|
||||
|
||||
// Handle when the menu is still selected.
|
||||
if (e.currentTarget.ancestor(SELECTOR.TOGGLE, true)) {
|
||||
if ((e.keyCode === 40 || (e.keyCode === 9 && !e.shiftKey)) && this.firstMenuChild) {
|
||||
this.firstMenuChild.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.keyCode === 38 && this.lastMenuChild) {
|
||||
this.lastMenuChild.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.keyCode === 9 && e.shiftKey) {
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
@ -334,11 +338,11 @@ ACTIONMENU.prototype = {
|
||||
if (e.keyCode === 27) {
|
||||
// The escape key was pressed so close the menu.
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
|
||||
} else if (e.keyCode === 32) {
|
||||
// The space bar was pressed. Trigger a click.
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
e.currentTarget.simulate('click');
|
||||
} else if (e.keyCode === 9) {
|
||||
// The tab key was pressed. Tab moves forwards, Shift + Tab moves backwards through the menu options.
|
||||
@ -346,13 +350,14 @@ ACTIONMENU.prototype = {
|
||||
// focus is moved to.
|
||||
if (e.target === this.firstMenuChild && e.shiftKey) {
|
||||
this.hideMenu(e);
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
} else if (e.target === this.lastMenuChild && !e.shiftKey) {
|
||||
if (this.hideMenu(e)) {
|
||||
// Determine the next selector and focus on it.
|
||||
next = this.menulink.next(SELECTOR.CAN_RECEIVE_FOCUS_SELECTOR);
|
||||
if (next) {
|
||||
next.focus();
|
||||
markEventHandled(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -401,7 +406,7 @@ ACTIONMENU.prototype = {
|
||||
|
||||
if (next) {
|
||||
next.focus();
|
||||
e.preventDefault();
|
||||
markEventHandled(e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user