Skip to content

Instantly share code, notes, and snippets.

@salsalabs
salsalabs / set_dropdown_default.html
Created August 28, 2019 14:44
Script to set the default value for a <select> (dropdown). The script contains a field name and an option name for a Salsa client.
<script type="javascript">
//Script to look for a specific value in a <select> (dropdown). If found
//then make it the default.
document.addEventListener(function() {
var e = document.querySelector('select[name="auswahl_spendenzweck"]');
if (e != null) {
var option = e.querySelector('option[value="Da wo es am nötigsten ist"]');
if (option != null) {
option.selected = true;
}
@salsalabs
salsalabs / hide_fed_country_muni.html
Created May 1, 2019 22:38
Hide federal, country and municipal legislators in the legislative_lookup.
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
if (window.location.href.indexOf('getLocal4.jsp') != -1) {
var a = Array.from(document.querySelectorAll('div[id^=officials]'))
a = a.filter(function(e) {
return /officials_S/.test(e.id) ? false : true;
})
a.forEach(function(e) {
e.style.display = 'none';
//Hide two trailing <br> tags.
@salsalabs
salsalabs / flat_10_dollar_shipping.html
Created May 1, 2019 21:21
Script to add a flat $10.00 shipping and handling to a storefront checkout if the merchandise total is $50 or less.
<script type="text/javascript">
$(document).ready(function() {
var shippingAndHandling = 10.00;
if (window.location.href.indexOf('/shop/checkOut.jsp') != -1) {
var s = $('input[name=sub]').val();
s = parseFloat(s);
if (s < 50.00) {
var t = s + shippingAndHandling;
$('input[name=shipping]').val(shippingAndHandling.toFixed(2));
$('input[name=amount]').val(t.toFixed(2));
@salsalabs
salsalabs / default_receive_email_to_unsubscribed.html
Created March 26, 2019 16:47
Script to set the default value of a Receive_Email field in a Classic form to -3. All other fields named "Receive_Email" are removed to avoid confusion.
<!-- BEGIN Default Receive_Email to unsubscribed. -->
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function () {
// Remove hard-coded Receive_Email hidden inputs. That will leave the
// Receive_Email dropdown that the user can see.
var a = document.querySelectorAll('input[name=Receive_Email]');
a.forEach(function(e) {
e.parentNode.removeChild(e);
});
// Set the default value for the Receive Email dropdown.
@salsalabs
salsalabs / action_invalid_address_highlight.html
Created February 20, 2019 20:38
CSS to highlight the "invalid address" message in targeted actions.
<!-- SalsaStaff 273659: BEGIN highlight for the address error in a targeted action. -->
<style type="text/css">
#notEnoughData {
padding-bottom: 20px;
color: red;
}
</style>
<!-- SalsaStaff 273659: END highlight for the address error in a targeted action. -->
@salsalabs
salsalabs / custom_column_option_values.sql
Created January 18, 2019 19:13
Query to retrieve custom column option values. Useful for creating cusotm fields in Engage when importing form Classic.
select cc.label, cc.type, cco.value
from custom_column cc
left outer join custom_column_option cco
on cco.custom_column_KEY = cc.custom_column_KEY
where cc.organization_KEY = 51035
and cco.organization_KEY = 51035
order by cc.label, cco.value;
@salsalabs
salsalabs / redirect_non-secure_signup_pages.html
Created January 10, 2019 20:01
Script to redirect non-secure signup page URLs to the secure version. Install this script just after the <head> tag in your template(s).
<!-- BEGIN redirect non-secure signup pages to secure URLs. -->
<script type="text/javascript">
if (window.location.href.indexOf('signup?signup_page_KEY=') != -1) {
if (window.location.protocol == 'http:') {
window.location.protocol = 'https:';
}
}
</script>
<!-- END redirect non-secure signup pages to secure URLs. -->
@salsalabs
salsalabs / blast_archive_titles.html
Created January 4, 2019 00:34
Script to change the labels at the top of the email blast archive. Text is for a specific client. Feel free to change it as necessary after it's installed.
<!-- SalsaStaff 267704: BEGIN script to modify titles on the email blast archive. -->
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
if (window.location.href.indexOf("blastContent.jsp") != -1) {
document.querySelector('#selectBlastSpan').innerHTML = "View a past newsletter: ";
document.querySelector('a[href$="email/public/rss"]:nth-child(2)').innerHTML = "Subscribe to the APFED Newsletter feed.";
}
})
</script>
<!-- SalsaStaff 267704: END script to modify titles on the email blast archive. -->
<!-- BEGIN script to remove commas from the "other" amount field on a donation page. -->
<script type="text/javascript">
$(document).ready(function() {
var e = $('form[name="subform"]');
if (e.length != 0) {
e.submit(function() {
var v = $('input[name="amountOther"]')
if (v.length != 0) {
v.val(v.val().replace(/,/g, ''));
}
@salsalabs
salsalabs / donation_oter_amount_no_commas.html
Created January 3, 2019 22:07
Remove commas from the "other" amount field.
<!-- BEGIN script to remove commas from the "other" amount field on a donation page. ==>
<script type="text/javascript">
$(document).ready(function() {
var e = $('form[name="subform"]');
if (e.length != 0) {
e.submit(function() {
var v = $('input[name="amountOther"]')
if (v.length != 0) {
v.val(v.val().replace(/,/g, ''));
}