aboutsummaryrefslogtreecommitdiffstats
path: root/src/widget/input.js
diff options
context:
space:
mode:
authorVojta Jina2012-02-27 14:49:36 -0800
committerVojta Jina2012-02-28 18:22:41 -0800
commit4e83399570391fe4a41ce4dc27c8a191f761d26d (patch)
treeeabf1aa8437513c7b1ce7b433fa6de00ca9243a4 /src/widget/input.js
parente7d610681114d278b2127757c1d1a65981bc4dc1 (diff)
downloadangular.js-4e83399570391fe4a41ce4dc27c8a191f761d26d.tar.bz2
fix(ng:model-instant): defer only keydown, throttle setTimeouts
Diffstat (limited to 'src/widget/input.js')
-rw-r--r--src/widget/input.js28
1 files changed, 19 insertions, 9 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);
}
};
}];