2023-05-06 11:29:46 +08:00
|
|
|
import {App} from "../index";
|
2023-05-07 17:31:50 +08:00
|
|
|
import {EventBus} from "./EventBus";
|
2023-05-04 18:28:57 +08:00
|
|
|
|
2023-05-06 11:29:46 +08:00
|
|
|
export class Plugin {
|
|
|
|
|
public i18n: IObject;
|
2023-05-07 17:31:50 +08:00
|
|
|
public eventBus: EventBus;
|
2023-05-04 18:28:57 +08:00
|
|
|
|
2023-05-06 11:29:46 +08:00
|
|
|
constructor(options: {
|
|
|
|
|
app: App,
|
|
|
|
|
id: string,
|
2023-05-07 17:31:50 +08:00
|
|
|
name: string,
|
2023-05-06 11:29:46 +08:00
|
|
|
i18n: IObject
|
|
|
|
|
}) {
|
|
|
|
|
this.i18n = options.i18n;
|
2023-05-07 17:31:50 +08:00
|
|
|
this.eventBus = new EventBus(options.name);
|
2023-05-04 18:28:57 +08:00
|
|
|
}
|
|
|
|
|
|
2023-05-08 10:56:52 +08:00
|
|
|
public addTopBar(options: {
|
|
|
|
|
icon: string,
|
|
|
|
|
title: string,
|
|
|
|
|
position: "right",
|
|
|
|
|
callback: (evt: MouseEvent) => void
|
|
|
|
|
}) {
|
|
|
|
|
const iconElement = document.createElement("div");
|
|
|
|
|
iconElement.className = "toolbar__item b3-tooltips b3-tooltips__sw";
|
|
|
|
|
iconElement.setAttribute("aria-label", options.title);
|
2023-05-08 12:35:56 +08:00
|
|
|
iconElement.setAttribute("data-menu", "true");
|
2023-05-08 10:56:52 +08:00
|
|
|
iconElement.innerHTML = options.icon.startsWith("icon") ? `<svg><use xlink:href="#${options.icon}"></use></svg>` : options.icon;
|
|
|
|
|
iconElement.addEventListener("click", options.callback);
|
|
|
|
|
document.querySelector("#" + (options.position === "right" ? "barSearch" : "drag")).before(iconElement);
|
|
|
|
|
return iconElement;
|
2023-05-04 18:28:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onload() {
|
2023-05-05 14:04:43 +08:00
|
|
|
console.log("Hello, world!");
|
2023-05-04 18:28:57 +08:00
|
|
|
}
|
|
|
|
|
}
|