|
82 | 82 | * following format:
|
83 | 83 | *
|
84 | 84 | * "Table chapter.number"
|
| 85 | + * |
| 86 | + * enableCrossReferences: true -- This converts the inner part all internal |
| 87 | + * links within the flow element into the page number of the page the referred |
| 88 | + * element is placed on. |
85 | 89 | *
|
86 | 90 | * bulkPagesToAdd: 50 -- This is the initial number of pages of each flowable
|
87 | 91 | * part (section, chapter). After this number is added, adjustments are made by
|
|
239 | 243 | 'enableTableOfFigures': false,
|
240 | 244 | 'enableTableOfTables': false,
|
241 | 245 | 'enableMarginNotes': false,
|
| 246 | + 'enableCrossReferences': true, |
242 | 247 | 'bulkPagesToAdd': 50,
|
243 | 248 | 'pagesToAddIncrementRatio': 1.4,
|
244 | 249 | 'frontmatterContents': '',
|
|
889 | 894 | pagination.adjustMarginNotesPositionsPerPage(allMarginNoteContainers[i]);
|
890 | 895 | }
|
891 | 896 | };
|
| 897 | + |
| 898 | + pagination.findAllCrossReferences = function () { |
| 899 | + /* Find all links that point to places within the same document |
| 900 | + */ |
| 901 | + var flowElement = eval(pagination.config('flowElement')), allReferences = flowElement.querySelectorAll('a'), referredElement, pageNumber, i; |
| 902 | + |
| 903 | + for (i=0; i < allReferences.length;i++) { |
| 904 | + if (allReferences[i].getAttribute('href')[0]==='#') { |
| 905 | + referredElement = flowElement.querySelector(allReferences[i].getAttribute('href')); |
| 906 | + pageNumber = pagination.findPage(referredElement).querySelector('.pagination-pagenumber').innerHTML; |
| 907 | + if (allReferences[i].innerHTML !== pageNumber) { |
| 908 | + allReferences[i].innerHTML = pageNumber; |
| 909 | + } |
| 910 | + } |
| 911 | + } |
| 912 | + }; |
892 | 913 |
|
893 | 914 | pagination.headersAndToc = function (bodyObjects) {
|
894 | 915 | /* Go through all pages of all flowObjects and add page headers and
|
|
1114 | 1135 | tot = pagination.tot(bodyObjects);
|
1115 | 1136 | fmObject.rawdiv.replaceChild(tot, oldTot);
|
1116 | 1137 | }
|
| 1138 | + if (pagination.config('enableCrossReferences')) { |
| 1139 | + pagination.findAllCrossReferences(); |
| 1140 | + } |
1117 | 1141 | };
|
1118 | 1142 | document.body.addEventListener('bodyLayoutUpdated', function() {
|
1119 | 1143 | // We have to set a time out of zero to make sure fonts have been applied, etc. before toc and tof are being calculated.
|
1120 |
| - // TODO:mIdeally, this shouldn't be needed. |
| 1144 | + // TODO: Ideally, this shouldn't be needed. |
1121 | 1145 | setTimeout(redoToc, 0);
|
1122 | 1146 |
|
1123 | 1147 | });
|
|
1127 | 1151 | document.body.dispatchEvent(pagination.events.bodyLayoutUpdated);
|
1128 | 1152 | });
|
1129 | 1153 | }
|
| 1154 | + if (pagination.config('enableCrossReferences')) { |
| 1155 | + pagination.findAllCrossReferences(); |
| 1156 | + } |
1130 | 1157 | document.dispatchEvent(pagination.events.layoutFlowFinished);
|
1131 | 1158 | };
|
1132 | 1159 |
|
|
0 commit comments