Custom events on book content

127 views
Skip to first unread message

Mateusz Wilk

unread,
Jun 7, 2015, 1:18:53 PM6/7/15
to epu...@googlegroups.com
Hello,

So I've studied all library today, and presumably I'll be using your library in my project.

Let's say I want to trigger an event on text selection. 

How do I add custom events on book content ? 

Let's say I have a backbone application inside which epub.js is displayed.
Now I want to add an event which will be listened by Backbone and I would like to call Backbone.listenTo function after this event on book content is triggered

Any help appreciated

Thanks!

Cyril Canete

unread,
Jul 29, 2015, 5:13:21 AM7/29/15
to epubjs, mate...@gmail.com
Hi!

Have you found a solution for listen those events ?
I'm looking for the same answer!

Thanks;
Cyril

Mateusz Wilk

unread,
Jul 30, 2015, 3:08:02 PM7/30/15
to epubjs, cyril....@gmail.com
Hello,

Yes, it's fairly easy, if you don't mind, I will give you links to my repository, with a bit of explanation.

So I have a backbone view which looks like this:


In this view I'm requiring ePub library.
Than in initialize method I'm creating new instance of the library with the given book url.

Than in render method, I'm just appending the div to which the book was attached and I'm rendering the view.

if you take a look at the beginning of the file you will notice this line : selection = require('epubhooks/selection');

this is the file when I'm keeping my event and it looks like this


The basic concept of ePub library, is that you are able to append any event on beforeChapterDisplay event.

So every time, I'm turning the page in the book (the name of the beforechapeterdisplay can be a bit misleading), I'm attaching new event to the body (look at epubhooks/selection file)

I'm sorry I can't show you the live example, but I haven't deployed mongodb on heroku, but you can form my repo and test it locally.

Ping me if you have any more questions.

Regards!
Mateusz 
Reply all
Reply to author
Forward
0 new messages