Skip to content

Commit 75d6d9f

Browse files
committed
added the ability to display the frame in the center
1 parent 5d3254e commit 75d6d9f

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ An Obsidian plugin that turns web apps into panes using iframes with custom styl
33

44
⚠️⚠️⚠️ **For header-heavy sites like Google Keep and Todoist to work, this plugin requires Obsidian 0.14.3.** ⚠️⚠️⚠️
55

6-
![A screenshot of the plugin in action](https://raw.githubusercontent.com/Ellpeck/ObsidianCustomFrames/master/screenshot.png)
6+
![A screenshot of the plugin in action, where you can see Google Keep attached as a narrow side pane on the right](https://raw.githubusercontent.com/Ellpeck/ObsidianCustomFrames/master/screenshot.png)
7+
8+
![A screenshot of the plugin in action, where you can see Google Calendar opened in the center, and the mouse hovering over the corresponding ribbon button](https://raw.githubusercontent.com/Ellpeck/ObsidianCustomFrames/master/screenshot-big.png)
79

810
![A screenshot of the plugin's settings](https://raw.githubusercontent.com/Ellpeck/ObsidianCustomFrames/master/settings.png)
911

1012
## 🤔 Usage
1113
To use this plugin, simply go into its settings and add a new frame, either from a preset shipped with the plugin, or a custom one that you can edit yourself. Each frame's pane can be opened using the "Custom Frames: Open" command.
1214

15+
There are also plenty of settings to customize your frame further, including adding custom CSS to the site, adding a ribbon icon, displaying the frame in the center of the editor, and more.
16+
1317
### 🗒️ Markdown Mode
1418
You can also display your custom frames in your Markdown documents. Custom Frames adds a special code block syntax that transforms the code block into a custom frame in Live Preview and Reading mode. Your code block should look like this:
1519
~~~

screenshot-big.png

123 KB
Loading

src/main.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export default class CustomFramesPlugin extends Plugin {
2626
this.addCommand({
2727
id: `open-${name}`,
2828
name: `Open ${frame.displayName}`,
29-
callback: () => this.openLeaf(name),
29+
callback: () => this.openLeaf(name, frame.openInCenter),
3030
});
3131

3232
if (frame.addRibbonIcon)
33-
this.addRibbonIcon(getIcon(frame), `Open ${frame.displayName}`, () => this.openLeaf(name));
33+
this.addRibbonIcon(getIcon(frame), `Open ${frame.displayName}`, () => this.openLeaf(name, frame.openInCenter));
3434
} catch {
3535
console.error(`Couldn't register frame ${name}, is there already one with the same name?`);
3636
}
@@ -75,9 +75,15 @@ export default class CustomFramesPlugin extends Plugin {
7575
await this.saveData(this.settings);
7676
}
7777

78-
private async openLeaf(name: string): Promise<void> {
79-
if (!this.app.workspace.getLeavesOfType(name).length)
80-
await this.app.workspace.getRightLeaf(false).setViewState({ type: name });
78+
private async openLeaf(name: string, center: boolean): Promise<void> {
79+
if (center) {
80+
this.app.workspace.detachLeavesOfType(name);
81+
await this.app.workspace.getUnpinnedLeaf().setViewState({ type: name });
82+
}
83+
else {
84+
if (!this.app.workspace.getLeavesOfType(name).length)
85+
await this.app.workspace.getRightLeaf(false).setViewState({ type: name });
86+
}
8187
this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(name)[0]);
8288
}
8389
}

src/settings-tab.ts

+11
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ export class CustomFramesSettingTab extends PluginSettingTab {
101101
await this.plugin.saveSettings();
102102
});
103103
});
104+
new Setting(content)
105+
.setName("Open in Center")
106+
.setDesc("Whether this frame should be opened in the unpinned center editor rather than one of the panes on the side. This is useful for sites that don't work well in a narrow view, or sites that don't require a note to be open when viewed.")
107+
.addToggle(t => {
108+
t.setValue(frame.openInCenter);
109+
t.onChange(async v => {
110+
frame.openInCenter = v;
111+
await this.plugin.saveSettings();
112+
});
113+
});
104114
new Setting(content)
105115
.setName("Page Zoom")
106116
.setDesc("The zoom that this frame's page should be displayed with, as a percentage.")
@@ -159,6 +169,7 @@ export class CustomFramesSettingTab extends PluginSettingTab {
159169
icon: "",
160170
hideOnMobile: true,
161171
addRibbonIcon: false,
172+
openInCenter: false,
162173
zoomLevel: 1,
163174
customCss: ""
164175
});

src/settings.ts

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const presets: Record<string, CustomFrameSettings> = {
99
icon: "edit",
1010
hideOnMobile: true,
1111
addRibbonIcon: true,
12+
openInCenter: true,
1213
zoomLevel: 1,
1314
customCss: ""
1415
},
@@ -18,6 +19,7 @@ export const presets: Record<string, CustomFrameSettings> = {
1819
icon: "calendar",
1920
hideOnMobile: true,
2021
addRibbonIcon: true,
22+
openInCenter: true,
2123
zoomLevel: 1,
2224
customCss: `/* hide right-side menu, and some buttons */
2325
div.d6McF,
@@ -36,6 +38,7 @@ div.dwlvNd {
3638
icon: "files",
3739
hideOnMobile: true,
3840
addRibbonIcon: false,
41+
openInCenter: false,
3942
zoomLevel: 1,
4043
customCss: `/* hide the menu bar and the "Keep" text */
4144
html > body > div:nth-child(2) > div:nth-child(2) > div:first-child,
@@ -49,6 +52,7 @@ html > body > div:first-child > header:first-child > div > div:first-child > div
4952
icon: "list-checks",
5053
hideOnMobile: true,
5154
addRibbonIcon: false,
55+
openInCenter: false,
5256
zoomLevel: 1,
5357
customCss: `/* hide the help, home, search, and productivity overview buttons, create extra space, and prevent toast pop-up from acting weird */
5458
[aria-label="Go to Home view"], #quick_find, [aria-label="Productivity"], [aria-label="Help & Feedback"] {
@@ -74,6 +78,7 @@ html > body > div:first-child > header:first-child > div > div:first-child > div
7478
icon: "box",
7579
hideOnMobile: true,
7680
addRibbonIcon: true,
81+
openInCenter: true,
7782
zoomLevel: 1,
7883
customCss: ""
7984
},
@@ -83,6 +88,7 @@ html > body > div:first-child > header:first-child > div > div:first-child > div
8388
icon: "twitter",
8489
hideOnMobile: true,
8590
addRibbonIcon: false,
91+
openInCenter: false,
8692
zoomLevel: 1,
8793
customCss: ""
8894
}
@@ -99,6 +105,7 @@ export interface CustomFrameSettings {
99105
icon: string;
100106
hideOnMobile: boolean;
101107
addRibbonIcon: boolean;
108+
openInCenter: boolean;
102109
zoomLevel: number;
103110
customCss: string;
104111
}

0 commit comments

Comments
 (0)