diff --git a/my-blog/static/js/ask-ai.js b/my-blog/static/js/ask-ai.js index 6b06687..a6ab0ae 100644 --- a/my-blog/static/js/ask-ai.js +++ b/my-blog/static/js/ask-ai.js @@ -513,6 +513,65 @@ document.addEventListener('DOMContentLoaded', function() { }); }); +// Game functionality +function showGame() { + const gameFrame = document.getElementById('gameFrame'); + const chatForm = document.getElementById('chatForm'); + const chatHistory = document.getElementById('chatHistory'); + const panel = document.getElementById('askAiPanel'); + + if (gameFrame && chatForm && panel) { + gameFrame.style.display = 'block'; + chatForm.style.display = 'none'; + chatHistory.style.display = 'none'; + panel.classList.add('game-mode'); + } +} + +function closeGame() { + const gameFrame = document.getElementById('gameFrame'); + const chatForm = document.getElementById('chatForm'); + const chatHistory = document.getElementById('chatHistory'); + const panel = document.getElementById('askAiPanel'); + + if (gameFrame && chatForm && panel) { + gameFrame.style.display = 'none'; + chatForm.style.display = 'block'; + chatHistory.style.display = 'block'; + panel.classList.remove('game-mode'); + } +} + +// Show game button when user is authenticated +function showGameButton() { + const gameButton = document.getElementById('gameButton'); + if (gameButton) { + gameButton.style.display = 'inline-block'; + } +} + +// Hide game button when user is not authenticated +function hideGameButton() { + const gameButton = document.getElementById('gameButton'); + if (gameButton) { + gameButton.style.display = 'none'; + } +} + +// Override handleAuthenticationStatus to include game button logic +const originalHandleAuthenticationStatus = handleAuthenticationStatus; +function handleAuthenticationStatus(isAuthenticated) { + originalHandleAuthenticationStatus(isAuthenticated); + + if (isAuthenticated) { + showGameButton(); + } else { + hideGameButton(); + } +} + // Global functions for onclick handlers window.toggleAskAI = toggleAskAI; window.askQuestion = askQuestion; +window.showGame = showGame; +window.closeGame = closeGame; diff --git a/my-blog/templates/base.html b/my-blog/templates/base.html index 82b8523..44f90e8 100644 --- a/my-blog/templates/base.html +++ b/my-blog/templates/base.html @@ -72,6 +72,7 @@