Skip to content

Commit

Permalink
format comments
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Nov 9, 2012
1 parent a39a5bc commit fefeade
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 33 deletions.
7 changes: 7 additions & 0 deletions book.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ width:5.8in;
page-break-after:always;
}

/* height of pages when no CSS regions present: auto. Also add some padding. */

.page.simple {
height:auto;
padding: 1in;
}

/* 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 */

.page {
Expand Down
110 changes: 77 additions & 33 deletions book.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,75 @@
/*
* (c) 2012 Aleksandar Erkalovic, Marita Fraser, Steven Levithan, Philip Schatz and Johannes Wilm. Freely available under the AGPL. For further details see LICENSE.txt
/**
* (c) 2012 Aleksandar Erkalovic, Marita Fraser, Steven Levithan,
* Philip Schatz and Johannes Wilm. Freely available under the AGPL. For
* further details see LICENSE.txt
*
* Using this library you can turn an HTML element into a series of pages using
* CSS Regions. If the browser doesn't support CSS Regions, everything will be
* flown into one large page container that looks like a very long page.
*
* In order to use this library, first link to this javascript file within your
* html code. Then you can change the following options to customize the
* pagination behavior. Make sure that the configuration options are mentioned
* after the link to this file. Below you can see the default values for these
* options. You only need to specify the options if you want to deviate from
* the default value.
*
* pagination.config.sectionStartMarker = 'h1'; This is the HTML element we
* look for to find where a new section starts.
*
* pagination.config.sectionTitleMarker = 'h1'; Within the newly found section,
* we look for the first instance of this element to determine the title of
* the section.
*
* pagination.config.chapterStartMarker = 'h2'; This is the HTML element we
* look for to find where a new chapter starts.
*
* pagination.config.chapterTitleMarker = 'h2'; Within the newly found chapter,
* we look for the first instance of this element to determine the title of the
* chapter.
*
* pagination.config.flowElement = "document.body"; This specifies element
* whose contents we will flow into pages. You can use any javascript selector
* here, such as "document.getElementById('contents')" .
*
* pagination.config.alwaysEven = false; This determines whether each section
* and chapter should have an even number of pages (2, 4, 6, 8, ...).
*
* pagination.config.columns = 1; This specifies the number of number of
* columns used for the body text.
*
* pagination.config.enableReflow = true; This decides whether pages should be
* reflown upon change of contents after the first page flow. This is important
* if one wants to add an HTML editor to the contents of the pages so that the
* contents may require more or less pages than initially or one wants to
* change the length contents in other ways dynamically.
*
* pagination.config.enableFrontmatter = true; This resolves whether a table of
* contents, page headers and other frontmatter contents should be added upon
* page creation.
*
* pagination.config.bulkPagesToAdd = 50; This is the initial number of pages
* of each flowable part (section, chapter). After this number is added,
* adjustments are made by adding another bulk of pages or deletin pages
* individually. It takes much less time to delete pages than to add them
* individually, so it is a point to overshoot the target value. For larger
* chapters add many pages at a time so there is less time spent reflowing
* text.
*
* pagination.config.pagesToAddIncrementRatio = 1.4; This is the ratio of how
* the bulk of pages incremented. If the initial bulkPagestoAdd is 50 and those
* initial 50 pages were not enough space to fit the contents of that chapter,
* then next 1.4*50 = 70 are pages, for a total of 50+70 = 120 pages, etc. .
* 1.4 seems to be the fastest in most situations.
*
* pagination.config.frontmatterContents = ''; These are the HTML contents that
* are added to the frontmatter before the table of contents. This would
* usually be a title page and a copyright page, including page breaks.
*
* pagination.config.autoStart = true; This controls whether pagination should
* be executed automatically upon page load.
*/

/* HOW TO CONFIGURE
Using this library you can turn an HTML element into a series of pages using CSS Regions. If the browser doesn't support CSS Regions, everything will be flown into one large page container that looks like a very long page.
In order to use this library, first link to this javascript file within your html code. Then you can change the following options to customize the pagination behavior. Make sure that the configuration options are mentioned after the link to this file. Below you can see the default values for these options. You only need to specify the options if you want to deviate from the default value.
pagination.config.sectionStartMarker = 'h1'; // This is the HTML element we look for to find where a new section starts.
pagination.config.sectionTitleMarker = 'h1'; // Within the newly found section, we look for the first instance of this element to determine the title of the section.
pagination.config.chapterStartMarker = 'h2'; // This is the HTML element we look for to find where a new chapter starts.
pagination.config.chapterTitleMarker = 'h2'; // Within the newly found chapter, we look for the first instance of this element to determine the title of the chapter.
pagination.config.flowElement = "document.body"; // This specifies element whose contents we will flow into pages. You can use any javascript selector here, such as "document.getElementById('contents')"
pagination.config.alwaysEven = false; // This determines whether each section and chapter should have an even number of pages (2, 4, 6, 8, ...).
pagination.config.columns = 1; // This specifies the number of number of columns used for the body text.
pagination.config.enableReflow = true; // This decides whether pages should be reflown upon change of contents after the first page flow. This is important if one wants to add an HTML editor to the contents of the pages so that the contents may require more or less pages than initially or one wants to change the length contents in other ways dynamically.
pagination.config.enableFrontmatter = true; // This resolves whether a table of contents, page headers and other frontmatter contents should be added upon page creation.
pagination.config.bulkPagesToAdd = 50; // This is the initial number of pages of each flowable part (section, chapter). After this number is added, adjustments are made by adding another bulk of pages or deletin pages individually. It takes much less time to delete pages than to add them individually, so it is a point to overshoot the target value. For larger chapters add many pages at a time so there is less time spent reflowing text
pagination.config.pagesToAddIncrementRatio = 1.4; // This is the ratio of how the bulk of pages incremented. If the initial bulkPagestoAdd is 50 and those initial 50 pages were not enough space to fit the contents of that chapter, then next 1.4*50 = 70 are pages, for a total of 50+70 = 120 pages, etc. . 1.4 seems to be the fastest in most situations.
pagination.config.frontmatterContents = ''; // These are the HTML contents that are added to the frontmatter before the table of contents. This would usually be a title page and a copyright page, including page breaks.
pagination.config.autoStart = true; // This controls whether pagination should be executed automatically upon page load. */

var pagination = new Object;

pagination.config = {
Expand Down Expand Up @@ -238,8 +277,12 @@ pagination.headersAndToc = function (bodyObjects) {
return tocDiv;
};

/**
* Creates objects for each item in the body (section start, chapter)
*/

pagination.createBodyObjects = function () {
//Create body objects
//
var bodyObjects = [];
var chapterCounter = 0;

Expand Down Expand Up @@ -492,7 +535,8 @@ pagination.applySimpleBookLayout = function () {
// Apply this alternative layout in case CSS Regions are not present
bodyContainer = eval(pagination.config.flowElement);
simplePage = document.createElement('div');
simplePage.classList.add('simplepage');
simplePage.classList.add('page');
simplePage.classList.add('simple');
simplePage.innerHTML = bodyContainer.innerHTML;
simplePage.id = bodyContainer.id;
bodyContainer.innerHTML = '';
Expand Down

0 comments on commit fefeade

Please sign in to comment.