| | @@ -672,14 +672,16 @@ |
| 672 | 672 | D.addClassBriefly(e, a, 0, cb); |
| 673 | 673 | } |
| 674 | 674 | return this; |
| 675 | 675 | } |
| 676 | 676 | }; |
| 677 | | - if(!D.attr(cs.e.inputField,'contenteditable','plaintext-only').isContentEditable){ |
| 678 | | - /* Only the Chrome family supports contenteditable=plaintext-only, |
| 679 | | - but Chrome is the only engine for which we need this flag: */ |
| 680 | | - D.attr(cs.e.inputField,'contenteditable','true'); |
| 677 | + if(D.attr(cs.e.inputField,'contenteditable','plaintext-only').isContentEditable){ |
| 678 | + cs.$browserHasPlaintextOnly = true; |
| 679 | + }else{ |
| 680 | + /* Only the Chrome family supports contenteditable=plaintext-only */ |
| 681 | + cs.$browserHasPlaintextOnly = false; |
| 682 | + D.attr(cs.e.inputField,'contenteditable','true'); |
| 681 | 683 | } |
| 682 | 684 | cs.animate.$disabled = true; |
| 683 | 685 | F.fetch.beforesend = ()=>cs.ajaxStart(); |
| 684 | 686 | F.fetch.aftersend = ()=>cs.ajaxEnd(); |
| 685 | 687 | cs.pageTitleOrig = cs.e.pageTitle.innerText; |
| | @@ -1324,23 +1326,30 @@ |
| 1324 | 1326 | return false; |
| 1325 | 1327 | } |
| 1326 | 1328 | /* else continue propagating */ |
| 1327 | 1329 | }; |
| 1328 | 1330 | document.addEventListener('paste', pasteListener, true); |
| 1329 | | - if(0){ |
| 1330 | | - const onPastePlainText = function(ev){ |
| 1331 | | - var pastedText = undefined; |
| 1332 | | - if (window.clipboardData && window.clipboardData.getData) { // IE |
| 1333 | | - pastedText = window.clipboardData.getData('Text'); |
| 1334 | | - }else if (ev.clipboardData && ev.clipboardData.getData) { |
| 1335 | | - pastedText = ev.clipboardData.getData('text/plain'); |
| 1336 | | - } |
| 1337 | | - ev.target.textContent += pastedText; |
| 1338 | | - ev.preventDefault(); |
| 1339 | | - return false; |
| 1340 | | - }; |
| 1341 | | - Chat.e.inputField.addEventListener('paste', onPastePlainText, false); |
| 1331 | + if(window.Selection && window.Range && !Chat.$browserHasPlaintextOnly){ |
| 1332 | + /* Acrobatics to keep *some* installations of Firefox |
| 1333 | + from pasting formatting into contenteditable fields. |
| 1334 | + This also works on Chrome, but chrome has the |
| 1335 | + contenteditable=plaintext-only property which does this |
| 1336 | + for us. */ |
| 1337 | + Chat.inputElement().addEventListener( |
| 1338 | + 'paste', |
| 1339 | + function(ev){ |
| 1340 | + if (ev.clipboardData && ev.clipboardData.getData) { |
| 1341 | + const pastedText = ev.clipboardData.getData('text/plain'); |
| 1342 | + const selection = window.getSelection(); |
| 1343 | + if (!selection.rangeCount) return false; |
| 1344 | + selection.deleteFromDocument(/*remove selected content*/); |
| 1345 | + selection.getRangeAt(0).insertNode(document.createTextNode(pastedText)); |
| 1346 | + selection.collapseToEnd(/*deselect pasted text and set cursor at the end*/); |
| 1347 | + ev.preventDefault(); |
| 1348 | + return false; |
| 1349 | + } |
| 1350 | + }, false); |
| 1342 | 1351 | } |
| 1343 | 1352 | const noDragDropEvents = function(ev){ |
| 1344 | 1353 | /* contenteditable tries to do its own thing with dropped data, |
| 1345 | 1354 | which is not compatible with how we use it, so... */ |
| 1346 | 1355 | ev.dataTransfer.effectAllowed = 'none'; |
| 1347 | 1356 | |