diff options
author | Roger Luo <rogerluo410@gmail.com> | 2021-03-18 10:02:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-17 22:02:38 -0400 |
commit | 119d2cb6e4abb4da90f0da6c908d52e4c26a49a4 (patch) | |
tree | aeb2cc30190edc0345315c821ca0f9c082eeb47f /web_src/js/index.js | |
parent | 03e99f847c357264597132006c9cf585626c36d8 (diff) | |
download | gitea-119d2cb6e4abb4da90f0da6c908d52e4c26a49a4.tar.gz gitea-119d2cb6e4abb4da90f0da6c908d52e4c26a49a4.zip |
Create new issue from code (#14863)
* Feat: add reference in new issue with permalink menu for code view.
* Fix: recover index.js file.
* Add comments and redo ci.
* Fix code convention
* Fix code.
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'web_src/js/index.js')
-rw-r--r-- | web_src/js/index.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/web_src/js/index.js b/web_src/js/index.js index ccd9276059..6c30d14fbb 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -2167,6 +2167,45 @@ function searchRepositories() { }); } +function showCodeViewMenu() { + // Get clicked tr + const $code_tr = $('.code-view td.lines-code.active').parent(); + + // Reset code line marker + $('.code-view-menu-list').appendTo($('.code-view')); + $('.code-line-marker').remove(); + + // Generate new one + const icon_wrap = $('<div>', { + class: 'code-line-marker' + }).prependTo($code_tr.find('td:eq(0)').get(0)).hide(); + + const a_wrap = $('<a>', { + class: 'code-line-link' + }).appendTo(icon_wrap); + + $('<i>', { + class: 'dropdown icon', + style: 'margin: 0px;' + }).appendTo(a_wrap); + + icon_wrap.css({ + left: '-7px', + display: 'block', + }); + + $('.code-view-menu-list').css({ + 'min-width': '220px', + }); + + // Popup the menu + $('.code-line-link').popup({ + popup: $('.code-view-menu-list'), + on: 'click', + lastResort: 'bottom left', + }); +} + function initCodeView() { if ($('.code-view .lines-num').length > 0) { $(document).on('click', '.lines-num span', function (e) { @@ -2179,6 +2218,9 @@ function initCodeView() { } selectRange($list, $list.filter(`[rel=${$select.attr('id')}]`), (e.shiftKey ? $list.filter('.active').eq(0) : null)); deSelect(); + + // show code view menu marker + showCodeViewMenu(); }); $(window).on('hashchange', () => { @@ -2193,6 +2235,10 @@ function initCodeView() { if (m) { $first = $list.filter(`[rel=${m[1]}]`); selectRange($list, $first, $list.filter(`[rel=${m[2]}]`)); + + // show code view menu marker + showCodeViewMenu(); + $('html, body').scrollTop($first.offset().top - 200); return; } @@ -2200,6 +2246,10 @@ function initCodeView() { if (m) { $first = $list.filter(`[rel=L${m[2]}]`); selectRange($list, $first); + + // show code view menu marker + showCodeViewMenu(); + $('html, body').scrollTop($first.offset().top - 200); } }).trigger('hashchange'); @@ -2752,11 +2802,30 @@ function selectRange($list, $select, $from) { } $list.filter(classes.join(',')).addClass('active'); changeHash(`#L${a}-L${b}`); + + // add hashchange to permalink + const $issue = $('a.ref-in-new-issue'); + const matched = $issue.attr('href').match(/%23L\d+$|%23L\d+-L\d+$/); + if (matched) { + $issue.attr('href', $issue.attr('href').replace($issue.attr('href').substr(matched.index), `%23L${a}-L${b}`)); + } else { + $issue.attr('href', `${$issue.attr('href')}%23L${a}-L${b}`); + } + return; } } $select.addClass('active'); changeHash(`#${$select.attr('rel')}`); + + // add hashchange to permalink + const $issue = $('a.ref-in-new-issue'); + const matched = $issue.attr('href').match(/%23L\d+$|%23L\d+-L\d+$/); + if (matched) { + $issue.attr('href', $issue.attr('href').replace($issue.attr('href').substr(matched.index), `%23${$select.attr('rel')}`)); + } else { + $issue.attr('href', `${$issue.attr('href')}%23${$select.attr('rel')}`); + } } $(() => { |