Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Force use of attachEvent when registering "propertychange" events (bypas... #444

Merged
merged 1 commit into from

2 participants

@SteveSanderson

...sing jQuery too, as that doesn't support "propertychange" at all)

@SteveSanderson SteveSanderson Force use of attachEvent when registering "propertychange" events (by…
…passing jQuery too, as that doesn't support "propertychange" at all)
c9f49db
@SteveSanderson

For any discussion about this particular pull request, please post to the original issue report here: #406

@mbest mbest merged commit c9f49db into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 23, 2012
  1. @SteveSanderson

    Force use of attachEvent when registering "propertychange" events (by…

    SteveSanderson authored
    …passing jQuery too, as that doesn't support "propertychange" at all)
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +4 −2 src/utils.js
View
6 src/utils.js
@@ -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() {
@@ -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
@@ -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) {
Something went wrong with that request. Please try again.