Looking for more instructions implementing hooks

313 views
Skip to first unread message

Carl-Arvid Ewerbring

unread,
Jan 30, 2014, 7:37:01 AM1/30/14
to epu...@googlegroups.com
Hey,

I would like to implement on hook, notifying me on which position the reader is at every time he/she turns the page.

Unfortunately, I cannot even seem to get the example at GitHub to work, where you add a hook to beforeChapterDisplayed.

I tried this code to my angularJS controller:
EPUBJS.Hooks.register("beforeChapterDisplay").example = function(callback, render) {

            console.log('Chapter chaaange ');
            if (callback) callback();
        }

But to no avail. Have any pointers you can give on how to implement a pageChanged hook?

Thanks

Carl-Arvid Ewerbring

unread,
Jan 31, 2014, 9:04:41 AM1/31/14
to epu...@googlegroups.com
To add information, this is what my EPUBJS objects look like after I ran the above mentioned code.

EPUBJS:: { "VERSION": "0.1.9", "plugins": {}, "filePath": "js/reading/", "core": {}, "Hooks": { "beforeChapterDisplay": {} }, "replace": {} }

I've tried fiddling around with this, and used the hooks 'book:pageChanged' and similar tactics, but no luck yet. Unfortunately, my JS skills are not up to reading the source code and figuring it out.

Thanks

Fred Chasen

unread,
Jan 31, 2014, 12:26:53 PM1/31/14
to epu...@googlegroups.com
The hooks are only used for when we want a bunch of things to complete before executing the next step. 
For now only "beforeChapterDisplay" uses them.

For what your are asking for, you can use the "renderer:pageChanged" event listener.

book.on("renderer:pageChanged", function(cfi) {
  console.log("at page:", cfi);
});

Let me know if that works for you.

- Fred

Carl-Arvid Ewerbring

unread,
Feb 2, 2014, 6:16:11 PM2/2/14
to epu...@googlegroups.com
Works great!

Thanks a bunch

Muhammad Hassan

unread,
Jan 4, 2015, 2:19:55 AM1/4/15
to epu...@googlegroups.com, caewe...@gmail.com
Works Perfectly for me Thanks :).
Reply all
Reply to author
Forward
0 new messages