@@ -92,3 +92,34 @@ const forceLightMode = false;
9292 darkQuery . addEventListener ( "change" , updateLightMode ) ;
9393 } ) ;
9494} ) ( ) ;
95+
96+ // Add 'tall' class to media elements exceeding --max-media-height
97+ ( function handleTallMedia ( ) {
98+ function getMaxMediaHeight ( ) {
99+ // Get the value of --max-media-height from the root element (in px)
100+ const root = document . documentElement ;
101+ const value = getComputedStyle ( root ) . getPropertyValue ( '--max-media-height' ) . trim ( ) ;
102+ // Parse value (assume px, fallback to 0 if not found)
103+ if ( value . endsWith ( 'px' ) ) {
104+ return parseFloat ( value ) ;
105+ }
106+ return 0 ;
107+ }
108+
109+ function updateTallMediaClasses ( ) {
110+ const maxHeight = getMaxMediaHeight ( ) ;
111+ if ( ! maxHeight ) return ;
112+ document . querySelectorAll ( 'img, video, iframe' ) . forEach ( function ( el ) {
113+ // Use offsetHeight for rendered height
114+ if ( el . offsetHeight > maxHeight ) {
115+ el . classList . add ( 'media-tall' ) ;
116+ } else {
117+ el . classList . remove ( 'media-tall' ) ;
118+ }
119+ } ) ;
120+ }
121+
122+ window . addEventListener ( "DOMContentLoaded" , updateTallMediaClasses ) ;
123+ window . addEventListener ( "load" , updateTallMediaClasses ) ;
124+ window . addEventListener ( "resize" , updateTallMediaClasses ) ;
125+ } ) ( ) ;
0 commit comments