1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | exports.__esModule = true;
|
5 | exports.default = void 0;
|
6 | exports.getSharedManager = getSharedManager;
|
7 | var _addClass = _interopRequireDefault(require("dom-helpers/addClass"));
|
8 | var _css = _interopRequireDefault(require("dom-helpers/css"));
|
9 | var _querySelectorAll = _interopRequireDefault(require("dom-helpers/querySelectorAll"));
|
10 | var _removeClass = _interopRequireDefault(require("dom-helpers/removeClass"));
|
11 | var _ModalManager = _interopRequireDefault(require("@restart/ui/ModalManager"));
|
12 | const Selector = {
|
13 | FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top',
|
14 | STICKY_CONTENT: '.sticky-top',
|
15 | NAVBAR_TOGGLER: '.navbar-toggler'
|
16 | };
|
17 | class BootstrapModalManager extends _ModalManager.default {
|
18 | adjustAndStore(prop, element, adjust) {
|
19 | const actual = element.style[prop];
|
20 |
|
21 |
|
22 | element.dataset[prop] = actual;
|
23 | (0, _css.default)(element, {
|
24 | [prop]: `${parseFloat((0, _css.default)(element, prop)) + adjust}px`
|
25 | });
|
26 | }
|
27 | restore(prop, element) {
|
28 | const value = element.dataset[prop];
|
29 | if (value !== undefined) {
|
30 | delete element.dataset[prop];
|
31 | (0, _css.default)(element, {
|
32 | [prop]: value
|
33 | });
|
34 | }
|
35 | }
|
36 | setContainerStyle(containerState) {
|
37 | super.setContainerStyle(containerState);
|
38 | const container = this.getElement();
|
39 | (0, _addClass.default)(container, 'modal-open');
|
40 | if (!containerState.scrollBarWidth) return;
|
41 | const paddingProp = this.isRTL ? 'paddingLeft' : 'paddingRight';
|
42 | const marginProp = this.isRTL ? 'marginLeft' : 'marginRight';
|
43 | (0, _querySelectorAll.default)(container, Selector.FIXED_CONTENT).forEach(el => this.adjustAndStore(paddingProp, el, containerState.scrollBarWidth));
|
44 | (0, _querySelectorAll.default)(container, Selector.STICKY_CONTENT).forEach(el => this.adjustAndStore(marginProp, el, -containerState.scrollBarWidth));
|
45 | (0, _querySelectorAll.default)(container, Selector.NAVBAR_TOGGLER).forEach(el => this.adjustAndStore(marginProp, el, containerState.scrollBarWidth));
|
46 | }
|
47 | removeContainerStyle(containerState) {
|
48 | super.removeContainerStyle(containerState);
|
49 | const container = this.getElement();
|
50 | (0, _removeClass.default)(container, 'modal-open');
|
51 | const paddingProp = this.isRTL ? 'paddingLeft' : 'paddingRight';
|
52 | const marginProp = this.isRTL ? 'marginLeft' : 'marginRight';
|
53 | (0, _querySelectorAll.default)(container, Selector.FIXED_CONTENT).forEach(el => this.restore(paddingProp, el));
|
54 | (0, _querySelectorAll.default)(container, Selector.STICKY_CONTENT).forEach(el => this.restore(marginProp, el));
|
55 | (0, _querySelectorAll.default)(container, Selector.NAVBAR_TOGGLER).forEach(el => this.restore(marginProp, el));
|
56 | }
|
57 | }
|
58 | let sharedManager;
|
59 | function getSharedManager(options) {
|
60 | if (!sharedManager) sharedManager = new BootstrapModalManager(options);
|
61 | return sharedManager;
|
62 | }
|
63 | var _default = BootstrapModalManager;
|
64 | exports.default = _default; |
\ | No newline at end of file |