Skip to content

Commit

Permalink
Ref #12. Allow navigational keys to be used when strictMax is set.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrussell committed Jun 17, 2013
1 parent e2ca2f0 commit 3d0e2be
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions jquery.simplyCountable.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
onMaxCount: function(){}
}, options);

var navKeys = [33,34,35,36,37,38,39,40];

return $(this).each(function(){

var countable = $(this);
Expand Down Expand Up @@ -107,9 +109,21 @@
};

countCheck();

countable.on('keyup blur paste', function(e) {
// Wait a few miliseconds if a paste event
setTimeout(countCheck, (e.type === 'paste' ? 5 : 0));
switch(e.type) {
case 'keyup':
// Skip navigational key presses
if ($.inArray(e.which, navKeys) < 0) { countCheck(); }
break;
case 'paste':
// Wait a few miliseconds if a paste event
setTimeout(countCheck, (e.type === 'paste' ? 5 : 0));
break;
default:
countCheck();
break;
}
});

});
Expand Down

0 comments on commit 3d0e2be

Please sign in to comment.