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