diff --git a/app/templates/common/macros.html b/app/templates/common/macros.html index 126ab7a..17e15b9 100644 --- a/app/templates/common/macros.html +++ b/app/templates/common/macros.html @@ -109,10 +109,10 @@ - stub: char count + stub: char count - + {%- if banned_tags -%}
Forbidden tags: diff --git a/data/static/js/bits/ui.js b/data/static/js/bits/ui.js index ef6d2ef..0e1637e 100644 --- a/data/static/js/bits/ui.js +++ b/data/static/js/bits/ui.js @@ -1,5 +1,6 @@ export const b = { babycodePreviewEndpoint: '/api/babycode-preview/', + init: 'babycodeEditorCharCountInit', } export function setTab(_, sender, el) { @@ -79,6 +80,26 @@ export function insertBabycode(_, sender, el) { el.setSelectionRange(newCursor, newCursor); } el.focus(); + b.send({ sender: el }, 'babycodeEditorCharCount'); +} + +export function babycodeEditorCharCount(evOrPayload, sender, el) { + if (!sender) { // sent from bitty, not input + sender = evOrPayload.sender; + } + + if (!sender.parentNode.contains(el)) { + return; + } + + const maxLength = sender.maxLength; + const currentLength = sender.value.length; + + el.innerText = `${currentLength}/${maxLength}` +} + +export function babycodeEditorCharCountInit(_, __, el) { + b.send({ sender: el }, 'babycodeEditorCharCount'); } export function babycodePreviewInit(ev, sender, el) {