aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2012-02-27 14:49:36 -0800
committerVojta Jina2012-02-28 18:22:41 -0800
commit4e83399570391fe4a41ce4dc27c8a191f761d26d (patch)
treeeabf1aa8437513c7b1ce7b433fa6de00ca9243a4
parente7d610681114d278b2127757c1d1a65981bc4dc1 (diff)
downloadangular.js-4e83399570391fe4a41ce4dc27c8a191f761d26d.tar.bz2
fix(ng:model-instant): defer only keydown, throttle setTimeouts
-rw-r--r--src/widget/input.js28
-rw-r--r--test/widget/inputSpec.js2
2 files changed, 19 insertions, 11 deletions
diff --git a/src/widget/input.js b/src/widget/input.js
index 5268f1a7..ca5ecc2b 100644
--- a/src/widget/input.js
+++ b/src/widget/input.js
@@ -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);
}
};
}];
diff --git a/test/widget/inputSpec.js b/test/widget/inputSpec.js
index e4df4fa5..69baba06 100644
--- a/test/widget/inputSpec.js
+++ b/test/widget/inputSpec.js
@@ -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');
}));
});