├── .gitignore ├── LICENSE.txt ├── README.md ├── book-config.js ├── book.css ├── book.js ├── changes.txt ├── index.html ├── test.html ├── test2.html ├── test3.html ├── test4.html ├── test4.png ├── test5.html ├── test7.html ├── test8.html └── test9.html /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | 663 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BookJS 2 | =========== 3 | 4 | BookJS was an effort to use the page formatting functions present in certain Chromium versions to convert a webpage into a set of pages formatted for printing, whch can be converted into a PDF with Chromium's print-to-PDF function. Please note that CSS Regions is an experimental feature and may not be available in your current browser. 5 | -------------------------------------------------------------------------------- /book-config.js: -------------------------------------------------------------------------------- 1 | paginationConfig = { 2 | 'sectionStartMarker': 'h1', 3 | 'sectionTitleMarker': 'h1', 4 | 'chapterStartMarker': 'h2', 5 | 'chapterTitleMarker': 'h2', 6 | 'flowElement': 'document.body', 7 | 'alwaysEven': true, 8 | 'divideContents': true, 9 | 'columns': 2, 10 | 'enableFrontmatter': true, 11 | 'bulkPagesToAdd': 50, 12 | 'pagesToAddIncrementRatio': 1.4, 13 | 'frontmatterContents': '

Book title

' 14 | + '

Book subtitle

