Autoría | Ultima modificación | Ver Log |
{"version":3,"file":"loader.min.js","sources":["../src/loader.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 * Video JS loader.\n *\n * This takes care of applying the filter on content which was dynamically loaded.\n *\n * @module media_videojs/loader\n * @copyright 2016 Frédéric Massart - FMCorz.net\n * @license http://www.gnu.
org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport Config from 'core/config';\nimport {eventTypes} from 'core_filters/events';\nimport LocalStorage from 'core/localstorage';\nimport Notification from 'core/notification';\nimport jQuery from 'jquery';\n\n/** @var {bool} Whether this is the first load of videojs module */\nlet firstLoad;\n\n/** @var {string} The language that is used in the player */\nlet language;\n\n/** @var {object} List of languages and translations for the current page */\nlet langStringCache;\n\n/**\n * Initialisei teh videojs Loader.\n *\n * Adds the listener for the event to then notify video.js.\n *\n * @method\n * @param {string} lang Language to be used in the player\n * @listens event:filterContentUpdated\n */\nexport const setUp = (lang) => {\n language = lang;\n firstLoad = true;\n\n // Notify Video.js about the nodes already present on the page.\n notifyVideoJS({\n detail: {\n nodes: document.body,\n }\n
});\n\n // We need to call popover automatically if nodes are added to the page later.\n document.addEventListener(eventTypes.filterContentUpdated, notifyVideoJS);\n};\n\n/**\n * Notify video.js of new nodes.\n *\n * @param {Event} e The event.\n */\nconst notifyVideoJS = e => {\n const nodes = jQuery(e.detail.nodes);\n const selector = '.mediaplugin_videojs';\n const langStrings = getLanguageJson();\n\n // Find the descendants matching the expected parent of the audio and video\n // tags. Then also addBack the nodes matching the same selector. Finally,\n // we find the audio and video tags contained in those parents. Kind thanks\n // to jQuery for the simplicity.\n nodes.find(selector)\n .addBack(selector)\n .find('audio, video').each((index, element) => {\n const id = jQuery(element).attr('id');\n const config = jQuery(element).data('setup-lazy');\n const modulePromises = [import('media_videojs/video-lazy')];\n\n if (
config.techOrder && config.techOrder.indexOf('youtube') !== -1) {\n // Add YouTube to the list of modules we require.\n modulePromises.push(import('media_videojs/Youtube-lazy'));\n }\n if (config.techOrder && config.techOrder.indexOf('OgvJS') !== -1) {\n config.ogvjs = {\n worker: true,\n wasm: true,\n base: Config.wwwroot + '/media/player/videojs/ogvloader.php/' + Config.jsrev + '/'\n };\n // Add Ogv.JS to the list of modules we require.\n modulePromises.push(import('media_videojs/videojs-ogvjs-lazy'));\n }\n Promise.all([langStrings, ...modulePromises])\n .then(([langJson, videojs]) => {\n if (firstLoad) {\n videojs.addLanguage(language, langJson);\n\n firstLoad = false;\n }\n videojs(id, config);\n return;\n
})\n .catch(Notification.exception);\n });\n};\n\n/**\n * Returns the json object of the language strings to be used in the player.\n *\n * @returns {Promise}\n */\nconst getLanguageJson = () => {\n if (langStringCache) {\n return Promise.resolve(langStringCache);\n }\n\n const cacheKey = `media_videojs/${language}`;\n\n const rawCacheContent = LocalStorage.get(cacheKey);\n if (rawCacheContent) {\n const cacheContent = JSON.parse(rawCacheContent);\n\n langStringCache = cacheContent;\n\n return Promise.resolve(langStringCache);\n }\n\n const request = {\n methodname: 'media_videojs_get_language',\n args: {\n lang: language,\n },\n };\n\n return Ajax.call([request])[0]\n .then(langStringData => {\n LocalStorage.set(cacheKey, langStringData);\n\n return langStringData;\n })\n .then(result => JSON.parse(result))\n .then(langStrings => {\n l
angStringCache = langStrings;\n\n return langStrings;\n });\n};\n"],"names":["firstLoad","language","langStringCache","lang","notifyVideoJS","detail","nodes","document","body","addEventListener","eventTypes","filterContentUpdated","e","langStrings","getLanguageJson","find","addBack","each","index","element","id","attr","config","data","modulePromises","techOrder","indexOf","push","ogvjs","worker","wasm","base","Config","wwwroot","jsrev","Promise","all","then","_ref","langJson","videojs","addLanguage","catch","Notification","exception","resolve","cacheKey","rawCacheContent","LocalStorage","get","cacheContent","JSON","parse","request","methodname","args","Ajax","call","langStringData","set","result"],"mappings":"2uBAiCIA,UAGAC,SAGAC,+BAWkBC,OAClBF,SAAWE,KACXH,WAAY,EAGZI,cAAc,CACVC,OAAQ,CACJC,MAAOC,SAASC,QAKxBD,SAASE,iBAAiBC,mBAAWC,qBAAsBP,sBAQzDA,cAAgBQ,UACZN,OAAQ,mBAAOM,EAAEP,OAAOC,OAExBO,YAAcC,kBAMpBR,MAAMS,KAPW,wBAQZC,QARY,wBASZD,KAAK,gBAAgBE,MAAK,CAACC,MAAOC,iBACzBC,IAAK,mBAAOD,SAASE,KAAK
,MAC1BC,QAAS,mBAAOH,SAASI,KAAK,cAC9BC,eAAiB,2nBAEnBF,OAAOG,YAAsD,IAAzCH,OAAOG,UAAUC,QAAQ,YAE7CF,eAAeG,qoBAEfL,OAAOG,YAAoD,IAAvCH,OAAOG,UAAUC,QAAQ,WAC7CJ,OAAOM,MAAQ,CACXC,QAAQ,EACRC,MAAM,EACNC,KAAMC,gBAAOC,QAAU,uCAAyCD,gBAAOE,MAAQ,KAGnFV,eAAeG,wpBAEnBQ,QAAQC,IAAI,CAACvB,eAAgBW,iBAC5Ba,MAAKC,WAAEC,SAAUC,cACVxC,YACAwC,QAAQC,YAAYxC,SAAUsC,UAE9BvC,WAAY,GAEhBwC,QAAQpB,GAAIE,WAGfoB,MAAMC,sBAAaC,eAS1B9B,gBAAkB,QAChBZ,uBACOiC,QAAQU,QAAQ3C,uBAGrB4C,iCAA4B7C,UAE5B8C,gBAAkBC,sBAAaC,IAAIH,aACrCC,gBAAiB,OACXG,aAAeC,KAAKC,MAAML,wBAEhC7C,gBAAkBgD,aAEXf,QAAQU,QAAQ3C,uBAGrBmD,QAAU,CACZC,WAAY,6BACZC,KAAM,CACFpD,KAAMF,kBAIPuD,cAAKC,KAAK,CAACJ,UAAU,GACvBhB,MAAKqB,uCACWC,IAAIb,SAAUY,gBAEpBA,kBAEVrB,MAAKuB,QAAUT,KAAKC,MAAMQ,UAC1BvB,MAAKxB,cACFX,gBAAkBW,YAEXA"}