Skip to content
This repository has been archived by the owner on Apr 21, 2022. It is now read-only.

chore(): add new pwa-features folder + initial demos #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
62 changes: 62 additions & 0 deletions docs/pwa-features/clipboard-api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Clipboard Demo</title>
</head>
<body>
<h1>
Clipboard API
</h1>

<p>
More details can be found in the
<a
href="https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/open/?tabs=cmd-Windows"
>browsers devtools console</a
>
</p>

<button onclick="copyText()">
Copy Text / URLs
</button>

<button onclick="copyFile()">
Copy a File
</button>

<p id="status-message"></p>

<script>
async function copyText() {
try {
await navigator.clipboard.writeText('Copying text!');
console.log('Text copied to clipboard');

document.querySelector("#status-message").textContent = "Text copied to clipboard";
} catch (err) {
console.error('Failed to copy: ', err);
}
}

async function copyFile() {
const test_file = new File(["some text..."], "filename.txt", {type: "text/plain"});

try {
await navigator.clipboard.write([
new ClipboardItem({
[test_file.type]: test_file
})
]);
console.log('Image copied.');

document.querySelector("#status-message").textContent = "Image copied to clipboard";
} catch (err) {
console.error('Failed to copy: ', err);
}
}
</script>
</body>
</html>
68 changes: 68 additions & 0 deletions docs/pwa-features/file-access-api.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>File Access API Demo</title>
</head>
<body>
<h1>
File Access API
</h1>

<p>
More details can be found in the
<a
href="https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/open/?tabs=cmd-Windows"
>browsers devtools console</a
>
</p>

<button onclick="chooseFile()">
Open File
</button>

<button onclick="saveFile()">
Save File
</button>

<script>
let file;

async function chooseFile() {
const fileHandles = await window.showOpenFilePicker({
startIn: "pictures"
});
file = await fileHandles[0].getFile();

if (file) {
console.log(file);

const img = new Image();
img.src = URL.createObjectURL(file);

document.body.append(img);
}
}

async function saveFile() {
const options = {
types: [
{
description: "Image Files",
accept: {
"image/png": [".png"]
}
}
]
};
const handle = await window.showSaveFilePicker(options);

const writable = await handle.createWritable();
await writable.write(file);
await writable.close();
}
</script>
</body>
</html>
66 changes: 66 additions & 0 deletions docs/pwa-features/web-share.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>Web Share Demo</title>
</head>
<body>
<h1>
Web Share API
</h1>

<p>
More details can be found in the
<a
href="https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/open/?tabs=cmd-Windows"
>browsers devtools console</a
>
</p>

<button onclick="shareText()">
Share Text / URLs
</button>

<button onclick="shareFile()">
Share a File
</button>

<script>
async function shareText() {
if (navigator.share) {
try {
await navigator.share({
title: 'Sharing!',
text: 'Check this out',
url: 'https://www.pwabuilder.com',
});
}
catch (err) {
console.log('Error sharing', error);
}
}
}

async function shareFile() {
const test_file = new File(["some text..."], "filename.txt", {type: "text/plain"});

if (navigator.canShare && navigator.canShare({ files: [test_file] })) {
try {
await navigator.share({
files: [test_file],
title: 'Sharing a File',
text: 'Just sharing a file (:',
})
}
catch (err) {
console.log('Error sharing', error);
}
} else {
console.log(`Your system doesn't support sharing files.`);
}
}
</script>
</body>
</html>