diff --git a/src/ep.json b/src/ep.json index 0c3179a64..da2bd8ad2 100644 --- a/src/ep.json +++ b/src/ep.json @@ -17,7 +17,8 @@ "client_hooks": { "aceKeyEvent": "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" } }, { diff --git a/src/static/js/chat.js b/src/static/js/chat.js index 9dd93932e..fa3c57436 100755 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -332,3 +332,43 @@ exports.handleClientMessage_CHAT_MESSAGES = (hookName, {msg}) => { $('#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(); + } +}; diff --git a/src/static/js/pad.js b/src/static/js/pad.js index b0c63aeac..8efab08ce 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -367,8 +367,6 @@ const pad = { }, _afterHandshake() { pad.clientTimeOffset = Date.now() - clientVars.serverTimestamp; - // initialize the chat - chat.init(this); getParams(); padcookie.init(); // initialize the cookies @@ -387,16 +385,6 @@ const pad = { 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); } @@ -409,17 +397,6 @@ const pad = { 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, clientVars, pad}); @@ -444,23 +421,7 @@ const pad = { 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'); - } - - 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(); } + if (window.clientVars.readonly) $('#myusernameedit').attr('disabled', true); $('body').addClass(window.clientVars.readonly ? 'readonly' : 'readwrite');