Refactor chid/grid attributes to data attributes

- We don't believe in imaginary HTML attributes that we make up, right?
This commit is contained in:
Wolfsblvt
2025-01-24 21:12:49 +01:00
parent a611a3ac59
commit 7c9b347116
7 changed files with 34 additions and 26 deletions

View File

@@ -1342,6 +1342,14 @@ export function resultCheckStatus() {
stopStatusLoading();
}
/**
* Switches the currently selected character to the one with the given ID. (character index, not the character key!)
*
* If the character ID doesn't exist, if the chat is being saved, or if a group is being generated, this function does nothing.
* If the character is different from the currently selected one, it will clear the chat and reset any selected character or group.
* @param {number} id The ID of the character to switch to.
*/
export async function selectCharacterById(id) {
if (characters[id] === undefined) {
return;
@@ -1415,7 +1423,7 @@ function getCharacterBlock(item, id) {
}
// Populate the template
const template = $('#character_template .character_select').clone();
template.attr({ 'chid': id, 'id': `CharID${id}` });
template.attr({ 'data-chid': id, 'id': `CharID${id}` });
template.find('img').attr('src', this_avatar).attr('alt', item.name);
template.find('.avatar').attr('title', `[Character] ${item.name}\nFile: ${item.avatar}`);
template.find('.ch_name').text(item.name).attr('title', `[Character] ${item.name}`);
@@ -6191,7 +6199,7 @@ export async function renameCharacter(name = null, { silent = false, renameChats
if (newChId !== -1) {
// Select the character after the renaming
this_chid = -1;
await selectCharacterById(String(newChId));
await selectCharacterById(newChId);
// Async delay to update UI
await delay(1);
@@ -9878,7 +9886,7 @@ jQuery(async function () {
});
$(document).on('click', '.character_select', async function () {
const id = $(this).attr('chid');
const id = Number($(this).attr('data-chid'));
await selectCharacterById(id);
});