js

print.js
const printButtons = document.querySelectorAll('[aria-labelledby^="print"]');

printButtons.forEach(printButton => {
    printButton.addEventListener('click', () => {
        // Example Traversing
        const article = printButton.parentElement.parentElement.previousElementSibling;

        article.setAttribute('id', 'show-for-print');
        body.classList.add('hide-from-print');
        window.print();

        // Toggle the class and ID after 1 second
        setTimeout(() => {
            article.removeAttribute('id');
            body.classList.remove('hide-from-print');
        }, 1000);
    });
});
print.scss
@media print {
  // add this to the body
  .hide-from-print {
     visibility: hidden;
  }

  // Add this to the target element
  #show-for-print {
    visibility: visible;
  }
}
22.05.2025 | Holger Weischenberg

Print only a part of a page

cssMediaQuery.js
// Retrieve all computed styles from the root HTML element (:root)
const rootStyles = getComputedStyle(document.documentElement);

// Get the value of the CSS variable --Breakpoint.
// Use a fallback (e.g., 768px) if the variable is not defined.
const breakpoint = rootStyles.getPropertyValue('--Breakpoint').trim() || '768px';

// Create a MediaQueryList based on the breakpoint value
const mediaQuery = window.matchMedia(`(min-width: ${breakpoint})`);

// Function that runs when the viewport is at or above the breakpoint
function handleDesktopLayout() {
    console.log("Viewport is at or above the breakpoint.");
}

// Function that runs when the viewport drops below the breakpoint
function handleMobileLayout() {
    console.log("Viewport is below the breakpoint.");
}

// Early return for the initial state:
// If the viewport does NOT meet the breakpoint requirement, run mobile logic and exit
if (!mediaQuery.matches) {
    handleMobileLayout();
    // No desktop logic needed at this point
} else {
    handleDesktopLayout();
}

// Listen for changes in viewport size relative to the breakpoint
mediaQuery.addEventListener('change', (event) => {
    if (event.matches) {
        // The viewport just became equal to or larger than the breakpoint
        handleDesktopLayout();
    } else {
        // The viewport just became smaller than the breakpoint
        handleMobileLayout();
    }
});

formDataManipulation.js
// Modifies form data on submit.
form.addEventListener("formdata", (e) => {
  const formData = e.formData;
  geoLocationFieldNames.forEach((name) => {
    formData.delete(name);
  });
});

29.01.2026 | Peter Gerken

Manipulate Form Data before Submit

getObjectFromDataByKeyValue.js
/**
 * Loads an object from another object by value of a certain key.
 *
 * @usage 
 *   data = [
 *     'foo': {
 *         'id' => 5,
 *         'label' => 'Foo'
 *     },
 *     'bar': {
 *         'id' => 6,
 *         'label' => 'Bar'
 *     }
 *   ]
 *   foo = getObjectFromDataByKeyValue('id', 5, data)
 *
 * @param key
 *   The key we are comparing our value with.
 * @param value
 *   The value the key should have.
 * @param data
 *   The data you want to search in.
 * @returns {unknown}
 */
function getObjectFromDataByKeyValue(key, value, data) {
  return Object.values(data).find(o => o[key] === value)
}