Current Path : C:/xampp/htdocs/moodle/mod/quiz/amd/build/ |
Current File : C:/xampp/htdocs/moodle/mod/quiz/amd/build/add_random_form.min.js.map |
{"version":3,"sources":["../src/add_random_form.js"],"names":["define","$","RandomQuestionFormPreview","SELECTORS","PREVIEW_CONTAINER","CATEGORY_FORM_ELEMENT","SUBCATEGORY_FORM_ELEMENT","TAG_IDS_FORM_ELEMENT","getCategorySelectValue","form","find","val","getCategoryId","valueString","values","split","isTopLevelCategorySelected","topCategories","selectedValue","indexOf","shouldIncludeSubcategories","is","getTagIds","map","value","parts","reloadQuestionPreview","contextId","previewContainer","reload","isInterestingElement","element","closest","length","addEventListeners","reloadTimerId","on","e","target","showLoadingIcon","clearTimeout","setTimeout","init","formId","isTagsEnabled"],"mappings":"AAuBAA,OAAM,4BACF,CACI,QADJ,CAEI,uCAFJ,CADE,CAKF,SACIC,CADJ,CAEIC,CAFJ,CAGE,IAKEC,CAAAA,CAAS,CAAG,CACZC,iBAAiB,CAAE,qDADP,CAEZC,qBAAqB,CAAE,qBAFX,CAGZC,wBAAwB,CAAE,iCAHd,CAIZC,oBAAoB,CAAE,uBAJV,CALd,CAkBEC,CAAsB,CAAG,SAASC,CAAT,CAAe,CACxC,MAAOA,CAAAA,CAAI,CAACC,IAAL,CAAUP,CAAS,CAACE,qBAApB,EAA2CM,GAA3C,EACV,CApBC,CA4BEC,CAAa,CAAG,SAASH,CAAT,CAAe,IAG3BI,CAAAA,CAAW,CAAGL,CAAsB,CAACC,CAAD,CAHT,CAK3BK,CAAM,CAAGD,CAAW,CAACE,KAAZ,CAAkB,GAAlB,CALkB,CAO/B,MAAOD,CAAAA,CAAM,CAAC,CAAD,CAChB,CApCC,CA6CEE,CAA0B,CAAG,SAASP,CAAT,CAAeQ,CAAf,CAA8B,CAC3D,GAAIC,CAAAA,CAAa,CAAGV,CAAsB,CAACC,CAAD,CAA1C,CACA,MAA+C,CAAC,CAAxC,CAAAQ,CAAa,CAACE,OAAd,CAAsBD,CAAtB,CAC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AACC,OAAR,CAAgB7B,CAAS,CAACI,oBAA1B,EAAgD0B,MAApD,CAAgE,CAC5D,QACH,CAED,QACH,CAxHC,CAyIEC,CAAiB,CAAG,SAASzB,CAAT,CAAekB,CAAf,CAA0BV,CAA1B,CAAyC,CAC7D,GAAIkB,CAAAA,CAAa,CAAG,IAApB,CAEA1B,CAAI,CAAC2B,EAAL,CAAQ,QAAR,CAAkB,SAASC,CAAT,CAAY,CAG1B,GAAI,CAACP,CAAoB,CAAC7B,CAAC,CAACoC,CAAC,CAACC,MAAH,CAAF,CAAzB,CAAwC,CACpC,MACH,CAIDpC,CAAyB,CAACqC,eAA1B,CAA0C9B,CAA1C,EAEA,GAAI0B,CAAJ,CAAmB,CAEfK,YAAY,CAACL,CAAD,CACf,CAKDA,CAAa,CAAGM,UAAU,CAAC,UAAW,CAClCf,CAAqB,CAACjB,CAAD,CAAOkB,CAAP,CAAkBV,CAAlB,CACxB,CAFyB,MAG7B,CAtBD,CAuBH,CAnKC,CAsLF,MAAO,CACHyB,IAAI,CATG,QAAPA,CAAAA,IAAO,CAASC,CAAT,CAAiBhB,CAAjB,CAA4BV,CAA5B,CAA2C2B,CAA3C,CAA0D,CAChE,GAAI,IAAAA,CAAJ,CAA2B,CACvB,GAAInC,CAAAA,CAAI,CAAGR,CAAC,CAAC,IAAM0C,CAAP,CAAZ,CACAjB,CAAqB,CAACjB,CAAD,CAAOkB,CAAP,CAAkBV,CAAlB,CAAiC2B,CAAjC,CAArB,CACAV,CAAiB,CAACzB,CAAD,CAAOkB,CAAP,CAAkBV,CAAlB,CAAiC2B,CAAjC,CACpB,CACL,CAEM,CAGV,CAjMK,CAAN","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 * JavaScript for the add_random_form class.\n *\n * @module mod_quiz/add_random_form\n * @package mod_quiz\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n [\n 'jquery',\n 'mod_quiz/random_question_form_preview'\n ],\n function(\n $,\n RandomQuestionFormPreview\n ) {\n\n // Wait 2 seconds before reloading the question set just in case\n // the user is still changing the criteria.\n var RELOAD_DELAY = 2000;\n var SELECTORS = {\n PREVIEW_CONTAINER: '[data-region=\"random-question-preview-container\"]',\n CATEGORY_FORM_ELEMENT: '[name=\"category\"]',\n SUBCATEGORY_FORM_ELEMENT: '[name=\"includesubcategories\"]',\n TAG_IDS_FORM_ELEMENT: '[name=\"fromtags[]\"]'\n };\n\n /**\n * Get the selected category value from the form.\n *\n * @param {jquery} form The form element.\n * @return {string} The category value.\n */\n var getCategorySelectValue = function(form) {\n return form.find(SELECTORS.CATEGORY_FORM_ELEMENT).val();\n };\n\n /**\n * Get the category id from the form.\n *\n * @param {jquery} form The form element.\n * @return {string} The category id.\n */\n var getCategoryId = function(form) {\n // The value string is the category id and category context id joined\n // by a comma.\n var valueString = getCategorySelectValue(form);\n // Split the two ids.\n var values = valueString.split(',');\n // Return just the category id.\n return values[0];\n };\n\n /**\n * Check if a top level category is selected in the form.\n *\n * @param {jquery} form The form element.\n * @param {string[]} topCategories List of top category values (matching the select box values)\n * @return {bool}\n */\n var isTopLevelCategorySelected = function(form, topCategories) {\n var selectedValue = getCategorySelectValue(form);\n return (topCategories.indexOf(selectedValue) > -1);\n };\n\n /**\n * Check if the form indicates we should include include subcategories in\n * the filter.\n *\n * @param {jquery} form The form element.\n * @param {string[]} topCategories List of top category values (matching the select box values)\n * @return {bool}\n */\n var shouldIncludeSubcategories = function(form, topCategories) {\n if (isTopLevelCategorySelected(form, topCategories)) {\n return true;\n } else {\n return form.find(SELECTORS.SUBCATEGORY_FORM_ELEMENT).is(':checked');\n }\n };\n\n /**\n * Get the tag ids for the selected tags in the form.\n *\n * @param {jquery} form The form element.\n * @return {string[]} The tag ids.\n */\n var getTagIds = function(form) {\n var values = form.find(SELECTORS.TAG_IDS_FORM_ELEMENT).val();\n return values.map(function(value) {\n // The tag element value is the tag id and tag name joined\n // by a comma. So we need to split them to get the tag id.\n var parts = value.split(',');\n return parts[0];\n });\n };\n\n /**\n * Reload the preview section with a new set of filters.\n *\n * @param {jquery} form The form element.\n * @param {int} contextId The current context id.\n * @param {string[]} topCategories List of top category values (matching the select box values)\n */\n var reloadQuestionPreview = function(form, contextId, topCategories) {\n var previewContainer = form.find(SELECTORS.PREVIEW_CONTAINER);\n RandomQuestionFormPreview.reload(\n previewContainer,\n getCategoryId(form),\n shouldIncludeSubcategories(form, topCategories),\n getTagIds(form),\n contextId\n );\n };\n\n /**\n * Is this an element we're interested in listening to changes on.\n *\n * @param {jquery} element The element to check.\n * @return {bool}\n */\n var isInterestingElement = function(element) {\n if (element.closest(SELECTORS.CATEGORY_FORM_ELEMENT).length > 0) {\n return true;\n }\n\n if (element.closest(SELECTORS.SUBCATEGORY_FORM_ELEMENT).length > 0) {\n return true;\n }\n\n if (element.closest(SELECTORS.TAG_IDS_FORM_ELEMENT).length > 0) {\n return true;\n }\n\n return false;\n };\n\n /**\n * Listen for changes to any of the interesting elements and reload the form\n * preview with the new filter values if they are changed.\n *\n * The reload is delayed for a small amount of time (see RELOAD_DELAY) in case\n * the user is actively editing the form. This allows us to avoid having to\n * send multiple requests to the server on each change.\n *\n * Instead we can just send a single request when the user appears to have\n * finished editing the form.\n *\n * @param {jquery} form The form element.\n * @param {int} contextId The current context id.\n * @param {string[]} topCategories List of top category values (matching the select box values)\n */\n var addEventListeners = function(form, contextId, topCategories) {\n var reloadTimerId = null;\n\n form.on('change', function(e) {\n // Only reload the preview when elements that will change the result\n // are modified.\n if (!isInterestingElement($(e.target))) {\n return;\n }\n\n // Show the loading icon to let the user know that the preview\n // will be updated after their actions.\n RandomQuestionFormPreview.showLoadingIcon(form);\n\n if (reloadTimerId) {\n // Reset the timer each time the form is modified.\n clearTimeout(reloadTimerId);\n }\n\n // Don't immediately reload the question preview section just\n // in case the user is still modifying the form. We don't want to\n // spam reload requests.\n reloadTimerId = setTimeout(function() {\n reloadQuestionPreview(form, contextId, topCategories);\n }, RELOAD_DELAY);\n });\n };\n\n /**\n * Trigger the first load of the preview section and then listen for modifications\n * to the form to reload the preview with new filter values.\n *\n * @param {jquery} formId The form element id.\n * @param {int} contextId The current context id.\n * @param {string[]} topCategories List of top category values (matching the select box values)\n * @param {bool} isTagsEnabled Whether tags feature is enabled or not.\n */\n var init = function(formId, contextId, topCategories, isTagsEnabled) {\n if (isTagsEnabled == true) {\n var form = $('#' + formId);\n reloadQuestionPreview(form, contextId, topCategories, isTagsEnabled);\n addEventListeners(form, contextId, topCategories, isTagsEnabled);\n }\n };\n\n return {\n init: init\n };\n});\n"],"file":"add_random_form.min.js"}