Skip to content

Commit

Permalink
Merge pull request #18 from Mathachew/dev
Browse files Browse the repository at this point in the history
Fixes issue with change event
  • Loading branch information
Mathachew committed Dec 13, 2013
2 parents e7b0f37 + 64e9698 commit 4ed46ab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Features:
* added support for auto tabbing by specific keys
* refactored various areas dealing with boolean evaulations and checking for iOS and Firefox

Bug fixes:

* fixed a bug that prevented the `change` event from triggering (#17)


## 1.4 (2013-11-12)

Expand Down
53 changes: 15 additions & 38 deletions js/jquery.autotab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Autotab - jQuery plugin 1.5b
* Autotab - jQuery plugin 1.5
* https://github.com/Mathachew/jquery-autotab
*
* Copyright (c) 2013 Matthew Miller
Expand Down Expand Up @@ -355,7 +355,8 @@

settings.focusChange = null;

var hasValue = document.selection && document.selection.createRange ? true : (e.charCode > 0);
var hasValue = document.selection && document.selection.createRange ? true : (e.charCode > 0),
valueChanged = false;

keyChar = filterValue(this, keyChar, defaults);

Expand All @@ -371,22 +372,6 @@
// Non-IE browsers and IE 9
start = this.selectionStart;
end = this.selectionEnd;

// Text is fully selected, so it needs to be replaced
if (start === 0 && end == this.value.length) {
this.value = keyChar;
}
else {
if (this.value.length == this.maxLength) {
$(this).trigger('autotab-next', defaults);
return false;
}

this.value = this.value.slice(0, start) + keyChar + this.value.slice(end);
}

// Move the caret
this.selectionStart = this.selectionEnd = start + 1;
}
else if (document.selection && document.selection.createRange) {
// For IE up to version 8
Expand All @@ -398,35 +383,27 @@
precedingRange.setEndPoint("EndToStart", textInputRange);
start = precedingRange.text.length;
end = start + selectionRange.text.length;
}

// Text is fully selected, so it needs to be replaced
if (start === 0 && end == this.value.length) {
this.value = keyChar;
}
else {
if (this.value.length == this.maxLength) {
$(this).trigger('autotab-next', defaults);
return false;
}

this.value = this.value.slice(0, start) + keyChar + this.value.slice(end);
// Text is fully selected, so it needs to be replaced
if (start === 0 && end == this.value.length) {
valueChanged = true;
}
else {
if (this.value.length == this.maxLength) {
$(this).trigger('autotab-next', defaults);
return false;
}

start++;

// Move the caret
textInputRange = this.createTextRange();
textInputRange.collapse(true);
textInputRange.move("character", start - (this.value.slice(0, start).split("\r\n").length - 1));
textInputRange.select();
valueChanged = true;
}
}

if (this.value.length == defaults.maxlength) {
if (valueChanged && (this.value.length + 1) == defaults.maxlength) {
$(this).trigger('autotab-next', defaults);
}

return false;
return valueChanged;
}).on('paste', function (e) {
var defaults = getSettings(this);

Expand Down
25 changes: 12 additions & 13 deletions js/jquery.autotab.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4ed46ab

Please sign in to comment.