-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathjquery-gantt.js
884 lines (755 loc) · 32 KB
/
jquery-gantt.js
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
/*!
* Gantt v1.0.0
* https://github.com/oguzhanoya/jquery-gantt
*
* Copyright (c) 2017 oguzhanoya
* Released under the MIT license
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery')) :
typeof define === 'function' && define.amd ? define(['jquery'], factory) :
(factory(global.$));
}(this, (function ($$1) { 'use strict';
$$1 = 'default' in $$1 ? $$1['default'] : $$1;
var DEFAULTS = {
// user defined data array of event [source]
data: [],
// data URL
dataURL: '',
// start date calendar
startDate: new Date(),
// end date calendar
endDate: new Date(),
// cell width px
cellWidth: 20,
// cell height px
cellHeight: 38,
// language
language: 'en',
// sticky header
stickyHeader: false,
// mouse scroll
mouseScroll: false,
// mouse scroll px
mouseScrollpx: 120,
// lazy load
lazyLoad: false,
// auto hide
autoHide: false,
// onInit event
onInit: $.noop,
// onDestroy event
onDestroy: $.noop
};
var lazyload = {
buildData: function buildData() {
var url = this.config.dataURL;
return $$1.ajax({
url: url,
dataType: 'jsonp',
jsonp: 'callback',
crossDomain: true,
contentType: 'application/json'
});
},
initLazyLoad: function initLazyLoad() {
var startDate = this.config.startDate;
var endDate = this.config.endDate;
startDate.setHours(0, 0, 0, 0);
endDate.setHours(0, 0, 0, 0);
this.scrollHandler();
},
renderLazyLoad: function renderLazyLoad(data, startDate, endDate) {
this.renderLazyLoadGrid(data, startDate, endDate);
var el = $$1(this.element);
var templateHeaderMonths = $$1('.gantt-header-months', el);
var templateHeaderDays = $$1('.gantt-header-days', el);
var templateHeaderDaysMin = $$1('.gantt-header-days-min', el);
// difference between start-date and end-date
var num = this.dateDiffInDays(startDate, endDate);
this.renderLazyLoadEvents(data, num);
for (var i = 0; i <= num; i += 1) {
var templateHeaderMonth = $$1('<div>', { class: 'gantt-header-month' });
var templateHeaderDay = $$1('<div>', { class: 'gantt-header-day' });
var templateHeaderDayMin = $$1('<div>', { class: 'gantt-header-day-min' });
// const weekOfday = startDate.getDay();
var day = startDate.getDate();
var month = startDate.getMonth() + 1;
var year = startDate.getFullYear();
var monthWidth = this.daysInMonth(month, year) * this.config.cellWidth;
// const weekOfdayName = this.config.region.dayNamesMin[weekOfday];
var monthName = this.config.region.monthNames[month - 1];
var dayTemplate = $$1(templateHeaderDay).text(day).css('width', this.config.cellWidth);
// const dayMinTemplate = $(templateHeaderDayMin).text(weekOfdayName)
// .css({ width: this.config.cellWidth });
var monthTemplate = $$1(templateHeaderMonth).text(monthName + ' ' + year).css({ width: monthWidth });
templateHeaderDays.append(dayTemplate);
templateHeaderDaysMin.append(templateHeaderDayMin);
var firstMonthIsNotFull = i === 0;
var firstDay = this.firstDayMonth(year, month);
firstDay.setHours(0, 0, 0, 0);
var firstDayEndDateMonth = this.firstDayMonth(this.config.endDate.getFullYear(), this.config.endDate.getMonth() + 1);
firstDayEndDateMonth.setHours(0, 0, 0, 0);
var checkFirstDayMonth = this.isEqual(startDate, firstDay);
var checkFirstDayMonthEndDate = this.isEqual(startDate, firstDayEndDateMonth);
if (checkFirstDayMonth || firstMonthIsNotFull) {
if (firstMonthIsNotFull) {
monthWidth -= (day - 1) * this.config.cellWidth;
}
if (checkFirstDayMonthEndDate) {
monthWidth = this.config.endDate.getDate() * this.config.cellWidth;
}
// var monthName = this.config.region.monthNames[month - 1];
// var monthTemplate = $(templateHeaderMonth).text(`${monthName} ${year}`)
// .css({ width: monthWidth });
templateHeaderMonths.append(monthTemplate);
}
startDate.setDate(startDate.getDate() + 1);
}
var totalWidth = $$1('.gantt-header-day', el).length * this.config.cellWidth;
$$1(templateHeaderMonths, el).css({ width: totalWidth });
$$1(templateHeaderDays, el).css({ width: totalWidth });
$$1(templateHeaderDaysMin, el).css({ width: totalWidth });
var templateGrid = $$1('.gantt-grid', el);
$$1(templateGrid, el).css({ width: totalWidth });
var templateGridRow = $$1('.gantt-grid-row', el);
$$1(templateGridRow, el).css({ width: this.gridDefaults.gridtotalWidth });
var templateGridCol = $$1('.gantt-grid-col', el);
$$1(templateGridCol, el).css({ height: this.gridDefaults.gridtotalHeight });
$$1('.gantt-event-row', el).css({ width: this.gridDefaults.gridtotalWidth });
this.gridDefaults.eventsWidth = this.gridDefaults.gridtotalWidth;
},
renderLazyLoadGrid: function renderLazyLoadGrid(data, startDate, endDate) {
var el = $$1(this.element);
// difference between start-date and end-date
var num = this.dateDiffInDays(startDate, endDate);
var totalWidth = this.getTotalWidth(num);
var totalHeight = this.getTotalHeight(data.length);
var templateGrid = $$1('.gantt-grid', el);
var templateGridCols = $$1('.gantt-grid-cols', el);
var templateGridRows = $$1('.gantt-grid-rows', el);
var sDate = new Date(startDate.getTime());
for (var i = 0; i <= num; i += 1) {
var templateGridCol = $$1('<div>', { class: 'gantt-grid-col', width: this.config.cellWidth, height: totalHeight });
// firefox width problem fix
templateGridCol.css('width', this.config.cellWidth);
var month = sDate.getMonth() + 1;
var year = sDate.getFullYear();
var lastDay = this.lastDayMonth(year, month);
if (this.isEqual(sDate, lastDay)) {
templateGridCol.css('border-color', '#bec5cc');
}
templateGridCols.append(templateGridCol);
// eslint-disable-line no-redeclare
sDate.setDate(sDate.getDate() + 1);
}
data.forEach(function () {
var templateGridRow = $$1('<div>', { class: 'gantt-grid-row', width: totalWidth, height: this.config.cellHeight });
templateGridRows.append(templateGridRow);
}, this);
templateGrid.append(templateGridCols).append(templateGridRows);
this.gridDefaults.gridtotalWidth += totalWidth;
this.gridDefaults.gridtotalHeight += totalHeight;
},
renderLazyLoadContainer: function renderLazyLoadContainer() {
var template = $$1('<div>', { class: 'gantt-container' });
var templateWrapper = $$1('<div>', { class: 'gantt-wrapper' });
var templateHeader = $$1('<div>', { class: 'gantt-header' });
var templateHeaderMonths = $$1('<div>', { class: 'gantt-header-months' });
var templateHeaderDays = $$1('<div>', { class: 'gantt-header-days' });
var templateHeaderDaysMin = $$1('<div>', { class: 'gantt-header-days-min' });
var arrowLeft = '<div class="arrow arrow-left"><span class="arrow-icon"></span></div>';
var arrowRight = '<div class="arrow arrow-right"><span class="arrow-icon"></span></div>';
var templateGrid = $$1('<div>', { class: 'gantt-grid' });
var templateEvents = $$1('<div>', { class: 'gantt-events' });
var templateLoading = $$1('<div>', { class: 'gantt-loading', style: 'display: none' });
templateHeader.append($$1(templateHeaderMonths));
templateHeader.append($$1(templateHeaderDays));
templateHeader.append($$1(templateHeaderDaysMin));
var templateGridCols = $$1('<div>', { class: 'gantt-grid-cols' });
var templateGridRows = $$1('<div>', { class: 'gantt-grid-rows' });
templateGrid.append(templateGridCols).append(templateGridRows);
template.append(templateHeader).append(templateGrid).append(templateEvents);
templateWrapper.append(arrowLeft).append(template).append(arrowRight).append(templateLoading);
return templateWrapper;
},
renderLazyLoadEvents: function renderLazyLoadEvents(data) {
var el = $$1(this.element);
var templateEvents = $$1('.gantt-events', el);
data.forEach(function (element) {
var itemStartDate = new Date(element.startdate);
var templateEventRow = $$1('<div>', { class: 'gantt-event-row', width: this.totalWidth });
var templateEvent = $$1('<div>', { class: 'gantt-event' });
var tourWidth = (parseInt(element.minNight, 10) + 1) * this.config.cellWidth;
var remDay = this.dateDiffInDays(this.config.startDate, itemStartDate);
var tooltipData = $$1.extend(element.tooltipData, { price: element.price });
var tourType = '';
if (element.type === 'Tur') {
tourType = 'tourFly';
} else if (element.type === 'TurBus') {
tourType = 'tourBus';
} else {
tourType = 'cruise';
}
var title = element.minNight + ' Gece';
var eventBlock = $$1('<a>', {
class: this.format('gantt-event-block {0}', tourType),
width: tourWidth + 'px',
href: '/' + element.url,
target: '_blank'
}).text(title).css('line-height', this.config.cellHeight - 28 + 'px').data('tooltip', this.tooltipView(tooltipData));
var eventIcon = $$1('<div class="gantt-event-icon"><div class="' + tourType + '"></div></div>');
var eventPrice = $$1('<div>', {
class: 'gantt-event-price'
}).text(element.price.original.price + ' ' + element.price.original.priceType);
var eventDesc = $$1('<div>', {
class: 'gantt-event-desc'
}).text(element.title);
var left = remDay * this.config.cellWidth + this.gridDefaults.eventsWidth;
templateEventRow.append(templateEvent.css('left', left).append(eventBlock).append(eventIcon).append(eventPrice).append(eventDesc)).css('height', this.config.cellHeight);
templateEvents.append(templateEventRow);
}, this);
return templateEvents;
}
};
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var Gantt = function () {
function Gantt(element, options) {
classCallCheck(this, Gantt);
var gridDefaults = {
gridtotalHeight: 0,
gridtotalWidth: 0,
eventsWidth: 0
};
var lang = options.language || DEFAULTS.language;
// eslint-disable-next-line no-param-reassign
options.lang = Gantt.LANGUAGES[lang];
// extend defaults with the init options.
this.config = $$1.extend({}, DEFAULTS, options);
// grid defaults
this.gridDefaults = $$1.extend({}, gridDefaults);
// store main DOM element.
this.element = element;
// no data source
if (this.config.dataURL === '' && this.config.data.length <= 0) console.warn('jquery-gantt: must provide a data source');
// dataURL is required
else if (this.config.dataURL === '' && this.config.lazyLoad) console.warn('jquery-gantt: dataURL is required for lazyLoad');
// initialize
else {
this.init();
}
}
createClass(Gantt, [{
key: 'init',
value: function init() {
var _this = this;
this.hook('onInit');
var html = '';
// erasing all the content from the container
$$1(this.element).html(html);
if (this.config.endDate.getTime() > this.config.startDate.getTime()) {
// lazy load
if (this.config.lazyLoad) {
this.initLazyLoad();
html = this.renderLazyLoadContainer();
} else if (this.config.data.length <= 0 && this.config.dataURL !== '') {
this.buildData().then(function (data) {
_this.config.data = data.Items;
html = _this.renderContainer();
$$1(_this.element).html(html);
_this.attachEvents(_this.element, _this.config);
_this.tooltipHover();
_this.colHighlighter();
});
} else {
html = this.renderContainer();
}
if (this.config.data.length > 0 || this.config.lazyLoad) {
$$1(this.element).html(html);
this.attachEvents(this.element, this.config);
this.tooltipHover();
this.colHighlighter();
}
} else {
console.warn('jquery-gantt: start-date is not greater than end-date');
}
}
}, {
key: 'hook',
value: function hook(hookName) {
if (this.config[hookName] !== undefined) {
this.config[hookName].call(this.el);
}
}
}, {
key: 'attachEvents',
value: function attachEvents(el, options) {
// sticky header
if (options.stickyHeader) {
var stickyH = function stickyH() {
var top = $$1('.gantt-wrapper', el).offset().top;
var height = $$1('.gantt-wrapper', el).height();
if (top >= $$1(this).scrollTop() || $$1(this).scrollTop() >= top + height - 80) {
$$1('.gantt-header', el).css('position', 'static');
$$1('.arrow', el).css('position', 'static');
} else {
$$1('.arrow', el).css({
position: 'relative',
top: $$1(this).scrollTop() - top + 'px'
});
$$1('.gantt-header', el).css({
position: 'relative',
top: $$1(this).scrollTop() - top + 'px',
left: $$1(this).scrollLeft + 'px',
'z-index': 1
});
}
};
$$1(window).scroll(stickyH);
}
// scroll page horizontally with mouse wheel
if (options.mouseScroll) {
$$1('.gantt-container', el).on('wheel mousewheel', function (e) {
if (e.originalEvent.wheelDelta > 0 || e.originalEvent.detail < 0) {
this.scrollLeft -= options.mouseScrollpx;
} else {
this.scrollLeft += options.mouseScrollpx;
}
});
}
if (options.lazyLoad) {
var self = this;
var loading = false;
$$1('.gantt-container', el).scroll(function () {
if (this.scrollWidth - this.clientWidth - this.scrollLeft < 900 && !loading) {
loading = true;
self.scrollHandler(function () {
loading = false;
});
}
});
}
// scroll drag
$$1('.gantt-container', el).on('mousedown', function (event) {
$$1(this).data('down', true).data('x', event.clientX).data('scrollLeft', this.scrollLeft).addClass('dragging');
return false;
}).on('mouseup', function () {
$$1(this).data('down', false).removeClass('dragging');
}).on('mousemove', function (event) {
if ($$1(this).data('down') === true) {
this.scrollLeft = $$1(this).data('scrollLeft') + $$1(this).data('x') - event.clientX;
}
if (options.autoHide) {
var sl = this.scrollLeft;
var daywidth = sl / options.cellWidth;
daywidth = Math.floor(daywidth);
var cWidth = daywidth * options.cellWidth;
var events = $$1('.gantt-events', el).find('.gantt-event');
$$1.each(events, function (index, elem) {
var eventLeft = $$1(elem).css('left');
eventLeft = parseInt(eventLeft, 10);
if (eventLeft <= cWidth) {
$$1(elem).closest('.gantt-event-row').hide();
} else {
$$1(elem).closest('.gantt-event-row').show();
}
});
var currentDay = new Date(options.startDate.getTime());
currentDay.setDate(currentDay.getDate() + daywidth);
}
}).on('mouseleave', function () {
$$1(this).data('down', false).removeClass('dragging');
});
// arrow button click
$$1('.arrow', el).on('click', function () {
var direction = $$1(this).hasClass('arrow-right');
var scrollLeft = $$1('.gantt-container', el).scrollLeft();
if (direction) {
$$1('.gantt-container', el).scrollLeft(scrollLeft + 240);
} else {
$$1('.gantt-container', el).scrollLeft(scrollLeft - 240);
}
});
}
}, {
key: 'xhrRequest',
value: function xhrRequest(startDate, endDate) {
var self = this;
var el = $$1(this.element);
var url = this.config.dataURL;
return $$1.ajax({
url: url,
dataType: 'jsonp',
jsonp: 'callback',
contentType: 'application/json',
crossDomain: true,
data: {
startDate: self.getFormattedDate(startDate),
endDate: self.getFormattedDate(endDate)
},
beforeSend: function beforeSend() {
$$1('.gantt-loading', el).fadeIn();
}
});
}
}, {
key: 'scrollHandler',
value: function scrollHandler(callback) {
var self = this;
var el = $$1(this.element);
var startDate = this.config.startDate;
var nextDate = new Date(this.config.startDate.getTime());
nextDate.setMonth(nextDate.getMonth() + 2);
var month = nextDate.getMonth() + 1;
var year = nextDate.getFullYear();
nextDate = this.lastDayMonth(year, month);
var monthEndDate = this.config.endDate.getMonth() + 1;
var yearEndDate = this.config.endDate.getFullYear();
var dayEndDate = this.config.endDate.getDate();
if (year === yearEndDate || year > yearEndDate) {
if (year > yearEndDate) {
nextDate.setMonth(monthEndDate - 1);
nextDate.setYear(yearEndDate);
nextDate.setDate(dayEndDate);
}
if (month === monthEndDate || month > monthEndDate) {
nextDate.setMonth(monthEndDate - 1);
nextDate.setDate(dayEndDate);
}
}
if (startDate.getTime() <= this.config.endDate.getTime()) {
this.xhrRequest(startDate, nextDate).done(function (data) {
self.renderLazyLoad(data.Items, startDate, nextDate);
self.tooltipHover();
self.colHighlighter();
if (typeof callback === 'function') {
callback();
}
}).always(function () {
$$1('.gantt-loading', el).fadeOut();
});
}
}
}, {
key: 'renderHeader',
value: function renderHeader(num) {
var templateHeader = $$1('<div>', { class: 'gantt-header' });
var templateHeaderMonths = $$1('<div>', { class: 'gantt-header-months' });
var templateHeaderDays = $$1('<div>', { class: 'gantt-header-days' });
var templateHeaderDaysMin = $$1('<div>', { class: 'gantt-header-days-min' });
var totalWidth = this.getTotalWidth(num);
this.setHours();
var startDate = new Date(this.config.startDate.getTime());
for (var i = 0; i <= num; i += 1) {
var templateHeaderMonth = $$1('<div>', { class: 'gantt-header-month' });
var templateHeaderDay = $$1('<div>', { class: 'gantt-header-day' });
var templateHeaderDayMin = $$1('<div>', { class: 'gantt-header-day-min' });
var weekOfday = startDate.getDay();
var day = startDate.getDate();
var month = startDate.getMonth() + 1;
var year = startDate.getFullYear();
var monthWidth = this.daysInMonth(month, year) * this.config.cellWidth;
var dayTemplate = $$1(templateHeaderDay).text(day).css('width', this.config.cellWidth);
$$1(templateHeaderDays).append(dayTemplate);
var weekOfdayName = this.config.lang.dayNamesMin[weekOfday];
var dayMinTemplate = $$1(templateHeaderDayMin).text(weekOfdayName).css({ width: this.config.cellWidth });
$$1(templateHeaderDaysMin).append(dayMinTemplate);
var firstMonthIsNotFull = i === 0;
var firstDay = this.firstDayMonth(year, month);
var firstDayEndDateMonth = this.firstDayMonth(this.config.endDate.getFullYear(), this.config.endDate.getMonth() + 1);
startDate.setHours(0, 0, 0, 0);
var checkFirstDayMonth = this.isEqual(startDate, firstDay);
var checkFirstDayMonthEndDate = this.isEqual(startDate, firstDayEndDateMonth);
if (checkFirstDayMonth || firstMonthIsNotFull) {
if (firstMonthIsNotFull) {
monthWidth -= (day - 1) * this.config.cellWidth;
}
if (checkFirstDayMonthEndDate) {
monthWidth = this.config.endDate.getDate() * this.config.cellWidth;
}
var monthName = this.config.lang.monthNames[month - 1];
var monthTemplate = $$1(templateHeaderMonth).text(monthName + ' ' + year).css({ width: monthWidth });
$$1(templateHeaderMonths).append(monthTemplate);
}
startDate.setDate(startDate.getDate() + 1);
}
templateHeader.append($$1(templateHeaderMonths).css('width', totalWidth));
templateHeader.append($$1(templateHeaderDays).css('width', totalWidth));
templateHeader.append($$1(templateHeaderDaysMin).css('width', totalWidth));
return templateHeader;
}
}, {
key: 'renderContainer',
value: function renderContainer() {
var template = $$1('<div>', { class: 'gantt-container' });
var templateWrapper = $$1('<div>', { class: 'gantt-wrapper' });
var arrowLeft = '<div class="arrow arrow-left"><span class="arrow-icon"></span></div>';
var arrowRight = '<div class="arrow arrow-right"><span class="arrow-icon"></span></div>';
// difference between start-date and end-date
var diffInDays = this.dateDiffInDays(this.config.startDate, this.config.endDate);
var templateHeader = this.renderHeader(diffInDays);
var templateGrid = this.renderGrid(diffInDays);
var templateEvents = this.renderEvents(diffInDays);
template.append(templateHeader).append(templateGrid).append(templateEvents);
templateWrapper.append(arrowLeft).append(template).append(arrowRight);
return templateWrapper;
}
}, {
key: 'renderGrid',
value: function renderGrid(num) {
var data = this.config.data;
var totalWidth = this.getTotalWidth(num);
var totalHeight = this.getTotalHeight(data.length);
var templateGrid = $$1('<div>', { class: 'gantt-grid', width: totalWidth });
var templateGridCols = $$1('<div>', { class: 'gantt-grid-cols' });
var templateGridRows = $$1('<div>', { class: 'gantt-grid-rows' });
var startDate = new Date(this.config.startDate.getTime());
for (var i = 0; i <= num; i += 1) {
var templateGridCol = $$1('<div>', { class: 'gantt-grid-col', width: this.config.cellWidth, height: totalHeight });
// firefox width problem fix
templateGridCol.css('width', this.config.cellWidth);
var month = startDate.getMonth() + 1;
var year = startDate.getFullYear();
var lastDay = this.lastDayMonth(year, month);
startDate.setHours(0, 0, 0, 0);
if (this.isEqual(startDate, lastDay)) {
templateGridCol.css('border-color', '#bec5cc');
}
templateGridCols.append(templateGridCol);
startDate.setDate(startDate.getDate() + 1);
}
data.forEach(function () {
var templateGridRow = $$1('<div>', { class: 'gantt-grid-row', width: totalWidth, height: this.config.cellHeight });
templateGridRows.append(templateGridRow);
}, this);
templateGrid.append(templateGridCols).append(templateGridRows);
return templateGrid;
}
}, {
key: 'renderEvents',
value: function renderEvents(num) {
var data = this.config.data;
var totalWidth = this.getTotalWidth(num);
// const totalHeight = this.getTotalHeight(data.length);
var templateEvents = $$1('<div>', { class: 'gantt-events', width: totalWidth });
data.forEach(function (el) {
var itemStartDate = new Date(el.startdate);
var templateEventRow = $$1('<div>', { class: 'gantt-event-row', width: this.totalWidth });
var templateEvent = $$1('<div>', { class: 'gantt-event' });
var tourWidth = (parseInt(el.minNight, 10) + 1) * this.config.cellWidth;
var remDay = this.dateDiffInDays(this.config.startDate, itemStartDate);
var tooltipData = $$1.extend(el.tooltipData, { price: el.price });
var tourType = '';
if (el.type === 'Tur') {
tourType = 'tourFly';
} else if (el.type === 'TurBus') {
tourType = 'tourBus';
} else {
tourType = 'cruise';
}
var title = el.minNight + ' Gece';
var eventBlock = $$1('<a>', {
class: 'gantt-event-block ' + tourType,
width: tourWidth + 'px',
href: '' + el.url,
target: '_blank'
}).text(title).css('line-height', this.config.cellHeight - 28 + 'px').data('tooltip', this.tooltipView(tooltipData));
var eventIcon = $$1('<div class="gantt-event-icon"><div class="' + tourType + '"></div></div>');
var eventPrice = $$1('<div>', {
class: 'gantt-event-price'
}).text(el.price.original.price + ' ' + el.price.original.priceType);
var eventDesc = $$1('<div>', {
class: 'gantt-event-desc'
}).text(el.title);
var left = remDay * this.config.cellWidth;
templateEventRow.append(templateEvent.css('left', left).append(eventBlock).append(eventIcon).append(eventPrice).append(eventDesc)).css('height', this.config.cellHeight);
templateEvents.append(templateEventRow);
}, this);
return templateEvents;
}
}, {
key: 'getTotalWidth',
value: function getTotalWidth(day) {
return day === 0 ? 0 : (day + 1) * this.config.cellWidth;
}
}, {
key: 'getTotalHeight',
value: function getTotalHeight(len) {
return len * this.config.cellHeight;
}
}, {
key: 'setHours',
value: function setHours() {
this.config.startDate.setHours(0, 0, 0, 0);
this.config.endDate.setHours(0, 0, 0, 0);
}
}, {
key: 'firstDayMonth',
value: function firstDayMonth(year, month) {
return new Date(year, month - 1, 1);
}
}, {
key: 'lastDayMonth',
value: function lastDayMonth(year, month) {
return new Date(year, month, 0);
}
}, {
key: 'daysInMonth',
value: function daysInMonth(month, year) {
return new Date(year, month, 0).getDate();
}
}, {
key: 'isEqual',
value: function isEqual(a, b) {
return a.getTime() === b.getTime();
}
}, {
key: 'dateDiffInDays',
value: function dateDiffInDays(a, b) {
var MS_PER_DAY = 1000 * 60 * 60 * 24;
var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
return Math.floor((utc2 - utc1) / MS_PER_DAY);
}
}, {
key: 'getFormattedDate',
value: function getFormattedDate(date) {
var currDate = date.getDate();
var currMonth = date.getMonth() + 1;
var currYear = date.getFullYear();
return currYear + '-' + currMonth + '-' + currDate;
}
}, {
key: 'tooltipView',
value: function tooltipView(data) {
var template = '' + '<div class="gantt-tooltip">' + ' <div class="tooltip-content">' + ' <img src="{0}" alt="tooltip-img">' + ' <span class="title">{1}</span>' + ' <div class="desc">' + ' {2} <br> {3} <br> {4}' + ' </div>' + ' </div>' + ' <div class="tooltip-action">' + ' <span>Gidiş: <span class="desc">{5}</span></span><br>' + ' <span>Dönüş: <span class="desc">{6}</span></span>' + ' <div class="price">' + ' <div class="tl">{7}</div>' + ' <div class="eur">{8}</div>' + ' </div>' + ' </div>' + '</div>';
var html = this.format(template, data.image, data.title, data.desc[0], data.desc[1], data.desc[2], data.dates.begin, data.dates.end, this.format('{0} {1}', data.price.converted.price, data.price.converted.priceType), this.format('{0} {1}', data.price.original.price, data.price.original.priceType));
return html;
}
}, {
key: 'tooltipHover',
value: function tooltipHover() {
var el = $$1(this.element);
var options = this.config;
// tooltip mouse enter & leave
$$1('.gantt-event-block', el).on('mouseenter', function () {
var elheight = $$1(el).height();
// const elwidth = $(el).width();
var eltop = $$1(el).offset().top;
var data = $$1(this).data('tooltip');
var left = $$1(this).offset().left;
var top = $$1(this).offset().top;
if (top >= elheight + eltop - 168) {
// position top
data = $$1(data).css({ left: left });
$$1('body').append(data);
var dheight = $$1('.gantt-tooltip', 'body').outerHeight();
$$1('.gantt-tooltip', 'body').css('top', top - dheight - 12);
} else {
// position bottom
data = $$1(data).css({
top: top + options.cellHeight,
left: left
});
$$1('body').append(data);
}
$$1('.gantt-tooltip', 'body').hide().fadeIn(250);
}).on('mouseleave', function () {
$$1('.gantt-tooltip', 'body').remove();
});
}
}, {
key: 'colHighlighter',
value: function colHighlighter() {
var el = $$1(this.element);
// highlighter
$$1('.gantt-grid-col, .gantt-header-day, .gantt-header-day-min', el).on('mouseenter', function () {
// const grIndex = $(this).closest('.gantt-grid-col').index();
var gcIndex = $$1(this).index();
$$1('.gantt-container', el).find('.gantt-grid-col').removeClass('active').eq(gcIndex).addClass('active');
$$1('.gantt-header', el).find('.gantt-header-days').find('.gantt-header-day').removeClass('active').eq(gcIndex).addClass('active');
$$1('.gantt-container', el).find('.gantt-header').find('.gantt-header-days-min').find('.gantt-header-day-min').removeClass('active').eq(gcIndex).addClass('active');
});
// event hover
$$1('.gantt-event-block', el).on('mousemove', function () {
$$1('.gantt-container', el).find('.gantt-grid-col').removeClass('active');
$$1('.gantt-header', el).find('.gantt-header-days').find('.gantt-header-day').removeClass('active');
$$1('.gantt-container', el).find('.gantt-header').find('.gantt-header-days-min').find('.gantt-header-day-min').removeClass('active');
});
}
}, {
key: 'format',
value: function format() {
// eslint-disable-next-line prefer-rest-params
var theString = arguments[0];
for (var i = 1; i < arguments.length; i += 1) {
var regEx = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
// eslint-disable-next-line prefer-rest-params
theString = theString.replace(regEx, arguments[i]);
}
return theString;
}
}, {
key: 'destroy',
value: function destroy() {
$$1(window).off('scroll');
this.element.empty();
this.element.removeData('plugin_Gantt');
this.hook('onDestroy');
}
}], [{
key: 'setDefaults',
value: function setDefaults(options) {
$$1.extend(DEFAULTS, options);
}
}]);
return Gantt;
}();
Gantt.LANGUAGES = {
en: {
monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
}
};
$$1.extend(Gantt.prototype, lazyload);
var other = $$1.fn.gantt;
$$1.fn.gantt = function (options) {
return this.each(function () {
if (!$$1.data(this, 'plugin_Gantt')) {
$$1.data(this, 'plugin_Gantt', new Gantt($$1(this), options));
}
});
};
$$1.fn.gantt.version = '1.0.0';
$$1.fn.gantt.l10n = Gantt.LANGUAGES;
$$1.fn.gantt.setDefaults = Gantt.setDefaults;
// No conflict
$$1.fn.gantt.noConflict = function () {
$$1.fn.gantt = other;
return this;
};
})));
//# sourceMappingURL=jquery-gantt.js.map