aboutsummaryrefslogtreecommitdiff
path: root/src/content/presenters
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2021-03-22 20:44:07 +0900
committerGitHub <noreply@github.com>2021-03-22 20:44:07 +0900
commitfa733c1ff110054f673f3d4e8d4760eb90d5d1eb (patch)
tree0a7d9f041a01d29f0bc5972a343e4988dc71b468 /src/content/presenters
parent3cbaf4a9f4245bd6be4eccdbff11e20ffaaf523a (diff)
parent690c9c080a2a511a30d555a90e5005e06b750351 (diff)
Merge pull request #1043 from ueokande/iframe-late-inject
iframe Late injection
Diffstat (limited to 'src/content/presenters')
-rw-r--r--src/content/presenters/ConsoleFramePresenter.ts31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/content/presenters/ConsoleFramePresenter.ts b/src/content/presenters/ConsoleFramePresenter.ts
index ccc196b..0db58f0 100644
--- a/src/content/presenters/ConsoleFramePresenter.ts
+++ b/src/content/presenters/ConsoleFramePresenter.ts
@@ -1,24 +1,43 @@
export default interface ConsoleFramePresenter {
- initialize(): void;
+ attach(): void;
+
+ detach(): void;
blur(): void;
resize(width: number, height: number): void;
+
+ isTopWindow(): boolean;
}
export class ConsoleFramePresenterImpl implements ConsoleFramePresenter {
- initialize(): void {
+ private static readonly IframeId = "vimvixen-console-frame" as const;
+
+ attach(): void {
+ const ele = document.getElementById("vimvixen-console-frame");
+ if (ele) {
+ return;
+ }
+
const iframe = document.createElement("iframe");
iframe.src = browser.runtime.getURL("build/console.html");
- iframe.id = "vimvixen-console-frame";
+ iframe.id = ConsoleFramePresenterImpl.IframeId;
iframe.className = "vimvixen-console-frame";
document.body.append(iframe);
}
+ detach(): void {
+ const ele = document.getElementById(ConsoleFramePresenterImpl.IframeId);
+ if (!ele) {
+ return;
+ }
+ ele.remove();
+ }
+
blur(): void {
const ele = document.getElementById("vimvixen-console-frame");
if (!ele) {
- throw new Error("console frame not created");
+ return;
}
ele.blur();
}
@@ -30,4 +49,8 @@ export class ConsoleFramePresenterImpl implements ConsoleFramePresenter {
}
ele.style.height = `${height}px`;
}
+
+ isTopWindow(): boolean {
+ return window.top === window;
+ }
}