MDL-61460 tool_componentlibrary: JS Documentation fix

This commit is contained in:
Andrew Nicols 2021-07-08 11:06:18 +08:00 committed by Eloy Lafuente (stronk7)
parent b3b7b3daca
commit f1525fbdbf
12 changed files with 103 additions and 18 deletions

View File

@ -1 +1 @@
{"version":3,"sources":["../src/clipboardwrapper.js"],"names":["idCounter","clipboardWrapper","document","querySelectorAll","selectors","clipboardcontent","forEach","element","id","Templates","renderForPromise","clipboardtarget","then","html","js","prependNodeContents","catch"],"mappings":"mPAwBA,OACA,O,qXAEIA,CAAAA,CAAS,CAAG,C,CAKHC,CAAgB,4CAAG,8FAC5BC,QAAQ,CAACC,gBAAT,CAA0BC,UAAUC,gBAApC,EAAsDC,OAAtD,CAA8D,SAAAC,CAAO,CAAI,CACrE,GAAI,CAACA,CAAO,CAACC,EAAb,CAAiB,CACbD,CAAO,CAACC,EAAR,yCAA8CR,CAAS,EAAvD,CACH,CACDS,UAAUC,gBAAV,CAA2B,uCAA3B,CAAoE,CAACC,eAAe,YAAMJ,CAAO,CAACC,EAAd,SAAhB,CAApE,EACCI,IADD,CACM,WAAgB,IAAdC,CAAAA,CAAc,GAAdA,IAAc,CAARC,CAAQ,GAARA,EAAQ,CAClBL,UAAUM,mBAAV,CAA8BR,CAA9B,CAAuCM,CAAvC,CAA6CC,CAA7C,EACA,MACH,CAJD,EAKCE,KALD,EAMH,CAVD,EAD4B,wCAAH,uD","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 * Interface to using clipboard.js\n *\n * @module tool_componentlibrary/clipboardwrapper\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport 'core/copy_to_clipboard';\nimport selectors from 'tool_componentlibrary/selectors';\nimport Templates from 'core/templates';\n\nlet idCounter = 0;\n\n/**\n * Initialise the clipboard button on all reusable code.\n */\nexport const clipboardWrapper = async() => {\n document.querySelectorAll(selectors.clipboardcontent).forEach(element => {\n if (!element.id) {\n element.id = `tool_componentlibrary_content-${idCounter++}`;\n }\n Templates.renderForPromise('tool_componentlibrary/clipboardbutton', {clipboardtarget: `#${element.id} code`})\n .then(({html, js}) => {\n Templates.prependNodeContents(element, html, js);\n return;\n })\n .catch();\n });\n};\n"],"file":"clipboardwrapper.min.js"}
{"version":3,"sources":["../src/clipboardwrapper.js"],"names":["idCounter","clipboardWrapper","document","querySelectorAll","selectors","clipboardcontent","forEach","element","id","Templates","renderForPromise","clipboardtarget","then","html","js","prependNodeContents","catch"],"mappings":"mPAuBA,OACA,O,qXAEIA,CAAAA,CAAS,CAAG,C,CAOHC,CAAgB,4CAAG,8FAC5BC,QAAQ,CAACC,gBAAT,CAA0BC,UAAUC,gBAApC,EAAsDC,OAAtD,CAA8D,SAAAC,CAAO,CAAI,CACrE,GAAI,CAACA,CAAO,CAACC,EAAb,CAAiB,CACbD,CAAO,CAACC,EAAR,yCAA8CR,CAAS,EAAvD,CACH,CACDS,UAAUC,gBAAV,CAA2B,uCAA3B,CAAoE,CAACC,eAAe,YAAMJ,CAAO,CAACC,EAAd,SAAhB,CAApE,EACCI,IADD,CACM,WAAgB,IAAdC,CAAAA,CAAc,GAAdA,IAAc,CAARC,CAAQ,GAARA,EAAQ,CAClBL,UAAUM,mBAAV,CAA8BR,CAA9B,CAAuCM,CAAvC,CAA6CC,CAA7C,EACA,MACH,CAJD,EAKCE,KALD,EAMH,CAVD,EAD4B,wCAAH,uD","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 * Wrapper to ensure that all Hugo example snippets have a \"Copy to clipboard\" button.\n *\n * @module tool_componentlibrary/clipboardwrapper\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport 'core/copy_to_clipboard';\nimport selectors from 'tool_componentlibrary/selectors';\nimport Templates from 'core/templates';\n\nlet idCounter = 0;\n\n/**\n * Initialise the clipboard button on all reusable code.\n *\n * @method\n */\nexport const clipboardWrapper = async() => {\n document.querySelectorAll(selectors.clipboardcontent).forEach(element => {\n if (!element.id) {\n element.id = `tool_componentlibrary_content-${idCounter++}`;\n }\n Templates.renderForPromise('tool_componentlibrary/clipboardbutton', {clipboardtarget: `#${element.id} code`})\n .then(({html, js}) => {\n Templates.prependNodeContents(element, html, js);\n return;\n })\n .catch();\n });\n};\n"],"file":"clipboardwrapper.min.js"}

