datepicker.common.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  1. /*!
  2. * Datepicker v1.0.10
  3. * https://fengyuanchen.github.io/datepicker
  4. *
  5. * Copyright 2014-present Chen Fengyuan
  6. * Released under the MIT license
  7. *
  8. * Date: 2020-09-29T14:46:10.983Z
  9. */
  10. 'use strict';
  11. var $ = require('jquery');
  12. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  13. var $__default = /*#__PURE__*/_interopDefaultLegacy($);
  14. function _classCallCheck(instance, Constructor) {
  15. if (!(instance instanceof Constructor)) {
  16. throw new TypeError("Cannot call a class as a function");
  17. }
  18. }
  19. function _defineProperties(target, props) {
  20. for (var i = 0; i < props.length; i++) {
  21. var descriptor = props[i];
  22. descriptor.enumerable = descriptor.enumerable || false;
  23. descriptor.configurable = true;
  24. if ("value" in descriptor) descriptor.writable = true;
  25. Object.defineProperty(target, descriptor.key, descriptor);
  26. }
  27. }
  28. function _createClass(Constructor, protoProps, staticProps) {
  29. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  30. if (staticProps) _defineProperties(Constructor, staticProps);
  31. return Constructor;
  32. }
  33. var DEFAULTS = {
  34. // Show the datepicker automatically when initialized
  35. autoShow: false,
  36. // Hide the datepicker automatically when picked
  37. autoHide: false,
  38. // Pick the initial date automatically when initialized
  39. autoPick: false,
  40. // Enable inline mode
  41. inline: false,
  42. // A element (or selector) for putting the datepicker
  43. container: null,
  44. // A element (or selector) for triggering the datepicker
  45. trigger: null,
  46. // The ISO language code (built-in: en-US)
  47. language: '',
  48. // The date string format
  49. format: 'mm/dd/yyyy',
  50. // The initial date
  51. date: null,
  52. // The start view date
  53. startDate: null,
  54. // The end view date
  55. endDate: null,
  56. // The start view when initialized
  57. startView: 0,
  58. // 0 for days, 1 for months, 2 for years
  59. // The start day of the week
  60. // 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday,
  61. // 4 for Thursday, 5 for Friday, 6 for Saturday
  62. weekStart: 0,
  63. // Show year before month on the datepicker header
  64. yearFirst: false,
  65. // A string suffix to the year number.
  66. yearSuffix: '',
  67. // Days' name of the week.
  68. days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  69. // Shorter days' name
  70. daysShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  71. // Shortest days' name
  72. daysMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
  73. // Months' name
  74. months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  75. // Shorter months' name
  76. monthsShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  77. // A element tag for each item of years, months and days
  78. itemTag: 'li',
  79. // A class (CSS) for muted date item
  80. mutedClass: 'muted',
  81. // A class (CSS) for picked date item
  82. pickedClass: 'picked',
  83. // A class (CSS) for disabled date item
  84. disabledClass: 'disabled',
  85. // A class (CSS) for highlight date item
  86. highlightedClass: 'highlighted',
  87. // The template of the datepicker
  88. template: '<div class="datepicker-container">' + '<div class="datepicker-panel" data-view="years picker">' + '<ul>' + '<li data-view="years prev">&lsaquo;</li>' + '<li data-view="years current"></li>' + '<li data-view="years next">&rsaquo;</li>' + '</ul>' + '<ul data-view="years"></ul>' + '</div>' + '<div class="datepicker-panel" data-view="months picker">' + '<ul>' + '<li data-view="year prev">&lsaquo;</li>' + '<li data-view="year current"></li>' + '<li data-view="year next">&rsaquo;</li>' + '</ul>' + '<ul data-view="months"></ul>' + '</div>' + '<div class="datepicker-panel" data-view="days picker">' + '<ul>' + '<li data-view="month prev">&lsaquo;</li>' + '<li data-view="month current"></li>' + '<li data-view="month next">&rsaquo;</li>' + '</ul>' + '<ul data-view="week"></ul>' + '<ul data-view="days"></ul>' + '</div>' + '</div>',
  89. // The offset top or bottom of the datepicker from the element
  90. offset: 10,
  91. // The `z-index` of the datepicker
  92. zIndex: 1000,
  93. // Filter each date item (return `false` to disable a date item)
  94. filter: null,
  95. // Event shortcuts
  96. show: null,
  97. hide: null,
  98. pick: null
  99. };
  100. var IS_BROWSER = typeof window !== 'undefined';
  101. var WINDOW = IS_BROWSER ? window : {};
  102. var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false;
  103. var NAMESPACE = 'datepicker';
  104. var EVENT_CLICK = "click.".concat(NAMESPACE);
  105. var EVENT_FOCUS = "focus.".concat(NAMESPACE);
  106. var EVENT_HIDE = "hide.".concat(NAMESPACE);
  107. var EVENT_KEYUP = "keyup.".concat(NAMESPACE);
  108. var EVENT_PICK = "pick.".concat(NAMESPACE);
  109. var EVENT_RESIZE = "resize.".concat(NAMESPACE);
  110. var EVENT_SCROLL = "scroll.".concat(NAMESPACE);
  111. var EVENT_SHOW = "show.".concat(NAMESPACE);
  112. var EVENT_TOUCH_START = "touchstart.".concat(NAMESPACE);
  113. var CLASS_HIDE = "".concat(NAMESPACE, "-hide");
  114. var LANGUAGES = {};
  115. var VIEWS = {
  116. DAYS: 0,
  117. MONTHS: 1,
  118. YEARS: 2
  119. };
  120. var toString = Object.prototype.toString;
  121. function typeOf(obj) {
  122. return toString.call(obj).slice(8, -1).toLowerCase();
  123. }
  124. function isString(value) {
  125. return typeof value === 'string';
  126. }
  127. var isNaN = Number.isNaN || WINDOW.isNaN;
  128. function isNumber(value) {
  129. return typeof value === 'number' && !isNaN(value);
  130. }
  131. function isUndefined(value) {
  132. return typeof value === 'undefined';
  133. }
  134. function isDate(value) {
  135. return typeOf(value) === 'date' && !isNaN(value.getTime());
  136. }
  137. function proxy(fn, context) {
  138. for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  139. args[_key - 2] = arguments[_key];
  140. }
  141. return function () {
  142. for (var _len2 = arguments.length, args2 = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  143. args2[_key2] = arguments[_key2];
  144. }
  145. return fn.apply(context, args.concat(args2));
  146. };
  147. }
  148. function selectorOf(view) {
  149. return "[data-view=\"".concat(view, "\"]");
  150. }
  151. function isLeapYear(year) {
  152. return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
  153. }
  154. function getDaysInMonth(year, month) {
  155. return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
  156. }
  157. function getMinDay(year, month, day) {
  158. return Math.min(day, getDaysInMonth(year, month));
  159. }
  160. var formatParts = /(y|m|d)+/g;
  161. function parseFormat(format) {
  162. var source = String(format).toLowerCase();
  163. var parts = source.match(formatParts);
  164. if (!parts || parts.length === 0) {
  165. throw new Error('Invalid date format.');
  166. }
  167. format = {
  168. source: source,
  169. parts: parts
  170. };
  171. $__default['default'].each(parts, function (i, part) {
  172. switch (part) {
  173. case 'dd':
  174. case 'd':
  175. format.hasDay = true;
  176. break;
  177. case 'mm':
  178. case 'm':
  179. format.hasMonth = true;
  180. break;
  181. case 'yyyy':
  182. case 'yy':
  183. format.hasYear = true;
  184. break;
  185. }
  186. });
  187. return format;
  188. }
  189. function getScrollParent(element) {
  190. var includeHidden = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  191. var $element = $__default['default'](element);
  192. var position = $element.css('position');
  193. var excludeStaticParent = position === 'absolute';
  194. var overflowRegex = includeHidden ? /auto|scroll|hidden/ : /auto|scroll/;
  195. var scrollParent = $element.parents().filter(function (index, parent) {
  196. var $parent = $__default['default'](parent);
  197. if (excludeStaticParent && $parent.css('position') === 'static') {
  198. return false;
  199. }
  200. return overflowRegex.test($parent.css('overflow') + $parent.css('overflow-y') + $parent.css('overflow-x'));
  201. }).eq(0);
  202. return position === 'fixed' || !scrollParent.length ? $__default['default'](element.ownerDocument || document) : scrollParent;
  203. }
  204. /**
  205. * Add leading zeroes to the given value
  206. * @param {number} value - The value to add.
  207. * @param {number} [length=1] - The expected value length.
  208. * @returns {string} Returns converted value.
  209. */
  210. function addLeadingZero(value) {
  211. var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  212. var str = String(Math.abs(value));
  213. var i = str.length;
  214. var result = '';
  215. if (value < 0) {
  216. result += '-';
  217. }
  218. while (i < length) {
  219. i += 1;
  220. result += '0';
  221. }
  222. return result + str;
  223. }
  224. var REGEXP_DIGITS = /\d+/g;
  225. var methods = {
  226. // Show the datepicker
  227. show: function show() {
  228. if (!this.built) {
  229. this.build();
  230. }
  231. if (this.shown) {
  232. return;
  233. }
  234. if (this.trigger(EVENT_SHOW).isDefaultPrevented()) {
  235. return;
  236. }
  237. this.shown = true;
  238. this.$picker.removeClass(CLASS_HIDE).on(EVENT_CLICK, $__default['default'].proxy(this.click, this));
  239. this.showView(this.options.startView);
  240. if (!this.inline) {
  241. this.$scrollParent.on(EVENT_SCROLL, $__default['default'].proxy(this.place, this));
  242. $__default['default'](window).on(EVENT_RESIZE, this.onResize = proxy(this.place, this));
  243. $__default['default'](document).on(EVENT_CLICK, this.onGlobalClick = proxy(this.globalClick, this));
  244. $__default['default'](document).on(EVENT_KEYUP, this.onGlobalKeyup = proxy(this.globalKeyup, this));
  245. if (IS_TOUCH_DEVICE) {
  246. $__default['default'](document).on(EVENT_TOUCH_START, this.onTouchStart = proxy(this.touchstart, this));
  247. }
  248. this.place();
  249. }
  250. },
  251. // Hide the datepicker
  252. hide: function hide() {
  253. if (!this.shown) {
  254. return;
  255. }
  256. if (this.trigger(EVENT_HIDE).isDefaultPrevented()) {
  257. return;
  258. }
  259. this.shown = false;
  260. this.$picker.addClass(CLASS_HIDE).off(EVENT_CLICK, this.click);
  261. if (!this.inline) {
  262. this.$scrollParent.off(EVENT_SCROLL, this.place);
  263. $__default['default'](window).off(EVENT_RESIZE, this.onResize);
  264. $__default['default'](document).off(EVENT_CLICK, this.onGlobalClick);
  265. $__default['default'](document).off(EVENT_KEYUP, this.onGlobalKeyup);
  266. if (IS_TOUCH_DEVICE) {
  267. $__default['default'](document).off(EVENT_TOUCH_START, this.onTouchStart);
  268. }
  269. }
  270. },
  271. toggle: function toggle() {
  272. if (this.shown) {
  273. this.hide();
  274. } else {
  275. this.show();
  276. }
  277. },
  278. // Update the datepicker with the current input value
  279. update: function update() {
  280. var value = this.getValue();
  281. if (value === this.oldValue) {
  282. return;
  283. }
  284. this.setDate(value, true);
  285. this.oldValue = value;
  286. },
  287. /**
  288. * Pick the current date to the element
  289. *
  290. * @param {String} _view (private)
  291. */
  292. pick: function pick(_view) {
  293. var $this = this.$element;
  294. var date = this.date;
  295. if (this.trigger(EVENT_PICK, {
  296. view: _view || '',
  297. date: date
  298. }).isDefaultPrevented()) {
  299. return;
  300. }
  301. date = this.formatDate(this.date);
  302. this.setValue(date);
  303. if (this.isInput) {
  304. $this.trigger('input');
  305. $this.trigger('change');
  306. }
  307. },
  308. // Reset the datepicker
  309. reset: function reset() {
  310. this.setDate(this.initialDate, true);
  311. this.setValue(this.initialValue);
  312. if (this.shown) {
  313. this.showView(this.options.startView);
  314. }
  315. },
  316. /**
  317. * Get the month name with given argument or the current date
  318. *
  319. * @param {Number} month (optional)
  320. * @param {Boolean} shortForm (optional)
  321. * @return {String} (month name)
  322. */
  323. getMonthName: function getMonthName(month, shortForm) {
  324. var options = this.options;
  325. var monthsShort = options.monthsShort;
  326. var months = options.months;
  327. if ($__default['default'].isNumeric(month)) {
  328. month = Number(month);
  329. } else if (isUndefined(shortForm)) {
  330. shortForm = month;
  331. }
  332. if (shortForm === true) {
  333. months = monthsShort;
  334. }
  335. return months[isNumber(month) ? month : this.date.getMonth()];
  336. },
  337. /**
  338. * Get the day name with given argument or the current date
  339. *
  340. * @param {Number} day (optional)
  341. * @param {Boolean} shortForm (optional)
  342. * @param {Boolean} min (optional)
  343. * @return {String} (day name)
  344. */
  345. getDayName: function getDayName(day, shortForm, min) {
  346. var options = this.options;
  347. var days = options.days;
  348. if ($__default['default'].isNumeric(day)) {
  349. day = Number(day);
  350. } else {
  351. if (isUndefined(min)) {
  352. min = shortForm;
  353. }
  354. if (isUndefined(shortForm)) {
  355. shortForm = day;
  356. }
  357. }
  358. if (min) {
  359. days = options.daysMin;
  360. } else if (shortForm) {
  361. days = options.daysShort;
  362. }
  363. return days[isNumber(day) ? day : this.date.getDay()];
  364. },
  365. /**
  366. * Get the current date
  367. *
  368. * @param {Boolean} formatted (optional)
  369. * @return {Date|String} (date)
  370. */
  371. getDate: function getDate(formatted) {
  372. var date = this.date;
  373. return formatted ? this.formatDate(date) : new Date(date);
  374. },
  375. /**
  376. * Set the current date with a new date
  377. *
  378. * @param {Date} date
  379. * @param {Boolean} _updated (private)
  380. */
  381. setDate: function setDate(date, _updated) {
  382. var filter = this.options.filter;
  383. if (isDate(date) || isString(date)) {
  384. date = this.parseDate(date);
  385. if ($__default['default'].isFunction(filter) && filter.call(this.$element, date, 'day') === false) {
  386. return;
  387. }
  388. this.date = date;
  389. this.viewDate = new Date(date);
  390. if (!_updated) {
  391. this.pick();
  392. }
  393. if (this.built) {
  394. this.render();
  395. }
  396. }
  397. },
  398. /**
  399. * Set the start view date with a new date
  400. *
  401. * @param {Date|string|null} date
  402. */
  403. setStartDate: function setStartDate(date) {
  404. if (isDate(date) || isString(date)) {
  405. this.startDate = this.parseDate(date);
  406. } else {
  407. this.startDate = null;
  408. }
  409. if (this.built) {
  410. this.render();
  411. }
  412. },
  413. /**
  414. * Set the end view date with a new date
  415. *
  416. * @param {Date|string|null} date
  417. */
  418. setEndDate: function setEndDate(date) {
  419. if (isDate(date) || isString(date)) {
  420. this.endDate = this.parseDate(date);
  421. } else {
  422. this.endDate = null;
  423. }
  424. if (this.built) {
  425. this.render();
  426. }
  427. },
  428. /**
  429. * Parse a date string with the set date format
  430. *
  431. * @param {String} date
  432. * @return {Date} (parsed date)
  433. */
  434. parseDate: function parseDate(date) {
  435. var format = this.format;
  436. var parts = [];
  437. if (!isDate(date)) {
  438. if (isString(date)) {
  439. parts = date.match(REGEXP_DIGITS) || [];
  440. }
  441. date = date ? new Date(date) : new Date();
  442. if (!isDate(date)) {
  443. date = new Date();
  444. }
  445. if (parts.length === format.parts.length) {
  446. // Set year and month first
  447. $__default['default'].each(parts, function (i, part) {
  448. var value = parseInt(part, 10);
  449. switch (format.parts[i]) {
  450. case 'yy':
  451. date.setFullYear(2000 + value);
  452. break;
  453. case 'yyyy':
  454. // Converts 2-digit year to 2000+
  455. date.setFullYear(part.length === 2 ? 2000 + value : value);
  456. break;
  457. case 'mm':
  458. case 'm':
  459. date.setMonth(value - 1);
  460. break;
  461. }
  462. }); // Set day in the last to avoid converting `31/10/2019` to `01/10/2019`
  463. $__default['default'].each(parts, function (i, part) {
  464. var value = parseInt(part, 10);
  465. switch (format.parts[i]) {
  466. case 'dd':
  467. case 'd':
  468. date.setDate(value);
  469. break;
  470. }
  471. });
  472. }
  473. } // Ignore hours, minutes, seconds and milliseconds to avoid side effect (#192)
  474. return new Date(date.getFullYear(), date.getMonth(), date.getDate());
  475. },
  476. /**
  477. * Format a date object to a string with the set date format
  478. *
  479. * @param {Date} date
  480. * @return {String} (formatted date)
  481. */
  482. formatDate: function formatDate(date) {
  483. var format = this.format;
  484. var formatted = '';
  485. if (isDate(date)) {
  486. var year = date.getFullYear();
  487. var month = date.getMonth();
  488. var day = date.getDate();
  489. var values = {
  490. d: day,
  491. dd: addLeadingZero(day, 2),
  492. m: month + 1,
  493. mm: addLeadingZero(month + 1, 2),
  494. yy: String(year).substring(2),
  495. yyyy: addLeadingZero(year, 4)
  496. };
  497. formatted = format.source;
  498. $__default['default'].each(format.parts, function (i, part) {
  499. formatted = formatted.replace(part, values[part]);
  500. });
  501. }
  502. return formatted;
  503. },
  504. // Destroy the datepicker and remove the instance from the target element
  505. destroy: function destroy() {
  506. this.unbind();
  507. this.unbuild();
  508. this.$element.removeData(NAMESPACE);
  509. }
  510. };
  511. var handlers = {
  512. click: function click(e) {
  513. var $target = $__default['default'](e.target);
  514. var options = this.options,
  515. date = this.date,
  516. viewDate = this.viewDate,
  517. format = this.format;
  518. e.stopPropagation();
  519. e.preventDefault();
  520. if ($target.hasClass('disabled')) {
  521. return;
  522. }
  523. var view = $target.data('view');
  524. var viewYear = viewDate.getFullYear();
  525. var viewMonth = viewDate.getMonth();
  526. var viewDay = viewDate.getDate();
  527. switch (view) {
  528. case 'years prev':
  529. case 'years next':
  530. {
  531. viewYear = view === 'years prev' ? viewYear - 10 : viewYear + 10;
  532. viewDate.setFullYear(viewYear);
  533. viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
  534. this.renderYears();
  535. break;
  536. }
  537. case 'year prev':
  538. case 'year next':
  539. viewYear = view === 'year prev' ? viewYear - 1 : viewYear + 1;
  540. viewDate.setFullYear(viewYear);
  541. viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
  542. this.renderMonths();
  543. break;
  544. case 'year current':
  545. if (format.hasYear) {
  546. this.showView(VIEWS.YEARS);
  547. }
  548. break;
  549. case 'year picked':
  550. if (format.hasMonth) {
  551. this.showView(VIEWS.MONTHS);
  552. } else {
  553. $target.siblings(".".concat(options.pickedClass)).removeClass(options.pickedClass).data('view', 'year');
  554. this.hideView();
  555. }
  556. this.pick('year');
  557. break;
  558. case 'year':
  559. viewYear = parseInt($target.text(), 10); // Set date first to avoid month changing (#195)
  560. date.setDate(getMinDay(viewYear, viewMonth, viewDay));
  561. date.setFullYear(viewYear);
  562. viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
  563. viewDate.setFullYear(viewYear);
  564. if (format.hasMonth) {
  565. this.showView(VIEWS.MONTHS);
  566. } else {
  567. $target.addClass(options.pickedClass).data('view', 'year picked').siblings(".".concat(options.pickedClass)).removeClass(options.pickedClass).data('view', 'year');
  568. this.hideView();
  569. }
  570. this.pick('year');
  571. break;
  572. case 'month prev':
  573. case 'month next':
  574. viewMonth = view === 'month prev' ? viewMonth - 1 : viewMonth + 1;
  575. if (viewMonth < 0) {
  576. viewYear -= 1;
  577. viewMonth += 12;
  578. } else if (viewMonth > 11) {
  579. viewYear += 1;
  580. viewMonth -= 12;
  581. }
  582. viewDate.setFullYear(viewYear);
  583. viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
  584. viewDate.setMonth(viewMonth);
  585. this.renderDays();
  586. break;
  587. case 'month current':
  588. if (format.hasMonth) {
  589. this.showView(VIEWS.MONTHS);
  590. }
  591. break;
  592. case 'month picked':
  593. if (format.hasDay) {
  594. this.showView(VIEWS.DAYS);
  595. } else {
  596. $target.siblings(".".concat(options.pickedClass)).removeClass(options.pickedClass).data('view', 'month');
  597. this.hideView();
  598. }
  599. this.pick('month');
  600. break;
  601. case 'month':
  602. viewMonth = $__default['default'].inArray($target.text(), options.monthsShort);
  603. date.setFullYear(viewYear); // Set date before month to avoid month changing (#195)
  604. date.setDate(getMinDay(viewYear, viewMonth, viewDay));
  605. date.setMonth(viewMonth);
  606. viewDate.setFullYear(viewYear);
  607. viewDate.setDate(getMinDay(viewYear, viewMonth, viewDay));
  608. viewDate.setMonth(viewMonth);
  609. if (format.hasDay) {
  610. this.showView(VIEWS.DAYS);
  611. } else {
  612. $target.addClass(options.pickedClass).data('view', 'month picked').siblings(".".concat(options.pickedClass)).removeClass(options.pickedClass).data('view', 'month');
  613. this.hideView();
  614. }
  615. this.pick('month');
  616. break;
  617. case 'day prev':
  618. case 'day next':
  619. case 'day':
  620. if (view === 'day prev') {
  621. viewMonth -= 1;
  622. } else if (view === 'day next') {
  623. viewMonth += 1;
  624. }
  625. viewDay = parseInt($target.text(), 10); // Set date to 1 to avoid month changing (#195)
  626. date.setDate(1);
  627. date.setFullYear(viewYear);
  628. date.setMonth(viewMonth);
  629. date.setDate(viewDay);
  630. viewDate.setDate(1);
  631. viewDate.setFullYear(viewYear);
  632. viewDate.setMonth(viewMonth);
  633. viewDate.setDate(viewDay);
  634. this.renderDays();
  635. if (view === 'day') {
  636. this.hideView();
  637. }
  638. this.pick('day');
  639. break;
  640. case 'day picked':
  641. this.hideView();
  642. this.pick('day');
  643. break;
  644. }
  645. },
  646. globalClick: function globalClick(_ref) {
  647. var target = _ref.target;
  648. var element = this.element,
  649. $trigger = this.$trigger;
  650. var trigger = $trigger[0];
  651. var hidden = true;
  652. while (target !== document) {
  653. if (target === trigger || target === element) {
  654. hidden = false;
  655. break;
  656. }
  657. target = target.parentNode;
  658. }
  659. if (hidden) {
  660. this.hide();
  661. }
  662. },
  663. keyup: function keyup() {
  664. this.update();
  665. },
  666. globalKeyup: function globalKeyup(_ref2) {
  667. var target = _ref2.target,
  668. key = _ref2.key,
  669. keyCode = _ref2.keyCode;
  670. if (this.isInput && target !== this.element && this.shown && (key === 'Tab' || keyCode === 9)) {
  671. this.hide();
  672. }
  673. },
  674. touchstart: function touchstart(_ref3) {
  675. var target = _ref3.target;
  676. // Emulate click in touch devices to support hiding the picker automatically (#197).
  677. if (this.isInput && target !== this.element && !$__default['default'].contains(this.$picker[0], target)) {
  678. this.hide();
  679. this.element.blur();
  680. }
  681. }
  682. };
  683. var render = {
  684. render: function render() {
  685. this.renderYears();
  686. this.renderMonths();
  687. this.renderDays();
  688. },
  689. renderWeek: function renderWeek() {
  690. var _this = this;
  691. var items = [];
  692. var _this$options = this.options,
  693. weekStart = _this$options.weekStart,
  694. daysMin = _this$options.daysMin;
  695. weekStart = parseInt(weekStart, 10) % 7;
  696. daysMin = daysMin.slice(weekStart).concat(daysMin.slice(0, weekStart));
  697. $__default['default'].each(daysMin, function (i, day) {
  698. items.push(_this.createItem({
  699. text: day
  700. }));
  701. });
  702. this.$week.html(items.join(''));
  703. },
  704. renderYears: function renderYears() {
  705. var options = this.options,
  706. startDate = this.startDate,
  707. endDate = this.endDate;
  708. var disabledClass = options.disabledClass,
  709. filter = options.filter,
  710. yearSuffix = options.yearSuffix;
  711. var viewYear = this.viewDate.getFullYear();
  712. var now = new Date();
  713. var thisYear = now.getFullYear();
  714. var year = this.date.getFullYear();
  715. var start = -5;
  716. var end = 6;
  717. var items = [];
  718. var prevDisabled = false;
  719. var nextDisabled = false;
  720. var i;
  721. for (i = start; i <= end; i += 1) {
  722. var date = new Date(viewYear + i, 1, 1);
  723. var disabled = false;
  724. if (startDate) {
  725. disabled = date.getFullYear() < startDate.getFullYear();
  726. if (i === start) {
  727. prevDisabled = disabled;
  728. }
  729. }
  730. if (!disabled && endDate) {
  731. disabled = date.getFullYear() > endDate.getFullYear();
  732. if (i === end) {
  733. nextDisabled = disabled;
  734. }
  735. }
  736. if (!disabled && filter) {
  737. disabled = filter.call(this.$element, date, 'year') === false;
  738. }
  739. var picked = viewYear + i === year;
  740. var view = picked ? 'year picked' : 'year';
  741. items.push(this.createItem({
  742. picked: picked,
  743. disabled: disabled,
  744. text: viewYear + i,
  745. view: disabled ? 'year disabled' : view,
  746. highlighted: date.getFullYear() === thisYear
  747. }));
  748. }
  749. this.$yearsPrev.toggleClass(disabledClass, prevDisabled);
  750. this.$yearsNext.toggleClass(disabledClass, nextDisabled);
  751. this.$yearsCurrent.toggleClass(disabledClass, true).html("".concat(viewYear + start + yearSuffix, " - ").concat(viewYear + end).concat(yearSuffix));
  752. this.$years.html(items.join(''));
  753. },
  754. renderMonths: function renderMonths() {
  755. var options = this.options,
  756. startDate = this.startDate,
  757. endDate = this.endDate,
  758. viewDate = this.viewDate;
  759. var disabledClass = options.disabledClass || '';
  760. var months = options.monthsShort;
  761. var filter = $__default['default'].isFunction(options.filter) && options.filter;
  762. var viewYear = viewDate.getFullYear();
  763. var now = new Date();
  764. var thisYear = now.getFullYear();
  765. var thisMonth = now.getMonth();
  766. var year = this.date.getFullYear();
  767. var month = this.date.getMonth();
  768. var items = [];
  769. var prevDisabled = false;
  770. var nextDisabled = false;
  771. var i;
  772. for (i = 0; i <= 11; i += 1) {
  773. var date = new Date(viewYear, i, 1);
  774. var disabled = false;
  775. if (startDate) {
  776. prevDisabled = date.getFullYear() === startDate.getFullYear();
  777. disabled = prevDisabled && date.getMonth() < startDate.getMonth();
  778. }
  779. if (!disabled && endDate) {
  780. nextDisabled = date.getFullYear() === endDate.getFullYear();
  781. disabled = nextDisabled && date.getMonth() > endDate.getMonth();
  782. }
  783. if (!disabled && filter) {
  784. disabled = filter.call(this.$element, date, 'month') === false;
  785. }
  786. var picked = viewYear === year && i === month;
  787. var view = picked ? 'month picked' : 'month';
  788. items.push(this.createItem({
  789. disabled: disabled,
  790. picked: picked,
  791. highlighted: viewYear === thisYear && date.getMonth() === thisMonth,
  792. index: i,
  793. text: months[i],
  794. view: disabled ? 'month disabled' : view
  795. }));
  796. }
  797. this.$yearPrev.toggleClass(disabledClass, prevDisabled);
  798. this.$yearNext.toggleClass(disabledClass, nextDisabled);
  799. this.$yearCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(viewYear + options.yearSuffix || '');
  800. this.$months.html(items.join(''));
  801. },
  802. renderDays: function renderDays() {
  803. var $element = this.$element,
  804. options = this.options,
  805. startDate = this.startDate,
  806. endDate = this.endDate,
  807. viewDate = this.viewDate,
  808. currentDate = this.date;
  809. var disabledClass = options.disabledClass,
  810. filter = options.filter,
  811. months = options.months,
  812. weekStart = options.weekStart,
  813. yearSuffix = options.yearSuffix;
  814. var viewYear = viewDate.getFullYear();
  815. var viewMonth = viewDate.getMonth();
  816. var now = new Date();
  817. var thisYear = now.getFullYear();
  818. var thisMonth = now.getMonth();
  819. var thisDay = now.getDate();
  820. var year = currentDate.getFullYear();
  821. var month = currentDate.getMonth();
  822. var day = currentDate.getDate();
  823. var length;
  824. var i;
  825. var n; // Days of prev month
  826. // -----------------------------------------------------------------------
  827. var prevItems = [];
  828. var prevViewYear = viewYear;
  829. var prevViewMonth = viewMonth;
  830. var prevDisabled = false;
  831. if (viewMonth === 0) {
  832. prevViewYear -= 1;
  833. prevViewMonth = 11;
  834. } else {
  835. prevViewMonth -= 1;
  836. } // The length of the days of prev month
  837. length = getDaysInMonth(prevViewYear, prevViewMonth); // The first day of current month
  838. var firstDay = new Date(viewYear, viewMonth, 1); // The visible length of the days of prev month
  839. // [0,1,2,3,4,5,6] - [0,1,2,3,4,5,6] => [-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6]
  840. n = firstDay.getDay() - parseInt(weekStart, 10) % 7; // [-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6] => [1,2,3,4,5,6,7]
  841. if (n <= 0) {
  842. n += 7;
  843. }
  844. if (startDate) {
  845. prevDisabled = firstDay.getTime() <= startDate.getTime();
  846. }
  847. for (i = length - (n - 1); i <= length; i += 1) {
  848. var prevViewDate = new Date(prevViewYear, prevViewMonth, i);
  849. var disabled = false;
  850. if (startDate) {
  851. disabled = prevViewDate.getTime() < startDate.getTime();
  852. }
  853. if (!disabled && filter) {
  854. disabled = filter.call($element, prevViewDate, 'day') === false;
  855. }
  856. prevItems.push(this.createItem({
  857. disabled: disabled,
  858. highlighted: prevViewYear === thisYear && prevViewMonth === thisMonth && prevViewDate.getDate() === thisDay,
  859. muted: true,
  860. picked: prevViewYear === year && prevViewMonth === month && i === day,
  861. text: i,
  862. view: 'day prev'
  863. }));
  864. } // Days of next month
  865. // -----------------------------------------------------------------------
  866. var nextItems = [];
  867. var nextViewYear = viewYear;
  868. var nextViewMonth = viewMonth;
  869. var nextDisabled = false;
  870. if (viewMonth === 11) {
  871. nextViewYear += 1;
  872. nextViewMonth = 0;
  873. } else {
  874. nextViewMonth += 1;
  875. } // The length of the days of current month
  876. length = getDaysInMonth(viewYear, viewMonth); // The visible length of next month (42 means 6 rows and 7 columns)
  877. n = 42 - (prevItems.length + length); // The last day of current month
  878. var lastDate = new Date(viewYear, viewMonth, length);
  879. if (endDate) {
  880. nextDisabled = lastDate.getTime() >= endDate.getTime();
  881. }
  882. for (i = 1; i <= n; i += 1) {
  883. var date = new Date(nextViewYear, nextViewMonth, i);
  884. var picked = nextViewYear === year && nextViewMonth === month && i === day;
  885. var _disabled = false;
  886. if (endDate) {
  887. _disabled = date.getTime() > endDate.getTime();
  888. }
  889. if (!_disabled && filter) {
  890. _disabled = filter.call($element, date, 'day') === false;
  891. }
  892. nextItems.push(this.createItem({
  893. disabled: _disabled,
  894. picked: picked,
  895. highlighted: nextViewYear === thisYear && nextViewMonth === thisMonth && date.getDate() === thisDay,
  896. muted: true,
  897. text: i,
  898. view: 'day next'
  899. }));
  900. } // Days of current month
  901. // -----------------------------------------------------------------------
  902. var items = [];
  903. for (i = 1; i <= length; i += 1) {
  904. var _date = new Date(viewYear, viewMonth, i);
  905. var _disabled2 = false;
  906. if (startDate) {
  907. _disabled2 = _date.getTime() < startDate.getTime();
  908. }
  909. if (!_disabled2 && endDate) {
  910. _disabled2 = _date.getTime() > endDate.getTime();
  911. }
  912. if (!_disabled2 && filter) {
  913. _disabled2 = filter.call($element, _date, 'day') === false;
  914. }
  915. var _picked = viewYear === year && viewMonth === month && i === day;
  916. var view = _picked ? 'day picked' : 'day';
  917. items.push(this.createItem({
  918. disabled: _disabled2,
  919. picked: _picked,
  920. highlighted: viewYear === thisYear && viewMonth === thisMonth && _date.getDate() === thisDay,
  921. text: i,
  922. view: _disabled2 ? 'day disabled' : view
  923. }));
  924. } // Render days picker
  925. // -----------------------------------------------------------------------
  926. this.$monthPrev.toggleClass(disabledClass, prevDisabled);
  927. this.$monthNext.toggleClass(disabledClass, nextDisabled);
  928. this.$monthCurrent.toggleClass(disabledClass, prevDisabled && nextDisabled).html(options.yearFirst ? "".concat(viewYear + yearSuffix, " ").concat(months[viewMonth]) : "".concat(months[viewMonth], " ").concat(viewYear).concat(yearSuffix));
  929. this.$days.html(prevItems.join('') + items.join('') + nextItems.join(''));
  930. }
  931. };
  932. var CLASS_TOP_LEFT = "".concat(NAMESPACE, "-top-left");
  933. var CLASS_TOP_RIGHT = "".concat(NAMESPACE, "-top-right");
  934. var CLASS_BOTTOM_LEFT = "".concat(NAMESPACE, "-bottom-left");
  935. var CLASS_BOTTOM_RIGHT = "".concat(NAMESPACE, "-bottom-right");
  936. var CLASS_PLACEMENTS = [CLASS_TOP_LEFT, CLASS_TOP_RIGHT, CLASS_BOTTOM_LEFT, CLASS_BOTTOM_RIGHT].join(' ');
  937. var Datepicker = /*#__PURE__*/function () {
  938. function Datepicker(element) {
  939. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  940. _classCallCheck(this, Datepicker);
  941. this.$element = $__default['default'](element);
  942. this.element = element;
  943. this.options = $__default['default'].extend({}, DEFAULTS, LANGUAGES[options.language], $__default['default'].isPlainObject(options) && options);
  944. this.$scrollParent = getScrollParent(element, true);
  945. this.built = false;
  946. this.shown = false;
  947. this.isInput = false;
  948. this.inline = false;
  949. this.initialValue = '';
  950. this.initialDate = null;
  951. this.startDate = null;
  952. this.endDate = null;
  953. this.init();
  954. }
  955. _createClass(Datepicker, [{
  956. key: "init",
  957. value: function init() {
  958. var $this = this.$element,
  959. options = this.options;
  960. var startDate = options.startDate,
  961. endDate = options.endDate,
  962. date = options.date;
  963. this.$trigger = $__default['default'](options.trigger);
  964. this.isInput = $this.is('input') || $this.is('textarea');
  965. this.inline = options.inline && (options.container || !this.isInput);
  966. this.format = parseFormat(options.format);
  967. var initialValue = this.getValue();
  968. this.initialValue = initialValue;
  969. this.oldValue = initialValue;
  970. date = this.parseDate(date || initialValue);
  971. if (startDate) {
  972. startDate = this.parseDate(startDate);
  973. if (date.getTime() < startDate.getTime()) {
  974. date = new Date(startDate);
  975. }
  976. this.startDate = startDate;
  977. }
  978. if (endDate) {
  979. endDate = this.parseDate(endDate);
  980. if (startDate && endDate.getTime() < startDate.getTime()) {
  981. endDate = new Date(startDate);
  982. }
  983. if (date.getTime() > endDate.getTime()) {
  984. date = new Date(endDate);
  985. }
  986. this.endDate = endDate;
  987. }
  988. this.date = date;
  989. this.viewDate = new Date(date);
  990. this.initialDate = new Date(this.date);
  991. this.bind();
  992. if (options.autoShow || this.inline) {
  993. this.show();
  994. }
  995. if (options.autoPick) {
  996. this.pick();
  997. }
  998. }
  999. }, {
  1000. key: "build",
  1001. value: function build() {
  1002. if (this.built) {
  1003. return;
  1004. }
  1005. this.built = true;
  1006. var $this = this.$element,
  1007. options = this.options;
  1008. var $picker = $__default['default'](options.template);
  1009. this.$picker = $picker;
  1010. this.$week = $picker.find(selectorOf('week')); // Years view
  1011. this.$yearsPicker = $picker.find(selectorOf('years picker'));
  1012. this.$yearsPrev = $picker.find(selectorOf('years prev'));
  1013. this.$yearsNext = $picker.find(selectorOf('years next'));
  1014. this.$yearsCurrent = $picker.find(selectorOf('years current'));
  1015. this.$years = $picker.find(selectorOf('years')); // Months view
  1016. this.$monthsPicker = $picker.find(selectorOf('months picker'));
  1017. this.$yearPrev = $picker.find(selectorOf('year prev'));
  1018. this.$yearNext = $picker.find(selectorOf('year next'));
  1019. this.$yearCurrent = $picker.find(selectorOf('year current'));
  1020. this.$months = $picker.find(selectorOf('months')); // Days view
  1021. this.$daysPicker = $picker.find(selectorOf('days picker'));
  1022. this.$monthPrev = $picker.find(selectorOf('month prev'));
  1023. this.$monthNext = $picker.find(selectorOf('month next'));
  1024. this.$monthCurrent = $picker.find(selectorOf('month current'));
  1025. this.$days = $picker.find(selectorOf('days'));
  1026. if (this.inline) {
  1027. $__default['default'](options.container || $this).append($picker.addClass("".concat(NAMESPACE, "-inline")));
  1028. } else {
  1029. $__default['default'](document.body).append($picker.addClass("".concat(NAMESPACE, "-dropdown")));
  1030. $picker.addClass(CLASS_HIDE).css({
  1031. zIndex: parseInt(options.zIndex, 10)
  1032. });
  1033. }
  1034. this.renderWeek();
  1035. }
  1036. }, {
  1037. key: "unbuild",
  1038. value: function unbuild() {
  1039. if (!this.built) {
  1040. return;
  1041. }
  1042. this.built = false;
  1043. this.$picker.remove();
  1044. }
  1045. }, {
  1046. key: "bind",
  1047. value: function bind() {
  1048. var options = this.options,
  1049. $this = this.$element;
  1050. if ($__default['default'].isFunction(options.show)) {
  1051. $this.on(EVENT_SHOW, options.show);
  1052. }
  1053. if ($__default['default'].isFunction(options.hide)) {
  1054. $this.on(EVENT_HIDE, options.hide);
  1055. }
  1056. if ($__default['default'].isFunction(options.pick)) {
  1057. $this.on(EVENT_PICK, options.pick);
  1058. }
  1059. if (this.isInput) {
  1060. $this.on(EVENT_KEYUP, $__default['default'].proxy(this.keyup, this));
  1061. }
  1062. if (!this.inline) {
  1063. if (options.trigger) {
  1064. this.$trigger.on(EVENT_CLICK, $__default['default'].proxy(this.toggle, this));
  1065. } else if (this.isInput) {
  1066. $this.on(EVENT_FOCUS, $__default['default'].proxy(this.show, this));
  1067. } else {
  1068. $this.on(EVENT_CLICK, $__default['default'].proxy(this.show, this));
  1069. }
  1070. }
  1071. }
  1072. }, {
  1073. key: "unbind",
  1074. value: function unbind() {
  1075. var $this = this.$element,
  1076. options = this.options;
  1077. if ($__default['default'].isFunction(options.show)) {
  1078. $this.off(EVENT_SHOW, options.show);
  1079. }
  1080. if ($__default['default'].isFunction(options.hide)) {
  1081. $this.off(EVENT_HIDE, options.hide);
  1082. }
  1083. if ($__default['default'].isFunction(options.pick)) {
  1084. $this.off(EVENT_PICK, options.pick);
  1085. }
  1086. if (this.isInput) {
  1087. $this.off(EVENT_KEYUP, this.keyup);
  1088. }
  1089. if (!this.inline) {
  1090. if (options.trigger) {
  1091. this.$trigger.off(EVENT_CLICK, this.toggle);
  1092. } else if (this.isInput) {
  1093. $this.off(EVENT_FOCUS, this.show);
  1094. } else {
  1095. $this.off(EVENT_CLICK, this.show);
  1096. }
  1097. }
  1098. }
  1099. }, {
  1100. key: "showView",
  1101. value: function showView(view) {
  1102. var $yearsPicker = this.$yearsPicker,
  1103. $monthsPicker = this.$monthsPicker,
  1104. $daysPicker = this.$daysPicker,
  1105. format = this.format;
  1106. if (format.hasYear || format.hasMonth || format.hasDay) {
  1107. switch (Number(view)) {
  1108. case VIEWS.YEARS:
  1109. $monthsPicker.addClass(CLASS_HIDE);
  1110. $daysPicker.addClass(CLASS_HIDE);
  1111. if (format.hasYear) {
  1112. this.renderYears();
  1113. $yearsPicker.removeClass(CLASS_HIDE);
  1114. this.place();
  1115. } else {
  1116. this.showView(VIEWS.DAYS);
  1117. }
  1118. break;
  1119. case VIEWS.MONTHS:
  1120. $yearsPicker.addClass(CLASS_HIDE);
  1121. $daysPicker.addClass(CLASS_HIDE);
  1122. if (format.hasMonth) {
  1123. this.renderMonths();
  1124. $monthsPicker.removeClass(CLASS_HIDE);
  1125. this.place();
  1126. } else {
  1127. this.showView(VIEWS.YEARS);
  1128. }
  1129. break;
  1130. // case VIEWS.DAYS:
  1131. default:
  1132. $yearsPicker.addClass(CLASS_HIDE);
  1133. $monthsPicker.addClass(CLASS_HIDE);
  1134. if (format.hasDay) {
  1135. this.renderDays();
  1136. $daysPicker.removeClass(CLASS_HIDE);
  1137. this.place();
  1138. } else {
  1139. this.showView(VIEWS.MONTHS);
  1140. }
  1141. }
  1142. }
  1143. }
  1144. }, {
  1145. key: "hideView",
  1146. value: function hideView() {
  1147. if (!this.inline && this.options.autoHide) {
  1148. this.hide();
  1149. }
  1150. }
  1151. }, {
  1152. key: "place",
  1153. value: function place() {
  1154. if (this.inline) {
  1155. return;
  1156. }
  1157. var $this = this.$element,
  1158. options = this.options,
  1159. $picker = this.$picker;
  1160. var containerWidth = $__default['default'](document).outerWidth();
  1161. var containerHeight = $__default['default'](document).outerHeight();
  1162. var elementWidth = $this.outerWidth();
  1163. var elementHeight = $this.outerHeight();
  1164. var width = $picker.width();
  1165. var height = $picker.height();
  1166. var _$this$offset = $this.offset(),
  1167. left = _$this$offset.left,
  1168. top = _$this$offset.top;
  1169. var offset = parseFloat(options.offset);
  1170. var placement = CLASS_TOP_LEFT;
  1171. if (isNaN(offset)) {
  1172. offset = 10;
  1173. }
  1174. if (top > height && top + elementHeight + height > containerHeight) {
  1175. top -= height + offset;
  1176. placement = CLASS_BOTTOM_LEFT;
  1177. } else {
  1178. top += elementHeight + offset;
  1179. }
  1180. if (left + width > containerWidth) {
  1181. left += elementWidth - width;
  1182. placement = placement.replace('left', 'right');
  1183. }
  1184. $picker.removeClass(CLASS_PLACEMENTS).addClass(placement).css({
  1185. top: top,
  1186. left: left
  1187. });
  1188. } // A shortcut for triggering custom events
  1189. }, {
  1190. key: "trigger",
  1191. value: function trigger(type, data) {
  1192. var e = $__default['default'].Event(type, data);
  1193. this.$element.trigger(e);
  1194. return e;
  1195. }
  1196. }, {
  1197. key: "createItem",
  1198. value: function createItem(data) {
  1199. var options = this.options;
  1200. var itemTag = options.itemTag;
  1201. var item = {
  1202. text: '',
  1203. view: '',
  1204. muted: false,
  1205. picked: false,
  1206. disabled: false,
  1207. highlighted: false
  1208. };
  1209. var classes = [];
  1210. $__default['default'].extend(item, data);
  1211. if (item.muted) {
  1212. classes.push(options.mutedClass);
  1213. }
  1214. if (item.highlighted) {
  1215. classes.push(options.highlightedClass);
  1216. }
  1217. if (item.picked) {
  1218. classes.push(options.pickedClass);
  1219. }
  1220. if (item.disabled) {
  1221. classes.push(options.disabledClass);
  1222. }
  1223. return "<".concat(itemTag, " class=\"").concat(classes.join(' '), "\" data-view=\"").concat(item.view, "\">").concat(item.text, "</").concat(itemTag, ">");
  1224. }
  1225. }, {
  1226. key: "getValue",
  1227. value: function getValue() {
  1228. var $this = this.$element;
  1229. return this.isInput ? $this.val() : $this.text();
  1230. }
  1231. }, {
  1232. key: "setValue",
  1233. value: function setValue() {
  1234. var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  1235. var $this = this.$element;
  1236. if (this.isInput) {
  1237. $this.val(value);
  1238. } else if (!this.inline || this.options.container) {
  1239. $this.text(value);
  1240. }
  1241. }
  1242. }], [{
  1243. key: "setDefaults",
  1244. value: function setDefaults() {
  1245. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  1246. $__default['default'].extend(DEFAULTS, LANGUAGES[options.language], $__default['default'].isPlainObject(options) && options);
  1247. }
  1248. }]);
  1249. return Datepicker;
  1250. }();
  1251. if ($__default['default'].extend) {
  1252. $__default['default'].extend(Datepicker.prototype, render, handlers, methods);
  1253. }
  1254. if ($__default['default'].fn) {
  1255. var AnotherDatepicker = $__default['default'].fn.datepicker;
  1256. $__default['default'].fn.datepicker = function jQueryDatepicker(option) {
  1257. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1258. args[_key - 1] = arguments[_key];
  1259. }
  1260. var result;
  1261. this.each(function (i, element) {
  1262. var $element = $__default['default'](element);
  1263. var isDestroy = option === 'destroy';
  1264. var datepicker = $element.data(NAMESPACE);
  1265. if (!datepicker) {
  1266. if (isDestroy) {
  1267. return;
  1268. }
  1269. var options = $__default['default'].extend({}, $element.data(), $__default['default'].isPlainObject(option) && option);
  1270. datepicker = new Datepicker(element, options);
  1271. $element.data(NAMESPACE, datepicker);
  1272. }
  1273. if (isString(option)) {
  1274. var fn = datepicker[option];
  1275. if ($__default['default'].isFunction(fn)) {
  1276. result = fn.apply(datepicker, args);
  1277. if (isDestroy) {
  1278. $element.removeData(NAMESPACE);
  1279. }
  1280. }
  1281. }
  1282. });
  1283. return !isUndefined(result) ? result : this;
  1284. };
  1285. $__default['default'].fn.datepicker.Constructor = Datepicker;
  1286. $__default['default'].fn.datepicker.languages = LANGUAGES;
  1287. $__default['default'].fn.datepicker.setDefaults = Datepicker.setDefaults;
  1288. $__default['default'].fn.datepicker.noConflict = function noConflict() {
  1289. $__default['default'].fn.datepicker = AnotherDatepicker;
  1290. return this;
  1291. };
  1292. }