refactor browser download utility
This commit is contained in:
Родитель
c9368acc75
Коммит
887f9e5077
|
@ -282,12 +282,7 @@ module TDev
|
|||
|
||||
ScriptProperties.firstTime = false
|
||||
|
||||
var link = <HTMLAnchorElement>window.document.createElement('a');
|
||||
link.href = res.dataurl;
|
||||
(<any>link).download = "microbit-" + Script.getName().replace(/[^\w]+/g, " ").trim().replace(/ /g, "-") + ".hex"
|
||||
var click = document.createEvent("Event");
|
||||
click.initEvent("click", true, true);
|
||||
link.dispatchEvent(click);
|
||||
HTML.browserDownload(res.dataurl, "microbit-" + Script.getName().replace(/[^\w]+/g, " ").trim().replace(/ /g, "-") + ".hex");
|
||||
})
|
||||
.done(() => {},
|
||||
e => {
|
||||
|
|
|
@ -681,12 +681,7 @@ module TDev.RT {
|
|||
}
|
||||
else {
|
||||
var url = this.canvas.toDataURL('image/png');
|
||||
var link = <HTMLAnchorElement>window.document.createElement('a');
|
||||
link.href = url;
|
||||
(<any>link).download = defaultName;
|
||||
var click = document.createEvent("Event");
|
||||
click.initEvent("click", true, true);
|
||||
link.dispatchEvent(click);
|
||||
HTML.browserDownload(url, defaultName);
|
||||
}
|
||||
return defaultName;
|
||||
});
|
||||
|
|
|
@ -896,6 +896,15 @@ module TDev.HTML {
|
|||
r.setChildren(elts)
|
||||
return r;
|
||||
}
|
||||
|
||||
export function browserDownload(href: string, filename: string) {
|
||||
var link = <HTMLAnchorElement>window.document.createElement('a');
|
||||
link.href = href;
|
||||
(<any>link).download = filename
|
||||
var click = document.createEvent("Event");
|
||||
click.initEvent("click", true, true);
|
||||
link.dispatchEvent(click);
|
||||
}
|
||||
|
||||
export function showNotification(msg: HTMLElement) {
|
||||
elt("root").appendChild(msg);
|
||||
|
|
Загрузка…
Ссылка в новой задаче