' 15 | + 'ed. Editor 1, Editor II, Editor III
' 16 | + '
Copyright: You
License: CC
' 17 | + '
', 18 | 'autoStart': true, 19 | } 20 | 21 | -------------------------------------------------------------------------------- /book.css: -------------------------------------------------------------------------------- 1 | /* background color is grey */ 2 | 3 | body { 4 | background-color:#efefef; /* SET AUTOMATICALLY */ 5 | } 6 | 7 | @page { 8 | size:5.8in 8.3in; /* Paper size for print */ 9 | } 10 | 11 | /* size of pages: A5 */ 12 | 13 | .pagination-page { 14 | height:8.3in; /* SET AUTOMATICALLY */ 15 | width:5.8in; /* SET AUTOMATICALLY */ 16 | } 17 | 18 | /* height of pages when no CSS regions present: auto. Also add some padding. */ 19 | 20 | .pagination-page.pagination-simple { 21 | padding: 1in; /* SET AUTOMATICALLY */ 22 | } 23 | 24 | /* Every .page contains various elements (.contents, .header, .pagenumber) that together make out the page. The elements are placed with absolute coordinates in relation to the page and are, if not specified otherwise, centered. Pages have white background color */ 25 | 26 | .pagination-page { 27 | background-color:#fff; /* SET AUTOMATICALLY */ 28 | } 29 | 30 | /* When showing the page on the screen, put a border around the page and add a little margin beween the pages. */ 31 | 32 | @media screen{ 33 | .pagination-page { 34 | border:solid 1px #000; /* SET AUTOMATICALLY */ 35 | margin-bottom:.2in; /* SET AUTOMATICALLY */ 36 | } 37 | } 38 | 39 | /* The .contents-container contains the .contents and the .footnotes */ 40 | 41 | .pagination-contents-container { 42 | height:6.67in; /* SET AUTOMATICALLY */ 43 | width:4.03in; /* SET AUTOMATICALLY */ 44 | bottom:.8in; /* SET AUTOMATICALLY */ 45 | } 46 | 47 | 48 | 49 | /* images should not overflow the contents box */ 50 | 51 | img { 52 | max-height: 6.57in; /* SET AUTOMATICALLY */ 53 | max-width: 3.93in; /* SET AUTOMATICALLY */ 54 | } 55 | 56 | .pagination-pagenumber { 57 | margin-top:.2in; /* SET AUTOMATICALLY */ 58 | bottom:.4in; /* SET AUTOMATICALLY */ 59 | left:0; /* SET AUTOMATICALLY */ 60 | right:0; /* SET AUTOMATICALLY */ 61 | font-size:15px; 62 | } 63 | 64 | .pagination-header { 65 | margin-bottom:.2in; /* SET AUTOMATICALLY */ 66 | top:.4in; /* SET AUTOMATICALLY */ 67 | left:0; /* SET AUTOMATICALLY */ 68 | right:0; /* SET AUTOMATICALLY */ 69 | font-size:13px; 70 | } 71 | 72 | /* Don't display section titles in the header on odd pages */ 73 | .pagination-page:nth-child(odd) .pagination-header .pagination-header-section { 74 | display:none; 75 | } 76 | 77 | /* Don't display chapter titles in the header on even pages */ 78 | .pagination-page:nth-child(even) .pagination-header .pagination-header-chapter { 79 | display:none; 80 | } 81 | 82 | /* Centering the page number on first pages of chapters */ 83 | .pagination-chapter .pagination-page:first-child .pagination-pagenumber { 84 | text-align: center; 85 | margin-left: auto; 86 | margin-right: auto; 87 | } 88 | 89 | 90 | /* ELEMENTS OF THE TABLE OF CONTENTS */ 91 | 92 | /* The title text of the TOC */ 93 | #pagination-toc-title:before { 94 | content:"Contents"; /* SET AUTOMATICALLY */ 95 | } 96 | 97 | /* Styling of the TOC title */ 98 | #pagination-toc-title { 99 | font-size:22px; 100 | font-weight:700; 101 | text-align:left; 102 | padding-bottom:.4in; 103 | } 104 | 105 | /* Styling of individual toc entry */ 106 | .pagination-toc-entry { 107 | width:4.2in; 108 | display:block; 109 | padding-bottom:.3in; 110 | } 111 | 112 | /* Page numbers of toc entries should float to the right and have normal font weight */ 113 | .pagination-toc-entry .pagination-toc-pagenumber { 114 | font-weight:400; 115 | display:inline-block; 116 | vertical-align:text-bottom; 117 | font-size:16px; 118 | float:right; /* SET AUTOMATICALLY */ 119 | } 120 | 121 | /* special styling for TOC entries that represent sections */ 122 | .pagination-toc-entry.section { 123 | font-weight:700; 124 | font-size:16px; 125 | text-transform:uppercase; 126 | padding-bottom:.3in; 127 | } 128 | 129 | /* Left and right page gutter */ 130 | .pagination-page:nth-child(odd) .pagination-contents-container { 131 | right:.6in; /* SET AUTOMATICALLY */ 132 | } 133 | 134 | .pagination-page:nth-child(even) .pagination-content-container { 135 | left:.6in; /* SET AUTOMATICALLY */ 136 | } 137 | 138 | /* Left and right page page numbers and headers */ 139 | 140 | .pagination-page:nth-child(odd) .pagination-pagenumber,.pagination-page:nth-child(odd) .pagination-header { 141 | right:.6in; /* SET AUTOMATICALLY */ 142 | text-align:right; /* SET AUTOMATICALLY */ 143 | } 144 | 145 | .pagination-page:nth-child(even) .pagination-pagenumber,.pagination-page:nth-child(even) .pagination-header { 146 | left:.6in; /* SET AUTOMATICALLY */ 147 | text-align:left; /* SET AUTOMATICALLY */ 148 | } 149 | 150 | /* No page number on section start pages and on title page */ 151 | .pagination-section .pagination-page:first-child .pagination-pagenumber,#pagination-frontmatter .pagination-page:first-child .pagination-pagenumber { 152 | display:none; 153 | } 154 | 155 | /* No header on section and chapter start pages */ 156 | .pagination-section .pagination-page:first-child .pagination-header,.pagination-chapter .pagination-page:first-child .pagination-header { 157 | display:none; 158 | } 159 | 160 | 161 | /* Styling of footnotes */ 162 | 163 | .pagination-footnote > * > * { 164 | font-size: 0.7em; /* SET AUTOMATICALLY */ 165 | line-height: 1em; 166 | margin:.25em; /* SET AUTOMATICALLY */ 167 | } 168 | 169 | .pagination-footnote > * > *::before, .pagination-footnote::before { 170 | position: relative; top: -0.5em; font-size: 80%; /* SET AUTOMATICALLY */ 171 | } 172 | 173 | .pagination-footnote { 174 | font-size:10px; 175 | font-weight: bold; 176 | } 177 | 178 | /* If footnotes are present, a margin of .2in is added between .contents and .footnotes and a black line is drawn above the footnotes. */ 179 | 180 | .pagination-footnotes div.pagination-footnote-item:first-child { 181 | padding-top: .5em; 182 | border-top: 1px solid black; 183 | } 184 | 185 | /* Work-around to make section title pages no longer than one page */ 186 | 187 | .objavi-subsection-heading { 188 | line-height:120px!important; 189 | font-size:22px; 190 | font-weight:700; 191 | text-align:left; 192 | display:none; 193 | } 194 | 195 | /* Custom CSS for elements that do not come directly out of body.html */ 196 | 197 | #booktitle { 198 | margin-top:1.7in; 199 | font-size:26px; 200 | font-weight:700; 201 | text-align:center; 202 | } 203 | 204 | #booksubtitle { 205 | font-size:18px; 206 | margin-top:.2in; 207 | font-weight:700; 208 | text-align:center; 209 | } 210 | 211 | #bookeditors { 212 | padding-top:2in; 213 | font-weight:700; 214 | text-align:center; 215 | font-size:12px; 216 | } 217 | 218 | /* General CSS for contents */ 219 | 220 | p { 221 | font-size:15px; 222 | line-height:20px; 223 | text-align:justify; 224 | } 225 | 226 | h1 { 227 | font-size:21px; 228 | } 229 | 230 | h2 { 231 | font-size:19px; 232 | } 233 | 234 | h3 { 235 | font-size:17px; 236 | } 237 | -------------------------------------------------------------------------------- /book.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * BookJS 3 | * Copyright 2012-13 Steven Levithan, and Johannes Wilm. Freely available 4 | * under the AGPL. For further details see LICENSE.txt 5 | * 6 | * Using this library you can turn an HTML element into a series 7 | * of pages using CSS Regions. If the browser doesn't support CSS Regions, 8 | * everything will be flown into one large page container that looks like a 9 | * very long page. 10 | * 11 | * 12 | * HOWTO 13 | * 14 | * In order to use this library, link to this javascript file within your html 15 | * code. 16 | * If you need to set custom options, set them before including this javascript 17 | * file by defining an object named paginationConfig and setting the 18 | * customization options as keys within this object. If you want to style the 19 | * output in a specific way, customize the pagination.css file and include it, like 20 | * this: 21 | * 22 | * 23 | * 30 | * 31 | * 32 | * OPTIONS 33 | * 34 | * The following options are available to customize the pagination behavior. In 35 | * the descriptions below you can see the default values for these options. You 36 | * only need to specify the options if you want to deviate from the default 37 | * value. 38 | * 39 | * sectionStartMarker: 'h1' -- This is the HTML element we look for to find where 40 | * a new section starts. 41 | * 42 | * sectionTitleMarker: 'h1' -- Within the newly found section, we look for the 43 | * first instance of this element to determine the title of the section. 44 | * 45 | * chapterStartMarker: 'h2' -- This is the HTML element we look for to find where 46 | * a new chapter starts. 47 | * 48 | * chapterTitleMarker: 'h2' -- Within the newly found chapter, we look for the 49 | * first instance of this element to determine the title of the chapter. 50 | * 51 | * flowElement: 'document.body' -- This specifies element the container element 52 | * of the content we will flow into pages. You can use any javascript selector 53 | * here, such as "document.getElementById('contents')" . 54 | * 55 | * alwaysEven: false -- This determines whether each section and chapter should 56 | * have an even number of pages (2, 4, 6, 8, ...). 57 | * 58 | * columns: 1 -- This specifies the number of number of columns used for the 59 | * body text. 60 | * 61 | * enableFrontmatter: true -- This resolves whether a table of contents, page\ 62 | * headers and other frontmatter contents should be added upon page creation. 63 | * Note: divideContents has to be true if one wants the frontmatter to render. 64 | * 65 | * enableTableOfFigures: false -- This creates a table of figures in the front. 66 | * Figures are expected to be in the HTML5 format: 67 | * 68 | *
...
69 | * 70 | * If an element is present in the figure, its alt-attribute text will be 71 | * used as the reference text. If no element is present, or one is 72 | * present, but it has no alt-attribute, the contents of the
73 | * element will be usd instead. If no
element is present, a 74 | * description text is generated of the following format: 75 | * 76 | * "Figure chapter.number" 77 | * 78 | * enableTableOfTables: false -- This creates a table of s within 79 | *
s, similarly to enableTableOfFigures. If this option is enabled, 80 | * tables will not additionally be listed in the table of figures. If no 81 | *
element is present, the description text will be in the 82 | * following format: 83 | * 84 | * "Table chapter.number" 85 | * 86 | * enableCrossReferences: true -- This converts the inner part of all internal 87 | * links within the flow element into the page number of the page the referred 88 | * element is placed on. 89 | * 90 | * enableWordIndex: true -- This creates a word index. An empty word index 91 | * element has to be placed somewhere in the HTML and given the class 92 | * pagination-index-list. every index word is defined this way: 93 | * 94 | * 96 | * 97 | * bulkPagesToAdd: 50 -- This is the initial number of pages of each flowable 98 | * part (section, chapter). After this number is added, adjustments are made by 99 | * adding another bulk of pages or deleting pages individually. It takes much 100 | * less time to delete pages than to add them individually, so it is a point to 101 | * overshoot the target value. For larger chapters add many pages at a time so 102 | * there is less time spent reflowing text. 103 | * 104 | * pagesToAddIncrementRatio: 1.4 -- This is the ratio of how the bulk of pages 105 | * incremented. If the initial bulkPagestoAdd is 50 and those initial 50 pages 106 | * were not enough space to fit the contents of that chapter, then next 107 | * 1.4 * 50 = 70 are pages, for a total of 50+70 = 120 pages, etc. . 1.4 seems 108 | * to be the fastest in most situations. 109 | * 110 | * frontmatterContents: none -- These are the HTML contents that are added to 111 | * the frontmatter before the table of contents. This would usually be a title 112 | * page and a copyright page, including page breaks. 113 | * 114 | * autoStart: true -- This controls whether pagination should be executed 115 | * automatically upon page load. If it is set to false, pagination has to be 116 | * initiated manually. See below under "methods." 117 | * 118 | * numberPages: true -- This controls whether page numbers should be used. If 119 | * page numbers are not used, the table of contents is automatically left out. 120 | * 121 | * divideContents: true -- This controls whether the contents are divdided up 122 | * according to sections and chapters before flowing. CSS Regions take a long 123 | * time when more than 20-30 pages are involved, which is why it usually makes 124 | * sense to divide the contents up. However, if the contents to be flown takes 125 | * up less space than this, there is no need to do this division. The added 126 | * benefit of not doing it is that the original DOM of the part that contains 127 | * the conents will not be modified. Only the container element that holds the 128 | * contents will be assigned another CSS class. Note: divideContents has to be 129 | * true if one wants the frontmatter to render. 130 | * 131 | * maxPageNumber: 10000 -- This controls the maximum amount of pages. If more 132 | * pages than this are added, BookJS will die. Notice that pages are added 133 | * incrementally, so you won't be able to control the exact number of pages. 134 | * You should always set this to something much larger than what you will ever 135 | * expect that you book will need. 136 | * 137 | * topfloatSelector: '.pagination-topfloat' -- This is the CSS selector used 138 | * for finding top floats within the HTML code. Top floats are placed on the 139 | * page either of the reference or the one following it. In editing 140 | * environments, the top float should be inserted inside two additional 141 | * elements, like this: 142 | * 143 | * This is the top float contents 144 | * 145 | * 146 | * footnoteSelector: '.pagination-footnote' -- This is the CSS selector used 147 | * for finding footnotes within the HTML code. Footnotes are automatically 148 | * moved if the page of their reference changes. In editing environments, the 149 | * footnote should be inserted inside two additional elements, like this: 150 | * 151 | * This is a footnote 152 | * . 153 | * 154 | * marginnoteSelector: '.pagination-marginnote' -- this is the CSS selector 155 | * used for finding marginnotes within the HTML code. Margin notes are moved 156 | * whenever the reference to them is moved. They do not overlap and don't go 157 | * beyond the bottom of the text. At the same time they are placed as close as 158 | * possible to where they are referenced from. 159 | * 160 | * This is a margin note 161 | * . 162 | * 163 | * Three settings can be defined to adjust margin notes: 164 | * 165 | * marginNotesWidth: 1.0 (inch): This is the width oiccupied by margin notes. 166 | * 167 | * marginNotesSeparatorWidth: 0.09 (inch): This is the gap between body text and 168 | * margin notes. 169 | * 170 | * marginNotesVerticalSeparatorWidth': 0.09 (inch): This is the vertical space 171 | * between any two margin notes. 172 | * 173 | * Page style options 174 | * 175 | * These settings provide a way to do simple styling of the page. These 176 | * settings are different from the baove ones in that they can be overriden 177 | * through CSS to provide more advanced designs (see the above note on 178 | * pagination.css). 179 | * 180 | * outerMargin: .5 (inch)-- This controls the margin on the outer part of the 181 | * page. 182 | * 183 | * innerMargin: .8 (inch)-- This controls the margin on the inenr part of the 184 | * page. 185 | * 186 | * contentsTopMargin: .8 (inch)-- This controls the margin between the top of 187 | * the page and the top of the contents. 188 | * 189 | * headerTopMargin: .3 (inch) -- This controls the margin between the top of 190 | * the page and the top of the page headers. 191 | * 192 | * contentsBottomMargin: .8 (inch) -- This controls the margin between the 193 | * bottom of the page and the bottom of the contents. 194 | * 195 | * pagenumberBottomMargin: .3 (inch) -- This controls the margin between the 196 | * bottom of the page and the bottom of the page number. 197 | * 198 | * pageHeight: 8.3 (inch) -- This controls the height of the page. 199 | * 200 | * pageWidth: 5.8 (inch) -- This controls the width of the page. 201 | * 202 | * columnSeparatorWidth: .09 (inch) -- This is the space between columns. 203 | * 204 | * lengthUnit: 'in' (inch) -- Use this to specify the unit used in all the page 205 | * style options. It can be any unit supported by CSS. 206 | * 207 | * METHODS 208 | * 209 | * Changing the page style after initialization 210 | * 211 | * At times the user might want to change the page design or page size after 212 | * BookJS has started -- for example to look at the same text in different page 213 | * sizes. To do this, he has to change all the page style options which are now 214 | * located inside paginationConfig and run pagination.setPageStyle(). Like 215 | * this: 216 | * 217 | * paginationConfig['pageHeight'] = 11; 218 | * paginationConfig['pageWidth'] = 8; 219 | * pagination.setPageStyle(); 220 | * 221 | * Initializing page flowing after loading 222 | * 223 | * If one chooses not to flow the pages automatically upon page loading, it has 224 | * to be initiated manually by calling pagination.applyBookLayout() or 225 | * pagination.applySimpleBookLayout() in case CSS Regions are not present. 226 | * 227 | * Check whether CSS regions are present. 228 | * 229 | * pagination._cssRegionCheck() will return true or false, depending on whether 230 | * CSS Regions are present or not. 231 | * 232 | */ (function () { 233 | 234 | var exports = this, 235 | defaults, 236 | pagination = {}; 237 | 238 | // pagination is the object that contains the namespace used by BookJS. 239 | 240 | defaults = { 241 | // pagination.config starts out with default config options. 242 | 'sectionStartMarker': 'h1', 243 | 'sectionTitleMarker': 'h1', 244 | 'chapterStartMarker': 'h2', 245 | 'chapterTitleMarker': 'h2', 246 | 'flowElement': 'document.body', 247 | 'alwaysEven': false, 248 | 'columns': 1, 249 | 'enableFrontmatter': true, 250 | 'enableTableOfFigures': false, 251 | 'enableTableOfTables': false, 252 | 'enableMarginNotes': false, 253 | 'enableCrossReferences': true, 254 | 'enableWordIndex': true, 255 | 'bulkPagesToAdd': 50, 256 | 'pagesToAddIncrementRatio': 1.4, 257 | 'frontmatterContents': '', 258 | 'autoStart': true, 259 | 'numberPages': true, 260 | 'divideContents': true, 261 | 'footnoteSelector': '.pagination-footnote', 262 | 'topfloatSelector': '.pagination-topfloat', 263 | 'marginnoteSelector': '.pagination-marginnote', 264 | 'maxPageNumber': 10000, 265 | 'columnSeparatorWidth': 0.09, 266 | 'outerMargin': 0.5, 267 | 'innerMargin': 0.8, 268 | 'contentsTopMargin': 0.8, 269 | 'headerTopMargin': 0.3, 270 | 'contentsBottomMargin': 0.8, 271 | 'pagenumberBottomMargin': 0.3, 272 | 'pageHeight': 8.3, 273 | 'pageWidth': 5.8, 274 | 'marginNotesWidth': 1.5, 275 | 'marginNotesSeparatorWidth': 0.09, 276 | 'marginNotesVerticalSeparatorWidth': 0.09, 277 | 'lengthUnit': 'in' 278 | }; 279 | 280 | // help functions 281 | 282 | pagination.romanize = function () { 283 | // Create roman numeral representations of numbers. 284 | var digits = String(+this.value).split(""), 285 | key = ["", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM", 286 | "", 287 | "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC", "", 288 | "I", "II", 289 | "III", "IV", "V", "VI", "VII", "VIII", "IX" 290 | ], 291 | roman = "", 292 | i = 3; 293 | while (i--) { 294 | roman = (key[+digits.pop() + (i * 10)] || "") + roman; 295 | } 296 | return new Array(+digits.join("") + 1).join("M") + roman; 297 | }; 298 | 299 | pagination.createRandomId = function (base) { 300 | // Create a random CSS Id that is not in use already. 301 | var randomId, stillSearchingForUniqueId = true; 302 | while (stillSearchingForUniqueId) { 303 | randomId = base + Math.floor(Math.random() * 100000); 304 | if (!document.getElementById(randomId)) { 305 | stillSearchingForUniqueId = false; 306 | } 307 | } 308 | return randomId; 309 | }; 310 | 311 | pagination.pageStyleSheet = document.createElement('style'); 312 | 313 | pagination.initiate = function () { 314 | /* Initiate BookJS by importing user set config options and setting basic 315 | * CSS style. 316 | */ 317 | 318 | this.setStyle(); 319 | this.setPageStyle(); 320 | document.head.insertBefore( 321 | pagination.pageStyleSheet, 322 | document.head.firstChild); 323 | }; 324 | 325 | pagination.config = function (configKey) { 326 | /* Return configuration variables either from paginationConfig if present, 327 | * or using default values. 328 | */ 329 | var returnValue; 330 | if (paginationConfig && paginationConfig.hasOwnProperty(configKey)) { 331 | returnValue = paginationConfig[configKey]; 332 | } else if (defaults.hasOwnProperty(configKey)) { 333 | returnValue = defaults[configKey]; 334 | } else { 335 | returnValue = false; 336 | } 337 | return returnValue; 338 | }; 339 | 340 | pagination.setStyle = function () { 341 | /* Set style for the regions and pages used by BookJS and add it to the 342 | * head of the DOM. 343 | */ 344 | var stylesheet = document.createElement('style'); 345 | stylesheet.innerHTML = 346 | ".pagination-main-contents-container {display: -webkit-flex; " + 347 | "-webkit-flex-direction: column;}" + 348 | "\n.pagination-contents-container {position: absolute;}" + 349 | "\n.pagination-contents {display: -webkit-flex; -webkit-flex: 1;}" 350 | /* There seems to be a bug in the new flexbox model code which requires the 351 | * height to be set to an arbitrary value (which is ignored). 352 | */ + "\n.pagination-contents {height: 0px;}" + 353 | "\n.pagination-contents-column {-webkit-flex: 1;}" + "\nbody {" + 354 | "counter-reset: pagination-footnote pagination-footnote-reference;}" + 355 | "\n.pagination-footnote::before {" + 356 | "counter-increment: pagination-footnote-reference; " + 357 | "content: counter(pagination-footnote-reference);}" + 358 | "\n.pagination-footnote > * > *:first-child::before {" + 359 | "counter-increment: pagination-footnote;" + 360 | "content: counter(pagination-footnote);}" + 361 | "\n.pagination-footnote > * > * {display: block;}" + 362 | "\n.pagination-page {page-break-after: always; position: relative;}" + 363 | "\nimg {-webkit-region-break-before: always; " + 364 | "-webkit-region-break-after: always;}" + 365 | "\n.pagination-pagenumber, .pagination-header {position: absolute;}" + 366 | "\n.pagination-pagebreak {-webkit-region-break-after: always;}" + 367 | "\n.pagination-simple {height: auto; position-relative;}" + 368 | "\n.pagination-page {margin-left:auto; margin-right:auto;}" + 369 | "\n.pagination-marginnote-item {position:absolute;}" + 370 | "\n.pagination-marginnote > * {display: block;}" + 371 | "\n.pagination-index-page {float:right;}" + 372 | "\n.pagination-index-list div {margin-left: 5px;)"; 373 | document.head.appendChild(stylesheet); 374 | }; 375 | 376 | pagination.setPageStyle = function () { 377 | // Set style for a particular page size. 378 | var unit = pagination.config('lengthUnit'), 379 | marginNotesWidthNumber = pagination.config('marginNotesWidth') * pagination.config('enableMarginNotes'), 380 | marginNotesWidth = marginNotesWidthNumber + unit, 381 | simpleMarginNotesWidth = pagination.config('marginNotesWidth') + unit, 382 | simpleMarginNotesWidthAndMargin = pagination.config('marginNotesWidth') + pagination.config('marginNotesVerticalSeparatorWidth') + unit, 383 | marginNotesSeparatorWidthNumber = pagination.config('marginNotesSeparatorWidth') * pagination.config('enableMarginNotes'), 384 | marginNotesSeparatorWidth = marginNotesSeparatorWidthNumber + unit, 385 | marginNotesVerticalSeparator = pagination.config('marginNotesVerticalSeparatorWidth') + unit, 386 | contentsWidthNumber = pagination.config('pageWidth') - pagination.config( 387 | 'innerMargin') - pagination.config('outerMargin') - (marginNotesWidthNumber + marginNotesSeparatorWidthNumber), 388 | contentsWidth = contentsWidthNumber + unit, 389 | contentsColumnSeparatorWidthNumber = pagination.config('columnSeparatorWidth'), 390 | contentsColumnSeparatorWidth = contentsColumnSeparatorWidthNumber + unit, 391 | columnWidth = contentsWidthNumber / pagination.config('columns') - 392 | (contentsColumnSeparatorWidthNumber * (pagination.config('columns') - 1)) 393 | + unit, 394 | contentsHeightNumber = pagination.config('pageHeight') - pagination 395 | .config('contentsTopMargin') - pagination.config( 396 | 'contentsBottomMargin'), 397 | contentsHeight = contentsHeightNumber + unit, 398 | pageWidth = pagination.config('pageWidth') + unit, 399 | pageHeight = pagination.config('pageHeight') + unit, 400 | contentsBottomMargin = pagination.config('contentsBottomMargin') + 401 | unit, 402 | innerMargin = pagination.config('innerMargin') + unit, 403 | outerMargin = pagination.config('outerMargin') + unit, 404 | pagenumberBottomMargin = pagination.config('pagenumberBottomMargin') + 405 | unit, 406 | headerTopMargin = pagination.config('headerTopMargin') + unit, 407 | imageMaxHeight = contentsHeightNumber - .1 + unit, 408 | imageMaxWidth = contentsWidthNumber - .1 + unit; 409 | 410 | pagination.pageStyleSheet.innerHTML = 411 | ".pagination-page {height:" + pageHeight + "; width:" + pageWidth + 412 | ";" + "background-color: #fff;}" + "\n@page {size:" + pageWidth + 413 | " " + pageHeight + ";}" + "\nbody {background-color: #efefef;}" 414 | // A .page.simple is employed when CSS Regions are not accessible 415 | + "\n.pagination-simple {padding: 1in;}" 416 | // To give the appearance on the screen of pages, add a space of .2in 417 | + "\n@media screen{.pagination-page {border:solid 1px #000; " + 418 | "margin-bottom:.2in;}}" + 419 | "\n.pagination-main-contents-container {width:" + contentsWidth + ";}" + 420 | "\n.pagination-contents-container {bottom:" + contentsBottomMargin + "; height:" + contentsHeight + "; display: -webkit-flex;}" 421 | // Images should at max size be slightly smaller than the contentsWidth. 422 | + "\nimg {max-height: " + imageMaxHeight + ";max-width: " + 423 | imageMaxWidth + ";}" + "\n.pagination-pagenumber {bottom:" + 424 | pagenumberBottomMargin + ";}" + "\n.pagination-header {top:" + 425 | headerTopMargin + ";}" + 426 | "\n#pagination-toc-title:before {content:'Contents';}" + 427 | "\n#pagination-tof-title:before {content:'Figures';}" + 428 | "\n#pagination-tot-title:before {content:'Tables';}" + 429 | "\n.pagination-page:nth-child(odd) .pagination-contents-container, " + 430 | ".pagination-page:nth-child(odd) .pagination-pagenumber," + 431 | ".pagination-page:nth-child(odd) .pagination-header {" + "right:" + 432 | outerMargin + ";left:" + innerMargin + ";}" + 433 | "\n.pagination-page:nth-child(even) .pagination-contents-container, " + 434 | ".pagination-page:nth-child(even) .pagination-pagenumber," + 435 | ".pagination-page:nth-child(even) .pagination-header {" + "right:" + 436 | innerMargin + ";left:" + outerMargin + ";}" + 437 | "\n.pagination-page:nth-child(odd) .pagination-pagenumber," + 438 | ".pagination-page:nth-child(odd) .pagination-header {" + 439 | "text-align:right;}" + 440 | "\n.pagination-page:nth-child(odd) .pagination-header-section {display:none;}" + 441 | "\n.pagination-page:nth-child(even) .pagination-header-chapter {display:none;}" + 442 | "\n.pagination-page:nth-child(even) .pagination-pagenumber," + 443 | ".pagination-page:nth-child(even) .pagination-header {" + 444 | "text-align:left;}" + 445 | "\n.pagination-footnote > * > * {font-size: 0.7em; margin:.25em;}" + 446 | "\n.pagination-footnote > * > *::before, .pagination-footnote::before " + 447 | "{position: relative; top: -0.5em; font-size: 80%;}" + 448 | "\n.pagination-toc-entry .pagination-toc-pagenumber, " + 449 | ".pagination-tof-entry .pagination-tof-pagenumber, " + 450 | ".pagination-tot-entry .pagination-tot-pagenumber {float:right}" 451 | /* This seems to be a bug in Webkit. But unless we set the width of the 452 | * original element that is being flown, some elements extend beyond the 453 | * mainContentsContainer's width. 454 | */ 455 | 456 | + "\n.pagination-contents-item {width:" + columnWidth + ";}" + 457 | "\n.pagination-frontmatter-contents {width:" + contentsWidth + ";}" 458 | + "\n.pagination-contents-column-separator {width:" + contentsColumnSeparatorWidth + ";}" + 459 | // Footnotes in non-CSS Regions browsers will render as right margin notes. 460 | "\n.pagination-simple .pagination-footnote > span, .pagination-simple .pagination-marginnote > span {" + 461 | "position: absolute; right: 0in; width: " + simpleMarginNotesWidth + ";}" + 462 | "\n.pagination-simple {padding-right:" + simpleMarginNotesWidthAndMargin + ";}" + 463 | "\n.pagination-marginnotes, .pagination-marginnote-item {width:" + marginNotesWidth + ";}" + 464 | "\n.pagination-marginnote-item {margin-bottom:" + marginNotesVerticalSeparator + ";}" + 465 | "\n.pagination-marginnotes-separator {width:" + marginNotesSeparatorWidth + ";}" + 466 | "\n.pagination-main-contents-container, .pagination-marginnotes, .pagination-marginnotes-separator {height:" + contentsHeight + ";}"; 467 | }; 468 | 469 | 470 | 471 | pagination.pageCounterCreator = function (cssClass, show) { 472 | /* Create a pagecounter. cssClass is the CSS class employed by this page 473 | * counter to mark all page numbers associated with it. If a show function 474 | * is specified, use this instead of the built-in show function. 475 | */ 476 | this.cssClass = cssClass; 477 | if (show !== undefined) { 478 | this.show = show; 479 | } 480 | }; 481 | 482 | pagination.pageCounterCreator.prototype.value = 0; 483 | // The initial value of any page counter is 0. 484 | 485 | pagination.pageCounterCreator.prototype.needsUpdate = false; 486 | /* needsUpdate controls whether a given page counter should be updated. 487 | * Initially this is not the case. 488 | */ 489 | 490 | pagination.pageCounterCreator.prototype.show = function () { 491 | /* Standard show function for page counter is to show the value itself 492 | * using arabic numbers. 493 | */ 494 | return this.value; 495 | }; 496 | 497 | pagination.pageCounterCreator.prototype.incrementAndShow = function () { 498 | /* Increment the page count by one and return the reuslt page count 499 | * using the show function. 500 | */ 501 | this.value++; 502 | return this.show(); 503 | }; 504 | 505 | 506 | pagination.pageCounterCreator.prototype.numberPages = function () { 507 | /* If the pages associated with this page counter need to be updated, 508 | * go through all of them from the start of the book and number them, 509 | * thereby potentially removing old page numbers. 510 | */ 511 | var pagenumbersToNumber, i; 512 | this.value = 0; 513 | this.needsUpdate = false; 514 | 515 | pagenumbersToNumber = document.querySelectorAll( 516 | '.pagination-page .pagination-pagenumber.pagination-' + this.cssClass); 517 | for (i = 0; i < pagenumbersToNumber.length; i++) { 518 | pagenumbersToNumber[i].innerHTML = this.incrementAndShow(); 519 | } 520 | }; 521 | 522 | pagination.pageCounters = {}; 523 | /* pagination.pageCounters contains all the page counters we use in a book -- 524 | * typically these are two -- roman for the frontmatter and arab for the main 525 | * body contents. 526 | */ 527 | 528 | pagination.pageCounters.arab = new pagination.pageCounterCreator( 529 | 'arabic'); 530 | // arab is the page counter used by the main body contents. 531 | 532 | pagination.pageCounters.roman = new pagination.pageCounterCreator( 533 | 'roman', 534 | pagination.romanize); 535 | // roman is the page counter used by the frontmatter. 536 | 537 | pagination.createPages = function (num, flowName, pageCounterClass, columns) { 538 | // Create the DOM structure of num number of pages. 539 | var page, contents, footnotes, contentsContainer, mainContentsContainer, column, columnSeparator, 540 | topfloats, header, chapterheader, sectionheader, pagenumberfield, 541 | marginNotesContainer, marginNotesSeparator, i, j, 542 | tempRoot = document.createDocumentFragment(); 543 | 544 | for (i = 0; i < num; i++) { 545 | page = document.createElement('div'); 546 | page.classList.add('pagination-page'); 547 | page.id = pagination.createRandomId('pagination-page-'); 548 | 549 | header = document.createElement('div'); 550 | header.classList.add('pagination-header'); 551 | 552 | chapterheader = document.createElement('span'); 553 | chapterheader.classList.add('pagination-header-chapter'); 554 | header.appendChild(chapterheader); 555 | 556 | sectionheader = document.createElement('span'); 557 | sectionheader.classList.add('pagination-header-section'); 558 | header.appendChild(sectionheader); 559 | 560 | page.appendChild(header); 561 | 562 | if (pagination.config('numberPages')) { 563 | pagenumberfield = document.createElement('div'); 564 | pagenumberfield.classList.add('pagination-pagenumber'); 565 | pagenumberfield.classList.add('pagination-' + pageCounterClass); 566 | 567 | page.appendChild(pagenumberfield); 568 | } 569 | 570 | // If flowName is given, create a page with content flow. 571 | if (flowName) { 572 | contentsContainer = document.createElement('div'); 573 | contentsContainer.classList.add('pagination-contents-container'); 574 | 575 | mainContentsContainer = document.createElement('div'); 576 | mainContentsContainer.classList.add('pagination-main-contents-container'); 577 | 578 | topfloats = document.createElement('div'); 579 | topfloats.classList.add('pagination-topfloats'); 580 | 581 | contents = document.createElement('div'); 582 | contents.classList.add('pagination-contents'); 583 | 584 | for (j = 0; j < columns; j++) { 585 | column = document.createElement('div'); 586 | column.classList.add('pagination-contents-column'); 587 | contents.appendChild(column); 588 | 589 | if ((columns - j) > 1) { 590 | columnSeparator = document.createElement('div'); 591 | columnSeparator.classList.add('pagination-contents-column-separator'); 592 | contents.appendChild(columnSeparator); 593 | } 594 | } 595 | 596 | footnotes = document.createElement('div'); 597 | footnotes.classList.add('pagination-footnotes'); 598 | 599 | mainContentsContainer.appendChild(topfloats); 600 | mainContentsContainer.appendChild(contents); 601 | mainContentsContainer.appendChild(footnotes); 602 | contentsContainer.appendChild(mainContentsContainer); 603 | 604 | // Containers for margin notes 605 | marginNotesSeparator = document.createElement('div'); 606 | marginNotesSeparator.classList.add('pagination-marginnotes-separator'); 607 | 608 | marginNotesContainer = document.createElement('div'); 609 | marginNotesContainer.classList.add('pagination-marginnotes'); 610 | 611 | if (i%2 == 0) { 612 | contentsContainer.appendChild(marginNotesSeparator); 613 | contentsContainer.appendChild(marginNotesContainer); 614 | } else { 615 | contentsContainer.insertBefore(marginNotesSeparator, contentsContainer.firstChild); 616 | contentsContainer.insertBefore(marginNotesContainer, contentsContainer.firstChild); 617 | } 618 | 619 | page.appendChild(contentsContainer); 620 | // If no flowName is given, an empty page is created. 621 | } else { 622 | page.classList.add('pagination-empty'); 623 | } 624 | 625 | tempRoot.appendChild(page); 626 | } 627 | return tempRoot; 628 | }; 629 | 630 | pagination.events = {}; 631 | // pagination.events represents all the events created specifically by BookJS. 632 | 633 | pagination.events.bodyLayoutUpdated = document.createEvent('Event'); 634 | pagination.events.bodyLayoutUpdated.initEvent( 635 | 'bodyLayoutUpdated', 636 | true, 637 | true); 638 | /* bodyLayoutUpdated is emitted when pages have been added or removed from any 639 | * body flowObject. 640 | */ 641 | 642 | pagination.events.layoutFlowFinished = document.createEvent('Event'); 643 | pagination.events.layoutFlowFinished.initEvent( 644 | 'layoutFlowFinished', 645 | true, 646 | true); 647 | /* layoutFlowFinished is emitted the first time the flow of the entire book has 648 | * been created. 649 | */ 650 | 651 | pagination.events.pageLayoutUpdate = document.createEvent('Event'); 652 | pagination.events.pageLayoutUpdate.initEvent( 653 | 'pageLayoutUpdate', 654 | true, 655 | true); 656 | /* pageLayoutUpdate is emitted when new pages have to added or excess pages be 657 | * removed. 658 | */ 659 | 660 | pagination.events.escapesNeedMove = document.createEvent('Event'); 661 | pagination.events.escapesNeedMove.initEvent( 662 | 'escapesNeedMove', 663 | true, 664 | true); 665 | /* escapesNeedMove is emitted when at least one reference to a an escape 666 | * node (footnote, top float) no longer is on the page where it used to be. 667 | */ 668 | 669 | pagination.events.marginnotesNeedMove = document.createEvent('Event'); 670 | pagination.events.marginnotesNeedMove.initEvent( 671 | 'marginnotesNeedMove', 672 | true, 673 | true); 674 | /* escapesNeedMove is emitted when at least one reference to a an escape 675 | * node (footnote, top float) no longer is on the page where it used to be. 676 | */ 677 | 678 | pagination.events.redoEscapes = document.createEvent('Event'); 679 | pagination.events.redoEscapes.initEvent( 680 | 'redoEscapes', 681 | true, 682 | true); 683 | /* redoEscapes is being listened to by BookJS to see when escape nodes 684 | * (footnotes, top floats) need to be refound and redrawn. This can be used 685 | * by editors that need to add new footnotes or top floats. 686 | */ 687 | 688 | pagination.tof = function (bodyObjects) { 689 | /* Go through all pages of all flowobjects, looking for all figures to 690 | * create a "table of figures". 691 | */ 692 | var tofDiv, tofTitleH1, figures, figure, image, title, caption, pagenumber, tofItemDiv, tofItemTextSpan, tofItemPnSpan, tofItemPnText, i, j; 693 | 694 | 695 | tofDiv = document.createElement('div'); 696 | tofDiv.id = 'pagination-tof'; 697 | 698 | tofTitleH1 = document.createElement('h1'); 699 | tofTitleH1.id = 'pagination-tof-title'; 700 | 701 | tofDiv.appendChild(tofTitleH1); 702 | 703 | 704 | for (i = 0; i < bodyObjects.length; i++) { 705 | figures = bodyObjects[i].rawdiv.querySelectorAll('figure'); 706 | for (j = 0; j < figures.length; j++) { 707 | figure = figures[j]; 708 | 709 | if (pagination.config('enableTableOfTables') && figure.querySelector('table')) { 710 | continue; 711 | } 712 | image = figure.querySelector('img'); 713 | caption = figure.querySelector('figcaption'); 714 | if (image && image.alt !== '') { 715 | title = image.alt; 716 | } else if (caption) { 717 | title = caption.innerText; 718 | } else { 719 | title = 'Figure '+ i + '.' + j; 720 | } 721 | pagenumber = pagination.findPage(figure).querySelector('.pagination-pagenumber').innerText; 722 | tofItemDiv = document.createElement('div'); 723 | tofItemDiv.classList.add('pagination-tof-entry'); 724 | tofItemTextSpan = document.createElement('span'); 725 | tofItemTextSpan.classList.add('pagination-tof-text'); 726 | tofItemTextSpan.innerHTML = title; 727 | tofItemDiv.appendChild(tofItemTextSpan); 728 | 729 | tofItemPnSpan = document.createElement('span'); 730 | tofItemPnSpan.classList.add('pagination-tof-pagenumber'); 731 | 732 | tofItemPnText = document.createTextNode(pagenumber); 733 | tofItemPnSpan.appendChild(tofItemPnText); 734 | 735 | tofItemDiv.appendChild(tofItemPnSpan); 736 | 737 | tofDiv.appendChild(tofItemDiv); 738 | 739 | } 740 | } 741 | 742 | return tofDiv; 743 | 744 | } 745 | 746 | pagination.closest = function(element, searchedFor) { 747 | if (element.webkitMatchesSelector(searchedFor)) { 748 | return element; 749 | } else { 750 | return pagination.closest(element.parentNode, searchedFor); 751 | } 752 | }; 753 | 754 | pagination.tot = function (bodyObjects) { 755 | /* Go through all pages of all flowobjects, looking for all tables within figures to 756 | * create a "table of tables". 757 | */ 758 | var totDiv, totTitleH1, tables, figure, table, title, caption, pagenumber, totItemDiv, totItemTextSpan, totItemPnSpan, totItemPnText, i, j; 759 | 760 | 761 | totDiv = document.createElement('div'); 762 | totDiv.id = 'pagination-tot'; 763 | 764 | totTitleH1 = document.createElement('h1'); 765 | totTitleH1.id = 'pagination-tot-title'; 766 | 767 | totDiv.appendChild(totTitleH1); 768 | 769 | for (i = 0; i < bodyObjects.length; i++) { 770 | tables = bodyObjects[i].rawdiv.querySelectorAll('figure table'); 771 | for (j = 0; j < tables.length; j++) { 772 | figure = pagination.closest(tables[j], 'figure'); 773 | caption = figure.querySelector('figcaption'); 774 | if (caption) { 775 | title = caption.innerText; 776 | } else { 777 | title = 'Table '+ i + '.' + j; 778 | } 779 | pagenumber = pagination.findPage(figure).querySelector('.pagination-pagenumber').innerText; 780 | totItemDiv = document.createElement('div'); 781 | totItemDiv.classList.add('pagination-tot-entry'); 782 | totItemTextSpan = document.createElement('span'); 783 | totItemTextSpan.classList.add('pagination-tot-text'); 784 | totItemTextSpan.innerHTML = title; 785 | totItemDiv.appendChild(totItemTextSpan); 786 | 787 | totItemPnSpan = document.createElement('span'); 788 | totItemPnSpan.classList.add('pagination-tot-pagenumber'); 789 | 790 | totItemPnText = document.createTextNode(pagenumber); 791 | totItemPnSpan.appendChild(totItemPnText); 792 | 793 | totItemDiv.appendChild(totItemPnSpan); 794 | 795 | totDiv.appendChild(totItemDiv); 796 | 797 | } 798 | } 799 | 800 | return totDiv; 801 | 802 | } 803 | 804 | pagination.findPage = function (object) { 805 | /* Find the page a certain element is placed on 806 | */ 807 | // TODO: cache some of these values, as they will be reused every time. 808 | var allPages, firstPage, firstPageOffsetTop, lastPage, lastPageOffsetTop, pageStartDistance, objectOffsetTop, pageNumber; 809 | allPages = document.querySelectorAll('.pagination-page'); 810 | firstPage = allPages[0]; 811 | firstPageOffsetTop = firstPage.getBoundingClientRect()['top']; 812 | lastPage = allPages[allPages.length-1]; 813 | lastPageOffsetTop = lastPage.getBoundingClientRect()['top']; 814 | pageStartDistance = (lastPageOffsetTop - firstPageOffsetTop)/(allPages.length-1); 815 | 816 | objectOffsetTop = object.getBoundingClientRect()['top']; 817 | pageNumber = parseInt((objectOffsetTop - firstPageOffsetTop)/pageStartDistance, 10); 818 | return allPages[pageNumber]; 819 | 820 | }; 821 | 822 | pagination.marginNotesContainerStartDistance = false; 823 | pagination.firstMarginNotesContainerOffsetTop = false; 824 | 825 | pagination.setMarginNotesContainerStartDistance = function () { 826 | /* Find the actual distance between the margin note containers between 827 | * pages and the top offset for the first page. We assume that the 828 | * first two pages are not empty for this to work. 829 | */ 830 | var allPages, 831 | firstMarginNotesContainer, 832 | firstMarginNotesContainerOffsetTop, 833 | secondMarginNotesContainer, 834 | secondMarginNotesContainersOffsetTop, 835 | marginNotesContainerStartDistance; 836 | allPages = document.querySelectorAll('.pagination-page'); 837 | firstMarginNotesContainer = allPages[0].querySelector('.pagination-marginnotes'); 838 | pagination.firstMarginNotesContainerOffsetTop = firstMarginNotesContainer.getBoundingClientRect()['top'] + window.pageYOffset; 839 | secondMarginNotesContainer = allPages[1].querySelector('.pagination-marginnotes'); 840 | secondMarginNotesContainersOffsetTop = secondMarginNotesContainer.getBoundingClientRect()['top'] + window.pageYOffset; 841 | pagination.marginNotesContainerStartDistance = secondMarginNotesContainersOffsetTop - pagination.firstMarginNotesContainerOffsetTop; 842 | }; 843 | 844 | pagination.findMarginNotesContainerAndOffset = function (object) { 845 | /* Find the margin note container next to the object, and the top 846 | * offset within it. 847 | */ 848 | 849 | var allPages, objectOffsetTop, containerNumber, offsetTopWithinContainer; 850 | 851 | if (!pagination.marginNotesContainerStartDistance) { 852 | pagination.setMarginNotesContainerStartDistance(); 853 | }; 854 | 855 | allPages = document.querySelectorAll('.pagination-page'); 856 | objectOffsetTop = object.getBoundingClientRect()['top'] + window.pageYOffset; 857 | 858 | containerNumber = parseInt((objectOffsetTop - pagination.firstMarginNotesContainerOffsetTop)/pagination.marginNotesContainerStartDistance, 10); 859 | 860 | offsetTopWithinContainer = objectOffsetTop - containerNumber * (pagination.marginNotesContainerStartDistance) - pagination.firstMarginNotesContainerOffsetTop; 861 | return [allPages[containerNumber].querySelector('.pagination-marginnotes'), offsetTopWithinContainer, objectOffsetTop]; 862 | }; 863 | 864 | pagination.adjustMarginNotesPositionsPerPage = function (marginNotesContainer) { 865 | /* Adjust the placement of all the margin notes on one particular page. 866 | */ 867 | var marginNotesItems = marginNotesContainer.querySelectorAll('.pagination-marginnote-item'), marginNotesList = [], i; 868 | 869 | if (marginNotesItems.length === 0) { 870 | return false; 871 | } 872 | 873 | for (i = 0; i < marginNotesItems.length; i++) { 874 | marginNotesList.push(marginNotesItems[i]); 875 | } 876 | 877 | marginNotesList.sort(function(a, b) { 878 | return a.offsetTop == b.offsetTop ? 0 : (a.offsetTop > b.offsetTop ? 1 : -1); 879 | }); 880 | 881 | for (i = 1; i < marginNotesList.length; i++) { 882 | if ((marginNotesList[i-1].offsetTop + marginNotesList[i-1].offsetHeight + parseInt(window.getComputedStyle(marginNotesList[i-1]).marginBottom)) > marginNotesList[i].offsetTop ) { 883 | marginNotesList[i].style.top = (marginNotesList[i-1].offsetTop + marginNotesList[i-1].offsetHeight + parseInt(window.getComputedStyle(marginNotesList[i-1]).marginBottom)) + 'px'; 884 | } 885 | } 886 | 887 | if (marginNotesList[marginNotesList.length-1].offsetTop + marginNotesList[marginNotesList.length-1].offsetHeight > marginNotesContainer.offsetHeight) { 888 | marginNotesList[marginNotesList.length-1].style.top = (marginNotesContainer.offsetHeight - marginNotesList[marginNotesList.length-1].offsetHeight) + 'px'; 889 | for (i = (marginNotesList.length-2); i > -1; i--) { 890 | if (marginNotesList[i+1].offsetTop < (marginNotesList[i].offsetTop + marginNotesList[i].offsetHeight + parseInt(window.getComputedStyle(marginNotesList[i]).marginBottom)) ) { 891 | marginNotesList[i].style.top = (marginNotesList[i+1].offsetTop - (marginNotesList[i].offsetHeight + parseInt(window.getComputedStyle(marginNotesList[i]).marginBottom)) ) + 'px'; 892 | } else { 893 | break; 894 | } 895 | } 896 | 897 | } 898 | 899 | return true; 900 | }; 901 | 902 | pagination.adjustAllMarginNotesPositions = function () { 903 | /* Add margin notes for the entire document 904 | */ 905 | var allMarginNoteContainers = document.querySelectorAll('.pagination-marginnotes'), i; 906 | 907 | for (i=0; i < allMarginNoteContainers.length; i++) { 908 | pagination.adjustMarginNotesPositionsPerPage(allMarginNoteContainers[i]); 909 | } 910 | }; 911 | 912 | pagination.findAllCrossReferences = function () { 913 | /* Find all links that point to places within the same document 914 | */ 915 | var flowElement = eval(pagination.config('flowElement')), allReferences = flowElement.querySelectorAll('a'), referredElement, pageNumber, i; 916 | 917 | for (i=0; i < allReferences.length;i++) { 918 | if (allReferences[i].getAttribute('href')[0]==='#') { 919 | referredElement = flowElement.querySelector(allReferences[i].getAttribute('href')); 920 | pageNumber = pagination.findPage(referredElement).querySelector('.pagination-pagenumber').innerHTML; 921 | if (allReferences[i].innerHTML !== pageNumber) { 922 | allReferences[i].innerHTML = pageNumber; 923 | } 924 | } 925 | } 926 | }; 927 | 928 | pagination.orderIndexItem = function (itemList, indexTerms, page) { 929 | /* take an index item as output by findAllIndexItems and order it. 930 | */ 931 | if (itemList.length===0) { 932 | if (!(indexTerms.hasOwnProperty('pagination-index-page'))) { 933 | indexTerms['pagination-index-page'] = []; 934 | } else if (indexTerms['pagination-index-page'][indexTerms['pagination-index-page'].length-1]===page) { 935 | // last page is same as this page 936 | return; 937 | } 938 | 939 | indexTerms['pagination-index-page'].push(page); 940 | return; 941 | } 942 | if (!(indexTerms.hasOwnProperty(itemList[0]))) { 943 | indexTerms[itemList[0]] = {}; 944 | } 945 | 946 | var subIndexTerms = indexTerms[itemList.shift()]; 947 | 948 | pagination.orderIndexItem(itemList,subIndexTerms,page); 949 | return; 950 | }; 951 | 952 | pagination.findAllIndexItems = function () { 953 | /* find all index items. 954 | */ 955 | var allIndexItems = document.querySelectorAll('.pagination-index'), pageNumber, indexTerms = {}, indexTerm, i; 956 | 957 | for (i=0; i < allIndexItems.length; i++) { 958 | indexTerm = allIndexItems[i].getAttribute('data-pagination-index').split('!'); 959 | pagination.orderIndexItem(indexTerm, indexTerms, pagination.findPage(allIndexItems[i]).querySelector('.pagination-pagenumber').innerHTML); 960 | } 961 | return indexTerms; 962 | }; 963 | 964 | pagination.sortAssociativeArray = function (associativeArray) { 965 | var keys = []; 966 | for (key in associativeArray) { 967 | keys.push(key); 968 | } 969 | return keys.sort(); 970 | }; 971 | 972 | pagination.layoutWordIndex = function (indexTerms, element) { 973 | var keys = pagination.sortAssociativeArray(indexTerms), newElement, pageElement, i; 974 | for (i=0; i < keys.length;i++) { 975 | if (keys[i] === 'pagination-index-page') { 976 | pageElement = document.createElement('span'); 977 | pageElement.classList.add('pagination-index-page'); 978 | 979 | pageElement.innerHTML = indexTerms[keys[i]]; 980 | element.insertBefore(pageElement, element.firstChild.nextSibling); 981 | } else { 982 | newElement = document.createElement('div'); 983 | newElement.innerHTML = '' + keys[i] + ''; 984 | element.appendChild(newElement); 985 | pagination.layoutWordIndex(indexTerms[keys[i]], newElement); 986 | } 987 | } 988 | 989 | }; 990 | 991 | pagination.createWordIndex = function () { 992 | var wordIndexElement = document.querySelector('.pagination-index-list'), newElement = document.createElement('div'); 993 | 994 | if (!wordIndexElement) { 995 | return; 996 | } 997 | 998 | pagination.layoutWordIndex(pagination.findAllIndexItems(), newElement); 999 | 1000 | if (wordIndexElement && (wordIndexElement.innerHTML !== newElement.innerHTML)) { 1001 | wordIndexElement.innerHTML = newElement.innerHTML; 1002 | } 1003 | 1004 | }; 1005 | 1006 | 1007 | pagination.headersAndToc = function (bodyObjects) { 1008 | /* Go through all pages of all flowObjects and add page headers and 1009 | * calculate the table fo contents (TOC) for the frontmatter. This has to 1010 | * be done after all pages representing the body of the text have been 1011 | * flown and has to redone when there are changes to the body contents that 1012 | * can influence the TOC (such as page creation or deletion). 1013 | */ 1014 | var currentChapterTitle = '', currentSectionTitle = '', pages, chapterHeader, sectionHeader, tocDiv, tocItemDiv, tocItemPnText, tocTitleH1, tocItemPnSpan, tocItemTextSpan, 1015 | i, j; 1016 | 1017 | if (pagination.config('numberPages')) { 1018 | tocDiv = document.createElement('div'); 1019 | tocDiv.id = 'pagination-toc'; 1020 | 1021 | tocTitleH1 = document.createElement('h1'); 1022 | tocTitleH1.id = 'pagination-toc-title'; 1023 | 1024 | tocDiv.appendChild(tocTitleH1); 1025 | } 1026 | 1027 | 1028 | for (i = 0; i < bodyObjects.length; i++) { 1029 | bodyObjects[i].findTitle(); 1030 | bodyObjects[i].findStartpageNumber(); 1031 | 1032 | if (bodyObjects[i].type === 'chapter') { 1033 | currentChapterTitle = bodyObjects[i].title; 1034 | } else if (bodyObjects[i].type === 'section') { 1035 | currentSectionTitle = bodyObjects[i].title; 1036 | } 1037 | pages = bodyObjects[i].div.childNodes; 1038 | 1039 | for (j = 0; j < pages.length; j++) { 1040 | chapterHeader = pages[j].querySelector( 1041 | '.pagination-header .pagination-header-chapter'); 1042 | if (chapterHeader) { 1043 | chapterHeader.innerHTML = currentChapterTitle; 1044 | } 1045 | 1046 | sectionHeader = pages[j].querySelector( 1047 | '.pagination-header .pagination-header-section'); 1048 | if (sectionHeader) { 1049 | sectionHeader.innerHTML = currentSectionTitle; 1050 | } 1051 | } 1052 | 1053 | if (bodyObjects[i].type && pagination.config('numberPages') && (typeof(bodyObjects[i].startpageNumber) != 'undefined')) { 1054 | 1055 | tocItemDiv = document.createElement('div'); 1056 | tocItemDiv.classList.add('pagination-toc-entry'); 1057 | tocItemDiv.classList.add(bodyObjects[i].type); 1058 | 1059 | tocItemTextSpan = document.createElement('span'); 1060 | tocItemTextSpan.classList.add('pagination-toc-text'); 1061 | 1062 | tocItemTextSpan.innerHTML = bodyObjects[i].title; 1063 | tocItemDiv.appendChild(tocItemTextSpan); 1064 | 1065 | tocItemPnSpan = document.createElement('span'); 1066 | tocItemPnSpan.classList.add('pagination-toc-pagenumber'); 1067 | 1068 | tocItemPnText = document.createTextNode( 1069 | bodyObjects[i].startpageNumber); 1070 | tocItemPnSpan.appendChild(tocItemPnText); 1071 | 1072 | tocItemDiv.appendChild(tocItemPnSpan); 1073 | 1074 | tocDiv.appendChild(tocItemDiv); 1075 | 1076 | } 1077 | 1078 | } 1079 | 1080 | return tocDiv; 1081 | }; 1082 | 1083 | pagination.createBodyObjects = function () { 1084 | /* Go through the entire body contents and look for chapterStartMarker and 1085 | * sectionStartMarker to divide it up. We will then float these elements 1086 | * individually, as CSS Regions has problems flowing material that requires 1087 | * 100+ regions. 1088 | */ 1089 | var bodyObjects = [], chapterCounter = 0, bodyContainer, bodyContents, i; 1090 | 1091 | bodyObjects.push( 1092 | new pagination.flowObject( 1093 | 'pagination-body-pre', 1094 | pagination.pageCounters.arab)); 1095 | 1096 | bodyContainer = eval(pagination.config('flowElement')); 1097 | bodyContents = bodyContainer.childNodes; 1098 | 1099 | 1100 | for (i = bodyContents.length; i > 0; i--) { 1101 | 1102 | if (bodyContents[0].nodeType === 1) { 1103 | if ( 1104 | bodyContents[0].webkitMatchesSelector( 1105 | pagination.config('chapterStartMarker'))) { 1106 | bodyObjects.push( 1107 | new pagination.flowObject( 1108 | 'pagination-body-' + chapterCounter++, 1109 | pagination.pageCounters.arab)); 1110 | bodyObjects[chapterCounter].setType('chapter'); 1111 | 1112 | } else if ( 1113 | bodyContents[0].webkitMatchesSelector( 1114 | pagination.config('sectionStartMarker'))) { 1115 | bodyObjects.push( 1116 | new pagination.flowObject( 1117 | 'pagination-body-' + chapterCounter++, 1118 | pagination.pageCounters.arab)); 1119 | bodyObjects[chapterCounter].setType('section'); 1120 | } 1121 | } 1122 | 1123 | bodyObjects[chapterCounter].rawdiv.appendChild(bodyContents[0]); 1124 | } 1125 | 1126 | return bodyObjects; 1127 | 1128 | }; 1129 | 1130 | pagination.applyBookLayoutNonDestructive = function () { 1131 | // Apply layout without changing the original DOM. 1132 | var rawdiv, bodyObject, layoutDiv; 1133 | 1134 | if (eval(pagination.config('flowElement')) === document.body) { 1135 | /* We are reflowing the body itself, yet the layout will be added to 1136 | * the body. This will make the broser crash. So we need to move the 1137 | * original contents inside a Div of its own first. 1138 | */ 1139 | rawdiv = document.createElement('div'); 1140 | rawdiv.id = 'pagination-contents'; 1141 | rawdiv.innerHTML = document.body.innerHTML; 1142 | document.body.innerHTML = ''; 1143 | document.body.appendChild(rawdiv); 1144 | 1145 | } else { 1146 | rawdiv = eval(pagination.config('flowElement')); 1147 | } 1148 | 1149 | bodyObject = new pagination.flowObject( 1150 | 'body', 1151 | pagination.pageCounters.arab, 1152 | rawdiv); 1153 | 1154 | // Create div for layout 1155 | layoutDiv = document.createElement('div'); 1156 | layoutDiv.id = 'pagination-layout'; 1157 | layoutDiv.appendChild(bodyObject.div); 1158 | 1159 | document.body.appendChild(layoutDiv); 1160 | 1161 | bodyObject.initiate(); 1162 | document.dispatchEvent(pagination.events.layoutFlowFinished); 1163 | }; 1164 | 1165 | pagination.applyBookLayout = function () { 1166 | /* Apply this layout if CSS Regions are present. 1167 | * Will first divide the original DOM up into individual chapters and 1168 | * sections. 1169 | */ 1170 | var bodyObjects, layoutDiv, contentsDiv, toc, tof, tot, redoToc, fmObject, i; 1171 | 1172 | bodyObjects = pagination.createBodyObjects(); 1173 | 1174 | // Create div for layout 1175 | layoutDiv = document.createElement('div'); 1176 | layoutDiv.id = 'pagination-layout'; 1177 | document.body.appendChild(layoutDiv); 1178 | 1179 | // Create div for contents 1180 | contentsDiv = document.createElement('div'); 1181 | contentsDiv.id = 'pagination-contents'; 1182 | document.body.appendChild(contentsDiv); 1183 | 1184 | 1185 | for (i = 0; i < bodyObjects.length; i++) { 1186 | layoutDiv.appendChild(bodyObjects[i].div); 1187 | contentsDiv.appendChild(bodyObjects[i].rawdiv); 1188 | bodyObjects[i].initiate(); 1189 | } 1190 | 1191 | pagination.pageCounters.arab.numberPages(); 1192 | 1193 | if (pagination.config('enableFrontmatter')) { 1194 | //Create and flow frontmatter 1195 | fmObject = new pagination.flowObject( 1196 | 'pagination-frontmatter', 1197 | pagination.pageCounters.roman, 1198 | false); 1199 | fmObject.columns = 1; 1200 | contentsDiv.insertBefore(fmObject.rawdiv, contentsDiv.firstChild); 1201 | fmObject.rawdiv.innerHTML = pagination.config('frontmatterContents'); 1202 | toc = pagination.headersAndToc(bodyObjects); 1203 | 1204 | if (pagination.config('numberPages')) { 1205 | fmObject.rawdiv.appendChild(toc); 1206 | } 1207 | if (pagination.config('enableTableOfFigures')) { 1208 | tof = pagination.tof(bodyObjects); 1209 | fmObject.rawdiv.appendChild(tof); 1210 | } 1211 | if (pagination.config('enableTableOfTables')) { 1212 | tot = pagination.tot(bodyObjects); 1213 | fmObject.rawdiv.appendChild(tot); 1214 | } 1215 | layoutDiv.insertBefore(fmObject.div, bodyObjects[0].div); 1216 | fmObject.initiate(); 1217 | redoToc = function () { 1218 | var oldToc = toc; 1219 | toc = pagination.headersAndToc(bodyObjects); 1220 | fmObject.rawdiv.replaceChild(toc, oldToc); 1221 | if (pagination.config('enableTableOfFigures')) { 1222 | var oldTof = tof; 1223 | tof = pagination.tof(bodyObjects); 1224 | fmObject.rawdiv.replaceChild(tof, oldTof); 1225 | } 1226 | if (pagination.config('enableTableOfTables')) { 1227 | var oldTot = tot; 1228 | tot = pagination.tot(bodyObjects); 1229 | fmObject.rawdiv.replaceChild(tot, oldTot); 1230 | } 1231 | if (pagination.config('enableCrossReferences')) { 1232 | pagination.findAllCrossReferences(); 1233 | } 1234 | if (pagination.config('enableWordIndex')) { 1235 | pagination.createWordIndex(); 1236 | } 1237 | }; 1238 | document.body.addEventListener('bodyLayoutUpdated', function() { 1239 | // We have to set a time out of zero to make sure fonts have been applied, etc. before toc and tof are being calculated. 1240 | // TODO: Ideally, this shouldn't be needed. 1241 | setTimeout(redoToc, 0); 1242 | 1243 | }); 1244 | if (document.hasOwnProperty('fontloader')) { 1245 | document.fontloader.addEventListener('loadingdone', function() { 1246 | // When fonts have been loaded, update the body layout. 1247 | // TODO: This does not seem to work at all times. 1248 | document.body.dispatchEvent(pagination.events.bodyLayoutUpdated); 1249 | }); 1250 | } 1251 | } 1252 | if (pagination.config('enableCrossReferences')) { 1253 | pagination.findAllCrossReferences(); 1254 | } 1255 | 1256 | if (pagination.config('enableWordIndex')) { 1257 | pagination.createWordIndex(); 1258 | } 1259 | document.dispatchEvent(pagination.events.layoutFlowFinished); 1260 | }; 1261 | 1262 | 1263 | pagination.applySimpleBookLayout = function () { 1264 | // Apply this alternative layout in case CSS Regions are not present 1265 | var contentsDiv, simplePage; 1266 | 1267 | if (eval(pagination.config('flowElement')) === document.body) { 1268 | /* We are reflowing the body itself, yet the layout will be added to 1269 | * the body. This will make the broser crash. So we need to move the 1270 | * original contents inside a Div of its own first. 1271 | */ 1272 | contentsDiv = document.createElement('div'); 1273 | contentsDiv.id = 'pagination-contents'; 1274 | contentsDiv.innerHTML = document.body.innerHTML; 1275 | document.body.innerHTML = ''; 1276 | document.body.appendChild(contentsDiv); 1277 | 1278 | if (!window.hasOwnProperty('paginationConfig')) { 1279 | window.paginationConfig = {}; 1280 | } 1281 | paginationConfig.flowElement = 1282 | "document.getElementById('pagination-contents')"; 1283 | } 1284 | 1285 | simplePage = eval(pagination.config('flowElement')); 1286 | //var simplePage = document.createElement('div'); 1287 | simplePage.classList.add('pagination-page'); 1288 | simplePage.classList.add('pagination-simple'); 1289 | //simplePage.innerHTML = bodyContainer.innerHTML; 1290 | //simplePage.id = bodyContainer.id; 1291 | //bodyContainer.innerHTML = ''; 1292 | //document.body.appendChild(simplePage); 1293 | pagination.adjustSimpleEscapenotes(simplePage); 1294 | 1295 | var observerOptions = { 1296 | attributes: false, 1297 | subtree: true, 1298 | characterData: true, 1299 | childList: true 1300 | }; 1301 | 1302 | var observer = new MutationObserver(function (mutations) { 1303 | observer.disconnect(); 1304 | pagination.adjustSimpleEscapenotes(simplePage); 1305 | observer.observe(simplePage,observerOptions); 1306 | }); 1307 | observer.observe(simplePage,observerOptions); 1308 | document.dispatchEvent(pagination.events.layoutFlowFinished); 1309 | }; 1310 | 1311 | pagination.resetSimpleEscapenotes = function () { 1312 | var escapenotes = eval(pagination.config('flowElement')).querySelectorAll(pagination.config('footnoteSelector')+' > *, '+ pagination.config('marginnoteSelector') + ' > *'), i; 1313 | for (i=0;i *, '+ pagination.config('marginnoteSelector') + ' > *'), i; 1320 | if (escapenotes.length > 0 && escapenotes[0].style.top !== '') { 1321 | escapenotes[0].style.top = ''; 1322 | } 1323 | if (escapenotes.length > 1) { 1324 | escapenotes[0].style.top=''; 1325 | for (i=1;i 0 && pagination.config('numberPages')) { 1502 | startpageNumberField = 1503 | this.div.querySelector('.pagination-pagenumber'); 1504 | if (startpageNumberField) { 1505 | this.startpageNumber = startpageNumberField.innerText; 1506 | } 1507 | } 1508 | }; 1509 | 1510 | // Footnote and top float handling 1511 | 1512 | flowObject.prototype.findEscapeReferencePage = function ( 1513 | escapeReference) { 1514 | /* Find the page where the the escape would be placed in the body text. 1515 | */ 1516 | var escapeReferenceNode; 1517 | if (!escapeReference) { 1518 | return false; 1519 | } 1520 | escapeReferenceNode = this.namedFlow.getRegionsByContent( 1521 | escapeReference)[0]; 1522 | if (escapeReferenceNode) { 1523 | return escapeReferenceNode.parentNode.parentNode.parentNode; 1524 | } else { 1525 | /* A bug in Webkit means that we don't find the footnote at times. In these 1526 | * situations we look for the parent element instead. 1527 | */ 1528 | return this.findEscapeReferencePage(escapeReference.parentNode); 1529 | } 1530 | }; 1531 | 1532 | flowObject.prototype.findEscapePage = function (escapeNode) { 1533 | if (escapeNode.parentNode) { 1534 | // Find the page where the escape itself is currently placed. 1535 | return escapeNode.parentNode.parentNode.parentNode; 1536 | } else { 1537 | return false; 1538 | } 1539 | }; 1540 | 1541 | flowObject.prototype.placeAllEscapes = function () { 1542 | /* Find and place all escapes. Then freeze the pages of the references 1543 | * to these. 1544 | */ 1545 | this.layoutTopfloats(); 1546 | this.layoutFootnotes(); 1547 | this.layoutMarginnotes(); 1548 | this.freezeEscapeReferencePages(); 1549 | }; 1550 | 1551 | flowObject.prototype.freezeEscapeReferencePages = function () { 1552 | /* For all the references of top/bottom escapes (topfloats, footnotes), 1553 | * note the page they are on. This way we can compare to this 1554 | * list when changes have been made and determine whether footnotes need to be reflown. 1555 | */ 1556 | var escapeTypes = ['footnote', 'topfloat', 'marginnote'], j, i; 1557 | 1558 | for (j = 0; j < escapeTypes.length; j++) { 1559 | for (i = 0; i < this.escapes[escapeTypes[j]].length; i++) { 1560 | this.escapes[escapeTypes[j]][i]['referencePage'] = 1561 | this.findEscapeReferencePage( 1562 | this.escapes[escapeTypes[j]][i]['reference']); 1563 | if (escapeTypes[j]==='marginnote') { 1564 | this.escapes[escapeTypes[j]][i]['referenceTopOffset'] = 1565 | this.escapes[escapeTypes[j]][i]['reference'].getBoundingClientRect()['top'] + window.pageYOffset; 1566 | } 1567 | } 1568 | } 1569 | }; 1570 | 1571 | flowObject.prototype.freezeMarginnoteOffsetTop = function () { 1572 | /* For all the references of margin notes, 1573 | * note their top offset. This way we can compare to this 1574 | * list when changes have been made and determine whether margin notes need to be moved. 1575 | */ 1576 | var i; 1577 | for (i = 0; i < this.escapes.marginnote.length; i++) { 1578 | this.escapes.marginnote[i]['referenceOffsetTop'] = 1579 | this.escapes.marginnote[i]['reference'].offsetTop; 1580 | } 1581 | }; 1582 | 1583 | flowObject.prototype.checkAllEscapeReferencePagesPlacements = function () { 1584 | /* For all the references of top/bottom escapes (topfloats, footnotes), 1585 | * check if they are still on the same page they were on when we froze 1586 | * them. If one has changed, dispatch a redoEscapes event. 1587 | */ 1588 | var escapeTypes = ['footnote', 'topfloat', 'marginnote'], j, i; 1589 | 1590 | for (j = 0; j < escapeTypes.length; j++) { 1591 | for (i = 0; i < this.escapes[escapeTypes[j]].length; i++) { 1592 | 1593 | if (document.getElementById(this.escapes[escapeTypes[j]][i][ 1594 | 'id' 1595 | ]) === null) { 1596 | /* It seems this escape reference had been deleted, so we dispatch an 1597 | * event that will redo all escapes. 1598 | */ 1599 | 1600 | if (escapeTypes[j] === 'marginnote') { 1601 | this.rawdiv.dispatchEvent(pagination.events.redoMarginnotes); 1602 | this.namedFlow.dispatchEvent(pagination.events.marginnotesNeedMove); 1603 | return; 1604 | } else { 1605 | this.rawdiv.dispatchEvent(pagination.events.redoEscapes); 1606 | this.namedFlow.dispatchEvent(pagination.events.escapesNeedMove); 1607 | return; 1608 | } 1609 | 1610 | } 1611 | 1612 | if (this.escapes[escapeTypes[j]][i]['referencePage'] !== this.findEscapeReferencePage( 1613 | this.escapes[escapeTypes[j]][i]['reference'])) { 1614 | if (escapeTypes[j] === 'marginnote') { 1615 | this.namedFlow.dispatchEvent(pagination.events.marginnotesNeedMove); 1616 | return; 1617 | } else { 1618 | this.namedFlow.dispatchEvent(pagination.events.escapesNeedMove); 1619 | return; 1620 | } 1621 | } else if (escapeTypes[j] === 'marginnote' && (this.escapes[escapeTypes[j]][i]['reference'].getBoundingClientRect()['top'] + window.pageYOffset) !== this.escapes[escapeTypes[j]][i]['referenceTopOffset']) { 1622 | this.namedFlow.dispatchEvent(pagination.events.marginnotesNeedMove); 1623 | } 1624 | 1625 | 1626 | 1627 | } 1628 | } 1629 | 1630 | return; 1631 | }; 1632 | 1633 | 1634 | flowObject.prototype.compareReferenceAndEscapePage = function ( 1635 | escapeObject) { 1636 | /* Check whether a footnote/top float and it's corresponding reference in the text 1637 | * are on the same page. 1638 | */ 1639 | var escapeReference = document.getElementById(escapeObject['id']), referencePage, escapePage; 1640 | 1641 | referencePage = this.findEscapeReferencePage( 1642 | escapeReference); 1643 | escapePage = this.findEscapePage( 1644 | escapeObject['item']); 1645 | 1646 | if (escapePage === referencePage) { 1647 | return true; 1648 | } else { 1649 | return false; 1650 | } 1651 | }; 1652 | 1653 | 1654 | flowObject.prototype.setupEscapeReflow = function () { 1655 | // Connect footnote reflow events with triggers. 1656 | var flowObject = this, reFlow, redoEscapes; 1657 | 1658 | 1659 | reFlow = function () { 1660 | flowObject.placeAllEscapes(); 1661 | }; 1662 | 1663 | this.namedFlow.addEventListener('escapesNeedMove', reFlow); 1664 | 1665 | reFlowMarginnotes = function () { 1666 | flowObject.layoutMarginnotes(); 1667 | flowObject.freezeEscapeReferencePages(); 1668 | }; 1669 | 1670 | this.namedFlow.addEventListener('marginnotesNeedMove', reFlowMarginnotes); 1671 | 1672 | redoEscapes = function () { 1673 | flowObject.redoEscapes(); 1674 | }; 1675 | 1676 | this.rawdiv.addEventListener('redoEscapes', redoEscapes); 1677 | }; 1678 | 1679 | flowObject.prototype.redoEscapes = function () { 1680 | /* Reset all top floats and footnotes. 1681 | */ 1682 | var escapeTypes = ['footnote', 'topfloat'], i, j; 1683 | 1684 | for (j = 0; j < escapeTypes.length; j++) { 1685 | 1686 | for (i = 0; i < this.escapes[escapeTypes[j]].length; i++) { 1687 | /* Go through all footnotes, removing all spacer blocks and footnote 1688 | * references from the DOM. 1689 | */ 1690 | 1691 | if (j === 'footnote' && 'hidden' in this.escapes[escapeTypes[j]][i]) { 1692 | this.escapes[escapeTypes[j]][i]['hidden'].parentNode.removeChild( 1693 | this.escapes[escapeTypes[j]][i]['hidden']); 1694 | } 1695 | 1696 | if (this.escapes[escapeTypes[j]][i]['item'].parentNode !== null) { 1697 | this.escapes[escapeTypes[j]][i]['item'].parentNode.removeChild( 1698 | this.escapes[escapeTypes[j]][i]['item']); 1699 | } 1700 | } 1701 | 1702 | // Start out with no footnotes or top floats. 1703 | this.escapes[escapeTypes[j]] = []; 1704 | } 1705 | 1706 | // Find footnotes from scratch. 1707 | this.findAllTopfloats(); 1708 | this.findAllFootnotes(); 1709 | }; 1710 | 1711 | flowObject.prototype.findAllTopfloats = function () { 1712 | // Find all the topfloats in the text and prepare them for flow. 1713 | this.findAllEscapes('topfloat'); 1714 | }; 1715 | 1716 | flowObject.prototype.findAllMarginnotes = function () { 1717 | // Find all the footnotes in the text and prepare them for flow. 1718 | this.findAllEscapes('marginnote'); 1719 | }; 1720 | 1721 | flowObject.prototype.findAllFootnotes = function () { 1722 | // Find all the footnotes in the text and prepare them for flow. 1723 | this.findAllEscapes('footnote'); 1724 | }; 1725 | 1726 | flowObject.prototype.findAllEscapes = function (escapeType) { 1727 | 1728 | /* Find all the escapes (footnotes, topfloats) in the text and prepare 1729 | * them for flow. 1730 | */ 1731 | var allEscapes, escapeId, escapeObject, escapeFlowTo, i; 1732 | 1733 | if (this.escapeStylesheets[escapeType].parentNode === document.head) { 1734 | // Remove all previous stylesheet rules of the same escape type. 1735 | document.head.removeChild(this.escapeStylesheets[escapeType]); 1736 | this.escapeStylesheets[escapeType].innerHTML = ''; 1737 | } 1738 | 1739 | 1740 | /* Look for all the items that have "pagination-"+escapeType in their 1741 | * class list. These will be treated as escapes from the normal text 1742 | * flow. 1743 | */ 1744 | allEscapes = this.rawdiv.querySelectorAll( 1745 | pagination.config(escapeType + 'Selector')); 1746 | 1747 | for (i = 0; i < allEscapes.length; i++) { 1748 | 1749 | if (allEscapes[i].id === '') { 1750 | /* If the escape has no id, create one, so that we can target it 1751 | * using CSS rules. 1752 | */ 1753 | allEscapes[i].id = pagination.createRandomId( 1754 | 'pagination-' + escapeType + '-'); 1755 | } 1756 | 1757 | escapeId = allEscapes[i].id; 1758 | 1759 | this.escapeStylesheets[escapeType].innerHTML += 1760 | '\n#' + escapeId + ' > * {-webkit-flow-into: ' + escapeId + 1761 | ';}' + '\n#' + escapeId + '-flow-into {-webkit-flow-from: ' + 1762 | escapeId + ';}'; 1763 | 1764 | 1765 | escapeObject = {}; 1766 | /* We create this object so that we can find the escape item and 1767 | * reference again later on. 1768 | */ 1769 | 1770 | escapeObject['reference'] = allEscapes[i]; 1771 | 1772 | escapeFlowTo = document.createElement('div'); 1773 | 1774 | escapeFlowTo.id = escapeId + '-flow-into'; 1775 | 1776 | escapeFlowTo.classList.add('pagination-' + escapeType + '-item'); 1777 | 1778 | escapeObject['item'] = escapeFlowTo; 1779 | 1780 | escapeObject['id'] = escapeId; 1781 | 1782 | this.escapes[escapeType].push(escapeObject); 1783 | 1784 | 1785 | } 1786 | if (this.escapeStylesheets[escapeType].innerHTML !== '') { 1787 | document.head.appendChild(this.escapeStylesheets[escapeType]); 1788 | } 1789 | 1790 | }; 1791 | 1792 | flowObject.prototype.layoutTopfloats = function () { 1793 | // Layout all top floats 1794 | this.layoutEscapes('topfloat'); 1795 | }; 1796 | 1797 | flowObject.prototype.layoutFootnotes = function () { 1798 | // Layout all footnotes 1799 | this.layoutEscapes('footnote'); 1800 | }; 1801 | 1802 | flowObject.prototype.layoutMarginnotes = function () { 1803 | // Layout all footnotes 1804 | this.layoutEscapes('marginnote'); 1805 | } 1806 | 1807 | flowObject.prototype.layoutEscapes = function (escapeType) { 1808 | // Layout all footnotes and top floats 1809 | var i; 1810 | 1811 | if (escapeType === 'footnote') { 1812 | 1813 | for (i = 0; i < this.escapes[escapeType].length; i++) { 1814 | /* Go through all footnotes, and remove the hidden nodes that were 1815 | * previously placed to make sure footnote reference and footnote 1816 | * were on the same page. 1817 | */ 1818 | 1819 | if ('hidden' in this.escapes[ 1820 | escapeType][i]) { 1821 | this.escapes[escapeType][i]['hidden'].parentNode.removeChild( 1822 | this.escapes[escapeType][i]['hidden']); 1823 | delete this.escapes[escapeType][i]['hidden']; 1824 | } 1825 | } 1826 | } 1827 | 1828 | 1829 | for (i = 0; i < this.escapes[escapeType].length; i++) { 1830 | /* Go through the escapes, this with the purpose of placing them 1831 | * correctly. 1832 | */ 1833 | var escapeReferencePage, firstEscapeContainer, marginnoteOffsetTop, marginnoteOffsetTopTotal, checkSpacerSize, observer, newEscapeReferencePage, newEscapeContainer, marginNotesAndOffset; 1834 | 1835 | if (escapeType === 'marginnote') { 1836 | marginNotesAndOffset = pagination.findMarginNotesContainerAndOffset(document.getElementById(this.escapes[escapeType][i]['id'])); 1837 | firstEscapeContainer = marginNotesAndOffset[0]; 1838 | marginnoteOffsetTop = marginNotesAndOffset[1]; 1839 | //marginnoteOffsetTopTotal = marginNotesAndOffset[2]; 1840 | 1841 | } else { 1842 | escapeReferencePage = this.findEscapeReferencePage( 1843 | document.getElementById(this.escapes[escapeType][i]['id'])); 1844 | 1845 | // We find the page where the escape is referenced from. 1846 | firstEscapeContainer = escapeReferencePage.querySelector( 1847 | '.pagination-' + escapeType + 's'); 1848 | } 1849 | 1850 | // Only if the escapenode is not already on the page of its reference do we need to get active. 1851 | if (this.escapes[escapeType][i]['item'].parentNode !== 1852 | firstEscapeContainer || (escapeType === 'marginnote' && marginnoteOffsetTop !== this.escapes[escapeType][i]['offsetTop'])) { 1853 | 1854 | if (this.escapes[escapeType][i]['item'].parentNode !== null) { 1855 | 1856 | /* If the escape node has been placed previously, we remove it and 1857 | * recalculate the escapeReferencePage and firstEscapeContainer 1858 | */ 1859 | 1860 | if (escapeType === 'topfloat' && this.escapes[escapeType][i][ 1861 | 'item' 1862 | ].parentNode.children.length === 1) { 1863 | /* If this is the only top float on the page where the top 1864 | * float had previously been placed, we remove the 1865 | * pagination-page-topfloat class of the page 1866 | */ 1867 | this.escapes[escapeType][i]['item'].parentNode.parentNode 1868 | .parentNode 1869 | .classList.remove('pagination-page-topfloat'); 1870 | } 1871 | 1872 | if (this.escapes[escapeType][i]['item'].parentNode !== firstEscapeContainer) { 1873 | this.escapes[escapeType][i]['item'].parentNode.removeChild( 1874 | this.escapes[escapeType][i]['item']); 1875 | 1876 | 1877 | escapeReferencePage = this.findEscapeReferencePage( 1878 | document.getElementById(this.escapes[escapeType][i][ 1879 | 'id' 1880 | ])); 1881 | firstEscapeContainer = escapeReferencePage.querySelector( 1882 | '.pagination-' + escapeType + 's'); 1883 | } 1884 | } 1885 | 1886 | 1887 | if (i === 0 || this.escapes[escapeType][i - 1]['item'].parentNode !== 1888 | firstEscapeContainer) { 1889 | /* If this is the first footnote or top float or the previous 1890 | * one is not on the same page, we insert it at the very 1891 | * beginning of the footnote/top float container. 1892 | */ 1893 | firstEscapeContainer.insertBefore(this.escapes[escapeType][ 1894 | i 1895 | ]['item'], firstEscapeContainer.firstChild); 1896 | } else { 1897 | /* If the previous footnote/top float is on the same page, we 1898 | * insert after that one 1899 | */ 1900 | firstEscapeContainer.insertBefore(this.escapes[escapeType][ 1901 | i 1902 | ]['item'], this.escapes[escapeType][i - 1]['item'].nextSibling); 1903 | } 1904 | 1905 | if (escapeType === 'topfloat') { 1906 | // We add the class 'pagination-page-topfloat' to the page where the top float was inserted. 1907 | firstEscapeContainer.parentNode.parentNode.classList.add( 1908 | 'pagination-page-topfloat'); 1909 | 1910 | } else if (escapeType === 'marginnote') { 1911 | this.escapes[escapeType][i]['item'].style.top = marginnoteOffsetTop + 'px'; 1912 | } 1913 | 1914 | } 1915 | 1916 | if (escapeType !== 'marginnote' && !(this.compareReferenceAndEscapePage( 1917 | this.escapes[escapeType][i]))) { 1918 | /* If the footnote reference has been moved from one page to 1919 | * another through the insertion procedure, we move the footnote to 1920 | * where it is referenced from now and create an empty div 1921 | * ('hidden') and set it in it's place. 1922 | */ 1923 | 1924 | if (escapeType === 'footnote') { 1925 | /* We insert a hidden element into the container where the 1926 | * footnote was previously so that the body text doesn't flow back. 1927 | */ 1928 | this.escapes[escapeType][i]['hidden'] = document.createElement( 1929 | 'div'); 1930 | 1931 | this.escapes[escapeType][i]['hidden'].style.height = ( 1932 | this.escapes[escapeType][i]['item'].clientHeight) + 1933 | 'px'; 1934 | 1935 | this.escapes[escapeType][i]['hidden'].id = this.escapes[ 1936 | escapeType][i][ 1937 | 'id' 1938 | ] + 1939 | 'hidden'; 1940 | 1941 | 1942 | firstEscapeContainer.replaceChild( 1943 | this.escapes[escapeType][i]['hidden'], 1944 | this.escapes[escapeType][i]['item']); 1945 | 1946 | checkSpacerSize = function () { 1947 | if (this.escapes[escapeType][i]['item'].clientHeight < 1948 | this.escapes[escapeType][i]['hidden'].clientHeight) { 1949 | /* The footnote is smaller than its space holder on another 1950 | * page. It means the footnote has been shortened and we 1951 | * need to reflow escapes! 1952 | */ 1953 | this.namedFlow.dispatchEvent( 1954 | pagination.events.escapesNeedMove); 1955 | } 1956 | }; 1957 | 1958 | observer = new MutationObserver(function (mutations) { 1959 | checkSpacerSize(); 1960 | }); 1961 | 1962 | observer.observe(this.escapes[escapeType][i]['item'], { 1963 | attributes: true, 1964 | subtree: true, 1965 | characterData: true, 1966 | childList: true 1967 | }); 1968 | 1969 | } 1970 | 1971 | newEscapeReferencePage = this.findEscapeReferencePage( 1972 | this.escapes[escapeType][i]['reference']); 1973 | /* We find the page where the escape node is referenced from now and 1974 | * move it there. 1975 | */ 1976 | newEscapeContainer = newEscapeReferencePage.querySelector( 1977 | '.pagination-' + escapeType + 's'); 1978 | 1979 | if (i === 0 || this.escapes[escapeType][i - 1]['item'].parentNode !== 1980 | newEscapeContainer) { 1981 | /* If this is the first footnote or top float or the previous 1982 | * one is not on the same page, we insert it at the very 1983 | * beginning of the footnote/top float container. 1984 | */ 1985 | newEscapeContainer.insertBefore(this.escapes[escapeType][i][ 1986 | 'item' 1987 | ], newEscapeContainer.firstChild); 1988 | } else { 1989 | /* If the previous footnote/top float is on the same page, we 1990 | * insert after that one 1991 | */ 1992 | newEscapeContainer.insertBefore(this.escapes[escapeType][i][ 1993 | 'item' 1994 | ], this.escapes[escapeType][i - 1]['item'].nextSibling); 1995 | } 1996 | 1997 | if (escapeType === 'footnote') { 1998 | if (firstEscapeContainer.children.length === 0) { 1999 | firstEscapeContainer.parentNode.parentNode 2000 | .classList.remove('pagination-page-topfloat'); 2001 | } 2002 | newEscapeContainer.parentNode.parentNode.classList.add( 2003 | 'pagination-page-topfloat'); 2004 | } 2005 | 2006 | } 2007 | } 2008 | 2009 | if (escapeType==='marginnote') { 2010 | pagination.adjustAllMarginNotesPositions(); 2011 | } 2012 | }; 2013 | 2014 | 2015 | flowObject.prototype.makeEvenPages = function () { 2016 | // If the number of pages is odd, add an empty page. 2017 | var emptyPage = this.div.querySelector( 2018 | '.pagination-page.pagination-empty'), allPages; 2019 | if (emptyPage) { 2020 | this.div.removeChild(emptyPage); 2021 | } 2022 | allPages = this.div.querySelectorAll('.pagination-page'); 2023 | if (allPages.length % 2 === 1) { 2024 | this.div.appendChild( 2025 | pagination.createPages( 2026 | 1, 2027 | false, 2028 | this.pageCounter.cssClass, 2029 | this.columns)); 2030 | } 2031 | }; 2032 | 2033 | flowObject.prototype.addPagesLoop = function (numberOfPages) { 2034 | /* Add pages. If the variable numberOfPages is defined, add this amount of 2035 | * pages. Else use the config option bulkPagesToAdd times 2036 | * pagesToAddIncrementRatio to determine how many pages should be added. 2037 | * It is a point to overshoot the target, as it is more costly to add than 2038 | * to remove pages. 2039 | */ 2040 | if (this.bulkPagesToAdd > pagination.config('maxPageNumber')) {return;} 2041 | if ('undefined' === typeof (numberOfPages)) { 2042 | this.div.appendChild( 2043 | pagination.createPages( 2044 | this.bulkPagesToAdd, 2045 | this.name, 2046 | this.pageCounter.cssClass, 2047 | this.columns)); 2048 | this.bulkPagesToAdd = Math.floor( 2049 | this.bulkPagesToAdd * pagination.config( 2050 | 'pagesToAddIncrementRatio')); 2051 | } else { 2052 | this.div.appendChild( 2053 | pagination.createPages( 2054 | numberOfPages, 2055 | this.name, 2056 | this.pageCounter.cssClass, 2057 | this.columns)); 2058 | } 2059 | this.addOrRemovePages(numberOfPages); 2060 | }; 2061 | 2062 | 2063 | flowObject.prototype.addOrRemovePages = function (pages) { 2064 | // This loop is called when we believe pages have to added or removed. 2065 | 2066 | if ((this.namedFlow.overset) && (this.rawdiv.innerText.length > 0)) { 2067 | /* If there are too few regions (overset==True) and the contents of 2068 | * rawdiv are at least 1 character long, pages need to be added. 2069 | */ 2070 | this.pageCounter.needsUpdate = true; 2071 | this.redoPages = true; 2072 | this.addPagesLoop(pages); 2073 | } else if ( 2074 | (this.namedFlow.firstEmptyRegionIndex !== -1) && ( 2075 | ( 2076 | this.namedFlow.getRegions().length - this.namedFlow.firstEmptyRegionIndex) >= 2077 | this.columns)) { 2078 | /* If there are excess regions, and the number of empty regions is 2079 | * equal to or higher than the number of columns, we need to remove 2080 | * pages. 2081 | */ 2082 | this.redoPages = true; 2083 | this.removeExcessPages(pages); 2084 | } else if (this.redoPages) { 2085 | /* If pages have either been added or removed, make sure than the total 2086 | * number of pages is even if alwaysEven has been set, and emit a 2087 | * bodyLayoutUpdated event if this is not the frontmatter. 2088 | */ 2089 | this.redoPages = false; 2090 | if (pagination.config('alwaysEven')) { 2091 | this.makeEvenPages(); 2092 | } 2093 | if (this.name !== 'pagination-frontmatter') { 2094 | document.body.dispatchEvent(pagination.events.bodyLayoutUpdated); 2095 | } 2096 | } 2097 | }; 2098 | 2099 | 2100 | flowObject.prototype.removeExcessPages = function (pages) { 2101 | /* Remove pages that are in excess. As it takes much less time to remove 2102 | * excess pages than to add new ones, it is preferable to add too many 2103 | * pages initially and then remove them givent hat we do not know exactly 2104 | * how many pages are needed before we add them. 2105 | */ 2106 | 2107 | var allPages = this.div.querySelectorAll('.pagination-page'), i; 2108 | 2109 | for ( 2110 | i = ( 2111 | Math.ceil(this.namedFlow.firstEmptyRegionIndex / this.columns)); i < 2112 | allPages.length; i++) { 2113 | this.div.removeChild(allPages[i]); 2114 | } 2115 | this.addOrRemovePages(pages); 2116 | }; 2117 | 2118 | 2119 | flowObject.prototype.setupReflow = function () { 2120 | /* Setup automatic addition and removing of pages when content is added or 2121 | * removed. 2122 | */ 2123 | var flowObject = this, checkOverset, checkAllEscapeReferencePagesPlacements, observer, observerOptions, reFlow, ourRawdiv; 2124 | 2125 | checkOverset = function () { 2126 | /* Something has changed in the contents of this flow. Check if the 2127 | * values of overset or firstEmptyRegionIndex have changed. If this is 2128 | * the case, emit a pageLayoutUpdate event. 2129 | */ 2130 | if ( 2131 | ( 2132 | flowObject.namedFlow.overset !== flowObject.overset) || ( 2133 | flowObject.namedFlow.firstEmptyRegionIndex !== flowObject.firstEmptyRegionIndex)) { 2134 | flowObject.overset = flowObject.namedFlow.overset; 2135 | flowObject.firstEmptyRegionIndex = 2136 | flowObject.namedFlow.firstEmptyRegionIndex; 2137 | flowObject.namedFlow.dispatchEvent( 2138 | pagination.events.pageLayoutUpdate); 2139 | } 2140 | }; 2141 | 2142 | 2143 | checkAllEscapeReferencePagesPlacements = function () { 2144 | flowObject.checkAllEscapeReferencePagesPlacements(); 2145 | }; 2146 | 2147 | 2148 | flowObject.namedFlow.addEventListener("webkitregionoversetchange", checkOverset); 2149 | 2150 | if (navigator.userAgent.indexOf('6.1 Safari/') > -1 2151 | || navigator.userAgent.indexOf('7.0 Safari/') > -1) { 2152 | /* Safari 6.1/7 does not include the regionoversetchange event. 2153 | * Newer versions should drop the regionlayoutupdate event. 2154 | */ 2155 | flowObject.namedFlow.addEventListener("webkitregionlayoutupdate", checkOverset); 2156 | } 2157 | 2158 | flowObject.currentlyChecking = false; 2159 | 2160 | if (this.rawdiv) { 2161 | /* Create an observer instance to watch if anything is being changed in 2162 | * the contents of the original text. 2163 | * We do this instead of listening to the webkitregionlayoutupdate 2164 | * event of the flow, because it is ridden with bugs and fires too often. 2165 | * This could be changed once 2166 | * https://bugs.webkit.org/show_bug.cgi?id=105366 has been resolved. 2167 | * 2168 | * TODO: Check whether throttling this event makes sense. 2169 | */ 2170 | observerOptions = { 2171 | attributes: false, 2172 | subtree: true, 2173 | characterData: true, 2174 | childList: true 2175 | }; 2176 | 2177 | ourRawdiv = this.rawdiv; 2178 | 2179 | observer = new MutationObserver(function (mutations) { 2180 | 2181 | if (!(flowObject.currentlyChecking)) { 2182 | flowObject.currentlyChecking = true; 2183 | setTimeout(function() { 2184 | checkAllEscapeReferencePagesPlacements(); 2185 | flowObject.currentlyChecking = false; 2186 | },1); 2187 | } 2188 | }); 2189 | 2190 | observer.observe(ourRawdiv,observerOptions); 2191 | 2192 | } 2193 | 2194 | reFlow = function () { 2195 | // The page layout has changed. Reflow by adding pages one by one. 2196 | flowObject.addOrRemovePages(1); 2197 | if (pagination.config('numberPages')) { 2198 | flowObject.pageCounter.numberPages(); 2199 | } 2200 | }; 2201 | this.namedFlow.addEventListener('pageLayoutUpdate', reFlow); 2202 | 2203 | }; 2204 | 2205 | exports.flowObject = flowObject; 2206 | 2207 | }).call(this.pagination); 2208 | 2209 | if (!paginationConfig || !paginationConfig.hasOwnProperty('autostart') || paginationConfig.autostart === false) { 2210 | pagination.initiate(); 2211 | } -------------------------------------------------------------------------------- /changes.txt: -------------------------------------------------------------------------------- 1 | 1.1-dev 2 | ---- 3 | use webkitregionoversetchange event to trigger add/removal of pages.s 4 | 5 | 1.0-dev 6 | ---- 7 | word index 8 | margin notes 9 | cross references 10 | column separators 11 | pages with top floats have extra CSS class: pagination-page-topfloat 12 | use mutation observers instead of flow events 13 | support for top floats 14 | changed default options reading. Changing page size on the fly now has to happen by changing page sized in paginationConfig rather than Pagionation.config 15 | 16 | 0.60 17 | ---- 18 | changed version scheme 19 | prefix flownames and content elements 20 | option not to change original DOM 21 | style-element creation through JS options 22 | allow for layout change event to be configurable 23 | 24 | 0.25.0 25 | ---- 26 | Add footnote support for dynamic contents 27 | Increased requirement to Chrome 25 28 | 29 | 0.23.1 30 | ---- 31 | Added footnote support for static content (reflow has to be enabled) 32 | Added multi column support 33 | 34 | 0.23.0 35 | ---- 36 | First stable version (version number correponds to Chrome version this can run under) 37 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Welcome to BookJS

