Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 71dbcec

Browse files
author
george
committed
[Version 4.2.0] Updates modal API to match other components
1 parent c901852 commit 71dbcec

20 files changed

+56
-54
lines changed

dist/undernet.bundle.esm.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* @license MIT (https://github.com/geotrev/undernet/blob/master/LICENSE)
3-
* Undernet v4.1.1 (https://undernet.io)
3+
* Undernet v4.2.0 (https://undernet.io)
44
* Copyright 2017-2019 George Treviranus
55
*/
66
const KeyCodes = {
@@ -837,8 +837,8 @@ const KeyCodes$2 = {
837837
const Selectors$3 = {
838838
// unique
839839
DATA_MODAL: "data-modal",
840-
DATA_MODAL_BUTTON: "data-modal-button",
841840
// common
841+
DATA_TARGET: "data-target",
842842
DATA_VISIBLE: "data-visible",
843843
DATA_CLOSE: "data-close",
844844
DATA_PARENT: "data-parent",
@@ -905,7 +905,6 @@ class Modal extends Utils {
905905
*/
906906
start() {
907907
this._modals = nodeListToArray(this._modalContainerAttr);
908-
this._modalButtons = nodeListToArray(`[${Selectors$3.DATA_MODAL_BUTTON}]`);
909908

910909
getFocusableElements(this._modalContainerAttr).forEach(element => {
911910
element.setAttribute(Selectors$3.TABINDEX, "-1");
@@ -914,11 +913,8 @@ class Modal extends Utils {
914913
if (this._modals.length) {
915914
this._modals.forEach(instance => {
916915
this._setupModal(instance);
917-
});
918-
}
919-
920-
if (this._modalButtons.length) {
921-
this._modalButtons.forEach(button => {
916+
const id = instance.getAttribute(Selectors$3.DATA_MODAL);
917+
const button = document.querySelector(`[${Selectors$3.DATA_TARGET}='${id}']`);
922918
button.addEventListener(Events$3.CLICK, this._render);
923919
});
924920
}
@@ -928,7 +924,9 @@ class Modal extends Utils {
928924
* Stop listening to modals
929925
*/
930926
stop() {
931-
this._modalButtons.forEach(button => {
927+
this._modals.forEach(instance => {
928+
const id = instance.getAttribute(Selectors$3.DATA_MODAL);
929+
const button = document.querySelector(`[${Selectors$3.DATA_TARGET}='${id}']`);
932930
button.removeEventListener(Events$3.CLICK, this._render);
933931
});
934932
}
@@ -942,7 +940,7 @@ class Modal extends Utils {
942940
_render(event) {
943941
event.preventDefault();
944942
this._activeModalButton = event.target;
945-
this._activeModalId = this._activeModalButton.getAttribute(Selectors$3.DATA_MODAL_BUTTON);
943+
this._activeModalId = this._activeModalButton.getAttribute(Selectors$3.DATA_TARGET);
946944

947945
if (!this._activeModalId) {
948946
return console.error(Messages$2.NO_BUTTON_ID_ERROR)
@@ -951,8 +949,10 @@ class Modal extends Utils {
951949
this._activeModalOverlay = document.querySelector(
952950
`[${Selectors$3.DATA_MODAL}="${this._activeModalId}"]`
953951
);
952+
954953
this._activeModalSelector = `[${Selectors$3.DATA_PARENT}='${this._activeModalId}']`;
955954
this._activeModal = this._activeModalOverlay.querySelector(this._activeModalSelector);
955+
956956
this._activeModalCloseButtons = nodeListToArray(
957957
`${this._activeModalSelector} [${Selectors$3.DATA_CLOSE}]`
958958
);
@@ -1091,11 +1091,15 @@ const KeyCodes$3 = {
10911091
};
10921092

10931093
const Selectors$4 = {
1094+
// unique
10941095
DATA_TOOLTIP: "data-tooltip",
1096+
// common
10951097
DATA_VISIBLE: "data-visible",
10961098
DATA_TARGET: "data-target",
1099+
// accessibility
10971100
ROLE: "role",
10981101
ARIA_DESCRIBEDBY: "aria-describedby",
1102+
// classes
10991103
DROP_LEFT_CLASS: "is-drop-left",
11001104
DROP_RIGHT_CLASS: "is-drop-right",
11011105
};

dist/undernet.bundle.js

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/undernet.bundle.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/undernet.bundle.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/undernet.bundle.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/undernet.css

Lines changed: 14 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/undernet.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/undernet.css.zip

-23 Bytes
Binary file not shown.

dist/undernet.js.zip

-31 Bytes
Binary file not shown.

dist/undernet.min.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)