|
103 | 103 | * You should always set this to something much larger than what you will ever
|
104 | 104 | * expect that you book will need.
|
105 | 105 | *
|
| 106 | + * topfloatSelector: '.pagination-topfloat' -- This is the CSS selector used |
| 107 | + * for finding top floats within the HTML code. Top floats are placed on the |
| 108 | + * page were they were in the text at the time of document loading, and they |
| 109 | + * are not moved later on.In editing environments, the top float should be |
| 110 | + * inserted into to additional elements, like this: |
| 111 | + * |
| 112 | + * <span class='pagination-topfloat'><span><span>This is the top float contents |
| 113 | + * </span></span></span> |
| 114 | + * |
| 115 | + * footnoteSelector: '.pagination-footnote' -- This is the CSS selector used |
| 116 | + * for finding footnotes within the HTML code. Footnotes are automatically |
| 117 | + * moved if the page of their reference changes. In editing environments, the |
| 118 | + * footnote should be inserted into to additional elements, like this: |
| 119 | + * |
| 120 | + * <span class='pagination-footnote'><span><span>This is a footnote</span> |
| 121 | + * </span></span>. |
| 122 | + * |
106 | 123 | * Page style options
|
107 | 124 | *
|
108 | 125 | * These settings provide a way to do simple styling of the page. These
|
|
184 | 201 | 'autoStart': true,
|
185 | 202 | 'numberPages': true,
|
186 | 203 | 'divideContents': true,
|
| 204 | + 'footnoteSelector': '.pagination-footnote', |
| 205 | + 'topfloatSelector': '.pagination-topfloat', |
187 | 206 | 'maxPageNumber': 10000,
|
188 | 207 | 'outerMargin': .5,
|
189 | 208 | 'innerMargin': .8,
|
|
267 | 286 | "\n.pagination-contents {display: -webkit-flex; -webkit-flex: 1;}"
|
268 | 287 | /* There seems to be a bug in the new flexbox model code which requires the
|
269 | 288 | * height to be set to an arbitrary value (which is ignored).
|
270 |
| - */ + "\n.pagination-contents {height: 0px;}" + |
| 289 | + */ |
| 290 | + + "\n.pagination-contents {height: 0px;}" + |
271 | 291 | "\n.pagination-contents-column {-webkit-flex: 1;}" + "\nbody {" +
|
272 | 292 | "counter-reset: pagination-footnote pagination-footnote-reference;}" +
|
273 | 293 | "\n.pagination-footnote::before {" +
|
|
350 | 370 | /* This seems to be a bug in Webkit. But unless we set the width of the
|
351 | 371 | * original element that is being flown, some elements extend beyond the
|
352 | 372 | * contentsContainer's width.
|
353 |
| - */ + "\n.pagination-contents-item {width:" + columnWidth + ";}" + |
| 373 | + */ |
| 374 | + + "\n.pagination-contents-item {width:" + columnWidth + ";}" + |
354 | 375 | "\n.pagination-frontmatter-contents {width:" + contentsWidth + ";}"
|
355 | 376 | // Footnotes in non-CSS Regions browsers will render as right margin notes.
|
356 | 377 | + "\n.pagination-simple .pagination-footnote > span {" +
|
|
459 | 480 | contentsContainer.classList.add('pagination-contents-container');
|
460 | 481 |
|
461 | 482 | topFloats = document.createElement('div');
|
462 |
| - topFloats.classList.add('pagination-top-floats'); |
| 483 | + topFloats.classList.add('pagination-topfloats'); |
463 | 484 |
|
464 | 485 | contents = document.createElement('div');
|
465 | 486 | contents.classList.add('pagination-contents');
|
|
849 | 870 |
|
850 | 871 | this.escapes = {}
|
851 | 872 | this.escapes.footnote = [];
|
| 873 | + this.escapes.topfloat = []; |
852 | 874 |
|
853 | 875 | this.escapeStylesheets = {}
|
854 | 876 | this.escapeStylesheets.footnote = document.createElement('style');
|
855 |
| - |
| 877 | + this.escapeStylesheets.topfloat = document.createElement('style'); |
856 | 878 | };
|
857 | 879 |
|
858 | 880 | flowObject.prototype.redoPages = false;
|
|
879 | 901 | this.namedFlow = document.webkitGetNamedFlows()[this.name];
|
880 | 902 | this.addOrRemovePages();
|
881 | 903 | this.setupReflow();
|
| 904 | + this.findAllTopfloats(); |
882 | 905 | this.findAllFootnotes();
|
| 906 | + this.layoutTopfloats(); |
883 | 907 | this.layoutFootnotes();
|
884 | 908 | this.setupFootnoteReflow();
|
885 | 909 | if (pagination.config('numberPages')) {
|
|
937 | 961 | }
|
938 | 962 | };
|
939 | 963 |
|
940 |
| - // Footnote handling |
| 964 | + // Footnote and top float handling |
941 | 965 |
|
942 | 966 | flowObject.prototype.findFootnoteReferencePage = function (
|
943 | 967 | footnoteReference) {
|
|
1073 | 1097 | }
|
1074 | 1098 | };
|
1075 | 1099 |
|
1076 |
| - |
1077 |
| - flowObject.prototype.findAllFootnotes = function() { |
| 1100 | + flowObject.prototype.findAllTopfloats = function () { |
| 1101 | + // Find all the topfloats in the text and prepare them for flow. |
| 1102 | + this.findAllEscapes('topfloat'); |
| 1103 | + } |
| 1104 | + |
| 1105 | + |
| 1106 | + flowObject.prototype.findAllFootnotes = function () { |
1078 | 1107 | // Find all the footnotes in the text and prepare them for flow.
|
1079 | 1108 | this.findAllEscapes('footnote');
|
1080 | 1109 | }
|
|
1084 | 1113 | // Find all the escapes (footnotes, topfloats) in the text and prepare them for flow.
|
1085 | 1114 |
|
1086 | 1115 | if (this.escapeStylesheets[escapeType].parentNode === document.head) {
|
1087 |
| - // Remove all previous footnote stylesheet rules. |
| 1116 | + // Remove all previous stylesheet rules of the same escape type. |
1088 | 1117 | document.head.removeChild(this.escapeStylesheets[escapeType]);
|
1089 | 1118 | this.escapeStylesheets[escapeType].innerHTML = '';
|
1090 | 1119 | }
|
1091 | 1120 |
|
1092 | 1121 | /* Look for all the items that have "pagination-"+escapeType in their class list. These
|
1093 | 1122 | * will be treated as escapes from the normal text flow.
|
1094 | 1123 | */
|
1095 |
| - var allEscapes = this.rawdiv.getElementsByClassName( |
1096 |
| - 'pagination-' + escapeType); |
| 1124 | + var allEscapes = this.rawdiv.querySelectorAll( |
| 1125 | + pagination.config(escapeType + 'Selector')); |
1097 | 1126 |
|
1098 | 1127 | for (var i = 0; i < allEscapes.length; i++) {
|
1099 | 1128 |
|
|
1102 | 1131 | * using CSS rules.
|
1103 | 1132 | */
|
1104 | 1133 | allEscapes[i].id = pagination.createRandomId(
|
1105 |
| - 'pagination-'+escapeType+'-'); |
| 1134 | + 'pagination-' + escapeType + '-'); |
1106 | 1135 | }
|
1107 | 1136 |
|
1108 | 1137 | var escapeId = allEscapes[i].id;
|
1109 | 1138 |
|
1110 |
| - this.escapeStylesheets.footnote.innerHTML += |
| 1139 | + this.escapeStylesheets[escapeType].innerHTML += |
1111 | 1140 | '\n#' + escapeId + ' > * {-webkit-flow-into: ' + escapeId +
|
1112 | 1141 | ';}' + '\n#' + escapeId + '-flow-into {-webkit-flow-from: ' +
|
1113 | 1142 | escapeId + ';}';
|
|
1124 | 1153 |
|
1125 | 1154 | escapeFlowTo.id = escapeId + '-flow-into';
|
1126 | 1155 |
|
1127 |
| - escapeFlowTo.classList.add('pagination-'+escapeType+'-item'); |
| 1156 | + escapeFlowTo.classList.add('pagination-' + escapeType + '-item'); |
1128 | 1157 |
|
1129 | 1158 | escapeObject['item'] = escapeFlowTo;
|
1130 | 1159 |
|
|
1134 | 1163 |
|
1135 | 1164 |
|
1136 | 1165 | }
|
1137 |
| - if (this.escapeStylesheets.footnote.innerHTML !== '') { |
1138 |
| - document.head.appendChild(this.escapeStylesheets.footnote); |
| 1166 | + if (this.escapeStylesheets[escapeType].innerHTML !== '') { |
| 1167 | + document.head.appendChild(this.escapeStylesheets[escapeType]); |
1139 | 1168 | }
|
1140 | 1169 |
|
1141 | 1170 | };
|
1142 | 1171 |
|
| 1172 | + flowObject.prototype.layoutTopfloats = function () { |
| 1173 | + // Layout all top floats |
| 1174 | + this.layoutTopBottomEscapes('topfloat'); |
| 1175 | + }; |
| 1176 | + |
1143 | 1177 | flowObject.prototype.layoutFootnotes = function () {
|
1144 | 1178 | // Layout all footnotes
|
| 1179 | + this.layoutTopBottomEscapes('footnote'); |
| 1180 | + } |
1145 | 1181 |
|
1146 |
| - for (var i = 0; i < this.escapes.footnote.length; i++) { |
1147 |
| - /* Go through all footnotes, delete the spacer blocks if they have any |
1148 |
| - * and remove the footnote itself from the DOM. |
| 1182 | + flowObject.prototype.layoutTopBottomEscapes = function (escapeType) { |
| 1183 | + // Layout all footnotes and top floats |
| 1184 | + |
| 1185 | + for (var i = 0; i < this.escapes[escapeType].length; i++) { |
| 1186 | + /* Go through all escapes, delete the spacer blocks if they have any |
| 1187 | + * in the case of footnotes and remove the escape node itself from the DOM. |
1149 | 1188 | */
|
1150 | 1189 |
|
1151 |
| - if ('hidden' in this.escapes.footnote[i]) { |
1152 |
| - this.escapes.footnote[i]['hidden'].parentNode.removeChild( |
1153 |
| - this.escapes.footnote[i]['hidden']); |
1154 |
| - delete this.escapes.footnote[i]['hidden']; |
| 1190 | + if (escapeType === 'footnote' && 'hidden' in this.escapes[ |
| 1191 | + escapeType][i]) { |
| 1192 | + this.escapes[escapeType][i]['hidden'].parentNode.removeChild( |
| 1193 | + this.escapes[escapeType][i]['hidden']); |
| 1194 | + delete this.escapes[escapeType][i]['hidden']; |
1155 | 1195 | }
|
1156 | 1196 |
|
1157 |
| - if (this.escapes.footnote[i]['item'].parentNode !== null) { |
1158 |
| - this.escapes.footnote[i]['item'].parentNode.removeChild( |
1159 |
| - this.escapes.footnote[i]['item']); |
| 1197 | + if (this.escapes[escapeType][i]['item'].parentNode !== null) { |
| 1198 | + this.escapes[escapeType][i]['item'].parentNode.removeChild( |
| 1199 | + this.escapes[escapeType][i]['item']); |
1160 | 1200 | }
|
1161 | 1201 | }
|
1162 | 1202 |
|
1163 |
| - for (var i = 0; i < this.escapes.footnote.length; i++) { |
1164 |
| - /* Go through the footnotes again, this time with the purpose of |
| 1203 | + for (var i = 0; i < this.escapes[escapeType].length; i++) { |
| 1204 | + /* Go through the escapes again, this time with the purpose of |
1165 | 1205 | * placing them correctly.
|
1166 | 1206 | */
|
1167 | 1207 |
|
1168 |
| - var footnoteReferencePage = this.findFootnoteReferencePage( |
1169 |
| - document.getElementById(this.escapes.footnote[i]['id'])); |
1170 |
| - // We find the page where the footnote is referenced from. |
1171 |
| - var firstFootnoteContainer = footnoteReferencePage.querySelector( |
1172 |
| - '.pagination-footnotes'); |
1173 |
| - firstFootnoteContainer.appendChild(this.escapes.footnote[i]['item']); |
1174 |
| - // We insert the footnote in the footnote container of that page. |
| 1208 | + var escapeReferencePage = this.findFootnoteReferencePage( |
| 1209 | + document.getElementById(this.escapes[escapeType][i]['id'])); |
| 1210 | + // We find the page where the escape is referenced from. |
| 1211 | + var firstEscapeContainer = escapeReferencePage.querySelector( |
| 1212 | + '.pagination-' + escapeType + 's'); |
| 1213 | + firstEscapeContainer.appendChild(this.escapes[escapeType][i]['item']); |
| 1214 | + // We insert the escape in the footnote or topfloat container of that page. |
1175 | 1215 |
|
1176 |
| - if (!(this.compareReferenceAndFootnotePage(this.escapes.footnote[i]))) { |
| 1216 | + if (escapeType === 'footnote' && !(this.compareReferenceAndFootnotePage( |
| 1217 | + this.escapes.footnote[i]))) { |
1177 | 1218 | /* If the footnote reference has been moved from one page to
|
1178 | 1219 | * another through the insertion procedure, we move the footnote to
|
1179 | 1220 | * where it is referenced from now and create an empty div
|
1180 | 1221 | * ('hidden') and set it in it's place.
|
1181 | 1222 | */
|
1182 | 1223 |
|
1183 |
| - this.escapes.footnote[i]['hidden'] = document.createElement('div'); |
| 1224 | + this.escapes.footnote[i]['hidden'] = document.createElement( |
| 1225 | + 'div'); |
1184 | 1226 |
|
1185 | 1227 | this.escapes.footnote[i]['hidden'].style.height = (
|
1186 | 1228 | this.escapes.footnote[i]['item'].clientHeight) + 'px';
|
1187 | 1229 |
|
1188 |
| - this.escapes.footnote[i]['hidden'].id = this.escapes.footnote[i]['id'] + |
| 1230 | + this.escapes.footnote[i]['hidden'].id = this.escapes.footnote[i][ |
| 1231 | + 'id' |
| 1232 | + ] + |
1189 | 1233 | 'hidden';
|
1190 | 1234 |
|
1191 | 1235 | var newFootnoteReferencePage = this.findFootnoteReferencePage(
|
|
1199 | 1243 | /* We then insert the hidden element into the container where the
|
1200 | 1244 | * footnote was previously so that the body text doesn't flow back.
|
1201 | 1245 | */
|
1202 |
| - firstFootnoteContainer.replaceChild( |
| 1246 | + firstEscapeContainer.replaceChild( |
1203 | 1247 | this.escapes.footnote[i]['hidden'],
|
1204 | 1248 | this.escapes.footnote[i]['item']);
|
1205 |
| - newFootnoteContainer.appendChild(this.escapes.footnote[i]['item']); |
| 1249 | + newFootnoteContainer.appendChild(this.escapes.footnote[i][ |
| 1250 | + 'item' |
| 1251 | + ]); |
1206 | 1252 |
|
1207 | 1253 | var checkSpacerSize = function () {
|
1208 | 1254 | if (this.escapes.footnote[i]['item'].clientHeight <
|
|
1216 | 1262 | }
|
1217 | 1263 | };
|
1218 | 1264 |
|
1219 |
| - |
1220 |
| - |
1221 | 1265 | var observer = new MutationObserver(function (mutations) {
|
1222 | 1266 | checkSpacerSize();
|
1223 | 1267 | });
|
|
1229 | 1273 |
|
1230 | 1274 | });
|
1231 | 1275 |
|
1232 |
| - |
1233 |
| - |
1234 |
| - |
1235 | 1276 | }
|
1236 | 1277 | }
|
1237 | 1278 | };
|
|
0 commit comments