aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-10-16 23:03:19 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-10-16 23:03:19 +0200
commitaafc838c0a1e4c08636c950d0d4fa9fe4018e046 (patch)
treec9335f31299cc2397d352c7ee73311f231560503
parentHTML add toggle for whole-day. (diff)
downloadcalp-aafc838c0a1e4c08636c950d0d4fa9fe4018e046.tar.gz
calp-aafc838c0a1e4c08636c950d0d4fa9fe4018e046.tar.xz
Minor JS cleanup.
-rw-r--r--static/lib.js14
-rw-r--r--static/script.js38
2 files changed, 28 insertions, 24 deletions
diff --git a/static/lib.js b/static/lib.js
index 3c11e23f..79e48f1e 100644
--- a/static/lib.js
+++ b/static/lib.js
@@ -131,4 +131,18 @@ function format_date(date, str) {
Object.prototype.format = function () { return this; } /* any number of arguments */
Date.prototype.format = function (str) { return format_date (this, str); }
+/*
+ * Finds the first element of the DOMTokenList whichs value matches
+ * the supplied regexp. Returns a pair of the index and the value.
+ */
+DOMTokenList.prototype.find = function (regexp) {
+ let entries = this.entries();
+ let entry;
+ while (! (entry = entries.next()).done) {
+ if (entry.value[1].match(regexp)) {
+ return entry.value;
+ }
+ }
+}
+
const xcal = "urn:ietf:params:xml:ns:icalendar-2.0";
diff --git a/static/script.js b/static/script.js
index 636bf086..d7e60488 100644
--- a/static/script.js
+++ b/static/script.js
@@ -10,6 +10,9 @@ let parser = new DOMParser();
let start_time = new Date();
let end_time = new Date();
+/*
+ Given the navbar of a popup, make it dragable.
+ */
function bind_popup_control (nav) {
nav.onmousedown = function (e) {
/* Ignore mousedown on children */
@@ -36,20 +39,6 @@ function bind_popup_control (nav) {
});
}
-/*
- * Finds the first element of the DOMTokenList whichs value matches
- * the supplied regexp. Returns a pair of the index and the value.
- */
-DOMTokenList.prototype.find = function (regexp) {
- let entries = this.entries();
- let entry;
- while (! (entry = entries.next()).done) {
- if (entry.value[1].match(regexp)) {
- return entry.value;
- }
- }
-}
-
class EventCreator {
/* dynamicly created event when dragging */
@@ -61,8 +50,10 @@ class EventCreator {
}
create_empty_event () {
- let event = document.getElementById("event-template").firstChild.cloneNode(true);
- let popup = document.getElementById("popup-template").firstChild.cloneNode(true);
+ let event = document.getElementById("event-template")
+ .firstChild.cloneNode(true);
+ let popup = document.getElementById("popup-template")
+ .firstChild.cloneNode(true);
popup.getElementsByClassName("edit-form")[0].onsubmit = function () {
create_event(event);
@@ -294,12 +285,6 @@ function update_current_time_bar () {
= (new Date).format("~Y-~m-~d") + ".html";
}
-function close_all_popups () {
- for (let popup of document.querySelectorAll(".popup-container.visible")) {
- close_popup(popup);
- }
-}
-
async function create_event (event) {
let xml = event.getElementsByTagName("icalendar")[0].outerHTML
@@ -325,7 +310,7 @@ async function create_event (event) {
let body = await response.text();
- /* servere is assumed to return an XML document on the form
+ /* server is assumed to return an XML document on the form
<properties>
**xcal property** ...
</properties>
@@ -398,7 +383,6 @@ window.onload = function () {
end_time.setTime(document.querySelector("meta[name='end-time']").content * 1000)
update_current_time_bar()
- // once a minute for now, could probably be slowed to every 10 minutes
window.setInterval(update_current_time_bar, 1000 * 60)
/* Is event creation active? */
@@ -668,6 +652,12 @@ function close_popup(popup) {
popup.classList.remove("visible");
}
+function close_all_popups () {
+ for (let popup of document.querySelectorAll(".popup-container.visible")) {
+ close_popup(popup);
+ }
+}
+
function open_popup(popup) {
popup.classList.add("visible");
let element = document.getElementById(popup.id.substr(5))