Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mr-sunset/window/llms.txt
Use this file to discover all available pages before exploring further.
script.js attaches all Window interactivity inside a single DOMContentLoaded listener, ensuring the DOM is fully parsed before any element lookups or event bindings occur. This page documents every variable, event listener, and the logic inside each handler.
Initialization
The entire script is wrapped in aDOMContentLoaded callback. The first thing it does is resolve the three elements the script needs by ID:
| Variable | Element ID | Purpose |
|---|---|---|
windowContainer | window-container | Root panel — repositioned during drag, hidden on close |
titleBar | title-bar | Drag handle — source of the mousedown event |
closeBtn | close | Red button — source of the click event |
State variables
Three module-scoped variables track drag state. They are declared inside theDOMContentLoaded callback and are shared across all event handlers:
| Variable | Type | Default | Description |
|---|---|---|---|
isDragging | boolean | false | true while a drag gesture is active (between mousedown and mouseup) |
offsetX | number | 0 | Horizontal distance from the mouse pointer to the window’s left edge at the moment dragging starts |
offsetY | number | 0 | Vertical distance from the mouse pointer to the window’s top edge at the moment dragging starts |
Event: titleBar mousedown
Fires when the user presses the mouse button anywhere inside the title bar. SetsisDragging to true and captures the offset between the current mouse position and the window’s current top-left corner. These offsets ensure the window moves relative to where it was grabbed rather than jumping to a fixed position.
e.clientX/e.clientY— mouse coordinates in the viewport at the moment of the press.windowContainer.offsetLeft/windowContainer.offsetTop— the window element’s current position relative to its offset parent.- The difference is stored so that
mousemovecan subtract it back out, keeping the grab point stable throughout the drag.
Event: document mousemove
Attached todocument (not the window element) so that dragging continues even if the pointer briefly leaves the panel. The if (isDragging) guard means no work is done unless a drag is actually in progress.
e.clientX - offsetXgives the newleftvalue: current pointer X minus the recorded grab offset.e.clientY - offsetYgives the newtopvalue: current pointer Y minus the recorded grab offset.- Both are written as inline
pxstyles directly onwindowContainer, which overrides the stylesheet’stransform: translate(-50%, -50%)centering after the first drag.
After the first drag interaction, the inline
left and top styles take full control of positioning and the CSS transform: translate(-50%, -50%) centring no longer applies. If you need to programmatically re-center the window you must clear those inline styles or reset them to 50% and restore the transform.Event: document mouseup
Attached todocument so it fires regardless of where the mouse button is released — even outside the browser window. Resets isDragging to false, which stops mousemove from repositioning the panel.
Event: closeBtn click
Fires when the user clicks the red.close button. Hides both the title bar and the entire window container by setting their display to 'none'.
windowContainer removes the panel from view, and titleBar is hidden separately so that restoring windowContainer alone does not inadvertently leave the title bar in an inconsistent state.
Re-opening the window
There is no built-in re-open handler inscript.js. To restore the window after it has been closed, set both display values back to their visible states:
titleBar must be restored to flex (not block) because its layout depends on display: flex to align the traffic-light buttons correctly, matching the stylesheet declaration.