How to Enable XPath in Internet Explorer

Yesterday, I shared a little bit about using a virtual machine to test frontend code under Internet Explorer (IE). My goal was to use Wicked Good XPath to add the proper XPath features to IE so that EPUB.js would work correctly, thus making the Philalethes E-Bulletin Online Reader work on all major browsers.

Well, I’d been thinking about this problem for a while, but had delayed working on it because I just didn’t want to fiddle with IE. While I’d been thinking about it, the EPUB.js instructions were updated with IE-specific steps. I didn’t have to look far.

After loading wgxpath.install.js in the header, I just had to add this bit of JavaScript before anything important happened:

1
2
3
4
5
6
7
8
9
// Internet Explorer workaround.
if (!window.XPathResult) {
    EPUBJS.Hooks.register("beforeChapterDisplay").wgxpath = function(callback, renderer){
       wgxpath.install(renderer.render.window);
 
       if (callback) callback();
    };
    wgxpath.install(window);
}

You can see on line 2 that I test for window.XPathResult instead of looking for a user agent or anything like that. That’s because it’s not really IE I’m interested in detecting. I want to find out if XPath is both available and somewhat standard. User agents are unreliable. Always test for feature availability instead!

Recent web browser usageThe results are good enough for now: the Online Reader works in IE, but it’s not perfect. The cover image doesn’t load full-size and fonts don’t seem to be loading correctly. IE users account for only 10% of the traffic on the website, so obviously I need to work on the EPUB.js cross-browser support. For now, though, it works. And it looks great on Chrome, Safari, and Firefox.

When to Develop Apps From Scratch

I haven’t had time to write anything interesting for the blog this week, so instead check out Sebastian Green’s article, “A transparent box: the case for developing from scratch,” which has been published over at Developer Drive.

Mr Green makes some great arguments for developing from scratch. Good software takes good planning, no matter what.

Philalethes E-Bulletin Online Reader

Philalethes Society SealI began working on the Philalethes E-Bulletin in the Fall of 2013, and published the first issue in January of 2014. The E-Bulletin is published quarterly in EPUB and MOBI formats.

It’s been a great learning experience. Not only have I learned a lot about editing, but I’ve really had to dive into how electronic publishing works. The intricacies of electronic book formats have become well-known to me.

The Philalethes Society isn’t entirely comfortable with modern technology, however. Most complaints about the E-Bulletin came from those who didn’t have e-book readers and weren’t comfortable installing software on their PC to handle a new file format. Because of this, I built an online e-book reader specifically for the E-Bulletin.

The online e-book reader is based around the excellent EPUB.js library, with additional backend code written in PHP.

Click here to visit the Philalethes E-Bulletin Online Reader.

Handling Widows and Orphans in EPUB Files

For a little over a year, I’ve been working with the EPUB format to build electronic books. I’ve been working on a software package to build EPUB files in Emacs, in fact.1 This has required learning more about design, and a great deal more about book layout. As with many design elements, once you’re made aware of them, you notice them all of the time. EPUBs, for instance, are not very good at handling widows and orphans.

Since EPUB uses HTML, it doesn’t have all of the tools available to print for handling these design issues. However, I’ve recently learned that there is hope. Over on Pigs, Gourds, and Wikis, I learned about the CSS div property, display: inline-block. I’m looking forward to using this in future EPUBs to improve format even more.

Typesetting


  1. Sorry, it’s not available for the general public yet. Someday!