4 |

Page headers, footnotes, pagenumbers, multi columns, TOC, using CSS Regions

5 | 6 | 7 |

Steps:

8 |
    9 |
  1. Download a recent version of Chromium/Chrome (29+) or Safari 6.1/7.0
  2. 10 |
  3. If you use Chrome/Chromium: 11 |
      12 |
    • Open a new tab and go to "chrome://flags/"
    • 13 |
    • Search for "Webkit Experimental Features" and enable them
    • 14 |
    • Restart your browser
    • 15 |
    16 |
  4. 17 |
  5. Read the "Notice" below so you know what to look for and then
  6. 18 |
  7. Check out the simple test book, a book with many chapters, or a book with a very long chapter, top floats.
  8. 19 |
20 | 21 |

Screenshot

22 |

You can find a screenshot of the last test here.

23 | 24 |

Notice:

25 |
    26 |
  1. There are multiple numbered "pages"
  2. 27 |
  3. The TOC is generated from the H1 tags and includes the page number the tag occurs on.
  4. 28 |
29 | 30 |

Configuration:

31 |

For configuration options, check the sourcefile book.js.

32 | 33 |

Footnotes:

34 |

In order to insert a footnote into the source text, simply insert it as a span with a class 'pagination-footnote', such as <span class='pagination-footnote'><span><span>This a footnote</span></span></span>. See also the source code of the Test Page.

