common.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /**
  2. * Swtich repo.
  3. *
  4. * @param int $repoID
  5. * @param string $module
  6. * @param string $method
  7. * @access public
  8. * @return void
  9. */
  10. function switchRepo(repoID, module, method)
  11. {
  12. if(typeof(eventKeyCode) == 'undefined') eventKeyCode = 0;
  13. if(eventKeyCode > 0 && eventKeyCode != 13) return false;
  14. /* The project id is a string, use it as the project model. */
  15. if(isNaN(repoID))
  16. {
  17. $.cookie('projectMode', repoID, {expires:config.cookieLife, path:config.webRoot});
  18. repoID = 0;
  19. }
  20. if(method != 'settings') method ="browse";
  21. link = createLink(module, method, 'repoID=' + repoID);
  22. location.href=link;
  23. }
  24. /**
  25. * Switch branch for git.
  26. *
  27. * @param string $branchID
  28. * @access public
  29. * @return void
  30. */
  31. function switchBranch(branchID)
  32. {
  33. $.cookie('repoBranch', branchID, {expires:config.cookieLife, path:config.webRoot});
  34. $.cookie('repoRefresh', 1, {expires:config.cookieLife, path:config.webRoot});
  35. location.href=location.href;
  36. }
  37. /**
  38. * Limit select two.
  39. * @return void
  40. */
  41. if($("input:checkbox[name='revision[]']:checked").length < 2)
  42. {
  43. $("input:checkbox[name='revision[]']:lt(2)").attr('checked', 'checked');
  44. }
  45. $("input:checkbox[name='revision[]']").each(function(){ if(!$(this).is(':checked')) $(this).attr("disabled","disabled")});
  46. $("input:checkbox[name='revision[]']").click(function(){
  47. var checkNum = $("input:checkbox[name='revision[]']:checked").length;
  48. if (checkNum >= 2)
  49. {
  50. $("input:checkbox[name='revision[]']").each(function(){ if(!$(this).is(':checked')) $(this).attr("disabled","disabled")});
  51. $('#submit').removeAttr('disabled');
  52. }
  53. else
  54. {
  55. $("input:checkbox[name='revision[]']").each(function(){$(this).attr("disabled", false)});
  56. $('#submit').attr('disabled', 'disabled');
  57. }
  58. });
  59. var distance = 0;
  60. /**
  61. * Aarrow tabs area.
  62. *
  63. * @param string domID
  64. * @param number shift 1|-1
  65. * @param bool hideRightBtn
  66. * @access public
  67. * @return void
  68. */
  69. function arrowTabs(domID, shift, hideRightBtn)
  70. {
  71. if($('#' + domID).html() == '') return;
  72. var hasParent = $('#' + domID + ' .btn-left').length;
  73. var $leftBtn = hasParent ? $('#' + domID + ' .btn-left') : $('.btn-left');
  74. var $rightBtn = hasParent ? $('#' + domID + ' .btn-right') : $('.btn-right');
  75. $leftBtn.show();
  76. $rightBtn.show();
  77. if(hideRightBtn) $rightBtn.hide();
  78. var tabItemWidth = $('#' + domID + ' > .tabs-navbar > .nav-tabs')[0].clientWidth;
  79. var tabsWidth = $('#' + domID)[0].clientWidth;
  80. if($('#' + domID + ' .close-bugs').length) tabsWidth = tabsWidth * 0.7;
  81. if(tabItemWidth < tabsWidth)
  82. {
  83. $leftBtn.hide();
  84. $rightBtn.hide();
  85. return;
  86. }
  87. distance += tabsWidth * shift * 0.2;
  88. if(distance > 0) distance = 0;
  89. if(distance == 0)
  90. {
  91. $leftBtn.hide();
  92. }
  93. if((tabItemWidth + distance) < tabsWidth * 0.75)
  94. {
  95. $rightBtn.hide();
  96. return arrowTabs(domID, 1, true);
  97. }
  98. $('#' + domID + ' > .tabs-navbar > .nav-tabs')[0].style.transform = 'translateX('+ distance +'px)';
  99. }
  100. /**
  101. * Close commit relations.
  102. *
  103. * @access public
  104. * @return void
  105. */
  106. function closeRelation()
  107. {
  108. $tabs = $('#relationTabs').data('zui.tabs');
  109. if($tabs) $tabs.closeAll();
  110. $('.history').html('');
  111. $('#log').data('line', 0);
  112. $('#log').hide();
  113. $('#codeContainer').css('height', codeHeight);
  114. $('#related').css('height', 0);
  115. };
  116. $(function()
  117. {
  118. $(document).on('click', '.ajaxPager', function()
  119. {
  120. $('#sidebar .side-body').load($(this).attr('data-href'));
  121. return false;
  122. }).on('click', '#log .btn-close', closeRelation);
  123. if($("main").is(".hide-sidebar"))
  124. {
  125. $(".sidebar-toggle").children().attr("class", "icon icon-angle-left");
  126. }
  127. else
  128. {
  129. $("#sidebar").bind("click", function ()
  130. {
  131. $(".sidebar-toggle").children().attr("class", "icon icon-angle-left");
  132. $(this).unbind();
  133. });
  134. }
  135. })