Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const searchForm = document.getElementById('search-form');
+ const searchInput = document.getElementById('search-input');
+ const suggestions = document.getElementById('suggestions');
+ const results = document.getElementById('results');
+
+ // Sample search function
+ searchForm.addEventListener('submit', function(e) {
+ e.preventDefault();
+ const query = searchInput.value.trim();
+ if (query) {
+ performSearch(query);
+ }
+ });
+
+ // Search input event listeners
+ searchInput.addEventListener('input', function() {
+ const query = searchInput.value.trim();
+ if (query.length > 2) {
+ showSuggestions(query);
+ } else {
+ suggestions.style.display = 'none';
+ }
+ });
+
+ // Sample search function
+ function performSearch(query) {
+ // In a real app, this would fetch from a search API
+ results.innerHTML = '';
+ suggestions.style.display = 'none';
+
+ // Sample results
+ const sampleResults = [
+ {
+ title: "Scroll Documentation",
+ url: "https://scroll.pub/docs",
+ snippet: "Official documentation for the Scroll markup language. Learn how to write beautiful documents with Scroll's simple syntax."
+ },
+ {
+ title: "Getting Started with Scroll",
+ url: "https://scroll.pub/tutorial",
+ snippet: "A beginner's guide to using Scroll. Learn the basics of the syntax and how to create your first document."
+ },
+ {
+ title: "Scroll GitHub Repository",
+ url: "https://github.com/breck7/scroll",
+ snippet: "The official GitHub repository for Scroll. Contribute to the project or report issues."
+ }
+ ];
+
+ // Display results
+ sampleResults.forEach(result => {
+ const card = document.createElement('div');
+ card.className = 'result-card';
+ card.innerHTML = `
+ ${result.url}
+ `;
+ results.appendChild(card);
+ });
+ }
+
+ // Sample suggestions
+ function showSuggestions(query) {
+ // In a real app, this would fetch suggestions from an API
+ const sampleSuggestions = [
+ "scroll documentation",
+ "scroll tutorial",
+ "scroll examples",
+ "scroll syntax",
+ "scroll github"
+ ];
+
+ suggestions.innerHTML = '';
+ sampleSuggestions
+ .filter(s => s.includes(query.toLowerCase()))
+ .forEach(suggestion => {
+ const div = document.createElement('div');
+ div.className = 'suggestion-item';
+ div.textContent = suggestion;
+ div.addEventListener('click', function() {
+ searchInput.value = suggestion;
+ performSearch(suggestion);
+ });
+ suggestions.appendChild(div);
+ });
+
+ suggestions.style.display = 'block';
+ }
+
+ // Close suggestions when clicking outside
+ document.addEventListener('click', function(e) {
+ if (!searchForm.contains(e.target)) {
+ suggestions.style.display = 'none';
+ }
+ });
+ });