@@ -8,7 +8,7 @@ import scala.concurrent.duration._
8
8
class SearchbarComponent (engine : SearchbarEngine , inkuireEngine : InkuireJSSearchEngine , parser : QueryParser ):
9
9
val resultsChunkSize = 100
10
10
extension (p : PageEntry )
11
- def toHTML =
11
+ def toHTML ( inkuire : Boolean = false ) =
12
12
val wrapper = document.createElement(" div" ).asInstanceOf [html.Div ]
13
13
wrapper.classList.add(" scaladoc-searchbar-result" )
14
14
wrapper.classList.add(" monospace" )
@@ -18,33 +18,7 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
18
18
icon.classList.add(p.kind.take(2 ))
19
19
20
20
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
48
22
resultA.text = s " ${p.fullName}"
49
23
50
24
val location = document.createElement(" span" )
@@ -61,7 +35,7 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
61
35
wrapper
62
36
63
37
def handleNewFluffQuery (matchers : List [Matchers ]) =
64
- val result = engine.query(matchers).map(_.toHTML)
38
+ val result = engine.query(matchers).map(_.toHTML(inkuire = false ) )
65
39
resultsDiv.scrollTop = 0
66
40
while (resultsDiv.hasChildNodes()) resultsDiv.removeChild(resultsDiv.lastChild)
67
41
val fragment = document.createDocumentFragment()
@@ -85,31 +59,35 @@ class SearchbarComponent(engine: SearchbarEngine, inkuireEngine: InkuireJSSearch
85
59
wrapper.classList.add(" scaladoc-searchbar-result" )
86
60
wrapper.classList.add(" monospace" )
87
61
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
90
65
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)
97
67
wrapper
98
68
99
69
var timeoutHandle : SetTimeoutHandle = null
100
70
def handleNewQuery (query : String ) =
101
71
clearTimeout(timeoutHandle)
102
72
resultsDiv.scrollTop = 0
73
+ resultsDiv.onscroll = (event : Event ) => { }
103
74
while (resultsDiv.hasChildNodes()) resultsDiv.removeChild(resultsDiv.lastChild)
104
75
val fragment = document.createDocumentFragment()
105
76
parser.parse(query) match {
106
77
case EngineMatchersQuery (matchers) =>
107
78
handleNewFluffQuery(matchers)
108
79
case BySignature (signature) =>
109
80
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)
110
87
inkuireEngine.query(query) { (p : PageEntry ) =>
111
- resultsDiv.appendChild(p.toHTMLInkuireHack )
88
+ resultsDiv.appendChild(p.toHTML(inkuire = true ) )
112
89
} { (s : String ) =>
90
+ animation.classList.remove(" loading" )
113
91
resultsDiv.appendChild(s.toHTMLError)
114
92
}
115
93
}
0 commit comments