- Home
'); Visualforce.remoting.Manager.invokeAction( 'kwac.KWAC_TakeActionCampaignDisplayController.getCampaignList', sState, function(result, event){ if (event.status) { if (sStateName === 'all states') sStateName = 'national'; if (sStateName === 'new york' ) sStateName = 'atlantic'; if (sStateName === 'kentucky' ) sStateName = 'cumberland'; if (sStateName === 'indiana' ) sStateName = 'hoosier'; if (sStateName === 'new mexico' ) sStateName = 'riogrande'; var currentactionurl = sStateName; if (sStateName === '' || sStateName === 'select state') { currentactionurl = document.location.href.toLowerCase().match(/.*\/actions\/([-a-zA-Z]+)[\/]?.*/); if (currentactionurl === null || currentactionurl.length === 0) currentactionurl = "national"; else currentactionurl = currentactionurl[1]; if (currentactionurl === "list") currentactionurl = "national"; } currentactionurl = currentactionurl.replace(' ',''); j$( "#CampaignList" ).empty(); kwSierraClub.actions = event.result; var currentPlace = 0; kwSierraClub.actionsTotal = kwSierraClub.actions.length; j$.each( event.result, function(index, value) { var urlToShare = value.kwac__URL_to_Share__c.toLowerCase(); var actionurl = urlToShare.match(/.*\/actions\/([-a-zA-Z]+)[\/]?.*/); if (actionurl === null || actionurl.length === 0) actionurl = ""; else actionurl = actionurl[1]; //console.log(value) var todaysDate = new Date().getTime(); var expireyDate = (typeof(value.EndDate) != "undefined" && value.EndDate !== "") ? value.EndDate : todaysDate; /* don't list test things or things in test mode */ if (actionurl === currentactionurl && todaysDate <= expireyDate && !value.kwac__Test_Mode__c) { if (location.host !== 'act.sierraclub.org' && urlToShare.indexOf('act.sierraclub.org') > -1) { urlToShare = urlToShare.replace('act.sierraclub.org', location.host); } var imageUrl = (typeof(value.Sharing_Image__c) != "undefined" && value.Sharing_Image__c !== "") ? value.Sharing_Image__c : default_image; imageUrl = imageUrl.replace('http://', 'https://'); var rex = /(<([^>]+)>)/ig; var backup = (typeof(value.kwac__Call_to_Action_Text__c) != "undefined" && value.kwac__Call_to_Action_Text__c!== "") ? value.kwac__Call_to_Action_Text__c.replace(rex,"").substring(0,250) + "..." : ''; var desc = (typeof(value.Sharing_Description__c) != "undefined" && value.Sharing_Description__c !== "") ? value.Sharing_Description__c: backup; var j$newdiv1 = j$("
" + value.kwac__Tagline__c + "
" + desc + "
Take Action
"); j$( "#CampaignList" ).append( j$newdiv1); currentPlace++; } else { // make sure total walked down for items that are not to be listed. // items that might be in the same state, but served under a different // template. kwSierraClub.actionsTotal--; } // only display as many items as we have in kwSierraClub.actionsPaging if (currentPlace === kwSierraClub.actionsPaging - 1 ) { // we would also want to set up simple pagination here... return false; } }); if (j$( "#CampaignList" ).html() === '') { j$( "#CampaignList" ).html('
No actions were found. Take other actions.
'); } } }, {escape: false} ); } j$( document ).ready(function() { if (typeof kwacState == "undefined") kwacState = ''; // console.log("knowwho campaign list ready"); // getCampaignList('', ''); j$(".statefilter").val(kwacState) j$(".statefilter option[value='-']").remove(); j$(".statefilter").change(function(){ getCampaignList(j$(".statefilter option:selected").val(), j$(".statefilter option:selected").text().toLowerCase()); }); getCampaignList(j$(".statefilter option:selected").val(), j$(".statefilter option:selected").text().toLowerCase()); });
'; $('.form-steps__step--two').prepend(resetForm); showMessageSection(); // could maybe? render kwac__Docket_Number__c here if we defined a function for it // Make sure we see the whole second step. window.jQuery('html, body').animate({ scrollTop: window.jQuery('.js-form-step:eq(1)').offset().top - 62 }, 250); $('.js-form-steps-progress li:eq(0)').addClass('complete'); $('.js-form-steps-progress li:eq(1)').addClass('active'); // ensure communications disclaimer text renders on step 2 // $step2.append($('#step-2-general-comms-disclaimer')); //$('#step-2-general-comms-disclaimer').insertBefore($('#actionbutton2 input[type="submit"]')); $('#general-comms-disclaimer').show(); } } // not sure why I need to define jQuery here, throws error otherwise var $ = jQuery; var $form = $(escapeSelector('#j_id0:j_id56:j_id57:action')), formNode = $form.get(0), $nextButton = $('.js-form-step-next'), $submitButton = $(escapeSelector('#j_id0:j_id56:j_id57:action:refreshbutton3')),// Form step 1. $step1 = $('.js-form-step:eq(0)'),// Reverse order matters. step1Fields = ['#ciPhone', '#adZip', '#ciEmail', '#nmLastname', '#nmFirstname'],// Form step 2. $step2 = $('.js-form-step:eq(1)'), step2Fields = ['#adState', '#adCity', '#adAddress1', '#nmSaluation']; if (formNode) { // Disable HTML5 validation popups formNode.addEventListener("invalid", function (event) { event.preventDefault(); }, true); // Prevent invalid form submission formNode.addEventListener("submit", function (event) { // Attempting form submit if (!this.checkValidity()) { // Form submit prevented event.preventDefault(); } }); $form.delegate(':input', 'input change invalid', validateInput); } // Move step 1 fields to step 1 div. for (var i = 0; i < step1Fields.length; i++) { var $field = $(step1Fields[i]); $step1.prepend($field); $field.find('input, select').first().attr('tabindex', 0); } // Manipulate next button tabIndex too. $nextButton.attr('tabIndex', 0); $nextButton.bind('keydown', function (e) { // Tab past the form. if (e.which === 9) { e.preventDefault(); $('#footer a:first').focus(); } // Enter on the CTA will try to submit step 1. else if (e.which === 13) { e.preventDefault(); nextStep(); } }); $('.form-steps input').bind('keydown', function (e) { if (e.which === 13) { e.preventDefault(); nextStep(); } }); // Move step2 fields to step 2 div. for (var _i = 0; _i < step2Fields.length; _i++) { var _$field = $(step2Fields[_i]); $step2.prepend(_$field); _$field.find('input, select').first().attr('tabindex', 0); } // If no visible fields in step two, render as single step action // if it has title, address, city or state, it is multistep. if ( hasTitle || hasAddress || hasCity || hasState ) { // Plug #MessagetoOfficials div & custom questions into the second step. $('body').addClass('multi-step'); //$('.form-steps__step--one #step-1-general-comms-disclaimer').hide(); $step2.append($('
')); $step2.append($('#MessagetoOfficials')); $step2.append($('.custom-questions-header')); $step2.append($('.custom-questions')); var submitBtnText = $('#actionbutton2 input[type="submit"]').val(); //if ($('.form-steps__step--one .small[data-lang="en"]').length > 0) { // var multiStepDisclaimer = $('#step-1-general-comms-disclaimer').html().replace('continue', submitBtnText); // $('#step-2-general-comms-disclaimer').html(multiStepDisclaimer); //} // $step2.append($('#step-2-general-comms-disclaimer')); // step 2 disclaimer will be unhidden in nextStep() //$('#step-2-general-comms-disclaimer').hide(); $step2.append($('#actionbutton2').closest('div.row')); $('#general-comms-disclaimer').hide(); //$('#step-2-general-comms-disclaimer').insertAfter($('#actionbutton2 input[type="submit"]').last()); } else { // hide continue button, adjust disclaimer text and render message section $('body').addClass('single-step'); $('.js-form-steps-progress').html('
'); $('.form-steps__actions a.js-form-step-next').hide(); var submitBtnText = $('#actionbutton2 input[type="submit"]').val(); //if ($('.form-steps__step--one .small[data-lang="en"]').length > 0) { // var oneStepDisclaimer = $('.form-steps__step--one .small').html().replace('continue', submitBtnText); // $('.form-steps__step--one .small').html(oneStepDisclaimer); //} //$('#step-1-general-comms-disclaimer').insertBefore($('#actionbutton2 input[type="submit"]').last()); //$('#step-2-general-comms-disclaimer').hide(); showMessageSection(); $('#general-comms-disclaimer').show(); // also could render kwac__Docket_Number__c if it has its own function defined } // On step 1 CTA click, try to move to step 2; but validate first. $nextButton.bind('click touch', function () { // Sanitize form data from any HTML tags. $('input.form-control, textarea.form-control').each(function(elem) { $(this).val($(this).val().replace(/(<([^>]+)>)/gi, "")); }) nextStep(); }); // Step 2 CTA - validate step 2 on click. $submitButton.bind('click touch', function () { $step2.find(':input').each(validateInput); }); // Move to Step 2 when data pre-populated, add reset form link, // unhide everything since re-rendering of page should be complete by now $(document).ready(function() { if(!false) { if($('#nmFirstname input').val() !== '' && $('#nmLastname input').val() !== '' && $('#ciEmail input').val() !== '' && $('#adZip input').val() !== '' && $('#ciPhone input').val() !== '') { // set reset form link for both sf data token and mobile commons url params var cleanUrl = getCleanUrl(); if (window.location.href.indexOf('&city=') > -1) { cleanUrl = window.location.href.substr(0, window.location.href.indexOf('&city=')); } var firstName = DOMPurify.sanitize($('#nmFirstname input').val()); var lastName = DOMPurify.sanitize($('#nmLastname input').val()); var email = DOMPurify.sanitize($('#ciEmail input').val()); var zip = DOMPurify.sanitize($('#adZip input').val()); // var resetForm = '
Not ' + firstName + ' ' + lastName + ' email: ' + email + ' zip: ' + zip + '? Reset form.
'; // var resetForm = '
Not ' + firstName + ' ' + lastName + '? Reset form.
'; var resetForm = '
' + firstName + ' ' + lastName + ' | ' + scTextGlobal['Email'].en + ': ' + email + ' | ' + scTextGlobal['Zip'].en + ': ' + zip + '
' + scTextKnowWho['Details not correct? Reset form.'].en + '
'; // var resetForm = '
' + firstName + ' ' + lastName + ' | email: ' + email + ' | zip: ' + zip + '
Not ' + firstName + ' ' + lastName + '? Reset form.
'; $('.form-steps__step--two').prepend(resetForm); // $('.form-progress__li').addClass('active'); $('.form-steps__step--one').removeClass('active'); $('.form-steps__step--one').addClass('complete'); $('.form-steps__step--two').addClass('active'); $('#actionbutton2 input').focus(); $('.js-form-steps-progress').html('
'); showMessageSection(); //$('#phone-disclaimer').hide(); $('#general-comms-disclaimer').show(); } else if ( ($('.form-steps__step--two input').length === 5) && ($('.form-control.phone').length === 1) && ($('.form-control.phone').val() !== '') ) { // if phone the only field in step 2, move to step 1 and update disclaimer and button text //var disclaimerStr = $('.form-steps__step--one .small[data-lang="en"]').text(); //if (disclaimerStr.length) { // disclaimerStr = disclaimerStr.replace('continue', $('#actionbutton2 input').val()); // $('.form-steps__step--one .small').html(disclaimerStr); //} movePhoneToStep1(); $('.js-form-steps-progress').html('
'); $('.form-steps__step--one .form-steps__actions').hide(); $('.form-steps__step--one').append($('#actionbutton2').parent().parent()); $('#actionbutton2').css('width', '100%'); showMessageSection(); } else if ($('.form-control.phone').length == 1) { movePhoneToStep1(); } } // unhide everything $('#main-wrapper').removeClass('hidden'); }); // Zipcode autofill function getCityState(addressObj) { var ret = {}; //Loop over the provided values because the API returns varying amounts of info in varying order. for (var v in addressObj) { var component = addressObj[v]; if (component.types[0] === "administrative_area_level_1") { //State ret['state'] = component.short_name; } else if (component.types[0] === "locality") { //City ret['city'] = component.long_name; } } return ret; } var $steps = $('.form-steps'), $zip = $steps.find('.form-control.zipcode'), $city = $steps.find('.form-control.city'), $state = $steps.find('.form-control.state'); $zip.change(function () { var zip = $zip.val(); $.get('https://maps.googleapis.com/maps/api/geocode/json?address=' + zip + '&sensor=true', function (data) { if (data.status === 'OK') { try { var values = getCityState(data.results[0].address_components); $city.val(values.city); $state.val(values.state); console.log('city:', values.city, 'state:', values.state, data.results[0].address_components); dataLayer.push({'zipCode': zip}); } catch (e) {} } }); }); // Zipcode autofill ends // CRO Test: SC-851 // This is scrolls the screen down to a specified target element with additional compensation for the offset of the header. function skipToForm(target) { const targetElement = document.querySelector(target); if (!targetElement) { console.error('skipToForm: Unable to find target element.'); return; } const headerHeight = document.querySelector('header').clientHeight; const scrollPoint = targetElement.getBoundingClientRect().top + window.scrollY - headerHeight; window.scrollTo({top: scrollPoint, behavior: 'smooth'}); }