From 1e2ba501c081281d2fe010c702a8f3e55e01f8e4 Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Thu, 26 Jun 2025 14:09:36 -0700 Subject: [PATCH] feat: added fillAvailableHeight js to dynamically resize vertical elements - Updated PHP opening tags from ` -"; - foreach ($logs as $file) $select[] = mk_option(1,$file,basename($file)); - $select[] = ""; + // add syslog to front of logs array + array_unshift($logs, $log); + $select[] = ""; } $select = implode($select); ?> @@ -85,11 +87,6 @@ function toggle(checked) { highlight(checked,'L'); $('span.label input[type=checkbox]').not('.ctrl').prop('checked',checked); } - -function resize() { - $('pre.up').height(Math.max(window.innerHeight-320,330)); -} - function showLog(log) { logfile = log; @@ -142,21 +139,21 @@ $(function() { } }); - resize(); - $(window).bind('resize',function(){resize();}); + fillAvailableHeight(); + $(window).bind('resize',function(){fillAvailableHeight();}); showLog(logfile); }); // $('.title .right').append(""); -
+
@@ -217,10 +214,12 @@ $(function() {
-

+

 
-
+
-
\ No newline at end of file +
+ + \ No newline at end of file diff --git a/emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php b/emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php index 4215ffc51..9d59a0855 100644 --- a/emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php +++ b/emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php @@ -446,4 +446,81 @@ function nchanFocusStop(banner=true) { } } + +/** + * Calculates and sets the height of a target element to fill the available viewport space. + * + * This function dynamically resizes an element to occupy the remaining vertical space + * after accounting for other page elements like headers, footers, controls, and their + * margins/padding. Useful for creating full-height scrollable content areas. + * + * @param {Object} params - Configuration object for height calculation + * @param {string} params.targetElementSelector - CSS selector for the element to resize + * @param {string[]} params.elementSelectorsForHeight - Array of CSS selectors for elements + * whose full height (including margins) should be subtracted from available space + * @param {string[]} params.elementSelectorsForSpacing - Array of CSS selectors for elements + * whose spacing (margins and padding only) should be subtracted from available space + * @param {number} params.manualSpacingOffset - Additional pixels to subtract for manual spacing + * + * @example + * // Use with default parameters + * fillAvailableHeight(); + * + * @example + * // Custom configuration + * fillAvailableHeight({ + * targetElementSelector: '.my-content', + * elementSelectorsForHeight: ['#header', '#footer'], + * elementSelectorsForSpacing: ['.my-content'], + * manualSpacingOffset: 20 + * }); + */ +function fillAvailableHeight(params = { // default params + targetElementSelector: '.js-syslog-output', + elementSelectorsForHeight: [ + '#header', + '#menu', + '.title', + '.js-syslog-controls', + '.js-syslog-actions', + '#footer', + ], + elementSelectorsForSpacing: [ + '.js-syslog-output', + '.displaybox', + ], + manualSpacingOffset: 10, +}) { + const minHeight = 330; + // elements with a height and margin we want to subtract from the target height + let targetHeight = window.innerHeight - params.elementSelectorsForHeight.reduce((acc, selector) => { + const element = document.querySelector(selector); + if (!element) return acc; + + const computedStyle = getComputedStyle(element); + const height = element.offsetHeight; + const marginTop = parseFloat(computedStyle.marginTop) || 0; + const marginBottom = parseFloat(computedStyle.marginBottom) || 0; + + return acc + height + marginTop + marginBottom; + }, 0); + // elements with spacing that we want to subtract from the target height + targetHeight -= params.elementSelectorsForSpacing.reduce((acc, selector) => { + const element = document.querySelector(selector); + if (!element) return acc; + + const computedStyle = getComputedStyle(element); + const marginTop = parseFloat(computedStyle.marginTop) || 0; + const marginBottom = parseFloat(computedStyle.marginBottom) || 0; + const paddingTop = parseFloat(computedStyle.paddingTop) || 0; + const paddingBottom = parseFloat(computedStyle.paddingBottom) || 0; + + return acc + marginTop + marginBottom + paddingTop + paddingBottom; + }, 0); + + // subtract 10px from the target height to provide spacing between the actions & the footer + targetHeight -= params.manualSpacingOffset || 0; + + $(params.targetElementSelector).height(Math.max(targetHeight, minHeight)); +} diff --git a/emhttp/plugins/dynamix/sheets/Syslog.css b/emhttp/plugins/dynamix/sheets/Syslog.css index a418409f7..11ce7c2b8 100644 --- a/emhttp/plugins/dynamix/sheets/Syslog.css +++ b/emhttp/plugins/dynamix/sheets/Syslog.css @@ -6,8 +6,6 @@ input#max { display: flex; justify-content: space-between; align-items: center; - gap: 10px; - margin-bottom: 10px; box-sizing: border-box; * {