bobjoll 0.0.4
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/LICENSE +21 -0
- package/README.md +35 -0
- package/package.json +25 -0
- package/scss/layout/_footer.scss +10 -0
- package/scss/layout/_header.scss +10 -0
- package/scss/modules/_fonts.scss +26 -0
- package/scss/modules/_reset.scss +219 -0
- package/scss/modules/bourbon/addons/_clearfix.scss +25 -0
- package/scss/modules/bourbon/addons/_ellipsis.scss +30 -0
- package/scss/modules/bourbon/addons/_position.scss +48 -0
- package/scss/modules/bourbon/addons/_prefixer.scss +66 -0
- package/scss/modules/bourbon/addons/_size.scss +51 -0
- package/scss/modules/bourbon/addons/_timing-functions.scss +34 -0
- package/scss/modules/bourbon/addons/_triangle.scss +63 -0
- package/scss/modules/bourbon/css3/_calc.scss +4 -0
- package/scss/modules/bourbon/css3/_flex-box.scss +287 -0
- package/scss/modules/bourbon/css3/_keyframes.scss +36 -0
- package/scss/modules/bourbon/css3/_linear-gradient.scss +38 -0
- package/scss/modules/bourbon/css3/_placeholder.scss +8 -0
- package/scss/modules/bourbon/css3/_selection.scss +42 -0
- package/scss/modules/bourbon/css3/_transition.scss +71 -0
- package/scss/modules/mixins/_component.scss +9 -0
- package/scss/modules/mixins/_grid.scss +75 -0
- package/scss/modules/mixins/_helpers.scss +224 -0
- package/scss/modules/variables/_colors.scss +447 -0
- package/scss/modules/variables/_general.scss +235 -0
- package/scss/partials/_accordion-v1-0.scss +165 -0
- package/scss/partials/_autocomplete-v1-0.scss +55 -0
- package/scss/partials/_general-v1-0.scss +51 -0
- package/scss/partials/_grid-v1-0.scss +109 -0
- package/scss/partials/_helper-v1-0.scss +299 -0
- package/scss/partials/_icon-v2-0.scss +323 -0
- package/scss/partials/_list-v1-0.scss +100 -0
- package/scss/partials/_modal-v1-0.scss +159 -0
- package/scss/partials/_notification-v1-1.scss +297 -0
- package/scss/partials/_progress-bar-v1.0.scss +25 -0
- package/scss/partials/_range-v1.0.scss +75 -0
- package/scss/partials/_tooltipFixed-v1.0.scss +128 -0
- package/scss/partials/_typography-v1-0.scss +201 -0
- package/scss/partials/animations/_fade.scss +23 -0
- package/scss/partials/animations/_rotate.scss +11 -0
- package/scss/partials/animations/_scale.scss +23 -0
- package/scss/partials/animations/_slide.scss +31 -0
- package/scss/partials/button-v4-0/_component.scss +304 -0
- package/scss/partials/form/_checkbox-and-radio-v1-0.scss +187 -0
- package/scss/partials/form/_dropdowns-v1-0.scss +323 -0
- package/scss/partials/form/_general-v1-0.scss +166 -0
- package/scss/partials/form/_group-v1-0.scss +157 -0
- package/scss/partials/form/_password-v1-0.scss +28 -0
- package/scss/partials/form/_switch-v1-0.scss +128 -0
- package/scss/partials/form/_upload-v1-0.scss +91 -0
- package/ts/library/common.ts +30 -0
- package/ts/library/cookie.ts +47 -0
- package/ts/library/delegate.ts +122 -0
- package/ts/library/dom.ts +124 -0
- package/ts/library/event.ts +138 -0
- package/ts/library/extend.js +32 -0
- package/ts/library/gr/dom.q.ts +12 -0
- package/ts/library/gr/social/dependency/twitter_pu.js +66 -0
- package/ts/library/gr/social/facebook.ts +154 -0
- package/ts/library/gr/social/google.ts +127 -0
- package/ts/library/gr/social/index.ts +35 -0
- package/ts/library/gr/social/twitter.ts +65 -0
- package/ts/library/helpers.ts +9 -0
- package/ts/library/number-abbreviate.js +57 -0
- package/ts/library/settings.ts +7 -0
- package/ts/library/storage.ts +131 -0
- package/ts/library/svg4everybody.legacy.js +122 -0
- package/ts/partials/accordion-v1.0.ts +104 -0
- package/ts/partials/accordionTabs-v1.0.ts +27 -0
- package/ts/partials/alert-v1.0.ts +51 -0
- package/ts/partials/copy-v1.0.ts +17 -0
- package/ts/partials/countdown-v1.0.ts +119 -0
- package/ts/partials/dropdown-v1.0.ts +247 -0
- package/ts/partials/hbs-v1.0.ts +9 -0
- package/ts/partials/modal-v1.0.ts +213 -0
- package/ts/partials/notifications-v1.1.ts +376 -0
- package/ts/partials/notify-v1.0.ts +746 -0
- package/ts/partials/password-v1.0.ts +19 -0
- package/ts/partials/popover-v1.0.ts +125 -0
- package/ts/partials/progress-bar-v1.0.ts +29 -0
- package/ts/partials/scroll-v1.0.ts +169 -0
- package/ts/partials/scrollable-v1.0.ts +90 -0
- package/ts/partials/tabs-v1.0.ts +79 -0
- package/ts/partials/tags-v1.0.ts +21 -0
- package/ts/partials/trigger-v2.0.ts +155 -0
- package/ts/partials/upload-v1.0.ts +17 -0
- package/ts/views/hbs/alert-v1.0/element.html.hbs +35 -0
- package/ts/views/hbs/countdown-v1.0/countdown-inner.hbs +39 -0
- package/ts/views/hbs/countdown-v1.0/countdown.hbs +4 -0
- package/ts/views/hbs/dropdown-v1.0/element.html.hbs +70 -0
- package/ts/views/hbs/helpers.js +58 -0
- package/ts/views/hbs/modal-v1.0/element.html.hbs +17 -0
- package/ts/views/hbs/notification-v1.1/element-disable.html.hbs +26 -0
- package/ts/views/hbs/notification-v1.1/element.html.hbs +43 -0
- package/ts/views/hbs/notification-v1.1/wrapper.html.hbs +4 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import '../library/common';
|
|
2
|
+
import { qq, q } from "../library/dom";
|
|
3
|
+
import View from 'BobjollView';
|
|
4
|
+
|
|
5
|
+
export class Dropdown {
|
|
6
|
+
private static readonly templateExt = View.ext;
|
|
7
|
+
private static readonly template = require(`BobjollTemplate/dropdown-v1.0/element.${Dropdown.templateExt}`);
|
|
8
|
+
private static readonly defaults: DropdownDefaults = {
|
|
9
|
+
search: false,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private settings: DropdownSettings;
|
|
13
|
+
private button: HTMLButtonElement;
|
|
14
|
+
private select: HTMLSelectElement;
|
|
15
|
+
private search: HTMLInputElement;
|
|
16
|
+
private options: HTMLUListElement[];
|
|
17
|
+
private instance: Boolean = false;
|
|
18
|
+
private eventHandlers: DropdownEventHanlder[] = [];
|
|
19
|
+
|
|
20
|
+
constructor(options: DropdownOptions) {
|
|
21
|
+
const select = <HTMLSelectElement|undefined>q('select', options.dropdown);
|
|
22
|
+
|
|
23
|
+
this.settings = {
|
|
24
|
+
...Dropdown.defaults,
|
|
25
|
+
...options,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (options.instance) {
|
|
29
|
+
this.instance = options.instance;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (select) {
|
|
33
|
+
this.select = select;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
this.render();
|
|
37
|
+
this.addEventListeners();
|
|
38
|
+
} catch(err) {
|
|
39
|
+
console.error(err);
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
console.error('There was no HTMLSelectElement found in the Dropdown element.');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private addEventListeners() {
|
|
47
|
+
this.eventHandlers.push({
|
|
48
|
+
element: this.button,
|
|
49
|
+
eventType: 'click',
|
|
50
|
+
eventHandler: this.eventHandlerButtonClick.bind(this.button, this),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
this.eventHandlers.push({
|
|
54
|
+
element: this.select,
|
|
55
|
+
eventType: 'change',
|
|
56
|
+
eventHandler: () => this.update(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
this.options.forEach(option =>
|
|
60
|
+
this.eventHandlers.push({
|
|
61
|
+
element: option,
|
|
62
|
+
eventType: 'click',
|
|
63
|
+
eventHandler: this.eventHandlerItemClick.bind(option, this)
|
|
64
|
+
})
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
if (this.search) {
|
|
68
|
+
this.eventHandlers.push({
|
|
69
|
+
element: this.search,
|
|
70
|
+
eventType: 'keyup',
|
|
71
|
+
eventHandler: this.eventHandlerInputKeyup.bind(this.search, this)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.eventHandlers.forEach(event => event.element.addEventListener(event.eventType, event.eventHandler));
|
|
76
|
+
|
|
77
|
+
window.addEventListener('mouseup', (e: Event) => {
|
|
78
|
+
const target = <Element>e.target;
|
|
79
|
+
if (target.parents && target.parents('.dropdown').length == 0) {
|
|
80
|
+
this.close();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private eventHandlerButtonClick(this: HTMLButtonElement, self: Dropdown) {
|
|
86
|
+
if (self.search) {
|
|
87
|
+
self.search.focus();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
self.close();
|
|
91
|
+
|
|
92
|
+
if (!this.classList.contains('active')) {
|
|
93
|
+
this.classList.add('active');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private eventHandlerItemClick(this: HTMLUListElement, self: Dropdown) {
|
|
98
|
+
const options = qq('option', self.select) as HTMLInputElement[];
|
|
99
|
+
const others = options.filter(option => option.dataset.other);
|
|
100
|
+
const valueSelected = this.dataset ? this.dataset.value : '';
|
|
101
|
+
|
|
102
|
+
if (others.length) {
|
|
103
|
+
others.forEach(other => {
|
|
104
|
+
const fieldElement = q(`input[name="${other.dataset.other || ''}"]`) as HTMLInputElement | undefined;
|
|
105
|
+
|
|
106
|
+
if (fieldElement) {
|
|
107
|
+
fieldElement.classList[(valueSelected) === other.value ? 'remove' : 'add']('hide');
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (valueSelected) {
|
|
113
|
+
Dropdown.changeCheckList(self, valueSelected);
|
|
114
|
+
self.select.value = valueSelected;
|
|
115
|
+
self.select.dispatchEvent(new Event('change', {
|
|
116
|
+
bubbles: true,
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
self.button.classList.remove('active');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
public static changeCheckList(dropdown: Dropdown, valueSelected: string) {
|
|
124
|
+
if (!dropdown.select.dataset.checkList) return;
|
|
125
|
+
|
|
126
|
+
dropdown.options.forEach(option => {
|
|
127
|
+
const icon = q('i', option);
|
|
128
|
+
icon && icon.classList[option.dataset.value === valueSelected ? 'remove' : 'add']('invisible')
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public changeValue(newVal: string) {
|
|
133
|
+
let targetOption = this.options.filter(option => option.dataset.value == newVal)[0];
|
|
134
|
+
|
|
135
|
+
this.button.innerText = targetOption.innerText;
|
|
136
|
+
|
|
137
|
+
this.select.value = newVal;
|
|
138
|
+
this.select.dispatchEvent(new Event('change', {
|
|
139
|
+
bubbles: true,
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
this.button.classList.remove('active');
|
|
143
|
+
this.button.innerText = targetOption.innerText;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private eventHandlerInputKeyup(this: HTMLInputElement, self: Dropdown) {
|
|
147
|
+
const value = this.value.trim();
|
|
148
|
+
const keyword = new RegExp(value, 'gi');
|
|
149
|
+
|
|
150
|
+
self.options.forEach(option => {
|
|
151
|
+
const text = option.innerText || '';
|
|
152
|
+
const value = option.dataset.value || '';
|
|
153
|
+
option.classList[text.match(keyword) || value.match(keyword) ? 'remove' : 'add']('hide');
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private update() {
|
|
158
|
+
const options = qq('option', this.select) as HTMLInputElement[];
|
|
159
|
+
|
|
160
|
+
options.forEach(option => {
|
|
161
|
+
if (this.select.value === option.value) {
|
|
162
|
+
this.button.innerText = option.innerText;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private close() {
|
|
168
|
+
qq('.dropdown__button').forEach(dropdown => dropdown.classList.remove('active'));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private render() {
|
|
172
|
+
if ('true' == this.select.dataset.search || this.settings.search) {
|
|
173
|
+
this.settings.search = true;
|
|
174
|
+
this.select.dataset.search = 'true';
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (!this.instance) {
|
|
178
|
+
this.select.insertAdjacentHTML('afterend',
|
|
179
|
+
View.render(Dropdown.template, {
|
|
180
|
+
checkList: this.select.dataset.checkList,
|
|
181
|
+
dataset: this.select.dataset,
|
|
182
|
+
options: [].slice.call(this.select.options),
|
|
183
|
+
selectedIndex: this.select.options.selectedIndex
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
this.options = <HTMLUListElement[]>qq('.dropdown__select li', this.settings.dropdown);
|
|
189
|
+
|
|
190
|
+
const button = <HTMLButtonElement|undefined>q('.dropdown__button', this.settings.dropdown);
|
|
191
|
+
|
|
192
|
+
if (button) {
|
|
193
|
+
this.button = button;
|
|
194
|
+
} else {
|
|
195
|
+
throw Error('Dropdown wasn\'t initialized correctly, the button element is missing, please check your template.');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (this.settings.search) {
|
|
199
|
+
const search = <HTMLInputElement | undefined>q('input', this.settings.dropdown);
|
|
200
|
+
|
|
201
|
+
if (search) {
|
|
202
|
+
this.search = search;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
this.settings.dropdown.classList.add('loaded');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
public destroy() {
|
|
210
|
+
const container = q('.dropdown__container', this.settings.dropdown);
|
|
211
|
+
if (container) {
|
|
212
|
+
this.settings.dropdown.removeChild(container);
|
|
213
|
+
}
|
|
214
|
+
this.eventHandlers.forEach(event => event.element.removeEventListener(event.eventType, event.eventHandler));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export const initializeDropdown = (loadDynamic = false) =>
|
|
219
|
+
qq(`.dropdown${loadDynamic ? '.dropdown--load-dynamic:not(.loaded)' : ''}`).forEach(dropdown =>
|
|
220
|
+
new Dropdown({ dropdown: dropdown, loadDynamic })
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
initializeDropdown();
|
|
224
|
+
|
|
225
|
+
export interface DropdownDefaults {
|
|
226
|
+
search: boolean;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface DropdownOptions {
|
|
230
|
+
dropdown: HTMLElement;
|
|
231
|
+
instance?: boolean;
|
|
232
|
+
loadDynamic?: boolean;
|
|
233
|
+
search?: boolean;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface DropdownSettings {
|
|
237
|
+
dropdown: HTMLElement;
|
|
238
|
+
instance?: boolean;
|
|
239
|
+
loadDynamic?: boolean;
|
|
240
|
+
search: boolean;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export interface DropdownEventHanlder {
|
|
244
|
+
element: Element;
|
|
245
|
+
eventHandler: EventListenerOrEventListenerObject;
|
|
246
|
+
eventType: string;
|
|
247
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
export interface ModalAddSettings {
|
|
2
|
+
name: string;
|
|
3
|
+
html?: string;
|
|
4
|
+
media?: string;
|
|
5
|
+
multilayer?: boolean;
|
|
6
|
+
containerHtml?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface ModalHideSettings {
|
|
10
|
+
all?: boolean;
|
|
11
|
+
show?: string;
|
|
12
|
+
dispatch?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ModalPrintSettings {
|
|
16
|
+
name: string;
|
|
17
|
+
html: string;
|
|
18
|
+
show?: boolean;
|
|
19
|
+
media?: string;
|
|
20
|
+
multilayer?: boolean;
|
|
21
|
+
containerHtml?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
import View from 'BobjollView';
|
|
25
|
+
import 'bobjoll/ts/library/common';
|
|
26
|
+
import { delegate } from 'bobjoll/ts/library/dom';
|
|
27
|
+
|
|
28
|
+
const EXT = View.ext;
|
|
29
|
+
var extend = require('bobjoll/ts/library/extend');
|
|
30
|
+
|
|
31
|
+
export class Modal {
|
|
32
|
+
private modalsActive: string[];
|
|
33
|
+
private modalsMultilayer: string[];
|
|
34
|
+
private modalsAddSettings: ModalAddSettings;
|
|
35
|
+
private modalsPrintSettings: ModalPrintSettings;
|
|
36
|
+
private modalsWrapper: HTMLElement;
|
|
37
|
+
|
|
38
|
+
constructor() {
|
|
39
|
+
this.modalsActive = [];
|
|
40
|
+
this.modalsMultilayer = [];
|
|
41
|
+
this.modalsAddSettings = {
|
|
42
|
+
name: '',
|
|
43
|
+
multilayer: false
|
|
44
|
+
};
|
|
45
|
+
this.modalsPrintSettings = {
|
|
46
|
+
name: '',
|
|
47
|
+
html: '',
|
|
48
|
+
multilayer: false
|
|
49
|
+
};
|
|
50
|
+
var modalsWrapper = document.getElementById('modals');
|
|
51
|
+
|
|
52
|
+
if (!modalsWrapper) {
|
|
53
|
+
modalsWrapper = document.createElement('div');
|
|
54
|
+
modalsWrapper.id = 'modals';
|
|
55
|
+
|
|
56
|
+
if (document.body) document.body.insertAdjacentElement('beforeend', modalsWrapper);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.modalsWrapper = modalsWrapper;
|
|
60
|
+
this.addEventListeners();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
add(settings: ModalAddSettings) {
|
|
64
|
+
let config = extend(this.modalsAddSettings, settings);
|
|
65
|
+
let modal = document.getElementById(`modal-${config.name}`);
|
|
66
|
+
|
|
67
|
+
if (!modal) {
|
|
68
|
+
let template = require(`BobjollTemplate/modal-v1.0/element.${EXT}`);
|
|
69
|
+
|
|
70
|
+
this.modalsWrapper.insertAdjacentHTML('beforeend', View.render(template, config));
|
|
71
|
+
|
|
72
|
+
modal = document.getElementById(`modal-${config.name}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (config.multilayer && this.modalsMultilayer.indexOf(`modal-${config.name}`) < 0) {
|
|
76
|
+
this.modalsMultilayer.push(`modal-${config.name}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return modal;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public show(id: string) {
|
|
83
|
+
let modal = document.getElementById(id);
|
|
84
|
+
let modalEvent = new Event('show');
|
|
85
|
+
|
|
86
|
+
if (modal) {
|
|
87
|
+
modal.classList.add('active');
|
|
88
|
+
document.body.classList.add('overflow-hidden');
|
|
89
|
+
|
|
90
|
+
if (modal.dataset['multilayer']) {
|
|
91
|
+
if (this.modalsMultilayer.indexOf(id) < 0) {
|
|
92
|
+
this.modalsMultilayer.push(id);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (this.modalsActive.indexOf(id) < 0) {
|
|
97
|
+
this.modalsActive.unshift(id);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
modal.dispatchEvent(modalEvent);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public hide(settings?: ModalHideSettings) {
|
|
105
|
+
if (this.modalsActive.length > 0) {
|
|
106
|
+
let modalSpliceList: number[] = [];
|
|
107
|
+
let modalHideAll = settings && settings.all ? true : false;
|
|
108
|
+
let modalEvent = new Event('hide');
|
|
109
|
+
|
|
110
|
+
[].forEach.call(this.modalsActive, (id: string, index: number) => {
|
|
111
|
+
let show = (settings && typeof settings.show !== 'undefined' ? (settings.show === id ? true : false) : false);
|
|
112
|
+
let modal = document.getElementById(id);
|
|
113
|
+
|
|
114
|
+
if (modal && (modalHideAll || !show)) {
|
|
115
|
+
let multilayer = this.modalsMultilayer.indexOf(id) < 0 ? false : true;
|
|
116
|
+
|
|
117
|
+
if (modalHideAll || (multilayer && this.modalsActive.length == 1 || !show && !multilayer)) {
|
|
118
|
+
modal.classList.remove('active');
|
|
119
|
+
|
|
120
|
+
modalSpliceList.push(index);
|
|
121
|
+
|
|
122
|
+
if (typeof settings === 'undefined' || typeof settings.dispatch === 'undefined' || settings.dispatch) modal.dispatchEvent(modalEvent);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
modalSpliceList
|
|
128
|
+
.sort((a, b) => b - a)
|
|
129
|
+
.forEach((position) => this.modalsActive.splice(position, 1));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (this.modalsActive.length === 0) {
|
|
133
|
+
document.body.classList.remove('overflow-hidden');
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
print(settings: ModalPrintSettings, show: boolean = true) {
|
|
138
|
+
let config = extend(this.modalsPrintSettings, settings);
|
|
139
|
+
let modal = document.getElementById(`modal-${config.name}`);
|
|
140
|
+
|
|
141
|
+
if (!modal) {
|
|
142
|
+
let addSettings: ModalAddSettings = {
|
|
143
|
+
name: config.name,
|
|
144
|
+
multilayer: config.multilayer
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
if (config.media) {
|
|
148
|
+
addSettings.media = config.media;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this.add(addSettings);
|
|
152
|
+
|
|
153
|
+
modal = document.getElementById(`modal-${config.name}`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (modal) {
|
|
157
|
+
let modalContent = modal.querySelector('.content');
|
|
158
|
+
|
|
159
|
+
if (modalContent) {
|
|
160
|
+
modalContent.innerHTML = config.html;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (show) {
|
|
164
|
+
this.show(`modal-${config.name}`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return modal;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
addEventListeners() {
|
|
172
|
+
let modal = this;
|
|
173
|
+
|
|
174
|
+
window.addEventListener('mouseup', (e: Event) => {
|
|
175
|
+
const target: EventTarget | null = e.target;
|
|
176
|
+
|
|
177
|
+
if (target instanceof HTMLElement) {
|
|
178
|
+
const wrapper = target.parents('.modal');
|
|
179
|
+
const container = target.parents('.modal__container');
|
|
180
|
+
const modal = (wrapper.length ? wrapper[0] : target) as HTMLElement;
|
|
181
|
+
const disabled = ("" === modal.dataset.disableMouseUp) ? true : false;
|
|
182
|
+
|
|
183
|
+
if ((wrapper.length || target.classList.contains('modal')) && 0 === container.length && !disabled) {
|
|
184
|
+
this.hide();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
delegate('.modal__close', 'click', function(this: HTMLElement) {
|
|
190
|
+
modal.hide();
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
delegate('.modal__trigger', 'click', function(this: HTMLElement, e: Event) {
|
|
194
|
+
if (!this.dataset.allowDefault) {
|
|
195
|
+
e.preventDefault();
|
|
196
|
+
e.stopPropagation();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
let id = this.dataset['modal'];
|
|
200
|
+
|
|
201
|
+
if (id) {
|
|
202
|
+
modal.show(id);
|
|
203
|
+
modal.hide({show: id});
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
window.addEventListener('keyup', (e) => {
|
|
208
|
+
if (e.keyCode === 27) this.hide();
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export var modal = new Modal();
|