personal-website/resources/sys/blog-viewer/blog-viewer.js

50 lines
1.5 KiB
JavaScript

class BlogViewer{
appId = "blog-viewer"
constructor(){
}
/**
* @param {string[]} chroot //TODO
* @param {string[]} args
*/
async NewWindow(args){
const response = await fetch(`app/${this.appId}/render?` + new URLSearchParams({
isMobile: WebDesktopEnvironment.isMobile,
path: args[0],
}))
if (response.status != 200){
WebDesktopEnvironment.Alert("Error render TODO") //TODO
return
}
const html = await response.text()
let newWindow = WebDesktopEnvironment.CreateNewWindow(this.appId, 500, 350 )
newWindow.innerHTML = html
let scrollBar = new WdeScrollBar(newWindow.querySelector(".ScrollbarPlace"), newWindow.querySelector(".ScrollContent"))
newWindow.querySelector("#closeWindowButton").addEventListener('click', function (params) {
WebDesktopEnvironment.CloseWindow(newWindow)
})
}
/**
* @param {MouseEvent} event
* @param {string} path
*/
static Click(event, path){
let fileType = event.target.getAttribute("fileType")
switch (fileType) {
case "app":
//TODO get real id
WebDesktopEnvironment.Open("personal-properties", [])
break;
case "img":
WebDesktopEnvironment.Open("img-viewer", ["pizda"])
break;
default:
console.log("Unsupported file type")
break;
}
}
}