export.js 843 B

123456789101112131415161718192021
  1. var selection = document.getSelection();
  2. var anchorNode = selection.anchorNode;
  3. var focusNode = selection.focusNode;
  4. (f = function(node) {
  5. if (node.nodeName === "#text") {
  6. if (anchorNode === node) handler.onAnchor(selection.anchorOffset);
  7. if (focusNode === node) handler.onFocus(selection.focusOffset);
  8. handler.onTxt(node.data);
  9. } else if (node.nodeName === "#comment") {
  10. handler.onCom(node.data);
  11. } else {
  12. if (node.nodeName !== "#document") {
  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. }
  17. handler.onNew(node.nodeName);
  18. for (var n = node.firstChild; n !== null; n = n.nextSibling) f(n);
  19. handler.onEnd(node.nodeName);
  20. }
  21. })(document);