mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-25 18:06:15 -04:00
chat: Move chat init to chat.js
This commit is contained in:
parent
8d3a6e5ef9
commit
a5c729af32
3 changed files with 43 additions and 41 deletions
|
@ -17,7 +17,8 @@
|
||||||
"client_hooks": {
|
"client_hooks": {
|
||||||
"aceKeyEvent": "ep_etherpad-lite/static/js/chat",
|
"aceKeyEvent": "ep_etherpad-lite/static/js/chat",
|
||||||
"handleClientMessage_CHAT_MESSAGE": "ep_etherpad-lite/static/js/chat",
|
"handleClientMessage_CHAT_MESSAGE": "ep_etherpad-lite/static/js/chat",
|
||||||
"handleClientMessage_CHAT_MESSAGES": "ep_etherpad-lite/static/js/chat"
|
"handleClientMessage_CHAT_MESSAGES": "ep_etherpad-lite/static/js/chat",
|
||||||
|
"postAceInit": "ep_etherpad-lite/static/js/chat"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -332,3 +332,43 @@ exports.handleClientMessage_CHAT_MESSAGES = (hookName, {msg}) => {
|
||||||
$('#chatloadmessagesbutton').css('display', 'block');
|
$('#chatloadmessagesbutton').css('display', 'block');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.postAceInit = async (hookName, {clientVars, pad}) => {
|
||||||
|
exports.chat.init(pad);
|
||||||
|
|
||||||
|
if (padcookie.getPref('chatAlwaysVisible')) {
|
||||||
|
exports.chat.stickToScreen(true);
|
||||||
|
$('#options-stickychat').prop('checked', true);
|
||||||
|
}
|
||||||
|
if (padcookie.getPref('chatAndUsers')) {
|
||||||
|
exports.chat.chatAndUsers(true);
|
||||||
|
$('#options-chatandusers').prop('checked', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent sticky chat or chat and users to be checked for mobiles
|
||||||
|
const checkChatAndUsersVisibility = (x) => {
|
||||||
|
if (!x.matches) return;
|
||||||
|
$('#options-chatandusers:checked').click();
|
||||||
|
$('#options-stickychat:checked').click();
|
||||||
|
};
|
||||||
|
const mobileMatch = window.matchMedia('(max-width: 800px)');
|
||||||
|
mobileMatch.addListener(checkChatAndUsersVisibility);
|
||||||
|
setTimeout(() => { checkChatAndUsersVisibility(mobileMatch); }, 0);
|
||||||
|
|
||||||
|
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 {
|
||||||
|
$('#chatloadmessagesbutton').css('display', 'none');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientVars.readonly) {
|
||||||
|
exports.chat.hide();
|
||||||
|
$('#chatinput').attr('disabled', true);
|
||||||
|
$('#options-chatandusers').parent().hide();
|
||||||
|
$('#options-stickychat').parent().hide();
|
||||||
|
} else if (!pad.settings.hideChat) {
|
||||||
|
$('#chaticon').show();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -367,8 +367,6 @@ const pad = {
|
||||||
},
|
},
|
||||||
_afterHandshake() {
|
_afterHandshake() {
|
||||||
pad.clientTimeOffset = Date.now() - clientVars.serverTimestamp;
|
pad.clientTimeOffset = Date.now() - clientVars.serverTimestamp;
|
||||||
// initialize the chat
|
|
||||||
chat.init(this);
|
|
||||||
getParams();
|
getParams();
|
||||||
|
|
||||||
padcookie.init(); // initialize the cookies
|
padcookie.init(); // initialize the cookies
|
||||||
|
@ -387,16 +385,6 @@ const pad = {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
padeditor.ace.focus();
|
padeditor.ace.focus();
|
||||||
}, 0);
|
}, 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) {
|
if (padcookie.getPref('showAuthorshipColors') === false) {
|
||||||
pad.changeViewOption('showAuthorColors', false);
|
pad.changeViewOption('showAuthorColors', false);
|
||||||
}
|
}
|
||||||
|
@ -409,17 +397,6 @@ const pad = {
|
||||||
pad.changeViewOption('padFontFamily', padcookie.getPref('padFontFamily'));
|
pad.changeViewOption('padFontFamily', padcookie.getPref('padFontFamily'));
|
||||||
$('#viewfontmenu').val(padcookie.getPref('padFontFamily')).niceSelect('update');
|
$('#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');
|
$('#editorcontainer').addClass('initialized');
|
||||||
|
|
||||||
hooks.aCallAll('postAceInit', {ace: padeditor.ace, clientVars, pad});
|
hooks.aCallAll('postAceInit', {ace: padeditor.ace, clientVars, pad});
|
||||||
|
@ -444,23 +421,7 @@ const pad = {
|
||||||
pad.collabClient.setOnChannelStateChange(pad.handleChannelStateChange);
|
pad.collabClient.setOnChannelStateChange(pad.handleChannelStateChange);
|
||||||
pad.collabClient.setOnInternalAction(pad.handleCollabAction);
|
pad.collabClient.setOnInternalAction(pad.handleCollabAction);
|
||||||
|
|
||||||
// load initial chat-messages
|
if (window.clientVars.readonly) $('#myusernameedit').attr('disabled', true);
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (window.clientVars.readonly) {
|
|
||||||
chat.hide();
|
|
||||||
$('#myusernameedit').attr('disabled', true);
|
|
||||||
$('#chatinput').attr('disabled', true);
|
|
||||||
$('#options-chatandusers').parent().hide();
|
|
||||||
$('#options-stickychat').parent().hide();
|
|
||||||
} else if (!settings.hideChat) { $('#chaticon').show(); }
|
|
||||||
|
|
||||||
$('body').addClass(window.clientVars.readonly ? 'readonly' : 'readwrite');
|
$('body').addClass(window.clientVars.readonly ? 'readonly' : 'readwrite');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue