No edit summary Tag: 2017 source edit |
No edit summary Tag: 2017 source edit |
||
Line 137: | Line 137: | ||
<html> | <html> | ||
<script> | <script> | ||
(function() { | (function () { | ||
var input = document.getElementById('customsearch-input'); | |||
var suggestionsBox = document.getElementById('suggestion-container'); | |||
var suggestionList = document.getElementById('suggestion-list'); | |||
var lastFetchController = null; | |||
// Hide suggestions | // Hide suggestions | ||
Line 163: | Line 163: | ||
} | } | ||
suggestions. | for (var i = 0; i < suggestions.length; i++) { | ||
var sugg = suggestions[i]; | |||
var li = document.createElement('li'); | |||
li.textContent = sugg; | li.textContent = sugg; | ||
li.style.padding = '8px 12px'; | li.style.padding = '8px 12px'; | ||
li.style.cursor = 'pointer'; | li.style.cursor = 'pointer'; | ||
li.addEventListener('click', () | li.addEventListener('click', function () { | ||
input.value = | input.value = this.textContent; | ||
hideSuggestions(); | hideSuggestions(); | ||
}); | }); | ||
suggestionList.appendChild(li); | suggestionList.appendChild(li); | ||
} | } | ||
showSuggestions(); | showSuggestions(); | ||
} | } | ||
// Fetch suggestions | // Fetch suggestions using XMLHttpRequest | ||
input.addEventListener('input', | function fetchSuggestions(query) { | ||
var xhr = new XMLHttpRequest(); | |||
var url = 'https://search-api.mdriven.net/wiki_suggestions?q=' + encodeURIComponent(query); | |||
xhr.open('GET', url, true); | |||
xhr.onreadystatechange = function () { | |||
if (xhr.readyState === 4 && xhr.status === 200) { | |||
try { | |||
var data = JSON.parse(xhr.responseText); | |||
updateSuggestions(data); | |||
} catch (err) { | |||
console.error('Error parsing suggestions:', err); | |||
} | |||
} | |||
}; | |||
xhr.onerror = function () { | |||
console.error('Error fetching suggestions'); | |||
}; | |||
xhr.send(); | |||
} | |||
// Listen for user input | |||
input.addEventListener('input', function () { | |||
var query = this.value.trim(); | |||
if (!query) { | if (!query) { | ||
hideSuggestions(); | hideSuggestions(); | ||
Line 192: | Line 218: | ||
lastFetchController.abort(); | lastFetchController.abort(); | ||
} | } | ||
// Create a new AbortController (Polyfill for ES5 compatibility) | |||
lastFetchController = new AbortControllerPolyfill(); | |||
// Fetch suggestions using XMLHttpRequest | |||
fetchSuggestions(query); | |||
}); | }); | ||
// Hide suggestions on clicking outside | // Hide suggestions on clicking outside | ||
document.addEventListener('click', (e) | document.addEventListener('click', function (e) { | ||
if (!suggestionsBox.contains(e.target) && e.target !== input) { | if (!suggestionsBox.contains(e.target) && e.target !== input) { | ||
hideSuggestions(); | hideSuggestions(); | ||
} | } | ||
}); | }); | ||
// Polyfill for AbortController for older browsers | |||
function AbortControllerPolyfill() { | |||
this.signal = {}; | |||
this.abort = function () { | |||
// Aborting is not fully supported in ES5, but this is a placeholder to mimic behavior | |||
}; | |||
} | |||
})(); | })(); | ||
</script> | </script> |
Revision as of 12:56, 31 March 2025
This page was created by MediaWiki default on 2016-11-24. Last edited by Edgar on 2025-03-31.
MDriven Learn
Learn. Model. Build.
Visualize and design your ideas. Discover more with MDriven documentation, hands-on training, and ready-made models to get the most from MDriven's tools and services.
Documentation
Find technical documentation
Gain understanding through in-depth explanations of the concepts behind the MDriven tools.
Training
Learn by doing
Practical training and tutorials on MDriven designed to educate and inspire you to model your ideas.
Q&A
Ask questions and get help
Write to us your MDriven-related questions and receive quality answers and feedback.
Model Examples
Try model samples
Use our unique, pre-built models to build your ideas and achieve your goals.
Best Practices
Explore effective solutions
Our suggestions on how you can maximize the benefits of the MDriven tools to realize business solutions.