tweb/src/components/sidebarLeft/index.ts

655 lines
21 KiB
TypeScript
Raw Normal View History

2021-04-08 15:52:31 +02:00
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
import { formatNumber } from "../../helpers/number";
import appImManager from "../../lib/appManagers/appImManager";
2021-04-28 21:43:25 +02:00
import appStateManager from "../../lib/appManagers/appStateManager";
import appUsersManager from "../../lib/appManagers/appUsersManager";
2020-11-15 04:33:47 +01:00
import rootScope from "../../lib/rootScope";
2021-01-01 20:44:31 +01:00
import { SearchGroup } from "../appSearch";
import "../avatar";
2020-12-25 13:53:20 +01:00
import Scrollable, { ScrollableX } from "../scrollable";
import InputSearch from "../inputSearch";
import SidebarSlider from "../slider";
import { TransitionSlider } from "../transition";
import AppNewGroupTab from "./tabs/newGroup";
import appMessagesManager from "../../lib/appManagers/appMessagesManager";
2020-12-25 13:53:20 +01:00
import AppSearchSuper from "../appSearchSuper.";
2020-12-25 18:38:32 +01:00
import { DateData, fillTipDates } from "../../helpers/date";
2021-02-13 16:32:10 +01:00
import { MOUNT_CLASS_TO } from "../../config/debug";
2021-02-20 18:10:26 +01:00
import AppSettingsTab from "./tabs/settings";
import AppNewChannelTab from "./tabs/newChannel";
import AppContactsTab from "./tabs/contacts";
import AppArchivedTab from "./tabs/archivedTab";
import AppAddMembersTab from "./tabs/addMembers";
2021-03-21 10:59:59 +01:00
import { i18n_, LangPackKey } from "../../lib/langPack";
2021-04-28 21:43:25 +02:00
import { ButtonMenuItemOptions } from "../buttonMenu";
import CheckboxField from "../checkboxField";
import { IS_MOBILE_SAFARI } from "../../environment/userAgent";
import appNavigationController from "../appNavigationController";
2021-04-04 17:39:17 +02:00
import findUpClassName from "../../helpers/dom/findUpClassName";
import findUpTag from "../../helpers/dom/findUpTag";
import PeerTitle from "../peerTitle";
2021-04-13 20:48:46 +02:00
import App from "../../config/app";
import ButtonMenuToggle from "../buttonMenuToggle";
import replaceContent from "../../helpers/dom/replaceContent";
import sessionStorage from "../../lib/sessionStorage";
import { CLICK_EVENT_NAME } from "../../helpers/dom/clickEvent";
import { closeBtnMenu } from "../misc";
2021-10-21 15:16:43 +02:00
import { indexOfAndSplice } from "../../helpers/array";
export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown';
export class AppSidebarLeft extends SidebarSlider {
private toolsBtn: HTMLButtonElement;
private backBtn: HTMLButtonElement;
//private searchInput = document.getElementById('global-search') as HTMLInputElement;
private inputSearch: InputSearch;
2020-02-08 12:58:22 +01:00
public archivedCount: HTMLSpanElement;
private newBtnMenu: HTMLElement;
//private log = logger('SL');
private searchGroups: {[k in 'contacts' | 'globalContacts' | 'messages' | 'people' | 'recent']: SearchGroup} = {} as any;
private searchSuper: AppSearchSuper;
2020-06-20 03:11:24 +02:00
2020-02-06 16:43:07 +01:00
constructor() {
2021-02-16 16:36:26 +01:00
super({
sidebarEl: document.getElementById('column-left') as HTMLDivElement,
navigationType: 'left'
});
//this._selectTab(0); // make first tab as default
this.inputSearch = new InputSearch('Search');
2020-11-15 04:33:47 +01:00
const sidebarHeader = this.sidebarEl.querySelector('.item-main .sidebar-header');
sidebarHeader.append(this.inputSearch.container);
2021-03-21 15:36:14 +01:00
const onNewGroupClick = () => {
new AppAddMembersTab(this).open({
type: 'chat',
skippable: false,
takeOut: (peerIds) => {
new AppNewGroupTab(this).open(peerIds);
},
2021-03-25 19:07:00 +01:00
title: 'GroupAddMembers',
placeholder: 'SendMessageTo'
2021-03-21 15:36:14 +01:00
});
};
const onContactsClick = () => {
new AppContactsTab(this).open();
};
//this.toolsBtn = this.sidebarEl.querySelector('.sidebar-tools-button') as HTMLButtonElement;
this.backBtn = this.sidebarEl.querySelector('.sidebar-back-button') as HTMLButtonElement;
const btnArchive: ButtonMenuItemOptions & {verify?: () => boolean} = {
2021-03-21 15:36:14 +01:00
icon: 'archive',
text: 'ArchivedChats',
2021-03-21 15:36:14 +01:00
onClick: () => {
new AppArchivedTab(this).open();
},
verify: () => {
2021-10-21 15:16:43 +02:00
const folder = appMessagesManager.dialogsStorage.getFolderDialogs(1, false);
return !!folder.length || !appMessagesManager.dialogsStorage.isDialogsLoaded(1);
2021-03-21 15:36:14 +01:00
}
};
2021-04-19 12:36:14 +02:00
const themeCheckboxField = new CheckboxField({
toggle: true,
checked: rootScope.getTheme().name === 'night'
2021-04-19 12:36:14 +02:00
});
themeCheckboxField.input.addEventListener('change', () => {
rootScope.settings.theme = themeCheckboxField.input.checked ? 'night' : 'day';
appStateManager.pushToState('settings', rootScope.settings);
appImManager.applyCurrentTheme();
});
2021-06-11 14:52:53 +02:00
rootScope.addEventListener('theme_change', () => {
themeCheckboxField.setValueSilently(rootScope.getTheme().name === 'night');
});
const menuButtons: (ButtonMenuItemOptions & {verify?: () => boolean})[] = [{
icon: 'saved',
text: 'SavedMessages',
2021-03-21 15:36:14 +01:00
onClick: () => {
setTimeout(() => { // menu doesn't close if no timeout (lol)
appImManager.setPeer(appImManager.myId);
}, 0);
}
}, btnArchive, {
icon: 'user',
text: 'Contacts',
onClick: onContactsClick
2021-03-21 15:36:14 +01:00
}, {
icon: 'settings',
text: 'Settings',
onClick: () => {
new AppSettingsTab(this).open();
}
}, {
icon: 'darkmode',
text: 'DarkMode',
onClick: () => {
},
2021-04-19 12:36:14 +02:00
checkboxField: themeCheckboxField
}, {
icon: 'animations',
text: 'Animations',
onClick: () => {
},
2021-04-02 23:45:51 +02:00
checkboxField: new CheckboxField({
toggle: true,
checked: true,
stateKey: 'settings.animationsEnabled',
})
}, {
icon: 'help',
2021-04-13 20:48:46 +02:00
text: 'TelegramFeatures',
2021-03-21 15:36:14 +01:00
onClick: () => {
appImManager.openUsername('TelegramTips');
2021-03-21 15:36:14 +01:00
}
2021-04-13 20:48:46 +02:00
}, {
icon: 'bug',
2021-04-13 20:48:46 +02:00
text: 'ReportBug',
onClick: () => {
const a = document.createElement('a');
a.target = '_blank';
a.href = 'https://bugs.telegram.org/?tag_ids=40&sort=time';
document.body.append(a);
a.click();
setTimeout(() => {
a.remove();
}, 0);
}
}, {
icon: 'char z',
text: 'ChatList.Menu.SwitchTo.Z',
onClick: () => {
2021-10-21 15:16:43 +02:00
Promise.all([
sessionStorage.set({kz_version: 'Z'}),
sessionStorage.delete('tgme_sync')
]).then(() => {
location.href = 'https://web.telegram.org/z/';
});
},
2021-06-11 14:15:28 +02:00
verify: () => App.isMainDomain
}, {
icon: 'char w',
text: 'ChatList.Menu.SwitchTo.Webogram',
onClick: () => {
2021-10-21 15:16:43 +02:00
sessionStorage.delete('tgme_sync').then(() => {
location.href = 'https://web.telegram.org/?legacy=1';
});
},
2021-06-11 14:15:28 +02:00
verify: () => App.isMainDomain
}];
this.toolsBtn = ButtonMenuToggle({}, 'bottom-right', menuButtons, (e) => {
menuButtons.forEach(button => {
if(button.verify) {
button.element.classList.toggle('hide', !button.verify());
}
});
});
this.toolsBtn.classList.remove('tgico-more');
this.toolsBtn.classList.add('sidebar-tools-button', 'is-visible');
this.backBtn.parentElement.insertBefore(this.toolsBtn, this.backBtn);
const btnMenu = this.toolsBtn.querySelector('.btn-menu') as HTMLElement;
2021-03-21 15:36:14 +01:00
const btnMenuFooter = document.createElement('a');
btnMenuFooter.href = 'https://github.com/morethanwords/tweb/blob/master/CHANGELOG.md';
btnMenuFooter.target = '_blank';
btnMenuFooter.rel = 'noopener noreferrer';
2021-04-13 20:48:46 +02:00
btnMenuFooter.classList.add('btn-menu-footer');
btnMenuFooter.addEventListener(CLICK_EVENT_NAME, (e) => {
e.stopPropagation();
closeBtnMenu();
});
2021-04-13 20:48:46 +02:00
const t = document.createElement('span');
t.classList.add('btn-menu-footer-text');
t.innerHTML = 'Telegram Web' + App.suffix + ' alpha ' + App.versionFull;
2021-04-13 20:48:46 +02:00
btnMenuFooter.append(t);
btnMenu.classList.add('has-footer');
btnMenu.append(btnMenuFooter);
this.newBtnMenu = ButtonMenuToggle({}, 'top-left', [{
2021-03-25 19:07:00 +01:00
icon: 'newchannel',
text: 'NewChannel',
onClick: () => {
new AppNewChannelTab(this).open();
}
}, {
icon: 'newgroup',
text: 'NewGroup',
onClick: onNewGroupClick
}, {
icon: 'newprivate',
text: 'NewPrivateChat',
onClick: onContactsClick
}]);
2021-05-03 21:17:50 +02:00
this.newBtnMenu.className = 'btn-circle rp btn-corner z-depth-1 btn-menu-toggle animated-button-icon';
this.newBtnMenu.insertAdjacentHTML('afterbegin', `
<span class="tgico tgico-newchat_filled"></span>
<span class="tgico tgico-close"></span>
`);
this.newBtnMenu.id = 'new-menu';
sidebarHeader.nextElementSibling.append(this.newBtnMenu);
2021-03-25 19:07:00 +01:00
2020-12-25 13:53:20 +01:00
this.inputSearch.input.addEventListener('focus', () => this.initSearch(), {once: true});
2021-03-25 19:07:00 +01:00
//parseMenuButtonsTo(this.newButtons, this.newBtnMenu.firstElementChild.children);
2021-03-21 15:36:14 +01:00
this.archivedCount = document.createElement('span');
this.archivedCount.className = 'archived-count badge badge-24 badge-gray';
2021-03-21 15:36:14 +01:00
btnArchive.element.append(this.archivedCount);
2021-10-21 15:16:43 +02:00
rootScope.addEventListener('folder_unread', (folder) => {
if(folder.id === 1) {
// const count = folder.unreadMessagesCount;
const count = folder.unreadDialogsCount;
this.archivedCount.innerText = '' + formatNumber(count, 1);
this.archivedCount.classList.toggle('hide', !count);
}
});
appUsersManager.getTopPeers('correspondents');
2021-04-28 21:43:25 +02:00
appStateManager.getState().then(state => {
const recentSearch = state.recentSearch || [];
for(let i = 0, length = recentSearch.length; i < length; ++i) {
appStateManager.requestPeer(recentSearch[i], 'recentSearch');
}
});
2020-06-20 03:11:24 +02:00
}
2020-12-25 13:53:20 +01:00
private initSearch() {
const searchContainer = this.sidebarEl.querySelector('#search-container') as HTMLDivElement;
const scrollable = new Scrollable(searchContainer);
2021-01-26 01:40:53 +01:00
const close = () => {
2021-02-04 00:00:15 +01:00
//setTimeout(() => {
this.backBtn.click();
//}, 0);
2021-01-26 01:40:53 +01:00
};
2020-12-25 13:53:20 +01:00
this.searchGroups = {
contacts: new SearchGroup('Search.Chats', 'contacts', undefined, undefined, undefined, undefined, close),
globalContacts: new SearchGroup('Search.Global', 'contacts', undefined, undefined, undefined, undefined, close),
messages: new SearchGroup('Search.Messages', 'messages'),
people: new SearchGroup(false, 'contacts', true, 'search-group-people', true, false, close),
2021-01-26 01:40:53 +01:00
recent: new SearchGroup('Recent', 'contacts', true, 'search-group-recent', true, true, close)
2020-12-25 13:53:20 +01:00
};
const searchSuper = this.searchSuper = new AppSearchSuper({
mediaTabs: [{
inputFilter: 'inputMessagesFilterEmpty',
name: 'FilterChats',
type: 'chats'
}, {
inputFilter: 'inputMessagesFilterPhotoVideo',
name: 'SharedMediaTab2',
type: 'media'
}, {
inputFilter: 'inputMessagesFilterUrl',
name: 'SharedLinksTab2',
type: 'links'
}, {
inputFilter: 'inputMessagesFilterDocument',
name: 'SharedFilesTab2',
type: 'files'
}, {
inputFilter: 'inputMessagesFilterMusic',
name: 'SharedMusicTab2',
type: 'music'
}, {
inputFilter: 'inputMessagesFilterRoundVoice',
name: 'SharedVoiceTab2',
type: 'voice'
}],
scrollable,
searchGroups: this.searchGroups,
asChatList: true,
hideEmptyTabs: false,
showSender: true
});
2020-12-25 13:53:20 +01:00
searchContainer.prepend(searchSuper.nav.parentElement.parentElement);
2020-12-25 13:53:20 +01:00
scrollable.container.append(searchSuper.container);
2020-12-25 18:38:32 +01:00
const resetSearch = () => {
searchSuper.setQuery({
2021-10-21 15:16:43 +02:00
peerId: ''.toPeerId(),
2020-12-25 18:38:32 +01:00
folderId: 0
});
searchSuper.selectTab(0);
searchSuper.load(true);
};
resetSearch();
let pickedElements: HTMLElement[] = [];
2021-10-21 15:16:43 +02:00
let selectedPeerId: PeerId = ''.toPeerId();
2020-12-25 18:38:32 +01:00
let selectedMinDate = 0;
let selectedMaxDate = 0;
const updatePicked = () => {
//(this.inputSearch.input as HTMLInputElement).placeholder = pickedElements.length ? 'Search' : 'Telegram Search';
2020-12-25 18:38:32 +01:00
this.inputSearch.container.classList.toggle('is-picked-twice', pickedElements.length === 2);
this.inputSearch.container.classList.toggle('is-picked', !!pickedElements.length);
if(pickedElements.length) {
this.inputSearch.input.style.setProperty('--paddingLeft', (pickedElements[pickedElements.length - 1].getBoundingClientRect().right - this.inputSearch.input.getBoundingClientRect().left) + 'px');
} else {
this.inputSearch.input.style.removeProperty('--paddingLeft');
}
};
const helper = document.createElement('div');
helper.classList.add('search-helper');
helper.addEventListener('click', (e) => {
const target = findUpClassName(e.target, 'selector-user');
if(!target) {
return;
}
const key = target.dataset.key;
if(key.indexOf('date_') === 0) {
const [_, minDate, maxDate] = key.split('_');
selectedMinDate = +minDate;
selectedMaxDate = +maxDate;
} else {
2021-10-21 15:16:43 +02:00
selectedPeerId = key.toPeerId();
2020-12-25 18:38:32 +01:00
}
target.addEventListener('click', () => {
unselectEntity(target);
});
this.inputSearch.container.append(target);
this.inputSearch.onChange(this.inputSearch.value = '');
pickedElements.push(target);
updatePicked();
2020-12-25 13:53:20 +01:00
});
2020-12-25 18:38:32 +01:00
searchSuper.nav.parentElement.append(helper);
2021-10-21 15:16:43 +02:00
const renderEntity = (key: PeerId | string, title?: string | HTMLElement) => {
2020-12-25 18:38:32 +01:00
const div = document.createElement('div');
div.classList.add('selector-user'/* , 'scale-in' */);
const avatarEl = document.createElement('avatar-element');
avatarEl.classList.add('selector-user-avatar', 'tgico');
avatarEl.setAttribute('dialog', '1');
avatarEl.classList.add('avatar-30');
2021-10-21 15:16:43 +02:00
div.dataset.key = '' + key;
if(key.isPeerId()) {
2020-12-25 18:38:32 +01:00
if(title === undefined) {
2021-10-21 15:16:43 +02:00
title = new PeerTitle({peerId: key.toPeerId()}).element;
2020-12-25 18:38:32 +01:00
}
2021-10-21 15:16:43 +02:00
avatarEl.setAttribute('peer', '' + key);
2020-12-25 18:38:32 +01:00
} else {
avatarEl.classList.add('tgico-calendarfilter');
}
if(title) {
if(typeof(title) === 'string') {
div.innerHTML = title;
} else {
replaceContent(div, title);
div.append(title);
}
2020-12-25 18:38:32 +01:00
}
div.insertAdjacentElement('afterbegin', avatarEl);
return div;
};
const unselectEntity = (target: HTMLElement) => {
const key = target.dataset.key;
if(key.indexOf('date_') === 0) {
selectedMinDate = selectedMaxDate = 0;
} else {
2021-10-21 15:16:43 +02:00
selectedPeerId = ''.toPeerId();
2020-12-25 18:38:32 +01:00
}
target.remove();
2021-10-21 15:16:43 +02:00
indexOfAndSplice(pickedElements, target);
2020-12-25 18:38:32 +01:00
setTimeout(() => {
updatePicked();
this.inputSearch.onChange(this.inputSearch.value);
}, 0);
};
this.inputSearch.onClear = () => {
pickedElements.forEach(el => {
unselectEntity(el);
});
};
2020-12-25 13:53:20 +01:00
this.inputSearch.onChange = (value) => {
searchSuper.cleanupHTML();
searchSuper.setQuery({
2020-12-25 18:38:32 +01:00
peerId: selectedPeerId,
folderId: selectedPeerId ? undefined : 0,
query: value,
minDate: selectedMinDate,
maxDate: selectedMaxDate
2020-12-25 13:53:20 +01:00
});
searchSuper.load(true);
2020-12-25 18:38:32 +01:00
helper.innerHTML = '';
searchSuper.nav.classList.remove('hide');
if(!value) {
}
if(!selectedPeerId && value.trim()) {
const middleware = searchSuper.middleware.get();
2020-12-25 18:38:32 +01:00
Promise.all([
2021-10-21 15:16:43 +02:00
// appMessagesManager.getConversationsAll(value).then(dialogs => dialogs.map(d => d.peerId)),
appMessagesManager.getConversations(value).promise.then(({dialogs}) => dialogs.map(d => d.peerId)),
appUsersManager.getContactsPeerIds(value, true)
2020-12-25 18:38:32 +01:00
]).then(results => {
if(!middleware()) return;
const peerIds = new Set(results[0].concat(results[1]));
peerIds.forEach(peerId => {
helper.append(renderEntity(peerId));
});
searchSuper.nav.classList.toggle('hide', !!helper.innerHTML);
//console.log('got peerIds by value:', value, [...peerIds]);
});
}
if(!selectedMinDate && value.trim()) {
const dates: DateData[] = [];
fillTipDates(value, dates);
dates.forEach(dateData => {
helper.append(renderEntity('date_' + dateData.minDate + '_' + dateData.maxDate, dateData.title));
});
searchSuper.nav.classList.toggle('hide', !!helper.innerHTML);
}
2020-12-25 13:53:20 +01:00
};
2021-02-04 00:00:15 +01:00
searchSuper.tabs.inputMessagesFilterEmpty.addEventListener('mousedown', (e) => {
2020-12-25 13:53:20 +01:00
const target = findUpTag(e.target, 'LI') as HTMLElement;
if(!target) {
2020-11-07 01:58:57 +01:00
return;
}
2020-12-25 13:53:20 +01:00
const searchGroup = findUpClassName(target, 'search-group');
if(!searchGroup || searchGroup.classList.contains('search-group-recent') || searchGroup.classList.contains('search-group-people')) {
return;
}
2020-06-20 03:11:24 +02:00
2021-10-21 15:16:43 +02:00
const peerId = target.getAttribute('data-peer-id').toPeerId();
2020-12-25 13:53:20 +01:00
appStateManager.getState().then(state => {
const recentSearch = state.recentSearch || [];
2021-02-04 01:30:23 +01:00
if(recentSearch[0] !== peerId) {
2021-10-21 15:16:43 +02:00
indexOfAndSplice(recentSearch, peerId);
2020-12-25 13:53:20 +01:00
recentSearch.unshift(peerId);
if(recentSearch.length > 20) {
recentSearch.length = 20;
}
appStateManager.pushToState('recentSearch', recentSearch);
for(const peerId of recentSearch) {
2021-04-27 17:45:53 +02:00
appStateManager.requestPeer(peerId, 'recentSearch');
2020-12-25 13:53:20 +01:00
}
}
});
2020-12-25 13:53:20 +01:00
}, {capture: true});
let peopleContainer = document.createElement('div');
peopleContainer.classList.add('search-group-scrollable');
peopleContainer.append(this.searchGroups.people.list);
this.searchGroups.people.container.append(peopleContainer);
let peopleScrollable = new ScrollableX(peopleContainer);
let first = true;
2020-12-25 13:53:20 +01:00
let hideNewBtnMenuTimeout: number;
//const transition = Transition.bind(null, searchContainer.parentElement, 150);
const transition = TransitionSlider(searchContainer.parentElement, 'zoom-fade', 150, (id) => {
if(hideNewBtnMenuTimeout) clearTimeout(hideNewBtnMenuTimeout);
if(id === 0 && !first) {
searchSuper.selectTab(0, false);
2020-12-25 13:53:20 +01:00
this.inputSearch.onClearClick();
hideNewBtnMenuTimeout = window.setTimeout(() => {
hideNewBtnMenuTimeout = 0;
this.newBtnMenu.classList.remove('is-hidden');
}, 150);
2020-06-21 14:25:17 +02:00
}
first = false;
});
2020-12-25 13:53:20 +01:00
transition(0);
const activeClassName = 'is-visible';
2020-12-25 13:53:20 +01:00
const onFocus = () => {
this.toolsBtn.classList.remove(activeClassName);
this.backBtn.classList.add(activeClassName);
2020-12-25 13:53:20 +01:00
this.newBtnMenu.classList.add('is-hidden');
this.toolsBtn.parentElement.firstElementChild.classList.toggle('state-back', true);
2020-12-25 13:53:20 +01:00
if(!IS_MOBILE_SAFARI && !appNavigationController.findItemByType('global-search')) {
appNavigationController.pushItem({
onPop: () => {
close();
},
type: 'global-search'
});
}
2020-12-25 13:53:20 +01:00
transition(1);
};
this.inputSearch.input.addEventListener('focus', onFocus);
onFocus();
this.backBtn.addEventListener('click', (e) => {
this.toolsBtn.classList.add(activeClassName);
this.backBtn.classList.remove(activeClassName);
this.toolsBtn.parentElement.firstElementChild.classList.toggle('state-back', false);
2020-12-25 13:53:20 +01:00
appNavigationController.removeByType('global-search');
2020-12-25 13:53:20 +01:00
transition(0);
});
const clearRecentSearchBtn = document.createElement('button');
clearRecentSearchBtn.classList.add('btn-icon', 'tgico-close');
this.searchGroups.recent.nameEl.append(clearRecentSearchBtn);
clearRecentSearchBtn.addEventListener('click', () => {
this.searchGroups.recent.clear();
appStateManager.pushToState('recentSearch', []);
});
}
2020-02-06 16:43:07 +01:00
}
2021-01-06 10:16:53 +01:00
export class SettingSection {
public container: HTMLElement;
public content: HTMLElement;
public title: HTMLElement;
public caption: HTMLElement;
2021-02-18 18:30:41 +01:00
constructor(options: {
2021-03-21 10:59:59 +01:00
name?: LangPackKey,
2021-03-23 17:13:35 +01:00
caption?: LangPackKey | true,
2021-07-20 18:11:58 +02:00
noDelimiter?: boolean,
fakeGradientDelimiter?: boolean
2021-02-18 18:30:41 +01:00
}) {
2021-01-06 10:16:53 +01:00
this.container = document.createElement('div');
this.container.classList.add('sidebar-left-section');
2021-07-20 18:11:58 +02:00
if(options.fakeGradientDelimiter) {
this.container.append(generateDelimiter());
this.container.classList.add('with-fake-delimiter');
} else if(!options.noDelimiter) {
2021-02-18 18:30:41 +01:00
const hr = document.createElement('hr');
this.container.append(hr);
2021-03-01 16:17:15 +01:00
} else {
this.container.classList.add('no-delimiter');
2021-02-18 18:30:41 +01:00
}
2021-01-06 10:16:53 +01:00
2021-02-18 18:30:41 +01:00
this.content = this.generateContentElement();
2021-01-06 10:16:53 +01:00
2021-02-18 18:30:41 +01:00
if(options.name) {
2021-01-06 10:16:53 +01:00
this.title = document.createElement('div');
this.title.classList.add('sidebar-left-h2', 'sidebar-left-section-name');
2021-03-21 10:59:59 +01:00
i18n_({element: this.title, key: options.name});
2021-01-06 10:16:53 +01:00
this.content.append(this.title);
}
2021-02-18 18:30:41 +01:00
if(options.caption) {
this.caption = this.generateContentElement();
2021-01-06 10:16:53 +01:00
this.caption.classList.add('sidebar-left-section-caption');
2021-03-23 17:13:35 +01:00
if(options.caption !== true) {
i18n_({element: this.caption, key: options.caption});
}
2021-01-06 10:16:53 +01:00
}
}
2021-02-18 18:30:41 +01:00
public generateContentElement() {
const content = document.createElement('div');
content.classList.add('sidebar-left-section-content');
this.container.append(content);
return content;
}
2021-01-06 10:16:53 +01:00
}
2021-03-23 17:13:35 +01:00
export const generateSection = (appendTo: Scrollable, name?: LangPackKey, caption?: LangPackKey) => {
2021-02-18 18:30:41 +01:00
const section = new SettingSection({name, caption});
2021-01-06 10:16:53 +01:00
appendTo.append(section.container);
return section.content;
};
2021-07-20 18:11:58 +02:00
export const generateDelimiter = () => {
const delimiter = document.createElement('div');
delimiter.classList.add('gradient-delimiter');
return delimiter;
};
2020-04-08 17:46:43 +02:00
const appSidebarLeft = new AppSidebarLeft();
MOUNT_CLASS_TO.appSidebarLeft = appSidebarLeft;
2020-04-08 17:46:43 +02:00
export default appSidebarLeft;