Skip to content

Commit

Permalink
Fix spurious spec failure on IE10 by treating IE10 as a standard browser
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSanderson committed Oct 8, 2012
1 parent 6654678 commit 0fcb5ab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 6 additions & 3 deletions spec/defaultBindings/valueBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,13 @@ describe('Binding: Value', {
value_of(dropdown.selectedIndex).should_be(2);
},

'On IE, should respond exactly once to "propertychange" followed by "blur" or "change" or both': function() {
var isIE = navigator.userAgent.indexOf("MSIE") >= 0;
'On IE < 10, should respond exactly once to "propertychange" followed by "blur" or "change" or both': function() {
// This spec describes the awkward choreography of events needed to detect changes to text boxes on IE < 10,
// because it doesn't fire regular "change" events when the user selects an autofill entry. It isn't applicable
// on IE 10+ or other browsers, because they don't have that problem with autofill.
var isOldIE = JSSpec.Browser.IEVersion && JSSpec.Browser.IEVersion < 10;

if (isIE) {
if (isOldIE) {
var myobservable = new ko.observable(123).extend({ notify: 'always' });
var numUpdates = 0;
myobservable.subscribe(function() { numUpdates++ });
Expand Down
16 changes: 15 additions & 1 deletion spec/lib/JSSpec.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,18 @@ JSSpec.prepareTestNode = function() {
testNode = document.createElement("div");
testNode.id = "testNode";
document.body.appendChild(testNode);
};
};

// Note that, since IE 10 does not support conditional comments, the following logic only detects IE < 10.
// Currently this is by design, since IE 10+ behaves correctly when treated as a standard browser.
// If there is a future need to detect specific versions of IE10+, we will amend this.
JSSpec.Browser.IEVersion = (function() {
var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');

// Keep constructing conditional HTML blocks until we hit one that resolves to an empty fragment
while (
div.innerHTML = '<!--[if gt IE ' + (++version) + ']><i></i><![endif]-->',
iElems[0]
);
return version > 4 ? version : undefined;
}());
3 changes: 3 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ ko.utils = new (function () {
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)
// Note that, since IE 10 does not support conditional comments, the following logic only detects IE < 10.
// Currently this is by design, since IE 10+ behaves correctly when treated as a standard browser.
// If there is a future need to detect specific versions of IE10+, we will amend this.
var ieVersion = (function() {
var version = 3, div = document.createElement('div'), iElems = div.getElementsByTagName('i');

Expand Down

0 comments on commit 0fcb5ab

Please sign in to comment.