Skip to content

Commit 9efecd1

Browse files
Style for scaladex autocomplete
1 parent 10e462e commit 9efecd1

File tree

4 files changed

+73
-33
lines changed

4 files changed

+73
-33
lines changed

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ defaults:
3030
layout: blog-detail
3131
includeTOC: true
3232

33-
# Custom collections
33+
# Custom collections
3434
collections:
3535
scala_items:
3636
output: false

_sass/layout/scala-ecosystem.scss

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,33 +93,52 @@
9393
}
9494
}
9595

96-
.autocomplete-suggestions {
97-
border: 1px solid $gray-light;
98-
background: #FFF;
99-
overflow: auto;
100-
}
96+
}
10197

102-
.autocomplete-suggestion {
103-
padding: 2px 5px;
104-
white-space: nowrap;
105-
overflow: hidden;
106-
}
98+
.autocomplete-suggestions {
99+
width: 100%;
100+
background: #fff;
101+
top: 42px;
102+
left: 0;
103+
position: absolute;
104+
z-index: 9999;
105+
-webkit-box-shadow: 0 2px 20px rgba(0, 0, 0, 0.2);
106+
box-shadow: 0 2px 20px rgba(0, 0, 0, 0.2);
107+
}
107108

108-
.autocomplete-selected {
109-
background: $gray-lighter;
110-
}
109+
.autocomplete-suggestions {
110+
padding: 0;
111+
margin: 0;
112+
}
111113

112-
.autocomplete-suggestions strong {
113-
font-weight: normal;
114-
color: $gray-dark;
115-
}
114+
.autocomplete-suggestions .autocomplete-suggestion {
115+
padding: 15px;
116+
list-style: none;
117+
border-bottom: 1px solid rgba(0, 43, 55, 0.1);
118+
}
116119

117-
.autocomplete-group {
118-
padding: 2px 5px;
119-
}
120+
.autocomplete-suggestions .autocomplete-suggestion:last-child {
121+
border-bottom: none;
122+
}
120123

121-
.autocomplete-group strong {
122-
display: block;
123-
border-bottom: 1px solid $gray-light;
124-
}
124+
.autocomplete-suggestions .autocomplete-suggestion a {
125+
color: #586e75;
126+
}
127+
128+
.autocomplete-suggestions .autocomplete-suggestion a:hover,
129+
.autocomplete-suggestions .autocomplete-suggestion a:active,
130+
.autocomplete-suggestions .autocomplete-suggestion a:focus {
131+
text-decoration: none;
132+
}
133+
134+
.autocomplete-suggestions .autocomplete-suggestion a p {
135+
color: #224951;
136+
margin: 0;
137+
font-weight: 400;
138+
}
139+
140+
.autocomplete-suggestions .autocomplete-suggestion:hover,
141+
.autocomplete-suggestions .autocomplete-suggestion.selected {
142+
background: #edf1f1;
143+
cursor: default;
125144
}

index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ scalaIDEs:
6262

6363
# Scala ecosystem
6464
ecosystemTitle: "Scala ecosystem"
65-
ecosystemDescription: "The Scala Library Index (or Scaladex) is a representation of a map of all published Scala libraries. With Scaladex, a developer can now query more than 100,000 releases of Scala libraries. Scaladex is officially supported by Scala Center."
65+
ecosystemDescription: "The Scala Library Index (or Scaladex) is a representation of a map of all published Scala libraries. With Scaladex, a developer can now query more than 175,000 releases of Scala libraries. Scaladex is officially supported by Scala Center."
6666
---

resources/js/functions.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ $('#scaladex-search').on('blur', function(e) {
142142
}
143143
});
144144

145+
function scaladexUrl(item) {
146+
return 'https://scaladex.scala-lang.org/' + item.organization + "/" + item.repository;
147+
}
148+
145149
$('#scaladex-search').autocomplete({
146150
paramName: 'q',
147151
serviceUrl: 'https://index.scala-lang.org/api/autocomplete',
@@ -157,11 +161,14 @@ $('#scaladex-search').autocomplete({
157161
}
158162
},
159163
transformResult: function(response) {
160-
return {
161-
suggestions: $.map(response, function(dataItem) {
162-
return { value: dataItem.repository, data: 'https://scaladex.scala-lang.org/' + dataItem.organization + "/" + dataItem.repository };
163-
})
164-
};
164+
return {
165+
suggestions: $.map(response, function(dataItem) {
166+
return {
167+
value: dataItem.organization + " / " + dataItem.repository,
168+
data: dataItem
169+
};
170+
})
171+
};
165172
},
166173
onSearchComplete: function (query, suggestions) {
167174
suggestions.length > 0 ? showSuggestions() : hideSuggestions();
@@ -171,10 +178,24 @@ $('#scaladex-search').autocomplete({
171178
prevResult = suggestion.data;
172179
hideSuggestions();
173180
$("#scaladex-search").blur();
174-
window.open(suggestion.data, '_blank');
181+
window.open(scaladexUrl(suggestion.data), '_blank');
175182
}
176-
}
183+
},
184+
formatResult: function(suggestion){
185+
var item = suggestion.data;
177186

187+
var url = scaladexUrl(item);
188+
189+
var title = item.organization + " / " + item.repository;
190+
191+
return '<a href="' + url + '">' + '\n' +
192+
' <p>' + title + '</p>' + '\n' +
193+
' <span>' + '\n' +
194+
item.description
195+
' </span>' + '\n' +
196+
'</a>';
197+
198+
}
178199
});
179200

180201
$(document).ready(function() {

0 commit comments

Comments
 (0)