mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
add passive event listener to headroom
This commit is contained in:
parent
85731c7453
commit
da25a9cc2a
1 changed files with 401 additions and 367 deletions
|
@ -101,6 +101,32 @@
|
||||||
return t === Object(t) ? t : { down: t, up: t };
|
return t === Object(t) ? t : { down: t, up: t };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var supportsCaptureOption = false;
|
||||||
|
try {
|
||||||
|
var opts = Object.defineProperty({}, 'capture', {
|
||||||
|
get: function () {
|
||||||
|
supportsCaptureOption = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("test", null, opts);
|
||||||
|
} catch (e) { }
|
||||||
|
|
||||||
|
function addEventListenerWithOptions(target, type, handler, options) {
|
||||||
|
var optionsOrCapture = options;
|
||||||
|
if (!supportsCaptureOption) {
|
||||||
|
optionsOrCapture = options.capture;
|
||||||
|
}
|
||||||
|
target.addEventListener(type, handler, optionsOrCapture);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeEventListenerWithOptions(target, type, handler, options) {
|
||||||
|
var optionsOrCapture = options;
|
||||||
|
if (!supportsCaptureOption) {
|
||||||
|
optionsOrCapture = options.capture;
|
||||||
|
}
|
||||||
|
target.removeEventListener(type, handler, optionsOrCapture);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UI enhancement for fixed headers.
|
* UI enhancement for fixed headers.
|
||||||
* Hides header when scrolling down
|
* Hides header when scrolling down
|
||||||
|
@ -138,9 +164,7 @@
|
||||||
|
|
||||||
this.elem.classList.add(this.classes.initial);
|
this.elem.classList.add(this.classes.initial);
|
||||||
|
|
||||||
// defer event registration to handle browser
|
this.attachEvent();
|
||||||
// potentially restoring previous scroll position
|
|
||||||
setTimeout(this.attachEvent.bind(this), 100);
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
@ -153,7 +177,10 @@
|
||||||
|
|
||||||
this.initialised = false;
|
this.initialised = false;
|
||||||
this.elem.classList.remove(classes.unpinned, classes.pinned, classes.top, classes.initial);
|
this.elem.classList.remove(classes.unpinned, classes.pinned, classes.top, classes.initial);
|
||||||
this.scroller.removeEventListener('scroll', this.debouncer, false);
|
removeEventListenerWithOptions(this.scroller, 'scroll', this.debouncer, {
|
||||||
|
capture: false,
|
||||||
|
passive: true
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,7 +191,10 @@
|
||||||
if (!this.initialised) {
|
if (!this.initialised) {
|
||||||
this.lastKnownScrollY = this.getScrollY();
|
this.lastKnownScrollY = this.getScrollY();
|
||||||
this.initialised = true;
|
this.initialised = true;
|
||||||
this.scroller.addEventListener('scroll', this.debouncer, false);
|
addEventListenerWithOptions(this.scroller, 'scroll', this.debouncer, {
|
||||||
|
capture: false,
|
||||||
|
passive: true
|
||||||
|
});
|
||||||
|
|
||||||
this.debouncer.handleEvent();
|
this.debouncer.handleEvent();
|
||||||
}
|
}
|
||||||
|
@ -295,10 +325,14 @@
|
||||||
* @return {bool} true if out of bounds, false otherwise
|
* @return {bool} true if out of bounds, false otherwise
|
||||||
*/
|
*/
|
||||||
isOutOfBounds: function (currentScrollY) {
|
isOutOfBounds: function (currentScrollY) {
|
||||||
var pastTop = currentScrollY < 0,
|
var pastTop = currentScrollY < 0;
|
||||||
pastBottom = currentScrollY + this.getViewportHeight() > this.getScrollerHeight();
|
|
||||||
|
|
||||||
return pastTop || pastBottom;
|
if (pastTop) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pastBottom = currentScrollY + this.getViewportHeight() > this.getScrollerHeight();
|
||||||
|
return pastBottom;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue