@@ -149,6 +149,42 @@ var tryExamplesGlobalMinHeight = 0;
149149 */
150150var tryExamplesConfigLoaded = false ;
151151
152+ // This function is used to check if the current device is a mobile device.
153+ // We assume the authenticity of the user agent string is enough to
154+ // determine that, and we also check the window size as a fallback.
155+ window . isMobileDevice = ( ) => {
156+ const mobilePatterns = [
157+ / A n d r o i d / i,
158+ / w e b O S / i,
159+ / i P h o n e / i,
160+ / i P a d / i,
161+ / i P o d / i,
162+ / B l a c k B e r r y / i,
163+ / I E M o b i l e / i,
164+ / W i n d o w s P h o n e / i,
165+ / O p e r a M i n i / i,
166+ / S a m s u n g B r o w s e r / i,
167+ / U C .* B r o w s e r | U C W E B / i,
168+ / M i u i B r o w s e r / i,
169+ / M o b i l e / i,
170+ / T a b l e t / i,
171+ ] ;
172+
173+ const isMobileByUA = mobilePatterns . some ( ( pattern ) =>
174+ pattern . test ( navigator . userAgent ) ,
175+ ) ;
176+ const isMobileBySize = window . innerWidth <= 480 || window . innerHeight <= 480 ;
177+ const isLikelyMobile = isMobileByUA || isMobileBySize ;
178+
179+ if ( isLikelyMobile ) {
180+ console . log (
181+ "Mobile device detected, disabling interactive example buttons to conserve bandwidth." ,
182+ ) ;
183+ }
184+
185+ return isLikelyMobile ;
186+ } ;
187+
152188// A config loader with improved error handling + request deduplication
153189const ConfigLoader = ( ( ) => {
154190 // setting a private state for managing requests and errors
@@ -173,6 +209,15 @@ const ConfigLoader = (() => {
173209 } ;
174210
175211 const loadConfig = async ( configFilePath ) => {
212+ if ( window . isMobileDevice ( ) ) {
213+ const buttons = document . getElementsByClassName ( "try_examples_button" ) ;
214+ for ( let i = 0 ; i < buttons . length ; i ++ ) {
215+ buttons [ i ] . classList . add ( "hidden" ) ;
216+ }
217+ tryExamplesConfigLoaded = true ; // mock it
218+ return ;
219+ }
220+
176221 if ( tryExamplesConfigLoaded ) {
177222 return ;
178223 }
@@ -254,6 +299,27 @@ const ConfigLoader = (() => {
254299 } ;
255300} ) ( ) ;
256301
302+ // Add a resize handler that will update the buttons' visibility on
303+ // orientation changes
304+ let resizeTimeout ;
305+ window . addEventListener ( "resize" , ( ) => {
306+ clearTimeout ( resizeTimeout ) ;
307+ resizeTimeout = setTimeout ( ( ) => {
308+ if ( ! tryExamplesConfigLoaded ) return ; // since we won't interfere if the config isn't loaded
309+
310+ const buttons = document . getElementsByClassName ( "try_examples_button" ) ;
311+ const shouldHide = window . isMobileDevice ( ) ;
312+
313+ for ( let i = 0 ; i < buttons . length ; i ++ ) {
314+ if ( shouldHide ) {
315+ buttons [ i ] . classList . add ( "hidden" ) ;
316+ } else {
317+ buttons [ i ] . classList . remove ( "hidden" ) ;
318+ }
319+ }
320+ } , 250 ) ;
321+ } ) ;
322+
257323window . loadTryExamplesConfig = ConfigLoader . loadConfig ;
258324
259325window . toggleTryExamplesButtons = ( ) => {
0 commit comments