##// END OF EJS Templates
js: fixes for new diff structure
ergo -
r1166:6a7cea5d default
parent child Browse files
Show More
@@ -1,494 +1,474 b''
1 // # Copyright (C) 2010-2016 RhodeCode GmbH
1 // # Copyright (C) 2010-2016 RhodeCode GmbH
2 // #
2 // #
3 // # This program is free software: you can redistribute it and/or modify
3 // # This program is free software: you can redistribute it and/or modify
4 // # it under the terms of the GNU Affero General Public License, version 3
4 // # it under the terms of the GNU Affero General Public License, version 3
5 // # (only), as published by the Free Software Foundation.
5 // # (only), as published by the Free Software Foundation.
6 // #
6 // #
7 // # This program is distributed in the hope that it will be useful,
7 // # This program is distributed in the hope that it will be useful,
8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // # GNU General Public License for more details.
10 // # GNU General Public License for more details.
11 // #
11 // #
12 // # You should have received a copy of the GNU Affero General Public License
12 // # You should have received a copy of the GNU Affero General Public License
13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 // #
14 // #
15 // # This program is dual-licensed. If you wish to learn more about the
15 // # This program is dual-licensed. If you wish to learn more about the
16 // # RhodeCode Enterprise Edition, including its added features, Support services,
16 // # RhodeCode Enterprise Edition, including its added features, Support services,
17 // # and proprietary license terms, please see https://rhodecode.com/licenses/
17 // # and proprietary license terms, please see https://rhodecode.com/licenses/
18
18
19 /**
19 /**
20 RhodeCode JS Files
20 RhodeCode JS Files
21 **/
21 **/
22
22
23 if (typeof console == "undefined" || typeof console.log == "undefined"){
23 if (typeof console == "undefined" || typeof console.log == "undefined"){
24 console = { log: function() {} }
24 console = { log: function() {} }
25 }
25 }
26
26
27 // TODO: move the following function to submodules
27 // TODO: move the following function to submodules
28
28
29 /**
29 /**
30 * show more
30 * show more
31 */
31 */
32 var show_more_event = function(){
32 var show_more_event = function(){
33 $('table .show_more').click(function(e) {
33 $('table .show_more').click(function(e) {
34 var cid = e.target.id.substring(1);
34 var cid = e.target.id.substring(1);
35 var button = $(this);
35 var button = $(this);
36 if (button.hasClass('open')) {
36 if (button.hasClass('open')) {
37 $('#'+cid).hide();
37 $('#'+cid).hide();
38 button.removeClass('open');
38 button.removeClass('open');
39 } else {
39 } else {
40 $('#'+cid).show();
40 $('#'+cid).show();
41 button.addClass('open one');
41 button.addClass('open one');
42 }
42 }
43 });
43 });
44 };
44 };
45
45
46 var compare_radio_buttons = function(repo_name, compare_ref_type){
46 var compare_radio_buttons = function(repo_name, compare_ref_type){
47 $('#compare_action').on('click', function(e){
47 $('#compare_action').on('click', function(e){
48 e.preventDefault();
48 e.preventDefault();
49
49
50 var source = $('input[name=compare_source]:checked').val();
50 var source = $('input[name=compare_source]:checked').val();
51 var target = $('input[name=compare_target]:checked').val();
51 var target = $('input[name=compare_target]:checked').val();
52 if(source && target){
52 if(source && target){
53 var url_data = {
53 var url_data = {
54 repo_name: repo_name,
54 repo_name: repo_name,
55 source_ref: source,
55 source_ref: source,
56 source_ref_type: compare_ref_type,
56 source_ref_type: compare_ref_type,
57 target_ref: target,
57 target_ref: target,
58 target_ref_type: compare_ref_type,
58 target_ref_type: compare_ref_type,
59 merge: 1
59 merge: 1
60 };
60 };
61 window.location = pyroutes.url('compare_url', url_data);
61 window.location = pyroutes.url('compare_url', url_data);
62 }
62 }
63 });
63 });
64 $('.compare-radio-button').on('click', function(e){
64 $('.compare-radio-button').on('click', function(e){
65 var source = $('input[name=compare_source]:checked').val();
65 var source = $('input[name=compare_source]:checked').val();
66 var target = $('input[name=compare_target]:checked').val();
66 var target = $('input[name=compare_target]:checked').val();
67 if(source && target){
67 if(source && target){
68 $('#compare_action').removeAttr("disabled");
68 $('#compare_action').removeAttr("disabled");
69 $('#compare_action').removeClass("disabled");
69 $('#compare_action').removeClass("disabled");
70 }
70 }
71 })
71 })
72 };
72 };
73
73
74 var showRepoSize = function(target, repo_name, commit_id, callback) {
74 var showRepoSize = function(target, repo_name, commit_id, callback) {
75 var container = $('#' + target);
75 var container = $('#' + target);
76 var url = pyroutes.url('repo_stats',
76 var url = pyroutes.url('repo_stats',
77 {"repo_name": repo_name, "commit_id": commit_id});
77 {"repo_name": repo_name, "commit_id": commit_id});
78
78
79 if (!container.hasClass('loaded')) {
79 if (!container.hasClass('loaded')) {
80 $.ajax({url: url})
80 $.ajax({url: url})
81 .complete(function (data) {
81 .complete(function (data) {
82 var responseJSON = data.responseJSON;
82 var responseJSON = data.responseJSON;
83 container.addClass('loaded');
83 container.addClass('loaded');
84 container.html(responseJSON.size);
84 container.html(responseJSON.size);
85 callback(responseJSON.code_stats)
85 callback(responseJSON.code_stats)
86 })
86 })
87 .fail(function (data) {
87 .fail(function (data) {
88 console.log('failed to load repo stats');
88 console.log('failed to load repo stats');
89 });
89 });
90 }
90 }
91
91
92 };
92 };
93
93
94 var showRepoStats = function(target, data){
94 var showRepoStats = function(target, data){
95 var container = $('#' + target);
95 var container = $('#' + target);
96
96
97 if (container.hasClass('loaded')) {
97 if (container.hasClass('loaded')) {
98 return
98 return
99 }
99 }
100
100
101 var total = 0;
101 var total = 0;
102 var no_data = true;
102 var no_data = true;
103 var tbl = document.createElement('table');
103 var tbl = document.createElement('table');
104 tbl.setAttribute('class', 'trending_language_tbl');
104 tbl.setAttribute('class', 'trending_language_tbl');
105
105
106 $.each(data, function(key, val){
106 $.each(data, function(key, val){
107 total += val.count;
107 total += val.count;
108 });
108 });
109
109
110 var sortedStats = [];
110 var sortedStats = [];
111 for (var obj in data){
111 for (var obj in data){
112 sortedStats.push([obj, data[obj]])
112 sortedStats.push([obj, data[obj]])
113 }
113 }
114 var sortedData = sortedStats.sort(function (a, b) {
114 var sortedData = sortedStats.sort(function (a, b) {
115 return b[1].count - a[1].count
115 return b[1].count - a[1].count
116 });
116 });
117 var cnt = 0;
117 var cnt = 0;
118 $.each(sortedData, function(idx, val){
118 $.each(sortedData, function(idx, val){
119 cnt += 1;
119 cnt += 1;
120 no_data = false;
120 no_data = false;
121
121
122 var hide = cnt > 2;
122 var hide = cnt > 2;
123 var tr = document.createElement('tr');
123 var tr = document.createElement('tr');
124 if (hide) {
124 if (hide) {
125 tr.setAttribute('style', 'display:none');
125 tr.setAttribute('style', 'display:none');
126 tr.setAttribute('class', 'stats_hidden');
126 tr.setAttribute('class', 'stats_hidden');
127 }
127 }
128
128
129 var key = val[0];
129 var key = val[0];
130 var obj = {"desc": val[1].desc, "count": val[1].count};
130 var obj = {"desc": val[1].desc, "count": val[1].count};
131
131
132 var percentage = Math.round((obj.count / total * 100), 2);
132 var percentage = Math.round((obj.count / total * 100), 2);
133
133
134 var td1 = document.createElement('td');
134 var td1 = document.createElement('td');
135 td1.width = 300;
135 td1.width = 300;
136 var trending_language_label = document.createElement('div');
136 var trending_language_label = document.createElement('div');
137 trending_language_label.innerHTML = obj.desc + " (.{0})".format(key);
137 trending_language_label.innerHTML = obj.desc + " (.{0})".format(key);
138 td1.appendChild(trending_language_label);
138 td1.appendChild(trending_language_label);
139
139
140 var td2 = document.createElement('td');
140 var td2 = document.createElement('td');
141 var trending_language = document.createElement('div');
141 var trending_language = document.createElement('div');
142 var nr_files = obj.count +" "+ _ngettext('file', 'files', obj.count);
142 var nr_files = obj.count +" "+ _ngettext('file', 'files', obj.count);
143
143
144 trending_language.title = key + " " + nr_files;
144 trending_language.title = key + " " + nr_files;
145
145
146 trending_language.innerHTML = "<span>" + percentage + "% " + nr_files
146 trending_language.innerHTML = "<span>" + percentage + "% " + nr_files
147 + "</span><b>" + percentage + "% " + nr_files + "</b>";
147 + "</span><b>" + percentage + "% " + nr_files + "</b>";
148
148
149 trending_language.setAttribute("class", 'trending_language');
149 trending_language.setAttribute("class", 'trending_language');
150 $('b', trending_language)[0].style.width = percentage + "%";
150 $('b', trending_language)[0].style.width = percentage + "%";
151 td2.appendChild(trending_language);
151 td2.appendChild(trending_language);
152
152
153 tr.appendChild(td1);
153 tr.appendChild(td1);
154 tr.appendChild(td2);
154 tr.appendChild(td2);
155 tbl.appendChild(tr);
155 tbl.appendChild(tr);
156 if (cnt == 3) {
156 if (cnt == 3) {
157 var show_more = document.createElement('tr');
157 var show_more = document.createElement('tr');
158 var td = document.createElement('td');
158 var td = document.createElement('td');
159 lnk = document.createElement('a');
159 lnk = document.createElement('a');
160
160
161 lnk.href = '#';
161 lnk.href = '#';
162 lnk.innerHTML = _gettext('Show more');
162 lnk.innerHTML = _gettext('Show more');
163 lnk.id = 'code_stats_show_more';
163 lnk.id = 'code_stats_show_more';
164 td.appendChild(lnk);
164 td.appendChild(lnk);
165
165
166 show_more.appendChild(td);
166 show_more.appendChild(td);
167 show_more.appendChild(document.createElement('td'));
167 show_more.appendChild(document.createElement('td'));
168 tbl.appendChild(show_more);
168 tbl.appendChild(show_more);
169 }
169 }
170 });
170 });
171
171
172 $(container).html(tbl);
172 $(container).html(tbl);
173 $(container).addClass('loaded');
173 $(container).addClass('loaded');
174
174
175 $('#code_stats_show_more').on('click', function (e) {
175 $('#code_stats_show_more').on('click', function (e) {
176 e.preventDefault();
176 e.preventDefault();
177 $('.stats_hidden').each(function (idx) {
177 $('.stats_hidden').each(function (idx) {
178 $(this).css("display", "");
178 $(this).css("display", "");
179 });
179 });
180 $('#code_stats_show_more').hide();
180 $('#code_stats_show_more').hide();
181 });
181 });
182
182
183 };
183 };
184
184
185
185
186 // Toggle Collapsable Content
186 // Toggle Collapsable Content
187 function collapsableContent() {
187 function collapsableContent() {
188
188
189 $('.collapsable-content').not('.no-hide').hide();
189 $('.collapsable-content').not('.no-hide').hide();
190
190
191 $('.btn-collapse').unbind(); //in case we've been here before
191 $('.btn-collapse').unbind(); //in case we've been here before
192 $('.btn-collapse').click(function() {
192 $('.btn-collapse').click(function() {
193 var button = $(this);
193 var button = $(this);
194 var togglename = $(this).data("toggle");
194 var togglename = $(this).data("toggle");
195 $('.collapsable-content[data-toggle='+togglename+']').toggle();
195 $('.collapsable-content[data-toggle='+togglename+']').toggle();
196 if ($(this).html()=="Show Less")
196 if ($(this).html()=="Show Less")
197 $(this).html("Show More");
197 $(this).html("Show More");
198 else
198 else
199 $(this).html("Show Less");
199 $(this).html("Show Less");
200 });
200 });
201 };
201 };
202
202
203 var timeagoActivate = function() {
203 var timeagoActivate = function() {
204 $("time.timeago").timeago();
204 $("time.timeago").timeago();
205 };
205 };
206
206
207 // Formatting values in a Select2 dropdown of commit references
207 // Formatting values in a Select2 dropdown of commit references
208 var formatSelect2SelectionRefs = function(commit_ref){
208 var formatSelect2SelectionRefs = function(commit_ref){
209 var tmpl = '';
209 var tmpl = '';
210 if (!commit_ref.text || commit_ref.type === 'sha'){
210 if (!commit_ref.text || commit_ref.type === 'sha'){
211 return commit_ref.text;
211 return commit_ref.text;
212 }
212 }
213 if (commit_ref.type === 'branch'){
213 if (commit_ref.type === 'branch'){
214 tmpl = tmpl.concat('<i class="icon-branch"></i> ');
214 tmpl = tmpl.concat('<i class="icon-branch"></i> ');
215 } else if (commit_ref.type === 'tag'){
215 } else if (commit_ref.type === 'tag'){
216 tmpl = tmpl.concat('<i class="icon-tag"></i> ');
216 tmpl = tmpl.concat('<i class="icon-tag"></i> ');
217 } else if (commit_ref.type === 'book'){
217 } else if (commit_ref.type === 'book'){
218 tmpl = tmpl.concat('<i class="icon-bookmark"></i> ');
218 tmpl = tmpl.concat('<i class="icon-bookmark"></i> ');
219 }
219 }
220 return tmpl.concat(commit_ref.text);
220 return tmpl.concat(commit_ref.text);
221 };
221 };
222
222
223 // takes a given html element and scrolls it down offset pixels
223 // takes a given html element and scrolls it down offset pixels
224 function offsetScroll(element, offset) {
224 function offsetScroll(element, offset) {
225 setTimeout(function() {
225 setTimeout(function() {
226 var location = element.offset().top;
226 var location = element.offset().top;
227 // some browsers use body, some use html
227 // some browsers use body, some use html
228 $('html, body').animate({ scrollTop: (location - offset) });
228 $('html, body').animate({ scrollTop: (location - offset) });
229 }, 100);
229 }, 100);
230 }
230 }
231
231
232 // scroll an element `percent`% from the top of page in `time` ms
232 // scroll an element `percent`% from the top of page in `time` ms
233 function scrollToElement(element, percent, time) {
233 function scrollToElement(element, percent, time) {
234 percent = (percent === undefined ? 25 : percent);
234 percent = (percent === undefined ? 25 : percent);
235 time = (time === undefined ? 100 : time);
235 time = (time === undefined ? 100 : time);
236
236
237 var $element = $(element);
237 var $element = $(element);
238 var elOffset = $element.offset().top;
238 var elOffset = $element.offset().top;
239 var elHeight = $element.height();
239 var elHeight = $element.height();
240 var windowHeight = $(window).height();
240 var windowHeight = $(window).height();
241 var offset = elOffset;
241 var offset = elOffset;
242 if (elHeight < windowHeight) {
242 if (elHeight < windowHeight) {
243 offset = elOffset - ((windowHeight / (100 / percent)) - (elHeight / 2));
243 offset = elOffset - ((windowHeight / (100 / percent)) - (elHeight / 2));
244 }
244 }
245 setTimeout(function() {
245 setTimeout(function() {
246 $('html, body').animate({ scrollTop: offset});
246 $('html, body').animate({ scrollTop: offset});
247 }, time);
247 }, time);
248 }
248 }
249
249
250 /**
250 /**
251 * global hooks after DOM is loaded
251 * global hooks after DOM is loaded
252 */
252 */
253 $(document).ready(function() {
253 $(document).ready(function() {
254 firefoxAnchorFix();
254 firefoxAnchorFix();
255
255
256 $('.navigation a.menulink').on('click', function(e){
256 $('.navigation a.menulink').on('click', function(e){
257 var menuitem = $(this).parent('li');
257 var menuitem = $(this).parent('li');
258 if (menuitem.hasClass('open')) {
258 if (menuitem.hasClass('open')) {
259 menuitem.removeClass('open');
259 menuitem.removeClass('open');
260 } else {
260 } else {
261 menuitem.addClass('open');
261 menuitem.addClass('open');
262 $(document).on('click', function(event) {
262 $(document).on('click', function(event) {
263 if (!$(event.target).closest(menuitem).length) {
263 if (!$(event.target).closest(menuitem).length) {
264 menuitem.removeClass('open');
264 menuitem.removeClass('open');
265 }
265 }
266 });
266 });
267 }
267 }
268 });
268 });
269 $('.compare_view_files').on(
269 $('.compare_view_files').on(
270 'mouseenter mouseleave', 'tr.line .lineno a',function(event) {
270 'mouseenter mouseleave', 'tr.line .lineno a',function(event) {
271 if (event.type === "mouseenter") {
271 if (event.type === "mouseenter") {
272 $(this).parents('tr.line').addClass('hover');
272 $(this).parents('tr.line').addClass('hover');
273 } else {
273 } else {
274 $(this).parents('tr.line').removeClass('hover');
274 $(this).parents('tr.line').removeClass('hover');
275 }
275 }
276 });
276 });
277
277
278 $('.compare_view_files').on(
278 $('.compare_view_files').on(
279 'mouseenter mouseleave', 'tr.line .add-comment-line a',function(event){
279 'mouseenter mouseleave', 'tr.line .add-comment-line a',function(event){
280 if (event.type === "mouseenter") {
280 if (event.type === "mouseenter") {
281 $(this).parents('tr.line').addClass('commenting');
281 $(this).parents('tr.line').addClass('commenting');
282 } else {
282 } else {
283 $(this).parents('tr.line').removeClass('commenting');
283 $(this).parents('tr.line').removeClass('commenting');
284 }
284 }
285 });
285 });
286
286
287 $('body').on( /* TODO: replace the $('.compare_view_files').on('click') below
287 $('body').on( /* TODO: replace the $('.compare_view_files').on('click') below
288 when new diffs are integrated */
288 when new diffs are integrated */
289 'click', '.cb-lineno a', function(event) {
289 'click', '.cb-lineno a', function(event) {
290
290
291 if ($(this).attr('data-line-no') !== ""){
291 if ($(this).attr('data-line-no') !== ""){
292 $('.cb-line-selected').removeClass('cb-line-selected');
292 $('.cb-line-selected').removeClass('cb-line-selected');
293 var td = $(this).parent();
293 var td = $(this).parent();
294 td.addClass('cb-line-selected'); // line number td
294 td.addClass('cb-line-selected'); // line number td
295 td.prev().addClass('cb-line-selected'); // line data td
295 td.prev().addClass('cb-line-selected'); // line data td
296 td.next().addClass('cb-line-selected'); // line content td
296 td.next().addClass('cb-line-selected'); // line content td
297
297
298 // Replace URL without jumping to it if browser supports.
298 // Replace URL without jumping to it if browser supports.
299 // Default otherwise
299 // Default otherwise
300 if (history.pushState) {
300 if (history.pushState) {
301 var new_location = location.href.rstrip('#');
301 var new_location = location.href.rstrip('#');
302 if (location.hash) {
302 if (location.hash) {
303 new_location = new_location.replace(location.hash, "");
303 new_location = new_location.replace(location.hash, "");
304 }
304 }
305
305
306 // Make new anchor url
306 // Make new anchor url
307 new_location = new_location + $(this).attr('href');
307 new_location = new_location + $(this).attr('href');
308 history.pushState(true, document.title, new_location);
308 history.pushState(true, document.title, new_location);
309
309
310 return false;
310 return false;
311 }
311 }
312 }
312 }
313 });
313 });
314
314
315 $('.compare_view_files').on( /* TODO: replace this with .cb function above
315 $('.compare_view_files').on( /* TODO: replace this with .cb function above
316 when new diffs are integrated */
316 when new diffs are integrated */
317 'click', 'tr.line .lineno a',function(event) {
317 'click', 'tr.line .lineno a',function(event) {
318 if ($(this).text() != ""){
318 if ($(this).text() != ""){
319 $('tr.line').removeClass('selected');
319 $('tr.line').removeClass('selected');
320 $(this).parents("tr.line").addClass('selected');
320 $(this).parents("tr.line").addClass('selected');
321
321
322 // Replace URL without jumping to it if browser supports.
322 // Replace URL without jumping to it if browser supports.
323 // Default otherwise
323 // Default otherwise
324 if (history.pushState) {
324 if (history.pushState) {
325 var new_location = location.href;
325 var new_location = location.href;
326 if (location.hash){
326 if (location.hash){
327 new_location = new_location.replace(location.hash, "");
327 new_location = new_location.replace(location.hash, "");
328 }
328 }
329
329
330 // Make new anchor url
330 // Make new anchor url
331 var new_location = new_location+$(this).attr('href');
331 var new_location = new_location+$(this).attr('href');
332 history.pushState(true, document.title, new_location);
332 history.pushState(true, document.title, new_location);
333
333
334 return false;
334 return false;
335 }
335 }
336 }
336 }
337 });
337 });
338
338
339 $('.compare_view_files').on(
339 $('.compare_view_files').on(
340 'click', 'tr.line .add-comment-line a',function(event) {
340 'click', 'tr.line .add-comment-line a',function(event) {
341 var tr = $(event.currentTarget).parents('tr.line')[0];
341 var tr = $(event.currentTarget).parents('tr.line')[0];
342 injectInlineForm(tr);
342 injectInlineForm(tr);
343 return false;
343 return false;
344 });
344 });
345
345
346 $('.collapse_file').on('click', function(e) {
346 $('.collapse_file').on('click', function(e) {
347 e.stopPropagation();
347 e.stopPropagation();
348 if ($(e.target).is('a')) { return; }
348 if ($(e.target).is('a')) { return; }
349 var node = $(e.delegateTarget).first();
349 var node = $(e.delegateTarget).first();
350 var icon = $($(node.children().first()).children().first());
350 var icon = $($(node.children().first()).children().first());
351 var id = node.attr('fid');
351 var id = node.attr('fid');
352 var target = $('#'+id);
352 var target = $('#'+id);
353 var tr = $('#tr_'+id);
353 var tr = $('#tr_'+id);
354 var diff = $('#diff_'+id);
354 var diff = $('#diff_'+id);
355 if(node.hasClass('expand_file')){
355 if(node.hasClass('expand_file')){
356 node.removeClass('expand_file');
356 node.removeClass('expand_file');
357 icon.removeClass('expand_file_icon');
357 icon.removeClass('expand_file_icon');
358 node.addClass('collapse_file');
358 node.addClass('collapse_file');
359 icon.addClass('collapse_file_icon');
359 icon.addClass('collapse_file_icon');
360 diff.show();
360 diff.show();
361 tr.show();
361 tr.show();
362 target.show();
362 target.show();
363 } else {
363 } else {
364 node.removeClass('collapse_file');
364 node.removeClass('collapse_file');
365 icon.removeClass('collapse_file_icon');
365 icon.removeClass('collapse_file_icon');
366 node.addClass('expand_file');
366 node.addClass('expand_file');
367 icon.addClass('expand_file_icon');
367 icon.addClass('expand_file_icon');
368 diff.hide();
368 diff.hide();
369 tr.hide();
369 tr.hide();
370 target.hide();
370 target.hide();
371 }
371 }
372 });
372 });
373
373
374 $('#expand_all_files').click(function() {
374 $('#expand_all_files').click(function() {
375 $('.expand_file').each(function() {
375 $('.expand_file').each(function() {
376 var node = $(this);
376 var node = $(this);
377 var icon = $($(node.children().first()).children().first());
377 var icon = $($(node.children().first()).children().first());
378 var id = $(this).attr('fid');
378 var id = $(this).attr('fid');
379 var target = $('#'+id);
379 var target = $('#'+id);
380 var tr = $('#tr_'+id);
380 var tr = $('#tr_'+id);
381 var diff = $('#diff_'+id);
381 var diff = $('#diff_'+id);
382 node.removeClass('expand_file');
382 node.removeClass('expand_file');
383 icon.removeClass('expand_file_icon');
383 icon.removeClass('expand_file_icon');
384 node.addClass('collapse_file');
384 node.addClass('collapse_file');
385 icon.addClass('collapse_file_icon');
385 icon.addClass('collapse_file_icon');
386 diff.show();
386 diff.show();
387 tr.show();
387 tr.show();
388 target.show();
388 target.show();
389 });
389 });
390 });
390 });
391
391
392 $('#collapse_all_files').click(function() {
392 $('#collapse_all_files').click(function() {
393 $('.collapse_file').each(function() {
393 $('.collapse_file').each(function() {
394 var node = $(this);
394 var node = $(this);
395 var icon = $($(node.children().first()).children().first());
395 var icon = $($(node.children().first()).children().first());
396 var id = $(this).attr('fid');
396 var id = $(this).attr('fid');
397 var target = $('#'+id);
397 var target = $('#'+id);
398 var tr = $('#tr_'+id);
398 var tr = $('#tr_'+id);
399 var diff = $('#diff_'+id);
399 var diff = $('#diff_'+id);
400 node.removeClass('collapse_file');
400 node.removeClass('collapse_file');
401 icon.removeClass('collapse_file_icon');
401 icon.removeClass('collapse_file_icon');
402 node.addClass('expand_file');
402 node.addClass('expand_file');
403 icon.addClass('expand_file_icon');
403 icon.addClass('expand_file_icon');
404 diff.hide();
404 diff.hide();
405 tr.hide();
405 tr.hide();
406 target.hide();
406 target.hide();
407 });
407 });
408 });
408 });
409
409
410 // Mouse over behavior for comments and line selection
410 // Mouse over behavior for comments and line selection
411
411
412 // Select the line that comes from the url anchor
412 // Select the line that comes from the url anchor
413 // At the time of development, Chrome didn't seem to support jquery's :target
413 // At the time of development, Chrome didn't seem to support jquery's :target
414 // element, so I had to scroll manually
414 // element, so I had to scroll manually
415
415
416 if (location.hash) { /* TODO: dan: remove this and replace with code block
416 if (location.hash) {
417 below when new diffs are ready */
418 var result = splitDelimitedHash(location.hash);
419 var loc = result.loc;
420 if (loc.length > 1){
421 var lineno = $(loc+'.lineno');
422 if (lineno.length > 0){
423 var tr = lineno.parents('tr.line');
424 tr.addClass('selected');
425
426 tr[0].scrollIntoView();
427
428 $.Topic('/ui/plugins/code/anchor_focus').prepareOrPublish({
429 tr: tr,
430 remainder: result.remainder});
431 }
432 }
433 }
434
435 if (location.hash) { /* TODO: dan: use this to replace the code block above
436 when new diffs are ready */
437 var result = splitDelimitedHash(location.hash);
417 var result = splitDelimitedHash(location.hash);
438 var loc = result.loc;
418 var loc = result.loc;
439 if (loc.length > 1) {
419 if (loc.length > 1) {
440
420
441 var highlightable_line_tds = [];
421 var highlightable_line_tds = [];
442
422
443 // source code line format
423 // source code line format
444 var page_highlights = loc.substring(
424 var page_highlights = loc.substring(
445 loc.indexOf('#') + 1).split('L');
425 loc.indexOf('#') + 1).split('L');
446
426
447 if (page_highlights.length > 1) {
427 if (page_highlights.length > 1) {
448 var highlight_ranges = page_highlights[1].split(",");
428 var highlight_ranges = page_highlights[1].split(",");
449 var h_lines = [];
429 var h_lines = [];
450 for (var pos in highlight_ranges) {
430 for (var pos in highlight_ranges) {
451 var _range = highlight_ranges[pos].split('-');
431 var _range = highlight_ranges[pos].split('-');
452 if (_range.length === 2) {
432 if (_range.length === 2) {
453 var start = parseInt(_range[0]);
433 var start = parseInt(_range[0]);
454 var end = parseInt(_range[1]);
434 var end = parseInt(_range[1]);
455 if (start < end) {
435 if (start < end) {
456 for (var i = start; i <= end; i++) {
436 for (var i = start; i <= end; i++) {
457 h_lines.push(i);
437 h_lines.push(i);
458 }
438 }
459 }
439 }
460 }
440 }
461 else {
441 else {
462 h_lines.push(parseInt(highlight_ranges[pos]));
442 h_lines.push(parseInt(highlight_ranges[pos]));
463 }
443 }
464 }
444 }
465 for (pos in h_lines) {
445 for (pos in h_lines) {
466 var line_td = $('td.cb-lineno#L' + h_lines[pos]);
446 var line_td = $('td.cb-lineno#L' + h_lines[pos]);
467 if (line_td.length) {
447 if (line_td.length) {
468 highlightable_line_tds.push(line_td);
448 highlightable_line_tds.push(line_td);
469 }
449 }
470 }
450 }
471 }
451 }
472
452
473 // now check a direct id reference (diff page)
453 // now check a direct id reference (diff page)
474 if ($(loc).length && $(loc).hasClass('cb-lineno')) {
454 if ($(loc).length && $(loc).hasClass('cb-lineno')) {
475 highlightable_line_tds.push($(loc));
455 highlightable_line_tds.push($(loc));
476 }
456 }
477 $.each(highlightable_line_tds, function (i, $td) {
457 $.each(highlightable_line_tds, function (i, $td) {
478 $td.addClass('cb-line-selected'); // line number td
458 $td.addClass('cb-line-selected'); // line number td
479 $td.prev().addClass('cb-line-selected'); // line data
459 $td.prev().addClass('cb-line-selected'); // line data
480 $td.next().addClass('cb-line-selected'); // line content
460 $td.next().addClass('cb-line-selected'); // line content
481 });
461 });
482
462
483 if (highlightable_line_tds.length) {
463 if (highlightable_line_tds.length) {
484 var $first_line_td = highlightable_line_tds[0];
464 var $first_line_td = highlightable_line_tds[0];
485 scrollToElement($first_line_td);
465 scrollToElement($first_line_td);
486 $.Topic('/ui/plugins/code/anchor_focus').prepareOrPublish({
466 $.Topic('/ui/plugins/code/anchor_focus').prepareOrPublish({
487 lineno: $first_line_td,
467 td: $first_line_td,
488 remainder: result.remainder
468 remainder: result.remainder
489 });
469 });
490 }
470 }
491 }
471 }
492 }
472 }
493 collapsableContent();
473 collapsableContent();
494 });
474 });
General Comments 0
You need to be logged in to leave comments. Login now