Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'gh-pages' into i18n

  • Loading branch information...
commit 21a9be6dc929f2dc2f8d7280b058b616a8bbfe1e 2 parents 7176a2f + f28342e
@toolness authored
View
33 js/fc/ui/preview-to-editor-mapping.js
@@ -61,6 +61,14 @@ define(["jquery", "./mark-tracker"], function($, MarkTracker) {
return parallelNode;
}
+ function intervalForElement(element, docFrag) {
+ var tagName = element.tagName.toLowerCase();
+ var interval = null;
+ if (tagName !== "html" && tagName !== "body")
+ return nodeToCode(element, docFrag);
+ return null;
+ }
+
function PreviewToEditorMapping(livePreview) {
var codeMirror = livePreview.codeMirror;
var marks = MarkTracker(codeMirror);
@@ -69,30 +77,31 @@ define(["jquery", "./mark-tracker"], function($, MarkTracker) {
livePreview.on("refresh", function(event) {
var docFrag = event.documentFragment;
marks.clear();
- $(event.window).on("mousedown", function(event) {
- marks.clear();
- var tagName = event.target.tagName.toLowerCase();
- var interval = null;
- if (tagName !== "html" && tagName !== "body")
- interval = nodeToCode(event.target, docFrag);
+ $(event.window).on("mousedown", "*", function(event) {
+ var interval = intervalForElement(this, docFrag);
if (interval) {
var start = codeMirror.posFromIndex(interval.start);
- var end = codeMirror.posFromIndex(interval.end);
- var contentStart = codeMirror.posFromIndex(interval.contentStart);
var startCoords = codeMirror.charCoords(start, "local");
codeMirror.scrollTo(startCoords.x, startCoords.y);
- marks.mark(interval.start, interval.end,
- "preview-to-editor-highlight");
codeMirror.focus();
- event.preventDefault();
- event.stopPropagation();
}
});
+ $(event.window).on("mouseleave", "html", function(event) {
+ marks.clear();
+ });
+ $(event.window).on("mouseover", function(event) {
+ marks.clear();
+ var interval = intervalForElement(event.target, docFrag);
+ if (interval)
+ marks.mark(interval.start, interval.end,
+ "preview-to-editor-highlight");
+ });
});
}
PreviewToEditorMapping._pathTo = pathTo;
PreviewToEditorMapping._nodeToCode = nodeToCode;
+ PreviewToEditorMapping._getParallelNode = getParallelNode;
return PreviewToEditorMapping;
});
View
11 test/preview-to-editor-mapping/test-preview-to-editor-mapping.js
@@ -8,7 +8,8 @@ defineTests([
var nodeToCode = PreviewToEditorMapping._nodeToCode;
var pathTo = PreviewToEditorMapping._pathTo;
-
+ var getParallelNode = PreviewToEditorMapping._getParallelNode;
+
function spaces(n) {
var s = [];
for (var i = 0; i < n; i++) s.push(" ");
@@ -38,12 +39,16 @@ defineTests([
var p = wind.document.querySelector(options.selector);
if (!p)
throw new Error("selector doesn't map to anything");
+ var parallelNode = getParallelNode(p, docFrag);
var interval = nodeToCode(p, docFrag);
if (!options.expect)
- ok(interval === null, desc + "doesn't map to any code");
- else
+ ok(interval === null && parallelNode === null,
+ desc + "doesn't map to any code");
+ else {
+ ok(parallelNode !== null, "parallel DOM node exists");
equal(html.slice(interval.start, interval.end), options.expect,
desc + "maps to code " + JSON.stringify(options.expect));
+ }
equal(domStructure(docFrag), originalDom,
"DOM structure of document fragment is unchanged");
});
Please sign in to comment.
Something went wrong with that request. Please try again.