Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement minified js system #11

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apiExamples/toggleDialog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
function toggleDialog(elem) {
let dialog = document.querySelector(elem);
export function toggleDialog(dialogID) {
const dialog = document.querySelector(dialogID);

dialog.hasAttribute('open')
? dialog.removeAttribute("open")
: (dialog.removeAttribute("open"),
dialog.setAttribute("open", true));
if (dialog.hasAttribute('open')) {
dialog.removeAttribute('open');
} else {
dialog.setAttribute('open', true);
}
}
6 changes: 4 additions & 2 deletions demo/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
});
</script>
<script type="module" data-demo-script="true" src="../index.js"></script>

<script src="../apiExamples/toggleDialog.js"></script>
<script src="./api.min.js"></script>
<script>
initDialogApiExamples();
</script>

<!-- If additional elements are needed for the demo, add them here. -->
<script src="https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-accordion@latest/dist/auro-accordion__bundled.js" type="module"></script>
Expand Down
16 changes: 16 additions & 0 deletions demo/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { toggleDialog } from "../apiExamples/toggleDialog";

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

try {
toggleDialog();
} catch (error) {
if (initCount <= 20) {
// setTimeout handles issue where content is sometimes loaded after the functions get called
setTimeout(() => {
initDialogApiExamples(initCount + 1);
}, 100);
}
}
}
25 changes: 25 additions & 0 deletions demo/api.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function toggleDialog(dialogID) {
const dialog = document.querySelector(dialogID);

if (dialog.hasAttribute('open')) {
dialog.removeAttribute('open');
} else {
dialog.setAttribute('open', true);
}
}

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

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

6 changes: 4 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
});
</script>
<script type="module" data-demo-script="true" src="../index.js"></script>

<script src="../apiExamples/toggleDialog.js"></script>
<script src="./index.min.js"></script>
<script>
initDialogIndexExamples();
</script>

<script type="module">
import { registerComponent } from '../index.js';
Expand Down
16 changes: 16 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { toggleDialog } from "../apiExamples/toggleDialog";

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

try {
toggleDialog();
} catch (error) {
if (initCount <= 20) {
// setTimeout handles issue where content is sometimes loaded after the functions get called
setTimeout(() => {
initDialogIndexExamples(initCount + 1);
}, 100);
}
}
}
17 changes: 8 additions & 9 deletions demo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,15 @@ The `<auro-dialog>` component should be used in situations where users may:
Triggering the dialog relies on functions being installed. See the following example code that is installed into this demo.

```javascript
function toggleDialog(elem) {
let dialog = document.querySelector(elem);

dialog.hasAttribute('open')
? dialog.removeAttribute("open")
: (dialog.removeAttribute("open"),
dialog.setAttribute("open", true));
function toggleDialog(dialogID) {
const dialog = document.querySelector(dialogID);

if (dialog.hasAttribute('open')) {
dialog.removeAttribute('open');
} else {
dialog.setAttribute('open', true);
}
}

// This function can be retrieved from https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-dialog@latest/dist/toggleDialog.js
```

Once the JavaScript is added to the scope of the experience, the next part is adding a trigger. In this example, the button component will toggle a dialog with the ID of `#demo1`.
Expand Down
25 changes: 25 additions & 0 deletions demo/index.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function toggleDialog(dialogID) {
const dialog = document.querySelector(dialogID);

if (dialog.hasAttribute('open')) {
dialog.removeAttribute('open');
} else {
dialog.setAttribute('open', true);
}
}

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

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

17 changes: 8 additions & 9 deletions docs/partials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ This file is generated based on a template fetched from `./docs/partials/index.m
Triggering the dialog relies on functions being installed. See the following example code that is installed into this demo.

```javascript
function toggleDialog(elem) {
let dialog = document.querySelector(elem);

dialog.hasAttribute('open')
? dialog.removeAttribute("open")
: (dialog.removeAttribute("open"),
dialog.setAttribute("open", true));
function toggleDialog(dialogID) {
const dialog = document.querySelector(dialogID);

if (dialog.hasAttribute('open')) {
dialog.removeAttribute('open');
} else {
dialog.setAttribute('open', true);
}
}

// This function can be retrieved from https://cdn.jsdelivr.net/npm/@aurodesignsystem/auro-dialog@latest/dist/toggleDialog.js
```

Once the JavaScript is added to the scope of the experience, the next part is adding a trigger. In this example, the button component will toggle a dialog with the ID of `#demo1`.
Expand Down
Loading