Skip to content

Commit ae34082

Browse files
committed
💄 双击非弹窗部分,关闭弹窗 #25
1 parent 090b013 commit ae34082

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

src/index.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,34 @@ class FootnoteDialog {
9494
document.addEventListener('mousemove', this.drag.bind(this));
9595
document.addEventListener('mouseup', this.stopDragging.bind(this));
9696

97-
// Add close button handler
97+
// 添加关闭按钮事件
9898
this.dialog.querySelector('.close-button').addEventListener('click', () => {
9999
this.dialog.close();
100100
this.dialog.remove();
101+
document.removeEventListener('dblclick', this.handleOutsideDoubleClick);
101102
});
102103

104+
// 添加在弹窗外双击关闭弹窗的事件监听
105+
document.addEventListener('dblclick', this.handleOutsideDoubleClick);
106+
103107
this.dialog.addEventListener('close', () => {
104108
this.dialog.remove();
109+
document.removeEventListener('dblclick', this.handleOutsideDoubleClick);
105110
});
106111

107112
this.dialog.show();
113+
}
108114

109-
115+
// 处理在弹窗外双击的事件
116+
private handleOutsideDoubleClick = (event: MouseEvent) => {
117+
if (!this.dialog.contains(event.target as Node)) {
118+
this.dialog.close();
119+
this.dialog.remove();
120+
document.removeEventListener('dblclick', this.handleOutsideDoubleClick);
121+
}
110122
}
111123

124+
112125
private startDragging(e: MouseEvent) {
113126
this.isDragging = true;
114127
const rect = this.dialog.getBoundingClientRect();
@@ -219,21 +232,41 @@ class FootnoteDialog2 {
219232
document.addEventListener('mousemove', this.drag.bind(this));
220233
document.addEventListener('mouseup', this.stopDragging.bind(this));
221234

235+
236+
222237
this.dialog.addEventListener('close', () => {
223238
onSubmit(this.textarea.value);
224239
this.dialog.remove();
240+
// 移除全局双击事件监听器
241+
document.removeEventListener('dblclick', this.handleOutsideDoubleClick);
225242
});
226-
// Add close button handler
243+
244+
// 添加在弹窗外双击关闭弹窗的事件监听
245+
document.addEventListener('dblclick', this.handleOutsideDoubleClick);
246+
247+
// 添加关闭按钮事件
227248
this.dialog.querySelector('.close-button').addEventListener('click', () => {
228249
onSubmit(this.textarea.value);
229250
this.dialog.close();
230251
this.dialog.remove();
252+
// 移除全局双击事件监听器
253+
document.removeEventListener('dblclick', this.handleOutsideDoubleClick);
231254
});
232255

233256
this.dialog.showModal();
234257
this.textarea.focus();
235258
}
236259

260+
// 处理在弹窗外双击的事件
261+
private handleOutsideDoubleClick = (event: MouseEvent) => {
262+
if (!this.dialog.contains(event.target as Node)) {
263+
this.dialog.close();
264+
this.dialog.remove();
265+
// 移除全局双击事件监听器
266+
document.removeEventListener('dblclick', this.handleOutsideDoubleClick);
267+
}
268+
}
269+
237270
private startDragging(e: MouseEvent) {
238271
this.isDragging = true;
239272
const rect = this.dialog.getBoundingClientRect();
@@ -288,6 +321,15 @@ export default class PluginFootnote extends Plugin {
288321
.protyle-wysiwyg [data-node-id] span[data-type*="custom-footnote-selected-text"] {
289322
border-bottom: 2px dashed var(--b3-font-color5);
290323
}
324+
/* 导出pdf脚注引用为上标样式 */
325+
.b3-typography a[custom-footnote],
326+
#preview .protyle-wysiwyg a[custom-footnote] {
327+
top: -0.5em;
328+
font-size: 75%;
329+
line-height: 0;
330+
vertical-align: baseline;
331+
position: relative;
332+
}
291333
292334
/* 自定义脚注内容块样式 */
293335
/* 脚注内容块如果设置为横排超级块则减少间距 */

0 commit comments

Comments
 (0)