webcimes-modal 2.0.1 → 2.1.0

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/README.md CHANGED
@@ -36,7 +36,7 @@ You can use an importmap to resolve the arbitrary module names to complete paths
36
36
  Then import javascript module:
37
37
 
38
38
  ```javascript
39
- import { CreateWebcimesModal } from 'webcimes-modal';
39
+ import { createWebcimesModal } from 'webcimes-modal';
40
40
  ```
41
41
 
42
42
  Or you can also set the full path directly in the import:
@@ -47,7 +47,7 @@ Or you can also set the full path directly in the import:
47
47
  ...
48
48
  <script type="module">
49
49
  // Import webcimes-modal
50
- import { CreateWebcimesModal } from "./node_modules/webcimes-modal/dist/js/webcimes-modal.esm.js";
50
+ import { createWebcimesModal } from "./node_modules/webcimes-modal/dist/js/webcimes-modal.esm.js";
51
51
  ...
52
52
  </script>
53
53
  </head>
@@ -58,7 +58,7 @@ Or you can also set the full path directly in the import:
58
58
  Or with JS bundlers (like Webpack) you can call directly the module :
59
59
 
60
60
  ```javascript
61
- import { CreateWebcimesModal } from 'webcimes-modal';
61
+ import { createWebcimesModal } from 'webcimes-modal';
62
62
  ```
63
63
 
64
64
  ### UDM
@@ -86,19 +86,21 @@ You can directly load the udm module in the script tag:
86
86
 
87
87
  ## Usage
88
88
 
89
- ### Call `CreateWebcimesModal()` to create modal:
89
+ ### Call `createWebcimesModal()` to create modal:
90
90
 
91
91
  ```javascript
92
- // Wait for dom content loaded or call CreateWebcimesModal before the end of body
92
+ // Wait for dom content loaded or call createWebcimesModal before the end of body
93
93
  document.addEventListener('DOMContentLoaded', function () {
94
94
  // Create modal
95
- const myModal = CreateWebcimesModal({
95
+ const myModal = createWebcimesModal({
96
96
  setId: null, // set a specific id on the modal. default "null"
97
97
  setClass: null, // set a specific class on the modal, default "null"
98
98
  width: 'auto', // width (specify unit), default "auto"
99
99
  height: 'auto', // height (specify unit), default "auto"
100
+ headerHtml: null, // html for header (overrides titleHtml), default "null"
100
101
  titleHtml: 'My title', // html for title, default "null"
101
102
  bodyHtml: 'My Body', // html for body, default "null"
103
+ footerHtml: null, // html for footer (overrides buttonCancelHtml and buttonConfirmHtml), default "null"
102
104
  buttonCancelHtml: 'Cancel', // html for cancel button, default "null"
103
105
  buttonConfirmHtml: 'Confirm', // html for confirm button, default "null"
104
106
  closeOnCancelButton: false, // close modal after trigger cancel button, default "true"
@@ -169,28 +171,72 @@ After a creating a modal, the basic html structure look like this:
169
171
 
170
172
  All parameters are optionnal, but to set the base message on the modal you can use `titleHtml` to create the title, `bodyHtml` contain the main message of the modal, and `buttonCancelHtml` & `buttonConfirmHtml` contain the html for each button.
171
173
 
172
- For these 4 fields you can just directly write the text or define tags, or call html from an element like this :
174
+ For these fields you can provide:
175
+
176
+ - **String**: Plain text or HTML tags
177
+ - **HTMLElement**: A DOM element
178
+ - **Function**: A function that returns an HTMLElement (useful for dynamic content or lazy loading)
173
179
 
174
180
  ```javascript
