Skip to content

Commit

Permalink
Merge pull request #20 from Mathachew/dev
Browse files Browse the repository at this point in the history
Max length bug in Internet explorer
  • Loading branch information
Mathachew committed Dec 17, 2013
2 parents 4ed46ab + 2ee3290 commit 5713579
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 44 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.5.1

Bug fixes:

* in Internet Explorer, reaching the max length caused the last character to appear in the target element after auto tabbing (#19)


## 1.5

Features:
Expand Down
58 changes: 26 additions & 32 deletions js/jquery.autotab.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Autotab - jQuery plugin 1.5
* Autotab - jQuery plugin 1.5.1
* https://github.com/Mathachew/jquery-autotab
*
* Copyright (c) 2013 Matthew Miller
Expand Down Expand Up @@ -67,18 +67,14 @@
var e = $(document.activeElement);

if (e.length) {
setTimeout(function () {
e.trigger('autotab-next');
}, 1);
e.trigger('autotab-next');
}
},
previous: function () {
var e = $(document.activeElement);

if (e.length) {
setTimeout(function () {
e.trigger('autotab-previous');
}, 1);
e.trigger('autotab-previous');
}
}
};
Expand Down Expand Up @@ -273,37 +269,35 @@
}

$(element).on('autotab-next', function (event, defaults) {
if (!defaults) {
defaults = getSettings(this);
}
var self = this;
setTimeout(function () {
if (!defaults) {
defaults = getSettings(self);
}

if (!defaults.disabled && defaults.target.length) {
// Using focus on iOS devices is a pain, so use the browser's next/previous buttons to proceed
if (!settings.iOS) {
defaults.target.focus().select();
settings.focusChange = new Date();
if (!defaults.disabled && defaults.target.length) {
// Using focus on iOS devices is a pain, so use the browser's next/previous buttons to proceed
if (!settings.iOS) {
defaults.target.focus().select();
settings.focusChange = new Date();
}
}
}
}, 1);
}).on('autotab-previous', function (event, defaults) {
if (!defaults) {
defaults = getSettings(this);
}
var self = this;
setTimeout(function () {
if (!defaults) {
defaults = getSettings(self);
}

if (!defaults.disabled && defaults.previous.length) {
defaults.previous.focus();
var previous = defaults.previous;

// When setting value = value, Firefox will not place the cursor at the end of a textbox
// when the cursor was last at any point before the final character within the same textbox
if (settings.firefox) {
var length = defaults.previous.val().length;
defaults.previous[0].setSelectionRange(length, length);
}
else {
defaults.previous.val(defaults.previous.val());
if (!defaults.disabled && previous.length) {
var value = previous.val();
previous.focus().val(value.substring(0, value.length - 1));
settings.focusChange = null;
}

settings.focusChange = null;
}
}, 1);
}).on('keydown', function (e) {
var defaults = getSettings(this);

Expand Down
24 changes: 12 additions & 12 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 5713579

Please sign in to comment.