forked from syncfusion/ej2-javascript-ui-controls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.ts
2446 lines (2362 loc) · 91.1 KB
/
dialog.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { Component, Property, Event, Collection, L10n, EmitType, Complex, compile, createElement } from '@syncfusion/ej2-base';
import { addClass, removeClass, detach, attributes, prepend, setStyleAttribute } from '@syncfusion/ej2-base';
import { NotifyPropertyChanges, INotifyPropertyChanged, ChildProperty, isBlazor } from '@syncfusion/ej2-base';
import { isNullOrUndefined, formatUnit, append, EventHandler, Draggable, extend } from '@syncfusion/ej2-base';
import { BlazorDragEventArgs, SanitizeHtmlHelper, Browser } from '@syncfusion/ej2-base';
import { Button, ButtonModel } from '@syncfusion/ej2-buttons';
import { Popup, PositionData, getZindexPartial } from '../popup/popup';
import { PositionDataModel } from '../popup/popup-model';
import { ButtonPropsModel, DialogModel, AnimationSettingsModel } from './dialog-model';
import { createResize, removeResize, setMinHeight, setMaxWidth, setMaxHeight } from '../common/resize';
/**
* Defines the types of a button in the dialog.
*/
export type ButtonType = 'Button' | 'Submit' | 'Reset';
/**
* Provides information about a SanitizeSelectors.
*/
export interface SanitizeSelectors {
/** Returns the tags. */
tags?: string[]
/** Returns the attributes. */
attributes?: SanitizeRemoveAttrs[]
}
/**
* Provides information about a BeforeSanitizeHtml event.
*/
export interface BeforeSanitizeHtmlArgs {
/** Illustrates whether the current action needs to be prevented or not. */
cancel?: boolean
/** It is a callback function and executed it before our inbuilt action. It should return HTML as a string.
*
* @function
* @param {string} value - Returns the value.
* @returns {string}
*/
// eslint-disable-next-line
helper?: Function
/** Returns the selectors object which carrying both tags and attributes selectors to block list of cross-site scripting attack.
*Also possible to modify the block list in this event.
*/
selectors?: SanitizeSelectors
}
/**
* Provides information about a SanitizeRemoveAttributes.
*/
export interface SanitizeRemoveAttrs {
/** Defines the attribute name to sanitize */
attribute?: string
/** Defines the selector that sanitize the specified attributes within the selector */
selector?: string
}
export class ButtonProps extends ChildProperty<ButtonProps> {
/**
* Specifies the flat appearance of the dialog buttons
*
* @default true
*/
@Property(true)
public isFlat: boolean;
/**
* Specifies the button component properties to render the dialog buttons.
*/
@Property()
public buttonModel: ButtonModel;
/**
* Specify the type of the button.
* Possible values are Button, Submit and Reset.
*
* @default 'Button'
* @aspType string
* @blazorType string
*/
@Property('Button')
public type: ButtonType | string;
/**
* Event triggers when `click` the dialog button.
*
* @event 'object'
* @blazorProperty 'OnClick'
*/
/* eslint-disable */
@Event()
public click: EmitType<Object>;
/* eslint-enable */
}
/**
* Configures the animation properties for both open and close the dialog.
*/
export class AnimationSettings extends ChildProperty<AnimationSettings> {
/**
* Specifies the animation name that should be applied on open and close the dialog.
* If user sets Fade animation, the dialog will open with `FadeIn` effect and close with `FadeOut` effect.
* The following are the list of animation effects available to configure to the dialog:
* 1. Fade
* 2. FadeZoom
* 3. FlipLeftDown
* 4. FlipLeftUp
* 5. FlipRightDown
* 6. FlipRightUp
* 7. FlipXDown
* 8. FlipXUp
* 9. FlipYLeft
* 10. FlipYRight
* 11. SlideBottom
* 12. SlideLeft
* 13. SlideRight
* 14. SlideTop
* 15. Zoom
* 16. None
*
* @default 'Fade'
*/
@Property('Fade')
public effect: DialogEffect;
/**
* Specifies the duration in milliseconds that the animation takes to open or close the dialog.
*
* @default 400
*/
@Property(400)
public duration: number;
/**
* Specifies the delay in milliseconds to start animation.
*
* @default 0
*/
@Property(0)
public delay: number;
}
/**
* Specifies the Dialog animation effects.
*/
export type DialogEffect = 'Fade' | 'FadeZoom' | 'FlipLeftDown' | 'FlipLeftUp' | 'FlipRightDown' | 'FlipRightUp'
| 'FlipXDown' | 'FlipXUp' | 'FlipYLeft' | 'FlipYRight' | 'SlideBottom' | 'SlideLeft' | 'SlideRight' | 'SlideTop' | 'Zoom'
| 'None';
/**
* Specifies the Resize Handles.
*/
export type ResizeDirections = 'South' | 'North' | 'East' | 'West' | 'NorthEast' | 'NorthWest' | 'SouthEast' | 'SouthWest' | 'All';
const ROOT: string = 'e-dialog';
const RTL: string = 'e-rtl';
const DLG_HEADER_CONTENT: string = 'e-dlg-header-content';
const DLG_HEADER: string = 'e-dlg-header';
const DLG_FOOTER_CONTENT: string = 'e-footer-content';
const MODAL_DLG: string = 'e-dlg-modal';
const DLG_CONTENT: string = 'e-dlg-content';
const DLG_CLOSE_ICON: string = 'e-icon-dlg-close';
const DLG_OVERLAY: string = 'e-dlg-overlay';
const DLG_TARGET: string = 'e-dlg-target';
const DLG_CONTAINER: string = 'e-dlg-container';
const SCROLL_DISABLED: string = 'e-scroll-disabled';
const DLG_PRIMARY_BUTTON: string = 'e-primary';
const ICON: string = 'e-icons';
const POPUP_ROOT: string = 'e-popup';
const DEVICE: string = 'e-device';
const FULLSCREEN: string = 'e-dlg-fullscreen';
const DLG_CLOSE_ICON_BTN: string = 'e-dlg-closeicon-btn';
const DLG_HIDE: string = 'e-popup-close';
const DLG_SHOW: string = 'e-popup-open';
const DLG_UTIL_DEFAULT_TITLE: string = 'Information';
const DLG_UTIL_ROOT: string = 'e-scroll-disabled';
const DLG_UTIL_ALERT: string = 'e-alert-dialog';
const DLG_UTIL_CONFIRM: string = 'e-confirm-dialog';
const DLG_RESIZABLE: string = 'e-dlg-resizable';
const DLG_RESTRICT_LEFT_VALUE: string = 'e-restrict-left';
const DLG_RESTRICT_WIDTH_VALUE: string = 'e-resize-viewport';
const DLG_REF_ELEMENT: string = 'e-dlg-ref-element';
const DLG_USER_ACTION_CLOSED: string = 'user action';
const DLG_CLOSE_ICON_CLOSED: string = 'close icon';
const DLG_ESCAPE_CLOSED: string = 'escape';
const DLG_OVERLAYCLICK_CLOSED: string = 'overlayClick';
/**
* Provides information about a BeforeOpen event.
*/
export interface BeforeOpenEventArgs {
/**
* Specify the value to override max-height value of dialog.
*/
maxHeight: string
/**
* Defines whether the current action can be prevented.
*/
cancel: boolean
/**
* Returns the root container element of the dialog.
*/
container: HTMLElement
/**
* Returns the element of the dialog.
*/
element: Element
/**
* Returns the target element of the dialog.
*
* @aspType string
* @blazorType string
* @deprecated
*/
target?: HTMLElement | string
}
/**
* Provides information about a BeforeClose event.
*/
export interface BeforeCloseEventArgs {
/**
* Defines whether the current action can be prevented.
*/
cancel: boolean
/**
* Determines whether the event is triggered by interaction.
*/
isInteracted: boolean
/**
* Returns the root container element of the dialog.
*/
container: HTMLElement
/**
* Returns the element of the dialog.
*/
element: Element
/**
* Returns the target element of the dialog.
*
* @aspType string
* @blazorType string
* @deprecated
*/
target?: HTMLElement | string
/**
* Returns the original event arguments.
*/
event: Event
/**
* Returns whether the dialog, is closed by "close icon", "overlayClick", "escape" and "user action"
*/
closedBy?: string
}
/**
* Provides information about a DialogOpen event.
*/
export interface OpenEventArgs {
/**
* Defines whether the focus action can be prevented in dialog.
*/
preventFocus: boolean
/**
* Defines whether the current action can be prevented.
*/
cancel: boolean
/**
* Returns the root container element of the dialog.
*/
container: HTMLElement
/**
* Returns the element of the dialog.
*/
element: Element
/**
* Specify the name of the event.
*/
name: string
}
/**
* Provides information about a Close event.
*/
export interface CloseEventArgs {
/**
* Defines whether the current action can be prevented.
*/
cancel: boolean
/**
* Returns the root container element of the dialog.
*/
container: HTMLElement
/**
* Returns the element of the dialog.
*/
element: Element
/**
* Returns the original event arguments.
*/
event: Event
/**
* Determines whether the event is triggered by interaction.
*/
isInteracted: boolean
/**
* Specify the name of the event.
*/
name: string
}
/**
* Provides information about a DragStart event.
*/
export interface DragStartEventArgs {
/**
* Returns the original event arguments.
*
* @blazorType MouseEventArgs
*/
event: Event
/**
* Returns the element of the dialog.
*/
element: Element
/**
* Returns the target element of the dialog.
*/
target: HTMLElement
/**
* Returns the name of the event.
*/
name: string
}
/**
* Provides information about a DragStop event.
*/
export interface DragStopEventArgs {
/**
* Returns the original event arguments.
*
* @blazorType MouseEventArgs
*/
event: Event
/**
* Returns the element of the dialog.
*/
element: Element
/**
* Returns the target element of the dialog.
*/
target: HTMLElement
/**
* Returns the helper element.
*/
helper: Element
/**
* Returns the name of the event.
*/
name: string
}
/**
* Provides information about a Drag event.
*/
export interface DragEventArgs {
/**
* Returns the original event arguments.
*
* @blazorType MouseEventArgs
*/
event: Event
/**
* Returns the element of the dialog.
*/
element: Element
/**
* Returns the target element of the dialog.
*/
target: HTMLElement
/**
* Returns the name of the event.
*/
name: string
}
/**
* Represents the dialog component that displays the information and get input from the user.
* Two types of dialog components are `Modal and Modeless (non-modal)` depending on its interaction with parent application.
* ```html
* <div id="dialog"></div>
* ```
* ```typescript
* <script>
* var dialogObj = new Dialog({ header: 'Dialog' });
* dialogObj.appendTo("#dialog");
* </script>
* ```
*/
@NotifyPropertyChanges
export class Dialog extends Component<HTMLElement> implements INotifyPropertyChanged {
// Internal variables
/* eslint-disable */
private closeIconClickEventHandler: Function;
private dlgOverlayClickEventHandler: Function;
private createEventHandler: Function;
/* eslint-enable */
private contentEle: HTMLElement;
private dlgOverlay: HTMLElement;
private dlgContainer: HTMLElement;
private headerEle: HTMLElement;
private buttonContent: string[];
private ftrTemplateContent: HTMLElement;
private headerContent: HTMLElement;
private closeIcon: HTMLElement;
private popupObj: Popup;
private btnObj: Button[];
private closeIconBtnObj: Button;
private dragObj: Draggable;
private primaryButtonEle: HTMLElement;
private targetEle: HTMLElement;
private dialogOpen: boolean;
private initialRender: boolean;
private innerContentElement: Node;
private storeActiveElement: HTMLElement;
private focusElements: HTMLElement[];
private focusIndex: number;
private l10n: L10n;
private clonedEle: HTMLElement;
// eslint-disable-next-line
private closeArgs: Object;
private calculatezIndex: boolean;
private allowMaxHeight: boolean;
private preventVisibility: boolean;
private refElement: HTMLElement;
private dlgClosedBy: string = DLG_USER_ACTION_CLOSED;
/**
* Specifies the value that can be displayed in dialog's content area.
* It can be information, list, or other HTML elements.
* The content of dialog can be loaded with dynamic data such as database, AJAX content, and more.
*
* {% codeBlock src="dialog/content-api/index.ts" %}{% endcodeBlock %}
*
* {% codeBlock src="dialog/content-api/index.html" %}{% endcodeBlock %}
*
* @default ''
* @blazorType string
*/
@Property('')
public content: string | HTMLElement;
/**
* Defines whether to allow the cross-scripting site or not.
*
* @default true
*/
@Property(true)
public enableHtmlSanitizer: boolean;
/**
* Specifies the value that represents whether the close icon is shown in the dialog component.
*
* @default false
*/
@Property(false)
public showCloseIcon: boolean;
/**
* Specifies the Boolean value whether the dialog can be displayed as modal or non-modal.
* * `Modal`: It creates overlay that disable interaction with the parent application and user should
* respond with modal before continuing with other applications.
* * `Modeless`: It does not prevent user interaction with parent application.
*
* @default false
*/
@Property(false)
public isModal: boolean;
/**
* Specifies the value that can be displayed in the dialog's title area that can be configured with plain text or HTML elements.
* This is optional property and the dialog can be displayed without header, if the header property is null.
*
* @default ''
* @blazorType string
*/
@Property('')
public header: string | HTMLElement;
/**
* Specifies the value that represents whether the dialog component is visible.
*
* @default true
*/
@Property(true)
public visible: boolean;
/**
* Specifies the value whether the dialog component can be resized by the end-user.
* If enableResize is true, the dialog component creates grip to resize it diagonal direction.
*
* @default false
*/
@Property(false)
public enableResize: boolean;
/**
* Specifies the resize handles direction in the dialog component that can be resized by the end-user.
*
* @default ['South-East']
*/
@Property(['South-East'])
public resizeHandles: ResizeDirections[];
/**
* Specifies the height of the dialog component.
*
* @default 'auto'
* @blazorType string
*/
@Property('auto')
public height: string | number;
/**
* Specify the min-height of the dialog component.
*
* @default ''
* @blazorType string
*/
@Property('')
public minHeight: string | number;
/**
* Specifies the width of the dialog.
*
* @default '100%'
* @blazorType string
*/
@Property('100%')
public width: string | number;
/**
* Specifies the CSS class name that can be appended with root element of the dialog.
* One or more custom CSS classes can be added to a dialog.
*
* @default ''
*/
@Property('')
public cssClass: string;
/**
* Specifies the z-order for rendering that determines whether the dialog is displayed in front or behind of another component.
*
* @default 1000
*/
@Property(1000)
public zIndex: number;
/**
* Specifies the target element in which to display the dialog.
* The default value is null, which refers the `document.body` element.
*
* @default null
* @blazorType string
*/
@Property(null)
public target: HTMLElement | string;
/**
* Specifies the template value that can be displayed with dialog's footer area.
* This is optional property and can be used only when the footer is occupied with information or custom components.
* By default, the footer is configured with action [buttons](#buttons).
* If footer template is configured to dialog, the action buttons property will be disabled.
*
* > More information on the footer template configuration can be found on this [documentation](../../dialog/template/#footer) section.
*
* @default ''
* @blazorType string
*/
@Property('')
public footerTemplate: HTMLElement | string;
/**
* Specifies the value whether the dialog component can be dragged by the end-user.
* The dialog allows to drag by selecting the header and dragging it for re-position the dialog.
*
* > More information on the draggable behavior can be found on this [documentation](../../dialog/getting-started/#draggable) section.
*
* {% codeBlock src='dialog/allowDragging/index.md' %}{% endcodeBlock %}
*
* @default false
*/
@Property(false)
public allowDragging: boolean;
/**
* Configures the action `buttons` that contains button properties with primary attributes and click events.
* One or more action buttons can be configured to the dialog.
*
* > More information on the button configuration can be found on this
* [documentation](../../dialog/getting-started/#enable-footer) section.
*
* {% codeBlock src="dialog/buttons-api/index.ts" %}{% endcodeBlock %}
*
* {% codeBlock src="dialog/buttons-api/index.html" %}{% endcodeBlock %}
*
* {% codeBlock src='dialog/buttons/index.md' %}{% endcodeBlock %}
*
* @default [{}]
*/
@Collection<ButtonPropsModel>([{}], ButtonProps)
public buttons: ButtonPropsModel[];
/**
* Specifies the boolean value whether the dialog can be closed with the escape key
* that is used to control the dialog's closing behavior.
*
* @default true
*/
@Property(true)
public closeOnEscape: boolean;
/**
* Specifies the animation settings of the dialog component.
* The animation effect can be applied on open and close the dialog with duration and delay.
*
* > More information on the animation settings in dialog can be found on this [documentation](../../dialog/animation/) section.
*
* {% codeBlock src="dialog/animation-api/index.ts" %}{% endcodeBlock %}
*
* {% codeBlock src="dialog/animation-api/index.html" %}{% endcodeBlock %}
*
* {% codeBlock src='dialog/animationSettings/index.md' %}{% endcodeBlock %}
*
* @default { effect: 'Fade', duration: 400, delay:0 }
*/
@Complex<AnimationSettingsModel>({}, AnimationSettings)
public animationSettings: AnimationSettingsModel;
/**
* Specifies the value where the dialog can be positioned within the document or target.
* The position can be represented with pre-configured positions or specific X and Y values.
* * `X value`: left, center, right, or offset value.
* * `Y value`: top, center, bottom, or offset value.
*
* > More information on the positioning in dialog can be found on this [documentation](../../dialog/getting-started/#positioning) section.
*
* {% codeBlock src='dialog/position/index.md' %}{% endcodeBlock %}
*
* @default { X: 'center', Y: 'center' }
*/
@Complex<PositionDataModel>({ X: 'center', Y: 'center' }, PositionData)
public position: PositionDataModel;
/**
* Event triggers when the dialog is created.
*
* @event 'object'
* @blazorProperty 'Created'
*/
/* eslint-disable */
@Event()
public created: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers when a dialog is opened.
*
* @event 'object'
* @blazorProperty 'Opened'
* @blazorType OpenEventArgs
*/
/* eslint-disable */
@Event()
public open: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers before sanitize the value.
*
* @event 'object'
* @blazorProperty 'OnSanitizeHtml'
*/
@Event()
public beforeSanitizeHtml: EmitType<BeforeSanitizeHtmlArgs>;
/**
* Event triggers when the dialog is being opened.
* If you cancel this event, the dialog remains closed.
* Set the cancel argument to true to cancel the open of a dialog.
*
* @event 'object'
* @blazorProperty 'OnOpen'
*/
@Event()
public beforeOpen: EmitType<BeforeOpenEventArgs>;
/**
* Event triggers after the dialog has been closed.
*
* @event 'object'
* @blazorProperty 'Closed'
* @blazorType CloseEventArgs
*/
/* eslint-disable */
@Event()
public close: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers before the dialog is closed.
* If you cancel this event, the dialog remains opened.
* Set the cancel argument to true to cancel the closure of a dialog.
*
* @event 'object'
* @blazorProperty 'OnClose'
*/
@Event()
public beforeClose: EmitType<BeforeCloseEventArgs>;
/**
* Event triggers when the user begins dragging the dialog.
*
* @event 'object'
* @blazorProperty 'OnDragStart'
* @blazorType DragStartEventArgs
*/
/* eslint-disable */
@Event()
public dragStart: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers when the user stop dragging the dialog.
*
* @event 'object'
* @blazorProperty 'OnDragStop'
* @blazorType DragStopEventArgs
*/
/* eslint-disable */
@Event()
public dragStop: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers when the user drags the dialog.
*
* @event 'object'
* @blazorProperty 'OnDrag'
* @blazorType DragEventArgs
*/
/* eslint-disable */
@Event()
public drag: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers when the overlay of dialog is clicked.
*
* @event 'object'
* @blazorProperty 'OnOverlayClick'
*/
/* eslint-disable */
@Event()
public overlayClick: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers when the user begins to resize a dialog.
*
* @event 'object'
* @blazorProperty 'OnResizeStart'
*/
/* eslint-disable */
@Event()
public resizeStart: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers when the user resize the dialog.
*
* @event 'object'
* @blazorProperty 'Resizing'
*/
/* eslint-disable */
@Event()
public resizing: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers when the user stop to resize a dialog.
*
* @event 'object'
* @blazorProperty 'OnResizeStop'
*/
/* eslint-disable */
@Event()
public resizeStop: EmitType<Object>;
/* eslint-enable */
/**
* Event triggers when the dialog is destroyed.
*
* @event 'object'
* @blazorProperty 'Destroyed'
*/
@Event()
public destroyed: EmitType<Event>;
/*
* * Constructor for creating the widget
*
* @param
* @param
* @hidden
*/
constructor(options?: DialogModel, element?: string | HTMLElement) {
super(options, <HTMLElement | string>element);
}
/**
*Initialize the control rendering
*
* @returns {void}
* @private
*/
public render(): void {
this.initialize();
this.initRender();
this.wireEvents();
if (this.width === '100%') {
this.element.style.width = '';
}
if (this.minHeight !== '') {
this.element.style.minHeight = formatUnit(this.minHeight);
}
if (this.enableResize) {
this.setResize();
if (this.animationSettings.effect === 'None') {
this.getMinHeight();
}
}
this.renderComplete();
}
/**
*Initialize the event handler
*
* @returns {void}
* @private
*/
protected preRender(): void {
this.headerContent = null;
this.allowMaxHeight = true;
this.preventVisibility = true;
this.clonedEle = <HTMLElement>this.element.cloneNode(true);
this.closeIconClickEventHandler = (event: Event): void => {
this.dlgClosedBy = DLG_CLOSE_ICON_CLOSED;
this.hide(event);
};
// eslint-disable-next-line
this.dlgOverlayClickEventHandler = (event: Object): void => {
this.dlgClosedBy = DLG_OVERLAYCLICK_CLOSED;
(event as {[key: string]: boolean}).preventFocus = false;
this.trigger('overlayClick', event, (overlayClickEventArgs: {[key: string]: object}) => {
if (!overlayClickEventArgs.preventFocus) {
this.focusContent();
}
this.dlgClosedBy = DLG_USER_ACTION_CLOSED;
});
};
// eslint-disable-next-line
const localeText: object = { close: 'Close' };
this.l10n = new L10n('dialog', localeText, this.locale);
this.checkPositionData();
if (isNullOrUndefined(this.target)) {
const prevOnChange: boolean = this.isProtectedOnChange;
this.isProtectedOnChange = true;
this.target = document.body;
this.isProtectedOnChange = prevOnChange;
}
}
private isNumberValue(value: string): boolean {
const isNumber: boolean = /^[-+]?\d*\.?\d+$/.test(value);
return isNumber;
}
private checkPositionData(): void {
if (!isNullOrUndefined(this.position)) {
if ( !isNullOrUndefined(this.position.X) && ( typeof(this.position.X) !== 'number')) {
const isNumber: boolean = this.isNumberValue(this.position.X);
if (isNumber) {
const prevOnChange: boolean = this.isProtectedOnChange;
this.isProtectedOnChange = true;
this.position.X = parseFloat(this.position.X);
this.isProtectedOnChange = prevOnChange;
}
}
if ( !isNullOrUndefined(this.position.Y) && ( typeof(this.position.Y) !== 'number')) {
const isNumber: boolean = this.isNumberValue(this.position.Y);
if (isNumber) {
const prevOnChange: boolean = this.isProtectedOnChange;
this.isProtectedOnChange = true;
this.position.Y = parseFloat(this.position.Y);
this.isProtectedOnChange = prevOnChange;
}
}
}
}
private getEle(list: HTMLCollection, selector: string): Element {
let element: Element = undefined;
for (let i: number = 0; i < list.length; i++) {
if ((list[i] as Element).classList.contains(selector)) {
element = list[i] as Element;
break;
}
}
return element;
}
/* istanbul ignore next */
private getMinHeight(): number {
let computedHeaderHeight: string = '0px';
let computedFooterHeight: string = '0px';
if (!isNullOrUndefined(this.element.querySelector('.' + DLG_HEADER_CONTENT))) {
computedHeaderHeight = getComputedStyle(this.headerContent).height;
}
const footerEle: Element = this.getEle(this.element.children, DLG_FOOTER_CONTENT);
if (!isNullOrUndefined(footerEle)) {
computedFooterHeight = getComputedStyle(footerEle).height;
}
const headerHeight: number = parseInt(computedHeaderHeight.slice(0, computedHeaderHeight.indexOf('p')), 10);
const footerHeight: number = parseInt(computedFooterHeight.slice(0, computedFooterHeight.indexOf('p')), 10);
setMinHeight(headerHeight + 30 + (isNaN(footerHeight) ? 0 : footerHeight));
return (headerHeight + 30 + footerHeight);
}
private onResizeStart(args: ResizeMouseEventArgs | ResizeTouchEventArgs, dialogObj: Dialog): boolean {
dialogObj.trigger('resizeStart', args);
return args.cancel;
}
private onResizing(args: MouseEvent | TouchEvent, dialogObj: Dialog): void {
dialogObj.trigger('resizing', args);
}
private onResizeComplete(args: MouseEvent | TouchEvent, dialogObj: Dialog): void {
dialogObj.trigger('resizeStop', args);
}
private setResize(): void {
if (this.enableResize) {
if (this.isBlazorServerRender() && !isNullOrUndefined(this.element.querySelector('.e-icons.e-resize-handle'))) {
return;
}
this.element.classList.add(DLG_RESIZABLE);
const computedHeight: string = getComputedStyle(this.element).minHeight;
const computedWidth: string = getComputedStyle(this.element).minWidth;
let direction: string = '';
for (let i: number = 0; i < this.resizeHandles.length; i++) {
if (this.resizeHandles[i] === 'All') {
direction = 'south north east west north-east north-west south-east south-west';
break;
} else {
let directionValue: string = '';
switch (this.resizeHandles[i].toString()) {
case 'SouthEast':
directionValue = 'south-east';
break;
case 'SouthWest':
directionValue = 'south-west';
break;
case 'NorthEast':
directionValue = 'north-east';
break;
case 'NorthWest':
directionValue = 'north-west';
break;
default:
directionValue = this.resizeHandles[i].toString();
break;
}
direction += directionValue.toLocaleLowerCase() + ' ';
}
}
if (this.enableRtl && direction.trim() === 'south-east') {
direction = 'south-west';
} else if (this.enableRtl && direction.trim() === 'south-west') {
direction = 'south-east';
}
if (this.isModal && this.enableRtl) {
this.element.classList.add(DLG_RESTRICT_LEFT_VALUE);
} else if (this.isModal && this.target === document.body) {
this.element.classList.add(DLG_RESTRICT_WIDTH_VALUE);
}
createResize({
element: this.element,
direction: direction,
minHeight: parseInt(computedHeight.slice(0, computedWidth.indexOf('p')), 10),
maxHeight: this.targetEle.clientHeight,
minWidth: parseInt(computedWidth.slice(0, computedWidth.indexOf('p')), 10),
maxWidth: this.targetEle.clientWidth,
boundary: this.target === document.body ? null : this.targetEle,
resizeBegin: this.onResizeStart.bind(this),
resizeComplete: this.onResizeComplete.bind(this),
resizing: this.onResizing.bind(this),
proxy: this
});
this.wireWindowResizeEvent();
} else {
removeResize();
this.unWireWindowResizeEvent();
if (this.isModal) {
this.element.classList.remove(DLG_RESTRICT_LEFT_VALUE);
} else {
this.element.classList.remove(DLG_RESTRICT_WIDTH_VALUE);
}
this.element.classList.remove(DLG_RESIZABLE);
}
}
private getFocusElement(target: HTMLElement): Button {
const value: string = 'input,select,textarea,button:enabled,a,[contenteditable="true"],[tabindex]';
const items: NodeListOf<HTMLElement> = target.querySelectorAll(value);
return { element: items[items.length - 1] as HTMLElement } as Button;
}
/* istanbul ignore next */
private keyDown(event: KeyboardEvent): void {
if (event.keyCode === 9) {
if (this.isModal) {
let buttonObj: Button;
if (!isNullOrUndefined(this.btnObj)) {
buttonObj = this.btnObj[this.btnObj.length - 1];
}
if ((isNullOrUndefined(this.btnObj)) && (!isNullOrUndefined(this.ftrTemplateContent))) {
buttonObj = this.getFocusElement(this.ftrTemplateContent);