MCPcopy Index your code
hub / github.com/easydiffusion/easydiffusion / createButton

Function createButton

ui/media/js/main.js:560–605  ·  view source on GitHub ↗
(btnInfo)

Source from the content-addressed store, hash-verified

558 redoBuffer: imageRedoBuffer,
559 }
560 const createButton = function (btnInfo) {
561 if (Array.isArray(btnInfo)) {
562 const wrapper = document.createElement("div")
563 btnInfo.map(createButton).forEach((buttonElement) => wrapper.appendChild(buttonElement))
564 return wrapper
565 }
566
567 const isLabel = btnInfo.type === "label"
568
569 const newButton = document.createElement(isLabel ? "span" : "button")
570 newButton.classList.add("tasksBtns")
571
572 if (btnInfo.html) {
573 const html = typeof btnInfo.html === "function" ? btnInfo.html() : btnInfo.html
574 if (html instanceof HTMLElement) {
575 newButton.appendChild(html)
576 } else {
577 newButton.innerHTML = html
578 }
579 } else {
580 newButton.innerText = typeof btnInfo.text === "function" ? btnInfo.text() : btnInfo.text
581 }
582
583 if (btnInfo.on_click || !isLabel) {
584 newButton.addEventListener("click", function (event) {
585 btnInfo.on_click.bind(newButton)(req, img, event, tools)
586 })
587 if (btnInfo.on_click === onUndoFilter) {
588 tools["undoButton"] = newButton
589 newButton.classList.add("displayNone")
590 }
591 if (btnInfo.on_click === onRedoFilter) {
592 tools["redoButton"] = newButton
593 newButton.classList.add("displayNone")
594 }
595 }
596
597 if (btnInfo.class !== undefined) {
598 if (Array.isArray(btnInfo.class)) {
599 newButton.classList.add(...btnInfo.class)
600 } else {
601 newButton.classList.add(btnInfo.class)
602 }
603 }
604 return newButton
605 }
606 buttons.forEach((btn) => {
607 if (Array.isArray(btn)) {
608 btn = btn.filter((btnInfo) => !btnInfo.filter || btnInfo.filter(req, img) === true)

Callers 1

showImagesFunction · 0.85

Calls 4

appendChildMethod · 0.45
addMethod · 0.45
addEventListenerMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected