mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
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:
@@ -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);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user