Lint: timeslider (#4580)

Squashed changes from rhansen@rhansen.org:
  * Move code back to where it was. (It's easier to review changes
    when the code isn't moved. This causes some no-use-before-define
    warnings to reappear, but those are just warnings.)
  * Move eslint-disable comment to same line
  * Use `window.clientvars` to resolve no-global-assign
  * Undo changes that aren't about fixing lint errors
pull/4574/head^2
Hossein Marzban 2020-12-21 02:54:17 +03:30 committed by GitHub
parent bca60c8b17
commit 170a230c3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 17 deletions

View File

@ -1,3 +1,5 @@
'use strict';
/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
@ -28,12 +30,12 @@ const Cookies = require('./pad_utils').Cookies;
const randomString = require('./pad_utils').randomString;
const hooks = require('./pluginfw/hooks');
let token, padId, export_links;
let token, padId, exportLinks, socket, changesetLoader, BroadcastSlider;
function init() {
const init = () => {
$(document).ready(() => {
// start the custom js
if (typeof customStart === 'function') customStart();
if (typeof customStart === 'function') customStart(); // eslint-disable-line no-undef
// get the padId out of the url
const urlParts = document.location.pathname.split('/');
@ -51,7 +53,7 @@ function init() {
const loc = document.location;
// get the correct port
const port = loc.port == '' ? (loc.protocol == 'https:' ? 443 : 80) : loc.port;
const port = loc.port === '' ? (loc.protocol === 'https:' ? 443 : 80) : loc.port;
// create the url
const url = `${loc.protocol}//${loc.hostname}:${port}/`;
// find out in which subfolder we are
@ -71,7 +73,7 @@ function init() {
// route the incoming messages
socket.on('message', (message) => {
if (message.type == 'CLIENT_VARS') {
if (message.type === 'CLIENT_VARS') {
handleClientVars(message);
} else if (message.accessStatus) {
$('body').html('<h2>You have no permission to access this pad</h2>');
@ -81,7 +83,7 @@ function init() {
});
// get all the export links
export_links = $('#export > .exportlink');
exportLinks = $('#export > .exportlink');
$('button#forcereconnect').click(() => {
window.location.reload();
@ -92,10 +94,10 @@ function init() {
hooks.aCallAll('postTimesliderInit');
});
}
};
// sends a message over the socket
function sendSocketMsg(type, data) {
const sendSocketMsg = (type, data) => {
socket.json.send({
component: 'pad', // FIXME: Remove this stupidity!
type,
@ -105,19 +107,21 @@ function sendSocketMsg(type, data) {
sessionID: Cookies.get('sessionID'),
protocolVersion: 2,
});
}
};
const fireWhenAllScriptsAreLoaded = [];
let changesetLoader;
function handleClientVars(message) {
const handleClientVars = (message) => {
// save the client Vars
clientVars = message.data;
window.clientVars = message.data;
// load all script that doesn't work without the clientVars
BroadcastSlider = require('./broadcast_slider').loadBroadcastSliderJS(fireWhenAllScriptsAreLoaded);
BroadcastSlider = require('./broadcast_slider')
.loadBroadcastSliderJS(fireWhenAllScriptsAreLoaded);
require('./broadcast_revisions').loadBroadcastRevisionsJS();
changesetLoader = require('./broadcast').loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, BroadcastSlider);
changesetLoader = require('./broadcast')
.loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, BroadcastSlider);
// initialize export ui
require('./pad_impexp').padimpexp.init();
@ -127,8 +131,8 @@ function handleClientVars(message) {
// change export urls when the slider moves
BroadcastSlider.onSlider((revno) => {
// export_links is a jQuery Array, so .each is allowed.
export_links.each(function () {
// exportLinks is a jQuery Array, so .each is allowed.
exportLinks.each(function () {
// Modified from regular expression to fix:
// https://github.com/ether/etherpad-lite/issues/4071
// Where a padId that was numeric would create the wrong export link
@ -156,7 +160,7 @@ function handleClientVars(message) {
$('#viewfontmenu').change(function () {
$('#innerdocbody').css('font-family', $(this).val() || '');
});
}
};
exports.baseURL = '';
exports.init = init;