stop typing in message bubbles, only type in user messages in "Type your message..." input - Follow Up Deployment
Browse files- index.html +56 -32
index.html
CHANGED
|
@@ -38,14 +38,16 @@
|
|
| 38 |
.user-bubble {
|
| 39 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 40 |
color: white;
|
| 41 |
-
|
|
|
|
| 42 |
border-bottom-right-radius: 4px;
|
| 43 |
}
|
| 44 |
|
| 45 |
.ai-bubble {
|
| 46 |
background: rgba(255, 255, 255, 0.9);
|
| 47 |
color: #333;
|
| 48 |
-
|
|
|
|
| 49 |
border-bottom-left-radius: 4px;
|
| 50 |
}
|
| 51 |
|
|
@@ -307,30 +309,45 @@
|
|
| 307 |
const message = userInput.value.trim();
|
| 308 |
if (message === '') return;
|
| 309 |
|
| 310 |
-
//
|
| 311 |
-
addMessage(message, 'user');
|
| 312 |
-
userInput.value = '';
|
| 313 |
-
|
| 314 |
-
// Show typing indicator
|
| 315 |
typingIndicator.classList.remove('hidden');
|
|
|
|
|
|
|
| 316 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 317 |
|
| 318 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 319 |
setTimeout(() => {
|
| 320 |
-
typingIndicator.
|
|
|
|
|
|
|
| 321 |
simulateAIResponse();
|
| 322 |
-
},
|
| 323 |
}
|
| 324 |
|
| 325 |
-
// Add message to chat
|
| 326 |
function addMessage(message, sender) {
|
| 327 |
const messageDiv = document.createElement('div');
|
| 328 |
messageDiv.className = `message-bubble ${sender}-bubble`;
|
| 329 |
-
messageDiv.innerHTML = message;
|
| 330 |
chatContainer.appendChild(messageDiv);
|
|
|
|
|
|
|
|
|
|
| 331 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
|
|
|
| 332 |
|
| 333 |
-
// Handle gallery images
|
| 334 |
if (sender === 'ai') {
|
| 335 |
setTimeout(() => {
|
| 336 |
const galleryImages = document.querySelectorAll('.gallery-img');
|
|
@@ -346,12 +363,15 @@
|
|
| 346 |
|
| 347 |
// Simulate AI response based on conversation flow
|
| 348 |
function simulateAIResponse() {
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
currentStep
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
|
|
|
|
|
|
|
|
|
| 355 |
}
|
| 356 |
|
| 357 |
// Event listeners
|
|
@@ -388,22 +408,26 @@
|
|
| 388 |
conversation.forEach((step, index) => {
|
| 389 |
// User message
|
| 390 |
setTimeout(() => {
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
|
|
|
| 396 |
typingIndicator.classList.remove('hidden');
|
| 397 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
-
delay +=
|
| 407 |
});
|
| 408 |
});
|
| 409 |
</script>
|
|
|
|
| 38 |
.user-bubble {
|
| 39 |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 40 |
color: white;
|
| 41 |
+
margin-left: auto;
|
| 42 |
+
margin-right: 0;
|
| 43 |
border-bottom-right-radius: 4px;
|
| 44 |
}
|
| 45 |
|
| 46 |
.ai-bubble {
|
| 47 |
background: rgba(255, 255, 255, 0.9);
|
| 48 |
color: #333;
|
| 49 |
+
margin-right: auto;
|
| 50 |
+
margin-left: 0;
|
| 51 |
border-bottom-left-radius: 4px;
|
| 52 |
}
|
| 53 |
|
|
|
|
| 309 |
const message = userInput.value.trim();
|
| 310 |
if (message === '') return;
|
| 311 |
|
| 312 |
+
// Show typing indicator for user
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
typingIndicator.classList.remove('hidden');
|
| 314 |
+
typingIndicator.style.marginLeft = 'auto';
|
| 315 |
+
typingIndicator.style.marginRight = '0';
|
| 316 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 317 |
|
| 318 |
+
// Clear input but keep message for animation
|
| 319 |
+
const messageToSend = message;
|
| 320 |
+
userInput.value = '';
|
| 321 |
+
|
| 322 |
+
// Add user message immediately
|
| 323 |
+
const bubble = document.createElement('div');
|
| 324 |
+
bubble.className = 'message-bubble user-bubble';
|
| 325 |
+
bubble.textContent = messageToSend;
|
| 326 |
+
chatContainer.appendChild(bubble);
|
| 327 |
+
|
| 328 |
+
typingIndicator.classList.add('hidden');
|
| 329 |
+
|
| 330 |
+
// Show AI typing after short delay
|
| 331 |
setTimeout(() => {
|
| 332 |
+
typingIndicator.style.marginLeft = '0';
|
| 333 |
+
typingIndicator.style.marginRight = 'auto';
|
| 334 |
+
typingIndicator.classList.remove('hidden');
|
| 335 |
simulateAIResponse();
|
| 336 |
+
}, 500);
|
| 337 |
}
|
| 338 |
|
| 339 |
+
// Add message to chat (for AI responses)
|
| 340 |
function addMessage(message, sender) {
|
| 341 |
const messageDiv = document.createElement('div');
|
| 342 |
messageDiv.className = `message-bubble ${sender}-bubble`;
|
|
|
|
| 343 |
chatContainer.appendChild(messageDiv);
|
| 344 |
+
|
| 345 |
+
// Add message immediately
|
| 346 |
+
messageDiv.innerHTML = message;
|
| 347 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 348 |
+
typingIndicator.classList.add('hidden');
|
| 349 |
|
| 350 |
+
// Handle gallery images after message is complete
|
| 351 |
if (sender === 'ai') {
|
| 352 |
setTimeout(() => {
|
| 353 |
const galleryImages = document.querySelectorAll('.gallery-img');
|
|
|
|
| 363 |
|
| 364 |
// Simulate AI response based on conversation flow
|
| 365 |
function simulateAIResponse() {
|
| 366 |
+
// Random delay before AI starts typing (1-3 seconds)
|
| 367 |
+
setTimeout(() => {
|
| 368 |
+
if (currentStep < conversation.length) {
|
| 369 |
+
addMessage(conversation[currentStep].ai, 'ai');
|
| 370 |
+
currentStep++;
|
| 371 |
+
} else {
|
| 372 |
+
addMessage("Is there anything else I can help you with today?", 'ai');
|
| 373 |
+
}
|
| 374 |
+
}, 500 + Math.random() * 2000);
|
| 375 |
}
|
| 376 |
|
| 377 |
// Event listeners
|
|
|
|
| 408 |
conversation.forEach((step, index) => {
|
| 409 |
// User message
|
| 410 |
setTimeout(() => {
|
| 411 |
+
const userBubble = document.createElement('div');
|
| 412 |
+
userBubble.className = 'message-bubble user-bubble';
|
| 413 |
+
userBubble.textContent = step.user;
|
| 414 |
+
chatContainer.appendChild(userBubble);
|
| 415 |
+
|
| 416 |
+
// Show AI typing
|
| 417 |
typingIndicator.classList.remove('hidden');
|
| 418 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 419 |
+
|
| 420 |
+
// AI response after delay
|
| 421 |
+
setTimeout(() => {
|
| 422 |
+
typingIndicator.classList.add('hidden');
|
| 423 |
+
const aiBubble = document.createElement('div');
|
| 424 |
+
aiBubble.className = 'message-bubble ai-bubble';
|
| 425 |
+
aiBubble.innerHTML = step.ai;
|
| 426 |
+
chatContainer.appendChild(aiBubble);
|
| 427 |
+
}, 1000);
|
| 428 |
+
}, delay);
|
| 429 |
|
| 430 |
+
delay += 2000; // Increment delay for next pair
|
| 431 |
});
|
| 432 |
});
|
| 433 |
</script>
|