Skip to content

Commit

Permalink
feat(requests): [COMM-1283] Check for "emptiness" when using WYSIWYG
Browse files Browse the repository at this point in the history
  • Loading branch information
fredefox committed Nov 30, 2020
1 parent fec4aa4 commit f9c81da
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions script.js
Expand Up @@ -92,9 +92,23 @@ document.addEventListener('DOMContentLoaded', function() {
// Change Mark as solved text according to whether comment is filled
var requestCommentTextarea = document.querySelector('.request-container .comment-container textarea');

var usesWysiwyg = requestCommentTextarea.dataset.helper === "wysiwyg";

function isEmptyPlaintext(s) {
return s.trim() === '';
}

function isEmptyHtml(xml) {
var doc = new DOMParser().parseFromString(`<_>${xml}</_>`, "text/xml");
var img = doc.querySelector("img");
return img === null && isEmptyPlaintext(doc.children[0].textContent);
};

var isEmpty = usesWysiwyg ? isEmptyHtml : isEmptyPlaintext;

if (requestCommentTextarea) {
requestCommentTextarea.addEventListener('input', function() {
if (requestCommentTextarea.value === '') {
if (isEmpty(requestCommentTextarea.value)) {
if (requestMarkAsSolvedButton) {
requestMarkAsSolvedButton.innerText = requestMarkAsSolvedButton.getAttribute('data-solve-translation');
}
Expand Down Expand Up @@ -384,4 +398,4 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
});
});
});

0 comments on commit f9c81da

Please sign in to comment.