From 5a810a0831efc4422385d69b4bda9c7d3bd89d59 Mon Sep 17 00:00:00 2001 From: Alex Horstmann Date: Tue, 6 Oct 2026 10:50:32 -0700 Subject: [PATCH 1/4] embedded donate form --- docs/dist/donate-button/embed.js | 85 +++++++++++++++++++ package.json | 8 +- packages/donate-embed/.prettierrc | 7 ++ packages/donate-embed/LICENSE | 21 +++++ packages/donate-embed/README.md | 42 +++++++++ .../donate-embed/dist/donate-button/embed.js | 85 +++++++++++++++++++ packages/donate-embed/embed.js | 85 +++++++++++++++++++ packages/donate-embed/package.json | 17 ++++ 8 files changed, 347 insertions(+), 3 deletions(-) create mode 100644 docs/dist/donate-button/embed.js create mode 100644 packages/donate-embed/.prettierrc create mode 100644 packages/donate-embed/LICENSE create mode 100644 packages/donate-embed/README.md create mode 100644 packages/donate-embed/dist/donate-button/embed.js create mode 100644 packages/donate-embed/embed.js create mode 100644 packages/donate-embed/package.json diff --git a/docs/dist/donate-button/embed.js b/docs/dist/donate-button/embed.js new file mode 100644 index 00000000..72d9ef2a --- /dev/null +++ b/docs/dist/donate-button/embed.js @@ -0,0 +1,85 @@ +/** + * every.org embedded donate form. + * + * Include this script and call: + * + * everyWidget.create({ + * selector: '#donate-widget', + * partnerSlug: 'your-partner-slug', + * nonprofitSlug: 'nonprofit-slug', + * onSuccess: function () {}, // optional + * }); + * + * selector CSS selector of the element the donate form is added to. + * partnerSlug The partner slug every.org assigned to you. + * nonprofitSlug The every.org slug of the nonprofit to donate to. + * onSuccess Called when a donation completes. + * + * The donate form renders in an iframe that fills the width of its + * container and resizes itself to fit its content. + */ +(function () { + var EMBED_ORIGIN = 'https://embed-staging.every.org'; + + function create(options) { + var container = document.querySelector(options.selector); + if (!container) { + console.error('everyWidget: no element matches', options.selector); + return null; + } + if (!options.partnerSlug || !options.nonprofitSlug) { + console.error( + 'everyWidget: partnerSlug and nonprofitSlug are required', + options + ); + return null; + } + + var iframe = document.createElement('iframe'); + iframe.src = + EMBED_ORIGIN + + '/embed/' + + encodeURIComponent(options.nonprofitSlug) + + '/donate?partnerSlug=' + + encodeURIComponent(options.partnerSlug); + iframe.title = 'Donate'; + // The form resizes itself to fit its content, so it never scrolls. + iframe.setAttribute('scrolling', 'no'); + // Required for Apple Pay / Google Pay. + iframe.setAttribute('allow', 'payment'); + iframe.style.display = 'block'; + iframe.style.width = '100%'; + iframe.style.border = '0'; + iframe.style.overflow = 'hidden'; + // Placeholder height until the form reports its own. + iframe.style.minHeight = '480px'; + container.appendChild(iframe); + + window.addEventListener('message', function (event) { + if ( + event.origin !== EMBED_ORIGIN || + event.source !== iframe.contentWindow + ) { + return; + } + + var data = event.data || {}; + if (data.source !== 'every-widget') { + return; + } + + if (data.type === 'resize' && typeof data.height === 'number') { + iframe.style.minHeight = '0'; + iframe.style.height = data.height + 'px'; + } + + if (data.type === 'success' && typeof options.onSuccess === 'function') { + options.onSuccess(); + } + }); + + return iframe; + } + + window.everyWidget = {create: create}; +})(); diff --git a/package.json b/package.json index 2d657c86..16593eac 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,9 @@ "build:donateButton": "yarn workspace @everydotorg/donate-button build && cp -r packages/donate-button/dist ./docs", "build:donateButtonNext": "yarn workspace @everydotorg/donate-button-next build && cp -r packages/donate-button-next/dist ./docs", "build:donateButtonV4": "yarn workspace @everydotorg/donate-button-v4 build && cp -r packages/donate-button-v4/dist ./docs", - "build": "yarn build:donateButtonV4", - "lint": "yarn workspace @everydotorg/donate-button-v4 lint", + "build:donateEmbed": "yarn workspace @everydotorg/donate-embed build && cp -r packages/donate-embed/dist ./docs", + "build": "yarn build:donateButtonV4 && yarn build:donateEmbed", + "lint": "yarn workspace @everydotorg/donate-button-v4 lint && yarn workspace @everydotorg/donate-embed lint", "lint:fix": "yarn workspaces @everydotorg/donate-button-v4 lint:fix", "test": "yarn concurrently -n 'api,website-next,common,partner-api' 'yarn workspace @everydotorg/donate-button-cloudflare-worker test' 'yarn workspace @everydotorg/donate-button test' 'yarn workspace @everydotorg/donate-button-next test' 'yarn workspace @everydotorg/donate-button-v4 test'", "postinstall": "patch-package" @@ -14,7 +15,8 @@ "packages/cloudflare-worker", "packages/donate-button", "packages/donate-button-next", - "packages/donate-button-v4" + "packages/donate-button-v4", + "packages/donate-embed" ], "devDependencies": { "concurrently": "^7.1.0", diff --git a/packages/donate-embed/.prettierrc b/packages/donate-embed/.prettierrc new file mode 100644 index 00000000..376cdae7 --- /dev/null +++ b/packages/donate-embed/.prettierrc @@ -0,0 +1,7 @@ +{ + "tabWidth": 2, + "useTabs": true, + "trailingComma": "none", + "bracketSpacing": false, + "singleQuote": true +} diff --git a/packages/donate-embed/LICENSE b/packages/donate-embed/LICENSE new file mode 100644 index 00000000..5bad0a3e --- /dev/null +++ b/packages/donate-embed/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Every.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/donate-embed/README.md b/packages/donate-embed/README.md new file mode 100644 index 00000000..41179008 --- /dev/null +++ b/packages/donate-embed/README.md @@ -0,0 +1,42 @@ +# donate-embed + +`embed.js` renders the every.org donate form inline on your page. It adds an +iframe to a container of your choice, sizes it to fit the form, and tells you +when a donation completes. + +Published at **https://embeds.every.org/embed.js**. + +## Usage + +```html + + + + +``` + +Options for `everyWidget.create`: + +- `selector` (required): CSS selector of the element the donate form is added to. +- `partnerSlug` (required): the partner slug every.org assigned to you. +- `nonprofitSlug` (required): the every.org slug of the nonprofit to donate to. +- `onSuccess` (optional): called when a donation completes. + +`create` returns the `