| 
									
										
										
										
											2020-08-14 00:03:07 -04:00
										 |  |  | window.addEventListener('load', () => { | 
					
						
							| 
									
										
										
										
											2020-08-14 20:09:59 -04:00
										 |  |  |     const tutorialWrapper = document.getElementById('tutorial-wrapper'); | 
					
						
							|  |  |  |     new Promise((resolve, reject) => { | 
					
						
							|  |  |  |         const ajax = new XMLHttpRequest(); | 
					
						
							|  |  |  |         ajax.onreadystatechange = () => { | 
					
						
							|  |  |  |             if (ajax.readyState !== 4) { return; } | 
					
						
							|  |  |  |             if (ajax.status === 404) { | 
					
						
							|  |  |  |                 reject("Sorry, the tutorial is not available in that language yet."); | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             if (ajax.status !== 200) { | 
					
						
							|  |  |  |                 reject("Something went wrong while loading the tutorial."); | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             resolve(ajax.responseText); | 
					
						
							|  |  |  |         }; | 
					
						
							| 
									
										
										
										
											2022-05-11 13:05:53 -05:00
										 |  |  |         ajax.open('GET', `${window.location.origin}/static/generated/docs/` + | 
					
						
							| 
									
										
										
										
											2021-01-03 17:46:47 -05:00
										 |  |  |             `${tutorialWrapper.getAttribute('data-game')}/${tutorialWrapper.getAttribute('data-file')}_` + | 
					
						
							|  |  |  |             `${tutorialWrapper.getAttribute('data-lang')}.md`, true); | 
					
						
							| 
									
										
										
										
											2020-08-14 20:09:59 -04:00
										 |  |  |         ajax.send(); | 
					
						
							|  |  |  |     }).then((results) => { | 
					
						
							|  |  |  |         // Populate page with HTML generated from markdown
 | 
					
						
							| 
									
										
										
										
											2021-09-07 19:22:04 -04:00
										 |  |  |         showdown.setOption('tables', true); | 
					
						
							|  |  |  |         showdown.setOption('strikethrough', true); | 
					
						
							|  |  |  |         showdown.setOption('literalMidWordUnderscores', true); | 
					
						
							| 
									
										
										
										
											2021-11-29 22:26:08 -05:00
										 |  |  |         showdown.setOption('disableForced4SpacesIndentedSublists', true); | 
					
						
							| 
									
										
										
										
											2020-09-19 15:20:13 -04:00
										 |  |  |         tutorialWrapper.innerHTML += (new showdown.Converter()).makeHtml(results); | 
					
						
							| 
									
										
										
										
											2020-12-03 01:55:06 -05:00
										 |  |  |         adjustHeaderWidth(); | 
					
						
							| 
									
										
										
										
											2020-08-14 00:03:07 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-07 00:01:07 +02:00
										 |  |  |         const title = document.querySelector('h1') | 
					
						
							|  |  |  |         if (title) { | 
					
						
							|  |  |  |             document.title = title.textContent; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 20:09:59 -04:00
										 |  |  |         // Reset the id of all header divs to something nicer
 | 
					
						
							| 
									
										
										
										
											2022-10-14 23:09:17 +02:00
										 |  |  |         for (const header of document.querySelectorAll('h1, h2, h3, h4, h5, h6')) { | 
					
						
							|  |  |  |             const headerId = header.innerText.replace(/\s+/g, '-').toLowerCase(); | 
					
						
							|  |  |  |             header.setAttribute('id', headerId); | 
					
						
							|  |  |  |             header.addEventListener('click', () => { | 
					
						
							|  |  |  |                 window.location.hash = `#${headerId}`; | 
					
						
							|  |  |  |                 header.scrollIntoView(); | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2020-08-14 20:09:59 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Manually scroll the user to the appropriate header if anchor navigation is used
 | 
					
						
							| 
									
										
										
										
											2022-10-14 23:09:17 +02:00
										 |  |  |         document.fonts.ready.finally(() => { | 
					
						
							|  |  |  |             if (window.location.hash) { | 
					
						
							|  |  |  |                 const scrollTarget = document.getElementById(window.location.hash.substring(1)); | 
					
						
							|  |  |  |                 scrollTarget?.scrollIntoView(); | 
					
						
							| 
									
										
										
										
											2020-08-14 20:09:59 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2022-10-14 23:09:17 +02:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-08-14 20:09:59 -04:00
										 |  |  |     }).catch((error) => { | 
					
						
							| 
									
										
										
										
											2021-01-03 17:46:47 -05:00
										 |  |  |         console.error(error); | 
					
						
							| 
									
										
										
										
											2020-08-14 20:09:59 -04:00
										 |  |  |         tutorialWrapper.innerHTML = | 
					
						
							| 
									
										
										
										
											2021-01-03 17:46:47 -05:00
										 |  |  |             `<h2>This page is out of logic!</h2>
 | 
					
						
							| 
									
										
										
										
											2020-08-14 20:09:59 -04:00
										 |  |  |             <h3>Click <a href="${window.location.origin}/tutorial">here</a> to return to safety.</h3>`; | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-08-14 00:03:07 -04:00
										 |  |  | }); |