MDL-57682 media_videojs: convert videojs loader to es6

This commit is contained in:
Shamim Rezaie 2020-08-06 21:37:15 +10:00
parent 4a6a2636a0
commit 2189db9c86
4 changed files with 64 additions and 66 deletions

View file

@ -1,2 +1,2 @@
define ("media_videojs/loader",["jquery","core/event"],function(a,b){var c,d=function(b,d){d.find(".mediaplugin_videojs").addBack(".mediaplugin_videojs").find("audio, video").each(function(){var b=a(this).attr("id"),d=a(this).data("setup-lazy"),e=["media_videojs/video-lazy"];if(d.techOrder&&-1!==d.techOrder.indexOf("youtube")){e.push("media_videojs/Youtube-lazy")}if(d.techOrder&&-1!==d.techOrder.indexOf("flash")){e.push("media_videojs/videojs-flash-lazy")}require(e,function(a){if(c){c(a);c=null}a(b,d)})})};return{setUp:function setUp(e){c=e;d(null,a("body"));b.getLegacyEvents().done(function(b){a(document).on(b.FILTER_CONTENT_UPDATED,d)})}}});
define ("media_videojs/loader",["exports","core/event","jquery"],function(a,b,c){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.setUp=void 0;b=d(b);c=d(c);var l="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function d(a){return a&&a.__esModule?a:{default:a}}function e(a,b){return k(a)||j(a,b)||g(a,b)||f()}function f(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function g(a,b){if(!a)return;if("string"==typeof a)return h(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);if("Object"===c&&a.constructor)c=a.constructor.name;if("Map"===c||"Set"===c)return Array.from(c);if("Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c))return h(a,b)}function h(a,b){if(null==b||b>a.length)b=a.length;for(var c=0,d=Array(b);c<b;c++){d[c]=a[c]}return d}function j(a,b){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(a)))return;var c=[],d=!0,e=!1,f=void 0;try{for(var g=a[Symbol.iterator](),h;!(d=(h=g.next()).done);d=!0){c.push(h.value);if(b&&c.length===b)break}}catch(a){e=!0;f=a}finally{try{if(!d&&null!=g["return"])g["return"]()}finally{if(e)throw f}}return c}function k(a){if(Array.isArray(a))return a}var m,n=function(a){m=a;o(null,(0,c.default)("body"));b.default.getLegacyEvents().done(function(a){(0,c.default)(document).on(a.FILTER_CONTENT_UPDATED,o)})};a.setUp=n;var o=function(a,b){b.find(".mediaplugin_videojs").addBack(".mediaplugin_videojs").find("audio, video").each(function(a,b){var d=(0,c.default)(b).attr("id"),f=(0,c.default)(b).data("setup-lazy"),g=["function"==typeof l.define&&l.define.amd?new Promise(function(a,b){l.require(["media_videojs/video-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&l.require&&"component"===l.require.loader?Promise.resolve(require(("media_videojs/video-lazy"))):Promise.resolve(l["media_videojs/video-lazy"])];if(f.techOrder&&-1!==f.techOrder.indexOf("youtube")){g.push("function"==typeof l.define&&l.define.amd?new Promise(function(a,b){l.require(["media_videojs/Youtube-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&l.require&&"component"===l.require.loader?Promise.resolve(require(("media_videojs/Youtube-lazy"))):Promise.resolve(l["media_videojs/Youtube-lazy"]))}if(f.techOrder&&-1!==f.techOrder.indexOf("flash")){g.push("function"==typeof l.define&&l.define.amd?new Promise(function(a,b){l.require(["media_videojs/videojs-flash-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&l.require&&"component"===l.require.loader?Promise.resolve(require(("media_videojs/videojs-flash-lazy"))):Promise.resolve(l["media_videojs/videojs-flash-lazy"]))}Promise.all(g).then(function(a){var b=e(a,1),c=b[0];if(m){m(c);m=null}c(d,f)}).catch(Notification.exception)})}});
//# sourceMappingURL=loader.min.js.map

View file

@ -1 +1 @@
{"version":3,"sources":["../src/loader.js"],"names":["define","$","Event","onload","notifyVideoJS","e","nodes","find","addBack","each","id","attr","config","data","modules","techOrder","indexOf","push","require","videojs","setUp","executeonload","getLegacyEvents","done","events","document","on","FILTER_CONTENT_UPDATED"],"mappings":"AAwBAA,OAAM,wBAAC,CAAC,QAAD,CAAW,YAAX,CAAD,CAA2B,SAASC,CAAT,CAAYC,CAAZ,CAAmB,IAK5CC,CAAAA,CAL4C,CA6B5CC,CAAa,CAAG,SAASC,CAAT,CAAYC,CAAZ,CAAmB,CAOnCA,CAAK,CAACC,IAAN,yBACKC,OADL,yBAEKD,IAFL,CAEU,cAFV,EAE0BE,IAF1B,CAE+B,UAAW,CAClC,GAAIC,CAAAA,CAAE,CAAGT,CAAC,CAAC,IAAD,CAAD,CAAQU,IAAR,CAAa,IAAb,CAAT,CACIC,CAAM,CAAGX,CAAC,CAAC,IAAD,CAAD,CAAQY,IAAR,CAAa,YAAb,CADb,CAEIC,CAAO,CAAG,CAAC,0BAAD,CAFd,CAIA,GAAIF,CAAM,CAACG,SAAP,EAA4D,CAAC,CAAzC,GAAAH,CAAM,CAACG,SAAP,CAAiBC,OAAjB,CAAyB,SAAzB,CAAxB,CAAoE,CAEhEF,CAAO,CAACG,IAAR,CAAa,4BAAb,CACH,CACD,GAAIL,CAAM,CAACG,SAAP,EAA0D,CAAC,CAAvC,GAAAH,CAAM,CAACG,SAAP,CAAiBC,OAAjB,CAAyB,OAAzB,CAAxB,CAAkE,CAE9DF,CAAO,CAACG,IAAR,CAAa,kCAAb,CACH,CACDC,OAAO,CAACJ,CAAD,CAAU,SAASK,CAAT,CAAkB,CAC/B,GAAIhB,CAAJ,CAAY,CACRA,CAAM,CAACgB,CAAD,CAAN,CACAhB,CAAM,CAAG,IACZ,CACDgB,CAAO,CAACT,CAAD,CAAKE,CAAL,CACV,CANM,CAOV,CAtBL,CAuBH,CA3D+C,CA6DhD,MAAO,CACHQ,KAAK,CAjDG,QAARA,CAAAA,KAAQ,CAASC,CAAT,CAAwB,CAChClB,CAAM,CAAGkB,CAAT,CAEAjB,CAAa,CAAC,IAAD,CAAOH,CAAC,CAAC,MAAD,CAAR,CAAb,CAEAC,CAAK,CAACoB,eAAN,GAAwBC,IAAxB,CAA6B,SAASC,CAAT,CAAiB,CAC1CvB,CAAC,CAACwB,QAAD,CAAD,CAAYC,EAAZ,CAAeF,CAAM,CAACG,sBAAtB,CAA8CvB,CAA9C,CACH,CAFD,CAGH,CAwCM,CAIV,CAjEK,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 * Video JS loader.\n *\n * This takes care of applying the filter on content which was dynamically loaded.\n *\n * @package media_videojs\n * @copyright 2016 Frédéric Massart - FMCorz.net\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/event'], function($, Event) {\n\n /**\n * Stores the method we need to execute on the first load of videojs module.\n */\n var onload;\n\n /**\n * Set-up.\n *\n * Adds the listener for the event to then notify video.js.\n * @param {Function} executeonload function to execute when media_videojs/video is loaded\n */\n var setUp = function(executeonload) {\n onload = executeonload;\n // Notify Video.js about the nodes already present on the page.\n notifyVideoJS(null, $('body'));\n // We need to call popover automatically if nodes are added to the page later.\n Event.getLegacyEvents().done(function(events) {\n $(document).on(events.FILTER_CONTENT_UPDATED, notifyVideoJS);\n });\n };\n\n /**\n * Notify video.js of new nodes.\n *\n * @param {Event} e The event.\n * @param {NodeList} nodes List of new nodes.\n */\n var notifyVideoJS = function(e, nodes) {\n var selector = '.mediaplugin_videojs';\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(function() {\n var id = $(this).attr('id'),\n config = $(this).data('setup-lazy'),\n modules = ['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 modules.push('media_videojs/Youtube-lazy');\n }\n if (config.techOrder && config.techOrder.indexOf('flash') !== -1) {\n // Add Flash to the list of modules we require.\n modules.push('media_videojs/videojs-flash-lazy');\n }\n require(modules, function(videojs) {\n if (onload) {\n onload(videojs);\n onload = null;\n }\n videojs(id, config);\n });\n });\n };\n\n return {\n setUp: setUp\n };\n\n});\n"],"file":"loader.min.js"}
{"version":3,"sources":["../src/loader.js"],"names":["onload","setUp","executeonload","notifyVideoJS","Event","getLegacyEvents","done","events","document","on","FILTER_CONTENT_UPDATED","e","nodes","find","addBack","each","index","element","id","attr","config","data","modulePromises","techOrder","indexOf","push","Promise","all","then","videojs","catch","Notification","exception"],"mappings":"8JA0BA,OACA,O,6nCAKIA,CAAAA,C,CAQSC,CAAK,CAAG,SAACC,CAAD,CAAmB,CACpCF,CAAM,CAAGE,CAAT,CAEAC,CAAa,CAAC,IAAD,CAAO,cAAO,MAAP,CAAP,CAAb,CAEAC,UAAMC,eAAN,GAAwBC,IAAxB,CAA6B,SAACC,CAAD,CAAY,CACrC,cAAOC,QAAP,EAAiBC,EAAjB,CAAoBF,CAAM,CAACG,sBAA3B,CAAmDP,CAAnD,CACH,CAFD,CAGH,C,WAQD,GAAMA,CAAAA,CAAa,CAAG,SAACQ,CAAD,CAAIC,CAAJ,CAAc,CAOhCA,CAAK,CAACC,IAAN,yBACKC,OADL,yBAEKD,IAFL,CAEU,cAFV,EAE0BE,IAF1B,CAE+B,SAACC,CAAD,CAAQC,CAAR,CAAoB,IACrCC,CAAAA,CAAE,CAAG,cAAOD,CAAP,EAAgBE,IAAhB,CAAqB,IAArB,CADgC,CAErCC,CAAM,CAAG,cAAOH,CAAP,EAAgBI,IAAhB,CAAqB,YAArB,CAF4B,CAGrCC,CAAc,CAAG,6SAAQ,0BAAR,mDAHoB,CAK3C,GAAIF,CAAM,CAACG,SAAP,EAA4D,CAAC,CAAzC,GAAAH,CAAM,CAACG,SAAP,CAAiBC,OAAjB,CAAyB,SAAzB,CAAxB,CAAoE,CAEhEF,CAAc,CAACG,IAAf,+SAA2B,4BAA3B,qDACH,CACD,GAAIL,CAAM,CAACG,SAAP,EAA0D,CAAC,CAAvC,GAAAH,CAAM,CAACG,SAAP,CAAiBC,OAAjB,CAAyB,OAAzB,CAAxB,CAAkE,CAE9DF,CAAc,CAACG,IAAf,qTAA2B,kCAA3B,2DACH,CACDC,OAAO,CAACC,GAAR,CAAYL,CAAZ,EAA4BM,IAA5B,CAAiC,WAAe,cAAbC,CAAa,MAC5C,GAAI7B,CAAJ,CAAY,CACRA,CAAM,CAAC6B,CAAD,CAAN,CACA7B,CAAM,CAAG,IACZ,CACD6B,CAAO,CAACX,CAAD,CAAKE,CAAL,CAEV,CAPD,EAOGU,KAPH,CAOSC,YAAY,CAACC,SAPtB,CAQH,CAvBL,CAwBH,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 * 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 * @package media_videojs\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 Event from 'core/event';\nimport jQuery from 'jquery';\n\n/**\n * Stores the method we need to execute on the first load of videojs module.\n */\nlet onload;\n\n/**\n * Set-up.\n *\n * Adds the listener for the event to then notify video.js.\n * @param {Function} executeonload function to execute when media_videojs/video is loaded\n */\nexport const setUp = (executeonload) => {\n onload = executeonload;\n // Notify Video.js about the nodes already present on the page.\n notifyVideoJS(null, jQuery('body'));\n // We need to call popover automatically if nodes are added to the page later.\n Event.getLegacyEvents().done((events) => {\n jQuery(document).on(events.FILTER_CONTENT_UPDATED, notifyVideoJS);\n });\n};\n\n/**\n * Notify video.js of new nodes.\n *\n * @param {Event} e The event.\n * @param {NodeList} nodes List of new nodes.\n */\nconst notifyVideoJS = (e, nodes) => {\n const selector = '.mediaplugin_videojs';\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('flash') !== -1) {\n // Add Flash to the list of modules we require.\n modulePromises.push(import('media_videojs/videojs-flash-lazy'));\n }\n Promise.all(modulePromises).then(([videojs]) => {\n if (onload) {\n onload(videojs);\n onload = null;\n }\n videojs(id, config);\n return;\n }).catch(Notification.exception);\n });\n};\n"],"file":"loader.min.js"}

View file

@ -18,73 +18,71 @@
*
* This takes care of applying the filter on content which was dynamically loaded.
*
* @module media_videojs/loader
* @package media_videojs
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/event'], function($, Event) {
/**
* Stores the method we need to execute on the first load of videojs module.
*/
var onload;
import Event from 'core/event';
import jQuery from 'jquery';
/**
* Set-up.
*
* Adds the listener for the event to then notify video.js.
* @param {Function} executeonload function to execute when media_videojs/video is loaded
*/
var setUp = function(executeonload) {
onload = executeonload;
// Notify Video.js about the nodes already present on the page.
notifyVideoJS(null, $('body'));
// We need to call popover automatically if nodes are added to the page later.
Event.getLegacyEvents().done(function(events) {
$(document).on(events.FILTER_CONTENT_UPDATED, notifyVideoJS);
/**
* Stores the method we need to execute on the first load of videojs module.
*/
let onload;
/**
* Set-up.
*
* Adds the listener for the event to then notify video.js.
* @param {Function} executeonload function to execute when media_videojs/video is loaded
*/
export const setUp = (executeonload) => {
onload = executeonload;
// Notify Video.js about the nodes already present on the page.
notifyVideoJS(null, jQuery('body'));
// We need to call popover automatically if nodes are added to the page later.
Event.getLegacyEvents().done((events) => {
jQuery(document).on(events.FILTER_CONTENT_UPDATED, notifyVideoJS);
});
};
/**
* Notify video.js of new nodes.
*
* @param {Event} e The event.
* @param {NodeList} nodes List of new nodes.
*/
const notifyVideoJS = (e, nodes) => {
const selector = '.mediaplugin_videojs';
// Find the descendants matching the expected parent of the audio and video
// tags. Then also addBack the nodes matching the same selector. Finally,
// we find the audio and video tags contained in those parents. Kind thanks
// to jQuery for the simplicity.
nodes.find(selector)
.addBack(selector)
.find('audio, video').each((index, element) => {
const id = jQuery(element).attr('id');
const config = jQuery(element).data('setup-lazy');
const modulePromises = [import('media_videojs/video-lazy')];
if (config.techOrder && config.techOrder.indexOf('youtube') !== -1) {
// Add YouTube to the list of modules we require.
modulePromises.push(import('media_videojs/Youtube-lazy'));
}
if (config.techOrder && config.techOrder.indexOf('flash') !== -1) {
// Add Flash to the list of modules we require.
modulePromises.push(import('media_videojs/videojs-flash-lazy'));
}
Promise.all(modulePromises).then(([videojs]) => {
if (onload) {
onload(videojs);
onload = null;
}
videojs(id, config);
return;
}).catch(Notification.exception);
});
};
/**
* Notify video.js of new nodes.
*
* @param {Event} e The event.
* @param {NodeList} nodes List of new nodes.
*/
var notifyVideoJS = function(e, nodes) {
var selector = '.mediaplugin_videojs';
// Find the descendants matching the expected parent of the audio and video
// tags. Then also addBack the nodes matching the same selector. Finally,
// we find the audio and video tags contained in those parents. Kind thanks
// to jQuery for the simplicity.
nodes.find(selector)
.addBack(selector)
.find('audio, video').each(function() {
var id = $(this).attr('id'),
config = $(this).data('setup-lazy'),
modules = ['media_videojs/video-lazy'];
if (config.techOrder && config.techOrder.indexOf('youtube') !== -1) {
// Add YouTube to the list of modules we require.
modules.push('media_videojs/Youtube-lazy');
}
if (config.techOrder && config.techOrder.indexOf('flash') !== -1) {
// Add Flash to the list of modules we require.
modules.push('media_videojs/videojs-flash-lazy');
}
require(modules, function(videojs) {
if (onload) {
onload(videojs);
onload = null;
}
videojs(id, config);
});
});
};
return {
setUp: setUp
};
});
};

View file

@ -423,7 +423,7 @@ class media_videojs_plugin extends core_media_player_native {
// when video is present on the page or added later to it in AJAX.
$path = new moodle_url('/media/player/videojs/videojs/video-js.swf');
$contents = 'videojs.options.flash.swf = "' . $path . '";' . "\n";
$contents .= $this->find_language(current_language());
$contents .= $this->find_language();
$page->requires->js_amd_inline(<<<EOT
require(["media_videojs/loader"], function(loader) {
loader.setUp(function(videojs) {