| | @@ -94,11 +94,11 @@ |
| 94 | 94 | ht = wh; |
| 95 | 95 | }else{ |
| 96 | 96 | elemsToCount.forEach((e)=>e ? extra += D.effectiveHeight(e) : false); |
| 97 | 97 | ht = wh - extra; |
| 98 | 98 | } |
| 99 | | - f.chat.e.inputField.style.maxHeight = (ht/2)+"px"; |
| 99 | + f.chat.e.inputX.style.maxHeight = (ht/2)+"px"; |
| 100 | 100 | /* ^^^^ this is a middle ground between having no size cap |
| 101 | 101 | on the input field and having a fixed arbitrary cap. */; |
| 102 | 102 | contentArea.style.height = |
| 103 | 103 | contentArea.style.maxHeight = [ |
| 104 | 104 | "calc(", (ht>=100 ? ht : 100), "px", |
| | @@ -110,11 +110,11 @@ |
| 110 | 110 | if(false){ |
| 111 | 111 | console.debug("resized.",wh, extra, ht, |
| 112 | 112 | window.getComputedStyle(contentArea).maxHeight, |
| 113 | 113 | contentArea); |
| 114 | 114 | console.debug("Set input max height to: ", |
| 115 | | - f.chat.e.inputField.style.maxHeight); |
| 115 | + f.chat.e.inputX.style.maxHeight); |
| 116 | 116 | } |
| 117 | 117 | }; |
| 118 | 118 | var doit; |
| 119 | 119 | window.addEventListener('resize',function(ev){ |
| 120 | 120 | clearTimeout(doit); |
| | @@ -131,16 +131,18 @@ |
| 131 | 131 | e:{/*map of certain DOM elements.*/ |
| 132 | 132 | messageInjectPoint: E1('#message-inject-point'), |
| 133 | 133 | pageTitle: E1('head title'), |
| 134 | 134 | loadOlderToolbar: undefined /* the load-posts toolbar (dynamically created) */, |
| 135 | 135 | inputWrapper: E1("#chat-input-area"), |
| 136 | | - inputLine: E1('#chat-input-line'), |
| 136 | + inputElementWrapper: E1('#chat-input-line-wrapper'), |
| 137 | 137 | fileSelectWrapper: E1('#chat-input-file-area'), |
| 138 | 138 | viewMessages: E1('#chat-messages-wrapper'), |
| 139 | 139 | btnSubmit: E1('#chat-button-submit'), |
| 140 | 140 | btnAttach: E1('#chat-button-attach'), |
| 141 | | - inputField: E1('#chat-input-field'), |
| 141 | + inputX: E1('#chat-input-field-x'), |
| 142 | + input1: E1('#chat-input-field-single'), |
| 143 | + inputM: E1('#chat-input-field-multi'), |
| 142 | 144 | inputFile: E1('#chat-input-file'), |
| 143 | 145 | contentDiv: E1('div.content'), |
| 144 | 146 | viewConfig: E1('#chat-config'), |
| 145 | 147 | viewPreview: E1('#chat-preview'), |
| 146 | 148 | previewContent: E1('#chat-preview-content'), |
| | @@ -176,23 +178,24 @@ |
| 176 | 178 | taking into account single- vs multi-line input. The getter returns |
| 177 | 179 | a string and the setter returns this object. */ |
| 178 | 180 | inputValue: function(){ |
| 179 | 181 | const e = this.inputElement(); |
| 180 | 182 | if(arguments.length){ |
| 181 | | - e.innerText = arguments[0]; |
| 183 | + if(e.isContentEditable) e.innerText = arguments[0]; |
| 184 | + else e.value = arguments[0]; |
| 182 | 185 | return this; |
| 183 | 186 | } |
| 184 | | - return e.innerText; |
| 187 | + return e.isContentEditable ? e.innerText : e.value; |
| 185 | 188 | }, |
| 186 | 189 | /** Asks the current user input field to take focus. Returns this. */ |
| 187 | 190 | inputFocus: function(){ |
| 188 | 191 | this.inputElement().focus(); |
| 189 | 192 | return this; |
| 190 | 193 | }, |
| 191 | 194 | /** Returns the current message input element. */ |
| 192 | 195 | inputElement: function(){ |
| 193 | | - return this.e.inputField; |
| 196 | + return this.e.inputFields[this.e.inputFields.$currentIndex]; |
| 194 | 197 | }, |
| 195 | 198 | /** Enables (if yes is truthy) or disables all elements in |
| 196 | 199 | * this.disableDuringAjax. */ |
| 197 | 200 | enableAjaxComponents: function(yes){ |
| 198 | 201 | D[yes ? 'enable' : 'disable'](this.disableDuringAjax); |
| | @@ -417,11 +420,17 @@ |
| 417 | 420 | timestamp of each user's most recent message. */ |
| 418 | 421 | "active-user-list-timestamps": false, |
| 419 | 422 | /* When on, the [audible-alert] is played for one's own |
| 420 | 423 | messages, else it is only played for other users' |
| 421 | 424 | messages. */ |
| 422 | | - "alert-own-messages": false |
| 425 | + "alert-own-messages": false, |
| 426 | + /* "Experimental mode" input: use a contenteditable field |
| 427 | + for input. This is generally more comfortable to use, |
| 428 | + and more modern, than plain text input fields, but |
| 429 | + the list of browser-specific quirks and bugs is... |
| 430 | + not short. */ |
| 431 | + "edit-widget-x": false |
| 423 | 432 | } |
| 424 | 433 | }, |
| 425 | 434 | /** Plays a new-message notification sound IF the audible-alert |
| 426 | 435 | setting is true, else this is a no-op. Returns this. |
| 427 | 436 | */ |
| | @@ -579,16 +588,22 @@ |
| 579 | 588 | D.addClassBriefly(e, a, 0, cb); |
| 580 | 589 | } |
| 581 | 590 | return this; |
| 582 | 591 | } |
| 583 | 592 | }; |
| 584 | | - if(D.attr(cs.e.inputField,'contenteditable','plaintext-only').isContentEditable){ |
| 593 | + cs.e.inputFields = [ cs.e.input1, cs.e.inputM, cs.e.inputX ]; |
| 594 | + cs.e.inputFields.$currentIndex = 0; |
| 595 | + cs.e.inputFields.forEach(function(e,ndx){ |
| 596 | + if(ndx===cs.e.inputFields.$currentIndex) D.removeClass(e,'hidden'); |
| 597 | + else D.addClass(e,'hidden'); |
| 598 | + }); |
| 599 | + if(D.attr(cs.e.inputX,'contenteditable','plaintext-only').isContentEditable){ |
| 585 | 600 | cs.$browserHasPlaintextOnly = true; |
| 586 | 601 | }else{ |
| 587 | 602 | /* Only the Chrome family supports contenteditable=plaintext-only */ |
| 588 | 603 | cs.$browserHasPlaintextOnly = false; |
| 589 | | - D.attr(cs.e.inputField,'contenteditable','true'); |
| 604 | + D.attr(cs.e.inputX,'contenteditable','true'); |
| 590 | 605 | } |
| 591 | 606 | cs.animate.$disabled = true; |
| 592 | 607 | F.fetch.beforesend = ()=>cs.ajaxStart(); |
| 593 | 608 | F.fetch.aftersend = ()=>cs.ajaxEnd(); |
| 594 | 609 | cs.pageTitleOrig = cs.e.pageTitle.innerText; |
| | @@ -1161,11 +1176,11 @@ |
| 1161 | 1176 | /* Acrobatics to keep *some* installations of Firefox |
| 1162 | 1177 | from pasting formatting into contenteditable fields. |
| 1163 | 1178 | This also works on Chrome, but chrome has the |
| 1164 | 1179 | contenteditable=plaintext-only property which does this |
| 1165 | 1180 | for us. */ |
| 1166 | | - Chat.inputElement().addEventListener( |
| 1181 | + Chat.e.inputX.addEventListener( |
| 1167 | 1182 | 'paste', |
| 1168 | 1183 | function(ev){ |
| 1169 | 1184 | if (ev.clipboardData && ev.clipboardData.getData) { |
| 1170 | 1185 | const pastedText = ev.clipboardData.getData('text/plain'); |
| 1171 | 1186 | const selection = window.getSelection(); |
| | @@ -1185,15 +1200,12 @@ |
| 1185 | 1200 | ev.dataTransfer.dropEffect = 'none'; |
| 1186 | 1201 | ev.preventDefault(); |
| 1187 | 1202 | ev.stopPropagation(); |
| 1188 | 1203 | return false; |
| 1189 | 1204 | }; |
| 1190 | | - |
| 1191 | 1205 | ['drop','dragenter','dragleave','dragend'].forEach( |
| 1192 | | - (k)=>{ |
| 1193 | | - Chat.inputElement().addEventListener(k, noDragDropEvents, false); |
| 1194 | | - } |
| 1206 | + (k)=>Chat.e.inputX.addEventListener(k, noDragDropEvents, false) |
| 1195 | 1207 | ); |
| 1196 | 1208 | return bxs; |
| 1197 | 1209 | })()/*drag/drop/paste*/; |
| 1198 | 1210 | |
| 1199 | 1211 | const tzOffsetToString = function(off){ |
| | @@ -1323,11 +1335,13 @@ |
| 1323 | 1335 | ev.stopPropagation(); |
| 1324 | 1336 | Chat.submitMessage(); |
| 1325 | 1337 | return false; |
| 1326 | 1338 | } |
| 1327 | 1339 | }; |
| 1328 | | - Chat.e.inputField.addEventListener('keydown', inputWidgetKeydown, false); |
| 1340 | + Chat.e.inputFields.forEach( |
| 1341 | + (e)=>e.addEventListener('keydown', inputWidgetKeydown, false) |
| 1342 | + ); |
| 1329 | 1343 | Chat.e.btnSubmit.addEventListener('click',(e)=>{ |
| 1330 | 1344 | e.preventDefault(); |
| 1331 | 1345 | Chat.submitMessage(); |
| 1332 | 1346 | return false; |
| 1333 | 1347 | }); |
| | @@ -1383,70 +1397,98 @@ |
| 1383 | 1397 | /** |
| 1384 | 1398 | Settings ops structure: |
| 1385 | 1399 | |
| 1386 | 1400 | label: string for the UI |
| 1387 | 1401 | |
| 1388 | | - boolValue: string (name of Chat.settings setting) or a |
| 1389 | | - function which returns true or false. |
| 1402 | + boolValue: string (name of Chat.settings setting) or a function |
| 1403 | + which returns true or false. If it is a string, it gets |
| 1404 | + replaced by a function which returns |
| 1405 | + Chat.settings.getBool(thatString) and the string gets assigned |
| 1406 | + to the persistentSetting property of this object. |
| 1390 | 1407 | |
| 1391 | 1408 | select: SELECT element (instead of boolValue) |
| 1392 | 1409 | |
| 1393 | 1410 | callback: optional handler to call after setting is modified. |
| 1411 | + Its "this" is the options object. If this object has a |
| 1412 | + boolValue string or a persistentSetting property, the argument |
| 1413 | + passed to the callback is a settings object in the form {key:K, |
| 1414 | + value:V}. If this object does not have boolValue string or |
| 1415 | + persistentSetting then the callback is passed an event object |
| 1416 | + in response to the config option's UI widget being activated, |
| 1417 | + normally a 'change' event. |
| 1418 | + |
| 1419 | + children: [array of settings objects]. These get listed under |
| 1420 | + this element and indented slightly for visual grouping. Only |
| 1421 | + one level of indention is supported. |
| 1422 | + |
| 1423 | + Elements which only have a label and maybe a hint and |
| 1424 | + children can be used as headings. |
| 1394 | 1425 | |
| 1395 | | - If a setting has a boolValue set, that gets transformed into a |
| 1426 | + If a setting has a boolValue set, that gets rendered as a |
| 1396 | 1427 | checkbox which toggles the given persistent setting (if |
| 1397 | 1428 | boolValue is a string) AND listens for changes to that setting |
| 1398 | 1429 | fired via Chat.settings.set() so that the checkbox can stay in |
| 1399 | 1430 | sync with external changes to that setting. Various Chat UI |
| 1400 | 1431 | elements stay in sync with the config UI via those settings |
| 1401 | | - events. |
| 1402 | | - */ |
| 1432 | + events. The checkbox element gets added to the options object |
| 1433 | + so that the callback() can reference it via this.checkbox. |
| 1434 | + */ |
| 1403 | 1435 | const settingsOps = [{ |
| 1436 | + label: "Chat Configuration Options", |
| 1437 | + hint: "Most of these settings are persistent via window.localStorage." |
| 1438 | + },{ |
| 1439 | + label: "Chat-only mode", |
| 1440 | + hint: "Toggle the page between normal fossil view and chat-only view.", |
| 1441 | + boolValue: 'chat-only-mode' |
| 1442 | + },{ |
| 1404 | 1443 | label: "Ctrl-enter to Send", |
| 1405 | | - hint: "When on, only Ctrl-Enter will send messages and Enter adds "+ |
| 1406 | | - "blank lines. "+ |
| 1407 | | - "When off, both Enter and Ctrl-Enter send. "+ |
| 1408 | | - "When the input field has focus, is empty, and preview "+ |
| 1409 | | - "mode is NOT active then Ctrl-Enter toggles this setting.", |
| 1444 | + hint: [ |
| 1445 | + "When on, only Ctrl-Enter will send messages and Enter adds ", |
| 1446 | + "blank lines. When off, both Enter and Ctrl-Enter send. ", |
| 1447 | + "When the input field has focus, is empty, and preview ", |
| 1448 | + "mode is NOT active then Ctrl-Enter toggles this setting." |
| 1449 | + ].join(''), |
| 1410 | 1450 | boolValue: 'edit-ctrl-send' |
| 1411 | 1451 | },{ |
| 1412 | 1452 | label: "Compact mode", |
| 1413 | | - hint: "Toggle between a space-saving or more spacious writing area. "+ |
| 1414 | | - "When the input field has focus, is empty, and preview mode "+ |
| 1415 | | - "is NOT active then Shift-Enter toggles this setting.", |
| 1453 | + hint: [ |
| 1454 | + "Toggle between a space-saving or more spacious writing area. ", |
| 1455 | + "When the input field has focus, is empty, and preview mode ", |
| 1456 | + "is NOT active then Shift-Enter toggles this setting."].join(''), |
| 1416 | 1457 | boolValue: 'edit-compact-mode' |
| 1417 | 1458 | },{ |
| 1418 | 1459 | label: "Left-align my posts", |
| 1419 | 1460 | hint: "Default alignment of your own messages is selected " |
| 1420 | | - +"based window width/height relationship.", |
| 1461 | + + "based window width/height relationship.", |
| 1421 | 1462 | boolValue: ()=>!document.body.classList.contains('my-messages-right'), |
| 1422 | 1463 | callback: function f(){ |
| 1423 | 1464 | document.body.classList[ |
| 1424 | 1465 | this.checkbox.checked ? 'remove' : 'add' |
| 1425 | 1466 | ]('my-messages-right'); |
| 1426 | 1467 | } |
| 1427 | 1468 | },{ |
| 1428 | 1469 | label: "Monospace message font", |
| 1429 | | - hint: "Use monospace font for message text?", |
| 1470 | + hint: "Use monospace font for message and input text.", |
| 1430 | 1471 | boolValue: 'monospace-messages', |
| 1431 | 1472 | callback: function(setting){ |
| 1432 | 1473 | document.body.classList[ |
| 1433 | 1474 | setting.value ? 'add' : 'remove' |
| 1434 | 1475 | ]('monospace-messages'); |
| 1435 | 1476 | } |
| 1436 | 1477 | },{ |
| 1437 | | - label: "Chat-only mode", |
| 1438 | | - hint: "Toggle the page between normal fossil view and chat-only view.", |
| 1439 | | - boolValue: 'chat-only-mode' |
| 1478 | + label: "Show images inline", |
| 1479 | + hint: "Show attached images inline or as a download link.", |
| 1480 | + boolValue: 'images-inline' |
| 1440 | 1481 | },{ |
| 1441 | | - label: "Show images inline", |
| 1442 | | - hint: "Whether to show images inline or as a hyperlink.", |
| 1443 | | - boolValue: 'images-inline' |
| 1444 | | - },namedOptions.activeUsers,{ |
| 1445 | | - label: "Timestamps in active users list", |
| 1446 | | - hint: "Whether to show last-message timestamps.", |
| 1447 | | - boolValue: 'active-user-list-timestamps' |
| 1482 | + label: "Use 'contenteditable' editing mode.", |
| 1483 | + boolValue: 'edit-widget-x', |
| 1484 | + hint: [ |
| 1485 | + "When enabled, chat input uses a so-called 'contenteditable' ", |
| 1486 | + "field. Though generally more comfortable and modern than ", |
| 1487 | + "plain-text input fields, browser-specific quirks and bugs ", |
| 1488 | + "may lead to frustration." |
| 1489 | + ].join('') |
| 1448 | 1490 | }]; |
| 1449 | 1491 | |
| 1450 | 1492 | /** Set up selection list of notification sounds. */ |
| 1451 | 1493 | if(1){ |
| 1452 | 1494 | const selectSound = D.select(); |
| | @@ -1465,45 +1507,64 @@ |
| 1465 | 1507 | selectSound.selectedIndex = firstSoundIndex; |
| 1466 | 1508 | } |
| 1467 | 1509 | } |
| 1468 | 1510 | Chat.setNewMessageSound(selectSound.value); |
| 1469 | 1511 | settingsOps.push({ |
| 1470 | | - hint: "Audio alert. How to enable audio playback is browser-specific!", |
| 1471 | | - select: selectSound, |
| 1472 | | - callback: function(ev){ |
| 1473 | | - const v = ev.target.value; |
| 1474 | | - Chat.setNewMessageSound(v); |
| 1475 | | - F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+"."); |
| 1476 | | - if(v) setTimeout(()=>Chat.playNewMessageSound(), 0); |
| 1477 | | - } |
| 1512 | + label: "Sound Options...", |
| 1513 | + hint: "How to enable audio playback is browser-specific!", |
| 1514 | + children:[{ |
| 1515 | + hint: "Audio alert", |
| 1516 | + select: selectSound, |
| 1517 | + callback: function(ev){ |
| 1518 | + const v = ev.target.value; |
| 1519 | + Chat.setNewMessageSound(v); |
| 1520 | + F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+"."); |
| 1521 | + if(v) setTimeout(()=>Chat.playNewMessageSound(), 0); |
| 1522 | + } |
| 1523 | + },{ |
| 1524 | + label: "Play notification for your own messages.", |
| 1525 | + hint: "When enabled, the audio notification will be played for all messages, "+ |
| 1526 | + "including your own. When disabled only messages from other users "+ |
| 1527 | + "will trigger a notification.", |
| 1528 | + boolValue: 'alert-own-messages' |
| 1529 | + }] |
| 1478 | 1530 | }); |
| 1479 | 1531 | }/*audio notification config*/ |
| 1480 | 1532 | settingsOps.push({ |
| 1481 | | - label: "Play notification for your own messages.", |
| 1482 | | - hint: "When enabled, the audio notification will be played for all messages, "+ |
| 1483 | | - "including your own. When disabled only messages from other users "+ |
| 1484 | | - "will trigger a notification.", |
| 1485 | | - boolValue: 'alert-own-messages' |
| 1533 | + label: "Active User List", |
| 1534 | + hint: [ |
| 1535 | + "/chat cannot track active connections, but it can tell ", |
| 1536 | + "you who has posted recently..."].join(''), |
| 1537 | + children:[ |
| 1538 | + namedOptions.activeUsers,{ |
| 1539 | + label: "Timestamps in active users list", |
| 1540 | + indent: true, |
| 1541 | + hint: "Show most recent message timestamps in the active user list.", |
| 1542 | + boolValue: 'active-user-list-timestamps' |
| 1543 | + } |
| 1544 | + ] |
| 1486 | 1545 | }); |
| 1487 | 1546 | /** |
| 1488 | 1547 | Build UI for config options... |
| 1489 | 1548 | */ |
| 1490 | | - settingsOps.forEach(function f(op){ |
| 1549 | + settingsOps.forEach(function f(op,indentOrIndex){ |
| 1491 | 1550 | const line = D.addClass(D.div(), 'menu-entry'); |
| 1551 | + if(true===indentOrIndex) D.addClass(line, 'indent'); |
| 1492 | 1552 | const label = op.label |
| 1493 | 1553 | ? D.append(D.label(),op.label) : undefined; |
| 1494 | 1554 | const labelWrapper = D.addClass(D.div(), 'label-wrapper'); |
| 1495 | 1555 | var hint; |
| 1496 | | - const col0 = D.span(); |
| 1497 | 1556 | if(op.hint){ |
| 1498 | 1557 | hint = D.append(D.addClass(D.span(),'hint'),op.hint); |
| 1499 | 1558 | } |
| 1500 | 1559 | if(op.hasOwnProperty('select')){ |
| 1501 | | - D.append(line, col0, labelWrapper); |
| 1560 | + const col0 = D.addClass(D.span(/*empty, but for spacing*/), |
| 1561 | + 'toggle-wrapper'); |
| 1562 | + D.append(line, labelWrapper, col0); |
| 1502 | 1563 | D.append(labelWrapper, op.select); |
| 1503 | 1564 | if(hint) D.append(labelWrapper, hint); |
| 1504 | | - if(label) D.append(col0, label); |
| 1565 | + if(label) D.append(label); |
| 1505 | 1566 | if(op.callback){ |
| 1506 | 1567 | op.select.addEventListener('change', (ev)=>op.callback(ev), false); |
| 1507 | 1568 | } |
| 1508 | 1569 | }else if(op.hasOwnProperty('boolValue')){ |
| 1509 | 1570 | if(undefined === f.$id) f.$id = 0; |
| | @@ -1515,23 +1576,26 @@ |
| 1515 | 1576 | } |
| 1516 | 1577 | const check = op.checkbox |
| 1517 | 1578 | = D.attr(D.checkbox(1, op.boolValue()), |
| 1518 | 1579 | 'aria-label', op.label); |
| 1519 | 1580 | const id = 'cfgopt'+f.$id; |
| 1581 | + const col0 = D.addClass(D.span(), 'toggle-wrapper'); |
| 1520 | 1582 | check.checked = op.boolValue(); |
| 1521 | 1583 | op.checkbox = check; |
| 1522 | 1584 | D.attr(check, 'id', id); |
| 1523 | | - D.append(line, col0, labelWrapper); |
| 1585 | + D.append(line, labelWrapper, col0); |
| 1524 | 1586 | D.append(col0, check); |
| 1525 | 1587 | if(label){ |
| 1526 | 1588 | D.attr(label, 'for', id); |
| 1527 | 1589 | D.append(labelWrapper, label); |
| 1528 | 1590 | } |
| 1529 | 1591 | if(hint) D.append(labelWrapper, hint); |
| 1530 | 1592 | }else{ |
| 1531 | | - line.addEventListener('click', callback); |
| 1532 | | - D.append(line, col0, labelWrapper); |
| 1593 | + if(op.callback){ |
| 1594 | + line.addEventListener('click', (ev)=>op.callback(ev)); |
| 1595 | + } |
| 1596 | + D.append(line, labelWrapper); |
| 1533 | 1597 | if(label) D.append(labelWrapper, label); |
| 1534 | 1598 | if(hint) D.append(labelWrapper, hint); |
| 1535 | 1599 | } |
| 1536 | 1600 | D.append(optionsMenu, line); |
| 1537 | 1601 | if(op.persistentSetting){ |
| | @@ -1550,10 +1614,11 @@ |
| 1550 | 1614 | }, false); |
| 1551 | 1615 | } |
| 1552 | 1616 | }else if(op.callback && op.checkbox){ |
| 1553 | 1617 | op.checkbox.addEventListener('change', (ev)=>op.callback(ev), false); |
| 1554 | 1618 | } |
| 1619 | + if(op.children) op.children.forEach((x)=>f(x,true)); |
| 1555 | 1620 | }); |
| 1556 | 1621 | })()/*#chat-button-settings setup*/; |
| 1557 | 1622 | |
| 1558 | 1623 | (function(){ |
| 1559 | 1624 | /* Install default settings... must come after |
| | @@ -1569,20 +1634,58 @@ |
| 1569 | 1634 | Chat.settings.addListener('active-user-list-timestamps',function(s){ |
| 1570 | 1635 | Chat.showActiveUserTimestamps(s.value); |
| 1571 | 1636 | }); |
| 1572 | 1637 | Chat.settings.addListener('chat-only-mode',function(s){ |
| 1573 | 1638 | Chat.chatOnlyMode(s.value); |
| 1639 | + }); |
| 1640 | + Chat.settings.addListener('edit-widget-x',function(s){ |
| 1641 | + let eSelected; |
| 1642 | + if(s.value){ |
| 1643 | + if(Chat.e.inputX===Chat.inputElement()) return; |
| 1644 | + eSelected = Chat.e.inputX; |
| 1645 | + }else{ |
| 1646 | + eSelected = Chat.settings.getBool('edit-compact-mode') |
| 1647 | + ? Chat.e.input1 : Chat.e.inputM; |
| 1648 | + } |
| 1649 | + const v = Chat.inputValue(); |
| 1650 | + Chat.inputValue(''); |
| 1651 | + Chat.e.inputFields.forEach(function(e,ndx){ |
| 1652 | + if(eSelected===e){ |
| 1653 | + Chat.e.inputFields.$currentIndex = ndx; |
| 1654 | + D.removeClass(e, 'hidden'); |
| 1655 | + } |
| 1656 | + else D.addClass(e,'hidden'); |
| 1657 | + }); |
| 1658 | + Chat.inputValue(v); |
| 1659 | + eSelected.focus(); |
| 1574 | 1660 | }); |
| 1575 | 1661 | Chat.settings.addListener('edit-compact-mode',function(s){ |
| 1576 | | - Chat.e.inputLine.classList[ |
| 1662 | + if(Chat.e.inputX!==Chat.inputElement()){ |
| 1663 | + /* Text field/textarea mode: swap them if needed. |
| 1664 | + Compact mode of inputX is toggled via CSS. */ |
| 1665 | + const a = s.value |
| 1666 | + ? [Chat.e.input1, Chat.e.inputM, 0] |
| 1667 | + : [Chat.e.inputM, Chat.e.input1, 1]; |
| 1668 | + const v = Chat.inputValue(); |
| 1669 | + Chat.inputValue(''); |
| 1670 | + Chat.e.inputFields.$currentIndex = a[2]; |
| 1671 | + Chat.inputValue(v); |
| 1672 | + D.removeClass(a[0], 'hidden'); |
| 1673 | + D.addClass(a[1], 'hidden'); |
| 1674 | + } |
| 1675 | + Chat.e.inputElementWrapper.classList[ |
| 1577 | 1676 | s.value ? 'add' : 'remove' |
| 1578 | 1677 | ]('compact'); |
| 1678 | + Chat.e.inputFields[Chat.e.inputFields.$currentIndex].focus(); |
| 1579 | 1679 | }); |
| 1580 | 1680 | Chat.settings.addListener('edit-ctrl-send',function(s){ |
| 1581 | 1681 | const label = (s.value ? "Ctrl-" : "")+"Enter submits messages."; |
| 1582 | | - const eInput = Chat.inputElement(); |
| 1583 | | - eInput.dataset.placeholder = eInput.dataset.placeholder0 + " " +label; |
| 1682 | + Chat.e.inputFields.forEach((e)=>{ |
| 1683 | + const v = e.dataset.placeholder0 + " " +label; |
| 1684 | + if(e.isContentEditable) e.dataset.placeholder = v; |
| 1685 | + else D.attr(e,'placeholder',v); |
| 1686 | + }); |
| 1584 | 1687 | Chat.e.btnSubmit.title = label; |
| 1585 | 1688 | }); |
| 1586 | 1689 | const valueKludges = { |
| 1587 | 1690 | /* Convert certain string-format values to other types... */ |
| 1588 | 1691 | "false": false, |
| | @@ -1607,11 +1710,11 @@ |
| 1607 | 1710 | this.inputFocus(); |
| 1608 | 1711 | }; |
| 1609 | 1712 | Chat.e.viewPreview.querySelector('#chat-preview-close'). |
| 1610 | 1713 | addEventListener('click', ()=>Chat.setCurrentView(Chat.e.viewMessages), false); |
| 1611 | 1714 | let previewPending = false; |
| 1612 | | - const elemsToEnable = [btnPreview, Chat.e.btnSubmit, Chat.e.inputField]; |
| 1715 | + const elemsToEnable = [btnPreview, Chat.e.btnSubmit, Chat.e.inputFields]; |
| 1613 | 1716 | const submit = function(ev){ |
| 1614 | 1717 | ev.preventDefault(); |
| 1615 | 1718 | ev.stopPropagation(); |
| 1616 | 1719 | if(previewPending) return false; |
| 1617 | 1720 | const txt = Chat.inputValue(); |
| 1618 | 1721 | |