mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00
lint: pad prefix files (#4577)
* lint: pad_connectionstatus * lint: pad_utils * lint: pad_userlist.js -- still WIP * shift underscore not to be in require but to be used from window * lint: pad_modals * pad_impexp.js * lint: more errors done * lint: auto reconn * lint: pad_editor * lint: finish auto reconn * lint: imp exp rework * lint: import * lint: pad.js nearly done but pizza here... * lint: clientVars global query * put clientVars in window * Revert incorrect lint fixes * Properly fix guard-for-in lint errors * Properly fix no-unused-vars error regarding `gritter` * Refine lint fixes Co-authored-by: Richard Hansen <rhansen@rhansen.org>
This commit is contained in:
parent
34ee77993f
commit
0362d3b05d
11 changed files with 512 additions and 459 deletions
|
@ -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.
|
||||
|
@ -20,8 +22,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* global $, window */
|
||||
|
||||
let socket;
|
||||
|
||||
// These jQuery things should create local references, but for now `require()`
|
||||
|
@ -43,24 +43,13 @@ const padsavedrevs = require('./pad_savedrevs');
|
|||
const paduserlist = require('./pad_userlist').paduserlist;
|
||||
const padutils = require('./pad_utils').padutils;
|
||||
const colorutils = require('./colorutils').colorutils;
|
||||
var randomString = require('./pad_utils').randomString;
|
||||
const gritter = require('./gritter').gritter;
|
||||
const randomString = require('./pad_utils').randomString;
|
||||
require('./gritter'); // Mutates the jQuery object to make $.gritter available.
|
||||
|
||||
const hooks = require('./pluginfw/hooks');
|
||||
|
||||
let receivedClientVars = false;
|
||||
|
||||
function randomString() {
|
||||
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
const string_length = 20;
|
||||
let randomstring = '';
|
||||
for (let i = 0; i < string_length; i++) {
|
||||
const rnum = Math.floor(Math.random() * chars.length);
|
||||
randomstring += chars.substring(rnum, rnum + 1);
|
||||
}
|
||||
return `t.${randomstring}`;
|
||||
}
|
||||
|
||||
// This array represents all GET-parameters which can be used to change a setting.
|
||||
// name: the parameter-name, eg `?noColors=true` => `noColors`
|
||||
// checkVal: the callback is only executed when
|
||||
|
@ -68,26 +57,101 @@ function randomString() {
|
|||
// * the parameter was supplied and checkVal is null
|
||||
// callback: the function to call when all above succeeds, `val` is the value supplied by the user
|
||||
const getParameters = [
|
||||
{name: 'noColors', checkVal: 'true', callback(val) { settings.noColors = true; $('#clearAuthorship').hide(); }},
|
||||
{name: 'showControls', checkVal: 'true', callback(val) { $('#editbar').css('display', 'flex'); }},
|
||||
{name: 'showChat', checkVal: null, callback(val) { if (val === 'false') { settings.hideChat = true; chat.hide(); $('#chaticon').hide(); } }},
|
||||
{name: 'showLineNumbers', checkVal: 'false', callback(val) { settings.LineNumbersDisabled = true; }},
|
||||
{name: 'useMonospaceFont', checkVal: 'true', callback(val) { settings.useMonospaceFontGlobal = true; }},
|
||||
// If the username is set as a parameter we should set a global value that we can call once we have initiated the pad.
|
||||
{name: 'userName', checkVal: null, callback(val) { settings.globalUserName = decodeURIComponent(val); clientVars.userName = decodeURIComponent(val); }},
|
||||
// If the userColor is set as a parameter, set a global value to use once we have initiated the pad.
|
||||
{name: 'userColor', checkVal: null, callback(val) { settings.globalUserColor = decodeURIComponent(val); clientVars.userColor = decodeURIComponent(val); }},
|
||||
{name: 'rtl', checkVal: 'true', callback(val) { settings.rtlIsTrue = true; }},
|
||||
{name: 'alwaysShowChat', checkVal: 'true', callback(val) { if (!settings.hideChat) chat.stickToScreen(); }},
|
||||
{name: 'chatAndUsers', checkVal: 'true', callback(val) { chat.chatAndUsers(); }},
|
||||
{name: 'lang', checkVal: null, callback(val) { window.html10n.localize([val, 'en']); Cookies.set('language', val); }},
|
||||
{
|
||||
name: 'noColors',
|
||||
checkVal: 'true',
|
||||
callback: (val) => {
|
||||
settings.noColors = true;
|
||||
$('#clearAuthorship').hide();
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'showControls',
|
||||
checkVal: 'true',
|
||||
callback: (val) => {
|
||||
$('#editbar').css('display', 'flex');
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'showChat',
|
||||
checkVal: null,
|
||||
callback: (val) => {
|
||||
if (val === 'false') {
|
||||
settings.hideChat = true;
|
||||
chat.hide();
|
||||
$('#chaticon').hide();
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'showLineNumbers',
|
||||
checkVal: 'false',
|
||||
callback: (val) => {
|
||||
settings.LineNumbersDisabled = true;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'useMonospaceFont',
|
||||
checkVal: 'true',
|
||||
callback: (val) => {
|
||||
settings.useMonospaceFontGlobal = true;
|
||||
},
|
||||
},
|
||||
// If the username is set as a parameter we should set a global value that we can call once we
|
||||
// have initiated the pad.
|
||||
{
|
||||
name: 'userName',
|
||||
checkVal: null,
|
||||
callback: (val) => {
|
||||
settings.globalUserName = decodeURIComponent(val);
|
||||
clientVars.userName = decodeURIComponent(val);
|
||||
},
|
||||
},
|
||||
// If the userColor is set as a parameter, set a global value to use once we have initiated the
|
||||
// pad.
|
||||
{
|
||||
name: 'userColor',
|
||||
checkVal: null,
|
||||
callback: (val) => {
|
||||
settings.globalUserColor = decodeURIComponent(val);
|
||||
clientVars.userColor = decodeURIComponent(val);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'rtl',
|
||||
checkVal: 'true',
|
||||
callback: (val) => {
|
||||
settings.rtlIsTrue = true;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'alwaysShowChat',
|
||||
checkVal: 'true',
|
||||
callback: (val) => {
|
||||
if (!settings.hideChat) chat.stickToScreen();
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'chatAndUsers',
|
||||
checkVal: 'true',
|
||||
callback: (val) => {
|
||||
chat.chatAndUsers();
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'lang',
|
||||
checkVal: null,
|
||||
callback: (val) => {
|
||||
window.html10n.localize([val, 'en']);
|
||||
Cookies.set('language', val);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
function getParams() {
|
||||
const getParams = () => {
|
||||
// Tries server enforced options first..
|
||||
for (var i = 0; i < getParameters.length; i++) {
|
||||
var setting = getParameters[i];
|
||||
var value = clientVars.padOptions[setting.name];
|
||||
for (const setting of getParameters) {
|
||||
const value = clientVars.padOptions[setting.name];
|
||||
if (value.toString() === setting.checkVal) {
|
||||
setting.callback(value);
|
||||
}
|
||||
|
@ -96,19 +160,18 @@ function getParams() {
|
|||
// Then URL applied stuff
|
||||
const params = getUrlVars();
|
||||
|
||||
for (var i = 0; i < getParameters.length; i++) {
|
||||
var setting = getParameters[i];
|
||||
var value = params[setting.name];
|
||||
for (const setting of getParameters) {
|
||||
const value = params[setting.name];
|
||||
|
||||
if (value && (value == setting.checkVal || setting.checkVal == null)) {
|
||||
if (value && (value === setting.checkVal || setting.checkVal == null)) {
|
||||
setting.callback(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function getUrlVars() {
|
||||
const vars = []; let
|
||||
hash;
|
||||
const getUrlVars = () => {
|
||||
const vars = [];
|
||||
let hash;
|
||||
const hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
||||
for (let i = 0; i < hashes.length; i++) {
|
||||
hash = hashes[i].split('=');
|
||||
|
@ -116,12 +179,13 @@ function getUrlVars() {
|
|||
vars[hash[0]] = hash[1];
|
||||
}
|
||||
return vars;
|
||||
}
|
||||
};
|
||||
|
||||
function sendClientReady(isReconnect, messageType) {
|
||||
const sendClientReady = (isReconnect, messageType) => {
|
||||
messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
|
||||
let padId = document.location.pathname.substring(document.location.pathname.lastIndexOf('/') + 1);
|
||||
padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
|
||||
// unescape neccesary due to Safari and Opera interpretation of spaces
|
||||
padId = decodeURIComponent(padId);
|
||||
|
||||
if (!isReconnect) {
|
||||
const titleArray = document.title.split('|');
|
||||
|
@ -151,12 +215,12 @@ function sendClientReady(isReconnect, messageType) {
|
|||
}
|
||||
|
||||
socket.json.send(msg);
|
||||
}
|
||||
};
|
||||
|
||||
function handshake() {
|
||||
const handshake = () => {
|
||||
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
|
||||
|
@ -211,12 +275,10 @@ function handshake() {
|
|||
throw new Error(`socket.io connection error: ${JSON.stringify(error)}`);
|
||||
});
|
||||
|
||||
let initalized = false;
|
||||
|
||||
socket.on('message', (obj) => {
|
||||
// the access was not granted, give the user a message
|
||||
if (obj.accessStatus) {
|
||||
if (obj.accessStatus == 'deny') {
|
||||
if (obj.accessStatus === 'deny') {
|
||||
$('#loading').hide();
|
||||
$('#permissionDenied').show();
|
||||
|
||||
|
@ -226,18 +288,15 @@ function handshake() {
|
|||
$('#editorloadingbox').show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if we haven't recieved the clientVars yet, then this message should it be
|
||||
else if (!receivedClientVars && obj.type == 'CLIENT_VARS') {
|
||||
} else if (!receivedClientVars && obj.type === 'CLIENT_VARS') {
|
||||
// if we haven't recieved the clientVars yet, then this message should it be
|
||||
receivedClientVars = true;
|
||||
|
||||
// set some client vars
|
||||
clientVars = obj.data;
|
||||
window.clientVars = obj.data;
|
||||
|
||||
// initalize the pad
|
||||
pad._afterHandshake();
|
||||
initalized = true;
|
||||
|
||||
if (clientVars.readonly) {
|
||||
chat.hide();
|
||||
|
@ -255,63 +314,61 @@ function handshake() {
|
|||
});
|
||||
|
||||
// If the LineNumbersDisabled value is set to true then we need to hide the Line Numbers
|
||||
if (settings.LineNumbersDisabled == true) {
|
||||
if (settings.LineNumbersDisabled === true) {
|
||||
pad.changeViewOption('showLineNumbers', false);
|
||||
}
|
||||
|
||||
// If the noColors value is set to true then we need to hide the background colors on the ace spans
|
||||
if (settings.noColors == true) {
|
||||
// If the noColors value is set to true then we need to
|
||||
// hide the background colors on the ace spans
|
||||
if (settings.noColors === true) {
|
||||
pad.changeViewOption('noColors', true);
|
||||
}
|
||||
|
||||
if (settings.rtlIsTrue == true) {
|
||||
if (settings.rtlIsTrue === true) {
|
||||
pad.changeViewOption('rtlIsTrue', true);
|
||||
}
|
||||
|
||||
// If the Monospacefont value is set to true then change it to monospace.
|
||||
if (settings.useMonospaceFontGlobal == true) {
|
||||
if (settings.useMonospaceFontGlobal === true) {
|
||||
pad.changeViewOption('padFontFamily', 'monospace');
|
||||
}
|
||||
// if the globalUserName value is set we need to tell the server and the client about the new authorname
|
||||
// if the globalUserName value is set we need to tell the server and
|
||||
// the client about the new authorname
|
||||
if (settings.globalUserName !== false) {
|
||||
pad.notifyChangeName(settings.globalUserName); // Notifies the server
|
||||
pad.myUserInfo.name = settings.globalUserName;
|
||||
$('#myusernameedit').val(settings.globalUserName); // Updates the current users UI
|
||||
}
|
||||
if (settings.globalUserColor !== false && colorutils.isCssHex(settings.globalUserColor)) {
|
||||
// Add a 'globalUserColor' property to myUserInfo, so collabClient knows we have a query parameter.
|
||||
// Add a 'globalUserColor' property to myUserInfo,
|
||||
// so collabClient knows we have a query parameter.
|
||||
pad.myUserInfo.globalUserColor = settings.globalUserColor;
|
||||
pad.notifyChangeColor(settings.globalUserColor); // Updates pad.myUserInfo.colorId
|
||||
paduserlist.setMyUserInfo(pad.myUserInfo);
|
||||
}
|
||||
}
|
||||
// This handles every Message after the clientVars
|
||||
else {
|
||||
// this message advices the client to disconnect
|
||||
if (obj.disconnect) {
|
||||
padconnectionstatus.disconnected(obj.disconnect);
|
||||
socket.disconnect();
|
||||
} else if (obj.disconnect) {
|
||||
padconnectionstatus.disconnected(obj.disconnect);
|
||||
socket.disconnect();
|
||||
|
||||
// block user from making any change to the pad
|
||||
padeditor.disable();
|
||||
padeditbar.disable();
|
||||
padimpexp.disable();
|
||||
// block user from making any change to the pad
|
||||
padeditor.disable();
|
||||
padeditbar.disable();
|
||||
padimpexp.disable();
|
||||
|
||||
return;
|
||||
} else {
|
||||
pad.collabClient.handleMessageFromServer(obj);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
pad.collabClient.handleMessageFromServer(obj);
|
||||
}
|
||||
});
|
||||
// Bind the colorpicker
|
||||
const fb = $('#colorpicker').farbtastic({callback: '#mycolorpickerpreview', width: 220});
|
||||
$('#colorpicker').farbtastic({callback: '#mycolorpickerpreview', width: 220});
|
||||
// Bind the read only button
|
||||
$('#readonlyinput').on('click', () => {
|
||||
padeditbar.setEmbedLinks();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var pad = {
|
||||
const pad = {
|
||||
// don't access these directly from outside this file, except
|
||||
// for debugging
|
||||
collabClient: null,
|
||||
|
@ -322,44 +379,28 @@ var pad = {
|
|||
padOptions: {},
|
||||
|
||||
// these don't require init; clientVars should all go through here
|
||||
getPadId() {
|
||||
return clientVars.padId;
|
||||
},
|
||||
getClientIp() {
|
||||
return clientVars.clientIp;
|
||||
},
|
||||
getColorPalette() {
|
||||
return clientVars.colorPalette;
|
||||
},
|
||||
getIsDebugEnabled() {
|
||||
return clientVars.debugEnabled;
|
||||
},
|
||||
getPrivilege(name) {
|
||||
return clientVars.accountPrivs[name];
|
||||
},
|
||||
getUserId() {
|
||||
return pad.myUserInfo.userId;
|
||||
},
|
||||
getUserName() {
|
||||
return pad.myUserInfo.name;
|
||||
},
|
||||
userList() {
|
||||
return paduserlist.users();
|
||||
},
|
||||
switchToPad(padId) {
|
||||
let newHref = new RegExp(/.*\/p\/[^\/]+/).exec(document.location.pathname) || clientVars.padId;
|
||||
getPadId: () => clientVars.padId,
|
||||
getClientIp: () => clientVars.clientIp,
|
||||
getColorPalette: () => clientVars.colorPalette,
|
||||
getIsDebugEnabled: () => clientVars.debugEnabled,
|
||||
getPrivilege: (name) => clientVars.accountPrivs[name],
|
||||
getUserId: () => pad.myUserInfo.userId,
|
||||
getUserName: () => pad.myUserInfo.name,
|
||||
userList: () => paduserlist.users(),
|
||||
switchToPad: (padId) => {
|
||||
let newHref = new RegExp(/.*\/p\/[^/]+/).exec(document.location.pathname) || clientVars.padId;
|
||||
newHref = newHref[0];
|
||||
|
||||
const options = clientVars.padOptions;
|
||||
if (typeof options !== 'undefined' && options != null) {
|
||||
var option_str = [];
|
||||
const optionArr = [];
|
||||
$.each(options, (k, v) => {
|
||||
const str = `${k}=${v}`;
|
||||
option_str.push(str);
|
||||
optionArr.push(str);
|
||||
});
|
||||
var option_str = option_str.join('&');
|
||||
const optionStr = optionArr.join('&');
|
||||
|
||||
newHref = `${newHref}?${option_str}`;
|
||||
newHref = `${newHref}?${optionStr}`;
|
||||
}
|
||||
|
||||
// destroy old pad from DOM
|
||||
|
@ -373,21 +414,21 @@ var pad = {
|
|||
window.history.pushState('', '', newHref);
|
||||
receivedClientVars = false;
|
||||
sendClientReady(false, 'SWITCH_TO_PAD');
|
||||
} else // fallback
|
||||
{
|
||||
} else {
|
||||
// fallback
|
||||
window.location.href = newHref;
|
||||
}
|
||||
},
|
||||
sendClientMessage(msg) {
|
||||
sendClientMessage: (msg) => {
|
||||
pad.collabClient.sendClientMessage(msg);
|
||||
},
|
||||
|
||||
init() {
|
||||
init: () => {
|
||||
padutils.setupGlobalExceptionHandler();
|
||||
|
||||
$(document).ready(() => {
|
||||
// start the custom js
|
||||
if (typeof customStart === 'function') customStart();
|
||||
if (typeof customStart === 'function') customStart(); // eslint-disable-line no-undef
|
||||
handshake();
|
||||
|
||||
// To use etherpad you have to allow cookies.
|
||||
|
@ -406,7 +447,6 @@ var pad = {
|
|||
pad.initTime = +(new Date());
|
||||
pad.padOptions = clientVars.initialOptions;
|
||||
|
||||
// order of inits is important here:
|
||||
pad.myUserInfo = {
|
||||
userId: clientVars.userId,
|
||||
name: clientVars.userName,
|
||||
|
@ -414,18 +454,60 @@ var pad = {
|
|||
colorId: clientVars.userColor,
|
||||
};
|
||||
|
||||
const postAceInit = () => {
|
||||
padeditbar.init();
|
||||
setTimeout(() => {
|
||||
padeditor.ace.focus();
|
||||
}, 0);
|
||||
// if we have a cookie for always showing chat then show it
|
||||
if (padcookie.getPref('chatAlwaysVisible')) {
|
||||
chat.stickToScreen(true); // stick it to the screen
|
||||
$('#options-stickychat').prop('checked', true); // set the checkbox to on
|
||||
}
|
||||
// if we have a cookie for always showing chat then show it
|
||||
if (padcookie.getPref('chatAndUsers')) {
|
||||
chat.chatAndUsers(true); // stick it to the screen
|
||||
$('#options-chatandusers').prop('checked', true); // set the checkbox to on
|
||||
}
|
||||
if (padcookie.getPref('showAuthorshipColors') === false) {
|
||||
pad.changeViewOption('showAuthorColors', false);
|
||||
}
|
||||
if (padcookie.getPref('showLineNumbers') === false) {
|
||||
pad.changeViewOption('showLineNumbers', false);
|
||||
}
|
||||
if (padcookie.getPref('rtlIsTrue') === true) {
|
||||
pad.changeViewOption('rtlIsTrue', true);
|
||||
}
|
||||
pad.changeViewOption('padFontFamily', padcookie.getPref('padFontFamily'));
|
||||
$('#viewfontmenu').val(padcookie.getPref('padFontFamily')).niceSelect('update');
|
||||
|
||||
// Prevent sticky chat or chat and users to be checked for mobiles
|
||||
const checkChatAndUsersVisibility = (x) => {
|
||||
if (x.matches) { // If media query matches
|
||||
$('#options-chatandusers:checked').click();
|
||||
$('#options-stickychat:checked').click();
|
||||
}
|
||||
};
|
||||
const mobileMatch = window.matchMedia('(max-width: 800px)');
|
||||
mobileMatch.addListener(checkChatAndUsersVisibility); // check if window resized
|
||||
setTimeout(() => { checkChatAndUsersVisibility(mobileMatch); }, 0); // check now after load
|
||||
|
||||
$('#editorcontainer').addClass('initialized');
|
||||
|
||||
hooks.aCallAll('postAceInit', {ace: padeditor.ace, pad});
|
||||
};
|
||||
|
||||
// order of inits is important here:
|
||||
padimpexp.init(this);
|
||||
padsavedrevs.init(this);
|
||||
|
||||
padeditor.init(postAceInit, pad.padOptions.view || {}, this);
|
||||
|
||||
paduserlist.init(pad.myUserInfo, this);
|
||||
padconnectionstatus.init();
|
||||
padmodals.init(this);
|
||||
|
||||
pad.collabClient = getCollabClient(padeditor.ace, clientVars.collab_client_vars, pad.myUserInfo, {
|
||||
colorPalette: pad.getColorPalette(),
|
||||
}, pad);
|
||||
pad.collabClient = getCollabClient(
|
||||
padeditor.ace, clientVars.collab_client_vars, pad.myUserInfo,
|
||||
{colorPalette: pad.getColorPalette()}, pad);
|
||||
pad.collabClient.setOnUserJoin(pad.handleUserJoin);
|
||||
pad.collabClient.setOnUpdateUserInfo(pad.handleUserUpdate);
|
||||
pad.collabClient.setOnUserLeave(pad.handleUserLeave);
|
||||
|
@ -434,68 +516,27 @@ var pad = {
|
|||
pad.collabClient.setOnInternalAction(pad.handleCollabAction);
|
||||
|
||||
// load initial chat-messages
|
||||
if (clientVars.chatHead != -1) {
|
||||
if (clientVars.chatHead !== -1) {
|
||||
const chatHead = clientVars.chatHead;
|
||||
const start = Math.max(chatHead - 100, 0);
|
||||
pad.collabClient.sendMessage({type: 'GET_CHAT_MESSAGES', start, end: chatHead});
|
||||
} else // there are no messages
|
||||
{
|
||||
} else {
|
||||
// there are no messages
|
||||
$('#chatloadmessagesbutton').css('display', 'none');
|
||||
}
|
||||
|
||||
function postAceInit() {
|
||||
padeditbar.init();
|
||||
setTimeout(() => {
|
||||
padeditor.ace.focus();
|
||||
}, 0);
|
||||
if (padcookie.getPref('chatAlwaysVisible')) { // if we have a cookie for always showing chat then show it
|
||||
chat.stickToScreen(true); // stick it to the screen
|
||||
$('#options-stickychat').prop('checked', true); // set the checkbox to on
|
||||
}
|
||||
if (padcookie.getPref('chatAndUsers')) { // if we have a cookie for always showing chat then show it
|
||||
chat.chatAndUsers(true); // stick it to the screen
|
||||
$('#options-chatandusers').prop('checked', true); // set the checkbox to on
|
||||
}
|
||||
if (padcookie.getPref('showAuthorshipColors') == false) {
|
||||
pad.changeViewOption('showAuthorColors', false);
|
||||
}
|
||||
if (padcookie.getPref('showLineNumbers') == false) {
|
||||
pad.changeViewOption('showLineNumbers', false);
|
||||
}
|
||||
if (padcookie.getPref('rtlIsTrue') == true) {
|
||||
pad.changeViewOption('rtlIsTrue', true);
|
||||
}
|
||||
pad.changeViewOption('padFontFamily', padcookie.getPref('padFontFamily'));
|
||||
$('#viewfontmenu').val(padcookie.getPref('padFontFamily')).niceSelect('update');
|
||||
|
||||
// Prevent sticky chat or chat and users to be checked for mobiles
|
||||
function checkChatAndUsersVisibility(x) {
|
||||
if (x.matches) { // If media query matches
|
||||
$('#options-chatandusers:checked').click();
|
||||
$('#options-stickychat:checked').click();
|
||||
}
|
||||
}
|
||||
const mobileMatch = window.matchMedia('(max-width: 800px)');
|
||||
mobileMatch.addListener(checkChatAndUsersVisibility); // check if window resized
|
||||
setTimeout(() => { checkChatAndUsersVisibility(mobileMatch); }, 0); // check now after load
|
||||
|
||||
$('#editorcontainer').addClass('initialized');
|
||||
|
||||
hooks.aCallAll('postAceInit', {ace: padeditor.ace, pad});
|
||||
}
|
||||
},
|
||||
dispose() {
|
||||
dispose: () => {
|
||||
padeditor.dispose();
|
||||
},
|
||||
notifyChangeName(newName) {
|
||||
notifyChangeName: (newName) => {
|
||||
pad.myUserInfo.name = newName;
|
||||
pad.collabClient.updateUserInfo(pad.myUserInfo);
|
||||
},
|
||||
notifyChangeColor(newColorId) {
|
||||
notifyChangeColor: (newColorId) => {
|
||||
pad.myUserInfo.colorId = newColorId;
|
||||
pad.collabClient.updateUserInfo(pad.myUserInfo);
|
||||
},
|
||||
changePadOption(key, value) {
|
||||
changePadOption: (key, value) => {
|
||||
const options = {};
|
||||
options[key] = value;
|
||||
pad.handleOptionsChange(options);
|
||||
|
@ -506,32 +547,30 @@ var pad = {
|
|||
changedBy: pad.myUserInfo.name || 'unnamed',
|
||||
});
|
||||
},
|
||||
changeViewOption(key, value) {
|
||||
changeViewOption: (key, value) => {
|
||||
const options = {
|
||||
view: {},
|
||||
};
|
||||
options.view[key] = value;
|
||||
pad.handleOptionsChange(options);
|
||||
},
|
||||
handleOptionsChange(opts) {
|
||||
handleOptionsChange: (opts) => {
|
||||
// opts object is a full set of options or just
|
||||
// some options to change
|
||||
if (opts.view) {
|
||||
if (!pad.padOptions.view) {
|
||||
pad.padOptions.view = {};
|
||||
}
|
||||
for (const k in opts.view) {
|
||||
pad.padOptions.view[k] = opts.view[k];
|
||||
padcookie.setPref(k, opts.view[k]);
|
||||
for (const [k, v] of Object.entries(opts.view)) {
|
||||
pad.padOptions.view[k] = v;
|
||||
padcookie.setPref(k, v);
|
||||
}
|
||||
padeditor.setViewOptions(pad.padOptions.view);
|
||||
}
|
||||
},
|
||||
getPadOptions() {
|
||||
// caller shouldn't mutate the object
|
||||
return pad.padOptions;
|
||||
},
|
||||
suggestUserName(userId, name) {
|
||||
// caller shouldn't mutate the object
|
||||
getPadOptions: () => pad.padOptions,
|
||||
suggestUserName: (userId, name) => {
|
||||
pad.collabClient.sendClientMessage(
|
||||
{
|
||||
type: 'suggestUserName',
|
||||
|
@ -539,31 +578,31 @@ var pad = {
|
|||
newName: name,
|
||||
});
|
||||
},
|
||||
handleUserJoin(userInfo) {
|
||||
handleUserJoin: (userInfo) => {
|
||||
paduserlist.userJoinOrUpdate(userInfo);
|
||||
},
|
||||
handleUserUpdate(userInfo) {
|
||||
handleUserUpdate: (userInfo) => {
|
||||
paduserlist.userJoinOrUpdate(userInfo);
|
||||
},
|
||||
handleUserLeave(userInfo) {
|
||||
handleUserLeave: (userInfo) => {
|
||||
paduserlist.userLeave(userInfo);
|
||||
},
|
||||
handleClientMessage(msg) {
|
||||
if (msg.type == 'suggestUserName') {
|
||||
if (msg.unnamedId == pad.myUserInfo.userId && msg.newName && !pad.myUserInfo.name) {
|
||||
handleClientMessage: (msg) => {
|
||||
if (msg.type === 'suggestUserName') {
|
||||
if (msg.unnamedId === pad.myUserInfo.userId && msg.newName && !pad.myUserInfo.name) {
|
||||
pad.notifyChangeName(msg.newName);
|
||||
paduserlist.setMyUserInfo(pad.myUserInfo);
|
||||
}
|
||||
} else if (msg.type == 'newRevisionList') {
|
||||
} else if (msg.type === 'newRevisionList') {
|
||||
padsavedrevs.newRevisionList(msg.revisionList);
|
||||
} else if (msg.type == 'revisionLabel') {
|
||||
} else if (msg.type === 'revisionLabel') {
|
||||
padsavedrevs.newRevisionList(msg.revisionList);
|
||||
} else if (msg.type == 'padoptions') {
|
||||
} else if (msg.type === 'padoptions') {
|
||||
const opts = msg.options;
|
||||
pad.handleOptionsChange(opts);
|
||||
}
|
||||
},
|
||||
dmesg(m) {
|
||||
dmesg: (m) => {
|
||||
if (pad.getIsDebugEnabled()) {
|
||||
const djs = $('#djs').get(0);
|
||||
const wasAtBottom = (djs.scrollTop - (djs.scrollHeight - $(djs).height()) >= -20);
|
||||
|
@ -573,31 +612,30 @@ var pad = {
|
|||
}
|
||||
}
|
||||
},
|
||||
handleChannelStateChange(newState, message) {
|
||||
handleChannelStateChange: (newState, message) => {
|
||||
const oldFullyConnected = !!padconnectionstatus.isFullyConnected();
|
||||
const wasConnecting = (padconnectionstatus.getStatus().what == 'connecting');
|
||||
if (newState == 'CONNECTED') {
|
||||
const wasConnecting = (padconnectionstatus.getStatus().what === 'connecting');
|
||||
if (newState === 'CONNECTED') {
|
||||
padeditor.enable();
|
||||
padeditbar.enable();
|
||||
padimpexp.enable();
|
||||
padconnectionstatus.connected();
|
||||
} else if (newState == 'RECONNECTING') {
|
||||
} else if (newState === 'RECONNECTING') {
|
||||
padeditor.disable();
|
||||
padeditbar.disable();
|
||||
padimpexp.disable();
|
||||
padconnectionstatus.reconnecting();
|
||||
} else if (newState == 'DISCONNECTED') {
|
||||
} else if (newState === 'DISCONNECTED') {
|
||||
pad.diagnosticInfo.disconnectedMessage = message;
|
||||
pad.diagnosticInfo.padId = pad.getPadId();
|
||||
pad.diagnosticInfo.socket = {};
|
||||
|
||||
// we filter non objects from the socket object and put them in the diagnosticInfo
|
||||
// this ensures we have no cyclic data - this allows us to stringify the data
|
||||
for (const i in socket.socket) {
|
||||
const value = socket.socket[i];
|
||||
for (const [i, value] of Object.entries(socket.socket || {})) {
|
||||
const type = typeof value;
|
||||
|
||||
if (type == 'string' || type == 'number') {
|
||||
if (type === 'string' || type === 'number') {
|
||||
pad.diagnosticInfo.socket[i] = value;
|
||||
}
|
||||
}
|
||||
|
@ -613,11 +651,11 @@ var pad = {
|
|||
padconnectionstatus.disconnected(message);
|
||||
}
|
||||
const newFullyConnected = !!padconnectionstatus.isFullyConnected();
|
||||
if (newFullyConnected != oldFullyConnected) {
|
||||
if (newFullyConnected !== oldFullyConnected) {
|
||||
pad.handleIsFullyConnected(newFullyConnected, wasConnecting);
|
||||
}
|
||||
},
|
||||
handleIsFullyConnected(isConnected, isInitialConnect) {
|
||||
handleIsFullyConnected: (isConnected, isInitialConnect) => {
|
||||
pad.determineChatVisibility(isConnected && !isInitialConnect);
|
||||
pad.determineChatAndUsersVisibility(isConnected && !isInitialConnect);
|
||||
pad.determineAuthorshipColorsVisibility();
|
||||
|
@ -625,7 +663,7 @@ var pad = {
|
|||
padeditbar.toggleDropDown('none');
|
||||
}, 1000);
|
||||
},
|
||||
determineChatVisibility(asNowConnectedFeedback) {
|
||||
determineChatVisibility: (asNowConnectedFeedback) => {
|
||||
const chatVisCookie = padcookie.getPref('chatAlwaysVisible');
|
||||
if (chatVisCookie) { // if the cookie is set for chat always visible
|
||||
chat.stickToScreen(true); // stick it to the screen
|
||||
|
@ -634,7 +672,7 @@ var pad = {
|
|||
$('#options-stickychat').prop('checked', false); // set the checkbox for off
|
||||
}
|
||||
},
|
||||
determineChatAndUsersVisibility(asNowConnectedFeedback) {
|
||||
determineChatAndUsersVisibility: (asNowConnectedFeedback) => {
|
||||
const chatAUVisCookie = padcookie.getPref('chatAndUsersVisible');
|
||||
if (chatAUVisCookie) { // if the cookie is set for chat always visible
|
||||
chat.chatAndUsers(true); // stick it to the screen
|
||||
|
@ -643,7 +681,7 @@ var pad = {
|
|||
$('#options-chatandusers').prop('checked', false); // set the checkbox for off
|
||||
}
|
||||
},
|
||||
determineAuthorshipColorsVisibility() {
|
||||
determineAuthorshipColorsVisibility: () => {
|
||||
const authColCookie = padcookie.getPref('showAuthorshipColors');
|
||||
if (authColCookie) {
|
||||
pad.changeViewOption('showAuthorColors', true);
|
||||
|
@ -652,14 +690,14 @@ var pad = {
|
|||
$('#options-colorscheck').prop('checked', false);
|
||||
}
|
||||
},
|
||||
handleCollabAction(action) {
|
||||
if (action == 'commitPerformed') {
|
||||
handleCollabAction: (action) => {
|
||||
if (action === 'commitPerformed') {
|
||||
padeditbar.setSyncStatus('syncing');
|
||||
} else if (action == 'newlyIdle') {
|
||||
} else if (action === 'newlyIdle') {
|
||||
padeditbar.setSyncStatus('done');
|
||||
}
|
||||
},
|
||||
asyncSendDiagnosticInfo() {
|
||||
asyncSendDiagnosticInfo: () => {
|
||||
window.setTimeout(() => {
|
||||
$.ajax(
|
||||
{
|
||||
|
@ -668,32 +706,29 @@ var pad = {
|
|||
data: {
|
||||
diagnosticInfo: JSON.stringify(pad.diagnosticInfo),
|
||||
},
|
||||
success() {},
|
||||
error() {},
|
||||
success: () => {},
|
||||
error: () => {},
|
||||
});
|
||||
}, 0);
|
||||
},
|
||||
forceReconnect() {
|
||||
forceReconnect: () => {
|
||||
$('form#reconnectform input.padId').val(pad.getPadId());
|
||||
pad.diagnosticInfo.collabDiagnosticInfo = pad.collabClient.getDiagnosticInfo();
|
||||
$('form#reconnectform input.diagnosticInfo').val(JSON.stringify(pad.diagnosticInfo));
|
||||
$('form#reconnectform input.missedChanges').val(JSON.stringify(pad.collabClient.getMissedChanges()));
|
||||
$('form#reconnectform input.missedChanges')
|
||||
.val(JSON.stringify(pad.collabClient.getMissedChanges()));
|
||||
$('form#reconnectform').submit();
|
||||
},
|
||||
// this is called from code put into a frame from the server:
|
||||
handleImportExportFrameCall(callName, varargs) {
|
||||
handleImportExportFrameCall: (callName, varargs) => {
|
||||
padimpexp.handleFrameCall.call(padimpexp, callName, Array.prototype.slice.call(arguments, 1));
|
||||
},
|
||||
callWhenNotCommitting(f) {
|
||||
callWhenNotCommitting: (f) => {
|
||||
pad.collabClient.callWhenNotCommitting(f);
|
||||
},
|
||||
getCollabRevisionNumber() {
|
||||
return pad.collabClient.getCurrentRevisionNumber();
|
||||
},
|
||||
isFullyConnected() {
|
||||
return padconnectionstatus.isFullyConnected();
|
||||
},
|
||||
addHistoricalAuthors(data) {
|
||||
getCollabRevisionNumber: () => pad.collabClient.getCurrentRevisionNumber(),
|
||||
isFullyConnected: () => padconnectionstatus.isFullyConnected(),
|
||||
addHistoricalAuthors: (data) => {
|
||||
if (!pad.collabClient) {
|
||||
window.setTimeout(() => {
|
||||
pad.addHistoricalAuthors(data);
|
||||
|
@ -704,11 +739,9 @@ var pad = {
|
|||
},
|
||||
};
|
||||
|
||||
function init() {
|
||||
return pad.init();
|
||||
}
|
||||
const init = () => pad.init();
|
||||
|
||||
var settings = {
|
||||
const settings = {
|
||||
LineNumbersDisabled: false,
|
||||
noColors: false,
|
||||
useMonospaceFontGlobal: false,
|
||||
|
@ -718,6 +751,7 @@ var settings = {
|
|||
};
|
||||
|
||||
pad.settings = settings;
|
||||
|
||||
exports.baseURL = '';
|
||||
exports.settings = settings;
|
||||
exports.randomString = randomString;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue