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:
parent
3369e92627
commit
2ef8eb0586
1 changed files with 18 additions and 0 deletions
|
@ -45,12 +45,30 @@ export default class App extends React.Component {
|
||||||
// Listen to preview mode changes
|
// Listen to preview mode changes
|
||||||
this.handleSearchUrl();
|
this.handleSearchUrl();
|
||||||
this.addKeyboardShortcuts();
|
this.addKeyboardShortcuts();
|
||||||
|
this.setupCustomTriggerButton();
|
||||||
this.hashHandler = () => {
|
this.hashHandler = () => {
|
||||||
this.handleSearchUrl();
|
this.handleSearchUrl();
|
||||||
};
|
};
|
||||||
window.addEventListener('hashchange', this.hashHandler, false);
|
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() {
|
handleSearchUrl() {
|
||||||
const [path] = window.location.hash.substr(1).split('?');
|
const [path] = window.location.hash.substr(1).split('?');
|
||||||
if (path === '/search' || path === '/search/') {
|
if (path === '/search' || path === '/search/') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue