diff --git a/extensions-builtin/anapnoe-sd-uiux/javascript/anapnoe_sd_uiux_core.js b/extensions-builtin/anapnoe-sd-uiux/javascript/anapnoe_sd_uiux_core.js index f33190c6..49ed4476 100644 --- a/extensions-builtin/anapnoe-sd-uiux/javascript/anapnoe_sd_uiux_core.js +++ b/extensions-builtin/anapnoe-sd-uiux/javascript/anapnoe_sd_uiux_core.js @@ -1,13 +1,13 @@ //var orig_all_gallery_buttons = window.all_gallery_buttons; -window.all_gallery_buttons = function(){ - //orig_all_gallery_buttons(); +window.all_gallery_buttons = function () { + //orig_all_gallery_buttons(); var tabitem = gradioApp().querySelector('#main-nav-bar button.active')?.getAttribute('tabitemid'); var visibleGalleryButtons = []; - if(tabitem){ + if (tabitem) { //console.log(tabitem, allGalleryButtons); - var allGalleryButtons = gradioApp().querySelectorAll(tabitem+' .gradio-gallery .thumbnails > .thumbnail-small'); - allGalleryButtons?.forEach(function(elem) { - if (elem.parentElement.offsetParent && elem.parentElement.offsetParent !== document.body) { + var allGalleryButtons = gradioApp().querySelectorAll(tabitem + ' .gradio-gallery .thumbnails > .thumbnail-small'); + allGalleryButtons?.forEach(function (elem) { + if (elem.parentElement.offsetParent && elem.parentElement.offsetParent !== document.body) { visibleGalleryButtons.push(elem); } }); @@ -15,75 +15,75 @@ window.all_gallery_buttons = function(){ return visibleGalleryButtons; } -window.extraNetworksSearchButton = function(tabname, extra_networks_tabname, event) { - var attr = event.target.parentElement.parentElement.getAttribute("search-field"); +window.extraNetworksSearchButton = function (tabname, extra_networks_tabname, event) { + var attr = event.target.parentElement.parentElement.getAttribute("search-field"); var searchTextarea = gradioApp().querySelector(attr); - var button = event.target; - var text = button.classList.contains("search-all") ? "" : button.textContent.trim(); + var button = event.target; + var text = button.classList.contains("search-all") ? "" : button.textContent.trim(); - searchTextarea.value = text; - window.updateInput(searchTextarea); + searchTextarea.value = text; + window.updateInput(searchTextarea); } -window.imageMaskResize = function(){ +window.imageMaskResize = function () { // override function empty we dont need any fix here } -window.extraNetworksEditUserMetadata = function(event, tabname, extraPage) { +window.extraNetworksEditUserMetadata = function (event, tabname, extraPage) { var tid = 'txt2img_' + extraPage + '_edit_user_metadata'; - var editor = extraPageUserMetadataEditors[tid]; - if (!editor) { - editor = {}; - editor.page = gradioApp().getElementById(tid); - editor.nameTextarea = gradioApp().querySelector("#" + tid + "_name" + ' textarea'); - editor.button = gradioApp().querySelector("#" + tid + "_button"); - extraPageUserMetadataEditors[tid] = editor; - } - var cardName = event.target.parentElement.parentElement.getAttribute("data-name"); - if(!cardName){ + var editor = extraPageUserMetadataEditors[tid]; + if (!editor) { + editor = {}; + editor.page = gradioApp().getElementById(tid); + editor.nameTextarea = gradioApp().querySelector("#" + tid + "_name" + ' textarea'); + editor.button = gradioApp().querySelector("#" + tid + "_button"); + extraPageUserMetadataEditors[tid] = editor; + } + var cardName = event.target.parentElement.parentElement.getAttribute("data-name"); + if (!cardName) { cardName = event.target.parentElement.parentElement.parentElement.querySelector('.tree-list-item-label').innerHTML.trim(); } - editor.nameTextarea.value = cardName; - updateInput(editor.nameTextarea); - editor.button.click(); - popup(editor.page); - event.stopPropagation(); + editor.nameTextarea.value = cardName; + updateInput(editor.nameTextarea); + editor.button.click(); + popup(editor.page); + event.stopPropagation(); } -window.get_uiCurrentTabContent = function(){ - //console.log(active_main_tab); - if(active_main_tab.id === "tab_txt2img"){ - return document.getElementById("txt2img_tabitem"); - }else if(active_main_tab.id === "tab_img2img"){ - return document.getElementById("img2img_tabitem"); - } +window.get_uiCurrentTabContent = function () { + //console.log(active_main_tab); + if (active_main_tab.id === "tab_txt2img") { + return document.getElementById("txt2img_tabitem"); + } else if (active_main_tab.id === "tab_img2img") { + return document.getElementById("img2img_tabitem"); + } } -async function getContributors(repoName, page = 1) { - let request = await fetch(`https://api.github.com/repos/${repoName}/contributors?per_page=100&page=${page}`, { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - } - }); +async function getContributors(repoName, page = 1) { + let request = await fetch(`https://api.github.com/repos/${repoName}/contributors?per_page=100&page=${page}`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + } + }); - // print data from the fetch on screen - let contributorsList = await request.json(); - return contributorsList; + // print data from the fetch on screen + let contributorsList = await request.json(); + return contributorsList; } async function getAllContributorsRecursive(repoName, page = 1, allContributors = []) { - const list = await getContributors(repoName, page); - allContributors = allContributors.concat(list); + const list = await getContributors(repoName, page); + allContributors = allContributors.concat(list); - if (list.length === 100) { - return getAllContributorsRecursive(repoName, page + 1, allContributors); - } + if (list.length === 100) { + return getAllContributorsRecursive(repoName, page + 1, allContributors); + } - // The base case: when the list is empty, return allContributors - return allContributors; + // The base case: when the list is empty, return allContributors + return allContributors; } - + localStorage.setItem('UiUxReady', "false"); localStorage.setItem('UiUxComplete', "false"); const default_ext_path = './file=extensions-builtin/anapnoe-sd-uiux/html/templates/'; @@ -95,76 +95,76 @@ const split_instances = []; const anapnoe_app_id = "#anapnoe_app"; function detectMobile() { - return ( ( window.innerWidth <= 768 ) );//&& ( window.innerHeight <= 600 ) ); + return ((window.innerWidth <= 768));//&& ( window.innerHeight <= 600 ) ); } /* function debounce(func){ - var timer; - return function(event){ - if(timer) clearTimeout(timer); - timer = setTimeout(func,100,event); - }; + var timer; + return function(event){ + if(timer) clearTimeout(timer); + timer = setTimeout(func,100,event); + }; } */ -function applyDefaultLayout(isMobile){ - anapnoe_app.querySelectorAll("[mobile]").forEach((tabItem) => { - //console.log(tabItem); - if(isMobile){ - if(tabItem.childElementCount === 0){ - const mobile_attr = tabItem.getAttribute("mobile"); - if(mobile_attr){ - const mobile_target = anapnoe_app.querySelector(mobile_attr); - if(mobile_target){ - tabItem.setAttribute("mobile-restore", `#${mobile_target.parentElement.id}`); - tabItem.append(mobile_target); - - } - } - } - }else{ - if(tabItem.childElementCount > 0){ - const mobile_restore_attr = tabItem.getAttribute("mobile-restore"); - if(mobile_restore_attr){ - const mobile_restore_target = anapnoe_app.querySelector(mobile_restore_attr); - if(mobile_restore_target){ - mobile_restore_target.append(tabItem.firstElementChild); - } - } - } - } - }); +function applyDefaultLayout(isMobile) { + anapnoe_app.querySelectorAll("[mobile]").forEach((tabItem) => { + //console.log(tabItem); + if (isMobile) { + if (tabItem.childElementCount === 0) { + const mobile_attr = tabItem.getAttribute("mobile"); + if (mobile_attr) { + const mobile_target = anapnoe_app.querySelector(mobile_attr); + if (mobile_target) { + tabItem.setAttribute("mobile-restore", `#${mobile_target.parentElement.id}`); + tabItem.append(mobile_target); - if(isMobile){ - anapnoe_app.querySelector(".accordion-vertical.expand #mask-icon-acc-arrow")?.click(); - anapnoe_app.classList.add("default-mobile"); - }else{ - anapnoe_app.classList.remove("default-mobile"); - } + } + } + } + } else { + if (tabItem.childElementCount > 0) { + const mobile_restore_attr = tabItem.getAttribute("mobile-restore"); + if (mobile_restore_attr) { + const mobile_restore_target = anapnoe_app.querySelector(mobile_restore_attr); + if (mobile_restore_target) { + mobile_restore_target.append(tabItem.firstElementChild); + } + } + } + } + }); + + if (isMobile) { + anapnoe_app.querySelector(".accordion-vertical.expand #mask-icon-acc-arrow")?.click(); + anapnoe_app.classList.add("default-mobile"); + } else { + anapnoe_app.classList.remove("default-mobile"); + } } -function switchMobile(){ - const optslayout = window.opts.uiux_default_layout; - //console.log(optslayout); - anapnoe_app.classList.add(`default-${optslayout.toLowerCase()}`); - if(optslayout === "Auto"){ - /* - window.addEventListener("resize", debounce(function(e){ - const isMobile = detectMobile(); - applyDefaultLayout(isMobile); - })); - */ - window.addEventListener('resize', function(event){ - const isMobile = detectMobile(); - applyDefaultLayout(isMobile); - }); - applyDefaultLayout(detectMobile()); +function switchMobile() { + const optslayout = window.opts.uiux_default_layout; + //console.log(optslayout); + anapnoe_app.classList.add(`default-${optslayout.toLowerCase()}`); + if (optslayout === "Auto") { + /* + window.addEventListener("resize", debounce(function(e){ + const isMobile = detectMobile(); + applyDefaultLayout(isMobile); + })); + */ + window.addEventListener('resize', function (event) { + const isMobile = detectMobile(); + applyDefaultLayout(isMobile); + }); + applyDefaultLayout(detectMobile()); - }else if(optslayout === "Mobile"){ - applyDefaultLayout(true); - }else{ - applyDefaultLayout(false); - } + } else if (optslayout === "Mobile") { + applyDefaultLayout(true); + } else { + applyDefaultLayout(false); + } } @@ -174,11 +174,11 @@ function getRootContainer() { } function mainTabs(element, tab) { - if(active_main_tab){ + if (active_main_tab) { active_main_tab.style.display = 'none'; } const ntab = document.querySelector(tab); - if(ntab){ + if (ntab) { ntab.style.display = 'block'; //console.log(tab, ntab); active_main_tab = ntab; @@ -189,7 +189,7 @@ function setAttrSelector(parent_elem, content_div, count, index, length) { //const t = parent_elem.getAttribute("data-timeout"); //const delay = t ? parseInt(t) : 0; - + //setTimeout(() => { const mcount = count % 2; @@ -197,10 +197,10 @@ function setAttrSelector(parent_elem, content_div, count, index, length) { const s = parent_elem.getAttribute("data-selector"); const sp = parent_elem.getAttribute("data-parent-selector"); - + let target_elem; - + switch (mcount) { case 0: target_elem = document.querySelector(`${sp} ${s}`); @@ -211,7 +211,7 @@ function setAttrSelector(parent_elem, content_div, count, index, length) { } if (target_elem && parent_elem) { - parent_elem.append(target_elem); + parent_elem.append(target_elem); total += 1; console.log("register | Ref", index, sp, s); const d = parent_elem.getAttribute('droppable'); @@ -223,12 +223,12 @@ function setAttrSelector(parent_elem, content_div, count, index, length) { //console.log("droppable", target_elem, parent_elem, childs); childs.forEach((c) => { if (c !== target_elem) { - if (target_elem.className.indexOf('gradio-accordion') !== -1) { - if(adx){ + if (target_elem.className.indexOf('gradio-accordion') !== -1) { + if (adx) { let idx = parseInt(adx, 10); let ebefore = target_elem.children[2].children[idx]; target_elem.children[2].insertBefore(c, ebefore); - }else{ + } else { target_elem.children[2].append(c); } } else { @@ -239,25 +239,25 @@ function setAttrSelector(parent_elem, content_div, count, index, length) { } const hb = parent_elem.getAttribute("show-button"); - if(hb){document.querySelector(hb)?.classList.remove("hidden");} + if (hb) { document.querySelector(hb)?.classList.remove("hidden"); } } else if (count < 4) { const t = parent_elem.getAttribute("data-timeout"); const delay = t ? parseInt(t) : 500; - + setTimeout(() => { - console.log( count + 1, "retry | ", delay, " | Ref", index, sp, s); + console.log(count + 1, "retry | ", delay, " | Ref", index, sp, s); setAttrSelector(parent_elem, content_div, count + 1, index, length); }, delay); } else { console.log("error | Ref", index, sp, s); - total += 1; + total += 1; } - if(total === length){ + if (total === length) { console.log("Runtime components initilized"); localStorage.setItem('UiUxReady', true); } @@ -266,10 +266,10 @@ function setAttrSelector(parent_elem, content_div, count, index, length) { } -function testpopup(){ +function testpopup() { const content_div = document.querySelector('#popup_tabitem'); //const meta_id = document.querySelector('.global-popup-inner > div')?.id; - content_div.querySelectorAll(`.portal`).forEach((el, index, array) => { + content_div.querySelectorAll(`.portal`).forEach((el, index, array) => { /* const childs = Array.from(el.children); childs.forEach((c) => { @@ -307,7 +307,7 @@ function createButtons4Extensions() { document.querySelectorAll(`#tabs > .tabitem`).forEach((c) => { const cid = c.id; const nid = cid.split('tab_')[1]; - if( cid !== "tab_txt2img" && + if (cid !== "tab_txt2img" && cid !== "tab_img2img" && cid !== "tab_extras" && cid !== "tab_pnginfo" && @@ -317,12 +317,10 @@ function createButtons4Extensions() { cid !== "tab_extensions" && cid !== "tab_ui_theme" && cid !== "tab_anapnoe_dock" && - cid !== "tab_anapnoe_sd_uiux_core") - - { + cid !== "tab_anapnoe_sd_uiux_core") { //tab_openpose_editor - const temp = document.createElement('div'); - temp.innerHTML= ` + const temp = document.createElement('div'); + temp.innerHTML = `