Skip to content

Commit

Permalink
Inline embed support
Browse files Browse the repository at this point in the history
  • Loading branch information
polterguy committed Sep 27, 2023
1 parent 1eec3b6 commit bd6348a
Show file tree
Hide file tree
Showing 3 changed files with 442 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/files/system/openai/front.files/chat/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ let ainiroUserId = null;
// Downloading ShowdownJS to be able to parse Markdown.
let hasDownloadedShowdownHighlight = false;


// Creating CSS inclusion.
fetch('[[url]]/magic/system/openai/include-style?file=' + encodeURIComponent('[[css]]'))
.then(res => {
Expand Down Expand Up @@ -109,6 +108,9 @@ window.ainiro_faq_question = function(e) {
e.stopPropagation();
}

// This is the parent DOM element of the chat window, if null, it is embedded into body.
let ainiroParentElement = '[[parent_node]]';

/*
* Function creating our chat UI.
*/
Expand Down Expand Up @@ -152,7 +154,12 @@ function aista_create_chat_ui() {
}
html += '</form>';
aistaChatWnd.innerHTML = html;
window.document.body.appendChild(aistaChatWnd);
if (ainiroParentElement && ainiroParentElement !== '') {
document.getElementById(ainiroParentElement).appendChild(aistaChatWnd);
aista_show_chat_window();
} else {
window.document.body.appendChild(aistaChatWnd);
}

// Adding event listener to input field to allow for closing it with escape key.
const aistaChatInpField = document.getElementsByClassName('aista-chat-prompt')[0];
Expand Down
Loading

0 comments on commit bd6348a

Please sign in to comment.