From 79dd943161e7ca2b26e8468cd3cb26ef55f9aa38 Mon Sep 17 00:00:00 2001 From: Kandrashin Denis Date: Fri, 14 Jun 2013 00:42:27 +0400 Subject: Fix HTML export script --- source/js/export.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/source/js/export.js b/source/js/export.js index 0e9ae8d..33e95e8 100644 --- a/source/js/export.js +++ b/source/js/export.js @@ -1,21 +1,24 @@ -var selection = document.getSelection(); -var anchorNode = selection.anchorNode; -var focusNode = selection.focusNode; -(f = function(node) { - if (node.nodeName === "#text") { - if (anchorNode === node) handler.onAnchor(selection.anchorOffset); - if (focusNode === node) handler.onFocus(selection.focusOffset); - handler.onTxt(node.data); - } else if (node.nodeName === "#comment") { - handler.onCom(node.data); - } else { - if (node.nodeName !== "#document") { +(function(root) { + var selection = document.getSelection(); + var anchorNode = selection.anchorNode; + var focusNode = selection.focusNode; + var f = function(node) { + if (node.nodeName === "#text") { + if (anchorNode === node) handler.onAnchor(selection.anchorOffset); + if (focusNode === node) handler.onFocus(selection.focusOffset); + handler.onTxt(node.data); + } else if (node.nodeName === "#comment") { + handler.onCom(node.data); + } else { var atts = node.attributes; var count = atts.length; for (var i = 0; i < count; i++) handler.onAttr(atts[i].name, atts[i].value); + handler.onNew(node.nodeName); + for (var n = node.firstChild; n !== null; n = n.nextSibling) f(n); + handler.onEnd(node.nodeName); } - handler.onNew(node.nodeName); - for (var n = node.firstChild; n !== null; n = n.nextSibling) f(n); - handler.onEnd(node.nodeName); } + handler.onNew(root.nodeName); + for (var n = root.firstChild; n !== null; n = n.nextSibling) f(n); + handler.onEnd(root.nodeName); })(document); -- cgit v1.2.3