@@ -16,6 +16,8 @@ import { debounceTime, filter } from 'rxjs/operators';
1616import { environment } from '../../environments/environment' ;
1717import { BasePageComponent } from './pages/page/page.component' ;
1818
19+ const CARBON_WIDTH_BREAKPOINT = 1200 ;
20+
1921@Component ( {
2022 selector : 'app-homepage' ,
2123 templateUrl : './homepage.component.html' ,
@@ -133,16 +135,26 @@ export class HomepageComponent implements OnInit, OnDestroy, AfterViewInit {
133135 if ( ! nativeElement ) {
134136 return ;
135137 }
138+
136139 this . contentRef = nativeElement . querySelector ( '.content' ) ;
137140 if ( this . contentRef && ! this . contentRef . querySelector ( '.carbon-wrapper' ) ) {
138141 const scriptTag = this . createCarbonScriptTag ( ) ;
139142 const carbonWrapper = document . createElement ( 'div' ) ;
140143 carbonWrapper . classList . add ( 'carbon-wrapper' ) ;
144+
145+ if ( window . innerWidth > CARBON_WIDTH_BREAKPOINT ) {
146+ carbonWrapper . classList . add ( 'hide' ) ;
147+ }
141148 carbonWrapper . prepend ( scriptTag ) ;
142149
143150 this . contentRef . prepend ( carbonWrapper ) ;
144151 }
152+
145153 this . cd . markForCheck ( ) ;
154+
155+ // Schedule check as TOC might not be rendered yet
156+ const adOverlapCheckDelay = 300 ;
157+ setTimeout ( ( ) => this . hideAdIfTocOverflow ( ) , adOverlapCheckDelay ) ;
146158 }
147159
148160 createCarbonScriptTag ( ) : HTMLScriptElement {
@@ -170,4 +182,25 @@ export class HomepageComponent implements OnInit, OnDestroy, AfterViewInit {
170182 } ;
171183 return scriptTag ;
172184 }
185+
186+ hideAdIfTocOverflow ( ) {
187+ const carbonHeight = 160 ;
188+ const offset = 200 ;
189+ const viewportHeight = window . innerHeight ;
190+ const maxTocHeight = viewportHeight - carbonHeight - offset ;
191+
192+ const tocElRef = document . querySelector ( '.toc-wrapper ul' ) ;
193+ if ( ! tocElRef ) {
194+ return ;
195+ }
196+
197+ if (
198+ tocElRef . clientHeight > maxTocHeight &&
199+ window . innerWidth > CARBON_WIDTH_BREAKPOINT
200+ ) {
201+ this . contentRef . querySelector ( '.carbon-wrapper' ) . classList . add ( 'hide' ) ;
202+ } else {
203+ this . contentRef . querySelector ( '.carbon-wrapper' ) . classList . remove ( 'hide' ) ;
204+ }
205+ }
173206}
0 commit comments