From e2cf27cf599f46402d28085fdb8d0bacae76d32b Mon Sep 17 00:00:00 2001 From: Jurie-Jan Botha Date: Sat, 14 Feb 2015 13:54:19 +0200 Subject: Specify modal selector in data attribute with backward compatibility. --- docs/components.html | 8 +++++--- js/modals.js | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/docs/components.html b/docs/components.html index 476ddc1..b8d3edb 100644 --- a/docs/components.html +++ b/docs/components.html @@ -1107,7 +1107,7 @@ document

Modals

- Open modal + Open modal
+

Modals are designed to only fire from links. Set the value of the toggle link's data-modal attribute to a selector that will produce the desired modal.

+ {% highlight html %} -Open modal +Open modal {% endhighlight %} -

Modals are designed to only fire from links. Set the value of the toggle links href to the id of a modal.

+

DEPRECATED: Alternatively you can specify the selector of the desired modal in the href attribute of the link. This will fail without a warning if a modal is not found.

diff --git a/js/modals.js b/js/modals.js index 21bc112..92abf97 100644 --- a/js/modals.js +++ b/js/modals.js @@ -32,8 +32,21 @@ var getModal = function (event) { var modalToggle = findModals(event.target); - if (modalToggle && modalToggle.hash) { - return document.querySelector(modalToggle.hash); + if (modalToggle) { + var modalSelector = modalToggle.getAttribute('data-modal'); + if (modalSelector) { + return document.querySelector(modalSelector); + } + else if (modalToggle.hash) { + try { + return document.querySelector(modalToggle.hash); + } + catch (error) { + if (error.name !== 'SyntaxError') { + throw error; + } + } + } } }; -- cgit v1.2.3