Skip to content

Instantly share code, notes, and snippets.

@code-boxx
Last active December 25, 2023 19:53
Show Gist options
  • Save code-boxx/0917c35f04b4e3044351e9b796f193fd to your computer and use it in GitHub Desktop.
Save code-boxx/0917c35f04b4e3044351e9b796f193fd to your computer and use it in GitHub Desktop.
PHP MYSQL calendar

PHP MYSQL CALENDAR

https://code-boxx.com/simple-php-calendar-events/

IMAGES

icon-512 favicon

NOTES

  1. Create a database and import 1-database.sql.
  2. Change the database settings in 2-cal-lib.php to your own.
  3. If you want "Monday first", change to mon : true in 4b-calendar.js.
  4. That's all – Launch 4a-cal-page.php in your browser.

LICENSE

Copyright by Code Boxx

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

CREATE TABLE `events` (
`evt_id` bigint(20) NOT NULL,
`evt_start` datetime NOT NULL,
`evt_end` datetime NOT NULL,
`evt_text` text NOT NULL,
`evt_color` varchar(7) NOT NULL,
`evt_bg` varchar(7) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
ALTER TABLE `events`
ADD PRIMARY KEY (`evt_id`),
ADD KEY `evt_start` (`evt_start`),
ADD KEY `evt_end` (`evt_end`);
ALTER TABLE `events`
MODIFY `evt_id` bigint(20) NOT NULL AUTO_INCREMENT;
<?php
class Calendar {
// (A) CONSTRUCTOR - CONNECT TO DATABASE
private $pdo = null;
private $stmt = null;
public $error = "";
function __construct () {
$this->pdo = new PDO(
"mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=".DB_CHARSET,
DB_USER, DB_PASSWORD, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
}
// (B) DESTRUCTOR - CLOSE DATABASE CONNECTION
function __destruct () {
if ($this->stmt!==null) { $this->stmt = null; }
if ($this->pdo!==null) { $this->pdo = null; }
}
// (C) HELPER - RUN SQL QUERY
function query ($sql, $data=null) : void {
$this->stmt = $this->pdo->prepare($sql);
$this->stmt->execute($data);
}
// (D) SAVE EVENT
function save ($start, $end, $txt, $color, $bg, $id=null) {
// (D1) START & END DATE CHECK
if (strtotime($end) < strtotime($start)) {
$this->error = "End date cannot be earlier than start date";
return false;
}
// (D2) RUN SQL
if ($id==null) {
$sql = "INSERT INTO `events` (`evt_start`, `evt_end`, `evt_text`, `evt_color`, `evt_bg`) VALUES (?,?,?,?,?)";
$data = [$start, $end, strip_tags($txt), $color, $bg];
} else {
$sql = "UPDATE `events` SET `evt_start`=?, `evt_end`=?, `evt_text`=?, `evt_color`=?, `evt_bg`=? WHERE `evt_id`=?";
$data = [$start, $end, strip_tags($txt), $color, $bg, $id];
}
$this->query($sql, $data);
return true;
}
// (E) DELETE EVENT
function del ($id) {
$this->query("DELETE FROM `events` WHERE `evt_id`=?", [$id]);
return true;
}
// (F) GET EVENTS FOR SELECTED PERIOD
function get ($month, $year) {
// (F1) DATE RANGE CALCULATIONS
$month = $month<10 ? "0$month" : $month ;
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$dateYM = "{$year}-{$month}-";
$start = $dateYM . "01 00:00:00";
$end = $dateYM . $daysInMonth . " 23:59:59";
// (F2) GET EVENTS
// s & e : start & end date
// c & b : text & background color
// t : event text
$this->query("SELECT * FROM `events` WHERE (
(`evt_start` BETWEEN ? AND ?)
OR (`evt_end` BETWEEN ? AND ?)
OR (`evt_start` <= ? AND `evt_end` >= ?)
)", [$start, $end, $start, $end, $start, $end]);
$events = [];
while ($r = $this->stmt->fetch()) {
$events[$r["evt_id"]] = [
"s" => $r["evt_start"], "e" => $r["evt_end"],
"c" => $r["evt_color"], "b" => $r["evt_bg"],
"t" => $r["evt_text"]
];
}
// (F3) RESULTS
return count($events)==0 ? false : $events ;
}
}
// (G) DATABASE SETTINGS - CHANGE TO YOUR OWN!
define("DB_HOST", "localhost");
define("DB_NAME", "test");
define("DB_CHARSET", "utf8mb4");
define("DB_USER", "root");
define("DB_PASSWORD", "");
// (H) NEW CALENDAR OBJECT
$_CAL = new Calendar();
<?php
if (isset($_POST["req"])) {
// (A) LOAD LIBRARY
require "2-cal-lib.php";
switch ($_POST["req"]) {
// (B) GET DATES & EVENTS FOR SELECTED PERIOD
case "get":
echo json_encode($_CAL->get($_POST["month"], $_POST["year"]));
break;
// (C) SAVE EVENT
case "save":
echo $_CAL->save(
$_POST["start"], $_POST["end"], $_POST["txt"], $_POST["color"], $_POST["bg"],
isset($_POST["id"]) ? $_POST["id"] : null
) ? "OK" : $_CAL->error ;
break;
// (D) DELETE EVENT
case "del":
echo $_CAL->del($_POST["id"]) ? "OK" : $_CAL->error ;
break;
}}
<!DOCTYPE html>
<html>
<head>
<title>Calendar Demo</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.5">
<link rel="icon" type="image/png" href="favicon.png">
<!-- ANDROID + CHROME + APPLE + WINDOWS APP -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="theme-color" content="white">
<link rel="apple-touch-icon" href="icon-512.png">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Calendar">
<meta name="msapplication-TileImage" content="icon-512.png">
<meta name="msapplication-TileColor" content="#ffffff">
<!-- WEB APP MANIFEST -->
<!-- https://web.dev/add-manifest/ -->
<link rel="manifest" href="5-manifest.json">
<!-- SERVICE WORKER -->
<script>
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("5-worker.js");
}
</script>
<!-- JS + CSS -->
<script src="4b-calendar.js"></script>
<link rel="stylesheet" href="4c-calendar.css">
</head>
<body>
<?php
// (A) DAYS MONTHS YEAR
$months = [
1 => "January", 2 => "Febuary", 3 => "March", 4 => "April",
5 => "May", 6 => "June", 7 => "July", 8 => "August",
9 => "September", 10 => "October", 11 => "November", 12 => "December"
];
$monthNow = date("m");
$yearNow = date("Y"); ?>
<!-- (B) PERIOD SELECTOR -->
<div id="calHead">
<div id="calPeriod">
<input id="calToday" type="button" value="&#9733;">
<input id="calBack" type="button" class="mi" value="&lt;">
<select id="calMonth"><?php foreach ($months as $m=>$mth) {
printf("<option value='%u'%s>%s</option>",
$m, $m==$monthNow?" selected":"", $mth
);
} ?></select>
<input id="calYear" type="number" value="<?=$yearNow?>">
<input id="calNext" type="button" class="mi" value="&gt;">
</div>
<input id="calAdd" type="button" value="+">
</div>
<!-- (C) CALENDAR WRAPPER -->
<div id="calWrap">
<div id="calDays"></div>
<div id="calBody"></div>
</div>
<!-- (D) EVENT FORM -->
<dialog id="calForm"><form method="dialog">
<div id="evtCX">X</div>
<h2 class="evt100">CALENDAR EVENT</h2>
<div class="evt50">
<label>Start</label>
<input id="evtStart" type="datetime-local" required>
</div>
<div class="evt50">
<label>End</label>
<input id="evtEnd" type="datetime-local" required>
</div>
<div class="evt50">
<label>Text Color</label>
<input id="evtColor" type="color" value="#000000" required>
</div>
<div class="evt50">
<label>Background Color</label>
<input id="evtBG" type="color" value="#ffdbdb" required>
</div>
<div class="evt100">
<label>Event</label>
<input id="evtTxt" type="text" autocomplete="off" required>
</div>
<div class="evt100">
<input type="hidden" id="evtID">
<input type="button" id="evtDel" value="Delete">
<input type="submit" id="evtSave" value="Save">
</div>
</form></dialog>
</body>
</html>
var cal = {
// (A) PROPERTIES
mon : false, // monday first
events : null, // events data for current month/year
sMth : 0, sYear : 0, // selected month & year
hMth : null, hYear : null, // html month & year
hCD : null, hCB : null, // html calendar days & body
// html form & fields
hFormWrap : null, hForm : null, hfID : null,
hfStart : null, hfEnd : null, hfTxt : null,
hfColor : null, hfBG : null, hfDel : null,
// (B) SUPPORT FUNCTION - AJAX FETCH
ajax : (data, onload) => {
// (B1) FORM DATA
let form = new FormData();
for (let [k,v] of Object.entries(data)) { form.append(k,v); }
// (B2) FETCH
fetch("3-cal-ajax.php", { method:"POST", body:form })
.then(res => res.text())
.then(txt => onload(txt))
.catch(err => console.error(err));
},
// (C) INIT CALENDAR
init : () => {
// (C1) GET HTML ELEMENTS
cal.hMth = document.getElementById("calMonth");
cal.hYear = document.getElementById("calYear");
cal.hCD = document.getElementById("calDays");
cal.hCB = document.getElementById("calBody");
cal.hFormWrap = document.getElementById("calForm");
cal.hForm = cal.hFormWrap.querySelector("form");
cal.hfID = document.getElementById("evtID");
cal.hfStart = document.getElementById("evtStart");
cal.hfEnd = document.getElementById("evtEnd");
cal.hfTxt = document.getElementById("evtTxt");
cal.hfColor = document.getElementById("evtColor");
cal.hfBG = document.getElementById("evtBG");
cal.hfDel = document.getElementById("evtDel");
// (C2) ATTACH CONTROLS
cal.hMth.onchange = cal.load;
cal.hYear.onchange = cal.load;
document.getElementById("calToday").onclick = () => cal.today();
document.getElementById("calBack").onclick = () => cal.pshift();
document.getElementById("calNext").onclick = () => cal.pshift(1);
document.getElementById("calAdd").onclick = () => cal.show();
cal.hForm.onsubmit = () => cal.save();
document.getElementById("evtCX").onclick = () => {
if (document.startViewTransition) { document.startViewTransition(() => cal.hFormWrap.close()); }
else { cal.hFormWrap.close(); }
}
cal.hfDel.onclick = cal.del;
// (C3) DRAW DAY NAMES
let days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
if (cal.mon) { days.push("Sun"); } else { days.unshift("Sun"); }
for (let d of days) {
let cell = document.createElement("div");
cell.className = "calCell";
cell.innerHTML = d;
cal.hCD.appendChild(cell);
}
// (C4) LOAD & DRAW CALENDAR
cal.load();
},
// (D) SHIFT CURRENT PERIOD BY 1 MONTH
pshift : forward => {
cal.sMth = parseInt(cal.hMth.value);
cal.sYear = parseInt(cal.hYear.value);
if (forward) { cal.sMth++; } else { cal.sMth--; }
if (cal.sMth > 12) { cal.sMth = 1; cal.sYear++; }
if (cal.sMth < 1) { cal.sMth = 12; cal.sYear--; }
cal.hMth.value = cal.sMth;
cal.hYear.value = cal.sYear;
cal.load();
},
// (E) JUMP TO TODAY
today : () => {
let now = new Date(), ny = now.getFullYear(), nm = now.getMonth()+1;
if (ny!=cal.sYear || (ny==cal.sYear && nm!=cal.sMth)) {
cal.hMth.value = nm;
cal.hYear.value = ny;
cal.load();
}
},
// (F) LOAD EVENTS
load : () => {
cal.sMth = parseInt(cal.hMth.value);
cal.sYear = parseInt(cal.hYear.value);
cal.ajax({
req : "get", month : cal.sMth, year : cal.sYear
}, events => {
cal.events = JSON.parse(events);
cal.draw();
});
},
// (G) DRAW CALENDAR
draw : () => {
// (G1) CALCULATE DAY MONTH YEAR
// note - jan is 0 & dec is 11 in js
// note - sun is 0 & sat is 6 in js
let daysInMth = new Date(cal.sYear, cal.sMth, 0).getDate(), // number of days in selected month
startDay = new Date(cal.sYear, cal.sMth-1, 1).getDay(), // first day of the month
endDay = new Date(cal.sYear, cal.sMth-1, daysInMth).getDay(), // last day of the month
now = new Date(), // current date
nowMth = now.getMonth()+1, // current month
nowYear = parseInt(now.getFullYear()), // current year
nowDay = cal.sMth==nowMth && cal.sYear==nowYear ? now.getDate() : null ;
// (G2) DRAW CALENDAR ROWS & CELLS
// (G2-1) INIT
let rowA, rowB, rowC, rowMap = {}, rowNum = 1, cell, cellNum = 1,
// (G2-2) HELPER - DRAW A NEW ROW
rower = () => {
rowA = document.createElement("div");
rowB = document.createElement("div");
rowC = document.createElement("div");
rowA.className = "calRow";
rowA.id = "calRow" + rowNum;
rowB.className = "calRowHead";
rowC.className = "calRowBack";
cal.hCB.appendChild(rowA);
rowA.appendChild(rowB);
rowA.appendChild(rowC);
},
// (G2-3) HELPER - DRAW A NEW CELL
celler = day => {
cell = document.createElement("div");
cell.className = "calCell";
if (day) {
cell.innerHTML = day;
cell.classList.add("calCellDay");
cell.onclick = () => {
cal.show();
let d = +day, m = +cal.hMth.value,
s = `${cal.hYear.value}-${String(m<10 ? "0"+m : m)}-${String(d<10 ? "0"+d : d)}T00:00:00`;
cal.hfStart.value = s;
cal.hfEnd.value = s;
};
}
rowB.appendChild(cell);
cell = document.createElement("div");
cell.className = "calCell";
if (day===undefined) { cell.classList.add("calBlank"); }
if (day!==undefined && day==nowDay) { cell.classList.add("calToday"); }
rowC.appendChild(cell);
};
// (G2-4) RESET CALENDAR
cal.hCB.innerHTML = ""; rower();
// (G2-5) BLANK CELLS BEFORE START OF MONTH
if (cal.mon && startDay != 1) {
let blanks = startDay==0 ? 7 : startDay ;
for (let i=1; i<blanks; i++) { celler(); cellNum++; }
}
if (!cal.mon && startDay != 0) {
for (let i=0; i<startDay; i++) { celler(); cellNum++; }
}
// (G2-6) DAYS OF THE MONTH
for (let i=1; i<=daysInMth; i++) {
rowMap[i] = { r : rowNum, c : cellNum };
celler(i);
if (i!=daysInMth && cellNum%7==0) { rowNum++; rower(); }
cellNum++;
}
// (G2-7) BLANK CELLS AFTER END OF MONTH
if (cal.mon && endDay != 0) {
let blanks = endDay==6 ? 1 : 7-endDay;
for (let i=0; i<blanks; i++) { celler(); cellNum++; }
}
if (!cal.mon && endDay != 6) {
let blanks = endDay==0 ? 6 : 6-endDay;
for (let i=0; i<blanks; i++) { celler(); cellNum++; }
}
// (G3) DRAW EVENTS
if (cal.events !== false) { for (let [id,evt] of Object.entries(cal.events)) {
// (G3-1) EVENT START & END DAY
let sd = new Date(evt.s), ed = new Date(evt.e);
if (sd.getFullYear() != cal.sYear) { sd = 1; }
else { sd = sd.getMonth()+1 < cal.sMth ? 1 : sd.getDate(); }
if (ed.getFullYear() != cal.sYear) { ed = daysInMth; }
else { ed = ed.getMonth()+1 > cal.sMth ? daysInMth : ed.getDate(); }
// (G3-2) "MAP" ONTO HTML CALENDAR
cell = {}; rowNum = 0;
for (let i=sd; i<=ed; i++) {
if (rowNum!=rowMap[i]["r"]) {
cell[rowMap[i]["r"]] = { s:rowMap[i]["c"], e:0 };
rowNum = rowMap[i]["r"];
}
if (cell[rowNum]) { cell[rowNum]["e"] = rowMap[i]["c"]; }
}
// (G3-3) DRAW HTML EVENT ROW
for (let [r,c] of Object.entries(cell)) {
let o = c.s - 1 - ((r-1) * 7), // event cell offset
w = c.e - c.s + 1; // event cell width
rowA = document.getElementById("calRow"+r);
rowB = document.createElement("div");
rowB.className = "calRowEvt";
rowB.innerHTML = cal.events[id]["t"];
rowB.style.color = cal.events[id]["c"];
rowB.style.backgroundColor = cal.events[id]["b"];
rowB.classList.add("w"+w);
if (o!=0) { rowB.classList.add("o"+o); }
rowB.onclick = () => cal.show(id);
rowA.appendChild(rowB);
}
}}
},
// (H) SHOW EVENT FORM
show : id => {
if (id) {
cal.hfID.value = id;
cal.hfStart.value = cal.events[id]["s"].replace(" ", "T").substring(0, 16);
cal.hfEnd.value = cal.events[id]["e"].replace(" ", "T").substring(0, 16);
cal.hfTxt.value = cal.events[id]["t"];
cal.hfColor.value = cal.events[id]["c"];
cal.hfBG.value = cal.events[id]["b"];
cal.hfDel.style.display = "inline-block";
} else {
cal.hForm.reset();
cal.hfID.value = "";
cal.hfDel.style.display = "none";
}
if (document.startViewTransition) { document.startViewTransition(() => cal.hFormWrap.show()); }
else { cal.hFormWrap.show(); }
},
// (I) SAVE EVENT
save : () => {
// (I1) COLLECT DATA
var data = {
req : "save",
start : cal.hfStart.value,
end : cal.hfEnd.value,
txt : cal.hfTxt.value,
color : cal.hfColor.value,
bg : cal.hfBG.value
};
if (cal.hfID.value != "") { data.id = cal.hfID.value; }
// (I2) DATE CHECK
if (new Date(data.start) > new Date(data.end)) {
alert("Start date cannot be later than end date!");
return false;
}
// (I3) AJAX SAVE
cal.ajax(data, res => { if (res == "OK") {
cal.hFormWrap.close();
cal.load();
} else { alert(res); }});
return false;
},
// (J) DELETE EVENT
del : () => { if (confirm("Delete event?")) {
cal.ajax({
req : "del", id : cal.hfID.value
}, res => { if (res == "OK") {
cal.hFormWrap.close();
cal.load();
} else { alert(res); }});
}}
};
window.onload = cal.init;
/* (A) WHOLE PAGE */
* {
font-family: Arial, Helvetica, sans-serif;
box-sizing: border-box;
}
body {
position: relative;
padding: 0; margin: 0;
overflow-x: hidden;
}
:root {
--bg-color-a: #3b39af; /* page header + form label */
--bg-color-b: #404040; /* calendar header */
--bg-color-c: #d73a3a; /* buttons */
}
@keyframes zoom-in {
from { transform: scale(0); }
to { transform: scale(1); }
}
@keyframes zoom-out {
from { transform: scale(1); }
to { transform:scale(0); }
}
::view-transition-old(zoom) { animation: .2s linear both zoom-out; }
::view-transition-new(zoom) { animation: .2s linear both zoom-in; }
/* (B) PERIOD SELECTOR */
#calHead {
display: flex; align-items: center;
padding: 15px;
background: var(--bg-color-a);
}
#calPeriod { flex-grow: 1; }
#calHead input, #calHead select {
font-size: 24px; color: #fff;
border: 0; outline: none; background: 0;
cursor: pointer;
}
#calMonth { margin: 0 10px; }
#calMonth option { color: #000; }
#calYear {
width: 100px;
margin-left: 10px;
}
#calAdd {
padding: 5px 20px;
background: var(--bg-color-c) !important;
}
/* (C) CALENDAR */
/* (C1) ROWS */
#calDays, .calRowHead, .calRowBack { display: flex; }
#calDays, .calRow, .calRowHead, .calRowEvt {
position: relative;
width: 100%;
}
.calRow { min-height: 100px; }
.calRowHead, .calRowEvt { z-index: 2; }
.calRowBack {
position: absolute;
top: 0; left: 0; z-index: 1;
width: 100%; height: 100%;
}
.calRowEvt {
padding: 3px 10px;
margin-top: 5px;
font-size: 12px;
white-space: nowrap; text-overflow: ellipsis;
overflow: hidden; cursor: pointer;
border-radius: 10px;
}
/* (C2) CELLS & EVENTS */
.calCell { width: 14.2857%; }
.w1 { width: 14.2857%; } .w2 { width: 28.5714%; } .w3 { width: 42.8571%; }
.w4 { width: 57.1428%; } .w5 { width: 71.4285%; } .w6 { width: 85.7142%; }
.w7 { width: 100%; }
.o1 { left: 14.2857%; } .o2 { left: 28.5714%; } .o3 { left: 42.8571%; }
.o4 { left: 57.1428%; } .o5 { left: 71.4285%; } .o6 { left: 85.7142%; }
#calDays .calCell {
color: #fff; background: var(--bg-color-b);
font-weight: 700; text-align: center;
padding: 15px 0;
}
.calRowHead .calCell {
font-size: 14px;
font-weight: 700;
color: #b5b5b5;
padding: 5px;
}
.calRowHead .calCellDay:hover {
color: #ff5b5b;
cursor: pointer;
}
.calRowBack .calCell { border: 1px solid #f5f5f5; }
.calBlank { background: #f5f5f5; }
.calToday { background: #feffd3; }
/* (D) EVENT FORM */
#calForm {
position: absolute; top: 0; left: 0; z-index: 999;
width: 100vw; height: 100%; min-height: 100vh;
padding: 0; margin: 0; border: 0;
background: rgba(0,0,0,0.5);
view-transition-name : zoom;
}
#calForm:is([open]), #calForm form {
display: flex; flex-wrap: wrap;
align-items: center; justify-content: center;
}
#calForm form {
position: relative;
width: 450px; padding: 15px;
border-radius: 10px;
background: #fff;
}
#evtCX {
position: absolute;
top: 0; right: 0;
padding: 10px;
color: #b12020;
font-size: 28px;
font-weight: 700;
cursor: pointer;
}
#calForm h2 { margin: 0 0 5px 0; }
#calForm .evt50 { width: 50%; }
#calForm .evt100 { width: 100%; }
#calForm .evt50, #calForm .evt100 { padding: 8px; }
#calForm label, #calForm input[type=datetime-local], #calForm input[type=color], #calForm input[type=text] {
display: block;
width: 100%;
}
#calForm label {
color: #a1a1a1;
font-size: 12px;
margin-bottom: 5px;
}
#calForm input[type=datetime-local], #calForm input[type=text] {
padding: 5px;
border: 1px solid #eee;
background: #f5f5f5;
}
#calForm input[type=color] { height: 30px; border: 0; }
#calForm input[type=button], #calForm input[type=submit] {
border: 0; padding: 10px; margin: 10px 2px 0 0;
color: #fff; background: var(--bg-color-c);
cursor: pointer;
}
{
"short_name": "Calendar",
"name": "Calendar",
"icons": [{
"src": "favicon.png",
"sizes": "64x64",
"type": "image/png"
}, {
"src": "icon-512.png",
"sizes": "512x512",
"type": "image/png"
}],
"start_url": "/4a-cal-page.php",
"scope": "/",
"background_color": "white",
"theme_color": "white",
"display": "standalone"
}
// (A) CREATE/INSTALL CACHE
self.addEventListener("install", evt => {
self.skipWaiting();
evt.waitUntil(
caches.open("phpcal")
.then(cache => cache.addAll([
"4b-calendar.js",
"4c-calendar.css",
"5-manifest.json",
"favicon.png",
"icon-512.png"
]))
.catch(err => console.error(err))
);
});
// (B) CLAIM CONTROL INSTANTLY
self.addEventListener("activate", evt => self.clients.claim());
// (C) LOAD FROM CACHE FIRST, FALLBACK TO NETWORK IF NOT FOUND
self.addEventListener("fetch", evt => evt.respondWith(
caches.match(evt.request).then(res => res || fetch(evt.request))
));
@twmshwn
Copy link

twmshwn commented Dec 25, 2023

Hi
can i make simple-php-calendar-events smalles it present state is full screen.
Thanks
Hywel Franc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment