Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit e656bf0

Browse files
committed
Support IE in fallback JavaScript
1 parent 896db73 commit e656bf0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Sources/swift-doc/Subcommands/Generate.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,15 @@ func fetchRemoteJS() throws -> Data {
147147
let jsURL = Bundle.module.url(forResource: "all", withExtension: "js")!
148148
return try Data(contentsOf: jsURL)
149149
#else
150-
return Data("""
151-
window.addEventListener("load", ()=>{
150+
// When using Swift Package Manager versions that don't support bundled resources, just hide the theme select drop-down.
151+
let fallbackJS = """
152+
var hideThemeSelect = function() {
152153
document.querySelector(".theme-select-container").hidden = true;
153-
})
154-
""".utf8)
154+
}
155+
// hiding the element in `requestAnimationFrame` causes the function to be called after the element exists,
156+
// but fast enough that the element does not flash on the screen.
157+
window.requestAnimationFrame(hideThemeSelect)
158+
"""
159+
return Data(fallbackJS.utf8)
155160
#endif
156161
}

0 commit comments

Comments
 (0)