lint: pluginfw/client_plugins (#4572)

This commit is contained in:
Hossein Marzban 2020-12-16 06:10:41 +03:30 committed by GitHub
parent a4e2ea7a8c
commit 6f309ac20a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,40 +1,36 @@
let $, jQuery; 'use strict';
$ = jQuery = require('ep_etherpad-lite/static/js/rjquery').$;
const _ = require('underscore');
const pluginUtils = require('./shared'); const pluginUtils = require('./shared');
const defs = require('./plugin_defs'); const defs = require('./plugin_defs');
exports.baseURL = ''; exports.baseURL = '';
exports.ensure = function (cb) { exports.ensure = (cb) => !defs.loaded ? exports.update(cb) : cb();
if (!defs.loaded) exports.update(cb);
else cb();
};
exports.update = function (cb) { exports.update = (cb) => {
// It appears that this response (see #620) may interrupt the current thread // It appears that this response (see #620) may interrupt the current thread
// of execution on Firefox. This schedules the response in the run-loop, // of execution on Firefox. This schedules the response in the run-loop,
// which appears to fix the issue. // which appears to fix the issue.
const callback = function () { setTimeout(cb, 0); }; const callback = () => setTimeout(cb, 0);
$.ajaxSetup({cache: false}); $.ajaxSetup({cache: false});
jQuery.getJSON(`${exports.baseURL}pluginfw/plugin-definitions.json`).done((data) => { jQuery.getJSON(`${exports.baseURL}pluginfw/plugin-definitions.json`).done((data) => {
defs.plugins = data.plugins; defs.plugins = data.plugins;
defs.parts = data.parts; defs.parts = data.parts;
defs.hooks = pluginUtils.extractHooks(defs.parts, 'client_hooks'); defs.hooks = pluginUtils.extractHooks(defs.parts, 'client_hooks');
defs.loaded = true; defs.loaded = true;
callback(); callback();
}).fail((e) => { }).fail((err) => {
console.error(`Failed to load plugin-definitions: ${err}`); console.error(`Failed to load plugin-definitions: ${err}`);
callback(); callback();
}); });
}; };
function adoptPluginsFromAncestorsOf(frame) { const adoptPluginsFromAncestorsOf = (frame) => {
// Bind plugins with parent; // Bind plugins with parent;
let parentRequire = null; let parentRequire = null;
try { try {
while (frame = frame.parent) { while ((frame = frame.parent)) {
if (typeof (frame.require) !== 'undefined') { if (typeof (frame.require) !== 'undefined') {
parentRequire = frame.require; parentRequire = frame.require;
break; break;
@ -42,20 +38,20 @@ function adoptPluginsFromAncestorsOf(frame) {
} }
} catch (error) { } catch (error) {
// Silence (this can only be a XDomain issue). // Silence (this can only be a XDomain issue).
console.error(error);
} }
if (parentRequire) {
const ancestorPluginDefs = parentRequire('ep_etherpad-lite/static/js/pluginfw/plugin_defs'); if (!parentRequire) throw new Error('Parent plugins could not be found.');
defs.hooks = ancestorPluginDefs.hooks;
defs.loaded = ancestorPluginDefs.loaded; const ancestorPluginDefs = parentRequire('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
defs.parts = ancestorPluginDefs.parts; defs.hooks = ancestorPluginDefs.hooks;
defs.plugins = ancestorPluginDefs.plugins; defs.loaded = ancestorPluginDefs.loaded;
const ancestorPlugins = parentRequire('ep_etherpad-lite/static/js/pluginfw/client_plugins'); defs.parts = ancestorPluginDefs.parts;
exports.baseURL = ancestorPlugins.baseURL; defs.plugins = ancestorPluginDefs.plugins;
exports.ensure = ancestorPlugins.ensure; const ancestorPlugins = parentRequire('ep_etherpad-lite/static/js/pluginfw/client_plugins');
exports.update = ancestorPlugins.update; exports.baseURL = ancestorPlugins.baseURL;
} else { exports.ensure = ancestorPlugins.ensure;
throw new Error('Parent plugins could not be found.'); exports.update = ancestorPlugins.update;
} };
}
exports.adoptPluginsFromAncestorsOf = adoptPluginsFromAncestorsOf; exports.adoptPluginsFromAncestorsOf = adoptPluginsFromAncestorsOf;