8000 Replace docs with mdoc by zetashift · Pull Request #766 · scala-js/scala-js-dom · GitHub
[go: up one dir, main page]

Skip to content

Replace docs with mdoc #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add base64 encoding example and minor formatting changes
  • Loading branch information
zetashift committed Feb 27, 2023
commit 67a58a2d2a34900e3187eadee21f3144c6ca4fdf
32 changes: 26 additions & 6 deletions docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ def storeInputInLocalStorage(input: html.Input, box: html.Div) = {
input.value = window.localStorage.getItem(key)

input.onkeyup = { (e: Event) =>
window.localStorage.setItem(
key, input.value
)
window.localStorage.setItem(key, input.value)

box.textContent = s"Saved: ${input.value} to local storage!"
}
Expand Down Expand Up @@ -166,8 +164,7 @@ document.getElementById("demo4-btn").addEventListener("click", (ev: Event) => {
import scala.concurrent.ExecutionContext.Implicits.global

def fetchBoredApi(element: html.Pre) = {
val url =
"https://www.boredapi.com/api/activity"
val url = "https://www.boredapi.com/api/activity"

val responseText = for {
response <- fetch(url).toFuture
Expand Down Expand Up @@ -218,7 +215,6 @@ document.getElementById("demo5-btn").addEventListener("click", (ev: Event) => {
```scala mdoc:js:shared
def changeColor(div: html.Div) = {
val colors = Seq("red", "green", "blue")

val index = util.Random.nextInt(colors.length)

div.style.color = colors(index)
Expand All @@ -234,6 +230,30 @@ document.getElementById("demo7-btn").addEventListener("click", (ev: Event) => {
})
```

### Encode in base64

```scala mdoc:js:shared
def encodeBase64(in: html.Input, out: html.Div) = {
in.onkeyup = { (e: Event) =>
out.textContent = window.btoa(in.value)
}
}
```

```scala mdoc:js:invisible
<input id="demo8-input" style="display: none;" />
<div id="demo8-output" style="display: none"></div>
<button id="demo8-btn">Run</button>
---
val input = document.getElementById("demo8-input").asInstanceOf[html.Input]
val output = document.getElementById("demo8-output").asInstanceOf[html.Div]
document.getElementById("demo8-btn").addEventListener("click", (ev: Event) => {
input.style.display = "block"
output.style.display = "block"
encodeBase64(input, output)
})
```

## Contributing

The DOM API is always evolving, and `scala-js-dom` tries to provide a thin-but-idiomatic Scala interface to modern browser APIs, without breaking the spec.
Expand Down
0