Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"clearchoice.min.js","sources":["../src/clearchoice.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 * Manages 'Clear my choice' functionality actions.\n *\n * @module     qtype_multichoice/clearchoice\n * @copyright  2019 Simey Lameze <simey@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @since      3.7\n */\ndefine(['jquery', 'core/custom_interaction_events'], function($, CustomEvents) {\n\n    var SELECTORS = {\n        CHOICE_ELEMENT: '.answer input',\n        LINK: 'a',\n        RADIO: 'input[type=\"radio\"]'\n    };\n\n    /**\n     * Mark clear choice radio as enabled and checked.\n     *\n     * @param {Object} clearChoiceContainer The clear choice option container.\n     */\n    var checkClearChoiceRadio = function(clearChoiceContainer) {\n        clearChoiceContainer.find(SELECTORS.RADIO).prop('disabled', false).prop('checked', true);\n    };\n\n    /**\n     * Get the clear choice div container.\n     *\n     * @param {Object} root The question root element.\n     * @param {string} fieldPrefix The question outer div prefix.\n     * @returns {Object} The clear choice div container.\n     */\n    var getClearChoiceElement = function(root, fieldPrefix) {\n        return root.find('div[id=\"' + fieldPrefix + '\"]');\n    };\n\n    /**\n     * Hide clear choice option.\n     *\n     * @param {Object} clearChoiceContainer The clear choice option container.\n     */\n    var hideClearChoiceOption = function(clearChoiceContainer) {\n        // We are using .sr-only and aria-hidden together so while the element is hidden\n        // from both the monitor and the screen-reader, it is still tabbable.\n        clearChoiceContainer.addClass('sr-only');\n        clearChoiceContainer.attr('aria-hidden', true);\n        clearChoiceContainer.find(SELECTORS.LINK).attr('tabindex', -1);\n    };\n\n    /**\n     * Shows clear choice option.\n     *\n     * @param {Object} clearChoiceContainer The clear choice option container.\n     */\n    var showClearChoiceOption = function(clearChoiceContainer) {\n        clearChoiceContainer.removeClass('sr-only');\n        clearChoiceContainer.removeAttr('aria-hidden');\n        clearChoiceContainer.find(SELECTORS.LINK).attr('tabindex', 0);\n        clearChoiceContainer.find(SELECTORS.RADIO).prop('disabled', true);\n    };\n\n    /**\n     * Register event listeners for the clear choice module.\n     *\n     * @param {Object} root The question outer div prefix.\n     * @param {string} fieldPrefix The \"Clear choice\" div prefix.\n     */\n    var registerEventListeners = function(root, fieldPrefix) {\n        var clearChoiceContainer = getClearChoiceElement(root, fieldPrefix);\n\n        clearChoiceContainer.on(CustomEvents.events.activate, SELECTORS.LINK, function(e, data) {\n\n                // Mark the clear choice radio element as checked.\n                checkClearChoiceRadio(clearChoiceContainer);\n                // Now that the hidden radio has been checked, hide the clear choice option.\n                hideClearChoiceOption(clearChoiceContainer);\n\n                data.originalEvent.preventDefault();\n        });\n\n        root.on('change', SELECTORS.CHOICE_ELEMENT, function() {\n            // If the event has been triggered by any other choice, show the clear choice option.\n            showClearChoiceOption(clearChoiceContainer);\n        });\n\n        // If the clear choice radio receives focus from using the tab key, return the focus\n        // to the first answer option.\n        clearChoiceContainer.find(SELECTORS.RADIO).focus(function() {\n            var firstChoice = root.find(SELECTORS.CHOICE_ELEMENT).first();\n            firstChoice.focus();\n        });\n    };\n\n    /**\n     * Initialise clear choice module.\n     *\n     * @param {string} root The question outer div prefix.\n     * @param {string} fieldPrefix The \"Clear choice\" div prefix.\n     */\n    var init = function(root, fieldPrefix) {\n        root = $('#' + root);\n        registerEventListeners(root, fieldPrefix);\n    };\n\n    return {\n        init: init\n    };\n});\n"],"names":["define","$","CustomEvents","SELECTORS","registerEventListeners","root","fieldPrefix","clearChoiceContainer","find","getClearChoiceElement","on","events","activate","e","data","prop","checkClearChoiceRadio","addClass","attr","hideClearChoiceOption","originalEvent","preventDefault","removeClass","removeAttr","showClearChoiceOption","focus","first","init"],"mappings":";;;;;;;;AAuBAA,uCAAO,CAAC,SAAU,mCAAmC,SAASC,EAAGC,kBAEzDC,yBACgB,gBADhBA,eAEM,IAFNA,gBAGO,sBAsDPC,uBAAyB,SAASC,KAAMC,iBACpCC,qBApCoB,SAASF,KAAMC,oBAChCD,KAAKG,KAAK,WAAaF,YAAc,MAmCjBG,CAAsBJ,KAAMC,aAEvDC,qBAAqBG,GAAGR,aAAaS,OAAOC,SAAUT,gBAAgB,SAASU,EAAGC,OAjD1D,SAASP,sBACjCA,qBAAqBC,KAAKL,iBAAiBY,KAAK,YAAY,GAAOA,KAAK,WAAW,GAmD3EC,CAAsBT,sBAhCN,SAASA,sBAGjCA,qBAAqBU,SAAS,WAC9BV,qBAAqBW,KAAK,eAAe,GACzCX,qBAAqBC,KAAKL,gBAAgBe,KAAK,YAAa,GA6BpDC,CAAsBZ,sBAEtBO,KAAKM,cAAcC,oBAG3BhB,KAAKK,GAAG,SAAUP,0BAA0B,YA1BpB,SAASI,sBACjCA,qBAAqBe,YAAY,WACjCf,qBAAqBgB,WAAW,eAChChB,qBAAqBC,KAAKL,gBAAgBe,KAAK,WAAY,GAC3DX,qBAAqBC,KAAKL,iBAAiBY,KAAK,YAAY,GAwBxDS,CAAsBjB,yBAK1BA,qBAAqBC,KAAKL,iBAAiBsB,OAAM,WAC3BpB,KAAKG,KAAKL,0BAA0BuB,QAC1CD,kBAeb,CACHE,KANO,SAAStB,KAAMC,aACtBD,KAAOJ,EAAE,IAAMI,MACfD,uBAAuBC,KAAMC"}