3

I have developed a library (which I will release under BSD/MIT license soon) to simulate Media Overlay support (aka "read aloud" or "SMIL") for reflowable EPUB3 eBooks in Apple iBooks. (I remind you that iBooks supports MO only in FXL layout mode, unlike Readium or Azardi.)

I would like to make iBooks "turn" page when the current active SMIL fragment leaves the current page and goes to the next one. To do so, I need to:

1) realize that the active fragment has gone outside the current page, and 2) force a page turn.

The first point can be (cumbersomely) achieved by computing the SMIL element offset; I am stuck at performing 2).

In Apple's ibooks.js there is nothing helpful, and injecting TouchEvent's does not seem to work, because they are reported to the active document and not to the "host WebKit".

Any ideas how to make iBooks turn page from within a JS loaded by the currently displayed EPUB3 reflowable ebook?

EDIT: following this question up, I released the aforementioned JS here: https://github.com/pettarin/rb_smil_emulator

Alberto Pettarin
  • 894
  • 6
  • 12

1 Answers1

1

If you are talking about progressing to the next XHTML document, then it should be adequate to simply do

location.href="nextpage.xhtml";

If you are talking about moving within the same XHTML document, then the best you can do is to somehow identify the location within that page using an ID'd element, and jump to it:

location.href="#id";

There is no way that I am aware of to simply execute/simulate a page turn.

  • I was asking for the second one, and your suggested approach works perfectly! (I am a bit ashamed by the fact I did not think about it... although I am not a JS expert at all!) Identifying the landing element is not a problem, because each SMIL fragment has its own id, and the JS knows them all. I accept this answer, and thank you for posting it! – Alberto Pettarin Jun 06 '13 at 16:13
  • Unfortunately, every time location.href is reset, iBooks produces the (IMHO, nasty) page flip effect. Otherwise, it would be the perfect solution to my problem, even avoiding computing whether the page should be actually "changed or not". Additionally, setting location.href breaks Readium pagination down. Hence, I released my JS with the autoturn page option off by default. – Alberto Pettarin Jun 11 '13 at 10:32
  • What you need to do is determine if the anchor in question is already on the current page, and execute the `location.href` only if it is not. You want to compare `elt.getBoundingClientRect.top` with `document.documentElement.scrollTop`, and same for bottom, left and right. –  Jun 12 '13 at 07:05
  • Follow up: starting from torazaburo's suggestion, and with some help from Frank Chen, I managed to decently implement the turn page feature in my JS library. Please go to https://github.com/pettarin/rb_smil_emulator to inspect the code. It is specifically enabled for iBooks only, because setting location.href breaks Readium pagination down. Thanks to everybody who contributed ideas and code. – Alberto Pettarin Sep 12 '13 at 12:47