class Help { constructor(options) { this._el = $.el('#help'); this._commands = options.commands; this._newTab = options.newTab; this._toggled = false; this._handleKeydown = this._handleKeydown.bind(this); this.toggle = this.toggle.bind(this); this.launch = this.launch.bind(this); this.launchCategory = this.launchCategory.bind(this); this._inputEl = $.el('#search-input'); this._inputElVal = ''; this._suggester = options.suggester; this._invertColors = options.invertedColors; this._buildAndAppendLists(); this._registerEvents(); this._invertValue; } toggle(show) { this._toggled = typeof show !== 'undefined' ? show : !this._toggled; this._toggled ? $.bodyClassAdd('help') : $.bodyClassRemove('help'); } hide() { $.bodyClassRemove('form'); this._inputEl.value = ''; this._inputElVal = ''; this._suggester.suggest(''); } launch() { this.hide(); this.toggle(true); $.bodyClassAdd('help'); CONFIG.commands.forEach(command => { if(command.quickLaunch) window.open(command.url); }); } launchCategory(){ const categorySet = new Set(); CONFIG.commands.forEach(command => { if(command.category) categorySet.add(command.category); }); const targetCategoryIndex = $.el('#search-input').value.replace('!', ''); const targetCategory = Array.from(categorySet)[targetCategoryIndex - 1]; CONFIG.commands.forEach(command => { if(targetCategory && command.category === targetCategory) window.open(command.url); }); } _buildAndAppendLists() { const lists = document.createElement('ul'); lists.classList.add('categories'); this._getCategories().forEach(category => { lists.insertAdjacentHTML( 'beforeend', `
  • ${category}

  • ` ); }); this._el.appendChild(lists); } _buildListCommands(currentCategory) { let invertValue = this._invertColors ? 1: 0; const bgcolor = invertValue ? getComputedStyle(document.documentElement).getPropertyValue('--foreground') : getComputedStyle(document.documentElement).getPropertyValue('--background'); const fgcolor = invertValue ? getComputedStyle(document.documentElement).getPropertyValue('--background') : getComputedStyle(document.documentElement).getPropertyValue('--foreground'); const commandListWithIcons = this._commands .map(({ category, name, key, url, icon }, i) => { const iconEl = CONFIG.iconExtension !== 'svg' ? `` : `` if (category === currentCategory) { return `
  • ${iconEl} ${name}
  • `; } }) .join(''); const commandListWithKeys = this._commands .map(({ category, name, key, url }, i) => { if (category === currentCategory) { return `
  • ${key} ${name}
  • `; } }) .join(''); return CONFIG.showKeys ? commandListWithKeys : commandListWithIcons; } _getCategories() { const categories = this._commands .map(v => v.category) .filter(category => category); return [...new Set(categories)]; } _handleKeydown(e) { if ($.key(e) === 'escape') this.toggle(false); } _registerEvents() { document.addEventListener('keydown', this._handleKeydown); } }