@daracl/dialog 0.0.6 → 0.0.8

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/dist/index.html DELETED
@@ -1,101 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
-
4
- <head>
5
- <meta charset="utf-8">
6
- <meta http-equiv="X-UA-compatible" content="IE=edge">
7
- <title>Dialog Notification - Darainfo</title>
8
- <link rel="stylesheet" href="../dist/daracl.dialog.min.css">
9
-
10
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
11
-
12
- <script defer src="daracl.dialog.js"></script></head>
13
-
14
- <body onload="dialogView()">
15
-
16
- <div style="padding-top:80px;">
17
- <div class="dialog-button">
18
- <button type="button" onclick="dialogEvent('show')">Show</button>
19
- <button type="button" onclick="dialogEvent('max')">Max</button>
20
- </div>
21
- </div>
22
-
23
- <div id="content"></div>
24
- </body>
25
-
26
- </html>
27
-
28
- <style>
29
- .dialog-button button {
30
- border: none;
31
- outline: none;
32
- cursor: pointer;
33
- margin: 0 5px;
34
- font-size: 1.2rem;
35
- padding: 10px 20px;
36
- border-radius: 4px;
37
- }
38
- </style>
39
-
40
- <script>
41
- var htmlStr = [];
42
- for (var i = 0; i < 1000; i++) {
43
- htmlStr.push(' <h2>dialog message</h2>');
44
- }
45
-
46
- //document.getElementById("content").innerHTML = htmlStr.join('');
47
- var dialogObj;
48
- function dialogView() {
49
- dialogObj = Daracl.dialog.create({
50
- title: 'dialog', width: 500, height: 'auto', icon: "info", isModal: true, resizable: true, autoOpen: false, template: '<a href="https://varsql.com" target="_blank">링크 이동</a>', buttons: [
51
- {
52
- label: 'ok', styleClass: "info", callback: function (e) {
53
- alert('ok')
54
- }
55
- }
56
- , {
57
- label: 'Cancel', callback: function (e) {
58
- dialogObj.hide();
59
- }
60
- }
61
- ], afterOpen: function () {
62
- console.log('after open')
63
- }
64
- });
65
-
66
- return;
67
-
68
- Daracl.dialog.create({
69
- title: 'dialog2222', width: 200, height: '150px', isModal1: true, template: 'https://www.naver.com', buttons: [
70
- {
71
- label: 'close', styleClass: "info", callback: function (e) {
72
- alert('11')
73
- console.log(e)
74
- }
75
- }
76
- , {
77
- label: 'Cancel', callback: function (e) {
78
- alert('22')
79
- console.log(e)
80
- }
81
- }
82
- ]
83
- });
84
- }
85
-
86
- function dialogEvent(mode) {
87
- switch (mode) {
88
- case 'show':
89
- dialogObj.show()
90
- break;
91
- case 'max':
92
- dialogObj.maximise()
93
- break;
94
-
95
- default:
96
- break;
97
- }
98
- }
99
-
100
-
101
- </script>
package/src/index.js DELETED
@@ -1,544 +0,0 @@
1
- let DIALOG_IDX = 0;
2
-
3
- const iconStyleMap = {
4
- primary: "primary",
5
- secondary: "secondary",
6
- info: "info",
7
- success: "success",
8
- warning: "warning",
9
- danger: "danger",
10
- };
11
-
12
- /**
13
- * 다이얼로그 옵션
14
- * @typedef {Object} defaultOptions
15
- * @property {string, number} [width = 400] - 넓이
16
- * @property {string, number} [height= 300] - 높이
17
- * @property {string} styleClass - css class
18
- * @property {boolean} [isModal= false] - 모달 사용여부
19
- * @property {string} [icon= ""] - icon primary, secondary, info, success, warning, danger
20
- * @property {boolean} [autoOpen= true] - 자동 열기 여부
21
- * @property {boolean} [draggable= true] - drag 가능여부
22
- * @property {boolean} [resizable= false] - 창 리사이즈 여부
23
- * @property {boolean} [enableHeader= true] - 헤더 영역 보일지 여부
24
- * @property {boolean} [enableFooter= true] - 하단 버튼 영역 보일지 여부
25
- * @property {boolean} [enableMaxButton= true] - 최대화 버튼
26
- * @property {boolean} [enableCloseButton= true] - 닫기 버튼 활성화 여부
27
- * @property {number} [minHeight= 130] - 최소 높이
28
- * @property {number} [minWidth= 230] - 최소 넓이
29
- * @property {number} [zIndex= 10000] - css z-index
30
- * @property {string} [dragOverflow= true] - darg 창 넘어서 drag 할지 여부
31
- * @property {Array} buttons= [] - dialog 하단 버튼
32
- * @property {number} moveDelay= 15 - drag delay time
33
- * @property {function} afterOpen - 오픈후
34
- */
35
-
36
- /** @type {defaultOptions} */
37
- let defaultOptions = {
38
- width: 400,
39
- height: 300,
40
- styleClass: "",
41
- isModal: false,
42
- icon: "", // info,
43
- // 자동 열기 여부
44
- autoOpen: true,
45
- // drag 가능여부
46
- draggable: true,
47
- // 창 리사이즈 여부
48
- resizable: false,
49
- // 헤더 영역 보일지 여부
50
- enableHeader: true,
51
- // 하단 버튼 영역 보일지 여부
52
- enableFooter: true,
53
- // 최대화 버튼
54
- enableMaxButton: true,
55
- // 닫기 버튼 활성화 여부
56
- enableCloseButton: true,
57
- // 최소 높이
58
- minHeight: 130,
59
- // 최소 넓이
60
- minWidth: 230,
61
- // css z-index
62
- zIndex: 10000,
63
- dragOverflow: true,
64
- buttons: [],
65
- moveDelay: 15,
66
- afterOpen: false, // open 후 호출 메소드
67
- };
68
-
69
- function dialogHiddenElement() {
70
- if (document.getElementById("daraclDialogHidden") == null) {
71
- document.querySelector("body")?.insertAdjacentHTML("beforeend", `<div id="daraclDialogHidden" class="daracl-dialog-hidden"></div>`);
72
- }
73
-
74
- return document.getElementById("daraclDialogHidden");
75
- }
76
-
77
- /**
78
- * dialog 모듈
79
- *
80
- * @export
81
- * @class Dialog
82
- * @typedef {Dialog}
83
- */
84
- export default class Dialog {
85
- static VERSION = APP_VERSION;
86
- constructor(options) {
87
- if (typeof options === "string") {
88
- options = { items: options };
89
- }
90
-
91
- this.options = Object.assign({}, defaultOptions, options);
92
- this.idx = DIALOG_IDX += 1;
93
-
94
- const dialogWrapperElement = document.createElement("div");
95
- dialogWrapperElement.className = `daracl-dialog-wrapper hide dd-${DIALOG_IDX}`;
96
- const style = dialogWrapperElement.style;
97
- style.zIndex = this.options.zIndex + DIALOG_IDX;
98
- style.width = this.options.width == "auto" ? "auto" : this.options.width + "px";
99
- style.height = this.options.height == "auto" ? "auto" : this.options.height + "px";
100
- style.minHeight = this.options.minHeight + "px";
101
- style.minWidth = this.options.minWidth + "px";
102
-
103
- dialogHiddenElement().appendChild(dialogWrapperElement);
104
- this.dialogWrapperElement = dialogWrapperElement;
105
-
106
- this.dialogTemplate();
107
-
108
- if (this.options.draggable !== false) {
109
- this.initDrag();
110
- }
111
-
112
- if (this.options.resizable === true) {
113
- dialogWrapperElement.classList.add("resizable");
114
- this.initResize();
115
- }
116
-
117
- if (this.options.autoOpen !== false) {
118
- this.show();
119
- }
120
- }
121
-
122
- static create(options) {
123
- return new Dialog(options);
124
- }
125
-
126
- /**
127
- * default options 셋팅
128
- *
129
- * @static
130
- * @typedef {Object} defaultOptions
131
- */
132
- static setOptions(options) {
133
- defaultOptions = Object.assign({}, defaultOptions, options);
134
- }
135
-
136
- /** 사이즈 조절 초기화 */
137
- initResize() {
138
- const dialogElement = this.dialogWrapperElement;
139
- const reslzeElement = this.dialogWrapperElement.querySelectorAll(".resizer");
140
-
141
- let dialogWidth, dialogHeight;
142
- let startX, startY;
143
- let moveMode = "";
144
- let offsetX = -1,
145
- offsetY = -1;
146
-
147
- let isResizeTop, isResizeLeft;
148
-
149
- this.addEvent(reslzeElement, "mousedown touchdown", (e) => {
150
- if (this.isMaximise()) {
151
- return false;
152
- }
153
-
154
- moveMode = e.target.getAttribute("data-mode");
155
-
156
- isResizeTop = moveMode.indexOf("t") > -1;
157
- isResizeLeft = moveMode.indexOf("l") > -1;
158
-
159
- offsetX = isResizeLeft ? dialogElement.getBoundingClientRect().left : -1;
160
- offsetY = isResizeTop ? dialogElement.getBoundingClientRect().top : -1;
161
-
162
- e.preventDefault();
163
-
164
- const oe = e.touches;
165
-
166
- startX = oe && oe[0] ? oe[0].pageX : e.pageX;
167
- startY = oe && oe[0] ? oe[0].pageY : e.pageY;
168
-
169
- dialogWidth = dialogElement.clientWidth;
170
- dialogHeight = dialogElement.clientHeight;
171
-
172
- if (!dialogElement.classList.contains("transform-disable")) {
173
- const offsetX = e.clientX - dialogElement.getBoundingClientRect().left;
174
- const offsetY = e.clientY - dialogElement.getBoundingClientRect().top;
175
-
176
- this.setPosition(e, offsetX, offsetY, dialogWidth, dialogHeight);
177
-
178
- dialogElement.classList.add("transform-disable");
179
- }
180
-
181
- this.addEvent(document, "mousemove touchmove", onResizeMouseMove);
182
-
183
- this.addEvent(document, "mouseup touchup", onResizeMouseUp);
184
- });
185
- let startTime = -1;
186
- let moveTimer;
187
- const moveDelay = this.options.moveDelay;
188
- const onResizeMouseMove = (e) => {
189
- if (startTime == -1) {
190
- startTime = new Date().getTime();
191
- }
192
-
193
- if (new Date().getTime() - moveDelay <= startTime) {
194
- clearTimeout(moveTimer);
195
- }
196
-
197
- const oe1 = e.touches;
198
-
199
- moveTimer = setTimeout(() => {
200
- startTime = -1;
201
- let moveX = (oe1 && oe1[0] ? oe1[0].pageX : e.pageX) - startX,
202
- moveY = (oe1 && oe1[0] ? oe1[0].pageY : e.pageY) - startY;
203
-
204
- moveY = isResizeTop ? moveY * -1 : moveY;
205
- moveX = isResizeLeft ? moveX * -1 : moveX;
206
-
207
- let resizeHeight = dialogHeight + moveY,
208
- resizeWidth = dialogWidth + moveX;
209
-
210
- if (this.options.minHeight >= resizeHeight) {
211
- resizeHeight = this.options.minHeight;
212
- moveY = (dialogHeight - resizeHeight) * -1;
213
- }
214
-
215
- if (this.options.minWidth >= resizeWidth) {
216
- resizeWidth = this.options.minWidth;
217
- moveX = (dialogWidth - resizeWidth) * -1;
218
- }
219
-
220
- let topVal = -1;
221
- if (isResizeTop) {
222
- topVal = offsetY - moveY;
223
- if (topVal <= 0) {
224
- topVal = 0;
225
- resizeHeight = dialogHeight + offsetY;
226
- }
227
- dialogElement.style.top = topVal + "px";
228
- }
229
-
230
- let leftVal = -1;
231
- if (isResizeLeft) {
232
- leftVal = offsetX - moveX;
233
- if (leftVal <= 0) {
234
- leftVal = 0;
235
- resizeWidth = dialogWidth + offsetX;
236
- }
237
- dialogElement.style.left = leftVal + "px";
238
- }
239
-
240
- if (moveMode != "b" && moveMode != "t") {
241
- dialogElement.style.width = resizeWidth + "px";
242
- }
243
-
244
- if (moveMode != "r" && moveMode != "l") {
245
- dialogElement.style.height = resizeHeight + "px";
246
- }
247
- }, moveDelay);
248
- };
249
-
250
- const onResizeMouseUp = () => {
251
- clearTimeout(moveTimer);
252
- this.removeEvent(document, "mousemove touchmove", onResizeMouseMove);
253
- this.removeEvent(document, "mouseup touchup", onResizeMouseUp);
254
- };
255
- }
256
-
257
- /**
258
- * init drag
259
- */
260
- initDrag() {
261
- const dialogElement = this.dialogWrapperElement;
262
- const dragElement = this.dialogWrapperElement.querySelector(".dialog-header");
263
-
264
- let isDragging = false;
265
-
266
- let offsetX, offsetY, dialogWidth, dialogHeight;
267
-
268
- let isDrag = false;
269
-
270
- this.addEvent(dragElement, "mousedown touchdown", (e) => {
271
- const tagName = e.target.tagName;
272
-
273
- if (tagName.search(/(input|textarea|select|button)/gi) > -1) {
274
- return true;
275
- }
276
-
277
- if (this.isMaximise()) {
278
- return false;
279
- }
280
-
281
- e.preventDefault();
282
-
283
- dialogWidth = dialogElement.clientWidth;
284
- dialogHeight = dialogElement.clientHeight;
285
-
286
- isDragging = true;
287
- offsetX = e.clientX - dialogElement.getBoundingClientRect().left;
288
- offsetY = e.clientY - dialogElement.getBoundingClientRect().top;
289
-
290
- if (!isDrag) {
291
- this.setPosition(e, offsetX, offsetY, dialogWidth, dialogHeight);
292
-
293
- isDrag = true;
294
- dialogElement.classList.add("transform-disable");
295
- }
296
-
297
- dialogElement.classList.add("move-on");
298
-
299
- this.addEvent(document, "mousemove touchmove", onMouseMove);
300
-
301
- this.addEvent(document, "mouseup touchup", onMouseUp);
302
- });
303
- let startTime = -1;
304
- let moveTimer;
305
- const moveDelay = this.options.moveDelay;
306
- const onMouseMove = (e) => {
307
- if (isDragging) {
308
- if (startTime == -1) {
309
- startTime = new Date().getTime();
310
- }
311
-
312
- if (new Date().getTime() - moveDelay <= startTime) {
313
- clearTimeout(moveTimer);
314
- }
315
-
316
- moveTimer = setTimeout(() => {
317
- startTime = -1;
318
- this.setPosition(e, offsetX, offsetY, dialogWidth, dialogHeight);
319
- }, moveDelay);
320
- }
321
- };
322
-
323
- const onMouseUp = () => {
324
- isDragging = false;
325
- clearTimeout(moveTimer);
326
-
327
- dialogElement.classList.remove("move-on");
328
- this.removeEvent(document, "mousemove touchmove", onMouseMove);
329
- this.removeEvent(document, "mouseup touchup", onMouseUp);
330
- };
331
- }
332
-
333
- /**
334
- * dialog position
335
- *
336
- * @param {Event} e event
337
- * @param {Number} offsetX offset x
338
- * @param {Number} offsetY offset y
339
- * @param {Number} dialogWidth dialog width
340
- * @param {Number} dialogHeight dialog height
341
- */
342
- setPosition(e, offsetX, offsetY, dialogWidth, dialogHeight) {
343
- let minX, minY;
344
- if (this.options.dragOverflow === false) {
345
- minX = Math.min(Math.max(e.clientX - offsetX, 0), window.innerWidth - dialogWidth);
346
- minY = Math.min(Math.max(e.clientY - offsetY, 0), window.innerHeight - dialogHeight);
347
- } else {
348
- minX = Math.min(Math.max(e.clientX - offsetX, (dialogWidth - 80) * -1), window.innerWidth - 80);
349
-
350
- minY = Math.min(Math.max(e.clientY - offsetY, 0), window.innerHeight - 30);
351
- }
352
-
353
- this.dialogWrapperElement.style.left = minX + "px";
354
- this.dialogWrapperElement.style.top = minY + "px";
355
- }
356
-
357
- dialogTemplate() {
358
- const enableHeader = this.options.enableHeader !== false;
359
- const dialog = document.createElement("div");
360
- const styleClass = this.options.styleClass ?? "";
361
-
362
- dialog.className = `daracl-dialog ${styleClass}`;
363
-
364
- let dialogHtml = [];
365
-
366
- if (enableHeader) {
367
- dialogHtml.push(
368
- `<div class="dialog-header" >
369
- ${this.options.title ?? ""}
370
- <div class="btn-area">
371
- ${this.options.enableMaxButton ? `<span class="dialog-maximise"></span>` : ""}
372
- ${this.options.enableCloseButton ? `<span class="dialog-close"></span>` : ""}
373
- </div>
374
- </div>`
375
- );
376
- }
377
-
378
- dialogHtml.push(
379
- `<div class="dialog-body ${iconStyleMap[this.options.icon] ?? ""}" style="height: calc(100% ${enableHeader ? " - 40px" : ""}${this.options.enableFooter ? " - 45px" : ""})"><div class="dialog-move-overay"></div><div class="dialog-content">`
380
- );
381
-
382
- if (this.options.url) {
383
- dialogHtml.push(`<iframe src="${this.options.url}" class="dialog-frame"></iframe>`);
384
- } else {
385
- if (typeof this.options.template === "string") {
386
- dialogHtml.push(this.options.template);
387
- } else {
388
- dialogHtml.push(this.options.template());
389
- }
390
- }
391
-
392
- dialogHtml.push("</div></div>");
393
-
394
- // footer
395
- const buttons = this.options.buttons ?? [];
396
-
397
- if (this.options.enableFooter !== false) {
398
- dialogHtml.push('<div class="dialog-footer"><div class="btn-area">');
399
-
400
- for (let i = 0; i < buttons.length; i++) {
401
- const button = buttons[i];
402
- const styleClass = button.styleClass ?? "success";
403
- dialogHtml.push(`<span class="dialog-btn dialog-btn-${i} ${styleClass}">${button.label}</span>`);
404
- }
405
-
406
- dialogHtml.push("</div></div>");
407
- }
408
-
409
- if (this.options.resizable === true) {
410
- dialogHtml.push(`
411
- <div class="resizer top" data-mode="t"></div>
412
- <div class="resizer left" data-mode="l"></div>
413
- <div class="resizer right" data-mode="r"></div>
414
- <div class="resizer bottom" data-mode="b"></div>
415
-
416
- <div class="resizer top-left" data-mode="tl"></div>
417
- <div class="resizer top-right" data-mode="tr"></div>
418
- <div class="resizer bottom-left" data-mode="bl"></div>
419
- <div class="resizer bottom-right" data-mode="br"></div>
420
- `);
421
- }
422
-
423
- dialog.innerHTML = dialogHtml.join("");
424
-
425
- this.dialogWrapperElement.appendChild(dialog); // Append the dialog element
426
-
427
- if (this.options.enableMaxButton) {
428
- dialog.querySelector(".dialog-maximise").addEventListener("click", () => {
429
- this.maximise(dialog);
430
- });
431
- }
432
-
433
- if (this.options.enableCloseButton) {
434
- dialog.querySelector(".dialog-close").addEventListener("click", () => {
435
- this.hide(dialog);
436
- });
437
- }
438
-
439
- if (this.options.enableFooter !== false) {
440
- for (let i = 0; i < buttons.length; i++) {
441
- const button = buttons[i];
442
- const btnElement = this.dialogWrapperElement.querySelector(`.dialog-footer .dialog-btn-${i}`);
443
- btnElement.addEventListener("mousedown", (e) => {
444
- if (button.callback) {
445
- button.callback(e);
446
- }
447
- });
448
- }
449
- }
450
- }
451
-
452
- /**
453
- * show dialog message
454
- * @param {*} viewItems
455
- * @returns
456
- */
457
- show = () => {
458
- this.dialogWrapperElement.classList.remove("hide");
459
- if (this.options.isModal === true) {
460
- const dialogOverrayElement = document.createElement("div");
461
- dialogOverrayElement.className = "daracl-dialog-overlay";
462
- dialogOverrayElement.style.zIndex = this.options.zIndex + this.idx;
463
-
464
- const hiddenElement = dialogHiddenElement();
465
- const firstChild = hiddenElement.firstChild;
466
-
467
- if (firstChild) {
468
- hiddenElement.insertBefore(dialogOverrayElement, firstChild);
469
- } else {
470
- hiddenElement.appendChild(dialogOverrayElement);
471
- }
472
-
473
- this.dialogOverrayElement = dialogOverrayElement;
474
- }
475
-
476
- if (typeof this.options.afterOpen === "function") {
477
- this.options.afterOpen.call(this, this.dialogWrapperElement);
478
- }
479
-
480
- return this;
481
- };
482
-
483
- /**
484
- * dialog hide
485
- */
486
- hide = () => {
487
- this.dialogWrapperElement.classList.add("hide");
488
-
489
- if (this.options.isModal === true) {
490
- dialogHiddenElement().removeChild(this.dialogOverrayElement);
491
- }
492
- };
493
-
494
- /**
495
- * maximise hide
496
- *
497
- */
498
- maximise = () => {
499
- const classList = this.dialogWrapperElement.classList;
500
- if (classList.contains("maximise")) {
501
- classList.remove("maximise");
502
- } else {
503
- classList.add("maximise");
504
- }
505
- };
506
-
507
- isMaximise() {
508
- return this.dialogWrapperElement.classList.contains("maximise");
509
- }
510
-
511
- addEvent(elements, events, fnHandler) {
512
- events.split(" ").forEach(function (e) {
513
- if (elements instanceof NodeList) {
514
- for (let element of elements) {
515
- element.addEventListener(e, fnHandler, false);
516
- }
517
- } else {
518
- elements.addEventListener(e, fnHandler, false);
519
- }
520
- });
521
- }
522
-
523
- removeEvent(elements, events, fnHandler) {
524
- events.split(" ").forEach(function (e) {
525
- if (elements instanceof NodeList) {
526
- for (let element of elements) {
527
- element.removeEventListener(e, fnHandler);
528
- }
529
- } else {
530
- elements.removeEventListener(e, fnHandler);
531
- }
532
- });
533
- }
534
-
535
- /**
536
- * dialog destroy
537
- */
538
- destroy = () => {
539
- dialogHiddenElement().removeChild(this.dialogWrapperElement);
540
- this.dialogWrapperElement = null;
541
- this.options = null;
542
- this.idx = -1;
543
- };
544
- }