From 3bbedc10075ba9b25e4b3912b2cb40107acb3fb7 Mon Sep 17 00:00:00 2001 From: taylor Date: Wed, 24 Mar 2021 11:41:44 +0200 Subject: [PATCH 1/3] Adds required fields for prompting add to homescreen in manifest.json --- public/js/manifest.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/public/js/manifest.json b/public/js/manifest.json index 7565124..da3aa9b 100644 --- a/public/js/manifest.json +++ b/public/js/manifest.json @@ -2,6 +2,9 @@ "name": "Quill", "short_name": "Quill", "description": "Quill is a simple app for posting to your website", + "background_color": "#428bca", + "display": "standalone", + "start_url": "/dashboard", "icons": [ { "src": "/images/quill-icon-57.png", From 7968fd490fbfe7d6b3d2d0b3be747f809385ecad Mon Sep 17 00:00:00 2001 From: taylor Date: Wed, 24 Mar 2021 12:00:48 +0200 Subject: [PATCH 2/3] Registers service worker on index page --- public/js/register-sw.js | 7 +++++ public/js/script.js | 67 ++++++++++++++++++++++++---------------- public/js/sw.js | 14 +++++++++ views/index.php | 1 + 4 files changed, 63 insertions(+), 26 deletions(-) create mode 100644 public/js/register-sw.js create mode 100644 public/js/sw.js diff --git a/public/js/register-sw.js b/public/js/register-sw.js new file mode 100644 index 0000000..edbe214 --- /dev/null +++ b/public/js/register-sw.js @@ -0,0 +1,7 @@ +(function registerSW() { + if ("serviceWorker" in navigator) { + navigator.serviceWorker.register("/js/sw.js").catch((e) => { + console.log("Registration fail: ", e); + }); + } +})(); diff --git a/public/js/script.js b/public/js/script.js index 57990ee..bf58156 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1,43 +1,58 @@ +function tz_seconds_to_offset(seconds) { + var tz_offset = ""; + var hours = zero_pad(Math.abs(seconds / 60 / 60)); + var minutes = zero_pad(Math.floor(seconds / 60) % 60); + return (seconds < 0 ? "-" : "+") + hours + ":" + minutes; +} - function tz_seconds_to_offset(seconds) { - var tz_offset = ''; - var hours = zero_pad(Math.abs(seconds / 60 / 60)); - var minutes = zero_pad(Math.floor(seconds / 60) % 60); - return (seconds < 0 ? '-' : '+') + hours + ":" + minutes; - } - - function zero_pad(num) { - num = "" + num; - if(num.length == 1) { - num = "0" + num; - } - return num; - } - - function tokenfieldToArray(sel) { - return $(sel).tokenfield("getTokens").map(function(t){ return t.value}); +function zero_pad(num) { + num = "" + num; + if (num.length == 1) { + num = "0" + num; } + return num; +} -$(function(){ +function tokenfieldToArray(sel) { + return $(sel) + .tokenfield("getTokens") + .map(function (t) { + return t.value; + }); +} +$(function () { // Set the date from JS var d = new Date(); - $("#note_date").val(d.getFullYear()+"-"+zero_pad(d.getMonth()+1)+"-"+zero_pad(d.getDate())); - $("#note_time").val(zero_pad(d.getHours())+":"+zero_pad(d.getMinutes())+":"+zero_pad(d.getSeconds())); - $("#note_tzoffset").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1)); + $("#note_date").val( + d.getFullYear() + + "-" + + zero_pad(d.getMonth() + 1) + + "-" + + zero_pad(d.getDate()) + ); + $("#note_time").val( + zero_pad(d.getHours()) + + ":" + + zero_pad(d.getMinutes()) + + ":" + + zero_pad(d.getSeconds()) + ); + $("#note_tzoffset").val( + tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1) + ); // ctrl-s to save - $(window).on('keydown', function(e){ - if(e.keyCode == 83 && e.ctrlKey){ + $(window).on("keydown", function (e) { + if (e.keyCode == 83 && e.ctrlKey) { $("#btn_post").click(); } }); - -}) +}); function auto_prefix_url_field(field) { var str = field.value; - if(!/^https?:\/\//.test(str)) { + if (!/^https?:\/\//.test(str)) { str = "http://" + str; } field.value = str; diff --git a/public/js/sw.js b/public/js/sw.js new file mode 100644 index 0000000..f9d8702 --- /dev/null +++ b/public/js/sw.js @@ -0,0 +1,14 @@ +// NOTE: This currently doesn't cache anything +// We are just installing it so that chrome users can be +// prompted to install Quill via add to homescreen +self.addEventListener("install", installWorker); + +async function installWorker() { + await self.skipWaiting(); +} + +self.addEventListener("activate", activateServiceWorker); + +async function activateServiceWorker(event) { + event.waitUntil(clients.claim()); // make the current sw the active sw in all pages +} diff --git a/views/index.php b/views/index.php index b06f20d..02f45e2 100644 --- a/views/index.php +++ b/views/index.php @@ -32,4 +32,5 @@ + From 99fd654e4b867133bb277ee2e1123ec512750eb1 Mon Sep 17 00:00:00 2001 From: taylor Date: Wed, 24 Mar 2021 22:16:52 +0200 Subject: [PATCH 3/3] Resets whitespace changes in script.js --- public/js/script.js | 67 ++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/public/js/script.js b/public/js/script.js index bf58156..57990ee 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1,58 +1,43 @@ -function tz_seconds_to_offset(seconds) { - var tz_offset = ""; - var hours = zero_pad(Math.abs(seconds / 60 / 60)); - var minutes = zero_pad(Math.floor(seconds / 60) % 60); - return (seconds < 0 ? "-" : "+") + hours + ":" + minutes; -} -function zero_pad(num) { - num = "" + num; - if (num.length == 1) { - num = "0" + num; + function tz_seconds_to_offset(seconds) { + var tz_offset = ''; + var hours = zero_pad(Math.abs(seconds / 60 / 60)); + var minutes = zero_pad(Math.floor(seconds / 60) % 60); + return (seconds < 0 ? '-' : '+') + hours + ":" + minutes; } - return num; -} -function tokenfieldToArray(sel) { - return $(sel) - .tokenfield("getTokens") - .map(function (t) { - return t.value; - }); -} + function zero_pad(num) { + num = "" + num; + if(num.length == 1) { + num = "0" + num; + } + return num; + } + + function tokenfieldToArray(sel) { + return $(sel).tokenfield("getTokens").map(function(t){ return t.value}); + } + +$(function(){ -$(function () { // Set the date from JS var d = new Date(); - $("#note_date").val( - d.getFullYear() + - "-" + - zero_pad(d.getMonth() + 1) + - "-" + - zero_pad(d.getDate()) - ); - $("#note_time").val( - zero_pad(d.getHours()) + - ":" + - zero_pad(d.getMinutes()) + - ":" + - zero_pad(d.getSeconds()) - ); - $("#note_tzoffset").val( - tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1) - ); + $("#note_date").val(d.getFullYear()+"-"+zero_pad(d.getMonth()+1)+"-"+zero_pad(d.getDate())); + $("#note_time").val(zero_pad(d.getHours())+":"+zero_pad(d.getMinutes())+":"+zero_pad(d.getSeconds())); + $("#note_tzoffset").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1)); // ctrl-s to save - $(window).on("keydown", function (e) { - if (e.keyCode == 83 && e.ctrlKey) { + $(window).on('keydown', function(e){ + if(e.keyCode == 83 && e.ctrlKey){ $("#btn_post").click(); } }); -}); + +}) function auto_prefix_url_field(field) { var str = field.value; - if (!/^https?:\/\//.test(str)) { + if(!/^https?:\/\//.test(str)) { str = "http://" + str; } field.value = str;