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.

813 lines
25 KiB

10 years ago
  1. // @codekit-prepend "lib/jquery-1.11.1.min.js"
  2. // @codekit-prepend "lib/lib.js"
  3. // @codekit-prepend "utils/tabs.js"
  4. // @codekit-prepend "utils/preview.js"
  5. // @codekit-prepend "lib/jquery.tipsy.js"
  6. var Gogs = {};
  7. (function ($) {
  8. // Extend jQuery ajax, set CSRF token value.
  9. var ajax = $.ajax;
  10. $.extend({
  11. ajax: function (url, options) {
  12. if (typeof url === 'object') {
  13. options = url;
  14. url = undefined;
  15. }
  16. options = options || {};
  17. url = options.url;
  18. var csrftoken = $('meta[name=_csrf]').attr('content');
  19. var headers = options.headers || {};
  20. var domain = document.domain.replace(/\./ig, '\\.');
  21. if (!/^(http:|https:).*/.test(url) || eval('/^(http:|https:)\\/\\/(.+\\.)*' + domain + '.*/').test(url)) {
  22. headers = $.extend(headers, {'X-Csrf-Token': csrftoken});
  23. }
  24. options.headers = headers;
  25. var callback = options.success;
  26. options.success = function (data) {
  27. if (data.once) {
  28. // change all _once value if ajax data.once exist
  29. $('[name=_once]').val(data.once);
  30. }
  31. if (callback) {
  32. callback.apply(this, arguments);
  33. }
  34. };
  35. return ajax(url, options);
  36. },
  37. changeHash: function (hash) {
  38. if (history.pushState) {
  39. history.pushState(null, null, hash);
  40. }
  41. else {
  42. location.hash = hash;
  43. }
  44. },
  45. deSelect: function () {
  46. if (window.getSelection) {
  47. window.getSelection().removeAllRanges();
  48. } else {
  49. document.selection.empty();
  50. }
  51. }
  52. });
  53. $.fn.extend({
  54. toggleHide: function () {
  55. $(this).addClass("hidden");
  56. },
  57. toggleShow: function () {
  58. $(this).removeClass("hidden");
  59. },
  60. toggleAjax: function (successCallback, errorCallback) {
  61. var url = $(this).data("ajax");
  62. var method = $(this).data('ajax-method') || 'get';
  63. var ajaxName = $(this).data('ajax-name');
  64. var data = {};
  65. if (ajaxName.endsWith("preview")) {
  66. data["mode"] = "gfm";
  67. data["context"] = $(this).data('ajax-context');
  68. }
  69. $('[data-ajax-rel=' + ajaxName + ']').each(function () {
  70. var field = $(this).data("ajax-field");
  71. var t = $(this).data("ajax-val");
  72. if (t == "val") {
  73. data[field] = $(this).val();
  74. return true;
  75. }
  76. if (t == "txt") {
  77. data[field] = $(this).text();
  78. return true;
  79. }
  80. if (t == "html") {
  81. data[field] = $(this).html();
  82. return true;
  83. }
  84. if (t == "data") {
  85. data[field] = $(this).data("ajax-data");
  86. return true;
  87. }
  88. return true;
  89. });
  90. console.log("toggleAjax:", method, url, data);
  91. $.ajax({
  92. url: url,
  93. method: method.toUpperCase(),
  94. data: data,
  95. error: errorCallback,
  96. success: function (d) {
  97. if (successCallback) {
  98. successCallback(d);
  99. }
  100. }
  101. })
  102. }
  103. });
  104. }(jQuery));
  105. (function ($) {
  106. // Render markdown.
  107. Gogs.renderMarkdown = function () {
  108. var $md = $('.markdown');
  109. var $pre = $md.find('pre > code').parent();
  110. $pre.addClass('prettyprint');
  111. prettyPrint();
  112. // Set anchor.
  113. var headers = {};
  114. $md.find('h1, h2, h3, h4, h5, h6').each(function () {
  115. var node = $(this);
  116. var val = encodeURIComponent(node.text().toLowerCase().replace(/[^\w\- ]/g, '').replace(/[ ]/g, '-'));
  117. var name = val;
  118. if (headers[val] > 0) {
  119. name = val + '-' + headers[val];
  120. }
  121. if (headers[val] == undefined) {
  122. headers[val] = 1;
  123. } else {
  124. headers[val] += 1;
  125. }
  126. node = node.wrap('<div id="' + name + '" class="anchor-wrap" ></div>');
  127. node.append('<a class="anchor" href="#' + name + '"><span class="octicon octicon-link"></span></a>');
  128. });
  129. };
  130. // Render code view.
  131. Gogs.renderCodeView = function () {
  132. function selectRange($list, $select, $from) {
  133. $list.removeClass('active');
  134. if ($from) {
  135. var a = parseInt($select.attr('rel').substr(1));
  136. var b = parseInt($from.attr('rel').substr(1));
  137. var c;
  138. if (a != b) {
  139. if (a > b) {
  140. c = a;
  141. a = b;
  142. b = c;
  143. }
  144. var classes = [];
  145. for (i = a; i <= b; i++) {
  146. classes.push('.L' + i);
  147. }
  148. $list.filter(classes.join(',')).addClass('active');
  149. $.changeHash('#L' + a + '-' + 'L' + b);
  150. return
  151. }
  152. }
  153. $select.addClass('active');
  154. $.changeHash('#' + $select.attr('rel'));
  155. }
  156. $(document).on('click', '.lines-num span', function (e) {
  157. var $select = $(this);
  158. var $list = $select.parent().siblings('.lines-code').find('ol.linenums > li');
  159. selectRange($list, $list.filter('[rel=' + $select.attr('rel') + ']'), (e.shiftKey ? $list.filter('.active').eq(0) : null));
  160. $.deSelect();
  161. });
  162. $('.code-view .lines-code > pre').each(function () {
  163. var $pre = $(this);
  164. var $lineCode = $pre.parent();
  165. var $lineNums = $lineCode.siblings('.lines-num');
  166. if ($lineNums.length > 0) {
  167. var nums = $pre.find('ol.linenums > li').length;
  168. for (var i = 1; i <= nums; i++) {
  169. $lineNums.append('<span id="L' + i + '" rel="L' + i + '">' + i + '</span>');
  170. }
  171. }
  172. });
  173. $(window).on('hashchange', function (e) {
  174. var m = window.location.hash.match(/^#(L\d+)\-(L\d+)$/);
  175. var $list = $('.code-view ol.linenums > li');
  176. var $first;
  177. if (m) {
  178. $first = $list.filter('.' + m[1]);
  179. selectRange($list, $first, $list.filter('.' + m[2]));
  180. $("html, body").scrollTop($first.offset().top - 200);
  181. return;
  182. }
  183. m = window.location.hash.match(/^#(L\d+)$/);
  184. if (m) {
  185. $first = $list.filter('.' + m[1]);
  186. selectRange($list, $first);
  187. $("html, body").scrollTop($first.offset().top - 200);
  188. }
  189. }).trigger('hashchange');
  190. };
  191. // Search users by keyword.
  192. Gogs.searchUsers = function (val, $target) {
  193. $.ajax({
  194. url: Gogs.AppSubUrl + '/api/v1/users/search?q=' + val,
  195. dataType: "json",
  196. success: function (json) {
  197. if (json.ok && json.data.length) {
  198. var html = '';
  199. $.each(json.data, function (i, item) {
  200. html += '<li><a><img src="' + item.avatar_url + '">' + item.username + '</a></li>';
  201. });
  202. $target.html(html);
  203. $target.toggleShow();
  204. } else {
  205. $target.toggleHide();
  206. }
  207. }
  208. });
  209. }
  210. // Search repositories by keyword.
  211. Gogs.searchRepos = function (val, $target, $param) {
  212. $.ajax({
  213. url: Gogs.AppSubUrl + '/api/v1/repos/search?q=' + val + '&' + $param,
  214. dataType: "json",
  215. success: function (json) {
  216. if (json.ok && json.data.length) {
  217. var html = '';
  218. $.each(json.data, function (i, item) {
  219. html += '<li><a><span class="octicon octicon-repo"></span> ' + item.full_name + '</a></li>';
  220. });
  221. $target.html(html);
  222. $target.toggleShow();
  223. } else {
  224. $target.toggleHide();
  225. }
  226. }
  227. });
  228. }
  229. // Copy util.
  230. Gogs.bindCopy = function (selector) {
  231. if ($(selector).hasClass('js-copy-bind')) {
  232. return;
  233. }
  234. $(selector).zclip({
  235. path: Gogs.AppSubUrl + "/js/ZeroClipboard.swf",
  236. copy: function () {
  237. var t = $(this).data("copy-val");
  238. var to = $($(this).data("copy-from"));
  239. var str = "";
  240. if (t == "txt") {
  241. str = to.text();
  242. }
  243. if (t == 'val') {
  244. str = to.val();
  245. }
  246. if (t == 'html') {
  247. str = to.html();
  248. }
  249. return str;
  250. },
  251. afterCopy: function () {
  252. var $this = $(this);
  253. $this.tipsy("hide").attr('original-title', $this.data('after-title'));
  254. setTimeout(function () {
  255. $this.tipsy("show");
  256. }, 200);
  257. setTimeout(function () {
  258. $this.tipsy('hide').attr('original-title', $this.data('original-title'));
  259. }, 2000);
  260. }
  261. }).addClass("js-copy-bind");
  262. }
  263. })(jQuery);
  264. function initCore() {
  265. Gogs.renderMarkdown();
  266. Gogs.renderCodeView();
  267. // Switch list.
  268. $('.js-tab-nav').click(function (e) {
  269. if (!$(this).hasClass('js-tab-nav-show')) {
  270. $(this).parent().find('.js-tab-nav-show').each(function () {
  271. $(this).removeClass('js-tab-nav-show');
  272. $($(this).data('tab-target')).hide();
  273. });
  274. $(this).addClass('js-tab-nav-show');
  275. $($(this).data('tab-target')).show();
  276. }
  277. e.preventDefault();
  278. });
  279. // Popup.
  280. $(document).on('click', '.popup-modal-dismiss', function (e) {
  281. e.preventDefault();
  282. $.magnificPopup.close();
  283. });
  284. // Plugins.
  285. $('.collapse').hide();
  286. $('.tipsy-tooltip').tipsy({
  287. fade: true
  288. });
  289. }
  290. function initUserSetting() {
  291. // Confirmation of change username in user profile page.
  292. var $username = $('#username');
  293. var $profile_form = $('#user-profile-form');
  294. $('#change-username-btn').magnificPopup({
  295. modal: true,
  296. callbacks: {
  297. open: function () {
  298. if (($username.data('uname') == $username.val())) {
  299. $.magnificPopup.close();
  300. $profile_form.submit();
  301. }
  302. }
  303. }
  304. }).click(function () {
  305. if (($username.data('uname') != $username.val())) {
  306. e.preventDefault();
  307. return true;
  308. }
  309. });
  310. $('#change-username-submit').click(function () {
  311. $.magnificPopup.close();
  312. $profile_form.submit();
  313. });
  314. // Show panels.
  315. $('.show-form-btn').click(function () {
  316. $($(this).data('target-form')).removeClass("hide");
  317. });
  318. // Confirmation of delete account.
  319. $('#delete-account-btn').magnificPopup({
  320. modal: true
  321. }).click(function (e) {
  322. e.preventDefault();
  323. return true;
  324. });
  325. $('#delete-account-submit').click(function () {
  326. $.magnificPopup.close();
  327. $('#delete-account-form').submit();
  328. });
  329. }
  330. function initRepoCreate() {
  331. // Owner switch menu click.
  332. $('#repo-create-owner-list').on('click', 'li', function () {
  333. if (!$(this).hasClass('checked')) {
  334. var uid = $(this).data('uid');
  335. $('#repo-owner-id').val(uid);
  336. $('#repo-owner-avatar').attr("src", $(this).find('img').attr("src"));
  337. $('#repo-owner-name').text($(this).text().trim());
  338. $(this).parent().find('.checked').removeClass('checked');
  339. $(this).addClass('checked');
  340. console.log("set repo owner to uid :", uid, $(this).text().trim());
  341. }
  342. });
  343. $('#auth-button').click(function (e) {
  344. $('#repo-migrate-auth').slideToggle('fast');
  345. e.preventDefault();
  346. })
  347. console.log('initRepoCreate');
  348. }
  349. function initRepo() {
  350. // Clone link switch button.
  351. $('#repo-clone-ssh').click(function () {
  352. $(this).removeClass('btn-gray').addClass('btn-blue');
  353. $('#repo-clone-https').removeClass('btn-blue').addClass('btn-gray');
  354. $('#repo-clone-url').val($(this).data('link'));
  355. $('.clone-url').text($(this).data('link'))
  356. });
  357. $('#repo-clone-https').click(function () {
  358. $(this).removeClass('btn-gray').addClass('btn-blue');
  359. $('#repo-clone-ssh').removeClass('btn-blue').addClass('btn-gray');
  360. $('#repo-clone-url').val($(this).data('link'));
  361. $('.clone-url').text($(this).data('link'))
  362. });
  363. // Copy URL.
  364. var $clone_btn = $('#repo-clone-copy');
  365. $clone_btn.hover(function () {
  366. Gogs.bindCopy($(this));
  367. })
  368. $clone_btn.tipsy({
  369. fade: true
  370. });
  371. }
  372. // when user changes hook type, hide/show proper divs
  373. function initHookTypeChange() {
  374. // web hook type change
  375. $('select#hook-type').on("change", function () {
  376. hookTypes = ['Gogs', 'Slack'];
  377. var curHook = $(this).val();
  378. hookTypes.forEach(function (hookType) {
  379. if (curHook === hookType) {
  380. $('div#' + hookType.toLowerCase()).toggleShow();
  381. }
  382. else {
  383. $('div#' + hookType.toLowerCase()).toggleHide();
  384. }
  385. });
  386. });
  387. }
  388. function initRepoSetting() {
  389. // Options.
  390. // Confirmation of changing repository name.
  391. var $reponame = $('#repo_name');
  392. var $setting_form = $('#repo-setting-form');
  393. $('#change-reponame-btn').magnificPopup({
  394. modal: true,
  395. callbacks: {
  396. open: function () {
  397. if (($reponame.data('repo-name') == $reponame.val())) {
  398. $.magnificPopup.close();
  399. $setting_form.submit();
  400. }
  401. }
  402. }
  403. }).click(function () {
  404. if (($reponame.data('repo-name') != $reponame.val())) {
  405. e.preventDefault();
  406. return true;
  407. }
  408. });
  409. $('#change-reponame-submit').click(function () {
  410. $.magnificPopup.close();
  411. $setting_form.submit();
  412. });
  413. initHookTypeChange();
  414. // Transfer repository.
  415. $('#transfer-repo-btn').magnificPopup({
  416. modal: true
  417. });
  418. $('#transfer-repo-submit').click(function () {
  419. $.magnificPopup.close();
  420. $('#transfer-repo-form').submit();
  421. });
  422. // Delete repository.
  423. $('#delete-repo-btn').magnificPopup({
  424. modal: true
  425. });
  426. $('#delete-repo-submit').click(function () {
  427. $.magnificPopup.close();
  428. $('#delete-repo-form').submit();
  429. });
  430. // Collaboration.
  431. $('#repo-collab-list hr:last-child').remove();
  432. var $ul = $('#repo-collaborator').next().next().find('ul');
  433. $('#repo-collaborator').on('keyup', function () {
  434. var $this = $(this);
  435. if (!$this.val()) {
  436. $ul.toggleHide();
  437. return;
  438. }
  439. Gogs.searchUsers($this.val(), $ul);
  440. }).on('focus', function () {
  441. if (!$(this).val()) {
  442. $ul.toggleHide();
  443. } else {
  444. $ul.toggleShow();
  445. }
  446. }).next().next().find('ul').on("click", 'li', function () {
  447. $('#repo-collaborator').val($(this).text());
  448. $ul.toggleHide();
  449. });
  450. }
  451. function initOrgSetting() {
  452. // Options.
  453. // Confirmation of changing organization name.
  454. var $orgname = $('#orgname');
  455. var $setting_form = $('#org-setting-form');
  456. $('#change-orgname-btn').magnificPopup({
  457. modal: true,
  458. callbacks: {
  459. open: function () {
  460. if (($orgname.data('orgname') == $orgname.val())) {
  461. $.magnificPopup.close();
  462. $setting_form.submit();
  463. }
  464. }
  465. }
  466. }).click(function () {
  467. if (($orgname.data('orgname') != $orgname.val())) {
  468. e.preventDefault();
  469. return true;
  470. }
  471. });
  472. $('#change-orgname-submit').click(function () {
  473. $.magnificPopup.close();
  474. $setting_form.submit();
  475. });
  476. // Confirmation of delete organization.
  477. $('#delete-org-btn').magnificPopup({
  478. modal: true
  479. }).click(function (e) {
  480. e.preventDefault();
  481. return true;
  482. });
  483. $('#delete-org-submit').click(function () {
  484. $.magnificPopup.close();
  485. $('#delete-org-form').submit();
  486. });
  487. initHookTypeChange();
  488. }
  489. function initInvite() {
  490. // Invitation.
  491. var $ul = $('#org-member-invite-list');
  492. $('#org-member-invite').on('keyup', function () {
  493. var $this = $(this);
  494. if (!$this.val()) {
  495. $ul.toggleHide();
  496. return;
  497. }
  498. Gogs.searchUsers($this.val(), $ul);
  499. }).on('focus', function () {
  500. if (!$(this).val()) {
  501. $ul.toggleHide();
  502. } else {
  503. $ul.toggleShow();
  504. }
  505. }).next().next().find('ul').on("click", 'li', function () {
  506. $('#org-member-invite').val($(this).text());
  507. $ul.toggleHide();
  508. });
  509. }
  510. function initOrgTeamCreate() {
  511. // Delete team.
  512. $('#org-team-delete').magnificPopup({
  513. modal: true
  514. }).click(function (e) {
  515. e.preventDefault();
  516. return true;
  517. });
  518. $('#delete-team-submit').click(function () {
  519. $.magnificPopup.close();
  520. var $form = $('#team-create-form');
  521. $form.attr('action', $form.data('delete-url'));
  522. });
  523. }
  524. function initTeamMembersList() {
  525. // Add team member.
  526. var $ul = $('#org-team-members-list');
  527. $('#org-team-members-add').on('keyup', function () {
  528. var $this = $(this);
  529. if (!$this.val()) {
  530. $ul.toggleHide();
  531. return;
  532. }
  533. Gogs.searchUsers($this.val(), $ul);
  534. }).on('focus', function () {
  535. if (!$(this).val()) {
  536. $ul.toggleHide();
  537. } else {
  538. $ul.toggleShow();
  539. }
  540. }).next().next().find('ul').on("click", 'li', function () {
  541. $('#org-team-members-add').val($(this).text());
  542. $ul.toggleHide();
  543. });
  544. }
  545. function initTeamRepositoriesList() {
  546. // Add team repository.
  547. var $ul = $('#org-team-repositories-list');
  548. $('#org-team-repositories-add').on('keyup', function () {
  549. var $this = $(this);
  550. if (!$this.val()) {
  551. $ul.toggleHide();
  552. return;
  553. }
  554. Gogs.searchRepos($this.val(), $ul, 'uid=' + $this.data('uid'));
  555. }).on('focus', function () {
  556. if (!$(this).val()) {
  557. $ul.toggleHide();
  558. } else {
  559. $ul.toggleShow();
  560. }
  561. }).next().next().find('ul').on("click", 'li', function () {
  562. $('#org-team-repositories-add').val($(this).text());
  563. $ul.toggleHide();
  564. });
  565. }
  566. function initAdmin() {
  567. // Create account.
  568. $('#login-type').on("change", function () {
  569. var v = $(this).val();
  570. if (v.indexOf("0-") + 1) {
  571. $('.auth-name').toggleHide();
  572. $(".pwd").find("input").attr("required", "required")
  573. .end().toggleShow();
  574. } else {
  575. $(".pwd").find("input").removeAttr("required")
  576. .end().toggleHide();
  577. $('.auth-name').toggleShow();
  578. }
  579. });
  580. // Delete account.
  581. $('#delete-account-btn').magnificPopup({
  582. modal: true
  583. }).click(function (e) {
  584. e.preventDefault();
  585. return true;
  586. });
  587. $('#delete-account-submit').click(function () {
  588. $.magnificPopup.close();
  589. var $form = $('#user-profile-form');
  590. $form.attr('action', $form.data('delete-url'));
  591. });
  592. // Create authorization.
  593. $('#auth-type').on("change", function () {
  594. var v = $(this).val();
  595. if (v == 2) {
  596. $('.ldap').toggleShow();
  597. $('.smtp').toggleHide();
  598. }
  599. if (v == 3) {
  600. $('.smtp').toggleShow();
  601. $('.ldap').toggleHide();
  602. }
  603. });
  604. // Delete authorization.
  605. $('#delete-auth-btn').magnificPopup({
  606. modal: true
  607. }).click(function (e) {
  608. e.preventDefault();
  609. return true;
  610. });
  611. $('#delete-auth-submit').click(function () {
  612. $.magnificPopup.close();
  613. var $form = $('#auth-setting-form');
  614. $form.attr('action', $form.data('delete-url'));
  615. });
  616. }
  617. function initInstall() {
  618. // Change database type.
  619. (function () {
  620. var mysql_default = '127.0.0.1:3306';
  621. var postgres_default = '127.0.0.1:5432';
  622. $('#install-database').on("change", function () {
  623. var val = $(this).val();
  624. if (val != "SQLite3") {
  625. $('.server-sql').show();
  626. $('.sqlite-setting').addClass("hide");
  627. if (val == "PostgreSQL") {
  628. $('.pgsql-setting').removeClass("hide");
  629. // Change the host value to the Postgres default, but only
  630. // if the user hasn't already changed it from the MySQL
  631. // default.
  632. if ($('#database-host').val() == mysql_default) {
  633. $('#database-host').val(postgres_default);
  634. }
  635. } else if (val == 'MySQL') {
  636. $('.pgsql-setting').addClass("hide");
  637. if ($('#database-host').val() == postgres_default) {
  638. $('#database-host').val(mysql_default);
  639. }
  640. } else {
  641. $('.pgsql-setting').addClass("hide");
  642. }
  643. } else {
  644. $('.server-sql').hide();
  645. $('.pgsql-setting').hide();
  646. $('.sqlite-setting').removeClass("hide");
  647. }
  648. });
  649. }());
  650. }
  651. function initProfile() {
  652. // Avatar.
  653. $('#profile-avatar').tipsy({
  654. fade: true
  655. });
  656. }
  657. function initTimeSwitch() {
  658. // Time switch.
  659. $(".time-since[title]").on("click", function () {
  660. var $this = $(this);
  661. var title = $this.attr("title");
  662. var text = $this.text();
  663. $this.text(title);
  664. $this.attr("title", text);
  665. });
  666. }
  667. function initDiff() {
  668. $('.diff-detail-box>a').click(function () {
  669. $($(this).data('target')).slideToggle(100);
  670. })
  671. var $counter = $('.diff-counter');
  672. if ($counter.length < 1) {
  673. return;
  674. }
  675. $counter.each(function (i, item) {
  676. var $item = $(item);
  677. var addLine = $item.find('span[data-line].add').data("line");
  678. var delLine = $item.find('span[data-line].del').data("line");
  679. var addPercent = parseFloat(addLine) / (parseFloat(addLine) + parseFloat(delLine)) * 100;
  680. $item.find(".bar .add").css("width", addPercent + "%");
  681. });
  682. }
  683. $(document).ready(function () {
  684. Gogs.AppSubUrl = $('head').data('suburl') || '';
  685. initCore();
  686. if ($('#user-profile-setting').length) {
  687. initUserSetting();
  688. }
  689. if ($('#repo-create-form').length || $('#repo-migrate-form').length) {
  690. initRepoCreate();
  691. }
  692. if ($('#repo-header').length) {
  693. initRepo();
  694. }
  695. if ($('#repo-setting').length) {
  696. initRepoSetting();
  697. }
  698. if ($('#org-setting').length) {
  699. initOrgSetting();
  700. }
  701. if ($('#invite-box').length) {
  702. initInvite();
  703. }
  704. if ($('#team-create-form').length) {
  705. initOrgTeamCreate();
  706. }
  707. if ($('#team-members-list').length) {
  708. initTeamMembersList();
  709. }
  710. if ($('#team-repositories-list').length) {
  711. initTeamRepositoriesList();
  712. }
  713. if ($('#admin-setting').length) {
  714. initAdmin();
  715. }
  716. if ($('#install-form').length) {
  717. initInstall();
  718. }
  719. if ($('#user-profile-page').length) {
  720. initProfile();
  721. }
  722. if ($('#diff-page').length) {
  723. initTimeSwitch();
  724. initDiff();
  725. }
  726. $('#dashboard-sidebar-menu').tabs();
  727. $('#pull-issue-preview').markdown_preview(".issue-add-comment");
  728. homepage();
  729. // Fix language drop-down menu height.
  730. var l = $('#footer-lang li').length;
  731. $('#footer-lang .drop-down').css({
  732. "top": (-31 * l) + "px",
  733. "height": (31 * l - 3) + "px"
  734. });
  735. });
  736. function homepage() {
  737. // Change method to GET if no username input.
  738. $('#promo-form').submit(function (e) {
  739. if ($('#username').val() === "") {
  740. e.preventDefault();
  741. window.location.href = Gogs.AppSubUrl + '/user/login';
  742. return true
  743. }
  744. });
  745. // Redirect to register page.
  746. $('#register-button').click(function (e) {
  747. if ($('#username').val() === "") {
  748. e.preventDefault();
  749. window.location.href = Gogs.AppSubUrl + '/user/sign_up';
  750. return true
  751. }
  752. $('#promo-form').attr('action', Gogs.AppSubUrl + '/user/sign_up');
  753. });
  754. }