Skip to content

Commit

Permalink
Merge pull request #1099 from cdrini/webdev5064/remove-class-shims
Browse files Browse the repository at this point in the history
Remove most class shims + v5 BR deprecations
  • Loading branch information
cdrini authored Nov 18, 2022
2 parents b8ebca0 + 5b45ab9 commit d2b02ff
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 524 deletions.
8 changes: 4 additions & 4 deletions src/BookNavigator/bookmarks/ia-bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ class IABookmarks extends LitElement {
color: this.getBookmarkColor(color) ? color : this.defaultColor.id,
};

const page = IABookmarks.formatPage(this.bookreader.getPageNum(leafNum));
const thumbnail = this.bookreader.getPageURI(`${leafNum}`.replace(/\D/g, ''), 32); // Request thumbnail 1/32 the size of original image
const page = IABookmarks.formatPage(this.bookreader.book.getPageNum(leafNum));
const thumbnail = this.bookreader.book.getPageURI(`${leafNum}`.replace(/\D/g, ''), 32); // Request thumbnail 1/32 the size of original image
const bookmark = {
...nomalizedParams,
id: leafNum,
Expand Down Expand Up @@ -297,7 +297,7 @@ class IABookmarks extends LitElement {
const pageBookmark = this.getBookmark(pageID);
const bookmarkState = pageBookmark ? 'filled' : 'hollow';
// eslint-disable-next-line
const pageData = this.bookreader._models.book.getPage(pageID);
const pageData = this.bookreader.book.getPage(pageID);
const { isViewable } = pageData;

if (!isViewable) { return; }
Expand Down Expand Up @@ -417,7 +417,7 @@ class IABookmarks extends LitElement {

bookmarkSelected({ detail }) {
const { leafNum } = detail.bookmark;
this.bookreader.jumpToPage(`${this.bookreader.getPageNum(`${leafNum}`.replace(/\D/g, ''))}`);
this.bookreader.jumpToPage(`${this.bookreader.book.getPageNum(`${leafNum}`.replace(/\D/g, ''))}`);
this.activeBookmarkID = leafNum;
}

Expand Down
403 changes: 65 additions & 338 deletions src/BookReader.js

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions src/BookReader/BookModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,10 @@ export class BookModel {

/** @type {{width: number, height: number}} memoize storage */
this._medianPageSize = null;
/** @deprecated @type {{width: number, height: number}} memoize storage */
this._medianPageSizePixels = null;
/** @type {[PageData[], number]} */
this._getDataFlattenedCached = null;
}

/**
* @deprecated Use getMedianPageSizeInches
* Memoized
* @return {{width: number, height: number}}
*/
getMedianPageSize() {
if (this._medianPageSizePixels) {
return this._medianPageSizePixels;
}

// A little expensive but we just do it once
const widths = [];
const heights = [];
for (let i = 0; i < this.getNumLeafs(); i++) {
widths.push(this.getPageWidth(i));
heights.push(this.getPageHeight(i));
}

widths.sort();
heights.sort();
this._medianPageSizePixels = {
width: widths[Math.floor(widths.length / 2)],
height: heights[Math.floor(heights.length / 2)]
};
return this._medianPageSizePixels;
}

/** Get median width/height of page in inches. Memoized for performance. */
getMedianPageSizeInches() {
if (this._medianPageSize) {
Expand Down
2 changes: 1 addition & 1 deletion src/BookReader/Mode1UpLit.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class Mode1UpLit extends LitElement {
this.throttledUpdateRenderedPages();
this.br.displayedIndices = this.visiblePages.map(p => p.index);
this.br.updateFirstIndex(this.br.displayedIndices[0]);
this.br.updateNavIndexThrottled();
this.br._components.navbar.updateNavIndexThrottled();
}
if (changedProps.has('scale')) {
const oldVal = changedProps.get('scale');
Expand Down
43 changes: 9 additions & 34 deletions src/BookReader/Mode2Up.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export class Mode2Up {

this.displayedIndices = [this.br.twoPage.currentIndexL, this.br.twoPage.currentIndexR];
this.br.displayedIndices = this.displayedIndices;
this.br.updateToolbarZoom(this.br.reduce);
this.br.trigger('pageChanged');
}

Expand Down Expand Up @@ -118,7 +117,7 @@ export class Mode2Up {

// Prepare view with new center to minimize visual glitches
const drawNewSpread = true;
this.prepareTwoPageView(oldCenter.percentageX, oldCenter.percentageY, drawNewSpread);
this.prepare(oldCenter.percentageX, oldCenter.percentageY, drawNewSpread);
}

/**
Expand Down Expand Up @@ -150,7 +149,7 @@ export class Mode2Up {
* @param {number} centerPercentageY
* @param {Boolean} drawNewSpread
*/
prepareTwoPageView(centerPercentageX, centerPercentageY, drawNewSpread = false) {
prepare(centerPercentageX, centerPercentageY, drawNewSpread = false) {
// Some decisions about two page view:
//
// Both pages will be displayed at the same height, even if they were different physical/scanned
Expand Down Expand Up @@ -241,7 +240,6 @@ export class Mode2Up {
this.br.displayedIndices = [];

this.drawLeafs();
this.br.updateToolbarZoom(this.br.reduce);
this.br.updateBrClasses();

this.smoothZoomer = this.smoothZoomer || new ModeSmoothZoom(this);
Expand Down Expand Up @@ -391,7 +389,7 @@ export class Mode2Up {

// Leaf edges
this.br.twoPage.edgeWidth = spreadSize.totalLeafEdgeWidth; // The combined width of both edges
this.br.twoPage.leafEdgeWidthL = this.br.leafEdgeWidth(this.br.twoPage.currentIndexL);
this.br.twoPage.leafEdgeWidthL = this.leafEdgeWidth(this.br.twoPage.currentIndexL);
this.br.twoPage.leafEdgeWidthR = this.br.twoPage.edgeWidth - this.br.twoPage.leafEdgeWidthL;


Expand Down Expand Up @@ -528,21 +526,6 @@ export class Mode2Up {
return spreadSize.reduce;
}

/**
* Returns true if the pages extend past the edge of the view
* @deprecated slated for deprecation by v5.0.0
* @return {boolean}
*/
isZoomedIn() {
let isZoomedIn = false;
if (this.br.twoPage.autofit != 'auto') {
if (this.br.reduce < this.getAutofitReduce()) {
isZoomedIn = true;
}
}
return isZoomedIn;
}

calculateReductionFactors() {
this.br.twoPage.reductionFactors = this.br.reductionFactors.concat([
{
Expand All @@ -553,14 +536,6 @@ export class Mode2Up {
this.br.twoPage.reductionFactors.sort(this.br._reduceSort);
}

/**
* Set the cursor for two page view
* @deprecated Since version 4.3.3. Will be deleted in version 5.0
*/
setCursor() {
console.warn('Call to deprecated method, Mode2Up.setCursor. No-op.');
}

/**
* @param {Number|null} index to flip back one spread, pass index=null
*/
Expand All @@ -584,7 +559,7 @@ export class Mode2Up {
if (prev.pageSide == 'R') index--;
}

this.br.updateNavIndexThrottled(index);
this.br._components.navbar.updateNavIndexThrottled(index);

const previousIndices = this.book.getSpreadIndices(index);

Expand Down Expand Up @@ -614,8 +589,8 @@ export class Mode2Up {
this.br.refs.$brContainer.addClass("BRpageFlipping");
const leftLeaf = this.br.twoPage.currentIndexL;

const oldLeafEdgeWidthL = this.br.leafEdgeWidth(this.br.twoPage.currentIndexL);
const newLeafEdgeWidthL = this.br.leafEdgeWidth(newIndexL);
const oldLeafEdgeWidthL = this.leafEdgeWidth(this.br.twoPage.currentIndexL);
const newLeafEdgeWidthL = this.leafEdgeWidth(newIndexL);
const leafEdgeTmpW = oldLeafEdgeWidthL - newLeafEdgeWidthL;

const currWidthL = this.getPageWidth(leftLeaf);
Expand Down Expand Up @@ -782,7 +757,7 @@ export class Mode2Up {
}
if (index > this.br.lastDisplayableIndex()) return;

this.br.updateNavIndexThrottled(index);
this.br._components.navbar.updateNavIndexThrottled(index);

this.br.animating = true;

Expand All @@ -808,9 +783,9 @@ export class Mode2Up {
flipRightToLeft(newIndexL, newIndexR) {
this.br.refs.$brContainer.addClass("BRpageFlipping");

const oldLeafEdgeWidthL = this.br.leafEdgeWidth(this.br.twoPage.currentIndexL);
const oldLeafEdgeWidthL = this.leafEdgeWidth(this.br.twoPage.currentIndexL);
const oldLeafEdgeWidthR = this.br.twoPage.edgeWidth - oldLeafEdgeWidthL;
const newLeafEdgeWidthL = this.br.leafEdgeWidth(newIndexL);
const newLeafEdgeWidthL = this.leafEdgeWidth(newIndexL);
const newLeafEdgeWidthR = this.br.twoPage.edgeWidth - newLeafEdgeWidthL;

const leafEdgeTmpW = oldLeafEdgeWidthR - newLeafEdgeWidthR;
Expand Down
4 changes: 1 addition & 3 deletions src/BookReader/ModeThumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class ModeThumb {
// shift viewModeOrder after clicking on thumbsnail leaf
const nextModeID = this.br.viewModeOrder.shift();
this.br.viewModeOrder.push(nextModeID);
this.br.updateViewModeButton($('.viewmode'), 'twopg', 'Two-page view');
this.br._components.navbar.updateViewModeButton($('.viewmode'), 'twopg', 'Two-page view');

this.br.trigger(EVENTS.fragmentChange);
event.stopPropagation();
Expand Down Expand Up @@ -215,8 +215,6 @@ export class ModeThumb {

// highlight current page
this.br.$('.pagediv' + this.br.currentIndex()).addClass('BRpagedivthumb_highlight');

this.br.updateToolbarZoom(this.br.reduce);
}

/**
Expand Down
13 changes: 8 additions & 5 deletions src/BookReader/Navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'jquery-ui/ui/widget.js';
import 'jquery-ui/ui/widgets/mouse.js';
import 'jquery-ui/ui/widgets/slider.js';
import { EVENTS } from '../events.js';
import { throttle } from '../utils.js';

export class Navbar {
/**
Expand All @@ -27,6 +28,8 @@ export class Navbar {
this.maximumControls = [
'book_left', 'book_right', 'zoom_in', 'zoom_out', 'onepg', 'twopg', 'thumb'
];

this.updateNavIndexThrottled = throttle(this.updateNavIndex.bind(this), 250, false);
}

controlFor(controlName) {
Expand Down Expand Up @@ -213,7 +216,7 @@ export class Navbar {
const $slider = this.$root.find('.BRpager').slider({
animate: true,
min: 0,
max: br.getNumLeafs() - 1,
max: br.book.getNumLeafs() - 1,
value: br.currentIndex(),
range: "min"
});
Expand Down Expand Up @@ -248,16 +251,16 @@ export class Navbar {
getNavPageNumString(index) {
const { br } = this;
// Accessible index starts at 0 (alas) so we add 1 to make human
const pageNum = br.getPageNum(index);
const pageType = br.getPageProp(index, 'pageType');
const numLeafs = br.getNumLeafs();
const pageNum = br.book.getPageNum(index);
const pageType = br.book.getPageProp(index, 'pageType');
const numLeafs = br.book.getNumLeafs();

if (!this.maxPageNum) {
// Calculate Max page num (used for pagination display)
let maxPageNum = 0;
let pageNumVal;
for (let i = 0; i < numLeafs; i++) {
pageNumVal = br.getPageNum(i);
pageNumVal = br.book.getPageNum(i);
if (!isNaN(pageNumVal) && pageNumVal > maxPageNum) {
maxPageNum = pageNumVal;
}
Expand Down
33 changes: 3 additions & 30 deletions src/BookReader/Toolbar/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ export class Toolbar {
br.$('.BRnavCntl').addClass('BRup');
br.$('.pause').hide();

this.updateToolbarZoom(br.reduce); // Pretty format

// We build in mode 2
br.refs.$BRtoolbar.append();

Expand Down Expand Up @@ -127,31 +125,6 @@ export class Toolbar {
});
}

/**
* @deprecated
* @todo .BRzoom doesn't exist anywhere, so this is likely dead code
* Update the displayed zoom factor based on reduction factor
* @param {number} reduce
*/
updateToolbarZoom(reduce) {
const { br } = this;
// $$$ TODO preserve zoom/fit for each mode
const autofit = br.mode == br.constMode2up ? br.twoPage.autofit : br.onePage.autofit;
/** @type {string} */
let value;
if (autofit) {
value = autofit.slice(0,1).toUpperCase() + autofit.slice(1);
} else {
value = (100 / reduce)
.toFixed(2)
// Strip trailing zeroes and decimal if all zeroes
.replace(/0+$/,'')
.replace(/\.$/,'')
+ '%';
}
br.$('.BRzoom').text(value);
}

/**
* @param {JQuery} $shareDiv
*/
Expand Down Expand Up @@ -216,7 +189,7 @@ export class Toolbar {
const params = {};
params.mode = $(form.find('.fieldset-embed input[name=pages]:checked')).val();
if (form.find('.fieldset-embed input[name=thispage]').prop('checked')) {
params.page = br.getPageNum(br.currentIndex());
params.page = br.book.getPageNum(br.currentIndex());
}

if (br.getEmbedCode) {
Expand Down Expand Up @@ -331,7 +304,7 @@ export class Toolbar {
}
}

export function blankInfoDiv() {
function blankInfoDiv() {
return $(`
<div class="BRfloat BRinfo">
<div class="BRfloatHead">About this book
Expand All @@ -351,7 +324,7 @@ export function blankInfoDiv() {
</div>`);
}

export function blankShareDiv() {
function blankShareDiv() {
return $(`
<div class="BRfloat BRshare">
<div class="BRfloatHead">
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/plugin.autoplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ BookReader.prototype.autoToggle = function(overrides) {
}

// Change to autofit if book is too large
if (this.reduce < this.twoPageGetAutofitReduce()) {
if (this.reduce < this._modes.mode2Up.getAutofitReduce()) {
this.zoom('auto');
}

Expand All @@ -94,7 +94,7 @@ BookReader.prototype.autoToggle = function(overrides) {
// don't flip immediately -- wait until timer fires
} else {
// flip immediately
this.flipFwdToIndex();
this.next({ triggerStop: false });
}

this.$('.play').hide();
Expand All @@ -103,9 +103,9 @@ BookReader.prototype.autoToggle = function(overrides) {
if (this.animating) return;

if (Math.max(this.twoPage.currentIndexL, this.twoPage.currentIndexR) >= this.lastDisplayableIndex()) {
this.flipBackToIndex(1); // $$$ really what we want?
this.prev({ triggerStop: false }); // $$$ really what we want?
} else {
this.flipFwdToIndex();
this.next({ triggerStop: false });
}
}, this.flipDelay);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/plugin.chapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ BookReader.prototype.init = (function(super_) {
*/
BookReader.prototype.addChapter = function(chapterTitle, pageNumber, pageIndex) {
const uiStringPage = 'Page'; // i18n
const percentThrough = BookReader.util.cssPercentage(pageIndex, this.getNumLeafs() - 1);
const percentThrough = BookReader.util.cssPercentage(pageIndex, this.book.getNumLeafs() - 1);
const jumpToChapter = (event) => {
this.jumpToIndex($(event.delegateTarget).data('pageIndex'));
$('.current-chapter').removeClass('current-chapter');
Expand Down Expand Up @@ -151,7 +151,7 @@ BookReader.prototype.updateTOC = function(tocEntries) {
* @param {TocEntry} tocEntryObject
*/
BookReader.prototype.addChapterFromEntry = function(tocEntryObject) {
tocEntryObject.pageIndex = this.getPageIndex(tocEntryObject['pagenum']);
tocEntryObject.pageIndex = this.book.getPageIndex(tocEntryObject['pagenum']);
//creates a string with non-void tocEntryObject.label and tocEntryObject.title
const chapterStr = [tocEntryObject.label, tocEntryObject.title]
.filter(x => x)
Expand Down
Loading

0 comments on commit d2b02ff

Please sign in to comment.