Code coverage report for lib/utils/index.js

Statements: 100% (14 / 14)      Branches: 100% (0 / 0)      Functions: 100% (2 / 2)      Lines: 100% (14 / 14)      Ignored: none     

All files » lib/utils/ » index.js
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 311   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;
  }
};