├── max-number-of-characters-in-target-block.html ├── other-donation-do-not-allow-currency-or-spaces.html ├── email-address-do-not-allow-spaces.html ├── pre-tick-and-hide-opt-in.html ├── field-masks.html ├── direct-debits-next-month-20th.html ├── validation-errors-group-into-one-place.html ├── locale-save.html ├── change-error-text-for-a-single-field.html ├── update-field-with-another-field's-value.html ├── tls-checker.html ├── disable-submit-until-target-message-keypress.html ├── placeholders.html ├── phone-mobile-number-hidden-email-address.html ├── opt-in-text-toggle.html ├── textarea-characters-remaining.html ├── currency-symbol-next-suggested-gift.js ├── ett-target-block-show-target-party.js ├── anonymous-random-email-address.html ├── display-recent-responses-to-questions.md ├── share-by-email-button.md ├── reference-and-target-data-in-a-text-block.md ├── progress-through-campaign-pages.md ├── direct-debits-next-two-possible-dates.html ├── account-number-sort-code-verify.md ├── whatsapp-legacy.html ├── searchable-selects.md ├── insert-today's-date.js ├── ETT-select-random-target-from-custom-database.md ├── direct-debits-next-two-possible-dates-v2.html ├── accessible-custom-checkboxes.css ├── floating-button-scroll.md ├── gift-aid-calculation.md ├── show-MP-name-on-data-capture.md ├── read-more-expand.md ├── Insert contact data on page 1.html ├── direct-debits-Stripe-start-date-population.html ├── shopping-list-money-buys.md └── README.md /max-number-of-characters-in-target-block.html: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /other-donation-do-not-allow-currency-or-spaces.html: -------------------------------------------------------------------------------- 1 | // requires jQuery 2 | $(function() { 3 | $("input[name='transaction.donationAmt.other']").bind({ 4 | keydown: function(e) { 5 | // prevent £, $ and space from being typed 6 | if (e.keyCode==51||e.keyCode==52||e.keyCode==32) { 7 | return false; 8 | } 9 | return true; 10 | } 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /email-address-do-not-allow-spaces.html: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /pre-tick-and-hide-opt-in.html: -------------------------------------------------------------------------------- 1 | 11 | -------------------------------------------------------------------------------- /field-masks.html: -------------------------------------------------------------------------------- 1 | 2 | 11 | -------------------------------------------------------------------------------- /direct-debits-next-month-20th.html: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /validation-errors-group-into-one-place.html: -------------------------------------------------------------------------------- 1 |
2 | 15 | -------------------------------------------------------------------------------- /locale-save.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 15 | -------------------------------------------------------------------------------- /change-error-text-for-a-single-field.html: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /update-field-with-another-field's-value.html: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /tls-checker.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | -------------------------------------------------------------------------------- /disable-submit-until-target-message-keypress.html: -------------------------------------------------------------------------------- 1 | 12 | 24 | -------------------------------------------------------------------------------- /placeholders.html: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /phone-mobile-number-hidden-email-address.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11 | 18 | -------------------------------------------------------------------------------- /opt-in-text-toggle.html: -------------------------------------------------------------------------------- 1 | 2 | 20 | -------------------------------------------------------------------------------- /textarea-characters-remaining.html: -------------------------------------------------------------------------------- 1 | 25 | -------------------------------------------------------------------------------- /currency-symbol-next-suggested-gift.js: -------------------------------------------------------------------------------- 1 | // NOTE: this requires the jQuery library 2 | // The Next Suggested Gift can change the radio donation amounts on a donation page 3 | // But it loses the currency symbol. This code adds the currency symbol (set as £ in this example) 4 | // to the amount label, if the first character is a number (e.g. "10" becomes "£10" but "£20" or "Other" stays the same) 5 | // setTimeout is needed to ensure this code runs after the NSG has done what it needs to do 6 | 27 | -------------------------------------------------------------------------------- /ett-target-block-show-target-party.js: -------------------------------------------------------------------------------- 1 | // Grab political party / other data from biography and insert it after the last name of the contact 2 | // For this to work, you need to insert the party as a field insert into the target block's biography tab 3 | $(document).ready(function(){ 4 | // Hide the biography tab 5 | $('.en__contact--open .en__contactDetails__background, .en__contacts--singleMessageMode .en__contactDetails__background').css("display", "none"); // one message to all contacts - update if individual msgs 6 | // Insert party 7 | $('.en__contacts').children('.en__contact').each(function () { 8 | var contactId = this.getAttribute('data-contact'); 9 | contactId = String(contactId); 10 | var temp = ".en__contact--"+contactId; 11 | var selector = temp + " .en__contactBackground__text"; 12 | 13 | var contactParty = $(selector).text(); 14 | contactParty = contactParty.replace(" ", ""); // strip extra spaces 15 | 16 | $(temp + ' .en__contactDetail--lastName').append('-'+contactParty+''); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /anonymous-random-email-address.html: -------------------------------------------------------------------------------- 1 | 24 | -------------------------------------------------------------------------------- /display-recent-responses-to-questions.md: -------------------------------------------------------------------------------- 1 | You can use our public API call to retrieve, and display, responses to a question directly on the page. 2 | 3 | To do this, you need to add a Code Block, with code similar to the below. Note that you'll need to get your own Public Token for the token variable, and to place in your own questionId. The questionId can be retrieved by following the instructions at the bottom of https://engagingnetworks.support/knowledge-base/public-data-services-using-a-token 4 | 5 | ```html 6 |
7 | 32 | ``` 33 | -------------------------------------------------------------------------------- /share-by-email-button.md: -------------------------------------------------------------------------------- 1 | # Add a share by email button to the simple social buttons 2 | 3 | The social share channels available are Facebook, Twitter, LinkedIn and WhatsApp. But what if you wanted to add another option to share by email here? 4 | 5 | If you add this code to the bottom of the page, below the social buttons then it'll do this for you. Adjust the settings for the email variables for your own content: 6 | 7 | Remember to add to the code if you have not already loaded the jQuery library 8 | 9 | ```html 10 | 26 | -------------------------------------------------------------------------------- /reference-and-target-data-in-a-text-block.md: -------------------------------------------------------------------------------- 1 | Reference data and target data (such as Party) can be inserted inside a target block message, in the contact details area of a target block, or in the background information tab of the block. 2 | 3 | If you wish for reference data to show up in a text block then you can insert this into the background information area of the target block first, then use the following code to display it in a text block as well (hiding the background information tab too). 4 | 5 | This code works for a three-page email-to-target campaign set-up, where the target block is on Page 2. 6 | 7 | 1) Add any html, target data inserts and reference data inserts you want to display inside the targetblock's background information area (via the target block's settings) first. 8 | For example: 9 | ```html 10 |

In {contact_data~organization}, there are {reference_data~123~column1} cases of graffiti every year.

11 | ``` 12 | 2) Add a Code Block at the bottom of the page with the following code (this assumes you have jQuery on your page): 13 | ```html 14 | 17 | 22 | ``` 23 | 3) Add a class of "referencemessage" to the text block that should display the html (it will replace everything inside the text block so you can add default text here should the code not work for some reason) 24 | -------------------------------------------------------------------------------- /progress-through-campaign-pages.md: -------------------------------------------------------------------------------- 1 | # Show progress through the campaign 2 | This is useful to give an indication of how far through the campaign the supporter is. 3 | For example, for a donation campaign, page 1 might be "Personal Details", 2 "Payment details" and 3 "Confirmation". 4 | This is very simple by using a text block on each page: 5 | 6 | ```html 7 |
    8 |
  1. Details
  2. 9 |
  3. Payment
  4. 10 |
  5. Complete
  6. 11 |
