Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add timeout for fix caret pasition if click placeholder part before mask
  • Loading branch information
gazaret committed Dec 16, 2016
1 parent d84a811 commit f9b75ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 11 additions & 2 deletions dist/mask.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* angular-ui-mask
* https://github.com/angular-ui/ui-mask
* Version: 1.8.7 - 2016-07-26T15:59:07.992Z
* Version: 1.8.7 - 2016-12-16T13:23:58.004Z
* License: MIT
*/

Expand Down Expand Up @@ -59,7 +59,7 @@ angular.module('ui.mask', [])
return tempOptions;
}];
})
.directive('uiMask', ['uiMask.Config', function(maskConfig) {
.directive('uiMask', ['uiMask.Config', '$timeout', function(maskConfig, $timeout) {
function isFocused (elem) {
return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
}
Expand Down Expand Up @@ -556,6 +556,8 @@ angular.module('ui.mask', [])

function eventHandler(e) {
/*jshint validthis: true */
var self = this;

e = e || {};
// Allows more efficient minification
var eventWhich = e.which,
Expand Down Expand Up @@ -681,6 +683,13 @@ angular.module('ui.mask', [])
}
oldCaretPosition = caretPos;
setCaretPosition(this, caretPos);

$timeout(function() {
var caretPos = getCaretPosition(iElement[0]);
if(caretPos < caretPosMin) {
setCaretPosition(self, caretPosMin);
}
}, 305);
}

function isValidCaretPosition(pos) {
Expand Down
4 changes: 2 additions & 2 deletions dist/mask.min.js

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

11 changes: 10 additions & 1 deletion src/mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ angular.module('ui.mask', [])
return tempOptions;
}];
})
.directive('uiMask', ['uiMask.Config', function(maskConfig) {
.directive('uiMask', ['uiMask.Config', '$timeout', function(maskConfig, $timeout) {
function isFocused (elem) {
return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
}
Expand Down Expand Up @@ -546,6 +546,8 @@ angular.module('ui.mask', [])

function eventHandler(e) {
/*jshint validthis: true */
var self = this;

e = e || {};
// Allows more efficient minification
var eventWhich = e.which,
Expand Down Expand Up @@ -671,6 +673,13 @@ angular.module('ui.mask', [])
}
oldCaretPosition = caretPos;
setCaretPosition(this, caretPos);

$timeout(function() {
var caretPos = getCaretPosition(iElement[0]);
if(caretPos < caretPosMin) {
setCaretPosition(self, caretPosMin);
}
}, 305);
}

function isValidCaretPosition(pos) {
Expand Down

0 comments on commit f9b75ab

Please sign in to comment.