_each()

in kitsune/sumo/static/sumo/js/diff.js [75:184]


      _each(self.rawDiffs, function(diff) {
        op = diff[0];    // Operation (insert, delete, equal)
        data = diff[1];  // Text of change.
        text = data
        .replace(ampRegex, '&')
        .replace(ltRegex, '<')
        .replace(gtRegex, '>')
        .replace(' ', ' ');

        sectionLines = text.split(paraRegex);

        for (i = 0, l = sectionLines.length; i < l; i++) {
          if (!fromContinued && !toContinued) {
            fromLine = toLine = {
              changes: false,
              hasFrom: false,
              hasTo: false,
              parts: []
            };
            lines.push(fromLine);
          } else if (!fromContinued) {
            fromLine = {
              changes: false,
              hasFrom: false,
              hasTo: false,
              parts: []
            };
            lines.push(fromLine);
            if (!toLine.hasTo) {
              toLine = fromLine;
            }
          } else if (!toContinued) {
            toLine = {
              changes: false,
              hasFrom: false,
              hasTo: false,
              parts: []
            };
            lines.push(toLine);
            if (!fromLine.hasFrom) {
              fromLine = toLine;
            }
          }

          text = sectionLines[i];

          if (op === DIFF_EQUAL) {
            fromLine.hasFrom = toLine.hasTo = true;
            if (fromLine === toLine) {
              fromLine.parts.push([op, sectionLines[i]]);
            } else {
              // If we aren't on the same line, change the op to not equal
              // to avoid weirdness in the outputted diff where it tries to
              // match across different lines.
              toLine.parts.push([DIFF_INSERT, sectionLines[i]]);
              fromLine.parts.push([DIFF_DELETE, sectionLines[i]]);
            }
            if (i === l - 1) {
              if (text.length !== 0) {
                // The last piece of text didn't have a \n.
                toContinued = fromContinued = true;
              } else {
                toContinued = fromContinued = false;
              }
            } else {
              toContinued = fromContinued = false;
              if (fromLine.hasFrom) {
                fromLine.fromLineNum = fromLineNum++;
              }
              if (toLine.hasTo) {
                toLine.toLineNum = toLineNum++;
              }
            }
          } else if (op === DIFF_DELETE) {
            fromLine.hasFrom = true;
            fromLine.parts.push([op, sectionLines[i]]);
            if (i === l - 1) {
              if (text.length !== 0) {
                // The last piece of text didn't have a \n.
                fromContinued = true;
              } else {
                fromContinued = false;
              }
            } else {
              fromContinued = false;
              if (fromLine.hasFrom) {
                fromLine.fromLineNum = fromLineNum++;
              }
            }
            toContinued = true;
          } else if (op === DIFF_INSERT) {
            toLine.hasTo = true;
            toLine.parts.push([op, sectionLines[i]]);
            if (i === l - 1) {
              if (text.length !== 0) {
                // The last piece of text didn't have a \n.
                toContinued = true;
              } else {
                toContinued = false;
              }
            } else {
              toContinued = false;
              if (toLine.hasTo) {
                toLine.toLineNum = toLineNum++;
              }
            }
            fromContinued = true;
          }
        }
      });