{"version":3,"file":"prefetch.min.js","sources":["https:\/\/hivtrainingcdu.remote-learner.net\/lib\/amd\/src\/prefetch.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 .\n\n\/**\n * Prefetch module to help lazily load content for use on the current page.\n *\n * @module     core\/prefetch\n * @class      prefetch\n * @package    core\n * @copyright  2020 Andrew Nicols \n * @license    http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\nimport Config from 'core\/config';\n\n\/\/ Keep track of whether the initial prefetch has occurred.\nlet initialPrefetchComplete = false;\n\n\/\/ Prefetch templates.\nlet templateList = [];\n\n\/\/ Prefetch strings.\nlet stringList = {};\n\nlet prefetchTimer;\n\n\/**\n * Fetch all queued items in the queue.\n *\n * Should only be called via processQueue.\n *\/\nconst fetchQueue = () => {\n    \/\/ Prefetch templates.\n    if (templateList) {\n        const templatesToLoad = templateList.slice();\n        templateList = [];\n        import('core\/templates')\n        .then(Templates => Templates.prefetchTemplates(templatesToLoad))\n        .catch();\n    }\n\n    \/\/ Prefetch strings.\n    const mappedStringsToFetch = stringList;\n    stringList = {};\n\n    const stringsToFetch = [];\n    Object.keys(mappedStringsToFetch).forEach(component => {\n        stringsToFetch.push(...mappedStringsToFetch[component].map(key => {\n            return {component, key};\n        }));\n    });\n\n    if (stringsToFetch) {\n        import('core\/str')\n        .then(Str => Str.get_strings(stringsToFetch))\n        .catch();\n    }\n};\n\n\/**\n * Process the prefetch queues as required.\n *\n * The initial call will queue the first fetch after a delay.\n * Subsequent fetches are immediate.\n *\/\nconst processQueue = () => {\n    if (prefetchTimer) {\n        \/\/ There is a live prefetch timer. The initial prefetch has been scheduled but is not complete.\n        return;\n    }\n\n    \/\/ The initial prefetch has compelted. Just queue as normal.\n    if (initialPrefetchComplete) {\n        fetchQueue();\n\n        return;\n    }\n\n    \/\/ Queue the initial prefetch in a short while.\n    prefetchTimer = setTimeout(() => {\n        initialPrefetchComplete = true;\n        prefetchTimer = null;\n\n        \/\/ Ensure that the icon system is loaded.\n        \/\/ This can be quite slow and delay UI interactions if it is loaded on demand.\n        import(Config.iconsystemmodule)\n        .then(IconSystem => {\n            const iconSystem = new IconSystem();\n            prefetchTemplate(iconSystem.getTemplateName());\n\n            return iconSystem;\n        })\n        .then(iconSystem => {\n            fetchQueue();\n            iconSystem.init();\n\n            return;\n        })\n        .catch();\n    }, 500);\n};\n\n\/**\n * Add a set of templates to the prefetch queue.\n *\n * @param {Array} templatesNames\n *\/\nconst prefetchTemplates = templatesNames => {\n    templateList = templateList.concat(templatesNames);\n\n    processQueue();\n};\n\n\/**\n * Add a single template to the prefetch queue.\n *\n * @param {String} templateName\n * @returns {undefined}\n *\/\nconst prefetchTemplate = templateName => prefetchTemplates([templateName]);\n\n\/**\n * Add a set of strings from the same component to the prefetch queue.\n *\n * @param {String} component\n * @param {String[]} keys\n *\/\nconst prefetchStrings = (component, keys) => {\n    if (!stringList[component]) {\n        stringList[component] = [];\n    }\n\n    stringList[component] = stringList[component].concat(keys);\n\n    processQueue();\n};\n\n\/**\n * Add a single string to the prefetch queue.\n *\n * @param {String} component\n * @param {String} key\n *\/\nconst prefetchString = (component, key) => {\n    if (!stringList[component]) {\n        stringList[component] = [];\n    }\n\n    stringList[component].push(key);\n\n    processQueue();\n};\n\n\/\/ Prefetch some commonly-used templates.\nprefetchTemplates([].concat(\n    ['core\/loading'],\n    ['core\/modal'],\n    ['core\/modal_backdrop'],\n));\n\n\/\/ And some commonly used strings.\nprefetchStrings('core', [\n    'cancel',\n    'closebuttontitle',\n    'loading',\n    'savechanges',\n]);\nprefetchStrings('core_form', [\n    'showless',\n    'showmore',\n]);\n\nexport default {\n    prefetchTemplate,\n    prefetchTemplates,\n    prefetchString,\n    prefetchStrings,\n};\n"],"names":["prefetchTimer","initialPrefetchComplete","templateList","stringList","fetchQueue","templatesToLoad","slice","then","Templates","prefetchTemplates","catch","mappedStringsToFetch","stringsToFetch","Object","keys","forEach","component","push","map","key","Str","get_strings","processQueue","setTimeout","Config","iconsystemmodule","IconSystem","iconSystem","prefetchTemplate","getTemplateName","init","templatesNames","concat","templateName","prefetchStrings","prefetchString"],"mappings":"uwCAmCIA,cARAC,yBAA0B,EAG1BC,aAAe,GAGfC,WAAa,GASXC,WAAa,cAEXF,aAAc,KACRG,gBAAkBH,aAAaI,QACrCJ,aAAe,gmBAEdK,MAAK,SAAAC,kBAAaA,UAAUC,kBAAkBJ,oBAC9CK,YAICC,qBAAuBR,WAC7BA,WAAa,OAEPS,eAAiB,GACvBC,OAAOC,KAAKH,sBAAsBI,SAAQ,SAAAC,WACtCJ,eAAeK,WAAfL,kCAAuBD,qBAAqBK,WAAWE,KAAI,SAAAC,WAChD,CAACH,UAAAA,UAAWG,IAAAA,aAIvBP,2lBAECL,MAAK,SAAAa,YAAOA,IAAIC,YAAYT,mBAC5BF,SAUHY,aAAe,WACbtB,gBAMAC,wBACAG,aAMJJ,cAAgBuB,YAAW,WACvBtB,yBAA0B,EAC1BD,cAAgB,sNAITwB,gBAAOC,4SAAPD,gBAAP,4EAAOA,gBAAOC,oBACblB,MAAK,SAAAmB,gBACIC,WAAa,IAAID,kBACvBE,iBAAiBD,WAAWE,mBAErBF,cAEVpB,MAAK,SAAAoB,YACFvB,aACAuB,WAAWG,UAIdpB,UACF,OAQDD,kBAAoB,SAAAsB,gBACtB7B,aAAeA,aAAa8B,OAAOD,gBAEnCT,gBASEM,iBAAmB,SAAAK,qBAAgBxB,kBAAkB,CAACw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