| | @@ -101,20 +101,24 @@ |
| 101 | 101 | e:{/*map of certain DOM elements.*/ |
| 102 | 102 | messageInjectPoint: E1('#message-inject-point'), |
| 103 | 103 | pageTitle: E1('head title'), |
| 104 | 104 | loadOlderToolbar: undefined /* the load-posts toolbar (dynamically created) */, |
| 105 | 105 | inputWrapper: E1("#chat-input-area"), |
| 106 | + inputLine: E1('#chat-input-line'), |
| 106 | 107 | fileSelectWrapper: E1('#chat-input-file-area'), |
| 107 | 108 | messagesWrapper: E1('#chat-messages-wrapper'), |
| 108 | 109 | inputForm: E1('#chat-form'), |
| 109 | 110 | btnSubmit: E1('#chat-message-submit'), |
| 110 | 111 | inputSingle: E1('#chat-input-single'), |
| 111 | 112 | inputMulti: E1('#chat-input-multi'), |
| 112 | 113 | inputCurrent: undefined/*one of inputSingle or inputMulti*/, |
| 113 | 114 | inputFile: E1('#chat-input-file'), |
| 114 | 115 | contentDiv: E1('div.content'), |
| 115 | | - configArea: E1('#chat-config') |
| 116 | + configArea: E1('#chat-config'), |
| 117 | + previewArea: E1('#chat-preview'), |
| 118 | + previewContent: E1('#chat-preview-content'), |
| 119 | + btnPreview: E1('#chat-preview-button') |
| 116 | 120 | }, |
| 117 | 121 | me: F.user.name, |
| 118 | 122 | mxMsg: F.config.chat.initSize ? -F.config.chat.initSize : -50, |
| 119 | 123 | mnMsg: undefined/*lowest message ID we've seen so far (for history loading)*/, |
| 120 | 124 | pageIsActive: 'visible'===document.visibilityState, |
| | @@ -147,12 +151,14 @@ |
| 147 | 151 | /** Toggles between single- and multi-line edit modes. Returns this. */ |
| 148 | 152 | inputToggleSingleMulti: function(){ |
| 149 | 153 | const old = this.e.inputCurrent; |
| 150 | 154 | if(this.e.inputCurrent === this.e.inputSingle){ |
| 151 | 155 | this.e.inputCurrent = this.e.inputMulti; |
| 156 | + this.e.inputLine.classList.remove('single-line'); |
| 152 | 157 | }else{ |
| 153 | 158 | this.e.inputCurrent = this.e.inputSingle; |
| 159 | + this.e.inputLine.classList.add('single-line'); |
| 154 | 160 | } |
| 155 | 161 | const m = this.e.messagesWrapper, |
| 156 | 162 | sTop = m.scrollTop, |
| 157 | 163 | mh1 = m.clientHeight; |
| 158 | 164 | D.addClass(old, 'hidden'); |
| | @@ -947,10 +953,11 @@ |
| 947 | 953 | */ |
| 948 | 954 | Chat.submitMessage = function f(){ |
| 949 | 955 | if(!f.spaces){ |
| 950 | 956 | f.spaces = /\s+$/; |
| 951 | 957 | } |
| 958 | + this.revealPreview(false); |
| 952 | 959 | const fd = new FormData(this.e.inputForm) |
| 953 | 960 | /* ^^^^ we don't really want/need the FORM element, but when |
| 954 | 961 | FormData() is default-constructed here then the server |
| 955 | 962 | segfaults, and i have no clue why! */; |
| 956 | 963 | var msg = this.inputValue().trim(); |
| | @@ -1019,11 +1026,17 @@ |
| 1019 | 1026 | |
| 1020 | 1027 | (function(){/*Set up #chat-settings-button */ |
| 1021 | 1028 | const settingsButton = document.querySelector('#chat-settings-button'); |
| 1022 | 1029 | const optionsMenu = E1('#chat-config-options'); |
| 1023 | 1030 | const cbToggle = function(){ |
| 1024 | | - D.toggleClass([Chat.e.messagesWrapper, Chat.e.configArea], 'hidden'); |
| 1031 | + if(Chat.e.configArea.classList.contains('hidden')){ |
| 1032 | + D.removeClass(Chat.e.configArea, 'hidden'); |
| 1033 | + D.addClass([Chat.e.messagesWrapper, Chat.e.previewArea], 'hidden'); |
| 1034 | + }else{ |
| 1035 | + D.addClass(Chat.e.configArea, 'hidden'); |
| 1036 | + D.removeClass(Chat.e.messagesWrapper, 'hidden'); |
| 1037 | + } |
| 1025 | 1038 | }; |
| 1026 | 1039 | D.attr(settingsButton, 'role', 'button').addEventListener('click', cbToggle, false); |
| 1027 | 1040 | Chat.e.configArea.querySelector('button').addEventListener('click', cbToggle, false); |
| 1028 | 1041 | /* Settings menu entries... */ |
| 1029 | 1042 | const settingsOps = [{ |
| | @@ -1061,11 +1074,11 @@ |
| 1061 | 1074 | F.toast.message("Image mode set to "+(v ? "inline" : "hyperlink")+"."); |
| 1062 | 1075 | } |
| 1063 | 1076 | }]; |
| 1064 | 1077 | |
| 1065 | 1078 | /** Set up selection list of notification sounds. */ |
| 1066 | | - if(false/*flip this to false to enable selection of audio files*/){ |
| 1079 | + if(1){ |
| 1067 | 1080 | settingsOps.push({ |
| 1068 | 1081 | label: "Audible alerts", |
| 1069 | 1082 | boolValue: ()=>Chat.settings.getBool('audible-alert'), |
| 1070 | 1083 | callback: function(){ |
| 1071 | 1084 | const v = Chat.settings.toggle('audible-alert'); |
| | @@ -1075,40 +1088,10 @@ |
| 1075 | 1088 | } |
| 1076 | 1089 | }); |
| 1077 | 1090 | Chat.setNewMessageSound( |
| 1078 | 1091 | Chat.settings.getBool('audible-alert') ? F.config.chat.alertSound : false |
| 1079 | 1092 | ); |
| 1080 | | - }else{ |
| 1081 | | - /* Disabled per chatroom discussion: selection list of audio files for |
| 1082 | | - chat notification. */ |
| 1083 | | - settingsOps.selectSound = D.addClass(D.div(), 'menu-entry'); |
| 1084 | | - const selectSound = D.select(); |
| 1085 | | - D.append(settingsOps.selectSound, |
| 1086 | | - D.append(D.span(),"Audio alert"), |
| 1087 | | - selectSound); |
| 1088 | | - D.option(selectSound, "", "(no audio)"); |
| 1089 | | - const firstSoundIndex = selectSound.options.length; |
| 1090 | | - F.config.chat.alerts.forEach(function(a){ |
| 1091 | | - D.option(selectSound, a); |
| 1092 | | - }); |
| 1093 | | - if(true===Chat.settings.getBool('audible-alert')){ |
| 1094 | | - selectSound.selectedIndex = firstSoundIndex; |
| 1095 | | - }else{ |
| 1096 | | - selectSound.value = Chat.settings.get('audible-alert',''); |
| 1097 | | - if(selectSound.selectedIndex<0){ |
| 1098 | | - /*Missing file - removed after this setting was applied. Fall back |
| 1099 | | - to the first sound in the list. */ |
| 1100 | | - selectSound.selectedIndex = firstSoundIndex; |
| 1101 | | - } |
| 1102 | | - } |
| 1103 | | - selectSound.addEventListener('change',function(){ |
| 1104 | | - const v = this.value; |
| 1105 | | - Chat.setNewMessageSound(v); |
| 1106 | | - F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+"."); |
| 1107 | | - if(v) setTimeout(()=>Chat.playNewMessageSound(), 0); |
| 1108 | | - }, false); |
| 1109 | | - Chat.setNewMessageSound(selectSound.value); |
| 1110 | 1093 | }/*audio notification config*/ |
| 1111 | 1094 | /** |
| 1112 | 1095 | Build list of options... |
| 1113 | 1096 | */ |
| 1114 | 1097 | settingsOps.forEach(function f(op){ |
| | @@ -1142,10 +1125,78 @@ |
| 1142 | 1125 | if(settingsOps.selectSound){ |
| 1143 | 1126 | D.append(optionsMenu, settingsOps.selectSound); |
| 1144 | 1127 | } |
| 1145 | 1128 | //settingsButton.click()/*for for development*/; |
| 1146 | 1129 | })()/*#chat-settings-button setup*/; |
| 1130 | + |
| 1131 | + (function(){/*set up message preview*/ |
| 1132 | + const btnPreview = Chat.e.btnPreview; |
| 1133 | + Chat.setPreviewText = function(t){ |
| 1134 | + this.revealPreview(true).e.previewContent.innerHTML = t; |
| 1135 | + }; |
| 1136 | + /** |
| 1137 | + Reveals preview area if showIt is true, else hides it. |
| 1138 | + This also shows/hides other elements, "as appropriate." |
| 1139 | + */ |
| 1140 | + Chat.revealPreview = function(showIt){ |
| 1141 | + if(showIt){ |
| 1142 | + D.removeClass(Chat.e.previewArea, 'hidden'); |
| 1143 | + D.addClass([Chat.e.messagesWrapper, Chat.e.configArea], |
| 1144 | + 'hidden'); |
| 1145 | + }else{ |
| 1146 | + D.addClass(Chat.e.previewArea, 'hidden'); |
| 1147 | + D.removeClass(Chat.e.messagesWrapper, 'hidden'); |
| 1148 | + } |
| 1149 | + return this; |
| 1150 | + }; |
| 1151 | + Chat.e.previewArea.querySelector('#chat-preview-close'). |
| 1152 | + addEventListener('click', ()=>Chat.revealPreview(false), false); |
| 1153 | + let previewPending = false; |
| 1154 | + const elemsToEnable = [ |
| 1155 | + btnPreview, Chat.e.btnSubmit, |
| 1156 | + Chat.e.inputSingle, Chat.e.inputMulti]; |
| 1157 | + Chat.disableDuringAjax.push(btnPreview); |
| 1158 | + const submit = function(ev){ |
| 1159 | + ev.preventDefault(); |
| 1160 | + ev.stopPropagation(); |
| 1161 | + if(previewPending) return false; |
| 1162 | + const txt = Chat.e.inputCurrent.value; |
| 1163 | + if(!txt){ |
| 1164 | + Chat.setPreviewText(''); |
| 1165 | + previewPending = false; |
| 1166 | + return false; |
| 1167 | + } |
| 1168 | + const fd = new FormData(); |
| 1169 | + fd.append('content', txt); |
| 1170 | + fd.append('filename','chat.md' |
| 1171 | + /*filename needed for mimetype determination*/); |
| 1172 | + fd.append('render_mode',F.page.previewModes.wiki); |
| 1173 | + F.fetch('ajax/preview-text',{ |
| 1174 | + payload: fd, |
| 1175 | + onload: (html)=>Chat.setPreviewText(html), |
| 1176 | + onerror: function(e){ |
| 1177 | + F.fetch.onerror(e); |
| 1178 | + Chat.setPreviewText("ERROR: "+( |
| 1179 | + e.message || 'Unknown error fetching preview!' |
| 1180 | + )); |
| 1181 | + }, |
| 1182 | + beforesend: function(){ |
| 1183 | + D.disable(elemsToEnable); |
| 1184 | + Chat.ajaxStart(); |
| 1185 | + previewPending = true; |
| 1186 | + Chat.setPreviewText("Loading preview..."); |
| 1187 | + }, |
| 1188 | + aftersend:function(){ |
| 1189 | + previewPending = false; |
| 1190 | + D.enable(elemsToEnable); |
| 1191 | + Chat.ajaxEnd(); |
| 1192 | + } |
| 1193 | + }); |
| 1194 | + return false; |
| 1195 | + }; |
| 1196 | + btnPreview.addEventListener('click', submit, false); |
| 1197 | + })()/*message preview setup*/; |
| 1147 | 1198 | |
| 1148 | 1199 | /** Callback for poll() to inject new content into the page. jx == |
| 1149 | 1200 | the response from /chat-poll. If atEnd is true, the message is |
| 1150 | 1201 | appended to the end of the chat list (for loading older |
| 1151 | 1202 | messages), else the beginning (the default). */ |
| 1152 | 1203 | |