repo.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. $(document).ready(function()
  2. {
  3. var $diffCode = $('.diff');
  4. var hidePreview;
  5. var $bugsPreview = $('#bugsPreview');
  6. var $bugsPreviewMenu = $('#bugsPreview').children('.dropdown-menu');
  7. var $rows = $diffCode.find('tr');
  8. var rowTip = $('#rowTip').html();
  9. var lastLine;
  10. $rows.each(function()
  11. {
  12. var $row = $(this);
  13. if(!$row.hasClass('empty'))
  14. {
  15. $row.children('th').first().prepend("<div class='comment-btn diff'><span class='icon-wrapper'><i class='icon-plus'></i></span></div>");
  16. $row.children('td').first().append(rowTip);
  17. if($row.data('type') != 'all')
  18. {
  19. var lineID = $row.data('line');
  20. var fileSrc = $row.data('src');
  21. $rightTh = $row.children('th').first().next();
  22. if(arrange == 'appose') $rightTh = $rightTh.next();
  23. $rightTh.prepend("<div class='diff-btn diff' onclick=showCommitInfo(this)><i class='icon-info-sign'></i></div>");
  24. }
  25. }
  26. if(lastLine && !$row.data('line'))
  27. {
  28. $row.attr('data-line', lastLine);
  29. }
  30. else
  31. {
  32. lastLine = $row.data('line');
  33. }
  34. }).hover(function()
  35. {
  36. var $this = $(this);
  37. if($this.hasClass('empty')) return;
  38. $this.addClass("over");
  39. },
  40. function()
  41. {
  42. $(this).removeClass("over");
  43. });
  44. var isInline = $.cookie('arrange') == 'inline';
  45. var $bugFormRow = $('<tr class="action-row"><th></th>' + (isInline ? '<th></th><td class="action-cell"></td>' : '<td colspan="3" class="action-cell"></td>') + '</tr>');
  46. var $bugForm = $('#bugForm');
  47. var $commentCell = $('#commentCell');
  48. var $bugPanel = $('#bugPanel');
  49. $bugFormRow.find('td').append($bugForm.removeClass('hide'));
  50. var highlight = function($e)
  51. {
  52. $('.highlight').removeClass('highlight');
  53. $e.addClass('highlight');
  54. };
  55. var createComment = function(comment, $comments)
  56. {
  57. var $comment = $commentCell.clone()
  58. .removeClass('hide')
  59. .attr('id', 'comment-' + comment.id)
  60. .attr('data-comment', comment.id);
  61. $comment.find('.realname').text(comment.realname);
  62. $comment.find('.comment-content').text(comment.comment);
  63. $comment.find('.date').text(comment.date);
  64. $comment.find('.edit').toggle(comment.edit);
  65. $comment.find('.comment-edit-form').attr('action', createLink('repo', 'editComment', 'commentID=' + comment.id));
  66. if(comment.user.avatar)
  67. {
  68. $comment.find('.avatar').removeClass('has-text').addClass('has-img');
  69. $comment.find('.avatar span').remove();
  70. $comment.find('.avatar').html('<img src="' + comment.user.avatar + '"/>');
  71. }
  72. else
  73. {
  74. $comment.find('.avatar').removeClass('has-img').addClass('has-text');
  75. $comment.find('.avatar img').remove();
  76. var name = comment.user.name ? comment.user.name : (comment.user.realname ? comment.user.realname : comment.user.account);
  77. $comment.find('.avatar').html('<span class="text text-len-' + name.replace(/[^\x00-\xff]/g, "00").length + '">' + name + '</span>');
  78. }
  79. if($comments)
  80. {
  81. if(typeof $comments !== 'object') $comments = $('#bug-' + $comments + ' .comments');
  82. ($comments.hasClass('comments') ? $comments : $comments.find('.comments')).append($comment);
  83. }
  84. return $comment;
  85. };
  86. var createBug = function(bug, line, $commentRow, show)
  87. {
  88. var commentCount, j;
  89. var $bug = $bugPanel.clone().removeClass('hide').attr('id', 'bug-' + bug.id).attr('data-bug', bug.id);
  90. $bug.find('.bugid').text(bug.id);
  91. $bug.find('.view-bug').attr('title', bug.title);
  92. $bug.find('.edit').toggle(bug.edit);
  93. $bug.find('.code-lines').text(bug.lines);
  94. $bug.find('.delete').toggle(bug.delete);
  95. $bug.find('input[name="objectID"]').val(bug.id);
  96. $bug.find('a.view-bug').attr('href', createLink('bug', 'view', 'bugID=' + bug.id + '&from=repo', '', true));
  97. $bug.find('a.bugEdit').attr('href', createLink('bug', 'edit', 'bugID=' + bug.id + '&from=repo', '', true));
  98. $bug.data('data', bug);
  99. $bug.toggleClass('show', show > 1);
  100. if(show > 2) highlight($bug);
  101. if(bug.comments)
  102. {
  103. commentCount = bug.comments.length;
  104. $bugComments = $bug.find('.comments');
  105. for(j = 0; j < commentCount; j++)
  106. {
  107. createComment(bug.comments[j], $bugComments);
  108. }
  109. }
  110. if(!line && bug.line) line = bug.line;
  111. if(line)
  112. {
  113. if(!$commentRow)
  114. {
  115. var $row = $rows.filter('[data-line="' + line + '"][data-src="' + bug.file + '"]').last();
  116. $commentRow = $row.next('tr');
  117. if(!$commentRow.hasClass('comment-row'))
  118. {
  119. $commentRow = $('<tr class="comment-row"><th class="w-num"></th>' + (isInline ? '<th class="w-num"></th><td class="comment-cell"><div class="comment-list"></div></td>' : '<td colspan="3" class="comment-cell"><div class="comment-list"></div></td>') + '</tr>');
  120. $row.addClass('commented').after($commentRow);
  121. }
  122. }
  123. ($commentRow.hasClass('comment-list') ? $commentRow : $commentRow.find('.comment-list')).append($bug);
  124. if(show && $commentRow.hasClass('comment-row')) $commentRow.addClass('show');
  125. }
  126. $bug.find('.iframe').initIframeModal();
  127. return $bug;
  128. };
  129. var toggleComment = function($row, show)
  130. {
  131. var $commentRow;
  132. if($row.hasClass('comment-row'))
  133. {
  134. $commentRow = $row;
  135. $row = $commentRow.prev('tr');
  136. if($row.hasClass('action-row'))
  137. {
  138. $row = $row.prev('tr');
  139. }
  140. }
  141. else
  142. {
  143. $commentRow = $row.next('tr');
  144. if($commentRow.hasClass('action-row'))
  145. {
  146. $commentRow = $commentRow.next('tr');
  147. }
  148. }
  149. if(show === undefined)
  150. {
  151. show = !$row.hasClass('open');
  152. }
  153. if($row.hasClass('commented') && $commentRow.hasClass('comment-row'))
  154. {
  155. $commentRow.toggleClass('show', show);
  156. $row.toggleClass('open', show);
  157. }
  158. };
  159. $diffCode.on('click', '.comment-btn', function(e)
  160. {
  161. $rows.removeClass('selected');
  162. var $row = $(this).closest('tr');
  163. if($diffCode.hasClass('with-action-row') && $row.hasClass('with-action-row'))
  164. {
  165. $diffCode.removeClass('with-action-row');
  166. }
  167. else
  168. {
  169. $diffCode.addClass('with-action-row');
  170. var line = $row.data('line');
  171. var fileName = $row.data('src');
  172. if(!$row.hasClass('with-action-row'))
  173. {
  174. $rows.removeClass('with-action-row')
  175. $row.addClass('with-action-row');
  176. $bugForm.find('input[name="entry"]').val(fileName);
  177. $bugForm.find('input[name="begin"]').val(line);
  178. $bugForm.find('input[name="end"]').attr('min', line).val(line);
  179. $bugForm.find('select#assignedTo').val(blamePairs[line]);
  180. $bugForm.find('select#assignedTo').trigger("chosen:updated");
  181. $row.after($bugFormRow);
  182. KindEditor.remove('#commentText');
  183. $('#commentText').kindeditor();
  184. var getCommiterLink = createLink('repo', 'ajaxgetcommitter', 'repoID=' + repoID + "&entry=" + file + "&revision=" + revision + "&line=" + line);
  185. var connector = getCommiterLink.indexOf('&') >= 0 ? '&' : '?';
  186. getCommiterLink = getCommiterLink + connector + 'entry=' + file;
  187. $.ajax({url: getCommiterLink}).done(function(responseText)
  188. {
  189. $bugForm.find('#assignedTo').val(responseText).trigger("chosen:updated");
  190. });
  191. }
  192. highlight($bugForm);
  193. $bugForm.find('input[name="title"]').focus();
  194. $row.addClass('selected');
  195. }
  196. e.stopPropagation();
  197. }).on('click', '.bugCancel', function()
  198. {
  199. $rows.removeClass('selected');
  200. $diffCode.removeClass('with-action-row');
  201. }).on('click', '.bugEdit,.view-bug', function(e)
  202. {
  203. if(!isonlybody) return false;
  204. }).on('click', '.bugDelete', function(e)
  205. {
  206. var $bug = $(this).closest('.panel-bug');
  207. if(!$bug.length) return;
  208. if(confirm(confirmDelete))
  209. {
  210. var link = createLink('repo', 'deleteBug', 'bugID=' + $bug.data('bug') + '&confirm=yes');
  211. $.get(link, function(data)
  212. {
  213. if(data == 'deleted')
  214. {
  215. var $commentRow = $bug.closest('.comment-row');
  216. if($commentRow.find('.panel-bug').length === 1)
  217. {
  218. $commentRow.removeClass('show').prev('tr').removeClass('commented');
  219. }
  220. $bug.remove();
  221. }
  222. });
  223. }
  224. e.stopPropagation();
  225. return false;
  226. }).on('click', '.addComment', function()
  227. {
  228. $(this).closest('.panel-bug').addClass('show-form').find('.commentForm textarea').focus();
  229. }).on('click', '.commentCancel', function()
  230. {
  231. $(this).closest('.panel-bug').removeClass('show-form');
  232. }).on('submit', '.commentForm', function()
  233. {
  234. var $form = $(this);
  235. $form.ajaxSubmit(
  236. {
  237. success:function(json)
  238. {
  239. var $panelBug = $form.closest('.panel-bug');
  240. $form.find('textarea').val('');
  241. $panelBug.removeClass('show-form');
  242. createComment($.parseJSON(json), $panelBug.data('bug'));
  243. },
  244. beforeSubmit:function(formData, jqForm)
  245. {
  246. var form = jqForm[0];
  247. if(!form.comment.value)
  248. {
  249. alert(commentError);
  250. return false;
  251. }
  252. }
  253. });
  254. return false;
  255. }).on('click', '.commentEdit', function()
  256. {
  257. var $comment = $(this).closest('.comment');
  258. if($comment.hasClass('show-form'))
  259. {
  260. $comment.removeClass('show-form');
  261. return;
  262. }
  263. $comment.addClass('show-form').find('textarea').val($comment.find('.comment-content').text()).focus();
  264. }).on('click', '.commentEditCancel', function()
  265. {
  266. $(this).closest('.comment').removeClass('show-form');
  267. }).on('submit', '.comment-edit-form', function()
  268. {
  269. var $form = $(this);
  270. $form.ajaxSubmit(
  271. {
  272. success:function(html)
  273. {
  274. var $comment = $form.closest('.comment');
  275. $comment.find('.comment-content').html(html);
  276. $comment.removeClass('show-form');
  277. },
  278. beforeSubmit:function(formData, jqForm)
  279. {
  280. var form = jqForm[0];
  281. if(!form.commentText.value)
  282. {
  283. alert(contentError);
  284. return false;
  285. }
  286. }
  287. });
  288. return false;
  289. }).on('click', '.commentDelete', function()
  290. {
  291. var $container = $(this).closest('.commentContainer');
  292. if(!$container.length) return;
  293. if(confirm(confirmDeleteComment))
  294. {
  295. var commentID = $container.data('comment');
  296. var link = createLink('repo', 'deleteComment', 'commentID=' + commentID + '&confirm=yes');
  297. $.get(link, function(data)
  298. {
  299. if(data == 'deleted')
  300. {
  301. var $commentRow = $container.closest('.comment-row');
  302. if($commentRow.find('.bugContainer, .commentContainer').length === 1)
  303. {
  304. $commentRow.removeClass('show').prev('tr').removeClass('commented');
  305. }
  306. $container.remove();
  307. }
  308. });
  309. }
  310. return false;
  311. }).on('click', 'tr.commented', function()
  312. {
  313. toggleComment($(this));
  314. }).on('click', '.panel-bug > .panel-heading', function()
  315. {
  316. $(this).closest('.panel-bug').toggleClass('show');
  317. }).on('mouseenter', 'tr.commented td .preview-icon', function(e)
  318. {
  319. var $cell = $(this).closest('td');
  320. var $row = $cell.closest('tr');
  321. var $commentRow = $row.next('tr');
  322. var $bugs = $commentRow.find('.panel-bug'), line = '?';
  323. $bugsPreviewMenu.children('li:not(.dropdown-header)').remove();
  324. $bugsPreviewMenu.find('.bug-count').text($bugs.length);
  325. $bugsPreviewMenu.find('.comment-count').text($commentRow.find('.comment').length);
  326. $bugs.each(function()
  327. {
  328. var bug = $(this).data('data');
  329. line = bug.line;
  330. $bugsPreviewMenu.append('<li><a href="javascript:;" data-id="#bug-' + bug.id + '"><small class="text-muted">#' + bug.id + '</small> ' + bug.title + '</a></li>');
  331. });
  332. $bugsPreviewMenu.find('.code-line').text(line);
  333. $bugsPreview.prependTo($cell);
  334. clearTimeout(hidePreview);
  335. $bugsPreviewMenu.css({top: 0-$bugsPreviewMenu.outerHeight(), left: Math.max(0, e.offsetX-$bugsPreviewMenu.outerWidth())}).addClass('show');
  336. setTimeout(function(){$bugsPreviewMenu.addClass('in');}, 50);
  337. }).on('mouseleave', 'tr.commented td', function()
  338. {
  339. $bugsPreviewMenu.removeClass('in');
  340. hidePreview = setTimeout(function(){$bugsPreviewMenu.removeClass('show');}, 200);
  341. });
  342. $bugsPreviewMenu.on('click', 'li', function(e)
  343. {
  344. var $bug = $($(this).find('a').data('id'));
  345. if($bug.length)
  346. {
  347. $bug.addClass('show');
  348. toggleComment($bug.closest('tr.comment-row'), true);
  349. highlight($bug);
  350. $bugsPreviewMenu.removeClass('in');
  351. hidePreview = setTimeout(function(){$bugsPreviewMenu.removeClass('show');}, 200);
  352. }
  353. e.stopPropagation();
  354. });
  355. $bugForm.submit(function()
  356. {
  357. $(this).ajaxSubmit(
  358. {
  359. success:function(json)
  360. {
  361. json = $.parseJSON(json);
  362. if(json.result == 'fail')
  363. {
  364. alert(json.message);
  365. return false;
  366. }
  367. createBug(json, null, null, 3);
  368. $diffCode.removeClass('with-action-row');
  369. $diffCode.find('tr.with-action-row.selected').removeClass('selected');
  370. $bugForm.find('#title').val('');
  371. KindEditor.html('#commentText', '');
  372. },
  373. beforeSubmit:function(formData, jqForm)
  374. {
  375. var form = jqForm[0];
  376. if(!form.product.value)
  377. {
  378. alert(productError);
  379. return false;
  380. }
  381. if(!form.title.value)
  382. {
  383. alert(titleError);
  384. $bugForm.find('input[name="title"]').focus();
  385. return false;
  386. }
  387. }
  388. });
  389. return false;
  390. }).on('change', 'input[name="begin"]', function()
  391. {
  392. var begin = $(this).val();
  393. var $end = $bugForm.find('input[name="end"]').attr('min', begin);
  394. if(parseInt($end.val()) < parseInt(begin))
  395. {
  396. $end.val(begin);
  397. }
  398. });
  399. if(bugs)
  400. {
  401. var lineBugs, bugsCount, i;
  402. for(var line in bugs)
  403. {
  404. if(line)
  405. {
  406. lineBugs = bugs[line];
  407. bugsCount = lineBugs.length;
  408. for(i = 0; i < bugsCount; i++)
  409. {
  410. createBug(lineBugs[i], line);
  411. }
  412. }
  413. }
  414. }
  415. setTimeout(anchor, 200);
  416. $(document).on('click', function()
  417. {
  418. $('.highlight').removeClass('highlight');
  419. });
  420. $(document).mouseup(function(e)
  421. {
  422. var $box = $('#commit-box');
  423. if(!$box.is(e.target) && $box.has(e.target).length === 0)
  424. {
  425. $('#commit-box').remove();
  426. }
  427. });
  428. function anchor()
  429. {
  430. var hash = window.location.hash;
  431. if(hash)
  432. {
  433. var line = hash.substr(1).replace('L', '');
  434. var $row = $('.diff tr[data-line="' + line +'"]').first();
  435. if($row.length)
  436. {
  437. var anchor = $row.offset().top;
  438. $('body,html').animate({scrollTop:anchor - 50}, 500);
  439. $row.addClass('highlight');
  440. if($row.hasClass('commented'))
  441. {
  442. toggleComment($row, true);
  443. var $commentRow = $row.next('tr');
  444. if($commentRow.hasClass('comment-row'))
  445. {
  446. $commentRow.addClass('highlight');
  447. }
  448. }
  449. }
  450. }
  451. }
  452. /* Diff url locate. */
  453. $('.diffForm').click(function()
  454. {
  455. if($(this).hasClass('disabled')) return false;
  456. var oldRevision = $('#oldRevision').val();
  457. var newRevision = $('#newRevision').val();
  458. var isBranchOrTag = $('#isBranchOrTag').val();
  459. if(!oldRevision || !newRevision)
  460. {
  461. (repo.SCM != 'Subversion') ? alert(repoLang.error.needTwoVersion) : alert(repoLang.error.emptyVersion);
  462. return false;
  463. }
  464. if(repo.SCM == 'Subversion')
  465. {
  466. var intRe = /^\d+$/;
  467. if((intRe.test(oldRevision) == false && oldRevision != '^') || (intRe.test(newRevision) == false && newRevision != '^'))
  468. {
  469. alert(repoLang.error.versionError);
  470. return false;
  471. }
  472. }
  473. if(oldRevision == newRevision)
  474. {
  475. alert(repoLang.error.differentVersions);
  476. return false;
  477. }
  478. if(isBranchOrTag)
  479. {
  480. oldRevision = btoa(encodeURIComponent(oldRevision));
  481. newRevision = btoa(encodeURIComponent(newRevision));
  482. }
  483. var url = createLink('repo', 'diff', 'repoID=' + repoID + '&objectID=' + objectID + '&entry=&oldRevision=' + oldRevision + '&newRevision=' +newRevision + '&showBug=0&encoding=&isBranchOrTag=' + isBranchOrTag);
  484. window.location = url;
  485. });
  486. $(document).on('click', '.branch-or-tag', function()
  487. {
  488. $('.diffForm').removeClass('disabled');
  489. var isSource = $(this).hasClass('source');
  490. var version = $(this).text();
  491. if(isSource)
  492. {
  493. if($('#newRevision').val() == version) $('.diffForm').addClass('disabled');
  494. $('#sourceSwapper .version-name').text(version);
  495. $('#sourceSwapper .repo-select').attr('title', version);
  496. $('#oldRevision').val(version);
  497. $('#sourceSwapper .branch-or-tag').removeClass('selected');
  498. }
  499. else
  500. {
  501. if($('#oldRevision').val() == version) $('.diffForm').addClass('disabled');
  502. $('#targetSwapper .version-name').text(version);
  503. $('#targetSwapper .repo-select').attr('title', version);
  504. $('#newRevision').val(version);
  505. $('#targetSwapper .branch-or-tag').removeClass('selected');
  506. }
  507. $(this).addClass('selected');
  508. });
  509. $(document).on('input', '.svn-version', function()
  510. {
  511. $('.diffForm').removeClass('disabled');
  512. var oldRevision = $('#oldRevision').val();
  513. var newRevision = $('#newRevision').val();
  514. if(oldRevision == newRevision) $('.diffForm').addClass('disabled');
  515. });
  516. $(document).on('click', '.label-exchange-git', function()
  517. {
  518. var source = $('#oldRevision').val();
  519. var target = $('#newRevision').val();
  520. if(source && target)
  521. {
  522. $('#oldRevision').val(target);
  523. $('#newRevision').val(source);
  524. $('.diffForm').click();
  525. }
  526. })
  527. $('.file-name').click(function()
  528. {
  529. $(this).prev().click();
  530. });
  531. /** Fix English grammar errors. */
  532. if($(".add-cot").length > 0)
  533. {
  534. $('.add-cot').html($('.add-cot').html().replace('1 lines', '1 line'));
  535. $('.delete-cot').html($('.delete-cot').html().replace('1 lines', '1 line'));
  536. }
  537. /* Disable the enter event. */
  538. $(document).keydown(function(event)
  539. {
  540. if(event.keyCode == 13) return false;
  541. });
  542. /** Press enter to trigger version search. */
  543. $("#searchSource").keydown(function(event)
  544. {
  545. if(event.keyCode == 13)
  546. {
  547. var version = $(this).val();
  548. if(!version) return;
  549. $('#sourceSwapper .version-name').text(version);
  550. $('#sourceSwapper .repo-select').attr('title', version);
  551. $('#oldRevision').val(version);
  552. $('#sourceSwapper .branch-or-tag').removeClass('selected');
  553. }
  554. });
  555. $("#searchTarget").keydown(function(event)
  556. {
  557. if(event.keyCode == 13)
  558. {
  559. var version = $(this).val();
  560. if(!version) return;
  561. $('#targetSwapper .version-name').text(version);
  562. $('#targetSwapper .repo-select').attr('title', version);
  563. $('#newRevision').val(version);
  564. $('#targetSwapper .branch-or-tag').removeClass('selected');
  565. }
  566. });
  567. if(['Git', 'Gitlab', 'Gogs', 'Gitea'].indexOf(repo.SCM)) getBranchAndTag();
  568. });
  569. /**
  570. * Change encode.
  571. *
  572. * @param string $encoding
  573. * @access public
  574. * @return void
  575. */
  576. function changeEncoding(encoding)
  577. {
  578. $('#encoding').val(encoding);
  579. $('#encoding').parents('form').submit();
  580. }
  581. /**
  582. * Get branch and tag.
  583. *
  584. * @param int $repoID
  585. * @access public
  586. * @return void
  587. */
  588. function getBranchAndTag()
  589. {
  590. if(repoID)
  591. {
  592. var link = createLink('repo', 'ajaxGetBranchesAndTags', 'repoID=' + repoID + '&oldRevision=' + sourceRevision + '&newRevision=' + revision);
  593. $.get(link, function(data)
  594. {
  595. var result = $.parseJSON(data);
  596. $('#sourceList').empty();
  597. $('#targetList').empty();
  598. $('#sourceList').append(result.sourceHtml);
  599. $('#targetList').append(result.targetHtml);
  600. });
  601. }
  602. }
  603. /**
  604. * Expand and collapse code blocks.
  605. *
  606. * @param node icon
  607. * @access public
  608. * @return void
  609. */
  610. function diffToggle(icon)
  611. {
  612. if($(icon).hasClass('list-toggle-open'))
  613. {
  614. $(icon).removeClass('list-toggle-open');
  615. $(icon).parents('.table').find('tr').hide();
  616. $(icon).parents('.table').find('.comment-row').addClass('hideImportant');
  617. }
  618. else
  619. {
  620. $(icon).addClass('list-toggle-open');
  621. $(icon).parents('.table').find('tr').show();
  622. $(icon).parents('.table').find('.comment-row').removeClass('hideImportant');
  623. }
  624. }
  625. /**
  626. * Jump to file.
  627. *
  628. * @param int $fileKey
  629. * @param node $aNode
  630. * @access public
  631. * @return void
  632. */
  633. function jumpFile(fileKey, aNode)
  634. {
  635. $("#fileTree a").removeClass('selected');
  636. $(aNode).addClass('selected');
  637. $("#file" + fileKey).find('.list-toggle').click();
  638. }
  639. /**
  640. * Show commit info.
  641. *
  642. * @param node $row
  643. * @access public
  644. * @return void
  645. */
  646. function showCommitInfo(row)
  647. {
  648. var fileSrc = $(row).parent().parent().data('src');
  649. var line = $(row).parent().parent().data('line');
  650. var link = createLink('repo', 'ajaxGetCommitInfo');
  651. var data = {
  652. repoID : repoID,
  653. entry : fileSrc,
  654. revision : revision,
  655. sourceRevision: sourceRevision,
  656. line : line,
  657. };
  658. $.post(link, data, function(html)
  659. {
  660. $(row).parent().append(html);
  661. })
  662. }