(options)
| 193 | |
| 194 | //creates input box |
| 195 | function promptCreateInput(options) { |
| 196 | const dataElement = document.createElement("input"); |
| 197 | dataElement.setAttribute("type", "text"); |
| 198 | |
| 199 | dataElement.value = options.value ?? ""; |
| 200 | |
| 201 | //insert custom input attributes if in options |
| 202 | if (options.inputAttrs && typeof options.inputAttrs === "object") { |
| 203 | for (const k in options.inputAttrs) { |
| 204 | if (!Object.prototype.hasOwnProperty.call(options.inputAttrs, k)) { |
| 205 | continue; |
| 206 | } |
| 207 | |
| 208 | dataElement.setAttribute(k, options.inputAttrs[k]); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | //Cancel/Exit on 'Escape' |
| 213 | dataElement.addEventListener("keyup", (event) => { |
| 214 | if (event.key === "Escape") { |
| 215 | promptCancel(); |
| 216 | } |
| 217 | }); |
| 218 | |
| 219 | //Confirm on 'Enter' |
| 220 | dataElement.addEventListener("keypress", (event) => { |
| 221 | if (event.key === "Enter") { |
| 222 | event.preventDefault(); |
| 223 | $("#ok").click(); |
| 224 | } |
| 225 | }); |
| 226 | |
| 227 | return dataElement; |
| 228 | } |
| 229 | |
| 230 | //add many inputs to container element |
| 231 | function promptCreateMultiInput(parentElement) { |
no test coverage detected