Browse Source

Registers service worker on index page

pull/135/head
taylor 3 years ago
parent
commit
7968fd490f
4 changed files with 63 additions and 26 deletions
  1. +7
    -0
      public/js/register-sw.js
  2. +41
    -26
      public/js/script.js
  3. +14
    -0
      public/js/sw.js
  4. +1
    -0
      views/index.php

+ 7
- 0
public/js/register-sw.js View File

@ -0,0 +1,7 @@
(function registerSW() {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/js/sw.js").catch((e) => {
console.log("Registration fail: ", e);
});
}
})();

+ 41
- 26
public/js/script.js View File

@ -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 // Set the date from JS
var d = new Date(); 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 // 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(); $("#btn_post").click();
} }
}); });
})
});
function auto_prefix_url_field(field) { function auto_prefix_url_field(field) {
var str = field.value; var str = field.value;
if(!/^https?:\/\//.test(str)) {
if (!/^https?:\/\//.test(str)) {
str = "http://" + str; str = "http://" + str;
} }
field.value = str; field.value = str;

+ 14
- 0
public/js/sw.js View File

@ -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
}

+ 1
- 0
views/index.php View File

@ -32,4 +32,5 @@
<a href="" class="u-url"></a> <a href="" class="u-url"></a>
</div> </div>
<script src="/js/register-sw.js"></script>
</div> </div>

Loading…
Cancel
Save