From b73ed6ebd3cca86de065549cfb0d109a1d0461c5 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Wed, 10 Apr 2024 19:05:10 +0200 Subject: split js files and do local time conversion --- src/jwebmail/static/src/dh-select-all-mails.js | 11 +++++++ .../static/src/dh-submit-sort-on-change.js | 12 ++++++++ src/jwebmail/static/src/dh-toggle-navbar.js | 13 ++++++++ src/jwebmail/static/src/displayheaders.js | 35 ---------------------- src/jwebmail/static/src/localtime.js | 5 ++++ src/jwebmail/static/src/multipart-alt-tabs.js | 21 +++++++++++++ src/jwebmail/static/src/rendermail.js | 21 ------------- 7 files changed, 62 insertions(+), 56 deletions(-) create mode 100644 src/jwebmail/static/src/dh-select-all-mails.js create mode 100644 src/jwebmail/static/src/dh-submit-sort-on-change.js create mode 100644 src/jwebmail/static/src/dh-toggle-navbar.js delete mode 100644 src/jwebmail/static/src/displayheaders.js create mode 100644 src/jwebmail/static/src/localtime.js create mode 100644 src/jwebmail/static/src/multipart-alt-tabs.js delete mode 100644 src/jwebmail/static/src/rendermail.js (limited to 'src/jwebmail/static') diff --git a/src/jwebmail/static/src/dh-select-all-mails.js b/src/jwebmail/static/src/dh-select-all-mails.js new file mode 100644 index 0000000..73f8ff3 --- /dev/null +++ b/src/jwebmail/static/src/dh-select-all-mails.js @@ -0,0 +1,11 @@ +function check_all() { + const setTo = this.checked; + const chkbox = document.getElementsByClassName('jwm-mail-checkbox'); + + for (const m of chkbox) + m.checked = setTo; +} + +document.addEventListener("DOMContentLoaded", function() { + document.getElementById("check-all").addEventListener("click", check_all); +}); diff --git a/src/jwebmail/static/src/dh-submit-sort-on-change.js b/src/jwebmail/static/src/dh-submit-sort-on-change.js new file mode 100644 index 0000000..6d0ab6d --- /dev/null +++ b/src/jwebmail/static/src/dh-submit-sort-on-change.js @@ -0,0 +1,12 @@ +function sort_select_submit() { + this.children[0].form.submit(); +} + +document.addEventListener("DOMContentLoaded", function() { + const sort_select = document.getElementById("sort"); + const current_option_name = new URL(document.location).searchParams.get("sort"); + if (current_option_name) + sort_select.value = current_option_name; + + document.getElementById("sort-select").addEventListener("change", sort_select_submit); +}); diff --git a/src/jwebmail/static/src/dh-toggle-navbar.js b/src/jwebmail/static/src/dh-toggle-navbar.js new file mode 100644 index 0000000..1325516 --- /dev/null +++ b/src/jwebmail/static/src/dh-toggle-navbar.js @@ -0,0 +1,13 @@ +function toggle_navbar() { + // Get the target from the "data-target" attribute + const target = this.dataset.target; + const $target = document.getElementById(target); + + // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu" + this.classList.toggle('is-active'); + $target.classList.toggle('is-active'); +} + +document.addEventListener("DOMContentLoaded", function() { + document.getElementById("navbar-toggle").addEventListener("click", toggle_navbar); +}); diff --git a/src/jwebmail/static/src/displayheaders.js b/src/jwebmail/static/src/displayheaders.js deleted file mode 100644 index 3c0936a..0000000 --- a/src/jwebmail/static/src/displayheaders.js +++ /dev/null @@ -1,35 +0,0 @@ -function toggle_navbar() { - // Get the target from the "data-target" attribute - const target = this.dataset.target; - const $target = document.getElementById(target); - - // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu" - this.classList.toggle('is-active'); - $target.classList.toggle('is-active'); -} - -function sort_select_submit() { - this.children[0].form.submit(); -} - -function check_all() { - const setTo = this.checked; - const chkbox = document.getElementsByClassName('jwm-mail-checkbox'); - - for (const m of chkbox) - m.checked = setTo; -} - -document.addEventListener("DOMContentLoaded", function() { - { - const sort_select = document.getElementById("sort"); - const current_option_name = new URL(document.location).searchParams.get("sort"); - if (current_option_name) - sort_select.value = current_option_name; - } - - document.getElementById("sort-select").addEventListener("change", sort_select_submit); - document.getElementById("navbar-toggle").addEventListener("click", toggle_navbar); - document.getElementById("check-all").addEventListener("click", check_all); -}); - diff --git a/src/jwebmail/static/src/localtime.js b/src/jwebmail/static/src/localtime.js new file mode 100644 index 0000000..daa1455 --- /dev/null +++ b/src/jwebmail/static/src/localtime.js @@ -0,0 +1,5 @@ +document.querySelectorAll('time.jwm-tolocaltime').forEach($e => { + const dateTime = new Date($e.dateTime); + $e.innerHTML = new Intl.DateTimeFormat(document.documentElement.lang). + format(dateTime.toLocaleString()); +}); diff --git a/src/jwebmail/static/src/multipart-alt-tabs.js b/src/jwebmail/static/src/multipart-alt-tabs.js new file mode 100644 index 0000000..1331913 --- /dev/null +++ b/src/jwebmail/static/src/multipart-alt-tabs.js @@ -0,0 +1,21 @@ +function tabSelection(evt) { + const self = evt.target; + + for (const ts of self.parentElement.parentElement.children) { + ts.classList.remove('is-active'); + } + self.parentNode.classList.add('is-active'); + + const bodies = self.parentElement.parentElement.parentElement.parentElement.children[1].children; + for (const ts of bodies) { + ts.classList.add('is-hidden'); + } + bodies[+self.parentElement.attributes.data.value].classList.remove('is-hidden'); +} + +document.addEventListener("DOMContentLoaded", function() { + const tabSections = document.getElementsByClassName("jwm-mail-body-multipart-alternative"); + for (const ts of tabSections) { + Array.from(ts.children[0].children[0].children).forEach(element => element.children[0].addEventListener('click', tabSelection)); + } +}) diff --git a/src/jwebmail/static/src/rendermail.js b/src/jwebmail/static/src/rendermail.js deleted file mode 100644 index 1331913..0000000 --- a/src/jwebmail/static/src/rendermail.js +++ /dev/null @@ -1,21 +0,0 @@ -function tabSelection(evt) { - const self = evt.target; - - for (const ts of self.parentElement.parentElement.children) { - ts.classList.remove('is-active'); - } - self.parentNode.classList.add('is-active'); - - const bodies = self.parentElement.parentElement.parentElement.parentElement.children[1].children; - for (const ts of bodies) { - ts.classList.add('is-hidden'); - } - bodies[+self.parentElement.attributes.data.value].classList.remove('is-hidden'); -} - -document.addEventListener("DOMContentLoaded", function() { - const tabSections = document.getElementsByClassName("jwm-mail-body-multipart-alternative"); - for (const ts of tabSections) { - Array.from(ts.children[0].children[0].children).forEach(element => element.children[0].addEventListener('click', tabSelection)); - } -}) -- cgit v1.2.3