View File

@ -1 +1 @@
{"version":3,"sources":["../src/jsrunner.js"],"names":["jsRunner","compLib","document","querySelector","selectors","componentlibrary","querySelectorAll","jscode","forEach","runjs","eval","innerHTML"],"mappings":"mNAwBA,8C,wEAQO,GAAMA,CAAAA,QAAQ,CAAG,UAAM,CAC1B,GAAMC,CAAAA,OAAO,CAAGC,QAAQ,CAACC,aAAT,CAAuBC,mBAAUC,gBAAjC,CAAhB,CACAJ,OAAO,CAACK,gBAAR,CAAyBF,mBAAUG,MAAnC,EAA2CC,OAA3C,CAAmD,SAAAC,KAAK,CAAI,CACxDC,IAAI,CAACD,KAAK,CAACE,SAAP,CACP,CAFD,CAGH,CALM,C","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 is called from to run any js code\n *\n * @module tool_componentlibrary/jsrunner\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport selectors from 'tool_componentlibrary/selectors';\n\n/**\n * The Hugo shortcodes changes the JavaScript in markdownfiles from\n * the Moodle mustache {{js}} code... {{/js}} syntax into a div with\n * attribute data-action='runjs'. See hugo/site/layouts/shortcodes/example.html.\n * This code fetches and runs the JavaScript content.\n */\nexport const jsRunner = () => {\n const compLib = document.querySelector(selectors.componentlibrary);\n compLib.querySelectorAll(selectors.jscode).forEach(runjs => {\n eval(runjs.innerHTML); // eslint-disable-line no-eval\n });\n};\n"],"file":"jsrunner.min.js"}
{"version":3,"sources":["../src/jsrunner.js"],"names":["jsRunner","compLib","document","querySelector","selectors","componentlibrary","querySelectorAll","jscode","forEach","runjs","eval","innerHTML"],"mappings":"mNAuBA,8C,wEAUO,GAAMA,CAAAA,QAAQ,CAAG,UAAM,CAC1B,GAAMC,CAAAA,OAAO,CAAGC,QAAQ,CAACC,aAAT,CAAuBC,mBAAUC,gBAAjC,CAAhB,CACAJ,OAAO,CAACK,gBAAR,CAAyBF,mBAAUG,MAAnC,EAA2CC,OAA3C,CAAmD,SAAAC,KAAK,CAAI,CACxDC,IAAI,CAACD,KAAK,CAACE,SAAP,CACP,CAFD,CAGH,CALM,C","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 * Run the JS required for example code to work in the library.\n *\n * @module tool_componentlibrary/jsrunner\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport selectors from 'tool_componentlibrary/selectors';\n\n/**\n * The Hugo shortcodes changes the JavaScript in markdownfiles from\n * the Moodle mustache {{js}} code... {{/js}} syntax into a div with\n * attribute data-action='runjs'. See hugo/site/layouts/shortcodes/example.html.\n * This code fetches and runs the JavaScript content.\n *\n * @method\n */\nexport const jsRunner = () => {\n const compLib = document.querySelector(selectors.componentlibrary);\n compLib.querySelectorAll(selectors.jscode).forEach(runjs => {\n eval(runjs.innerHTML); // eslint-disable-line no-eval\n });\n};\n"],"file":"jsrunner.min.js"}

View File

