-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6fae89
commit b187bfc
Showing
3 changed files
with
196 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ // Counter for character count | ||
for(const counter of document.getElementsByClassName('char-count')) { | ||
const associatedId = counter.getAttribute('for'); | ||
if(!associatedId) { | ||
console.error('No associated input found for: ', counter); | ||
continue; | ||
} | ||
|
||
const associatedInput = document.getElementById(associatedId); | ||
if(!associatedInput) { | ||
console.error('No input found with id: ', associatedId); | ||
continue; | ||
} | ||
|
||
associatedInput.addEventListener('input', () => updateCounter(counter)); | ||
updateCounter(counter); | ||
} | ||
|
||
function updateCounter(element) { | ||
const associatedId = element.getAttribute('for'); | ||
if(!associatedId) { | ||
console.error('No associated input found for: ', element); | ||
return; | ||
} | ||
|
||
const associatedInput = document.getElementById(associatedId); | ||
if(!associatedInput) { | ||
console.error('No input found with id: ', associatedId); | ||
return; | ||
} | ||
|
||
const maxChars = Number(associatedInput.getAttribute('maxlength') ?? Infinity); | ||
const currentChars = associatedInput.value.length; | ||
element.textContent = `${currentChars} / ${maxChars}`; | ||
} | ||
} | ||
{ // Handle profile image upload | ||
const profileImageInput = document.getElementById('pfp-input'); | ||
profileImageInput?.addEventListener('change', () => { | ||
const file = profileImageInput.files[0]; | ||
if(!file) return; | ||
|
||
const reader = new FileReader(); | ||
reader.onload = () => { | ||
const image = document.getElementById('pfp-preview'); | ||
if(image) { | ||
image.src = reader.result; | ||
} | ||
}; | ||
reader.readAsDataURL(file); | ||
}); | ||
} |