Skip to content

Commit 7238940

Browse files
committed
feat: Allow pass-through of URL hash parameters to card
1 parent b076f0b commit 7238940

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

javascript/engine-js/src/view/TokenViewData.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,14 @@ export class TokenViewData {
7272
body = this.processTags(part, body);
7373
}
7474

75-
// TODO: Due to a floor in the svelte template routing, card param injection for deeplinks will need to be added
76-
// to the card SDK so it does not conflict with current usage of document.location.hash which would break existing TokenScripts
77-
//const browserParams = new URLSearchParams(document.location.hash.substring(1));
78-
7975
return `
8076
<!DOCTYPE html>
8177
<html lang="en">
8278
<head>
8379
<title>TokenScript</title>
8480
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
8581
<script>
86-
document.location.hash = '${(this.card.urlFragment ? "#" + this.card.urlFragment : "")}';
82+
document.location.hash = '${"#" + this.getCardUrlParameters()}';
8783
</script>
8884
</head>
8985
<body>
@@ -93,6 +89,22 @@ export class TokenViewData {
9389
`;
9490
}
9591

92+
public getCardUrlParameters(){
93+
94+
let urlParams: string;
95+
96+
if (this.card.urlFragment){
97+
urlParams = this.card.urlFragment;
98+
} else {
99+
const browserHashParams = new URLSearchParams(document.location.hash.substring(1));
100+
browserHashParams.set("card", this.card.name);
101+
browserHashParams.set("tsViewerType", (new URLSearchParams(document.location.search)).get("viewType") ?? "default");
102+
urlParams = browserHashParams.toString();
103+
}
104+
105+
return urlParams;
106+
}
107+
96108
/**
97109
* Process tags to ensure the correct HTML formatting for styles & scripts, reverting entity escaping where necessary.
98110
* @param part

javascript/tokenscript-viewer/src/integration/abstractViewBinding.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export abstract class AbstractViewBinding implements IViewBinding {
102102

103103
if (new URLSearchParams(document.location.search).has("___b64url")){
104104
const blob = new Blob([html], {type: "text/html"});
105-
iframe.src = URL.createObjectURL(blob) + (card.urlFragment ? "#" + card.urlFragment : "");
105+
iframe.src = URL.createObjectURL(blob) + ("#" + viewController.tokenViewData.getCardUrlParameters());
106106
} else {
107107
iframe.srcdoc = html;
108108
}

0 commit comments

Comments
 (0)