@ -1 +1 @@
{"version":3,"sources":["../src/loader.js"],"names":["init","jsonFile"],"mappings":"oNAkCoB,QAAPA,CAAAA,IAAO,CAAAC,CAAQ,CAAI,CAC5B,iBACA,iBACA,yBACA,aAAOA,CAAP,CACH,C","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 initialises the component library JS\n *\n * @module tool_componentlibrary/loader\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {mustache} from './mustache';\nimport {jsRunner} from './jsrunner';\nimport {clipboardWrapper} from './clipboardwrapper';\nimport {search} from './search';\n\n/**\n * Load all the component library JavaScript.\n *\n * @param {string} jsonFile Full path to the JSON file with the search DB.\n */\nexport const init = jsonFile => {\n mustache();\n jsRunner();\n clipboardWrapper();\n search(jsonFile);\n};\n"],"file":"loader.min.js"}
{"version":3,"sources":["../src/loader.js"],"names":["init","jsonFile"],"mappings":"oNAiCoB,QAAPA,CAAAA,IAAO,CAAAC,CAAQ,CAAI,CAC5B,iBACA,iBACA,yBACA,aAAOA,CAAP,CACH,C","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 initialises the component library JS\n *\n * @module tool_componentlibrary/loader\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {mustache} from './mustache';\nimport {jsRunner} from './jsrunner';\nimport {clipboardWrapper} from './clipboardwrapper';\nimport {search} from './search';\n\n/**\n * Load all the component library JavaScript.\n *\n * @param {string} jsonFile Full path to the JSON file with the search DB.\n */\nexport const init = jsonFile => {\n mustache();\n jsRunner();\n clipboardWrapper();\n search(jsonFile);\n};\n"],"file":"loader.min.js"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"version":3,"sources":["../src/selectors.js"],"names":["clipboardbutton","clipboardcontent","searchinput","searchsubmit","dropdownmenu","componentlibrary","jscode","mustachecode","mustacherawcontext","mustacherendered","mustachesource","mustachecontext"],"mappings":"2JAwBe,CACXA,eAAe,CAAE,gBADN,CAEXC,gBAAgB,CAAE,iCAFP,CAGXC,WAAW,CAAE,mCAHF,CAIXC,YAAY,CAAE,yCAJH,CAKXC,YAAY,CAAE,4CALH,CAMXC,gBAAgB,CAAE,oCANP,CAOXC,MAAM,CAAE,yBAPG,CAQXC,YAAY,CAAE,gCARH,CASXC,kBAAkB,CAAE,8BATT,CAUXC,gBAAgB,CAAE,oCAVP,CAWXC,cAAc,CAAE,kCAXL,CAYXC,eAAe,CAAE,mCAZN,C","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 * Selectors for the component library\n *\n * @module tool_componentlibrary/selectors\n * @package tool_componentlibrary\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default {\n clipboardbutton: '.btn-clipboard',\n clipboardcontent: 'figure.highlight, div.highlight',\n searchinput: '[data-region=\"docsearch\"] input',\n searchsubmit: '[data-region=\"docsearch\"] .btn-submit',\n dropdownmenu: '[data-region=\"docsearch\"] .dropdown-menu',\n componentlibrary: '[data-region=\"componentlibrary\"]',\n jscode: '[data-action=\"runjs\"]',\n mustachecode: '[data-region=\"mustachecode\"]',\n mustacherawcontext: '[data-region=\"rawcontext\"]',\n mustacherendered: '[data-region=\"mustacherendered\"]',\n mustachesource: '[data-region=\"mustachesource\"]',\n mustachecontext: '[data-region=\"mustachecontext\"]',\n};\n"],"file":"selectors.min.js"}
{"version":3,"sources":["../src/selectors.js"],"names":["clipboardbutton","clipboardcontent","searchinput","searchsubmit","dropdownmenu","componentlibrary","jscode","mustachecode","mustacherawcontext","mustacherendered","mustachesource","mustachecontext"],"mappings":"2JAsBe,CAMXA,eAAe,CAAE,gBANN,CAaXC,gBAAgB,CAAE,iCAbP,CAoBXC,WAAW,CAAE,mCApBF,CA2BXC,YAAY,CAAE,yCA3BH,CAkCXC,YAAY,CAAE,4CAlCH,CAyCXC,gBAAgB,CAAE,oCAzCP,CAgDXC,MAAM,CAAE,yBAhDG,CAuDXC,YAAY,CAAE,gCAvDH,CA8DXC,kBAAkB,CAAE,8BA9DT,CAqEXC,gBAAgB,CAAE,oCArEP,CA4EXC,cAAc,CAAE,kCA5EL,CAmFXC,eAAe,CAAE,mCAnFN,C","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 * Selectors for the component library\n *\n * @module tool_componentlibrary/selectors\n * @copyright 2021 Bas Brands <bas@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default {\n /**\n * A selector relating to the 'Copy to clipboard' button.\n *\n * @type {string}\n */\n clipboardbutton: '.btn-clipboard',\n\n /**\n * A selector relating to the content copied by the 'Copy to clipboard' button.\n *\n * @type {string}\n */\n clipboardcontent: 'figure.highlight, div.highlight',\n\n /**\n * A selector relating to the 'Search' text input.\n *\n * @type {string}\n */\n searchinput: '[data-region=\"docsearch\"] input',\n\n /**\n * A selector relating to the 'Search' submit btton.\n *\n * @type {string}\n */\n searchsubmit: '[data-region=\"docsearch\"] .btn-submit',\n\n /**\n * A selector relating to the search dropdown menu.\n *\n * @type {string}\n */\n dropdownmenu: '[data-region=\"docsearch\"] .dropdown-menu',\n\n /**\n * A selector relating to the entire Component Library content region.\n *\n * @type {string}\n */\n componentlibrary: '[data-region=\"componentlibrary\"]',\n\n /**\n * A selector relating to JS Code which is to be run for examples to function.\n *\n * @type {string}\n */\n jscode: '[data-action=\"runjs\"]',\n\n /**\n * A selector relating to Mustache Template code regions.\n *\n * @type {string}\n */\n mustachecode: '[data-region=\"mustachecode\"]',\n\n /**\n * A selector relating to raw Mustache content regions.\n *\n * @type {string}\n */\n mustacherawcontext: '[data-region=\"rawcontext\"]',\n\n /**\n * A selector relating to rendered Mustache content regions.\n *\n * @type {string}\n */\n mustacherendered: '[data-region=\"mustacherendered\"]',\n\n /**\n * A selector relating to Mustache source code regions.\n *\n * @type {string}\n */\n mustachesource: '[data-region=\"mustachesource\"]',\n\n /**\n * A selector relating to Mustache context regions.\n *\n * @type {string}\n */\n mustachecontext: '[data-region=\"mustachecontext\"]',\n};\n"],"file":"selectors.min.js"}

