(function setupResponsiveContainer(containerId, breakpoints) {
var container;
function handleMessage(event) {
if (event.data && event.data.event && event.data.event.type === 'resize') {
return handleParentResize(event.data.event);
}
}
function handleParentResize(event) {
container = container || document.getElementById(containerId);
if (!container) {
return;
}
// remove the existing breakpoint class (if any) and add in the current one
container.className = container.className
.split(/\s+/)
.filter(isNotBreakpointClassName)
.concat([ event.breakpoint ])
.join(' ');
}
function isNotBreakpointClassName(className) {
return (breakpoints.indexOf(className) < 0);
}
window.addEventListener('message', handleMessage, false);
})('Piano', [ 'extraSmall', 'small', 'medium', 'large' ]);
// Helper because you can't type html tag into Piano script because it gets stripped out! e.g. $("
") breaks
// Not nessecary in ActionKit but this code is shared (via copy/paste) between the two platforms.
$.create = function(tag, options) { return $(String.fromCharCode(60) + tag + String.fromCharCode(62), options) };
function initThermometer(className, dataUrl) {
$.getJSON(dataUrl).then(function(data) {
// Set thermometer level - use 'each' because AK page has two views
$('.' + className).each(function(_, thermoView) {
thermoView = $(thermoView)
if (thermoView.length === 0) return;
var thermoBorder = $.create('div', { class: className+'-border' });
var thermoLevelView = $.create('div', { class: className+'-level' });
var thermoAmountView = $.create('div', { class: className+'-amount' });
thermoBorder.append(thermoLevelView);
thermoView.append(thermoBorder, thermoAmountView);
var percent = parseInt(data.progress);
if (percent == 100 || percent == 0) {
thermoLevelView.addClass('no-border');
}
thermoLevelView.css('width', percent + '%');
thermoAmountView.text(data.goal.condensed + data.goal.scaleAbbreviation);
thermoView.css('opacity', 1);
});
// Update setence which states donation levels
$('.' + className + '-goal-text').each(function(_, goalTextView) {
goalTextView = $(goalTextView)
var t = goalTextView.text();
t = t.replace('{goal}', data.goal.condensed + ' ' + data.goal.scale);
t = t.replace('{donated}', data.amount.condensed + ' ' + data.amount.scale);
goalTextView.text(t);
});
});
}
window.addEventListener('load', function(event) {
var html = document.getElementsByTagName( 'html' )[0];
var theme = document.getElementById('Piano-theme');
html.className = html.className + ' loaded';
var enableSidebar = true;
if (enableSidebar) {
html.className += ' enable-sidebar';
}
if (theme) {
html.className += ' ' + theme.value;
}
initThermometer('DirectAsk-thermo', 'https://static.theintercept.com/actionkit/thermometers/2019_campaign/data.json');
})