Skip to content
Permalink
0b139d7318
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
26 lines (24 sloc) 721 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
*/
this.innerText = this.innerText
.split('')
.map(function(letter, i) {
return i % 2 ? letter.toUpperCase() : letter.toLowerCase();
})
.join('');
}