generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ts
92 lines (61 loc) · 2.81 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { App, Editor, MarkdownPostProcessorContext, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting } from 'obsidian';
import { getAPI, isPluginEnabled, DataviewAPI } from "obsidian-dataview";
import YearTimeline from "functionsYear";
import MonthTimeline from "functionsMonth";
import WeekTimeline from "functionsWeek";
import { ReleaseTimelineSettings, DEFAULT_SETTINGS, SampleSettingTab } from "settings";
export default class ReleaseTimeline extends Plugin {
settings: ReleaseTimelineSettings;
YearTimelineFunctions = new YearTimeline(this);
MonthTimelineFunctions = new MonthTimeline(this);
WeekTimelineFunctions = new WeekTimeline(this);
async onload() {
this.app.workspace.onLayoutReady( () => {
const isDataviewInstalled = !!getAPI();
if (!isDataviewInstalled) {
new Notice("The Release Timeline plugin requires Dataview to properly function.");
}
});
await this.loadSettings();
console.log("loading obsidian-release-timeline");
this.addSettingTab(new SampleSettingTab(this.app, this));
this.registerMarkdownCodeBlockProcessor('release-timeline', async (content: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
let timelineTable = await this.YearTimelineFunctions.renderTimeline(content);
//render
el.appendChild(timelineTable);
let bulletOption = this.settings.bulletPoints;
let matches = el.querySelectorAll(".td-first, .td-next");
matches.forEach(function(match) {
match.classList.toggle('bullet-points', bulletOption);
});
});
this.registerMarkdownCodeBlockProcessor('release-timeline-month', async (content: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
let timelineTable = await this.MonthTimelineFunctions.renderTimelineMonth(content);
//render
el.appendChild(timelineTable);
let bulletOption = this.settings.bulletPoints;
let matches = el.querySelectorAll(".td-first, .td-next");
matches.forEach(function(match) {
match.classList.toggle('bullet-points', bulletOption);
});
});
this.registerMarkdownCodeBlockProcessor('release-timeline-week', async (content: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
let timelineTable = await this.WeekTimelineFunctions.renderTimelineWeek(content);
//render
el.appendChild(timelineTable);
let bulletOption = this.settings.bulletPoints;
let matches = el.querySelectorAll(".td-next");
matches.forEach(function(match) {
match.classList.toggle('bullet-points', bulletOption);
});
});
}
onunload() {
}
async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}
async saveSettings() {
await this.saveData(this.settings);
}
}