1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

Pass mark events from the rendition

This commit is contained in:
Fred Chasen 2017-04-27 15:38:09 -04:00
parent 1eb2566b15
commit ee2264b064
3 changed files with 18 additions and 3 deletions

View file

@ -69,8 +69,13 @@
// Apply a class to selected text
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);
}
});
contents.window.getSelection().removeAllRanges();

View file

@ -6,7 +6,7 @@ import {replaceLinks} from "./utils/replacements";
import { Pane, Highlight, Underline } from "marks-pane";
// 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 {
constructor(doc, content, cfiBase) {

View file

@ -555,6 +555,7 @@ class Rendition {
});
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);
}
/**
* 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
* @param {string} cfi EpubCfi String