mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-57682 mediaplayer_videojs: Improve in-page caching of lang strings
This commit is contained in:
parent
36f90b454c
commit
5f581ce9eb
2
media/player/videojs/amd/build/loader.min.js
vendored
2
media/player/videojs/amd/build/loader.min.js
vendored
@ -1,2 +1,2 @@
|
||||
define ("media_videojs/loader",["exports","core/config","core/event","jquery","core/ajax","core/localstorage","core/notification"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.setUp=void 0;b=h(b);c=h(c);d=h(d);e=h(e);f=h(f);g=h(g);var o="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function h(a){return a&&a.__esModule?a:{default:a}}function i(a,b){return n(a)||m(a,b)||k(a,b)||j()}function j(){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 k(a,b){if(!a)return;if("string"==typeof a)return l(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 l(a,b)}function l(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 m(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 n(a){if(Array.isArray(a))return a}var p,q,r=function(a){q=a;p=!0;s(null,(0,d.default)("body"));c.default.getLegacyEvents().done(function(a){(0,d.default)(document).on(a.FILTER_CONTENT_UPDATED,s)})};a.setUp=r;var s=function(a,c){var e=t();c.find(".mediaplugin_videojs").addBack(".mediaplugin_videojs").find("audio, video").each(function(a,c){var f=(0,d.default)(c).attr("id"),h=(0,d.default)(c).data("setup-lazy"),j=["function"==typeof o.define&&o.define.amd?new Promise(function(a,b){o.require(["media_videojs/video-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&o.require&&"component"===o.require.loader?Promise.resolve(require(("media_videojs/video-lazy"))):Promise.resolve(o["media_videojs/video-lazy"])];if(h.techOrder&&-1!==h.techOrder.indexOf("youtube")){j.push("function"==typeof o.define&&o.define.amd?new Promise(function(a,b){o.require(["media_videojs/Youtube-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&o.require&&"component"===o.require.loader?Promise.resolve(require(("media_videojs/Youtube-lazy"))):Promise.resolve(o["media_videojs/Youtube-lazy"]))}if(h.techOrder&&-1!==h.techOrder.indexOf("flash")){j.push("function"==typeof o.define&&o.define.amd?new Promise(function(a,b){o.require(["media_videojs/videojs-flash-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&o.require&&"component"===o.require.loader?Promise.resolve(require(("media_videojs/videojs-flash-lazy"))):Promise.resolve(o["media_videojs/videojs-flash-lazy"]))}Promise.all([e].concat(j)).then(function(a){var c=i(a,2),d=c[0],e=c[1];if(p){e.options.flash.swf="".concat(b.default.wwwroot,"/media/player/videojs/videojs/video-js.swf");e.addLanguage(q,d);p=!1}e(f,h)}).catch(g.default.exception)})},t=function(){var a=JSON.parse(f.default.get("media_videojs")||"{}");if(q in a){return Promise.resolve(a[q])}var b={methodname:"media_videojs_get_language",args:{lang:q}};return e.default.call([b])[0].then(function(b){a[q]=JSON.parse(b);f.default.set("media_videojs",JSON.stringify(a));return a[q]})}});
|
||||
define ("media_videojs/loader",["exports","core/config","core/event","jquery","core/ajax","core/localstorage","core/notification"],function(a,b,c,d,e,f,g){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.setUp=void 0;b=h(b);c=h(c);d=h(d);e=h(e);f=h(f);g=h(g);var o="undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:{};function h(a){return a&&a.__esModule?a:{default:a}}function i(a,b){return n(a)||m(a,b)||k(a,b)||j()}function j(){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 k(a,b){if(!a)return;if("string"==typeof a)return l(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 l(a,b)}function l(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 m(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 n(a){if(Array.isArray(a))return a}var p,q,r,s=function(a){q=a;p=!0;t(null,(0,d.default)("body"));c.default.getLegacyEvents().done(function(a){(0,d.default)(document).on(a.FILTER_CONTENT_UPDATED,t)})};a.setUp=s;var t=function(a,c){var e=u();c.find(".mediaplugin_videojs").addBack(".mediaplugin_videojs").find("audio, video").each(function(a,c){var f=(0,d.default)(c).attr("id"),h=(0,d.default)(c).data("setup-lazy"),j=["function"==typeof o.define&&o.define.amd?new Promise(function(a,b){o.require(["media_videojs/video-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&o.require&&"component"===o.require.loader?Promise.resolve(require(("media_videojs/video-lazy"))):Promise.resolve(o["media_videojs/video-lazy"])];if(h.techOrder&&-1!==h.techOrder.indexOf("youtube")){j.push("function"==typeof o.define&&o.define.amd?new Promise(function(a,b){o.require(["media_videojs/Youtube-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&o.require&&"component"===o.require.loader?Promise.resolve(require(("media_videojs/Youtube-lazy"))):Promise.resolve(o["media_videojs/Youtube-lazy"]))}if(h.techOrder&&-1!==h.techOrder.indexOf("flash")){j.push("function"==typeof o.define&&o.define.amd?new Promise(function(a,b){o.require(["media_videojs/videojs-flash-lazy"],a,b)}):"undefined"!=typeof module&&module.exports&&"undefined"!=typeof require||"undefined"!=typeof module&&module.component&&o.require&&"component"===o.require.loader?Promise.resolve(require(("media_videojs/videojs-flash-lazy"))):Promise.resolve(o["media_videojs/videojs-flash-lazy"]))}Promise.all([e].concat(j)).then(function(a){var c=i(a,2),d=c[0],e=c[1];if(p){e.options.flash.swf="".concat(b.default.wwwroot,"/media/player/videojs/videojs/video-js.swf");e.addLanguage(q,d);p=!1}e(f,h)}).catch(g.default.exception)})},u=function(){if(r){return Promise.resolve(r)}var a="media_videojs/".concat(q),b=f.default.get(a);if(b){var d=JSON.parse(b);r=d;return Promise.resolve(r)}var c={methodname:"media_videojs_get_language",args:{lang:q}};return e.default.call([c])[0].then(function(b){f.default.set(a,b);return b}).then(function(a){return JSON.parse(a)}).then(function(a){r=a;return a})}});
|
||||
//# sourceMappingURL=loader.min.js.map
|
||||
|
File diff suppressed because one or more lines are too long
@ -31,16 +31,15 @@ import Ajax from 'core/ajax';
|
||||
import LocalStorage from 'core/localstorage';
|
||||
import Notification from 'core/notification';
|
||||
|
||||
/**
|
||||
* Whether this is the first load of videojs module.
|
||||
*/
|
||||
/** @var {bool} Whether this is the first load of videojs module */
|
||||
let firstLoad;
|
||||
|
||||
/**
|
||||
* The language that is used in the player
|
||||
*/
|
||||
/** @var {string} The language that is used in the player */
|
||||
let language;
|
||||
|
||||
/** @var {object} List of languages and translations for the current page */
|
||||
let langStringCache;
|
||||
|
||||
/**
|
||||
* Set-up.
|
||||
*
|
||||
@ -108,21 +107,38 @@ const notifyVideoJS = (e, nodes) => {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
const getLanguageJson = () => {
|
||||
const cached = JSON.parse(LocalStorage.get('media_videojs') || '{}');
|
||||
if (language in cached) {
|
||||
return Promise.resolve(cached[language]);
|
||||
if (langStringCache) {
|
||||
return Promise.resolve(langStringCache);
|
||||
}
|
||||
|
||||
const cacheKey = `media_videojs/${language}`;
|
||||
|
||||
const rawCacheContent = LocalStorage.get(cacheKey);
|
||||
if (rawCacheContent) {
|
||||
const cacheContent = JSON.parse(rawCacheContent);
|
||||
|
||||
langStringCache = cacheContent;
|
||||
|
||||
return Promise.resolve(langStringCache);
|
||||
}
|
||||
|
||||
const request = {
|
||||
methodname: 'media_videojs_get_language',
|
||||
args: {
|
||||
lang: language
|
||||
lang: language,
|
||||
},
|
||||
};
|
||||
return Ajax.call([request])[0].then(result => {
|
||||
cached[language] = JSON.parse(result);
|
||||
LocalStorage.set('media_videojs', JSON.stringify(cached));
|
||||
|
||||
return cached[language];
|
||||
});
|
||||
return Ajax.call([request])[0]
|
||||
.then(langStringData => {
|
||||
LocalStorage.set(cacheKey, langStringData);
|
||||
|
||||
return langStringData;
|
||||
})
|
||||
.then(result => JSON.parse(result))
|
||||
.then(langStrings => {
|
||||
langStringCache = langStrings;
|
||||
|
||||
return langStrings;
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user