Skip to content

Commit

Permalink
:refactor: #1348
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanessa219 committed Jan 15, 2023
1 parent 6da6b67 commit 4ccd6fc
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Vditor change log

### 升级
* 3.9
* 添加 option.link
* 3.8
* 添加 plantumlRender 方法
* options.input 移除 previewElement 参数
Expand Down Expand Up @@ -105,6 +107,7 @@

### v3.9.0 / 2023-01

* [1348](https://github.com/Vanessa219/vditor/pull/1348) 新增链接和图片处理接口 `引入特性`
* [1342](https://github.com/Vanessa219/vditor/pull/1342) 初始化后不自动聚焦 `改进功能`
* [1341](https://github.com/Vanessa219/vditor/pull/1341) 支持 markmap `引入特性`
* [1335](https://github.com/Vanessa219/vditor/issues/1335) 嵌入 Iframe 时无法导出 PDF `修复缺陷`
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,11 @@ previewImage: (img: HTMLImageElement) => void;
对原图片双击预览的拦截,对图片的扩展操作。

#### options.link
``` ts
link?: {
open?: boolean;
trigger?: (href: string) => void;
}
```

| | 说明 | 默认值 |
| - | - | - |
| open | 是否点击打开(window.open)地址 | - |
| trigger | 地址点击触发 | - |
| open | 是否打开链接地址 | true |
| trigger(bom: Element) => void | 点击链接触发事件 | - |

#### options.hint

Expand Down
7 changes: 7 additions & 0 deletions README_en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,13 @@ Default: ["desktop", "tablet", "mobile", "mp-wechat", "zhihu"]
| className | Button Class | - |
| click(key: string) | Click Event | - |

#### options.link

| | Explanation | Default |
| - | - | - |
| open | Whether to open the link address | true |
| trigger(bom: Element) => void | Click link trigger event | - |

#### options.hint

| | Explanation | Default |
Expand Down
6 changes: 6 additions & 0 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const initVditor = (language) => {
cdn: 'http://localhost:9000',
toolbar,
lang: language,
link: {
open: false,
trigger(bom){
console.log(bom)
}
},
mode: 'wysiwyg',
height: window.innerHeight + 100,
outline: {
Expand Down
13 changes: 6 additions & 7 deletions src/ts/ir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ class IR {
if (this.preventInput) {
this.preventInput = false;
processAfterRender(vditor, {
enableAddUndoStack: true,
enableHint: true,
enableInput: true,
enableAddUndoStack: true,
enableHint: true,
enableInput: true,
});
return;
}
Expand Down Expand Up @@ -149,10 +149,9 @@ class IR {
// 打开链接
const aElement = hasClosestByAttribute(event.target, "data-type", "a");
if (aElement && (!aElement.classList.contains("vditor-ir__node--expand"))) {
if (vditor.options.link && vditor.options.link.trigger) {
vditor.options.link.trigger(aElement.querySelector(":scope > .vditor-ir__marker--link").textContent);
}
if (vditor.options.link && vditor.options.link.open) {
if (vditor.options.link.trigger) {
vditor.options.link.trigger(aElement.querySelector(":scope > .vditor-ir__marker--link"));
} else if (vditor.options.link.open) {
window.open(aElement.querySelector(":scope > .vditor-ir__marker--link").textContent);
}
return;
Expand Down
3 changes: 3 additions & 0 deletions src/ts/util/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class Options {
mode: "both",
theme: Constants.THEME_OPTIONS,
},
link: {
open: true,
},
resize: {
enable: false,
position: "bottom",
Expand Down
8 changes: 7 additions & 1 deletion src/ts/wysiwyg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,13 @@ class WYSIWYG {

// 打开链接
if (event.target.tagName === "A") {
window.open(event.target.getAttribute("href"));
if (vditor.options.link.trigger) {
vditor.options.link.trigger(event.target);
} else if (vditor.options.link.open) {
window.open(event.target.getAttribute("href"));
}
event.preventDefault();
return;
}

const range = getEditorRange(vditor);
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ interface IOptions {
previewImage?: (img: HTMLImageElement) => void;
link?: {
open?: boolean;
trigger?: (href: string) => void;
trigger?: (bom: Element) => void;
},
/** @link https://ld246.com/article/1549638745630#options-hint */
hint?: IHint;
Expand Down

0 comments on commit 4ccd6fc

Please sign in to comment.