| 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 | 1×
1×
1×
1×
1×
1×
1×
931×
931×
931×
602×
602×
602×
602×
329×
931×
37×
37×
29×
931×
37×
37×
29×
931×
32×
32×
16×
931×
3×
4×
931×
931×
931×
1×
1×
12×
12×
12×
5×
1×
12×
12×
4×
4×
2×
4×
1×
53×
53×
1×
3×
3×
1×
338×
338×
338×
338×
338×
53×
338×
329×
329×
9×
1×
9×
338×
338×
338×
62×
62×
338×
9×
9×
338×
317×
338×
20×
338×
338×
338×
338×
338×
285×
283×
285×
338×
53×
1×
53×
12×
1×
931×
909×
5002×
5002×
811×
811×
871×
871×
866×
866×
899×
899×
725×
725×
931×
1×
14×
11×
3×
1×
395×
72×
72×
13×
323×
8×
323×
1×
2936×
2936×
1×
34×
34×
34×
34×
32×
2×
2×
34×
18×
34×
34×
34×
1×
34×
8×
4×
4×
4×
4×
4×
34×
1×
34×
13×
34×
13×
1×
45×
45×
44×
44×
1×
931×
931×
931×
5×
5×
926×
931×
931×
1×
1965×
1965×
41×
1965×
17×
17×
17×
4×
13×
1×
1×
818×
3×
818×
12×
1×
1×
952×
952×
952×
348×
341×
341×
7×
7×
604×
38×
566×
566×
1×
1×
739×
35×
704×
739×
2×
1×
1×
874×
25×
849×
1×
1×
884×
884×
850×
850×
34×
34×
884×
2×
1×
1×
37×
37×
34×
3×
3×
1×
1×
855×
1708×
1708×
1708×
1708×
854×
1708×
576×
1708×
1×
1707×
1×
1×
38×
72×
72×
72×
72×
36×
72×
21×
72×
1×
71×
1×
1×
8×
8×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
2×
1×
1×
9×
9×
9×
9×
9×
9×
9×
9×
9×
9×
9×
8×
9×
6×
3×
3×
3×
3×
3×
1×
1×
2×
2×
1×
1×
1003×
1003×
1003×
1003×
1002×
1006×
1006×
1×
1×
3×
3×
1×
71×
67×
1×
71×
71×
71×
71×
1×
71×
71×
1×
1001×
1001×
1001×
1001×
1001×
4×
1001×
1001×
1×
| define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var CLASSNAMES = {
RTL: 'e-rtl',
DISABLE: 'e-disabled',
INPUT: 'e-input',
INPUTGROUP: 'e-input-group',
FLOATINPUT: 'e-float-input',
FLOATLINE: 'e-float-line',
FLOATTEXT: 'e-float-text',
CLEARICON: 'e-clear-icon',
CLEARICONHIDE: 'e-clear-icon-hide',
LABELTOP: 'e-label-top',
LABELBOTTOM: 'e-label-bottom',
NOFLOATLABEL: 'e-no-float-label',
INPUTCUSTOMTAG: 'e-input-custom-tag',
FLOATCUSTOMTAG: 'e-float-custom-tag'
};
/**
* Base for Input creation through util methods.
*/
var Input;
(function (Input) {
var privateInputObj = {
container: null,
buttons: [],
clearButton: null
};
/**
* Create a wrapper to input element with multiple span elements and set the basic properties to input based components.
* ```
* E.g : Input.createInput({ element: element, floatLabelType : "Auto", properties: { placeholder: 'Search' } });
* ```
* @param args
*/
function createInput(args, internalCreateElement) {
var makeElement = !ej2_base_1.isNullOrUndefined(internalCreateElement) ? internalCreateElement : ej2_base_1.createElement;
var inputObject = { container: null, buttons: [], clearButton: null };
if (ej2_base_1.isNullOrUndefined(args.floatLabelType) || args.floatLabelType === 'Never') {
inputObject.container = createInputContainer(args, CLASSNAMES.INPUTGROUP, CLASSNAMES.INPUTCUSTOMTAG, 'span', makeElement);
args.element.parentNode.insertBefore(inputObject.container, args.element);
ej2_base_1.addClass([args.element], CLASSNAMES.INPUT);
inputObject.container.appendChild(args.element);
}
else {
createFloatingInput(args, inputObject, makeElement);
}
args.element.addEventListener('focus', function () {
var parent = getParentNode(this);
if (parent.classList.contains('e-input-group')) {
parent.classList.add('e-input-focus');
}
});
args.element.addEventListener('blur', function () {
var parent = getParentNode(this);
if (parent.classList.contains('e-input-group')) {
parent.classList.remove('e-input-focus');
}
});
if (!ej2_base_1.isNullOrUndefined(args.properties) && !ej2_base_1.isNullOrUndefined(args.properties.showClearButton) && args.properties.showClearButton) {
setClearButton(args.properties.showClearButton, args.element, inputObject, true, makeElement);
if (inputObject.container.classList.contains(CLASSNAMES.FLOATINPUT)) {
ej2_base_1.addClass([inputObject.container], CLASSNAMES.INPUTGROUP);
}
}
if (!ej2_base_1.isNullOrUndefined(args.buttons)) {
for (var i = 0; i < args.buttons.length; i++) {
inputObject.buttons.push(appendSpan(args.buttons[i], inputObject.container, makeElement));
}
}
inputObject = setPropertyValue(args, inputObject);
privateInputObj = inputObject;
return inputObject;
}
Input.createInput = createInput;
function _focusFn() {
var label = getParentNode(this).getElementsByClassName('e-float-text')[0];
ej2_base_1.addClass([label], CLASSNAMES.LABELTOP);
if (label.classList.contains(CLASSNAMES.LABELBOTTOM)) {
ej2_base_1.removeClass([label], CLASSNAMES.LABELBOTTOM);
}
}
function _blurFn() {
var parent = getParentNode(this);
if (parent.getElementsByTagName('input')[0].value === '') {
var label = parent.getElementsByClassName('e-float-text')[0];
if (label.classList.contains(CLASSNAMES.LABELTOP)) {
ej2_base_1.removeClass([label], CLASSNAMES.LABELTOP);
}
ej2_base_1.addClass([label], CLASSNAMES.LABELBOTTOM);
}
}
function wireFloatingEvents(element) {
element.addEventListener('focus', _focusFn);
element.addEventListener('blur', _blurFn);
}
function unwireFloatingEvents(element) {
element.removeEventListener('focus', _focusFn);
element.removeEventListener('blur', _blurFn);
}
function createFloatingInput(args, inputObject, internalCreateElement) {
var makeElement = !ej2_base_1.isNullOrUndefined(internalCreateElement) ? internalCreateElement : ej2_base_1.createElement;
var inputElement;
var floatLinelement;
var floatLabelElement;
if (args.floatLabelType === 'Auto') {
wireFloatingEvents(args.element);
}
if (ej2_base_1.isNullOrUndefined(inputObject.container)) {
inputObject.container = createInputContainer(args, CLASSNAMES.FLOATINPUT, CLASSNAMES.FLOATCUSTOMTAG, 'div', makeElement);
args.element.parentNode.insertBefore(inputObject.container, args.element);
}
else {
if (!ej2_base_1.isNullOrUndefined(args.customTag)) {
inputObject.container.classList.add(CLASSNAMES.FLOATCUSTOMTAG);
}
inputObject.container.classList.add(CLASSNAMES.FLOATINPUT);
}
floatLinelement = makeElement('span', { className: CLASSNAMES.FLOATLINE });
floatLabelElement = makeElement('label', { className: CLASSNAMES.FLOATTEXT });
if (!ej2_base_1.isNullOrUndefined(args.element.id) && args.element.id !== '') {
floatLabelElement.id = 'label_' + args.element.id.replace(/ /g, '_');
ej2_base_1.attributes(args.element, { 'aria-labelledby': floatLabelElement.id });
}
if (!ej2_base_1.isNullOrUndefined(args.element.placeholder) && args.element.placeholder !== '') {
floatLabelElement.innerHTML = args.element.placeholder;
args.element.removeAttribute('placeholder');
}
if (!ej2_base_1.isNullOrUndefined(args.properties) && !ej2_base_1.isNullOrUndefined(args.properties.placeholder) &&
args.properties.placeholder !== '') {
floatLabelElement.innerHTML = args.properties.placeholder;
}
if (!floatLabelElement.innerHTML) {
inputObject.container.classList.add(CLASSNAMES.NOFLOATLABEL);
}
inputObject.container.appendChild(args.element);
inputObject.container.appendChild(floatLinelement);
inputObject.container.appendChild(floatLabelElement);
updateLabelState(args.element.value, floatLabelElement);
if (args.floatLabelType === 'Always') {
if (floatLabelElement.classList.contains(CLASSNAMES.LABELBOTTOM)) {
ej2_base_1.removeClass([floatLabelElement], CLASSNAMES.LABELBOTTOM);
}
ej2_base_1.addClass([floatLabelElement], CLASSNAMES.LABELTOP);
}
if (args.floatLabelType === 'Auto') {
args.element.addEventListener('input', function (event) {
updateLabelState(args.element.value, floatLabelElement);
});
args.element.addEventListener('blur', function (event) {
updateLabelState(args.element.value, floatLabelElement);
});
}
}
function setPropertyValue(args, inputObject) {
if (!ej2_base_1.isNullOrUndefined(args.properties)) {
for (var _i = 0, _a = Object.keys(args.properties); _i < _a.length; _i++) {
var prop = _a[_i];
switch (prop) {
case 'cssClass':
setCssClass(args.properties.cssClass, [inputObject.container]);
break;
case 'enabled':
setEnabled(args.properties.enabled, args.element);
break;
case 'enableRtl':
setEnableRtl(args.properties.enableRtl, [inputObject.container]);
break;
case 'placeholder':
setPlaceholder(args.properties.placeholder, args.element);
break;
case 'readonly':
setReadonly(args.properties.readonly, args.element);
break;
}
}
}
return inputObject;
}
function updateIconState(value, button) {
if (value) {
ej2_base_1.removeClass([button], CLASSNAMES.CLEARICONHIDE);
}
else {
ej2_base_1.addClass([button], CLASSNAMES.CLEARICONHIDE);
}
}
function updateLabelState(value, label) {
if (value) {
ej2_base_1.addClass([label], CLASSNAMES.LABELTOP);
if (label.classList.contains(CLASSNAMES.LABELBOTTOM)) {
ej2_base_1.removeClass([label], CLASSNAMES.LABELBOTTOM);
}
}
else {
if (label.classList.contains(CLASSNAMES.LABELTOP)) {
ej2_base_1.removeClass([label], CLASSNAMES.LABELTOP);
}
ej2_base_1.addClass([label], CLASSNAMES.LABELBOTTOM);
}
}
function getParentNode(element) {
var parentNode = element.parentNode;
return parentNode;
}
/**
* To create clear button.
*/
function createClearButton(element, inputObject, initial, internalCreateElement) {
var makeElement = !ej2_base_1.isNullOrUndefined(internalCreateElement) ? internalCreateElement : ej2_base_1.createElement;
var button = makeElement('span', { className: CLASSNAMES.CLEARICON });
var container = inputObject.container;
if (!ej2_base_1.isNullOrUndefined(initial)) {
container.appendChild(button);
}
else {
var baseElement = inputObject.container.classList.contains(CLASSNAMES.FLOATINPUT) ?
inputObject.container.querySelector('.' + CLASSNAMES.FLOATTEXT) : element;
baseElement.insertAdjacentElement('afterend', button);
}
if (!ej2_base_1.isNullOrUndefined(container) &&
container.classList.contains(CLASSNAMES.FLOATINPUT)) {
ej2_base_1.addClass([container], CLASSNAMES.INPUTGROUP);
}
ej2_base_1.addClass([button], CLASSNAMES.CLEARICONHIDE);
wireClearBtnEvents(element, button, container);
return button;
}
function wireClearBtnEvents(element, button, container) {
button.addEventListener('click', function (event) {
if (!(element.classList.contains(CLASSNAMES.DISABLE) || element.readOnly)) {
event.preventDefault();
Eif (element !== document.activeElement) {
element.focus();
}
element.value = '';
ej2_base_1.addClass([button], CLASSNAMES.CLEARICONHIDE);
}
});
element.addEventListener('input', function (event) {
updateIconState(element.value, button);
});
element.addEventListener('focus', function (event) {
updateIconState(element.value, button);
});
element.addEventListener('blur', function (event) {
setTimeout(function () { ej2_base_1.addClass([button], CLASSNAMES.CLEARICONHIDE); }, 200);
});
}
function validateLabel(element, floatLabelType) {
var parent = getParentNode(element);
if (parent.classList.contains(CLASSNAMES.FLOATINPUT) && floatLabelType === 'Auto') {
var label = getParentNode(element).getElementsByClassName('e-float-text')[0];
updateLabelState(element.value, label);
}
}
/**
* To create input box contianer.
*/
function createInputContainer(args, className, tagClass, tag, internalCreateElement) {
var makeElement = !ej2_base_1.isNullOrUndefined(internalCreateElement) ? internalCreateElement : ej2_base_1.createElement;
var container;
if (!ej2_base_1.isNullOrUndefined(args.customTag)) {
container = makeElement(args.customTag, { className: className });
container.classList.add(tagClass);
}
else {
container = makeElement(tag, { className: className });
}
container.classList.add('e-control-wrapper');
return container;
}
/**
* Sets the value to the input element.
* ```
* E.g : Input.setValue('content', element, "Auto", true );
* ```
* @param value - Specify the value of the input element.
* @param element - The element on which the specified value is updated.
* @param floatLabelType - Specify the float label type of the input element.
* @param clearButton - Boolean value to specify whether the clear icon is enabled / disabled on the input.
*/
function setValue(value, element, floatLabelType, clearButton) {
element.value = value;
if ((!ej2_base_1.isNullOrUndefined(floatLabelType)) && floatLabelType === 'Auto') {
validateLabel(element, floatLabelType);
}
if (!ej2_base_1.isNullOrUndefined(clearButton) && clearButton) {
var parentElement = getParentNode(element);
var button = parentElement.getElementsByClassName(CLASSNAMES.CLEARICON)[0];
if (element.value && parentElement.classList.contains('e-input-focus')) {
ej2_base_1.removeClass([button], CLASSNAMES.CLEARICONHIDE);
}
else {
ej2_base_1.addClass([button], CLASSNAMES.CLEARICONHIDE);
}
}
}
Input.setValue = setValue;
/**
* Sets the single or multiple cssClass to wrapper of input element.
* ```
* E.g : Input.setCssClass('e-custom-class', [element]);
* ```
* @param cssClass - Css class names which are needed to add.
* @param elements - The elements which are needed to add / remove classes.
* @param oldClass - Css class names which are needed to remove. If old classes are need to remove, can give this optional parameter.
*/
function setCssClass(cssClass, elements, oldClass) {
if (!ej2_base_1.isNullOrUndefined(oldClass) && oldClass !== '') {
ej2_base_1.removeClass(elements, oldClass);
}
if (!ej2_base_1.isNullOrUndefined(cssClass) && cssClass !== '') {
ej2_base_1.addClass(elements, cssClass);
}
}
Input.setCssClass = setCssClass;
/**
* Set the placeholder attribute to the input element.
* ```
* E.g : Input.setPlaceholder('Search here', element);
* ```
* @param placeholder - Placeholder value which is need to add.
* @param element - The element on which the placeholder is need to add.
*/
function setPlaceholder(placeholder, element) {
var parentElement;
parentElement = getParentNode(element);
if (parentElement.classList.contains(CLASSNAMES.FLOATINPUT)) {
if (!ej2_base_1.isNullOrUndefined(placeholder) && placeholder !== '') {
parentElement.getElementsByClassName(CLASSNAMES.FLOATTEXT)[0].textContent = placeholder;
parentElement.classList.remove(CLASSNAMES.NOFLOATLABEL);
}
else {
parentElement.classList.add(CLASSNAMES.NOFLOATLABEL);
parentElement.getElementsByClassName(CLASSNAMES.FLOATTEXT)[0].textContent = '';
}
}
else {
if (!ej2_base_1.isNullOrUndefined(placeholder) && placeholder !== '') {
ej2_base_1.attributes(element, { 'placeholder': placeholder, 'aria-placeholder': placeholder });
}
else {
element.removeAttribute('placeholder');
element.removeAttribute('aria-placeholder');
}
}
}
Input.setPlaceholder = setPlaceholder;
/**
* Set the read only attribute to the input element
* ```
* E.g : Input.setReadonly(true, element);
* ```
* @param isReadonly
* - Boolean value to specify whether to set read only. Setting "True" value enables read only.
* @param element
* - The element which is need to enable read only.
*/
function setReadonly(isReadonly, element, floatLabelType) {
if (isReadonly) {
ej2_base_1.attributes(element, { readonly: '' });
}
else {
element.removeAttribute('readonly');
}
if (!ej2_base_1.isNullOrUndefined(floatLabelType)) {
validateLabel(element, floatLabelType);
}
}
Input.setReadonly = setReadonly;
/**
* Displays the element direction from right to left when its enabled.
* ```
* E.g : Input.setEnableRtl(true, [inputObj.container]);
* ```
* @param isRtl
* - Boolean value to specify whether to set RTL. Setting "True" value enables the RTL mode.
* @param elements
* - The elements that are needed to enable/disable RTL.
*/
function setEnableRtl(isRtl, elements) {
if (isRtl) {
ej2_base_1.addClass(elements, CLASSNAMES.RTL);
}
else {
ej2_base_1.removeClass(elements, CLASSNAMES.RTL);
}
}
Input.setEnableRtl = setEnableRtl;
/**
* Enables or disables the given input element.
* ```
* E.g : Input.setEnabled(false, element);
* ```
* @param isEnable
* - Boolean value to specify whether to enable or disable.
* @param element
* - Element to be enabled or disabled.
*/
function setEnabled(isEnable, element, floatLabelType) {
var disabledAttrs = { 'disabled': 'disabled', 'aria-disabled': 'true' };
if (isEnable) {
element.classList.remove(CLASSNAMES.DISABLE);
removeAttributes(disabledAttrs, element);
}
else {
element.classList.add(CLASSNAMES.DISABLE);
addAttributes(disabledAttrs, element);
}
if (!ej2_base_1.isNullOrUndefined(floatLabelType)) {
validateLabel(element, floatLabelType);
}
}
Input.setEnabled = setEnabled;
function setClearButton(isClear, element, inputObject, initial, internalCreateElement) {
var makeElement = !ej2_base_1.isNullOrUndefined(internalCreateElement) ? internalCreateElement : ej2_base_1.createElement;
if (isClear) {
inputObject.clearButton = createClearButton(element, inputObject, initial, makeElement);
}
else {
inputObject.clearButton.remove();
inputObject.clearButton = null;
}
}
Input.setClearButton = setClearButton;
/**
* Removing the multiple attributes from the given element such as "disabled","id" , etc.
* ```
* E.g : Input.removeAttributes({ 'disabled': 'disabled', 'aria-disabled': 'true' }, element);
* ```
* @param attrs
* - Array of attributes which are need to removed from the element.
* @param element
* - Element on which the attributes are needed to be removed.
*/
function removeAttributes(attrs, element) {
for (var _i = 0, _a = Object.keys(attrs); _i < _a.length; _i++) {
var key = _a[_i];
var parentElement = void 0;
parentElement = getParentNode(element);
if (key === 'disabled') {
element.classList.remove(CLASSNAMES.DISABLE);
}
if (key === 'disabled' && parentElement.classList.contains(CLASSNAMES.INPUTGROUP)) {
parentElement.classList.remove(CLASSNAMES.DISABLE);
}
if (key === 'placeholder' && parentElement.classList.contains(CLASSNAMES.FLOATINPUT)) {
parentElement.getElementsByClassName(CLASSNAMES.FLOATTEXT)[0].textContent = '';
}
else {
element.removeAttribute(key);
}
}
}
Input.removeAttributes = removeAttributes;
/**
* Adding the multiple attributes to the given element such as "disabled","id" , etc.
* ```
* E.g : Input.addAttributes({ 'id': 'inputpopup' }, element);
* ```
* @param attrs
* - Array of attributes which is added to element.
* @param element
* - Element on which the attributes are needed to be added.
*/
function addAttributes(attrs, element) {
for (var _i = 0, _a = Object.keys(attrs); _i < _a.length; _i++) {
var key = _a[_i];
var parentElement = void 0;
parentElement = getParentNode(element);
if (key === 'disabled') {
element.classList.add(CLASSNAMES.DISABLE);
}
if (key === 'disabled' && parentElement.classList.contains(CLASSNAMES.INPUTGROUP)) {
parentElement.classList.add(CLASSNAMES.DISABLE);
}
if (key === 'placeholder' && parentElement.classList.contains(CLASSNAMES.FLOATINPUT)) {
parentElement.getElementsByClassName(CLASSNAMES.FLOATTEXT)[0].textContent = attrs[key];
}
else {
element.setAttribute(key, attrs[key]);
}
}
}
Input.addAttributes = addAttributes;
function removeFloating(input) {
var container = input.container;
if (!ej2_base_1.isNullOrUndefined(container) && container.classList.contains(CLASSNAMES.FLOATINPUT)) {
var inputEle = container.querySelector('input');
var placeholder = container.querySelector('.' + CLASSNAMES.FLOATTEXT).textContent;
var clearButton = container.querySelector('.e-clear-icon') !== null;
ej2_base_1.detach(container.querySelector('.' + CLASSNAMES.FLOATLINE));
ej2_base_1.detach(container.querySelector('.' + CLASSNAMES.FLOATTEXT));
ej2_base_1.classList(container, [CLASSNAMES.INPUTGROUP], [CLASSNAMES.FLOATINPUT]);
unwireFloatingEvents(inputEle);
ej2_base_1.attributes(inputEle, { 'placeholder': placeholder });
inputEle.classList.add(CLASSNAMES.INPUT);
if (!clearButton) {
inputEle.removeAttribute('required');
}
}
}
Input.removeFloating = removeFloating;
function addFloating(input, type, placeholder, internalCreateElement) {
var makeElement = !ej2_base_1.isNullOrUndefined(internalCreateElement) ? internalCreateElement : ej2_base_1.createElement;
var container = ej2_base_1.closest(input, '.' + CLASSNAMES.INPUTGROUP);
Eif (type !== 'Never') {
var customTag = container.tagName;
customTag = customTag !== 'DIV' && customTag !== 'SPAN' ? customTag : null;
var args = { element: input, floatLabelType: type, customTag: customTag, properties: { placeholder: placeholder } };
var iconEle = container.querySelector('.e-clear-icon');
var inputObj = { container: container };
input.classList.remove(CLASSNAMES.INPUT);
createFloatingInput(args, inputObj, makeElement);
if (ej2_base_1.isNullOrUndefined(iconEle)) {
iconEle = container.querySelector('.e-input-group-icon');
}
if (ej2_base_1.isNullOrUndefined(iconEle)) {
container.classList.remove(CLASSNAMES.INPUTGROUP);
}
else {
var floatLine = container.querySelector('.' + CLASSNAMES.FLOATLINE);
var floatText = container.querySelector('.' + CLASSNAMES.FLOATTEXT);
container.insertBefore(input, iconEle);
container.insertBefore(floatLine, iconEle);
container.insertBefore(floatText, iconEle);
}
}
}
Input.addFloating = addFloating;
/**
* Enable or Disable the ripple effect on the icons inside the Input. Ripple effect is only applicable for material theme.
* ```
* E.g : Input.setRipple(true, [inputObjects]);
* ```
* @param isRipple
* - Boolean value to specify whether to enable the ripple effect.
* @param inputObject
* - Specify the collection of input objects.
*/
function setRipple(isRipple, inputObj) {
for (var i = 0; i < inputObj.length; i++) {
_internalRipple(isRipple, inputObj[i].container);
}
}
Input.setRipple = setRipple;
function _internalRipple(isRipple, container, button) {
var argsButton = [];
argsButton.push(button);
var buttons = ej2_base_1.isNullOrUndefined(button) ?
container.querySelectorAll('.e-input-group-icon') : argsButton;
if (isRipple && buttons.length > 0) {
for (var index = 0; index < buttons.length; index++) {
buttons[index].addEventListener('mousedown', _onMouseDownRipple, false);
buttons[index].addEventListener('mouseup', _onMouseUpRipple, false);
}
}
else Eif (buttons.length > 0) {
for (var index = 0; index < buttons.length; index++) {
buttons[index].removeEventListener('mousedown', _onMouseDownRipple, this);
buttons[index].removeEventListener('mouseup', _onMouseUpRipple, this);
}
}
}
function _onMouseRipple(container, button) {
if (!container.classList.contains('e-disabled') && !container.querySelector('input').readOnly) {
button.classList.add('e-input-btn-ripple');
}
}
function _onMouseDownRipple() {
var ele = this;
var parentEle = this.parentElement;
while (!parentEle.classList.contains('e-input-group')) {
parentEle = parentEle.parentElement;
}
_onMouseRipple(parentEle, ele);
}
function _onMouseUpRipple() {
var ele = this;
setTimeout(function () { ele.classList.remove('e-input-btn-ripple'); }, 500);
}
/**
* Creates a new span element with the given icons added and append it in container element.
* ```
* E.g : Input.appendSpan('e-icon-spin', inputObj.container);
* ```
* @param iconClass - Icon classes which are need to add to the span element which is going to created.
* Span element acts as icon or button element for input.
* @param container - The container on which created span element is going to append.
*/
function appendSpan(iconClass, container, internalCreateElement) {
var makeElement = !ej2_base_1.isNullOrUndefined(internalCreateElement) ? internalCreateElement : ej2_base_1.createElement;
var button = makeElement('span', { className: iconClass });
button.classList.add('e-input-group-icon');
container.appendChild(button);
if (!container.classList.contains(CLASSNAMES.INPUTGROUP)) {
container.classList.add(CLASSNAMES.INPUTGROUP);
}
_internalRipple(true, container, button);
return button;
}
Input.appendSpan = appendSpan;
})(Input = exports.Input || (exports.Input = {}));
});
|