175
- const myModal = CreateWebcimesModal({
181
+ const myModal = createWebcimesModal({
176
182
  titleHtml: "My title <span style='color:red'>with red color</span>", // directly put an html tag or attribute like span and style
177
- bodyHtml: document.querySelector('#myID').outerHTML, // set html from an HTML element
178
- buttonCancelHtml: "Cancel <img src='my-url' alt=''>", // put the img tag
183
+ bodyHtml: document.querySelector('#myID'), // set HTMLElement directly
184
+ buttonCancelHtml: () => {
185
+ const btn = document.createElement('span');
186
+ btn.textContent = 'Cancel';
187
+ btn.style.fontWeight = 'bold';
188
+ return btn;
189
+ }, // use a function that returns an HTMLElement
179
190
  buttonConfirmHtml: 'Confirm', // or just text
180
191
  });
181
192
  ```
182
193
 
183
- if any of these 4 fields is set to null (the default), it will not appear on the modal
194
+ ### Advanced: Full control with headerHtml and footerHtml
195
+
196
+ For complete customization, you can use `headerHtml` and `footerHtml` which override their respective simple options:
197
+
198
+ - `headerHtml` overrides `titleHtml`
199
+ - `footerHtml` overrides `buttonCancelHtml` and `buttonConfirmHtml`
200
+
201
+ ```javascript
202
+ const myModal = createWebcimesModal({
203
+ headerHtml: () => {
204
+ const header = document.createElement('div');
205
+ header.innerHTML = '<h2>Custom Header</h2><p>Subtitle here</p>';
206
+ return header;
207
+ },
208
+ showCloseButton: true, // Close button will still be added
209
+ footerHtml: () => {
210
+ const footer = document.createElement('div');
211
+ footer.innerHTML = '<button class="webcimes-modal__close">Custom Close</button>';
212
+ return footer;
213
+ },
214
+ });
215
+ ```
216
+
217
+ **Note**: Any element with the class `webcimes-modal__close` will automatically close the modal when clicked.
218
+
219
+ if any of these fields is set to null (the default), it will not appear on the modal
184
220
 
185
221
  ### Remove specific structure of the modal:
186
222
 
187
- If you want to completely remove `webcimes-modal__header`, `webcimes-modal__body` or `webcimes-modal__footer` you need:
223
+ Modal sections are automatically hidden when all their content properties are empty or disabled:
224
+
225
+ **To remove `webcimes-modal__header`:** set `headerHtml` to `null`, `titleHtml` to `null` and `showCloseButton` to `false`
226
+
227
+ **To remove `webcimes-modal__body`:** set `bodyHtml` to `null`
188
228
 
189
- To remove `webcimes-modal__header`: set `titleHtml` to `null` and `showCloseButton` to `false`
229
+ **To remove `webcimes-modal__footer`:** set `footerHtml` to `null`, `buttonCancelHtml` to `null` and `buttonConfirmHtml` to `null`
190
230
 
191
- To remove `webcimes-modal__body`: set `bodyHtml` to `null`
231
+ Example:
192
232
 
193
- To remove `webcimes-modal__footer`: set `buttonCancelHtml` to `null` and `buttonConfirmHtml` to `null`
233
+ ```javascript
234
+ const myModal = createWebcimesModal({
235
+ bodyHtml: 'My message', // Only body will be displayed
236
+ // header is removed (all null/false)
237
+ // footer is removed (all null)
238
+ });
239
+ ```
194
240
 
195
241
  ### Scale the modal:
196
242
 
@@ -199,7 +245,7 @@ By default the `height` and `width` are set to `auto`, the modal will also be si
199
245
  You can also set the determined `height` or `width` by indicating the value with a number and a unit.
200
246
 
201
247
  ```javascript
202
- const myModal = CreateWebcimesModal({
248
+ const myModal = createWebcimesModal({
203
249
  width: '80vm',
204
250
  height: '200px',
205
251
  });
@@ -210,7 +256,7 @@ const myModal = CreateWebcimesModal({
210
256
  Below are the different options for customize the modal behavior.
211
257
 
212
258
  ```javascript
213
- const myModal = CreateWebcimesModal({
259
+ const myModal = createWebcimesModal({
214
260
  closeOnCancelButton: false, // close modal after triggering cancel button, default "true"
215
261
  closeOnConfirmButton: false, // close modal after triggering confirm button, default "true"
216
262
  showCloseButton: true, // show close button, default "true"
@@ -229,7 +275,7 @@ const myModal = CreateWebcimesModal({
229
275
  You can define the style of the modal with `css`, but you can also use the style property which allows to directly add an additional style to the modal.
230
276
 
231
277
  ```javascript
232
- const myModal = CreateWebcimesModal({
278
+ const myModal = createWebcimesModal({
233
279
  style: 'background:black; color:#fff; text-align:center;',
234
280
  });
235
281
  ```
@@ -245,7 +291,7 @@ For `animationOnDestroy` you can choose between `animDropUp` or `animFadeOut`
245
291
  And you can set the duration of all animation by setting `animationDuration` with a number in ms.
246
292
 
247
293
  ```javascript
248
- const myModal = CreateWebcimesModal({
294
+ const myModal = createWebcimesModal({
249
295
  animationOnShow: 'animDropDown', // "animDropDown" or "animFadeIn" for show animation, default "animDropDown"
250
296
  animationOnDestroy: 'animDropUp', // "animDropUp" or "animFadeOut" for destroy animation, default "animDropUp"
251
297
  animationDuration: 500, // anim duration in ms, default "500"
@@ -258,7 +304,7 @@ You can get the dom element of the current modal like this:
258
304
 
259
305
  ```javascript
260
306
  // Get the instance
261
- const myModal = CreateWebcimesModal(...);
307
+ const myModal = createWebcimesModal(...);
262
308
 
263
309
  // Things
264
310
 
@@ -270,7 +316,7 @@ Or you can get the global container of all modals like this:
270
316
 
271
317
  ```javascript
272
318
  // Get the instance
273
- const myModal = CreateWebcimesModal(...);
319
+ const myModal = createWebcimesModal(...);
274
320
 
275
321
  // Things
276
322
 
@@ -283,7 +329,7 @@ myModal.modals;
283
329
  Multiple events exist, which allow to interact with the modal at each step. You can use all events below:
284
330
 
285
331
  ```javascript
286
- const myModal = CreateWebcimesModal({
332
+ const myModal = createWebcimesModal({
287
333
  beforeShow: () => {
288
334
  console.log('before show');
289
335
  }, // callback before show modal
@@ -309,7 +355,7 @@ You can also use `addEventListener` for get the events from the instance like th
309
355
 
310
356
  ```javascript
311
357
  // Get the instance
312
- const myModal = CreateWebcimesModal(...);
358
+ const myModal = createWebcimesModal(...);
313
359
 
314
360
  // Create an event on the current modal
315
361
  myModal.modal.addEventListener("afterDestroy", () => {
@@ -331,7 +377,7 @@ To destroy the modal, you have several ways:
331
377
 
332
378
  ```javascript
333
379
  // Get the instance
334
- const myModal = CreateWebcimesModal(...);
380
+ const myModal = createWebcimesModal(...);
335
381
 
336
382
  // Things
337
383
 
@@ -1,15 +1,18 @@
1
1
  // Import webcimes-modal
2
- import { CreateWebcimesModal } from '../dist/js/webcimes-modal.esm.js';
2
+ import { createWebcimesModal } from '../dist/js/webcimes-modal.esm.js';
3
3
 
4
4
  // Wait for dom content loaded
5
5
  document.addEventListener('DOMContentLoaded', function () {
6
- const myModal = CreateWebcimesModal({
6
+ // Example 1: Full options with string content
7
+ const myModal = createWebcimesModal({
7
8
  setId: null, // set specific id to the modal, default "null"
8
9
  setClass: null, // set specific class to the modal, default "null"
9
10
  width: 'auto', // width (specify the unit), default "auto"
10
11
  height: 'auto', // height (specify the unit), default "auto"
12
+ headerHtml: null, // html for header (overrides titleHtml), default "null"
11
13
  titleHtml: 'My title', // html for title, default "null"
12
14
  bodyHtml: 'My Body', // html for body, default "null"
15
+ footerHtml: null, // html for footer (overrides buttonCancelHtml and buttonConfirmHtml), default "null"
13
16
  buttonCancelHtml: 'Cancel', // html for cancel button, default "null"
14
17
  buttonConfirmHtml: 'Confirm', // html for confirm button, default "null"
15
18
  closeOnCancelButton: true, // close the modal after trigger cancel button, default "true"
@@ -46,9 +49,10 @@ document.addEventListener('DOMContentLoaded', function () {
46
49
  }, // callback after trigger confirm button
47
50
  });
48
51
 
49
- const myModal2 = CreateWebcimesModal({
52
+ // Example 2: Modal with HTMLElement from DOM
53
+ const myModal2 = createWebcimesModal({
50
54
  titleHtml: 'My title', // html for title, default "null"
51
- bodyHtml: document.querySelector('.test').outerHTML, // html for body, default "null"
55
+ bodyHtml: document.querySelector('.test'), // pass HTMLElement directly
52
56
  buttonCancelHtml: 'Cancel', // html for cancel button, default "null"
53
57
  buttonConfirmHtml: 'Confirm', // html for confirm button, default "null"
54
58
  closeOnConfirmButton: false, // close the modal after trigger confirm button, default "true"
@@ -60,4 +64,48 @@ document.addEventListener('DOMContentLoaded', function () {
60
64
  myModal2.destroy();
61
65
  }, // callback after trigger confirm button
62
66
  });
67
+
68
+ // Example 3: Modal with custom header and footer using functions
69
+ createWebcimesModal({
70
+ headerHtml: () => {
71
+ const header = document.createElement('div');
72
+ header.innerHTML =
73
+ '<h2 style="margin: 0; color: #333;">Custom Header</h2><p style="margin: 5px 0 0; font-size: 14px; color: #666;">With dynamic content</p>';
74
+ return header;
75
+ },
76
+ bodyHtml: () => {
77
+ const body = document.createElement('div');
78
+ body.innerHTML =
79
+ '<p>This modal demonstrates custom header and footer.</p><p>The close button is automatically added after the header content.</p>';
80
+ return body;
81
+ },
82
+ footerHtml: () => {
83
+ const footer = document.createElement('div');
84
+ footer.style.display = 'flex';
85
+ footer.style.gap = '10px';
86
+ footer.style.justifyContent = 'flex-end';
87
+
88
+ const cancelBtn = document.createElement('button');
89
+ cancelBtn.textContent = 'Custom Cancel';
90
+ cancelBtn.className = 'webcimes-modal__close';
91
+ cancelBtn.style.padding = '8px 16px';
92
+ cancelBtn.style.cursor = 'pointer';
93
+
94
+ const confirmBtn = document.createElement('button');
95
+ confirmBtn.textContent = 'Custom Confirm';
96
+ confirmBtn.className = 'webcimes-modal__close';
97
+ confirmBtn.style.padding = '8px 16px';
98
+ confirmBtn.style.cursor = 'pointer';
99
+ confirmBtn.style.background = '#007bff';
100
+ confirmBtn.style.color = 'white';
101
+ confirmBtn.style.border = 'none';
102
+ confirmBtn.style.borderRadius = '4px';
103
+
104
+ footer.appendChild(cancelBtn);
105
+ footer.appendChild(confirmBtn);
106
+ return footer;
107
+ },
108
+ showCloseButton: true, // Close button will be added after headerHtml content
109
+ allowCloseOutside: true,
110
+ });
63
111
  });
@@ -1,12 +1,15 @@
1
1
  // Wait for dom content loaded
2
2
  document.addEventListener('DOMContentLoaded', function () {
3
- const myModal = CreateWebcimesModal({
3
+ // Example 1: Full options with string content
4
+ const myModal = createWebcimesModal({
4
5
  setId: null, // set specific id to the modal, default "null"
5
6
  setClass: null, // set specific class to the modal, default "null"
6
7
  width: 'auto', // width (specify the unit), default "auto"
7
8
  height: 'auto', // height (specify the unit), default "auto"
9
+ headerHtml: null, // html for header (overrides titleHtml), default "null"
8
10
  titleHtml: 'My title', // html for title, default "null"
9
11
  bodyHtml: 'My Body', // html for body, default "null"
12
+ footerHtml: null, // html for footer (overrides buttonCancelHtml and buttonConfirmHtml), default "null"
10
13
  buttonCancelHtml: 'Cancel', // html for cancel button, default "null"
11
14
  buttonConfirmHtml: 'Confirm', // html for confirm button, default "null"
12
15
  closeOnCancelButton: true, // close the modal after trigger cancel button, default "true"
@@ -43,9 +46,10 @@ document.addEventListener('DOMContentLoaded', function () {
43
46
  }, // callback after trigger confirm button
44
47
  });
45
48
 
46
- const myModal2 = CreateWebcimesModal({
49
+ // Example 2: Modal with HTMLElement from DOM
50
+ const myModal2 = createWebcimesModal({
47
51
  titleHtml: 'My title', // html for title, default "null"
48
- bodyHtml: document.querySelector('.test').outerHTML, // html for body, default "null"
52
+ bodyHtml: document.querySelector('.test'), // pass HTMLElement directly
49
53
  buttonCancelHtml: 'Cancel', // html for cancel button, default "null"
50
54
  buttonConfirmHtml: 'Confirm', // html for confirm button, default "null"
51
55
  closeOnConfirmButton: false, // close the modal after trigger confirm button, default "true"
@@ -57,4 +61,48 @@ document.addEventListener('DOMContentLoaded', function () {
57
61
  myModal2.destroy();
58
62
  }, // callback after trigger confirm button
59
63
  });
64
+
65
+ // Example 3: Modal with custom header and footer using functions
66
+ createWebcimesModal({
67
+ headerHtml: () => {
68
+ const header = document.createElement('div');
69
+ header.innerHTML =
70
+ '<h2 style="margin: 0; color: #333;">Custom Header</h2><p style="margin: 5px 0 0; font-size: 14px; color: #666;">With dynamic content</p>';
71
+ return header;
72
+ },
73
+ bodyHtml: () => {
74
+ const body = document.createElement('div');
75
+ body.innerHTML =
76
+ '<p>This modal demonstrates custom header and footer.</p><p>The close button is automatically added after the header content.</p>';
77
+ return body;
78
+ },
79
+ footerHtml: () => {
80
+ const footer = document.createElement('div');
81
+ footer.style.display = 'flex';
82
+ footer.style.gap = '10px';
83
+ footer.style.justifyContent = 'flex-end';
84
+
85
+ const cancelBtn = document.createElement('button');
86
+ cancelBtn.textContent = 'Custom Cancel';
87
+ cancelBtn.className = 'webcimes-modal__close';
88
+ cancelBtn.style.padding = '8px 16px';
89
+ cancelBtn.style.cursor = 'pointer';
90
+
91
+ const confirmBtn = document.createElement('button');
92
+ confirmBtn.textContent = 'Custom Confirm';
93
+ confirmBtn.className = 'webcimes-modal__close';
94
+ confirmBtn.style.padding = '8px 16px';
95
+ confirmBtn.style.cursor = 'pointer';
96
+ confirmBtn.style.background = '#007bff';
97
+ confirmBtn.style.color = 'white';
98
+ confirmBtn.style.border = 'none';
99
+ confirmBtn.style.borderRadius = '4px';
100
+
101
+ footer.appendChild(cancelBtn);
102
+ footer.appendChild(confirmBtn);
103
+ return footer;
104
+ },
105
+ showCloseButton: true, // Close button will be added after headerHtml content
106
+ allowCloseOutside: true,
107
+ });
60
108
  });
@@ -29,14 +29,18 @@ export interface Options {
29
29
  width: string;
30
30
  /** height (specify unit), default "auto" */
31
31
  height: string;
32
+ /** html for header (overrides titleHtml), default "null" */
33
+ headerHtml: string | HTMLElement | (() => HTMLElement) | null;
32
34
  /** html for title, default "null" */
33
- titleHtml: string | null;
35
+ titleHtml: string | HTMLElement | (() => HTMLElement) | null;
34
36
  /** html for body, default "null" */
35
- bodyHtml: string | null;
37
+ bodyHtml: string | HTMLElement | (() => HTMLElement) | null;
38
+ /** html for footer (overrides buttonCancelHtml and buttonConfirmHtml), default "null" */
39
+ footerHtml: string | HTMLElement | (() => HTMLElement) | null;
36
40
  /** html for cancel button, default "null" */
37
- buttonCancelHtml: string | null;
41
+ buttonCancelHtml: string | HTMLElement | (() => HTMLElement) | null;
38
42
  /** html for confirm button, default "null" */
39
- buttonConfirmHtml: string | null;
43
+ buttonConfirmHtml: string | HTMLElement | (() => HTMLElement) | null;
40
44
  /** close modal after trigger cancel button, default "true" */
41
45
  closeOnCancelButton: boolean;
42
46
  /** close modal after trigger confirm button, default "true" */
@@ -93,5 +97,5 @@ export interface WebcimesModal {
93
97
  /**
94
98
  * Factory function to create a WebcimesModal instance with proper typing
95
99
  */
96
- export declare function CreateWebcimesModal(options: Partial<Options>): WebcimesModal;
100
+ export declare function createWebcimesModal(options: Partial<Options>): WebcimesModal;
97
101
  //# sourceMappingURL=webcimes-modal.d.ts.map
@@ -1,2 +1,2 @@
1
- var t={d:(o,e)=>{for(var s in e)t.o(e,s)&&!t.o(o,s)&&Object.defineProperty(o,s,{enumerable:!0,get:e[s]})},o:(t,o)=>Object.prototype.hasOwnProperty.call(t,o)},o={};t.d(o,{f:()=>s});class e{modals;modal;options;eventCancelButton=()=>{this.modal.dispatchEvent(new CustomEvent("onCancelButton")),"function"==typeof this.options.onCancelButton&&this.options.onCancelButton()};eventConfirmButton=()=>{this.modal.dispatchEvent(new CustomEvent("onConfirmButton")),"function"==typeof this.options.onConfirmButton&&this.options.onConfirmButton()};eventClickOutside=t=>{t.target==this.modals&&(this.options.allowCloseOutside?this.destroy():(this.modal.classList.add("animGrowShrink"),setTimeout((()=>{this.modal.classList.remove("animGrowShrink")}),this.options.animationDuration)))};eventClickCloseButton=()=>{this.destroy()};eventDragModalOnTop=t=>{if(!t.target.closest(".webcimes-modal__close")&&document.querySelectorAll(".webcimes-modal").length>1&&null!==this.modal.nextElementSibling){let t=this.modal.scrollTop;this.modals.insertAdjacentElement("beforeend",this.modal),this.modal.scrollTop=t}};position;offset;isDragging=!1;moveFromElements=[];eventDragStart=t=>{t.target.closest(".webcimes-modal__button")||(this.isDragging=!0,t.clientX?this.offset={x:this.modal.offsetLeft-t.clientX,y:this.modal.offsetTop-t.clientY}:t.touches&&(this.offset={x:this.modal.offsetLeft-t.touches[0].clientX,y:this.modal.offsetTop-t.touches[0].clientY}))};eventMove=t=>{this.isDragging&&(t.clientX?this.position={x:t.clientX,y:t.clientY}:t.touches&&(this.position={x:t.touches[0].clientX,y:t.touches[0].clientY}),this.modal.style.left=this.position.x+this.offset.x+"px",this.modal.style.top=this.position.y+this.offset.y+"px")};eventDragStop=()=>{this.isDragging=!1};eventPreventSelectText=t=>{this.isDragging&&t.preventDefault()};eventResize=()=>{this.modal.style.removeProperty("left"),this.modal.style.removeProperty("top")};constructor(t){this.options={setId:null,setClass:null,width:"auto",height:"auto",titleHtml:null,bodyHtml:null,buttonCancelHtml:null,buttonConfirmHtml:null,closeOnCancelButton:!0,closeOnConfirmButton:!0,showCloseButton:!0,allowCloseOutside:!0,allowMovement:!0,moveFromHeader:!0,moveFromBody:!1,moveFromFooter:!0,stickyHeader:!0,stickyFooter:!0,style:null,animationOnShow:"animDropDown",animationOnDestroy:"animDropUp",animationDuration:500,beforeShow:()=>{},afterShow:()=>{},beforeDestroy:()=>{},afterDestroy:()=>{},onCancelButton:()=>{},onConfirmButton:()=>{},...t},this.init()}init(){if(document.querySelector(".webcimes-modals")?(this.modals=document.querySelector(".webcimes-modals"),this.modals.classList.remove("animFadeOut")):(document.body.insertAdjacentHTML("beforeend",'<div class="webcimes-modals animFadeIn"></div>'),this.modals=document.querySelector(".webcimes-modals"),this.modals.style.setProperty("animation-duration",this.options.animationDuration+"ms"),setTimeout((()=>{this.modals.classList.remove("animFadeIn")}),this.options.animationDuration)),this.modals.insertAdjacentHTML("beforeend",'<div class="webcimes-modal '+(this.options.setClass?this.options.setClass:"")+" "+this.options.animationOnShow+'" '+(this.options.setId?'id="'+this.options.setId+'"':"")+">\n\t\t\t\t"+(this.options.titleHtml||this.options.showCloseButton?'<div class="webcimes-modal__header '+(this.options.stickyHeader?"webcimes-modal__header--is-sticky":"")+" "+(this.options.moveFromHeader?"webcimes-modal__header--is-movable":"")+'">\n\t\t\t\t\t\t'+(this.options.titleHtml?'<div class="webcimes-modal__title">'+this.options.titleHtml+"</div>":"")+"\n\t\t\t\t\t\t"+(this.options.showCloseButton?'<button class="webcimes-modal__button webcimes-modal__header-close webcimes-modal__close"></button>':"")+"\n\t\t\t\t\t</div>":"")+"\n\t\t\t\t"+(this.options.bodyHtml?'<div class="webcimes-modal__body '+(this.options.moveFromBody?".webcimes-modal__body--is-movable":"")+'">\n\t\t\t\t\t\t'+this.options.bodyHtml+"\n\t\t\t\t\t</div>":"")+"\n\t\t\t\t"+(this.options.buttonCancelHtml||this.options.buttonConfirmHtml?'<div class="webcimes-modal__footer '+(this.options.stickyFooter?".webcimes-modal__footer--is-sticky":"")+" "+(this.options.moveFromFooter?"webcimes-modal__footer--is-movable":"")+'">\n\t\t\t\t\t\t'+(this.options.buttonCancelHtml?'<button class="webcimes-modal__button webcimes-modal__footer-button webcimes-modal__footer-button--cancel '+(this.options.closeOnCancelButton?"webcimes-modal__close":"")+'">'+this.options.buttonCancelHtml+"</button>":"")+"\n\t\t\t\t\t\t"+(this.options.buttonConfirmHtml?'<button class="webcimes-modal__button webcimes-modal__footer-button webcimes-modal__footer-button--confirm '+(this.options.closeOnConfirmButton?"webcimes-modal__close":"")+'">'+this.options.buttonConfirmHtml+"</button>":"")+"\n\t\t\t\t\t</div>":"")+"\n\t\t\t</div>"),this.modal=this.modals.lastElementChild,setTimeout((()=>{this.modal.dispatchEvent(new CustomEvent("beforeShow")),"function"==typeof this.options.beforeShow&&this.options.beforeShow()}),0),this.modal.style.setProperty("animation-duration",this.options.animationDuration+"ms"),setTimeout((()=>{this.modal.classList.remove(this.options.animationOnShow),this.modal.dispatchEvent(new CustomEvent("afterShow")),"function"==typeof this.options.afterShow&&this.options.afterShow()}),this.options.animationDuration),this.modal.style.setProperty("max-width","90%"),"auto"!=this.options.width&&this.options.width?this.modal.style.setProperty("width",this.options.width):this.modal.style.setProperty("width","max-content"),this.modal.style.setProperty("max-height","90%"),"auto"!=this.options.height&&this.options.height?this.modal.style.setProperty("height",this.options.height):this.modal.style.setProperty("height","max-content"),this.options.style){let t=this.modal.getAttribute("style")??"";this.modal.setAttribute("style",t+this.options.style)}this.options.buttonCancelHtml&&this.modal.querySelector(".webcimes-modal__footer-button--cancel")?.addEventListener("click",this.eventCancelButton),this.options.buttonConfirmHtml&&this.modal.querySelector(".webcimes-modal__footer-button--confirm")?.addEventListener("click",this.eventConfirmButton),this.modals.addEventListener("click",this.eventClickOutside),this.modal.querySelectorAll(".webcimes-modal__close").forEach((t=>{t.addEventListener("click",this.eventClickCloseButton)})),["mousedown","touchstart"].forEach((t=>{this.modal.addEventListener(t,this.eventDragModalOnTop)})),this.options.allowMovement&&(this.options.moveFromHeader||this.options.moveFromBody||this.options.moveFromFooter)&&(this.options.moveFromHeader&&this.modal.querySelector(".webcimes-modal__header")&&this.moveFromElements.push(this.modal.querySelector(".webcimes-modal__header")),this.options.moveFromBody&&this.modal.querySelector(".webcimes-modal__body")&&this.moveFromElements.push(this.modal.querySelector(".webcimes-modal__body")),this.options.moveFromFooter&&this.modal.querySelector(".webcimes-modal__footer")&&this.moveFromElements.push(this.modal.querySelector(".webcimes-modal__footer")),["mousedown","touchstart"].forEach((t=>{this.moveFromElements.forEach((o=>{o.addEventListener(t,this.eventDragStart)}))})),["mousemove","touchmove"].forEach((t=>{document.addEventListener(t,this.eventMove)})),["mouseup","touchend"].forEach((t=>{document.addEventListener(t,this.eventDragStop)})),document.addEventListener("selectstart",this.eventPreventSelectText)),window.addEventListener("resize",this.eventResize)}destroy(){this.modal.getAttribute("data-destroying")||(this.modal.dispatchEvent(new CustomEvent("beforeDestroy")),"function"==typeof this.options.beforeDestroy&&this.options.beforeDestroy(),1==document.querySelectorAll(".webcimes-modal:not([data-destroying])").length&&this.modals.classList.add("animFadeOut"),this.modal.setAttribute("data-destroying","1"),this.modal.classList.add(this.options.animationOnDestroy),setTimeout((()=>{void 0!==this.modal&&(this.options.buttonCancelHtml&&this.modal.querySelector(".webcimes-modal__footer-button--cancel")?.removeEventListener("click",this.eventCancelButton),this.options.buttonConfirmHtml&&this.modal.querySelector(".webcimes-modal__footer-button--confirm")?.removeEventListener("click",this.eventConfirmButton),this.modals.removeEventListener("click",this.eventClickOutside),this.modal.querySelectorAll(".webcimes-modal__close").forEach((t=>{t.removeEventListener("click",this.eventClickCloseButton)})),["mousedown","touchstart"].forEach((t=>{this.modal.removeEventListener(t,this.eventDragModalOnTop)})),this.options.allowMovement&&(this.options.moveFromHeader||this.options.moveFromBody||this.options.moveFromFooter)&&(["mousedown","touchstart"].forEach((t=>{this.moveFromElements.forEach((o=>{o.removeEventListener(t,this.eventDragStart)}))})),["mousemove","touchmove"].forEach((t=>{document.removeEventListener(t,this.eventMove)})),["mouseup","touchend"].forEach((t=>{document.removeEventListener(t,this.eventDragStop)})),document.removeEventListener("selectstart",this.eventPreventSelectText)),window.removeEventListener("resize",this.eventResize),(document.querySelectorAll(".webcimes-modal").length>1?this.modal:this.modals).remove()),this.modal.dispatchEvent(new CustomEvent("afterDestroy")),"function"==typeof this.options.afterDestroy&&this.options.afterDestroy()}),this.options.animationDuration))}}function s(t){return new e(t)}var i=o.f;export{i as CreateWebcimesModal};
1
+ var t={d:(e,o)=>{for(var s in o)t.o(o,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:o[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{H:()=>s});class o{modals;modal;options;eventCancelButton=()=>{this.modal.dispatchEvent(new CustomEvent("onCancelButton")),"function"==typeof this.options.onCancelButton&&this.options.onCancelButton()};eventConfirmButton=()=>{this.modal.dispatchEvent(new CustomEvent("onConfirmButton")),"function"==typeof this.options.onConfirmButton&&this.options.onConfirmButton()};eventClickOutside=t=>{t.target==this.modals&&(this.options.allowCloseOutside?this.destroy():(this.modal.classList.add("animGrowShrink"),setTimeout((()=>{this.modal.classList.remove("animGrowShrink")}),this.options.animationDuration)))};eventClickCloseButton=()=>{this.destroy()};eventDragModalOnTop=t=>{if(!t.target.closest(".webcimes-modal__close")&&document.querySelectorAll(".webcimes-modal").length>1&&null!==this.modal.nextElementSibling){let t=this.modal.scrollTop;this.modals.insertAdjacentElement("beforeend",this.modal),this.modal.scrollTop=t}};position;offset;isDragging=!1;moveFromElements=[];eventDragStart=t=>{t.target.closest(".webcimes-modal__button")||(this.isDragging=!0,t.clientX?this.offset={x:this.modal.offsetLeft-t.clientX,y:this.modal.offsetTop-t.clientY}:t.touches&&(this.offset={x:this.modal.offsetLeft-t.touches[0].clientX,y:this.modal.offsetTop-t.touches[0].clientY}))};eventMove=t=>{this.isDragging&&(t.clientX?this.position={x:t.clientX,y:t.clientY}:t.touches&&(this.position={x:t.touches[0].clientX,y:t.touches[0].clientY}),this.modal.style.left=this.position.x+this.offset.x+"px",this.modal.style.top=this.position.y+this.offset.y+"px")};eventDragStop=()=>{this.isDragging=!1};eventPreventSelectText=t=>{this.isDragging&&t.preventDefault()};eventResize=()=>{this.modal.style.removeProperty("left"),this.modal.style.removeProperty("top")};setElementContent(t,e){"string"==typeof e?t.innerHTML=e:"function"==typeof e?t.appendChild(e()):t.appendChild(e)}buildHeader(){if(!this.options.headerHtml&&!this.options.titleHtml&&!this.options.showCloseButton)return null;const t=document.createElement("div");if(t.className="webcimes-modal__header",this.options.stickyHeader&&t.classList.add("webcimes-modal__header--is-sticky"),this.options.moveFromHeader&&t.classList.add("webcimes-modal__header--is-movable"),this.options.headerHtml){if(this.setElementContent(t,this.options.headerHtml),this.options.showCloseButton){const e=document.createElement("button");e.className="webcimes-modal__button webcimes-modal__header-close webcimes-modal__close",e.setAttribute("aria-label","Close modal"),t.appendChild(e)}return t}if(this.options.titleHtml){const e=document.createElement("div");e.className="webcimes-modal__title",this.setElementContent(e,this.options.titleHtml),t.appendChild(e)}if(this.options.showCloseButton){const e=document.createElement("button");e.className="webcimes-modal__button webcimes-modal__header-close webcimes-modal__close",e.setAttribute("aria-label","Close modal"),t.appendChild(e)}return t}buildBody(){if(!this.options.bodyHtml)return null;const t=document.createElement("div");return t.className="webcimes-modal__body",this.options.moveFromBody&&t.classList.add("webcimes-modal__body--is-movable"),this.setElementContent(t,this.options.bodyHtml),t}buildFooter(){if(!this.options.footerHtml&&!this.options.buttonCancelHtml&&!this.options.buttonConfirmHtml)return null;const t=document.createElement("div");if(t.className="webcimes-modal__footer",this.options.stickyFooter&&t.classList.add("webcimes-modal__footer--is-sticky"),this.options.moveFromFooter&&t.classList.add("webcimes-modal__footer--is-movable"),this.options.footerHtml)return this.setElementContent(t,this.options.footerHtml),t;if(this.options.buttonCancelHtml){const e=document.createElement("button");e.className="webcimes-modal__button webcimes-modal__footer-button webcimes-modal__footer-button--cancel",this.options.closeOnCancelButton&&e.classList.add("webcimes-modal__close"),this.setElementContent(e,this.options.buttonCancelHtml),t.appendChild(e)}if(this.options.buttonConfirmHtml){const e=document.createElement("button");e.className="webcimes-modal__button webcimes-modal__footer-button webcimes-modal__footer-button--confirm",this.options.closeOnConfirmButton&&e.classList.add("webcimes-modal__close"),this.setElementContent(e,this.options.buttonConfirmHtml),t.appendChild(e)}return t}buildModal(){const t=document.createElement("div");t.className=`webcimes-modal ${this.options.animationOnShow}`,t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),this.options.setClass&&t.classList.add(this.options.setClass),this.options.setId&&(t.id=this.options.setId);const e=this.buildHeader();e&&t.appendChild(e);const o=this.buildBody();o&&t.appendChild(o);const s=this.buildFooter();return s&&t.appendChild(s),t}constructor(t){this.options={setId:null,setClass:null,width:"auto",height:"auto",headerHtml:null,titleHtml:null,bodyHtml:null,footerHtml:null,buttonCancelHtml:null,buttonConfirmHtml:null,closeOnCancelButton:!0,closeOnConfirmButton:!0,showCloseButton:!0,allowCloseOutside:!0,allowMovement:!0,moveFromHeader:!0,moveFromBody:!1,moveFromFooter:!0,stickyHeader:!0,stickyFooter:!0,style:null,animationOnShow:"animDropDown",animationOnDestroy:"animDropUp",animationDuration:500,beforeShow:()=>{},afterShow:()=>{},beforeDestroy:()=>{},afterDestroy:()=>{},onCancelButton:()=>{},onConfirmButton:()=>{},...t},this.init()}init(){if(document.querySelector(".webcimes-modals")?(this.modals=document.querySelector(".webcimes-modals"),this.modals.classList.remove("animFadeOut")):(this.modals=document.createElement("div"),this.modals.className="webcimes-modals animFadeIn",this.modals.style.setProperty("animation-duration",this.options.animationDuration+"ms"),document.body.appendChild(this.modals),setTimeout((()=>{this.modals.classList.remove("animFadeIn")}),this.options.animationDuration)),this.modal=this.buildModal(),this.modals.appendChild(this.modal),setTimeout((()=>{this.modal.dispatchEvent(new CustomEvent("beforeShow")),"function"==typeof this.options.beforeShow&&this.options.beforeShow()}),0),this.modal.style.setProperty("animation-duration",this.options.animationDuration+"ms"),setTimeout((()=>{this.modal.classList.remove(this.options.animationOnShow),this.modal.dispatchEvent(new CustomEvent("afterShow")),"function"==typeof this.options.afterShow&&this.options.afterShow()}),this.options.animationDuration),this.modal.style.setProperty("max-width","90%"),"auto"!=this.options.width&&this.options.width?this.modal.style.setProperty("width",this.options.width):this.modal.style.setProperty("width","max-content"),this.modal.style.setProperty("max-height","90%"),"auto"!=this.options.height&&this.options.height?this.modal.style.setProperty("height",this.options.height):this.modal.style.setProperty("height","max-content"),this.options.style){let t=this.modal.getAttribute("style")??"";this.modal.setAttribute("style",t+this.options.style)}this.options.buttonCancelHtml&&this.modal.querySelector(".webcimes-modal__footer-button--cancel")?.addEventListener("click",this.eventCancelButton),this.options.buttonConfirmHtml&&this.modal.querySelector(".webcimes-modal__footer-button--confirm")?.addEventListener("click",this.eventConfirmButton),this.modals.addEventListener("click",this.eventClickOutside),this.modal.querySelectorAll(".webcimes-modal__close").forEach((t=>{t.addEventListener("click",this.eventClickCloseButton)})),["mousedown","touchstart"].forEach((t=>{this.modal.addEventListener(t,this.eventDragModalOnTop)})),this.options.allowMovement&&(this.options.moveFromHeader||this.options.moveFromBody||this.options.moveFromFooter)&&(this.options.moveFromHeader&&this.modal.querySelector(".webcimes-modal__header")&&this.moveFromElements.push(this.modal.querySelector(".webcimes-modal__header")),this.options.moveFromBody&&this.modal.querySelector(".webcimes-modal__body")&&this.moveFromElements.push(this.modal.querySelector(".webcimes-modal__body")),this.options.moveFromFooter&&this.modal.querySelector(".webcimes-modal__footer")&&this.moveFromElements.push(this.modal.querySelector(".webcimes-modal__footer")),["mousedown","touchstart"].forEach((t=>{this.moveFromElements.forEach((e=>{e.addEventListener(t,this.eventDragStart)}))})),["mousemove","touchmove"].forEach((t=>{document.addEventListener(t,this.eventMove)})),["mouseup","touchend"].forEach((t=>{document.addEventListener(t,this.eventDragStop)})),document.addEventListener("selectstart",this.eventPreventSelectText)),window.addEventListener("resize",this.eventResize)}destroy(){this.modal.getAttribute("data-destroying")||(this.modal.dispatchEvent(new CustomEvent("beforeDestroy")),"function"==typeof this.options.beforeDestroy&&this.options.beforeDestroy(),1==document.querySelectorAll(".webcimes-modal:not([data-destroying])").length&&this.modals.classList.add("animFadeOut"),this.modal.setAttribute("data-destroying","1"),this.modal.classList.add(this.options.animationOnDestroy),setTimeout((()=>{void 0!==this.modal&&(this.options.buttonCancelHtml&&this.modal.querySelector(".webcimes-modal__footer-button--cancel")?.removeEventListener("click",this.eventCancelButton),this.options.buttonConfirmHtml&&this.modal.querySelector(".webcimes-modal__footer-button--confirm")?.removeEventListener("click",this.eventConfirmButton),this.modals.removeEventListener("click",this.eventClickOutside),this.modal.querySelectorAll(".webcimes-modal__close").forEach((t=>{t.removeEventListener("click",this.eventClickCloseButton)})),["mousedown","touchstart"].forEach((t=>{this.modal.removeEventListener(t,this.eventDragModalOnTop)})),this.options.allowMovement&&(this.options.moveFromHeader||this.options.moveFromBody||this.options.moveFromFooter)&&(["mousedown","touchstart"].forEach((t=>{this.moveFromElements.forEach((e=>{e.removeEventListener(t,this.eventDragStart)}))})),["mousemove","touchmove"].forEach((t=>{document.removeEventListener(t,this.eventMove)})),["mouseup","touchend"].forEach((t=>{document.removeEventListener(t,this.eventDragStop)})),document.removeEventListener("selectstart",this.eventPreventSelectText)),window.removeEventListener("resize",this.eventResize),(document.querySelectorAll(".webcimes-modal").length>1?this.modal:this.modals).remove()),this.modal.dispatchEvent(new CustomEvent("afterDestroy")),"function"==typeof this.options.afterDestroy&&this.options.afterDestroy()}),this.options.animationDuration))}}function s(t){return new o(t)}var i=e.H;export{i as createWebcimesModal};
2
2
  //# sourceMappingURL=webcimes-modal.esm.js.map