From 48cfc933c1488066af958a6e0407c8589690c151 Mon Sep 17 00:00:00 2001 From: Aleksey Kuznietsov Date: Thu, 7 Dec 2023 03:01:53 -0500 Subject: [PATCH 1/5] Handle clicks on the button child elements --- build/alertify.js | 2 +- src/js/dialog/actions.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/alertify.js b/build/alertify.js index 59763ac..61dff68 100644 --- a/build/alertify.js +++ b/build/alertify.js @@ -1297,7 +1297,7 @@ var target = event.srcElement || event.target; triggerCallback(instance, function (button) { // if this button caused the click, cancel keyup event - return button.element === target && (cancelKeyup = true); + return button.element.contains(target) && (cancelKeyup = true); }); } diff --git a/src/js/dialog/actions.js b/src/js/dialog/actions.js index 555600c..37a7d1a 100644 --- a/src/js/dialog/actions.js +++ b/src/js/dialog/actions.js @@ -41,7 +41,7 @@ var target = event.srcElement || event.target; triggerCallback(instance, function (button) { // if this button caused the click, cancel keyup event - return button.element === target && (cancelKeyup = true); + return button.element.contains(target) && (cancelKeyup = true); }); } From c34f99c979fbe0c482470d4131ef3e68196d0cc4 Mon Sep 17 00:00:00 2001 From: Aleksey Kuznietsov Date: Sun, 19 May 2024 02:08:07 -0400 Subject: [PATCH 2/5] Label to focus the input field in prompt dialog --- src/js/prompt.js | 34 +++++++++++++++++----------------- src/less/alertify.less | 4 ++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/js/prompt.js b/src/js/prompt.js index 6e9d915..72e6843 100644 --- a/src/js/prompt.js +++ b/src/js/prompt.js @@ -9,8 +9,10 @@ * alertify.prompt(title, message, value, onok, oncancel); */ alertify.dialog('prompt', function () { - var input = document.createElement('INPUT'); - var p = document.createElement('P'); + var input = document.createElement('INPUT'), + label = document.createElement('LABEL'), + labelText = document.createElement('P'); + return { main: function (_title, _message, _value, _onok, _oncancel) { var title, message, value, onok, oncancel; @@ -77,19 +79,21 @@ input.className = alertify.defaults.theme.input; input.setAttribute('type', 'text'); input.value = this.get('value'); - this.elements.content.appendChild(p); - this.elements.content.appendChild(input); + + this.elements.content.appendChild(label); + label.appendChild(labelText); + label.appendChild(input); }, prepare: function () { //nothing }, setMessage: function (message) { - if (isString(message)) { - clearContents(p); - p.innerHTML = message; - } else if (message instanceof window.HTMLElement && p.firstChild !== message) { - clearContents(p); - p.appendChild(message); + if (typeof message === 'string') { + clearContents(labelText); + labelText.innerHTML = message; + } else if (message instanceof window.HTMLElement && labelText.firstChild !== message) { + clearContents(labelText); + labelText.appendChild(message); } }, settings: { @@ -139,11 +143,7 @@ } break; case 'reverseButtons': - if (newValue === true) { - this.elements.buttons.primary.appendChild(this.__internal.buttons[0].element); - } else { - this.elements.buttons.primary.appendChild(this.__internal.buttons[1].element); - } + this.elements.buttons.primary.appendChild(this.__internal.buttons[newValue ? 0 : 1].element); break; } }, @@ -154,7 +154,7 @@ this.settings.value = input.value; if (typeof this.get('onok') === 'function') { returnValue = this.get('onok').call(this, closeEvent, this.settings.value); - if (typeof returnValue !== 'undefined') { + if (returnValue !== undefined) { closeEvent.cancel = !returnValue; } } @@ -162,7 +162,7 @@ case 1: if (typeof this.get('oncancel') === 'function') { returnValue = this.get('oncancel').call(this, closeEvent); - if (typeof returnValue !== 'undefined') { + if (returnValue !== undefined) { closeEvent.cancel = !returnValue; } } diff --git a/src/less/alertify.less b/src/less/alertify.less index 3e89364..6f92ba2 100644 --- a/src/less/alertify.less +++ b/src/less/alertify.less @@ -93,6 +93,10 @@ .content { padding: 16px 24px 16px 16px; + + label { + width: 100%; + } } } From 8fd1dd7b6d580206480347c4ef2c8cb1fc46c03c Mon Sep 17 00:00:00 2001 From: Aleksey Kuznietsov Date: Sun, 19 May 2024 02:09:24 -0400 Subject: [PATCH 3/5] space --- src/js/dialog/dialog.js | 2 +- src/js/dialog/intro.js | 2 +- src/js/intro.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/dialog/dialog.js b/src/js/dialog/dialog.js index 6d32aaa..0112760 100644 --- a/src/js/dialog/dialog.js +++ b/src/js/dialog/dialog.js @@ -369,7 +369,7 @@ dispatchEvent('onclose', this); //remove from open dialogs - openDialogs.splice(openDialogs.indexOf(this),1); + openDialogs.splice(openDialogs.indexOf(this), 1); this.__internal.isOpen = false; ensureNoOverflow(); diff --git a/src/js/dialog/intro.js b/src/js/dialog/intro.js index 377402f..6980ce4 100644 --- a/src/js/dialog/intro.js +++ b/src/js/dialog/intro.js @@ -478,7 +478,7 @@ if(document.body.lastChild !== instance.elements.root){ document.body.appendChild(instance.elements.root); //also make sure its at the end of the list - openDialogs.splice(openDialogs.indexOf(instance),1); + openDialogs.splice(openDialogs.indexOf(instance), 1); openDialogs.push(instance); setFocus(instance); } diff --git a/src/js/intro.js b/src/js/intro.js index f701009..884f3ed 100644 --- a/src/js/intro.js +++ b/src/js/intro.js @@ -111,7 +111,7 @@ for (var x = 0; x < toBeRemoved.length; x += 1) { var index = original.indexOf(toBeRemoved[x]); if (index > -1){ - original.splice(index,1); + original.splice(index, 1); } } element.className = original.join(' '); From 7c329aa7808b8bf1cccc97b7dd408cf17c8cbde1 Mon Sep 17 00:00:00 2001 From: Aleksey Kuznietsov Date: Sun, 19 May 2024 02:17:00 -0400 Subject: [PATCH 4/5] Update prompt.js --- src/js/prompt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/prompt.js b/src/js/prompt.js index 72e6843..9ef7843 100644 --- a/src/js/prompt.js +++ b/src/js/prompt.js @@ -88,7 +88,7 @@ //nothing }, setMessage: function (message) { - if (typeof message === 'string') { + if (isString(message)) { clearContents(labelText); labelText.innerHTML = message; } else if (message instanceof window.HTMLElement && labelText.firstChild !== message) { From 1d21138b687e671a96e470dfe5db07814cc781bb Mon Sep 17 00:00:00 2001 From: Aleksey Kuznietsov Date: Sun, 19 May 2024 02:18:16 -0400 Subject: [PATCH 5/5] Update prompt.js --- src/js/prompt.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/prompt.js b/src/js/prompt.js index 9ef7843..2c9319a 100644 --- a/src/js/prompt.js +++ b/src/js/prompt.js @@ -154,7 +154,7 @@ this.settings.value = input.value; if (typeof this.get('onok') === 'function') { returnValue = this.get('onok').call(this, closeEvent, this.settings.value); - if (returnValue !== undefined) { + if (typeof returnValue !== 'undefined') { closeEvent.cancel = !returnValue; } } @@ -162,7 +162,7 @@ case 1: if (typeof this.get('oncancel') === 'function') { returnValue = this.get('oncancel').call(this, closeEvent); - if (returnValue !== undefined) { + if (typeof returnValue !== 'undefined') { closeEvent.cancel = !returnValue; } }