Skip to content

Commit 0213b32

Browse files
authored
Merge pull request #1142 from cdrini/features/textsel-protected
Add protected option to text selection plugin
2 parents db907e5 + 9c08cf0 commit 0213b32

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/plugins/plugin.text_selection.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ export class TextSelectionPlugin extends BookReaderPlugin {
8282
$(window.getSelection().anchorNode).closest('.BRpagecontainer').addClass('BRpagecontainer--hasSelection');
8383
}
8484
}).attach();
85+
86+
if (this.br.protected) {
87+
// Prevent right clicking when selected text
88+
$(document.body).on('contextmenu dragstart copy', (e) => {
89+
const selection = document.getSelection();
90+
if (selection?.toString()) {
91+
const intersectsTextLayer = $('.BRtextLayer')
92+
.toArray()
93+
.some(el => selection.containsNode(el, true));
94+
if (intersectsTextLayer) {
95+
e.preventDefault();
96+
return false;
97+
}
98+
}
99+
});
100+
}
85101
}
86102

87103
/**

0 commit comments

Comments
 (0)