{"version":3,"file":"custom_interaction_events.min.js","sources":["../src/custom_interaction_events.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * This module provides a wrapper to encapsulate a lot of the common combinations of\n * user interaction we use in Moodle.\n *\n * @module core/custom_interaction_events\n * @copyright 2016 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since 3.2\n */\ndefine(['jquery', 'core/key_codes'], function($, keyCodes) {\n // The list of events provided by this module. Namespaced to avoid clashes.\n var events = {\n activate: 'cie:activate',\n keyboardActivate: 'cie:keyboardactivate',\n escape: 'cie:escape',\n down: 'cie:down',\n up: 'cie:up',\n home: 'cie:home',\n end: 'cie:end',\n next: 'cie:next',\n previous: 'cie:previous',\n asterix: 'cie:asterix',\n scrollLock: 'cie:scrollLock',\n scrollTop: 'cie:scrollTop',\n scrollBottom: 'cie:scrollBottom',\n ctrlPageUp: 'cie:ctrlPageUp',\n ctrlPageDown: 'cie:ctrlPageDown',\n enter: 'cie:enter',\n accessibleChange: 'cie:accessibleChange',\n };\n // Static cache of jQuery events that have been handled. This should\n // only be populated by JavaScript generated events (which will keep it\n // fairly small).\n var triggeredEvents = {};\n\n /**\n * Check if the caller has asked for the given event type to be\n * registered.\n *\n * @method shouldAddEvent\n * @private\n * @param {string} eventType name of the event (see events above)\n * @param {array} include the list of events to be added\n * @return {bool} true if the event should be added, false otherwise.\n */\n var shouldAddEvent = function(eventType, include) {\n include = include || [];\n\n if (include.length && include.indexOf(eventType) !== -1) {\n return true;\n }\n\n return false;\n };\n\n /**\n * Check if any of the modifier keys have been pressed on the event.\n *\n * @method isModifierPressed\n * @private\n * @param {event} e jQuery event\n * @return {bool} true if shift, meta (command on Mac), alt or ctrl are pressed\n */\n var isModifierPressed = function(e) {\n return (e.shiftKey || e.metaKey || e.altKey || e.ctrlKey);\n };\n\n /**\n * Trigger the custom event for the given jQuery event.\n *\n * This function will only fire the custom event if one hasn't already been\n * fired for the jQuery event.\n *\n * This is to prevent multiple custom event handlers triggering multiple\n * custom events for a single jQuery event as it bubbles up the stack.\n *\n * @param {string} eventName The name of the custom event\n * @param {event} e The jQuery event\n * @return {void}\n */\n var triggerEvent = function(eventName, e) {\n var eventTypeKey = \"\";\n\n if (!e.hasOwnProperty('originalEvent')) {\n // This is a jQuery event generated from JavaScript not a browser event so\n // we need to build the cache key for the event.\n eventTypeKey = \"\" + eventName + e.type + e.timeStamp;\n\n if (!triggeredEvents.hasOwnProperty(eventTypeKey)) {\n // If we haven't s