2022-11-29 19:19:30 +01:00
|
|
|
import { ready } from './ready';
|
|
|
|
|
2022-11-29 21:47:26 +01:00
|
|
|
/**
|
|
|
|
* @param {NodeList} elements
|
2022-12-10 14:59:26 +01:00
|
|
|
* @param {string} prop
|
2022-11-29 21:47:26 +01:00
|
|
|
* @param {*} value
|
|
|
|
*/
|
|
|
|
const applyStyle = (elements, prop, value) => {
|
|
|
|
elements.forEach((element) => {
|
|
|
|
element.style[prop] = value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:09:37 +01:00
|
|
|
/**
|
|
|
|
* Enables the fixed headers and time lane for the shift-calendar and datatables
|
|
|
|
*/
|
2022-11-29 21:47:26 +01:00
|
|
|
ready(() => {
|
|
|
|
if (!document.querySelector('.shift-calendar')) return;
|
|
|
|
|
|
|
|
const headers = document.querySelectorAll('.shift-calendar .header');
|
|
|
|
const timeLane = document.querySelector('.shift-calendar .time');
|
|
|
|
const topReference = document.querySelector('.container-fluid .row');
|
|
|
|
|
|
|
|
if (!headers.length || !timeLane || !topReference) return;
|
|
|
|
|
|
|
|
timeLane.style.position = 'relative';
|
|
|
|
timeLane.style.zIndex = 999;
|
|
|
|
|
|
|
|
applyStyle(headers, 'position', 'relative');
|
|
|
|
applyStyle(headers, 'zIndex', 900);
|
|
|
|
|
|
|
|
window.addEventListener('scroll', () => {
|
|
|
|
const top = headers.item(0).parentNode.getBoundingClientRect().top;
|
2022-12-04 12:00:18 +01:00
|
|
|
const left = Math.max(0, window.scrollX - 15);
|
2022-11-29 21:47:26 +01:00
|
|
|
|
2022-12-04 12:00:18 +01:00
|
|
|
timeLane.style.left = `${left}px`;
|
2022-11-29 21:47:26 +01:00
|
|
|
|
|
|
|
const headersTop = Math.max(
|
|
|
|
0,
|
|
|
|
window.scrollY - top - 13 + topReference.getBoundingClientRect().top
|
2022-12-04 12:00:18 +01:00
|
|
|
);
|
|
|
|
applyStyle(headers, 'top', `${headersTop}px`);
|
2022-11-29 21:47:26 +01:00
|
|
|
});
|
2017-01-02 15:43:36 +01:00
|
|
|
});
|