Skip to content

Commit

Permalink
🎨 fix #1627
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed May 28, 2024
1 parent b3a14d6 commit ba20e38
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
* 添加 hljs.defaultLang
* 添加 hljs.renderMenu
* 添加 preview.render.media.enable
* 添加 updateToolbarConfig

### TODO

* [open issues](https://github.com/Vanessa219/vditor/issues)

### v3.10.5 / 2024-05

* [添加 `updateToolbarConfig` 方法](https://github.com/Vanessa219/vditor/issues/1627) `引入特性`

### v3.10.4 / 2024-04-16

* [移动端支持划选阅读](https://github.com/Vanessa219/vditor/issues/1611) `改进功能`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ if (xhr.status === 200) {
| hlCommentIds(ids: string[]) | 高亮评论 |
| unHlCommentIds(ids: string[]) | 取消评论高亮 |
| removeCommentIds(removeIds: string[]) | 删除评论 |
| updateToolbarConfig(config: {hide?: boolean, pin?: boolean}) | 更新工具栏配置 |

#### static methods

Expand Down
1 change: 1 addition & 0 deletions README_en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ xhr.send(JSON.stringify({url: src})); // src is the address of the image outside
| hlCommentIds(ids: string[]) | Highlight comment by Ids |
| unHlCommentIds(ids: string[]) | Cancel highlight comment by Ids |
| removeCommentIds(removeIds: string[]) | Remove comment by Ids |
| updateToolbarConfig(config: {hide?: boolean, pin?: boolean}) | Update toolbar config |

#### static methods

Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class Vditor extends VditorMethod {
tip.show(error, 0)
}

public updateToolbarConfig(options: IToolbarConfig) {
this.vditor.toolbar.updateConfig(this.vditor, options);
}

/** 设置主题 */
public setTheme(
theme: "dark" | "classic",
Expand Down
17 changes: 17 additions & 0 deletions src/ts/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ export class Toolbar {
}
}

public updateConfig(vditor: IVditor, options: IToolbarConfig) {
vditor.options.toolbarConfig = Object.assign({
hide: false,
pin: false,
}, options);
if (vditor.options.toolbarConfig.hide) {
this.element.classList.add("vditor-toolbar--hide");
} else {
this.element.classList.remove("vditor-toolbar--hide");
}
if (vditor.options.toolbarConfig.pin) {
this.element.classList.add("vditor-toolbar--pin");
} else {
this.element.classList.remove("vditor-toolbar--pin");
}
}

private genItem(vditor: IVditor, menuItem: IMenuItem, index: number) {
let menuItemObj;
switch (menuItem.name) {
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ interface IVditor {
toolbar?: {
elements?: { [key: string]: HTMLElement },
element?: HTMLElement,
updateConfig(vditor: IVditor, options: IToolbarConfig): void,
};
preview?: {
element: HTMLElement,
Expand Down

0 comments on commit ba20e38

Please sign in to comment.