@ -1230,104 +1230,53 @@ function hideWhenLostFocus(body, parent) {
}
}
function searchUsers ( ) {
function searchUsers ( ) {
if ( ! $ ( '#search-user-box .results' ) . length ) {
return ;
}
var $searchUserBox = $ ( '#search-user-box' ) ;
var $searchUserBox = $ ( '#search-user-box' ) ;
var $results = $searchUserBox . find ( '.results' ) ;
$searchUserBox . search ( {
$searchUserBox . keyup ( function ( ) {
minCharacters : 2 ,
var $this = $ ( this ) ;
apiSettings : {
var keyword = $this . find ( 'input' ) . val ( ) ;
url : suburl + '/api/v1/users/search?q={query}' ,
if ( keyword . length < 2 ) {
onResponse : function ( response ) {
$results . hide ( ) ;
var items = [ ] ;
return ;
}
$ . ajax ( {
url : suburl + '/api/v1/users/search?q=' + keyword ,
dataType : "json" ,
success : function ( response ) {
var notEmpty = function ( str ) {
return str && str . length > 0 ;
} ;
$results . html ( '' ) ;
if ( response . ok && response . data . length ) {
var html = '' ;
$ . each ( response . data , function ( i , item ) {
$ . each ( response . data , function ( i , item ) {
html += '<div class="item"><img class="ui avatar image" src="' + item . avatar _url + '"><span class="username">' + item . login + '</span>' ;
var title = item . login ;
if ( notEmpty ( item . full _name ) ) {
if ( item . full _name && item . full _name . length > 0 ) {
html += ' (' + item . full _name + ')' ;
title += ' (' + item . full _name + ')' ;
}
}
html += '</div>' ;
items . push ( {
} ) ;
title : title ,
$results . html ( html ) ;
image : item . avatar _url
$this . find ( '.results .item' ) . click ( function ( ) {
} )
$this . find ( 'input' ) . val ( $ ( this ) . find ( '.username' ) . text ( ) ) ;
$results . hide ( ) ;
} ) ;
} ) ;
$results . show ( ) ;
} else {
return { results : items }
$results . hide ( ) ;
}
}
}
} ,
searchFields : [ 'login' , 'full_name' ] ,
showNoResults : false
} ) ;
} ) ;
} ) ;
$searchUserBox . find ( 'input' ) . focus ( function ( ) {
$searchUserBox . keyup ( ) ;
} ) ;
hideWhenLostFocus ( '#search-user-box .results' , '#search-user-box' ) ;
}
}
// FIXME: merge common parts in two functions
function searchRepositories ( ) {
function searchRepositories ( ) {
if ( ! $ ( '#search-repo-box .results' ) . length ) {
return ;
}
var $searchRepoBox = $ ( '#search-repo-box' ) ;
var $searchRepoBox = $ ( '#search-repo-box' ) ;
var $results = $searchRepoBox . find ( '.results' ) ;
$searchRepoBox . search ( {
$searchRepoBox . keyup ( function ( ) {
minCharacters : 2 ,
var $this = $ ( this ) ;
apiSettings : {
var keyword = $this . find ( 'input' ) . val ( ) ;
url : suburl + '/api/v1/repos/search?q={query}&uid=' + $searchRepoBox . data ( 'uid' ) ,
if ( keyword . length < 2 ) {
onResponse : function ( response ) {
$results . hide ( ) ;
var items = [ ] ;
return ;
}
$ . ajax ( {
url : suburl + '/api/v1/repos/search?q=' + keyword + "&uid=" + $searchRepoBox . data ( 'uid' ) ,
dataType : "json" ,
success : function ( response ) {
var notEmpty = function ( str ) {
return str && str . length > 0 ;
} ;
$results . html ( '' ) ;
if ( response . ok && response . data . length ) {
var html = '' ;
$ . each ( response . data , function ( i , item ) {
$ . 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>' ;
items . push ( {
} ) ;
title : item . full _name . split ( "/" ) [ 1 ] ,
$results . html ( html ) ;
description : item . full _name
$this . find ( '.results .item' ) . click ( function ( ) {
} )
$this . find ( 'input' ) . val ( $ ( this ) . find ( '.fullname' ) . text ( ) . split ( "/" ) [ 1 ] ) ;
$results . hide ( ) ;
} ) ;
} ) ;
$results . show ( ) ;
} else {
return { results : items }
$results . hide ( ) ;
}
}
}
} ,
searchFields : [ 'full_name' ] ,
showNoResults : false
} ) ;
} ) ;
} ) ;
$searchRepoBox . find ( 'input' ) . focus ( function ( ) {
$searchRepoBox . keyup ( ) ;
} ) ;
hideWhenLostFocus ( '#search-repo-box .results' , '#search-repo-box' ) ;
}
}
function initCodeView ( ) {
function initCodeView ( ) {