/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: Toshio Kuratomi
  • Date: 2010-04-18 17:55:33 UTC
  • mto: (464.1.1 mod-wsgi)
  • mto: This revision was merged to the branch mainline in revision 465.
  • Revision ID: toshio@fedoraproject.org-20100418175533-bmrymlv9ir7v7jwg
Merge README.mod_wsgi into the installation instructions in docs/index.rst and add mod_wsgi note to NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
var unified = true;
2
2
 
3
 
function make_unified(index) {
 
3
function make_unified(chunk) {
4
4
  var pending_added = [];
5
5
  function flush_adds(before) {
6
6
    for (var i = 0; i < pending_added.length; i++) {
7
 
      $(pending_added[i]).insertBefore(before);
 
7
      before.ancestor().insertBefore(pending_added[i], before);
8
8
    }
9
9
    pending_added.length = 0;
10
10
  }
11
 
  $(this).children().filter(".pseudorow").each(
12
 
    function (i, line) {
13
 
      line = $(line);
 
11
  chunk.get('children').filter(".pseudorow").each(
 
12
    function (line) {
14
13
      if (line.hasClass("context-row")) {
15
14
        flush_adds(line);
16
 
        line.find('.code')[0].remove();
 
15
        line.removeChild(line.query('.code'));
17
16
      }
18
17
      else if (line.hasClass("both-row")) {
19
 
        var added_line = $('<div class="pseudorow insert-row"><div class="lineNumber first">&nbsp;</div><div class="clear">&nbsp;</div></div>');
20
 
        var clear = $(added_line).find('.clear');
21
 
        $(line).find('.lineNumber.second').insertBefore(clear);
22
 
        $(line).find('.code.insert').insertBefore(clear);
 
18
        var added_line = line.create('<div class="pseudorow insert-row"><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);
23
22
        pending_added[pending_added.length] = added_line;
24
 
        $('<div class="lineNumber second">&nbsp;</div>').insertBefore($(line).find('.code.delete'));
25
 
        line.addClass('delete-row').removeClass('both-row');
 
23
        line.insertBefore(line.create('<div class="lineNumber second">&nbsp;</div>'), line.query('.code.delete'));
 
24
        line.replaceClass("both-row", "delete-row");
26
25
      }
27
26
      else if (line.hasClass("insert-row")) {
28
27
        flush_adds(line);
29
 
        line.find('.blank').remove();
 
28
        line.removeChild(line.query('.blank'));
30
29
      }
31
30
      else if (line.hasClass("delete-row")) {
32
 
        $(line).find('.blank').remove();
33
 
        $(line).find('.lineNumber.second').insertBefore($(line).find('.code.delete'));
 
31
        line.removeChild(line.query('.blank'));
 
32
        line.insertBefore(line.query('.lineNumber.second'), line.query('.code.delete'));
34
33
      }
35
34
    });
36
35
  flush_adds(null);
37
 
  $(this).addClass('unified').removeClass('sbs');
 
36
  chunk.replaceClass('sbs', 'unified');
38
37
}
39
38
 
40
 
function make_sbs(index) {
 
39
function make_sbs(chunk) {
41
40
  var added = [];
42
41
  var removed = [];
43
42
  function clear_bufs(before) {
46
45
    for (var i = 0; i < common; i++) {
47
46
      var a = added[i];
48
47
      var r = removed[i];
49
 
      a.remove();
50
 
      r.find('.lineNumber.second').remove();
51
 
      $(a).find('.lineNumber.second').insertBefore($(r).find('.clear'));
52
 
      $(a).find('.code.insert').insertBefore($(r).find('.clear'));
53
 
      r.addClass('both-row').removeClass('removed-row');
 
48
      a.ancestor().removeChild(a);
 
49
      r.removeChild(r.query('.lineNumber.second'));
 
50
      r.insertBefore(a.query('.lineNumber.second'), r.query('.clear'));
 
51
      r.insertBefore(a.query('.code.insert'), r.query('.clear'));
 
52
      r.replaceClass('removed-row', 'both-row');
54
53
    }
55
54
    if (added.length > removed.length) {
56
55
      for (var j = common; j < added.length; j++) {
57
 
        a = $(added[j]);
58
 
        a.find('.lineNumber.second').before('<div class="code blank">&nbsp;</div>');
 
56
        a = added[j];
 
57
        a.insertBefore(a.create('<div class="blank">&nbsp;</div>'), a.query('.lineNumber.second'));
59
58
      }
60
59
    }
61
60
    else if (added.length < removed.length) {
62
61
      for (var j = common; j < removed.length; j++) {
63
 
        r = $(removed[j]);
64
 
        r.find('.code.delete').insertBefore(r.find('.lineNumber.second'));
65
 
        r.find('.clear').before('<div class="code blank">&nbsp;</div>')
 
62
        r = removed[j];
 
63
        r.insertBefore(r.query('.code.delete'), r.query('.lineNumber.second'));
 
64
        r.insertBefore(r.create('<div class="blank">&nbsp;</div>'), r.query('.clear'));
66
65
      }
67
66
    }
68
67
    added.length = 0;
69
68
    removed.length = 0;
70
69
  }
71
 
  $(this).children().filter(".pseudorow").each(
72
 
    function (i, line) {
73
 
      line = $(line);
 
70
  chunk.get('children').filter(".pseudorow").each(
 
71
    function (line) {
74
72
      if (line.hasClass("context-row")) {
75
73
        clear_bufs(line);
76
 
        $(line).find(".second").before($(line).find('.code').clone());
 
74
        line.insertBefore(line.query('.code').cloneNode(true), line.query(".second"));
77
75
      }
78
76
      else if (line.hasClass("insert-row")) {
79
77
        added[added.length] = line;
83
81
      }
84
82
    });
85
83
  clear_bufs(null);
86
 
  $(this).addClass('sbs').removeClass('unified');
 
84
  chunk.replaceClass('unified', 'sbs');
87
85
 
88
86
}
89
87
 
90
88
function toggle_unified_sbs(event) {
91
89
  event.preventDefault();
92
 
  var pts = $(".pseudotable");
 
90
  var pts = Y.all(".pseudotable");
93
91
  if (unified) {
94
92
    pts && pts.each(make_sbs);
95
93
    unified = false;
96
 
    $("#toggle_unified_sbs").html("Show unified diffs");
 
94
    Y.get("#toggle_unified_sbs").set('innerHTML', "Show unified diffs");
97
95
  }
98
96
  else {
99
97
    pts && pts.each(make_unified);
100
98
    unified = true;
101
 
    $("#toggle_unified_sbs").html("Show diffs side-by-side");
 
99
    Y.get("#toggle_unified_sbs").set('innerHTML', "Show diffs side-by-side");
102
100
  }
103
101
}
104
102
 
105
 
$(function() {
106
 
$('#toggle_unified_sbs').on("click", toggle_unified_sbs);
107
 
});
 
103
Y.on("click", toggle_unified_sbs, '#toggle_unified_sbs');
108
104
 
109
105
function toggle_expand_all_revisionview(action)
110
106
{
111
 
  var diffs = $('.diff');
 
107
  var diffs = Y.all('.diff');
112
108
  if (diffs == null) return;
113
109
  diffs.each(
114
 
    function(i, item)
 
110
    function(item, i)
115
111
    {
116
112
      var collapsable = item.collapsable;
117
113
      if(action == 'close')
118
114
      {
119
 
        $('#expand_all').css({'display': 'block'});
120
 
        $('#collapse_all').css({'display': 'none'});
 
115
        Y.get('#expand_all').setStyle('display','block');
 
116
        Y.get('#collapse_all').setStyle('display','none');
121
117
        collapsable.close();
122
118
      }
123
119
      else if(action == 'open')
124
120
      {
125
 
        $('#expand_all').css({'display': 'none'});
126
 
        $('#collapse_all').css({'display': 'block'});
 
121
        Y.get('#expand_all').setStyle('display','none');
 
122
        Y.get('#collapse_all').setStyle('display','block');
127
123
        collapsable.open();
128
124
      }
129
125
    });
130
126
}
131
127
 
132
 
$(function() {
133
 
$('#expand_all a').on(
 
128
Y.on(
134
129
  'click',
135
130
  function (event) {
136
131
    event.preventDefault();
137
132
    toggle_expand_all_revisionview('open');
138
133
  },
 
134
  '#expand_all a'
139
135
);
140
 
});
141
136
 
142
 
$(function() {
143
 
$('#collapse_all a').on(
 
137
Y.on(
144
138
  'click',
145
139
  function (event) {
146
140
    event.preventDefault();
147
141
    toggle_expand_all_revisionview('close');
148
142
  },
 
143
  '#collapse_all a'
149
144
);
150
 
});
151
145
 
152
146
function node_process(node) {
153
147
  if (!unified) {
154
 
    node.children().filter('.pseudotable').each(make_sbs);
 
148
    node.get('children').filter('.pseudotable').each(make_sbs);
155
149
  }
156
150
}
157
151
 
158
152
function zoom_to_diff (path) {
159
 
  var collapsable = $('#' + path_to_id[path]).collapsable;
 
153
  var collapsable = Y.get('#' + path_to_id[path]).collapsable;
160
154
  if (!collapsable.is_open) {
161
155
    collapsable.open(
162
156
      function () {
165
159
  }
166
160
}
167
161
 
168
 
var original_diff_download_link = null;
169
 
 
170
 
function compute_diff_links() {
171
 
  var numlines = $('#contextLines').val();
172
 
  $('.diff').each(
173
 
    function(i, item)
174
 
    {
175
 
      item.collapsable.source = global_path + '+filediff/' + link_data[item.id] + '?context=' + numlines;
176
 
    });
177
 
  if(original_diff_download_link == null) original_diff_download_link = $('#download_link').attr('href');
178
 
  $('#download_link').attr('href', original_diff_download_link + '?context=' + numlines);
179
 
}
180
 
 
181
 
function get_num_lines() {
182
 
  var numlines = $('#contextLines').val();
183
 
  return numlines;
184
 
}
185
 
 
186
 
$(function () {
187
 
    $(".show_if_js").removeClass("show_if_js");
 
162
Y.on(
 
163
  "domready", function () {
 
164
    Y.all(".show_if_js").removeClass("show_if_js");
188
165
    if (!specific_path) {
189
 
      $("a#list-files").on(
 
166
      Y.all("#list-files a").on(
190
167
        'click',
191
168
        function (e) {
192
169
          e.preventDefault();
193
 
          var path = decodeURIComponent(e.target.href.split('#')[1]);
 
170
          var path = decodeURIComponent(e.target.get('href').split('#')[1]);
194
171
          window.location.hash = '#' + path;
195
172
          zoom_to_diff(path);
196
173
        });
197
174
    }
198
 
    var diffs = $('.diff');
 
175
    var diffs = Y.all('.diff');
199
176
    if (diffs == null) return;
200
 
    var numlines = $('#contextLines').val();
201
177
    diffs.each(
202
 
      function(i, item)
 
178
      function(item, i)
203
179
      {
204
 
        var source_url = global_path + '+filediff/' + link_data[item.id] + '?context=' + numlines;
205
 
        $(item).find('.the-link').on(
 
180
        var source_url = null;
 
181
        if (!specific_path)
 
182
          source_url = global_path + '+filediff/' + link_data[item.get('id')];
 
183
        item.query('.the-link').on(
206
184
          'click',
207
185
          function(e) {
208
186
            e.preventDefault();
209
 
            item.collapsable.source = global_path + '+filediff/' + link_data[item.id] + '?context=' + $('#contextLines').val();
210
187
            collapsable.toggle();
211
188
          });
212
189
        var collapsable = new Collapsable(
213
190
          {
214
 
            expand_icon: $(item).find('.expand_diff'),
215
 
            open_node: $(item).find('.diffinfo'),
 
191
            expand_icon: item.query('.expand_diff'),
 
192
            open_node: item.query('.diffinfo'),
216
193
            close_node: null,
217
194
            source: source_url,
218
195
            is_open: specific_path != null,
219
 
            loading: $(item).find('.loading'),
 
196
            loading: item.query('.loading'),
220
197
            node_process: node_process
221
198
          });
222
199
       item.collapsable=collapsable;
223
200
       });
224
 
    compute_diff_links();
225
201
    if (window.location.hash && !specific_path) {
226
202
      zoom_to_diff(window.location.hash.substring(1));
227
203
    }