Created
February 22, 2022 11:39
-
-
Save calien666/e6d07510cfbb452e288bc2f0b899aed0 to your computer and use it in GitHub Desktop.
Adding tx_solr[q] as speaking URL part to TYPO3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Search: | |
type: Plugin | |
namespace: tx_solr | |
routePath: '/{q}' | |
limitToPages: [1571] | |
defaults: | |
q: '' | |
requirements: | |
q: '^.*$' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const triggerNewUrl = function (form) { | |
var searchField = form.querySelector('.input--search'); | |
var currentSearchWord = searchField.value; | |
searchField.removeAttribute('name'); | |
var action = form.action.split('?')[0]; | |
form.addEventListener('keyup', function (event) { | |
if (event.target === searchField) { | |
var actionParams = action.split('/'); | |
var lastParam = actionParams.pop(); | |
var searchParams = actionParams.pop(); | |
if (searchParams !== lastParam) { | |
actionParams.push(searchParams); | |
} | |
if (currentSearchWord.length > 0) { | |
var encodedSearchWord = encodeURI(currentSearchWord); | |
actionParams.forEach(function (elem, index) { | |
if (elem === encodedSearchWord) { | |
actionParams[index] = encodeURI(searchField.value); | |
} | |
}); | |
} else { | |
actionParams.push(encodeURI(searchField.value)); | |
} | |
actionParams.push(lastParam); | |
action = actionParams.join('/'); | |
currentSearchWord = searchField.value; | |
form.action = action; | |
} | |
}); | |
form.addEventListener('submit', function (event) { | |
event.preventDefault(); | |
event.stopPropagation(); | |
if (searchField.value !== currentSearchWord) { | |
if (currentSearchWord) { | |
action = action.replace(encodeURI(currentSearchWord), encodeURI(searchField.value)); | |
} else { | |
action += searchField.value + "/"; | |
} | |
form.action = action; | |
} | |
window.location.href = form.action; | |
return false; | |
}); | |
}; | |
const triggerHeaderSearchUrl = function () { | |
var form = document.querySelector('.navigation__bar .tx_solr form'); | |
triggerNewUrl(form); | |
}; | |
$(document).ready(function () { | |
var mainForm = document.querySelector('.wrap--content-element .tx_solr form'); | |
if (mainForm) { | |
triggerNewUrl(mainForm); | |
} | |
var searchForm = document.querySelector('.tx-euwid-search form'); | |
if (searchForm) { | |
triggerNewUrl(searchForm); | |
} | |
triggerHeaderSearchUrl(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment