|
16 | 16 | <div class="panel panel-editor"> |
17 | 17 | <div id="editor"></div> |
18 | 18 | <p> |
19 | | - Load an Example: |
20 | | - <a href="?load=pinouts/esp32-c3-super-mini.yaml">ESP32-C3 Super Mini</a>, |
21 | | - <a href="?load=pinouts/raspberry-pi.yaml">Raspberry Pi</a>, |
22 | | - <a href="?load=pinouts/a4988.yaml">A4988 Motor Driver</a> |
| 19 | + <label for="example-select">Load an Example:</label> |
| 20 | + <select name="examples" id="example-select"> |
| 21 | + <option value="">--Please choose an example--</option> |
| 22 | + </select> |
23 | 23 | </p> |
| 24 | + <script> |
| 25 | + document.addEventListener('DOMContentLoaded', () => { |
| 26 | + const selectElement = document.getElementById('example-select'); |
| 27 | + |
| 28 | + fetch('index.json') |
| 29 | + .then(response => { |
| 30 | + if (!response.ok) { |
| 31 | + throw new Error(`HTTP error! status: ${response.status}`); |
| 32 | + } |
| 33 | + return response.json(); |
| 34 | + }) |
| 35 | + .then(data => { |
| 36 | + // Sort examples alphabetically by title |
| 37 | + const sortedExamples = Object.entries(data).sort(([, titleA], [, titleB]) => |
| 38 | + titleA.localeCompare(titleB) |
| 39 | + ); |
| 40 | + |
| 41 | + sortedExamples.forEach(([path, title]) => { |
| 42 | + const option = document.createElement('option'); |
| 43 | + option.value = path; |
| 44 | + option.textContent = title; |
| 45 | + selectElement.appendChild(option); |
| 46 | + }); |
| 47 | + }) |
| 48 | + .catch(error => { |
| 49 | + console.error('Error loading or parsing index.json:', error); |
| 50 | + // Optionally disable the select or show an error message |
| 51 | + selectElement.disabled = true; |
| 52 | + const errorOption = document.createElement('option'); |
| 53 | + errorOption.textContent = 'Error loading examples'; |
| 54 | + selectElement.appendChild(errorOption); |
| 55 | + }); |
| 56 | + |
| 57 | + selectElement.addEventListener('change', (event) => { |
| 58 | + const selectedPath = event.target.value; |
| 59 | + if (selectedPath) { |
| 60 | + window.location.search = `?load=${encodeURIComponent(selectedPath)}`; |
| 61 | + } |
| 62 | + }); |
| 63 | + }); |
| 64 | + </script> |
24 | 65 |
|
25 | 66 | <p> |
26 | 67 | <b>Learn more</b> about the tool and available config options in the |
|
0 commit comments