__getBranch: function()

in static/js/com/toc.js [141:172]


  __getBranch: function (sections, level, start, firstRun) {
    var that = this;
    var firstRun = (typeof firstRun !== 'undefined') ? firstRun : true;
    var end = sections.length;
    var tree = [];
    var section, prevSect;

    for (var i = start; i < end; i++) {
      section = sections[i];
      prevSect = (typeof sections[i - 1] !== 'undefined')
        ? sections[i - 1]
        : null;

      if (section.level == level) {
        // siblings
        tree.push(section);
      }
      else if (section.level > level) {
        // inner branch
        if (prevSect && prevSect.level < section.level) {
          prevSect.content = this.__getBranch(sections, section.level, i, false);
        }
      }
      else if (section.level < level) {
        // out of branch
        if (!firstRun) {
          break;
        }
      }
    }
    return tree;
  }