diff options
Diffstat (limited to 'javascript')
-rw-r--r-- | javascript/hints.js | 1 | ||||
-rw-r--r-- | javascript/ui.js | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/javascript/hints.js b/javascript/hints.js index 623bc25c..04ec67fb 100644 --- a/javascript/hints.js +++ b/javascript/hints.js @@ -17,6 +17,7 @@ titles = { "\u2199\ufe0f": "Read generation parameters from prompt or last generation if prompt is empty into user interface.", "\u{1f4c2}": "Open images output directory", "\u{1f4be}": "Save style", + "\U0001F5D1": "Clear prompt" "\u{1f4cb}": "Apply selected styles to current prompt", "Inpaint a part of image": "Draw a mask over an image, and the script will regenerate the masked area with content according to prompt", diff --git a/javascript/ui.js b/javascript/ui.js index 7e116465..00e80fd6 100644 --- a/javascript/ui.js +++ b/javascript/ui.js @@ -131,6 +131,46 @@ function ask_for_style_name(_, prompt_text, negative_prompt_text) { return [name_, prompt_text, negative_prompt_text] } +// returns css id for currently selected tab in ui +function selected_tab_id() { + tabs = gradioApp().querySelectorAll('#tabs div.tabitem') + + for(var tab = 0; tab < tabs.length; tab++) { + if (tabs[tab].style.display != "none") return tabs[tab].id + + } + +} + +function clear_prompt() { + +if(confirm("Delete prompt?")) { + + let pos_prompt = gradioApp().querySelector("#txt2img_prompt > label > textarea"); + let neg_prompt = gradioApp().querySelector("#txt2img_neg_prompt > label > textarea"); + + if (selected_tab_id() == "tab_txt2img") { + } else { + pos_prompt = gradioApp().querySelector("#img2img_prompt > label > textarea"); + neg_prompt = gradioApp().querySelector("#img2img_neg_prompt > label > textarea"); + } + + pos_prompt.value = "" + neg_prompt.value = "" + + //update prompt values on server-side + pos_prompt.dispatchEvent( + new Event("input", {bubbles: true}) + ) + neg_prompt.dispatchEvent( + new Event("input", {bubbles: true}) + ) + + return true +} else return false + +} + opts = {} |