calendar.js 84 KB

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