mirror of
https://github.com/Ellpeck/ObsidianCustomFrames.git
synced 2024-11-23 01:58:34 +01:00
Merge 3898f04c0e
into 56ec2ea4e2
This commit is contained in:
commit
9a9502420f
1 changed files with 17 additions and 9 deletions
26
src/frame.ts
26
src/frame.ts
|
@ -2,7 +2,6 @@ import { Platform } from "obsidian";
|
||||||
import { CustomFrameSettings, CustomFramesSettings, getId } from "./settings";
|
import { CustomFrameSettings, CustomFramesSettings, getId } from "./settings";
|
||||||
|
|
||||||
export class CustomFrame {
|
export class CustomFrame {
|
||||||
|
|
||||||
private readonly settings: CustomFramesSettings;
|
private readonly settings: CustomFramesSettings;
|
||||||
private readonly data: CustomFrameSettings;
|
private readonly data: CustomFrameSettings;
|
||||||
private frame: HTMLIFrameElement | any;
|
private frame: HTMLIFrameElement | any;
|
||||||
|
@ -14,8 +13,7 @@ export class CustomFrame {
|
||||||
|
|
||||||
create(parent: HTMLElement, additionalStyle: string = undefined, urlSuffix: string = undefined): void {
|
create(parent: HTMLElement, additionalStyle: string = undefined, urlSuffix: string = undefined): void {
|
||||||
let style = `padding: ${this.settings.padding}px;`;
|
let style = `padding: ${this.settings.padding}px;`;
|
||||||
if (additionalStyle)
|
if (additionalStyle) style += additionalStyle;
|
||||||
style += additionalStyle;
|
|
||||||
if (Platform.isDesktopApp && !this.data.forceIframe) {
|
if (Platform.isDesktopApp && !this.data.forceIframe) {
|
||||||
let frameDoc = parent.doc;
|
let frameDoc = parent.doc;
|
||||||
this.frame = frameDoc.createElement("webview");
|
this.frame = frameDoc.createElement("webview");
|
||||||
|
@ -24,7 +22,7 @@ export class CustomFrame {
|
||||||
this.frame.addEventListener("dom-ready", () => {
|
this.frame.addEventListener("dom-ready", () => {
|
||||||
this.frame.setZoomFactor(this.data.zoomLevel);
|
this.frame.setZoomFactor(this.data.zoomLevel);
|
||||||
this.frame.insertCSS(this.data.customCss);
|
this.frame.insertCSS(this.data.customCss);
|
||||||
this.frame.executeJavaScript(this.data.customJs)
|
this.frame.executeJavaScript(this.data.customJs);
|
||||||
});
|
});
|
||||||
this.frame.addEventListener("destroyed", () => {
|
this.frame.addEventListener("destroyed", () => {
|
||||||
// recreate the webview if it was moved to a new window
|
// recreate the webview if it was moved to a new window
|
||||||
|
@ -44,13 +42,23 @@ export class CustomFrame {
|
||||||
this.frame.addClass(`custom-frames-${getId(this.data)}`);
|
this.frame.addClass(`custom-frames-${getId(this.data)}`);
|
||||||
this.frame.setAttribute("style", style);
|
this.frame.setAttribute("style", style);
|
||||||
|
|
||||||
let src = this.data.url;
|
let src = new URL(this.data.url);
|
||||||
|
|
||||||
if (urlSuffix) {
|
if (urlSuffix) {
|
||||||
if (!urlSuffix.startsWith("/"))
|
let suffix = new URL(urlSuffix, src.origin);
|
||||||
src += "/";
|
|
||||||
src += urlSuffix;
|
suffix.searchParams.forEach((value, key) => {
|
||||||
|
src.searchParams.set(key, value);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (suffix.pathname !== "/") {
|
||||||
|
src.pathname += suffix.pathname;
|
||||||
}
|
}
|
||||||
this.frame.setAttribute("src", src);
|
|
||||||
|
src.hash = suffix.hash || src.hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.frame.setAttribute("src", src.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh(): void {
|
refresh(): void {
|
||||||
|
|
Loading…
Reference in a new issue