2020-08-14 08:46:34 +02:00
|
|
|
import globalize from '../../scripts/globalize';
|
2020-08-16 20:24:45 +02:00
|
|
|
import { appHost } from '../apphost';
|
2020-08-14 08:46:34 +02:00
|
|
|
import appSettings from '../../scripts/settings/appSettings';
|
|
|
|
import focusManager from '../focusManager';
|
|
|
|
import layoutManager from '../layoutManager';
|
|
|
|
import loading from '../loading/loading';
|
|
|
|
import subtitleAppearanceHelper from './subtitleappearancehelper';
|
|
|
|
import settingsHelper from '../settingshelper';
|
|
|
|
import dom from '../../scripts/dom';
|
2020-10-17 19:08:56 +01:00
|
|
|
import { Events } from 'jellyfin-apiclient';
|
2020-08-14 08:46:34 +02:00
|
|
|
import '../listview/listview.css';
|
|
|
|
import '../../elements/emby-select/emby-select';
|
|
|
|
import '../../elements/emby-slider/emby-slider';
|
|
|
|
import '../../elements/emby-input/emby-input';
|
|
|
|
import '../../elements/emby-checkbox/emby-checkbox';
|
|
|
|
import '../../assets/css/flexstyles.css';
|
|
|
|
import './subtitlesettings.css';
|
2020-10-17 19:08:56 +01:00
|
|
|
import ServerConnections from '../ServerConnections';
|
2020-10-18 15:18:15 +01:00
|
|
|
import toast from '../toast/toast';
|
2020-05-03 20:30:35 +02:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
/**
|
2020-06-28 16:36:00 +09:00
|
|
|
* Subtitle settings.
|
2020-05-04 03:20:38 +02:00
|
|
|
* @module components/subtitleSettings/subtitleSettings
|
|
|
|
*/
|
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
function getSubtitleAppearanceObject(context) {
|
2020-07-17 10:33:31 +02:00
|
|
|
const appearanceSettings = {};
|
2020-05-03 20:30:35 +02:00
|
|
|
|
|
|
|
appearanceSettings.textSize = context.querySelector('#selectTextSize').value;
|
|
|
|
appearanceSettings.dropShadow = context.querySelector('#selectDropShadow').value;
|
|
|
|
appearanceSettings.font = context.querySelector('#selectFont').value;
|
|
|
|
appearanceSettings.textBackground = context.querySelector('#inputTextBackground').value;
|
|
|
|
appearanceSettings.textColor = context.querySelector('#inputTextColor').value;
|
2020-07-26 13:35:17 +03:00
|
|
|
appearanceSettings.verticalPosition = context.querySelector('#sliderVerticalPosition').value;
|
2020-05-03 20:30:35 +02:00
|
|
|
|
|
|
|
return appearanceSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadForm(context, user, userSettings, appearanceSettings, apiClient) {
|
|
|
|
apiClient.getCultures().then(function (allCultures) {
|
|
|
|
if (appHost.supports('subtitleburnsettings') && user.Policy.EnableVideoPlaybackTranscoding) {
|
|
|
|
context.querySelector('.fldBurnIn').classList.remove('hide');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-17 10:33:31 +02:00
|
|
|
const selectSubtitleLanguage = context.querySelector('#selectSubtitleLanguage');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
settingsHelper.populateLanguages(selectSubtitleLanguage, allCultures);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-09 15:37:07 +02:00
|
|
|
selectSubtitleLanguage.value = user.Configuration.SubtitleLanguagePreference || '';
|
|
|
|
context.querySelector('#selectSubtitlePlaybackMode').value = user.Configuration.SubtitleMode || '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
context.querySelector('#selectSubtitlePlaybackMode').dispatchEvent(new CustomEvent('change', {}));
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
context.querySelector('#selectTextSize').value = appearanceSettings.textSize || '';
|
|
|
|
context.querySelector('#selectDropShadow').value = appearanceSettings.dropShadow || '';
|
|
|
|
context.querySelector('#inputTextBackground').value = appearanceSettings.textBackground || 'transparent';
|
|
|
|
context.querySelector('#inputTextColor').value = appearanceSettings.textColor || '#ffffff';
|
|
|
|
context.querySelector('#selectFont').value = appearanceSettings.font || '';
|
2020-07-26 13:35:17 +03:00
|
|
|
context.querySelector('#sliderVerticalPosition').value = appearanceSettings.verticalPosition;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
context.querySelector('#selectSubtitleBurnIn').value = appSettings.get('subtitleburnin') || '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
onAppearanceFieldChange({
|
|
|
|
target: context.querySelector('#selectTextSize')
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
function saveUser(context, user, userSettingsInstance, appearanceKey, apiClient) {
|
2020-06-28 16:36:00 +09:00
|
|
|
let appearanceSettings = userSettingsInstance.getSubtitleAppearanceSettings(appearanceKey);
|
2020-05-03 20:30:35 +02:00
|
|
|
appearanceSettings = Object.assign(appearanceSettings, getSubtitleAppearanceObject(context));
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
userSettingsInstance.setSubtitleAppearanceSettings(appearanceSettings, appearanceKey);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
user.Configuration.SubtitleLanguagePreference = context.querySelector('#selectSubtitleLanguage').value;
|
|
|
|
user.Configuration.SubtitleMode = context.querySelector('#selectSubtitlePlaybackMode').value;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
return apiClient.updateUserConfiguration(user.Id, user.Configuration);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
function save(instance, context, userId, userSettings, apiClient, enableSaveConfirmation) {
|
2020-05-03 20:30:35 +02:00
|
|
|
loading.show();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
appSettings.set('subtitleburnin', context.querySelector('#selectSubtitleBurnIn').value);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
apiClient.getUser(userId).then(function (user) {
|
|
|
|
saveUser(context, user, userSettings, instance.appearanceKey, apiClient).then(function () {
|
|
|
|
loading.hide();
|
|
|
|
if (enableSaveConfirmation) {
|
2020-10-18 15:18:15 +01:00
|
|
|
toast(globalize.translate('SettingsSaved'));
|
2020-05-03 20:30:35 +02:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-09-08 02:05:02 -04:00
|
|
|
Events.trigger(instance, 'saved');
|
2020-05-03 20:30:35 +02:00
|
|
|
}, function () {
|
|
|
|
loading.hide();
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-05-03 20:30:35 +02:00
|
|
|
});
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
function onSubtitleModeChange(e) {
|
2020-07-17 10:33:31 +02:00
|
|
|
const view = dom.parentWithClass(e.target, 'subtitlesettings');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-17 10:33:31 +02:00
|
|
|
const subtitlesHelp = view.querySelectorAll('.subtitlesHelp');
|
2020-05-03 20:30:35 +02:00
|
|
|
for (let i = 0, length = subtitlesHelp.length; i < length; i++) {
|
|
|
|
subtitlesHelp[i].classList.add('hide');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-05-03 20:30:35 +02:00
|
|
|
view.querySelector('.subtitles' + this.value + 'Help').classList.remove('hide');
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
function onAppearanceFieldChange(e) {
|
2020-07-17 10:33:31 +02:00
|
|
|
const view = dom.parentWithClass(e.target, 'subtitlesettings');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-17 10:33:31 +02:00
|
|
|
const appearanceSettings = getSubtitleAppearanceObject(view);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-17 10:33:31 +02:00
|
|
|
const elements = {
|
2020-06-28 16:36:00 +09:00
|
|
|
window: view.querySelector('.subtitleappearance-preview-window'),
|
2020-07-26 13:35:17 +03:00
|
|
|
text: view.querySelector('.subtitleappearance-preview-text'),
|
|
|
|
preview: true
|
2020-05-03 20:30:35 +02:00
|
|
|
};
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
subtitleAppearanceHelper.applyStyles(elements, appearanceSettings);
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
subtitleAppearanceHelper.applyStyles({
|
|
|
|
window: view.querySelector('.subtitleappearance-fullpreview-window'),
|
|
|
|
text: view.querySelector('.subtitleappearance-fullpreview-text')
|
|
|
|
}, appearanceSettings);
|
|
|
|
}
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
const subtitlePreviewDelay = 1000;
|
|
|
|
let subtitlePreviewTimer;
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
function showSubtitlePreview(persistent) {
|
|
|
|
clearTimeout(subtitlePreviewTimer);
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
this._fullPreview.classList.remove('subtitleappearance-fullpreview-hide');
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
if (persistent) {
|
|
|
|
this._refFullPreview++;
|
|
|
|
}
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
if (this._refFullPreview === 0) {
|
|
|
|
subtitlePreviewTimer = setTimeout(hideSubtitlePreview.bind(this), subtitlePreviewDelay);
|
2020-07-07 01:06:47 +03:00
|
|
|
}
|
2020-07-26 13:35:17 +03:00
|
|
|
}
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
function hideSubtitlePreview(persistent) {
|
|
|
|
clearTimeout(subtitlePreviewTimer);
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
if (persistent) {
|
|
|
|
this._refFullPreview--;
|
|
|
|
}
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
if (this._refFullPreview === 0) {
|
|
|
|
this._fullPreview.classList.add('subtitleappearance-fullpreview-hide');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2020-05-03 20:30:35 +02:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
function embed(options, self) {
|
2020-08-14 08:46:34 +02:00
|
|
|
import('./subtitlesettings.template.html').then(({default: template}) => {
|
2020-05-03 20:30:35 +02:00
|
|
|
options.element.classList.add('subtitlesettings');
|
2020-07-18 09:21:15 +01:00
|
|
|
options.element.innerHTML = globalize.translateHtml(template, 'core');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-12 16:37:11 +03:00
|
|
|
options.element.querySelector('form').addEventListener('submit', self.onSubmit.bind(self));
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
options.element.querySelector('#selectSubtitlePlaybackMode').addEventListener('change', onSubtitleModeChange);
|
|
|
|
options.element.querySelector('#selectTextSize').addEventListener('change', onAppearanceFieldChange);
|
|
|
|
options.element.querySelector('#selectDropShadow').addEventListener('change', onAppearanceFieldChange);
|
|
|
|
options.element.querySelector('#selectFont').addEventListener('change', onAppearanceFieldChange);
|
|
|
|
options.element.querySelector('#inputTextColor').addEventListener('change', onAppearanceFieldChange);
|
|
|
|
options.element.querySelector('#inputTextBackground').addEventListener('change', onAppearanceFieldChange);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
if (options.enableSaveButton) {
|
|
|
|
options.element.querySelector('.btnSave').classList.remove('hide');
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-06 22:09:24 +02:00
|
|
|
if (appHost.supports('subtitleappearancesettings')) {
|
2020-05-03 20:30:35 +02:00
|
|
|
options.element.querySelector('.subtitleAppearanceSection').classList.remove('hide');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
self._fullPreview = options.element.querySelector('.subtitleappearance-fullpreview');
|
|
|
|
self._refFullPreview = 0;
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
const sliderVerticalPosition = options.element.querySelector('#sliderVerticalPosition');
|
|
|
|
sliderVerticalPosition.addEventListener('input', onAppearanceFieldChange);
|
|
|
|
sliderVerticalPosition.addEventListener('input', () => showSubtitlePreview.call(self));
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
const eventPrefix = window.PointerEvent ? 'pointer' : 'mouse';
|
|
|
|
sliderVerticalPosition.addEventListener(`${eventPrefix}enter`, () => showSubtitlePreview.call(self, true));
|
|
|
|
sliderVerticalPosition.addEventListener(`${eventPrefix}leave`, () => hideSubtitlePreview.call(self, true));
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
if (layoutManager.tv) {
|
|
|
|
sliderVerticalPosition.addEventListener('focus', () => showSubtitlePreview.call(self, true));
|
|
|
|
sliderVerticalPosition.addEventListener('blur', () => hideSubtitlePreview.call(self, true));
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
// Give CustomElements time to attach
|
|
|
|
setTimeout(() => {
|
|
|
|
sliderVerticalPosition.classList.add('focusable');
|
|
|
|
sliderVerticalPosition.enableKeyboardDragging();
|
|
|
|
}, 0);
|
|
|
|
}
|
2020-07-07 01:06:47 +03:00
|
|
|
|
2020-07-26 13:35:17 +03:00
|
|
|
options.element.querySelector('.chkPreview').addEventListener('change', (e) => {
|
|
|
|
if (e.target.checked) {
|
|
|
|
showSubtitlePreview.call(self, true);
|
|
|
|
} else {
|
|
|
|
hideSubtitlePreview.call(self, true);
|
2020-07-07 01:06:47 +03:00
|
|
|
}
|
2020-07-26 13:35:17 +03:00
|
|
|
});
|
2020-05-03 20:30:35 +02:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
self.loadData();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-03 20:30:35 +02:00
|
|
|
if (options.autoFocus) {
|
|
|
|
focusManager.autoFocus(options.element);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
export class SubtitleSettings {
|
|
|
|
constructor(options) {
|
|
|
|
this.options = options;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
embed(options, this);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
loadData() {
|
2020-07-17 10:33:31 +02:00
|
|
|
const self = this;
|
|
|
|
const context = self.options.element;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
loading.show();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-17 10:33:31 +02:00
|
|
|
const userId = self.options.userId;
|
2020-10-17 19:08:56 +01:00
|
|
|
const apiClient = ServerConnections.getApiClient(self.options.serverId);
|
2020-07-17 10:33:31 +02:00
|
|
|
const userSettings = self.options.userSettings;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
apiClient.getUser(userId).then(function (user) {
|
|
|
|
userSettings.setUserInfo(userId, apiClient).then(function () {
|
|
|
|
self.dataLoaded = true;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-17 10:33:31 +02:00
|
|
|
const appearanceSettings = userSettings.getSubtitleAppearanceSettings(self.options.appearanceKey);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
loadForm(context, user, userSettings, appearanceSettings, apiClient);
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-05-04 03:20:38 +02:00
|
|
|
}
|
2020-05-03 20:30:35 +02:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
submit() {
|
2020-06-28 16:36:00 +09:00
|
|
|
this.onSubmit(null);
|
2020-05-04 03:20:38 +02:00
|
|
|
}
|
2020-05-03 20:30:35 +02:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
destroy() {
|
|
|
|
this.options = null;
|
|
|
|
}
|
|
|
|
|
2020-06-28 16:36:00 +09:00
|
|
|
onSubmit(e) {
|
2020-05-04 03:20:38 +02:00
|
|
|
const self = this;
|
2020-10-17 19:08:56 +01:00
|
|
|
const apiClient = ServerConnections.getApiClient(self.options.serverId);
|
2020-07-17 10:33:31 +02:00
|
|
|
const userId = self.options.userId;
|
|
|
|
const userSettings = self.options.userSettings;
|
2020-05-04 03:20:38 +02:00
|
|
|
|
|
|
|
userSettings.setUserInfo(userId, apiClient).then(function () {
|
2020-07-17 10:33:31 +02:00
|
|
|
const enableSaveConfirmation = self.options.enableSaveConfirmation;
|
2020-05-04 03:20:38 +02:00
|
|
|
save(self, self.options.element, userId, userSettings, apiClient, enableSaveConfirmation);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Disable default form submission
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 20:30:35 +02:00
|
|
|
|
2020-05-04 03:20:38 +02:00
|
|
|
export default SubtitleSettings;
|