From 1481d8e07c3239b1506213bb45b836a6ec8fc16a Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Tue, 17 Jul 2018 19:17:41 -0600 Subject: [PATCH 1/2] Adds `refresh` method to re-fetch `[data-modal]` See #6 for more information. I know this isn't the best solution, but I'm not a great JS developer. Another alternative would be to add something like this: ``` /** * @param {Element} item */ ARIAmodal.addModal = function ( item ) { modal.push( item ); }; ``` and then refactor `setupModal` so it runs only on one modal at a time, then add a new `setupModals` method that would loop through all the items in the `modal` array and run `setupModal` on them. Again, I'm not great at JS. Thank you for the script, and please let me know if I can help with the PR. --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index fec8292..a1f138f 100644 --- a/index.js +++ b/index.js @@ -704,7 +704,17 @@ } }; + + /** + * If modals are being added to the DOM dynamically, redefine the modal variable + * and initialize again. + */ + ARIAmodal.refresh = function () { + modal = doc.querySelectorAll('[data-modal]'); + ARIAmodal.init(); + }; + /** * Initialize modal functions. * If expanding this script, put From d76289ba2b57b47856883cbd28496f8ba1a79e0c Mon Sep 17 00:00:00 2001 From: Zack Katz Date: Tue, 17 Jul 2018 19:25:03 -0600 Subject: [PATCH 2/2] Refresh the children as well --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index a1f138f..7d9639c 100644 --- a/index.js +++ b/index.js @@ -711,6 +711,7 @@ */ ARIAmodal.refresh = function () { modal = doc.querySelectorAll('[data-modal]'); + children = doc.querySelectorAll('body > *:not([data-modal])'); ARIAmodal.init(); };