Skip to content
Permalink
2ea41fe33b
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
28 lines (24 sloc) 835 Bytes
/**
* Get the editable instance.
*/
let editable = document.querySelector("[contenteditable=true]");
/**
* When focus is removed, run the `formatText` function
*/
editable.addEventListener('blur', formatText);
/**
* Format the innerText of the SpongeBob meme
*/
function formatText(event){
/* Format the text
* Split the text into an array, for each character in the array, if the index of the letter is odd,
* return the letter uppercase, otherwise return it lowercase
* then join the array with no delimiter returning it to a normal string
*/
let memedText = this.innerText.split("")
.map(function (letter, i) {
return i % 2 ? letter.toUpperCase() : letter.toLowerCase()
}).join("")
// Replace the old text with new text
this.innerText = memedText;
}