@@ -78,42 +78,43 @@ window.tryExamplesHideIframe = (examplesContainerId, iframeParentContainerId) =>
7878}
7979
8080
81- window . loadTryExamplesConfig = ( ignoreFilePath ) => {
82- // Add a timestamp as query parameter to ensure a cached version of the
83- // file is not used.
84- const timestamp = new Date ( ) . getTime ( ) ;
85- const ignoreFileUrl = `${ ignoreFilePath } ?cb=${ timestamp } ` ;
86- const currentPageUrl = window . location . pathname ;
87- fetch ( ignoreFileUrl )
88- . then ( response => {
89- if ( ! response . ok ) {
90- if ( response . status === 404 ) {
91- // try examples ignore file is not present.
92- return null ;
93- }
94- throw new Error ( `Error fetching ${ ignoreFilePath } ` ) ;
95- }
96- return response . json ( ) ;
97- } )
98- . then ( data => {
99- if ( ! data ) {
81+ window . loadTryExamplesConfig = async ( ignoreFilePath ) => {
82+ try {
83+ // Add a timestamp as query parameter to ensure a cached version of the
84+ // file is not used.
85+ const timestamp = new Date ( ) . getTime ( ) ;
86+ const ignoreFileUrl = `${ ignoreFilePath } ?cb=${ timestamp } ` ;
87+ const currentPageUrl = window . location . pathname ;
88+
89+ const response = await fetch ( ignoreFileUrl ) ;
90+ if ( ! response . ok ) {
91+ if ( response . status === 404 ) {
92+ // Try examples ignore file is not present.
93+ console . log ( 'Ignore file not found.' ) ;
10094 return ;
10195 }
102- // Disable interactive examples if file matches one of the ignore patterns
103- // by hiding try_examples_buttons.
104- const regexPatterns = data . ignore_patterns ;
105- for ( let pattern of regexPatterns ) {
106- let regex = new RegExp ( pattern ) ;
107- if ( regex . test ( currentPageUrl ) ) {
108- var buttons = document . getElementsByClassName ( 'try_examples_button' ) ;
109- for ( var i = 0 ; i < buttons . length ; i ++ ) {
110- buttons [ i ] . classList . add ( 'hidden' ) ;
111- }
112- break ;
96+ throw new Error ( `Error fetching ${ ignoreFilePath } ` ) ;
97+ }
98+
99+ const data = await response . json ( ) ;
100+ if ( ! data ) {
101+ return ;
102+ }
103+
104+ // Disable interactive examples if file matches one of the ignore patterns
105+ // by hiding try_examples_buttons.
106+ Patterns = data . ignore_patterns ;
107+ for ( let pattern of Patterns ) {
108+ let regex = new RegExp ( pattern ) ;
109+ if ( regex . test ( currentPageUrl ) ) {
110+ var buttons = document . getElementsByClassName ( 'try_examples_button' ) ;
111+ for ( var i = 0 ; i < buttons . length ; i ++ ) {
112+ buttons [ i ] . classList . add ( 'hidden' ) ;
113113 }
114+ break ;
114115 }
115- } )
116- . catch ( error => {
117- console . error ( error ) ;
118- } ) ;
116+ }
117+ } catch ( error ) {
118+ console . error ( error ) ;
119+ }
119120} ;
0 commit comments