Skip to content

Commit

Permalink
add cross references
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Jun 17, 2013
1 parent 6b136a5 commit e81eedd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
29 changes: 28 additions & 1 deletion book.js
Expand Up @@ -82,6 +82,10 @@
* following format:
*
* "Table chapter.number"
*
* enableCrossReferences: true -- This converts the inner part all internal
* links within the flow element into the page number of the page the referred
* element is placed on.
*
* bulkPagesToAdd: 50 -- This is the initial number of pages of each flowable
* part (section, chapter). After this number is added, adjustments are made by
Expand Down Expand Up @@ -239,6 +243,7 @@
'enableTableOfFigures': false,
'enableTableOfTables': false,
'enableMarginNotes': false,
'enableCrossReferences': true,
'bulkPagesToAdd': 50,
'pagesToAddIncrementRatio': 1.4,
'frontmatterContents': '',
Expand Down Expand Up @@ -889,6 +894,22 @@
pagination.adjustMarginNotesPositionsPerPage(allMarginNoteContainers[i]);
}
};

pagination.findAllCrossReferences = function () {
/* Find all links that point to places within the same document
*/
var flowElement = eval(pagination.config('flowElement')), allReferences = flowElement.querySelectorAll('a'), referredElement, pageNumber, i;

for (i=0; i < allReferences.length;i++) {
if (allReferences[i].getAttribute('href')[0]==='#') {
referredElement = flowElement.querySelector(allReferences[i].getAttribute('href'));
pageNumber = pagination.findPage(referredElement).querySelector('.pagination-pagenumber').innerHTML;
if (allReferences[i].innerHTML !== pageNumber) {
allReferences[i].innerHTML = pageNumber;
}
}
}
};

pagination.headersAndToc = function (bodyObjects) {
/* Go through all pages of all flowObjects and add page headers and
Expand Down Expand Up @@ -1114,10 +1135,13 @@
tot = pagination.tot(bodyObjects);
fmObject.rawdiv.replaceChild(tot, oldTot);
}
if (pagination.config('enableCrossReferences')) {
pagination.findAllCrossReferences();
}
};
document.body.addEventListener('bodyLayoutUpdated', function() {
// We have to set a time out of zero to make sure fonts have been applied, etc. before toc and tof are being calculated.
// TODO:mIdeally, this shouldn't be needed.
// TODO: Ideally, this shouldn't be needed.
setTimeout(redoToc, 0);

});
Expand All @@ -1127,6 +1151,9 @@
document.body.dispatchEvent(pagination.events.bodyLayoutUpdated);
});
}
if (pagination.config('enableCrossReferences')) {
pagination.findAllCrossReferences();
}
document.dispatchEvent(pagination.events.layoutFlowFinished);
};

Expand Down
4 changes: 2 additions & 2 deletions test3.html
Expand Up @@ -37,7 +37,7 @@ <h1>Some text part</h1>
non habent claritatem insitam; est usus legentis in iis qui facit eorum
claritatem. Investigationes demonstraverunt lectores legere me lius quod
ii legunt saepius<span class="pagination-footnote"><span><span>And this is a third footnote.</span></span></span>.</div>
<div>3 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
<div id="important">3 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy
nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut
wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure
Expand Down Expand Up @@ -2127,7 +2127,7 @@ <h1>Some text part</h1>
</div>
<h1>Another text part</h1>
<div contenteditable="true">
<div>17 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
<div>See page <a href="#important">SOMETHING</a> 17 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit
lobortis nisl ut aliquip ex ea commodo consequat<span class="pagination-footnote"><span><span>This is a footnote.</span></span></span>. Duis autem vel eum iriure
Expand Down

0 comments on commit e81eedd

Please sign in to comment.