35 | 36 |

License:

37 | BookJS is licensed under the AGPL license. For further information, check LICENSE.txt. 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BookJS test 5 | 6 | 7 | 8 | 9 | 10 |

Some text part

11 |
12 | 13 |
1 Lorem ipsum dolor sit amet, consectetuer adipiscing elit 14 | This is a footnote. Footnotes can be quite long and go over several lines. As you will notice, footnotes span the entire width of the page, even in multi column layouts. 15 | , sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam 16 | erat volutpat.

THIS IS A TOP FLOAT!

Different from footnotes, it doesn't move when text is moved around.

17 |
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 18 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 19 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 20 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 21 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 22 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 23 | eleifend option congue nihil imperdiet doming id quod mazim placerat 24 | facer possim assum.This is another footnote. 25 | Typi non habent claritatem insitam; est usus legentis in iis qui facit 26 | eorum claritatem. Investigationes demonstraverunt lectores legere me 27 | lius quod ii legunt saepius.
28 |
2 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 29 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 30 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 31 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 32 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 33 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 34 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 35 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 36 | eleifend option congue nihil imperdiet doming id quod mazim placerat 37 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 38 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 39 | legere me lius quod ii legunt saepiusAnd this is a third footnote. 40 | .
41 |
3 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 42 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 43 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 44 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 45 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 46 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 47 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 48 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 49 | eleifend option congue nihil imperdiet doming id quod mazim placerat 50 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 51 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 52 | legere me lius quod ii legunt saepius.
53 |
4 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 54 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 55 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 56 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 57 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 58 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 59 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 60 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 61 | eleifend option congue nihil imperdiet doming id quod mazim placerat 62 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 63 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 64 | legere me lius quod ii legunt saepius.
65 |
5 Lorem ipsum dolor sit amet,consectetuer adipiscing elit, sed diam nonummy 66 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 67 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 68 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 69 | vel eumThis is a fourth footnote. 70 | iriure dolor in hendrerit in vulputate velit esse molestie consequat, 71 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 72 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 73 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 74 | eleifend option congue nihil imperdiet doming id quod mazim placerat 75 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 76 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 77 | legere me lius quod ii legunt saepius.
78 |
6 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 79 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 80 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 81 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 82 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 83 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 84 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 85 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 86 | eleifend option congue nihil imperdiet doming id quod mazim placerat 87 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 88 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 89 | legere me lius quod ii legunt saepius.
90 |
7 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 91 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 92 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 93 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 94 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 95 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 96 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 97 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 98 | eleifend option congue nihil imperdiet doming id quod mazim placerat 99 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 100 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 101 | legere me lius quod ii legunt saepius.
102 |
8 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 103 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 104 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 105 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 106 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 107 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 108 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 109 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 110 | eleifend option congue nihil imperdiet doming id quod mazim placerat 111 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 112 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 113 | legere me lius quod ii legunt saepius.
114 |
9 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 115 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 116 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 117 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 118 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 119 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 120 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 121 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 122 | eleifend option congue nihil imperdiet doming id quod mazim placerat 123 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 124 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 125 | legere me lius quod ii legunt saepius.
126 |
10 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 127 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 128 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 129 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 130 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 131 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 132 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 133 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 134 | eleifend option congue nihil imperdiet doming id quod mazim placerat 135 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 136 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 137 | legere me lius quod ii legunt saepius.
138 |
11 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 139 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 140 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 141 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 142 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 143 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 144 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 145 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 146 | eleifend option congue nihil imperdiet doming id quod mazim placerat 147 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 148 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 149 | legere me lius quod ii legunt saepius.
150 |
12 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 151 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 152 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 153 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 154 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 155 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 156 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 157 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 158 | eleifend option congue nihil imperdiet doming id quod mazim placerat 159 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 160 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 161 | legere me lius quod ii legunt saepius.
162 |
13 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 163 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 164 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 165 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 166 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 167 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 168 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 169 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 170 | eleifend option congue nihil imperdiet doming id quod mazim placerat 171 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 172 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 173 | legere me lius quod ii legunt saepius.
174 |
14 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 175 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 176 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 177 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 178 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 179 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 180 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 181 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 182 | eleifend option congue nihil imperdiet doming id quod mazim placerat 183 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 184 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 185 | legere me lius quod ii legunt saepius.
186 |
TESTETSTETST
187 |
15 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 188 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 189 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 190 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 191 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 192 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 193 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 194 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 195 | eleifend option congue nihil imperdiet doming id quod mazim placerat 196 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 197 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 198 | legere me lius quod ii legunt saepius.
199 |
16 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 200 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 201 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 202 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 203 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 204 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 205 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 206 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 207 | eleifend option congue nihil imperdiet doming id quod mazim placerat 208 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 209 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 210 | legere me lius quod ii legunt saepius.
211 |
212 |

