mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Pass mark events from the rendition
This commit is contained in:
parent
1eb2566b15
commit
ee2264b064
3 changed files with 18 additions and 3 deletions
|
@ -69,8 +69,13 @@
|
||||||
// Apply a class to selected text
|
// Apply a class to selected text
|
||||||
rendition.on("selected", function(cfiRange, contents) {
|
rendition.on("selected", function(cfiRange, contents) {
|
||||||
|
|
||||||
contents.mark(cfiRange, {'something' : true}, (e) => {
|
var m = contents.mark(cfiRange, {'something' : true}, (e) => {
|
||||||
|
var bounds = e.target.getBoundingClientRect();
|
||||||
|
var clientX = e.clientX;
|
||||||
|
|
||||||
|
if (clientX > bounds.right) {
|
||||||
console.log("mark clicked", e.target);
|
console.log("mark clicked", e.target);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
contents.window.getSelection().removeAllRanges();
|
contents.window.getSelection().removeAllRanges();
|
||||||
|
|
|
@ -6,7 +6,7 @@ import {replaceLinks} from "./utils/replacements";
|
||||||
import { Pane, Highlight, Underline } from "marks-pane";
|
import { Pane, Highlight, Underline } from "marks-pane";
|
||||||
|
|
||||||
// Dom events to listen for
|
// Dom events to listen for
|
||||||
const EVENTS = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click", "touchend", "touchstart", "markClicked"];
|
const EVENTS = ["keydown", "keyup", "keypressed", "mouseup", "mousedown", "click", "touchend", "touchstart"];
|
||||||
|
|
||||||
class Contents {
|
class Contents {
|
||||||
constructor(doc, content, cfiBase) {
|
constructor(doc, content, cfiBase) {
|
||||||
|
|
|
@ -555,6 +555,7 @@ class Rendition {
|
||||||
});
|
});
|
||||||
|
|
||||||
contents.on("selected", (e) => this.triggerSelectedEvent(e, contents));
|
contents.on("selected", (e) => this.triggerSelectedEvent(e, contents));
|
||||||
|
contents.on("markClicked", (cfiRange, data) => this.triggerMarkEvent(cfiRange, data, contents));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -575,6 +576,15 @@ class Rendition {
|
||||||
this.emit("selected", cfirange, contents);
|
this.emit("selected", cfirange, contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emit a markClicked event with the cfiRange and data from a mark
|
||||||
|
* @private
|
||||||
|
* @param {EpubCFI} cfirange
|
||||||
|
*/
|
||||||
|
triggerMarkEvent(cfiRange, data, contents){
|
||||||
|
this.emit("markClicked", cfiRange, data, contents);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Range from a Visible CFI
|
* Get a Range from a Visible CFI
|
||||||
* @param {string} cfi EpubCfi String
|
* @param {string} cfi EpubCfi String
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue