2020-12-20 08:15:58 +01:00
|
|
|
'use strict';
|
|
|
|
|
2011-12-04 16:33:56 +01:00
|
|
|
/**
|
2017-05-03 17:59:57 +02:00
|
|
|
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
2011-12-04 16:33:56 +01:00
|
|
|
* This helps other people to understand this code better and helps them to improve it.
|
|
|
|
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
|
|
|
*/
|
|
|
|
|
2011-03-26 14:10:41 +01:00
|
|
|
/**
|
2011-08-11 16:26:41 +02:00
|
|
|
* Copyright 2009 Google Inc., 2011 Peter 'Pita' Martischka (Primary Technology Ltd)
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-07-07 19:59:34 +02:00
|
|
|
*
|
2011-03-26 14:10:41 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
let socket;
|
2012-01-16 03:22:28 +01:00
|
|
|
|
2012-01-29 00:26:39 +01:00
|
|
|
// These jQuery things should create local references, but for now `require()`
|
|
|
|
// assigns to the global `$` and augments it with plugins.
|
2012-03-07 02:27:03 +01:00
|
|
|
require('./jquery');
|
|
|
|
require('./farbtastic');
|
|
|
|
require('./excanvas');
|
2020-12-10 23:24:28 +01:00
|
|
|
require('./gritter');
|
2012-01-29 00:26:39 +01:00
|
|
|
|
2020-10-03 00:43:12 +02:00
|
|
|
const Cookies = require('./pad_utils').Cookies;
|
2020-11-23 19:24:19 +01:00
|
|
|
const chat = require('./chat').chat;
|
|
|
|
const getCollabClient = require('./collab_client').getCollabClient;
|
|
|
|
const padconnectionstatus = require('./pad_connectionstatus').padconnectionstatus;
|
|
|
|
const padcookie = require('./pad_cookie').padcookie;
|
|
|
|
const padeditbar = require('./pad_editbar').padeditbar;
|
|
|
|
const padeditor = require('./pad_editor').padeditor;
|
|
|
|
const padimpexp = require('./pad_impexp').padimpexp;
|
|
|
|
const padmodals = require('./pad_modals').padmodals;
|
|
|
|
const padsavedrevs = require('./pad_savedrevs');
|
|
|
|
const paduserlist = require('./pad_userlist').paduserlist;
|
|
|
|
const padutils = require('./pad_utils').padutils;
|
|
|
|
const colorutils = require('./colorutils').colorutils;
|
2020-12-20 08:15:58 +01:00
|
|
|
const randomString = require('./pad_utils').randomString;
|
2020-12-10 23:24:28 +01:00
|
|
|
const socketio = require('./socketio');
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
const hooks = require('./pluginfw/hooks');
|
2012-03-27 22:23:55 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
let receivedClientVars = false;
|
2014-06-14 20:24:54 +02:00
|
|
|
|
2013-01-27 11:02:15 +01:00
|
|
|
// 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
|
|
|
|
// * the parameter was supplied and matches checkVal
|
|
|
|
// * 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
|
2020-11-23 19:24:19 +01:00
|
|
|
const getParameters = [
|
2020-12-20 08:15:58 +01:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
},
|
2013-01-27 11:02:15 +01:00
|
|
|
];
|
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const getParams = () => {
|
2015-04-11 22:22:00 +02:00
|
|
|
// Tries server enforced options first..
|
2020-12-20 08:15:58 +01:00
|
|
|
for (const setting of getParameters) {
|
|
|
|
const value = clientVars.padOptions[setting.name];
|
2020-11-23 19:24:19 +01:00
|
|
|
if (value.toString() === setting.checkVal) {
|
2015-04-11 22:22:00 +02:00
|
|
|
setting.callback(value);
|
|
|
|
}
|
|
|
|
}
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2015-04-11 22:22:00 +02:00
|
|
|
// Then URL applied stuff
|
2020-11-23 19:24:19 +01:00
|
|
|
const params = getUrlVars();
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
for (const setting of getParameters) {
|
|
|
|
const value = params[setting.name];
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
if (value && (value === setting.checkVal || setting.checkVal == null)) {
|
2013-01-27 11:02:15 +01:00
|
|
|
setting.callback(value);
|
2012-11-12 18:31:02 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-08-12 17:00:09 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const getUrlVars = () => {
|
|
|
|
const vars = [];
|
|
|
|
let hash;
|
2020-11-23 19:24:19 +01:00
|
|
|
const hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
|
|
|
for (let i = 0; i < hashes.length; i++) {
|
2011-08-12 17:00:09 +02:00
|
|
|
hash = hashes[i].split('=');
|
|
|
|
vars.push(hash[0]);
|
|
|
|
vars[hash[0]] = hash[1];
|
|
|
|
}
|
|
|
|
return vars;
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-08-12 17:00:09 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const sendClientReady = (isReconnect, messageType) => {
|
2014-07-12 22:27:00 +02:00
|
|
|
messageType = typeof messageType !== 'undefined' ? messageType : 'CLIENT_READY';
|
2020-11-23 19:24:19 +01:00
|
|
|
let padId = document.location.pathname.substring(document.location.pathname.lastIndexOf('/') + 1);
|
2020-12-20 08:15:58 +01:00
|
|
|
// unescape neccesary due to Safari and Opera interpretation of spaces
|
|
|
|
padId = decodeURIComponent(padId);
|
2014-06-14 20:24:54 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
if (!isReconnect) {
|
|
|
|
const titleArray = document.title.split('|');
|
|
|
|
const title = titleArray[titleArray.length - 1];
|
|
|
|
document.title = `${padId.replace(/_+/g, ' ')} | ${title}`;
|
2014-06-14 20:24:54 +02:00
|
|
|
}
|
|
|
|
|
2020-10-03 00:43:12 +02:00
|
|
|
let token = Cookies.get('token');
|
2020-11-23 19:24:19 +01:00
|
|
|
if (token == null) {
|
|
|
|
token = `t.${randomString()}`;
|
2020-10-03 00:43:12 +02:00
|
|
|
Cookies.set('token', token, {expires: 60});
|
2014-06-14 20:24:54 +02:00
|
|
|
}
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-10-03 00:43:12 +02:00
|
|
|
const msg = {
|
|
|
|
component: 'pad',
|
|
|
|
type: messageType,
|
2020-11-23 19:24:19 +01:00
|
|
|
padId,
|
2020-10-03 00:43:12 +02:00
|
|
|
sessionID: Cookies.get('sessionID'),
|
2020-11-23 19:24:19 +01:00
|
|
|
token,
|
|
|
|
protocolVersion: 2,
|
2014-06-14 20:24:54 +02:00
|
|
|
};
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-09-13 06:43:38 +02:00
|
|
|
// this is a reconnect, lets tell the server our revisionnumber
|
|
|
|
if (isReconnect) {
|
|
|
|
msg.client_rev = pad.collabClient.getCurrentRevisionNumber();
|
|
|
|
msg.reconnect = true;
|
2014-06-14 20:24:54 +02:00
|
|
|
}
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2014-06-14 20:24:54 +02:00
|
|
|
socket.json.send(msg);
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2014-06-14 20:24:54 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const handshake = () => {
|
2020-12-10 23:24:28 +01:00
|
|
|
socket = pad.socket = socketio.connect(exports.baseURL, '/', {
|
2020-11-23 19:24:19 +01:00
|
|
|
reconnectionAttempts: 5,
|
|
|
|
reconnection: true,
|
|
|
|
reconnectionDelay: 1000,
|
|
|
|
reconnectionDelayMax: 5000,
|
2011-07-07 19:59:34 +02:00
|
|
|
});
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
socket.once('connect', () => {
|
2011-11-26 00:24:10 +01:00
|
|
|
sendClientReady(false);
|
|
|
|
});
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
socket.on('reconnect', () => {
|
2020-10-19 20:19:07 +02:00
|
|
|
// pad.collabClient might be null if the hanshake failed (or it never got that far).
|
|
|
|
if (pad.collabClient != null) {
|
|
|
|
pad.collabClient.setChannelState('CONNECTED');
|
|
|
|
}
|
2020-10-20 01:35:30 +02:00
|
|
|
sendClientReady(receivedClientVars);
|
2011-11-26 00:24:10 +01:00
|
|
|
});
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
socket.on('reconnecting', () => {
|
2020-10-19 20:19:07 +02:00
|
|
|
// pad.collabClient might be null if the hanshake failed (or it never got that far).
|
|
|
|
if (pad.collabClient != null) {
|
|
|
|
pad.collabClient.setStateIdle();
|
|
|
|
pad.collabClient.setIsPendingRevision(true);
|
|
|
|
pad.collabClient.setChannelState('RECONNECTING');
|
|
|
|
}
|
2016-11-20 12:27:27 +01:00
|
|
|
});
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
socket.on('reconnect_failed', (error) => {
|
2020-10-19 20:19:07 +02:00
|
|
|
// pad.collabClient might be null if the hanshake failed (or it never got that far).
|
|
|
|
if (pad.collabClient != null) {
|
|
|
|
pad.collabClient.setChannelState('DISCONNECTED', 'reconnect_timeout');
|
|
|
|
} else {
|
|
|
|
throw new Error('Reconnect timed out');
|
|
|
|
}
|
2011-07-07 19:59:34 +02:00
|
|
|
});
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
socket.on('error', (error) => {
|
2020-10-19 20:19:07 +02:00
|
|
|
// pad.collabClient might be null if the error occurred before the hanshake completed.
|
|
|
|
if (pad.collabClient != null) {
|
|
|
|
pad.collabClient.setStateIdle();
|
|
|
|
pad.collabClient.setIsPendingRevision(true);
|
|
|
|
}
|
2020-10-19 20:12:09 +02:00
|
|
|
throw new Error(`socket.io connection error: ${JSON.stringify(error)}`);
|
2018-02-05 18:07:49 +01:00
|
|
|
});
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
socket.on('message', (obj) => {
|
|
|
|
// the access was not granted, give the user a message
|
|
|
|
if (obj.accessStatus) {
|
2020-12-20 08:15:58 +01:00
|
|
|
if (obj.accessStatus === 'deny') {
|
2012-12-02 18:03:56 +01:00
|
|
|
$('#loading').hide();
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#permissionDenied').show();
|
2013-04-03 11:19:26 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
if (receivedClientVars) {
|
2013-04-03 11:19:26 +02:00
|
|
|
// got kicked
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#editorcontainer').hide();
|
|
|
|
$('#editorloadingbox').show();
|
2013-04-03 11:19:26 +02:00
|
|
|
}
|
2011-08-15 19:26:20 +02:00
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
} else if (!receivedClientVars && obj.type === 'CLIENT_VARS') {
|
|
|
|
// if we haven't recieved the clientVars yet, then this message should it be
|
2011-07-07 19:59:34 +02:00
|
|
|
receivedClientVars = true;
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
// set some client vars
|
2020-12-20 08:15:58 +01:00
|
|
|
window.clientVars = obj.data;
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
// initalize the pad
|
2012-01-27 06:10:41 +01:00
|
|
|
pad._afterHandshake();
|
2011-08-13 20:53:02 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
if (clientVars.readonly) {
|
2015-05-20 02:50:37 +02:00
|
|
|
chat.hide();
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#myusernameedit').attr('disabled', true);
|
|
|
|
$('#chatinput').attr('disabled', true);
|
2015-05-20 02:05:53 +02:00
|
|
|
$('#chaticon').hide();
|
|
|
|
$('#options-chatandusers').parent().hide();
|
|
|
|
$('#options-stickychat').parent().hide();
|
2020-11-23 19:24:19 +01:00
|
|
|
} else if (!settings.hideChat) { $('#chaticon').show(); }
|
2015-05-19 18:52:43 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
$('body').addClass(clientVars.readonly ? 'readonly' : 'readwrite');
|
2012-05-17 12:03:38 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
padeditor.ace.callWithAce((ace) => {
|
2012-04-23 16:41:41 +02:00
|
|
|
ace.ace_setEditable(!clientVars.readonly);
|
|
|
|
});
|
|
|
|
|
2011-08-13 20:53:02 +02:00
|
|
|
// If the LineNumbersDisabled value is set to true then we need to hide the Line Numbers
|
2020-12-20 08:15:58 +01:00
|
|
|
if (settings.LineNumbersDisabled === true) {
|
2011-08-13 20:53:02 +02:00
|
|
|
pad.changeViewOption('showLineNumbers', false);
|
2011-08-13 19:37:44 +02:00
|
|
|
}
|
2011-09-04 14:48:53 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
// If the noColors value is set to true then we need to
|
|
|
|
// hide the background colors on the ace spans
|
|
|
|
if (settings.noColors === true) {
|
2011-09-04 14:48:53 +02:00
|
|
|
pad.changeViewOption('noColors', true);
|
|
|
|
}
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
if (settings.rtlIsTrue === true) {
|
2013-03-05 23:12:00 +01:00
|
|
|
pad.changeViewOption('rtlIsTrue', true);
|
2011-12-04 19:55:35 +01:00
|
|
|
}
|
2011-09-04 14:48:53 +02:00
|
|
|
|
2011-08-13 23:10:58 +02:00
|
|
|
// If the Monospacefont value is set to true then change it to monospace.
|
2020-12-20 08:15:58 +01:00
|
|
|
if (settings.useMonospaceFontGlobal === true) {
|
2018-11-08 21:56:10 +01:00
|
|
|
pad.changeViewOption('padFontFamily', 'monospace');
|
2011-08-13 23:10:58 +02:00
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
// if the globalUserName value is set we need to tell the server and
|
|
|
|
// the client about the new authorname
|
2020-11-23 19:24:19 +01:00
|
|
|
if (settings.globalUserName !== false) {
|
2012-01-16 03:22:28 +01:00
|
|
|
pad.notifyChangeName(settings.globalUserName); // Notifies the server
|
|
|
|
pad.myUserInfo.name = settings.globalUserName;
|
2013-10-03 01:36:15 +02:00
|
|
|
$('#myusernameedit').val(settings.globalUserName); // Updates the current users UI
|
2011-08-13 20:53:02 +02:00
|
|
|
}
|
2020-11-23 19:24:19 +01:00
|
|
|
if (settings.globalUserColor !== false && colorutils.isCssHex(settings.globalUserColor)) {
|
2020-12-20 08:15:58 +01:00
|
|
|
// Add a 'globalUserColor' property to myUserInfo,
|
|
|
|
// so collabClient knows we have a query parameter.
|
2012-09-15 23:48:04 +02:00
|
|
|
pad.myUserInfo.globalUserColor = settings.globalUserColor;
|
|
|
|
pad.notifyChangeColor(settings.globalUserColor); // Updates pad.myUserInfo.colorId
|
|
|
|
paduserlist.setMyUserInfo(pad.myUserInfo);
|
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
} 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();
|
|
|
|
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
pad.collabClient.handleMessageFromServer(obj);
|
2011-07-07 19:59:34 +02:00
|
|
|
}
|
|
|
|
});
|
2011-08-20 19:22:10 +02:00
|
|
|
// Bind the colorpicker
|
2020-12-20 08:15:58 +01:00
|
|
|
$('#colorpicker').farbtastic({callback: '#mycolorpickerpreview', width: 220});
|
2017-05-03 17:59:57 +02:00
|
|
|
// Bind the read only button
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#readonlyinput').on('click', () => {
|
2012-10-04 22:16:58 +02:00
|
|
|
padeditbar.setEmbedLinks();
|
|
|
|
});
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2011-03-26 14:10:41 +01:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const pad = {
|
2011-03-26 14:10:41 +01:00
|
|
|
// don't access these directly from outside this file, except
|
|
|
|
// for debugging
|
|
|
|
collabClient: null,
|
|
|
|
myUserInfo: null,
|
|
|
|
diagnosticInfo: {},
|
|
|
|
initTime: 0,
|
2011-07-14 17:15:38 +02:00
|
|
|
clientTimeOffset: null,
|
2011-03-26 14:10:41 +01:00
|
|
|
padOptions: {},
|
|
|
|
|
|
|
|
// these don't require init; clientVars should all go through here
|
2020-12-20 08:15:58 +01:00
|
|
|
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;
|
2020-06-05 20:58:25 +02:00
|
|
|
newHref = newHref[0];
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
const options = clientVars.padOptions;
|
|
|
|
if (typeof options !== 'undefined' && options != null) {
|
2020-12-20 08:15:58 +01:00
|
|
|
const optionArr = [];
|
2020-11-23 19:24:19 +01:00
|
|
|
$.each(options, (k, v) => {
|
|
|
|
const str = `${k}=${v}`;
|
2020-12-20 08:15:58 +01:00
|
|
|
optionArr.push(str);
|
2020-11-23 19:24:19 +01:00
|
|
|
});
|
2020-12-20 08:15:58 +01:00
|
|
|
const optionStr = optionArr.join('&');
|
2020-06-05 20:58:25 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
newHref = `${newHref}?${optionStr}`;
|
2020-06-05 20:58:25 +02:00
|
|
|
}
|
|
|
|
|
2020-04-23 17:38:01 +02:00
|
|
|
// destroy old pad from DOM
|
|
|
|
// See https://github.com/ether/etherpad-lite/pull/3915
|
|
|
|
// TODO: Check if Destroying is enough and doesn't leave negative stuff
|
|
|
|
// See ace.js "editor.destroy" for a reference of how it was done before
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#editorcontainer').find('iframe')[0].remove();
|
2014-07-07 00:22:24 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
if (window.history && window.history.pushState) {
|
|
|
|
$('#chattext p').remove(); // clear the chat messages
|
|
|
|
window.history.pushState('', '', newHref);
|
2014-07-07 00:22:24 +02:00
|
|
|
receivedClientVars = false;
|
2014-07-12 22:27:00 +02:00
|
|
|
sendClientReady(false, 'SWITCH_TO_PAD');
|
2020-12-20 08:15:58 +01:00
|
|
|
} else {
|
|
|
|
// fallback
|
2014-07-07 00:22:24 +02:00
|
|
|
window.location.href = newHref;
|
|
|
|
}
|
2014-06-14 20:24:54 +02:00
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
sendClientMessage: (msg) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.collabClient.sendClientMessage(msg);
|
|
|
|
},
|
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
init: () => {
|
2012-01-29 03:12:01 +01:00
|
|
|
padutils.setupGlobalExceptionHandler();
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
$(document).ready(() => {
|
2012-02-05 00:22:25 +01:00
|
|
|
// start the custom js
|
2020-12-20 08:15:58 +01:00
|
|
|
if (typeof customStart === 'function') customStart(); // eslint-disable-line no-undef
|
2012-01-27 06:10:41 +01:00
|
|
|
handshake();
|
2014-12-28 15:02:56 +01:00
|
|
|
|
|
|
|
// To use etherpad you have to allow cookies.
|
2016-07-10 12:44:45 +02:00
|
|
|
// This will check if the prefs-cookie is set.
|
2014-12-28 15:02:56 +01:00
|
|
|
// Otherwise it shows up a message to the user.
|
2016-12-20 21:57:01 +01:00
|
|
|
padcookie.init();
|
2012-01-27 06:10:41 +01:00
|
|
|
});
|
|
|
|
},
|
2020-11-23 19:24:19 +01:00
|
|
|
_afterHandshake() {
|
2019-02-26 23:25:15 +01:00
|
|
|
pad.clientTimeOffset = Date.now() - clientVars.serverTimestamp;
|
2020-11-23 19:24:19 +01:00
|
|
|
// initialize the chat
|
2012-01-16 06:05:19 +01:00
|
|
|
chat.init(this);
|
2015-04-11 22:22:00 +02:00
|
|
|
getParams();
|
|
|
|
|
2013-03-23 03:59:12 +01:00
|
|
|
padcookie.init(); // initialize the cookies
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.initTime = +(new Date());
|
|
|
|
pad.padOptions = clientVars.initialOptions;
|
|
|
|
|
|
|
|
pad.myUserInfo = {
|
|
|
|
userId: clientVars.userId,
|
|
|
|
name: clientVars.userName,
|
|
|
|
ip: pad.getClientIp(),
|
|
|
|
colorId: clientVars.userColor,
|
|
|
|
};
|
2011-08-20 19:22:10 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const postAceInit = () => {
|
2011-03-26 14:10:41 +01:00
|
|
|
padeditbar.init();
|
2020-11-23 19:24:19 +01:00
|
|
|
setTimeout(() => {
|
2011-07-07 19:59:34 +02:00
|
|
|
padeditor.ace.focus();
|
|
|
|
}, 0);
|
2020-12-20 08:15:58 +01:00
|
|
|
// if we have a cookie for always showing chat then show it
|
|
|
|
if (padcookie.getPref('chatAlwaysVisible')) {
|
2012-02-25 20:35:49 +01:00
|
|
|
chat.stickToScreen(true); // stick it to the screen
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#options-stickychat').prop('checked', true); // set the checkbox to on
|
2012-02-25 20:35:49 +01:00
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
// if we have a cookie for always showing chat then show it
|
|
|
|
if (padcookie.getPref('chatAndUsers')) {
|
2015-01-19 02:45:49 +01:00
|
|
|
chat.chatAndUsers(true); // stick it to the screen
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#options-chatandusers').prop('checked', true); // set the checkbox to on
|
2015-01-19 02:45:49 +01:00
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
if (padcookie.getPref('showAuthorshipColors') === false) {
|
2013-02-07 11:15:16 +01:00
|
|
|
pad.changeViewOption('showAuthorColors', false);
|
2012-02-27 16:24:36 +01:00
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
if (padcookie.getPref('showLineNumbers') === false) {
|
2014-12-27 15:08:54 +01:00
|
|
|
pad.changeViewOption('showLineNumbers', false);
|
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
if (padcookie.getPref('rtlIsTrue') === true) {
|
2014-12-27 15:08:54 +01:00
|
|
|
pad.changeViewOption('rtlIsTrue', true);
|
|
|
|
}
|
2020-11-23 19:24:19 +01:00
|
|
|
pad.changeViewOption('padFontFamily', padcookie.getPref('padFontFamily'));
|
|
|
|
$('#viewfontmenu').val(padcookie.getPref('padFontFamily')).niceSelect('update');
|
2015-03-25 13:24:20 +01:00
|
|
|
|
2020-04-15 16:11:23 +02:00
|
|
|
// Prevent sticky chat or chat and users to be checked for mobiles
|
2020-12-20 08:15:58 +01:00
|
|
|
const checkChatAndUsersVisibility = (x) => {
|
2020-04-15 16:11:23 +02:00
|
|
|
if (x.matches) { // If media query matches
|
|
|
|
$('#options-chatandusers:checked').click();
|
|
|
|
$('#options-stickychat:checked').click();
|
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
2020-11-23 19:24:19 +01:00
|
|
|
const mobileMatch = window.matchMedia('(max-width: 800px)');
|
2020-04-15 16:11:23 +02:00
|
|
|
mobileMatch.addListener(checkChatAndUsersVisibility); // check if window resized
|
2020-11-23 19:24:19 +01:00
|
|
|
setTimeout(() => { checkChatAndUsersVisibility(mobileMatch); }, 0); // check now after load
|
2020-04-15 16:11:23 +02:00
|
|
|
|
2020-04-28 16:14:00 +02:00
|
|
|
$('#editorcontainer').addClass('initialized');
|
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
hooks.aCallAll('postAceInit', {ace: padeditor.ace, pad});
|
2020-12-20 08:15:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// 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.setOnUserJoin(pad.handleUserJoin);
|
|
|
|
pad.collabClient.setOnUpdateUserInfo(pad.handleUserUpdate);
|
|
|
|
pad.collabClient.setOnUserLeave(pad.handleUserLeave);
|
|
|
|
pad.collabClient.setOnClientMessage(pad.handleClientMessage);
|
|
|
|
pad.collabClient.setOnChannelStateChange(pad.handleChannelStateChange);
|
|
|
|
pad.collabClient.setOnInternalAction(pad.handleCollabAction);
|
|
|
|
|
|
|
|
// load initial chat-messages
|
|
|
|
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
|
|
|
|
$('#chatloadmessagesbutton').css('display', 'none');
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
dispose: () => {
|
2011-03-26 14:10:41 +01:00
|
|
|
padeditor.dispose();
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
notifyChangeName: (newName) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.myUserInfo.name = newName;
|
|
|
|
pad.collabClient.updateUserInfo(pad.myUserInfo);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
notifyChangeColor: (newColorId) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.myUserInfo.colorId = newColorId;
|
|
|
|
pad.collabClient.updateUserInfo(pad.myUserInfo);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
changePadOption: (key, value) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
const options = {};
|
2011-03-26 14:10:41 +01:00
|
|
|
options[key] = value;
|
|
|
|
pad.handleOptionsChange(options);
|
2011-07-07 19:59:34 +02:00
|
|
|
pad.collabClient.sendClientMessage(
|
2020-11-23 19:24:19 +01:00
|
|
|
{
|
|
|
|
type: 'padoptions',
|
|
|
|
options,
|
|
|
|
changedBy: pad.myUserInfo.name || 'unnamed',
|
|
|
|
});
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
changeViewOption: (key, value) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
const options = {
|
|
|
|
view: {},
|
2011-07-07 19:59:34 +02:00
|
|
|
};
|
2011-03-26 14:10:41 +01:00
|
|
|
options.view[key] = value;
|
|
|
|
pad.handleOptionsChange(options);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleOptionsChange: (opts) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
// opts object is a full set of options or just
|
|
|
|
// some options to change
|
2020-11-23 19:24:19 +01:00
|
|
|
if (opts.view) {
|
|
|
|
if (!pad.padOptions.view) {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.padOptions.view = {};
|
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
for (const [k, v] of Object.entries(opts.view)) {
|
|
|
|
pad.padOptions.view[k] = v;
|
|
|
|
padcookie.setPref(k, v);
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
|
|
|
padeditor.setViewOptions(pad.padOptions.view);
|
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
// caller shouldn't mutate the object
|
|
|
|
getPadOptions: () => pad.padOptions,
|
|
|
|
suggestUserName: (userId, name) => {
|
2011-07-07 19:59:34 +02:00
|
|
|
pad.collabClient.sendClientMessage(
|
2020-11-23 19:24:19 +01:00
|
|
|
{
|
|
|
|
type: 'suggestUserName',
|
|
|
|
unnamedId: userId,
|
|
|
|
newName: name,
|
|
|
|
});
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleUserJoin: (userInfo) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
paduserlist.userJoinOrUpdate(userInfo);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleUserUpdate: (userInfo) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
paduserlist.userJoinOrUpdate(userInfo);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleUserLeave: (userInfo) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
paduserlist.userLeave(userInfo);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleClientMessage: (msg) => {
|
|
|
|
if (msg.type === 'suggestUserName') {
|
|
|
|
if (msg.unnamedId === pad.myUserInfo.userId && msg.newName && !pad.myUserInfo.name) {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.notifyChangeName(msg.newName);
|
|
|
|
paduserlist.setMyUserInfo(pad.myUserInfo);
|
|
|
|
}
|
2020-12-20 08:15:58 +01:00
|
|
|
} else if (msg.type === 'newRevisionList') {
|
2011-03-26 14:10:41 +01:00
|
|
|
padsavedrevs.newRevisionList(msg.revisionList);
|
2020-12-20 08:15:58 +01:00
|
|
|
} else if (msg.type === 'revisionLabel') {
|
2011-03-26 14:10:41 +01:00
|
|
|
padsavedrevs.newRevisionList(msg.revisionList);
|
2020-12-20 08:15:58 +01:00
|
|
|
} else if (msg.type === 'padoptions') {
|
2020-11-23 19:24:19 +01:00
|
|
|
const opts = msg.options;
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.handleOptionsChange(opts);
|
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
dmesg: (m) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
if (pad.getIsDebugEnabled()) {
|
|
|
|
const djs = $('#djs').get(0);
|
|
|
|
const wasAtBottom = (djs.scrollTop - (djs.scrollHeight - $(djs).height()) >= -20);
|
|
|
|
$('#djs').append(`<p>${m}</p>`);
|
|
|
|
if (wasAtBottom) {
|
2011-03-26 14:10:41 +01:00
|
|
|
djs.scrollTop = djs.scrollHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleChannelStateChange: (newState, message) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
const oldFullyConnected = !!padconnectionstatus.isFullyConnected();
|
2020-12-20 08:15:58 +01:00
|
|
|
const wasConnecting = (padconnectionstatus.getStatus().what === 'connecting');
|
|
|
|
if (newState === 'CONNECTED') {
|
2016-07-21 20:23:14 +02:00
|
|
|
padeditor.enable();
|
2020-09-10 19:11:10 +02:00
|
|
|
padeditbar.enable();
|
|
|
|
padimpexp.enable();
|
2011-03-26 14:10:41 +01:00
|
|
|
padconnectionstatus.connected();
|
2020-12-20 08:15:58 +01:00
|
|
|
} else if (newState === 'RECONNECTING') {
|
2020-09-10 19:11:10 +02:00
|
|
|
padeditor.disable();
|
|
|
|
padeditbar.disable();
|
|
|
|
padimpexp.disable();
|
2011-03-26 14:10:41 +01:00
|
|
|
padconnectionstatus.reconnecting();
|
2020-12-20 08:15:58 +01:00
|
|
|
} else if (newState === 'DISCONNECTED') {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.diagnosticInfo.disconnectedMessage = message;
|
2011-11-26 00:24:10 +01:00
|
|
|
pad.diagnosticInfo.padId = pad.getPadId();
|
|
|
|
pad.diagnosticInfo.socket = {};
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-11-23 19:24:19 +01:00
|
|
|
// 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
|
2020-12-20 08:15:58 +01:00
|
|
|
for (const [i, value] of Object.entries(socket.socket || {})) {
|
2020-11-23 19:24:19 +01:00
|
|
|
const type = typeof value;
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
if (type === 'string' || type === 'number') {
|
2011-11-26 00:24:10 +01:00
|
|
|
pad.diagnosticInfo.socket[i] = value;
|
|
|
|
}
|
|
|
|
}
|
2017-05-03 17:59:57 +02:00
|
|
|
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.asyncSendDiagnosticInfo();
|
2020-11-23 19:24:19 +01:00
|
|
|
if (typeof window.ajlog === 'string') {
|
|
|
|
window.ajlog += (`Disconnected: ${message}\n`);
|
2011-07-07 19:59:34 +02:00
|
|
|
}
|
2011-03-26 14:10:41 +01:00
|
|
|
padeditor.disable();
|
|
|
|
padeditbar.disable();
|
|
|
|
padimpexp.disable();
|
|
|
|
|
|
|
|
padconnectionstatus.disconnected(message);
|
|
|
|
}
|
2020-11-23 19:24:19 +01:00
|
|
|
const newFullyConnected = !!padconnectionstatus.isFullyConnected();
|
2020-12-20 08:15:58 +01:00
|
|
|
if (newFullyConnected !== oldFullyConnected) {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.handleIsFullyConnected(newFullyConnected, wasConnecting);
|
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleIsFullyConnected: (isConnected, isInitialConnect) => {
|
2012-01-28 23:24:14 +01:00
|
|
|
pad.determineChatVisibility(isConnected && !isInitialConnect);
|
2015-01-21 17:08:54 +01:00
|
|
|
pad.determineChatAndUsersVisibility(isConnected && !isInitialConnect);
|
2012-02-27 16:24:36 +01:00
|
|
|
pad.determineAuthorshipColorsVisibility();
|
2020-11-23 19:24:19 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
padeditbar.toggleDropDown('none');
|
2015-05-10 12:46:49 +02:00
|
|
|
}, 1000);
|
2011-07-07 19:59:34 +02:00
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
determineChatVisibility: (asNowConnectedFeedback) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
const chatVisCookie = padcookie.getPref('chatAlwaysVisible');
|
|
|
|
if (chatVisCookie) { // if the cookie is set for chat always visible
|
2012-01-28 23:24:14 +01:00
|
|
|
chat.stickToScreen(true); // stick it to the screen
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#options-stickychat').prop('checked', true); // set the checkbox to on
|
|
|
|
} else {
|
|
|
|
$('#options-stickychat').prop('checked', false); // set the checkbox for off
|
2012-01-28 23:24:14 +01:00
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
determineChatAndUsersVisibility: (asNowConnectedFeedback) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
const chatAUVisCookie = padcookie.getPref('chatAndUsersVisible');
|
|
|
|
if (chatAUVisCookie) { // if the cookie is set for chat always visible
|
2015-01-19 02:45:49 +01:00
|
|
|
chat.chatAndUsers(true); // stick it to the screen
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#options-chatandusers').prop('checked', true); // set the checkbox to on
|
|
|
|
} else {
|
|
|
|
$('#options-chatandusers').prop('checked', false); // set the checkbox for off
|
2015-01-19 02:45:49 +01:00
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
determineAuthorshipColorsVisibility: () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
const authColCookie = padcookie.getPref('showAuthorshipColors');
|
|
|
|
if (authColCookie) {
|
2012-02-27 16:24:36 +01:00
|
|
|
pad.changeViewOption('showAuthorColors', true);
|
2020-11-23 19:24:19 +01:00
|
|
|
$('#options-colorscheck').prop('checked', true);
|
|
|
|
} else {
|
|
|
|
$('#options-colorscheck').prop('checked', false);
|
2012-02-27 16:24:36 +01:00
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
handleCollabAction: (action) => {
|
|
|
|
if (action === 'commitPerformed') {
|
2020-11-23 19:24:19 +01:00
|
|
|
padeditbar.setSyncStatus('syncing');
|
2020-12-20 08:15:58 +01:00
|
|
|
} else if (action === 'newlyIdle') {
|
2020-11-23 19:24:19 +01:00
|
|
|
padeditbar.setSyncStatus('done');
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
asyncSendDiagnosticInfo: () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
window.setTimeout(() => {
|
2011-07-07 19:59:34 +02:00
|
|
|
$.ajax(
|
2020-11-23 19:24:19 +01:00
|
|
|
{
|
|
|
|
type: 'post',
|
|
|
|
url: 'ep/pad/connection-diagnostic-info',
|
|
|
|
data: {
|
|
|
|
diagnosticInfo: JSON.stringify(pad.diagnosticInfo),
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
success: () => {},
|
|
|
|
error: () => {},
|
2020-11-23 19:24:19 +01:00
|
|
|
});
|
2011-03-26 14:10:41 +01:00
|
|
|
}, 0);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
forceReconnect: () => {
|
2011-03-26 14:10:41 +01:00
|
|
|
$('form#reconnectform input.padId').val(pad.getPadId());
|
|
|
|
pad.diagnosticInfo.collabDiagnosticInfo = pad.collabClient.getDiagnosticInfo();
|
|
|
|
$('form#reconnectform input.diagnosticInfo').val(JSON.stringify(pad.diagnosticInfo));
|
2020-12-20 08:15:58 +01:00
|
|
|
$('form#reconnectform input.missedChanges')
|
|
|
|
.val(JSON.stringify(pad.collabClient.getMissedChanges()));
|
2011-03-26 14:10:41 +01:00
|
|
|
$('form#reconnectform').submit();
|
|
|
|
},
|
|
|
|
// this is called from code put into a frame from the server:
|
2020-12-20 08:15:58 +01:00
|
|
|
handleImportExportFrameCall: (callName, varargs) => {
|
2011-07-07 19:59:34 +02:00
|
|
|
padimpexp.handleFrameCall.call(padimpexp, callName, Array.prototype.slice.call(arguments, 1));
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
callWhenNotCommitting: (f) => {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.collabClient.callWhenNotCommitting(f);
|
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
getCollabRevisionNumber: () => pad.collabClient.getCurrentRevisionNumber(),
|
|
|
|
isFullyConnected: () => padconnectionstatus.isFullyConnected(),
|
|
|
|
addHistoricalAuthors: (data) => {
|
2020-11-23 19:24:19 +01:00
|
|
|
if (!pad.collabClient) {
|
|
|
|
window.setTimeout(() => {
|
2011-07-07 19:59:34 +02:00
|
|
|
pad.addHistoricalAuthors(data);
|
|
|
|
}, 1000);
|
2020-11-23 19:24:19 +01:00
|
|
|
} else {
|
2011-03-26 14:10:41 +01:00
|
|
|
pad.collabClient.addHistoricalAuthors(data);
|
|
|
|
}
|
2020-11-23 19:24:19 +01:00
|
|
|
},
|
2011-03-26 14:10:41 +01:00
|
|
|
};
|
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const init = () => pad.init();
|
2012-01-27 06:40:13 +01:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
const settings = {
|
2020-11-23 19:24:19 +01:00
|
|
|
LineNumbersDisabled: false,
|
|
|
|
noColors: false,
|
|
|
|
useMonospaceFontGlobal: false,
|
|
|
|
globalUserName: false,
|
|
|
|
globalUserColor: false,
|
|
|
|
rtlIsTrue: false,
|
2012-01-27 06:40:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pad.settings = settings;
|
2020-12-20 08:15:58 +01:00
|
|
|
|
2012-04-25 10:23:58 +02:00
|
|
|
exports.baseURL = '';
|
2012-01-16 02:23:48 +01:00
|
|
|
exports.settings = settings;
|
|
|
|
exports.randomString = randomString;
|
|
|
|
exports.getParams = getParams;
|
|
|
|
exports.getUrlVars = getUrlVars;
|
|
|
|
exports.handshake = handshake;
|
|
|
|
exports.pad = pad;
|
2012-01-27 06:10:41 +01:00
|
|
|
exports.init = init;
|