From 79448f5fe701ec6cd4fa5a4a3212936c5ddefce3 Mon Sep 17 00:00:00 2001
From: city-unit <140349364+city-unit@users.noreply.github.com>
Date: Mon, 28 Aug 2023 00:49:20 -0400
Subject: [PATCH] Getting there, but it's not great.
---
public/css/toggle-dependent.css | 1 +
public/index.html | 6 ++
public/scripts/RossAscends-mods.js | 3 +
public/scripts/extensions/gallery/index.js | 98 ++++++++++++++++++----
public/style.css | 28 +++++++
5 files changed, 121 insertions(+), 15 deletions(-)
diff --git a/public/css/toggle-dependent.css b/public/css/toggle-dependent.css
index 45994d690..82ecfd7c3 100644
--- a/public/css/toggle-dependent.css
+++ b/public/css/toggle-dependent.css
@@ -348,6 +348,7 @@ body.movingUI #sheld,
body.movingUI .drawer-content,
body.movingUI #expression-holder,
body.movingUI .zoomed_avatar,
+body.movingUI .draggable,
body.movingUI #floatingPrompt,
body.movingUI #groupMemberListPopout {
resize: both;
diff --git a/public/index.html b/public/index.html
index ea91c7adc..ea25c341d 100644
--- a/public/index.html
+++ b/public/index.html
@@ -4341,6 +4341,12 @@
+
+
diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js
index 884f719cc..a7d8f2bfd 100644
--- a/public/scripts/RossAscends-mods.js
+++ b/public/scripts/RossAscends-mods.js
@@ -17,6 +17,7 @@ import {
getEntitiesList,
getThumbnailUrl,
selectCharacterById,
+ eventSource,
} from "../script.js";
import {
@@ -34,6 +35,7 @@ import { debounce, delay, getStringHash, waitUntilCondition } from "./utils.js";
import { chat_completion_sources, oai_settings } from "./openai.js";
import { getTokenCount } from "./tokenizers.js";
+
var RPanelPin = document.getElementById("rm_button_panel_pin");
var LPanelPin = document.getElementById("lm_button_panel_pin");
var WIPanelPin = document.getElementById("WI_panel_pin");
@@ -556,6 +558,7 @@ export function dragElement(elmnt) {
console.debug(`Saving ${elmntName} Height/Width`)
power_user.movingUIState[elmntName].width = width;
power_user.movingUIState[elmntName].height = height;
+ eventSource.emit('resizeUI', elmntName);
saveSettingsDebounced();
})
}
diff --git a/public/scripts/extensions/gallery/index.js b/public/scripts/extensions/gallery/index.js
index 49cc58718..63b0e6f38 100644
--- a/public/scripts/extensions/gallery/index.js
+++ b/public/scripts/extensions/gallery/index.js
@@ -7,11 +7,15 @@ import {
} from "../../../script.js";
import { selected_group } from "../../group-chats.js";
import { loadFileToDocument } from "../../utils.js";
+import { loadMovingUIState } from '../../power-user.js';
+import { dragElement } from '../../RossAscends-mods.js'
const extensionName = "gallery";
const extensionFolderPath = `scripts/extensions/${extensionName}/`;
let firstTime = true;
+// TODO:Some user wanted the gallery to be detachable / movable.For hmm, good chatting experience.I think it's easy to make any block movable with Ross's function, you need to check this out.
+// TODO:Haven't seen any guidance on how to populate the gallery in-app still.
/**
@@ -44,18 +48,41 @@ async function getGalleryItems(url) {
* @returns {Promise} - Promise representing the completion of the gallery initialization.
*/
async function initGallery(items, url) {
- $("#my-gallery").nanogallery2({
- items: items,
+ $("#zoomFor_test").nanogallery2({
+ "items": items,
+ thumbnailWidth: 'auto',
thumbnailHeight: 150,
- thumbnailWidth: 150,
+ paginationVisiblePages: 5,
+ paginationMaxLinesPerPage: 2,
+ galleryMaxRows : 3,
+ "galleryDisplayMode": "pagination",
+ "fnThumbnailOpen": viewWithFancybox,
});
+ $(document).ready(function () {
+ $('.nGY2GThumbnailImage').on('click', function () {
+ let imageUrl = $(this).find('.nGY2GThumbnailImg').attr('src');
+ // Do what you want with the imageUrl, for example:
+ // Display it in a full-size view or replace the gallery grid content with this image
+ console.log(imageUrl);
+ });
+ });
+
+ eventSource.on('resizeUI', function (elmntName) {
+ console.log('resizeUI saw', elmntName);
+ // Your logic here
+
+ // If you want to resize the nanogallery2 instance when this event is triggered:
+ jQuery("#zoomFor_test").nanogallery2('resize');
+ });
+
+
// Initialize dropzone handlers
- const dropZone = $('#dialogue_popup');
+ const dropZone = $('#zoomFor_test');
dropZone.on('dragover', function (e) {
e.stopPropagation(); // Ensure this event doesn't propagate
e.preventDefault();
- $(this).addClass('dragging'); // Add a CSS class to change appearance during drag-over
+ $(this).addClass('dragging'); // Add a CSS class to change appearance during drag-over
});
dropZone.on('dragleave', function (e) {
@@ -106,8 +133,8 @@ async function showCharGallery() {
}
const items = await getGalleryItems(url);
-
- let close = callPopup('', "text");
+ makeMovable();
+ let close = callPopup('', "text");
console.log("close", close);
if ($("body").css("position") === "fixed") {
$("body").css("position", "static");
@@ -117,14 +144,17 @@ async function showCharGallery() {
await initGallery(items, url);
}, 100);
- close.then(() => {
- $("#my-gallery").nanogallery2("destroy");
- if ($("body").css("position") === "static") {
- $("body").css("position", "fixed");
- }
- const dropZone = $('#dialogue_popup');
- dropZone.off('dragover dragleave drop');
- });
+ //next, we add `` to zoomFor_test
+ document.getElementById(`zoomFor_test`).innerHTML += ``;
+
+ // close.then(() => {
+ // $("#my-gallery").nanogallery2("destroy");
+ // if ($("body").css("position") === "static") {
+ // $("body").css("position", "fixed");
+ // }
+ // const dropZone = $('#dialogue_popup');
+ // dropZone.off('dragover dragleave drop');
+ // });
} catch (err) {
console.error(err);
}
@@ -207,3 +237,41 @@ $(document).ready(function () {
})
);
});
+
+function makeMovable(){
+
+ let charname = "gallery"
+
+ console.debug('making new container from template')
+ const template = $('#generic_draggable_template').html();
+ const newElement = $(template);
+ newElement.attr('forChar', charname);
+ newElement.attr('id', `zoomFor_${charname}`);
+ newElement.find('.drag-grabber').attr('id', `zoomFor_${charname}header`);
+ //add a div for the gallery
+ newElement.append(``);
+ // add no-scrollbar class to this element
+ newElement.addClass('no-scrollbar');
+
+
+ $(`#zoomFor_test`).css('display', 'block');
+
+ $('body').append(newElement);
+
+ loadMovingUIState();
+ $(`.draggable[forChar="${charname}"]`).css('display', 'block');
+ dragElement(newElement);
+
+ $(`.draggable[forChar="${charname}"] img`).on('dragstart', (e) => {
+ console.log('saw drag on avatar!');
+ e.preventDefault();
+ return false;
+ });
+}
+
+function viewWithFancybox(items) {
+ if (items && items.length > 0) {
+ var url = items[0].responsiveURL(); // Get the URL of the clicked image/video
+ window.open(url, '_blank'); // Open the URL in a new window/tab
+ }
+}
diff --git a/public/style.css b/public/style.css
index 3bc531046..9003a39a1 100644
--- a/public/style.css
+++ b/public/style.css
@@ -3406,6 +3406,34 @@ a {
border-radius: 10px;
}
+.draggable {
+ min-width: 100px;
+ min-height: 100px;
+ max-height: 90vh;
+ max-width: 90vh;
+ width: calc((100vw - var(--sheldWidth)) /2);
+ position: absolute;
+ padding: 0;
+ filter: drop-shadow(2px 2px 2px var(--grey7070a));
+ z-index: 29;
+ overflow: hidden;
+ display: none;
+ bottom: 0;
+ aspect-ratio: 2 / 3;
+ border-radius: 10px;
+}
+
+/* Hide scrollbar for Chrome, Safari and Opera */
+.no-scrollbar::-webkit-scrollbar {
+ display: none;
+}
+
+/* Hide scrollbar for IE, Edge, and Firefox */
+.no-scrollbar {
+ -ms-overflow-style: none; /* IE and Edge */
+ scrollbar-width: none; /* Firefox */
+}
+
#groupMemberListPopoutClose {
height: 15px;
aspect-ratio: 1 / 1;