You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2021/12/13 22:51:55 UTC

[incubator-ponymail-foal] 01/02: Adjust calendar max size according to viewport

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit d7744a88150d8a01b233ebebc91e4d965632ea88
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Dec 13 23:51:33 2021 +0100

    Adjust calendar max size according to viewport
---
 webui/js/source/sidebar-calendar.js | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/webui/js/source/sidebar-calendar.js b/webui/js/source/sidebar-calendar.js
index 3e1ed41..5a03f5d 100644
--- a/webui/js/source/sidebar-calendar.js
+++ b/webui/js/source/sidebar-calendar.js
@@ -19,10 +19,24 @@ let calendar_index = 0;
 let current_calendar_size = CALENDAR_YEARS_SHOWN;
 let calendar_state = {}
 
+
+function calendar_max_height() {
+    let body = document.body;
+    let html = document.documentElement;
+    let height = Math.max(body.scrollHeight,
+        html.clientHeight, html.scrollHeight);
+    let width = Math.max(body.scrollWidth,
+        html.clientWidth, html.scrollWidth);
+    let year_height = 48; // Height of one calendar year
+    height -= document.getElementById("emails").getBoundingClientRect().y + 16; // top area height plus footer
+    let number_of_years = Math.max(5, Math.floor(height / year_height));
+    return number_of_years;
+}
+
 function renderCalendar(state) {
     calendar_state = state ? state : calendar_state;
     calendar_index = 0;
-    current_calendar_size = G_show_stats_sidebar ? CALENDAR_YEARS_SHOWN : CALENDAR_YEARS_SHOWN * 3;
+    current_calendar_size = G_show_stats_sidebar ? CALENDAR_YEARS_SHOWN : calendar_max_height();
     // Only render if calendar div is present
     let cal = document.getElementById('sidebar_calendar');
     if (!cal) {