mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix(ng:model-instant): defer only keydown, throttle setTimeouts
This commit is contained in:
parent
e7d6106811
commit
4e83399570
2 changed files with 19 additions and 11 deletions
|
|
@ -1038,14 +1038,8 @@ var ngModelInstantDirective = ['$browser', function($browser) {
|
|||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, element, attr, ctrl) {
|
||||
element.bind('keydown change input', function(event) {
|
||||
var key = event.keyCode;
|
||||
|
||||
// command modifiers arrows
|
||||
if (key === 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) return;
|
||||
|
||||
$browser.defer(function() {
|
||||
var touched = ctrl.touch(),
|
||||
var handler = function() {
|
||||
var touched = ctrl.touch(),
|
||||
value = trim(element.val());
|
||||
|
||||
if (ctrl.viewValue !== value) {
|
||||
|
|
@ -1055,8 +1049,24 @@ var ngModelInstantDirective = ['$browser', function($browser) {
|
|||
} else if (touched) {
|
||||
scope.$apply();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var timeout;
|
||||
element.bind('keydown', function(event) {
|
||||
var key = event.keyCode;
|
||||
|
||||
// command modifiers arrows
|
||||
if (key === 91 || (15 < key && key < 19) || (37 <= key && key <= 40)) return;
|
||||
|
||||
if (!timeout) {
|
||||
timeout = $browser.defer(function() {
|
||||
handler();
|
||||
timeout = null;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
element.bind('change input', handler);
|
||||
}
|
||||
};
|
||||
}];
|
||||
|
|
|
|||
|
|
@ -949,14 +949,12 @@ describe('input', function() {
|
|||
|
||||
inputElm.val('value2');
|
||||
browserTrigger(inputElm, 'change');
|
||||
$browser.defer.flush();
|
||||
expect(scope.value).toBe('value2');
|
||||
|
||||
if (msie < 9) return;
|
||||
|
||||
inputElm.val('value3');
|
||||
browserTrigger(inputElm, 'input');
|
||||
$browser.defer.flush();
|
||||
expect(scope.value).toBe('value3');
|
||||
}));
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue