@@ -8,7 +8,7 @@ import scala.concurrent.duration._
88class 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 }
0 commit comments