mNo edit summary |
mNo edit summary |
||
Line 17: | Line 17: | ||
// Use the selected template as a parameter in the parser function | // Use the selected template as a parameter in the parser function | ||
var parserFunction = "{{Companies/Search" + parameters + "}}"; | var parserFunction = "{{Companies/Search" + parameters + "}}"; | ||
console.log(parserFunction) | |||
// Replace the content in the dynamic content container with the parsed template | // Replace the content in the dynamic content container with the parsed template | ||
$.get(mw.util.wikiScript('api'), { action: 'parse', format: 'json', text: parserFunction }, function(data) { | $.get(mw.util.wikiScript('api'), { action: 'parse', format: 'json', text: parserFunction }, function(data) { | ||
Line 23: | Line 23: | ||
var content = document.createElement('div') | var content = document.createElement('div') | ||
content.innerHTML = parsedContent | content.innerHTML = parsedContent | ||
console.log(content) | |||
if ( content.querySelector('.mw-parser-output #companies-search-container') ) { | if ( content.querySelector('.mw-parser-output #companies-search-container') ) { |
Revision as of 16:54, 26 March 2024
<input type="text" id="companies__name" placeholder="Name...">
<script>
// Get the input and dropdown content elements var input = document.getElementById("search--input");
function updateTemplate() {
var parameters = ; let name = document.getElementById("companies__name").value; if ( name !== ) parameters += '|name=' + name
var contentContainer = document.getElementById("companies--list"); // Use the selected template as a parameter in the parser function var parserFunction = "Template:Companies/Search" + parameters + ""; console.log(parserFunction) // Replace the content in the dynamic content container with the parsed template $.get(mw.util.wikiScript('api'), { action: 'parse', format: 'json', text: parserFunction }, function(data) { var parsedContent = data.parse.text['*']; var content = document.createElement('div') content.innerHTML = parsedContent
console.log(content)
if ( content.querySelector('.mw-parser-output #companies-search-container') ) { contentContainer.innerHTML = content.querySelector('#companies-search-container').outerHTML; } else { contentContainer.innerHTML = 'No locations found' }
}); }
// Name input to run 500ms after last input let timeoutId; document.getElementById('location__name').addEventListener('input', function() { // Clear previous timeout (if any) clearTimeout(timeoutId);
// Set a new timeout for 500ms timeoutId = setTimeout(updateTemplate, 500); });
</script>