mirror of
https://github.com/Ellpeck/ObsidianCustomFrames.git
synced 2024-11-24 18:28:35 +01:00
focus a frame's content when it gets opened
This commit is contained in:
parent
33f3407afe
commit
4340d08e29
4 changed files with 43 additions and 13 deletions
22
src/frame.ts
22
src/frame.ts
|
@ -12,7 +12,7 @@ export class CustomFrame {
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
public create(additionalStyle: string = undefined, urlSuffix: string = undefined): any {
|
||||
create(additionalStyle: string = undefined, urlSuffix: string = undefined): any {
|
||||
let style = `padding: ${this.settings.padding}px;`;
|
||||
if (additionalStyle)
|
||||
style += additionalStyle;
|
||||
|
@ -44,7 +44,7 @@ export class CustomFrame {
|
|||
return this.frame;
|
||||
}
|
||||
|
||||
public refresh(): void {
|
||||
refresh(): void {
|
||||
if (this.frame instanceof HTMLIFrameElement) {
|
||||
this.frame.contentWindow.location.reload();
|
||||
} else {
|
||||
|
@ -52,7 +52,7 @@ export class CustomFrame {
|
|||
}
|
||||
}
|
||||
|
||||
public return(): void {
|
||||
return(): void {
|
||||
if (this.frame instanceof HTMLIFrameElement) {
|
||||
this.frame.contentWindow.open(this.data.url);
|
||||
} else {
|
||||
|
@ -60,7 +60,7 @@ export class CustomFrame {
|
|||
}
|
||||
}
|
||||
|
||||
public goBack(): void {
|
||||
goBack(): void {
|
||||
if (this.frame instanceof HTMLIFrameElement) {
|
||||
this.frame.contentWindow.history.back();
|
||||
} else {
|
||||
|
@ -68,7 +68,7 @@ export class CustomFrame {
|
|||
}
|
||||
}
|
||||
|
||||
public goForward(): void {
|
||||
goForward(): void {
|
||||
if (this.frame instanceof HTMLIFrameElement) {
|
||||
this.frame.contentWindow.history.forward();
|
||||
} else {
|
||||
|
@ -76,7 +76,7 @@ export class CustomFrame {
|
|||
}
|
||||
}
|
||||
|
||||
public toggleDevTools(): void {
|
||||
toggleDevTools(): void {
|
||||
if (!(this.frame instanceof HTMLIFrameElement)) {
|
||||
if (!this.frame.isDevToolsOpened()) {
|
||||
this.frame.openDevTools();
|
||||
|
@ -86,7 +86,15 @@ export class CustomFrame {
|
|||
}
|
||||
}
|
||||
|
||||
public getCurrentUrl(): string {
|
||||
getCurrentUrl(): string {
|
||||
return this.frame instanceof HTMLIFrameElement ? this.frame.contentWindow.location.href : this.frame.getURL();
|
||||
}
|
||||
|
||||
focus(): void {
|
||||
if (this.frame instanceof HTMLIFrameElement) {
|
||||
this.frame.contentWindow.focus();
|
||||
} else {
|
||||
this.frame.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
src/main.ts
10
src/main.ts
|
@ -1,4 +1,4 @@
|
|||
import { Plugin, Platform } from "obsidian";
|
||||
import { Plugin, Platform, WorkspaceLeaf } from "obsidian";
|
||||
import { CustomFrame } from "./frame";
|
||||
import { CustomFramesSettings, defaultSettings, getIcon, getId } from "./settings";
|
||||
import { CustomFramesSettingTab } from "./settings-tab";
|
||||
|
@ -81,13 +81,17 @@ export default class CustomFramesPlugin extends Plugin {
|
|||
}
|
||||
|
||||
private async openLeaf(name: string, center: boolean, split: boolean): Promise<void> {
|
||||
let leaf: WorkspaceLeaf;
|
||||
if (center) {
|
||||
let leaf = this.app.workspace.getLeaf(split);
|
||||
leaf = this.app.workspace.getLeaf(split);
|
||||
await leaf.setViewState({ type: name, active: true });
|
||||
} else {
|
||||
if (!this.app.workspace.getLeavesOfType(name).length)
|
||||
await this.app.workspace.getRightLeaf(false).setViewState({ type: name, active: true });
|
||||
this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(name)[0]);
|
||||
leaf = this.app.workspace.getLeavesOfType(name)[0];
|
||||
this.app.workspace.revealLeaf(leaf);
|
||||
}
|
||||
if (leaf.view instanceof CustomFrameView)
|
||||
leaf.view.focus();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,10 @@ export class CustomFrameView extends ItemView {
|
|||
getIcon(): string {
|
||||
return getIcon(this.data);
|
||||
}
|
||||
|
||||
focus(): void {
|
||||
this.frame.focus();
|
||||
}
|
||||
}
|
||||
|
||||
interface Action {
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue