Merge pull request #6862 from SimonBrandner/task/usercontent-ts

Convert `/src/usercontent` to TS
This commit is contained in:
Travis Ralston 2021-09-25 20:52:37 -06:00 committed by GitHub
commit 0354a7025d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
let hasCalled = false; let hasCalled = false;
function remoteRender(event) { function remoteRender(event: MessageEvent): void {
const data = event.data; const data = event.data;
// If we're handling secondary calls, start from scratch // If we're handling secondary calls, start from scratch
@ -8,13 +8,14 @@ function remoteRender(event) {
} }
hasCalled = true; hasCalled = true;
const img = document.createElement("span"); // we'll mask it as an image const img: HTMLSpanElement = document.createElement("span"); // we'll mask it as an image
img.id = "img"; img.id = "img";
const a = document.createElement("a"); const a: HTMLAnchorElement = document.createElement("a");
a.id = "a"; a.id = "a";
a.rel = "noreferrer noopener"; a.rel = "noreferrer noopener";
a.download = data.download; a.download = data.download;
// @ts-ignore
a.style = data.style; a.style = data.style;
a.style.fontFamily = "Arial, Helvetica, Sans-Serif"; a.style.fontFamily = "Arial, Helvetica, Sans-Serif";
a.href = window.URL.createObjectURL(data.blob); a.href = window.URL.createObjectURL(data.blob);
@ -23,24 +24,24 @@ function remoteRender(event) {
// Apply image style after so we can steal the anchor's colour. // Apply image style after so we can steal the anchor's colour.
// Style copied from a rendered version of mx_MFileBody_download_icon // Style copied from a rendered version of mx_MFileBody_download_icon
img.style = (data.imgStyle || "" + if (data.imgStyle) {
"width: 12px; height: 12px;" + // @ts-ignore
"-webkit-mask-size: 12px;" + img.style = data.imgStyle;
"mask-size: 12px;" + } else {
"-webkit-mask-position: center;" + img.style.width = "12px";
"mask-position: center;" + img.style.height = "12px";
"-webkit-mask-repeat: no-repeat;" + img.style.webkitMaskSize = "12px";
"mask-repeat: no-repeat;" + img.style.webkitMaskPosition = "center";
"display: inline-block;") + "" + img.style.webkitMaskRepeat = "no-repeat";
img.style.display = "inline-block";
// Always add these styles img.style.webkitMaskImage = `url('${data.imgSrc}')`;
`-webkit-mask-image: url('${data.imgSrc}');` + img.style.backgroundColor = `${a.style.color}`;
`mask-image: url('${data.imgSrc}');` + }
`background-color: ${a.style.color};`;
const body = document.body; const body = document.body;
// Don't display scrollbars if the link takes more than one line to display. // Don't display scrollbars if the link takes more than one line to display.
body.style = "margin: 0px; overflow: hidden"; body.style .margin = "0px";
body.style.overflow = "hidden";
body.appendChild(a); body.appendChild(a);
if (event.data.auto) { if (event.data.auto) {
@ -48,7 +49,7 @@ function remoteRender(event) {
} }
} }
window.onmessage = function(e) { window.onmessage = function(e: MessageEvent): void {
if (e.origin === window.location.origin) { if (e.origin === window.location.origin) {
if (e.data.blob) remoteRender(e); if (e.data.blob) remoteRender(e);
} }