* @param {() => (string | ImageModalRequest) | string | ImageModalRequest} optionsFactory
(optionsFactory)
| 142 | * @param {() => (string | ImageModalRequest) | string | ImageModalRequest} optionsFactory |
| 143 | */ |
| 144 | function init(optionsFactory) { |
| 145 | if (!optionsFactory) { |
| 146 | close() |
| 147 | return |
| 148 | } |
| 149 | |
| 150 | clear() |
| 151 | |
| 152 | const options = typeof optionsFactory === "function" ? optionsFactory() : optionsFactory |
| 153 | const src = typeof options === "string" ? options : options.src |
| 154 | |
| 155 | const imgElem = createElement("img", { src }, "natural-zoom") |
| 156 | addImageGrabbing(imgElem) |
| 157 | imageContainer.appendChild(imgElem) |
| 158 | modalElem.classList.add("active") |
| 159 | document.body.style.overflow = "hidden" |
| 160 | setZoomLevel(false) |
| 161 | |
| 162 | if (typeof options === "object" && options.previous) { |
| 163 | state.previous = options.previous |
| 164 | backElem.style.display = "unset" |
| 165 | } else { |
| 166 | backElem.style.display = "none" |
| 167 | } |
| 168 | |
| 169 | if (typeof options === "object" && options.next) { |
| 170 | state.next = options.next |
| 171 | forwardElem.style.display = "unset" |
| 172 | } else { |
| 173 | forwardElem.style.display = "none" |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | const back = () => { |
| 178 | if (state.previous) { |
no test coverage detected