comparison 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
comparison
equal deleted inserted replaced
3:eee6d4f59811 4:b1adec083e44
68 } 68 }
69 ajax(url,post,{form:form}); 69 ajax(url,post,{form:form});
70 } 70 }
71 71
72 72
73 function showWaitingAiIcon() { 73 let currentPulldown = null;
74 document.querySelector('[waiting-ai-icon]').style.display = 'block'; 74 let newPulldown = null;
75 }
76 75
77 const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; 76 function clickMenu(clicked,display) {
78 77 //console.log('clickMenu');
79 function textareaKey(aiKey,event) { 78 let pulldown = clicked.parentNode.querySelector('div');
80 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) { 79 if( pulldown !== currentPulldown ) {
81 event.preventDefault(); 80 pulldown.style.display = display || 'block';
82 askAi(aiKey); 81 newPulldown = pulldown;
82 window.onclick = function() {
83 //console.log('window.onclick');
84 if( currentPulldown ) {
85 currentPulldown.style.display = 'none';
86 if( !newPulldown )
87 window.onclick = null;
88 }
89 currentPulldown = newPulldown;
90 newPulldown = null;
91 };
92 pulldown.scrollIntoViewIfNeeded(false);
83 } 93 }
84 } 94 }
85 95
86 function fixTextarea(event) { 96 function getEnclosingDialog(el) {
87 let textarea = event.target; 97 while( el.nodeName !== 'DIALOG' )
88 textarea.style.height = 'initial'; 98 el = el.parentNode;
89 textarea.style.height = (textarea.scrollHeight+2) + 'px'; 99 return el;
90 textarea.scrollIntoViewIfNeeded(false);
91 } 100 }
92 101
93 function askAi(aiKey) { 102 function closeModal(el) {
94 let aiDiv = document.querySelector(`[ai_container="${aiKey}"]`); 103 getEnclosingDialog(el).close();
95 let input = aiDiv.querySelector('textarea');
96 let url = `ai_ask.js?key=${aiKey}&input=${encodeURIComponent(input.value)}`;
97 ajax(url);
98 input.value = '';
99 showWaitingAiIcon();
100 } 104 }