Skip to content

Commit 84feae8

Browse files
committed
Change local storage to session storage, fix bugs with undefined js variable
1 parent d7bd586 commit 84feae8

File tree

5 files changed

+52
-34
lines changed

5 files changed

+52
-34
lines changed

scaladoc-js/src/versions-dropdown/DropdownHandler.scala

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class DropdownHandler:
2727
child.href = v
2828
child.text = k
2929
ddc.appendChild(child)
30+
val arrow = document.createElement("span").asInstanceOf[html.Span]
31+
arrow.classList.add("ar")
32+
document.getElementById("dropdown-button").appendChild(arrow)
3033

3134
private def disableButton() =
3235
val btn = document.getElementById("dropdown-button").asInstanceOf[html.Button]
@@ -35,53 +38,57 @@ class DropdownHandler:
3538

3639
private def getURLContent(url: String): Future[String] = Ajax.get(url).map(_.responseText)
3740

38-
window.localStorage.getItem(KEY) match
41+
window.sessionStorage.getItem(KEY) match
3942
case null => // If no key, returns null
40-
Globals.versionsDictionaryUrl match
41-
case null => // global property not defined
42-
// do nothing
43-
case url: String =>
44-
getURLContent(url).onComplete {
45-
case Success(json: String) =>
46-
window.localStorage.setItem(KEY, json)
47-
addVersionsList(json)
48-
case Failure(_) =>
49-
window.localStorage.setItem(KEY, UNDEFINED_VERSIONS)
50-
disableButton()
51-
}
43+
try
44+
getURLContent(Globals.versionsDictionaryUrl).onComplete {
45+
case Success(json: String) =>
46+
window.sessionStorage.setItem(KEY, json)
47+
addVersionsList(json)
48+
case Failure(_) =>
49+
window.sessionStorage.setItem(KEY, UNDEFINED_VERSIONS)
50+
disableButton()
51+
}
52+
catch // Globals.versionDictionaruUrl is undefined
53+
case e =>
54+
window.sessionStorage.setItem(KEY, UNDEFINED_VERSIONS)
55+
disableButton()
5256
case value => value match
5357
case UNDEFINED_VERSIONS =>
5458
disableButton()
5559
case json =>
5660
addVersionsList(json)
5761

58-
59-
document.onclick = (e: Event) => {
62+
document.addEventListener("click", (e: Event) => {
6063
if e.target.asInstanceOf[html.Element].id != "dropdown-button" then
6164
document.getElementById("dropdown-content").classList.remove("show")
62-
}
65+
document.getElementById("dropdown-button").classList.remove("expanded")
66+
})
6367

6468
document.getElementById("version").asInstanceOf[html.Span].onclick = (e: Event) => {
6569
e.stopPropagation
6670
}
67-
71+
end DropdownHandler
6872

6973
@JSExportTopLevel("dropdownHandler")
7074
def dropdownHandler() =
7175
if document.getElementById("dropdown-content").getElementsByTagName("a").size > 0 &&
7276
window.getSelection.toString.length == 0 then
7377
document.getElementById("dropdown-content").classList.toggle("show")
78+
document.getElementById("dropdown-button").classList.toggle("expanded")
7479

7580
@JSExportTopLevel("filterFunction")
7681
def filterFunction() =
7782
val input = document.getElementById("dropdown-input").asInstanceOf[html.Input]
7883
val filter = input.value.toUpperCase
7984
val div = document.getElementById("dropdown-content")
80-
val a = div.getElementsByTagName("a")
81-
for i <- 0 until a.length do
82-
val txtValue = a(i).innerText
83-
val disp = if txtValue.toUpperCase.indexOf(filter) > -1 then
84-
""
85+
val as = div.getElementsByTagName("a")
86+
87+
as.foreach { a =>
88+
val txtValue = a.innerText
89+
val cl = a.asInstanceOf[html.Anchor].classList
90+
if txtValue.toUpperCase.indexOf(filter) > -1 then
91+
cl.remove("filtered")
8592
else
86-
"none"
87-
a(i).asInstanceOf[html.Anchor].style.display = disp
93+
cl.add("filtered")
94+
}

scaladoc/resources/dotty_res/styles/scalastyle.css

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ th {
199199
#logo .projectVersion {
200200
color: var(--leftbar-fg);
201201
font-size: 12px;
202+
display: flex;
203+
padding-left: calc(0.05 * var(--side-width));
204+
padding-right: calc(0.08 * var(--side-width));
202205
}
203206

204207
.scaladoc_logo {
@@ -277,7 +280,7 @@ th {
277280
}
278281

279282
/* spans represent a expand button */
280-
#sideMenu2 span.ar {
283+
span.ar {
281284
align-items: center;
282285
cursor: pointer;
283286
position: absolute;
@@ -286,7 +289,7 @@ th {
286289
padding: 4px;
287290
}
288291

289-
#sideMenu2 span.ar::before {
292+
span.ar::before {
290293
content: "\e903"; /* arrow down */
291294
font-family: "dotty-icons" !important;
292295
font-size: 20px;
@@ -297,11 +300,11 @@ th {
297300
align-items: center;
298301
justify-content: center;
299302
}
300-
#sideMenu2 .expanded>span.ar::before {
303+
.expanded>span.ar::before {
301304
content: "\e905"; /* arrow up */
302305
}
303306

304-
#sideMenu2 .div:hover>span.ar::before {
307+
.div:hover>span.ar::before {
305308
color: var(--leftbar-current-bg);
306309
}
307310

@@ -865,7 +868,6 @@ footer {
865868
/* The container <div> - needed to position the dropdown content */
866869
.versions-dropdown {
867870
position: relative;
868-
display: inline-block;
869871
}
870872

871873
/* Dropdown Button */
@@ -920,4 +922,11 @@ footer {
920922
.dropdown-content a:hover {background-color: #f1f1f1}
921923

922924
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
923-
.show {display:block;}
925+
.show {
926+
display:block;
927+
}
928+
929+
/* Filtered entries in dropdown menu */
930+
.dropdown-content a.filtered {
931+
display: none;
932+
}

scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings:
9696
val versionsDictionaryUrl: Setting[String] = StringSetting(
9797
"-versions-dictionary-url",
9898
"versions dictionary url",
99-
"A URL pointing to json with dictionary version -> documentation location. Useful for libraries that maintain different releases docs",
99+
"A URL pointing to a JSON document containing a dictionary version -> documentation location. Useful for libraries that maintain different releases docs",
100100
""
101101
)
102102

scaladoc/src/dotty/tools/scaladoc/SourceLinks.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ object SourceLinks:
125125
| €{FILE_PATH}, and €{FILE_LINE} patterns
126126
|
127127
|
128-
|Template can defined only by subset of sources defined by path prefix represented by `<sub-path>`.
128+
|Template can be defined only by subset of sources defined by path prefix represented by `<sub-path>`.
129129
|In such case paths used in templates will be relativized against `<sub-path>`""".stripMargin
130130

131131
def load(config: Seq[String], revision: Option[String], projectRoot: Path = Paths.get("").toAbsolutePath)(using CompilerContext): SourceLinks =

scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,11 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
223223
span(
224224
div(cls:="projectName")(args.name)
225225
),
226-
span(id := "version")(
226+
div(id := "version")(
227227
div(cls := "versions-dropdown")(
228-
div(onclick := "dropdownHandler()", id := "dropdown-button", cls := "dropdownbtn dropdownbtnactive")(args.projectVersion.map(v => div(cls:="projectVersion")(v)).toList),
228+
div(onclick := "dropdownHandler()", id := "dropdown-button", cls := "dropdownbtn dropdownbtnactive")(
229+
args.projectVersion.map(v => div(cls:="projectVersion")(v)).getOrElse("")
230+
),
229231
div(id := "dropdown-content", cls := "dropdown-content")(
230232
input(`type` := "text", placeholder := "Search...", id := "dropdown-input", onkeyup := "filterFunction()"),
231233
),

0 commit comments

Comments
 (0)