Progress on poem display
Spent most of the day working on the popup functionality which enables you to read in either the apparatus or the poem, and get popups from the other.
The basic idea is simple, and it took no time at all to get popups of notes from the apparatus in response to clicking on note anchors in the poem. There were only two small wrinkles there: first, because we're cloning the note node, we need to make sure any ids in its contents are replaced with new unique ids, otherwise the document structure will be violated. Wrote a recursive function for that. Secondly, since notes are list items, when they're cloned they need to be wrapped in a list container element (in this case <ul>, so that they don't end up with a different number).
Getting an appropriate segment of the poem to pop up is a different kind of problem, though. The issue is that the note anchor is usually interleaved with other tags, inside the poem div. There's no point in popping up the note anchor itself; it's just a number. What you want is the element to which it refers. That's not its parent, in the case of this document. Personally, I'd say that it should be -- the <note> tag should be inside the <l> or <lg> tag to which it refers -- but in this document the note can be a sibling of the <lg> tag. Its immediate parent is the entire poem, so that's no use. What I ended up doing was getting a list of elements which are children of the note anchor's parent element, then filtering out all which are not either the note anchor itself, or <div> elements. Then I was able to choose either the preceding element in the list (if there is one), or the following element, and pop that up. Generally, that means a line, but sometimes it's a stanza.
This would have been a perfect job for the DOM Traversal API, but it's not widely supported, so I had to do it manually.
Then I tested on other browsers, and found two bugs in IE7 that I had to work around:
- DOM level 3 says that when you ask for Element.getAttribute('blah'), if there is no such attribute, you should get back an empty string. However, IE gives you back null. If you then test for length, you get an error. So now I check for null before checking for length.
- ID7 doesn't seem to define, or provide access to, the node type constants (e.g. Node.ELEMENT_NODE), which we use to determine what type of node we're dealing with. I had to revert to using hard-coded integers (in this case, 1).
With these fixes, everything works on Firefox, IE7, Opera, and Safari. Next steps:
- A fixup to ensure that when the popup is off the bottom of the screen, it moves its bottom up to where its top was. This will be finnicky because of IE's oddities, but we've done it before.
- Fading out the poem or the apparatus when a popup shows up. This is cosmetic, but significant from a usability point of view, and will be interesting to do. Again, I predict problems with IE's opacity handling.