Skip to content

Commit

Permalink
Force use of attachEvent when registering "propertychange" events (by…
Browse files Browse the repository at this point in the history
…passing jQuery too, as that doesn't support "propertychange" at all)
  • Loading branch information
SteveSanderson committed Apr 23, 2012
1 parent f4a861a commit c9f49db
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ko.utils = new (function () {
knownEventTypesByEventName[knownEventsForType[i]] = eventType;
}
}
var eventsThatMustBeRegisteredUsingAttachEvent = { 'propertychange': true }; // Workaround for an IE9 issue - https://github.com/SteveSanderson/knockout/issues/406

// Detect IE versions for bug workarounds (uses IE conditionals, not UA string, for robustness)
var ieVersion = (function() {
Expand Down Expand Up @@ -216,7 +217,8 @@ ko.utils = new (function () {
},

registerEventHandler: function (element, eventType, handler) {
if (typeof jQuery != "undefined") {
var mustUseAttachEvent = ieVersion && eventsThatMustBeRegisteredUsingAttachEvent[eventType];
if (!mustUseAttachEvent && typeof jQuery != "undefined") {
if (isClickOnCheckableElement(element, eventType)) {
// For click events on checkboxes, jQuery interferes with the event handling in an awkward way:
// it toggles the element checked state *after* the click event handlers run, whereas native
Expand All @@ -232,7 +234,7 @@ ko.utils = new (function () {
};
}
jQuery(element)['bind'](eventType, handler);
} else if (typeof element.addEventListener == "function")
} else if (!mustUseAttachEvent && typeof element.addEventListener == "function")
element.addEventListener(eventType, handler, false);
else if (typeof element.attachEvent != "undefined")
element.attachEvent("on" + eventType, function (event) {
Expand Down

0 comments on commit c9f49db

Please sign in to comment.