Skip to content

Commit b107075

Browse files
committed
TMP
1 parent d0336c6 commit b107075

5 files changed

Lines changed: 53 additions & 12 deletions

File tree

src/BookReader.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,35 @@ BookReader.prototype.setup = function(options) {
174174
/** @deprecated */
175175
this.bookPath = options.bookPath;
176176
this.fader = utils.debounce(
177-
() => $(document.body).addClass('faded'),
177+
(source) => {
178+
console.log('Fading UI');
179+
$(document.body)
180+
.addClass('faded')
181+
.toggleClass('faded--scroll', source === 'scroll');
182+
// const animation = this.$('.BRfooter')[0].getAnimations()[0];
183+
// if (!animation) return;
184+
// if (source === 'scroll') animation.pause();
185+
// animation.currentTime = 0;
186+
},
178187
2000,
179-
() => $(document.body).removeClass('faded'),
188+
(source) => {
189+
console.log('Show UI');
190+
$(document.body)
191+
.removeClass('faded')
192+
.toggleClass('faded--scroll', source === 'scroll');
193+
},
194+
{
195+
tap: (source) => {
196+
console.log('Show UI ...', source);
197+
// if (source === 'scroll') {
198+
// const animation = this.$('.BRfooter')[0].getAnimations()[0];
199+
// if (animation) {
200+
// // const max = animation.effect.getComputedTiming().duration;
201+
// animation.currentTime += 1;
202+
// }
203+
// }
204+
},
205+
},
180206
);
181207

182208
// Construct the usual plugins first to get type hints
@@ -747,8 +773,8 @@ BookReader.prototype.init = function() {
747773
}
748774
}
749775

750-
this.refs.$br.on('mousemove', this.fader);
751-
this.refs.$brContainer.on('scroll', utils.onScrollUp(this.fader));
776+
this.refs.$br.on('mousemove', () => this.fader('mousemove'));
777+
this.refs.$brContainer[0].addEventListener('scroll', utils.eventFilterScrollUp(() => this.fader('scroll')), { passive: true });
752778

753779
this.init.initComplete = true;
754780
this.trigger(BookReader.eventNames.PostInit);
@@ -1986,6 +2012,7 @@ BookReader.prototype.queryStringFromParams = function(
19862012

19872013
/**
19882014
* Helper to select within instance's elements
2015+
* @returns {JQuery<HTMLElement>}
19892016
*/
19902017
BookReader.prototype.$ = function(selector) {
19912018
return this.refs.$br.find(selector);

src/BookReader/Mode1Up.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Mode1UpLit } from './Mode1UpLit.js';
33
import { DragScrollable } from './DragScrollable.js';
44
import { ModeAbstract } from './ModeAbstract.js';
5-
import { onScrollUp } from './utils.js';
5+
import { eventFilterScrollUp } from './utils.js';
66
/** @typedef {import('../BookReader.js').default} BookReader */
77
/** @typedef {import('./BookModel.js').BookModel} BookModel */
88
/** @typedef {import('./BookModel.js').PageIndex} PageIndex */
@@ -25,8 +25,8 @@ export class Mode1Up extends ModeAbstract {
2525
// We CANNOT use `br-mode-1up` as a class, because it's the same
2626
// as the name of the web component, and the webcomponents polyfill
2727
// uses the name of component as a class for style scoping 😒
28-
.addClass('br-mode-1up__root BRmode1up')
29-
.on('scroll', onScrollUp(this.br.fader));
28+
.addClass('br-mode-1up__root BRmode1up');
29+
this.$el[0].addEventListener('scroll', eventFilterScrollUp(() => this.br.fader('scroll')), { passive: true });
3030

3131
/** Has mode1up ever been rendered before? */
3232
this.everShown = false;

src/BookReader/Mode2Up.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Mode2UpLit } from './Mode2UpLit.js';
33
import { DragScrollable } from './DragScrollable.js';
44
import { ModeAbstract } from './ModeAbstract.js';
5-
import { onScrollUp } from './utils.js';
5+
import { eventFilterScrollUp } from './utils.js';
66
/** @typedef {import('../BookReader.js').default} BookReader */
77
/** @typedef {import('./BookModel.js').BookModel} BookModel */
88
/** @typedef {import('./BookModel.js').PageIndex} PageIndex */
@@ -31,8 +31,8 @@ export class Mode2Up extends ModeAbstract {
3131
// We CANNOT use `br-mode-2up` as a class, because it's the same
3232
// as the name of the web component, and the webcomponents polyfill
3333
// uses the name of component as a class for style scoping 😒
34-
.addClass('br-mode-2up__root BRmode2up')
35-
.on('scroll', onScrollUp(this.br.fader));
34+
.addClass('br-mode-2up__root BRmode2up');
35+
this.$el[0].addEventListener('scroll', eventFilterScrollUp(() => this.br.fader('scroll')), { passive: true });
3636

3737
/** Has mode2up ever been rendered before? */
3838
this.everShown = false;

src/BookReader/utils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ export function encodeURIComponentPlus(value) {
110110
* @param {boolean | function} immediate If true, calls func on the leading edge. If a
111111
* function is provided, that function is called on the leading edge instead of `func`.
112112
* `func` is still called on the trailing edge.
113+
* @param {Object} [options]
114+
* @param {function | null} [options.tap] Function to tap the event stream -- eg not debounced
113115
* @return {T}
114116
*/
115-
export function debounce(func, wait, immediate) {
117+
export function debounce(func, wait, immediate, {tap = null} = {}) {
116118
let timeout;
117119
return function() {
118120
const context = this;
@@ -131,6 +133,10 @@ export function debounce(func, wait, immediate) {
131133
func.apply(context, args);
132134
}
133135
}
136+
137+
if (tap) {
138+
tap.apply(context, args);
139+
}
134140
};
135141
}
136142

@@ -326,7 +332,7 @@ export function sortBy(array, valueFn) {
326332
* @param {number} [options.scrollDelay=20] How many pixels to scroll before triggering
327333
* @returns {function(): void}
328334
*/
329-
export function onScrollUp(callback, {scrollDelay = 20} = {}) {
335+
export function eventFilterScrollUp(callback, {scrollDelay = 20} = {}) {
330336
let lastScrollTop = 0;
331337
let accumulatedScroll = 0;
332338
return function() {

src/css/_BRnav.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ ia-bookreader::part(minimized-menu) {
120120
}
121121
}
122122

123+
.faded--scroll {
124+
.BRfooter:not(:focus-within):not(:hover) {
125+
translate: 0 20px;
126+
}
127+
ia-bookreader::part(minimized-menu) {
128+
translate: 0 20px;
129+
}
130+
}
123131

124132
.BRnav {
125133
box-sizing: border-box;

0 commit comments

Comments
 (0)