diff --git a/CHANGELOG.md b/CHANGELOG.md index c33f6f9..5b9a998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/js/jquery.autotab.js b/js/jquery.autotab.js index 68375e4..33a82a6 100644 --- a/js/jquery.autotab.js +++ b/js/jquery.autotab.js @@ -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 @@ -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); @@ -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 @@ -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); diff --git a/js/jquery.autotab.min.js b/js/jquery.autotab.min.js index 3104601..f8deba6 100644 --- a/js/jquery.autotab.min.js +++ b/js/jquery.autotab.min.js @@ -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 @@ -8,15 +8,14 @@ * http://www.opensource.org/licenses/mit-license.php */ -(function(e){var h=navigator.platform,d={tabPause:800,focusChange:null,iOS:"iPad"===h||"iPhone"===h||"iPod"===h,firefox:"undefined"!==typeof InstallTrigger},m=function(a,c){if(null!==c&&"undefined"!==typeof c)for(var b in c)e(a).data("autotab-"+b,c[b])},l=function(a){var c={format:"all",loaded:!1,disabled:!1,pattern:null,uppercase:!1,lowercase:!1,nospace:!1,maxlength:2147483647,target:null,previous:null,trigger:null},b;for(b in c)c[b]=e(a).data("autotab-"+b)||c[b];c.loaded||(null!==c.trigger&&"string"=== -typeof c.trigger&&(c.trigger=c.trigger.toString()),m(a,c));return c};e.autotab={next:function(){var a=e(document.activeElement);a.length&&setTimeout(function(){a.trigger("autotab-next")},1)},previous:function(){var a=e(document.activeElement);a.length&&setTimeout(function(){a.trigger("autotab-previous")},1)}};e.fn.autotab=function(a,c){if(!this.length)return this;if("filter"==a){if("string"===typeof c||"function"===typeof c)c={format:c};for(var b=0,d=this.length;b