diff --git a/apiExamples/toggleDialog.js b/apiExamples/toggleDialog.js index 882d361..41ea1e8 100644 --- a/apiExamples/toggleDialog.js +++ b/apiExamples/toggleDialog.js @@ -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); + } } diff --git a/demo/api.html b/demo/api.html index 15eebd3..e812124 100644 --- a/demo/api.html +++ b/demo/api.html @@ -41,8 +41,10 @@ }); - - + + diff --git a/demo/api.js b/demo/api.js new file mode 100644 index 0000000..fedabe6 --- /dev/null +++ b/demo/api.js @@ -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); + } + } +} diff --git a/demo/api.min.js b/demo/api.min.js new file mode 100644 index 0000000..af0a074 --- /dev/null +++ b/demo/api.min.js @@ -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); + } + } +} + diff --git a/demo/index.html b/demo/index.html index c9869ae..38b3d5f 100644 --- a/demo/index.html +++ b/demo/index.html @@ -41,8 +41,10 @@ }); - - + +