Explorar o código

fix backspace/del and cut event for IE9

Evan You %!s(int64=12) %!d(string=hai) anos
pai
achega
73c9c90c8d
Modificáronse 1 ficheiros con 16 adicións e 5 borrados
  1. 16 5
      src/directives/model.js

+ 16 - 5
src/directives/model.js

@@ -1,5 +1,5 @@
 var utils = require('../utils'),
-    isIE  = !!document.attachEvent
+    isIE9 = navigator.userAgent.indexOf('MSIE 9.0') > 0
 
 module.exports = {
 
@@ -35,13 +35,20 @@ module.exports = {
 
         // fix shit for IE9
         // since it doesn't fire input on backspace / del / cut
-        if (isIE) {
-            el.addEventListener('cut', self.set)
-            el.addEventListener('keydown', function (e) {
+        if (isIE9) {
+            self.onCut = function () {
+                // cut event fires before the value actually changes
+                setTimeout(function () {
+                    self.set()
+                }, 0)
+            }
+            self.onDel = function (e) {
                 if (e.keyCode === 46 || e.keyCode === 8) {
                     self.set()
                 }
-            })
+            }
+            el.addEventListener('cut', self.onCut)
+            el.addEventListener('keyup', self.onDel)
         }
     },
 
@@ -73,5 +80,9 @@ module.exports = {
 
     unbind: function () {
         this.el.removeEventListener(this.event, this.set)
+        if (isIE9) {
+            this.el.removeEventListener('cut', this.onCut)
+            this.el.removeEventListener('keyup', this.onDel)
+        }
     }
 }