Created
January 26, 2016 12:26
-
-
Save matijs/5af365742761f449e027 to your computer and use it in GitHub Desktop.
Trigger a click on a 'save' button by pressing cmd/ctrl-s in a textarea (adapt as needed)
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
(function() { | |
'use strict'; | |
document.addEventListener('keydown', function(event) { | |
var S = 83, | |
activeElement = document.activeElement, | |
saveButtonId, | |
saveButton; | |
if ((event.key === S || event.keyCode === S) && (event.metaKey || event.ctrlKey) && activeElement.nodeName === 'TEXTAREA') { | |
saveButtonId = activeElement.getAttribute('data-save-with'); | |
saveButton = document.getElementById(saveButtonId); | |
if (saveButton && typeof saveButton.click === 'function') { | |
event.preventDefault(); | |
saveButton.click(); | |
} | |
} | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment