View Full Version : Including jQuery in an ePUB3.0 eBook


tincanbot
02-27-2013, 04:40 PM
Because ePUB3.0 supports JavaScript, I'm wondering if it's also possible to embed the jQuery source in eBooks so it's possible to include jQuery scripting. I haven't the faintest idea of how to go about this. Is it even possible?

Thank you!

AlPe
02-27-2013, 05:18 PM
Technicly, it is possible, but the problem, as always with EPUB 3, is the support in reading applications/devices.

Specifically, iBooks has some problems with jQuery (I did some testing a couple of months ago, I do not rember exactly what went wrong). Readium should be ok. But other readers (say, Blio) completely ignore the JS embedded.

EDIT: for the "how", have a look at the IDPF samples. Basically, include your JS script, add it to the manifest, and add "scripted" property to the page(s) using it.

tincanbot
02-27-2013, 06:09 PM
Thank you for your response, AlPe. I can embed normal javascript into an eBook without any issues and it'll display just fine on the iPad. I'm wondering if the iPad can natively understand and display jQuery code or if I would have to embed the jQuery source code in the eBook or use some sort of namespace reference in the header, etc., and if so how that's done. Thus far all of my attempts have been for naught. I'm beginning to think it's not possible, unfortunately.

JSWolf
02-27-2013, 06:19 PM
Thank you for your response, AlPe. I can embed normal javascript into an eBook without any issues and it'll display just fine on the iPad. I'm wondering if the iPad can natively understand and display jQuery code or if I would have to embed the jQuery source code in the eBook or use some sort of namespace reference in the header, etc., and if so how that's done. Thus far all of my attempts have been for naught. I'm beginning to think it's not possible, unfortunately.

You are totally messing your terminology up here. Please do not use iPad when you should be using iBooks. What the iPad can do with eBooks is up to the app, not the iPad itself. iPad is the device. iBooks is the app. Don't use ipad in place of iBooks. It just makes you look bad.

tincanbot
02-27-2013, 06:26 PM
I think most anyone can safely assume that when I said "on the iPad" I was referring to its native eBook display program, iBooks. Thanks for contributing to the discussion, though.

JSWolf
02-27-2013, 06:26 PM
I think most anyone can safely assume that when I said "on the iPad" I was referring to its native eBook display program, iBooks. Thanks for contributing to the discussion, though.

It's not native. It's an add-on app. Why should we have to assume? Why can't iBooks just be specified when that's what you mean?

dgatwood
02-28-2013, 02:23 AM
For the most part, I would expect jQuery to work the same way that it does in Safari. This is not to say that you won't find interesting bugs and edge cases where jQuery does the wrong thing, of course. If you find such problems, file bugs with jQuery, and if they conclude it's a bug in iBooks, then file bugs against iBooks. :)

But yes, you almost certainly will have to embed the jQuery library code in the book. To the best of my knowledge, EPUB books are not allowed to use resources outside the book bundle; they must be self-contained.

AlPe
02-28-2013, 08:47 AM
Thank you for your response, AlPe. I can embed normal javascript into an eBook without any issues and it'll display just fine on the iPad. I'm wondering if the iPad can natively understand and display jQuery code or if I would have to embed the jQuery source code in the eBook or use some sort of namespace reference in the header, etc., and if so how that's done. Thus far all of my attempts have been for naught. I'm beginning to think it's not possible, unfortunately.

Add in the XHTML page (say) p001.xhtml:

<script src="path/to/your/script.js" type="text/javascript"></script>


In the OPF file:

<item id="p001" href="path/to/your/p001.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
<item id="s001" href="path/to/your/script.js" media-type="text/javascript"/>


If you are going to try this in iBooks, you might want/need to include META-INF/com.apple.ibooks.display-options.xml declaring:

<option name="interactive">true</option>

AlPe
02-28-2013, 08:51 AM
But yes, you almost certainly will have to embed the jQuery library code in the book. To the best of my knowledge, EPUB books are not allowed to use resources outside the book bundle; they must be self-contained.

Yes, yes, you need to embed the JS script into your book, either in the XHTML page or embedding the JS file.

(FYI, audio/video resource might be outside the EPUB 3 container: http://idpf.org/epub/30/spec/epub30-publications.html#sec-resource-locations )