Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmhunt committed Aug 30, 2015
2 parents 4abb62f + 967389d commit 2ec506b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions spec/bindingAttributeBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ describe('Binding attribute syntax', function() {
});

it('<template>', function() {
document.createElement('template'); // For old IE
testNode.innerHTML = "<p>Hello</p><template>test</template><p>Goodbye</p>";
ko.applyBindings({ sometext: 'hello' }, testNode);
expect(testNode).toContainHtml('<p>replaced</p><template>test</template><p>replaced</p>');
Expand Down
2 changes: 1 addition & 1 deletion spec/defaultBindings/foreachBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('Binding: Foreach', function() {

it('Exception in afterAdd callback should not cause extra elements on next update', function () {
// See https://github.com/knockout/knockout/issues/1794
testNode.innerHTML = "<ul data-bind='foreach: { data: someItems, afterAdd: callback }'><li data-bind='text: $data'></li></ul>";
testNode.innerHTML = "<div data-bind='foreach: { data: someItems, afterAdd: callback }'><span data-bind='text: $data'></span></div>";
var someItems = ko.observableArray([ 'A', 'B', 'C' ]),
callback = function(element, index, data) { if (data === 'D') throw "Exception"; };

Expand Down
4 changes: 4 additions & 0 deletions spec/parseHtmlFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ describe('Parse HTML fragment', function() {
var parsedNodes = ko.utils.parseHtmlFragment(data.html, document);

if (jasmine.ieVersion <= 8 && parsedNodes.length > 1 && data.parsed && data.parsed.length == 1) {
if (parsedNodes[1].tagName === "TBODY") {
// IE 7 adds a tbody tag; ignore it for the purpose of the test
parsedNodes.pop();
}
ko.utils.arrayForEach(parsedNodes, function (node) {
testNode.appendChild(node);
});
Expand Down
6 changes: 3 additions & 3 deletions src/utils.domManipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
return ko.utils.makeArray(div.lastChild.childNodes);
}

function shouldUseJQueryToParse(html) {
function canUseJQueryToParse(html) {
if (jQueryCanParseTrComponent === undefined) {
jQueryCanParseTrComponent = (jQueryHtmlParse('<tr-component></tr-component>').length > 0);
}
Expand Down Expand Up @@ -88,7 +88,7 @@
}

ko.utils.parseHtmlFragment = function(html, documentContext) {
return (jQueryInstance && shouldUseJQueryToParse(html)) ?
return (jQueryInstance && canUseJQueryToParse(html)) ?
jQueryHtmlParse(html, documentContext) : // As below, benefit from jQuery's optimisations where possible
simpleHtmlParse(html, documentContext); // ... otherwise, this simple logic will do in most common cases.
};
Expand All @@ -106,7 +106,7 @@
// jQuery contains a lot of sophisticated code to parse arbitrary HTML fragments,
// for example <tr> elements which are not normally allowed to exist on their own.
// If you've referenced jQuery we'll use that rather than duplicating its code.
if (jQueryInstance && shouldUseJQueryToParse(html)) {
if (jQueryInstance && canUseJQueryToParse(html)) {
jQueryInstance(node)['html'](html);
} else {
// ... otherwise, use KO's own parsing logic.
Expand Down

0 comments on commit 2ec506b

Please sign in to comment.