diff --git a/CHANGES.md b/CHANGES.md index 2289d0bc285cc2e52bebcc76db145d9e240cf56b..dce59a68491e68e84e4cd35a4fb0977080e57fd5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2017-09-25 - Improved catching shortcuts feature to prevent the catching when form elements are focused. * 2017-09-22 - Check if user is logged in before showing the switched role information box. ### Release v3.2-r3 diff --git a/amd/build/catchshortcuts.min.js b/amd/build/catchshortcuts.min.js index abc970c4978f4a2712d6217746d2e96f6b2199c2..24aa6e99995eff5a4a623a864dfa45f37a24a6bd 100644 --- a/amd/build/catchshortcuts.min.js +++ b/amd/build/catchshortcuts.min.js @@ -1 +1 @@ -define(["jquery"],function(a){"use strict";function b(b){"end"==b&&a(document).keydown(function(a){35==a.keyCode&&c(a)}),navigator.appVersion.indexOf("Mac")!=-1&&"cmdarrowdown"==b&&a(document).keydown(function(a){40==a.keyCode&&a.metaKey&&c(a)}),navigator.appVersion.indexOf("Win")!=-1&&"ctrlarrowdown"==b&&a(document).keydown(function(a){40==a.keyCode&&a.ctrlKey&&c(a)})}function c(b){b.preventDefault(),a("html, body").animate({scrollTop:a("#page-footer").offset().top-a(window).height()+50},500)}return{init:function(a){for(var c=0,d=a.length;c<d;c++)b(a[c])}}}); \ No newline at end of file +define(["jquery"],function(a){"use strict";function b(b){"end"==b&&a(document).keydown(function(a){35==a.keyCode&&1!=d()&&c(a)}),navigator.appVersion.indexOf("Mac")!=-1&&"cmdarrowdown"==b&&a(document).keydown(function(a){40==a.keyCode&&a.metaKey&&1!=d()&&c(a)}),navigator.appVersion.indexOf("Win")!=-1&&"ctrlarrowdown"==b&&a(document).keydown(function(a){40==a.keyCode&&a.ctrlKey&&1!=d()&&c(a)})}function c(b){b.preventDefault(),a("html, body").animate({scrollTop:a("#page-footer").offset().top-a(window).height()+50},500)}function d(){var a=document.activeElement.tagName,b=!1;return"INPUT"!=a&&"TEXTAREA"!=a||(b=!0),b}return{init:function(a){for(var c=0,d=a.length;c<d;c++)b(a[c])}}}); \ No newline at end of file diff --git a/amd/src/catchshortcuts.js b/amd/src/catchshortcuts.js index bbfdf8f250b7ecf7ad6526fe0bb0b009a5a2a24c..c39543ef5416bd6e82032b93e00eb0734033465a 100644 --- a/amd/src/catchshortcuts.js +++ b/amd/src/catchshortcuts.js @@ -34,8 +34,11 @@ define(['jquery'], function($) { // Catch the end key to be able to change the behavior. $(document).keydown(function(e) { if (e.keyCode == 35) { - // Scroll only to the bottom of the course content. - scrollToBottomOfCourse(e); + // Additionally check no active focus in form elements. + if (checkForActiveFormElement() != true) { + // Scroll only to the bottom of the course content. + scrollToBottomOfCourse(e); + } } }); } @@ -44,8 +47,11 @@ define(['jquery'], function($) { // Bind the cmd + arrow down shortcut to be able to change the behavior. $(document).keydown(function(e) { if (e.keyCode == 40 && e.metaKey) { - // Scroll only to the bottom of the course content. - scrollToBottomOfCourse(e); + // Additionally check no active focus in form elements. + if (checkForActiveFormElement() != true) { + // Scroll only to the bottom of the course content. + scrollToBottomOfCourse(e); + } } }); } @@ -54,8 +60,11 @@ define(['jquery'], function($) { // Bind the ctrl + arrow down shortcut to be able to change the behavior. $(document).keydown(function(e) { if (e.keyCode == 40 && e.ctrlKey) { - // Scroll only to the bottom of the course content. - scrollToBottomOfCourse(e); + // Additionally check no active focus in form elements. + if (checkForActiveFormElement() != true) { + // Scroll only to the bottom of the course content. + scrollToBottomOfCourse(e); + } } }); } @@ -75,6 +84,22 @@ define(['jquery'], function($) { }, 500); } + /** + * Function to check for an active form element. + * + * @return boolean + */ + function checkForActiveFormElement() { + // Get the active Element for the current page. + var activeElement = document.activeElement.tagName; + var returnvalue = false; + // Check if the given active element is an input field or a textarea. + if (activeElement == 'INPUT' || activeElement == 'TEXTAREA') { + returnvalue = true; + } + return returnvalue; + } + return { init: function(params) { for (var i = 0, len = params.length; i < len; i++) {