|
@@ -76,15 +76,22 @@ class BrowserHost {
|
|
|
alert(message);
|
|
alert(message);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ import(file, callback) {
|
|
|
|
|
+ var url = this.url(file);
|
|
|
|
|
+ var script = document.createElement('script');
|
|
|
|
|
+ script.onload = () => {
|
|
|
|
|
+ callback(null);
|
|
|
|
|
+ };
|
|
|
|
|
+ script.onerror = (e) => {
|
|
|
|
|
+ callback(new Error('The script \'' + e.target.src + '\' failed to load.'));
|
|
|
|
|
+ };
|
|
|
|
|
+ script.setAttribute('type', 'text/javascript');
|
|
|
|
|
+ script.setAttribute('src', url);
|
|
|
|
|
+ document.head.appendChild(script);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
request(file, callback) {
|
|
request(file, callback) {
|
|
|
- var url = file;
|
|
|
|
|
- if (window && window.location && window.location.href) {
|
|
|
|
|
- var location = window.location.href;
|
|
|
|
|
- if (location.endsWith('/')) {
|
|
|
|
|
- location = location.slice(0, -1);
|
|
|
|
|
- }
|
|
|
|
|
- url = location + file;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ var url = this.url(file);
|
|
|
var request = new XMLHttpRequest();
|
|
var request = new XMLHttpRequest();
|
|
|
if (file.endsWith('.pb')) {
|
|
if (file.endsWith('.pb')) {
|
|
|
request.responseType = 'arraybuffer';
|
|
request.responseType = 'arraybuffer';
|
|
@@ -110,6 +117,18 @@ class BrowserHost {
|
|
|
request.send();
|
|
request.send();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ url(file) {
|
|
|
|
|
+ var url = file;
|
|
|
|
|
+ if (window && window.location && window.location.href) {
|
|
|
|
|
+ var location = window.location.href;
|
|
|
|
|
+ if (location.endsWith('/')) {
|
|
|
|
|
+ location = location.slice(0, -1);
|
|
|
|
|
+ }
|
|
|
|
|
+ url = location + file;
|
|
|
|
|
+ }
|
|
|
|
|
+ return url;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
openURL(url) {
|
|
openURL(url) {
|
|
|
window.open(url, '_target');
|
|
window.open(url, '_target');
|
|
|
}
|
|
}
|