Skip to content

Instantly share code, notes, and snippets.

@salsalabs
salsalabs / groups_and_hidden_custom_fields.html
Last active August 26, 2015 22:51
Script and configuration that allows custom fields to be placed below an optional group. If the optional group is checked, then the fields appear. If an optional group is unchecked, then the groups disappear.
<script type="text/javascript">
$(document).ready(function() {
var groupMap = {};
// Click handler for a group checkbox. Hides or or shows the
// associated custom fields.
function groupClickHandler() {
if ($(this).is(':checked')) {
$('.option_box', $(this).parent()).css('display', 'block');
@salsalabs
salsalabs / embed_petition_signup.html
Last active August 29, 2015 13:56
Lines that make a signup page sign a petition.
<!-- Add these two lines to your form if you want a supporter to sign
the petition with action_KEY 12345. -->
<input type="hidden" name="link" value="action"/>
<input type="hidden" name="linkKey" value="12345"/>
@salsalabs
salsalabs / create_an_empty_template.html
Last active August 29, 2015 14:01
Create an empty template
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<!-- TemplateBeginEditable name="content" -->
<h1>Page content goes here...</h1>
<!-- TemplateEndEditable -->
</body>
@salsalabs
salsalabs / picklists_as_radio_buttons.html
Created May 5, 2014 16:49
Convert a Salsa picklist from a dropdown to a list of radio buttons
<script type="text/javascript">
/*
* Script to convert a picklist <select> tag into a series of radio buttons.
*/
$(document).ready(function () {
var name = "tee_shirt_size";
var select = $('select[name="' + name + '"]');
if (select.length == 1) {
var id = select.attr('id');
var style = select.attr('class');
@salsalabs
salsalabs / hide_target_email_addresses.html
Last active August 29, 2015 14:01
Hide the email addresses on the letter page of an action. Updated to handle blind targeted actions and confirmation pages.
<script type="text/javascript">
// See https://help.salsalabs.com/entries/22876904-Hide-email-addresses-on-targeted-actions
$(document).ready(function() {
if (RegExp('action_KEY=NNNNN').test(window.location.href)) {
var checkExist = null;
var recipientChecker = function() {
if ($('.recipient').length > 0) {
$('.recipient .number').each(function() {
var x = $(this).html();
x = x.replace(RegExp('Email.+?</span>'), '');
@salsalabs
salsalabs / action_change_letter_label.html
Created May 7, 2014 15:04
Change the lable for the letter field in Salsa actions
<script type="text/javascript">
// See https://help.salsalabs.com/entries/22876904-Hide-email-addresses-on-targeted-actions
$(document).ready(function() {
if (RegExp('action_KEY=NNNNN').test(window.location.href)) {
var checkExist = null;
var recipientChecker = function() {
if ($('.recipient').length) {
clearInterval(checkExist);
$('label[for^=Content]').text("YOUR REPLACEMENT HERE");
}
@salsalabs
salsalabs / hide_view_respondents.html
Last active August 29, 2015 14:01
HIde "View Respondents" on distributed event
<script type="text/javascript">
// See https://help.salsalabs.com/entries/37087850-Hide-View-Respondents-on-distributed-event-page
$(document).ready(function() {
$('a[href*="profile/host.jsp?event_KEY="]').hide()
});
</script>
@salsalabs
salsalabs / validate_us_phone_number.html
Last active August 29, 2015 14:01
Validate at US phone number input field
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// FIELD_NAME can be Phone, Cell_Phone or the API name of a custom supporter field.
$('input[name=FIELD_NAME]').blur(function() {
if (!RegExp('\\d{3}-\\d{3}-\\d{4}').test($(this).val())) {
alert('Please provide a phone number like NNN-NNN-NNNN.');
return false;
}
return true;
@salsalabs
salsalabs / change_in_memory_of.html
Created May 8, 2014 16:35
Change the content and CSS ID of the "in memory of" prompt.
<!-- Style and script to change the contents of the "in memory of" message
on a Salsa donation page. See (SalsaCommons link here.) -->
<style type="text/css">
#was-in-memory-of {
padding-top: 20px;
font-size: 12pt;
color: red;
}
</style>
<script type="text/javascript">
@salsalabs
salsalabs / q_answers_from_url.html
Last active August 29, 2015 14:01
Clicks answers in a questionnaire based on queries in the URL.
<script type="text/javascript">
$(document).ready(function () {
// SalsaStaff 88363: Click options in the checkbox/radio button
// questions based on queries passed in the URL. The general form of
// a query is `&Qm=n`, where `m` is the question number and `n` is
// the answer number. Both `m` and `n` are cardinal integers.
//
// @note This GIST contains guard logic to work on a single questoinnaire
// because the script must go into a template.
//