export.js 1014 B

123456789101112131415161718192021222324
  1. (function(root) {
  2. var selection = document.getSelection();
  3. var anchorNode = selection.anchorNode;
  4. var focusNode = selection.focusNode;
  5. var f = function(node) {
  6. if (node.nodeName === "#text") {
  7. handler.onTxt(node.data);
  8. if (anchorNode === node) handler.onAnchor(selection.anchorOffset);
  9. if (focusNode === node) handler.onFocus(selection.focusOffset);
  10. } else if (node.nodeName === "#comment") {
  11. handler.onCom(node.data);
  12. } else {
  13. var atts = node.attributes;
  14. var count = atts.length;
  15. for (var i = 0; i < count; ++i) handler.onAttr(atts[i].name, atts[i].value);
  16. handler.onNew(node.nodeName);
  17. for (var n = node.firstChild; n !== null; n = n.nextSibling) f(n);
  18. handler.onEnd(node.nodeName);
  19. }
  20. }
  21. handler.onNew(root.nodeName);
  22. for (var n = root.firstChild; n !== null; n = n.nextSibling) f(n);
  23. handler.onEnd(root.nodeName);
  24. })(document);