forked from forgejo/forgejo
fix #650
This commit is contained in:
parent
b80e848d02
commit
52c8f69163
84 changed files with 746 additions and 12755 deletions
|
@ -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');
|
||||
}
|
||||
|
||||
if (!$(target).is('#search-user-box .results') && !$(target).parents().is('#search-user-box')) {
|
||||
$('#search-user-box .results').hide();
|
||||
function searchRepositories() {
|
||||
if (!$('#search-repo-box .results').length) {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue