Skip to content
This repository was archived by the owner on Apr 4, 2019. It is now read-only.

Add temporary workaround for SimpleDOM #425

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
"emberjs-build": "0.2.1",
"git-repo-version": "^0.1.2",
"handlebars": "^3.0.2",
"morph-range": "0.2.5",
"morph-range": "0.3.0",
"qunit": "^0.7.2",
"rsvp": "~3.0.6"
"rsvp": "~3.0.6",
"simple-dom": "~0.2.4"
}
}
18 changes: 15 additions & 3 deletions packages/dom-helper/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,23 @@ prototype.insertBoundary = function(fragment, index) {
this.insertBefore(fragment, this.createTextNode(''), child);
};

prototype.setMorphHTML = function(morph, html) {
morph.setHTML(html);
// We plan to remove this eventually, and move to using `setInnerHTML`
// and `insertAdjacentHTML` as the main APIs, so please try not to
// introduce new usage if it can be avoided.
prototype.parseHTML = function(html, contextualElement) {
if (typeof this.document.createRawHTMLSection === 'function') {
// Temporary workaround to support SimpleDOM in node
return this._createRawHTMLSection(html);
}

return this._createDocumentFragmentFromHTML(html, contextualElement);
};

prototype.parseHTML = function(html, contextualElement) {
prototype._createRawHTMLSection = function(html) {
return this.document.createRawHTMLSection(html);
};

prototype._createDocumentFragmentFromHTML = function(html, contextualElement) {
var childNodes;

if (interiorNamespace(contextualElement) === svgNamespace) {
Expand Down
28 changes: 28 additions & 0 deletions packages/dom-helper/tests/dom-helper-node-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/*globals require*/

import DOMHelper from "../dom-helper";

var SimpleDOM = require('simple-dom');

var dom;

QUnit.module('DOM Helper (Node)', {
Expand Down Expand Up @@ -34,3 +38,27 @@ test('it instantiates with a stub document', function(){
var createdElement = dom.createElement('div');
equal(createdElement, element, 'dom helper calls passed stub');
});

QUnit.module('DOM Helper (Integration: SimpleDOM)', {
afterEach: function() {
dom = null;
}
});

test('it instantiates with a SimpleDOM document', function(){
var doc = new SimpleDOM.Document();
dom = new DOMHelper(doc);
ok(dom, 'dom helper can instantiate');
var createdElement = dom.createElement('div');
equal(createdElement.tagName, 'DIV', 'dom helper calls passed stub');
});

test('it does not parse HTML', function(){
var doc = new SimpleDOM.Document();
dom = new DOMHelper(doc);
ok(dom, 'dom helper can instantiate');
var parsed = dom.parseHTML('<div>Hello</div>');
equal(parsed.nodeType, -1, 'parseHTML creates a RawHTMLSection');
equal(parsed.nodeName, '#raw-html-section', 'parseHTML creates a RawHTMLSection');
equal(parsed.nodeValue, '<div>Hello</div>', 'parseHTML creates a RawHTMLSection');
});