diff --git a/assets/js/main.js b/assets/js/main.js index 206da8ebe5b..a68e241924f 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -1,5 +1,44 @@ $(document).ready(function () { + //////////////////////////////////////// + // Shared helpers + //////////////////////////////////////// + + const trackSubscribeClick = function (event) { + if ( typeof gtag !== 'function' ) { + return; + } + + const subscribe_target = event.currentTarget; + + gtag('event', 'click_subscribe', { + page: window.location.pathname, + place: subscribe_target.dataset.subscribeClick, + }); + }; + + const queueSubscribeModal = function (subscribe_trigger) { + const parent_modal_selector = subscribe_trigger.data('subscribe-parent-modal'); + const subscribe_modal = $('#subscribeModal'); + + if ( !parent_modal_selector || !subscribe_modal.length ) { + return; + } + + const parent_modal = $(parent_modal_selector); + + if ( !parent_modal.length ) { + subscribe_modal.modal('show'); + return; + } + + parent_modal.one('hidden.bs.modal', function () { + subscribe_modal.modal('show'); + }); + + parent_modal.modal('hide'); + }; + //////////////////////////////////////// // Mutation observer - watch for RTL //////////////////////////////////////// @@ -8,9 +47,10 @@ $(document).ready(function () { const observer = new MutationObserver( function(mutations) { mutations.forEach( function() { - var classes = target.getAttribute('class'); - var single_class = 'translated-rtl'; - if (classes.includes(single_class)) { + const classes = target.getAttribute('class') || ''; + const single_class = 'translated-rtl'; + + if ( classes.includes(single_class) ) { target.setAttribute('dir', 'rtl'); } else { target.setAttribute('dir', 'ltr'); @@ -22,7 +62,7 @@ $(document).ready(function () { attributes: true, attributeFilter: ['class'] } - + observer.observe(target, config); //////////////////////////////////////// @@ -61,9 +101,24 @@ $(document).ready(function () { }); //////////////////////////////////////// - // Email Subscription Modal + // Subscribe links and modal //////////////////////////////////////// + const subscribe_triggers = $('[data-subscribe-click]'); + + if ( subscribe_triggers.length ) { + subscribe_triggers.on('click', function (event) { + const subscribe_trigger = $(this); + + trackSubscribeClick(event); + + if ( subscribe_trigger.data('subscribe-parent-modal') ) { + event.preventDefault(); + queueSubscribeModal(subscribe_trigger); + } + }); + } + const subscribe_modal = $('#subscribeModal'); if ( subscribe_modal.length ) { @@ -80,19 +135,23 @@ $(document).ready(function () { const subscribe_iframe = $(' + Open the subscription form diff --git a/content/data-stories/redesign/index.md b/content/data-stories/redesign/index.md index ce70b3b9162..c87076b8b03 100644 --- a/content/data-stories/redesign/index.md +++ b/content/data-stories/redesign/index.md @@ -93,7 +93,7 @@ If you’re curious about the nuts and bolts, you can find out more in our [site We built this site for you, so please help us continue developing it:  -- [Sign up for our email list](https://docs.google.com/forms/d/e/1FAIpQLSfUg3JE5ODNc6aqBPJwM8mZ80TYtK6ISw-OM7PBwKuoN3M--g/viewform?embedded=true) – we'll send occasional requests for users to participate in user testing or co-design work  +- Sign up for our email list – we'll send occasional requests for users to participate in user testing or co-design work  - Visit our Github repositories ([site](https://github.com/nychealth/EH-dataportal), [data](https://github.com/nychealth/EHDP-data)) and explore the code, file an issue, or suggest features  - Email us with any questions you have at ehdp@health.nyc.gov – we're here to help.   diff --git a/themes/dohmh/layouts/data-stories/single.html b/themes/dohmh/layouts/data-stories/single.html index 0d5123d31c3..a4b53d1b3e3 100644 --- a/themes/dohmh/layouts/data-stories/single.html +++ b/themes/dohmh/layouts/data-stories/single.html @@ -62,7 +62,7 @@