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.

index.js 90KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655
  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. // Listsubmit
  164. function initListSubmits(selector, outerSelector) {
  165. var $list = $('.ui.' + outerSelector + '.list');
  166. var $noSelect = $list.find('.no-select');
  167. var $listMenu = $('.' + selector + ' .menu');
  168. var hasLabelUpdateAction = $listMenu.data('action') == 'update';
  169. $('.' + selector).dropdown('setting', 'onHide', function(){
  170. hasLabelUpdateAction = $listMenu.data('action') == 'update'; // Update the var
  171. if (hasLabelUpdateAction) {
  172. location.reload();
  173. }
  174. });
  175. $listMenu.find('.item:not(.no-select)').click(function () {
  176. // we don't need the action attribute when updating assignees
  177. if (selector == 'select-assignees-modify') {
  178. // UI magic. We need to do this here, otherwise it would destroy the functionality of
  179. // adding/removing labels
  180. if ($(this).hasClass('checked')) {
  181. $(this).removeClass('checked');
  182. $(this).find('.octicon').removeClass('octicon-check');
  183. } else {
  184. $(this).addClass('checked');
  185. $(this).find('.octicon').addClass('octicon-check');
  186. }
  187. updateIssuesMeta(
  188. $listMenu.data('update-url'),
  189. "",
  190. $listMenu.data('issue-id'),
  191. $(this).data('id')
  192. );
  193. $listMenu.data('action', 'update'); // Update to reload the page when we updated items
  194. return false;
  195. }
  196. if ($(this).hasClass('checked')) {
  197. $(this).removeClass('checked');
  198. $(this).find('.octicon').removeClass('octicon-check');
  199. if (hasLabelUpdateAction) {
  200. updateIssuesMeta(
  201. $listMenu.data('update-url'),
  202. "detach",
  203. $listMenu.data('issue-id'),
  204. $(this).data('id')
  205. );
  206. }
  207. } else {
  208. $(this).addClass('checked');
  209. $(this).find('.octicon').addClass('octicon-check');
  210. if (hasLabelUpdateAction) {
  211. updateIssuesMeta(
  212. $listMenu.data('update-url'),
  213. "attach",
  214. $listMenu.data('issue-id'),
  215. $(this).data('id')
  216. );
  217. }
  218. }
  219. var listIds = [];
  220. $(this).parent().find('.item').each(function () {
  221. if ($(this).hasClass('checked')) {
  222. listIds.push($(this).data('id'));
  223. $($(this).data('id-selector')).removeClass('hide');
  224. } else {
  225. $($(this).data('id-selector')).addClass('hide');
  226. }
  227. });
  228. if (listIds.length == 0) {
  229. $noSelect.removeClass('hide');
  230. } else {
  231. $noSelect.addClass('hide');
  232. }
  233. $($(this).parent().data('id')).val(listIds.join(","));
  234. return false;
  235. });
  236. $listMenu.find('.no-select.item').click(function () {
  237. if (hasLabelUpdateAction || selector == 'select-assignees-modify') {
  238. updateIssuesMeta(
  239. $listMenu.data('update-url'),
  240. "clear",
  241. $listMenu.data('issue-id'),
  242. ""
  243. );
  244. $listMenu.data('action', 'update'); // Update to reload the page when we updated items
  245. }
  246. $(this).parent().find('.item').each(function () {
  247. $(this).removeClass('checked');
  248. $(this).find('.octicon').removeClass('octicon-check');
  249. });
  250. $list.find('.item').each(function () {
  251. $(this).addClass('hide');
  252. });
  253. $noSelect.removeClass('hide');
  254. $($(this).parent().data('id')).val('');
  255. });
  256. }
  257. // Init labels and assignees
  258. initListSubmits('select-label', 'labels');
  259. initListSubmits('select-assignees', 'assignees');
  260. initListSubmits('select-assignees-modify', 'assignees');
  261. function selectItem(select_id, input_id) {
  262. var $menu = $(select_id + ' .menu');
  263. var $list = $('.ui' + select_id + '.list');
  264. var hasUpdateAction = $menu.data('action') == 'update';
  265. $menu.find('.item:not(.no-select)').click(function () {
  266. $(this).parent().find('.item').each(function () {
  267. $(this).removeClass('selected active')
  268. });
  269. $(this).addClass('selected active');
  270. if (hasUpdateAction) {
  271. updateIssuesMeta(
  272. $menu.data('update-url'),
  273. "",
  274. $menu.data('issue-id'),
  275. $(this).data('id'),
  276. function() { location.reload(); }
  277. );
  278. }
  279. switch (input_id) {
  280. case '#milestone_id':
  281. $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
  282. $(this).text() + '</a>');
  283. break;
  284. case '#assignee_id':
  285. $list.find('.selected').html('<a class="item" href=' + $(this).data('href') + '>' +
  286. '<img class="ui avatar image" src=' + $(this).data('avatar') + '>' +
  287. $(this).text() + '</a>');
  288. }
  289. $('.ui' + select_id + '.list .no-select').addClass('hide');
  290. $(input_id).val($(this).data('id'));
  291. });
  292. $menu.find('.no-select.item').click(function () {
  293. $(this).parent().find('.item:not(.no-select)').each(function () {
  294. $(this).removeClass('selected active')
  295. });
  296. if (hasUpdateAction) {
  297. updateIssuesMeta(
  298. $menu.data('update-url'),
  299. "",
  300. $menu.data('issue-id'),
  301. $(this).data('id'),
  302. function() { location.reload(); }
  303. );
  304. }
  305. $list.find('.selected').html('');
  306. $list.find('.no-select').removeClass('hide');
  307. $(input_id).val('');
  308. });
  309. }
  310. // Milestone and assignee
  311. selectItem('.select-milestone', '#milestone_id');
  312. selectItem('.select-assignee', '#assignee_id');
  313. }
  314. function initInstall() {
  315. if ($('.install').length == 0) {
  316. return;
  317. }
  318. if ($('#db_host').val()=="") {
  319. $('#db_host').val("127.0.0.1:3306");
  320. $('#db_user').val("gitea");
  321. $('#db_name').val("gitea");
  322. }
  323. // Database type change detection.
  324. $("#db_type").change(function () {
  325. var sqliteDefault = 'data/gitea.db';
  326. var tidbDefault = 'data/gitea_tidb';
  327. var dbType = $(this).val();
  328. if (dbType === "SQLite3" || dbType === "TiDB") {
  329. $('#sql_settings').hide();
  330. $('#pgsql_settings').hide();
  331. $('#sqlite_settings').show();
  332. if (dbType === "SQLite3" && $('#db_path').val() == tidbDefault) {
  333. $('#db_path').val(sqliteDefault);
  334. } else if (dbType === "TiDB" && $('#db_path').val() == sqliteDefault) {
  335. $('#db_path').val(tidbDefault);
  336. }
  337. return;
  338. }
  339. var dbDefaults = {
  340. "MySQL": "127.0.0.1:3306",
  341. "PostgreSQL": "127.0.0.1:5432",
  342. "MSSQL": "127.0.0.1:1433"
  343. };
  344. $('#sqlite_settings').hide();
  345. $('#sql_settings').show();
  346. $('#pgsql_settings').toggle(dbType === "PostgreSQL");
  347. $.each(dbDefaults, function(type, defaultHost) {
  348. if ($('#db_host').val() == defaultHost) {
  349. $('#db_host').val(dbDefaults[dbType]);
  350. return false;
  351. }
  352. });
  353. });
  354. // TODO: better handling of exclusive relations.
  355. $('#offline-mode input').change(function () {
  356. if ($(this).is(':checked')) {
  357. $('#disable-gravatar').checkbox('check');
  358. $('#federated-avatar-lookup').checkbox('uncheck');
  359. }
  360. });
  361. $('#disable-gravatar input').change(function () {
  362. if ($(this).is(':checked')) {
  363. $('#federated-avatar-lookup').checkbox('uncheck');
  364. } else {
  365. $('#offline-mode').checkbox('uncheck');
  366. }
  367. });
  368. $('#federated-avatar-lookup input').change(function () {
  369. if ($(this).is(':checked')) {
  370. $('#disable-gravatar').checkbox('uncheck');
  371. $('#offline-mode').checkbox('uncheck');
  372. }
  373. });
  374. $('#enable-openid-signin input').change(function () {
  375. if ($(this).is(':checked')) {
  376. if ( $('#disable-registration input').is(':checked') ) {
  377. } else {
  378. $('#enable-openid-signup').checkbox('check');
  379. }
  380. } else {
  381. $('#enable-openid-signup').checkbox('uncheck');
  382. }
  383. });
  384. $('#disable-registration input').change(function () {
  385. if ($(this).is(':checked')) {
  386. $('#enable-captcha').checkbox('uncheck');
  387. $('#enable-openid-signup').checkbox('uncheck');
  388. } else {
  389. $('#enable-openid-signup').checkbox('check');
  390. }
  391. });
  392. $('#enable-captcha input').change(function () {
  393. if ($(this).is(':checked')) {
  394. $('#disable-registration').checkbox('uncheck');
  395. }
  396. });
  397. }
  398. function initRepository() {
  399. if ($('.repository').length == 0) {
  400. return;
  401. }
  402. function initFilterSearchDropdown(selector) {
  403. var $dropdown = $(selector);
  404. $dropdown.dropdown({
  405. fullTextSearch: true,
  406. selectOnKeydown: false,
  407. onChange: function (text, value, $choice) {
  408. if ($choice.data('url')) {
  409. window.location.href = $choice.data('url');
  410. }
  411. },
  412. message: {noResults: $dropdown.data('no-results')}
  413. });
  414. }
  415. // File list and commits
  416. if ($('.repository.file.list').length > 0 ||
  417. ('.repository.commits').length > 0) {
  418. initFilterBranchTagDropdown('.choose.reference .dropdown');
  419. }
  420. // Wiki
  421. if ($('.repository.wiki.view').length > 0) {
  422. initFilterSearchDropdown('.choose.page .dropdown');
  423. }
  424. // Options
  425. if ($('.repository.settings.options').length > 0) {
  426. $('#repo_name').keyup(function () {
  427. var $prompt = $('#repo-name-change-prompt');
  428. if ($(this).val().toString().toLowerCase() != $(this).data('repo-name').toString().toLowerCase()) {
  429. $prompt.show();
  430. } else {
  431. $prompt.hide();
  432. }
  433. });
  434. // Enable or select internal/external wiki system and issue tracker.
  435. $('.enable-system').change(function () {
  436. if (this.checked) {
  437. $($(this).data('target')).removeClass('disabled');
  438. if (!$(this).data('context')) $($(this).data('context')).addClass('disabled');
  439. } else {
  440. $($(this).data('target')).addClass('disabled');
  441. if (!$(this).data('context')) $($(this).data('context')).removeClass('disabled');
  442. }
  443. });
  444. $('.enable-system-radio').change(function () {
  445. if (this.value == 'false') {
  446. $($(this).data('target')).addClass('disabled');
  447. if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).removeClass('disabled');
  448. } else if (this.value == 'true') {
  449. $($(this).data('target')).removeClass('disabled');
  450. if (typeof $(this).data('context') !== 'undefined') $($(this).data('context')).addClass('disabled');
  451. }
  452. });
  453. }
  454. // Labels
  455. if ($('.repository.labels').length > 0) {
  456. // Create label
  457. var $newLabelPanel = $('.new-label.segment');
  458. $('.new-label.button').click(function () {
  459. $newLabelPanel.show();
  460. });
  461. $('.new-label.segment .cancel').click(function () {
  462. $newLabelPanel.hide();
  463. });
  464. $('.color-picker').each(function () {
  465. $(this).minicolors();
  466. });
  467. $('.precolors .color').click(function () {
  468. var color_hex = $(this).data('color-hex');
  469. $('.color-picker').val(color_hex);
  470. $('.minicolors-swatch-color').css("background-color", color_hex);
  471. });
  472. $('.edit-label-button').click(function () {
  473. $('#label-modal-id').val($(this).data('id'));
  474. $('.edit-label .new-label-input').val($(this).data('title'));
  475. $('.edit-label .new-label-desc-input').val($(this).data('description'));
  476. $('.edit-label .color-picker').val($(this).data('color'));
  477. $('.minicolors-swatch-color').css("background-color", $(this).data('color'));
  478. $('.edit-label.modal').modal({
  479. onApprove: function () {
  480. $('.edit-label.form').submit();
  481. }
  482. }).modal('show');
  483. return false;
  484. });
  485. }
  486. // Milestones
  487. if ($('.repository.milestones').length > 0) {
  488. }
  489. if ($('.repository.new.milestone').length > 0) {
  490. var $datepicker = $('.milestone.datepicker');
  491. $datepicker.datetimepicker({
  492. lang: $datepicker.data('lang'),
  493. inline: true,
  494. timepicker: false,
  495. startDate: $datepicker.data('start-date'),
  496. formatDate: 'Y-m-d',
  497. onSelectDate: function (ct) {
  498. $('#deadline').val(ct.dateFormat('Y-m-d'));
  499. }
  500. });
  501. $('#clear-date').click(function () {
  502. $('#deadline').val('');
  503. return false;
  504. });
  505. }
  506. // Issues
  507. if ($('.repository.view.issue').length > 0) {
  508. // Edit issue title
  509. var $issueTitle = $('#issue-title');
  510. var $editInput = $('#edit-title-input input');
  511. var editTitleToggle = function () {
  512. $issueTitle.toggle();
  513. $('.not-in-edit').toggle();
  514. $('#edit-title-input').toggle();
  515. $('.in-edit').toggle();
  516. $editInput.focus();
  517. return false;
  518. };
  519. $('#edit-title').click(editTitleToggle);
  520. $('#cancel-edit-title').click(editTitleToggle);
  521. $('#save-edit-title').click(editTitleToggle).click(function () {
  522. if ($editInput.val().length == 0 ||
  523. $editInput.val() == $issueTitle.text()) {
  524. $editInput.val($issueTitle.text());
  525. return false;
  526. }
  527. $.post($(this).data('update-url'), {
  528. "_csrf": csrf,
  529. "title": $editInput.val()
  530. },
  531. function (data) {
  532. $editInput.val(data.title);
  533. $issueTitle.text(data.title);
  534. location.reload();
  535. });
  536. return false;
  537. });
  538. // Edit issue or comment content
  539. $('.edit-content').click(function () {
  540. var $segment = $(this).parent().parent().parent().next();
  541. var $editContentZone = $segment.find('.edit-content-zone');
  542. var $renderContent = $segment.find('.render-content');
  543. var $rawContent = $segment.find('.raw-content');
  544. var $textarea;
  545. // Setup new form
  546. if ($editContentZone.html().length == 0) {
  547. $editContentZone.html($('#edit-content-form').html());
  548. $textarea = $('#content');
  549. issuesTribute.attach($textarea.get());
  550. emojiTribute.attach($textarea.get());
  551. // Give new write/preview data-tab name to distinguish from others
  552. var $editContentForm = $editContentZone.find('.ui.comment.form');
  553. var $tabMenu = $editContentForm.find('.tabular.menu');
  554. $tabMenu.attr('data-write', $editContentZone.data('write'));
  555. $tabMenu.attr('data-preview', $editContentZone.data('preview'));
  556. $tabMenu.find('.write.item').attr('data-tab', $editContentZone.data('write'));
  557. $tabMenu.find('.preview.item').attr('data-tab', $editContentZone.data('preview'));
  558. $editContentForm.find('.write.segment').attr('data-tab', $editContentZone.data('write'));
  559. $editContentForm.find('.preview.segment').attr('data-tab', $editContentZone.data('preview'));
  560. initCommentPreviewTab($editContentForm);
  561. $editContentZone.find('.cancel.button').click(function () {
  562. $renderContent.show();
  563. $editContentZone.hide();
  564. });
  565. $editContentZone.find('.save.button').click(function () {
  566. $renderContent.show();
  567. $editContentZone.hide();
  568. $.post($editContentZone.data('update-url'), {
  569. "_csrf": csrf,
  570. "content": $textarea.val(),
  571. "context": $editContentZone.data('context')
  572. },
  573. function (data) {
  574. if (data.length == 0) {
  575. $renderContent.html($('#no-content').html());
  576. } else {
  577. $renderContent.html(data.content);
  578. emojify.run($renderContent[0]);
  579. $('pre code', $renderContent[0]).each(function (i, block) {
  580. hljs.highlightBlock(block);
  581. });
  582. }
  583. });
  584. });
  585. } else {
  586. $textarea = $segment.find('textarea');
  587. }
  588. // Show write/preview tab and copy raw content as needed
  589. $editContentZone.show();
  590. $renderContent.hide();
  591. if ($textarea.val().length == 0) {
  592. $textarea.val($rawContent.text());
  593. }
  594. $textarea.focus();
  595. return false;
  596. });
  597. // Delete comment
  598. $('.delete-comment').click(function () {
  599. var $this = $(this);
  600. if (confirm($this.data('locale'))) {
  601. $.post($this.data('url'), {
  602. "_csrf": csrf
  603. }).success(function () {
  604. $('#' + $this.data('comment-id')).remove();
  605. });
  606. }
  607. return false;
  608. });
  609. // Change status
  610. var $statusButton = $('#status-button');
  611. $('#comment-form .edit_area').keyup(function () {
  612. if ($(this).val().length == 0) {
  613. $statusButton.text($statusButton.data('status'))
  614. } else {
  615. $statusButton.text($statusButton.data('status-and-comment'))
  616. }
  617. });
  618. $statusButton.click(function () {
  619. $('#status').val($statusButton.data('status-val'));
  620. $('#comment-form').submit();
  621. });
  622. // Pull Request merge button
  623. var $mergeButton = $('.merge-button > button');
  624. $mergeButton.on('click', function(e) {
  625. e.preventDefault();
  626. $('.' + $(this).data('do') + '-fields').show();
  627. $(this).parent().hide();
  628. });
  629. $('.merge-button > .dropdown').dropdown({
  630. onChange: function (text, value, $choice) {
  631. if ($choice.data('do')) {
  632. $mergeButton.find('.button-text').text($choice.text());
  633. $mergeButton.data('do', $choice.data('do'));
  634. }
  635. }
  636. });
  637. $('.merge-cancel').on('click', function(e) {
  638. e.preventDefault();
  639. $(this).closest('.form').hide();
  640. $mergeButton.parent().show();
  641. });
  642. initReactionSelector();
  643. }
  644. // Diff
  645. if ($('.repository.diff').length > 0) {
  646. var $counter = $('.diff-counter');
  647. if ($counter.length >= 1) {
  648. $counter.each(function (i, item) {
  649. var $item = $(item);
  650. var addLine = $item.find('span[data-line].add').data("line");
  651. var delLine = $item.find('span[data-line].del').data("line");
  652. var addPercent = parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine)) * 100;
  653. $item.find(".bar .add").css("width", addPercent + "%");
  654. });
  655. }
  656. }
  657. // Quick start and repository home
  658. $('#repo-clone-ssh').click(function () {
  659. $('.clone-url').text($(this).data('link'));
  660. $('#repo-clone-url').val($(this).data('link'));
  661. $(this).addClass('blue');
  662. $('#repo-clone-https').removeClass('blue');
  663. localStorage.setItem('repo-clone-protocol', 'ssh');
  664. });
  665. $('#repo-clone-https').click(function () {
  666. $('.clone-url').text($(this).data('link'));
  667. $('#repo-clone-url').val($(this).data('link'));
  668. $(this).addClass('blue');
  669. $('#repo-clone-ssh').removeClass('blue');
  670. localStorage.setItem('repo-clone-protocol', 'https');
  671. });
  672. $('#repo-clone-url').click(function () {
  673. $(this).select();
  674. });
  675. // Pull request
  676. if ($('.repository.compare.pull').length > 0) {
  677. initFilterSearchDropdown('.choose.branch .dropdown');
  678. }
  679. // Branches
  680. if ($('.repository.settings.branches').length > 0) {
  681. initFilterSearchDropdown('.protected-branches .dropdown');
  682. $('.enable-protection, .enable-whitelist').change(function () {
  683. if (this.checked) {
  684. $($(this).data('target')).removeClass('disabled');
  685. } else {
  686. $($(this).data('target')).addClass('disabled');
  687. }
  688. });
  689. }
  690. }
  691. function initPullRequestReview() {
  692. $('.show-outdated').on('click', function (e) {
  693. e.preventDefault();
  694. var id = $(this).data('comment');
  695. $(this).addClass("hide");
  696. $("#code-comments-" + id).removeClass('hide');
  697. $("#code-preview-" + id).removeClass('hide');
  698. $("#hide-outdated-" + id).removeClass('hide');
  699. });
  700. $('.hide-outdated').on('click', function (e) {
  701. e.preventDefault();
  702. var id = $(this).data('comment');
  703. $(this).addClass("hide");
  704. $("#code-comments-" + id).addClass('hide');
  705. $("#code-preview-" + id).addClass('hide');
  706. $("#show-outdated-" + id).removeClass('hide');
  707. });
  708. $('button.comment-form-reply').on('click', function (e) {
  709. e.preventDefault();
  710. $(this).hide();
  711. var form = $(this).parent().find('.comment-form')
  712. form.removeClass('hide');
  713. assingMenuAttributes(form.find('.menu'));
  714. });
  715. // The following part is only for diff views
  716. if ($('.repository.pull.diff').length == 0) {
  717. return;
  718. }
  719. $('.diff-detail-box.ui.sticky').sticky();
  720. $('.btn-review').on('click', function(e) {
  721. e.preventDefault();
  722. $(this).closest('.dropdown').find('.menu').toggle('visible');
  723. }).closest('.dropdown').find('.link.close').on('click', function(e) {
  724. e.preventDefault();
  725. $(this).closest('.menu').toggle('visible');
  726. });
  727. $('.code-view .lines-code,.code-view .lines-num')
  728. .on('mouseenter', function() {
  729. var parent = $(this).closest('td');
  730. $(this).closest('tr').addClass(
  731. parent.hasClass('lines-num-old') || parent.hasClass('lines-code-old')
  732. ? 'focus-lines-old' : 'focus-lines-new'
  733. );
  734. })
  735. .on('mouseleave', function() {
  736. $(this).closest('tr').removeClass('focus-lines-new focus-lines-old');
  737. });
  738. $('.add-code-comment').on('click', function(e) {
  739. e.preventDefault();
  740. var isSplit = $(this).closest('.code-diff').hasClass('code-diff-split');
  741. var side = $(this).data('side');
  742. var idx = $(this).data('idx');
  743. var path = $(this).data('path');
  744. var form = $('#pull_review_add_comment').html();
  745. var tr = $(this).closest('tr');
  746. var ntr = tr.next();
  747. if (!ntr.hasClass('add-comment')) {
  748. ntr = $('<tr class="add-comment">'
  749. + (isSplit ? '<td class="lines-num"></td><td class="add-comment-left"></td><td class="lines-num"></td><td class="add-comment-right"></td>'
  750. : '<td class="lines-num"></td><td class="lines-num"></td><td class="add-comment-left add-comment-right"></td>')
  751. + '</tr>');
  752. tr.after(ntr);
  753. }
  754. var td = ntr.find('.add-comment-' + side);
  755. var commentCloud = td.find('.comment-code-cloud');
  756. if (commentCloud.length === 0) {
  757. td.html(form);
  758. commentCloud = td.find('.comment-code-cloud');
  759. assingMenuAttributes(commentCloud.find('.menu'));
  760. td.find("input[name='line']").val(idx);
  761. td.find("input[name='side']").val(side === "left" ? "previous":"proposed");
  762. td.find("input[name='path']").val(path);
  763. }
  764. commentCloud.find('textarea').focus();
  765. });
  766. }
  767. function assingMenuAttributes(menu) {
  768. var id = Math.floor(Math.random() * Math.floor(1000000));
  769. menu.attr('data-write', menu.attr('data-write') + id);
  770. menu.attr('data-preview', menu.attr('data-preview') + id);
  771. menu.find('.item').each(function(i, item) {
  772. $(item).attr('data-tab', $(item).attr('data-tab') + id);
  773. });
  774. menu.parent().find("*[data-tab='write']").attr('data-tab', 'write' + id);
  775. menu.parent().find("*[data-tab='preview']").attr('data-tab', 'preview' + id);
  776. initCommentPreviewTab(menu.parent(".form"));
  777. return id;
  778. }
  779. function initRepositoryCollaboration() {
  780. // Change collaborator access mode
  781. $('.access-mode.menu .item').click(function () {
  782. var $menu = $(this).parent();
  783. $.post($menu.data('url'), {
  784. "_csrf": csrf,
  785. "uid": $menu.data('uid'),
  786. "mode": $(this).data('value')
  787. })
  788. });
  789. }
  790. function initTeamSettings() {
  791. // Change team access mode
  792. $('.organization.new.team input[name=permission]').change(function () {
  793. var val = $('input[name=permission]:checked', '.organization.new.team').val()
  794. if (val === 'admin') {
  795. $('.organization.new.team .team-units').hide();
  796. } else {
  797. $('.organization.new.team .team-units').show();
  798. }
  799. });
  800. }
  801. function initWikiForm() {
  802. var $editArea = $('.repository.wiki textarea#edit_area');
  803. if ($editArea.length > 0) {
  804. var simplemde = new SimpleMDE({
  805. autoDownloadFontAwesome: false,
  806. element: $editArea[0],
  807. forceSync: true,
  808. previewRender: function (plainText, preview) { // Async method
  809. setTimeout(function () {
  810. // FIXME: still send render request when return back to edit mode
  811. $.post($editArea.data('url'), {
  812. "_csrf": csrf,
  813. "mode": "gfm",
  814. "context": $editArea.data('context'),
  815. "text": plainText
  816. },
  817. function (data) {
  818. preview.innerHTML = '<div class="markdown">' + data + '</div>';
  819. emojify.run($('.editor-preview')[0]);
  820. }
  821. );
  822. }, 0);
  823. return "Loading...";
  824. },
  825. renderingConfig: {
  826. singleLineBreaks: false
  827. },
  828. indentWithTabs: false,
  829. tabSize: 4,
  830. spellChecker: false,
  831. toolbar: ["bold", "italic", "strikethrough", "|",
  832. "heading-1", "heading-2", "heading-3", "heading-bigger", "heading-smaller", "|",
  833. "code", "quote", "|",
  834. "unordered-list", "ordered-list", "|",
  835. "link", "image", "table", "horizontal-rule", "|",
  836. "clean-block", "preview", "fullscreen"]
  837. })
  838. $(simplemde.codemirror.getInputField()).addClass("js-quick-submit");
  839. }
  840. }
  841. var simpleMDEditor;
  842. var codeMirrorEditor;
  843. // For IE
  844. String.prototype.endsWith = function (pattern) {
  845. var d = this.length - pattern.length;
  846. return d >= 0 && this.lastIndexOf(pattern) === d;
  847. };
  848. // Adding function to get the cursor position in a text field to jQuery object.
  849. (function ($, undefined) {
  850. $.fn.getCursorPosition = function () {
  851. var el = $(this).get(0);
  852. var pos = 0;
  853. if ('selectionStart' in el) {
  854. pos = el.selectionStart;
  855. } else if ('selection' in document) {
  856. el.focus();
  857. var Sel = document.selection.createRange();
  858. var SelLength = document.selection.createRange().text.length;
  859. Sel.moveStart('character', -el.value.length);
  860. pos = Sel.text.length - SelLength;
  861. }
  862. return pos;
  863. }
  864. })(jQuery);
  865. function setSimpleMDE($editArea) {
  866. if (codeMirrorEditor) {
  867. codeMirrorEditor.toTextArea();
  868. codeMirrorEditor = null;
  869. }
  870. if (simpleMDEditor) {
  871. return true;
  872. }
  873. simpleMDEditor = new SimpleMDE({
  874. autoDownloadFontAwesome: false,
  875. element: $editArea[0],
  876. forceSync: true,
  877. renderingConfig: {
  878. singleLineBreaks: false
  879. },
  880. indentWithTabs: false,
  881. tabSize: 4,
  882. spellChecker: false,
  883. previewRender: function (plainText, preview) { // Async method
  884. setTimeout(function () {
  885. // FIXME: still send render request when return back to edit mode
  886. $.post($editArea.data('url'), {
  887. "_csrf": csrf,
  888. "mode": "gfm",
  889. "context": $editArea.data('context'),
  890. "text": plainText
  891. },
  892. function (data) {
  893. preview.innerHTML = '<div class="markdown">' + data + '</div>';
  894. emojify.run($('.editor-preview')[0]);
  895. }
  896. );
  897. }, 0);
  898. return "Loading...";
  899. },
  900. toolbar: ["bold", "italic", "strikethrough", "|",
  901. "heading-1", "heading-2", "heading-3", "heading-bigger", "heading-smaller", "|",
  902. "code", "quote", "|",
  903. "unordered-list", "ordered-list", "|",
  904. "link", "image", "table", "horizontal-rule", "|",
  905. "clean-block", "preview", "fullscreen", "side-by-side"]
  906. });
  907. return true;
  908. }
  909. function setCodeMirror($editArea) {
  910. if (simpleMDEditor) {
  911. simpleMDEditor.toTextArea();
  912. simpleMDEditor = null;
  913. }
  914. if (codeMirrorEditor) {
  915. return true;
  916. }
  917. codeMirrorEditor = CodeMirror.fromTextArea($editArea[0], {
  918. lineNumbers: true
  919. });
  920. codeMirrorEditor.on("change", function (cm, change) {
  921. $editArea.val(cm.getValue());
  922. });
  923. return true;
  924. }
  925. function initEditor() {
  926. $('.js-quick-pull-choice-option').change(function () {
  927. if ($(this).val() == 'commit-to-new-branch') {
  928. $('.quick-pull-branch-name').show();
  929. $('.quick-pull-branch-name input').prop('required',true);
  930. } else {
  931. $('.quick-pull-branch-name').hide();
  932. $('.quick-pull-branch-name input').prop('required',false);
  933. }
  934. });
  935. var $editFilename = $("#file-name");
  936. $editFilename.keyup(function (e) {
  937. var $section = $('.breadcrumb span.section');
  938. var $divider = $('.breadcrumb div.divider');
  939. if (e.keyCode == 8) {
  940. if ($(this).getCursorPosition() == 0) {
  941. if ($section.length > 0) {
  942. var value = $section.last().find('a').text();
  943. $(this).val(value + $(this).val());
  944. $(this)[0].setSelectionRange(value.length, value.length);
  945. $section.last().remove();
  946. $divider.last().remove();
  947. }
  948. }
  949. }
  950. if (e.keyCode == 191) {
  951. var parts = $(this).val().split('/');
  952. for (var i = 0; i < parts.length; ++i) {
  953. var value = parts[i];
  954. if (i < parts.length - 1) {
  955. if (value.length) {
  956. $('<span class="section"><a href="#">' + value + '</a></span>').insertBefore($(this));
  957. $('<div class="divider"> / </div>').insertBefore($(this));
  958. }
  959. }
  960. else {
  961. $(this).val(value);
  962. }
  963. $(this)[0].setSelectionRange(0, 0);
  964. }
  965. }
  966. var parts = [];
  967. $('.breadcrumb span.section').each(function (i, element) {
  968. element = $(element);
  969. if (element.find('a').length) {
  970. parts.push(element.find('a').text());
  971. } else {
  972. parts.push(element.text());
  973. }
  974. });
  975. if ($(this).val())
  976. parts.push($(this).val());
  977. $('#tree_path').val(parts.join('/'));
  978. }).trigger('keyup');
  979. var $editArea = $('.repository.editor textarea#edit_area');
  980. if (!$editArea.length)
  981. return;
  982. var markdownFileExts = $editArea.data("markdown-file-exts").split(",");
  983. var lineWrapExtensions = $editArea.data("line-wrap-extensions").split(",");
  984. $editFilename.on("keyup", function (e) {
  985. var val = $editFilename.val(), m, mode, spec, extension, extWithDot, previewLink, dataUrl, apiCall;
  986. extension = extWithDot = "";
  987. if (m = /.+\.([^.]+)$/.exec(val)) {
  988. extension = m[1];
  989. extWithDot = "." + extension;
  990. }
  991. var info = CodeMirror.findModeByExtension(extension);
  992. previewLink = $('a[data-tab=preview]');
  993. if (info) {
  994. mode = info.mode;
  995. spec = info.mime;
  996. apiCall = mode;
  997. }
  998. else {
  999. apiCall = extension
  1000. }
  1001. if (previewLink.length && apiCall && previewFileModes && previewFileModes.length && previewFileModes.indexOf(apiCall) >= 0) {
  1002. dataUrl = previewLink.data('url');
  1003. previewLink.data('url', dataUrl.replace(/(.*)\/.*/i, '$1/' + mode));
  1004. previewLink.show();
  1005. }
  1006. else {
  1007. previewLink.hide();
  1008. }
  1009. // If this file is a Markdown extensions, we will load that editor and return
  1010. if (markdownFileExts.indexOf(extWithDot) >= 0) {
  1011. if (setSimpleMDE($editArea)) {
  1012. return;
  1013. }
  1014. }
  1015. // Else we are going to use CodeMirror
  1016. if (!codeMirrorEditor && !setCodeMirror($editArea)) {
  1017. return;
  1018. }
  1019. if (mode) {
  1020. codeMirrorEditor.setOption("mode", spec);
  1021. CodeMirror.autoLoadMode(codeMirrorEditor, mode);
  1022. }
  1023. if (lineWrapExtensions.indexOf(extWithDot) >= 0) {
  1024. codeMirrorEditor.setOption("lineWrapping", true);
  1025. }
  1026. else {
  1027. codeMirrorEditor.setOption("lineWrapping", false);
  1028. }
  1029. // get the filename without any folder
  1030. var value = $editFilename.val();
  1031. if (value.length === 0) {
  1032. return;
  1033. }
  1034. value = value.split('/');
  1035. value = value[value.length - 1];
  1036. $.getJSON($editFilename.data('ec-url-prefix')+value, function(editorconfig) {
  1037. if (editorconfig.indent_style === 'tab') {
  1038. codeMirrorEditor.setOption("indentWithTabs", true);
  1039. codeMirrorEditor.setOption('extraKeys', {});
  1040. } else {
  1041. codeMirrorEditor.setOption("indentWithTabs", false);
  1042. // required because CodeMirror doesn't seems to use spaces correctly for {"indentWithTabs": false}:
  1043. // - https://github.com/codemirror/CodeMirror/issues/988
  1044. // - https://codemirror.net/doc/manual.html#keymaps
  1045. codeMirrorEditor.setOption('extraKeys', {
  1046. Tab: function(cm) {
  1047. var spaces = Array(parseInt(cm.getOption("indentUnit")) + 1).join(" ");
  1048. cm.replaceSelection(spaces);
  1049. }
  1050. });
  1051. }
  1052. codeMirrorEditor.setOption("indentUnit", editorconfig.indent_size || 4);
  1053. codeMirrorEditor.setOption("tabSize", editorconfig.tab_width || 4);
  1054. });
  1055. }).trigger('keyup');
  1056. }
  1057. function initOrganization() {
  1058. if ($('.organization').length == 0) {
  1059. return;
  1060. }
  1061. // Options
  1062. if ($('.organization.settings.options').length > 0) {
  1063. $('#org_name').keyup(function () {
  1064. var $prompt = $('#org-name-change-prompt');
  1065. if ($(this).val().toString().toLowerCase() != $(this).data('org-name').toString().toLowerCase()) {
  1066. $prompt.show();
  1067. } else {
  1068. $prompt.hide();
  1069. }
  1070. });
  1071. }
  1072. }
  1073. function initUserSettings() {
  1074. // Options
  1075. if ($('.user.settings.profile').length > 0) {
  1076. $('#username').keyup(function () {
  1077. var $prompt = $('#name-change-prompt');
  1078. if ($(this).val().toString().toLowerCase() != $(this).data('name').toString().toLowerCase()) {
  1079. $prompt.show();
  1080. } else {
  1081. $prompt.hide();
  1082. }
  1083. });
  1084. }
  1085. }
  1086. function initWebhook() {
  1087. if ($('.new.webhook').length == 0) {
  1088. return;
  1089. }
  1090. $('.events.checkbox input').change(function () {
  1091. if ($(this).is(':checked')) {
  1092. $('.events.fields').show();
  1093. }
  1094. });
  1095. $('.non-events.checkbox input').change(function () {
  1096. if ($(this).is(':checked')) {
  1097. $('.events.fields').hide();
  1098. }
  1099. });
  1100. // Test delivery
  1101. $('#test-delivery').click(function () {
  1102. var $this = $(this);
  1103. $this.addClass('loading disabled');
  1104. $.post($this.data('link'), {
  1105. "_csrf": csrf
  1106. }).done(
  1107. setTimeout(function () {
  1108. window.location.href = $this.data('redirect');
  1109. }, 5000)
  1110. )
  1111. });
  1112. }
  1113. function initAdmin() {
  1114. if ($('.admin').length == 0) {
  1115. return;
  1116. }
  1117. // New user
  1118. if ($('.admin.new.user').length > 0 ||
  1119. $('.admin.edit.user').length > 0) {
  1120. $('#login_type').change(function () {
  1121. if ($(this).val().substring(0, 1) == '0') {
  1122. $('#login_name').removeAttr('required');
  1123. $('.non-local').hide();
  1124. $('.local').show();
  1125. $('#user_name').focus();
  1126. if ($(this).data('password') == "required") {
  1127. $('#password').attr('required', 'required');
  1128. }
  1129. } else {
  1130. $('#login_name').attr('required', 'required');
  1131. $('.non-local').show();
  1132. $('.local').hide();
  1133. $('#login_name').focus();
  1134. $('#password').removeAttr('required');
  1135. }
  1136. });
  1137. }
  1138. function onSecurityProtocolChange() {
  1139. if ($('#security_protocol').val() > 0) {
  1140. $('.has-tls').show();
  1141. } else {
  1142. $('.has-tls').hide();
  1143. }
  1144. }
  1145. function onUsePagedSearchChange() {
  1146. if ($('#use_paged_search').prop('checked')) {
  1147. $('.search-page-size').show()
  1148. .find('input').attr('required', 'required');
  1149. } else {
  1150. $('.search-page-size').hide()
  1151. .find('input').removeAttr('required');
  1152. }
  1153. }
  1154. function onOAuth2Change() {
  1155. $('.open_id_connect_auto_discovery_url, .oauth2_use_custom_url').hide();
  1156. $('.open_id_connect_auto_discovery_url input[required]').removeAttr('required');
  1157. var provider = $('#oauth2_provider').val();
  1158. switch (provider) {
  1159. case 'github':
  1160. case 'gitlab':
  1161. $('.oauth2_use_custom_url').show();
  1162. break;
  1163. case 'openidConnect':
  1164. $('.open_id_connect_auto_discovery_url input').attr('required', 'required');
  1165. $('.open_id_connect_auto_discovery_url').show();
  1166. break;
  1167. }
  1168. onOAuth2UseCustomURLChange();
  1169. }
  1170. function onOAuth2UseCustomURLChange() {
  1171. var provider = $('#oauth2_provider').val();
  1172. $('.oauth2_use_custom_url_field').hide();
  1173. $('.oauth2_use_custom_url_field input[required]').removeAttr('required');
  1174. if ($('#oauth2_use_custom_url').is(':checked')) {
  1175. if (!$('#oauth2_token_url').val()) {
  1176. $('#oauth2_token_url').val($('#' + provider + '_token_url').val());
  1177. }
  1178. if (!$('#oauth2_auth_url').val()) {
  1179. $('#oauth2_auth_url').val($('#' + provider + '_auth_url').val());
  1180. }
  1181. if (!$('#oauth2_profile_url').val()) {
  1182. $('#oauth2_profile_url').val($('#' + provider + '_profile_url').val());
  1183. }
  1184. if (!$('#oauth2_email_url').val()) {
  1185. $('#oauth2_email_url').val($('#' + provider + '_email_url').val());
  1186. }
  1187. switch (provider) {
  1188. case 'github':
  1189. $('.oauth2_token_url input, .oauth2_auth_url input, .oauth2_profile_url input, .oauth2_email_url input').attr('required', 'required');
  1190. $('.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url, .oauth2_email_url').show();
  1191. break;
  1192. case 'gitlab':
  1193. $('.oauth2_token_url input, .oauth2_auth_url input, .oauth2_profile_url input').attr('required', 'required');
  1194. $('.oauth2_token_url, .oauth2_auth_url, .oauth2_profile_url').show();
  1195. $('#oauth2_email_url').val('');
  1196. break;
  1197. }
  1198. }
  1199. }
  1200. // New authentication
  1201. if ($('.admin.new.authentication').length > 0) {
  1202. $('#auth_type').change(function () {
  1203. $('.ldap, .dldap, .smtp, .pam, .oauth2, .has-tls .search-page-size').hide();
  1204. $('.ldap input[required], .dldap input[required], .smtp input[required], .pam input[required], .oauth2 input[required], .has-tls input[required]').removeAttr('required');
  1205. var authType = $(this).val();
  1206. switch (authType) {
  1207. case '2': // LDAP
  1208. $('.ldap').show();
  1209. $('.ldap div.required:not(.dldap) input').attr('required', 'required');
  1210. break;
  1211. case '3': // SMTP
  1212. $('.smtp').show();
  1213. $('.has-tls').show();
  1214. $('.smtp div.required input, .has-tls').attr('required', 'required');
  1215. break;
  1216. case '4': // PAM
  1217. $('.pam').show();
  1218. $('.pam input').attr('required', 'required');
  1219. break;
  1220. case '5': // LDAP
  1221. $('.dldap').show();
  1222. $('.dldap div.required:not(.ldap) input').attr('required', 'required');
  1223. break;
  1224. case '6': // OAuth2
  1225. $('.oauth2').show();
  1226. $('.oauth2 div.required:not(.oauth2_use_custom_url,.oauth2_use_custom_url_field,.open_id_connect_auto_discovery_url) input').attr('required', 'required');
  1227. onOAuth2Change();
  1228. break;
  1229. }
  1230. if (authType == '2' || authType == '5') {
  1231. onSecurityProtocolChange()
  1232. }
  1233. if (authType == '2') {
  1234. onUsePagedSearchChange();
  1235. }
  1236. });
  1237. $('#auth_type').change();
  1238. $('#security_protocol').change(onSecurityProtocolChange);
  1239. $('#use_paged_search').change(onUsePagedSearchChange);
  1240. $('#oauth2_provider').change(onOAuth2Change);
  1241. $('#oauth2_use_custom_url').change(onOAuth2UseCustomURLChange);
  1242. }
  1243. // Edit authentication
  1244. if ($('.admin.edit.authentication').length > 0) {
  1245. var authType = $('#auth_type').val();
  1246. if (authType == '2' || authType == '5') {
  1247. $('#security_protocol').change(onSecurityProtocolChange);
  1248. if (authType == '2') {
  1249. $('#use_paged_search').change(onUsePagedSearchChange);
  1250. }
  1251. } else if (authType == '6') {
  1252. $('#oauth2_provider').change(onOAuth2Change);
  1253. $('#oauth2_use_custom_url').change(onOAuth2UseCustomURLChange);
  1254. onOAuth2Change();
  1255. }
  1256. }
  1257. // Notice
  1258. if ($('.admin.notice')) {
  1259. var $detailModal = $('#detail-modal');
  1260. // Attach view detail modals
  1261. $('.view-detail').click(function () {
  1262. $detailModal.find('.content p').text($(this).data('content'));
  1263. $detailModal.modal('show');
  1264. return false;
  1265. });
  1266. // Select actions
  1267. var $checkboxes = $('.select.table .ui.checkbox');
  1268. $('.select.action').click(function () {
  1269. switch ($(this).data('action')) {
  1270. case 'select-all':
  1271. $checkboxes.checkbox('check');
  1272. break;
  1273. case 'deselect-all':
  1274. $checkboxes.checkbox('uncheck');
  1275. break;
  1276. case 'inverse':
  1277. $checkboxes.checkbox('toggle');
  1278. break;
  1279. }
  1280. });
  1281. $('#delete-selection').click(function () {
  1282. var $this = $(this);
  1283. $this.addClass("loading disabled");
  1284. var ids = [];
  1285. $checkboxes.each(function () {
  1286. if ($(this).checkbox('is checked')) {
  1287. ids.push($(this).data('id'));
  1288. }
  1289. });
  1290. $.post($this.data('link'), {
  1291. "_csrf": csrf,
  1292. "ids": ids
  1293. }).done(function () {
  1294. window.location.href = $this.data('redirect');
  1295. });
  1296. });
  1297. }
  1298. }
  1299. function buttonsClickOnEnter() {
  1300. $('.ui.button').keypress(function (e) {
  1301. if (e.keyCode == 13 || e.keyCode == 32) // enter key or space bar
  1302. $(this).click();
  1303. });
  1304. }
  1305. function hideWhenLostFocus(body, parent) {
  1306. $(document).click(function (e) {
  1307. var target = e.target;
  1308. if (!$(target).is(body) && !$(target).parents().is(parent)) {
  1309. $(body).hide();
  1310. }
  1311. });
  1312. }
  1313. function searchUsers() {
  1314. var $searchUserBox = $('#search-user-box');
  1315. $searchUserBox.search({
  1316. minCharacters: 2,
  1317. apiSettings: {
  1318. url: suburl + '/api/v1/users/search?q={query}',
  1319. onResponse: function(response) {
  1320. var items = [];
  1321. $.each(response.data, function (i, item) {
  1322. var title = item.login;
  1323. if (item.full_name && item.full_name.length > 0) {
  1324. title += ' (' + item.full_name + ')';
  1325. }
  1326. items.push({
  1327. title: title,
  1328. image: item.avatar_url
  1329. })
  1330. });
  1331. return { results: items }
  1332. }
  1333. },
  1334. searchFields: ['login', 'full_name'],
  1335. showNoResults: false
  1336. });
  1337. }
  1338. function searchRepositories() {
  1339. var $searchRepoBox = $('#search-repo-box');
  1340. $searchRepoBox.search({
  1341. minCharacters: 2,
  1342. apiSettings: {
  1343. url: suburl + '/api/v1/repos/search?q={query}&uid=' + $searchRepoBox.data('uid'),
  1344. onResponse: function(response) {
  1345. var items = [];
  1346. $.each(response.data, function (i, item) {
  1347. items.push({
  1348. title: item.full_name.split("/")[1],
  1349. description: item.full_name
  1350. })
  1351. });
  1352. return { results: items }
  1353. }
  1354. },
  1355. searchFields: ['full_name'],
  1356. showNoResults: false
  1357. });
  1358. }
  1359. function initCodeView() {
  1360. if ($('.code-view .linenums').length > 0) {
  1361. $(document).on('click', '.lines-num span', function (e) {
  1362. var $select = $(this);
  1363. var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
  1364. selectRange($list, $list.filter('[rel=' + $select.attr('id') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
  1365. deSelect();
  1366. });
  1367. $(window).on('hashchange', function (e) {
  1368. var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
  1369. var $list = $('.code-view ol.linenums > li');
  1370. var $first;
  1371. if (m) {
  1372. $first = $list.filter('.' + m[1]);
  1373. selectRange($list, $first, $list.filter('.' + m[2]));
  1374. $("html, body").scrollTop($first.offset().top - 200);
  1375. return;
  1376. }
  1377. m = window.location.hash.match(/^#(L\d+)$/);
  1378. if (m) {
  1379. $first = $list.filter('.' + m[1]);
  1380. selectRange($list, $first);
  1381. $("html, body").scrollTop($first.offset().top - 200);
  1382. }
  1383. }).trigger('hashchange');
  1384. }
  1385. }
  1386. function initU2FAuth() {
  1387. if($('#wait-for-key').length === 0) {
  1388. return
  1389. }
  1390. u2fApi.ensureSupport()
  1391. .then(function () {
  1392. $.getJSON('/user/u2f/challenge').success(function(req) {
  1393. u2fApi.sign(req.appId, req.challenge, req.registeredKeys, 30)
  1394. .then(u2fSigned)
  1395. .catch(function (err) {
  1396. if(err === undefined) {
  1397. u2fError(1);
  1398. return
  1399. }
  1400. u2fError(err.metaData.code);
  1401. });
  1402. });
  1403. }).catch(function () {
  1404. // Fallback in case browser do not support U2F
  1405. window.location.href = "/user/two_factor"
  1406. })
  1407. }
  1408. function u2fSigned(resp) {
  1409. $.ajax({
  1410. url:'/user/u2f/sign',
  1411. type:"POST",
  1412. headers: {"X-Csrf-Token": csrf},
  1413. data: JSON.stringify(resp),
  1414. contentType:"application/json; charset=utf-8",
  1415. }).done(function(res){
  1416. window.location.replace(res);
  1417. }).fail(function (xhr, textStatus) {
  1418. u2fError(1);
  1419. });
  1420. }
  1421. function u2fRegistered(resp) {
  1422. if (checkError(resp)) {
  1423. return;
  1424. }
  1425. $.ajax({
  1426. url:'/user/settings/security/u2f/register',
  1427. type:"POST",
  1428. headers: {"X-Csrf-Token": csrf},
  1429. data: JSON.stringify(resp),
  1430. contentType:"application/json; charset=utf-8",
  1431. success: function(){
  1432. window.location.reload();
  1433. },
  1434. fail: function (xhr, textStatus) {
  1435. u2fError(1);
  1436. }
  1437. });
  1438. }
  1439. function checkError(resp) {
  1440. if (!('errorCode' in resp)) {
  1441. return false;
  1442. }
  1443. if (resp.errorCode === 0) {
  1444. return false;
  1445. }
  1446. u2fError(resp.errorCode);
  1447. return true;
  1448. }
  1449. function u2fError(errorType) {
  1450. var u2fErrors = {
  1451. 'browser': $('#unsupported-browser'),
  1452. 1: $('#u2f-error-1'),
  1453. 2: $('#u2f-error-2'),
  1454. 3: $('#u2f-error-3'),
  1455. 4: $('#u2f-error-4'),
  1456. 5: $('.u2f-error-5')
  1457. };
  1458. u2fErrors[errorType].removeClass('hide');
  1459. for(var type in u2fErrors){
  1460. if(type != errorType){
  1461. u2fErrors[type].addClass('hide');
  1462. }
  1463. }
  1464. $('#u2f-error').modal('show');
  1465. }
  1466. function initU2FRegister() {
  1467. $('#register-device').modal({allowMultiple: false});
  1468. $('#u2f-error').modal({allowMultiple: false});
  1469. $('#register-security-key').on('click', function(e) {
  1470. e.preventDefault();
  1471. u2fApi.ensureSupport()
  1472. .then(u2fRegisterRequest)
  1473. .catch(function() {
  1474. u2fError('browser');
  1475. })
  1476. })
  1477. }
  1478. function u2fRegisterRequest() {
  1479. $.post("/user/settings/security/u2f/request_register", {
  1480. "_csrf": csrf,
  1481. "name": $('#nickname').val()
  1482. }).success(function(req) {
  1483. $("#nickname").closest("div.field").removeClass("error");
  1484. $('#register-device').modal('show');
  1485. if(req.registeredKeys === null) {
  1486. req.registeredKeys = []
  1487. }
  1488. u2fApi.register(req.appId, req.registerRequests, req.registeredKeys, 30)
  1489. .then(u2fRegistered)
  1490. .catch(function (reason) {
  1491. if(reason === undefined) {
  1492. u2fError(1);
  1493. return
  1494. }
  1495. u2fError(reason.metaData.code);
  1496. });
  1497. }).fail(function(xhr, status, error) {
  1498. if(xhr.status === 409) {
  1499. $("#nickname").closest("div.field").addClass("error");
  1500. }
  1501. });
  1502. }
  1503. function initWipTitle() {
  1504. $(".title_wip_desc > a").click(function (e) {
  1505. e.preventDefault();
  1506. var $issueTitle = $("#issue_title");
  1507. $issueTitle.focus();
  1508. var value = $issueTitle.val().trim().toUpperCase();
  1509. for (var i in wipPrefixes) {
  1510. if (value.startsWith(wipPrefixes[i].toUpperCase())) {
  1511. return;
  1512. }
  1513. }
  1514. $issueTitle.val(wipPrefixes[0] + " " + $issueTitle.val());
  1515. });
  1516. }
  1517. $(document).ready(function () {
  1518. csrf = $('meta[name=_csrf]').attr("content");
  1519. suburl = $('meta[name=_suburl]').attr("content");
  1520. // Show exact time
  1521. $('.time-since').each(function () {
  1522. $(this).addClass('poping up').attr('data-content', $(this).attr('title')).attr('data-variation', 'inverted tiny').attr('title', '');
  1523. });
  1524. // Semantic UI modules.
  1525. $('.dropdown:not(.custom)').dropdown();
  1526. $('.jump.dropdown').dropdown({
  1527. action: 'hide',
  1528. onShow: function () {
  1529. $('.poping.up').popup('hide');
  1530. }
  1531. });
  1532. $('.slide.up.dropdown').dropdown({
  1533. transition: 'slide up'
  1534. });
  1535. $('.upward.dropdown').dropdown({
  1536. direction: 'upward'
  1537. });
  1538. $('.ui.accordion').accordion();
  1539. $('.ui.checkbox').checkbox();
  1540. $('.ui.progress').progress({
  1541. showActivity: false
  1542. });
  1543. $('.poping.up').popup();
  1544. $('.top.menu .poping.up').popup({
  1545. onShow: function () {
  1546. if ($('.top.menu .menu.transition').hasClass('visible')) {
  1547. return false;
  1548. }
  1549. }
  1550. });
  1551. $('.tabular.menu .item').tab();
  1552. $('.tabable.menu .item').tab();
  1553. $('.toggle.button').click(function () {
  1554. $($(this).data('target')).slideToggle(100);
  1555. });
  1556. // make table <tr> element clickable like a link
  1557. $('tr[data-href]').click(function(event) {
  1558. window.location = $(this).data('href');
  1559. });
  1560. // Highlight JS
  1561. if (typeof hljs != 'undefined') {
  1562. hljs.initHighlightingOnLoad();
  1563. }
  1564. // Dropzone
  1565. var $dropzone = $('#dropzone');
  1566. if ($dropzone.length > 0) {
  1567. // Disable auto discover for all elements:
  1568. Dropzone.autoDiscover = false;
  1569. var filenameDict = {};
  1570. $dropzone.dropzone({
  1571. url: $dropzone.data('upload-url'),
  1572. headers: {"X-Csrf-Token": csrf},
  1573. maxFiles: $dropzone.data('max-file'),
  1574. maxFilesize: $dropzone.data('max-size'),
  1575. acceptedFiles: ($dropzone.data('accepts') === '*/*') ? null : $dropzone.data('accepts'),
  1576. addRemoveLinks: true,
  1577. dictDefaultMessage: $dropzone.data('default-message'),
  1578. dictInvalidFileType: $dropzone.data('invalid-input-type'),
  1579. dictFileTooBig: $dropzone.data('file-too-big'),
  1580. dictRemoveFile: $dropzone.data('remove-file'),
  1581. init: function () {
  1582. this.on("success", function (file, data) {
  1583. filenameDict[file.name] = data.uuid;
  1584. var input = $('<input id="' + data.uuid + '" name="files" type="hidden">').val(data.uuid);
  1585. $('.files').append(input);
  1586. });
  1587. this.on("removedfile", function (file) {
  1588. if (file.name in filenameDict) {
  1589. $('#' + filenameDict[file.name]).remove();
  1590. }
  1591. if ($dropzone.data('remove-url') && $dropzone.data('csrf')) {
  1592. $.post($dropzone.data('remove-url'), {
  1593. file: filenameDict[file.name],
  1594. _csrf: $dropzone.data('csrf')
  1595. });
  1596. }
  1597. })
  1598. }
  1599. });
  1600. }
  1601. // Emojify
  1602. emojify.setConfig({
  1603. img_dir: suburl + '/vendor/plugins/emojify/images',
  1604. ignore_emoticons: true
  1605. });
  1606. var hasEmoji = document.getElementsByClassName('has-emoji');
  1607. for (var i = 0; i < hasEmoji.length; i++) {
  1608. emojify.run(hasEmoji[i]);
  1609. for (var j = 0; j < hasEmoji[i].childNodes.length; j++) {
  1610. if (hasEmoji[i].childNodes[j].nodeName === "A") {
  1611. emojify.run(hasEmoji[i].childNodes[j])
  1612. }
  1613. }
  1614. }
  1615. // Clipboard JS
  1616. var clipboard = new Clipboard('.clipboard');
  1617. clipboard.on('success', function (e) {
  1618. e.clearSelection();
  1619. $('#' + e.trigger.getAttribute('id')).popup('destroy');
  1620. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-success'))
  1621. $('#' + e.trigger.getAttribute('id')).popup('show');
  1622. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
  1623. });
  1624. clipboard.on('error', function (e) {
  1625. $('#' + e.trigger.getAttribute('id')).popup('destroy');
  1626. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-error'))
  1627. $('#' + e.trigger.getAttribute('id')).popup('show');
  1628. e.trigger.setAttribute('data-content', e.trigger.getAttribute('data-original'))
  1629. });
  1630. // Helpers.
  1631. $('.delete-button').click(showDeletePopup);
  1632. $('.delete-branch-button').click(showDeletePopup);
  1633. $('.undo-button').click(function() {
  1634. var $this = $(this);
  1635. $.post($this.data('url'), {
  1636. "_csrf": csrf,
  1637. "id": $this.data("id")
  1638. }).done(function(data) {
  1639. window.location.href = data.redirect;
  1640. });
  1641. });
  1642. $('.show-panel.button').click(function () {
  1643. $($(this).data('panel')).show();
  1644. });
  1645. $('.show-modal.button').click(function () {
  1646. $($(this).data('modal')).modal('show');
  1647. });
  1648. $('.delete-post.button').click(function () {
  1649. var $this = $(this);
  1650. $.post($this.data('request-url'), {
  1651. "_csrf": csrf
  1652. }).done(function () {
  1653. window.location.href = $this.data('done-url');
  1654. });
  1655. });
  1656. // Set anchor.
  1657. $('.markdown').each(function () {
  1658. var headers = {};
  1659. $(this).find('h1, h2, h3, h4, h5, h6').each(function () {
  1660. var node = $(this);
  1661. var val = encodeURIComponent(node.text().toLowerCase().replace(/[^\u00C0-\u1FFF\u2C00-\uD7FF\w\- ]/g, '').replace(/[ ]/g, '-'));
  1662. var name = val;
  1663. if (headers[val] > 0) {
  1664. name = val + '-' + headers[val];
  1665. }
  1666. if (headers[val] == undefined) {
  1667. headers[val] = 1;
  1668. } else {
  1669. headers[val] += 1;
  1670. }
  1671. node = node.wrap('<div id="' + name + '" class="anchor-wrap" ></div>');
  1672. node.append('<a class="anchor" href="#' + name + '"><span class="octicon octicon-link"></span></a>');
  1673. });
  1674. });
  1675. $('.issue-checkbox').click(function() {
  1676. var numChecked = $('.issue-checkbox').children('input:checked').length;
  1677. if (numChecked > 0) {
  1678. $('#issue-filters').hide();
  1679. $('#issue-actions').show();
  1680. } else {
  1681. $('#issue-filters').show();
  1682. $('#issue-actions').hide();
  1683. }
  1684. });
  1685. $('.issue-action').click(function () {
  1686. var action = this.dataset.action
  1687. var elementId = this.dataset.elementId
  1688. var issueIDs = $('.issue-checkbox').children('input:checked').map(function() {
  1689. return this.dataset.issueId;
  1690. }).get().join();
  1691. var url = this.dataset.url
  1692. updateIssuesMeta(url, action, issueIDs, elementId, function() {
  1693. location.reload();
  1694. });
  1695. });
  1696. buttonsClickOnEnter();
  1697. searchUsers();
  1698. searchRepositories();
  1699. initCommentForm();
  1700. initInstall();
  1701. initRepository();
  1702. initWikiForm();
  1703. initEditForm();
  1704. initEditor();
  1705. initOrganization();
  1706. initWebhook();
  1707. initAdmin();
  1708. initCodeView();
  1709. initVueApp();
  1710. initTeamSettings();
  1711. initCtrlEnterSubmit();
  1712. initNavbarContentToggle();
  1713. initTopicbar();
  1714. initU2FAuth();
  1715. initU2FRegister();
  1716. initIssueList();
  1717. initWipTitle();
  1718. initPullRequestReview();
  1719. // Repo clone url.
  1720. if ($('#repo-clone-url').length > 0) {
  1721. switch (localStorage.getItem('repo-clone-protocol')) {
  1722. case 'ssh':
  1723. if ($('#repo-clone-ssh').click().length === 0) {
  1724. $('#repo-clone-https').click();
  1725. }
  1726. break;
  1727. default:
  1728. $('#repo-clone-https').click();
  1729. break;
  1730. }
  1731. }
  1732. var routes = {
  1733. 'div.user.settings': initUserSettings,
  1734. 'div.repository.settings.collaboration': initRepositoryCollaboration
  1735. };
  1736. var selector;
  1737. for (selector in routes) {
  1738. if ($(selector).length > 0) {
  1739. routes[selector]();
  1740. break;
  1741. }
  1742. }
  1743. });
  1744. function changeHash(hash) {
  1745. if (history.pushState) {
  1746. history.pushState(null, null, hash);
  1747. }
  1748. else {
  1749. location.hash = hash;
  1750. }
  1751. }
  1752. function deSelect() {
  1753. if (window.getSelection) {
  1754. window.getSelection().removeAllRanges();
  1755. } else {
  1756. document.selection.empty();
  1757. }
  1758. }
  1759. function selectRange($list, $select, $from) {
  1760. $list.removeClass('active');
  1761. if ($from) {
  1762. var a = parseInt($select.attr('rel').substr(1));
  1763. var b = parseInt($from.attr('rel').substr(1));
  1764. var c;
  1765. if (a != b) {
  1766. if (a > b) {
  1767. c = a;
  1768. a = b;
  1769. b = c;
  1770. }
  1771. var classes = [];
  1772. for (var i = a; i <= b; i++) {
  1773. classes.push('.L' + i);
  1774. }
  1775. $list.filter(classes.join(',')).addClass('active');
  1776. changeHash('#L' + a + '-' + 'L' + b);
  1777. return
  1778. }
  1779. }
  1780. $select.addClass('active');
  1781. changeHash('#' + $select.attr('rel'));
  1782. }
  1783. $(function () {
  1784. // Warn users that try to leave a page after entering data into a form.
  1785. // Except on sign-in pages, and for forms marked as 'ignore-dirty'.
  1786. if ($('.user.signin').length === 0) {
  1787. $('form:not(.ignore-dirty)').areYouSure();
  1788. }
  1789. // Parse SSH Key
  1790. $("#ssh-key-content").on('change paste keyup',function(){
  1791. var arrays = $(this).val().split(" ");
  1792. var $title = $("#ssh-key-title")
  1793. if ($title.val() === "" && arrays.length === 3 && arrays[2] !== "") {
  1794. $title.val(arrays[2]);
  1795. }
  1796. });
  1797. });
  1798. function showDeletePopup() {
  1799. var $this = $(this);
  1800. var filter = "";
  1801. if ($this.attr("id")) {
  1802. filter += "#" + $this.attr("id")
  1803. }
  1804. var dialog = $('.delete.modal' + filter);
  1805. dialog.find('.repo-name').text($this.data('repo-name'));
  1806. dialog.modal({
  1807. closable: false,
  1808. onApprove: function() {
  1809. if ($this.data('type') == "form") {
  1810. $($this.data('form')).submit();
  1811. return;
  1812. }
  1813. $.post($this.data('url'), {
  1814. "_csrf": csrf,
  1815. "id": $this.data("id")
  1816. }).done(function(data) {
  1817. window.location.href = data.redirect;
  1818. });
  1819. }
  1820. }).modal('show');
  1821. return false;
  1822. }
  1823. function initVueComponents(){
  1824. var vueDelimeters = ['${', '}'];
  1825. Vue.component('repo-search', {
  1826. delimiters: vueDelimeters,
  1827. props: {
  1828. searchLimit: {
  1829. type: Number,
  1830. default: 10
  1831. },
  1832. suburl: {
  1833. type: String,
  1834. required: true
  1835. },
  1836. uid: {
  1837. type: Number,
  1838. required: true
  1839. },
  1840. organizations: {
  1841. type: Array,
  1842. default: []
  1843. },
  1844. isOrganization: {
  1845. type: Boolean,
  1846. default: true
  1847. },
  1848. canCreateOrganization: {
  1849. type: Boolean,
  1850. default: false
  1851. },
  1852. organizationsTotalCount: {
  1853. type: Number,
  1854. default: 0
  1855. },
  1856. moreReposLink: {
  1857. type: String,
  1858. default: ''
  1859. }
  1860. },
  1861. data: function() {
  1862. return {
  1863. tab: 'repos',
  1864. repos: [],
  1865. reposTotalCount: 0,
  1866. reposFilter: 'all',
  1867. searchQuery: '',
  1868. isLoading: false,
  1869. repoTypes: {
  1870. 'all': {
  1871. count: 0,
  1872. searchMode: '',
  1873. },
  1874. 'forks': {
  1875. count: 0,
  1876. searchMode: 'fork',
  1877. },
  1878. 'mirrors': {
  1879. count: 0,
  1880. searchMode: 'mirror',
  1881. },
  1882. 'sources': {
  1883. count: 0,
  1884. searchMode: 'source',
  1885. },
  1886. 'collaborative': {
  1887. count: 0,
  1888. searchMode: 'collaborative',
  1889. },
  1890. }
  1891. }
  1892. },
  1893. computed: {
  1894. showMoreReposLink: function() {
  1895. return this.repos.length > 0 && this.repos.length < this.repoTypes[this.reposFilter].count;
  1896. },
  1897. searchURL: function() {
  1898. 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' : '');
  1899. },
  1900. repoTypeCount: function() {
  1901. return this.repoTypes[this.reposFilter].count;
  1902. }
  1903. },
  1904. mounted: function() {
  1905. this.searchRepos(this.reposFilter);
  1906. var self = this;
  1907. Vue.nextTick(function() {
  1908. self.$refs.search.focus();
  1909. });
  1910. },
  1911. methods: {
  1912. changeTab: function(t) {
  1913. this.tab = t;
  1914. },
  1915. changeReposFilter: function(filter) {
  1916. this.reposFilter = filter;
  1917. this.repos = [];
  1918. this.repoTypes[filter].count = 0;
  1919. this.searchRepos(filter);
  1920. },
  1921. showRepo: function(repo, filter) {
  1922. switch (filter) {
  1923. case 'sources':
  1924. return repo.owner.id == this.uid && !repo.mirror && !repo.fork;
  1925. case 'forks':
  1926. return repo.owner.id == this.uid && !repo.mirror && repo.fork;
  1927. case 'mirrors':
  1928. return repo.mirror;
  1929. case 'collaborative':
  1930. return repo.owner.id != this.uid && !repo.mirror;
  1931. default:
  1932. return true;
  1933. }
  1934. },
  1935. searchRepos: function(reposFilter) {
  1936. var self = this;
  1937. this.isLoading = true;
  1938. var searchedMode = this.repoTypes[reposFilter].searchMode;
  1939. var searchedURL = this.searchURL;
  1940. var searchedQuery = this.searchQuery;
  1941. $.getJSON(searchedURL, function(result, textStatus, request) {
  1942. if (searchedURL == self.searchURL) {
  1943. self.repos = result.data;
  1944. var count = request.getResponseHeader('X-Total-Count');
  1945. if (searchedQuery === '' && searchedMode === '') {
  1946. self.reposTotalCount = count;
  1947. }
  1948. self.repoTypes[reposFilter].count = count;
  1949. }
  1950. }).always(function() {
  1951. if (searchedURL == self.searchURL) {
  1952. self.isLoading = false;
  1953. }
  1954. });
  1955. },
  1956. repoClass: function(repo) {
  1957. if (repo.fork) {
  1958. return 'octicon octicon-repo-forked';
  1959. } else if (repo.mirror) {
  1960. return 'octicon octicon-repo-clone';
  1961. } else if (repo.private) {
  1962. return 'octicon octicon-lock';
  1963. } else {
  1964. return 'octicon octicon-repo';
  1965. }
  1966. }
  1967. }
  1968. })
  1969. }
  1970. function initCtrlEnterSubmit() {
  1971. $(".js-quick-submit").keydown(function(e) {
  1972. if (((e.ctrlKey && !e.altKey) || e.metaKey) && (e.keyCode == 13 || e.keyCode == 10)) {
  1973. $(this).closest("form").submit();
  1974. }
  1975. });
  1976. }
  1977. function initVueApp() {
  1978. var el = document.getElementById('app');
  1979. if (!el) {
  1980. return;
  1981. }
  1982. initVueComponents();
  1983. new Vue({
  1984. delimiters: ['${', '}'],
  1985. el: el,
  1986. data: {
  1987. searchLimit: document.querySelector('meta[name=_search_limit]').content,
  1988. suburl: document.querySelector('meta[name=_suburl]').content,
  1989. uid: document.querySelector('meta[name=_context_uid]').content,
  1990. },
  1991. });
  1992. }
  1993. function timeAddManual() {
  1994. $('.mini.modal')
  1995. .modal({
  1996. duration: 200,
  1997. onApprove: function() {
  1998. $('#add_time_manual_form').submit();
  1999. }
  2000. }).modal('show')
  2001. ;
  2002. }
  2003. function toggleStopwatch() {
  2004. $("#toggle_stopwatch_form").submit();
  2005. }
  2006. function cancelStopwatch() {
  2007. $("#cancel_stopwatch_form").submit();
  2008. }
  2009. function initFilterBranchTagDropdown(selector) {
  2010. $(selector).each(function() {
  2011. var $dropdown = $(this);
  2012. var $data = $dropdown.find('.data');
  2013. var data = {
  2014. items: [],
  2015. mode: $data.data('mode'),
  2016. searchTerm: '',
  2017. noResults: '',
  2018. canCreateBranch: false,
  2019. menuVisible: false,
  2020. active: 0
  2021. };
  2022. $data.find('.item').each(function() {
  2023. data.items.push({
  2024. name: $(this).text(),
  2025. url: $(this).data('url'),
  2026. branch: $(this).hasClass('branch'),
  2027. tag: $(this).hasClass('tag'),
  2028. selected: $(this).hasClass('selected')
  2029. });
  2030. });
  2031. $data.remove();
  2032. new Vue({
  2033. delimiters: ['${', '}'],
  2034. el: this,
  2035. data: data,
  2036. beforeMount: function () {
  2037. var vm = this;
  2038. this.noResults = vm.$el.getAttribute('data-no-results');
  2039. this.canCreateBranch = vm.$el.getAttribute('data-can-create-branch') === 'true';
  2040. document.body.addEventListener('click', function(event) {
  2041. if (vm.$el.contains(event.target)) {
  2042. return;
  2043. }
  2044. if (vm.menuVisible) {
  2045. Vue.set(vm, 'menuVisible', false);
  2046. }
  2047. });
  2048. },
  2049. watch: {
  2050. menuVisible: function(visible) {
  2051. if (visible) {
  2052. this.focusSearchField();
  2053. }
  2054. }
  2055. },
  2056. computed: {
  2057. filteredItems: function() {
  2058. var vm = this;
  2059. var items = vm.items.filter(function (item) {
  2060. return ((vm.mode === 'branches' && item.branch)
  2061. || (vm.mode === 'tags' && item.tag))
  2062. && (!vm.searchTerm
  2063. || item.name.toLowerCase().indexOf(vm.searchTerm.toLowerCase()) >= 0);
  2064. });
  2065. vm.active = (items.length === 0 && vm.showCreateNewBranch ? 0 : -1);
  2066. return items;
  2067. },
  2068. showNoResults: function() {
  2069. return this.filteredItems.length === 0
  2070. && !this.showCreateNewBranch;
  2071. },
  2072. showCreateNewBranch: function() {
  2073. var vm = this;
  2074. if (!this.canCreateBranch || !vm.searchTerm || vm.mode === 'tags') {
  2075. return false;
  2076. }
  2077. return vm.items.filter(function (item) {
  2078. return item.name.toLowerCase() === vm.searchTerm.toLowerCase()
  2079. }).length === 0;
  2080. }
  2081. },
  2082. methods: {
  2083. selectItem: function(item) {
  2084. var prev = this.getSelected();
  2085. if (prev !== null) {
  2086. prev.selected = false;
  2087. }
  2088. item.selected = true;
  2089. window.location.href = item.url;
  2090. },
  2091. createNewBranch: function() {
  2092. if (!this.showCreateNewBranch) {
  2093. return;
  2094. }
  2095. this.$refs.newBranchForm.submit();
  2096. },
  2097. focusSearchField: function() {
  2098. var vm = this;
  2099. Vue.nextTick(function() {
  2100. vm.$refs.searchField.focus();
  2101. });
  2102. },
  2103. getSelected: function() {
  2104. for (var i = 0, j = this.items.length; i < j; ++i) {
  2105. if (this.items[i].selected)
  2106. return this.items[i];
  2107. }
  2108. return null;
  2109. },
  2110. getSelectedIndexInFiltered: function() {
  2111. for (var i = 0, j = this.filteredItems.length; i < j; ++i) {
  2112. if (this.filteredItems[i].selected)
  2113. return i;
  2114. }
  2115. return -1;
  2116. },
  2117. scrollToActive: function() {
  2118. var el = this.$refs['listItem' + this.active];
  2119. if (!el || el.length === 0) {
  2120. return;
  2121. }
  2122. if (Array.isArray(el)) {
  2123. el = el[0];
  2124. }
  2125. var cont = this.$refs.scrollContainer;
  2126. if (el.offsetTop < cont.scrollTop) {
  2127. cont.scrollTop = el.offsetTop;
  2128. }
  2129. else if (el.offsetTop + el.clientHeight > cont.scrollTop + cont.clientHeight) {
  2130. cont.scrollTop = el.offsetTop + el.clientHeight - cont.clientHeight;
  2131. }
  2132. },
  2133. keydown: function(event) {
  2134. var vm = this;
  2135. if (event.keyCode === 40) {
  2136. // arrow down
  2137. event.preventDefault();
  2138. if (vm.active === -1) {
  2139. vm.active = vm.getSelectedIndexInFiltered();
  2140. }
  2141. if (vm.active + (vm.showCreateNewBranch ? 0 : 1) >= vm.filteredItems.length) {
  2142. return;
  2143. }
  2144. vm.active++;
  2145. vm.scrollToActive();
  2146. }
  2147. if (event.keyCode === 38) {
  2148. // arrow up
  2149. event.preventDefault();
  2150. if (vm.active === -1) {
  2151. vm.active = vm.getSelectedIndexInFiltered();
  2152. }
  2153. if (vm.active <= 0) {
  2154. return;
  2155. }
  2156. vm.active--;
  2157. vm.scrollToActive();
  2158. }
  2159. if (event.keyCode == 13) {
  2160. // enter
  2161. event.preventDefault();
  2162. if (vm.active >= vm.filteredItems.length) {
  2163. vm.createNewBranch();
  2164. } else if (vm.active >= 0) {
  2165. vm.selectItem(vm.filteredItems[vm.active]);
  2166. }
  2167. }
  2168. if (event.keyCode == 27) {
  2169. // escape
  2170. event.preventDefault();
  2171. vm.menuVisible = false;
  2172. }
  2173. }
  2174. }
  2175. });
  2176. });
  2177. }
  2178. $(".commit-button").click(function() {
  2179. $(this).parent().find('.commit-body').toggle();
  2180. });
  2181. function initNavbarContentToggle() {
  2182. var content = $('#navbar');
  2183. var toggle = $('#navbar-expand-toggle');
  2184. var isExpanded = false;
  2185. toggle.click(function() {
  2186. isExpanded = !isExpanded;
  2187. if (isExpanded) {
  2188. content.addClass('shown');
  2189. toggle.addClass('active');
  2190. }
  2191. else {
  2192. content.removeClass('shown');
  2193. toggle.removeClass('active');
  2194. }
  2195. });
  2196. }
  2197. function initTopicbar() {
  2198. var mgrBtn = $("#manage_topic"),
  2199. editDiv = $("#topic_edit"),
  2200. viewDiv = $("#repo-topic"),
  2201. saveBtn = $("#save_topic"),
  2202. topicDropdown = $('#topic_edit .dropdown'),
  2203. topicForm = $('#topic_edit.ui.form'),
  2204. topicPrompts;
  2205. mgrBtn.click(function() {
  2206. viewDiv.hide();
  2207. editDiv.css('display', ''); // show Semantic UI Grid
  2208. });
  2209. function getPrompts() {
  2210. var hidePrompt = $("div.hide#validate_prompt"),
  2211. prompts = {
  2212. countPrompt: hidePrompt.children('#count_prompt').text(),
  2213. formatPrompt: hidePrompt.children('#format_prompt').text()
  2214. };
  2215. hidePrompt.remove();
  2216. return prompts;
  2217. }
  2218. saveBtn.click(function() {
  2219. var topics = $("input[name=topics]").val();
  2220. $.post(saveBtn.data('link'), {
  2221. "_csrf": csrf,
  2222. "topics": topics
  2223. }, function(data, textStatus, xhr){
  2224. if (xhr.responseJSON.status === 'ok') {
  2225. viewDiv.children(".topic").remove();
  2226. if (topics.length === 0) {
  2227. return
  2228. }
  2229. var topicArray = topics.split(",");
  2230. var last = viewDiv.children("a").last();
  2231. for (var i=0; i < topicArray.length; i++) {
  2232. $('<div class="ui green basic label topic" style="cursor:pointer;">'+topicArray[i]+'</div>').insertBefore(last)
  2233. }
  2234. editDiv.css('display', 'none'); // hide Semantic UI Grid
  2235. viewDiv.show();
  2236. }
  2237. }).fail(function(xhr){
  2238. if (xhr.status === 422) {
  2239. if (xhr.responseJSON.invalidTopics.length > 0) {
  2240. topicPrompts.formatPrompt = xhr.responseJSON.message;
  2241. var invalidTopics = xhr.responseJSON.invalidTopics,
  2242. topicLables = topicDropdown.children('a.ui.label');
  2243. topics.split(',').forEach(function(value, index) {
  2244. for (var i=0; i < invalidTopics.length; i++) {
  2245. if (invalidTopics[i] === value) {
  2246. topicLables.eq(index).removeClass("green").addClass("red");
  2247. }
  2248. }
  2249. });
  2250. } else {
  2251. topicPrompts.countPrompt = xhr.responseJSON.message;
  2252. }
  2253. }
  2254. }).always(function() {
  2255. topicForm.form('validate form');
  2256. });
  2257. });
  2258. topicDropdown.dropdown({
  2259. allowAdditions: true,
  2260. fields: { name: "description", value: "data-value" },
  2261. saveRemoteData: false,
  2262. label: {
  2263. transition : 'horizontal flip',
  2264. duration : 200,
  2265. variation : false,
  2266. blue : true,
  2267. basic: true,
  2268. },
  2269. className: {
  2270. label: 'ui green basic label'
  2271. },
  2272. apiSettings: {
  2273. url: suburl + '/api/v1/topics/search?q={query}',
  2274. throttle: 500,
  2275. cache: false,
  2276. onResponse: function(res) {
  2277. var formattedResponse = {
  2278. success: false,
  2279. results: [],
  2280. };
  2281. if (res.topics) {
  2282. formattedResponse.success = true;
  2283. for (var i=0;i < res.topics.length;i++) {
  2284. formattedResponse.results.push({"description": res.topics[i].Name, "data-value":res.topics[i].Name})
  2285. }
  2286. }
  2287. return formattedResponse;
  2288. },
  2289. },
  2290. onLabelCreate: function(value) {
  2291. value = value.toLowerCase().trim();
  2292. this.attr("data-value", value).contents().first().replaceWith(value);
  2293. return $(this);
  2294. },
  2295. onAdd: function(addedValue, addedText, $addedChoice) {
  2296. addedValue = addedValue.toLowerCase().trim();
  2297. $($addedChoice).attr('data-value', addedValue);
  2298. $($addedChoice).attr('data-text', addedValue);
  2299. }
  2300. });
  2301. $.fn.form.settings.rules.validateTopic = function(values, regExp) {
  2302. var topics = topicDropdown.children('a.ui.label'),
  2303. status = topics.length === 0 || topics.last().attr("data-value").match(regExp);
  2304. if (!status) {
  2305. topics.last().removeClass("green").addClass("red");
  2306. }
  2307. return status && topicDropdown.children('a.ui.label.red').length === 0;
  2308. };
  2309. topicPrompts = getPrompts();
  2310. topicForm.form({
  2311. on: 'change',
  2312. inline : true,
  2313. fields: {
  2314. topics: {
  2315. identifier: 'topics',
  2316. rules: [
  2317. {
  2318. type: 'validateTopic',
  2319. value: /^[a-z0-9][a-z0-9-]{1,35}$/,
  2320. prompt: topicPrompts.formatPrompt
  2321. },
  2322. {
  2323. type: 'maxCount[25]',
  2324. prompt: topicPrompts.countPrompt
  2325. }
  2326. ]
  2327. },
  2328. }
  2329. });
  2330. }
  2331. function toggleDeadlineForm() {
  2332. $('#deadlineForm').fadeToggle(150);
  2333. }
  2334. function setDeadline() {
  2335. var deadline = $('#deadlineDate').val();
  2336. updateDeadline(deadline);
  2337. }
  2338. function updateDeadline(deadlineString) {
  2339. $('#deadline-err-invalid-date').hide();
  2340. $('#deadline-loader').addClass('loading');
  2341. var realDeadline = null;
  2342. if (deadlineString !== '') {
  2343. var newDate = Date.parse(deadlineString)
  2344. if (isNaN(newDate)) {
  2345. $('#deadline-loader').removeClass('loading');
  2346. $('#deadline-err-invalid-date').show();
  2347. return false;
  2348. }
  2349. realDeadline = new Date(newDate);
  2350. }
  2351. $.ajax($('#update-issue-deadline-form').attr('action') + '/deadline', {
  2352. data: JSON.stringify({
  2353. 'due_date': realDeadline,
  2354. }),
  2355. contentType: 'application/json',
  2356. type: 'POST',
  2357. success: function () {
  2358. window.location.reload();
  2359. },
  2360. error: function () {
  2361. $('#deadline-loader').removeClass('loading');
  2362. $('#deadline-err-invalid-date').show();
  2363. }
  2364. });
  2365. }
  2366. function deleteDependencyModal(id, type) {
  2367. $('.remove-dependency')
  2368. .modal({
  2369. closable: false,
  2370. duration: 200,
  2371. onApprove: function () {
  2372. $('#removeDependencyID').val(id);
  2373. $('#dependencyType').val(type);
  2374. $('#removeDependencyForm').submit();
  2375. }
  2376. }).modal('show')
  2377. ;
  2378. }
  2379. function initIssueList() {
  2380. var repolink = $('#repolink').val();
  2381. $('.new-dependency-drop-list')
  2382. .dropdown({
  2383. apiSettings: {
  2384. url: suburl + '/api/v1/repos' + repolink + '/issues?q={query}',
  2385. onResponse: function(response) {
  2386. var filteredResponse = {'success': true, 'results': []};
  2387. // Parse the response from the api to work with our dropdown
  2388. $.each(response, function(index, issue) {
  2389. filteredResponse.results.push({
  2390. 'name' : '#' + issue.number + '&nbsp;' + issue.title,
  2391. 'value' : issue.id
  2392. });
  2393. });
  2394. return filteredResponse;
  2395. },
  2396. },
  2397. fullTextSearch: true
  2398. })
  2399. ;
  2400. }
  2401. function cancelCodeComment(btn) {
  2402. var form = $(btn).closest("form");
  2403. if(form.length > 0 && form.hasClass('comment-form')) {
  2404. form.addClass('hide');
  2405. form.parent().find('button.comment-form-reply').show();
  2406. } else {
  2407. form.closest('.comment-code-cloud').remove()
  2408. }
  2409. }