diff --git a/CHANGES.md b/CHANGES.md index 46fb8de1a9993a75a8a62485168896e873bbe4e0..b6f94af9051549993fcc1b3e7c0945a99e6f4019 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2017-07-04 - Settings to be able to catch specific shortcuts to redefine the scrolling to bottom event. * 2017-07-04 - Added modification hints to overridden layout files. * 2017-07-04 - Fix CSS selector for the footer separator lines. * 2017-07-03 - Minor improvements to the availability info for activities and resources. diff --git a/README.md b/README.md index eed4aedcc7450f89630f1a06b8742145eba6fe1c..46d4d216e75fa5c59b35c4c3d25e8ba73f34f195 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,21 @@ This setting is already available in the Moodle core theme Boost. For more infor This setting is already available in the Moodle core theme Boost. For more information how to use it, please have a look at the official Moodle documentation: http://docs.moodle.org/en/Boost_theme +#### Catch keyboard commands +The following settings are intended to serve the needs for advanced users, especially if your Moodle instance has a large footer. Advanced users are likely to use keyboard shortcuts to navigate through the sites. They may use this for reaching the end of the page in the intention to get fast to the most recent topic in the course (for adding content or grading latest activities). If the footer is not quite small, they would need to scroll up again. With these settings you can enable that the following shortcuts are caught and would only scroll to the bottom of the main course content. + +##### End key + +This setting will catch the "End" key (should work on all main browsers and operating systems), prevent the default scrolling to the bottom of the web page and changes the behavior to scroll only to the bottom of the main course content. + +##### Cmd + Arrow down shortcut + +This setting will catch the "Cmd + Arrow down" shortcut (MAC), prevent the default scrolling to the bottom of the web page and changes the behavior to scroll only to the bottom of the main course content. + +##### Ctrl + Arrow down shortcut + +This setting will catch the "Ctrl + Arrow down" shortcut (Windows), prevent the default scrolling to the bottom of the web page and changes the behavior to scroll only to the bottom of the main course content. + ### 3. Tab "Course Layout Settings" diff --git a/amd/build/catchshortcuts.min.js b/amd/build/catchshortcuts.min.js new file mode 100644 index 0000000000000000000000000000000000000000..abc970c4978f4a2712d6217746d2e96f6b2199c2 --- /dev/null +++ b/amd/build/catchshortcuts.min.js @@ -0,0 +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 diff --git a/amd/src/catchshortcuts.js b/amd/src/catchshortcuts.js new file mode 100644 index 0000000000000000000000000000000000000000..265b7a78b568866ef1e17b1f90dbb3a1b86629e1 --- /dev/null +++ b/amd/src/catchshortcuts.js @@ -0,0 +1,75 @@ +// This file is part of Moodle - http://moodle.org/ +// +// Moodle is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Moodle is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. + +/** + * Theme Boost Campus - JS code for catching pressed keys. + * + * @package theme_boost_campus + * @copyright 2017 Kathrin Osswald, Ulm University <kathrin.osswald@uni-ulm.de> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +define(['jquery'], function($) { + "use strict"; + + function initcatchshortcuts(value) { + if (value == 'end') { + // 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); + } + }); + } + // This shortcut is only relevant for users operating on MacOS. + if (navigator.appVersion.indexOf("Mac") != -1 && value == 'cmdarrowdown') { + // 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); + } + }); + } + // This shortcut is only relevant for users operating on Windows. + if (navigator.appVersion.indexOf("Win") != -1 && value == 'ctrlarrowdown') { + // 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); + } + }); + } + } + + function scrollToBottomOfCourse(event) { + // Prevent default behavior. + event.preventDefault(); + // Scroll only to the bottom of the course content. + $('html, body').animate({ + scrollTop: $('#page-footer').offset().top - $(window).height() + 50 + }, 500); + } + + return { + init: function(params) { + for (var i = 0, len = params.length; i < len; i++) { + initcatchshortcuts(params[i]); + } + } + }; +}); diff --git a/lang/en/theme_boost_campus.php b/lang/en/theme_boost_campus.php index 43a7da5ccdb96e2818eb7d630e8315ac308bc461..bfa471b28aa086d41a57ea85d0782372a3d8e7e6 100644 --- a/lang/en/theme_boost_campus.php +++ b/lang/en/theme_boost_campus.php @@ -48,6 +48,18 @@ $string['faviconheadingsetting'] = 'Favicon'; $string['faviconsetting'] = 'Favicon'; $string['faviconsetting_desc'] = 'You can upload one image (.ico or .png format) that the browser will show as the favicon of your Moodle website.'; +// Advanced settings. +// ... Catch keyboard commands. +$string['catchkeyboardcommandsheadingsetting'] = 'Catch keyboard commands'; +$string['catchkeyboardcommandsheadingsetting_desc'] = 'The following settings are intended to serve the needs for advanced users, especially if your Moodle instance has a large footer. Advanced users are likely to use keyboard shortcuts to navigate through the sites. They may use this for reaching the end of the page in the intention to get fast to the most recent topic in the course (for adding content or grading latest activities). If the footer is not quite small, they would need to scroll up again. With these settings you can enable that the following shortcuts are caught and would only scroll to the bottom of the main course content.'; +$string['catchendkeysetting'] = 'End key'; +$string['catchendkeysetting_desc'] = 'This setting will catch the "End" key (should work on all main browsers and operating systems), '; +$string['catchcmdarrowdownsetting'] = 'Cmd + Arrow down shortcut'; +$string['catchcmdarrowdownsetting_desc'] = 'This setting will catch the "Cmd + Arrow down" shortcut (MAC),'; +$string['catchctrlarrowdownsetting'] = 'Ctrl + Arrow down shortcut'; +$string['catchctrlarrowdownsetting_desc'] = 'This setting will catch the "Ctrl + Arrow down" shortcut (Windows),'; +$string['catchkeys_desc_addition'] = 'prevent the default scrolling to the bottom of the web page and changes the behavior to scroll only to the bottom of the main course content.'; + // Course layout settings. $string['courselayoutsettings'] = 'Course Layout Settings'; // ...Section 0. diff --git a/layout/columns2.php b/layout/columns2.php index c152685e0648ef89d8366aec464cf543453e5c02..44ddcace6547f8591d07076fc93b59336517fe3c 100644 --- a/layout/columns2.php +++ b/layout/columns2.php @@ -41,6 +41,19 @@ $bodyattributes = $OUTPUT->body_attributes($extraclasses); $blockshtml = $OUTPUT->blocks('side-pre'); $hasblocks = strpos($blockshtml, 'data-block=') !== false; $regionmainsettingsmenu = $OUTPUT->region_main_settings_menu(); +$catchshortcuts = array(); +$catchendkey = get_config('theme_boost_campus', 'catchendkey'); +if (isset($catchendkey) && $catchendkey == true) { + $catchshortcuts[] = 'end'; +} +$catchcmdarrowdown = get_config('theme_boost_campus', 'catchcmdarrowdown'); +if (isset($catchcmdarrowdown) && $catchcmdarrowdown == true) { + $catchshortcuts[] = 'cmdarrowdown'; +} +$catchctrlarrowdown = get_config('theme_boost_campus', 'catchctrlarrowdown'); +if (isset($catchctrlarrowdown) && $catchctrlarrowdown == true) { + $catchshortcuts[] = 'ctrlarrowdown'; +} $templatecontext = [ 'sitename' => format_string($SITE->shortname, true, ['context' => context_course::instance(SITEID), "escape" => false]), 'output' => $OUTPUT, @@ -49,7 +62,8 @@ $templatecontext = [ 'bodyattributes' => $bodyattributes, 'navdraweropen' => $navdraweropen, 'regionmainsettingsmenu' => $regionmainsettingsmenu, - 'hasregionmainsettingsmenu' => !empty($regionmainsettingsmenu) + 'hasregionmainsettingsmenu' => !empty($regionmainsettingsmenu), + 'catchshortcuts' => json_encode($catchshortcuts) ]; $templatecontext['flatnavigation'] = $PAGE->flatnav; diff --git a/settings.php b/settings.php index 983b04f8ec767bd20dc89de2bfe8c1e643f8af0b..5d64ce03c05f9f512512e29f4b100ef82410b692 100644 --- a/settings.php +++ b/settings.php @@ -159,6 +159,40 @@ if ($ADMIN->fulltree) { $setting->set_updatedcallback('theme_reset_all_caches'); $page->add($setting); + // Settings title for the catching keybaord commands. + $name = 'theme_boost_campus/catchkeyboardcommandsheading'; + $title = get_string('catchkeyboardcommandsheadingsetting', 'theme_boost_campus', null, true); + $description = get_string('catchkeyboardcommandsheadingsetting_desc', 'theme_boost_campus', null, true); + $setting = new admin_setting_heading($name, $title, $description); + $page->add($setting); + + // Setting for catching the end key. + $name = 'theme_boost_campus/catchendkey'; + $title = get_string('catchendkeysetting', 'theme_boost_campus', null, true); + $description = get_string('catchendkeysetting_desc', 'theme_boost_campus', null, true) . ' ' . + get_string('catchkeys_desc_addition', 'theme_boost_campus', null, true); + $setting = new admin_setting_configcheckbox($name, $title, $description, 0); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + + // Setting for catching the cmd + arrow down keys. + $name = 'theme_boost_campus/catchcmdarrowdown'; + $title = get_string('catchcmdarrowdownsetting', 'theme_boost_campus', null, true); + $description = get_string('catchcmdarrowdownsetting_desc', 'theme_boost_campus', null, true) . ' ' . + get_string('catchkeys_desc_addition', 'theme_boost_campus', null, true); + $setting = new admin_setting_configcheckbox($name, $title, $description, 0); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + + // Setting for catching the strg + arrow down keys. + $name = 'theme_boost_campus/catchctrlarrowdown'; + $title = get_string('catchctrlarrowdownsetting', 'theme_boost_campus', null, true); + $description = get_string('catchctrlarrowdownsetting_desc', 'theme_boost_campus', null, true) . ' ' . + get_string('catchkeys_desc_addition', 'theme_boost_campus', null, true); + $setting = new admin_setting_configcheckbox($name, $title, $description, 0); + $setting->set_updatedcallback('theme_reset_all_caches'); + $page->add($setting); + // Add tab to settings page. $settings->add($page); diff --git a/templates/columns2.mustache b/templates/columns2.mustache index b08137a529ab0e365975faa6edba12df67aa7c7c..1391e365ca24fd5c5880545f4a014dbf952a458a 100644 --- a/templates/columns2.mustache +++ b/templates/columns2.mustache @@ -109,4 +109,7 @@ require(['theme_boost/drawer'], function(mod) { mod.init(); }); require(['theme_boost_campus/backtotop']); +require(['theme_boost_campus/catchshortcuts'], function(mod) { + mod.init({{{catchshortcuts}}}); +}); {{/js}} diff --git a/version.php b/version.php index 62af3b9365ec7af570c9be7248d83aaf6735957f..050aed2dbc32e9096fbfe7d5f321b583b5c4c7b6 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $plugin->component = 'theme_boost_campus'; -$plugin->version = 2017061200; +$plugin->version = 2017063001; $plugin->release = 'v3.2-r1'; $plugin->requires = 2016070700; $plugin->maturity = MATURITY_STABLE;