Skip to content

Commit

Permalink
Added text editor PWA support
Browse files Browse the repository at this point in the history
  • Loading branch information
bit-turtle authored Nov 1, 2024
1 parent 01e971a commit 9150b60
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
21 changes: 19 additions & 2 deletions texteditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<html>
<head>
<title>Text Editor</title>

<!-- PWA -->
<link rel="manifest" href="texteditor.manifest.json" />
<!-- ios support -->
<link rel="apple-touch-icon" href="texteditor.png" />
<meta name="apple-mobile-web-app-status-bar" content="cornflowerblue" />
<meta name="theme-color" content="cornflowerblue" />

<style>
* { margin: 0; }
html { height: 95%; }
Expand Down Expand Up @@ -248,9 +256,9 @@
el.value += text;
}
};
document.querySelector("#editor").addEventListener("keydown", function(e) {
textdom.addEventListener("keydown", function(e) {
var TABKEY = 9;
if(e.keyCode == TABKEY) {
if(e.keyCode == TABKEY && document.activeElement == textdom) {
insertAtCursor(this, "\t");
if(e.preventDefault) {
e.preventDefault();
Expand All @@ -259,6 +267,15 @@
}
}, false);

if ("serviceWorker" in navigator) {
window.addEventListener("load", function() {
navigator.serviceWorker
.register("/texteditor.service.js")
.then(e=>{})
.catch(e=>{})
})
}

</script>

</body>
Expand Down
15 changes: 15 additions & 0 deletions texteditor.manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Text Editor",
"short_name": "Text",
"start_url": "texteditor.html",
"display": "standalone",
"theme_color": "cornflowerblue",
"background_color": "lightblue",
"orientation": "portrait-primary",
"icons": [
{
"src": "/texteditor.png",
"type": "image/png", "sizes": "72x72"
}
]
}
Binary file added texteditor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions texteditor.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const staticDevCoffee = "dev-coffee-site-v1";
const assets = [
"/texteditor.html",
"/texteditor.png"
];

self.addEventListener("install", installEvent => {
installEvent.waitUntil(
caches.open(staticDevCoffee).then(cache => {
cache.addAll(assets)
})
)
});

self.addEventListener("fetch", fetchEvent => {
fetchEvent.respondWith(
caches.match(fetchEvent.request).then(res => {
return res || fetch(fetchEvent.request)
})
)
});

0 comments on commit 9150b60

Please sign in to comment.