-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add chapter title and page number info to the book page #40
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,9 +54,33 @@ | |
}); | ||
reader.listen("monocle:pagechange", function(event) { | ||
var place = reader.getPlace(); | ||
|
||
// Following code taken from Monacle to estimate overall pages | ||
|
||
var book = place.properties.component.properties.book; | ||
var componentIds = book.properties.componentIds; | ||
var weights = book.componentWeights(); | ||
var cmptIndex = place.properties.component.properties.index; | ||
var pc = weights[cmptIndex] * place.properties.percent; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume |
||
for (var i = 0, ii = cmptIndex; i < ii; ++i) { pc += weights[i]; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why introduce There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, put the loop code on a new line. |
||
|
||
// Note: This is a decent estimation of current page number and total | ||
// number of pages, but it's very approximate. Could be improved by storing | ||
// the page counts of all components accessed (since the dimensions of the | ||
// reader last changed), and averaging the result across them. (You | ||
// probably want to ignore calcs for components < 2 or 3 pages long, too. | ||
// The bigger the component, the more accurate the calculation.) | ||
// | ||
var bkPages = place.properties.component.lastPageNumber() / weights[cmptIndex]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this really need to be calculated every page turn? Couldn't it be cached and only recalculated when the current component changed? |
||
|
||
Messaging.sendMessage("PageChange", { chapterSrc: place.chapterSrc(), | ||
componentId: place.componentId(), | ||
percent: place.percentageThrough() }); | ||
percent: place.percentageThrough(), | ||
title: place.chapterTitle(), | ||
page: Math.floor(pc * bkPages), | ||
pages: Math.floor(bkPages), | ||
totalPercentage: pc | ||
}); | ||
}); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling