From 02a41530f49e6bb97ddc893192ba4583f67a9b89 Mon Sep 17 00:00:00 2001 From: Ryan Peters Date: Fri, 2 Dec 2022 15:18:04 -0500 Subject: [PATCH] ignore certain key codes --- wwwroot/js/site.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/wwwroot/js/site.js b/wwwroot/js/site.js index 654b0ca..03da00a 100644 --- a/wwwroot/js/site.js +++ b/wwwroot/js/site.js @@ -22,13 +22,20 @@ $(function () { - // save after half-second delay after typing var timer = null; - $('textarea').keyup(function () { + let ignoredKeyCodes = [17, 18, 20, 27, 37, 38, 39, 40, 91]; + + // save after half-second delay after typing + $('textarea').keyup(function (e) { + clearTimeout(timer); - timer = setTimeout(function () { - saveContent(); - }, 1000); + + // only set timer if key isn't ignored + if (!ignoredKeyCodes.includes(e.keyCode)) { + timer = setTimeout(function () { + saveContent(); + }, 1000); + } }); // 20 second interval