2019-01-23 11:33:34 +00:00
|
|
|
define(['scroller', 'dom', 'layoutManager', 'inputManager', 'focusManager', 'browser', 'registerElement'], function (scroller, dom, layoutManager, inputManager, focusManager, browser) {
|
2019-01-10 15:39:37 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var ScrollerProtoType = Object.create(HTMLDivElement.prototype);
|
|
|
|
|
|
|
|
ScrollerProtoType.createdCallback = function () {
|
|
|
|
this.classList.add('emby-scroller');
|
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function initCenterFocus(elem, scrollerInstance) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
dom.addEventListener(elem, 'focus', function (e) {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var focused = focusManager.focusableParent(e.target);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (focused) {
|
|
|
|
scrollerInstance.toCenter(focused);
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
}, {
|
2019-01-10 15:39:37 +03:00
|
|
|
capture: true,
|
|
|
|
passive: true
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
ScrollerProtoType.scrollToBeginning = function () {
|
|
|
|
if (this.scroller) {
|
|
|
|
this.scroller.slideTo(0, true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
ScrollerProtoType.toStart = function (elem, immediate) {
|
|
|
|
if (this.scroller) {
|
|
|
|
this.scroller.toStart(elem, immediate);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
ScrollerProtoType.toCenter = function (elem, immediate) {
|
|
|
|
if (this.scroller) {
|
|
|
|
this.scroller.toCenter(elem, immediate);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.scrollToPosition = function (pos, immediate) {
|
|
|
|
if (this.scroller) {
|
|
|
|
this.scroller.slideTo(pos, immediate);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.getScrollPosition = function () {
|
|
|
|
if (this.scroller) {
|
|
|
|
return this.scroller.getScrollPosition();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.getScrollSize = function () {
|
|
|
|
if (this.scroller) {
|
|
|
|
return this.scroller.getScrollSize();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.getScrollEventName = function () {
|
|
|
|
if (this.scroller) {
|
|
|
|
return this.scroller.getScrollEventName();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.getScrollSlider = function () {
|
|
|
|
if (this.scroller) {
|
|
|
|
return this.scroller.getScrollSlider();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.addScrollEventListener = function (fn, options) {
|
|
|
|
if (this.scroller) {
|
|
|
|
dom.addEventListener(this.scroller.getScrollFrame(), this.scroller.getScrollEventName(), fn, options);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.removeScrollEventListener = function (fn, options) {
|
|
|
|
if (this.scroller) {
|
|
|
|
dom.removeEventListener(this.scroller.getScrollFrame(), this.scroller.getScrollEventName(), fn, options);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function onInputCommand(e) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var cmd = e.detail.command;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (cmd === 'end') {
|
|
|
|
focusManager.focusLast(this, '.' + this.getAttribute('data-navcommands'));
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
else if (cmd === 'pageup') {
|
|
|
|
focusManager.moveFocus(e.target, this, '.' + this.getAttribute('data-navcommands'), -12);
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
else if (cmd === 'pagedown') {
|
|
|
|
focusManager.moveFocus(e.target, this, '.' + this.getAttribute('data-navcommands'), 12);
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function initHeadroom(elem) {
|
2019-01-10 15:39:37 +03:00
|
|
|
require(['headroom'], function (Headroom) {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var headroom = new Headroom([], {
|
|
|
|
scroller: elem
|
|
|
|
});
|
2019-02-27 23:26:28 +00:00
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
headroom.add(document.querySelector('.skinHeader'));
|
|
|
|
elem.headroom = headroom;
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2019-01-10 15:39:37 +03:00
|
|
|
ScrollerProtoType.attachedCallback = function () {
|
|
|
|
|
|
|
|
if (this.getAttribute('data-navcommands')) {
|
|
|
|
inputManager.on(this, onInputCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
var horizontal = this.getAttribute('data-horizontal') !== 'false';
|
|
|
|
|
|
|
|
var slider = this.querySelector('.scrollSlider');
|
|
|
|
|
|
|
|
if (horizontal) {
|
|
|
|
slider.style['white-space'] = 'nowrap';
|
|
|
|
}
|
|
|
|
|
|
|
|
var bindHeader = this.getAttribute('data-bindheader') === 'true';
|
|
|
|
|
|
|
|
var scrollFrame = this;
|
|
|
|
var enableScrollButtons = layoutManager.desktop && horizontal && this.getAttribute('data-scrollbuttons') !== 'false';
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
horizontal: horizontal,
|
|
|
|
mouseDragging: 1,
|
|
|
|
mouseWheel: this.getAttribute('data-mousewheel') !== 'false',
|
|
|
|
touchDragging: 1,
|
|
|
|
slidee: slider,
|
|
|
|
scrollBy: 200,
|
|
|
|
speed: horizontal ? 270 : 240,
|
|
|
|
//immediateSpeed: pageOptions.immediateSpeed,
|
|
|
|
elasticBounds: 1,
|
|
|
|
dragHandle: 1,
|
|
|
|
scrollWidth: this.getAttribute('data-scrollsize') === 'auto' ? null : 5000000,
|
|
|
|
autoImmediate: true,
|
|
|
|
skipSlideToWhenVisible: this.getAttribute('data-skipfocuswhenvisible') === 'true',
|
|
|
|
dispatchScrollEvent: enableScrollButtons || bindHeader || this.getAttribute('data-scrollevent') === 'true',
|
|
|
|
hideScrollbar: enableScrollButtons || this.getAttribute('data-hidescrollbar') === 'true',
|
|
|
|
allowNativeSmoothScroll: this.getAttribute('data-allownativesmoothscroll') === 'true' && !enableScrollButtons,
|
|
|
|
allowNativeScroll: !enableScrollButtons,
|
|
|
|
forceHideScrollbars: enableScrollButtons,
|
|
|
|
|
|
|
|
// In edge, with the native scroll, the content jumps around when hovering over the buttons
|
|
|
|
requireAnimation: enableScrollButtons && browser.edge
|
|
|
|
};
|
|
|
|
|
|
|
|
// If just inserted it might not have any height yet - yes this is a hack
|
|
|
|
this.scroller = new scroller(scrollFrame, options);
|
|
|
|
this.scroller.init();
|
|
|
|
|
|
|
|
if (layoutManager.tv && this.getAttribute('data-centerfocus')) {
|
|
|
|
initCenterFocus(this, this.scroller);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bindHeader) {
|
|
|
|
initHeadroom(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enableScrollButtons) {
|
|
|
|
loadScrollButtons(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function loadScrollButtons(scroller) {
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
require(['emby-scrollbuttons'], function () {
|
|
|
|
scroller.insertAdjacentHTML('beforeend', '<div is="emby-scrollbuttons"></div>');
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
ScrollerProtoType.pause = function () {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var headroom = this.headroom;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (headroom) {
|
|
|
|
headroom.pause();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.resume = function () {
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var headroom = this.headroom;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (headroom) {
|
|
|
|
headroom.resume();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ScrollerProtoType.detachedCallback = function () {
|
|
|
|
|
|
|
|
if (this.getAttribute('data-navcommands')) {
|
|
|
|
inputManager.off(this, onInputCommand);
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var headroom = this.headroom;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (headroom) {
|
|
|
|
headroom.destroy();
|
|
|
|
this.headroom = null;
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var scrollerInstance = this.scroller;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (scrollerInstance) {
|
|
|
|
scrollerInstance.destroy();
|
|
|
|
this.scroller = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
document.registerElement('emby-scroller', {
|
2018-10-23 01:05:09 +03:00
|
|
|
prototype: ScrollerProtoType,
|
2019-01-10 15:39:37 +03:00
|
|
|
extends: 'div'
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|