fixed bug that wouldn't allow submitting only text formatted content

This commit is contained in:
sairaj mote 2022-03-30 16:04:58 +05:30
parent fba92592aa
commit 271c543579

View File

@ -1483,9 +1483,12 @@
currentElement.remove() currentElement.remove()
} }
}) })
let activeEntry
getRef('article_wrapper').addEventListener("focusin", e => { getRef('article_wrapper').addEventListener("focusin", e => {
if (e.target.closest('.content__area')) { if (e.target.closest('.content__area')) {
const target = e.target.closest('.content__area') const target = e.target.closest('.content__area')
activeEntry = target.closest('.content-card')
document.addEventListener('selectionchange', detectFormatting) document.addEventListener('selectionchange', detectFormatting)
if (target.childNodes[0] === undefined) { if (target.childNodes[0] === undefined) {
target.innerHTML = `<p><br/></p>` target.innerHTML = `<p><br/></p>`
@ -1508,6 +1511,7 @@
if (!e.relatedTarget?.closest('#text_toolbar')) { if (!e.relatedTarget?.closest('#text_toolbar')) {
getRef('text_toolbar').classList.add('hide-completely') getRef('text_toolbar').classList.add('hide-completely')
childObserver.disconnect() childObserver.disconnect()
activeEntry = undefined
} }
} }
}) })
@ -1527,6 +1531,7 @@
document.execCommand("defaultParagraphSeparator", false, "p"); document.execCommand("defaultParagraphSeparator", false, "p");
function formatDoc(sCmd, sValue) { function formatDoc(sCmd, sValue) {
document.execCommand(sCmd, false, sValue); document.execCommand(sCmd, false, sValue);
checkEntry()
} }
function incScore(value) { function incScore(value) {
let currentScore = parseFloat(getRef('update_score_field').value) let currentScore = parseFloat(getRef('update_score_field').value)
@ -1796,11 +1801,11 @@
} }
const checkEntry = debounce(e => { const checkEntry = debounce(e => {
const contentCard = e.target.closest('.content-card') const contentCard = activeEntry
const contentArea = contentCard.querySelector('.content__area') const contentArea = contentCard.querySelector('.content__area')
const uid = contentCard.dataset.uid const uid = contentCard.dataset.uid
const isUniqueEntry = contentArea.dataset.type === 'origin' const isUniqueEntry = contentArea.dataset.type === 'origin'
if (contentArea.textContent.trim() === '') { if (contentArea.innerText.trim() === '') {
contentCard.querySelector('.submit-entry').classList.add('hide-completely') contentCard.querySelector('.submit-entry').classList.add('hide-completely')
} else { } else {
const cleanHTML = DOMPurify.sanitize(contentArea.innerHTML.split('\n').map(v => v.trim()).filter(v => v).join('\n'), { FORBID_ATTR: ['style'], ADD_ATTR: ['target'] }) const cleanHTML = DOMPurify.sanitize(contentArea.innerHTML.split('\n').map(v => v.trim()).filter(v => v).join('\n'), { FORBID_ATTR: ['style'], ADD_ATTR: ['target'] })