1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 1 1 12 12 12 12 2 2 2 12 12 12 2 12 | var createDocumentSection = require("document-section"); module.exports = { getNodePath: function(node) { var path = []; var p = node.parentNode; var c = node; while (p) { // need to slice since some browsers don't support indexOf for child nodes path.unshift(Array.prototype.slice.call(p.childNodes).indexOf(c)); c = p; p = p.parentNode; } return path; }, getNodeByPath: function(node, path) { var c = node; for (var i = 0, n = path.length; i < n; i++) { c = c.childNodes[path[i]]; } return c; } }; |