View File

@ -14,10 +14,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Interface to using clipboard.js
* Wrapper to ensure that all Hugo example snippets have a "Copy to clipboard" button.
*
* @module tool_componentlibrary/clipboardwrapper
* @package tool_componentlibrary
* @copyright 2021 Bas Brands <bas@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -29,6 +28,8 @@ let idCounter = 0;
/**
* Initialise the clipboard button on all reusable code.
*
* @method
*/
export const clipboardWrapper = async() => {
document.querySelectorAll(selectors.clipboardcontent).forEach(element => {

View File

@ -14,10 +14,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This is called from to run any js code
* Run the JS required for example code to work in the library.
*
* @module tool_componentlibrary/jsrunner
* @package tool_componentlibrary
* @copyright 2021 Bas Brands <bas@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -29,6 +28,8 @@ import selectors from 'tool_componentlibrary/selectors';
* the Moodle mustache {{js}} code... {{/js}} syntax into a div with
* attribute data-action='runjs'. See hugo/site/layouts/shortcodes/example.html.
* This code fetches and runs the JavaScript content.
*
* @method
*/
export const jsRunner = () => {
const compLib = document.querySelector(selectors.componentlibrary);

View File

@ -17,7 +17,6 @@
* This initialises the component library JS
*
* @module tool_componentlibrary/loader
* @package tool_componentlibrary
* @copyright 2021 Bas Brands <bas@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

View File

@ -14,10 +14,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This is called from to render mustache templates
* Render mustache template examples within the component library.
*
* @module tool_componentlibrary/mustache
* @package tool_componentlibrary
* @copyright 2021 Bas Brands <bas@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -32,6 +31,8 @@ import Notification from 'core/notification';
/**
* Handle a template loaded response.
*
* @method
* @private
* @param {String} container The template container
* @param {String} templateName The template name
* @param {String} context Data for the template.
@ -55,6 +56,8 @@ const renderTemplate = async(container, templateName, context) => {
/**
* Load the a template source from Moodle.
*
* @method
* @private
* @param {String} container The template container
*/
const loadTemplate = container => {
@ -96,8 +99,9 @@ const loadTemplate = container => {
};
/**
* Initialize module
* Initialize the module.
*
* @method
*/
export const mustache = () => {
document.querySelectorAll(selectors.mustachecode).forEach((container) => {

View File

@ -17,7 +17,6 @@
* Interface to the Lunr search engines.
*
* @module tool_componentlibrary/search
* @package tool_componentlibrary
* @copyright 2021 Bas Brands <bas@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@ -34,8 +33,10 @@ let pagesIndex = null;
/**
* Get the jsonFile that is generated when the component library is build.
*
* @method
* @private
* @param {String} jsonFile the URL to the json file.
* @retrun {Object}
* @return {Object}
*/
const fetchJson = async(jsonFile) => {
const response = await fetch(jsonFile);
@ -50,6 +51,8 @@ const fetchJson = async(jsonFile) => {
/**
* Initiate lunr on the data in the jsonFile and add the jsondata to the pagesIndex
*
* @method
* @private
* @param {String} jsonFile the URL to the json file.
*/
const initLunr = jsonFile => {
@ -71,6 +74,9 @@ const initLunr = jsonFile => {
/**
* Setup the eventlistener to listen on user input on the search field.
*
* @method
* @private
*/
const initUI = () => {
const searchInput = document.querySelector(selectors.searchinput);
@ -95,6 +101,8 @@ const initUI = () => {
/**
* Trigger a search in lunr and transform the result.
*
* @method
* @private
* @param {String} query
* @return {Array} results
*/
@ -115,6 +123,8 @@ const searchIndex = query => {
/**
* Display the 10 first results
*
* @method
* @private
* @param {Array} results to display
*/
const renderResults = results => {
@ -146,6 +156,7 @@ const renderResults = results => {
/**
* Initialize module.
*
* @method
* @param {String} jsonFile Full path to the search DB json file.
*/
export const search = jsonFile => {

View File

@ -17,22 +17,91 @@
* Selectors for the component library
*
* @module tool_componentlibrary/selectors
* @package tool_componentlibrary
* @copyright 2021 Bas Brands <bas@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
export default {
/**
* A selector relating to the 'Copy to clipboard' button.
*
* @type {string}
*/
clipboardbutton: '.btn-clipboard',
/**
* A selector relating to the content copied by the 'Copy to clipboard' button.
*
* @type {string}
*/
clipboardcontent: 'figure.highlight, div.highlight',
/**
* A selector relating to the 'Search' text input.
*
* @type {string}
*/
searchinput: '[data-region="docsearch"] input',
/**
* A selector relating to the 'Search' submit btton.
*
* @type {string}
*/
searchsubmit: '[data-region="docsearch"] .btn-submit',
/**
* A selector relating to the search dropdown menu.
*
* @type {string}
*/
dropdownmenu: '[data-region="docsearch"] .dropdown-menu',
/**
* A selector relating to the entire Component Library content region.
*
* @type {string}
*/
componentlibrary: '[data-region="componentlibrary"]',
/**
* A selector relating to JS Code which is to be run for examples to function.
*
* @type {string}
*/
jscode: '[data-action="runjs"]',
/**
* A selector relating to Mustache Template code regions.
*
* @type {string}
*/
mustachecode: '[data-region="mustachecode"]',
/**
* A selector relating to raw Mustache content regions.
*
* @type {string}
*/
mustacherawcontext: '[data-region="rawcontext"]',
/**
* A selector relating to rendered Mustache content regions.
*
* @type {string}
*/
mustacherendered: '[data-region="mustacherendered"]',
/**
* A selector relating to Mustache source code regions.
*
* @type {string}
*/
mustachesource: '[data-region="mustachesource"]',
/**
* A selector relating to Mustache context regions.
*
* @type {string}
*/
mustachecontext: '[data-region="mustachecontext"]',
};