1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

mouseover & mouseenter POC

This commit is contained in:
Do Park 2023-10-28 11:39:47 -07:00
parent f09089cf77
commit 83b0f7755f
4 changed files with 9857 additions and 9 deletions

View file

@ -115,11 +115,27 @@
// Apply a class to selected text // Apply a class to selected text
rendition.on("selected", function(cfiRange, contents) { rendition.on("selected", function(cfiRange, contents) {
rendition.annotations.highlight(cfiRange, {}, (e) => { rendition.annotations.highlight(cfiRange, {},
(e) => {
console.log("highlight clicked", e.target); console.log("highlight clicked", e.target);
}); },
(e) => {
console.log("highlight mouseover", e.target);
}
);
contents.window.getSelection().removeAllRanges(); contents.window.getSelection().removeAllRanges();
// const highlights = document.querySelectorAll('g')
// console.log('highlights', highlights)
// highlights.forEach((highlight) => {
// highlight.addEventListener('mouseover', (e) => {
// console.log('highlight hover', e.target)
// })
// highlight.addEventListener('click',(e)=>{
// console.log('custom click', e.target)
// })
// })
}); });
this.rendition.themes.default({ this.rendition.themes.default({

View file

@ -603,17 +603,34 @@ class IframeView {
return this.elementBounds; return this.elementBounds;
} }
highlight(cfiRange, data={}, cb, className = "epubjs-hl", styles = {}) { highlight(cfiRange, data={}, cb, cb2, className = "epubjs-hl", styles = {}) {
if (!this.contents) { if (!this.contents) {
return; return;
} }
const attributes = Object.assign({"fill": "yellow", "fill-opacity": "0.3", "mix-blend-mode": "multiply"}, styles); const attributes = Object.assign({"fill": "yellow", "fill-opacity": "0.3", "mix-blend-mode": "multiply"}, styles);
let range = this.contents.range(cfiRange); let range = this.contents.range(cfiRange);
let emitter = () => { const onMount = (container) => {
container.style.pointerEvents = "all";
};
const onEject = (container) => {
// container.style.pointerEvents = "none";
};
const emitOnClick = () => {
this.emit(EVENTS.VIEWS.MARK_CLICKED, cfiRange, data); this.emit(EVENTS.VIEWS.MARK_CLICKED, cfiRange, data);
}; };
const emitOnMouseOver = (el) => {
this.emit(EVENTS.VIEWS.MARK_HOVERED, cfiRange, data);
onMount(el);
};
const emitOnMouseOut = (el) => {
onEject(el);
};
data["epubcfi"] = cfiRange; data["epubcfi"] = cfiRange;
if (!this.pane) { if (!this.pane) {
@ -623,15 +640,19 @@ class IframeView {
let m = new Highlight(range, className, data, attributes); let m = new Highlight(range, className, data, attributes);
let h = this.pane.addMark(m); let h = this.pane.addMark(m);
this.highlights[cfiRange] = { "mark": h, "element": h.element, "listeners": [emitter, cb] }; this.highlights[cfiRange] = { "mark": h, "element": h.element, "listeners": [emitOnClick, cb, cb2] };
h.element.setAttribute("ref", className); h.element.setAttribute("ref", className);
h.element.addEventListener("click", emitter); h.element.addEventListener("click", emitOnClick);
h.element.addEventListener("touchstart", emitter); h.element.addEventListener("touchstart", emitOnClick);
h.element.addEventListener("mouseover", emitOnMouseOver(this.pane.element));
h.element.addEventListener("mouseout", emitOnMouseOut(this.pane.element));
if (cb) { if (cb) {
h.element.addEventListener("click", cb); h.element.addEventListener("click", cb);
h.element.addEventListener("touchstart", cb); h.element.addEventListener("touchstart", cb);
h.element.addEventListener("mouseover", cb2);
h.element.addEventListener("mouseout", ()=>{console.log('mouse is out');});
} }
return h; return h;
} }

View file

@ -1,7 +1,7 @@
export const EPUBJS_VERSION = "0.3"; export const EPUBJS_VERSION = "0.3";
// Dom events to listen for // Dom events to listen for
export const DOM_EVENTS = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "mousemove", "click", "touchend", "touchstart", "touchmove"]; export const DOM_EVENTS = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "mousemove", "click", "touchend", "touchstart", "touchmove", "mouseover", "mouseenter"];
export const EVENTS = { export const EVENTS = {
BOOK : { BOOK : {
@ -35,7 +35,8 @@ export const EVENTS = {
DISPLAYED : "displayed", DISPLAYED : "displayed",
SHOWN : "shown", SHOWN : "shown",
HIDDEN : "hidden", HIDDEN : "hidden",
MARK_CLICKED : "markClicked" MARK_CLICKED : "markClicked",
MARK_HOVERED: "markHovered"
}, },
RENDITION : { RENDITION : {
STARTED : "started", STARTED : "started",

9810
yarn.lock Normal file

File diff suppressed because it is too large Load diff