@@ -1230,104 +1230,53 @@ function hideWhenLostFocus(body, parent) {
12301230}
12311231
12321232function searchUsers ( ) {
1233- if ( ! $ ( '#search-user-box .results' ) . length ) {
1234- return ;
1235- }
1236-
12371233 var $searchUserBox = $ ( '#search-user-box' ) ;
1238- var $results = $searchUserBox . find ( '.results' ) ;
1239- $searchUserBox . keyup ( function ( ) {
1240- var $this = $ ( this ) ;
1241- var keyword = $this . find ( 'input' ) . val ( ) ;
1242- if ( keyword . length < 2 ) {
1243- $results . hide ( ) ;
1244- return ;
1245- }
1234+ $searchUserBox . search ( {
1235+ minCharacters : 2 ,
1236+ apiSettings : {
1237+ url : suburl + '/api/v1/users/search?q={query}' ,
1238+ onResponse : function ( response ) {
1239+ var items = [ ] ;
1240+ $ . each ( response . data , function ( i , item ) {
1241+ var title = item . login ;
1242+ if ( item . full_name && item . full_name . length > 0 ) {
1243+ title += ' (' + item . full_name + ')' ;
1244+ }
1245+ items . push ( {
1246+ title : title ,
1247+ image : item . avatar_url
1248+ } )
1249+ } ) ;
12461250
1247- $ . ajax ( {
1248- url : suburl + '/api/v1/users/search?q=' + keyword ,
1249- dataType : "json" ,
1250- success : function ( response ) {
1251- var notEmpty = function ( str ) {
1252- return str && str . length > 0 ;
1253- } ;
1254-
1255- $results . html ( '' ) ;
1256-
1257- if ( response . ok && response . data . length ) {
1258- var html = '' ;
1259- $ . each ( response . data , function ( i , item ) {
1260- html += '<div class="item"><img class="ui avatar image" src="' + item . avatar_url + '"><span class="username">' + item . login + '</span>' ;
1261- if ( notEmpty ( item . full_name ) ) {
1262- html += ' (' + item . full_name + ')' ;
1263- }
1264- html += '</div>' ;
1265- } ) ;
1266- $results . html ( html ) ;
1267- $this . find ( '.results .item' ) . click ( function ( ) {
1268- $this . find ( 'input' ) . val ( $ ( this ) . find ( '.username' ) . text ( ) ) ;
1269- $results . hide ( ) ;
1270- } ) ;
1271- $results . show ( ) ;
1272- } else {
1273- $results . hide ( ) ;
1274- }
1251+ return { results : items }
12751252 }
1276- } ) ;
1277- } ) ;
1278- $searchUserBox . find ( 'input' ) . focus ( function ( ) {
1279- $searchUserBox . keyup ( ) ;
1253+ } ,
1254+ searchFields : [ 'login' , 'full_name' ] ,
1255+ showNoResults : false
12801256 } ) ;
1281- hideWhenLostFocus ( '#search-user-box .results' , '#search-user-box' ) ;
12821257}
12831258
1284- // FIXME: merge common parts in two functions
12851259function searchRepositories ( ) {
1286- if ( ! $ ( '#search-repo-box .results' ) . length ) {
1287- return ;
1288- }
1289-
12901260 var $searchRepoBox = $ ( '#search-repo-box' ) ;
1291- var $results = $searchRepoBox . find ( '.results' ) ;
1292- $searchRepoBox . keyup ( function ( ) {
1293- var $this = $ ( this ) ;
1294- var keyword = $this . find ( 'input' ) . val ( ) ;
1295- if ( keyword . length < 2 ) {
1296- $results . hide ( ) ;
1297- return ;
1298- }
1299-
1300- $ . ajax ( {
1301- url : suburl + '/api/v1/repos/search?q=' + keyword + "&uid=" + $searchRepoBox . data ( 'uid' ) ,
1302- dataType : "json" ,
1303- success : function ( response ) {
1304- var notEmpty = function ( str ) {
1305- return str && str . length > 0 ;
1306- } ;
1307-
1308- $results . html ( '' ) ;
1261+ $searchRepoBox . search ( {
1262+ minCharacters : 2 ,
1263+ apiSettings : {
1264+ url : suburl + '/api/v1/repos/search?q={query}&uid=' + $searchRepoBox . data ( 'uid' ) ,
1265+ onResponse : function ( response ) {
1266+ var items = [ ] ;
1267+ $ . each ( response . data , function ( i , item ) {
1268+ items . push ( {
1269+ title : item . full_name . split ( "/" ) [ 1 ] ,
1270+ description : item . full_name
1271+ } )
1272+ } ) ;
13091273
1310- if ( response . ok && response . data . length ) {
1311- var html = '' ;
1312- $ . each ( response . data , function ( i , item ) {
1313- html += '<div class="item"><i class="icon octicon octicon-repo"></i> <span class="fullname">' + item . full_name + '</span></div>' ;
1314- } ) ;
1315- $results . html ( html ) ;
1316- $this . find ( '.results .item' ) . click ( function ( ) {
1317- $this . find ( 'input' ) . val ( $ ( this ) . find ( '.fullname' ) . text ( ) . split ( "/" ) [ 1 ] ) ;
1318- $results . hide ( ) ;
1319- } ) ;
1320- $results . show ( ) ;
1321- } else {
1322- $results . hide ( ) ;
1323- }
1274+ return { results : items }
13241275 }
1325- } ) ;
1326- } ) ;
1327- $searchRepoBox . find ( 'input' ) . focus ( function ( ) {
1328- $searchRepoBox . keyup ( ) ;
1276+ } ,
1277+ searchFields : [ 'full_name' ] ,
1278+ showNoResults : false
13291279 } ) ;
1330- hideWhenLostFocus ( '#search-repo-box .results' , '#search-repo-box' ) ;
13311280}
13321281
13331282function initCodeView ( ) {
0 commit comments