diff options
author | Unknwon <u@gogs.io> | 2015-11-22 01:32:09 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-11-22 01:32:09 -0500 |
commit | 52c8f691630548fe091d30bcfe8164545a05d3d5 (patch) | |
tree | 12ad797f4c2f8ae6ea81e59e4a0e73ec76abaef3 /public/js | |
parent | b80e848d02b4e27e067910c03aadeddcbdd5f3f5 (diff) | |
download | gitea-52c8f691630548fe091d30bcfe8164545a05d3d5.tar.gz gitea-52c8f691630548fe091d30bcfe8164545a05d3d5.zip |
fix #650
Diffstat (limited to 'public/js')
-rw-r--r-- | public/js/gogs.js | 60 |
1 files changed, 56 insertions, 4 deletions
diff --git a/public/js/gogs.js b/public/js/gogs.js index d429516e4b..0fd2b46ab9 100644 --- a/public/js/gogs.js +++ b/public/js/gogs.js @@ -564,6 +564,16 @@ function buttonsClickOnEnter() { }); } +function hideWhenLostFocus(body, parent) { + $(document).click(function (e) { + var target = e.target; + + if (!$(target).is(body) && !$(target).parents().is(parent)) { + $(body).hide(); + } + }); +} + function searchUsers() { if (!$('#search-user-box .results').length) { return; @@ -613,12 +623,53 @@ function searchUsers() { $search_user_box.find('input').focus(function () { $search_user_box.keyup(); }); - $(document).click(function (e) { - var target = e.target; + hideWhenLostFocus('#search-user-box .results', '#search-user-box'); +} + +function searchRepositories() { + if (!$('#search-repo-box .results').length) { + return; + } - if (!$(target).is('#search-user-box .results') && !$(target).parents().is('#search-user-box')) { - $('#search-user-box .results').hide(); + var $search_repo_box = $('#search-repo-box'); + var $result_list = $search_repo_box.find('.results'); + $search_repo_box.keyup(function () { + var $this = $(this); + var keyword = $this.find('input').val(); + if (keyword.length < 2) { + $result_list.hide(); + return; } + + $.ajax({ + url: suburl + '/api/v1/repos/search?q=' + keyword + "&uid=" + $search_repo_box.data('uid'), + dataType: "json", + success: function (response) { + var notEmpty = function (str) { + return str && str.length > 0; + }; + + $result_list.html(''); + + if (response.ok && response.data.length) { + var html = ''; + $.each(response.data, function (i, item) { + html += '<div class="item"><i class="icon octicon octicon-repo"></i> <span class="fullname">' + item.full_name + '</span></div>'; + }); + $result_list.html(html); + $this.find('.results .item').click(function () { + $this.find('input').val($(this).find('.fullname').text().split("/")[1]); + $result_list.hide(); + }); + $result_list.show(); + } else { + $result_list.hide(); + } + } + }); + }); + $search_repo_box.find('input').focus(function () { + $search_repo_box.keyup(); }); } @@ -776,6 +827,7 @@ $(document).ready(function () { buttonsClickOnEnter(); searchUsers(); + searchRepositories(); initCommentForm(); |