diff options
author | Kandrashin Denis <mail@lintest.ru> | 2013-06-14 00:42:27 +0400 |
---|---|---|
committer | Kandrashin Denis <mail@lintest.ru> | 2013-06-14 00:42:27 +0400 |
commit | 79dd943161e7ca2b26e8468cd3cb26ef55f9aa38 (patch) | |
tree | 7b001917cc1d53c02d8e95b3042df83e11afa89b | |
parent | 026c23d861946c0bd5297189b1df8263a31e0b1b (diff) |
Fix HTML export script
-rw-r--r-- | source/js/export.js | 33 |
1 files 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); |