0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Handled opening search popup with data attribute

refs https://github.com/TryGhost/Team/issues/1665

- allows opening search popup in themes with custom data attribute
This commit is contained in:
Rishabh 2022-07-06 17:48:59 +02:00
parent 3369e92627
commit 2ef8eb0586

View file

@ -45,12 +45,30 @@ export default class App extends React.Component {
// Listen to preview mode changes
this.handleSearchUrl();
this.addKeyboardShortcuts();
this.setupCustomTriggerButton();
this.hashHandler = () => {
this.handleSearchUrl();
};
window.addEventListener('hashchange', this.hashHandler, false);
}
/** Setup custom trigger buttons handling on page */
setupCustomTriggerButton() {
// Handler for custom buttons
this.clickHandler = (event) => {
event.preventDefault();
this.setState({
showPopup: true
});
};
const customTriggerSelector = '[data-ghost-search]';
this.customTriggerButtons = document.querySelectorAll(customTriggerSelector) || [];
this.customTriggerButtons.forEach((customTriggerButton) => {
customTriggerButton.removeEventListener('click', this.clickHandler);
customTriggerButton.addEventListener('click', this.clickHandler);
});
}
handleSearchUrl() {
const [path] = window.location.hash.substr(1).split('?');
if (path === '/search' || path === '/search/') {