mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
fix: MovingUI breaking, typos, WI selector scroll
This commit is contained in:
@ -27,7 +27,7 @@ import {
|
||||
SECRET_KEYS,
|
||||
secret_state,
|
||||
} from "./secrets.js";
|
||||
import { sortByCssOrder, debounce } from "./utils.js";
|
||||
import { sortByCssOrder, debounce, delay } from "./utils.js";
|
||||
import { chat_completion_sources, oai_settings } from "./openai.js";
|
||||
|
||||
var NavToggle = document.getElementById("nav-toggle");
|
||||
@ -479,13 +479,30 @@ function OpenNavPanels() {
|
||||
|
||||
export function dragElement(elmnt) {
|
||||
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
|
||||
var height, width, top, left;
|
||||
var height, width, top, left, right, bottom;
|
||||
|
||||
var oldTop = Number((String($(elmnt).css('top')).replace('px', '')))
|
||||
var oldLeft = Number((String($(elmnt).css('left')).replace('px', '')))
|
||||
var oldWidth = Number((String($(elmnt).css('width')).replace('px', '')))
|
||||
var oldHeight = Number((String($(elmnt).css('width')).replace('px', '')))
|
||||
var oldRight = Number((String($(elmnt).css('right')).replace('px', '')))
|
||||
var oldBottom = Number((String($(elmnt).css('bottom')).replace('px', '')))
|
||||
var elmntName = elmnt.attr('id');
|
||||
console.debug(`init drag for ${elmntName}`)
|
||||
console.debug(`${elmntName} init state:
|
||||
T: ${$(elmnt).css('top')}
|
||||
L: ${$(elmnt).css('left')}
|
||||
W: ${$(elmnt).css('width')}
|
||||
H: ${$(elmnt).css('height')}
|
||||
R: ${$(elmnt).css('right')}
|
||||
B: ${$(elmnt).css('bottom')}
|
||||
---`);
|
||||
|
||||
|
||||
const elmntNameEscaped = $.escapeSelector(elmntName);
|
||||
const elmntHeader = $(`#${elmntNameEscaped}header`);
|
||||
if (elmntHeader.length) {
|
||||
elmntHeader.off('mousedown').on('mousedown', (e) => {
|
||||
|
||||
dragMouseDown(e);
|
||||
});
|
||||
} else {
|
||||
@ -498,6 +515,7 @@ export function dragElement(elmnt) {
|
||||
|| $(target).hasClass('resizing')
|
||||
|| Number((String(target.height).replace('px', ''))) < 50
|
||||
|| Number((String(target.width).replace('px', ''))) < 50
|
||||
|| power_user.movingUI === false
|
||||
|| isMobile() === true
|
||||
) {
|
||||
console.debug('aborting mutator')
|
||||
@ -510,12 +528,8 @@ export function dragElement(elmnt) {
|
||||
width = target.offsetWidth;
|
||||
top = parseInt(style.top);
|
||||
left = parseInt(style.left);
|
||||
|
||||
/* console.log(`
|
||||
height=${height},
|
||||
width=${width},
|
||||
top=${top},
|
||||
left=${left}`); */
|
||||
right = parseInt(style.right);
|
||||
bottom = parseInt(style.bottom);
|
||||
|
||||
if (!power_user.movingUIState[elmntName]) {
|
||||
console.debug(`adding config property for ${elmntName}`)
|
||||
@ -524,11 +538,32 @@ export function dragElement(elmnt) {
|
||||
|
||||
power_user.movingUIState[elmntName].top = top;
|
||||
power_user.movingUIState[elmntName].left = left;
|
||||
power_user.movingUIState[elmntName].width = width;
|
||||
power_user.movingUIState[elmntName].height = height;
|
||||
power_user.movingUIState[elmntName].right = 'unset';
|
||||
power_user.movingUIState[elmntName].bottom = 'unset';
|
||||
power_user.movingUIState[elmntName].margin = 'unset';
|
||||
|
||||
if (!isNaN(oldWidth)
|
||||
&& !isNaN(oldHeight)
|
||||
&& (oldHeight !== height || oldWidth !== width)) {
|
||||
power_user.movingUIState[elmntName].width = width;
|
||||
power_user.movingUIState[elmntName].height = height;
|
||||
} else {
|
||||
console.debug('skipping W/H setting')
|
||||
}
|
||||
power_user.movingUIState[elmntName].right = right;
|
||||
power_user.movingUIState[elmntName].bottom = bottom;
|
||||
if (!isNaN(oldTop) && !isNaN(oldLeft) && (oldTop !== top || oldLeft !== left)) {
|
||||
console.debug('unsetting margin due to custom position')
|
||||
console.debug(`${elmntName}:
|
||||
T: ${oldTop}>>${top}
|
||||
L: ${oldLeft}>> ${left}
|
||||
H: ${oldHeight} >> ${height}
|
||||
W: ${oldWidth}>> ${width}
|
||||
R: ${oldRight} >> ${right}
|
||||
B: ${oldBottom}>> ${bottom}
|
||||
---`)
|
||||
power_user.movingUIState[elmntName].margin = 'unset';
|
||||
} else {
|
||||
console.log('skipped unsetting margins')
|
||||
console.log(oldTop, top, oldLeft, left)
|
||||
}
|
||||
saveSettingsDebounced();
|
||||
|
||||
|
||||
@ -632,29 +667,28 @@ export function dragElement(elmnt) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function initMovingUI() {
|
||||
if (isMobile() === false && power_user.movingUI === true) {
|
||||
console.debug('START MOVING UI')
|
||||
dragElement($("#sheld"));
|
||||
dragElement($("#left-nav-panel"));
|
||||
dragElement($("#right-nav-panel"));
|
||||
dragElement($("#WorldInfo"));
|
||||
await delay(1000)
|
||||
console.debug('loading AN draggable function')
|
||||
dragElement($("#floatingPrompt"))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
|
||||
$("document").ready(function () {
|
||||
|
||||
// initial status check
|
||||
setTimeout(() => {
|
||||
|
||||
if (isMobile() === false) {
|
||||
console.debug('START MOVING UI')
|
||||
dragElement($("#sheld"));
|
||||
dragElement($("#left-nav-panel"));
|
||||
dragElement($("#right-nav-panel"));
|
||||
dragElement($("#WorldInfo"));
|
||||
dragElement($("#floatingPrompt"));
|
||||
}
|
||||
RA_checkOnlineStatus
|
||||
}
|
||||
, 100);
|
||||
|
||||
|
||||
|
||||
|
||||
//$('div').on('resize', saveMovingUIState());
|
||||
RA_checkOnlineStatus();
|
||||
}, 100);
|
||||
|
||||
// read the state of AutoConnect and AutoLoadChat.
|
||||
$(AutoConnectCheckbox).prop("checked", LoadLocalBool("AutoConnectEnabled"));
|
||||
|
@ -18,7 +18,7 @@ import {
|
||||
replaceCurrentChat,
|
||||
setCharacterId
|
||||
} from "../script.js";
|
||||
import { favsToHotswap, isMobile } from "./RossAscends-mods.js";
|
||||
import { favsToHotswap, isMobile, initMovingUI } from "./RossAscends-mods.js";
|
||||
import {
|
||||
groups,
|
||||
selected_group,
|
||||
@ -310,7 +310,13 @@ function switchMovingUI() {
|
||||
const movingUI = localStorage.getItem(storage_keys.movingUI);
|
||||
power_user.movingUI = movingUI === null ? false : movingUI == "true";
|
||||
$("body").toggleClass("movingUI", power_user.movingUI);
|
||||
scrollChatToBottom();
|
||||
if (power_user.movingUI === true) {
|
||||
initMovingUI()
|
||||
if (power_user.movingUIState) {
|
||||
loadMovingUIState();
|
||||
}
|
||||
};
|
||||
//scrollChatToBottom();
|
||||
}
|
||||
|
||||
function noShadows() {
|
||||
@ -649,7 +655,10 @@ function loadPowerUserSettings(settings, data) {
|
||||
}
|
||||
|
||||
function loadMovingUIState() {
|
||||
if (isMobile() === false && power_user.movingUIState) {
|
||||
if (isMobile() === false
|
||||
&& power_user.movingUIState
|
||||
&& power_user.movingUI === true) {
|
||||
console.debug('loading movingUI state')
|
||||
for (var elmntName of Object.keys(power_user.movingUIState)) {
|
||||
var elmntState = power_user.movingUIState[elmntName];
|
||||
try {
|
||||
@ -665,7 +674,7 @@ function loadMovingUIState() {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.debug('skipping movingUI state load for mobile')
|
||||
console.debug('skipping movingUI state load')
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -940,6 +949,22 @@ function resetMovablePanels() {
|
||||
document.getElementById("right-nav-panel").style.width = '';
|
||||
document.getElementById("right-nav-panel").style.margin = '';
|
||||
|
||||
document.getElementById("WorldInfo").style.top = '';
|
||||
document.getElementById("WorldInfo").style.left = '';
|
||||
document.getElementById("WorldInfo").style.right = '';
|
||||
document.getElementById("WorldInfo").style.bottom = '';
|
||||
document.getElementById("WorldInfo").style.height = '';
|
||||
document.getElementById("WorldInfo").style.width = '';
|
||||
document.getElementById("WorldInfo").style.margin = '';
|
||||
|
||||
document.getElementById("floatingPrompt").style.top = '';
|
||||
document.getElementById("floatingPrompt").style.left = '';
|
||||
document.getElementById("floatingPrompt").style.right = '';
|
||||
document.getElementById("floatingPrompt").style.bottom = '';
|
||||
document.getElementById("floatingPrompt").style.height = '';
|
||||
document.getElementById("floatingPrompt").style.width = '';
|
||||
document.getElementById("floatingPrompt").style.margin = '';
|
||||
|
||||
if ($("#expression-holder")) {
|
||||
document.getElementById("expression-holder").style.top = '';
|
||||
document.getElementById("expression-holder").style.left = '';
|
||||
@ -960,23 +985,6 @@ function resetMovablePanels() {
|
||||
$(".zoomed_avatar").css('margin', '');
|
||||
}
|
||||
|
||||
|
||||
document.getElementById("WorldInfo").style.top = '';
|
||||
document.getElementById("WorldInfo").style.left = '';
|
||||
document.getElementById("WorldInfo").style.right = '';
|
||||
document.getElementById("WorldInfo").style.bottom = '';
|
||||
document.getElementById("WorldInfo").style.height = '';
|
||||
document.getElementById("WorldInfo").style.width = '';
|
||||
document.getElementById("WorldInfo").style.margin = '';
|
||||
|
||||
document.getElementById("floatingPrompt").style.top = '';
|
||||
document.getElementById("floatingPrompt").style.left = '';
|
||||
document.getElementById("floatingPrompt").style.right = '';
|
||||
document.getElementById("floatingPrompt").style.bottom = '';
|
||||
document.getElementById("floatingPrompt").style.height = '';
|
||||
document.getElementById("floatingPrompt").style.width = '';
|
||||
document.getElementById("floatingPrompt").style.margin = '';
|
||||
|
||||
$('*[data-dragged="true"]').removeAttr('data-dragged');
|
||||
power_user.movingUIState = {}
|
||||
saveSettingsDebounced();
|
||||
|
@ -1370,4 +1370,21 @@ jQuery(() => {
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$("#world_info").on('mousewheel', function (e) {
|
||||
e.preventDefault();
|
||||
if ($(this).is(':animated')) {
|
||||
return; //dont force multiple scroll animations
|
||||
}
|
||||
var wheelDelta = e.originalEvent.wheelDelta.toFixed(0);
|
||||
var DeltaPosNeg = (wheelDelta >= 0) ? 1 : -1; //determine if scrolling up or down
|
||||
var containerHeight = $(this).height().toFixed(0);
|
||||
var optionHeight = $(this).find('option').first().height().toFixed(0);
|
||||
var visibleOptions = (containerHeight / optionHeight).toFixed(0); //how many options we can see
|
||||
var pixelsToScroll = (optionHeight * visibleOptions * DeltaPosNeg).toFixed(0); //scroll a full container height
|
||||
var scrollTop = ($(this).scrollTop() - pixelsToScroll).toFixed(0);
|
||||
|
||||
$(this).animate({ scrollTop: scrollTop }, 200);
|
||||
});
|
||||
|
||||
})
|
||||
|
Reference in New Issue
Block a user