Skip to content

Commit

Permalink
Fix issue knockout#194 (HTML5 elements on IE < 9)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSanderson committed Nov 17, 2011
1 parent 00ab90c commit a697229
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
10 changes: 10 additions & 0 deletions spec/defaultBindingsBehaviors.js
Expand Up @@ -1418,5 +1418,15 @@ describe('Binding: Foreach', {
// ... but IE < 8 doesn't add ones that immediately precede a <li>
value_of(testNode).should_contain_html('<ul><li>header item</li><!-- ko foreach: someitems --><li data-bind="text: $data">alpha<li data-bind="text: $data">beta</li><!-- /ko --></ul>');
}
},

'Should be able to output HTML5 elements (even on IE<9, as long as you reference either innershiv.js or jQuery1.7+Modernizr)': function() {
// Represents https://github.com/SteveSanderson/knockout/issues/194
ko.utils.setHtml(testNode, "<div data-bind='foreach:someitems'><section data-bind='text: $data'></section></div>");
var viewModel = {
someitems: [ 'Alpha', 'Beta' ]
};
ko.applyBindings(viewModel, testNode);
value_of(testNode).should_contain_html('<div data-bind="foreach:someitems"><section data-bind="text: $data">alpha</section><section data-bind="text: $data">beta</section></div>');
}
});
2 changes: 2 additions & 0 deletions spec/lib/innershiv.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion spec/runner.html
Expand Up @@ -5,8 +5,9 @@
<link rel="stylesheet" type="text/css" href="lib/JSSpec.css" />

<!-- All specs should pass with or without jQuery being referenced -->
<!-- <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.js"></script> -->
<!-- <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.0.js"></script> -->

<script type="text/javascript" src="lib/innershiv.js"></script>
<script type="text/javascript" src="lib/diff_match_patch.js"></script>
<script type="text/javascript" src="lib/JSSpec.js"></script>
<script type="text/javascript">
Expand Down
10 changes: 8 additions & 2 deletions src/utils.domManipulation.js
Expand Up @@ -21,7 +21,12 @@

// Go to html and back, then peel off extra wrappers
// Note that we always prefix with some dummy text, because otherwise, IE<9 will strip out leading comment nodes in descendants. Total madness.
div.innerHTML = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>";
var markup = "ignored<div>" + wrap[1] + html + wrap[2] + "</div>";
if (typeof window['innerShiv'] == "function") {
div.appendChild(window['innerShiv'](markup));
} else {
div.innerHTML = markup;
}

// Move to the right depth
while (wrap[0]--)
Expand Down Expand Up @@ -57,4 +62,5 @@
};
})();

ko.exportSymbol('ko.utils.parseHtmlFragment', ko.utils.parseHtmlFragment);
ko.exportSymbol('ko.utils.parseHtmlFragment', ko.utils.parseHtmlFragment);
ko.exportSymbol('ko.utils.setHtml', ko.utils.setHtml);

0 comments on commit a697229

Please sign in to comment.