Another text part

213 |
214 |
17 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 215 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 216 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 217 | suscipit lobortis nisl ut aliquip ex ea commodo consequatThis is a footnote. 218 | . Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse 219 | molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero 220 | eros et accumsan et iusto odio dignissim qui blandit praesent luptatum 221 | zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber 222 | tempor cum soluta nobis eleifend option congue nihil imperdiet doming 223 | id quod mazim placerat facer possim assum. Typi non habent claritatem 224 | insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes 225 | demonstraverunt lectores legere me lius quod ii legunt saepius.
226 |
18 Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy 227 | nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. 228 | Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper 229 | suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem 230 | vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, 231 | vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan 232 | et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue 233 | duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis 234 | eleifend option congue nihil imperdiet doming id quod mazim placerat 235 | facer possim assum. Typi non habent claritatem insitam; est usus legentis 236 | in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores 237 | legere me lius quod ii legunt saepius.
238 |
239 | 240 | 241 | -------------------------------------------------------------------------------- /test4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | The Malay Archipelago 7 | 37 | 59 | 60 | 61 | 62 | 63 | 64 |
65 | 66 |
67 | 68 |

The Malay Archipelago

69 |
70 | Malay Archipelago Chief's House 71 |
72 | Malay Archipelago Chief's House and Rice-shed in a Sumatran Village 73 |
74 |
75 |
76 |

