Skip to content

Commit

Permalink
fix backspace/del and cut event for IE9
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan You committed Nov 4, 2013
1 parent db284ff commit 73c9c90
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions 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 = {

Expand Down Expand Up @@ -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)
}
},

Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 73c9c90

Please sign in to comment.