hw 6-7 some fixes

This commit is contained in:
redtea committed 2026-05-28 17:51:07 +03:00
1 parent 34630657b8
commit 3080e5b5b6
8 files changed
+67 -65

No files matched your search

+24 -28
View File
@@ -55,6 +55,30 @@ if (searchInput) {
});
}
function askItSearch(event) {
event.preventDefault();
const query = searchInput ? searchInput.value.trim() : '';
if (!query) {
return false;
}
fetch(`/search?q=${encodeURIComponent(query)}`)
.then(response => response.json())
.then(data => {
const results = data.results || [];
if (results.length) {
window.location.href = results[0].url;
} else {
window.location.href = `/ask?q=${encodeURIComponent(query)}`;
}
})
.catch(() => {
window.location.href = `/ask?q=${encodeURIComponent(query)}`;
});
return false;
}
function postReaction(url, data, onSuccess) {
$.ajax({
url,
@@ -167,31 +191,3 @@ $(document).on('click', '.correct-answer-btn', function () {
console.error('centrifuge init error', e);
}
})();
// Handle ASK IT button - transfer search text to ask page
function redirectToAsk(event) {
event.preventDefault();
const searchInput = document.getElementById('search-input');
const query = searchInput ? searchInput.value.trim() : '';
const url = query ? `/ask?q=${encodeURIComponent(query)}` : '/ask';
window.location.href = url;
}
// Populate title field from URL parameter on ask page
function initializeTitleFromQuery() {
const params = new URLSearchParams(window.location.search);
const query = params.get('q');
if (query) {
const titleField = document.querySelector('[name="title"]');
if (titleField) {
titleField.value = query;
titleField.focus();
}
}
}
// Run immediately (script.js loads at end of page, DOMContentLoaded may have already fired)
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeTitleFromQuery);
} else {
initializeTitleFromQuery();
}