Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions js/views/cfi_navigation_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1278,16 +1278,19 @@ var CfiNavigationLogic = function(options) {
_.each($elements, function ($node) {
var isTextNode = ($node[0].nodeType === Node.TEXT_NODE);
var $element = isTextNode ? $node.parent() : $node;
var visibilityPercentage = checkVisibilityByRectangles(
$node, true, visibleContentOffsets, frameDimensions);

if (visibilityPercentage) {
visibleElements.push({
element: $element[0], // DOM Element is pushed
textNode: isTextNode ? $node[0] : null,
percentVisible: visibilityPercentage
});
}
if (($element[0].tagName !== "A") || $node[0].nodeValue) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that be true for any element whose content model model is non-empty, but whose actual content is? (e.g. h1)

Copy link
Author

@tddpirate tddpirate Apr 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably yes.

  1. My patch is conservative in that it ignores empty text nodes only when they are in tags.
    It may be that we can safely treat all empty text nodes and their enclosing elements as invisible regardless of what checkVisibilityByRectangles() tells us.
  2. If we should not ignore all elements enclosing empty text nodes:
    Is there a function (either a DOM element function or a Readium-specific) for identifying elements with non-empty content model?
    If yes, its inverse should replace the ($element[0].tagName !== "A") test.
  3. It is possible that checkVisibilityByRectangles() has a bug (a corner case) in handling empty text nodes. At the moment I do not have time to look into this.

// Skip <a> tags with empty content.
var visibilityPercentage = checkVisibilityByRectangles(
$node, true, visibleContentOffsets, frameDimensions);

if (visibilityPercentage) {
visibleElements.push({
element: $element[0], // DOM Element is pushed
textNode: isTextNode ? $node[0] : null,
percentVisible: visibilityPercentage
});
}
}
});

return visibleElements;
Expand Down