Skip to content

Commit

Permalink
perf(examples): refactor js example execution so it works on docsite #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-capsule42 committed May 23, 2023
1 parent 8c0c38f commit ffe429f
Show file tree
Hide file tree
Showing 11 changed files with 17,454 additions and 94 deletions.
24 changes: 11 additions & 13 deletions demo/demo.md
Expand Up @@ -243,18 +243,16 @@ The `auro-menu` component supports the use of the `matchWord` attribute to highl
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./partials/matchWord.js) -->
<!-- The below code snippet is automatically added from ./partials/matchWord.js -->
```js
let matchWordInput;
let matchWordMenu;

function matchWords() {
matchWordInput = document.querySelector('#matchWordInput');
matchWordMenu = document.querySelector('#matchWordMenu');
function updateMatch() {
let matchWordMenu = document.querySelector('#matchWordMenu');

matchWordInput.addEventListener('keyup', updateMatch);
matchWordMenu.matchWord = matchWordInput.value;
}

function updateMatch() {
matchWordMenu.matchWord = matchWordInput.value;
export function auroMenuMatchWordExample() {
let matchWordInput = document.querySelector('#matchWordInput');

matchWordInput.addEventListener('keyup', updateMatch);
}
```
<!-- AURO-GENERATED-CONTENT:END -->
Expand Down Expand Up @@ -653,7 +651,7 @@ The `auro-menu` may be reset to a state with no menuoption selected by setting t
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./partials/reset.js) -->
<!-- The below code snippet is automatically added from ./partials/reset.js -->
```js
setTimeout(() => {
export function auroMenuResetExample() {
const resetExampleBtnElem = document.querySelector('#resetExampleBtn');
const resetExampleElem = document.querySelector('#resetExample');

Expand All @@ -662,7 +660,7 @@ The `auro-menu` may be reset to a state with no menuoption selected by setting t
resetExampleElem.value = undefined;
})
}
}, 500);
}
```
<!-- AURO-GENERATED-CONTENT:END -->

Expand Down Expand Up @@ -690,7 +688,7 @@ The `auro-menuoption` element supports scenarios where a custom event should be
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./partials/customEvent.js) -->
<!-- The below code snippet is automatically added from ./partials/customEvent.js -->
```js
setTimeout(() => {
export function auroMenuCustomEventExample() {
let menuCustomEventEl = document.querySelector('auro-menu#customEvent');

if (menuCustomEventEl) {
Expand All @@ -699,7 +697,7 @@ The `auro-menuoption` element supports scenarios where a custom event should be
alert(`My Custom Event Fired`);
});
}
}, 1000);
}
```
<!-- AURO-GENERATED-CONTENT:END -->

Expand Down
10 changes: 4 additions & 6 deletions demo/index.html
Expand Up @@ -25,18 +25,16 @@
document.querySelector('main').innerHTML = rawHtml;
Prism.highlightAll();
})
.then(() => {
matchWords();
});
</script>
<script type="module" src="../src/auro-menu.js"></script>
<script type="module" src="../src/auro-menuoption.js"></script>
<script src="https://unpkg.com/@alaskaairux/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
<script src="https://unpkg.com/@alaskaairux/auro-icon@latest/dist/auro-icon__bundled.js" type="module"></script>
<script src="https://unpkg.com/@aurodesignsystem/auro-input@latest/dist/auro-input__bundled.js" type="module"></script>
<script src="https://unpkg.com/@alaskaairux/auro-button@latest/dist/auro-button__bundled.js" type="module"></script>
<script src="./partials/matchWord.js"></script>
<script type="module" src="./partials/reset.js"></script>
<script type="module" src="./partials/customEvent.js"></script>
<script src="./index.min.js"></script>
<script>
initMenuIndexExamples();
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions demo/index.js
@@ -0,0 +1,20 @@
import { auroMenuResetExample } from './partials/reset';
import { auroMenuMatchWordExample } from './partials/matchWord';
import { auroMenuCustomEventExample } from './partials/customEvent';

export function initMenuIndexExamples(initCount) {
initCount = initCount || 0;

try {
auroMenuResetExample();
auroMenuMatchWordExample();
auroMenuCustomEventExample();
} catch {
if (initCount <= 20) {
// setTimeout handles issue where content is sometimes loaded after the functions get called
setTimeout(() => {
initMenuIndexExamples(initCount + 1);
}, 100);
}
}
}
51 changes: 51 additions & 0 deletions demo/index.min.js
@@ -0,0 +1,51 @@
function auroMenuResetExample() {
const resetExampleBtnElem = document.querySelector('#resetExampleBtn');
const resetExampleElem = document.querySelector('#resetExample');

if (resetExampleElem && resetExampleBtnElem) {
resetExampleBtnElem.addEventListener('click', () => {
resetExampleElem.value = undefined;
});
}
}

function updateMatch() {
let matchWordMenu = document.querySelector('#matchWordMenu');

matchWordMenu.matchWord = matchWordInput.value;
}

function auroMenuMatchWordExample() {
let matchWordInput = document.querySelector('#matchWordInput');

matchWordInput.addEventListener('keyup', updateMatch);
}

function auroMenuCustomEventExample() {
let menuCustomEventEl = document.querySelector('auro-menu#customEvent');

if (menuCustomEventEl) {
menuCustomEventEl.addEventListener('mycustomevent', () => {
console.warn('My Custom Event Fired');
alert(`My Custom Event Fired`);
});
}
}

function initMenuIndexExamples(initCount) {
initCount = initCount || 0;

try {
auroMenuResetExample();
auroMenuMatchWordExample();
auroMenuCustomEventExample();
} catch {
if (initCount <= 20) {
// setTimeout handles issue where content is sometimes loaded after the functions get called
setTimeout(() => {
initMenuIndexExamples(initCount + 1);
}, 100);
}
}
}

4 changes: 2 additions & 2 deletions demo/partials/customEvent.js
@@ -1,4 +1,4 @@
setTimeout(() => {
export function auroMenuCustomEventExample() {
let menuCustomEventEl = document.querySelector('auro-menu#customEvent');

if (menuCustomEventEl) {
Expand All @@ -7,4 +7,4 @@ setTimeout(() => {
alert(`My Custom Event Fired`);
});
}
}, 1000);
}
16 changes: 7 additions & 9 deletions demo/partials/matchWord.js
@@ -1,13 +1,11 @@
let matchWordInput;
let matchWordMenu;

function matchWords() {
matchWordInput = document.querySelector('#matchWordInput');
matchWordMenu = document.querySelector('#matchWordMenu');
function updateMatch() {
let matchWordMenu = document.querySelector('#matchWordMenu');

matchWordInput.addEventListener('keyup', updateMatch);
matchWordMenu.matchWord = matchWordInput.value;
}

function updateMatch() {
matchWordMenu.matchWord = matchWordInput.value;
export function auroMenuMatchWordExample() {
let matchWordInput = document.querySelector('#matchWordInput');

matchWordInput.addEventListener('keyup', updateMatch);
}
5 changes: 2 additions & 3 deletions demo/partials/reset.js
@@ -1,5 +1,4 @@

setTimeout(() => {
export function auroMenuResetExample() {
const resetExampleBtnElem = document.querySelector('#resetExampleBtn');
const resetExampleElem = document.querySelector('#resetExample');

Expand All @@ -8,4 +7,4 @@ setTimeout(() => {
resetExampleElem.value = undefined;
})
}
}, 500);
}

0 comments on commit ffe429f

Please sign in to comment.