Skip to content

Commit

Permalink
Fix bug in the wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
wwahammy committed Jun 12, 2023
1 parent 29f034a commit edd4327
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
19 changes: 19 additions & 0 deletions app/javascript/common/UrlSearchParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// License: LGPL-3.0-or-later

export function appendAll(base:URLSearchParams, toAdd:URLSearchParams):URLSearchParams;
export function appendAll(base:URLSearchParams, toAdd:Record<string, string>):URLSearchParams;
export function appendAll(base:URLSearchParams, toAdd:Record<string, string> | URLSearchParams):URLSearchParams
{
if (toAdd instanceof URLSearchParams) {
toAdd.forEach((value, key) => {
base.append(key, value);
});
}
else {
for (const key in toAdd) {
base.append(key, toAdd[key]);
}
}

return base;
}
17 changes: 11 additions & 6 deletions app/javascript/donate-button/donate-button.v2.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { appendAll } from "../common/UrlSearchParams";

const donate_css = require('../../assets/stylesheets/donate-button/donate-button.v2.css');

const iframeHost = require('./details.js.erb')
Expand Down Expand Up @@ -55,11 +57,14 @@ const iframeHost = require('./details.js.erb')
return div
}

commitchange.createIframe = (source:string) => {
commitchange.createIframe = (source:URL, params:URLSearchParams=new URLSearchParams()) => {
let i = document.createElement('iframe')
const url = document.location.href
i.setAttribute('class', 'commitchange-closed commitchange-iframe')
i.src = source + "&origin=" + url

appendAll(source.searchParams, params);
source.searchParams.set(origin, url);
i.src = source.toString();
return i
}

Expand Down Expand Up @@ -97,7 +102,7 @@ const iframeHost = require('./details.js.erb')

}
// Remove false values from the options
for(let key in options) {
for(const key in options) {
if(!options[key]) delete options[key]
}
return options
Expand All @@ -113,19 +118,19 @@ const iframeHost = require('./details.js.erb')

for(let i = 0; i < elems.length; ++i) {
let elem:any = elems[i]
let source = baseSource
let source = new URL(baseSource)


const options = {
offsite: "t",
...commitchange.getParamsFromUrl(["utm_campaign","utm_content","utm_source","utm_medium","first_name","last_name","country","postal_code","address","city"]),
...commitchange.getParamsFromButton(elem)
}
} as Record<string, string>
const params = new URLSearchParams(options);

if(elem.hasAttribute('data-embedded')) {
params.append("mode", "embedded");
let iframe = commitchange.createIframe(new URL(baseSource + "&" + params.toString()).toString());
let iframe = commitchange.createIframe(new URL(baseSource), params);
elem.appendChild(iframe)
iframe.setAttribute('class', 'commitchange-iframe-embedded')
commitchange.iframes.push(iframe)
Expand Down

0 comments on commit edd4327

Please sign in to comment.