2020-01-25 13:11:25 +01:00
|
|
|
export default class FileLoader
|
|
|
|
{
|
|
|
|
constructor(filename)
|
|
|
|
{
|
|
|
|
this.filename = filename;
|
|
|
|
this.content = '';
|
2023-09-19 11:44:56 +02:00
|
|
|
|
|
|
|
this.onLoad = () => {};
|
2020-01-25 13:11:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getContent()
|
|
|
|
{
|
|
|
|
return this.content;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadContent()
|
|
|
|
{
|
|
|
|
let request = new XMLHttpRequest();
|
|
|
|
|
|
|
|
request.onreadystatechange = () => {
|
|
|
|
if (request.status === 200 && request.readyState === 4) {
|
|
|
|
this.content = request.responseText;
|
2023-09-19 11:44:56 +02:00
|
|
|
this.onLoad(this.content);
|
2020-01-25 13:11:25 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
request.open('GET', this.filename, false);
|
|
|
|
request.send();
|
|
|
|
}
|
2023-09-19 11:44:56 +02:00
|
|
|
}
|