MCPcopy Create free account
hub / github.com/Comfy-Org/litegraph.js / createPanel

Method createPanel

src/LGraphCanvas.ts:7087–7276  ·  view source on GitHub ↗
(title: string, options: ICreatePanelOptions)

Source from the content-addressed store, hash-verified

7085 }
7086
7087 createPanel(title: string, options: ICreatePanelOptions) {
7088 options = options || {}
7089
7090 const ref_window = options.window || window
7091 // TODO: any kludge
7092 const root: any = document.createElement("div")
7093 root.className = "litegraph dialog"
7094 root.innerHTML = "<div class='dialog-header'><span class='dialog-title'></span></div><div class='dialog-content'></div><div style='display:none;' class='dialog-alt-content'></div><div class='dialog-footer'></div>"
7095 root.header = root.querySelector(".dialog-header")
7096
7097 if (options.width)
7098 root.style.width = options.width + (typeof options.width === "number" ? "px" : "")
7099 if (options.height)
7100 root.style.height = options.height + (typeof options.height === "number" ? "px" : "")
7101 if (options.closable) {
7102 const close = document.createElement("span")
7103 close.innerHTML = "&#10005;"
7104 close.classList.add("close")
7105 close.addEventListener("click", function () {
7106 root.close()
7107 })
7108 root.header.append(close)
7109 }
7110 root.title_element = root.querySelector(".dialog-title")
7111 root.title_element.textContent = title
7112 root.content = root.querySelector(".dialog-content")
7113 root.alt_content = root.querySelector(".dialog-alt-content")
7114 root.footer = root.querySelector(".dialog-footer")
7115
7116 root.close = function () {
7117 if (typeof root.onClose == "function") root.onClose()
7118 root.remove()
7119 this.remove()
7120 }
7121
7122 // function to swap panel content
7123 root.toggleAltContent = function (force: unknown) {
7124 let vTo: string
7125 let vAlt: string
7126 if (force !== undefined) {
7127 vTo = force ? "block" : "none"
7128 vAlt = force ? "none" : "block"
7129 } else {
7130 vTo = root.alt_content.style.display != "block" ? "block" : "none"
7131 vAlt = root.alt_content.style.display != "block" ? "none" : "block"
7132 }
7133 root.alt_content.style.display = vTo
7134 root.content.style.display = vAlt
7135 }
7136
7137 root.toggleFooterVisibility = function (force: unknown) {
7138 let vTo: string
7139 if (force !== undefined) {
7140 vTo = force ? "block" : "none"
7141 } else {
7142 vTo = root.footer.style.display != "block" ? "block" : "none"
7143 }
7144 root.footer.style.display = vTo

Callers 1

showShowNodePanelMethod · 0.95

Calls 5

addMethod · 0.80
addEventListenerMethod · 0.65
closeMethod · 0.65
removeMethod · 0.45

Tested by

no test coverage detected