mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Disabled keyboard shortcut for missing data attributes
refs https://github.com/TryGhost/Team/issues/1665 - in case no data-ghost-search attributes on a site, the keyboard shortcut to enable search is disabled - allows site owners to completely disable search on their site
This commit is contained in:
parent
f722cab8b5
commit
604cde2633
1 changed files with 11 additions and 2 deletions
|
@ -73,14 +73,19 @@ export default class App extends React.Component {
|
|||
showPopup: true
|
||||
});
|
||||
};
|
||||
const customTriggerSelector = '[data-ghost-search]';
|
||||
this.customTriggerButtons = document.querySelectorAll(customTriggerSelector) || [];
|
||||
|
||||
this.customTriggerButtons = this.getCustomTriggerButtons();
|
||||
this.customTriggerButtons.forEach((customTriggerButton) => {
|
||||
customTriggerButton.removeEventListener('click', this.clickHandler);
|
||||
customTriggerButton.addEventListener('click', this.clickHandler);
|
||||
});
|
||||
}
|
||||
|
||||
getCustomTriggerButtons() {
|
||||
const customTriggerSelector = '[data-ghost-search]';
|
||||
return document.querySelectorAll(customTriggerSelector) || [];
|
||||
}
|
||||
|
||||
handleSearchUrl() {
|
||||
const [path] = window.location.hash.substr(1).split('?');
|
||||
if (path === '/search' || path === '/search/') {
|
||||
|
@ -92,6 +97,10 @@ export default class App extends React.Component {
|
|||
}
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
const customTriggerButtons = this.getCustomTriggerButtons();
|
||||
if (!customTriggerButtons?.length) {
|
||||
return;
|
||||
}
|
||||
this.handleKeyDown = (e) => {
|
||||
if (e.key === 'k' && e.metaKey) {
|
||||
this.setState({
|
||||
|
|
Loading…
Add table
Reference in a new issue