Mercurial Hosting > lang
diff src/site.js @ 4:b1adec083e44
chat work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 08 Jul 2025 22:15:41 -0600 |
parents | 78708fa556a0 |
children | 2b7dcf355a78 |
line wrap: on
line diff
--- a/src/site.js Tue Jul 08 16:02:29 2025 -0600 +++ b/src/site.js Tue Jul 08 22:15:41 2025 -0600 @@ -70,31 +70,35 @@ } -function showWaitingAiIcon() { - document.querySelector('[waiting-ai-icon]').style.display = 'block'; -} +let currentPulldown = null; +let newPulldown = null; -const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; - -function textareaKey(aiKey,event) { - if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) { - event.preventDefault(); - askAi(aiKey); +function clickMenu(clicked,display) { + //console.log('clickMenu'); + let pulldown = clicked.parentNode.querySelector('div'); + if( pulldown !== currentPulldown ) { + pulldown.style.display = display || 'block'; + newPulldown = pulldown; + window.onclick = function() { + //console.log('window.onclick'); + if( currentPulldown ) { + currentPulldown.style.display = 'none'; + if( !newPulldown ) + window.onclick = null; + } + currentPulldown = newPulldown; + newPulldown = null; + }; + pulldown.scrollIntoViewIfNeeded(false); } } -function fixTextarea(event) { - let textarea = event.target; - textarea.style.height = 'initial'; - textarea.style.height = (textarea.scrollHeight+2) + 'px'; - textarea.scrollIntoViewIfNeeded(false); +function getEnclosingDialog(el) { + while( el.nodeName !== 'DIALOG' ) + el = el.parentNode; + return el; } -function askAi(aiKey) { - let aiDiv = document.querySelector(`[ai_container="${aiKey}"]`); - let input = aiDiv.querySelector('textarea'); - let url = `ai_ask.js?key=${aiKey}&input=${encodeURIComponent(input.value)}`; - ajax(url); - input.value = ''; - showWaitingAiIcon(); +function closeModal(el) { + getEnclosingDialog(el).close(); }