| 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 |
1×
1×
1×
1×
1×
1×
1×
6×
6×
6×
1×
80×
80×
80×
80×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
164×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
58×
1×
58×
1×
1×
294×
1×
1×
1×
58×
58×
58×
58×
58×
58×
58×
58×
58×
58×
1×
61×
60×
60×
59×
59×
1×
60×
60×
60×
60×
2×
2×
60×
2×
2×
1×
60×
1×
62×
61×
61×
60×
60×
1×
58×
1×
59×
59×
59×
59×
164×
164×
164×
152×
152×
48×
152×
152×
152×
152×
152×
152×
152×
152×
96×
152×
152×
1×
152×
1×
12×
164×
164×
1×
63×
63×
63×
180×
180×
45×
180×
45×
63×
63×
63×
1×
148×
148×
148×
144×
4×
1×
60×
1×
20×
20×
8×
20×
20×
8×
12×
20×
20×
20×
1×
8×
8×
8×
8×
1×
153×
153×
153×
153×
153×
101×
6×
6×
95×
52×
153×
1×
59×
59×
164×
1×
58×
58×
1×
2×
2×
8×
1×
58×
58×
58×
58×
58×
58×
58×
58×
58×
1×
10×
10×
10×
10×
10×
10×
2×
2×
2×
2×
1×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
2×
1×
26×
26×
26×
11×
1×
1×
10×
10×
10×
10×
10×
10×
11×
3×
3×
4×
4×
2×
2×
2×
2×
2×
2×
2×
2×
2×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| /* istanbul ignore next */
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
/* istanbul ignore next */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
Iif (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) Eif (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ITEMLISTCONTAINER = 'e-timeline-items';
var ITEMCONTAINER = 'e-timeline-item';
var OPPOSITECONTENT = 'e-opposite-content';
var DOTCONTAINER = 'e-dot-item';
var DOTCONTENT = 'e-dot';
var CONTENT = 'e-content';
var ITEMCONNECTOR = 'e-connector';
var VERTICAL = 'e-vertical';
var HORIZONTAL = 'e-horizontal';
var TIMELINEREVERSE = 'e-timeline-reverse';
var RTL = 'e-rtl';
var DISABLED = 'e-item-disabled';
var TEMPLATE = 'e-item-template';
/**
* Defines the orientation type of the Timeline.
*/
var TimelineOrientation;
(function (TimelineOrientation) {
/**
* Items are displayed horizontally.
*/
TimelineOrientation["Horizontal"] = "Horizontal";
/**
* Items are displayed vertically.
*/
TimelineOrientation["Vertical"] = "Vertical";
})(TimelineOrientation = exports.TimelineOrientation || (exports.TimelineOrientation = {}));
/**
* Specifies the alignment of item content within the Timeline.
*/
var TimelineAlign;
(function (TimelineAlign) {
/**
* Aligns item content to the top and opposite content to the bottom when the Timeline is in a horizontal orientation, or the content to the left and opposite content to the right when the Timeline is in a vertical orientation.
*/
TimelineAlign["Before"] = "Before";
/**
* Aligns item content to the bottom and opposite content to the top when the Timeline is in a horizontal orientation, or the content to the right and opposite content to the left when the Timeline is in a vertical orientation.
*/
TimelineAlign["After"] = "After";
/**
* Aligns item content alternatively, regardless of the Timeline's orientation.
*/
TimelineAlign["Alternate"] = "Alternate";
/**
* Aligns item content in alternate reverse, regardless of the Timeline's orientation.
*/
TimelineAlign["AlternateReverse"] = "AlternateReverse";
})(TimelineAlign = exports.TimelineAlign || (exports.TimelineAlign = {}));
/**
* Specifies the items of the Timeline.
*/
var TimelineItem = /** @class */ (function (_super) {
__extends(TimelineItem, _super);
function TimelineItem() {
return _super !== null && _super.apply(this, arguments) || this;
}
__decorate([
ej2_base_1.Property('')
], TimelineItem.prototype, "dotCss", void 0);
__decorate([
ej2_base_1.Property('')
], TimelineItem.prototype, "content", void 0);
__decorate([
ej2_base_1.Property('')
], TimelineItem.prototype, "oppositeContent", void 0);
__decorate([
ej2_base_1.Property(false)
], TimelineItem.prototype, "disabled", void 0);
__decorate([
ej2_base_1.Property('')
], TimelineItem.prototype, "cssClass", void 0);
return TimelineItem;
}(ej2_base_1.ChildProperty));
exports.TimelineItem = TimelineItem;
/**
* The Timeline component presents a series of events or activities in chronological order, allowing users to track the progression of time.
*
* ```html
* <div id="timeline"></div>
* ```
* ```typescript
* <script>
* let timelineObj: Timeline = new Timeline({items : [{}, {}, {}, {}, {}]});
* timelineObj.appendTo('#timeline');
* </script>
* ```
*/
var Timeline = /** @class */ (function (_super) {
__extends(Timeline, _super);
/**
* * Constructor for creating the Timeline component.
*
* @param {TimelineModel} options - Specifies the Timeline model.
* @param {string | HTMLElement} element - Specifies the element to render as component.
* @private
*/
function Timeline(options, element) {
return _super.call(this, options, element) || this;
}
Timeline.prototype.preRender = function () {
if (!this.element.id) {
this.element.id = ej2_base_1.getUniqueID('e-' + this.getModuleName());
}
};
/**
* To get component name.
*
* @returns {string} - It returns the current module name.
* @private
*/
Timeline.prototype.getModuleName = function () {
return 'timeline';
};
/**
* This method is abstract member of the Component<HTMLElement>.
*
* @private
* @returns {string} - It returns the persisted data.
*/
Timeline.prototype.getPersistData = function () {
return this.addOnPersist([]);
};
Timeline.prototype.render = function () {
ej2_base_1.attributes(this.element, { 'role': 'navigation', 'aria-label': this.element.id });
this.timelineListEle = this.createElement('ol', { className: ITEMLISTCONTAINER });
this.updateOrientation();
this.updateCssClass(this.cssClass);
this.updateAlign();
this.updateReverse();
this.updateRtl();
this.updateTemplateFunction();
this.renderItems();
this.element.appendChild(this.timelineListEle);
};
Timeline.prototype.updateOrientation = function () {
if (!(ej2_base_1.isNullOrUndefined(this.orientation))) {
var orientation_1 = this.orientation.toLowerCase();
if (orientation_1 === 'horizontal' || orientation_1 === 'vertical') {
this.element.classList.remove(HORIZONTAL, VERTICAL);
this.element.classList.add('e-' + orientation_1);
}
}
};
Timeline.prototype.updateCssClass = function (addCss, removeCss) {
if (removeCss === void 0) { removeCss = ''; }
var _a, _b;
var cssClasses;
if (removeCss) {
cssClasses = removeCss.trim().split(' ');
(_a = this.element.classList).remove.apply(_a, cssClasses);
}
if (addCss) {
cssClasses = addCss.trim().split(' ');
(_b = this.element.classList).add.apply(_b, cssClasses);
}
};
Timeline.prototype.updateRtl = function () {
this.element.classList[this.enableRtl ? 'add' : 'remove'](RTL);
};
Timeline.prototype.updateAlign = function () {
if (!(ej2_base_1.isNullOrUndefined(this.align))) {
var align = this.align.toLowerCase();
if (align === 'before' || align === 'after' || align === 'alternate' || align === 'alternatereverse') {
this.element.classList.remove('e-align-before', 'e-align-after', 'e-align-alternate', 'e-align-alternatereverse');
this.element.classList.add('e-align-' + align);
}
}
};
Timeline.prototype.updateReverse = function () {
this.element.classList[this.reverse ? 'add' : 'remove'](TIMELINEREVERSE);
};
Timeline.prototype.renderItems = function () {
var _this = this;
var _a;
this.haveOneSidecontent();
for (var index = 0; index < this.items.length; index++) {
var item = this.items[parseInt(index.toString(), 10)];
var timelineItem = this.createElement('li', { className: ITEMCONTAINER + ' ' + ITEMCONNECTOR });
if (!this.template) {
var oppositeTextEle = this.createElement('div', { className: OPPOSITECONTENT });
if (item.oppositeContent) {
this.updateItemContent(false, item, index, oppositeTextEle);
}
timelineItem.appendChild(oppositeTextEle);
var dotContainer = this.createElement('div', { className: DOTCONTAINER });
var dotEleCss = item.dotCss ? DOTCONTENT + ' ' + item.dotCss.trim() : DOTCONTENT;
var dotEle = this.createElement('div', { className: dotEleCss });
dotContainer.appendChild(dotEle);
timelineItem.appendChild(dotContainer);
var contentEle = this.createElement('div', { className: CONTENT });
if (item.content) {
this.updateItemContent(true, item, index, contentEle);
}
timelineItem.appendChild(contentEle);
if (item.cssClass) {
(_a = timelineItem.classList).add.apply(_a, item.cssClass.trim().split(' '));
}
if (item.disabled) {
timelineItem.classList.add(DISABLED);
}
}
else {
this.renderItemContent(index, false, timelineItem);
}
var eventArgs = { element: timelineItem, index: index };
this.trigger('beforeItemRender', eventArgs, function (args) { _this.timelineListEle.appendChild(args.element); });
}
};
Timeline.prototype.haveOneSidecontent = function () {
var haveContent = false;
var haveOppContent = false;
for (var index = 0; index < this.items.length; index++) {
var item = this.items[parseInt(index.toString(), 10)];
if (!haveContent) {
(haveContent = item.content.length > 0 || !ej2_base_1.isNullOrUndefined(item.content));
}
if (!haveOppContent) {
(haveOppContent = item.oppositeContent.length > 0 || !ej2_base_1.isNullOrUndefined(item.content));
}
}
this.element.classList.remove('e-content-only', 'e-opposite-content-only');
Iif (haveContent && !haveOppContent) {
this.element.classList.add('e-content-only');
}
Iif (haveOppContent && !haveContent) {
this.element.classList.add('e-opposite-content-only');
}
};
Timeline.prototype.updateItemContent = function (isContent, item, index, contentEle) {
var notCompile = !(this.isReact || this.isVue);
var ctn = this.getTemplateFunction(isContent ? item.content : item.oppositeContent, notCompile);
if (typeof ctn === 'string') {
contentEle.innerText = ctn;
}
else {
ej2_base_1.append(ctn({ item: item, itemIndex: index }, this), contentEle);
}
};
Timeline.prototype.updateTemplateFunction = function () {
this.templateFunction = this.template ? this.getTemplateFunction(this.template, false) : null;
};
Timeline.prototype.renderItemContent = function (index, isrerender, timelineItem) {
var listItems = this.timelineListEle.querySelectorAll('li');
if (isrerender) {
this.removeItemContent(listItems[parseInt((index).toString(), 10)]);
}
Eif (this.template) {
if (isrerender) {
listItems[parseInt((index).toString(), 10)].classList.add(TEMPLATE);
}
else {
timelineItem.classList.add(TEMPLATE);
}
var item = this.items[parseInt(index.toString(), 10)];
ej2_base_1.append(this.templateFunction({ item: item, itemIndex: index }, this, 'timelineTemplate', (this.element.id + '_timelineTemplate'), this.isStringTemplate), isrerender ? listItems[parseInt((index).toString(), 10)] : timelineItem);
}
this.renderReactTemplates();
};
Timeline.prototype.removeItemContent = function (ele) {
ele.classList.remove(TEMPLATE);
var firstChild = ele.firstElementChild;
for (var i = 0; i < ele.childElementCount; i++) {
firstChild.remove();
}
};
/**
* Gets template content based on the template property value.
*
* @param {string | Function} template - Template property value.
* @param {boolean} notCompile - Compile property value.
* @returns {Function} - Return template function.
* @hidden
*/
Timeline.prototype.getTemplateFunction = function (template, notCompile) {
Iif (notCompile === void 0) { notCompile = true; }
Eif (typeof template === 'string') {
var content = '';
try {
var tempEle = ej2_base_1.select(template);
if (tempEle) {
//Return innerHTML incase of jsrenderer script else outerHTML
content = tempEle.tagName === 'SCRIPT' ? tempEle.innerHTML : tempEle.outerHTML;
notCompile = false;
}
else {
content = template;
}
}
catch (e) {
content = template;
}
return notCompile ? content : ej2_base_1.compile(content);
}
else {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
return ej2_base_1.compile(template);
}
};
Timeline.prototype.removeItemElements = function () {
var listItems = this.timelineListEle.querySelectorAll('li');
for (var i = 0; i < listItems.length; i++) {
ej2_base_1.remove(listItems[parseInt(i.toString(), 10)]);
}
};
Timeline.prototype.updateElementClassArray = function () {
var classArray = [RTL, 'e-align-before', 'e-align-after', 'e-outline', 'e-fill', 'e-align-alternate',
'e-align-alternatereverse', TIMELINEREVERSE, HORIZONTAL, VERTICAL];
ej2_base_1.removeClass([this.element], classArray);
};
Timeline.prototype.updateContent = function () {
Iif (this.isReact) {
this.clearTemplate(['timelineTemplate']);
}
for (var i = 0; i < this.items.length; i++) {
this.renderItemContent(i, true);
}
};
Timeline.prototype.destroy = function () {
_super.prototype.destroy.call(this);
// unwires the events and detach the li elements
this.removeItemElements();
this.element.removeAttribute('role');
this.element.removeAttribute('aria-label');
this.clearTemplate();
Eif (this.timelineListEle) {
ej2_base_1.remove(this.timelineListEle);
}
this.timelineListEle = null;
this.updateElementClassArray();
};
Timeline.prototype.updateItems = function (newProp, oldPropItems, index, item) {
var _a, _b, _c, _d;
var timelineItemElements = this.timelineListEle.querySelectorAll('li');
var dotEle;
var contentEle;
var oppositeEle;
switch (newProp) {
case 'dotCss':
dotEle = timelineItemElements[parseInt(index.toString(), 10)].querySelector('.' + DOTCONTENT);
Eif (oldPropItems.dotCss !== '') {
(_a = dotEle.classList).remove.apply(_a, oldPropItems.dotCss.trim().split(' '));
}
if (item.dotCss !== '') {
(_b = dotEle.classList).add.apply(_b, this.items[parseInt(index.toString(), 10)].dotCss.trim().split(' '));
}
break;
case 'content':
contentEle = timelineItemElements[parseInt(index.toString(), 10)].querySelector('.' + CONTENT);
contentEle.innerText = '';
this.updateItemContent(true, item, index, contentEle);
this.haveOneSidecontent();
break;
case 'oppositeContent':
oppositeEle = timelineItemElements[parseInt(index.toString(), 10)].querySelector('.' + OPPOSITECONTENT);
oppositeEle.innerText = '';
this.updateItemContent(false, item, index, oppositeEle);
this.haveOneSidecontent();
break;
case 'disabled':
timelineItemElements[parseInt(index.toString(), 10)].classList[this.items[parseInt(index.toString(), 10)].disabled ? 'add' : 'remove'](DISABLED);
break;
case 'cssClass':
Eif (oldPropItems.cssClass !== '') {
(_c = timelineItemElements[parseInt(index.toString(), 10)].classList).remove.apply(_c, oldPropItems.cssClass.trim().split(' '));
}
if (item.cssClass !== '') {
(_d = timelineItemElements[parseInt(index.toString(), 10)].classList).add.apply(_d, item.cssClass.trim().split(' '));
}
break;
}
};
/**
* Called internally if any of the property value changed.
*
* @param {TimelineModel} newProp - Specifies new properties
* @param {TimelineModel} oldProp - Specifies old properties
* @returns {void}
* @private
*/
Timeline.prototype.onPropertyChanged = function (newProp, oldProp) {
for (var _i = 0, _a = Object.keys(newProp); _i < _a.length; _i++) {
var prop = _a[_i];
switch (prop) {
case 'items':
if (Array.isArray(newProp.items)) {
this.removeItemElements();
this.renderItems();
}
else {
var itemLength = Object.keys(newProp.items).length;
for (var i = 0; i < itemLength; i++) {
var itemPropLength = parseInt(Object.keys(newProp.items)[i], 10);
for (var j = 0; j < Object.keys(newProp.items[itemPropLength]).length; j++) {
var property = Object.keys(newProp.items[itemPropLength])[j];
this.updateItems(property, oldProp.items[itemPropLength], itemPropLength, newProp.items[itemPropLength]);
}
}
}
break;
case 'orientation':
this.updateOrientation();
break;
case 'align':
this.updateAlign();
break;
case 'enableRtl':
this.updateRtl();
break;
case 'cssClass':
this.updateCssClass(newProp.cssClass, oldProp.cssClass);
break;
case 'reverse':
this.element.classList[this.reverse ? 'add' : 'remove'](TIMELINEREVERSE);
break;
case 'template':
this.updateTemplateFunction();
this.updateContent();
break;
}
}
};
__decorate([
ej2_base_1.Property(TimelineOrientation.Vertical)
], Timeline.prototype, "orientation", void 0);
__decorate([
ej2_base_1.Property(TimelineAlign.After)
], Timeline.prototype, "align", void 0);
__decorate([
ej2_base_1.Collection([], TimelineItem)
], Timeline.prototype, "items", void 0);
__decorate([
ej2_base_1.Property('')
], Timeline.prototype, "cssClass", void 0);
__decorate([
ej2_base_1.Property(false)
], Timeline.prototype, "reverse", void 0);
__decorate([
ej2_base_1.Property('')
], Timeline.prototype, "template", void 0);
__decorate([
ej2_base_1.Event()
], Timeline.prototype, "created", void 0);
__decorate([
ej2_base_1.Event()
], Timeline.prototype, "beforeItemRender", void 0);
Timeline = __decorate([
ej2_base_1.NotifyPropertyChanges
], Timeline);
return Timeline;
}(ej2_base_1.Component));
exports.Timeline = Timeline;
});
|