diff --git a/hub/static/css/_area.scss b/hub/static/css/_area.scss index 15ccaecb5..add7c17b2 100644 --- a/hub/static/css/_area.scss +++ b/hub/static/css/_area.scss @@ -181,3 +181,17 @@ [data-copy-text][data-copied] { animation: 500ms linear success-ping; } + +// Mailing list signup on area page +// TODO: This is super hacky, maybe we should make a component for this? +.row > * + * > .mailing-list-signup { + margin-top: map-get($spacers, 4); + padding-top: map-get($spacers, 4); + border-top: var(--#{$prefix}border-width) var(--#{$prefix}border-style) var(--#{$prefix}border-color); + + @include media-breakpoint-up('lg') { + margin-top: 0; + padding-top: 0; + border-top: none; + } +} \ No newline at end of file diff --git a/hub/static/css/_utilities.scss b/hub/static/css/_utilities.scss index 215c77386..284fc5dbc 100644 --- a/hub/static/css/_utilities.scss +++ b/hub/static/css/_utilities.scss @@ -59,6 +59,22 @@ $utilities: map-merge( ), ), ), + "max-width": map-merge( + map-get($utilities, "max-width"), + ( + values: ( + 50: 50%, + 100: 100%, + 10rem: 10rem, // 160px, 3-6 words + 20rem: 20rem, // 320px, 6-9 words + 30rem: 30rem, // 480px, 9-12 words + 35rem: 35rem, + 40rem: 40rem, // 640px, 12-15 words + 45rem: 45rem, + 50rem: 50rem, + ), + ), + ), "position": map-merge( map-get($utilities, "position"), ( diff --git a/hub/static/js/home.js b/hub/static/js/home.js index 3a0074e04..7283bb177 100644 --- a/hub/static/js/home.js +++ b/hub/static/js/home.js @@ -16,6 +16,28 @@ async function mailingListSignup($form) { return response.json() } +var setUpCollapsableMailingListForm = function() { + var $form = $(this); + var selectors = '.js-mailing-list-name, .js-mailing-list-extras'; + var trigger = '.js-mailing-list-email input#email'; + var instances = []; + + var updateUI = function() { + var emailEntered = $(trigger).val() !== ''; + $.each(instances, function(i, instance){ + emailEntered ? instance.show() : instance.hide(); + }); + }; + + $(selectors, $form).addClass('collapse').each(function(){ + instances.push(new Collapse(this, { toggle: false })); + }); + $(trigger, $form).on('keyup change', function(){ + updateUI(); + }); + updateUI(); +}; + $(function(){ if( 'geolocation' in navigator ) { $('.js-geolocate').removeClass('d-none'); @@ -100,14 +122,16 @@ $(function(){ }); }) - $('#mailing_list_signup').on('submit', function(e){ + $('.js-collapsable-mailing-list-form').each(setUpCollapsableMailingListForm); + + $('.js-mailing-list-signup').on('submit', function(e){ e.preventDefault(); var $form = $(this); $('.invalid-feedback').remove() mailingListSignup($form).then(function(response){ if (response['response'] == 'ok') { - $form.parent().hide() - $('#mailing_list_success').removeClass('d-none') + $form.hide() + $('.js-mailing-list-success').removeClass('d-none') } else { console.log(response) for (var k in response["errors"]) { diff --git a/hub/templates/hub/area.html b/hub/templates/hub/area.html index 294c8afab..1166b5388 100644 --- a/hub/templates/hub/area.html +++ b/hub/templates/hub/area.html @@ -662,18 +662,25 @@
Whether you’ve spotted an error on the site, or you have new data to contribute, or you need help managing your account, or anything else – send an email to localintelligencehub@theclimatecoalition.org, and we’ll direct your message to the right place.