:recycle: [Refactor] Separate InputsBinder and CommonsLoader from main.js
Browse files- commons/commons_loader.js +14 -0
- {common → commons}/live.js +0 -0
- components/inputs_binder.js +48 -0
- main.js +7 -44
commons/commons_loader.js
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export class CommonsLoader {
|
2 |
+
constructor() {}
|
3 |
+
load() {
|
4 |
+
load_live_js();
|
5 |
+
}
|
6 |
+
}
|
7 |
+
|
8 |
+
function load_live_js() {
|
9 |
+
if (window.location.protocol !== "https:") {
|
10 |
+
var script = document.createElement("script");
|
11 |
+
script.src = "./commons/live.js";
|
12 |
+
document.head.appendChild(script);
|
13 |
+
}
|
14 |
+
}
|
{common → commons}/live.js
RENAMED
File without changes
|
components/inputs_binder.js
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import {
|
2 |
+
setup_available_models_on_select,
|
3 |
+
setup_temperature_on_select,
|
4 |
+
} from "../components/llm_models_loader.js";
|
5 |
+
|
6 |
+
export class InputsBinder {
|
7 |
+
constructor() {}
|
8 |
+
bind() {
|
9 |
+
setup_available_models_on_select();
|
10 |
+
setup_temperature_on_select();
|
11 |
+
let user_input_resizer = new UserInputResizer();
|
12 |
+
user_input_resizer.bind();
|
13 |
+
let chat_session_container_resize_binder =
|
14 |
+
new ChatSessionContainerResizeBinder();
|
15 |
+
chat_session_container_resize_binder.bind();
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
class UserInputResizer {
|
20 |
+
constructor() {}
|
21 |
+
bind() {
|
22 |
+
// https://stackoverflow.com/questions/37629860/automatically-resizing-textarea-in-bootstrap
|
23 |
+
document.getElementById("user-input").addEventListener(
|
24 |
+
"input",
|
25 |
+
function () {
|
26 |
+
this.style.height = 0;
|
27 |
+
this.style.height = this.scrollHeight + 3 + "px";
|
28 |
+
},
|
29 |
+
false
|
30 |
+
);
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
class ChatSessionContainerResizeBinder {
|
35 |
+
constructor() {}
|
36 |
+
bind() {
|
37 |
+
this.resize();
|
38 |
+
$(window).on("resize", this.resize);
|
39 |
+
}
|
40 |
+
resize() {
|
41 |
+
let user_interaction_height = $("#user-interactions").outerHeight(true);
|
42 |
+
let page_height = $(window).height();
|
43 |
+
$("#chat-session-container").css(
|
44 |
+
"max-height",
|
45 |
+
page_height - user_interaction_height + "px"
|
46 |
+
);
|
47 |
+
}
|
48 |
+
}
|
main.js
CHANGED
@@ -1,49 +1,12 @@
|
|
1 |
-
import {
|
2 |
-
setup_available_models_on_select,
|
3 |
-
setup_temperature_on_select,
|
4 |
-
} from "./components/llm_models_loader.js";
|
5 |
import { ButtonsBinder } from "./components/buttons_binder.js";
|
|
|
|
|
6 |
|
7 |
-
function
|
8 |
-
// https://stackoverflow.com/questions/37629860/automatically-resizing-textarea-in-bootstrap
|
9 |
-
document.getElementById("user-input").addEventListener(
|
10 |
-
"input",
|
11 |
-
function () {
|
12 |
-
this.style.height = 0;
|
13 |
-
this.style.height = this.scrollHeight + 3 + "px";
|
14 |
-
},
|
15 |
-
false
|
16 |
-
);
|
17 |
-
}
|
18 |
-
|
19 |
-
function load_live_js() {
|
20 |
-
if (window.location.protocol !== "https:") {
|
21 |
-
var script = document.createElement("script");
|
22 |
-
script.src = "./common/live.js";
|
23 |
-
document.head.appendChild(script);
|
24 |
-
}
|
25 |
-
}
|
26 |
-
|
27 |
-
function setup_interactive_components() {
|
28 |
-
setup_available_models_on_select();
|
29 |
-
setup_temperature_on_select();
|
30 |
-
auto_resize_user_input();
|
31 |
let buttons_binder = new ButtonsBinder();
|
32 |
buttons_binder.bind();
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
function adjust_messagers_container_max_height() {
|
38 |
-
var user_interaction_height = $("#user-interactions").outerHeight(true);
|
39 |
-
var page_height = $(window).height();
|
40 |
-
$("#chat-session-container").css(
|
41 |
-
"max-height",
|
42 |
-
page_height - user_interaction_height + "px"
|
43 |
-
);
|
44 |
-
}
|
45 |
-
|
46 |
-
$(document).ready(function () {
|
47 |
-
load_live_js();
|
48 |
-
setup_interactive_components();
|
49 |
});
|
|
|
|
|
|
|
|
|
|
|
1 |
import { ButtonsBinder } from "./components/buttons_binder.js";
|
2 |
+
import { InputsBinder } from "./components/inputs_binder.js";
|
3 |
+
import { CommonsLoader } from "./commons/commons_loader.js";
|
4 |
|
5 |
+
$(document).ready(function () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
let buttons_binder = new ButtonsBinder();
|
7 |
buttons_binder.bind();
|
8 |
+
let inputs_binder = new InputsBinder();
|
9 |
+
inputs_binder.bind();
|
10 |
+
let commons_loader = new CommonsLoader();
|
11 |
+
commons_loader.load();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
});
|