Skip to content

Commit ddafdcf

Browse files
committed
added max page number (default 10000) and changed class name of page headers to avoid confusion
1 parent 4fb4a71 commit ddafdcf

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

book.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ font-size:13px;
7070
}
7171

7272
/* Don't display section titles in the header on odd pages */
73-
.pagination-page:nth-child(odd) .pagination-header .pagination-section {
73+
.pagination-page:nth-child(odd) .pagination-header .pagination-header-section {
7474
display:none;
7575
}
7676

7777
/* Don't display chapter titles in the header on even pages */
78-
.pagination-page:nth-child(even) .pagination-header .pagination-chapter {
78+
.pagination-page:nth-child(even) .pagination-header .pagination-header-chapter {
7979
display:none;
8080
}
8181

book.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
* to set this to 'webkitRegionLayoutUpdate'. A bug in early development
104104
* versions of Chrome 25 did that the event anme was 'regionlayoutupdate'.
105105
*
106+
* maxPageNumber: 10000 -- This controls the maximum amount of pages. If more
107+
* pages than this are added, BookJS will die. Notice that pages are added
108+
* incrementally, so you won't be able to control the exact number of pages.
109+
* You should always set this to something much larger than what you will ever
110+
* expect that you book will need.
111+
*
106112
* Page style options
107113
*
108114
* These settings provide a way to do simple styling of the page. These
@@ -181,6 +187,7 @@ Pagination.config = {
181187
'autoStart': true,
182188
'numberPages': true,
183189
'divideContents': true,
190+
'maxPageNumber': 10000,
184191
'outerMargin': .5,
185192
'innerMargin': .8,
186193
'contentsTopMargin': .8,
@@ -435,11 +442,11 @@ Pagination.createPages = function (num, flowName, pageCounterClass, columns) {
435442
header.classList.add('pagination-header');
436443

437444
chapterheader = document.createElement('span');
438-
chapterheader.classList.add('pagination-chapter');
445+
chapterheader.classList.add('pagination-header-chapter');
439446
header.appendChild(chapterheader);
440447

441448
sectionheader = document.createElement('span');
442-
sectionheader.classList.add('pagination-section');
449+
sectionheader.classList.add('pagination-header-section');
443450
header.appendChild(sectionheader);
444451

445452
page.appendChild(header);
@@ -575,12 +582,12 @@ Pagination.headersAndToc = function (bodyObjects) {
575582

576583
for (var j = 0; j < pages.length; j++) {
577584
var chapterHeader = pages[j].querySelector(
578-
'.pagination-header .pagination-chapter'
585+
'.pagination-header .pagination-header-chapter'
579586
);
580587
chapterHeader.innerHTML = currentChapterTitle;
581588

582589
var sectionHeader = pages[j].querySelector(
583-
'.pagination-header .pagination-section'
590+
'.pagination-header .pagination-header-section'
584591
);
585592
sectionHeader.innerHTML = currentSectionTitle;
586593
}
@@ -1284,6 +1291,7 @@ Pagination.flowObject.prototype.addPagesLoop = function (numberOfPages) {
12841291
* It is a point to overshoot the target, as it is more costly to add than
12851292
* to remove pages.
12861293
*/
1294+
if (this.bulkPagesToAdd > Pagination.config['maxPageNumber']) return;
12871295
if ('undefined' === typeof (numberOfPages)) {
12881296
this.div.appendChild(
12891297
Pagination.createPages(

test.html

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ <h1>Some text part</h1>
180180
Typi non habent claritatem insitam; est usus legentis in iis qui facit
181181
eorum claritatem. Investigationes demonstraverunt lectores legere me lius
182182
quod ii legunt saepius.</div>
183+
<div style="float:right;">TESTETSTETST</div>
183184
<div>15 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam
184185
nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
185186
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit

0 commit comments

Comments
 (0)