Skip to content

Commit

Permalink
Updated with fix for #2
Browse files Browse the repository at this point in the history
  • Loading branch information
josem committed Apr 30, 2016
1 parent 464c845 commit ca41ab6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion autojump.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"autojump",
"plugins"
],
"version": "0.1.0",
"version": "0.3.0",
"author": {
"name": "José M. Gilgado",
"email": "jm.gilgado@gmail.com",
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jquery.autojump",
"version": "0.1.0",
"version": "0.3.0",
"homepage": "http://github.com/josem/jquery.autojump",
"authors": [
"José M. Gilgado <jm.gilgado@gmail.com>"
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h1>AutoJump Demo</h1>

<script>
$(function() {
$("input,textarea").autoJump();
$("form").autoJump();
});
</script>
</body>
Expand Down
21 changes: 17 additions & 4 deletions src/jquery.autojump.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,30 @@
}

$.extend(Plugin.prototype, {
fields: [],
index: 0,

init: function () {
$(this.element).on("keypress paste", this.controlKeyStrokes);
this.fields = $(this.element).find("input,select,textarea");
$(this.fields).on("keypress paste", {object: this}, this.controlKeyStrokes);
},

controlKeyStrokes: function () {
controlKeyStrokes: function (e) {
var object = e.data.object;
var currentLength = $(this).val().length;
var maxLength = $(this).data("autojump");

if (currentLength === maxLength - 1) {
if (currentLength >= maxLength) {
e.preventDefault();
}

if (currentLength >= maxLength - 1) {
$(this).one("keyup", function() {
$(this).nextAll("input,textarea,select").first().focus();
$(object.fields[++object.index]).focus();

if ($(object.fields[object.index]).is("input[type=submit]")) {
object.index = 0;
}
});
}
}
Expand Down

0 comments on commit ca41ab6

Please sign in to comment.