mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Unique img ids, comments
This commit is contained in:
@ -55,8 +55,10 @@ async function initGallery(items, url) {
|
|||||||
paginationVisiblePages: 5,
|
paginationVisiblePages: 5,
|
||||||
paginationMaxLinesPerPage: 2,
|
paginationMaxLinesPerPage: 2,
|
||||||
galleryMaxRows : 3,
|
galleryMaxRows : 3,
|
||||||
|
galleryPaginationTopButtons: false,
|
||||||
|
galleryNavigationOverlayButtons: true,
|
||||||
"galleryDisplayMode": "pagination",
|
"galleryDisplayMode": "pagination",
|
||||||
"fnThumbnailOpen": viewWithFancybox,
|
"fnThumbnailOpen": viewWithDragbox,
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
@ -237,6 +239,12 @@ $(document).ready(function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new draggable container based on a template.
|
||||||
|
* This function takes a template with the ID 'generic_draggable_template' and clones it.
|
||||||
|
* The cloned element has its attributes set, a new child div appended, and is made visible on the body.
|
||||||
|
* Additionally, it sets up the element to prevent dragging on its images.
|
||||||
|
*/
|
||||||
function makeMovable(){
|
function makeMovable(){
|
||||||
|
|
||||||
let charname = "gallery"
|
let charname = "gallery"
|
||||||
@ -268,6 +276,17 @@ function makeMovable(){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new draggable image based on a template.
|
||||||
|
*
|
||||||
|
* This function clones a provided template with the ID 'generic_draggable_template',
|
||||||
|
* appends the given image URL, ensures the element has a unique ID,
|
||||||
|
* and attaches the element to the body. After appending, it also prevents
|
||||||
|
* dragging on the appended image.
|
||||||
|
*
|
||||||
|
* @param {string} id - A base identifier for the new draggable element.
|
||||||
|
* @param {string} url - The URL of the image to be added to the draggable element.
|
||||||
|
*/
|
||||||
function makeDragImg(id, url) {
|
function makeDragImg(id, url) {
|
||||||
// Step 1: Clone the template content
|
// Step 1: Clone the template content
|
||||||
const template = document.getElementById('generic_draggable_template');
|
const template = document.getElementById('generic_draggable_template');
|
||||||
@ -282,21 +301,27 @@ function makeDragImg(id, url) {
|
|||||||
// Step 2: Append the given image
|
// Step 2: Append the given image
|
||||||
const imgElem = document.createElement('img');
|
const imgElem = document.createElement('img');
|
||||||
imgElem.src = url;
|
imgElem.src = url;
|
||||||
|
let uniqueId = `draggable_${id}`;
|
||||||
const draggableElem = newElement.querySelector('.draggable');
|
const draggableElem = newElement.querySelector('.draggable');
|
||||||
if (draggableElem) {
|
if (draggableElem) {
|
||||||
draggableElem.appendChild(imgElem);
|
draggableElem.appendChild(imgElem);
|
||||||
|
|
||||||
// Set a unique id for the draggable element
|
// Find a unique id for the draggable element
|
||||||
draggableElem.id = `draggable_${id}`;
|
|
||||||
|
let counter = 1;
|
||||||
|
while (document.getElementById(uniqueId)) {
|
||||||
|
uniqueId = `draggable_${id}_${counter}`;
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
draggableElem.id = uniqueId;
|
||||||
|
|
||||||
// Ensure that the newly added element is displayed as block
|
// Ensure that the newly added element is displayed as block
|
||||||
draggableElem.style.display = 'block';
|
draggableElem.style.display = 'block';
|
||||||
|
|
||||||
// Find the .drag-grabber and set its ID
|
// Find the .drag-grabber and set its matching unique ID
|
||||||
const dragGrabber = draggableElem.querySelector('.drag-grabber');
|
const dragGrabber = draggableElem.querySelector('.drag-grabber');
|
||||||
if (dragGrabber) {
|
if (dragGrabber) {
|
||||||
dragGrabber.id = `draggable_${id}header`;
|
dragGrabber.id = `${uniqueId}header`; // appending _header to make it match the parent's unique ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,16 +329,14 @@ function makeDragImg(id, url) {
|
|||||||
document.body.appendChild(newElement);
|
document.body.appendChild(newElement);
|
||||||
|
|
||||||
// Step 4: Call dragElement and loadMovingUIState
|
// Step 4: Call dragElement and loadMovingUIState
|
||||||
const appendedElement = document.getElementById(`draggable_${id}`);
|
const appendedElement = document.getElementById(uniqueId);
|
||||||
if (appendedElement) {
|
if (appendedElement) {
|
||||||
var elmntName = $(appendedElement);
|
var elmntName = $(appendedElement);
|
||||||
loadMovingUIState();
|
loadMovingUIState();
|
||||||
dragElement(elmntName);
|
dragElement(elmntName);
|
||||||
|
|
||||||
|
|
||||||
// Prevent dragging the image
|
// Prevent dragging the image
|
||||||
console.log(`#draggable_${id} img`);
|
$(`#${uniqueId} img`).on('dragstart', (e) => {
|
||||||
$(`#draggable_${id} img`).on('dragstart', (e) => {
|
|
||||||
console.log('saw drag on avatar!');
|
console.log('saw drag on avatar!');
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
@ -324,7 +347,16 @@ function makeDragImg(id, url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function viewWithFancybox(items) {
|
/**
|
||||||
|
* Processes a list of items (containing URLs) and creates a draggable box for the first item.
|
||||||
|
*
|
||||||
|
* If the provided list of items is non-empty, it takes the URL of the first item,
|
||||||
|
* derives an ID from the URL, and uses the makeDragImg function to create
|
||||||
|
* a draggable image element based on that ID and URL.
|
||||||
|
*
|
||||||
|
* @param {Array} items - A list of items where each item has a responsiveURL method that returns a URL.
|
||||||
|
*/
|
||||||
|
function viewWithDragbox(items) {
|
||||||
if (items && items.length > 0) {
|
if (items && items.length > 0) {
|
||||||
var url = items[0].responsiveURL(); // Get the URL of the clicked image/video
|
var url = items[0].responsiveURL(); // Get the URL of the clicked image/video
|
||||||
// ID should just be the last part of the URL, removing the extension
|
// ID should just be the last part of the URL, removing the extension
|
||||||
|
Reference in New Issue
Block a user