Skip to content

Instantly share code, notes, and snippets.

@aleckyann
Created January 27, 2017 18:40
Show Gist options
  • Save aleckyann/df1725b569aca19c3e87401a4ad2cfc3 to your computer and use it in GitHub Desktop.
Save aleckyann/df1725b569aca19c3e87401a4ad2cfc3 to your computer and use it in GitHub Desktop.
now working
function onMessageClick(e) {
if(e.keyCode == 13) {
document.getElementById('enviaMensagem').click();
}
}
if(sessionStorage.getItem('enterToSend') === 'true'){
document.getElementById('enterToSend').setAttribute('checked', true);
document.getElementById('mensagem').addEventListener('keydown', onMessageClick);
} else {
document.getElementById('enterToSend').removeAttribute('checked'); //remove checked do checkbox
document.getElementById('mensagem').removeEventListener('keydown', onMessageClick);
}
function enterToSend(e){
if(sessionStorage.getItem('enterToSend') === 'false'){//Enviar com enter!
sessionStorage.setItem('enterToSend', 'true');
document.addEventListener('keydown', onMessageClick);
}else{
document.removeEventListener('keydown', onMessageClick); //remove envento com enter
sessionStorage.setItem('enterToSend', 'false');
}
}
(function initEnterToSend(){
if(sessionStorage.getItem('enterToSend') === null){
sessionStorage.setItem('enterToSend', 'false');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment