/loggerhead/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerhead/trunk

« back to all changes in this revision

Viewing changes to loggerhead/static/javascript/diff.js

  • Committer: Michael Hudson
  • Date: 2009-02-24 01:46:23 UTC
  • mfrom: (270.3.20 no-more-mootools)
  • Revision ID: michael.hudson@canonical.com-20090224014623-44zenkmtzus7xo3x
merge no-more-mootools
this removes all use of mootools and switches over to YUI3 PR2 for all the
dynamic stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI().use(
2
 
  "node", function (Y) {
3
 
    var unified = true;
4
 
 
5
 
    function make_unified(chunk) {
6
 
      var pending_added = [];
7
 
      function flush_adds(before) {
8
 
        for (var i = 0; i < pending_added.length; i++) {
9
 
          before.ancestor().insertBefore(pending_added[i], before);
10
 
        }
11
 
        pending_added.length = 0;
12
 
      }
13
 
      chunk.get('children').filter(".pseudorow").each(
14
 
        function (line) {
15
 
          if (line.hasClass("context")) {
16
 
            flush_adds(line);
17
 
            line.removeChild(line.query('.code'));
18
 
          }
19
 
          else if (line.hasClass("both")) {
20
 
            var added_line = line.create('<div class="pseudorow insert"><div class="lineNumber first">&nbsp;</div><div class="clear">&nbsp;</div></div>');
21
 
            var clear = added_line.query('.clear');
22
 
            added_line.insertBefore(line.query('.lineNumber.second'), clear);
23
 
            added_line.insertBefore(line.query('.code.insert'), clear);
24
 
            pending_added[pending_added.length] = added_line;
25
 
            line.insertBefore(line.create('<div class="lineNumber second">&nbsp;</div>'), line.query('.code.delete'));
26
 
            line.replaceClass("both", "delete");
27
 
          }
28
 
          else if (line.hasClass("insert")) {
29
 
            flush_adds(line);
30
 
            line.removeChild(line.query('.blank'));
31
 
          }
32
 
          else if (line.hasClass("delete")) {
33
 
            line.removeChild(line.query('.blank'));
34
 
            line.insertBefore(line.query('.lineNumber.second'), line.query('.code.delete'));
35
 
          }
36
 
        });
37
 
      flush_adds(null);
38
 
      chunk.replaceClass('sbs', 'unified');
39
 
    }
40
 
 
41
 
    function make_sbs(chunk) {
42
 
      var added = [];
43
 
      var removed = [];
44
 
      function clear_bufs(before) {
45
 
        if (!added.length && !removed.length) return;
46
 
        Y.log('hai');
47
 
        var common = Math.min(added.length, removed.length);
48
 
        for (var i = 0; i < common; i++) {
49
 
          var a = added[i];
50
 
          var r = removed[i];
51
 
          a.ancestor().removeChild(a);
52
 
          r.removeChild(r.query('.lineNumber.second'));
53
 
          r.insertBefore(a.query('.lineNumber.second'), r.query('.clear'));
54
 
          r.insertBefore(a.query('.code.insert'), r.query('.clear'));
55
 
          r.replaceClass('removed', 'both');
56
 
        }
57
 
        Y.log('hai');
58
 
        if (added.length > removed.length) {
59
 
          for (var j = common; j < added.length; j++) {
60
 
            a = added[j];
61
 
            a.insertBefore(a.create('<div class="blank">&nbsp;</div>'), a.query('.lineNumber.second'));
62
 
          }
63
 
        }
64
 
        else if (added.length < removed.length) {
65
 
          for (var j = common; j < removed.length; j++) {
66
 
            r = removed[j];
67
 
            r.insertBefore(r.query('.code.delete'), r.query('.lineNumber.second'));
68
 
            r.insertBefore(r.create('<div class="blank">&nbsp;</div>'), r.query('.clear'));
69
 
          }
70
 
        }
71
 
        added.length = 0;
72
 
        removed.length = 0;
73
 
      }
74
 
      chunk.get('children').filter(".pseudorow").each(
75
 
        function (line) {
76
 
          if (line.hasClass("context")) {
77
 
            clear_bufs(line);
78
 
            line.insertBefore(line.query('.code').cloneNode(true), line.query(".second"));
79
 
          }
80
 
          else if (line.hasClass("insert")) {
81
 
            added[added.length] = line;
82
 
          }
83
 
          else if (line.hasClass("delete")) {
84
 
            removed[removed.length] = line;
85
 
          }
86
 
        });
87
 
      clear_bufs(null);
88
 
      chunk.replaceClass('unified', 'sbs');
89
 
 
90
 
    }
91
 
 
92
 
    function toggle_unified_sbs(event) {
93
 
      event.preventDefault();
94
 
      if (unified) {
95
 
        Y.all(".pseudotable").each(make_sbs);
96
 
        unified = false;
97
 
        Y.get("#toggle_unified_sbs").set('textContent', "Show unified diffs");
98
 
      }
99
 
      else {
100
 
        Y.all(".pseudotable").each(make_unified);
101
 
        unified = true;
102
 
        Y.get("#toggle_unified_sbs").set('textContent', "Show diffs side-by-side");
103
 
      }
104
 
    }
105
 
 
106
 
    Y.on("click", toggle_unified_sbs, '#toggle_unified_sbs');
107
 
    Y.on(
108
 
      "domready", function () {
109
 
        Y.all(".show_if_js").removeClass("show_if_js");
 
1
var unified = true;
 
2
 
 
3
function make_unified(chunk) {
 
4
  var pending_added = [];
 
5
  function flush_adds(before) {
 
6
    for (var i = 0; i < pending_added.length; i++) {
 
7
      before.ancestor().insertBefore(pending_added[i], before);
 
8
    }
 
9
    pending_added.length = 0;
 
10
  }
 
11
  chunk.get('children').filter(".pseudorow").each(
 
12
    function (line) {
 
13
      if (line.hasClass("context")) {
 
14
        flush_adds(line);
 
15
        line.removeChild(line.query('.code'));
 
16
      }
 
17
      else if (line.hasClass("both")) {
 
18
        var added_line = line.create('<div class="pseudorow insert"><div class="lineNumber first">&nbsp;</div><div class="clear">&nbsp;</div></div>');
 
19
        var clear = added_line.query('.clear');
 
20
        added_line.insertBefore(line.query('.lineNumber.second'), clear);
 
21
        added_line.insertBefore(line.query('.code.insert'), clear);
 
22
        pending_added[pending_added.length] = added_line;
 
23
        line.insertBefore(line.create('<div class="lineNumber second">&nbsp;</div>'), line.query('.code.delete'));
 
24
        line.replaceClass("both", "delete");
 
25
      }
 
26
      else if (line.hasClass("insert")) {
 
27
        flush_adds(line);
 
28
        line.removeChild(line.query('.blank'));
 
29
      }
 
30
      else if (line.hasClass("delete")) {
 
31
        line.removeChild(line.query('.blank'));
 
32
        line.insertBefore(line.query('.lineNumber.second'), line.query('.code.delete'));
 
33
      }
 
34
    });
 
35
  flush_adds(null);
 
36
  chunk.replaceClass('sbs', 'unified');
 
37
}
 
38
 
 
39
function make_sbs(chunk) {
 
40
  var added = [];
 
41
  var removed = [];
 
42
  function clear_bufs(before) {
 
43
    if (!added.length && !removed.length) return;
 
44
    Y.log('hai');
 
45
    var common = Math.min(added.length, removed.length);
 
46
    for (var i = 0; i < common; i++) {
 
47
      var a = added[i];
 
48
      var r = removed[i];
 
49
      a.ancestor().removeChild(a);
 
50
      r.removeChild(r.query('.lineNumber.second'));
 
51
      r.insertBefore(a.query('.lineNumber.second'), r.query('.clear'));
 
52
      r.insertBefore(a.query('.code.insert'), r.query('.clear'));
 
53
      r.replaceClass('removed', 'both');
 
54
    }
 
55
    Y.log('hai');
 
56
    if (added.length > removed.length) {
 
57
      for (var j = common; j < added.length; j++) {
 
58
        a = added[j];
 
59
        a.insertBefore(a.create('<div class="blank">&nbsp;</div>'), a.query('.lineNumber.second'));
 
60
      }
 
61
    }
 
62
    else if (added.length < removed.length) {
 
63
      for (var j = common; j < removed.length; j++) {
 
64
        r = removed[j];
 
65
        r.insertBefore(r.query('.code.delete'), r.query('.lineNumber.second'));
 
66
        r.insertBefore(r.create('<div class="blank">&nbsp;</div>'), r.query('.clear'));
 
67
      }
 
68
    }
 
69
    added.length = 0;
 
70
    removed.length = 0;
 
71
  }
 
72
  chunk.get('children').filter(".pseudorow").each(
 
73
    function (line) {
 
74
      if (line.hasClass("context")) {
 
75
        clear_bufs(line);
 
76
        line.insertBefore(line.query('.code').cloneNode(true), line.query(".second"));
 
77
      }
 
78
      else if (line.hasClass("insert")) {
 
79
        added[added.length] = line;
 
80
      }
 
81
      else if (line.hasClass("delete")) {
 
82
        removed[removed.length] = line;
 
83
      }
 
84
    });
 
85
  clear_bufs(null);
 
86
  chunk.replaceClass('unified', 'sbs');
 
87
 
 
88
}
 
89
 
 
90
function toggle_unified_sbs(event) {
 
91
  event.preventDefault();
 
92
  if (unified) {
 
93
    Y.all(".pseudotable").each(make_sbs);
 
94
    unified = false;
 
95
    Y.get("#toggle_unified_sbs").set('textContent', "Show unified diffs");
 
96
  }
 
97
  else {
 
98
    Y.all(".pseudotable").each(make_unified);
 
99
    unified = true;
 
100
    Y.get("#toggle_unified_sbs").set('textContent', "Show diffs side-by-side");
 
101
  }
 
102
}
 
103
 
 
104
Y.on("click", toggle_unified_sbs, '#toggle_unified_sbs');
 
105
 
 
106
function toggle_expand_all_revisionview(action)
 
107
{
 
108
  var diffs = Y.all('.diffBox');
 
109
  if (diffs == null) return;
 
110
  diffs.each(
 
111
    function(item, i)
 
112
    {
 
113
      var collapsable = item.collapsable;
 
114
      if(action == 'close')
 
115
      {
 
116
        Y.get('#expand_all').setStyle('display','block');
 
117
        Y.get('#collapse_all').setStyle('display','none');
 
118
        collapsable.close();
 
119
      }
 
120
      else if(action == 'open')
 
121
      {
 
122
        Y.get('#expand_all').setStyle('display','none');
 
123
        Y.get('#collapse_all').setStyle('display','block');
 
124
        collapsable.open();
 
125
      }
 
126
    });
 
127
}
 
128
 
 
129
Y.on(
 
130
  'click',
 
131
  function (event) {
 
132
    event.preventDefault();
 
133
    toggle_expand_all_revisionview('open');
 
134
  },
 
135
  '#expand_all a'
 
136
);
 
137
 
 
138
Y.on(
 
139
  'click',
 
140
  function (event) {
 
141
    event.preventDefault();
 
142
    toggle_expand_all_revisionview('close');
 
143
  },
 
144
  '#collapse_all a'
 
145
);
 
146
 
 
147
Y.on(
 
148
  "domready", function () {
 
149
    Y.all(".show_if_js").removeClass("show_if_js");
 
150
    var diffs = Y.all('.diffBox');
 
151
    if (diffs == null) return;
 
152
    diffs.each(
 
153
      function(item, i)
 
154
      {
 
155
        var item_slide = item.next('.diffinfo');
 
156
        var expand_icon = item.query( '.expand_diff' );
 
157
        var collapsable = new Collapsable(item_slide, expand_icon, [], [], true);
 
158
        item.query('.expand_diff').on('click', function(){collapsable.toggle();});
 
159
        item.collapsable=collapsable;
110
160
      });
111
 
  });
 
 
b'\\ No newline at end of file'
 
161
  });