1
0
Fork 0
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:
Luke Pulverenti 2016-08-06 22:09:28 -04:00
parent 85731c7453
commit da25a9cc2a

View file

@ -101,6 +101,32 @@
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.
* Hides header when scrolling down
@ -138,9 +164,7 @@
this.elem.classList.add(this.classes.initial);
// defer event registration to handle browser
// potentially restoring previous scroll position
setTimeout(this.attachEvent.bind(this), 100);
this.attachEvent();
return this;
},
@ -153,7 +177,10 @@
this.initialised = false;
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) {
this.lastKnownScrollY = this.getScrollY();
this.initialised = true;
this.scroller.addEventListener('scroll', this.debouncer, false);
addEventListenerWithOptions(this.scroller, 'scroll', this.debouncer, {
capture: false,
passive: true
});
this.debouncer.handleEvent();
}
@ -295,10 +325,14 @@
* @return {bool} true if out of bounds, false otherwise
*/
isOutOfBounds: function (currentScrollY) {
var pastTop = currentScrollY < 0,
pastBottom = currentScrollY + this.getViewportHeight() > this.getScrollerHeight();
var pastTop = currentScrollY < 0;
return pastTop || pastBottom;
if (pastTop) {
return true;
}
var pastBottom = currentScrollY + this.getViewportHeight() > this.getScrollerHeight();
return pastBottom;
},
/**