Skip to content

Commit 35aefbe

Browse files
committed
Change local storage to session storage, fix bugs with undefined js variable
1 parent c46d686 commit 35aefbe

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,21 @@ class DropdownHandler:
3535

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

38-
window.localStorage.getItem(KEY) match
38+
window.sessionStorage.getItem(KEY) match
3939
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-
}
40+
try
41+
getURLContent(Globals.versionsDictionaryUrl).onComplete {
42+
case Success(json: String) =>
43+
window.sessionStorage.setItem(KEY, json)
44+
addVersionsList(json)
45+
case Failure(_) =>
46+
window.sessionStorage.setItem(KEY, UNDEFINED_VERSIONS)
47+
disableButton()
48+
}
49+
catch // Globals.versionDictionaruUrl is undefined
50+
case e =>
51+
window.sessionStorage.setItem(KEY, UNDEFINED_VERSIONS)
52+
disableButton()
5253
case value => value match
5354
case UNDEFINED_VERSIONS =>
5455
disableButton()
@@ -64,7 +65,7 @@ class DropdownHandler:
6465
document.getElementById("version").asInstanceOf[html.Span].onclick = (e: Event) => {
6566
e.stopPropagation
6667
}
67-
68+
end DropdownHandler
6869

6970
@JSExportTopLevel("dropdownHandler")
7071
def dropdownHandler() =

scaladoc/resources/dotty_res/styles/scalastyle.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,5 +842,17 @@ footer {
842842
/* Change color of dropdown links on hover */
843843
.dropdown-content a:hover {background-color: #f1f1f1}
844844

845+
.arrow-down {
846+
content: "\e903"; /* arrow down */
847+
font-family: "dotty-icons" !important;
848+
font-size: 20px;
849+
line-height: var(--leftbar-font-size);
850+
color: var(--leftbar-fg);
851+
display: flex;
852+
flex-direction: row;
853+
align-items: center;
854+
justify-content: center;
855+
}
856+
845857
/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
846858
.show {display:block;}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
225225
),
226226
span(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+
div(cls := "arrow-down")
231+
),
229232
div(id := "dropdown-content", cls := "dropdown-content")(
230233
input(`type` := "text", placeholder := "Search...", id := "dropdown-input", onkeyup := "filterFunction()"),
231234
),

0 commit comments

Comments
 (0)