Skip to content

Commit 9472679

Browse files
committed
Various small improvements
1 parent 21bbe87 commit 9472679

File tree

8 files changed

+1979
-1937
lines changed

8 files changed

+1979
-1937
lines changed

scaladoc-js/resources/scaladoc-searchbar.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
border: none;
5959
border-bottom: 1px solid #bbb;
6060
padding: 10px;
61+
color: black;
6162
}
6263

6364
#scaladoc-searchbar-input:focus {

scaladoc-js/src/searchbar/SearchbarComponent.scala

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import scala.concurrent.duration._
88
class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearchEngine, parser: QueryParser):
99
val resultsChunkSize = 100
1010
extension (p: PageEntry)
11-
def toHTML =
11+
def toHTML(inkuire: Boolean = false) =
1212
val wrapper = document.createElement("div").asInstanceOf[html.Div]
1313
wrapper.classList.add("scaladoc-searchbar-result")
1414
wrapper.classList.add("monospace")
@@ -18,33 +18,7 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
1818
icon.classList.add(p.kind.take(2))
1919

2020
val resultA = document.createElement("a").asInstanceOf[html.Anchor]
21-
resultA.href = Globals.pathToRoot + p.location
22-
resultA.text = s"${p.fullName}"
23-
24-
val location = document.createElement("span")
25-
location.classList.add("pull-right")
26-
location.classList.add("scaladoc-searchbar-location")
27-
location.textContent = p.description
28-
29-
wrapper.appendChild(icon)
30-
wrapper.appendChild(resultA)
31-
wrapper.appendChild(location)
32-
wrapper.addEventListener("mouseover", {
33-
case e: MouseEvent => handleHover(wrapper)
34-
})
35-
wrapper
36-
37-
def toHTMLInkuireHack =
38-
val wrapper = document.createElement("div").asInstanceOf[html.Div]
39-
wrapper.classList.add("scaladoc-searchbar-result")
40-
wrapper.classList.add("monospace")
41-
42-
val icon = document.createElement("span").asInstanceOf[html.Span]
43-
icon.classList.add("micon")
44-
icon.classList.add(p.kind.take(2))
45-
46-
val resultA = document.createElement("a").asInstanceOf[html.Anchor]
47-
resultA.href = p.location
21+
resultA.href = if inkuire then p.location else Globals.pathToRoot + p.location
4822
resultA.text = s"${p.fullName}"
4923

5024
val location = document.createElement("span")
@@ -61,7 +35,7 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
6135
wrapper
6236

6337
def handleNewFluffQuery(matchers: List[Matchers]) =
64-
val result = engine.query(matchers).map(_.toHTML)
38+
val result = engine.query(matchers).map(_.toHTML(inkuire = false))
6539
resultsDiv.scrollTop = 0
6640
while (resultsDiv.hasChildNodes()) resultsDiv.removeChild(resultsDiv.lastChild)
6741
val fragment = document.createDocumentFragment()
@@ -85,31 +59,35 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
8559
wrapper.classList.add("scaladoc-searchbar-result")
8660
wrapper.classList.add("monospace")
8761

88-
val resultA = document.createElement("a").asInstanceOf[html.Anchor]
89-
resultA.text = s
62+
val errorSpan = document.createElement("span").asInstanceOf[html.Span]
63+
errorSpan.classList.add("search-error")
64+
errorSpan.textContent = s
9065

91-
val location = document.createElement("span")
92-
location.classList.add("pull-right")
93-
location.classList.add("scaladoc-searchbar-location")
94-
95-
wrapper.appendChild(resultA)
96-
wrapper.appendChild(location)
66+
wrapper.appendChild(errorSpan)
9767
wrapper
9868

9969
var timeoutHandle: SetTimeoutHandle = null
10070
def handleNewQuery(query: String) =
10171
clearTimeout(timeoutHandle)
10272
resultsDiv.scrollTop = 0
73+
resultsDiv.onscroll = (event: Event) => { }
10374
while (resultsDiv.hasChildNodes()) resultsDiv.removeChild(resultsDiv.lastChild)
10475
val fragment = document.createDocumentFragment()
10576
parser.parse(query) match {
10677
case EngineMatchersQuery(matchers) =>
10778
handleNewFluffQuery(matchers)
10879
case BySignature(signature) =>
10980
timeoutHandle = setTimeout(1.second) {
81+
val loading = document.createElement("div").asInstanceOf[html.Div]
82+
loading.classList.add("loading-wrapper")
83+
val animation = document.createElement("div").asInstanceOf[html.Div]
84+
animation.classList.add("loading")
85+
loading.appendChild(animation)
86+
resultsDiv.appendChild(loading)
11087
inkuireEngine.query(query) { (p: PageEntry) =>
111-
resultsDiv.appendChild(p.toHTMLInkuireHack)
88+
resultsDiv.appendChild(p.toHTML(inkuire = true))
11289
} { (s: String) =>
90+
animation.classList.remove("loading")
11391
resultsDiv.appendChild(s.toHTMLError)
11492
}
11593
}

scaladoc-js/src/searchbar/engine/InkuireJSSearchEngine.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ class InkuireJSSearchEngine {
2727
)
2828
}
2929

30-
def query(s: String)(callback: PageEntry => Node)(errorCallback: String => Node): List[PageEntry] = {
30+
def query(s: String)(callback: PageEntry => Node)(endCallback: String => Node): List[PageEntry] = {
3131
worker.onmessage = _ => ()
3232
val res = ListBuffer[PageEntry]()
3333
val func = (msg: MessageEvent) => {
3434
msg.data.asInstanceOf[String] match {
3535
case "engine_ready" =>
3636
case "new_query" =>
37+
case endMsg if endMsg.startsWith("query_ended") =>
38+
endCallback(endMsg.drop("query_ended".length))
3739
case q =>
3840
val matches = JSON.parse(q).matches
3941
val actualMatches = matches.asInstanceOf[js.Array[Dynamic]].map(dynamicToPageEntry)

0 commit comments

Comments
 (0)