Skip to content

Commit 698666c

Browse files
authored
feat(Watermark): add data-bb-watermark attribute (#5825)
* refactor: 增加全局水印时移动到文档根节点逻辑 * refactor: 增加变量保护 * refactor: 完善 dispose 逻辑防止 dom 残留
1 parent 2e2e2b9 commit 698666c

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/BootstrapBlazor/Components/Watermark/Watermark.razor.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ export function dispose(id) {
4141
Data.remove(id);
4242

4343
if (watermark) {
44-
const { ob } = watermark;
44+
const { el, ob } = watermark;
4545
ob.disconnect();
4646

4747
delete watermark.ob;
48+
document.body.removeAttribute('data-bb-watermark');
49+
el.remove();
4850
}
4951
}
5052

@@ -102,13 +104,13 @@ const createWatermark = watermark => {
102104
if (mark) {
103105
mark.remove();
104106
}
107+
el.appendChild(div);
105108

106-
if (bg.isPage) {
107-
document.body.appendChild(div);
108-
}
109-
else {
110-
el.appendChild(div);
109+
if (options.isPage) {
110+
document.body.setAttribute('data-bb-watermark', "true");
111+
document.body.appendChild(el);
111112
}
113+
112114
options.bg = bg;
113115
requestAnimationFrame(() => monitor(watermark));
114116
}
@@ -179,8 +181,12 @@ const monitor = watermark => {
179181

180182
const clearWatermark = watermark => {
181183
const { el, ob } = watermark;
182-
ob.disconnect();
183-
el.innerHTML = '';
184+
if (ob) {
185+
ob.disconnect();
186+
}
187+
if (el) {
188+
el.innerHTML = '';
189+
}
184190
}
185191

186192
const getWatermark = props => {

0 commit comments

Comments
 (0)