1
0
Kandrashin Denis 12 жил өмнө
parent
commit
79dd943161
1 өөрчлөгдсөн 18 нэмэгдсэн , 15 устгасан
  1. 18 15
      source/js/export.js

+ 18 - 15
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 atts = node.attributes;
             var count = atts.length;
             var count = atts.length;
             for (var i = 0; i < count; i++) handler.onAttr(atts[i].name, atts[i].value);
             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);
 })(document);