From 7efab51a7edbb42886f78bce97d2e7c6ebcde973 Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Mon, 28 Jan 2013 10:35:26 +0000 Subject: [PATCH] MDL-34671 Stop browser receiving escape keydown in modal dialogues In certain modal dialogues, we listen on the Escape key to close a dialogue. However, this is still passed to the browser. As a result, if the browser is in full screen mode and that browser respects the escape key as a means to exit full screen. As a result, we need to ensure that we listen for the escape key at keydown rather than keyup, and additionally prevent the default browser behaviour. This is a workaround to http://yuilibrary.com/projects/yui3/ticket/2532616 and, should that issue be fixed, it should be removed. --- course/yui/toolboxes/toolboxes.js | 5 +++-- lib/yui/chooserdialogue/chooserdialogue.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/course/yui/toolboxes/toolboxes.js b/course/yui/toolboxes/toolboxes.js index cdb20206b53..7304fceb329 100644 --- a/course/yui/toolboxes/toolboxes.js +++ b/course/yui/toolboxes/toolboxes.js @@ -557,8 +557,9 @@ YUI.add('moodle-course-toolboxes', function(Y) { // Cancel the edit if we lose focus or the escape key is pressed thisevent = editor.on('blur', cancel_edittitle); listenevents.push(thisevent); - thisevent = Y.one('document').on('keyup', function(e) { - if (e.keyCode == 27) { + thisevent = Y.one('document').on('keydown', function(e) { + if (e.keyCode === 27) { + e.preventDefault(); cancel_edittitle(e); } }); diff --git a/lib/yui/chooserdialogue/chooserdialogue.js b/lib/yui/chooserdialogue/chooserdialogue.js index 03a19cf45e8..8627b5afabd 100644 --- a/lib/yui/chooserdialogue/chooserdialogue.js +++ b/lib/yui/chooserdialogue/chooserdialogue.js @@ -143,7 +143,7 @@ YUI.add('moodle-core-chooserdialogue', function(Y) { this.listenevents.push(thisevent); // Grab global keyup events and handle them - thisevent = Y.one('document').on('keyup', this.handle_key_press, this); + thisevent = Y.one('document').on('keydown', this.handle_key_press, this); this.listenevents.push(thisevent); // Add references to various elements we adjust