@@ -149,6 +149,42 @@ var tryExamplesGlobalMinHeight = 0;
149
149
*/
150
150
var tryExamplesConfigLoaded = false ;
151
151
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
+
152
188
// A config loader with improved error handling + request deduplication
153
189
const ConfigLoader = ( ( ) => {
154
190
// setting a private state for managing requests and errors
@@ -173,6 +209,15 @@ const ConfigLoader = (() => {
173
209
} ;
174
210
175
211
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
+
176
221
if ( tryExamplesConfigLoaded ) {
177
222
return ;
178
223
}
@@ -254,6 +299,27 @@ const ConfigLoader = (() => {
254
299
} ;
255
300
} ) ( ) ;
256
301
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
+
257
323
window . loadTryExamplesConfig = ConfigLoader . loadConfig ;
258
324
259
325
window . toggleTryExamplesButtons = ( ) => {
0 commit comments