#91 Optimized the JS code
This commit is contained in:
parent
05d66bb108
commit
b256fa8e5e
|
@ -45,9 +45,6 @@ function addCharCounter(textarea) {
|
||||||
function updateCharCounter(textarea, charCounterSpan) {
|
function updateCharCounter(textarea, charCounterSpan) {
|
||||||
const SHAKE_CLASS = 'awp-w2g-chatCounter-max';
|
const SHAKE_CLASS = 'awp-w2g-chatCounter-max';
|
||||||
|
|
||||||
// reset class
|
|
||||||
charCounterSpan.classList.remove(SHAKE_CLASS);
|
|
||||||
|
|
||||||
let current = textarea.value.length;
|
let current = textarea.value.length;
|
||||||
let max = textarea.maxLength;
|
let max = textarea.maxLength;
|
||||||
|
|
||||||
|
@ -55,9 +52,11 @@ function updateCharCounter(textarea, charCounterSpan) {
|
||||||
|
|
||||||
// animation if at max
|
// animation if at max
|
||||||
// this need to be delayed because removing and adding it too fast again will prevent the browsers to replay the animation
|
// this need to be delayed because removing and adding it too fast again will prevent the browsers to replay the animation
|
||||||
if (current >= max) {
|
if (current >= max && !charCounterSpan.classList.contains(SHAKE_CLASS)) {
|
||||||
|
charCounterSpan.classList.add(SHAKE_CLASS);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
charCounterSpan.classList.add(SHAKE_CLASS);
|
charCounterSpan.classList.remove(SHAKE_CLASS);
|
||||||
}, 100);
|
}, 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue