Skip to content

Instantly share code, notes, and snippets.

@salsalabs
salsalabs / change_states_for_country.html
Last active November 9, 2022 19:22
Javascript to change the list of states when a country changes
<script type="text/javascript">
// Workaround to change the value of `State` select options from `CC+XX` to the
// state name. Bogus values will not show up in supporter records -- A Good Thing.
//
// @note The Salsa-provided `change` event handler is unbound by this code. It's
// the one that plants bogus values in the `State` select options, and doesn't
// need to run. To make this happen correctly, this script must appear *just before*
// the </body> tag in your template.
//
// @see https://help.salsalabs.com/entries/23796550
@salsalabs
salsalabs / fill_personal_info.html
Last active July 27, 2021 15:33
Provide a way to fill the personal information into a page based on the type of page.
<!-- BEGIN solution to autofill supporter information on most Salsa pages. -->
<?
// Server-side script to build an object containing the supporter fields to use
// on this page. The supporter key is retrieved from the "&k=" URL query.
// Nothing will appear if there is not a supporter_KEY or if the page key is not
// one that's supported by this solution.
// Caution! This script does not yet handle pages with short URLs.
var data = {};
var pageType = 'unknown';
var supporter_KEY = null;
@salsalabs
salsalabs / expiration_date_year_fix.html
Last active April 30, 2021 15:07
Script to change credit card expiration dates so that they start from the current year. This can be useful on Salsa storefronts.
<!-- BEGIN Change credit card expiration date year to start with the current year. -->
$(document).ready(() => {
const years = 20;
var e = $('select[name=ccExpYear]');
if (e.length == 0) {
return;
}
$('option', e).remove();
e.append('<option value="">Year</option>')
var thisYear = new Date().getFullYear();
@salsalabs
salsalabs / delete_email_archive_rss.html
Last active March 12, 2021 20:38
Script to delete the RSS feed links on the Salsa email blast archive.
<script type="text/javascript">
// Remove the RSS subscribe on the email blast archive.
// The client doesn't want it, and the image has a non-secure URL.
document.addEventListener("DOMContentLoaded", () => {
if (window.location.href.indexOf("blastContent.jsp") != -1) {
var e = document.querySelector('a[href$="/rss"]');
if (e != null) {
e.parentNode.remove();
}
}
@salsalabs
salsalabs / README.markdown
Last active March 12, 2021 19:20
Wait for an element to appear then modify it. This is the best method to wait for a field to appear in targeted actions and multi-content targeted actions.

Wait for an element and modify it

Background

From time to time, Salsa Classic clients want to change an element on a page. That's a snap when the element already appears on the page. However, fields that appear in targeted advocacy actions may not appear on the first displayed page.

Targeted advocacy actions in Salsa Classic are executed as a series of pages. The pages are loaded into the same HTML page using AJAX. The general flow of pages is

  1. Gather address and zip.
  2. Provide personal information and custimize the letter to the target(s).
@salsalabs
salsalabs / LTE_paper_urls_to_links.html
Created March 11, 2021 20:10
Change newspaper URLs to links in the LTE paper selection grid. Makes it *much* easier to use.
@salsalabs
salsalabs / hide_optional_groups.html
Last active March 8, 2021 23:12
Hide optional groups when no optional groups are selected.
<!-- BEGIN script to hide optional groups prompt when there are no optional groups. -->
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", () => {
var e = document.querySelector("#salsa-optional-groups-header")
if (e != null) {
var f = document.querySelectorAll("li.salsa-optional-group")
if (f.length == 0) {
e.style.display = "None"
}
}
@salsalabs
salsalabs / fix_iho_imo.html
Last active February 23, 2021 18:14
Clean up In Honor Of and In Memory Of to make them legible and have the same style as the rest of the donation page.
<!-- BEGIN Clean up In Honor Of and in Memory Of fields on donation pages. -->
<!-- See: https://gist.github.com/salsalabs/120d0cd6b476242bf7d7cd79ddbacd8e -->
<style type="text/css">
/* Force label to appear before In_Honor_Address. */
label[for=In_Honor_Address],
*[name=In_Honor_Address] {
float: left;
}
/* SalsaStaff 386297: Make the "In Memory Of" prompt easier to read. */
#honorof > p:nth-child(6) {
@salsalabs
salsalabs / move-content-after-submit.html
Created December 14, 2020 22:22
Put "content after submit button" after the submit button in a client signup page.
<!-- SalsaStaff 373827: BEGIN Position privacy statement below submit button. -->
<div class="formRow" id="post-submit">
Roots Action considers your contact information to be private and confidential. We will NOT disclose it to any other
entity unless you specifically authorize us to do so. You can read our privacy policy in its entirety
<a href="http://www.rootsaction.org/privacy-policy"> here</a>.
</div>
<script type="text/javascript">
$(document).ready(() => {
var diaFields = $('input[name=Email]').parent().parent();
var submit = $('#submitSignup');
@salsalabs
salsalabs / age_group_checkbox.html
Created November 16, 2020 22:19
Provide a age group box for a client. The age group box is a <select> with a series of checkboxes inside.
<!-- BEGIN SalsaStaff 366219: Put a fieldset containing "nn-nn years old" optional groups after the Organization field in a
Salsa Classic form. The optional groups are all of subgroups to the "Age Groups" group.
The age group box will apppear on any page that has
1. "An Organization" field.
2. This special html.
<div style="display: none;" id="show-age-group-box"></div>