diff --git a/dist/basicModal.min.js b/dist/basicModal.min.js index f366ba1..1b03d3e 100644 --- a/dist/basicModal.min.js +++ b/dist/basicModal.min.js @@ -1 +1 @@ -!function(t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).basicModal=t()}(function(){return function o(a,c,i){function l(n,t){if(!c[n]){if(!a[n]){var e="function"==typeof require&&require;if(!t&&e)return e(n,!0);if(s)return s(n,!0);throw(t=new Error("Cannot find module '"+n+"'")).code="MODULE_NOT_FOUND",t}e=c[n]={exports:{}},a[n][0].call(e.exports,function(t){return l(a[n][1][t]||t)},e,e.exports,o,a,c,i)}return c[n].exports}for(var s="function"==typeof require&&require,t=0;tt.length)&&(n=t.length);for(var e=0,o=new Array(n);e'):(B.cancelButton=B.dialogButtons.appendChild(document.createElement("a")),B.cancelButton.textContent=e.buttons.cancel.title),B.cancelButton.id="basicModal__cancel",B.cancelButton.classList.add("basicModal__button"),(o=B.cancelButton.classList).add.apply(o,b(e.buttons.cancel.classList));for(var c=0,i=Object.entries(e.buttons.cancel.attributes);ct.length)&&(n=t.length);for(var e=0,o=new Array(n);e'):(B.cancelButton=B.dialogButtons.appendChild(document.createElement("a")),B.cancelButton.textContent=e.buttons.cancel.title),B.cancelButton.id="basicModal__cancel",B.cancelButton.classList.add("basicModal__button"),(o=B.cancelButton.classList).add.apply(o,b(e.buttons.cancel.classList));for(var c=0,i=Object.entries(e.buttons.cancel.attributes);c", "The Lychee Organization" diff --git a/src/scripts/main.js b/src/scripts/main.js index ffe795d..58f1516 100644 --- a/src/scripts/main.js +++ b/src/scripts/main.js @@ -466,11 +466,23 @@ export const show = function(confData) { // Bind elements bind(confData); + // Execute ready callback when available + if (confData.readyCB) confData.readyCB(_dom.namedFormElements, _dom.dialogContent); + + // Make dialog visible _after_ the dialog has been initialized by the + // callback. + document.body.appendChild(_dom.container); + + // Focus the first suitable element + // Note: Focussing only works _after_ the dialog has become part of the + // DOM and became visible if (_dom.inputElements.length !== 0) { - // Select the first input when available + // Focus the first input and select all text when available + _dom.inputElements.item(0).focus(); _dom.inputElements.item(0).select(); } else if (_dom.textAreaElements.length !== 0) { - // If there is no input element but a text area, select it + // If there is no input element but a text area, focus it and select all text in it + _dom.textAreaElements.item(0).focus(); _dom.textAreaElements.item(0).select(); } else if (_dom.selectElements.length !== 0) { // If there is neither an input nor a text area element but a select element, select it @@ -482,13 +494,6 @@ export const show = function(confData) { // If there is no input/select/action but a cancel button, select it _dom.cancelButton.focus(); } - - // Execute ready callback when available - if (confData.readyCB) confData.readyCB(_dom.namedFormElements, _dom.dialogContent); - - // Make dialog visible _after_ the dialog has been initialized by the - // callback. - document.body.appendChild(_dom.container); }