12 | ``` 13 | 14 | Note that the "active" class shows the current stage in the process. 15 | 16 | An example style is below - this changes the numbers into circles and adds an underline in the submit button's colour (if using the Free and Flexible templates): 17 | 18 | ```css 19 | /* Page progress */ 20 | .progress ol { 21 | padding: 0; 22 | display: flex; 23 | width: 100%; 24 | list-style: none; 25 | counter-reset: item; 26 | } 27 | .progress ol li { 28 | width: 33%; 29 | font-weight: bold; 30 | border-bottom: 3px solid #dddddd; 31 | padding-bottom: 14px; 32 | list-style-position: inside; 33 | counter-increment: item; 34 | text-align: center; 35 | } 36 | .progress ol li.active { 37 | border-bottom: 3px solid var(--submit__button_background-color); 38 | color: var(--submit__button_background-color); 39 | } 40 | .progress ol li::before { 41 | content: counter(item); 42 | margin-right: 5px; 43 | background-color: #aaa; 44 | border-radius: 100%; 45 | color: #ffffff; 46 | width: 24px; 47 | display: inline-block; 48 | text-align: center; 49 | } 50 | .progress ol li.active::before { 51 | background-color: var(--submit__button_background-color); 52 | } 53 | ``` 54 | -------------------------------------------------------------------------------- /direct-debits-next-two-possible-dates.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 45 | -------------------------------------------------------------------------------- /account-number-sort-code-verify.md: -------------------------------------------------------------------------------- 1 | # Verify account number and sort code 2 | 3 | You cannot insert some field values into thanks emails or on thanks pages. For example, tagged account number and sort code. 4 | Therefore if you want to verify these to the supporter, you need to create new untagged fields in your Account Data Structure 5 | and add them to the form block as Hidden fields. You can then use a Code Block to update these fields with the data that 6 | the supporter enters. 7 | 8 | **Note:** how you verify supporter's financial information with them is up to you and depends on many factors - we do not offer advice on what you should do, just the technical aspect of it. The code below is simply an example. 9 | 10 | In this example, the code block will update the untagged fields NOT_TAGGED_13 and NOT_TAGGED_14 with the tagged fields. 11 | Your own IDs may vary. 12 | 13 | In addition, the code masks out the first 4 digits of the account number. 14 | 15 | ```html 16 | 31 | ``` 32 | 33 | Now you can simply use the field insert tool to display this information to the supporter. 34 | -------------------------------------------------------------------------------- /whatsapp-legacy.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 38 | -------------------------------------------------------------------------------- /searchable-selects.md: -------------------------------------------------------------------------------- 1 | If you have a lot of values in a select field, you might want it to be fully searchable. 2 | 3 | There is a third-party JavaScript plug-in called [Selectize](https://github.com/selectize/selectize.js) that works well. 4 | 5 | ## Example 6 | For example, this allows you to search for specific UK towns: 7 | 8 | https://secure.engagingnetworks.net/page/47877/petition/1?mode=DEMO&locale=en-GB 9 | 10 | In that example, it uses a code block to call CDN files (this applies to all Selects - you can change this to be more specific via the .selectize() line in this code): 11 | 12 | ```html 13 | 14 | 15 | 16 | 21 | ``` 22 | 23 | There are many other options available, so check out Selectize's documentation. 24 | 25 | ## Styling 26 | 27 | Some example stylings for the selectize box: 28 | 29 | ```css 30 | .selectize-input input { 31 | border-radius: .5em; 32 | color: #264334; 33 | min-height: 3em; 34 | padding: .55em !important; 35 | border-color: #000; 36 | } 37 | ``` 38 | 39 | To make it full width: 40 | 41 | ```css 42 | .selectize-control { 43 | width: 100%; 44 | padding: 0; 45 | } 46 | ``` 47 | 48 | And to style the search text (highlight) and the active one you hover on (active): 49 | 50 | ```css 51 | .selectize-control .highlight { 52 | color: white; 53 | background-color: #333333 !important; 54 | } 55 | .selectize-control .active { 56 | background-color: #ccc; 57 | } 58 | ``` 59 | 60 | And to style the placeholder text: 61 | 62 | ```css 63 | .selectize-control input::placeholder { 64 | color: black; 65 | } 66 | ``` 67 | 68 | -------------------------------------------------------------------------------- /insert-today's-date.js: -------------------------------------------------------------------------------- 1 | $( document ).ready(function() { 2 | // this example: 3 | // ... inserts today's date into #en__field_supporter_NOT_TAGGED_6, 4 | // ... inserts the date a year from now into #en__field_supporter_NOT_TAGGED_8, 5 | // ... inserts the date a year from now, minus one, into #en__field_supporter_NOT_TAGGED_7 6 | // It will format them as YYYYMMDD which means you can use profile and query filters (e.g. Is After) 7 | // Note 1: the IDs of the fields you want to insert the dates into will be different for your own account! 8 | // Note 2: the fields would need to be on the page, and hidden by CSS (NOT as a Hidden type otherwise val cannot be set) 9 | // Note 3: Hide the fields using CSS in a code block so you can still see them in page-builder 10 | // Note 4: You don't need all three fields of course - if you just want today's date, only insert for the start date 11 | // Note 5: You need jQuery for this to work. You can put this in a Code Block on the same page as the fields to insert into 12 | 13 | var daytoday = new Date(); 14 | var dayinyear = new Date(); 15 | var dayinyearlessone = new Date(); 16 | dayinyear.setFullYear(dayinyear.getFullYear() + 1); 17 | dayinyearlessone.setFullYear(dayinyearlessone.getFullYear() + 1); 18 | dayinyearlessone.setDate(dayinyearlessone.getDate()-1); 19 | $("#en__field_supporter_NOT_TAGGED_6").val(formatDate(daytoday)); // today's date (e.g. start date) 20 | $("#en__field_supporter_NOT_TAGGED_7").val(formatDate(dayinyearlessone)); // date a year from now, minus one (e.g. end date) 21 | $("#en__field_supporter_NOT_TAGGED_8").val(formatDate(dayinyear)); // date a year from now (e.g. due date) 22 | function formatDate(date) { 23 | var year=String(date.getFullYear()); 24 | var month=String(date.getMonth() + 1); 25 | var day=String(date.getDate()); 26 | if (month.length < 2) { 27 | month = "0" + String(month); 28 | } 29 | if (day.length < 2) { 30 | day = "0" + String(day); 31 | } 32 | var formattedDate=String(year)+String(month)+String(day); 33 | return formattedDate; 34 | } 35 | }); 36 | -------------------------------------------------------------------------------- /ETT-select-random-target-from-custom-database.md: -------------------------------------------------------------------------------- 1 | # Select a random target for a custom database ETT 2 | 3 | Usually when using a custom database that requires a Match field, you match the target 4 | on a field determined by the supporter, e.g. their broadband company 5 | 6 | However, you may want to randomise this, so that the supporter is given a randomised target from a list of targets. 7 | 8 | This is especially useful for the UK's House of Lords database, since these aren't determined by a postcode. 9 | 10 | 1) Create your custom database as usual, with a column of match numbers from 1 upwards, so each row has a unique number 11 | 2) Create a match field in your account data structure that will hold the randomised match number 12 | 3) Add the field to your ETT's first page, and the target block on the 2nd page 13 | 4) Add the code block below, ensuring you amend num to be the total number of targets in your database 14 | 5) Also amend matchFieldID to be the ID of your field (you can see this in the HTML of your page) 15 | 16 | 17 | ```html 18 | 49 | ``` 50 | -------------------------------------------------------------------------------- /direct-debits-next-two-possible-dates-v2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 67 | -------------------------------------------------------------------------------- /accessible-custom-checkboxes.css: -------------------------------------------------------------------------------- 1 | /* Styling checkboxes can often make them inaccessible with either the keyboard, screenreaders, or even both. 2 | This CSS allows you to replace the default browser checkboxes with fully accessible replacements. 3 | There are comments which indicate which parts to change to customise for your brand. */ 4 | 5 | input[type='checkbox'] { 6 | position: absolute; 7 | } 8 | 9 | input[type='checkbox'] + label { 10 | display: block; 11 | position: relative; 12 | padding: 0 1.5rem; 13 | } 14 | 15 | input[type='checkbox'] + label::before { 16 | content: ''; 17 | position: relative; 18 | display: inline-block; 19 | margin-right: 10px; 20 | width: 25px; /* Modify this to change the size of the checkbox. */ 21 | height: 25px; /* Modify this to change the size of the checkbox. */ 22 | background: #ffffff; /* Modify this to change the background colour of the checkbox. */ 23 | border: 1px solid #000000; /* Modify this to change colour of the border of the checkbox and the thickness of the border. */ 24 | vertical-align: text-bottom; 25 | } 26 | 27 | input[type='checkbox']:checked + label::before { 28 | background: #ffffff; /* Modify this to change the colour of background of the checkbox when it is checked. */ 29 | } 30 | 31 | input[type='checkbox']:checked + label::after { 32 | content: ''; 33 | position: absolute; 34 | top: 7px; /* Modify this to adjust the position of the tick inside the checkbox. */ 35 | left: 22px; /* Modify this to adjust the position of the tick inside the checkbox. */ 36 | border-left: 2px solid #000000; /* Modify this to change the colour of the tick inside the checkbox. */ 37 | border-bottom: 2px solid #000000; /* Modify this to change the colour of the tick inside the checkbox. */ 38 | height: 6px; /* Modify this to change the size of the tick inside the checkbox. */ 39 | width: 13px; /* Modify this to change the size of the tick inside the checkbox. */ 40 | transform: rotate(-45deg); 41 | } 42 | 43 | input[type='checkbox']:focus + label::before { 44 | outline: #000000 solid 1px; /* Modify this to change the focus colour for the checkbox. */ 45 | box-shadow: 0 0px 8px ; 46 | } 47 | 48 | input[type='checkbox'] { 49 | position: absolute !important; 50 | height: 1px; 51 | width: 1px; 52 | overflow: hidden; 53 | clip: rect(1px 1px 1px 1px); /* IE6, IE7 */ 54 | clip: rect(1px, 1px, 1px, 1px); 55 | } 56 | -------------------------------------------------------------------------------- /floating-button-scroll.md: -------------------------------------------------------------------------------- 1 | # Floating button for mobiles to scroll to form 2 | This code will add a button fixed to the bottom of the page for screens less than 600 pixels wide that, when clicked, 3 | will scroll to specified content, such as the second column. 4 | 5 | This is useful if you are worried that the left column (which will sit above the right column in narrow screens is obscuring the fields that the supporter needs to complete. 6 | 7 | This code should all be within one code block. Note that you will need to have styled .button 8 | 9 | The button will scroll to the selector specified in $slideTo 10 | 11 | Example page: https://e-activist.com/page/29146/petition/1?mode=DEMO&locale=en-GB 12 | 13 | ```html 14 | 36 | 68 | ``` 69 | -------------------------------------------------------------------------------- /gift-aid-calculation.md: -------------------------------------------------------------------------------- 1 | You might want to tell the supporter how much their donation would be worth if they ticked the Gift Aid option. You can achieve this using calculated fields, but what if you want to show this within a text block, e.g. "With Gift Aid your donation would be worth £1.25"? 2 | 3 | One way is to add a code block with the following code: 4 | 5 | ```html 6 | 56 | ``` 57 | 58 | And then inside the text block (with class "gift-aid") where you want to show the calculated amount, add this: 59 | 60 | ```html 61 |

Gift aid

62 |

With gift aid, every £1 63 | you give to us would be worth £1.25 64 | at no extra cost to you.

65 | ``` 66 | 67 | The code will replace the values inside the text block with values based on the input donation amount. Bingo! 68 | -------------------------------------------------------------------------------- /show-MP-name-on-data-capture.md: -------------------------------------------------------------------------------- 1 | This example uses the EaAOContactData public data service call. 2 | 3 | You can use data calls to query our contact databases for information and display them to the user, without having to use an email to target form. 4 | 5 | Here's an example using a postcode field on the first page of an action. When the supporter types this in and submits the page, the second page uses the postcode to request information from our MP contact database and then displays the supporter's MP in a copy block. 6 | 7 | 1) Create the first page of the data capture action, including the postcode field, email address and anything else you want. 8 | 9 | 2) On the second page, add a code block 10 | 11 | 3) In the Code Block, put in the following, updating 'your-token' with your public token 12 | 13 | ``` html 14 | 15 |

Your MP is

16 | 17 | 41 | ``` 42 | 43 | 5) The page will then display something like: Your MP is Caroline Lucas MP 44 | 45 | # How does it work? 46 | The first span just puts the supporter's postcode in a hidden box so we can reference it later. The next paragraph then shows text to the supporter "Your MP is xxx", where xxx is filled in by the script. 47 | 48 | The script begins by assigning the postcode to a variable, which it gets from the hidden span. The dataurl that will be used to query the contact database is then made, including a filter for the supporter's postcode. The database ID refers to the Westminster MP database, and the service as seen on Public Data Services. The token is the public token you have on your account. 49 | 50 | The data request is then made, using the URL. When it is done, the received JSON information is put in a variable called data. From this, the MP's name is assembled via a few columns of the received data. Finally, it is inserted into the mpName span from the second line. 51 | -------------------------------------------------------------------------------- /read-more-expand.md: -------------------------------------------------------------------------------- 1 | # Adding a read more expanding text block 2 | 3 | If you want some text that is hidden until a link is clicked, then you can do it by following these instructions 4 | 5 | First of all your template will need some javascript to add the functionality. Paste this into the bottom of your footer, just before the `` tag: 6 | 7 | ```html 8 | 9 | 18 | ``` 19 | 20 | Note you need jquery for this to work, so add the library if you don't already have it (see https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/README.md). 21 | 22 | If you want to, you can add styling to the header that is clicked, so that an arrow appears before the link which twists downwards when it is clicked to expand open. The example styles below requires the Font Awesome font to be installed, which is a handy font because it contains lots of nice symbols. You can do that by visiting https://fontawesome.com/get-started and copying the code it gives you and putting it in your template's header, somewhere inside the `` tags. 23 | 24 | Then insert the styles below into your `` also: 25 | 26 | ```html 27 | 56 | ``` 57 | 58 | Finally, to actually add the text to your page, drag in a new text block, then click the Source button and paste in this HTML: 59 | 60 | ```html 61 |
62 |
63 | Click for more information 64 |
65 |
66 |

More info more info

67 |

More info more info

68 |

More info more info

69 |

More info more info

70 |
71 |
72 | ``` 73 | 74 | Any content that appears between the moreinfo-content div will be hidden until the moreinfo-heading is clicked. 75 | -------------------------------------------------------------------------------- /Insert contact data on page 1.html: -------------------------------------------------------------------------------- 1 | 6 | 77 | -------------------------------------------------------------------------------- /direct-debits-Stripe-start-date-population.html: -------------------------------------------------------------------------------- 1 | 99 | 104 | -------------------------------------------------------------------------------- /shopping-list-money-buys.md: -------------------------------------------------------------------------------- 1 | # Shopping list for donation amounts 2 | You might want to have a page that has a "shopping list" or "money-buys" for different amounts chosen, e.g. "£20 could pay for a a water filtration kit". 3 | This can be done via some JavaScript (using jQuery) and CSS, then a text block with bulleted items where you set the text. 4 | 5 | ## To accept single and recurring (via Reccuring Payment field) 6 | To do that, you need code like this: 7 | 8 | ```html 9 | 45 | ``` 46 | 47 | Then, add this CSS to style the prompts: 48 | 49 | ```html 50 | 70 | ``` 71 | 72 | Then you add a text block, with a class of "prompts". 73 | It will look like a bulleted list, but the data-amount and data-rec are set via the HTML (get there using the Source button). 74 | For example, ```
  • ``` will show when the donation amount is 5, and the recurring payment is N: 75 | 76 | ```html 77 | 89 | ``` 90 | 91 | ## To accept one-off donations only (you don't have a Recurring Payment field on the page) 92 | 93 | Code: 94 | 95 | ```html 96 | 126 | ``` 127 | 128 | Style is the same, HTML of the prompts block is: 129 | 130 | ```html 131 | 138 | ``` 139 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # page-builder: Code Blocks 2 | 3 | Code Blocks can contain styles and javascript that only run when you preview or load the live page. They can add extra functionality to your pages. 4 | 5 | **Note that these need to be thoroughly tested by you before launching your page! It is functionality outside of the normal operation of the platform.** 6 | 7 | Many of these code blocks assume you have the jQuery library loaded in your template. If you do not, then you can add it via a line in your template's ``, e.g.: 8 | 9 | ```html 10 | 11 | ``` 12 | ## Where to put the code block 13 | The code block's position is important - if it is responding to a part of the page but it loads before it, it may not work. It is good to position the block at the bottom of your pages. Sometimes, you may want to wrap the code up in a ready event - this is so that it will only fire once the page has fully loaded: 14 | 15 | ```javascript 16 | $( document ).ready(function() { 17 | // your code here 18 | }); 19 | ``` 20 | 21 | ## Do I have to use a Code Block? 22 | No! The Code Block is useful when you only want to run the code on one page of a campaign, but you could add it directly into the template so all campaigns and their pages using that template get the code. 23 | 24 | ## Fields code 25 | 26 | Add placeholders within text boxes that match the input's label 27 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/placeholders.html 28 | 29 | Do not allow spaces in an email address field 30 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/email-address-do-not-allow-spaces.html 31 | 32 | Create and place a random email address - useful for anonymous actions 33 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/anonymous-random-email-address.html 34 | 35 | Create and place a random email address based on the supporter's phone/mobile number 36 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/phone-mobile-number-hidden-email-address.html 37 | 38 | Disable the submit button until the supporter presses a key inside the email-to-target message (to force them to edit it) 39 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/disable-submit-until-target-message-keypress.html 40 | 41 | Field masks, e.g. for phone numbers or credit card numbers 42 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/field-masks.html 43 | 44 | Change the error text for a specific field 45 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/change-error-text-for-a-single-field.html 46 | 47 | Counters for characters remaining in textareas 48 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/textarea-characters-remaining.html 49 | 50 | Update a field with another's contents 51 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/update-field-with-another-field's-value.html 52 | 53 | Locale - save to a question/field when you submit the page 54 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/locale-save.html 55 | 56 | Target block messages to have a maximum number of allowed characters 57 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/max-number-of-characters-in-target-block.html 58 | 59 | Searchable select field 60 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/searchable-selects.md 61 | 62 | ## Opt-in code 63 | 64 | Show and hide an alert if the supporter chooses No for a radio opt-in 65 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/opt-in-text-toggle.html 66 | 67 | Pre-tick and hide a checkbox or radio opt-in 68 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/pre-tick-and-hide-opt-in.html 69 | 70 | ## Donation pages code 71 | 72 | Choose the next two available start dates on the 1st of the month 73 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/direct-debits-next-two-possible-dates-v2.html 74 | 75 | Choose the next two available start dates on the 1st or 15th of the month 76 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/direct-debits-next-two-possible-dates.html 77 | 78 | Choose the next available start date as the 20th of next month 79 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/direct-debits-next-month-20th.html 80 | 81 | Gift aid calculation display in a text block 82 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/gift-aid-calculation.md 83 | 84 | Verify account number and sort code for thanks emails 85 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/account-number-sort-code-verify.md 86 | 87 | ## Social code 88 | 89 | Add a share by email button 90 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/share-by-email-button.md 91 | 92 | ## Other 93 | 94 | Add a more info link that expands to reveal more content 95 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/read-more-expand.md 96 | 97 | Add a fixed floating button to allow supporters to scroll down to the form for narrow screens/mobiles 98 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/floating-button-scroll.md 99 | 100 | Alert supporters if their browser does not support TLS 1.1 or above (see http://support.engagingnetworks.net/manually-enabling-tls-11-andor-tls-12-protocols-web-browsers for more information) 101 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/tls-checker.html 102 | 103 | Show the supporter's MP name on a non-email-to-target page 104 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/show-MP-name-on-data-capture.md 105 | 106 | Add a shopping list/money-buys to show when certain donation amounts are chosen 107 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/shopping-list-money-buys.md 108 | 109 | Show progress through a campaign 110 | https://github.com/EngagingNetworks/page-builder-code-blocks/blob/master/progress-through-campaign-pages.md 111 | --------------------------------------------------------------------------------