1
0
Fork 0
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:
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 // 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) => {
console.log("mark clicked", e.target); var bounds = e.target.getBoundingClientRect();
var clientX = e.clientX;
if (clientX > bounds.right) {
console.log("mark clicked", e.target);
}
}); });
contents.window.getSelection().removeAllRanges(); contents.window.getSelection().removeAllRanges();

View file

@ -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) {

View file

@ -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