UNPKG

109 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/animations'), require('@angular/common'), require('primeng/button'), require('primeng/dom'), require('primeng/api'), require('@angular/forms')) :
3 typeof define === 'function' && define.amd ? define('primeng/calendar', ['exports', '@angular/core', '@angular/animations', '@angular/common', 'primeng/button', 'primeng/dom', 'primeng/api', '@angular/forms'], factory) :
4 (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.calendar = {}), global.ng.core, global.ng.animations, global.ng.common, global.primeng.button, global.primeng.dom, global.primeng.api, global.ng.forms));
5}(this, (function (exports, core, animations, common, button, dom, api, forms) { 'use strict';
6
7 var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
8 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
10 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
11 return c > 3 && r && Object.defineProperty(target, key, r), r;
12 };
13 var __read = (this && this.__read) || function (o, n) {
14 var m = typeof Symbol === "function" && o[Symbol.iterator];
15 if (!m) return o;
16 var i = m.call(o), r, ar = [], e;
17 try {
18 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19 }
20 catch (error) { e = { error: error }; }
21 finally {
22 try {
23 if (r && !r.done && (m = i["return"])) m.call(i);
24 }
25 finally { if (e) throw e.error; }
26 }
27 return ar;
28 };
29 var __spread = (this && this.__spread) || function () {
30 for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
31 return ar;
32 };
33 var __values = (this && this.__values) || function(o) {
34 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
35 if (m) return m.call(o);
36 if (o && typeof o.length === "number") return {
37 next: function () {
38 if (o && i >= o.length) o = void 0;
39 return { value: o && o[i++], done: !o };
40 }
41 };
42 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
43 };
44 var CALENDAR_VALUE_ACCESSOR = {
45 provide: forms.NG_VALUE_ACCESSOR,
46 useExisting: core.forwardRef(function () { return Calendar; }),
47 multi: true
48 };
49 var Calendar = /** @class */ (function () {
50 function Calendar(el, renderer, cd, zone) {
51 this.el = el;
52 this.renderer = renderer;
53 this.cd = cd;
54 this.zone = zone;
55 this.dateFormat = 'mm/dd/yy';
56 this.multipleSeparator = ',';
57 this.rangeSeparator = '-';
58 this.inline = false;
59 this.showOtherMonths = true;
60 this.icon = 'pi pi-calendar';
61 this.shortYearCutoff = '+10';
62 this.hourFormat = '24';
63 this.stepHour = 1;
64 this.stepMinute = 1;
65 this.stepSecond = 1;
66 this.showSeconds = false;
67 this.showOnFocus = true;
68 this.showWeek = false;
69 this.dataType = 'date';
70 this.selectionMode = 'single';
71 this.todayButtonStyleClass = 'ui-button-secondary';
72 this.clearButtonStyleClass = 'ui-button-secondary';
73 this.autoZIndex = true;
74 this.baseZIndex = 0;
75 this.keepInvalid = false;
76 this.hideOnDateTimeSelect = true;
77 this.numberOfMonths = 1;
78 this.view = 'date';
79 this.timeSeparator = ":";
80 this.showTransitionOptions = '225ms ease-out';
81 this.hideTransitionOptions = '195ms ease-in';
82 this.onFocus = new core.EventEmitter();
83 this.onBlur = new core.EventEmitter();
84 this.onClose = new core.EventEmitter();
85 this.onSelect = new core.EventEmitter();
86 this.onInput = new core.EventEmitter();
87 this.onTodayClick = new core.EventEmitter();
88 this.onClearClick = new core.EventEmitter();
89 this.onMonthChange = new core.EventEmitter();
90 this.onYearChange = new core.EventEmitter();
91 this.onClickOutside = new core.EventEmitter();
92 this.onShow = new core.EventEmitter();
93 this._locale = {
94 firstDayOfWeek: 0,
95 dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
96 dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
97 dayNamesMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
98 monthNames: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
99 monthNamesShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
100 today: 'Today',
101 clear: 'Clear',
102 dateFormat: 'mm/dd/yy',
103 weekHeader: 'Wk'
104 };
105 this.onModelChange = function () { };
106 this.onModelTouched = function () { };
107 this.inputFieldValue = null;
108 this.navigationState = null;
109 this.convertTo24Hour = function (hours, pm) {
110 if (this.hourFormat == '12') {
111 if (hours === 12) {
112 return (pm ? 12 : 0);
113 }
114 else {
115 return (pm ? hours + 12 : hours);
116 }
117 }
118 return hours;
119 };
120 }
121 Object.defineProperty(Calendar.prototype, "content", {
122 set: function (content) {
123 var _this = this;
124 this.contentViewChild = content;
125 if (this.contentViewChild) {
126 if (this.isMonthNavigate) {
127 Promise.resolve(null).then(function () { return _this.updateFocus(); });
128 this.isMonthNavigate = false;
129 }
130 else {
131 this.initFocusableCell();
132 }
133 }
134 },
135 enumerable: true,
136 configurable: true
137 });
138 ;
139 Object.defineProperty(Calendar.prototype, "minDate", {
140 get: function () {
141 return this._minDate;
142 },
143 set: function (date) {
144 this._minDate = date;
145 if (this.currentMonth != undefined && this.currentMonth != null && this.currentYear) {
146 this.createMonths(this.currentMonth, this.currentYear);
147 }
148 },
149 enumerable: true,
150 configurable: true
151 });
152 Object.defineProperty(Calendar.prototype, "maxDate", {
153 get: function () {
154 return this._maxDate;
155 },
156 set: function (date) {
157 this._maxDate = date;
158 if (this.currentMonth != undefined && this.currentMonth != null && this.currentYear) {
159 this.createMonths(this.currentMonth, this.currentYear);
160 }
161 },
162 enumerable: true,
163 configurable: true
164 });
165 Object.defineProperty(Calendar.prototype, "disabledDates", {
166 get: function () {
167 return this._disabledDates;
168 },
169 set: function (disabledDates) {
170 this._disabledDates = disabledDates;
171 if (this.currentMonth != undefined && this.currentMonth != null && this.currentYear) {
172 this.createMonths(this.currentMonth, this.currentYear);
173 }
174 },
175 enumerable: true,
176 configurable: true
177 });
178 Object.defineProperty(Calendar.prototype, "disabledDays", {
179 get: function () {
180 return this._disabledDays;
181 },
182 set: function (disabledDays) {
183 this._disabledDays = disabledDays;
184 if (this.currentMonth != undefined && this.currentMonth != null && this.currentYear) {
185 this.createMonths(this.currentMonth, this.currentYear);
186 }
187 },
188 enumerable: true,
189 configurable: true
190 });
191 Object.defineProperty(Calendar.prototype, "yearRange", {
192 get: function () {
193 return this._yearRange;
194 },
195 set: function (yearRange) {
196 this._yearRange = yearRange;
197 if (yearRange) {
198 var years = yearRange.split(':');
199 var yearStart = parseInt(years[0]);
200 var yearEnd = parseInt(years[1]);
201 this.populateYearOptions(yearStart, yearEnd);
202 }
203 },
204 enumerable: true,
205 configurable: true
206 });
207 Object.defineProperty(Calendar.prototype, "showTime", {
208 get: function () {
209 return this._showTime;
210 },
211 set: function (showTime) {
212 this._showTime = showTime;
213 if (this.currentHour === undefined) {
214 this.initTime(this.value || new Date());
215 }
216 this.updateInputfield();
217 },
218 enumerable: true,
219 configurable: true
220 });
221 Object.defineProperty(Calendar.prototype, "locale", {
222 get: function () {
223 return this._locale;
224 },
225 set: function (newLocale) {
226 this._locale = newLocale;
227 if (this.view === 'date') {
228 this.createWeekDays();
229 this.createMonths(this.currentMonth, this.currentYear);
230 }
231 else if (this.view === 'month') {
232 this.createMonthPickerValues();
233 }
234 },
235 enumerable: true,
236 configurable: true
237 });
238 Calendar.prototype.ngOnInit = function () {
239 var date = this.defaultDate || new Date();
240 this.currentMonth = date.getMonth();
241 this.currentYear = date.getFullYear();
242 if (this.view === 'date') {
243 this.createWeekDays();
244 this.initTime(date);
245 this.createMonths(this.currentMonth, this.currentYear);
246 this.ticksTo1970 = (((1970 - 1) * 365 + Math.floor(1970 / 4) - Math.floor(1970 / 100) + Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000);
247 }
248 else if (this.view === 'month') {
249 this.createMonthPickerValues();
250 }
251 };
252 Calendar.prototype.ngAfterContentInit = function () {
253 var _this = this;
254 this.templates.forEach(function (item) {
255 switch (item.getType()) {
256 case 'date':
257 _this.dateTemplate = item.template;
258 break;
259 case 'disabledDate':
260 _this.disabledDateTemplate = item.template;
261 break;
262 default:
263 _this.dateTemplate = item.template;
264 break;
265 }
266 });
267 };
268 Calendar.prototype.populateYearOptions = function (start, end) {
269 this.yearOptions = [];
270 for (var i = start; i <= end; i++) {
271 this.yearOptions.push(i);
272 }
273 };
274 Calendar.prototype.createWeekDays = function () {
275 this.weekDays = [];
276 var dayIndex = this.locale.firstDayOfWeek;
277 for (var i = 0; i < 7; i++) {
278 this.weekDays.push(this.locale.dayNamesMin[dayIndex]);
279 dayIndex = (dayIndex == 6) ? 0 : ++dayIndex;
280 }
281 };
282 Calendar.prototype.createMonthPickerValues = function () {
283 this.monthPickerValues = [];
284 for (var i = 0; i <= 11; i++) {
285 this.monthPickerValues.push(this.locale.monthNamesShort[i]);
286 }
287 };
288 Calendar.prototype.createMonths = function (month, year) {
289 this.months = this.months = [];
290 for (var i = 0; i < this.numberOfMonths; i++) {
291 var m = month + i;
292 var y = year;
293 if (m > 11) {
294 m = m % 11 - 1;
295 y = year + 1;
296 }
297 this.months.push(this.createMonth(m, y));
298 }
299 };
300 Calendar.prototype.getWeekNumber = function (date) {
301 var checkDate = new Date(date.getTime());
302 checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
303 var time = checkDate.getTime();
304 checkDate.setMonth(0);
305 checkDate.setDate(1);
306 return Math.floor(Math.round((time - checkDate.getTime()) / 86400000) / 7) + 1;
307 };
308 Calendar.prototype.createMonth = function (month, year) {
309 var dates = [];
310 var firstDay = this.getFirstDayOfMonthIndex(month, year);
311 var daysLength = this.getDaysCountInMonth(month, year);
312 var prevMonthDaysLength = this.getDaysCountInPrevMonth(month, year);
313 var dayNo = 1;
314 var today = new Date();
315 var weekNumbers = [];
316 var monthRows = Math.ceil((daysLength + firstDay) / 7);
317 for (var i = 0; i < monthRows; i++) {
318 var week = [];
319 if (i == 0) {
320 for (var j = (prevMonthDaysLength - firstDay + 1); j <= prevMonthDaysLength; j++) {
321 var prev = this.getPreviousMonthAndYear(month, year);
322 week.push({ day: j, month: prev.month, year: prev.year, otherMonth: true,
323 today: this.isToday(today, j, prev.month, prev.year), selectable: this.isSelectable(j, prev.month, prev.year, true) });
324 }
325 var remainingDaysLength = 7 - week.length;
326 for (var j = 0; j < remainingDaysLength; j++) {
327 week.push({ day: dayNo, month: month, year: year, today: this.isToday(today, dayNo, month, year),
328 selectable: this.isSelectable(dayNo, month, year, false) });
329 dayNo++;
330 }
331 }
332 else {
333 for (var j = 0; j < 7; j++) {
334 if (dayNo > daysLength) {
335 var next = this.getNextMonthAndYear(month, year);
336 week.push({ day: dayNo - daysLength, month: next.month, year: next.year, otherMonth: true,
337 today: this.isToday(today, dayNo - daysLength, next.month, next.year),
338 selectable: this.isSelectable((dayNo - daysLength), next.month, next.year, true) });
339 }
340 else {
341 week.push({ day: dayNo, month: month, year: year, today: this.isToday(today, dayNo, month, year),
342 selectable: this.isSelectable(dayNo, month, year, false) });
343 }
344 dayNo++;
345 }
346 }
347 if (this.showWeek) {
348 weekNumbers.push(this.getWeekNumber(new Date(week[0].year, week[0].month, week[0].day)));
349 }
350 dates.push(week);
351 }
352 return {
353 month: month,
354 year: year,
355 dates: dates,
356 weekNumbers: weekNumbers
357 };
358 };
359 Calendar.prototype.initTime = function (date) {
360 this.pm = date.getHours() > 11;
361 if (this.showTime) {
362 this.currentMinute = date.getMinutes();
363 this.currentSecond = date.getSeconds();
364 this.setCurrentHourPM(date.getHours());
365 }
366 else if (this.timeOnly) {
367 this.currentMinute = 0;
368 this.currentHour = 0;
369 this.currentSecond = 0;
370 }
371 };
372 Calendar.prototype.navBackward = function (event) {
373 var _this = this;
374 event.stopPropagation();
375 if (this.disabled) {
376 event.preventDefault();
377 return;
378 }
379 this.isMonthNavigate = true;
380 if (this.view === 'month') {
381 this.decrementYear();
382 setTimeout(function () {
383 _this.updateFocus();
384 }, 1);
385 }
386 else {
387 if (this.currentMonth === 0) {
388 this.currentMonth = 11;
389 this.decrementYear();
390 }
391 else {
392 this.currentMonth--;
393 }
394 this.onMonthChange.emit({ month: this.currentMonth + 1, year: this.currentYear });
395 this.createMonths(this.currentMonth, this.currentYear);
396 }
397 };
398 Calendar.prototype.navForward = function (event) {
399 var _this = this;
400 event.stopPropagation();
401 if (this.disabled) {
402 event.preventDefault();
403 return;
404 }
405 this.isMonthNavigate = true;
406 if (this.view === 'month') {
407 this.incrementYear();
408 setTimeout(function () {
409 _this.updateFocus();
410 }, 1);
411 }
412 else {
413 if (this.currentMonth === 11) {
414 this.currentMonth = 0;
415 this.incrementYear();
416 }
417 else {
418 this.currentMonth++;
419 }
420 this.onMonthChange.emit({ month: this.currentMonth + 1, year: this.currentYear });
421 this.createMonths(this.currentMonth, this.currentYear);
422 }
423 };
424 Calendar.prototype.decrementYear = function () {
425 this.currentYear--;
426 if (this.yearNavigator && this.currentYear < this.yearOptions[0]) {
427 var difference = this.yearOptions[this.yearOptions.length - 1] - this.yearOptions[0];
428 this.populateYearOptions(this.yearOptions[0] - difference, this.yearOptions[this.yearOptions.length - 1] - difference);
429 }
430 };
431 Calendar.prototype.incrementYear = function () {
432 this.currentYear++;
433 if (this.yearNavigator && this.currentYear > this.yearOptions[this.yearOptions.length - 1]) {
434 var difference = this.yearOptions[this.yearOptions.length - 1] - this.yearOptions[0];
435 this.populateYearOptions(this.yearOptions[0] + difference, this.yearOptions[this.yearOptions.length - 1] + difference);
436 }
437 };
438 Calendar.prototype.onDateSelect = function (event, dateMeta) {
439 var _this = this;
440 if (this.disabled || !dateMeta.selectable) {
441 event.preventDefault();
442 return;
443 }
444 if (this.isMultipleSelection() && this.isSelected(dateMeta)) {
445 this.value = this.value.filter(function (date, i) {
446 return !_this.isDateEquals(date, dateMeta);
447 });
448 if (this.value.length === 0) {
449 this.value = null;
450 }
451 this.updateModel(this.value);
452 }
453 else {
454 if (this.shouldSelectDate(dateMeta)) {
455 this.selectDate(dateMeta);
456 }
457 }
458 if (this.isSingleSelection() && this.hideOnDateTimeSelect) {
459 setTimeout(function () {
460 event.preventDefault();
461 _this.hideOverlay();
462 if (_this.mask) {
463 _this.disableModality();
464 }
465 _this.cd.markForCheck();
466 }, 150);
467 }
468 this.updateInputfield();
469 event.preventDefault();
470 };
471 Calendar.prototype.shouldSelectDate = function (dateMeta) {
472 if (this.isMultipleSelection())
473 return this.maxDateCount != null ? this.maxDateCount > (this.value ? this.value.length : 0) : true;
474 else
475 return true;
476 };
477 Calendar.prototype.onMonthSelect = function (event, index) {
478 if (!dom.DomHandler.hasClass(event.target, 'ui-state-disabled')) {
479 this.onDateSelect(event, { year: this.currentYear, month: index, day: 1, selectable: true });
480 }
481 };
482 Calendar.prototype.updateInputfield = function () {
483 var formattedValue = '';
484 if (this.value) {
485 if (this.isSingleSelection()) {
486 formattedValue = this.formatDateTime(this.value);
487 }
488 else if (this.isMultipleSelection()) {
489 for (var i = 0; i < this.value.length; i++) {
490 var dateAsString = this.formatDateTime(this.value[i]);
491 formattedValue += dateAsString;
492 if (i !== (this.value.length - 1)) {
493 formattedValue += this.multipleSeparator + ' ';
494 }
495 }
496 }
497 else if (this.isRangeSelection()) {
498 if (this.value && this.value.length) {
499 var startDate = this.value[0];
500 var endDate = this.value[1];
501 formattedValue = this.formatDateTime(startDate);
502 if (endDate) {
503 formattedValue += ' ' + this.rangeSeparator + ' ' + this.formatDateTime(endDate);
504 }
505 }
506 }
507 }
508 this.inputFieldValue = formattedValue;
509 this.updateFilledState();
510 if (this.inputfieldViewChild && this.inputfieldViewChild.nativeElement) {
511 this.inputfieldViewChild.nativeElement.value = this.inputFieldValue;
512 }
513 };
514 Calendar.prototype.formatDateTime = function (date) {
515 var formattedValue = null;
516 if (date) {
517 if (this.timeOnly) {
518 formattedValue = this.formatTime(date);
519 }
520 else {
521 formattedValue = this.formatDate(date, this.getDateFormat());
522 if (this.showTime) {
523 formattedValue += ' ' + this.formatTime(date);
524 }
525 }
526 }
527 return formattedValue;
528 };
529 Calendar.prototype.setCurrentHourPM = function (hours) {
530 if (this.hourFormat == '12') {
531 this.pm = hours > 11;
532 if (hours >= 12) {
533 this.currentHour = (hours == 12) ? 12 : hours - 12;
534 }
535 else {
536 this.currentHour = (hours == 0) ? 12 : hours;
537 }
538 }
539 else {
540 this.currentHour = hours;
541 }
542 };
543 Calendar.prototype.selectDate = function (dateMeta) {
544 var date = new Date(dateMeta.year, dateMeta.month, dateMeta.day);
545 if (this.showTime) {
546 if (this.hourFormat == '12') {
547 if (this.currentHour === 12)
548 date.setHours(this.pm ? 12 : 0);
549 else
550 date.setHours(this.pm ? this.currentHour + 12 : this.currentHour);
551 }
552 else {
553 date.setHours(this.currentHour);
554 }
555 date.setMinutes(this.currentMinute);
556 date.setSeconds(this.currentSecond);
557 }
558 if (this.minDate && this.minDate > date) {
559 date = this.minDate;
560 this.setCurrentHourPM(date.getHours());
561 this.currentMinute = date.getMinutes();
562 this.currentSecond = date.getSeconds();
563 }
564 if (this.maxDate && this.maxDate < date) {
565 date = this.maxDate;
566 this.setCurrentHourPM(date.getHours());
567 this.currentMinute = date.getMinutes();
568 this.currentSecond = date.getSeconds();
569 }
570 if (this.isSingleSelection()) {
571 this.updateModel(date);
572 }
573 else if (this.isMultipleSelection()) {
574 this.updateModel(this.value ? __spread(this.value, [date]) : [date]);
575 }
576 else if (this.isRangeSelection()) {
577 if (this.value && this.value.length) {
578 var startDate = this.value[0];
579 var endDate = this.value[1];
580 if (!endDate && date.getTime() >= startDate.getTime()) {
581 endDate = date;
582 }
583 else {
584 startDate = date;
585 endDate = null;
586 }
587 this.updateModel([startDate, endDate]);
588 }
589 else {
590 this.updateModel([date, null]);
591 }
592 }
593 this.onSelect.emit(date);
594 };
595 Calendar.prototype.updateModel = function (value) {
596 var _this = this;
597 this.value = value;
598 if (this.dataType == 'date') {
599 this.onModelChange(this.value);
600 }
601 else if (this.dataType == 'string') {
602 if (this.isSingleSelection()) {
603 this.onModelChange(this.formatDateTime(this.value));
604 }
605 else {
606 var stringArrValue = null;
607 if (this.value) {
608 stringArrValue = this.value.map(function (date) { return _this.formatDateTime(date); });
609 }
610 this.onModelChange(stringArrValue);
611 }
612 }
613 };
614 Calendar.prototype.getFirstDayOfMonthIndex = function (month, year) {
615 var day = new Date();
616 day.setDate(1);
617 day.setMonth(month);
618 day.setFullYear(year);
619 var dayIndex = day.getDay() + this.getSundayIndex();
620 return dayIndex >= 7 ? dayIndex - 7 : dayIndex;
621 };
622 Calendar.prototype.getDaysCountInMonth = function (month, year) {
623 return 32 - this.daylightSavingAdjust(new Date(year, month, 32)).getDate();
624 };
625 Calendar.prototype.getDaysCountInPrevMonth = function (month, year) {
626 var prev = this.getPreviousMonthAndYear(month, year);
627 return this.getDaysCountInMonth(prev.month, prev.year);
628 };
629 Calendar.prototype.getPreviousMonthAndYear = function (month, year) {
630 var m, y;
631 if (month === 0) {
632 m = 11;
633 y = year - 1;
634 }
635 else {
636 m = month - 1;
637 y = year;
638 }
639 return { 'month': m, 'year': y };
640 };
641 Calendar.prototype.getNextMonthAndYear = function (month, year) {
642 var m, y;
643 if (month === 11) {
644 m = 0;
645 y = year + 1;
646 }
647 else {
648 m = month + 1;
649 y = year;
650 }
651 return { 'month': m, 'year': y };
652 };
653 Calendar.prototype.getSundayIndex = function () {
654 return this.locale.firstDayOfWeek > 0 ? 7 - this.locale.firstDayOfWeek : 0;
655 };
656 Calendar.prototype.isSelected = function (dateMeta) {
657 var e_1, _a;
658 if (this.value) {
659 if (this.isSingleSelection()) {
660 return this.isDateEquals(this.value, dateMeta);
661 }
662 else if (this.isMultipleSelection()) {
663 var selected = false;
664 try {
665 for (var _b = __values(this.value), _c = _b.next(); !_c.done; _c = _b.next()) {
666 var date = _c.value;
667 selected = this.isDateEquals(date, dateMeta);
668 if (selected) {
669 break;
670 }
671 }
672 }
673 catch (e_1_1) { e_1 = { error: e_1_1 }; }
674 finally {
675 try {
676 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
677 }
678 finally { if (e_1) throw e_1.error; }
679 }
680 return selected;
681 }
682 else if (this.isRangeSelection()) {
683 if (this.value[1])
684 return this.isDateEquals(this.value[0], dateMeta) || this.isDateEquals(this.value[1], dateMeta) || this.isDateBetween(this.value[0], this.value[1], dateMeta);
685 else
686 return this.isDateEquals(this.value[0], dateMeta);
687 }
688 }
689 else {
690 return false;
691 }
692 };
693 Calendar.prototype.isMonthSelected = function (month) {
694 var day = this.value ? (Array.isArray(this.value) ? this.value[0].getDate() : this.value.getDate()) : 1;
695 return this.isSelected({ year: this.currentYear, month: month, day: day, selectable: true });
696 };
697 Calendar.prototype.isDateEquals = function (value, dateMeta) {
698 if (value)
699 return value.getDate() === dateMeta.day && value.getMonth() === dateMeta.month && value.getFullYear() === dateMeta.year;
700 else
701 return false;
702 };
703 Calendar.prototype.isDateBetween = function (start, end, dateMeta) {
704 var between = false;
705 if (start && end) {
706 var date = new Date(dateMeta.year, dateMeta.month, dateMeta.day);
707 return start.getTime() <= date.getTime() && end.getTime() >= date.getTime();
708 }
709 return between;
710 };
711 Calendar.prototype.isSingleSelection = function () {
712 return this.selectionMode === 'single';
713 };
714 Calendar.prototype.isRangeSelection = function () {
715 return this.selectionMode === 'range';
716 };
717 Calendar.prototype.isMultipleSelection = function () {
718 return this.selectionMode === 'multiple';
719 };
720 Calendar.prototype.isToday = function (today, day, month, year) {
721 return today.getDate() === day && today.getMonth() === month && today.getFullYear() === year;
722 };
723 Calendar.prototype.isSelectable = function (day, month, year, otherMonth) {
724 var validMin = true;
725 var validMax = true;
726 var validDate = true;
727 var validDay = true;
728 if (otherMonth && !this.selectOtherMonths) {
729 return false;
730 }
731 if (this.minDate) {
732 if (this.minDate.getFullYear() > year) {
733 validMin = false;
734 }
735 else if (this.minDate.getFullYear() === year) {
736 if (this.minDate.getMonth() > month) {
737 validMin = false;
738 }
739 else if (this.minDate.getMonth() === month) {
740 if (this.minDate.getDate() > day) {
741 validMin = false;
742 }
743 }
744 }
745 }
746 if (this.maxDate) {
747 if (this.maxDate.getFullYear() < year) {
748 validMax = false;
749 }
750 else if (this.maxDate.getFullYear() === year) {
751 if (this.maxDate.getMonth() < month) {
752 validMax = false;
753 }
754 else if (this.maxDate.getMonth() === month) {
755 if (this.maxDate.getDate() < day) {
756 validMax = false;
757 }
758 }
759 }
760 }
761 if (this.disabledDates) {
762 validDate = !this.isDateDisabled(day, month, year);
763 }
764 if (this.disabledDays) {
765 validDay = !this.isDayDisabled(day, month, year);
766 }
767 return validMin && validMax && validDate && validDay;
768 };
769 Calendar.prototype.isDateDisabled = function (day, month, year) {
770 var e_2, _a;
771 if (this.disabledDates) {
772 try {
773 for (var _b = __values(this.disabledDates), _c = _b.next(); !_c.done; _c = _b.next()) {
774 var disabledDate = _c.value;
775 if (disabledDate.getFullYear() === year && disabledDate.getMonth() === month && disabledDate.getDate() === day) {
776 return true;
777 }
778 }
779 }
780 catch (e_2_1) { e_2 = { error: e_2_1 }; }
781 finally {
782 try {
783 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
784 }
785 finally { if (e_2) throw e_2.error; }
786 }
787 }
788 return false;
789 };
790 Calendar.prototype.isDayDisabled = function (day, month, year) {
791 if (this.disabledDays) {
792 var weekday = new Date(year, month, day);
793 var weekdayNumber = weekday.getDay();
794 return this.disabledDays.indexOf(weekdayNumber) !== -1;
795 }
796 return false;
797 };
798 Calendar.prototype.onInputFocus = function (event) {
799 this.focus = true;
800 if (this.showOnFocus) {
801 this.showOverlay();
802 }
803 this.onFocus.emit(event);
804 };
805 Calendar.prototype.onInputClick = function () {
806 if (this.overlay && this.autoZIndex) {
807 this.overlay.style.zIndex = String(this.baseZIndex + (++dom.DomHandler.zindex));
808 }
809 if (this.showOnFocus && !this.overlayVisible) {
810 this.showOverlay();
811 }
812 };
813 Calendar.prototype.onInputBlur = function (event) {
814 this.focus = false;
815 this.onBlur.emit(event);
816 if (!this.keepInvalid) {
817 this.updateInputfield();
818 }
819 this.onModelTouched();
820 };
821 Calendar.prototype.onButtonClick = function (event, inputfield) {
822 if (!this.overlayVisible) {
823 inputfield.focus();
824 this.showOverlay();
825 }
826 else {
827 this.hideOverlay();
828 }
829 };
830 Calendar.prototype.onPrevButtonClick = function (event) {
831 this.navigationState = { backward: true, button: true };
832 this.navBackward(event);
833 };
834 Calendar.prototype.onNextButtonClick = function (event) {
835 this.navigationState = { backward: false, button: true };
836 this.navForward(event);
837 };
838 Calendar.prototype.onContainerButtonKeydown = function (event) {
839 switch (event.which) {
840 //tab
841 case 9:
842 if (!this.inline) {
843 this.trapFocus(event);
844 }
845 break;
846 //escape
847 case 27:
848 this.overlayVisible = false;
849 event.preventDefault();
850 break;
851 default:
852 //Noop
853 break;
854 }
855 };
856 Calendar.prototype.onInputKeydown = function (event) {
857 this.isKeydown = true;
858 if (event.keyCode === 9 && this.contentViewChild) {
859 this.trapFocus(event);
860 }
861 else if (event.keyCode === 27) {
862 if (this.overlayVisible) {
863 this.overlayVisible = false;
864 event.preventDefault();
865 }
866 }
867 };
868 Calendar.prototype.onDateCellKeydown = function (event, date, groupIndex) {
869 var cellContent = event.currentTarget;
870 var cell = cellContent.parentElement;
871 switch (event.which) {
872 //down arrow
873 case 40: {
874 cellContent.tabIndex = '-1';
875 var cellIndex = dom.DomHandler.index(cell);
876 var nextRow = cell.parentElement.nextElementSibling;
877 if (nextRow) {
878 var focusCell = nextRow.children[cellIndex].children[0];
879 if (dom.DomHandler.hasClass(focusCell, 'ui-state-disabled')) {
880 this.navigationState = { backward: false };
881 this.navForward(event);
882 }
883 else {
884 nextRow.children[cellIndex].children[0].tabIndex = '0';
885 nextRow.children[cellIndex].children[0].focus();
886 }
887 }
888 else {
889 this.navigationState = { backward: false };
890 this.navForward(event);
891 }
892 event.preventDefault();
893 break;
894 }
895 //up arrow
896 case 38: {
897 cellContent.tabIndex = '-1';
898 var cellIndex = dom.DomHandler.index(cell);
899 var prevRow = cell.parentElement.previousElementSibling;
900 if (prevRow) {
901 var focusCell = prevRow.children[cellIndex].children[0];
902 if (dom.DomHandler.hasClass(focusCell, 'ui-state-disabled')) {
903 this.navigationState = { backward: true };
904 this.navBackward(event);
905 }
906 else {
907 focusCell.tabIndex = '0';
908 focusCell.focus();
909 }
910 }
911 else {
912 this.navigationState = { backward: true };
913 this.navBackward(event);
914 }
915 event.preventDefault();
916 break;
917 }
918 //left arrow
919 case 37: {
920 cellContent.tabIndex = '-1';
921 var prevCell = cell.previousElementSibling;
922 if (prevCell) {
923 var focusCell = prevCell.children[0];
924 if (dom.DomHandler.hasClass(focusCell, 'ui-state-disabled') || dom.DomHandler.hasClass(focusCell.parentElement, 'ui-datepicker-weeknumber')) {
925 this.navigateToMonth(true, groupIndex);
926 }
927 else {
928 focusCell.tabIndex = '0';
929 focusCell.focus();
930 }
931 }
932 else {
933 this.navigateToMonth(true, groupIndex);
934 }
935 event.preventDefault();
936 break;
937 }
938 //right arrow
939 case 39: {
940 cellContent.tabIndex = '-1';
941 var nextCell = cell.nextElementSibling;
942 if (nextCell) {
943 var focusCell = nextCell.children[0];
944 if (dom.DomHandler.hasClass(focusCell, 'ui-state-disabled')) {
945 this.navigateToMonth(false, groupIndex);
946 }
947 else {
948 focusCell.tabIndex = '0';
949 focusCell.focus();
950 }
951 }
952 else {
953 this.navigateToMonth(false, groupIndex);
954 }
955 event.preventDefault();
956 break;
957 }
958 //enter
959 case 13: {
960 this.onDateSelect(event, date);
961 event.preventDefault();
962 break;
963 }
964 //escape
965 case 27: {
966 this.overlayVisible = false;
967 event.preventDefault();
968 break;
969 }
970 //tab
971 case 9: {
972 if (!this.inline) {
973 this.trapFocus(event);
974 }
975 break;
976 }
977 default:
978 //no op
979 break;
980 }
981 };
982 Calendar.prototype.onMonthCellKeydown = function (event, index) {
983 var cell = event.currentTarget;
984 switch (event.which) {
985 //arrows
986 case 38:
987 case 40: {
988 cell.tabIndex = '-1';
989 var cells = cell.parentElement.children;
990 var cellIndex = dom.DomHandler.index(cell);
991 var nextCell = cells[event.which === 40 ? cellIndex + 3 : cellIndex - 3];
992 if (nextCell) {
993 nextCell.tabIndex = '0';
994 nextCell.focus();
995 }
996 event.preventDefault();
997 break;
998 }
999 //left arrow
1000 case 37: {
1001 cell.tabIndex = '-1';
1002 var prevCell = cell.previousElementSibling;
1003 if (prevCell) {
1004 prevCell.tabIndex = '0';
1005 prevCell.focus();
1006 }
1007 event.preventDefault();
1008 break;
1009 }
1010 //right arrow
1011 case 39: {
1012 cell.tabIndex = '-1';
1013 var nextCell = cell.nextElementSibling;
1014 if (nextCell) {
1015 nextCell.tabIndex = '0';
1016 nextCell.focus();
1017 }
1018 event.preventDefault();
1019 break;
1020 }
1021 //enter
1022 case 13: {
1023 this.onMonthSelect(event, index);
1024 event.preventDefault();
1025 break;
1026 }
1027 //escape
1028 case 27: {
1029 this.overlayVisible = false;
1030 event.preventDefault();
1031 break;
1032 }
1033 //tab
1034 case 9: {
1035 if (!this.inline) {
1036 this.trapFocus(event);
1037 }
1038 break;
1039 }
1040 default:
1041 //no op
1042 break;
1043 }
1044 };
1045 Calendar.prototype.navigateToMonth = function (prev, groupIndex) {
1046 if (prev) {
1047 if (this.numberOfMonths === 1 || (groupIndex === 0)) {
1048 this.navigationState = { backward: true };
1049 this.navBackward(event);
1050 }
1051 else {
1052 var prevMonthContainer = this.contentViewChild.nativeElement.children[groupIndex - 1];
1053 var cells = dom.DomHandler.find(prevMonthContainer, '.ui-datepicker-calendar td a');
1054 var focusCell = cells[cells.length - 1];
1055 focusCell.tabIndex = '0';
1056 focusCell.focus();
1057 }
1058 }
1059 else {
1060 if (this.numberOfMonths === 1 || (groupIndex === this.numberOfMonths - 1)) {
1061 this.navigationState = { backward: false };
1062 this.navForward(event);
1063 }
1064 else {
1065 var nextMonthContainer = this.contentViewChild.nativeElement.children[groupIndex + 1];
1066 var focusCell = dom.DomHandler.findSingle(nextMonthContainer, '.ui-datepicker-calendar td a');
1067 focusCell.tabIndex = '0';
1068 focusCell.focus();
1069 }
1070 }
1071 };
1072 Calendar.prototype.updateFocus = function () {
1073 var cell;
1074 if (this.navigationState) {
1075 if (this.navigationState.button) {
1076 this.initFocusableCell();
1077 if (this.navigationState.backward)
1078 dom.DomHandler.findSingle(this.contentViewChild.nativeElement, '.ui-datepicker-prev').focus();
1079 else
1080 dom.DomHandler.findSingle(this.contentViewChild.nativeElement, '.ui-datepicker-next').focus();
1081 }
1082 else {
1083 if (this.navigationState.backward) {
1084 var cells = dom.DomHandler.find(this.contentViewChild.nativeElement, '.ui-datepicker-calendar td a');
1085 cell = cells[cells.length - 1];
1086 }
1087 else {
1088 cell = dom.DomHandler.findSingle(this.contentViewChild.nativeElement, '.ui-datepicker-calendar td a');
1089 }
1090 if (cell) {
1091 cell.tabIndex = '0';
1092 cell.focus();
1093 }
1094 }
1095 this.navigationState = null;
1096 }
1097 else {
1098 this.initFocusableCell();
1099 }
1100 };
1101 Calendar.prototype.initFocusableCell = function () {
1102 var cell;
1103 if (this.view === 'month') {
1104 var cells = dom.DomHandler.find(this.contentViewChild.nativeElement, '.ui-monthpicker .ui-monthpicker-month:not(.ui-state-disabled)');
1105 var selectedCell = dom.DomHandler.findSingle(this.contentViewChild.nativeElement, '.ui-monthpicker .ui-monthpicker-month.ui-state-highlight');
1106 cells.forEach(function (cell) { return cell.tabIndex = -1; });
1107 cell = selectedCell || cells[0];
1108 if (cells.length === 0) {
1109 var disabledCells = dom.DomHandler.find(this.contentViewChild.nativeElement, '.ui-monthpicker .ui-monthpicker-month.ui-state-disabled[tabindex = "0"]');
1110 disabledCells.forEach(function (cell) { return cell.tabIndex = -1; });
1111 }
1112 }
1113 else {
1114 cell = dom.DomHandler.findSingle(this.contentViewChild.nativeElement, 'a.ui-state-active');
1115 if (!cell) {
1116 var todayCell = dom.DomHandler.findSingle(this.contentViewChild.nativeElement, 'td.ui-datepicker-today a:not(.ui-state-disabled)');
1117 if (todayCell)
1118 cell = todayCell;
1119 else
1120 cell = dom.DomHandler.findSingle(this.contentViewChild.nativeElement, '.ui-datepicker-calendar td a');
1121 }
1122 }
1123 if (cell) {
1124 cell.tabIndex = '0';
1125 }
1126 };
1127 Calendar.prototype.trapFocus = function (event) {
1128 event.preventDefault();
1129 var focusableElements = dom.DomHandler.getFocusableElements(this.contentViewChild.nativeElement);
1130 if (focusableElements && focusableElements.length > 0) {
1131 if (!document.activeElement) {
1132 focusableElements[0].focus();
1133 }
1134 else {
1135 var focusedIndex = focusableElements.indexOf(document.activeElement);
1136 if (event.shiftKey) {
1137 if (focusedIndex == -1 || focusedIndex === 0)
1138 focusableElements[focusableElements.length - 1].focus();
1139 else
1140 focusableElements[focusedIndex - 1].focus();
1141 }
1142 else {
1143 if (focusedIndex == -1 || focusedIndex === (focusableElements.length - 1))
1144 focusableElements[0].focus();
1145 else
1146 focusableElements[focusedIndex + 1].focus();
1147 }
1148 }
1149 }
1150 };
1151 Calendar.prototype.onMonthDropdownChange = function (m) {
1152 this.currentMonth = parseInt(m);
1153 this.onMonthChange.emit({ month: this.currentMonth + 1, year: this.currentYear });
1154 this.createMonths(this.currentMonth, this.currentYear);
1155 };
1156 Calendar.prototype.onYearDropdownChange = function (y) {
1157 this.currentYear = parseInt(y);
1158 this.onYearChange.emit({ month: this.currentMonth + 1, year: this.currentYear });
1159 this.createMonths(this.currentMonth, this.currentYear);
1160 };
1161 Calendar.prototype.validateTime = function (hour, minute, second, pm) {
1162 var value = this.value;
1163 var convertedHour = this.convertTo24Hour(hour, pm);
1164 if (this.isRangeSelection()) {
1165 value = this.value[1] || this.value[0];
1166 }
1167 if (this.isMultipleSelection()) {
1168 value = this.value[this.value.length - 1];
1169 }
1170 var valueDateString = value ? value.toDateString() : null;
1171 if (this.minDate && valueDateString && this.minDate.toDateString() === valueDateString) {
1172 if (this.minDate.getHours() > convertedHour) {
1173 return false;
1174 }
1175 if (this.minDate.getHours() === convertedHour) {
1176 if (this.minDate.getMinutes() > minute) {
1177 return false;
1178 }
1179 if (this.minDate.getMinutes() === minute) {
1180 if (this.minDate.getSeconds() > second) {
1181 return false;
1182 }
1183 }
1184 }
1185 }
1186 if (this.maxDate && valueDateString && this.maxDate.toDateString() === valueDateString) {
1187 if (this.maxDate.getHours() < convertedHour) {
1188 return false;
1189 }
1190 if (this.maxDate.getHours() === convertedHour) {
1191 if (this.maxDate.getMinutes() < minute) {
1192 return false;
1193 }
1194 if (this.maxDate.getMinutes() === minute) {
1195 if (this.maxDate.getSeconds() < second) {
1196 return false;
1197 }
1198 }
1199 }
1200 }
1201 return true;
1202 };
1203 Calendar.prototype.incrementHour = function (event) {
1204 var prevHour = this.currentHour;
1205 var newHour = this.currentHour + this.stepHour;
1206 var newPM = this.pm;
1207 if (this.hourFormat == '24')
1208 newHour = (newHour >= 24) ? (newHour - 24) : newHour;
1209 else if (this.hourFormat == '12') {
1210 // Before the AM/PM break, now after
1211 if (prevHour < 12 && newHour > 11) {
1212 newPM = !this.pm;
1213 }
1214 newHour = (newHour >= 13) ? (newHour - 12) : newHour;
1215 }
1216 if (this.validateTime(newHour, this.currentMinute, this.currentSecond, newPM)) {
1217 this.currentHour = newHour;
1218 this.pm = newPM;
1219 }
1220 event.preventDefault();
1221 };
1222 Calendar.prototype.onTimePickerElementMouseDown = function (event, type, direction) {
1223 if (!this.disabled) {
1224 this.repeat(event, null, type, direction);
1225 event.preventDefault();
1226 }
1227 };
1228 Calendar.prototype.onTimePickerElementMouseUp = function (event) {
1229 if (!this.disabled) {
1230 this.clearTimePickerTimer();
1231 this.updateTime();
1232 }
1233 };
1234 Calendar.prototype.onTimePickerElementMouseOut = function (event) {
1235 if (!this.disabled && this.timePickerTimer) {
1236 this.clearTimePickerTimer();
1237 this.updateTime();
1238 }
1239 };
1240 Calendar.prototype.repeat = function (event, interval, type, direction) {
1241 var _this = this;
1242 var i = interval || 500;
1243 this.clearTimePickerTimer();
1244 this.timePickerTimer = setTimeout(function () {
1245 _this.repeat(event, 100, type, direction);
1246 }, i);
1247 switch (type) {
1248 case 0:
1249 if (direction === 1)
1250 this.incrementHour(event);
1251 else
1252 this.decrementHour(event);
1253 break;
1254 case 1:
1255 if (direction === 1)
1256 this.incrementMinute(event);
1257 else
1258 this.decrementMinute(event);
1259 break;
1260 case 2:
1261 if (direction === 1)
1262 this.incrementSecond(event);
1263 else
1264 this.decrementSecond(event);
1265 break;
1266 }
1267 this.updateInputfield();
1268 };
1269 Calendar.prototype.clearTimePickerTimer = function () {
1270 if (this.timePickerTimer) {
1271 clearTimeout(this.timePickerTimer);
1272 }
1273 };
1274 Calendar.prototype.decrementHour = function (event) {
1275 var newHour = this.currentHour - this.stepHour;
1276 var newPM = this.pm;
1277 if (this.hourFormat == '24')
1278 newHour = (newHour < 0) ? (24 + newHour) : newHour;
1279 else if (this.hourFormat == '12') {
1280 // If we were at noon/midnight, then switch
1281 if (this.currentHour === 12) {
1282 newPM = !this.pm;
1283 }
1284 newHour = (newHour <= 0) ? (12 + newHour) : newHour;
1285 }
1286 if (this.validateTime(newHour, this.currentMinute, this.currentSecond, newPM)) {
1287 this.currentHour = newHour;
1288 this.pm = newPM;
1289 }
1290 event.preventDefault();
1291 };
1292 Calendar.prototype.incrementMinute = function (event) {
1293 var newMinute = this.currentMinute + this.stepMinute;
1294 newMinute = (newMinute > 59) ? newMinute - 60 : newMinute;
1295 if (this.validateTime(this.currentHour, newMinute, this.currentSecond, this.pm)) {
1296 this.currentMinute = newMinute;
1297 }
1298 event.preventDefault();
1299 };
1300 Calendar.prototype.decrementMinute = function (event) {
1301 var newMinute = this.currentMinute - this.stepMinute;
1302 newMinute = (newMinute < 0) ? 60 + newMinute : newMinute;
1303 if (this.validateTime(this.currentHour, newMinute, this.currentSecond, this.pm)) {
1304 this.currentMinute = newMinute;
1305 }
1306 event.preventDefault();
1307 };
1308 Calendar.prototype.incrementSecond = function (event) {
1309 var newSecond = this.currentSecond + this.stepSecond;
1310 newSecond = (newSecond > 59) ? newSecond - 60 : newSecond;
1311 if (this.validateTime(this.currentHour, this.currentMinute, newSecond, this.pm)) {
1312 this.currentSecond = newSecond;
1313 }
1314 event.preventDefault();
1315 };
1316 Calendar.prototype.decrementSecond = function (event) {
1317 var newSecond = this.currentSecond - this.stepSecond;
1318 newSecond = (newSecond < 0) ? 60 + newSecond : newSecond;
1319 if (this.validateTime(this.currentHour, this.currentMinute, newSecond, this.pm)) {
1320 this.currentSecond = newSecond;
1321 }
1322 event.preventDefault();
1323 };
1324 Calendar.prototype.updateTime = function () {
1325 var value = this.value;
1326 if (this.isRangeSelection()) {
1327 value = this.value[1] || this.value[0];
1328 }
1329 if (this.isMultipleSelection()) {
1330 value = this.value[this.value.length - 1];
1331 }
1332 value = value ? new Date(value.getTime()) : new Date();
1333 if (this.hourFormat == '12') {
1334 if (this.currentHour === 12)
1335 value.setHours(this.pm ? 12 : 0);
1336 else
1337 value.setHours(this.pm ? this.currentHour + 12 : this.currentHour);
1338 }
1339 else {
1340 value.setHours(this.currentHour);
1341 }
1342 value.setMinutes(this.currentMinute);
1343 value.setSeconds(this.currentSecond);
1344 if (this.isRangeSelection()) {
1345 if (this.value[1])
1346 value = [this.value[0], value];
1347 else
1348 value = [value, null];
1349 }
1350 if (this.isMultipleSelection()) {
1351 value = __spread(this.value.slice(0, -1), [value]);
1352 }
1353 this.updateModel(value);
1354 this.onSelect.emit(value);
1355 this.updateInputfield();
1356 };
1357 Calendar.prototype.toggleAMPM = function (event) {
1358 var newPM = !this.pm;
1359 if (this.validateTime(this.currentHour, this.currentMinute, this.currentSecond, newPM)) {
1360 this.pm = newPM;
1361 this.updateTime();
1362 }
1363 event.preventDefault();
1364 };
1365 Calendar.prototype.onUserInput = function (event) {
1366 // IE 11 Workaround for input placeholder : https://github.com/primefaces/primeng/issues/2026
1367 if (!this.isKeydown) {
1368 return;
1369 }
1370 this.isKeydown = false;
1371 var val = event.target.value;
1372 try {
1373 var value = this.parseValueFromString(val);
1374 if (this.isValidSelection(value)) {
1375 this.updateModel(value);
1376 this.updateUI();
1377 }
1378 }
1379 catch (err) {
1380 //invalid date
1381 this.updateModel(null);
1382 }
1383 this.filled = val != null && val.length;
1384 this.onInput.emit(event);
1385 };
1386 Calendar.prototype.isValidSelection = function (value) {
1387 var _this = this;
1388 var isValid = true;
1389 if (this.isSingleSelection()) {
1390 if (!this.isSelectable(value.getDate(), value.getMonth(), value.getFullYear(), false)) {
1391 isValid = false;
1392 }
1393 }
1394 else if (value.every(function (v) { return _this.isSelectable(v.getDate(), v.getMonth(), v.getFullYear(), false); })) {
1395 if (this.isRangeSelection()) {
1396 isValid = value.length > 1 && value[1] > value[0] ? true : false;
1397 }
1398 }
1399 return isValid;
1400 };
1401 Calendar.prototype.parseValueFromString = function (text) {
1402 var e_3, _a;
1403 if (!text || text.trim().length === 0) {
1404 return null;
1405 }
1406 var value;
1407 if (this.isSingleSelection()) {
1408 value = this.parseDateTime(text);
1409 }
1410 else if (this.isMultipleSelection()) {
1411 var tokens = text.split(this.multipleSeparator);
1412 value = [];
1413 try {
1414 for (var tokens_1 = __values(tokens), tokens_1_1 = tokens_1.next(); !tokens_1_1.done; tokens_1_1 = tokens_1.next()) {
1415 var token = tokens_1_1.value;
1416 value.push(this.parseDateTime(token.trim()));
1417 }
1418 }
1419 catch (e_3_1) { e_3 = { error: e_3_1 }; }
1420 finally {
1421 try {
1422 if (tokens_1_1 && !tokens_1_1.done && (_a = tokens_1.return)) _a.call(tokens_1);
1423 }
1424 finally { if (e_3) throw e_3.error; }
1425 }
1426 }
1427 else if (this.isRangeSelection()) {
1428 var tokens = text.split(' ' + this.rangeSeparator + ' ');
1429 value = [];
1430 for (var i = 0; i < tokens.length; i++) {
1431 value[i] = this.parseDateTime(tokens[i].trim());
1432 }
1433 }
1434 return value;
1435 };
1436 Calendar.prototype.parseDateTime = function (text) {
1437 var date;
1438 var parts = text.split(' ');
1439 if (this.timeOnly) {
1440 date = new Date();
1441 this.populateTime(date, parts[0], parts[1]);
1442 }
1443 else {
1444 var dateFormat = this.getDateFormat();
1445 if (this.showTime) {
1446 var ampm = this.hourFormat == '12' ? parts.pop() : null;
1447 var timeString = parts.pop();
1448 date = this.parseDate(parts.join(' '), dateFormat);
1449 this.populateTime(date, timeString, ampm);
1450 }
1451 else {
1452 date = this.parseDate(text, dateFormat);
1453 }
1454 }
1455 return date;
1456 };
1457 Calendar.prototype.populateTime = function (value, timeString, ampm) {
1458 if (this.hourFormat == '12' && !ampm) {
1459 throw 'Invalid Time';
1460 }
1461 this.pm = (ampm === 'PM' || ampm === 'pm');
1462 var time = this.parseTime(timeString);
1463 value.setHours(time.hour);
1464 value.setMinutes(time.minute);
1465 value.setSeconds(time.second);
1466 };
1467 Calendar.prototype.updateUI = function () {
1468 var val = this.value || this.defaultDate || new Date();
1469 if (Array.isArray(val)) {
1470 val = val[0];
1471 }
1472 this.currentMonth = val.getMonth();
1473 this.currentYear = val.getFullYear();
1474 this.createMonths(this.currentMonth, this.currentYear);
1475 if (this.showTime || this.timeOnly) {
1476 this.setCurrentHourPM(val.getHours());
1477 this.currentMinute = val.getMinutes();
1478 this.currentSecond = val.getSeconds();
1479 }
1480 };
1481 Calendar.prototype.showOverlay = function () {
1482 if (!this.overlayVisible) {
1483 this.updateUI();
1484 this.overlayVisible = true;
1485 }
1486 };
1487 Calendar.prototype.hideOverlay = function () {
1488 this.overlayVisible = false;
1489 this.clearTimePickerTimer();
1490 if (this.touchUI) {
1491 this.disableModality();
1492 }
1493 };
1494 Calendar.prototype.toggle = function () {
1495 if (!this.inline) {
1496 if (!this.overlayVisible) {
1497 this.showOverlay();
1498 this.inputfieldViewChild.nativeElement.focus();
1499 }
1500 else {
1501 this.hideOverlay();
1502 }
1503 }
1504 };
1505 Calendar.prototype.onOverlayAnimationStart = function (event) {
1506 switch (event.toState) {
1507 case 'visible':
1508 case 'visibleTouchUI':
1509 if (!this.inline) {
1510 this.overlay = event.element;
1511 this.appendOverlay();
1512 if (this.autoZIndex) {
1513 this.overlay.style.zIndex = String(this.baseZIndex + (++dom.DomHandler.zindex));
1514 }
1515 this.alignOverlay();
1516 this.onShow.emit(event);
1517 }
1518 break;
1519 case 'void':
1520 this.onOverlayHide();
1521 this.onClose.emit(event);
1522 break;
1523 }
1524 };
1525 Calendar.prototype.onOverlayAnimationDone = function (event) {
1526 switch (event.toState) {
1527 case 'visible':
1528 case 'visibleTouchUI':
1529 if (!this.inline) {
1530 this.bindDocumentClickListener();
1531 this.bindDocumentResizeListener();
1532 }
1533 break;
1534 }
1535 };
1536 Calendar.prototype.appendOverlay = function () {
1537 if (this.appendTo) {
1538 if (this.appendTo === 'body')
1539 document.body.appendChild(this.overlay);
1540 else
1541 dom.DomHandler.appendChild(this.overlay, this.appendTo);
1542 }
1543 };
1544 Calendar.prototype.restoreOverlayAppend = function () {
1545 if (this.overlay && this.appendTo) {
1546 this.el.nativeElement.appendChild(this.overlay);
1547 }
1548 };
1549 Calendar.prototype.alignOverlay = function () {
1550 if (this.touchUI) {
1551 this.enableModality(this.overlay);
1552 }
1553 else {
1554 if (this.appendTo)
1555 dom.DomHandler.absolutePosition(this.overlay, this.inputfieldViewChild.nativeElement);
1556 else
1557 dom.DomHandler.relativePosition(this.overlay, this.inputfieldViewChild.nativeElement);
1558 }
1559 };
1560 Calendar.prototype.enableModality = function (element) {
1561 var _this = this;
1562 if (!this.mask) {
1563 this.mask = document.createElement('div');
1564 this.mask.style.zIndex = String(parseInt(element.style.zIndex) - 1);
1565 var maskStyleClass = 'ui-widget-overlay ui-datepicker-mask ui-datepicker-mask-scrollblocker';
1566 dom.DomHandler.addMultipleClasses(this.mask, maskStyleClass);
1567 this.maskClickListener = this.renderer.listen(this.mask, 'click', function (event) {
1568 _this.disableModality();
1569 });
1570 document.body.appendChild(this.mask);
1571 dom.DomHandler.addClass(document.body, 'ui-overflow-hidden');
1572 }
1573 };
1574 Calendar.prototype.disableModality = function () {
1575 if (this.mask) {
1576 document.body.removeChild(this.mask);
1577 var bodyChildren = document.body.children;
1578 var hasBlockerMasks = void 0;
1579 for (var i = 0; i < bodyChildren.length; i++) {
1580 var bodyChild = bodyChildren[i];
1581 if (dom.DomHandler.hasClass(bodyChild, 'ui-datepicker-mask-scrollblocker')) {
1582 hasBlockerMasks = true;
1583 break;
1584 }
1585 }
1586 if (!hasBlockerMasks) {
1587 dom.DomHandler.removeClass(document.body, 'ui-overflow-hidden');
1588 }
1589 this.unbindMaskClickListener();
1590 this.mask = null;
1591 }
1592 };
1593 Calendar.prototype.unbindMaskClickListener = function () {
1594 if (this.maskClickListener) {
1595 this.maskClickListener();
1596 this.maskClickListener = null;
1597 }
1598 };
1599 Calendar.prototype.writeValue = function (value) {
1600 this.value = value;
1601 if (this.value && typeof this.value === 'string') {
1602 this.value = this.parseValueFromString(this.value);
1603 }
1604 this.updateInputfield();
1605 this.updateUI();
1606 };
1607 Calendar.prototype.registerOnChange = function (fn) {
1608 this.onModelChange = fn;
1609 };
1610 Calendar.prototype.registerOnTouched = function (fn) {
1611 this.onModelTouched = fn;
1612 };
1613 Calendar.prototype.setDisabledState = function (val) {
1614 this.disabled = val;
1615 };
1616 Calendar.prototype.getDateFormat = function () {
1617 return this.dateFormat || this.locale.dateFormat;
1618 };
1619 // Ported from jquery-ui datepicker formatDate
1620 Calendar.prototype.formatDate = function (date, format) {
1621 if (!date) {
1622 return '';
1623 }
1624 var iFormat;
1625 var lookAhead = function (match) {
1626 var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
1627 if (matches) {
1628 iFormat++;
1629 }
1630 return matches;
1631 }, formatNumber = function (match, value, len) {
1632 var num = '' + value;
1633 if (lookAhead(match)) {
1634 while (num.length < len) {
1635 num = '0' + num;
1636 }
1637 }
1638 return num;
1639 }, formatName = function (match, value, shortNames, longNames) {
1640 return (lookAhead(match) ? longNames[value] : shortNames[value]);
1641 };
1642 var output = '';
1643 var literal = false;
1644 if (date) {
1645 for (iFormat = 0; iFormat < format.length; iFormat++) {
1646 if (literal) {
1647 if (format.charAt(iFormat) === '\'' && !lookAhead('\'')) {
1648 literal = false;
1649 }
1650 else {
1651 output += format.charAt(iFormat);
1652 }
1653 }
1654 else {
1655 switch (format.charAt(iFormat)) {
1656 case 'd':
1657 output += formatNumber('d', date.getDate(), 2);
1658 break;
1659 case 'D':
1660 output += formatName('D', date.getDay(), this.locale.dayNamesShort, this.locale.dayNames);
1661 break;
1662 case 'o':
1663 output += formatNumber('o', Math.round((new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime() -
1664 new Date(date.getFullYear(), 0, 0).getTime()) / 86400000), 3);
1665 break;
1666 case 'm':
1667 output += formatNumber('m', date.getMonth() + 1, 2);
1668 break;
1669 case 'M':
1670 output += formatName('M', date.getMonth(), this.locale.monthNamesShort, this.locale.monthNames);
1671 break;
1672 case 'y':
1673 output += lookAhead('y') ? date.getFullYear() : (date.getFullYear() % 100 < 10 ? '0' : '') + (date.getFullYear() % 100);
1674 break;
1675 case '@':
1676 output += date.getTime();
1677 break;
1678 case '!':
1679 output += date.getTime() * 10000 + this.ticksTo1970;
1680 break;
1681 case '\'':
1682 if (lookAhead('\'')) {
1683 output += '\'';
1684 }
1685 else {
1686 literal = true;
1687 }
1688 break;
1689 default:
1690 output += format.charAt(iFormat);
1691 }
1692 }
1693 }
1694 }
1695 return output;
1696 };
1697 Calendar.prototype.formatTime = function (date) {
1698 if (!date) {
1699 return '';
1700 }
1701 var output = '';
1702 var hours = date.getHours();
1703 var minutes = date.getMinutes();
1704 var seconds = date.getSeconds();
1705 if (this.hourFormat == '12' && hours > 11 && hours != 12) {
1706 hours -= 12;
1707 }
1708 if (this.hourFormat == '12') {
1709 output += hours === 0 ? 12 : (hours < 10) ? '0' + hours : hours;
1710 }
1711 else {
1712 output += (hours < 10) ? '0' + hours : hours;
1713 }
1714 output += ':';
1715 output += (minutes < 10) ? '0' + minutes : minutes;
1716 if (this.showSeconds) {
1717 output += ':';
1718 output += (seconds < 10) ? '0' + seconds : seconds;
1719 }
1720 if (this.hourFormat == '12') {
1721 output += date.getHours() > 11 ? ' PM' : ' AM';
1722 }
1723 return output;
1724 };
1725 Calendar.prototype.parseTime = function (value) {
1726 var tokens = value.split(':');
1727 var validTokenLength = this.showSeconds ? 3 : 2;
1728 if (tokens.length !== validTokenLength) {
1729 throw "Invalid time";
1730 }
1731 var h = parseInt(tokens[0]);
1732 var m = parseInt(tokens[1]);
1733 var s = this.showSeconds ? parseInt(tokens[2]) : null;
1734 if (isNaN(h) || isNaN(m) || h > 23 || m > 59 || (this.hourFormat == '12' && h > 12) || (this.showSeconds && (isNaN(s) || s > 59))) {
1735 throw "Invalid time";
1736 }
1737 else {
1738 if (this.hourFormat == '12') {
1739 if (h !== 12 && this.pm) {
1740 h += 12;
1741 }
1742 else if (!this.pm && h === 12) {
1743 h -= 12;
1744 }
1745 }
1746 return { hour: h, minute: m, second: s };
1747 }
1748 };
1749 // Ported from jquery-ui datepicker parseDate
1750 Calendar.prototype.parseDate = function (value, format) {
1751 if (format == null || value == null) {
1752 throw "Invalid arguments";
1753 }
1754 value = (typeof value === "object" ? value.toString() : value + "");
1755 if (value === "") {
1756 return null;
1757 }
1758 var iFormat, dim, extra, iValue = 0, shortYearCutoff = (typeof this.shortYearCutoff !== "string" ? this.shortYearCutoff : new Date().getFullYear() % 100 + parseInt(this.shortYearCutoff, 10)), year = -1, month = -1, day = -1, doy = -1, literal = false, date, lookAhead = function (match) {
1759 var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) === match);
1760 if (matches) {
1761 iFormat++;
1762 }
1763 return matches;
1764 }, getNumber = function (match) {
1765 var isDoubled = lookAhead(match), size = (match === "@" ? 14 : (match === "!" ? 20 :
1766 (match === "y" && isDoubled ? 4 : (match === "o" ? 3 : 2)))), minSize = (match === "y" ? size : 1), digits = new RegExp("^\\d{" + minSize + "," + size + "}"), num = value.substring(iValue).match(digits);
1767 if (!num) {
1768 throw "Missing number at position " + iValue;
1769 }
1770 iValue += num[0].length;
1771 return parseInt(num[0], 10);
1772 }, getName = function (match, shortNames, longNames) {
1773 var index = -1;
1774 var arr = lookAhead(match) ? longNames : shortNames;
1775 var names = [];
1776 for (var i = 0; i < arr.length; i++) {
1777 names.push([i, arr[i]]);
1778 }
1779 names.sort(function (a, b) {
1780 return -(a[1].length - b[1].length);
1781 });
1782 for (var i = 0; i < names.length; i++) {
1783 var name_1 = names[i][1];
1784 if (value.substr(iValue, name_1.length).toLowerCase() === name_1.toLowerCase()) {
1785 index = names[i][0];
1786 iValue += name_1.length;
1787 break;
1788 }
1789 }
1790 if (index !== -1) {
1791 return index + 1;
1792 }
1793 else {
1794 throw "Unknown name at position " + iValue;
1795 }
1796 }, checkLiteral = function () {
1797 if (value.charAt(iValue) !== format.charAt(iFormat)) {
1798 throw "Unexpected literal at position " + iValue;
1799 }
1800 iValue++;
1801 };
1802 if (this.view === 'month') {
1803 day = 1;
1804 }
1805 for (iFormat = 0; iFormat < format.length; iFormat++) {
1806 if (literal) {
1807 if (format.charAt(iFormat) === "'" && !lookAhead("'")) {
1808 literal = false;
1809 }
1810 else {
1811 checkLiteral();
1812 }
1813 }
1814 else {
1815 switch (format.charAt(iFormat)) {
1816 case "d":
1817 day = getNumber("d");
1818 break;
1819 case "D":
1820 getName("D", this.locale.dayNamesShort, this.locale.dayNames);
1821 break;
1822 case "o":
1823 doy = getNumber("o");
1824 break;
1825 case "m":
1826 month = getNumber("m");
1827 break;
1828 case "M":
1829 month = getName("M", this.locale.monthNamesShort, this.locale.monthNames);
1830 break;
1831 case "y":
1832 year = getNumber("y");
1833 break;
1834 case "@":
1835 date = new Date(getNumber("@"));
1836 year = date.getFullYear();
1837 month = date.getMonth() + 1;
1838 day = date.getDate();
1839 break;
1840 case "!":
1841 date = new Date((getNumber("!") - this.ticksTo1970) / 10000);
1842 year = date.getFullYear();
1843 month = date.getMonth() + 1;
1844 day = date.getDate();
1845 break;
1846 case "'":
1847 if (lookAhead("'")) {
1848 checkLiteral();
1849 }
1850 else {
1851 literal = true;
1852 }
1853 break;
1854 default:
1855 checkLiteral();
1856 }
1857 }
1858 }
1859 if (iValue < value.length) {
1860 extra = value.substr(iValue);
1861 if (!/^\s+/.test(extra)) {
1862 throw "Extra/unparsed characters found in date: " + extra;
1863 }
1864 }
1865 if (year === -1) {
1866 year = new Date().getFullYear();
1867 }
1868 else if (year < 100) {
1869 year += new Date().getFullYear() - new Date().getFullYear() % 100 +
1870 (year <= shortYearCutoff ? 0 : -100);
1871 }
1872 if (doy > -1) {
1873 month = 1;
1874 day = doy;
1875 do {
1876 dim = this.getDaysCountInMonth(year, month - 1);
1877 if (day <= dim) {
1878 break;
1879 }
1880 month++;
1881 day -= dim;
1882 } while (true);
1883 }
1884 date = this.daylightSavingAdjust(new Date(year, month - 1, day));
1885 if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
1886 throw "Invalid date"; // E.g. 31/02/00
1887 }
1888 return date;
1889 };
1890 Calendar.prototype.daylightSavingAdjust = function (date) {
1891 if (!date) {
1892 return null;
1893 }
1894 date.setHours(date.getHours() > 12 ? date.getHours() + 2 : 0);
1895 return date;
1896 };
1897 Calendar.prototype.updateFilledState = function () {
1898 this.filled = this.inputFieldValue && this.inputFieldValue != '';
1899 };
1900 Calendar.prototype.onTodayButtonClick = function (event) {
1901 var date = new Date();
1902 var dateMeta = { day: date.getDate(), month: date.getMonth(), year: date.getFullYear(), otherMonth: date.getMonth() !== this.currentMonth || date.getFullYear() !== this.currentYear, today: true, selectable: true };
1903 this.onDateSelect(event, dateMeta);
1904 this.onTodayClick.emit(event);
1905 };
1906 Calendar.prototype.onClearButtonClick = function (event) {
1907 this.updateModel(null);
1908 this.updateInputfield();
1909 this.hideOverlay();
1910 this.onClearClick.emit(event);
1911 };
1912 Calendar.prototype.bindDocumentClickListener = function () {
1913 var _this = this;
1914 if (!this.documentClickListener) {
1915 this.zone.runOutsideAngular(function () {
1916 _this.documentClickListener = _this.renderer.listen('document', 'click', function (event) {
1917 if (_this.isOutsideClicked(event) && _this.overlayVisible) {
1918 _this.zone.run(function () {
1919 _this.hideOverlay();
1920 _this.onClickOutside.emit(event);
1921 _this.cd.markForCheck();
1922 });
1923 }
1924 });
1925 });
1926 }
1927 };
1928 Calendar.prototype.unbindDocumentClickListener = function () {
1929 if (this.documentClickListener) {
1930 this.documentClickListener();
1931 this.documentClickListener = null;
1932 }
1933 };
1934 Calendar.prototype.bindDocumentResizeListener = function () {
1935 if (!this.documentResizeListener && !this.touchUI) {
1936 this.documentResizeListener = this.onWindowResize.bind(this);
1937 window.addEventListener('resize', this.documentResizeListener);
1938 }
1939 };
1940 Calendar.prototype.unbindDocumentResizeListener = function () {
1941 if (this.documentResizeListener) {
1942 window.removeEventListener('resize', this.documentResizeListener);
1943 this.documentResizeListener = null;
1944 }
1945 };
1946 Calendar.prototype.isOutsideClicked = function (event) {
1947 return !(this.el.nativeElement.isSameNode(event.target) || this.isNavIconClicked(event) ||
1948 this.el.nativeElement.contains(event.target) || (this.overlay && this.overlay.contains(event.target)));
1949 };
1950 Calendar.prototype.isNavIconClicked = function (event) {
1951 return (dom.DomHandler.hasClass(event.target, 'ui-datepicker-prev') || dom.DomHandler.hasClass(event.target, 'ui-datepicker-prev-icon')
1952 || dom.DomHandler.hasClass(event.target, 'ui-datepicker-next') || dom.DomHandler.hasClass(event.target, 'ui-datepicker-next-icon'));
1953 };
1954 Calendar.prototype.onWindowResize = function () {
1955 if (this.overlayVisible && !dom.DomHandler.isAndroid()) {
1956 this.hideOverlay();
1957 }
1958 };
1959 Calendar.prototype.onOverlayHide = function () {
1960 this.unbindDocumentClickListener();
1961 this.unbindMaskClickListener();
1962 this.unbindDocumentResizeListener();
1963 this.overlay = null;
1964 this.disableModality();
1965 };
1966 Calendar.prototype.ngOnDestroy = function () {
1967 this.clearTimePickerTimer();
1968 this.restoreOverlayAppend();
1969 this.onOverlayHide();
1970 };
1971 Calendar.ctorParameters = function () { return [
1972 { type: core.ElementRef },
1973 { type: core.Renderer2 },
1974 { type: core.ChangeDetectorRef },
1975 { type: core.NgZone }
1976 ]; };
1977 __decorate([
1978 core.Input()
1979 ], Calendar.prototype, "defaultDate", void 0);
1980 __decorate([
1981 core.Input()
1982 ], Calendar.prototype, "style", void 0);
1983 __decorate([
1984 core.Input()
1985 ], Calendar.prototype, "styleClass", void 0);
1986 __decorate([
1987 core.Input()
1988 ], Calendar.prototype, "inputStyle", void 0);
1989 __decorate([
1990 core.Input()
1991 ], Calendar.prototype, "inputId", void 0);
1992 __decorate([
1993 core.Input()
1994 ], Calendar.prototype, "name", void 0);
1995 __decorate([
1996 core.Input()
1997 ], Calendar.prototype, "inputStyleClass", void 0);
1998 __decorate([
1999 core.Input()
2000 ], Calendar.prototype, "placeholder", void 0);
2001 __decorate([
2002 core.Input()
2003 ], Calendar.prototype, "ariaLabelledBy", void 0);
2004 __decorate([
2005 core.Input()
2006 ], Calendar.prototype, "disabled", void 0);
2007 __decorate([
2008 core.Input()
2009 ], Calendar.prototype, "dateFormat", void 0);
2010 __decorate([
2011 core.Input()
2012 ], Calendar.prototype, "multipleSeparator", void 0);
2013 __decorate([
2014 core.Input()
2015 ], Calendar.prototype, "rangeSeparator", void 0);
2016 __decorate([
2017 core.Input()
2018 ], Calendar.prototype, "inline", void 0);
2019 __decorate([
2020 core.Input()
2021 ], Calendar.prototype, "showOtherMonths", void 0);
2022 __decorate([
2023 core.Input()
2024 ], Calendar.prototype, "selectOtherMonths", void 0);
2025 __decorate([
2026 core.Input()
2027 ], Calendar.prototype, "showIcon", void 0);
2028 __decorate([
2029 core.Input()
2030 ], Calendar.prototype, "icon", void 0);
2031 __decorate([
2032 core.Input()
2033 ], Calendar.prototype, "appendTo", void 0);
2034 __decorate([
2035 core.Input()
2036 ], Calendar.prototype, "readonlyInput", void 0);
2037 __decorate([
2038 core.Input()
2039 ], Calendar.prototype, "shortYearCutoff", void 0);
2040 __decorate([
2041 core.Input()
2042 ], Calendar.prototype, "monthNavigator", void 0);
2043 __decorate([
2044 core.Input()
2045 ], Calendar.prototype, "yearNavigator", void 0);
2046 __decorate([
2047 core.Input()
2048 ], Calendar.prototype, "hourFormat", void 0);
2049 __decorate([
2050 core.Input()
2051 ], Calendar.prototype, "timeOnly", void 0);
2052 __decorate([
2053 core.Input()
2054 ], Calendar.prototype, "stepHour", void 0);
2055 __decorate([
2056 core.Input()
2057 ], Calendar.prototype, "stepMinute", void 0);
2058 __decorate([
2059 core.Input()
2060 ], Calendar.prototype, "stepSecond", void 0);
2061 __decorate([
2062 core.Input()
2063 ], Calendar.prototype, "showSeconds", void 0);
2064 __decorate([
2065 core.Input()
2066 ], Calendar.prototype, "required", void 0);
2067 __decorate([
2068 core.Input()
2069 ], Calendar.prototype, "showOnFocus", void 0);
2070 __decorate([
2071 core.Input()
2072 ], Calendar.prototype, "showWeek", void 0);
2073 __decorate([
2074 core.Input()
2075 ], Calendar.prototype, "dataType", void 0);
2076 __decorate([
2077 core.Input()
2078 ], Calendar.prototype, "selectionMode", void 0);
2079 __decorate([
2080 core.Input()
2081 ], Calendar.prototype, "maxDateCount", void 0);
2082 __decorate([
2083 core.Input()
2084 ], Calendar.prototype, "showButtonBar", void 0);
2085 __decorate([
2086 core.Input()
2087 ], Calendar.prototype, "todayButtonStyleClass", void 0);
2088 __decorate([
2089 core.Input()
2090 ], Calendar.prototype, "clearButtonStyleClass", void 0);
2091 __decorate([
2092 core.Input()
2093 ], Calendar.prototype, "autoZIndex", void 0);
2094 __decorate([
2095 core.Input()
2096 ], Calendar.prototype, "baseZIndex", void 0);
2097 __decorate([
2098 core.Input()
2099 ], Calendar.prototype, "panelStyleClass", void 0);
2100 __decorate([
2101 core.Input()
2102 ], Calendar.prototype, "panelStyle", void 0);
2103 __decorate([
2104 core.Input()
2105 ], Calendar.prototype, "keepInvalid", void 0);
2106 __decorate([
2107 core.Input()
2108 ], Calendar.prototype, "hideOnDateTimeSelect", void 0);
2109 __decorate([
2110 core.Input()
2111 ], Calendar.prototype, "numberOfMonths", void 0);
2112 __decorate([
2113 core.Input()
2114 ], Calendar.prototype, "view", void 0);
2115 __decorate([
2116 core.Input()
2117 ], Calendar.prototype, "touchUI", void 0);
2118 __decorate([
2119 core.Input()
2120 ], Calendar.prototype, "timeSeparator", void 0);
2121 __decorate([
2122 core.Input()
2123 ], Calendar.prototype, "showTransitionOptions", void 0);
2124 __decorate([
2125 core.Input()
2126 ], Calendar.prototype, "hideTransitionOptions", void 0);
2127 __decorate([
2128 core.Output()
2129 ], Calendar.prototype, "onFocus", void 0);
2130 __decorate([
2131 core.Output()
2132 ], Calendar.prototype, "onBlur", void 0);
2133 __decorate([
2134 core.Output()
2135 ], Calendar.prototype, "onClose", void 0);
2136 __decorate([
2137 core.Output()
2138 ], Calendar.prototype, "onSelect", void 0);
2139 __decorate([
2140 core.Output()
2141 ], Calendar.prototype, "onInput", void 0);
2142 __decorate([
2143 core.Output()
2144 ], Calendar.prototype, "onTodayClick", void 0);
2145 __decorate([
2146 core.Output()
2147 ], Calendar.prototype, "onClearClick", void 0);
2148 __decorate([
2149 core.Output()
2150 ], Calendar.prototype, "onMonthChange", void 0);
2151 __decorate([
2152 core.Output()
2153 ], Calendar.prototype, "onYearChange", void 0);
2154 __decorate([
2155 core.Output()
2156 ], Calendar.prototype, "onClickOutside", void 0);
2157 __decorate([
2158 core.Output()
2159 ], Calendar.prototype, "onShow", void 0);
2160 __decorate([
2161 core.ContentChildren(api.PrimeTemplate)
2162 ], Calendar.prototype, "templates", void 0);
2163 __decorate([
2164 core.Input()
2165 ], Calendar.prototype, "tabindex", void 0);
2166 __decorate([
2167 core.ViewChild('inputfield', { static: false })
2168 ], Calendar.prototype, "inputfieldViewChild", void 0);
2169 __decorate([
2170 core.ViewChild('contentWrapper', { static: false })
2171 ], Calendar.prototype, "content", null);
2172 __decorate([
2173 core.Input()
2174 ], Calendar.prototype, "minDate", null);
2175 __decorate([
2176 core.Input()
2177 ], Calendar.prototype, "maxDate", null);
2178 __decorate([
2179 core.Input()
2180 ], Calendar.prototype, "disabledDates", null);
2181 __decorate([
2182 core.Input()
2183 ], Calendar.prototype, "disabledDays", null);
2184 __decorate([
2185 core.Input()
2186 ], Calendar.prototype, "yearRange", null);
2187 __decorate([
2188 core.Input()
2189 ], Calendar.prototype, "showTime", null);
2190 __decorate([
2191 core.Input()
2192 ], Calendar.prototype, "locale", null);
2193 Calendar = __decorate([
2194 core.Component({
2195 selector: 'p-calendar',
2196 template: "\n <span [ngClass]=\"{'ui-calendar':true, 'ui-calendar-w-btn': showIcon, 'ui-calendar-timeonly': timeOnly}\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <ng-template [ngIf]=\"!inline\">\n <input #inputfield type=\"text\" [attr.id]=\"inputId\" [attr.name]=\"name\" [attr.required]=\"required\" [attr.aria-required]=\"required\" [value]=\"inputFieldValue\" (focus)=\"onInputFocus($event)\" (keydown)=\"onInputKeydown($event)\" (click)=\"onInputClick()\" (blur)=\"onInputBlur($event)\"\n [readonly]=\"readonlyInput\" (input)=\"onUserInput($event)\" [ngStyle]=\"inputStyle\" [class]=\"inputStyleClass\" [placeholder]=\"placeholder||''\" [disabled]=\"disabled\" [attr.tabindex]=\"tabindex\"\n [ngClass]=\"'ui-inputtext ui-widget ui-state-default ui-corner-all'\" autocomplete=\"off\" [attr.aria-labelledby]=\"ariaLabelledBy\"\n ><button type=\"button\" [icon]=\"icon\" pButton *ngIf=\"showIcon\" (click)=\"onButtonClick($event,inputfield)\" class=\"ui-datepicker-trigger ui-calendar-button\"\n [ngClass]=\"{'ui-state-disabled':disabled}\" [disabled]=\"disabled\" tabindex=\"0\"></button>\n </ng-template>\n <div #contentWrapper [class]=\"panelStyleClass\" [ngStyle]=\"panelStyle\" [ngClass]=\"{'ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all': true, 'ui-datepicker-inline':inline,'ui-shadow':!inline,\n 'ui-state-disabled':disabled,'ui-datepicker-timeonly':timeOnly,'ui-datepicker-multiple-month': this.numberOfMonths > 1, 'ui-datepicker-monthpicker': (view === 'month'), 'ui-datepicker-touch-ui': touchUI}\"\n [@overlayAnimation]=\"touchUI ? {value: 'visibleTouchUI', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}: \n {value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\" \n [@.disabled]=\"inline === true\" (@overlayAnimation.start)=\"onOverlayAnimationStart($event)\" (@overlayAnimation.done)=\"onOverlayAnimationDone($event)\" *ngIf=\"inline || overlayVisible\">\n <ng-content select=\"p-header\"></ng-content>\n <ng-container *ngIf=\"!timeOnly\">\n <div class=\"ui-datepicker-group ui-widget-content\" *ngFor=\"let month of months; let i = index;\">\n <div class=\"ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all\">\n <a class=\"ui-datepicker-prev ui-corner-all\" (click)=\"onPrevButtonClick($event)\" (keydown.enter)=\"onPrevButtonClick($event)\" *ngIf=\"i === 0\" tabindex=\"0\" (keydown)=\"onInputKeydown($event)\">\n <span class=\"ui-datepicker-prev-icon pi pi-chevron-left\"></span>\n </a>\n <div class=\"ui-datepicker-title\">\n <span class=\"ui-datepicker-month\" *ngIf=\"!monthNavigator && (view !== 'month')\">{{locale.monthNames[month.month]}}</span>\n <select tabindex=\"0\" class=\"ui-datepicker-month\" *ngIf=\"monthNavigator && (view !== 'month') && numberOfMonths === 1\" (change)=\"onMonthDropdownChange($event.target.value)\">\n <option [value]=\"i\" *ngFor=\"let monthName of locale.monthNames;let i = index\" [selected]=\"i === month.month\">{{monthName}}</option>\n </select>\n <select tabindex=\"0\" class=\"ui-datepicker-year\" *ngIf=\"yearNavigator && numberOfMonths === 1\" (change)=\"onYearDropdownChange($event.target.value)\">\n <option [value]=\"year\" *ngFor=\"let year of yearOptions\" [selected]=\"year === currentYear\">{{year}}</option>\n </select>\n <span class=\"ui-datepicker-year\" *ngIf=\"!yearNavigator\">{{view === 'month' ? currentYear : month.year}}</span>\n </div>\n <a class=\"ui-datepicker-next ui-corner-all\" (click)=\"onNextButtonClick($event)\" (keydown.enter)=\"onNextButtonClick($event)\" *ngIf=\"numberOfMonths === 1 ? true : (i === numberOfMonths -1)\" tabindex=\"0\" (keydown)=\"onInputKeydown($event)\">\n <span class=\"ui-datepicker-next-icon pi pi-chevron-right\"></span>\n </a>\n </div>\n <div class=\"ui-datepicker-calendar-container\" *ngIf=\"view ==='date'\">\n <table class=\"ui-datepicker-calendar\">\n <thead>\n <tr>\n <th *ngIf=\"showWeek\" class=\"ui-datepicker-weekheader\">\n <span>{{locale['weekHeader']}}</span>\n </th>\n <th scope=\"col\" *ngFor=\"let weekDay of weekDays;let begin = first; let end = last\">\n <span>{{weekDay}}</span>\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let week of month.dates; let j = index;\">\n <td *ngIf=\"showWeek\" class=\"ui-datepicker-weeknumber ui-state-disabled\">\n <span>\n {{month.weekNumbers[j]}}\n </span>\n </td>\n <td *ngFor=\"let date of week\" [ngClass]=\"{'ui-datepicker-other-month': date.otherMonth,\n 'ui-datepicker-current-day':isSelected(date),'ui-datepicker-today':date.today}\">\n <ng-container *ngIf=\"date.otherMonth ? showOtherMonths : true\">\n <a class=\"ui-state-default\" *ngIf=\"date.selectable\" [ngClass]=\"{'ui-state-active':isSelected(date), 'ui-state-highlight':date.today}\"\n (click)=\"onDateSelect($event,date)\" draggable=\"false\" (keydown)=\"onDateCellKeydown($event,date,i)\">\n <ng-container *ngIf=\"!dateTemplate\">{{date.day}}</ng-container>\n <ng-container *ngTemplateOutlet=\"dateTemplate; context: {$implicit: date}\"></ng-container>\n </a>\n <span class=\"ui-state-default ui-state-disabled\" [ngClass]=\"{'ui-state-active':isSelected(date), 'ui-state-highlight':date.today}\" *ngIf=\"!date.selectable\">\n <ng-container *ngIf=\"!disabledDateTemplate\">{{date.day}}</ng-container>\n <ng-container *ngTemplateOutlet=\"disabledDateTemplate; context: {$implicit: date}\"></ng-container>\n </span>\n </ng-container>\n </td>\n </tr>\n </tbody>\n </table>\n </div>\n </div>\n <div class=\"ui-monthpicker\" *ngIf=\"view === 'month'\">\n <a *ngFor=\"let m of monthPickerValues; let i = index\" (click)=\"onMonthSelect($event, i)\" (keydown)=\"onMonthCellKeydown($event,i)\" class=\"ui-monthpicker-month\" [ngClass]=\"{'ui-state-active': isMonthSelected(i), 'ui-state-disabled':!isSelectable(1, i, this.currentYear, false)}\">\n {{m}}\n </a>\n </div>\n </ng-container>\n <div class=\"ui-timepicker ui-widget-header ui-corner-all\" *ngIf=\"showTime||timeOnly\">\n <div class=\"ui-hour-picker\">\n <a tabindex=\"0\" (keydown)=\"onContainerButtonKeydown($event)\" (keydown.enter)=\"incrementHour($event)\" (mousedown)=\"onTimePickerElementMouseDown($event, 0, 1)\" (mouseup)=\"onTimePickerElementMouseUp($event)\" (mouseout)=\"onTimePickerElementMouseOut($event)\">\n <span class=\"pi pi-chevron-up\"></span>\n </a>\n <span [ngStyle]=\"{'display': currentHour < 10 ? 'inline': 'none'}\">0</span><span>{{currentHour}}</span>\n <a tabindex=\"0\" (keydown)=\"onContainerButtonKeydown($event)\" (keydown.enter)=\"decrementHour($event)\" (mousedown)=\"onTimePickerElementMouseDown($event, 0, -1)\" (mouseup)=\"onTimePickerElementMouseUp($event)\" (mouseout)=\"onTimePickerElementMouseOut($event)\">\n <span class=\"pi pi-chevron-down\"></span>\n </a>\n </div>\n <div class=\"ui-separator\">\n <a>\n <span class=\"pi pi-chevron-up\"></span>\n </a>\n <span>{{timeSeparator}}</span>\n <a>\n <span class=\"pi pi-chevron-down\"></span>\n </a>\n </div>\n <div class=\"ui-minute-picker\">\n <a tabindex=\"0\" (keydown)=\"onContainerButtonKeydown($event)\" (keydown.enter)=\"incrementMinute($event)\" (mousedown)=\"onTimePickerElementMouseDown($event, 1, 1)\" (mouseup)=\"onTimePickerElementMouseUp($event)\" (mouseout)=\"onTimePickerElementMouseOut($event)\">\n <span class=\"pi pi-chevron-up\"></span>\n </a>\n <span [ngStyle]=\"{'display': currentMinute < 10 ? 'inline': 'none'}\">0</span><span>{{currentMinute}}</span>\n <a tabindex=\"0\" (keydown)=\"onContainerButtonKeydown($event)\" (keydown.enter)=\"decrementMinute($event)\" (mousedown)=\"onTimePickerElementMouseDown($event, 1, -1)\" (mouseup)=\"onTimePickerElementMouseUp($event)\" (mouseout)=\"onTimePickerElementMouseOut($event)\">\n <span class=\"pi pi-chevron-down\"></span>\n </a>\n </div>\n <div class=\"ui-separator\" *ngIf=\"showSeconds\">\n <a>\n <span class=\"pi pi-chevron-up\"></span>\n </a>\n <span>{{timeSeparator}}</span>\n <a>\n <span class=\"pi pi-chevron-down\"></span>\n </a>\n </div>\n <div class=\"ui-second-picker\" *ngIf=\"showSeconds\">\n <a tabindex=\"0\" (keydown)=\"onContainerButtonKeydown($event)\" (keydown.enter)=\"incrementSecond($event)\" (mousedown)=\"onTimePickerElementMouseDown($event, 2, 1)\" (mouseup)=\"onTimePickerElementMouseUp($event)\" (mouseout)=\"onTimePickerElementMouseOut($event)\">\n <span class=\"pi pi-chevron-up\"></span>\n </a>\n <span [ngStyle]=\"{'display': currentSecond < 10 ? 'inline': 'none'}\">0</span><span>{{currentSecond}}</span>\n <a tabindex=\"0\" (keydown)=\"onContainerButtonKeydown($event)\" (keydown.enter)=\"decrementSecond($event)\" (mousedown)=\"onTimePickerElementMouseDown($event, 2, -1)\" (mouseup)=\"onTimePickerElementMouseUp($event)\" (mouseout)=\"onTimePickerElementMouseOut($event)\">\n <span class=\"pi pi-chevron-down\"></span>\n </a>\n </div>\n <div class=\"ui-ampm-picker\" *ngIf=\"hourFormat=='12'\">\n <a tabindex=\"0\" (keydown)=\"onContainerButtonKeydown($event)\" (click)=\"toggleAMPM($event)\" (keydown.enter)=\"toggleAMPM($event)\">\n <span class=\"pi pi-chevron-up\"></span>\n </a>\n <span>{{pm ? 'PM' : 'AM'}}</span>\n <a tabindex=\"0\" (keydown)=\"onContainerButtonKeydown($event)\" (click)=\"toggleAMPM($event)\" (keydown.enter)=\"toggleAMPM($event)\">\n <span class=\"pi pi-chevron-down\"></span>\n </a>\n </div>\n </div>\n <div class=\"ui-datepicker-buttonbar ui-widget-header\" *ngIf=\"showButtonBar\">\n <button type=\"button\" tabindex=\"0\" [label]=\"_locale.today\" (keydown)=\"onContainerButtonKeydown($event)\" (click)=\"onTodayButtonClick($event)\" pButton [ngClass]=\"[todayButtonStyleClass]\"></button>\n <button type=\"button\" tabindex=\"0\" [label]=\"_locale.clear\" (keydown)=\"onContainerButtonKeydown($event)\" (click)=\"onClearButtonClick($event)\" pButton [ngClass]=\"[clearButtonStyleClass]\"></button>\n </div>\n <ng-content select=\"p-footer\"></ng-content>\n </div>\n </span>\n ",
2197 animations: [
2198 animations.trigger('overlayAnimation', [
2199 animations.state('visible', animations.style({
2200 transform: 'translateY(0)',
2201 opacity: 1
2202 })),
2203 animations.state('visibleTouchUI', animations.style({
2204 transform: 'translate(-50%,-50%)',
2205 opacity: 1
2206 })),
2207 animations.transition('void => visible', [
2208 animations.style({ transform: 'translateY(5%)', opacity: 0 }),
2209 animations.animate('{{showTransitionParams}}')
2210 ]),
2211 animations.transition('visible => void', [
2212 animations.animate(('{{hideTransitionParams}}'), animations.style({
2213 opacity: 0,
2214 transform: 'translateY(5%)'
2215 }))
2216 ]),
2217 animations.transition('void => visibleTouchUI', [
2218 animations.style({ opacity: 0, transform: 'translate3d(-50%, -40%, 0) scale(0.9)' }),
2219 animations.animate('{{showTransitionParams}}')
2220 ]),
2221 animations.transition('visibleTouchUI => void', [
2222 animations.animate(('{{hideTransitionParams}}'), animations.style({
2223 opacity: 0,
2224 transform: 'translate3d(-50%, -40%, 0) scale(0.9)'
2225 }))
2226 ])
2227 ])
2228 ],
2229 host: {
2230 '[class.ui-inputwrapper-filled]': 'filled',
2231 '[class.ui-inputwrapper-focus]': 'focus'
2232 },
2233 providers: [CALENDAR_VALUE_ACCESSOR],
2234 changeDetection: core.ChangeDetectionStrategy.Default
2235 })
2236 ], Calendar);
2237 return Calendar;
2238 }());
2239 var CalendarModule = /** @class */ (function () {
2240 function CalendarModule() {
2241 }
2242 CalendarModule = __decorate([
2243 core.NgModule({
2244 imports: [common.CommonModule, button.ButtonModule, api.SharedModule],
2245 exports: [Calendar, button.ButtonModule, api.SharedModule],
2246 declarations: [Calendar]
2247 })
2248 ], CalendarModule);
2249 return CalendarModule;
2250 }());
2251
2252 exports.CALENDAR_VALUE_ACCESSOR = CALENDAR_VALUE_ACCESSOR;
2253 exports.Calendar = Calendar;
2254 exports.CalendarModule = CalendarModule;
2255
2256 Object.defineProperty(exports, '__esModule', { value: true });
2257
2258})));
2259//# sourceMappingURL=primeng-calendar.umd.js.map