@ulu/frontend 0.0.23 → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/deprecated/js/drupal-programmatic-modal.js +91 -0
- package/{js/ui/modals.js → deprecated/js/micromodal-modals.js} +41 -67
- package/dist/ulu-frontend.min.css +1 -1
- package/dist/ulu-frontend.min.js +70 -1
- package/index.js +6 -1
- package/js/events/index.js +58 -7
- package/js/index.js +3 -7
- package/js/{helpers/css-breakpoint.js → ui/breakpoints.js} +9 -11
- package/js/ui/collapsible.js +195 -0
- package/js/ui/dialog.js +157 -0
- package/js/ui/dialog.todo +37 -0
- package/js/ui/flipcard.js +55 -11
- package/js/ui/grid.js +2 -47
- package/js/ui/index.js +21 -0
- package/js/ui/modal-builder.js +197 -0
- package/js/ui/overflow-scroller-pager.js +1 -1
- package/js/ui/overflow-scroller.js +8 -5
- package/js/ui/page.js +14 -0
- package/js/ui/popover.js +135 -0
- package/js/ui/print-details.js +44 -0
- package/js/ui/print.js +67 -0
- package/js/ui/programmatic-modal.js +79 -81
- package/js/ui/proxy-click.js +80 -0
- package/js/ui/resizer.js +3 -3
- package/js/ui/scroll-slider.js +56 -0
- package/js/ui/scrollpoint.js +300 -0
- package/js/ui/slider.js +72 -10
- package/js/ui/tabs.js +85 -58
- package/js/ui/theme-toggle.js +129 -0
- package/js/ui/tooltip.js +268 -67
- package/js/utils/{logger.js → class-logger.js} +6 -5
- package/js/utils/dom.js +122 -0
- package/js/utils/file-save.js +67 -0
- package/js/utils/floating-ui.js +83 -0
- package/js/utils/id.js +22 -0
- package/js/utils/index.js +7 -0
- package/js/{helpers → utils}/pause-youtube-video.js +1 -1
- package/package.json +33 -13
- package/resources/drupal/twig-macros/accordion.twig +99 -0
- package/resources/drupal/twig-macros/dropdown.twig +44 -0
- package/resources/drupal/twig-macros/flipcard.twig +69 -0
- package/resources/drupal/twig-macros/image.twig +30 -0
- package/resources/drupal/twig-macros/layout.twig +338 -0
- package/resources/drupal/twig-macros/slider.twig +214 -0
- package/resources/drupal/twig-macros/tabs.twig +84 -0
- package/scss/README.md +13 -1
- package/scss/_breakpoint.scss +69 -26
- package/scss/_button.scss +148 -57
- package/scss/_color.scss +46 -28
- package/scss/_cssvar.scss +103 -12
- package/scss/_element.scss +84 -67
- package/scss/_index.scss +0 -3
- package/scss/_layout.scss +57 -26
- package/scss/_path.scss +2 -2
- package/scss/_selector.scss +20 -11
- package/scss/_typography.scss +115 -82
- package/scss/_units.scss +14 -13
- package/scss/_utils.scss +280 -18
- package/scss/base/_color.scss +2 -1
- package/scss/base/_elements.scss +61 -35
- package/scss/base/_index.scss +60 -23
- package/scss/base/_keyframes.scss +115 -16
- package/scss/base/_layout.scss +10 -6
- package/scss/base/_normalize.scss +6 -122
- package/scss/base/_print.scss +49 -0
- package/scss/base/_root.scss +28 -0
- package/scss/base/_typography.scss +4 -1
- package/scss/components/_accordion.scss +217 -0
- package/scss/components/_adaptive-spacing.scss +148 -0
- package/scss/components/_badge.scss +17 -14
- package/scss/components/_button-verbose.scss +138 -0
- package/scss/components/_button.scss +9 -4
- package/scss/components/_callout.scss +175 -0
- package/scss/components/_captioned-figure.scss +173 -0
- package/scss/components/_card-grid.scss +75 -0
- package/scss/components/_card.scss +420 -0
- package/scss/components/_css-icon.scss +433 -0
- package/scss/{_grid.scss → components/_data-grid.scss} +100 -68
- package/scss/components/_data-table.scss +180 -0
- package/scss/components/_fill-context.scss +20 -22
- package/scss/components/_flipcard-grid.scss +66 -0
- package/scss/components/_flipcard.scss +304 -0
- package/scss/components/_form-theme.scss +633 -0
- package/scss/components/_hero.scss +183 -0
- package/scss/components/_horizontal-rule.scss +51 -0
- package/scss/components/_image-grid.scss +71 -0
- package/scss/components/_index.scss +276 -38
- package/scss/components/_links.scss +1 -1
- package/scss/components/_list-lines.scss +14 -3
- package/scss/components/_list-ordered.scss +3 -1
- package/scss/components/_list-unordered.scss +3 -1
- package/scss/components/_menu-stack.scss +245 -0
- package/scss/components/_modal.scss +495 -0
- package/scss/components/_nav-strip.scss +148 -0
- package/scss/components/_overlay-section.scss +122 -0
- package/scss/components/_pager.scss +168 -0
- package/scss/components/_placeholder-block.scss +121 -0
- package/scss/components/_popover.scss +263 -0
- package/scss/components/_pull-quote.scss +111 -0
- package/scss/components/_ratio-box.scss +64 -0
- package/scss/components/_rule.scss +12 -9
- package/scss/components/_scroll-slider.scss +204 -0
- package/scss/components/_skip-link.scss +92 -0
- package/scss/components/_slider.scss +241 -0
- package/scss/components/_spoke-spinner.scss +193 -0
- package/scss/components/_tabs.scss +179 -0
- package/scss/components/_tag.scss +156 -0
- package/scss/components/_tile-button.scss +131 -0
- package/scss/components/_tile-grid-overlay.scss +132 -0
- package/scss/components/_tile-grid.scss +172 -0
- package/scss/components/_vignette.scss +65 -0
- package/scss/components/_wysiwyg.scss +94 -0
- package/scss/helpers/_color.scss +1 -0
- package/scss/helpers/_display.scss +2 -1
- package/scss/helpers/_index.scss +45 -22
- package/scss/helpers/_print.scss +20 -43
- package/scss/helpers/_typography.scss +3 -0
- package/scss/helpers/_units.scss +10 -13
- package/scss/helpers/_utilities.scss +5 -1
- package/scss/stylesheets/base-styles.scss +7 -0
- package/scss/stylesheets/component-styles.scss +7 -0
- package/scss/stylesheets/helper-styles.scss +7 -0
- package/types/events/index.d.ts +1 -1
- package/types/events/index.d.ts.map +1 -1
- package/types/index.d.ts +2 -2
- package/types/{helpers/css-breakpoint.d.ts → ui/breakpoints.d.ts} +3 -3
- package/types/ui/breakpoints.d.ts.map +1 -0
- package/types/ui/collapsible.d.ts +67 -0
- package/types/ui/collapsible.d.ts.map +1 -0
- package/types/ui/dialog.d.ts +42 -0
- package/types/ui/dialog.d.ts.map +1 -0
- package/types/ui/flipcard.d.ts +8 -1
- package/types/ui/flipcard.d.ts.map +1 -1
- package/types/ui/grid.d.ts +0 -11
- package/types/ui/grid.d.ts.map +1 -1
- package/types/ui/index.d.ts +23 -0
- package/types/ui/index.d.ts.map +1 -0
- package/types/ui/modal-builder.d.ts +54 -0
- package/types/ui/modal-builder.d.ts.map +1 -0
- package/types/ui/overflow-scroller-pager.d.ts +1 -1
- package/types/ui/overflow-scroller-pager.d.ts.map +1 -1
- package/types/ui/overflow-scroller.d.ts +3 -1
- package/types/ui/overflow-scroller.d.ts.map +1 -1
- package/types/ui/page.d.ts +5 -0
- package/types/ui/page.d.ts.map +1 -0
- package/types/ui/popover.d.ts +40 -0
- package/types/ui/popover.d.ts.map +1 -0
- package/types/ui/print-details.d.ts +10 -0
- package/types/ui/print-details.d.ts.map +1 -0
- package/types/ui/print.d.ts +10 -0
- package/types/ui/print.d.ts.map +1 -0
- package/types/ui/programmatic-modal.d.ts +19 -1
- package/types/ui/programmatic-modal.d.ts.map +1 -1
- package/types/ui/proxy-click.d.ts +18 -0
- package/types/ui/proxy-click.d.ts.map +1 -0
- package/types/ui/resizer.d.ts +1 -1
- package/types/ui/resizer.d.ts.map +1 -1
- package/types/ui/scroll-slider.d.ts +13 -0
- package/types/ui/scroll-slider.d.ts.map +1 -0
- package/types/ui/scrollpoint.d.ts +133 -0
- package/types/ui/scrollpoint.d.ts.map +1 -0
- package/types/ui/slider.d.ts +14 -2
- package/types/ui/slider.d.ts.map +1 -1
- package/types/ui/tabs.d.ts +22 -0
- package/types/ui/tabs.d.ts.map +1 -1
- package/types/ui/theme-toggle.d.ts +14 -0
- package/types/ui/theme-toggle.d.ts.map +1 -0
- package/types/ui/tooltip.d.ts +92 -10
- package/types/ui/tooltip.d.ts.map +1 -1
- package/types/utils/{logger.d.ts → class-logger.d.ts} +1 -1
- package/types/utils/class-logger.d.ts.map +1 -0
- package/types/utils/dom.d.ts +48 -0
- package/types/utils/dom.d.ts.map +1 -0
- package/types/utils/file-save.d.ts +64 -0
- package/types/utils/file-save.d.ts.map +1 -0
- package/types/utils/floating-ui.d.ts +19 -0
- package/types/utils/floating-ui.d.ts.map +1 -0
- package/types/utils/id.d.ts +10 -0
- package/types/utils/id.d.ts.map +1 -0
- package/types/utils/index.d.ts +9 -0
- package/types/utils/index.d.ts.map +1 -0
- package/types/utils/pause-youtube-video.d.ts.map +1 -0
- package/js/helpers/file-save.js +0 -52
- package/js/helpers/scrollbar-width-property.js +0 -14
- package/project.todo +0 -22
- package/scss/_calculate.scss +0 -64
- package/scss/_utility.scss +0 -12
- package/types/helpers/css-breakpoint.d.ts.map +0 -1
- package/types/helpers/file-save.d.ts +0 -17
- package/types/helpers/file-save.d.ts.map +0 -1
- package/types/helpers/node-data-manager.d.ts +0 -45
- package/types/helpers/node-data-manager.d.ts.map +0 -1
- package/types/helpers/pause-youtube-video.d.ts.map +0 -1
- package/types/helpers/scrollbar-width-property.d.ts +0 -11
- package/types/helpers/scrollbar-width-property.d.ts.map +0 -1
- package/types/ui/modals.d.ts +0 -27
- package/types/ui/modals.d.ts.map +0 -1
- package/types/utils/logger.d.ts.map +0 -1
- package/vite.config.js +0 -36
- /package/{js/deprecated → deprecated/js}/doc-ready.js +0 -0
- /package/{js/deprecated → deprecated/js}/jquery-prototypes.js +0 -0
- /package/{js/deprecated → deprecated/js}/mini-collapsible-popper-positioning.js +0 -0
- /package/{js/deprecated → deprecated/js}/mini-collapsible.js +0 -0
- /package/{js/helpers → deprecated/js}/node-data-manager.js +0 -0
- /package/{js/deprecated → deprecated/js}/script-loader.js +0 -0
- /package/{js/deprecated → deprecated/js}/waypoints/README.md +0 -0
- /package/{js/deprecated → deprecated/js}/waypoints/anchor-menu.js +0 -0
- /package/{js/deprecated → deprecated/js}/waypoints/element-waypoint.js +0 -0
- /package/{js/deprecated → deprecated/js}/waypoints/examples/page-link-menu.md +0 -0
- /package/{js/deprecated → deprecated/js}/waypoints/state-in-attribute.js +0 -0
- /package/types/{helpers → utils}/pause-youtube-video.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## Version 0.1.0-beta.1
|
|
4
|
+
|
|
5
|
+
- Remove dev dependencies from package json (vite, autoprefixer) and move specific JS module dependencies (ie. floating ui, ally.js and aria-tablist) to optionalDependencies so they can be installed if the user is using modules that require them
|
|
6
|
+
|
|
7
|
+
## Version 0.1.0-beta.0
|
|
8
|
+
|
|
9
|
+
- Minor release keeps most of the current API for SASS the same but adds new functions/mixins and components. JS has been slightly reorganized and outdated modules have been replaced
|
|
10
|
+
- Remove calculate module and move the functions to utils (responsive property and pixel-to-em)
|
|
11
|
+
- Add other components modules
|
|
12
|
+
- Update documentation and API documentation
|
|
13
|
+
- Update all sass to work with new/future sass version
|
|
14
|
+
- Add root styles for ulu specific custom properties
|
|
15
|
+
- Add transitions to buttons
|
|
16
|
+
- JS remove mini collapsible and rely on floating ui library for tooltip/popovers
|
|
17
|
+
- JS move to native dialog element instead of micro-modal
|
|
18
|
+
- JS add new collapsible class for popovers or other accessible collapsible containers
|
|
19
|
+
- JS reorganize utils and helpers
|
|
20
|
+
- Create new docs website with api docs and component examples
|
|
21
|
+
- Full build (ie. /dist/) is bundled by Vite
|
|
22
|
+
|
|
3
23
|
## Version 0.0.23
|
|
4
24
|
|
|
5
25
|
- Fix mistake introduced in 0.0.22, that broke container css
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module programmatic-modal
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Version: 1.0.3
|
|
6
|
+
// Changes:
|
|
7
|
+
// 1.0.2 | Updates to work with the updated modal script which has
|
|
8
|
+
// to attach it's own trigger handlers
|
|
9
|
+
// Description: Drupal programmatic modal insertion script (interface = jquery prototype)
|
|
10
|
+
// Changes: 1.0.2 - Added ability to pass class to container
|
|
11
|
+
|
|
12
|
+
import { setupModal, show, attachTriggers, triggerAttr } from "./micromodal-modals.js";
|
|
13
|
+
import { dispatch } from "../../js/events.js";
|
|
14
|
+
|
|
15
|
+
const $ = window.jQuery;
|
|
16
|
+
const containerId = 'programmatic-modal';
|
|
17
|
+
const selectorTrigger = '[data-programmatic-modal-trigger]';
|
|
18
|
+
const defaults = {
|
|
19
|
+
removeOnClose: true,
|
|
20
|
+
settings: {},
|
|
21
|
+
classes: []
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
let count = 0;
|
|
25
|
+
let cachedTrigger;
|
|
26
|
+
|
|
27
|
+
// Drupal calls the jquery 'programaticModal' from InvokeCommand())
|
|
28
|
+
$.fn.programaticModal = newModal;
|
|
29
|
+
|
|
30
|
+
// keep track of trigger clicks to return user on close (Drupal doesn't send trigger clicked, that I know of)
|
|
31
|
+
document.addEventListener('click', cacheTrigger, true);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Sets up a new ajax triggered modal and opens it
|
|
35
|
+
* @param {String} args Arguments provided from Drupal (JSON format)
|
|
36
|
+
*/
|
|
37
|
+
function newModal(args) {
|
|
38
|
+
args = args ? JSON.parse(args) : {};
|
|
39
|
+
const config = Object.assign({}, defaults, args);
|
|
40
|
+
const modal = document.querySelector(`#${ containerId }`);
|
|
41
|
+
const id = setModalId(modal, config.id);
|
|
42
|
+
const classes = ["programmatic-modal-content", ...config.classes ];
|
|
43
|
+
modal.classList.add(...classes);
|
|
44
|
+
// Add a new placeholder container
|
|
45
|
+
newContainer();
|
|
46
|
+
// Intialize and open the new modal
|
|
47
|
+
setupModal(modal, config.settings);
|
|
48
|
+
show(id, {
|
|
49
|
+
onShow(modal) {
|
|
50
|
+
dispatch('pageModified', modal);
|
|
51
|
+
},
|
|
52
|
+
onClose(element) {
|
|
53
|
+
if (config.removeOnClose) {
|
|
54
|
+
element.parentNode.removeChild(element);
|
|
55
|
+
}
|
|
56
|
+
// For accessiblity/usablity (return to last clicked trigger)
|
|
57
|
+
if (cachedTrigger) {
|
|
58
|
+
cachedTrigger.focus();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
// Attach handler so that it can reopen that modal
|
|
63
|
+
if (!config.removeOnClose && cachedTrigger) {
|
|
64
|
+
cachedTrigger.setAttribute(triggerAttr, id);
|
|
65
|
+
attachTriggers();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Sets and returns the modal's id
|
|
70
|
+
*/
|
|
71
|
+
function setModalId(element, id) {
|
|
72
|
+
element.id = id || `programmatic-modal--id-${ ++count }`;
|
|
73
|
+
return element.id;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Once we remove the placeholder containers id (above)
|
|
77
|
+
* we create another programmatic placeholder container
|
|
78
|
+
* for the next programmitic container
|
|
79
|
+
*/
|
|
80
|
+
function newContainer() {
|
|
81
|
+
const container = document.createElement('div');
|
|
82
|
+
container.id = 'programmatic-modal';
|
|
83
|
+
document.body.append(container);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Document click handler, will cache the trigger that caused the modal to open
|
|
87
|
+
*/
|
|
88
|
+
function cacheTrigger(event) {
|
|
89
|
+
const trigger = event.target.closest(selectorTrigger);
|
|
90
|
+
if (trigger) cachedTrigger = trigger;
|
|
91
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module ui/modals
|
|
3
3
|
*/
|
|
4
|
-
// Version: 1.0.
|
|
4
|
+
// Version: 1.0.5
|
|
5
|
+
//
|
|
5
6
|
// Changes:
|
|
7
|
+
// 1.0.5 | Added title icon and remove calling of init
|
|
8
|
+
// Moved setup modals stuff to inside init (contextual) [may affect programmatic modals]
|
|
6
9
|
// 1.0.4 | The modal library has a bug with multiple modals and using a custom close handler
|
|
7
10
|
// In the future we want to abandon this library but for now it works by setting up our own open and close buttons
|
|
8
11
|
// This is not setup to work with programmatic modals!!
|
|
@@ -10,17 +13,17 @@
|
|
|
10
13
|
// 1.0.3 | Added youtube video closing stuff
|
|
11
14
|
// 1.0.2 | Added custom close handler and checked to make sure resizer doesn't trigger click
|
|
12
15
|
// 1.0.1 | Added optional resizable (allowResize)
|
|
13
|
-
// Todo: - Make the container the content is getting the
|
|
16
|
+
// Todo: - Make the container the content is getting the original classes, or don't remove them. And allow user to pass classes via config
|
|
14
17
|
|
|
15
|
-
// Javascript builds
|
|
16
|
-
// Modal theme and
|
|
18
|
+
// Javascript builds structure, modal's live in content in simple container.
|
|
19
|
+
// Modal theme and structure is added in scripting That way if we change the
|
|
17
20
|
// interface in the future we don't need to change/update markup.
|
|
18
|
-
import MicroModal from
|
|
19
|
-
import Resizer from
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
21
|
+
import MicroModal from "micromodal";
|
|
22
|
+
import { Resizer } from "../resizer.js";
|
|
23
|
+
import { pauseVideos, prepVideos } from "../utils/pause-youtube-video.js";
|
|
24
|
+
import { createElementFromHtml } from "@ulu/utils/browser/dom.js";
|
|
22
25
|
const classes = {
|
|
23
|
-
open:
|
|
26
|
+
open: "site-modal--open",
|
|
24
27
|
container: "site-modal__container",
|
|
25
28
|
body: "site-modal__body",
|
|
26
29
|
resizer: "site-modal__resizer"
|
|
@@ -32,13 +35,14 @@ const defaults = {
|
|
|
32
35
|
allowResize: true,
|
|
33
36
|
position: "center",
|
|
34
37
|
containerClass: "",
|
|
35
|
-
closeSelector: "[data-site-modal-close]"
|
|
38
|
+
closeSelector: "[data-site-modal-close]",
|
|
39
|
+
titleIcon: false
|
|
36
40
|
};
|
|
37
41
|
const configMicroModal = {
|
|
38
42
|
openClass: classes.open,
|
|
39
43
|
disableScroll: true,
|
|
40
|
-
openTrigger:
|
|
41
|
-
closeTrigger:
|
|
44
|
+
openTrigger: "data-site-modal-trigger",
|
|
45
|
+
closeTrigger: "data-NOT-USED", // Proxied to avoid this click handler (on keydown, allow click on things underneath)
|
|
42
46
|
onClose: function(modal) {
|
|
43
47
|
pauseVideos(modal);
|
|
44
48
|
}
|
|
@@ -50,17 +54,12 @@ const wrappers = [];
|
|
|
50
54
|
// page and move to the bottom of the page
|
|
51
55
|
// const container = createContainer();
|
|
52
56
|
|
|
53
|
-
// The [data-site-modal] is used to seperate the libraries' interface
|
|
54
|
-
// and the modal's styling classes, so it can be adjusted or extended
|
|
55
|
-
// in the future
|
|
56
|
-
document.querySelectorAll('[data-site-modal]').forEach((element) => setupModal(element));
|
|
57
57
|
|
|
58
|
-
// Intialize modal library script
|
|
59
|
-
// init();
|
|
60
|
-
attachTriggers();
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
// Initialize modal library script
|
|
60
|
+
|
|
61
|
+
export function init(context = document) {
|
|
62
|
+
const flag = "data-site-modal-trigger-attached";
|
|
64
63
|
context.querySelectorAll(triggerSelector).forEach(trigger => {
|
|
65
64
|
if (!trigger.hasAttribute(flag)) {
|
|
66
65
|
const mid = trigger.getAttribute(triggerAttr);
|
|
@@ -69,17 +68,21 @@ export function attachTriggers(context = document) {
|
|
|
69
68
|
} else {
|
|
70
69
|
trigger.setAttribute(flag, "");
|
|
71
70
|
trigger.addEventListener("click", () => {
|
|
72
|
-
show(mid)
|
|
71
|
+
show(mid);
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
});
|
|
76
|
+
// The [data-site-modal] is used to separate the libraries' interface
|
|
77
|
+
// and the modal's styling classes, so it can be adjusted or extended
|
|
78
|
+
// in the future
|
|
79
|
+
context.querySelectorAll("[data-site-modal]").forEach((element) => setupModal(element));
|
|
77
80
|
}
|
|
78
81
|
|
|
79
82
|
/**
|
|
80
83
|
* Function to setup each modal
|
|
81
84
|
* - Creates structure
|
|
82
|
-
* - Gets settings from elements data
|
|
85
|
+
* - Gets settings from elements data attribute
|
|
83
86
|
* - Moves it to the end of the document
|
|
84
87
|
* - Adds resizer if position (left || right)
|
|
85
88
|
* @param {Node} modal Modal element ie. `[data-site-modal]`
|
|
@@ -88,25 +91,25 @@ export function attachTriggers(context = document) {
|
|
|
88
91
|
export function setupModal(modal, settings) {
|
|
89
92
|
// Grab things from original element before modifying
|
|
90
93
|
const id = modal.id;
|
|
91
|
-
const originalClasses = modal.getAttribute(
|
|
94
|
+
const originalClasses = modal.getAttribute("class") || "";
|
|
92
95
|
// Grab settings from element and optionally from settings passed
|
|
93
96
|
let data = {};
|
|
94
97
|
if (modal.dataset.siteModal) {
|
|
95
|
-
data = JSON.parse(modal.dataset.siteModal)
|
|
98
|
+
data = JSON.parse(modal.dataset.siteModal);
|
|
96
99
|
}
|
|
97
100
|
data = Object.assign({}, defaults, data, settings);
|
|
98
101
|
const { allowResize, position } = data;
|
|
99
102
|
const notCenter = position !== "center";
|
|
100
103
|
const hasResizer = notCenter && allowResize;
|
|
101
|
-
const resizerMarkup = hasResizer ? `<div class="${ classes.resizer }"></div>` :
|
|
104
|
+
const resizerMarkup = hasResizer ? `<div class="${ classes.resizer }"></div>` : "";
|
|
102
105
|
const resizerModifierClass = allowResize ? "resize" : "no-resize";
|
|
103
106
|
const closeAttr = "data-site-modal-close";
|
|
104
107
|
// Remove attributes
|
|
105
|
-
modal.removeAttribute(
|
|
106
|
-
modal.removeAttribute(
|
|
107
|
-
modal.removeAttribute(
|
|
108
|
+
modal.removeAttribute("data-site-modal");
|
|
109
|
+
modal.removeAttribute("id");
|
|
110
|
+
modal.removeAttribute("class");
|
|
108
111
|
// Template for new modal container (modal's body, the original element is
|
|
109
|
-
// appended after as not to lose any
|
|
112
|
+
// appended after as not to lose any listener's/etc
|
|
110
113
|
const markup = `
|
|
111
114
|
<div
|
|
112
115
|
class="
|
|
@@ -120,7 +123,10 @@ export function setupModal(modal, settings) {
|
|
|
120
123
|
<div class="site-modal__overlay" tabindex="-1" ${ closeAttr }>
|
|
121
124
|
<div class="site-modal__container" role="dialog" aria-modal="true" aria-labelledby="${ id }-title">
|
|
122
125
|
<div class="site-modal__header">
|
|
123
|
-
<h2 class="site-modal__title" id="${ id }-title" tabindex="0"
|
|
126
|
+
<h2 class="site-modal__title" id="${ id }-title" tabindex="0">
|
|
127
|
+
${ data.titleIcon ? `<span class="site-modal__title-icon ${ data.titleIcon }" aria-hidden="true"></span>` : "" }
|
|
128
|
+
<span class="site-modal__title-text">${ data.title }</span>
|
|
129
|
+
</h2>
|
|
124
130
|
<button class="site-modal__close" aria-label="Close modal" ${ closeAttr }>
|
|
125
131
|
<span class="site-modal__close-icon" aria-hidden="true" ${ closeAttr }></span>
|
|
126
132
|
</button>
|
|
@@ -136,9 +142,9 @@ export function setupModal(modal, settings) {
|
|
|
136
142
|
const select = (container, classKey) => container.querySelector("." + classes[classKey]);
|
|
137
143
|
const wrapper = createElementFromHtml(markup.trim());
|
|
138
144
|
const elements = {
|
|
139
|
-
body: select(wrapper,
|
|
140
|
-
resizer: select(wrapper,
|
|
141
|
-
container: select(wrapper,
|
|
145
|
+
body: select(wrapper, "body"),
|
|
146
|
+
resizer: select(wrapper, "resizer"),
|
|
147
|
+
container: select(wrapper, "container")
|
|
142
148
|
};
|
|
143
149
|
|
|
144
150
|
// Move the orginal content into the modal's body
|
|
@@ -158,7 +164,7 @@ export function setupModal(modal, settings) {
|
|
|
158
164
|
document.body.appendChild(wrapper);
|
|
159
165
|
// Add our own close handlers to avoide the native
|
|
160
166
|
const closeButtons = wrapper.querySelectorAll(data.closeSelector);
|
|
161
|
-
closeButtons.forEach(b => b.addEventListener(
|
|
167
|
+
closeButtons.forEach(b => b.addEventListener("click", ({ target }) => {
|
|
162
168
|
const outsideContainer = !elements.container.contains(target) && target !== elements.container;
|
|
163
169
|
// Last condition is the overlay/backdrop (click outside)
|
|
164
170
|
if (target.matches(`[${ closeAttr }]`) || outsideContainer) {
|
|
@@ -188,35 +194,3 @@ export function show(id, config) {
|
|
|
188
194
|
export function close(id) {
|
|
189
195
|
MicroModal.close(id);
|
|
190
196
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
// function createContainer() {
|
|
195
|
-
// const container = document.createElement('div');
|
|
196
|
-
// container.classList.add('site-modals');
|
|
197
|
-
// document.body.appendChild(container);
|
|
198
|
-
// return container;
|
|
199
|
-
// }
|
|
200
|
-
|
|
201
|
-
// From GITHUB Issues (user remedy)
|
|
202
|
-
// export function refresh() {
|
|
203
|
-
// // Use whatever selector you're using for MicroModal triggers.
|
|
204
|
-
// const modalTrigger = 'data-micromodal-trigger';
|
|
205
|
-
|
|
206
|
-
// // Get all triggers.
|
|
207
|
-
// const modalTriggers = document.querySelectorAll( `[${modalTrigger}]` );
|
|
208
|
-
|
|
209
|
-
// modalTriggers.forEach( trigger => {
|
|
210
|
-
// // Get the attribute to save.
|
|
211
|
-
// const triggerElement = trigger.getAttribute( modalTrigger );
|
|
212
|
-
|
|
213
|
-
// // Remove the attribute briefly to clear memory/existing modals.
|
|
214
|
-
// trigger.removeAttribute( modalTrigger );
|
|
215
|
-
|
|
216
|
-
// // Immediately add it back.
|
|
217
|
-
// trigger.setAttribute( modalTrigger, triggerElement );
|
|
218
|
-
|
|
219
|
-
// // Re-initialize.
|
|
220
|
-
// init();
|
|
221
|
-
// } );
|
|
222
|
-
// }
|