gogs.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. 'use strict';
  2. var csrf;
  3. var suburl;
  4. function initCommentPreviewTab($form) {
  5. var $tab_menu = $form.find('.tabular.menu');
  6. $tab_menu.find('.item').tab();
  7. $tab_menu.find('.item[data-tab="' + $tab_menu.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="' + $tab_menu.data('write') + '"] textarea').val()
  14. },
  15. function (data) {
  16. var $preview_tab = $form.find('.tab.segment[data-tab="' + $tab_menu.data('preview') + '"]');
  17. $preview_tab.html(data);
  18. emojify.run($preview_tab[0]);
  19. $('pre code', $preview_tab[0]).each(function (i, block) {
  20. hljs.highlightBlock(block);
  21. });
  22. }
  23. );
  24. });
  25. buttonsClickOnEnter();
  26. }
  27. function initCommentForm() {
  28. if ($('.comment.form').length == 0) {
  29. return
  30. }
  31. initCommentPreviewTab($('.comment.form'));
  32. // Labels
  33. var $list = $('.ui.labels.list');
  34. var $no_select = $list.find('.no-select');
  35. var $label_menu = $('.select-label .menu');
  36. var has_label_update_action = $label_menu.data('action') == 'update';
  37. function updateIssueMeta(url, action, id) {
  38. $.post(url, {
  39. "_csrf": csrf,
  40. "action": action,
  41. "id": id
  42. });
  43. }
  44. $label_menu.find('.item:not(.no-select)').click(function () {
  45. if ($(this).hasClass('checked')) {
  46. $(this).removeClass('checked');
  47. $(this).find('.octicon').removeClass('octicon-check');
  48. if (has_label_update_action) {
  49. updateIssueMeta($label_menu.data('update-url'), "detach", $(this).data('id'));
  50. }
  51. } else {
  52. $(this).addClass('checked');
  53. $(this).find('.octicon').addClass('octicon-check');
  54. if (has_label_update_action) {
  55. updateIssueMeta($label_menu.data('update-url'), "attach", $(this).data('id'));
  56. }
  57. }
  58. var label_ids = "";
  59. $(this).parent().find('.item').each(function () {
  60. if ($(this).hasClass('checked')) {
  61. label_ids += $(this).data('id') + ",";
  62. $($(this).data('id-selector')).removeClass('hide');
  63. } else {
  64. $($(this).data('id-selector')).addClass('hide');
  65. }
  66. });
  67. if (label_ids.length == 0) {
  68. $no_select.removeClass('hide');
  69. } else {
  70. $no_select.addClass('hide');
  71. }
  72. $($(this).parent().data('id')).val(label_ids);
  73. return false;
  74. });
  75. $label_menu.find('.no-select.item').click(function () {
  76. if (has_label_update_action) {
  77. updateIssueMeta($label_menu.data('update-url'), "clear", '');
  78. }
  79. $(this).parent().find('.item').each(function () {
  80. $(this).removeClass('checked');
  81. $(this).find('.octicon').removeClass('octicon-check');
  82. });
  83. $list.find('.item').each(function () {
  84. $(this).addClass('hide');
  85. });
  86. $no_select.removeClass('hide');
  87. $($(this).parent().data('id')).val('');
  88. });
  89. function selectItem(select_id, input_id) {
  90. var $menu = $(select_id + ' .menu');
  91. var $list = $('.ui' + select_id + '.list');
  92. var has_update_action = $menu.data('action') == 'update';
  93. $menu.find('.item:not(.no-select)').click(function () {
  94. $(this).parent().find('.item').each(function () {
  95. $(this).removeClass('selected active')
  96. });
  97. $(this).addClass('selected active');
  98. if (has_update_action) {
  99. updateIssueMeta($menu.data('update-url'), '', $(this).data('id'));
  100. }
  101. switch (input_id) {
  102. case '#milestone_id':
  103. $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
  104. $(this).text() + '</a>');
  105. break;
  106. case '#assignee_id':
  107. $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
  108. '<img class="ui avatar image" src=' + $(this).data('avatar') + '>' +
  109. $(this).text() + '</a>');
  110. }
  111. $('.ui' + select_id + '.list .no-select').addClass('hide');
  112. $(input_id).val($(this).data('id'));
  113. });
  114. $menu.find('.no-select.item').click(function () {
  115. $(this).parent().find('.item:not(.no-select)').each(function () {
  116. $(this).removeClass('selected active')
  117. });
  118. if (has_update_action) {
  119. updateIssueMeta($menu.data('update-url'), '', '');
  120. }
  121. $list.find('.selected').html('');
  122. $list.find('.no-select').removeClass('hide');
  123. $(input_id).val('');
  124. });
  125. }
  126. // Milestone and assignee
  127. selectItem('.select-milestone', '#milestone_id');
  128. selectItem('.select-assignee', '#assignee_id');
  129. }
  130. function initInstall() {
  131. if ($('.install').length == 0) {
  132. return;
  133. }
  134. // Database type change detection.
  135. $("#db_type").change(function () {
  136. var sqlite_default = 'data/gogs.db';
  137. var tidb_default = 'data/gogs_tidb';
  138. var db_type = $(this).val();
  139. if (db_type === "SQLite3" || db_type === "TiDB") {
  140. $('#sql_settings').hide();
  141. $('#pgsql_settings').hide();
  142. $('#sqlite_settings').show();
  143. if (db_type === "SQLite3" && $('#db_path').val() == tidb_default) {
  144. $('#db_path').val(sqlite_default);
  145. } else if (db_type === "TiDB" && $('#db_path').val() == sqlite_default) {
  146. $('#db_path').val(tidb_default);
  147. }
  148. return;
  149. }
  150. var mysql_default = '127.0.0.1:3306';
  151. var postgres_default = '127.0.0.1:5432';
  152. $('#sqlite_settings').hide();
  153. $('#sql_settings').show();
  154. if (db_type === "PostgreSQL") {
  155. $('#pgsql_settings').show();
  156. if ($('#db_host').val() == mysql_default) {
  157. $('#db_host').val(postgres_default);
  158. }
  159. } else {
  160. $('#pgsql_settings').hide();
  161. if ($('#db_host').val() == postgres_default) {
  162. $('#db_host').val(mysql_default);
  163. }
  164. }
  165. });
  166. $('#offline-mode input').change(function () {
  167. if ($(this).is(':checked')) {
  168. $('#disable-gravatar').checkbox('check');
  169. }
  170. });
  171. $('#disable-registration input').change(function () {
  172. if ($(this).is(':checked')) {
  173. $('#enable-captcha').checkbox('uncheck');
  174. }
  175. });
  176. $('#enable-captcha input').change(function () {
  177. if ($(this).is(':checked')) {
  178. $('#disable-registration').checkbox('uncheck');
  179. }
  180. });
  181. }
  182. function initRepository() {
  183. if ($('.repository').length == 0) {
  184. return;
  185. }
  186. function initFilterSearchDropdown(selector) {
  187. var $dropdown = $(selector);
  188. $dropdown.dropdown({
  189. fullTextSearch: true,
  190. onChange: function (text, value, $choice) {
  191. window.location.href = $choice.data('url');
  192. console.log($choice.data('url'))
  193. },
  194. message: {noResults: $dropdown.data('no-results')}
  195. });
  196. }
  197. // File list and commits
  198. if ($('.repository.file.list').length > 0 ||
  199. ('.repository.commits').length > 0) {
  200. initFilterSearchDropdown('.choose.reference .dropdown');
  201. $('.reference.column').click(function () {
  202. $('.choose.reference .scrolling.menu').css('display', 'none');
  203. $('.choose.reference .text').removeClass('black');
  204. $($(this).data('target')).css('display', 'block');
  205. $(this).find('.text').addClass('black');
  206. return false;
  207. });
  208. }
  209. // Wiki
  210. if ($('.repository.wiki.view').length > 0) {
  211. initFilterSearchDropdown('.choose.page .dropdown');
  212. }
  213. // Options
  214. if ($('.repository.settings.options').length > 0) {
  215. $('#repo_name').keyup(function () {
  216. var $prompt_span = $('#repo-name-change-prompt');
  217. if ($(this).val().toString().toLowerCase() != $(this).data('repo-name').toString().toLowerCase()) {
  218. $prompt_span.show();
  219. } else {
  220. $prompt_span.hide();
  221. }
  222. });
  223. }
  224. // Labels
  225. if ($('.repository.labels').length > 0) {
  226. // Create label
  227. var $new_label_panel = $('.new-label.segment');
  228. $('.new-label.button').click(function () {
  229. $new_label_panel.show();
  230. });
  231. $('.new-label.segment .cancel').click(function () {
  232. $new_label_panel.hide();
  233. });
  234. $('.color-picker').each(function () {
  235. $(this).minicolors();
  236. });
  237. $('.precolors .color').click(function () {
  238. var color_hex = $(this).data('color-hex');
  239. $('.color-picker').val(color_hex);
  240. $('.minicolors-swatch-color').css("background-color", color_hex);
  241. });
  242. $('.edit-label-button').click(function () {
  243. $('#label-modal-id').val($(this).data('id'));
  244. $('.edit-label .new-label-input').val($(this).data('title'));
  245. $('.edit-label .color-picker').val($(this).data('color'));
  246. $('.minicolors-swatch-color').css("background-color", $(this).data('color'));
  247. $('.edit-label.modal').modal({
  248. onApprove: function () {
  249. $('.edit-label.form').submit();
  250. }
  251. }).modal('show');
  252. return false;
  253. });
  254. }
  255. // Milestones
  256. if ($('.repository.milestones').length > 0) {
  257. }
  258. if ($('.repository.new.milestone').length > 0) {
  259. var $datepicker = $('.milestone.datepicker');
  260. $datepicker.datetimepicker({
  261. lang: $datepicker.data('lang'),
  262. inline: true,
  263. timepicker: false,
  264. startDate: $datepicker.data('start-date'),
  265. formatDate: 'Y-m-d',
  266. onSelectDate: function (ct) {
  267. $('#deadline').val(ct.dateFormat('Y-m-d'));
  268. }
  269. });
  270. $('#clear-date').click(function () {
  271. $('#deadline').val('');
  272. return false;
  273. });
  274. }
  275. // Issues
  276. if ($('.repository.view.issue').length > 0) {
  277. // Edit issue title
  278. var $issue_title = $('#issue-title');
  279. var $edit_input = $('#edit-title-input input');
  280. var editTitleToggle = function () {
  281. $issue_title.toggle();
  282. $('.not-in-edit').toggle();
  283. $('#edit-title-input').toggle();
  284. $('.in-edit').toggle();
  285. $edit_input.focus();
  286. return false;
  287. };
  288. $('#edit-title').click(editTitleToggle);
  289. $('#cancel-edit-title').click(editTitleToggle);
  290. $('#save-edit-title').click(editTitleToggle).click(function () {
  291. if ($edit_input.val().length == 0 ||
  292. $edit_input.val() == $issue_title.text()) {
  293. $edit_input.val($issue_title.text());
  294. return false;
  295. }
  296. $.post($(this).data('update-url'), {
  297. "_csrf": csrf,
  298. "title": $edit_input.val()
  299. },
  300. function (data) {
  301. $edit_input.val(data.title);
  302. $issue_title.text(data.title);
  303. });
  304. return false;
  305. });
  306. // Edit issue or comment content
  307. $('.edit-content').click(function () {
  308. var $segment = $(this).parent().parent().next();
  309. var $edit_content_zone = $segment.find('.edit-content-zone');
  310. var $render_content = $segment.find('.render-content');
  311. var $raw_content = $segment.find('.raw-content');
  312. var $textarea;
  313. // Setup new form
  314. if ($edit_content_zone.html().length == 0) {
  315. $edit_content_zone.html($('#edit-content-form').html());
  316. $textarea = $segment.find('textarea');
  317. // Give new write/preview data-tab name to distinguish from others
  318. var $edit_content_form = $edit_content_zone.find('.ui.comment.form');
  319. var $tabular_menu = $edit_content_form.find('.tabular.menu');
  320. $tabular_menu.attr('data-write', $edit_content_zone.data('write'));
  321. $tabular_menu.attr('data-preview', $edit_content_zone.data('preview'));
  322. $tabular_menu.find('.write.item').attr('data-tab', $edit_content_zone.data('write'));
  323. $tabular_menu.find('.preview.item').attr('data-tab', $edit_content_zone.data('preview'));
  324. $edit_content_form.find('.write.segment').attr('data-tab', $edit_content_zone.data('write'));
  325. $edit_content_form.find('.preview.segment').attr('data-tab', $edit_content_zone.data('preview'));
  326. initCommentPreviewTab($edit_content_form);
  327. $edit_content_zone.find('.cancel.button').click(function () {
  328. $render_content.show();
  329. $edit_content_zone.hide();
  330. });
  331. $edit_content_zone.find('.save.button').click(function () {
  332. $render_content.show();
  333. $edit_content_zone.hide();
  334. $.post($edit_content_zone.data('update-url'), {
  335. "_csrf": csrf,
  336. "content": $textarea.val(),
  337. "context": $edit_content_zone.data('context')
  338. },
  339. function (data) {
  340. if (data.length == 0) {
  341. $render_content.html($('#no-content').html());
  342. } else {
  343. $render_content.html(data.content);
  344. emojify.run($render_content[0]);
  345. $('pre code', $render_content[0]).each(function (i, block) {
  346. hljs.highlightBlock(block);
  347. });
  348. }
  349. });
  350. });
  351. } else {
  352. $textarea = $segment.find('textarea');
  353. }
  354. // Show write/preview tab and copy raw content as needed
  355. $edit_content_zone.show();
  356. $render_content.hide();
  357. if ($textarea.val().length == 0) {
  358. $textarea.val($raw_content.text());
  359. }
  360. $textarea.focus();
  361. return false;
  362. });
  363. // Change status
  364. var $status_btn = $('#status-button');
  365. $('#content').keyup(function () {
  366. if ($(this).val().length == 0) {
  367. $status_btn.text($status_btn.data('status'))
  368. } else {
  369. $status_btn.text($status_btn.data('status-and-comment'))
  370. }
  371. });
  372. $status_btn.click(function () {
  373. $('#status').val($status_btn.data('status-val'));
  374. $('#comment-form').submit();
  375. });
  376. }
  377. // Diff
  378. if ($('.repository.diff').length > 0) {
  379. var $counter = $('.diff-counter');
  380. if ($counter.length >= 1) {
  381. $counter.each(function (i, item) {
  382. var $item = $(item);
  383. var addLine = $item.find('span[data-line].add').data("line");
  384. var delLine = $item.find('span[data-line].del').data("line");
  385. var addPercent = parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine)) * 100;
  386. $item.find(".bar .add").css("width", addPercent + "%");
  387. });
  388. }
  389. }
  390. // Quick start and repository home
  391. $('#repo-clone-ssh').click(function () {
  392. $('.clone-url').text($(this).data('link'));
  393. $('#repo-clone-url').val($(this).data('link'));
  394. $(this).addClass('blue');
  395. $('#repo-clone-https').removeClass('blue');
  396. localStorage.setItem('repo-clone-protocol', 'ssh');
  397. });
  398. $('#repo-clone-https').click(function () {
  399. $('.clone-url').text($(this).data('link'));
  400. $('#repo-clone-url').val($(this).data('link'));
  401. $(this).addClass('blue');
  402. $('#repo-clone-ssh').removeClass('blue');
  403. localStorage.setItem('repo-clone-protocol', 'https');
  404. });
  405. $('#repo-clone-url').click(function () {
  406. $(this).select();
  407. });
  408. // Pull request
  409. if ($('.repository.compare.pull').length > 0) {
  410. initFilterSearchDropdown('.choose.branch .dropdown');
  411. }
  412. }
  413. function initRepositoryCollaboration(){
  414. console.log('initRepositoryCollaboration');
  415. // Change collaborator access mode
  416. $('.access-mode.menu .item').click(function(){
  417. var $menu = $(this).parent();
  418. $.post($menu.data('url'), {
  419. "_csrf": csrf,
  420. "uid": $menu.data('uid'),
  421. "mode": $(this).data('value')
  422. })
  423. });
  424. }
  425. function initWiki() {
  426. if ($('.repository.wiki').length == 0) {
  427. return;
  428. }
  429. if ($('.repository.wiki.new').length > 0) {
  430. var $edit_area = $('#edit-area');
  431. var simplemde = new SimpleMDE({
  432. autoDownloadFontAwesome: false,
  433. element: $edit_area[0],
  434. previewRender: function (plainText, preview) { // Async method
  435. setTimeout(function () {
  436. // FIXME: still send render request when return back to edit mode
  437. $.post($edit_area.data('url'), {
  438. "_csrf": csrf,
  439. "mode": "gfm",
  440. "context": $edit_area.data('context'),
  441. "text": plainText
  442. },
  443. function (data) {
  444. preview.innerHTML = '<div class="markdown">' + data + '</div>';
  445. emojify.run($('.editor-preview')[0]);
  446. }
  447. );
  448. }, 0);
  449. return "Loading...";
  450. },
  451. renderingConfig: {
  452. singleLineBreaks: false
  453. },
  454. spellChecker: false,
  455. tabSize: 4,
  456. toolbar: ["bold", "italic", "strikethrough", "|",
  457. "heading", "heading-1", "heading-2", "heading-3", "|",
  458. "code", "quote", "|",
  459. "unordered-list", "ordered-list", "|",
  460. "link", "image", "horizontal-rule", "|",
  461. "preview", "fullscreen"]
  462. })
  463. }
  464. }
  465. function initOrganization() {
  466. if ($('.organization').length == 0) {
  467. return;
  468. }
  469. // Options
  470. if ($('.organization.settings.options').length > 0) {
  471. $('#org_name').keyup(function () {
  472. var $prompt_span = $('#org-name-change-prompt');
  473. if ($(this).val().toString().toLowerCase() != $(this).data('org-name').toString().toLowerCase()) {
  474. $prompt_span.show();
  475. } else {
  476. $prompt_span.hide();
  477. }
  478. });
  479. }
  480. }
  481. function initUserSettings() {
  482. console.log('initUserSettings');
  483. // Options
  484. if ($('.user.settings.profile').length > 0) {
  485. $('#username').keyup(function () {
  486. var $prompt_span = $('#name-change-prompt');
  487. if ($(this).val().toString().toLowerCase() != $(this).data('name').toString().toLowerCase()) {
  488. $prompt_span.show();
  489. } else {
  490. $prompt_span.hide();
  491. }
  492. });
  493. }
  494. }
  495. function initWebhook() {
  496. if ($('.new.webhook').length == 0) {
  497. return;
  498. }
  499. $('.events.checkbox input').change(function () {
  500. if ($(this).is(':checked')) {
  501. $('.events.fields').show();
  502. }
  503. });
  504. $('.non-events.checkbox input').change(function () {
  505. if ($(this).is(':checked')) {
  506. $('.events.fields').hide();
  507. }
  508. });
  509. // Test delivery
  510. $('#test-delivery').click(function () {
  511. var $this = $(this);
  512. $this.addClass('loading disabled');
  513. $.post($this.data('link'), {
  514. "_csrf": csrf
  515. }).done(
  516. setTimeout(function () {
  517. window.location.href = $this.data('redirect');
  518. }, 5000)
  519. )
  520. });
  521. }
  522. function initAdmin() {
  523. if ($('.admin').length == 0) {
  524. return;
  525. }
  526. // New user
  527. if ($('.admin.new.user').length > 0 ||
  528. $('.admin.edit.user').length > 0) {
  529. $('#login_type').change(function () {
  530. if ($(this).val().substring(0, 1) == '0') {
  531. $('#login_name').removeAttr('required');
  532. $('.non-local').hide();
  533. $('.local').show();
  534. $('#user_name').focus();
  535. if ($(this).data('password') == "required") {
  536. $('#password').attr('required', 'required');
  537. }
  538. } else {
  539. $('#login_name').attr('required', 'required');
  540. $('.non-local').show();
  541. $('.local').hide();
  542. $('#login_name').focus();
  543. $('#password').removeAttr('required');
  544. }
  545. });
  546. }
  547. // New authentication
  548. if ($('.admin.new.authentication').length > 0) {
  549. $('#auth_type').change(function () {
  550. $('.ldap').hide();
  551. $('.dldap').hide();
  552. $('.smtp').hide();
  553. $('.pam').hide();
  554. var auth_type = $(this).val();
  555. switch (auth_type) {
  556. case '2': // LDAP
  557. $('.ldap').show();
  558. break;
  559. case '3': // SMTP
  560. $('.smtp').show();
  561. break;
  562. case '4': // PAM
  563. $('.pam').show();
  564. break;
  565. case '5': // LDAP
  566. $('.dldap').show();
  567. break;
  568. }
  569. });
  570. }
  571. // Notice
  572. if ($('.admin.notice')) {
  573. var $detail_modal = $('#detail-modal');
  574. // Attach view detail modals
  575. $('.view-detail').click(function () {
  576. $detail_modal.find('.content p').text($(this).data('content'));
  577. $detail_modal.modal('show');
  578. return false;
  579. });
  580. // Select actions
  581. var $checkboxes = $('.select.table .ui.checkbox');
  582. $('.select.action').click(function () {
  583. switch ($(this).data('action')) {
  584. case 'select-all':
  585. $checkboxes.checkbox('check');
  586. break;
  587. case 'deselect-all':
  588. $checkboxes.checkbox('uncheck');
  589. break;
  590. case 'inverse':
  591. $checkboxes.checkbox('toggle');
  592. break;
  593. }
  594. });
  595. $('#delete-selection').click(function () {
  596. var $this = $(this);
  597. $this.addClass("loading disabled");
  598. var ids = [];
  599. $checkboxes.each(function () {
  600. if ($(this).checkbox('is checked')) {
  601. ids.push($(this).data('id'));
  602. }
  603. });
  604. $.post($this.data('link'), {
  605. "_csrf": csrf,
  606. "ids": ids
  607. }).done(function () {
  608. window.location.href = $this.data('redirect');
  609. });
  610. });
  611. }
  612. }
  613. function buttonsClickOnEnter() {
  614. $('.ui.button').keypress(function (e) {
  615. if (e.keyCode == 13 || e.keyCode == 32) // enter key or space bar
  616. $(this).click();
  617. });
  618. }
  619. function hideWhenLostFocus(body, parent) {
  620. $(document).click(function (e) {
  621. var target = e.target;
  622. if (!$(target).is(body) && !$(target).parents().is(parent)) {
  623. $(body).hide();
  624. }
  625. });
  626. }
  627. function searchUsers() {
  628. if (!$('#search-user-box .results').length) {
  629. return;
  630. }
  631. var $search_user_box = $('#search-user-box');
  632. var $result_list = $search_user_box.find('.results');
  633. $search_user_box.keyup(function () {
  634. var $this = $(this);
  635. var keyword = $this.find('input').val();
  636. if (keyword.length < 2) {
  637. $result_list.hide();
  638. return;
  639. }
  640. $.ajax({
  641. url: suburl + '/api/v1/users/search?q=' + keyword,
  642. dataType: "json",
  643. success: function (response) {
  644. var notEmpty = function (str) {
  645. return str && str.length > 0;
  646. };
  647. $result_list.html('');
  648. if (response.ok && response.data.length) {
  649. var html = '';
  650. $.each(response.data, function (i, item) {
  651. html += '<div class="item"><img class="ui avatar image" src="' + item.avatar_url + '"><span class="username">' + item.username + '</span>';
  652. if (notEmpty(item.full_name)) {
  653. html += ' (' + item.full_name + ')';
  654. }
  655. html += '</div>';
  656. });
  657. $result_list.html(html);
  658. $this.find('.results .item').click(function () {
  659. $this.find('input').val($(this).find('.username').text());
  660. $result_list.hide();
  661. });
  662. $result_list.show();
  663. } else {
  664. $result_list.hide();
  665. }
  666. }
  667. });
  668. });
  669. $search_user_box.find('input').focus(function () {
  670. $search_user_box.keyup();
  671. });
  672. hideWhenLostFocus('#search-user-box .results', '#search-user-box');
  673. }
  674. // FIXME: merge common parts in two functions
  675. function searchRepositories() {
  676. if (!$('#search-repo-box .results').length) {
  677. return;
  678. }
  679. var $search_repo_box = $('#search-repo-box');
  680. var $result_list = $search_repo_box.find('.results');
  681. $search_repo_box.keyup(function () {
  682. var $this = $(this);
  683. var keyword = $this.find('input').val();
  684. if (keyword.length < 2) {
  685. $result_list.hide();
  686. return;
  687. }
  688. $.ajax({
  689. url: suburl + '/api/v1/repos/search?q=' + keyword + "&uid=" + $search_repo_box.data('uid'),
  690. dataType: "json",
  691. success: function (response) {
  692. var notEmpty = function (str) {
  693. return str && str.length > 0;
  694. };
  695. $result_list.html('');
  696. if (response.ok && response.data.length) {
  697. var html = '';
  698. $.each(response.data, function (i, item) {
  699. html += '<div class="item"><i class="icon octicon octicon-repo"></i> <span class="fullname">' + item.full_name + '</span></div>';
  700. });
  701. $result_list.html(html);
  702. $this.find('.results .item').click(function () {
  703. $this.find('input').val($(this).find('.fullname').text().split("/")[1]);
  704. $result_list.hide();
  705. });
  706. $result_list.show();
  707. } else {
  708. $result_list.hide();
  709. }
  710. }
  711. });
  712. });
  713. $search_repo_box.find('input').focus(function () {
  714. $search_repo_box.keyup();
  715. });
  716. hideWhenLostFocus('#search-repo-box .results', '#search-repo-box');
  717. }
  718. $(document).ready(function () {
  719. csrf = $('meta[name=_csrf]').attr("content");
  720. suburl = $('meta[name=_suburl]').attr("content");
  721. // Show exact time
  722. $('.time-since').each(function () {
  723. $(this).addClass('poping up').attr('data-content', $(this).attr('title')).attr('data-variation', 'inverted tiny').attr('title', '');
  724. });
  725. // Semantic UI modules.
  726. $('.dropdown').dropdown();
  727. $('.jump.dropdown').dropdown({
  728. action: 'hide',
  729. onShow: function () {
  730. $('.poping.up').popup('hide');
  731. }
  732. });
  733. $('.slide.up.dropdown').dropdown({
  734. transition: 'slide up'
  735. });
  736. $('.upward.dropdown').dropdown({
  737. direction: 'upward'
  738. });
  739. $('.ui.accordion').accordion();
  740. $('.ui.checkbox').checkbox();
  741. $('.ui.progress').progress({
  742. showActivity: false
  743. });
  744. $('.poping.up').popup();
  745. $('.top.menu .poping.up').popup({
  746. onShow: function () {
  747. if ($('.top.menu .menu.transition').hasClass('visible')) {
  748. return false;
  749. }
  750. }
  751. });
  752. $('.tabular.menu .item').tab();
  753. $('.tabable.menu .item').tab();
  754. $('.toggle.button').click(function () {
  755. $($(this).data('target')).slideToggle(100);
  756. });
  757. // Highlight JS
  758. if (typeof hljs != 'undefined') {
  759. hljs.initHighlightingOnLoad();
  760. }
  761. // Dropzone
  762. if ($('#dropzone').length > 0) {
  763. // Disable auto discover for all elements:
  764. Dropzone.autoDiscover = false;
  765. var filenameDict = {};
  766. var $dropz = $('#dropzone');
  767. $dropz.dropzone({
  768. url: $dropz.data('upload-url'),
  769. headers: {"X-Csrf-Token": csrf},
  770. maxFiles: $dropz.data('max-file'),
  771. maxFilesize: $dropz.data('max-size'),
  772. acceptedFiles: ($dropz.data('accepts') === '*/*') ? null : $dropz.data('accepts'),
  773. addRemoveLinks: true,
  774. dictDefaultMessage: $dropz.data('default-message'),
  775. dictInvalidFileType: $dropz.data('invalid-input-type'),
  776. dictFileTooBig: $dropz.data('file-too-big'),
  777. dictRemoveFile: $dropz.data('remove-file'),
  778. init: function () {
  779. this.on("success", function (file, data) {
  780. filenameDict[file.name] = data.uuid;
  781. $('.attachments').append('<input id="' + data.uuid + '" name="attachments" type="hidden" value="' + data.uuid + '">');
  782. });
  783. this.on("removedfile", function (file) {
  784. if (file.name in filenameDict) {
  785. $('#' + filenameDict[file.name]).remove();
  786. }
  787. })
  788. }
  789. });
  790. }
  791. // Emojify
  792. emojify.setConfig({
  793. img_dir: suburl + '/img/emoji',
  794. ignore_emoticons: true
  795. });
  796. var hasEmoji = document.getElementsByClassName('has-emoji');
  797. for (var i = 0; i < hasEmoji.length; i++) {
  798. emojify.run(hasEmoji[i]);
  799. }
  800. // Clipboard JS
  801. var clipboard = new Clipboard('.clipboard');
  802. clipboard.on('success', function (e) {
  803. e.clearSelection();
  804. $('#' + e.trigger.getAttribute('id')).popup('destroy');
  805. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-success'))
  806. $('#' + e.trigger.getAttribute('id')).popup('show');
  807. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
  808. });
  809. clipboard.on('error', function (e) {
  810. $('#' + e.trigger.getAttribute('id')).popup('destroy');
  811. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-error'))
  812. $('#' + e.trigger.getAttribute('id')).popup('show');
  813. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
  814. });
  815. // Helpers.
  816. $('.delete-button').click(function () {
  817. var $this = $(this);
  818. $('.delete.modal').modal({
  819. closable: false,
  820. onApprove: function () {
  821. if ($this.data('type') == "form") {
  822. $($this.data('form')).submit();
  823. return;
  824. }
  825. $.post($this.data('url'), {
  826. "_csrf": csrf,
  827. "id": $this.data("id")
  828. }).done(function (data) {
  829. window.location.href = data.redirect;
  830. });
  831. }
  832. }).modal('show');
  833. return false;
  834. });
  835. $('.show-panel.button').click(function () {
  836. $($(this).data('panel')).show();
  837. });
  838. $('.show-modal.button').click(function () {
  839. $($(this).data('modal')).modal('show');
  840. });
  841. $('.delete-post.button').click(function(){
  842. var $this = $(this);
  843. $.post($this.data('request-url'),{
  844. "_csrf": csrf
  845. }).done(function(){
  846. window.location.href = $this.data('done-url');
  847. });
  848. });
  849. // Set anchor.
  850. $('.markdown').each(function () {
  851. var headers = {};
  852. $(this).find('h1, h2, h3, h4, h5, h6').each(function () {
  853. var node = $(this);
  854. var val = encodeURIComponent(node.text().toLowerCase().replace(/[^\w\- ]/g, '').replace(/[ ]/g, '-'));
  855. var name = val;
  856. if (headers[val] > 0) {
  857. name = val + '-' + headers[val];
  858. }
  859. if (headers[val] == undefined) {
  860. headers[val] = 1;
  861. } else {
  862. headers[val] += 1;
  863. }
  864. node = node.wrap('<div id="' + name + '" class="anchor-wrap" ></div>');
  865. node.append('<a class="anchor" href="#' + name + '"><span class="octicon octicon-link"></span></a>');
  866. });
  867. });
  868. buttonsClickOnEnter();
  869. searchUsers();
  870. searchRepositories();
  871. initCommentForm();
  872. initInstall();
  873. initRepository();
  874. initWiki();
  875. initOrganization();
  876. initWebhook();
  877. initAdmin();
  878. var routes = {
  879. 'div.user.settings': initUserSettings,
  880. 'div.repository.settings.collaboration': initRepositoryCollaboration
  881. };
  882. var selector;
  883. for (selector in routes) {
  884. if ($(selector).length > 0) {
  885. routes[selector]();
  886. break;
  887. }
  888. }
  889. });
  890. $(window).load(function () {
  891. function changeHash(hash) {
  892. if (history.pushState) {
  893. history.pushState(null, null, hash);
  894. }
  895. else {
  896. location.hash = hash;
  897. }
  898. }
  899. function deSelect() {
  900. if (window.getSelection) {
  901. window.getSelection().removeAllRanges();
  902. } else {
  903. document.selection.empty();
  904. }
  905. }
  906. function selectRange($list, $select, $from) {
  907. $list.removeClass('active');
  908. if ($from) {
  909. var a = parseInt($select.attr('rel').substr(1));
  910. var b = parseInt($from.attr('rel').substr(1));
  911. var c;
  912. if (a != b) {
  913. if (a > b) {
  914. c = a;
  915. a = b;
  916. b = c;
  917. }
  918. var classes = [];
  919. for (i = a; i <= b; i++) {
  920. classes.push('.L' + i);
  921. }
  922. $list.filter(classes.join(',')).addClass('active');
  923. changeHash('#L' + a + '-' + 'L' + b);
  924. return
  925. }
  926. }
  927. $select.addClass('active');
  928. changeHash('#' + $select.attr('rel'));
  929. }
  930. // Code view.
  931. if ($('.code-view .linenums').length > 0) {
  932. var $block = $('.code-view .linenums');
  933. var lines = $block.html().split("\n");
  934. $block.html('');
  935. var $num_list = $('.code-view .lines-num');
  936. // Building blocks.
  937. for (var i = 0; i < lines.length; i++) {
  938. $block.append('<li class="L' + (i + 1) + '" rel="L' + (i + 1) + '">' + lines[i] + '</li>');
  939. $num_list.append('<span id="L' + (i + 1) + '">' + (i + 1) + '</span>');
  940. }
  941. $(document).on('click', '.lines-num span', function (e) {
  942. var $select = $(this);
  943. var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
  944. selectRange($list, $list.filter('[rel=' + $select.attr('id') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
  945. deSelect();
  946. });
  947. $(window).on('hashchange', function (e) {
  948. var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
  949. var $list = $('.code-view ol.linenums > li');
  950. var $first;
  951. if (m) {
  952. $first = $list.filter('.' + m[1]);
  953. selectRange($list, $first, $list.filter('.' + m[2]));
  954. $("html, body").scrollTop($first.offset().top - 200);
  955. return;
  956. }
  957. m = window.location.hash.match(/^#(L\d+)$/);
  958. if (m) {
  959. $first = $list.filter('.' + m[1]);
  960. selectRange($list, $first);
  961. $("html, body").scrollTop($first.offset().top - 200);
  962. }
  963. }).trigger('hashchange');
  964. }
  965. // Repo clone url.
  966. if ($('#repo-clone-url').length > 0) {
  967. switch (localStorage.getItem('repo-clone-protocol')) {
  968. case 'ssh':
  969. if ($('#repo-clone-ssh').click().length === 0) {
  970. $('#repo-clone-https').click();
  971. }
  972. ;
  973. break;
  974. default:
  975. $('#repo-clone-https').click();
  976. break;
  977. }
  978. }
  979. });
PANIC: session(release): write data/sessions/e/b/ebd9f971c896d171: no space left on device

PANIC

session(release): write data/sessions/e/b/ebd9f971c896d171: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)