The Malay Archipelago is a book by the British naturalist Alfred Russel Wallace that chronicles his scientific exploration, during the eight-year period 1854 to 1862, of the southern portion of the Malay Archipelago including Malaysia, Singapore, the islands of Indonesia, then known as the Dutch East Indies, and the island of New Guinea. It was published in two volumes in 1869, delayed by Wallace's ill health and the work needed to describe the many specimens he brought home. The book went through ten editions in the nineteenth century; it has been reprinted many times since, and has been translated into at least eight languages.

77 |

The book described each island that he visited in turn, giving a detailed account of its physical and human geography, its volcanoes, and the variety of animals of plants that he found and collected. At the same time, he describes his experiences, the difficulties of travel, and the help he received from the different peoples that he met. The preface notes that he travelled over 14,000 miles and collected 125,660 natural history specimens, mostly of insects though also with thousands of molluscs, birds, mammals and reptiles.

78 |

The Malay Archipelago attracted many reviews, with interest from scientific, geographic, church and general periodicals. Reviewers noted and sometimes disagreed with various of his theories, especially the division of fauna and flora along what soon became known as the Wallace line, natural selection and uniformitarianism. Nearly all agreed that he had provided an interesting and comprehensive account of the geography, natural history, and peoples of the archipelago, which was little known to their readers at the time, and that he had collected an astonishing number of specimens. The book is much cited, and is Wallace's most successful, both commercially and as a piece of literature.

