You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096
  1. 'use strict';
  2. var csrf;
  3. var suburl;
  4. function initCommentPreviewTab($form) {
  5. var $tabMenu = $form.find('.tabular.menu');
  6. $tabMenu.find('.item').tab();
  7. $tabMenu.find('.item[data-tab="' + $tabMenu.data('preview') + '"]').click(function () {
  8. var $this = $(this);
  9. $.post($this.data('url'), {
  10. "_csrf": csrf,
  11. "mode": "gfm",
  12. "context": $this.data('context'),
  13. "text": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
  14. },
  15. function (data) {
  16. var $previewPanel = $form.find('.tab.segment[data-tab="' + $tabMenu.data('preview') + '"]');
  17. $previewPanel.html(data);
  18. emojify.run($previewPanel[0]);
  19. $('pre code', $previewPanel[0]).each(function (i, block) {
  20. hljs.highlightBlock(block);
  21. });
  22. }
  23. );
  24. });
  25. buttonsClickOnEnter();
  26. }
  27. var previewFileModes;
  28. function initEditPreviewTab($form) {
  29. var $tabMenu = $form.find('.tabular.menu');
  30. $tabMenu.find('.item').tab();
  31. var $previewTab = $tabMenu.find('.item[data-tab="' + $tabMenu.data('preview') + '"]');
  32. if ($previewTab.length) {
  33. previewFileModes = $previewTab.data('preview-file-modes').split(',');
  34. $previewTab.click(function () {
  35. var $this = $(this);
  36. $.post($this.data('url'), {
  37. "_csrf": csrf,
  38. "mode": "gfm",
  39. "context": $this.data('context'),
  40. "text": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
  41. },
  42. function (data) {
  43. var $previewPanel = $form.find('.tab.segment[data-tab="' + $tabMenu.data('preview') + '"]');
  44. $previewPanel.html(data);
  45. emojify.run($previewPanel[0]);
  46. $('pre code', $previewPanel[0]).each(function (i, block) {
  47. hljs.highlightBlock(block);
  48. });
  49. }
  50. );
  51. });
  52. }
  53. }
  54. function initEditDiffTab($form) {
  55. var $tabMenu = $form.find('.tabular.menu');
  56. $tabMenu.find('.item').tab();
  57. $tabMenu.find('.item[data-tab="' + $tabMenu.data('diff') + '"]').click(function () {
  58. var $this = $(this);
  59. $.post($this.data('url'), {
  60. "_csrf": csrf,
  61. "context": $this.data('context'),
  62. "content": $form.find('.tab.segment[data-tab="' + $tabMenu.data('write') + '"] textarea').val()
  63. },
  64. function (data) {
  65. var $diffPreviewPanel = $form.find('.tab.segment[data-tab="' + $tabMenu.data('diff') + '"]');
  66. $diffPreviewPanel.html(data);
  67. emojify.run($diffPreviewPanel[0]);
  68. }
  69. );
  70. });
  71. }
  72. function initEditForm() {
  73. if ($('.edit.form').length == 0) {
  74. return;
  75. }
  76. initEditPreviewTab($('.edit.form'));
  77. initEditDiffTab($('.edit.form'));
  78. }
  79. function initBranchSelector() {
  80. var $selectBranch = $('.ui.select-branch')
  81. var $branchMenu = $selectBranch.find('.reference-list-menu');
  82. $branchMenu.find('.item:not(.no-select)').click(function () {
  83. var selectedValue = $(this).data('id');
  84. $($(this).data('id-selector')).val(selectedValue);
  85. $selectBranch.find('.ui .branch-name').text(selectedValue);
  86. });
  87. $selectBranch.find('.reference.column').click(function () {
  88. $selectBranch.find('.scrolling.reference-list-menu').css('display', 'none');
  89. $selectBranch.find('.reference .text').removeClass('black');
  90. $($(this).data('target')).css('display', 'block');
  91. $(this).find('.text').addClass('black');
  92. return false;
  93. });
  94. }
  95. function updateIssuesMeta(url, action, issueIds, elementId, afterSuccess) {
  96. $.ajax({
  97. type: "POST",
  98. url: url,
  99. data: {
  100. "_csrf": csrf,
  101. "action": action,
  102. "issue_ids": issueIds,
  103. "id": elementId
  104. },
  105. success: afterSuccess
  106. })
  107. }
  108. function initReactionSelector(parent) {
  109. var reactions = '';
  110. if (!parent) {
  111. parent = $(document);
  112. reactions = '.reactions > ';
  113. }
  114. parent.find(reactions + 'a.label').popup({'position': 'bottom left', 'metadata': {'content': 'title', 'title': 'none'}});
  115. parent.find('.select-reaction > .menu > .item, ' + reactions + 'a.label').on('click', function(e){
  116. var vm = this;
  117. e.preventDefault();
  118. if ($(this).hasClass('disabled')) return;
  119. var actionURL = $(this).hasClass('item') ?
  120. $(this).closest('.select-reaction').data('action-url') :
  121. $(this).data('action-url');
  122. var url = actionURL + '/' + ($(this).hasClass('blue') ? 'unreact' : 'react');
  123. $.ajax({
  124. type: 'POST',
  125. url: url,
  126. data: {
  127. '_csrf': csrf,
  128. 'content': $(this).data('content')
  129. }
  130. }).done(function(resp) {
  131. if (resp && (resp.html || resp.empty)) {
  132. var content = $(vm).closest('.content');
  133. var react = content.find('.segment.reactions');
  134. if (react.length > 0) {
  135. react.remove();
  136. }
  137. if (!resp.empty) {
  138. react = $('<div class="ui attached segment reactions"></div>');
  139. var attachments = content.find('.segment.bottom:first');
  140. if (attachments.length > 0) {
  141. react.insertBefore(attachments);
  142. } else {
  143. react.appendTo(content);
  144. }
  145. react.html(resp.html);
  146. var hasEmoji = react.find('.has-emoji');
  147. for (var i = 0; i < hasEmoji.length; i++) {
  148. emojify.run(hasEmoji.get(i));
  149. }
  150. react.find('.dropdown').dropdown();
  151. initReactionSelector(react);
  152. }
  153. }
  154. });
  155. });
  156. }
  157. function initCommentForm() {
  158. if ($('.comment.form').length == 0) {
  159. return
  160. }
  161. initBranchSelector();
  162. initCommentPreviewTab($('.comment.form'));
  163. // Labels
  164. var $list = $('.ui.labels.list');
  165. var $noSelect = $list.find('.no-select');
  166. var $labelMenu = $('.select-label .menu');
  167. var hasLabelUpdateAction = $labelMenu.data('action') == 'update';
  168. $('.select-label').dropdown('setting', 'onHide', function(){
  169. if (hasLabelUpdateAction) {
  170. location.reload();
  171. }
  172. });
  173. $labelMenu.find('.item:not(.no-select)').click(function () {
  174. if ($(this).hasClass('checked')) {
  175. $(this).removeClass('checked');
  176. $(this).find('.octicon').removeClass('octicon-check');
  177. if (hasLabelUpdateAction) {
  178. updateIssuesMeta(
  179. $labelMenu.data('update-url'),
  180. "detach",
  181. $labelMenu.data('issue-id'),
  182. $(this).data('id')
  183. );
  184. }
  185. } else {
  186. $(this).addClass('checked');
  187. $(this).find('.octicon').addClass('octicon-check');
  188. if (hasLabelUpdateAction) {
  189. updateIssuesMeta(
  190. $labelMenu.data('update-url'),
  191. "attach",
  192. $labelMenu.data('issue-id'),
  193. $(this).data('id')
  194. );
  195. }
  196. }
  197. var labelIds = [];
  198. $(this).parent().find('.item').each(function () {
  199. if ($(this).hasClass('checked')) {
  200. labelIds.push($(this).data('id'));
  201. $($(this).data('id-selector')).removeClass('hide');
  202. } else {
  203. $($(this).data('id-selector')).addClass('hide');
  204. }
  205. });
  206. if (labelIds.length == 0) {
  207. $noSelect.removeClass('hide');
  208. } else {
  209. $noSelect.addClass('hide');
  210. }
  211. $($(this).parent().data('id')).val(labelIds.join(","));
  212. return false;
  213. });
  214. $labelMenu.find('.no-select.item').click(function () {
  215. if (hasLabelUpdateAction) {
  216. updateIssuesMeta(
  217. $labelMenu.data('update-url'),
  218. "clear",
  219. $labelMenu.data('issue-id'),
  220. ""
  221. );
  222. }
  223. $(this).parent().find('.item').each(function () {
  224. $(this).removeClass('checked');
  225. $(this).find('.octicon').removeClass('octicon-check');
  226. });
  227. $list.find('.item').each(function () {
  228. $(this).addClass('hide');
  229. });
  230. $noSelect.removeClass('hide');
  231. $($(this).parent().data('id')).val('');
  232. });
  233. function selectItem(select_id, input_id) {
  234. var $menu = $(select_id + ' .menu');
  235. var $list = $('.ui' + select_id + '.list');
  236. var hasUpdateAction = $menu.data('action') == 'update';
  237. $menu.find('.item:not(.no-select)').click(function () {
  238. $(this).parent().find('.item').each(function () {
  239. $(this).removeClass('selected active')
  240. });
  241. $(this).addClass('selected active');
  242. if (hasUpdateAction) {
  243. updateIssuesMeta(
  244. $menu.data('update-url'),
  245. "",
  246. $menu.data('issue-id'),
  247. $(this).data('id'),
  248. function() { location.reload(); }
  249. );
  250. }
  251. switch (input_id) {
  252. case '#milestone_id':
  253. $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
  254. $(this).text() + '</a>');
  255. break;
  256. case '#assignee_id':
  257. $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
  258. '<img class="ui avatar image" src=' + $(this).data('avatar') + '>' +
  259. $(this).text() + '</a>');
  260. }
  261. $('.ui' + select_id + '.list .no-select').addClass('hide');
  262. $(input_id).val($(this).data('id'));
  263. });
  264. $menu.find('.no-select.item').click(function () {
  265. $(this).parent().find('.item:not(.no-select)').each(function () {
  266. $(this).removeClass('selected active')
  267. });
  268. if (hasUpdateAction) {
  269. updateIssuesMeta(
  270. $menu.data('update-url'),
  271. "",
  272. $menu.data('issue-id'),
  273. $(this).data('id'),
  274. function() { location.reload(); }
  275. );
  276. }
  277. $list.find('.selected').html('');
  278. $list.find('.no-select').removeClass('hide');
  279. $(input_id).val('');
  280. });
  281. }
  282. // Milestone and assignee
  283. selectItem('.select-milestone', '#milestone_id');
  284. selectItem('.select-assignee', '#assignee_id');
  285. }
  286. function initInstall() {
  287. if ($('.install').length == 0) {
  288. return;
  289. }
  290. if ($('#db_host').val()=="") {
  291. $('#db_host').val("127.0.0.1:3306");
  292. $('#db_user').val("gitea");
  293. $('#db_name').val("gitea");
  294. }
  295. // Database type change detection.
  296. $("#db_type").change(function () {
  297. var sqliteDefault = 'data/gitea.db';
  298. var tidbDefault = 'data/gitea_tidb';
  299. var dbType = $(this).val();
  300. if (dbType === "SQLite3" || dbType === "TiDB") {
  301. $('#sql_settings').hide();
  302. $('#pgsql_settings').hide();
  303. $('#sqlite_settings').show();
  304. if (dbType === "SQLite3" && $('#db_path').val() == tidbDefault) {
  305. $('#db_path').val(sqliteDefault);
  306. } else if (dbType === "TiDB" && $('#db_path').val() == sqliteDefault) {
  307. $('#db_path').val(tidbDefault);
  308. }
  309. return;
  310. }
  311. var dbDefaults = {
  312. "MySQL": "127.0.0.1:3306",
  313. "PostgreSQL": "127.0.0.1:5432",
  314. "MSSQL": "127.0.0.1:1433"
  315. };
  316. $('#sqlite_settings').hide();
  317. $('#sql_settings').show();
  318. $('#pgsql_settings').toggle(dbType === "PostgreSQL");
  319. $.each(dbDefaults, function(type, defaultHost) {
  320. if ($('#db_host').val() == defaultHost) {
  321. $('#db_host').val(dbDefaults[dbType]);
  322. return false;
  323. }
  324. });
  325. });
  326. // TODO: better handling of exclusive relations.
  327. $('#offline-mode input').change(function () {
  328. if ($(this).is(':checked')) {
  329. $('#disable-gravatar').checkbox('check');
  330. $('#federated-avatar-lookup').checkbox('uncheck');
  331. }
  332. });
  333. $('#disable-gravatar input').change(function () {
  334. if ($(this).is(':checked')) {
  335. $('#federated-avatar-lookup').checkbox('uncheck');
  336. } else {
  337. $('#offline-mode').checkbox('uncheck');
  338. }
  339. });
  340. $('#federated-avatar-lookup input').change(function () {
  341. if ($(this).is(':checked')) {
  342. $('#disable-gravatar').checkbox('uncheck');
  343. $('#offline-mode').checkbox('uncheck');
  344. }
  345. });
  346. $('#enable-openid-signin input').change(function () {
  347. if ($(this).is(':checked')) {
  348. if ( $('#disable-registration input').is(':checked') ) {
  349. } else {
  350. $('#enable-openid-signup').checkbox('check');
  351. }
  352. } else {
  353. $('#enable-openid-signup').checkbox('uncheck');
  354. }
  355. });
  356. $('#disable-registration input').change(function () {
  357. if ($(this).is(':checked')) {
  358. $('#enable-captcha').checkbox('uncheck');
  359. $('#enable-openid-signup').checkbox('uncheck');
  360. } else {
  361. $('#enable-openid-signup').checkbox('check');
  362. }
  363. });
  364. $('#enable-captcha input').change(function () {
  365. if ($(this).is(':checked')) {
  366. $('#disable-registration').checkbox('uncheck');
  367. }
  368. });
  369. }
  370. function initRepository() {
  371. if ($('.repository').length == 0) {
  372. return;
  373. }
  374. function initFilterSearchDropdown(selector) {
  375. var $dropdown = $(selector);
  376. $dropdown.dropdown({
  377. fullTextSearch: true,
  378. selectOnKeydown: false,
  379. onChange: function (text, value, $choice) {
  380. if ($choice.data('url')) {
  381. window.location.href = $choice.data('url');
  382. }
  383. },
  384. message: {noResults: $dropdown.data('no-results')}
  385. });
  386. }
  387. // File list and commits
  388. if ($('.repository.file.list').length > 0 ||
  389. ('.repository.commits').length > 0) {
  390. initFilterBranchTagDropdown('.choose.reference .dropdown');
  391. }
  392. // Wiki
  393. if ($('.repository.wiki.view').length > 0) {
  394. initFilterSearchDropdown('.choose.page .dropdown');
  395. }
  396. // Options
  397. if ($('.repository.settings.options').length > 0) {
  398. $('#repo_name').keyup(function () {
  399. var $prompt = $('#repo-name-change-prompt');
  400. if ($(this).val().toString().toLowerCase() != $(this).data('repo-name').toString().toLowerCase()) {
  401. $prompt.show();
  402. } else {
  403. $prompt.hide();
  404. }
  405. });
  406. // Enable or select internal/external wiki system and issue tracker.
  407. $('.enable-system').change(function () {
  408. if (this.checked) {
  409. $($(this).data('target')).removeClass('disabled');
  410. if (!$(this).data('context')) $($(this).data('context')).addClass('disabled');
  411. } else {
  412. $($(this).data('target')).addClass('disabled');
  413. if (!$(this).data('context')) $($(this).data('context')).removeClass('disabled');
  414. }
  415. });
  416. $('.enable-system-radio').change(function () {
  417. if (this.value == 'false') {
  418. $($(this).data('target')).addClass('disabled');
  419. if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).removeClass('disabled');
  420. } else if (this.value == 'true') {
  421. $($(this).data('target')).removeClass('disabled');
  422. if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).addClass('disabled');
  423. }
  424. });
  425. }
  426. // Labels
  427. if ($('.repository.labels').length > 0) {
  428. // Create label
  429. var $newLabelPanel = $('.new-label.segment');
  430. $('.new-label.button').click(function () {
  431. $newLabelPanel.show();
  432. });
  433. $('.new-label.segment .cancel').click(function () {
  434. $newLabelPanel.hide();
  435. });
  436. $('.color-picker').each(function () {
  437. $(this).minicolors();
  438. });
  439. $('.precolors .color').click(function () {
  440. var color_hex = $(this).data('color-hex');
  441. $('.color-picker').val(color_hex);
  442. $('.minicolors-swatch-color').css("background-color", color_hex);
  443. });
  444. $('.edit-label-button').click(function () {
  445. $('#label-modal-id').val($(this).data('id'));
  446. $('.edit-label .new-label-input').val($(this).data('title'));
  447. $('.edit-label .color-picker').val($(this).data('color'));
  448. $('.minicolors-swatch-color').css("background-color", $(this).data('color'));
  449. $('.edit-label.modal').modal({
  450. onApprove: function () {
  451. $('.edit-label.form').submit();
  452. }
  453. }).modal('show');
  454. return false;
  455. });
  456. }
  457. // Milestones
  458. if ($('.repository.milestones').length > 0) {
  459. }
  460. if ($('.repository.new.milestone').length > 0) {
  461. var $datepicker = $('.milestone.datepicker');
  462. $datepicker.datetimepicker({
  463. lang: $datepicker.data('lang'),
  464. inline: true,
  465. timepicker: false,
  466. startDate: $datepicker.data('start-date'),
  467. formatDate: 'Y-m-d',
  468. onSelectDate: function (ct) {
  469. $('#deadline').val(ct.dateFormat('Y-m-d'));
  470. }
  471. });
  472. $('#clear-date').click(function () {
  473. $('#deadline').val('');
  474. return false;
  475. });
  476. }
  477. // Issues
  478. if ($('.repository.view.issue').length > 0) {
  479. // Edit issue title
  480. var $issueTitle = $('#issue-title');
  481. var $editInput = $('#edit-title-input input');
  482. var editTitleToggle = function () {
  483. $issueTitle.toggle();
  484. $('.not-in-edit').toggle();
  485. $('#edit-title-input').toggle();
  486. $('.in-edit').toggle();
  487. $editInput.focus();
  488. return false;
  489. };
  490. $('#edit-title').click(editTitleToggle);
  491. $('#cancel-edit-title').click(editTitleToggle);
  492. $('#save-edit-title').click(editTitleToggle).click(function () {
  493. if ($editInput.val().length == 0 ||
  494. $editInput.val() == $issueTitle.text()) {
  495. $editInput.val($issueTitle.text());
  496. return false;
  497. }
  498. $.post($(this).data('update-url'), {
  499. "_csrf": csrf,
  500. "title": $editInput.val()
  501. },
  502. function (data) {
  503. $editInput.val(data.title);
  504. $issueTitle.text(data.title);
  505. location.reload();
  506. });
  507. return false;
  508. });
  509. // Edit issue or comment content
  510. $('.edit-content').click(function () {
  511. var $segment = $(this).parent().parent().parent().next();
  512. var $editContentZone = $segment.find('.edit-content-zone');
  513. var $renderContent = $segment.find('.render-content');
  514. var $rawContent = $segment.find('.raw-content');
  515. var $textarea;
  516. // Setup new form
  517. if ($editContentZone.html().length == 0) {
  518. $editContentZone.html($('#edit-content-form').html());
  519. $textarea = $segment.find('textarea');
  520. issuesTribute.attach($textarea.get());
  521. // Give new write/preview data-tab name to distinguish from others
  522. var $editContentForm = $editContentZone.find('.ui.comment.form');
  523. var $tabMenu = $editContentForm.find('.tabular.menu');
  524. $tabMenu.attr('data-write', $editContentZone.data('write'));
  525. $tabMenu.attr('data-preview', $editContentZone.data('preview'));
  526. $tabMenu.find('.write.item').attr('data-tab', $editContentZone.data('write'));
  527. $tabMenu.find('.preview.item').attr('data-tab', $editContentZone.data('preview'));
  528. $editContentForm.find('.write.segment').attr('data-tab', $editContentZone.data('write'));
  529. $editContentForm.find('.preview.segment').attr('data-tab', $editContentZone.data('preview'));
  530. initCommentPreviewTab($editContentForm);
  531. $editContentZone.find('.cancel.button').click(function () {
  532. $renderContent.show();
  533. $editContentZone.hide();
  534. });
  535. $editContentZone.find('.save.button').click(function () {
  536. $renderContent.show();
  537. $editContentZone.hide();
  538. $.post($editContentZone.data('update-url'), {
  539. "_csrf": csrf,
  540. "content": $textarea.val(),
  541. "context": $editContentZone.data('context')
  542. },
  543. function (data) {
  544. if (data.length == 0) {
  545. $renderContent.html($('#no-content').html());
  546. } else {
  547. $renderContent.html(data.content);
  548. emojify.run($renderContent[0]);
  549. $('pre code', $renderContent[0]).each(function (i, block) {
  550. hljs.highlightBlock(block);
  551. });
  552. }
  553. });
  554. });
  555. } else {
  556. $textarea = $segment.find('textarea');
  557. }
  558. // Show write/preview tab and copy raw content as needed
  559. $editContentZone.show();
  560. $renderContent.hide();
  561. if ($textarea.val().length == 0) {
  562. $textarea.val($rawContent.text());
  563. }
  564. $textarea.focus();
  565. return false;
  566. });
  567. // Delete comment
  568. $('.delete-comment').click(function () {
  569. var $this = $(this);
  570. if (confirm($this.data('locale'))) {
  571. $.post($this.data('url'), {
  572. "_csrf": csrf
  573. }).success(function () {
  574. $('#' + $this.data('comment-id')).remove();
  575. });
  576. }
  577. return false;
  578. });
  579. // Change status
  580. var $statusButton = $('#status-button');
  581. $('#comment-form .edit_area').keyup(function () {
  582. if ($(this).val().length == 0) {
  583. $statusButton.text($statusButton.data('status'))
  584. } else {
  585. $statusButton.text($statusButton.data('status-and-comment'))
  586. }
  587. });
  588. $statusButton.click(function () {
  589. $('#status').val($statusButton.data('status-val'));
  590. $('#comment-form').submit();
  591. });
  592. initReactionSelector();
  593. }
  594. // Diff
  595. if ($('.repository.diff').length > 0) {
  596. var $counter = $('.diff-counter');
  597. if ($counter.length >= 1) {
  598. $counter.each(function (i, item) {
  599. var $item = $(item);
  600. var addLine = $item.find('span[data-line].add').data("line");
  601. var delLine = $item.find('span[data-line].del').data("line");
  602. var addPercent = parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine)) * 100;
  603. $item.find(".bar .add").css("width", addPercent + "%");
  604. });
  605. }
  606. }
  607. // Quick start and repository home
  608. $('#repo-clone-ssh').click(function () {
  609. $('.clone-url').text($(this).data('link'));
  610. $('#repo-clone-url').val($(this).data('link'));
  611. $(this).addClass('blue');
  612. $('#repo-clone-https').removeClass('blue');
  613. localStorage.setItem('repo-clone-protocol', 'ssh');
  614. });
  615. $('#repo-clone-https').click(function () {
  616. $('.clone-url').text($(this).data('link'));
  617. $('#repo-clone-url').val($(this).data('link'));
  618. $(this).addClass('blue');
  619. $('#repo-clone-ssh').removeClass('blue');
  620. localStorage.setItem('repo-clone-protocol', 'https');
  621. });
  622. $('#repo-clone-url').click(function () {
  623. $(this).select();
  624. });
  625. // Pull request
  626. if ($('.repository.compare.pull').length > 0) {
  627. initFilterSearchDropdown('.choose.branch .dropdown');
  628. }
  629. // Branches
  630. if ($('.repository.settings.branches').length > 0) {
  631. initFilterSearchDropdown('.protected-branches .dropdown');
  632. $('.enable-protection, .enable-whitelist').change(function () {
  633. if (this.checked) {
  634. $($(this).data('target')).removeClass('disabled');
  635. } else {
  636. $($(this).data('target')).addClass('disabled');
  637. }
  638. });
  639. }
  640. }
  641. function initRepositoryCollaboration() {
  642. console.log('initRepositoryCollaboration');
  643. // Change collaborator access mode
  644. $('.access-mode.menu .item').click(function () {
  645. var $menu = $(this).parent();
  646. $.post($menu.data('url'), {
  647. "_csrf": csrf,
  648. "uid": $menu.data('uid'),
  649. "mode": $(this).data('value')
  650. })
  651. });
  652. }
  653. function initTeamSettings() {
  654. // Change team access mode
  655. $('.organization.new.team input[name=permission]').change(function () {
  656. var val = $('input[name=permission]:checked', '.organization.new.team').val()
  657. if (val === 'admin') {
  658. $('.organization.new.team .team-units').hide();
  659. } else {
  660. $('.organization.new.team .team-units').show();
  661. }
  662. });
  663. }
  664. function initWikiForm() {
  665. var $editArea = $('.repository.wiki textarea#edit_area');
  666. if ($editArea.length > 0) {
  667. new SimpleMDE({
  668. autoDownloadFontAwesome: false,
  669. element: $editArea[0],
  670. forceSync: true,
  671. previewRender: function (plainText, preview) { // Async method
  672. setTimeout(function () {
  673. // FIXME: still send render request when return back to edit mode
  674. $.post($editArea.data('url'), {
  675. "_csrf": csrf,
  676. "mode": "gfm",
  677. "context": $editArea.data('context'),
  678. "text": plainText
  679. },
  680. function (data) {
  681. preview.innerHTML = '<div class="markdown">' + data + '</div>';
  682. emojify.run($('.editor-preview')[0]);
  683. $('.editor-preview').autolink();
  684. }
  685. );
  686. }, 0);
  687. return "Loading...";
  688. },
  689. renderingConfig: {
  690. singleLineBreaks: false
  691. },
  692. indentWithTabs: false,
  693. tabSize: 4,
  694. spellChecker: false,
  695. toolbar: ["bold", "italic", "strikethrough", "|",
  696. "heading-1", "heading-2", "heading-3", "heading-bigger", "heading-smaller", "|",
  697. "code", "quote", "|",
  698. "unordered-list", "ordered-list", "|",
  699. "link", "image", "table", "horizontal-rule", "|",
  700. "clean-block", "preview", "fullscreen"]
  701. })
  702. }
  703. }
  704. var simpleMDEditor;
  705. var codeMirrorEditor;
  706. // For IE
  707. String.prototype.endsWith = function (pattern) {
  708. var d = this.length - pattern.length;
  709. return d >= 0 && this.lastIndexOf(pattern) === d;
  710. };
  711. // Adding function to get the cursor position in a text field to jQuery object.
  712. (function ($, undefined) {
  713. $.fn.getCursorPosition = function () {
  714. var el = $(this).get(0);
  715. var pos = 0;
  716. if ('selectionStart' in el) {
  717. pos = el.selectionStart;
  718. } else if ('selection' in document) {
  719. el.focus();
  720. var Sel = document.selection.createRange();
  721. var SelLength = document.selection.createRange().text.length;
  722. Sel.moveStart('character', -el.value.length);
  723. pos = Sel.text.length - SelLength;
  724. }
  725. return pos;
  726. }
  727. })(jQuery);
  728. function setSimpleMDE($editArea) {
  729. if (codeMirrorEditor) {
  730. codeMirrorEditor.toTextArea();
  731. codeMirrorEditor = null;
  732. }
  733. if (simpleMDEditor) {
  734. return true;
  735. }
  736. simpleMDEditor = new SimpleMDE({
  737. autoDownloadFontAwesome: false,
  738. element: $editArea[0],
  739. forceSync: true,
  740. renderingConfig: {
  741. singleLineBreaks: false
  742. },
  743. indentWithTabs: false,
  744. tabSize: 4,
  745. spellChecker: false,
  746. previewRender: function (plainText, preview) { // Async method
  747. setTimeout(function () {
  748. // FIXME: still send render request when return back to edit mode
  749. $.post($editArea.data('url'), {
  750. "_csrf": csrf,
  751. "mode": "gfm",
  752. "context": $editArea.data('context'),
  753. "text": plainText
  754. },
  755. function (data) {
  756. preview.innerHTML = '<div class="markdown">' + data + '</div>';
  757. emojify.run($('.editor-preview')[0]);
  758. }
  759. );
  760. }, 0);
  761. return "Loading...";
  762. },
  763. toolbar: ["bold", "italic", "strikethrough", "|",
  764. "heading-1", "heading-2", "heading-3", "heading-bigger", "heading-smaller", "|",
  765. "code", "quote", "|",
  766. "unordered-list", "ordered-list", "|",
  767. "link", "image", "table", "horizontal-rule", "|",
  768. "clean-block", "preview", "fullscreen", "side-by-side"]
  769. });
  770. return true;
  771. }
  772. function setCodeMirror($editArea) {
  773. if (simpleMDEditor) {
  774. simpleMDEditor.toTextArea();
  775. simpleMDEditor = null;
  776. }
  777. if (codeMirrorEditor) {
  778. return true;
  779. }
  780. codeMirrorEditor = CodeMirror.fromTextArea($editArea[0], {
  781. lineNumbers: true
  782. });
  783. codeMirrorEditor.on("change", function (cm, change) {
  784. $editArea.val(cm.getValue());
  785. });
  786. return true;
  787. }
  788. function initEditor() {
  789. $('.js-quick-pull-choice-option').change(function () {
  790. if ($(this).val() == 'commit-to-new-branch') {
  791. $('.quick-pull-branch-name').show();
  792. $('.quick-pull-branch-name input').prop('required',true);
  793. } else {
  794. $('.quick-pull-branch-name').hide();
  795. $('.quick-pull-branch-name input').prop('required',false);
  796. }
  797. });
  798. var $editFilename = $("#file-name");
  799. $editFilename.keyup(function (e) {
  800. var $section = $('.breadcrumb span.section');
  801. var $divider = $('.breadcrumb div.divider');
  802. if (e.keyCode == 8) {
  803. if ($(this).getCursorPosition() == 0) {
  804. if ($section.length > 0) {
  805. var value = $section.last().find('a').text();
  806. $(this).val(value + $(this).val());
  807. $(this)[0].setSelectionRange(value.length, value.length);
  808. $section.last().remove();
  809. $divider.last().remove();
  810. }
  811. }
  812. }
  813. if (e.keyCode == 191) {
  814. var parts = $(this).val().split('/');
  815. for (var i = 0; i < parts.length; ++i) {
  816. var value = parts[i];
  817. if (i < parts.length - 1) {
  818. if (value.length) {
  819. $('<span class="section"><a href="#">' + value + '</a></span>').insertBefore($(this));
  820. $('<div class="divider"> / </div>').insertBefore($(this));
  821. }
  822. }
  823. else {
  824. $(this).val(value);
  825. }
  826. $(this)[0].setSelectionRange(0, 0);
  827. }
  828. }
  829. var parts = [];
  830. $('.breadcrumb span.section').each(function (i, element) {
  831. element = $(element);
  832. if (element.find('a').length) {
  833. parts.push(element.find('a').text());
  834. } else {
  835. parts.push(element.text());
  836. }
  837. });
  838. if ($(this).val())
  839. parts.push($(this).val());
  840. $('#tree_path').val(parts.join('/'));
  841. }).trigger('keyup');
  842. var $editArea = $('.repository.editor textarea#edit_area');
  843. if (!$editArea.length)
  844. return;
  845. var markdownFileExts = $editArea.data("markdown-file-exts").split(",");
  846. var lineWrapExtensions = $editArea.data("line-wrap-extensions").split(",");
  847. $editFilename.on("keyup", function (e) {
  848. var val = $editFilename.val(), m, mode, spec, extension, extWithDot, previewLink, dataUrl, apiCall;
  849. extension = extWithDot = "";
  850. if (m = /.+\.([^.]+)$/.exec(val)) {
  851. extension = m[1];
  852. extWithDot = "." + extension;
  853. }
  854. var info = CodeMirror.findModeByExtension(extension);
  855. previewLink = $('a[data-tab=preview]');
  856. if (info) {
  857. mode = info.mode;
  858. spec = info.mime;
  859. apiCall = mode;
  860. }
  861. else {
  862. apiCall = extension
  863. }
  864. if (previewLink.length && apiCall && previewFileModes && previewFileModes.length && previewFileModes.indexOf(apiCall) >= 0) {
  865. dataUrl = previewLink.data('url');
  866. previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, '$1/' + mode));
  867. previewLink.show();
  868. }
  869. else {
  870. previewLink.hide();
  871. }
  872. // If this file is a Markdown extensions, we will load that editor and return
  873. if (markdownFileExts.indexOf(extWithDot) >= 0) {
  874. if (setSimpleMDE($editArea)) {
  875. return;
  876. }
  877. }
  878. // Else we are going to use CodeMirror
  879. if (!codeMirrorEditor && !setCodeMirror($editArea)) {
  880. return;
  881. }
  882. if (mode) {
  883. codeMirrorEditor.setOption("mode", spec);
  884. CodeMirror.autoLoadMode(codeMirrorEditor, mode);
  885. }
  886. if (lineWrapExtensions.indexOf(extWithDot) >= 0) {
  887. codeMirrorEditor.setOption("lineWrapping", true);
  888. }
  889. else {
  890. codeMirrorEditor.setOption("lineWrapping", false);
  891. }
  892. // get the filename without any folder
  893. var value = $editFilename.val();
  894. if (value.length === 0) {
  895. return;
  896. }
  897. value = value.split('/');
  898. value = value[value.length - 1];
  899. $.getJSON($editFilename.data('ec-url-prefix')+value, function(editorconfig) {
  900. if (editorconfig.indent_style === 'tab') {
  901. codeMirrorEditor.setOption("indentWithTabs", true);
  902. codeMirrorEditor.setOption('extraKeys', {});
  903. } else {
  904. codeMirrorEditor.setOption("indentWithTabs", false);
  905. // required because CodeMirror doesn't seems to use spaces correctly for {"indentWithTabs": false}:
  906. // - https://github.com/codemirror/CodeMirror/issues/988
  907. // - https://codemirror.net/doc/manual.html#keymaps
  908. codeMirrorEditor.setOption('extraKeys', {
  909. Tab: function(cm) {
  910. var spaces = Array(parseInt(cm.getOption("indentUnit")) + 1).join(" ");
  911. cm.replaceSelection(spaces);
  912. }
  913. });
  914. }
  915. codeMirrorEditor.setOption("indentUnit", editorconfig.indent_size || 4);
  916. codeMirrorEditor.setOption("tabSize", editorconfig.tab_width || 4);
  917. });
  918. }).trigger('keyup');
  919. }
  920. function initOrganization() {
  921. if ($('.organization').length == 0) {
  922. return;
  923. }
  924. // Options
  925. if ($('.organization.settings.options').length > 0) {
  926. $('#org_name').keyup(function () {
  927. var $prompt = $('#org-name-change-prompt');
  928. if ($(this).val().toString().toLowerCase() != $(this).data('org-name').toString().toLowerCase()) {
  929. $prompt.show();
  930. } else {
  931. $prompt.hide();
  932. }
  933. });
  934. }
  935. }
  936. function initUserSettings() {
  937. console.log('initUserSettings');
  938. // Options
  939. if ($('.user.settings.profile').length > 0) {
  940. $('#username').keyup(function () {
  941. var $prompt = $('#name-change-prompt');
  942. if ($(this).val().toString().toLowerCase() != $(this).data('name').toString().toLowerCase()) {
  943. $prompt.show();
  944. } else {
  945. $prompt.hide();
  946. }
  947. });
  948. }
  949. }
  950. function initWebhook() {
  951. if ($('.new.webhook').length == 0) {
  952. return;
  953. }
  954. $('.events.checkbox input').change(function () {
  955. if ($(this).is(':checked')) {
  956. $('.events.fields').show();
  957. }
  958. });
  959. $('.non-events.checkbox input').change(function () {
  960. if ($(this).is(':checked')) {
  961. $('.events.fields').hide();
  962. }
  963. });
  964. // Test delivery
  965. $('#test-delivery').click(function () {
  966. var $this = $(this);
  967. $this.addClass('loading disabled');
  968. $.post($this.data('link'), {
  969. "_csrf": csrf
  970. }).done(
  971. setTimeout(function () {
  972. window.location.href = $this.data('redirect');
  973. }, 5000)
  974. )
  975. });
  976. }
  977. function initAdmin() {
  978. if ($('.admin').length == 0) {
  979. return;
  980. }
  981. // New user
  982. if ($('.admin.new.user').length > 0 ||
  983. $('.admin.edit.user').length > 0) {
  984. $('#login_type').change(function () {
  985. if ($(this).val().substring(0, 1) == '0') {
  986. $('#login_name').removeAttr('required');
  987. $('.non-local').hide();
  988. $('.local').show();
  989. $('#user_name').focus();
  990. if ($(this).data('password') == "required") {
  991. $('#password').attr('required', 'required');
  992. }
  993. } else {
  994. $('#login_name').attr('required', 'required');
  995. $('.non-local').show();
  996. $('.local').hide();
  997. $('#login_name').focus();
  998. $('#password').removeAttr('required');
  999. }
  1000. });
  1001. }
  1002. function onSecurityProtocolChange() {
  1003. if ($('#security_protocol').val() > 0) {
  1004. $('.has-tls').show();
  1005. } else {
  1006. $('.has-tls').hide();
  1007. }
  1008. }
  1009. function onOAuth2Change() {
  1010. $('.open_id_connect_auto_discovery_url, .oauth2_use_custom_url').hide();
  1011. $('.open_id_connect_auto_discovery_url input[required]').removeAttr('required');
  1012. var provider = $('#oauth2_provider').val();
  1013. switch (provider) {
  1014. case 'github':
  1015. case 'gitlab':
  1016. $('.oauth2_use_custom_url').show();
  1017. break;
  1018. case 'openidConnect':
  1019. $('.open_id_connect_auto_discovery_url input').attr('required', 'required');
  1020. $('.open_id_connect_auto_discovery_url').show();
  1021. break;
  1022. }
  1023. onOAuth2UseCustomURLChange();
  1024. }
  1025. function onOAuth2UseCustomURLChange() {
  1026. var provider = $('#oauth2_provider').val();
  1027. $('.oauth2_use_custom_url_field').hide();
  1028. $('.oauth2_use_custom_url_field input[required]').removeAttr('required');
  1029. if ($('#oauth2_use_custom_url').is(':checked')) {
  1030. if (!$('#oauth2_token_url').val()) {
  1031. $('#oauth2_token_url').val($('#' + provider + '_token_url').val());
  1032. }
  1033. if (!$('#oauth2_auth_url').val()) {
  1034. $('#oauth2_auth_url').val($('#' + provider + '_auth_url').val());
  1035. }
  1036. if (!$('#oauth2_profile_url').val()) {
  1037. $('#oauth2_profile_url').val($('#' + provider + '_profile_url').val());
  1038. }
  1039. if (!$('#oauth2_email_url').val()) {
  1040. $('#oauth2_email_url').val($('#' + provider + '_email_url').val());
  1041. }
  1042. switch (provider) {
  1043. case 'github':
  1044. $('.oauth2_token_url input, .oauth2_auth_url input, .oauth2_profile_url input, .oauth2_email_url input').attr('required', 'required');
  1045. $('.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url, .oauth2_email_url').show();
  1046. break;
  1047. case 'gitlab':
  1048. $('.oauth2_token_url input, .oauth2_auth_url input, .oauth2_profile_url input').attr('required', 'required');
  1049. $('.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url').show();
  1050. $('#oauth2_email_url').val('');
  1051. break;
  1052. }
  1053. }
  1054. }
  1055. // New authentication
  1056. if ($('.admin.new.authentication').length > 0) {
  1057. $('#auth_type').change(function () {
  1058. $('.ldap, .dldap, .smtp, .pam, .oauth2, .has-tls').hide();
  1059. $('.ldap input[required], .dldap input[required], .smtp input[required], .pam input[required], .oauth2 input[required], .has-tls input[required]').removeAttr('required');
  1060. var authType = $(this).val();
  1061. switch (authType) {
  1062. case '2': // LDAP
  1063. $('.ldap').show();
  1064. $('.ldap div.required:not(.dldap) input').attr('required', 'required');
  1065. break;
  1066. case '3': // SMTP
  1067. $('.smtp').show();
  1068. $('.has-tls').show();
  1069. $('.smtp div.required input, .has-tls').attr('required', 'required');
  1070. break;
  1071. case '4': // PAM
  1072. $('.pam').show();
  1073. $('.pam input').attr('required', 'required');
  1074. break;
  1075. case '5': // LDAP
  1076. $('.dldap').show();
  1077. $('.dldap div.required:not(.ldap) input').attr('required', 'required');
  1078. break;
  1079. case '6': // OAuth2
  1080. $('.oauth2').show();
  1081. $('.oauth2 div.required:not(.oauth2_use_custom_url,.oauth2_use_custom_url_field,.open_id_connect_auto_discovery_url) input').attr('required', 'required');
  1082. onOAuth2Change();
  1083. break;
  1084. }
  1085. if (authType == '2' || authType == '5') {
  1086. onSecurityProtocolChange()
  1087. }
  1088. });
  1089. $('#auth_type').change();
  1090. $('#security_protocol').change(onSecurityProtocolChange);
  1091. $('#oauth2_provider').change(onOAuth2Change);
  1092. $('#oauth2_use_custom_url').change(onOAuth2UseCustomURLChange);
  1093. }
  1094. // Edit authentication
  1095. if ($('.admin.edit.authentication').length > 0) {
  1096. var authType = $('#auth_type').val();
  1097. if (authType == '2' || authType == '5') {
  1098. $('#security_protocol').change(onSecurityProtocolChange);
  1099. } else if (authType == '6') {
  1100. $('#oauth2_provider').change(onOAuth2Change);
  1101. $('#oauth2_use_custom_url').change(onOAuth2UseCustomURLChange);
  1102. onOAuth2Change();
  1103. }
  1104. }
  1105. // Notice
  1106. if ($('.admin.notice')) {
  1107. var $detailModal = $('#detail-modal');
  1108. // Attach view detail modals
  1109. $('.view-detail').click(function () {
  1110. $detailModal.find('.content p').text($(this).data('content'));
  1111. $detailModal.modal('show');
  1112. return false;
  1113. });
  1114. // Select actions
  1115. var $checkboxes = $('.select.table .ui.checkbox');
  1116. $('.select.action').click(function () {
  1117. switch ($(this).data('action')) {
  1118. case 'select-all':
  1119. $checkboxes.checkbox('check');
  1120. break;
  1121. case 'deselect-all':
  1122. $checkboxes.checkbox('uncheck');
  1123. break;
  1124. case 'inverse':
  1125. $checkboxes.checkbox('toggle');
  1126. break;
  1127. }
  1128. });
  1129. $('#delete-selection').click(function () {
  1130. var $this = $(this);
  1131. $this.addClass("loading disabled");
  1132. var ids = [];
  1133. $checkboxes.each(function () {
  1134. if ($(this).checkbox('is checked')) {
  1135. ids.push($(this).data('id'));
  1136. }
  1137. });
  1138. $.post($this.data('link'), {
  1139. "_csrf": csrf,
  1140. "ids": ids
  1141. }).done(function () {
  1142. window.location.href = $this.data('redirect');
  1143. });
  1144. });
  1145. }
  1146. }
  1147. function buttonsClickOnEnter() {
  1148. $('.ui.button').keypress(function (e) {
  1149. if (e.keyCode == 13 || e.keyCode == 32) // enter key or space bar
  1150. $(this).click();
  1151. });
  1152. }
  1153. function hideWhenLostFocus(body, parent) {
  1154. $(document).click(function (e) {
  1155. var target = e.target;
  1156. if (!$(target).is(body) && !$(target).parents().is(parent)) {
  1157. $(body).hide();
  1158. }
  1159. });
  1160. }
  1161. function searchUsers() {
  1162. var $searchUserBox = $('#search-user-box');
  1163. $searchUserBox.search({
  1164. minCharacters: 2,
  1165. apiSettings: {
  1166. url: suburl + '/api/v1/users/search?q={query}',
  1167. onResponse: function(response) {
  1168. var items = [];
  1169. $.each(response.data, function (i, item) {
  1170. var title = item.login;
  1171. if (item.full_name && item.full_name.length > 0) {
  1172. title += ' (' + item.full_name + ')';
  1173. }
  1174. items.push({
  1175. title: title,
  1176. image: item.avatar_url
  1177. })
  1178. });
  1179. return { results: items }
  1180. }
  1181. },
  1182. searchFields: ['login', 'full_name'],
  1183. showNoResults: false
  1184. });
  1185. }
  1186. function searchRepositories() {
  1187. var $searchRepoBox = $('#search-repo-box');
  1188. $searchRepoBox.search({
  1189. minCharacters: 2,
  1190. apiSettings: {
  1191. url: suburl + '/api/v1/repos/search?q={query}&uid=' + $searchRepoBox.data('uid'),
  1192. onResponse: function(response) {
  1193. var items = [];
  1194. $.each(response.data, function (i, item) {
  1195. items.push({
  1196. title: item.full_name.split("/")[1],
  1197. description: item.full_name
  1198. })
  1199. });
  1200. return { results: items }
  1201. }
  1202. },
  1203. searchFields: ['full_name'],
  1204. showNoResults: false
  1205. });
  1206. }
  1207. function initCodeView() {
  1208. if ($('.code-view .linenums').length > 0) {
  1209. $(document).on('click', '.lines-num span', function (e) {
  1210. var $select = $(this);
  1211. var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
  1212. selectRange($list, $list.filter('[rel=' + $select.attr('id') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
  1213. deSelect();
  1214. });
  1215. $(window).on('hashchange', function (e) {
  1216. var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
  1217. var $list = $('.code-view ol.linenums > li');
  1218. var $first;
  1219. if (m) {
  1220. $first = $list.filter('.' + m[1]);
  1221. selectRange($list, $first, $list.filter('.' + m[2]));
  1222. $("html, body").scrollTop($first.offset().top - 200);
  1223. return;
  1224. }
  1225. m = window.location.hash.match(/^#(L\d+)$/);
  1226. if (m) {
  1227. $first = $list.filter('.' + m[1]);
  1228. selectRange($list, $first);
  1229. $("html, body").scrollTop($first.offset().top - 200);
  1230. }
  1231. }).trigger('hashchange');
  1232. }
  1233. }
  1234. $(document).ready(function () {
  1235. csrf = $('meta[name=_csrf]').attr("content");
  1236. suburl = $('meta[name=_suburl]').attr("content");
  1237. // Show exact time
  1238. $('.time-since').each(function () {
  1239. $(this).addClass('poping up').attr('data-content', $(this).attr('title')).attr('data-variation', 'inverted tiny').attr('title', '');
  1240. });
  1241. // Semantic UI modules.
  1242. $('.dropdown:not(.custom)').dropdown();
  1243. $('.jump.dropdown').dropdown({
  1244. action: 'hide',
  1245. onShow: function () {
  1246. $('.poping.up').popup('hide');
  1247. }
  1248. });
  1249. $('.slide.up.dropdown').dropdown({
  1250. transition: 'slide up'
  1251. });
  1252. $('.upward.dropdown').dropdown({
  1253. direction: 'upward'
  1254. });
  1255. $('.ui.accordion').accordion();
  1256. $('.ui.checkbox').checkbox();
  1257. $('.ui.progress').progress({
  1258. showActivity: false
  1259. });
  1260. $('.poping.up').popup();
  1261. $('.top.menu .poping.up').popup({
  1262. onShow: function () {
  1263. if ($('.top.menu .menu.transition').hasClass('visible')) {
  1264. return false;
  1265. }
  1266. }
  1267. });
  1268. $('.tabular.menu .item').tab();
  1269. $('.tabable.menu .item').tab();
  1270. $('.toggle.button').click(function () {
  1271. $($(this).data('target')).slideToggle(100);
  1272. });
  1273. // make table <tr> element clickable like a link
  1274. $('tr[data-href]').click(function(event) {
  1275. window.location = $(this).data('href');
  1276. });
  1277. // Highlight JS
  1278. if (typeof hljs != 'undefined') {
  1279. hljs.initHighlightingOnLoad();
  1280. }
  1281. // Dropzone
  1282. var $dropzone = $('#dropzone');
  1283. if ($dropzone.length > 0) {
  1284. // Disable auto discover for all elements:
  1285. Dropzone.autoDiscover = false;
  1286. var filenameDict = {};
  1287. $dropzone.dropzone({
  1288. url: $dropzone.data('upload-url'),
  1289. headers: {"X-Csrf-Token": csrf},
  1290. maxFiles: $dropzone.data('max-file'),
  1291. maxFilesize: $dropzone.data('max-size'),
  1292. acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
  1293. addRemoveLinks: true,
  1294. dictDefaultMessage: $dropzone.data('default-message'),
  1295. dictInvalidFileType: $dropzone.data('invalid-input-type'),
  1296. dictFileTooBig: $dropzone.data('file-too-big'),
  1297. dictRemoveFile: $dropzone.data('remove-file'),
  1298. init: function () {
  1299. this.on("success", function (file, data) {
  1300. filenameDict[file.name] = data.uuid;
  1301. var input = $('<input id="' + data.uuid + '" name="files" type="hidden">').val(data.uuid);
  1302. $('.files').append(input);
  1303. });
  1304. this.on("removedfile", function (file) {
  1305. if (file.name in filenameDict) {
  1306. $('#' + filenameDict[file.name]).remove();
  1307. }
  1308. if ($dropzone.data('remove-url') && $dropzone.data('csrf')) {
  1309. $.post($dropzone.data('remove-url'), {
  1310. file: filenameDict[file.name],
  1311. _csrf: $dropzone.data('csrf')
  1312. });
  1313. }
  1314. })
  1315. }
  1316. });
  1317. }
  1318. // Emojify
  1319. emojify.setConfig({
  1320. img_dir: suburl + '/vendor/plugins/emojify/images',
  1321. ignore_emoticons: true
  1322. });
  1323. var hasEmoji = document.getElementsByClassName('has-emoji');
  1324. for (var i = 0; i < hasEmoji.length; i++) {
  1325. emojify.run(hasEmoji[i]);
  1326. }
  1327. // Clipboard JS
  1328. var clipboard = new Clipboard('.clipboard');
  1329. clipboard.on('success', function (e) {
  1330. e.clearSelection();
  1331. $('#' + e.trigger.getAttribute('id')).popup('destroy');
  1332. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-success'))
  1333. $('#' + e.trigger.getAttribute('id')).popup('show');
  1334. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
  1335. });
  1336. clipboard.on('error', function (e) {
  1337. $('#' + e.trigger.getAttribute('id')).popup('destroy');
  1338. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-error'))
  1339. $('#' + e.trigger.getAttribute('id')).popup('show');
  1340. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
  1341. });
  1342. // Helpers.
  1343. $('.delete-button').click(showDeletePopup);
  1344. $('.delete-branch-button').click(showDeletePopup);
  1345. $('.undo-button').click(function() {
  1346. var $this = $(this);
  1347. $.post($this.data('url'), {
  1348. "_csrf": csrf,
  1349. "id": $this.data("id")
  1350. }).done(function(data) {
  1351. window.location.href = data.redirect;
  1352. });
  1353. });
  1354. $('.show-panel.button').click(function () {
  1355. $($(this).data('panel')).show();
  1356. });
  1357. $('.show-modal.button').click(function () {
  1358. $($(this).data('modal')).modal('show');
  1359. });
  1360. $('.delete-post.button').click(function () {
  1361. var $this = $(this);
  1362. $.post($this.data('request-url'), {
  1363. "_csrf": csrf
  1364. }).done(function () {
  1365. window.location.href = $this.data('done-url');
  1366. });
  1367. });
  1368. // Set anchor.
  1369. $('.markdown').each(function () {
  1370. var headers = {};
  1371. $(this).find('h1, h2, h3, h4, h5, h6').each(function () {
  1372. var node = $(this);
  1373. var val = encodeURIComponent(node.text().toLowerCase().replace(/[^\u00C0-\u1FFF\u2C00-\uD7FF\w\- ]/g, '').replace(/[ ]/g, '-'));
  1374. var name = val;
  1375. if (headers[val] > 0) {
  1376. name = val + '-' + headers[val];
  1377. }
  1378. if (headers[val] == undefined) {
  1379. headers[val] = 1;
  1380. } else {
  1381. headers[val] += 1;
  1382. }
  1383. node = node.wrap('<div id="' + name + '" class="anchor-wrap" ></div>');
  1384. node.append('<a class="anchor" href="#' + name + '"><span class="octicon octicon-link"></span></a>');
  1385. });
  1386. });
  1387. $('.markdown').autolink();
  1388. $('.issue-checkbox').click(function() {
  1389. var numChecked = $('.issue-checkbox').children('input:checked').length;
  1390. if (numChecked > 0) {
  1391. $('#issue-filters').hide();
  1392. $('#issue-actions').show();
  1393. } else {
  1394. $('#issue-filters').show();
  1395. $('#issue-actions').hide();
  1396. }
  1397. });
  1398. $('.issue-action').click(function () {
  1399. var action = this.dataset.action
  1400. var elementId = this.dataset.elementId
  1401. var issueIDs = $('.issue-checkbox').children('input:checked').map(function() {
  1402. return this.dataset.issueId;
  1403. }).get().join();
  1404. var url = this.dataset.url
  1405. updateIssuesMeta(url, action, issueIDs, elementId, function() {
  1406. location.reload();
  1407. });
  1408. });
  1409. buttonsClickOnEnter();
  1410. searchUsers();
  1411. searchRepositories();
  1412. initCommentForm();
  1413. initInstall();
  1414. initRepository();
  1415. initWikiForm();
  1416. initEditForm();
  1417. initEditor();
  1418. initOrganization();
  1419. initWebhook();
  1420. initAdmin();
  1421. initCodeView();
  1422. initVueApp();
  1423. initTeamSettings();
  1424. initCtrlEnterSubmit();
  1425. initNavbarContentToggle();
  1426. // Repo clone url.
  1427. if ($('#repo-clone-url').length > 0) {
  1428. switch (localStorage.getItem('repo-clone-protocol')) {
  1429. case 'ssh':
  1430. if ($('#repo-clone-ssh').click().length === 0) {
  1431. $('#repo-clone-https').click();
  1432. }
  1433. break;
  1434. default:
  1435. $('#repo-clone-https').click();
  1436. break;
  1437. }
  1438. }
  1439. var routes = {
  1440. 'div.user.settings': initUserSettings,
  1441. 'div.repository.settings.collaboration': initRepositoryCollaboration
  1442. };
  1443. var selector;
  1444. for (selector in routes) {
  1445. if ($(selector).length > 0) {
  1446. routes[selector]();
  1447. break;
  1448. }
  1449. }
  1450. });
  1451. function changeHash(hash) {
  1452. if (history.pushState) {
  1453. history.pushState(null, null, hash);
  1454. }
  1455. else {
  1456. location.hash = hash;
  1457. }
  1458. }
  1459. function deSelect() {
  1460. if (window.getSelection) {
  1461. window.getSelection().removeAllRanges();
  1462. } else {
  1463. document.selection.empty();
  1464. }
  1465. }
  1466. function selectRange($list, $select, $from) {
  1467. $list.removeClass('active');
  1468. if ($from) {
  1469. var a = parseInt($select.attr('rel').substr(1));
  1470. var b = parseInt($from.attr('rel').substr(1));
  1471. var c;
  1472. if (a != b) {
  1473. if (a > b) {
  1474. c = a;
  1475. a = b;
  1476. b = c;
  1477. }
  1478. var classes = [];
  1479. for (var i = a; i <= b; i++) {
  1480. classes.push('.L' + i);
  1481. }
  1482. $list.filter(classes.join(',')).addClass('active');
  1483. changeHash('#L' + a + '-' + 'L' + b);
  1484. return
  1485. }
  1486. }
  1487. $select.addClass('active');
  1488. changeHash('#' + $select.attr('rel'));
  1489. }
  1490. $(function () {
  1491. if ($('.user.signin').length > 0) return;
  1492. $('form').areYouSure();
  1493. // Parse SSH Key
  1494. $("#ssh-key-content").on('change paste keyup',function(){
  1495. var arrays = $(this).val().split(" ");
  1496. var $title = $("#ssh-key-title")
  1497. if ($title.val() === "" && arrays.length === 3 && arrays[2] !== "") {
  1498. $title.val(arrays[2]);
  1499. }
  1500. });
  1501. });
  1502. function showDeletePopup() {
  1503. var $this = $(this);
  1504. var filter = "";
  1505. if ($this.attr("id")) {
  1506. filter += "#" + $this.attr("id")
  1507. }
  1508. $('.delete.modal' + filter).modal({
  1509. closable: false,
  1510. onApprove: function() {
  1511. if ($this.data('type') == "form") {
  1512. $($this.data('form')).submit();
  1513. return;
  1514. }
  1515. $.post($this.data('url'), {
  1516. "_csrf": csrf,
  1517. "id": $this.data("id")
  1518. }).done(function(data) {
  1519. window.location.href = data.redirect;
  1520. });
  1521. }
  1522. }).modal('show');
  1523. return false;
  1524. }
  1525. function initVueComponents(){
  1526. var vueDelimeters = ['${', '}'];
  1527. Vue.component('repo-search', {
  1528. delimiters: vueDelimeters,
  1529. props: {
  1530. searchLimit: {
  1531. type: Number,
  1532. default: 10
  1533. },
  1534. suburl: {
  1535. type: String,
  1536. required: true
  1537. },
  1538. uid: {
  1539. type: Number,
  1540. required: true
  1541. },
  1542. organizations: {
  1543. type: Array,
  1544. default: []
  1545. },
  1546. isOrganization: {
  1547. type: Boolean,
  1548. default: true
  1549. },
  1550. canCreateOrganization: {
  1551. type: Boolean,
  1552. default: false
  1553. },
  1554. organizationsTotalCount: {
  1555. type: Number,
  1556. default: 0
  1557. },
  1558. moreReposLink: {
  1559. type: String,
  1560. default: ''
  1561. }
  1562. },
  1563. data: function() {
  1564. return {
  1565. tab: 'repos',
  1566. repos: [],
  1567. reposTotalCount: 0,
  1568. reposFilter: 'all',
  1569. searchQuery: '',
  1570. isLoading: false,
  1571. repoTypes: {
  1572. 'all': {
  1573. count: 0,
  1574. searchMode: '',
  1575. },
  1576. 'forks': {
  1577. count: 0,
  1578. searchMode: 'fork',
  1579. },
  1580. 'mirrors': {
  1581. count: 0,
  1582. searchMode: 'mirror',
  1583. },
  1584. 'sources': {
  1585. count: 0,
  1586. searchMode: 'source',
  1587. },
  1588. 'collaborative': {
  1589. count: 0,
  1590. searchMode: 'collaborative',
  1591. },
  1592. }
  1593. }
  1594. },
  1595. computed: {
  1596. showMoreReposLink: function() {
  1597. return this.repos.length > 0 && this.repos.length < this.repoTypes[this.reposFilter].count;
  1598. },
  1599. searchURL: function() {
  1600. return this.suburl + '/api/v1/repos/search?uid=' + this.uid + '&q=' + this.searchQuery + '&limit=' + this.searchLimit + '&mode=' + this.repoTypes[this.reposFilter].searchMode + (this.reposFilter !== 'all' ? '&exclusive=1' : '');
  1601. },
  1602. repoTypeCount: function() {
  1603. return this.repoTypes[this.reposFilter].count;
  1604. }
  1605. },
  1606. mounted: function() {
  1607. this.searchRepos(this.reposFilter);
  1608. var self = this;
  1609. Vue.nextTick(function() {
  1610. self.$refs.search.focus();
  1611. });
  1612. },
  1613. methods: {
  1614. changeTab: function(t) {
  1615. this.tab = t;
  1616. },
  1617. changeReposFilter: function(filter) {
  1618. this.reposFilter = filter;
  1619. this.repos = [];
  1620. this.repoTypes[filter].count = 0;
  1621. this.searchRepos(filter);
  1622. },
  1623. showRepo: function(repo, filter) {
  1624. switch (filter) {
  1625. case 'sources':
  1626. return repo.owner.id == this.uid && !repo.mirror && !repo.fork;
  1627. case 'forks':
  1628. return repo.owner.id == this.uid && !repo.mirror && repo.fork;
  1629. case 'mirrors':
  1630. return repo.mirror;
  1631. case 'collaborative':
  1632. return repo.owner.id != this.uid && !repo.mirror;
  1633. default:
  1634. return true;
  1635. }
  1636. },
  1637. searchRepos: function(reposFilter) {
  1638. var self = this;
  1639. this.isLoading = true;
  1640. var searchedMode = this.repoTypes[reposFilter].searchMode;
  1641. var searchedURL = this.searchURL;
  1642. var searchedQuery = this.searchQuery;
  1643. $.getJSON(searchedURL, function(result, textStatus, request) {
  1644. if (searchedURL == self.searchURL) {
  1645. self.repos = result.data;
  1646. var count = request.getResponseHeader('X-Total-Count');
  1647. if (searchedQuery === '' && searchedMode === '') {
  1648. self.reposTotalCount = count;
  1649. }
  1650. self.repoTypes[reposFilter].count = count;
  1651. }
  1652. }).always(function() {
  1653. if (searchedURL == self.searchURL) {
  1654. self.isLoading = false;
  1655. }
  1656. });
  1657. },
  1658. repoClass: function(repo) {
  1659. if (repo.fork) {
  1660. return 'octicon octicon-repo-forked';
  1661. } else if (repo.mirror) {
  1662. return 'octicon octicon-repo-clone';
  1663. } else if (repo.private) {
  1664. return 'octicon octicon-lock';
  1665. } else {
  1666. return 'octicon octicon-repo';
  1667. }
  1668. }
  1669. }
  1670. })
  1671. }
  1672. function initCtrlEnterSubmit() {
  1673. $(".js-quick-submit").keydown(function(e) {
  1674. if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
  1675. $(this).closest("form").submit();
  1676. }
  1677. });
  1678. }
  1679. function initVueApp() {
  1680. var el = document.getElementById('app');
  1681. if (!el) {
  1682. return;
  1683. }
  1684. initVueComponents();
  1685. new Vue({
  1686. delimiters: ['${', '}'],
  1687. el: el,
  1688. data: {
  1689. searchLimit: document.querySelector('meta[name=_search_limit]').content,
  1690. suburl: document.querySelector('meta[name=_suburl]').content,
  1691. uid: document.querySelector('meta[name=_context_uid]').content,
  1692. },
  1693. });
  1694. }
  1695. function timeAddManual() {
  1696. $('.mini.modal')
  1697. .modal({
  1698. duration: 200,
  1699. onApprove: function() {
  1700. $('#add_time_manual_form').submit();
  1701. }
  1702. }).modal('show')
  1703. ;
  1704. }
  1705. function toggleStopwatch() {
  1706. $("#toggle_stopwatch_form").submit();
  1707. }
  1708. function cancelStopwatch() {
  1709. $("#cancel_stopwatch_form").submit();
  1710. }
  1711. function initFilterBranchTagDropdown(selector) {
  1712. $(selector).each(function() {
  1713. var $dropdown = $(this);
  1714. var $data = $dropdown.find('.data');
  1715. var data = {
  1716. items: [],
  1717. mode: $data.data('mode'),
  1718. searchTerm: '',
  1719. noResults: '',
  1720. canCreateBranch: false,
  1721. menuVisible: false,
  1722. active: 0
  1723. };
  1724. $data.find('.item').each(function() {
  1725. data.items.push({
  1726. name: $(this).text(),
  1727. url: $(this).data('url'),
  1728. branch: $(this).hasClass('branch'),
  1729. tag: $(this).hasClass('tag'),
  1730. selected: $(this).hasClass('selected')
  1731. });
  1732. });
  1733. $data.remove();
  1734. new Vue({
  1735. delimiters: ['${', '}'],
  1736. el: this,
  1737. data: data,
  1738. beforeMount: function () {
  1739. var vm = this;
  1740. this.noResults = vm.$el.getAttribute('data-no-results');
  1741. this.canCreateBranch = vm.$el.getAttribute('data-can-create-branch') === 'true';
  1742. document.body.addEventListener('click', function(event) {
  1743. if (vm.$el.contains(event.target)) {
  1744. return;
  1745. }
  1746. if (vm.menuVisible) {
  1747. Vue.set(vm, 'menuVisible', false);
  1748. }
  1749. });
  1750. },
  1751. watch: {
  1752. menuVisible: function(visible) {
  1753. if (visible) {
  1754. this.focusSearchField();
  1755. }
  1756. }
  1757. },
  1758. computed: {
  1759. filteredItems: function() {
  1760. var vm = this;
  1761. var items = vm.items.filter(function (item) {
  1762. return ((vm.mode === 'branches' && item.branch)
  1763. || (vm.mode === 'tags' && item.tag))
  1764. && (!vm.searchTerm
  1765. || item.name.toLowerCase().indexOf(vm.searchTerm.toLowerCase()) >= 0);
  1766. });
  1767. vm.active = (items.length === 0 && vm.showCreateNewBranch ? 0 : -1);
  1768. return items;
  1769. },
  1770. showNoResults: function() {
  1771. return this.filteredItems.length === 0
  1772. && !this.showCreateNewBranch;
  1773. },
  1774. showCreateNewBranch: function() {
  1775. var vm = this;
  1776. if (!this.canCreateBranch || !vm.searchTerm || vm.mode === 'tags') {
  1777. return false;
  1778. }
  1779. return vm.items.filter(function (item) {
  1780. return item.name.toLowerCase() === vm.searchTerm.toLowerCase()
  1781. }).length === 0;
  1782. }
  1783. },
  1784. methods: {
  1785. selectItem: function(item) {
  1786. var prev = this.getSelected();
  1787. if (prev !== null) {
  1788. prev.selected = false;
  1789. }
  1790. item.selected = true;
  1791. window.location.href = item.url;
  1792. },
  1793. createNewBranch: function() {
  1794. if (!this.showCreateNewBranch) {
  1795. return;
  1796. }
  1797. this.$refs.newBranchForm.submit();
  1798. },
  1799. focusSearchField: function() {
  1800. var vm = this;
  1801. Vue.nextTick(function() {
  1802. vm.$refs.searchField.focus();
  1803. });
  1804. },
  1805. getSelected: function() {
  1806. for (var i = 0, j = this.items.length; i < j; ++i) {
  1807. if (this.items[i].selected)
  1808. return this.items[i];
  1809. }
  1810. return null;
  1811. },
  1812. getSelectedIndexInFiltered: function() {
  1813. for (var i = 0, j = this.filteredItems.length; i < j; ++i) {
  1814. if (this.filteredItems[i].selected)
  1815. return i;
  1816. }
  1817. return -1;
  1818. },
  1819. scrollToActive: function() {
  1820. var el = this.$refs['listItem' + this.active];
  1821. if (!el || el.length === 0) {
  1822. return;
  1823. }
  1824. if (Array.isArray(el)) {
  1825. el = el[0];
  1826. }
  1827. var cont = this.$refs.scrollContainer;
  1828. if (el.offsetTop < cont.scrollTop) {
  1829. cont.scrollTop = el.offsetTop;
  1830. }
  1831. else if (el.offsetTop + el.clientHeight > cont.scrollTop + cont.clientHeight) {
  1832. cont.scrollTop = el.offsetTop + el.clientHeight - cont.clientHeight;
  1833. }
  1834. },
  1835. keydown: function(event) {
  1836. var vm = this;
  1837. if (event.keyCode === 40) {
  1838. // arrow down
  1839. event.preventDefault();
  1840. if (vm.active === -1) {
  1841. vm.active = vm.getSelectedIndexInFiltered();
  1842. }
  1843. if (vm.active + (vm.showCreateNewBranch ? 0 : 1) >= vm.filteredItems.length) {
  1844. return;
  1845. }
  1846. vm.active++;
  1847. vm.scrollToActive();
  1848. }
  1849. if (event.keyCode === 38) {
  1850. // arrow up
  1851. event.preventDefault();
  1852. if (vm.active === -1) {
  1853. vm.active = vm.getSelectedIndexInFiltered();
  1854. }
  1855. if (vm.active <= 0) {
  1856. return;
  1857. }
  1858. vm.active--;
  1859. vm.scrollToActive();
  1860. }
  1861. if (event.keyCode == 13) {
  1862. // enter
  1863. event.preventDefault();
  1864. if (vm.active >= vm.filteredItems.length) {
  1865. vm.createNewBranch();
  1866. } else if (vm.active >= 0) {
  1867. vm.selectItem(vm.filteredItems[vm.active]);
  1868. }
  1869. }
  1870. if (event.keyCode == 27) {
  1871. // escape
  1872. event.preventDefault();
  1873. vm.menuVisible = false;
  1874. }
  1875. }
  1876. }
  1877. });
  1878. });
  1879. }
  1880. $(".commit-button").click(function() {
  1881. $(this).parent().find('.commit-body').toggle();
  1882. });
  1883. function initNavbarContentToggle() {
  1884. var content = $('#navbar');
  1885. var toggle = $('#navbar-expand-toggle');
  1886. var isExpanded = false;
  1887. toggle.click(function() {
  1888. isExpanded = !isExpanded;
  1889. if (isExpanded) {
  1890. content.addClass('shown');
  1891. toggle.addClass('active');
  1892. }
  1893. else {
  1894. content.removeClass('shown');
  1895. toggle.removeClass('active');
  1896. }
  1897. });
  1898. }