Merge pull request #15331 from AUTOMATIC1111/extra-networks-buttons

Fix extra networks buttons when filename contains an apostrophe
This commit is contained in:
AUTOMATIC1111 2024-03-20 06:53:55 +03:00 committed by GitHub
commit 060e55dfe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 12 additions and 11 deletions

View File

@ -1,5 +1,5 @@
<div class="copy-path-button card-button" <div class="copy-path-button card-button"
title="Copy path to clipboard" title="Copy path to clipboard"
onclick='extraNetworksCopyCardPath(event, {filename})' onclick="extraNetworksCopyCardPath(event)"
data-clipboard-text={filename}> data-clipboard-text="{filename}">
</div> </div>

View File

@ -1,4 +1,4 @@
<div class="edit-button card-button" <div class="edit-button card-button"
title="Edit metadata" title="Edit metadata"
onclick="extraNetworksEditUserMetadata(event, '{tabname}', '{extra_networks_tabname}', '{name}')"> onclick="extraNetworksEditUserMetadata(event, '{tabname}', '{extra_networks_tabname}')">
</div> </div>

View File

@ -1,4 +1,4 @@
<div class="metadata-button card-button" <div class="metadata-button card-button"
title="Show internal metadata" title="Show internal metadata"
onclick="extraNetworksRequestMetadata(event, '{extra_networks_tabname}', '{name}')"> onclick="extraNetworksRequestMetadata(event, '{extra_networks_tabname}')">
</div> </div>

View File

@ -605,16 +605,18 @@ function requestGet(url, data, handler, errorHandler) {
xhr.send(js); xhr.send(js);
} }
function extraNetworksCopyCardPath(event, path) { function extraNetworksCopyCardPath(event) {
navigator.clipboard.writeText(path); navigator.clipboard.writeText(event.target.getAttribute("data-clipboard-text"));
event.stopPropagation(); event.stopPropagation();
} }
function extraNetworksRequestMetadata(event, extraPage, cardName) { function extraNetworksRequestMetadata(event, extraPage) {
var showError = function() { var showError = function() {
extraNetworksShowMetadata("there was an error getting metadata"); extraNetworksShowMetadata("there was an error getting metadata");
}; };
var cardName = event.target.parentElement.parentElement.getAttribute("data-name");
requestGet("./sd_extra_networks/metadata", {page: extraPage, item: cardName}, function(data) { requestGet("./sd_extra_networks/metadata", {page: extraPage, item: cardName}, function(data) {
if (data && data.metadata) { if (data && data.metadata) {
extraNetworksShowMetadata(data.metadata); extraNetworksShowMetadata(data.metadata);
@ -628,7 +630,7 @@ function extraNetworksRequestMetadata(event, extraPage, cardName) {
var extraPageUserMetadataEditors = {}; var extraPageUserMetadataEditors = {};
function extraNetworksEditUserMetadata(event, tabname, extraPage, cardName) { function extraNetworksEditUserMetadata(event, tabname, extraPage) {
var id = tabname + '_' + extraPage + '_edit_user_metadata'; var id = tabname + '_' + extraPage + '_edit_user_metadata';
var editor = extraPageUserMetadataEditors[id]; var editor = extraPageUserMetadataEditors[id];
@ -640,6 +642,7 @@ function extraNetworksEditUserMetadata(event, tabname, extraPage, cardName) {
extraPageUserMetadataEditors[id] = editor; extraPageUserMetadataEditors[id] = editor;
} }
var cardName = event.target.parentElement.parentElement.getAttribute("data-name");
editor.nameTextarea.value = cardName; editor.nameTextarea.value = cardName;
updateInput(editor.nameTextarea); updateInput(editor.nameTextarea);

View File

@ -239,21 +239,19 @@ class ExtraNetworksPage:
) )
onclick = html.escape(onclick) onclick = html.escape(onclick)
btn_copy_path = self.btn_copy_path_tpl.format(**{"filename": quote_js(item["filename"])}) btn_copy_path = self.btn_copy_path_tpl.format(**{"filename": item["filename"]})
btn_metadata = "" btn_metadata = ""
metadata = item.get("metadata") metadata = item.get("metadata")
if metadata: if metadata:
btn_metadata = self.btn_metadata_tpl.format( btn_metadata = self.btn_metadata_tpl.format(
**{ **{
"extra_networks_tabname": self.extra_networks_tabname, "extra_networks_tabname": self.extra_networks_tabname,
"name": html.escape(item["name"]),
} }
) )
btn_edit_item = self.btn_edit_item_tpl.format( btn_edit_item = self.btn_edit_item_tpl.format(
**{ **{
"tabname": tabname, "tabname": tabname,
"extra_networks_tabname": self.extra_networks_tabname, "extra_networks_tabname": self.extra_networks_tabname,
"name": html.escape(item["name"]),
} }
) )