79 |

Context

80 |

In 1847, Wallace and his friend Henry Walter Bates, both in their early twenties,Bates was 22, Wallace was 24. agreed that they would jointly make a collecting trip to the Amazon "towards solving the problem of origin of species";Mallet, Jim. "Henry Walter Bates". University College London. Retrieved December 11, 2012. Charles Darwin's book on the Origin of Species was not published until 11 years later, in 1859, itself precipitated by a famous letter from Wallace which described the theory in outline.Shoumatoff, Alex (22 August 1988). "A Critic at Large, Henry Walter Bates". New Yorker. They had been inspired by reading the American entomologist William Henry Edwards's pioneering 1847 book A Voyage Up the River Amazon, with a residency at Pará.Edwards, 1847. Bates stayed in the Amazons for 11 years, going on to write The Naturalist on the River Amazons (1863); Wallace, ill with fever, went home in 1852 with thousands of specimens, some for science and some for sale. The ship and his collection were destroyed by fire at sea near the Guianas. Rather than giving up, Wallace wrote about the Amazon in both prose and poetry, and then set sail again, this time for the Malay Archipelago.Edwards, 1847.

81 |

Publication

82 |

The Malay Archipelago was first published in 1869 in two volumes by Macmillan (London), and the same year in one volume by Harper & Brothers (New York). Wallace returned to England in 1862, but explains in the Preface that given the large quantity of specimens and his poor health after his stay in the tropics, it took a long time. He noted that he could at once have printed his notes and journals, but felt that doing that would have been disappointing and unhelpful. Instead, therefore, he waited until he had published papers on his discoveries, and other scientists had described and named as new species some 2,000 of his beetles (Coleoptera), and over 900 Hymenoptera including 200 new species of ant.Wallace, 1869. pp. vii–ix. The book went through 10 editions, with the last published in 1890.

83 |

Overview

84 | 85 |
86 | Wallace's map 87 |
88 | Fold-out coloured map at front of book, showing Wallace's travels around the archipelago 89 |
90 |
91 |
92 |

The preface summarizes Wallace’s travels, the thousands of specimens he collected, and some of the results from their analysis after his return to England. In the preface he notes that he travelled over 14,000 miles and collected 125,660 specimens, mostly of insects: 83,200 beetles, 13,100 butterflies and moths, 13,400 other insects. He also returned to England 7,500 "shells" (such as molluscs), 8,050 birds, 310 mammals and 100 reptiles.Wallace, 1869. p. xiv.

93 |

The book is dedicated to Charles Darwin, but as Wallace explains in the preface, he has chosen to avoid discussing the evolutionary implications of his discoveries. Instead he confines himself to the "interesting facts of the problem, whose solution is to be found in the principles developed by Mr. Darwin",Wallace, 1869. p. xii. so from a scientific point of view, the book is largely a descriptive natural history. This modesty belies the fact that while in Sarawak in 1855 Wallace wrote the paper On the Law which has Regulated the Introduction of New Species, concluding with the evolutionary "Sarawak Law", "Every species has come into existence coincident both in space and time with a closely allied species", three years before he fatefully wrote to Darwin proposing the concept of natural selection.Wallace, Alfred Russel (1855). "On the Law Which has Regulated the Introduction of Species". Western Kentucky University. Retrieved 22 March 2013.

94 |

The first chapter describes the physical geography and geology of the islands with particular attention to the role of volcanoes and earthquakes. It also discusses the overall pattern of the flora and fauna including the fact that the islands can be divided, by what would eventually become known as the Wallace line, into two parts, those whose animals are more closely related to those of Asia and those whose fauna is closer to that of Australia.

95 |

The following chapters describe in detail the places Wallace visited. Wallace includes numerous observations on the people, their languages, ways of living, and social organization, as well as on the plants and animals found in each location. He talks about the biogeographic patterns he observes and their implications for natural history, in terms both of the movement of speciesImplying adaptive radiation. and of the geologic history of the region. He also narrates some of his personal experiences during his travels. The final chapter is an overview of the ethnic, linguistic, and cultural divisions among the people who live in the region and speculation about what such divisions might indicate about their history.

96 |

Illustrations

97 | 98 |
99 | Great-shielded Grasshopper 100 |
101 | "Great-shielded Grasshopper" drawn and signed by E. W. Robinson 102 |
103 |
104 |
105 |

The illustrations are, according to the Preface, made from Wallace's own sketches, photographs, or specimens. Wallace thanks Walter and Henry Woodbury for some photographs of scenery and native people. He acknowledges William Wilson Saunders and Mr Pascoe for horned flies and very rare Longhorn beetles: all the rest were from his own enormous collection.

106 | 107 | 108 | 109 | 110 |
111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /test4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/booktype/BookJS/a6e25c04ad66d551069855e7d3f7ea6b55fa03dc/test4.png -------------------------------------------------------------------------------- /test5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | BookJS test 7 | 23 | 24 | 25 | 33 | 34 | 35 | 36 | 37 |
38 |

Here it says X² using mathjax: $X^2$.

39 |

Here it says X+10=Y using mathjax: $X+10=Y$.

40 |

And this is the next line.

41 |
42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /test7.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | The Malay Archipelago 7 | 41 | 64 | 65 | 66 | 67 | 68 | 69 |
70 | 71 |
72 | 73 |

The Malay Archipelago

74 |
75 | Malay Archipelago Chief's House 76 |
77 | Malay Archipelago Chief's House and Rice-shed in a Sumatran Village 78 |
79 |
80 |
81 |

The Malay Archipelago is a book by the British naturalist Alfred Russel Wallace that chronicles his scientific exploration, during the eight-year period 1854 to 1862, of the southern portion of the Malay Archipelago including Malaysia, Singapore, the islands of Indonesia, then known as the Dutch East Indies, and the island of New Guinea. It was published in two volumes in 1869, delayed by Wallace's ill health and the work needed to describe the many specimens he brought home. The book went through ten editions in the nineteenth century; it has been reprinted many times since, and has been translated into at least eight languages.

82 |

The book described each island that he visited in turn, giving a detailed account of its physical and human geography, its volcanoes, and the variety of animals of plants that he found and collected. At the same time, he describes his experiences, the difficulties of travel, and the help he received from the different peoples that he met. The preface notes that he travelled over 14,000 miles and collected 125,660 natural history specimens, mostly of insects though also with thousands of molluscs, birds, mammals and reptiles.

83 |

The Malay Archipelago attracted many reviews, with interest from scientific, geographic, church and general periodicals. Reviewers noted and sometimes disagreed with various of his theories, especially the division of fauna and flora along what soon became known as the Wallace line, natural selection and uniformitarianism. Nearly all agreed that he had provided an interesting and comprehensive account of the geography, natural history, and peoples of the archipelago, which was little known to their readers at the time, and that he had collected an astonishing number of specimens. The book is much cited, and is Wallace's most successful, both commercially and as a piece of literature.

84 |

Context

85 |

In 1847, Wallace and his friend Henry Walter Bates, both in their early twenties,Bates was 22, Wallace was 24.Bates was 23, Wallace was 25.Bates was 27, Wallace was 29. agreed that they would jointly make a collecting trip to the Amazon "towards solving the problem of origin of species";Mallet, Jim. "Henry Walter Bates". University College London. Retrieved December 11, 2012. Charles Darwin's book on the Origin of Species was not published until 11 years later, in 1859, itself precipitated by a famous letter from Wallace which described the theory in outline.Shoumatoff, Alex (22 August 1988). "A Critic at Large, Henry Walter Bates". New Yorker. They had been inspired by reading the American entomologist William Henry Edwards's pioneering 1847 book A Voyage Up the River Amazon, with a residency at Pará.Edwards, 1847. Bates stayed in the Amazons for 11 years, going on to write The Naturalist on the River Amazons (1863); Wallace, ill with fever, went home in 1852 with thousands of specimens, some for science and some for sale. The ship and his collection were destroyed by fire at sea near the Guianas. Rather than giving up, Wallace wrote about the Amazon in both prose and poetry, and then set sail again, this time for the Malay Archipelago.Edwards, 1847.

86 |

