Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
nodeToCode() now works on void elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed May 27, 2012
1 parent bd7866d commit 562994a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions js/fc/ui/preview-to-editor-mapping.js
Expand Up @@ -39,12 +39,15 @@ define([
var path = "html " + pathTo(root, node);
var parallelNode = docFrag.querySelector(path);
var result = null;
if (parallelNode)
if (parallelNode) {
var pi = parallelNode.parseInfo;
var isVoidElement = !pi.closeTag;
result = {
start: parallelNode.parseInfo.openTag.start,
end: parallelNode.parseInfo.closeTag.end,
contentStart: parallelNode.parseInfo.openTag.end
start: pi.openTag.start,
end: isVoidElement ? pi.openTag.end : pi.closeTag.end,
contentStart: isVoidElement ? pi.openTag.start : pi.openTag.end
};
}
if (origDocFrag != docFrag) {
for (i = 0; i < htmlNode.childNodes.length; i++)
origDocFrag.appendChild(htmlNode.childNodes[i]);
Expand Down
Expand Up @@ -48,6 +48,13 @@ require([
expect: "<p>u</p>"
});

n2cTest({
name: "nodeToCode() works on void element",
html: '<html><img id="foo"></html>',
selector: "img",
expect: '<img id="foo">'
});

n2cTest({
name: "nodeToCode() can't map to anything from implied <html>",
html: "<p>hi</p>",
Expand Down

0 comments on commit 562994a

Please sign in to comment.