Skip to content

Instantly share code, notes, and snippets.

View crowdfundhq's full-sized avatar

CrowdfundHQ crowdfundhq

View GitHub Profile
@crowdfundhq
crowdfundhq / api_usage.html
Last active October 26, 2016 12:48
An example of how to use the CrowdfundHQ API from within your site
<script>
// Enable 'Sessions enabled' in Manage Site > Configuration > Settings > API
// Then use this script in Manage Site > Design > Pages or Scripts to fetch users
document.addEventListener('DOMContentLoaded', function(){
// Define variables
var url = '/api/v1/user/list', result, list, user;
// Do ajax call using hq.js
hq.ajax(url, {
success: function(json) {
@crowdfundhq
crowdfundhq / setup_froala_editor.html
Last active November 9, 2016 13:49
How to set up the Froala editor on existing CrowdfundHQ sites
<!-- How to set up the Froala editor (https://froala.com) on CrowdfundHQ (https://crowdfundhq.com) if it's not working -->
<!-- First go to Manage Site > Configuration > Settings > General and make sure Text Editor is set to Froala -->
<!-- Froala requires FontAwesome (http://fontawesome.io) and jQuery (https://jquery.com), install them if you don't have them already -->
<!-- Include jQuery by pasting the following line into Manage Site > Design > Scripts -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<!-- Include FontAwesome by pasting the following line into Manage Site > Design > Libraries -->
<script>
document.addEventListener('DOMContentLoaded', function(){
if(hq.isMobile()) {
var campaignContent = document.getElementById('campaign_content');
if(campaignContent) {
var campaignSidebar = document.getElementById('campaign_sidebar');
var stats = document.getElementById('stats');
campaignSidebar.insertBefore(campaignContent, stats);
campaignContent.style.marginBottom = '2em';
}
<script>
// Add this to the bottom of the contribution/new liquid template
var inputs = document.querySelectorAll('#selectable input');
var amount = document.querySelector('#contribution_amount');
// Sets the amount to be the same as the reward you chose
var select = function (event) {
var input = event.target;
var value = input.getAttribute('data-amount');
if (value) {
{% comment %} Search by custom field {% endcomment %}
{% assign campaigns = current_site.campaigns | where: 'custom_fields.phone', '555-1234' | all %}
{% Options for the option_list filter %}
<!-- Default, no options -->
{{ settings.countries | option_list }}
<!-- With empty prompt -->
{{ settings.countries | option_list: prompt: true }}
<!-- With selected -->
{{ settings.countries | option_list: selected: 'BR' }}
{% if current_user %}
{% assign contributed = campaign.contributions | where: user_id: current_user.id | first %}
{% if contributed %}
Already contributed!
<script>
// Redirect back
window.location = '{{ request.referer }}'
</script>
{% else %}
Not contributed.
<!-- This is an example on how to update contributions with jQuery from within your site -->
<p>The API says:</p>
<div id="response"></div>
<div id="error"></div>
<script>
document.addEventListener('DOMContentLoaded', function() {
var response = document.getElementById('response')
@crowdfundhq
crowdfundhq / hash_page_in_url.html
Last active October 7, 2018 01:38
Add page to CrowdfundHQ using hash in URL
<div class="normal">
<h3>Normal content</h3>
<p>This is what the user normally sees</p>
<a href="/test/liquid#invite">Invite</a>
</div>
<div class="invite" style="display:none">
<h3>Invite form</h3>
<p>The invite page</p>
<a href="/test/liquid#">Back</a>
<script>
window.hq.postDialog = function(form){
var params = hq.serialize(form);
var center = hq.initDialog();
window.hq.post(form.action, center, params);
};
// General post ajax method
window.hq.post = function(url, el, params){
if(!el){ el = document.getElementById('content');}
hq.ajax(url, {