Publication

87 |

The Malay Archipelago was first published in 1869 in two volumes by Macmillan (London), and the same year in one volume by Harper & Brothers (New York). Wallace returned to England in 1862, but explains in the Preface that given the large quantity of specimens and his poor health after his stay in the tropics, it took a long time. He noted that he could at once have printed his notes and journals, but felt that doing that would have been disappointing and unhelpful. Instead, therefore, he waited until he had published papers on his discoveries, and other scientists had described and named as new species some 2,000 of his beetles (Coleoptera), and over 900 Hymenoptera including 200 new species of ant.Wallace, 1869. pp. vii–ix. The book went through 10 editions, with the last published in 1890.

88 |

Overview

89 | 90 |
91 | Wallace's map 92 |
93 | Fold-out coloured map at front of book, showing Wallace's travels around the archipelago 94 |
95 |
96 |
97 |

The preface summarizes Wallace’s travels, the thousands of specimens he collected, and some of the results from their analysis after his return to England. In the preface he notes that he travelled over 14,000 miles and collected 125,660 specimens, mostly of insects: 83,200 beetles, 13,100 butterflies and moths, 13,400 other insects. He also returned to England 7,500 "shells" (such as molluscs), 8,050 birds, 310 mammals and 100 reptiles.Wallace, 1869. p. xiv.

98 |

The book is dedicated to Charles Darwin, but as Wallace explains in the preface, he has chosen to avoid discussing the evolutionary implications of his discoveries. Instead he confines himself to the "interesting facts of the problem, whose solution is to be found in the principles developed by Mr. Darwin",Wallace, 1869. p. xii. so from a scientific point of view, the book is largely a descriptive natural history. This modesty belies the fact that while in Sarawak in 1855 Wallace wrote the paper On the Law which has Regulated the Introduction of New Species, concluding with the evolutionary "Sarawak Law", "Every species has come into existence coincident both in space and time with a closely allied species", three years before he fatefully wrote to Darwin proposing the concept of natural selection.Wallace, Alfred Russel (1855). "On the Law Which has Regulated the Introduction of Species". Western Kentucky University. Retrieved 22 March 2013.

99 |

The first chapter describes the physical geography and geology of the islands with particular attention to the role of volcanoes and earthquakes. It also discusses the overall pattern of the flora and fauna including the fact that the islands can be divided, by what would eventually become known as the Wallace line, into two parts, those whose animals are more closely related to those of Asia and those whose fauna is closer to that of Australia.

100 |

The following chapters describe in detail the places Wallace visited. Wallace includes numerous observations on the people, their languages, ways of living, and social organization, as well as on the plants and animals found in each location. He talks about the biogeographic patterns he observes and their implications for natural history, in terms both of the movement of speciesImplying adaptive radiation. and of the geologic history of the region. He also narrates some of his personal experiences during his travels. The final chapter is an overview of the ethnic, linguistic, and cultural divisions among the people who live in the region and speculation about what such divisions might indicate about their history.

101 |

Illustrations

102 | 103 |
104 | Great-shielded Grasshopper 105 |
106 | "Great-shielded Grasshopper" drawn and signed by E. W. Robinson 107 |
108 |
109 |
110 |

The illustrations are, according to the Preface, made from Wallace's own sketches, photographs, or specimens. Wallace thanks Walter and Henry Woodbury for some photographs of scenery and native people. He acknowledges William Wilson Saunders and Mr Pascoe for horned flies and very rare Longhorn beetles: all the rest were from his own enormous collection.

111 | 112 | 113 | 114 | 115 |
116 | 117 | 118 | 119 | -------------------------------------------------------------------------------- /test8.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | The Malay Archipelago 7 | 40 | 63 | 64 | 65 | 66 | 67 | 68 |
69 | 70 |
71 | 72 |

The Malay Archipelago

73 |
74 | Malay Archipelago Chief's House 75 |
76 | Malay Archipelago Chief's House and Rice-shed in a Sumatran Village 77 |
78 |
79 |
80 |

The Malay Archipelago is a book by the British naturalist Alfred Russel Wallace that chronicles his scientific exploration, during the eight-year period 1854 to 1862, of the southern portion of the Malay Archipelago including Malaysia, Singapore, the islands of Indonesia, then known as the Dutch East Indies, and the island of New Guinea. It was published in two volumes in 1869, delayed by Wallace's ill health and the work needed to describe the many specimens he brought home. The book went through ten editions in the nineteenth century; it has been reprinted many times since, and has been translated into at least eight languages.

81 |

The book described each island that he visited in turn, giving a detailed account of its physical and human geography, its volcanoes, and the variety of animals of plants that he found and collected. At the same time, he describes his experiences, the difficulties of travel, and the help he received from the different peoples that he met. The preface notes that he travelled over 14,000 miles and collected 125,660 natural history specimens, mostly of insects though also with thousands of molluscs, birds, mammals and reptiles.

82 |

The Malay Archipelago attracted many reviews, with interest from scientific, geographic, church and general periodicals. Reviewers noted and sometimes disagreed with various of his theories, especially the division of fauna and flora along what soon became known as the Wallace line, natural selection and uniformitarianism. Nearly all agreed that he had provided an interesting and comprehensive account of the geography, natural history, and peoples of the archipelago, which was little known to their readers at the time, and that he had collected an astonishing number of specimens. The book is much cited, and is Wallace's most successful, both commercially and as a piece of literature.

83 |

Context

84 |

In 1847, Wallace and his friend Henry Walter Bates, both in their early twenties,Bates was 22, Wallace was 24. agreed that they would jointly make a collecting trip to the Amazon "towards solving the problem of origin of species";Mallet, Jim. "Henry Walter Bates". University College London. Retrieved December 11, 2012. Charles Darwin's book on the Origin of Species was not published until 11 years later, in 1859, itself precipitated by a famous letter from Wallace which described the theory in outline.Shoumatoff, Alex (22 August 1988). "A Critic at Large, Henry Walter Bates". New Yorker. They had been inspired by reading the American entomologist William Henry Edwards's pioneering 1847 book A Voyage Up the River Amazon, with a residency at Pará.Edwards, 1847. Bates stayed in the Amazons for 11 years, going on to write The Naturalist on the River Amazons (1863); Wallace, ill with fever, went home in 1852 with thousands of specimens, some for science and some for sale. The ship and his collection were destroyed by fire at sea near the Guianas. Rather than giving up, Wallace wrote about the Amazon in both prose and poetry, and then set sail again, this time for the Malay Archipelago.Edwards, 1847.

85 |

Publication

86 |

The Malay Archipelago was first published in 1869 in two volumes by Macmillan (London), and the same year in one volume by Harper & Brothers (New York). Wallace returned to England in 1862, but explains in the Preface that given the large quantity of specimens and his poor health after his stay in the tropics, it took a long time. He noted that he could at once have printed his notes and journals, but felt that doing that would have been disappointing and unhelpful. Instead, therefore, he waited until he had published papers on his discoveries, and other scientists had described and named as new species some 2,000 of his beetles (Coleoptera), and over 900 Hymenoptera including 200 new species of ant.Wallace, 1869. pp. vii–ix. The book went through 10 editions, with the last published in 1890.

87 |

Overview

88 | 89 |
90 | Wallace's map 91 |
92 | Fold-out coloured map at front of book, showing Wallace's travels around the archipelago 93 |
94 |
95 |
96 |

The preface summarizes Wallace’s travels, the thousands of specimens he collected, and some of the results from their analysis after his return to England. In the preface he notes that he travelled over 14,000 miles and collected 125,660 specimens, mostly of insects: 83,200 beetles, 13,100 butterflies and moths, 13,400 other insects. He also returned to England 7,500 "shells" (such as molluscs), 8,050 birds, 310 mammals and 100 reptiles.Wallace, 1869. p. xiv.

97 |

The book is dedicated to Charles Darwin, but as Wallace explains in the preface, he has chosen to avoid discussing the evolutionary implications of his discoveries. Instead he confines himself to the "interesting facts of the problem, whose solution is to be found in the principles developed by Mr. Darwin",Wallace, 1869. p. xii. so from a scientific point of view, the book is largely a descriptive natural history. This modesty belies the fact that while in Sarawak in 1855 Wallace wrote the paper On the Law which has Regulated the Introduction of New Species, concluding with the evolutionary "Sarawak Law", "Every species has come into existence coincident both in space and time with a closely allied species", three years before he fatefully wrote to Darwin proposing the concept of natural selection.Wallace, Alfred Russel (1855). "On the Law Which has Regulated the Introduction of Species". Western Kentucky University. Retrieved 22 March 2013.

98 | 99 |
100 |
101 | Production info on the Malay Archipelago 102 |
103 |
104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 |
Author(s)Alfred Russel Wallace
Original titleThe Malay Archipelago: The land of the orang-utan, and the bird of paradise. A narrative of travel, with sketches of man and nature
LanguageEnglish
Genre(s)Natural History, Travel
PublisherMacmillan
Publication date1869
Media type2 volumes
134 | 135 | 136 | 137 |

The first chapter describes the physical geography and geology of the islands with particular attention to the role of volcanoes and earthquakes. It also discusses the overall pattern of the flora and fauna including the fact that the islands can be divided, by what would eventually become known as the Wallace line, into two parts, those whose animals are more closely related to those of Asia and those whose fauna is closer to that of Australia.

138 |

The following chapters describe in detail the places Wallace visited. Wallace includes numerous observations on the people, their languages, ways of living, and social organization, as well as on the plants and animals found in each location. He talks about the biogeographic patterns he observes and their implications for natural history, in terms both of the movement of speciesImplying adaptive radiation. and of the geologic history of the region. He also narrates some of his personal experiences during his travels. The final chapter is an overview of the ethnic, linguistic, and cultural divisions among the people who live in the region and speculation about what such divisions might indicate about their history.

139 |

Illustrations

140 | 141 |
142 | Great-shielded Grasshopper 143 |
144 | "Great-shielded Grasshopper" drawn and signed by E. W. Robinson 145 |
146 |
147 |
148 |

The illustrations are, according to the Preface, made from Wallace's own sketches, photographs, or specimens. Wallace thanks Walter and Henry Woodbury for some photographs of scenery and native people. He acknowledges William Wilson Saunders and Mr Pascoe for horned flies and very rare Longhorn beetles: all the rest were from his own enormous collection.

149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /test9.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | The Malay Archipelago 8 | 38 | 60 | 61 | 62 | 63 | 64 | 65 |
66 | 67 |
68 | 69 |

The Malay Archipelago

70 |
71 | Malay Archipelago Chief's House 72 |
73 | Malay Archipelago Chief's House and Rice-shed in a Sumatran Village 74 |
75 |
76 |
77 |

The Malay Archipelago is a book by the British naturalist Alfred Russel Wallace that chronicles his scientific exploration, during the eight-year period 1854 to 1862, of the southern portion of the Malay Archipelago including Malaysia, Singapore, the islands of Indonesia, then known as the Dutch East Indies, and the island of New Guinea. It was published in two volumes in 1869, delayed by Wallace's ill health and the work needed to describe the many specimens he brought home. The book went through ten editions in the nineteenth century; it has been reprinted many times since, and has been translated into at least eight languages.

78 |

The book described each island that he visited in turn, giving a detailed account of its physical and human geography, its volcanoes, and the variety of animals of plants that he found and collected. At the same time, he describes his experiences, the difficulties of travel, and the help he received from the different peoples that he met. The preface notes that he travelled over 14,000 miles and collected 125,660 natural history specimens, mostly of insects though also with thousands of molluscs, birds, mammals and reptiles.

79 |

The Malay Archipelago attracted many reviews, with interest from scientific, geographic, church and general periodicals. Reviewers noted and sometimes disagreed with various of his theories, especially the division of fauna and flora along what soon became known as the Wallace line, natural selection and uniformitarianism. Nearly all agreed that he had provided an interesting and comprehensive account of the geography, natural history, and peoples of the archipelago, which was little known to their readers at the time, and that he had collected an astonishing number of specimens. The book is much cited, and is Wallace's most successful, both commercially and as a piece of literature.

80 |

Context

81 |

In 1847, Wallace and his friend Henry Walter Bates, both in their early twenties,Bates was 22, Wallace was 24. agreed that they would jointly make a collecting trip to the Amazon "towards solving the problem of origin of species";Mallet, Jim. "Henry Walter Bates". University College London. Retrieved December 11, 2012. Charles Darwin's book on the Origin of Species was not published until 11 years later, in 1859, itself precipitated by a famous letter from Wallace which described the theory in outline.Shoumatoff, Alex (22 August 1988). "A Critic at Large, Henry Walter Bates". New Yorker. They had been inspired by reading the American entomologist William Henry Edwards's pioneering 1847 book A Voyage Up the River Amazon, with a residency at Pará.Edwards, 1847. Bates stayed in the Amazons for 11 years, going on to write The Naturalist on the River Amazons (1863); Wallace, ill with fever, went home in 1852 with thousands of specimens, some for science and some for sale. The ship and his collection were destroyed by fire at sea near the Guianas. Rather than giving up, Wallace wrote about the Amazon in both prose and poetry, and then set sail again, this time for the Malay Archipelago.Edwards, 1847.

82 |

Publication

83 |

The Malay Archipelago was first published in 1869 in two volumes by Macmillan (London), and the same year in one volume by Harper & Brothers (New York). Wallace returned to England in 1862, but explains in the Preface that given the large quantity of specimens and his poor health after his stay in the tropics, it took a long time. He noted that he could at once have printed his notes and journals, but felt that doing that would have been disappointing and unhelpful. Instead, therefore, he waited until he had published papers on his discoveries, and other scientists had described and named as new species some 2,000 of his beetles (Coleoptera), and over 900 Hymenoptera including 200 new species of ant.Wallace, 1869. pp. vii–ix. The book went through 10 editions, with the last published in 1890.

84 |

Overview

85 | 86 |
87 | Wallace's map 88 |
89 | Fold-out coloured map at front of book, showing Wallace's travels around the archipelago 90 |
91 |
92 |
93 |

The preface summarizes Wallace’s travels, the thousands of specimens he collected, and some of the results from their analysis after his return to England. In the preface he notes that he travelled over 14,000 miles and collected 125,660 specimens, mostly of insects: 83,200 beetles, 13,100 butterflies and moths, 13,400 other insects. He also returned to England 7,500 "shells" (such as molluscs), 8,050 birds, 310 mammals and 100 reptiles.Wallace, 1869. p. xiv.

94 |

The book is dedicated to Charles Darwin, but as Wallace explains in the preface, he has chosen to avoid discussing the evolutionary implications of his discoveries. Instead he confines himself to the "interesting facts of the problem, whose solution is to be found in the principles developed by Mr. Darwin",Wallace, 1869. p. xii. so from a scientific point of view, the book is largely a descriptive natural history. This modesty belies the fact that while in Sarawak in 1855 Wallace wrote the paper On the Law which has Regulated the Introduction of New Species, concluding with the evolutionary "Sarawak Law", "Every species has come into existence coincident both in space and time with a closely allied species", three years before he fatefully wrote to Darwin proposing the concept of natural selection.Wallace, Alfred Russel (1855). "On the Law Which has Regulated the Introduction of Species". Western Kentucky University. Retrieved 22 March 2013.

95 |

The first chapter describes the physical geography and geology of the islands with particular attention to the role of volcanoes and earthquakes. It also discusses the overall pattern of the flora and fauna including the fact that the islands can be divided, by what would eventually become known as the Wallace line, into two parts, those whose animals are more closely related to those of Asia and those whose fauna is closer to that of Australia.

96 |

The following chapters describe in detail the places Wallace visited. Wallace includes numerous observations on the people, their languages, ways of living, and social organization, as well as on the plants and animals found in each location. He talks about the biogeographic patterns he observes and their implications for natural history, in terms both of the movement of speciesImplying adaptive radiation. and of the geologic history of the region. He also narrates some of his personal experiences during his travels. The final chapter is an overview of the ethnic, linguistic, and cultural divisions among the people who live in the region and speculation about what such divisions might indicate about their history.

97 |

Illustrations

98 | 99 |
100 | Great-shielded Grasshopper 101 |
102 | "Great-shielded Grasshopper" drawn and signed by E. W. Robinson 103 |
104 |
105 |
106 |

The illustrations are, according to the Preface, made from Wallace's own sketches, photographs, or specimens. Wallace thanks Walter and Henry Woodbury for some photographs of scenery and native people. He acknowledges William Wilson Saunders and Mr Pascoe for horned flies and very rare Longhorn beetles: all the rest were from his own enormous collection.

107 | 108 |

Word index

109 |
110 | 111 |
112 | 113 | 114 | 115 | --------------------------------------------------------------------------------