Skip to content

Commit

Permalink
Add constants for key codes
Browse files Browse the repository at this point in the history
  • Loading branch information
okcoker committed Sep 13, 2013
1 parent c569905 commit 75fdeed
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions assets/js/taggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
}
};

BACKSPACE = 8,
COMMA = 188,
TAB = 9,
ENTER = 13;

var Taggle = function(el, options) {
var self = this;
Expand Down Expand Up @@ -255,6 +259,7 @@

//8 - backspace
if (self.tag_input.value === '' && e.keyCode === 8) {
if (self.input.value === '' && e.keyCode === BACKSPACE) {
if (last_taggle.classList.contains(hot_class)) {
self.removeFromTheTags(last_taggle);
last_taggle.remove();
Expand Down Expand Up @@ -328,8 +333,8 @@
Taggle.prototype.isConfirmKey = function(e) {
var code = e.keyCode,
confirm_key = false;
// comma or tab or enter
if (code === 188 || code === 9 || code === 13) {

if (code === COMMA || code === TAB || code === ENTER) {
confirm_key = true;
}

Expand Down Expand Up @@ -413,11 +418,7 @@


//tab, enter
if (code === 9 || code === 13) {
dupes = self.checkForDupes();
}

if (!dupes || self.options.allowDuplicates) {
if (code === TAB || code === ENTER) {
self.add();
}

Expand Down

0 comments on commit 75fdeed

Please sign in to comment.