Convert index to TS

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-09-24 20:37:59 +02:00
parent 79b52f8a22
commit bffebb9304
No known key found for this signature in database
GPG Key ID: 55C211A1226CB17D
1 changed files with 16 additions and 18 deletions

View File

@ -1,5 +1,5 @@
let hasCalled = false;
function remoteRender(event) {
function remoteRender(event: MessageEvent): void {
const data = event.data;
// If we're handling secondary calls, start from scratch
@ -11,10 +11,11 @@ function remoteRender(event) {
const img = document.createElement("span"); // we'll mask it as an image
img.id = "img";
const a = document.createElement("a");
const a: HTMLAnchorElement = document.createElement("a");
a.id = "a";
a.rel = "noreferrer noopener";
a.download = data.download;
// @ts-ignore
a.style = data.style;
a.style.fontFamily = "Arial, Helvetica, Sans-Serif";
a.href = window.URL.createObjectURL(data.blob);
@ -23,24 +24,21 @@ function remoteRender(event) {
// Apply image style after so we can steal the anchor's colour.
// Style copied from a rendered version of mx_MFileBody_download_icon
img.style = (data.imgStyle || "" +
"width: 12px; height: 12px;" +
"-webkit-mask-size: 12px;" +
"mask-size: 12px;" +
"-webkit-mask-position: center;" +
"mask-position: center;" +
"-webkit-mask-repeat: no-repeat;" +
"mask-repeat: no-repeat;" +
"display: inline-block;") + "" +
// Always add these styles
`-webkit-mask-image: url('${data.imgSrc}');` +
`mask-image: url('${data.imgSrc}');` +
`background-color: ${a.style.color};`;
// @ts-ignore
img.style = data.imgStyle ?? "";
img.style.width = "12px";
img.style.height = "12px";
img.style.webkitMaskSize = "12px";
img.style.webkitMaskPosition = "center";
img.style.webkitMaskRepeat = "no-repeat";
img.style.display = "inline-block";
img.style.webkitMaskImage = `url('${data.imgSrc}')`;
img.style.backgroundColor = `${a.style.color}`;
const body = document.body;
// 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);
if (event.data.auto) {
@ -48,7 +46,7 @@ function remoteRender(event) {
}
}
window.onmessage = function(e) {
window.onmessage = function(e: MessageEvent): void {
if (e.origin === window.location.origin) {
if (e.data.blob) remoteRender(e);
}