From 6f309ac20a07654f2a1525df408f533bdf4f4e84 Mon Sep 17 00:00:00 2001 From: Hossein Marzban Date: Wed, 16 Dec 2020 06:10:41 +0330 Subject: [PATCH] lint: pluginfw/client_plugins (#4572) --- src/static/js/pluginfw/client_plugins.js | 48 +++++++++++------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/static/js/pluginfw/client_plugins.js b/src/static/js/pluginfw/client_plugins.js index dadfc6811..6163241a6 100644 --- a/src/static/js/pluginfw/client_plugins.js +++ b/src/static/js/pluginfw/client_plugins.js @@ -1,40 +1,36 @@ -let $, jQuery; -$ = jQuery = require('ep_etherpad-lite/static/js/rjquery').$; -const _ = require('underscore'); +'use strict'; const pluginUtils = require('./shared'); const defs = require('./plugin_defs'); exports.baseURL = ''; -exports.ensure = function (cb) { - if (!defs.loaded) exports.update(cb); - else cb(); -}; +exports.ensure = (cb) => !defs.loaded ? exports.update(cb) : cb(); -exports.update = function (cb) { +exports.update = (cb) => { // It appears that this response (see #620) may interrupt the current thread // of execution on Firefox. This schedules the response in the run-loop, // which appears to fix the issue. - const callback = function () { setTimeout(cb, 0); }; + const callback = () => setTimeout(cb, 0); $.ajaxSetup({cache: false}); + jQuery.getJSON(`${exports.baseURL}pluginfw/plugin-definitions.json`).done((data) => { defs.plugins = data.plugins; defs.parts = data.parts; defs.hooks = pluginUtils.extractHooks(defs.parts, 'client_hooks'); defs.loaded = true; callback(); - }).fail((e) => { + }).fail((err) => { console.error(`Failed to load plugin-definitions: ${err}`); callback(); }); }; -function adoptPluginsFromAncestorsOf(frame) { +const adoptPluginsFromAncestorsOf = (frame) => { // Bind plugins with parent; let parentRequire = null; try { - while (frame = frame.parent) { + while ((frame = frame.parent)) { if (typeof (frame.require) !== 'undefined') { parentRequire = frame.require; break; @@ -42,20 +38,20 @@ function adoptPluginsFromAncestorsOf(frame) { } } catch (error) { // Silence (this can only be a XDomain issue). + console.error(error); } - if (parentRequire) { - const ancestorPluginDefs = parentRequire('ep_etherpad-lite/static/js/pluginfw/plugin_defs'); - defs.hooks = ancestorPluginDefs.hooks; - defs.loaded = ancestorPluginDefs.loaded; - defs.parts = ancestorPluginDefs.parts; - defs.plugins = ancestorPluginDefs.plugins; - const ancestorPlugins = parentRequire('ep_etherpad-lite/static/js/pluginfw/client_plugins'); - exports.baseURL = ancestorPlugins.baseURL; - exports.ensure = ancestorPlugins.ensure; - exports.update = ancestorPlugins.update; - } else { - throw new Error('Parent plugins could not be found.'); - } -} + + if (!parentRequire) throw new Error('Parent plugins could not be found.'); + + const ancestorPluginDefs = parentRequire('ep_etherpad-lite/static/js/pluginfw/plugin_defs'); + defs.hooks = ancestorPluginDefs.hooks; + defs.loaded = ancestorPluginDefs.loaded; + defs.parts = ancestorPluginDefs.parts; + defs.plugins = ancestorPluginDefs.plugins; + const ancestorPlugins = parentRequire('ep_etherpad-lite/static/js/pluginfw/client_plugins'); + exports.baseURL = ancestorPlugins.baseURL; + exports.ensure = ancestorPlugins.ensure; + exports.update = ancestorPlugins.update; +}; exports.adoptPluginsFromAncestorsOf = adoptPluginsFromAncestorsOf;