markdown: using iframe

This commit is contained in:
Steven Hugg 2020-07-10 15:19:01 -05:00
parent 1e9b164c55
commit 34aba0443e
1 changed files with 16 additions and 6 deletions

View File

@ -4,13 +4,16 @@ import { PLATFORMS } from "../common/emu";
import { Platform } from "../common/baseplatform";
class MarkdownPlatform implements Platform {
mainElement;
htmlDiv;
mainElement : HTMLElement;
iframe : HTMLIFrameElement;
constructor(mainElement:HTMLElement) {
this.mainElement = mainElement;
this.htmlDiv = $('<div class="markdown">').appendTo(mainElement);
$(mainElement).css('overflowY', 'auto');
this.iframe = $('<iframe sandbox seamless src="javascript:void(0);" width="100%" height="100%"/>').appendTo(mainElement)[0] as HTMLIFrameElement;
//this.iframe = $('<iframe sandbox src="res/markdown-iframe.html" width="100%" height="100%"/>').appendTo(mainElement)[0] as HTMLIFrameElement;
this.iframe.style.backgroundColor = 'white';
mainElement.classList.add("vertical-scroll"); //100% height
mainElement.style.overflowY = 'auto';
}
start() {
}
@ -20,8 +23,15 @@ class MarkdownPlatform implements Platform {
}
resume() {
}
loadROM(title, data) {
this.htmlDiv.html(data);
loadROM(title, data:string) {
// have to do this b/c sandboxed without same origin
// TODO: preserve scroll position
if (this.iframe.srcdoc)
this.iframe.srcdoc = data;
else
this.iframe.src = "data:text/html;charset=utf-8," + escape(data);
//this.iframe.contentWindow.postMessage({body:data}, "*");
//$(this.iframe).contents().find('body').html(data);
}
isRunning() {
return false;