1
0

tempusdominus-bootstrap-4.js 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779
  1. /*@preserve
  2. * Tempus Dominus Bootstrap4 v5.1.2 (https://tempusdominus.github.io/bootstrap-4/)
  3. * Copyright 2016-2018 Jonathan Peterson
  4. * Licensed under MIT (https://github.com/tempusdominus/bootstrap-3/blob/master/LICENSE)
  5. */
  6. if (typeof jQuery === 'undefined') {
  7. throw new Error('Tempus Dominus Bootstrap4\'s requires jQuery. jQuery must be included before Tempus Dominus Bootstrap4\'s JavaScript.');
  8. }
  9. +function ($) {
  10. var version = $.fn.jquery.split(' ')[0].split('.');
  11. if ((version[0] < 2 && version[1] < 9) || (version[0] === 1 && version[1] === 9 && version[2] < 1) || (version[0] >= 4)) {
  12. throw new Error('Tempus Dominus Bootstrap4\'s requires at least jQuery v3.0.0 but less than v4.0.0');
  13. }
  14. }(jQuery);
  15. if (typeof moment === 'undefined') {
  16. throw new Error('Tempus Dominus Bootstrap4\'s requires moment.js. Moment.js must be included before Tempus Dominus Bootstrap4\'s JavaScript.');
  17. }
  18. var version = moment.version.split('.')
  19. if ((version[0] <= 2 && version[1] < 17) || (version[0] >= 3)) {
  20. throw new Error('Tempus Dominus Bootstrap4\'s requires at least moment.js v2.17.0 but less than v3.0.0');
  21. }
  22. +function () {
  23. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  24. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  25. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  26. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  27. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  28. // ReSharper disable once InconsistentNaming
  29. var DateTimePicker = function ($, moment) {
  30. // ReSharper disable InconsistentNaming
  31. var NAME = 'datetimepicker',
  32. DATA_KEY = '' + NAME,
  33. EVENT_KEY = '.' + DATA_KEY,
  34. DATA_API_KEY = '.data-api',
  35. Selector = {
  36. DATA_TOGGLE: '[data-toggle="' + DATA_KEY + '"]'
  37. },
  38. ClassName = {
  39. INPUT: NAME + '-input'
  40. },
  41. Event = {
  42. CHANGE: 'change' + EVENT_KEY,
  43. BLUR: 'blur' + EVENT_KEY,
  44. KEYUP: 'keyup' + EVENT_KEY,
  45. KEYDOWN: 'keydown' + EVENT_KEY,
  46. FOCUS: 'focus' + EVENT_KEY,
  47. CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY,
  48. //emitted
  49. UPDATE: 'update' + EVENT_KEY,
  50. ERROR: 'error' + EVENT_KEY,
  51. HIDE: 'hide' + EVENT_KEY,
  52. SHOW: 'show' + EVENT_KEY
  53. },
  54. DatePickerModes = [{
  55. CLASS_NAME: 'days',
  56. NAV_FUNCTION: 'M',
  57. NAV_STEP: 1
  58. }, {
  59. CLASS_NAME: 'months',
  60. NAV_FUNCTION: 'y',
  61. NAV_STEP: 1
  62. }, {
  63. CLASS_NAME: 'years',
  64. NAV_FUNCTION: 'y',
  65. NAV_STEP: 10
  66. }, {
  67. CLASS_NAME: 'decades',
  68. NAV_FUNCTION: 'y',
  69. NAV_STEP: 100
  70. }],
  71. KeyMap = {
  72. 'up': 38,
  73. 38: 'up',
  74. 'down': 40,
  75. 40: 'down',
  76. 'left': 37,
  77. 37: 'left',
  78. 'right': 39,
  79. 39: 'right',
  80. 'tab': 9,
  81. 9: 'tab',
  82. 'escape': 27,
  83. 27: 'escape',
  84. 'enter': 13,
  85. 13: 'enter',
  86. 'pageUp': 33,
  87. 33: 'pageUp',
  88. 'pageDown': 34,
  89. 34: 'pageDown',
  90. 'shift': 16,
  91. 16: 'shift',
  92. 'control': 17,
  93. 17: 'control',
  94. 'space': 32,
  95. 32: 'space',
  96. 't': 84,
  97. 84: 't',
  98. 'delete': 46,
  99. 46: 'delete'
  100. },
  101. ViewModes = ['times', 'days', 'months', 'years', 'decades'],
  102. keyState = {},
  103. keyPressHandled = {};
  104. var Default = {
  105. timeZone: '',
  106. format: false,
  107. dayViewHeaderFormat: 'MMMM YYYY',
  108. extraFormats: false,
  109. stepping: 1,
  110. minDate: false,
  111. maxDate: false,
  112. useCurrent: true,
  113. collapse: true,
  114. locale: moment.locale(),
  115. defaultDate: false,
  116. disabledDates: false,
  117. enabledDates: false,
  118. icons: {
  119. time: 'fa fa-clock-o',
  120. date: 'fa fa-calendar',
  121. up: 'fa fa-arrow-up',
  122. down: 'fa fa-arrow-down',
  123. previous: 'fa fa-chevron-left',
  124. next: 'fa fa-chevron-right',
  125. today: 'fa fa-calendar-check-o',
  126. clear: 'fa fa-delete',
  127. close: 'fa fa-times'
  128. },
  129. tooltips: {
  130. today: 'Go to today',
  131. clear: 'Clear selection',
  132. close: 'Close the picker',
  133. selectMonth: 'Select Month',
  134. prevMonth: 'Previous Month',
  135. nextMonth: 'Next Month',
  136. selectYear: 'Select Year',
  137. prevYear: 'Previous Year',
  138. nextYear: 'Next Year',
  139. selectDecade: 'Select Decade',
  140. prevDecade: 'Previous Decade',
  141. nextDecade: 'Next Decade',
  142. prevCentury: 'Previous Century',
  143. nextCentury: 'Next Century',
  144. pickHour: 'Pick Hour',
  145. incrementHour: 'Increment Hour',
  146. decrementHour: 'Decrement Hour',
  147. pickMinute: 'Pick Minute',
  148. incrementMinute: 'Increment Minute',
  149. decrementMinute: 'Decrement Minute',
  150. pickSecond: 'Pick Second',
  151. incrementSecond: 'Increment Second',
  152. decrementSecond: 'Decrement Second',
  153. togglePeriod: 'Toggle Period',
  154. selectTime: 'Select Time',
  155. selectDate: 'Select Date'
  156. },
  157. useStrict: false,
  158. sideBySide: false,
  159. daysOfWeekDisabled: false,
  160. calendarWeeks: false,
  161. viewMode: 'days',
  162. toolbarPlacement: 'default',
  163. buttons: {
  164. showToday: false,
  165. showClear: false,
  166. showClose: false
  167. },
  168. widgetPositioning: {
  169. horizontal: 'auto',
  170. vertical: 'auto'
  171. },
  172. widgetParent: null,
  173. ignoreReadonly: false,
  174. keepOpen: false,
  175. focusOnShow: true,
  176. inline: false,
  177. keepInvalid: false,
  178. keyBinds: {
  179. up: function up() {
  180. if (!this.widget) {
  181. return false;
  182. }
  183. var d = this._dates[0] || this.getMoment();
  184. if (this.widget.find('.datepicker').is(':visible')) {
  185. this.date(d.clone().subtract(7, 'd'));
  186. } else {
  187. this.date(d.clone().add(this.stepping(), 'm'));
  188. }
  189. return true;
  190. },
  191. down: function down() {
  192. if (!this.widget) {
  193. this.show();
  194. return false;
  195. }
  196. var d = this._dates[0] || this.getMoment();
  197. if (this.widget.find('.datepicker').is(':visible')) {
  198. this.date(d.clone().add(7, 'd'));
  199. } else {
  200. this.date(d.clone().subtract(this.stepping(), 'm'));
  201. }
  202. return true;
  203. },
  204. 'control up': function controlUp() {
  205. if (!this.widget) {
  206. return false;
  207. }
  208. var d = this._dates[0] || this.getMoment();
  209. if (this.widget.find('.datepicker').is(':visible')) {
  210. this.date(d.clone().subtract(1, 'y'));
  211. } else {
  212. this.date(d.clone().add(1, 'h'));
  213. }
  214. return true;
  215. },
  216. 'control down': function controlDown() {
  217. if (!this.widget) {
  218. return false;
  219. }
  220. var d = this._dates[0] || this.getMoment();
  221. if (this.widget.find('.datepicker').is(':visible')) {
  222. this.date(d.clone().add(1, 'y'));
  223. } else {
  224. this.date(d.clone().subtract(1, 'h'));
  225. }
  226. return true;
  227. },
  228. left: function left() {
  229. if (!this.widget) {
  230. return false;
  231. }
  232. var d = this._dates[0] || this.getMoment();
  233. if (this.widget.find('.datepicker').is(':visible')) {
  234. this.date(d.clone().subtract(1, 'd'));
  235. }
  236. return true;
  237. },
  238. right: function right() {
  239. if (!this.widget) {
  240. return false;
  241. }
  242. var d = this._dates[0] || this.getMoment();
  243. if (this.widget.find('.datepicker').is(':visible')) {
  244. this.date(d.clone().add(1, 'd'));
  245. }
  246. return true;
  247. },
  248. pageUp: function pageUp() {
  249. if (!this.widget) {
  250. return false;
  251. }
  252. var d = this._dates[0] || this.getMoment();
  253. if (this.widget.find('.datepicker').is(':visible')) {
  254. this.date(d.clone().subtract(1, 'M'));
  255. }
  256. return true;
  257. },
  258. pageDown: function pageDown() {
  259. if (!this.widget) {
  260. return false;
  261. }
  262. var d = this._dates[0] || this.getMoment();
  263. if (this.widget.find('.datepicker').is(':visible')) {
  264. this.date(d.clone().add(1, 'M'));
  265. }
  266. return true;
  267. },
  268. enter: function enter() {
  269. if (!this.widget) {
  270. return false;
  271. }
  272. this.hide();
  273. return true;
  274. },
  275. escape: function escape() {
  276. if (!this.widget) {
  277. return false;
  278. }
  279. this.hide();
  280. return true;
  281. },
  282. 'control space': function controlSpace() {
  283. if (!this.widget) {
  284. return false;
  285. }
  286. if (this.widget.find('.timepicker').is(':visible')) {
  287. this.widget.find('.btn[data-action="togglePeriod"]').click();
  288. }
  289. return true;
  290. },
  291. t: function t() {
  292. if (!this.widget) {
  293. return false;
  294. }
  295. this.date(this.getMoment());
  296. return true;
  297. },
  298. 'delete': function _delete() {
  299. if (!this.widget) {
  300. return false;
  301. }
  302. this.clear();
  303. return true;
  304. }
  305. },
  306. debug: false,
  307. allowInputToggle: false,
  308. disabledTimeIntervals: false,
  309. disabledHours: false,
  310. enabledHours: false,
  311. viewDate: false,
  312. allowMultidate: false,
  313. multidateSeparator: ','
  314. };
  315. // ReSharper restore InconsistentNaming
  316. // ReSharper disable once DeclarationHides
  317. // ReSharper disable once InconsistentNaming
  318. var DateTimePicker = function () {
  319. /** @namespace eData.dateOptions */
  320. /** @namespace moment.tz */
  321. function DateTimePicker(element, options) {
  322. _classCallCheck(this, DateTimePicker);
  323. this._options = this._getOptions(options);
  324. this._element = element;
  325. this._dates = [];
  326. this._datesFormatted = [];
  327. this._viewDate = null;
  328. this.unset = true;
  329. this.component = false;
  330. this.widget = false;
  331. this.use24Hours = null;
  332. this.actualFormat = null;
  333. this.parseFormats = null;
  334. this.currentViewMode = null;
  335. this.MinViewModeNumber = 0;
  336. this._int();
  337. }
  338. /**
  339. * @return {string}
  340. */
  341. //private
  342. DateTimePicker.prototype._int = function _int() {
  343. var targetInput = this._element.data('target-input');
  344. if (this._element.is('input')) {
  345. this.input = this._element;
  346. } else if (targetInput !== undefined) {
  347. if (targetInput === 'nearest') {
  348. this.input = this._element.find('input');
  349. } else {
  350. this.input = $(targetInput);
  351. }
  352. }
  353. this._dates = [];
  354. this._dates[0] = this.getMoment();
  355. this._viewDate = this.getMoment().clone();
  356. $.extend(true, this._options, this._dataToOptions());
  357. this.options(this._options);
  358. this._initFormatting();
  359. if (this.input !== undefined && this.input.is('input') && this.input.val().trim().length !== 0) {
  360. this._setValue(this._parseInputDate(this.input.val().trim()), 0);
  361. } else if (this._options.defaultDate && this.input !== undefined && this.input.attr('placeholder') === undefined) {
  362. this._setValue(this._options.defaultDate, 0);
  363. }
  364. if (this._options.inline) {
  365. this.show();
  366. }
  367. };
  368. DateTimePicker.prototype._update = function _update() {
  369. if (!this.widget) {
  370. return;
  371. }
  372. this._fillDate();
  373. this._fillTime();
  374. };
  375. DateTimePicker.prototype._setValue = function _setValue(targetMoment, index) {
  376. var oldDate = this.unset ? null : this._dates[index];
  377. var outpValue = '';
  378. // case of calling setValue(null or false)
  379. if (!targetMoment) {
  380. if (!this._options.allowMultidate || this._dates.length === 1) {
  381. this.unset = true;
  382. this._dates = [];
  383. this._datesFormatted = [];
  384. } else {
  385. outpValue = this._element.data('date') + ',';
  386. outpValue = outpValue.replace(oldDate.format(this.actualFormat) + ',', '').replace(',,', '').replace(/,\s*$/, '');
  387. this._dates.splice(index, 1);
  388. this._datesFormatted.splice(index, 1);
  389. }
  390. if (this.input !== undefined) {
  391. this.input.val(outpValue);
  392. this.input.trigger('input');
  393. }
  394. this._element.data('date', outpValue);
  395. this._notifyEvent({
  396. type: DateTimePicker.Event.CHANGE,
  397. date: false,
  398. oldDate: oldDate
  399. });
  400. this._update();
  401. return;
  402. }
  403. targetMoment = targetMoment.clone().locale(this._options.locale);
  404. if (this._hasTimeZone()) {
  405. targetMoment.tz(this._options.timeZone);
  406. }
  407. if (this._options.stepping !== 1) {
  408. targetMoment.minutes(Math.round(targetMoment.minutes() / this._options.stepping) * this._options.stepping).seconds(0);
  409. }
  410. if (this._isValid(targetMoment)) {
  411. this._dates[index] = targetMoment;
  412. this._datesFormatted[index] = targetMoment.format('YYYY-MM-DD');
  413. this._viewDate = targetMoment.clone();
  414. if (this._options.allowMultidate && this._dates.length > 1) {
  415. for (var i = 0; i < this._dates.length; i++) {
  416. outpValue += '' + this._dates[i].format(this.actualFormat) + this._options.multidateSeparator;
  417. }
  418. outpValue = outpValue.replace(/,\s*$/, '');
  419. } else {
  420. outpValue = this._dates[index].format(this.actualFormat);
  421. }
  422. if (this.input !== undefined) {
  423. this.input.val(outpValue);
  424. this.input.trigger('input');
  425. }
  426. this._element.data('date', outpValue);
  427. this.unset = false;
  428. this._update();
  429. this._notifyEvent({
  430. type: DateTimePicker.Event.CHANGE,
  431. date: this._dates[index].clone(),
  432. oldDate: oldDate
  433. });
  434. } else {
  435. if (!this._options.keepInvalid) {
  436. if (this.input !== undefined) {
  437. this.input.val('' + (this.unset ? '' : this._dates[index].format(this.actualFormat)));
  438. this.input.trigger('input');
  439. }
  440. } else {
  441. this._notifyEvent({
  442. type: DateTimePicker.Event.CHANGE,
  443. date: targetMoment,
  444. oldDate: oldDate
  445. });
  446. }
  447. this._notifyEvent({
  448. type: DateTimePicker.Event.ERROR,
  449. date: targetMoment,
  450. oldDate: oldDate
  451. });
  452. }
  453. };
  454. DateTimePicker.prototype._change = function _change(e) {
  455. var val = $(e.target).val().trim(),
  456. parsedDate = val ? this._parseInputDate(val) : null;
  457. this._setValue(parsedDate);
  458. e.stopImmediatePropagation();
  459. return false;
  460. };
  461. //noinspection JSMethodCanBeStatic
  462. DateTimePicker.prototype._getOptions = function _getOptions(options) {
  463. options = $.extend(true, {}, Default, options);
  464. return options;
  465. };
  466. DateTimePicker.prototype._hasTimeZone = function _hasTimeZone() {
  467. return moment.tz !== undefined && this._options.timeZone !== undefined && this._options.timeZone !== null && this._options.timeZone !== '';
  468. };
  469. DateTimePicker.prototype._isEnabled = function _isEnabled(granularity) {
  470. if (typeof granularity !== 'string' || granularity.length > 1) {
  471. throw new TypeError('isEnabled expects a single character string parameter');
  472. }
  473. switch (granularity) {
  474. case 'y':
  475. return this.actualFormat.indexOf('Y') !== -1;
  476. case 'M':
  477. return this.actualFormat.indexOf('M') !== -1;
  478. case 'd':
  479. return this.actualFormat.toLowerCase().indexOf('d') !== -1;
  480. case 'h':
  481. case 'H':
  482. return this.actualFormat.toLowerCase().indexOf('h') !== -1;
  483. case 'm':
  484. return this.actualFormat.indexOf('m') !== -1;
  485. case 's':
  486. return this.actualFormat.indexOf('s') !== -1;
  487. case 'a':
  488. case 'A':
  489. return this.actualFormat.toLowerCase().indexOf('a') !== -1;
  490. default:
  491. return false;
  492. }
  493. };
  494. DateTimePicker.prototype._hasTime = function _hasTime() {
  495. return this._isEnabled('h') || this._isEnabled('m') || this._isEnabled('s');
  496. };
  497. DateTimePicker.prototype._hasDate = function _hasDate() {
  498. return this._isEnabled('y') || this._isEnabled('M') || this._isEnabled('d');
  499. };
  500. DateTimePicker.prototype._dataToOptions = function _dataToOptions() {
  501. var eData = this._element.data();
  502. var dataOptions = {};
  503. if (eData.dateOptions && eData.dateOptions instanceof Object) {
  504. dataOptions = $.extend(true, dataOptions, eData.dateOptions);
  505. }
  506. $.each(this._options, function (key) {
  507. var attributeName = 'date' + key.charAt(0).toUpperCase() + key.slice(1); //todo data api key
  508. if (eData[attributeName] !== undefined) {
  509. dataOptions[key] = eData[attributeName];
  510. } else {
  511. delete dataOptions[key];
  512. }
  513. });
  514. return dataOptions;
  515. };
  516. DateTimePicker.prototype._notifyEvent = function _notifyEvent(e) {
  517. if (e.type === DateTimePicker.Event.CHANGE && (e.date && e.date.isSame(e.oldDate)) || !e.date && !e.oldDate) {
  518. return;
  519. }
  520. this._element.trigger(e);
  521. };
  522. DateTimePicker.prototype._viewUpdate = function _viewUpdate(e) {
  523. if (e === 'y') {
  524. e = 'YYYY';
  525. }
  526. this._notifyEvent({
  527. type: DateTimePicker.Event.UPDATE,
  528. change: e,
  529. viewDate: this._viewDate.clone()
  530. });
  531. };
  532. DateTimePicker.prototype._showMode = function _showMode(dir) {
  533. if (!this.widget) {
  534. return;
  535. }
  536. if (dir) {
  537. this.currentViewMode = Math.max(this.MinViewModeNumber, Math.min(3, this.currentViewMode + dir));
  538. }
  539. this.widget.find('.datepicker > div').hide().filter('.datepicker-' + DatePickerModes[this.currentViewMode].CLASS_NAME).show();
  540. };
  541. DateTimePicker.prototype._isInDisabledDates = function _isInDisabledDates(testDate) {
  542. return this._options.disabledDates[testDate.format('YYYY-MM-DD')] === true;
  543. };
  544. DateTimePicker.prototype._isInEnabledDates = function _isInEnabledDates(testDate) {
  545. return this._options.enabledDates[testDate.format('YYYY-MM-DD')] === true;
  546. };
  547. DateTimePicker.prototype._isInDisabledHours = function _isInDisabledHours(testDate) {
  548. return this._options.disabledHours[testDate.format('H')] === true;
  549. };
  550. DateTimePicker.prototype._isInEnabledHours = function _isInEnabledHours(testDate) {
  551. return this._options.enabledHours[testDate.format('H')] === true;
  552. };
  553. DateTimePicker.prototype._isValid = function _isValid(targetMoment, granularity) {
  554. if (!targetMoment.isValid()) {
  555. return false;
  556. }
  557. if (this._options.disabledDates && granularity === 'd' && this._isInDisabledDates(targetMoment)) {
  558. return false;
  559. }
  560. if (this._options.enabledDates && granularity === 'd' && !this._isInEnabledDates(targetMoment)) {
  561. return false;
  562. }
  563. if (this._options.minDate && targetMoment.isBefore(this._options.minDate, granularity)) {
  564. return false;
  565. }
  566. if (this._options.maxDate && targetMoment.isAfter(this._options.maxDate, granularity)) {
  567. return false;
  568. }
  569. if (this._options.daysOfWeekDisabled && granularity === 'd' && this._options.daysOfWeekDisabled.indexOf(targetMoment.day()) !== -1) {
  570. return false;
  571. }
  572. if (this._options.disabledHours && (granularity === 'h' || granularity === 'm' || granularity === 's') && this._isInDisabledHours(targetMoment)) {
  573. return false;
  574. }
  575. if (this._options.enabledHours && (granularity === 'h' || granularity === 'm' || granularity === 's') && !this._isInEnabledHours(targetMoment)) {
  576. return false;
  577. }
  578. if (this._options.disabledTimeIntervals && (granularity === 'h' || granularity === 'm' || granularity === 's')) {
  579. var found = false;
  580. $.each(this._options.disabledTimeIntervals, function () {
  581. if (targetMoment.isBetween(this[0], this[1])) {
  582. found = true;
  583. return false;
  584. }
  585. });
  586. if (found) {
  587. return false;
  588. }
  589. }
  590. return true;
  591. };
  592. DateTimePicker.prototype._parseInputDate = function _parseInputDate(inputDate) {
  593. if (this._options.parseInputDate === undefined) {
  594. if (!moment.isMoment(inputDate)) {
  595. inputDate = this.getMoment(inputDate);
  596. }
  597. } else {
  598. inputDate = this._options.parseInputDate(inputDate);
  599. }
  600. //inputDate.locale(this.options.locale);
  601. return inputDate;
  602. };
  603. DateTimePicker.prototype._keydown = function _keydown(e) {
  604. var handler = null,
  605. index = void 0,
  606. index2 = void 0,
  607. keyBindKeys = void 0,
  608. allModifiersPressed = void 0;
  609. var pressedKeys = [],
  610. pressedModifiers = {},
  611. currentKey = e.which,
  612. pressed = 'p';
  613. keyState[currentKey] = pressed;
  614. for (index in keyState) {
  615. if (keyState.hasOwnProperty(index) && keyState[index] === pressed) {
  616. pressedKeys.push(index);
  617. if (parseInt(index, 10) !== currentKey) {
  618. pressedModifiers[index] = true;
  619. }
  620. }
  621. }
  622. for (index in this._options.keyBinds) {
  623. if (this._options.keyBinds.hasOwnProperty(index) && typeof this._options.keyBinds[index] === 'function') {
  624. keyBindKeys = index.split(' ');
  625. if (keyBindKeys.length === pressedKeys.length && KeyMap[currentKey] === keyBindKeys[keyBindKeys.length - 1]) {
  626. allModifiersPressed = true;
  627. for (index2 = keyBindKeys.length - 2; index2 >= 0; index2--) {
  628. if (!(KeyMap[keyBindKeys[index2]] in pressedModifiers)) {
  629. allModifiersPressed = false;
  630. break;
  631. }
  632. }
  633. if (allModifiersPressed) {
  634. handler = this._options.keyBinds[index];
  635. break;
  636. }
  637. }
  638. }
  639. }
  640. if (handler) {
  641. if (handler.call(this)) {
  642. e.stopPropagation();
  643. e.preventDefault();
  644. }
  645. }
  646. };
  647. //noinspection JSMethodCanBeStatic,SpellCheckingInspection
  648. DateTimePicker.prototype._keyup = function _keyup(e) {
  649. keyState[e.which] = 'r';
  650. if (keyPressHandled[e.which]) {
  651. keyPressHandled[e.which] = false;
  652. e.stopPropagation();
  653. e.preventDefault();
  654. }
  655. };
  656. DateTimePicker.prototype._indexGivenDates = function _indexGivenDates(givenDatesArray) {
  657. // Store given enabledDates and disabledDates as keys.
  658. // This way we can check their existence in O(1) time instead of looping through whole array.
  659. // (for example: options.enabledDates['2014-02-27'] === true)
  660. var givenDatesIndexed = {},
  661. self = this;
  662. $.each(givenDatesArray, function () {
  663. var dDate = self._parseInputDate(this);
  664. if (dDate.isValid()) {
  665. givenDatesIndexed[dDate.format('YYYY-MM-DD')] = true;
  666. }
  667. });
  668. return Object.keys(givenDatesIndexed).length ? givenDatesIndexed : false;
  669. };
  670. DateTimePicker.prototype._indexGivenHours = function _indexGivenHours(givenHoursArray) {
  671. // Store given enabledHours and disabledHours as keys.
  672. // This way we can check their existence in O(1) time instead of looping through whole array.
  673. // (for example: options.enabledHours['2014-02-27'] === true)
  674. var givenHoursIndexed = {};
  675. $.each(givenHoursArray, function () {
  676. givenHoursIndexed[this] = true;
  677. });
  678. return Object.keys(givenHoursIndexed).length ? givenHoursIndexed : false;
  679. };
  680. DateTimePicker.prototype._initFormatting = function _initFormatting() {
  681. var format = this._options.format || 'L LT',
  682. self = this;
  683. this.actualFormat = format.replace(/(\[[^\[]*])|(\\)?(LTS|LT|LL?L?L?|l{1,4})/g, function (formatInput) {
  684. return self._dates[0].localeData().longDateFormat(formatInput) || formatInput; //todo taking the first date should be ok
  685. });
  686. this.parseFormats = this._options.extraFormats ? this._options.extraFormats.slice() : [];
  687. if (this.parseFormats.indexOf(format) < 0 && this.parseFormats.indexOf(this.actualFormat) < 0) {
  688. this.parseFormats.push(this.actualFormat);
  689. }
  690. this.use24Hours = this.actualFormat.toLowerCase().indexOf('a') < 1 && this.actualFormat.replace(/\[.*?]/g, '').indexOf('h') < 1;
  691. if (this._isEnabled('y')) {
  692. this.MinViewModeNumber = 2;
  693. }
  694. if (this._isEnabled('M')) {
  695. this.MinViewModeNumber = 1;
  696. }
  697. if (this._isEnabled('d')) {
  698. this.MinViewModeNumber = 0;
  699. }
  700. this.currentViewMode = Math.max(this.MinViewModeNumber, this.currentViewMode);
  701. if (!this.unset) {
  702. this._setValue(this._dates[0], 0);
  703. }
  704. };
  705. DateTimePicker.prototype._getLastPickedDate = function _getLastPickedDate() {
  706. return this._dates[this._getLastPickedDateIndex()];
  707. };
  708. DateTimePicker.prototype._getLastPickedDateIndex = function _getLastPickedDateIndex() {
  709. return this._dates.length - 1;
  710. };
  711. //public
  712. DateTimePicker.prototype.getMoment = function getMoment(d) {
  713. var returnMoment = void 0;
  714. if (d === undefined || d === null) {
  715. returnMoment = moment(); //TODO should this use format? and locale?
  716. } else if (this._hasTimeZone()) {
  717. // There is a string to parse and a default time zone
  718. // parse with the tz function which takes a default time zone if it is not in the format string
  719. returnMoment = moment.tz(d, this.parseFormats, this._options.locale, this._options.useStrict, this._options.timeZone);
  720. } else {
  721. returnMoment = moment(d, this.parseFormats, this._options.locale, this._options.useStrict);
  722. }
  723. if (this._hasTimeZone()) {
  724. returnMoment.tz(this._options.timeZone);
  725. }
  726. return returnMoment;
  727. };
  728. DateTimePicker.prototype.toggle = function toggle() {
  729. return this.widget ? this.hide() : this.show();
  730. };
  731. DateTimePicker.prototype.ignoreReadonly = function ignoreReadonly(_ignoreReadonly) {
  732. if (arguments.length === 0) {
  733. return this._options.ignoreReadonly;
  734. }
  735. if (typeof _ignoreReadonly !== 'boolean') {
  736. throw new TypeError('ignoreReadonly () expects a boolean parameter');
  737. }
  738. this._options.ignoreReadonly = _ignoreReadonly;
  739. };
  740. DateTimePicker.prototype.options = function options(newOptions) {
  741. if (arguments.length === 0) {
  742. return $.extend(true, {}, this._options);
  743. }
  744. if (!(newOptions instanceof Object)) {
  745. throw new TypeError('options() this.options parameter should be an object');
  746. }
  747. $.extend(true, this._options, newOptions);
  748. var self = this;
  749. $.each(this._options, function (key, value) {
  750. if (self[key] !== undefined) {
  751. self[key](value);
  752. }
  753. });
  754. };
  755. DateTimePicker.prototype.date = function date(newDate, index) {
  756. index = index || 0;
  757. if (arguments.length === 0) {
  758. if (this.unset) {
  759. return null;
  760. }
  761. if (this._options.allowMultidate) {
  762. return this._dates.join(this._options.multidateSeparator);
  763. } else {
  764. return this._dates[index].clone();
  765. }
  766. }
  767. if (newDate !== null && typeof newDate !== 'string' && !moment.isMoment(newDate) && !(newDate instanceof Date)) {
  768. throw new TypeError('date() parameter must be one of [null, string, moment or Date]');
  769. }
  770. this._setValue(newDate === null ? null : this._parseInputDate(newDate), index);
  771. };
  772. DateTimePicker.prototype.format = function format(newFormat) {
  773. if (arguments.length === 0) {
  774. return this._options.format;
  775. }
  776. if (typeof newFormat !== 'string' && (typeof newFormat !== 'boolean' || newFormat !== false)) {
  777. throw new TypeError('format() expects a string or boolean:false parameter ' + newFormat);
  778. }
  779. this._options.format = newFormat;
  780. if (this.actualFormat) {
  781. this._initFormatting(); // reinitialize formatting
  782. }
  783. };
  784. DateTimePicker.prototype.timeZone = function timeZone(newZone) {
  785. if (arguments.length === 0) {
  786. return this._options.timeZone;
  787. }
  788. if (typeof newZone !== 'string') {
  789. throw new TypeError('newZone() expects a string parameter');
  790. }
  791. this._options.timeZone = newZone;
  792. };
  793. DateTimePicker.prototype.dayViewHeaderFormat = function dayViewHeaderFormat(newFormat) {
  794. if (arguments.length === 0) {
  795. return this._options.dayViewHeaderFormat;
  796. }
  797. if (typeof newFormat !== 'string') {
  798. throw new TypeError('dayViewHeaderFormat() expects a string parameter');
  799. }
  800. this._options.dayViewHeaderFormat = newFormat;
  801. };
  802. DateTimePicker.prototype.extraFormats = function extraFormats(formats) {
  803. if (arguments.length === 0) {
  804. return this._options.extraFormats;
  805. }
  806. if (formats !== false && !(formats instanceof Array)) {
  807. throw new TypeError('extraFormats() expects an array or false parameter');
  808. }
  809. this._options.extraFormats = formats;
  810. if (this.parseFormats) {
  811. this._initFormatting(); // reinit formatting
  812. }
  813. };
  814. DateTimePicker.prototype.disabledDates = function disabledDates(dates) {
  815. if (arguments.length === 0) {
  816. return this._options.disabledDates ? $.extend({}, this._options.disabledDates) : this._options.disabledDates;
  817. }
  818. if (!dates) {
  819. this._options.disabledDates = false;
  820. this._update();
  821. return true;
  822. }
  823. if (!(dates instanceof Array)) {
  824. throw new TypeError('disabledDates() expects an array parameter');
  825. }
  826. this._options.disabledDates = this._indexGivenDates(dates);
  827. this._options.enabledDates = false;
  828. this._update();
  829. };
  830. DateTimePicker.prototype.enabledDates = function enabledDates(dates) {
  831. if (arguments.length === 0) {
  832. return this._options.enabledDates ? $.extend({}, this._options.enabledDates) : this._options.enabledDates;
  833. }
  834. if (!dates) {
  835. this._options.enabledDates = false;
  836. this._update();
  837. return true;
  838. }
  839. if (!(dates instanceof Array)) {
  840. throw new TypeError('enabledDates() expects an array parameter');
  841. }
  842. this._options.enabledDates = this._indexGivenDates(dates);
  843. this._options.disabledDates = false;
  844. this._update();
  845. };
  846. DateTimePicker.prototype.daysOfWeekDisabled = function daysOfWeekDisabled(_daysOfWeekDisabled) {
  847. if (arguments.length === 0) {
  848. return this._options.daysOfWeekDisabled.splice(0);
  849. }
  850. if (typeof _daysOfWeekDisabled === 'boolean' && !_daysOfWeekDisabled) {
  851. this._options.daysOfWeekDisabled = false;
  852. this._update();
  853. return true;
  854. }
  855. if (!(_daysOfWeekDisabled instanceof Array)) {
  856. throw new TypeError('daysOfWeekDisabled() expects an array parameter');
  857. }
  858. this._options.daysOfWeekDisabled = _daysOfWeekDisabled.reduce(function (previousValue, currentValue) {
  859. currentValue = parseInt(currentValue, 10);
  860. if (currentValue > 6 || currentValue < 0 || isNaN(currentValue)) {
  861. return previousValue;
  862. }
  863. if (previousValue.indexOf(currentValue) === -1) {
  864. previousValue.push(currentValue);
  865. }
  866. return previousValue;
  867. }, []).sort();
  868. if (this._options.useCurrent && !this._options.keepInvalid) {
  869. for (var i = 0; i < this._dates.length; i++) {
  870. var tries = 0;
  871. while (!this._isValid(this._dates[i], 'd')) {
  872. this._dates[i].add(1, 'd');
  873. if (tries === 31) {
  874. throw 'Tried 31 times to find a valid date';
  875. }
  876. tries++;
  877. }
  878. this._setValue(this._dates[i], i);
  879. }
  880. }
  881. this._update();
  882. };
  883. DateTimePicker.prototype.maxDate = function maxDate(_maxDate) {
  884. if (arguments.length === 0) {
  885. return this._options.maxDate ? this._options.maxDate.clone() : this._options.maxDate;
  886. }
  887. if (typeof _maxDate === 'boolean' && _maxDate === false) {
  888. this._options.maxDate = false;
  889. this._update();
  890. return true;
  891. }
  892. if (typeof _maxDate === 'string') {
  893. if (_maxDate === 'now' || _maxDate === 'moment') {
  894. _maxDate = this.getMoment();
  895. }
  896. }
  897. var parsedDate = this._parseInputDate(_maxDate);
  898. if (!parsedDate.isValid()) {
  899. throw new TypeError('maxDate() Could not parse date parameter: ' + _maxDate);
  900. }
  901. if (this._options.minDate && parsedDate.isBefore(this._options.minDate)) {
  902. throw new TypeError('maxDate() date parameter is before this.options.minDate: ' + parsedDate.format(this.actualFormat));
  903. }
  904. this._options.maxDate = parsedDate;
  905. for (var i = 0; i < this._dates.length; i++) {
  906. if (this._options.useCurrent && !this._options.keepInvalid && this._dates[i].isAfter(_maxDate)) {
  907. this._setValue(this._options.maxDate, i);
  908. }
  909. }
  910. if (this._viewDate.isAfter(parsedDate)) {
  911. this._viewDate = parsedDate.clone().subtract(this._options.stepping, 'm');
  912. }
  913. this._update();
  914. };
  915. DateTimePicker.prototype.minDate = function minDate(_minDate) {
  916. if (arguments.length === 0) {
  917. return this._options.minDate ? this._options.minDate.clone() : this._options.minDate;
  918. }
  919. if (typeof _minDate === 'boolean' && _minDate === false) {
  920. this._options.minDate = false;
  921. this._update();
  922. return true;
  923. }
  924. if (typeof _minDate === 'string') {
  925. if (_minDate === 'now' || _minDate === 'moment') {
  926. _minDate = this.getMoment();
  927. }
  928. }
  929. var parsedDate = this._parseInputDate(_minDate);
  930. if (!parsedDate.isValid()) {
  931. throw new TypeError('minDate() Could not parse date parameter: ' + _minDate);
  932. }
  933. if (this._options.maxDate && parsedDate.isAfter(this._options.maxDate)) {
  934. throw new TypeError('minDate() date parameter is after this.options.maxDate: ' + parsedDate.format(this.actualFormat));
  935. }
  936. this._options.minDate = parsedDate;
  937. for (var i = 0; i < this._dates.length; i++) {
  938. if (this._options.useCurrent && !this._options.keepInvalid && this._dates[i].isBefore(_minDate)) {
  939. this._setValue(this._options.minDate, i);
  940. }
  941. }
  942. if (this._viewDate.isBefore(parsedDate)) {
  943. this._viewDate = parsedDate.clone().add(this._options.stepping, 'm');
  944. }
  945. this._update();
  946. };
  947. DateTimePicker.prototype.defaultDate = function defaultDate(_defaultDate) {
  948. if (arguments.length === 0) {
  949. return this._options.defaultDate ? this._options.defaultDate.clone() : this._options.defaultDate;
  950. }
  951. if (!_defaultDate) {
  952. this._options.defaultDate = false;
  953. return true;
  954. }
  955. if (typeof _defaultDate === 'string') {
  956. if (_defaultDate === 'now' || _defaultDate === 'moment') {
  957. _defaultDate = this.getMoment();
  958. } else {
  959. _defaultDate = this.getMoment(_defaultDate);
  960. }
  961. }
  962. var parsedDate = this._parseInputDate(_defaultDate);
  963. if (!parsedDate.isValid()) {
  964. throw new TypeError('defaultDate() Could not parse date parameter: ' + _defaultDate);
  965. }
  966. if (!this._isValid(parsedDate)) {
  967. throw new TypeError('defaultDate() date passed is invalid according to component setup validations');
  968. }
  969. this._options.defaultDate = parsedDate;
  970. if (this._options.defaultDate && this._options.inline || this.input !== undefined && this.input.val().trim() === '') {
  971. this._setValue(this._options.defaultDate, 0);
  972. }
  973. };
  974. DateTimePicker.prototype.locale = function locale(_locale) {
  975. if (arguments.length === 0) {
  976. return this._options.locale;
  977. }
  978. if (!moment.localeData(_locale)) {
  979. throw new TypeError('locale() locale ' + _locale + ' is not loaded from moment locales!');
  980. }
  981. this._options.locale = _locale;
  982. for (var i = 0; i < this._dates.length; i++) {
  983. this._dates[i].locale(this._options.locale);
  984. }
  985. this._viewDate.locale(this._options.locale);
  986. if (this.actualFormat) {
  987. this._initFormatting(); // reinitialize formatting
  988. }
  989. if (this.widget) {
  990. this.hide();
  991. this.show();
  992. }
  993. };
  994. DateTimePicker.prototype.stepping = function stepping(_stepping) {
  995. if (arguments.length === 0) {
  996. return this._options.stepping;
  997. }
  998. _stepping = parseInt(_stepping, 10);
  999. if (isNaN(_stepping) || _stepping < 1) {
  1000. _stepping = 1;
  1001. }
  1002. this._options.stepping = _stepping;
  1003. };
  1004. DateTimePicker.prototype.useCurrent = function useCurrent(_useCurrent) {
  1005. var useCurrentOptions = ['year', 'month', 'day', 'hour', 'minute'];
  1006. if (arguments.length === 0) {
  1007. return this._options.useCurrent;
  1008. }
  1009. if (typeof _useCurrent !== 'boolean' && typeof _useCurrent !== 'string') {
  1010. throw new TypeError('useCurrent() expects a boolean or string parameter');
  1011. }
  1012. if (typeof _useCurrent === 'string' && useCurrentOptions.indexOf(_useCurrent.toLowerCase()) === -1) {
  1013. throw new TypeError('useCurrent() expects a string parameter of ' + useCurrentOptions.join(', '));
  1014. }
  1015. this._options.useCurrent = _useCurrent;
  1016. };
  1017. DateTimePicker.prototype.collapse = function collapse(_collapse) {
  1018. if (arguments.length === 0) {
  1019. return this._options.collapse;
  1020. }
  1021. if (typeof _collapse !== 'boolean') {
  1022. throw new TypeError('collapse() expects a boolean parameter');
  1023. }
  1024. if (this._options.collapse === _collapse) {
  1025. return true;
  1026. }
  1027. this._options.collapse = _collapse;
  1028. if (this.widget) {
  1029. this.hide();
  1030. this.show();
  1031. }
  1032. };
  1033. DateTimePicker.prototype.icons = function icons(_icons) {
  1034. if (arguments.length === 0) {
  1035. return $.extend({}, this._options.icons);
  1036. }
  1037. if (!(_icons instanceof Object)) {
  1038. throw new TypeError('icons() expects parameter to be an Object');
  1039. }
  1040. $.extend(this._options.icons, _icons);
  1041. if (this.widget) {
  1042. this.hide();
  1043. this.show();
  1044. }
  1045. };
  1046. DateTimePicker.prototype.tooltips = function tooltips(_tooltips) {
  1047. if (arguments.length === 0) {
  1048. return $.extend({}, this._options.tooltips);
  1049. }
  1050. if (!(_tooltips instanceof Object)) {
  1051. throw new TypeError('tooltips() expects parameter to be an Object');
  1052. }
  1053. $.extend(this._options.tooltips, _tooltips);
  1054. if (this.widget) {
  1055. this.hide();
  1056. this.show();
  1057. }
  1058. };
  1059. DateTimePicker.prototype.useStrict = function useStrict(_useStrict) {
  1060. if (arguments.length === 0) {
  1061. return this._options.useStrict;
  1062. }
  1063. if (typeof _useStrict !== 'boolean') {
  1064. throw new TypeError('useStrict() expects a boolean parameter');
  1065. }
  1066. this._options.useStrict = _useStrict;
  1067. };
  1068. DateTimePicker.prototype.sideBySide = function sideBySide(_sideBySide) {
  1069. if (arguments.length === 0) {
  1070. return this._options.sideBySide;
  1071. }
  1072. if (typeof _sideBySide !== 'boolean') {
  1073. throw new TypeError('sideBySide() expects a boolean parameter');
  1074. }
  1075. this._options.sideBySide = _sideBySide;
  1076. if (this.widget) {
  1077. this.hide();
  1078. this.show();
  1079. }
  1080. };
  1081. DateTimePicker.prototype.viewMode = function viewMode(_viewMode) {
  1082. if (arguments.length === 0) {
  1083. return this._options.viewMode;
  1084. }
  1085. if (typeof _viewMode !== 'string') {
  1086. throw new TypeError('viewMode() expects a string parameter');
  1087. }
  1088. if (DateTimePicker.ViewModes.indexOf(_viewMode) === -1) {
  1089. throw new TypeError('viewMode() parameter must be one of (' + DateTimePicker.ViewModes.join(', ') + ') value');
  1090. }
  1091. this._options.viewMode = _viewMode;
  1092. this.currentViewMode = Math.max(DateTimePicker.ViewModes.indexOf(_viewMode) - 1, this.MinViewModeNumber);
  1093. this._showMode();
  1094. };
  1095. DateTimePicker.prototype.calendarWeeks = function calendarWeeks(_calendarWeeks) {
  1096. if (arguments.length === 0) {
  1097. return this._options.calendarWeeks;
  1098. }
  1099. if (typeof _calendarWeeks !== 'boolean') {
  1100. throw new TypeError('calendarWeeks() expects parameter to be a boolean value');
  1101. }
  1102. this._options.calendarWeeks = _calendarWeeks;
  1103. this._update();
  1104. };
  1105. DateTimePicker.prototype.buttons = function buttons(_buttons) {
  1106. if (arguments.length === 0) {
  1107. return $.extend({}, this._options.buttons);
  1108. }
  1109. if (!(_buttons instanceof Object)) {
  1110. throw new TypeError('buttons() expects parameter to be an Object');
  1111. }
  1112. $.extend(this._options.buttons, _buttons);
  1113. if (typeof this._options.buttons.showToday !== 'boolean') {
  1114. throw new TypeError('buttons.showToday expects a boolean parameter');
  1115. }
  1116. if (typeof this._options.buttons.showClear !== 'boolean') {
  1117. throw new TypeError('buttons.showClear expects a boolean parameter');
  1118. }
  1119. if (typeof this._options.buttons.showClose !== 'boolean') {
  1120. throw new TypeError('buttons.showClose expects a boolean parameter');
  1121. }
  1122. if (this.widget) {
  1123. this.hide();
  1124. this.show();
  1125. }
  1126. };
  1127. DateTimePicker.prototype.keepOpen = function keepOpen(_keepOpen) {
  1128. if (arguments.length === 0) {
  1129. return this._options.keepOpen;
  1130. }
  1131. if (typeof _keepOpen !== 'boolean') {
  1132. throw new TypeError('keepOpen() expects a boolean parameter');
  1133. }
  1134. this._options.keepOpen = _keepOpen;
  1135. };
  1136. DateTimePicker.prototype.focusOnShow = function focusOnShow(_focusOnShow) {
  1137. if (arguments.length === 0) {
  1138. return this._options.focusOnShow;
  1139. }
  1140. if (typeof _focusOnShow !== 'boolean') {
  1141. throw new TypeError('focusOnShow() expects a boolean parameter');
  1142. }
  1143. this._options.focusOnShow = _focusOnShow;
  1144. };
  1145. DateTimePicker.prototype.inline = function inline(_inline) {
  1146. if (arguments.length === 0) {
  1147. return this._options.inline;
  1148. }
  1149. if (typeof _inline !== 'boolean') {
  1150. throw new TypeError('inline() expects a boolean parameter');
  1151. }
  1152. this._options.inline = _inline;
  1153. };
  1154. DateTimePicker.prototype.clear = function clear() {
  1155. this._setValue(null); //todo
  1156. };
  1157. DateTimePicker.prototype.keyBinds = function keyBinds(_keyBinds) {
  1158. if (arguments.length === 0) {
  1159. return this._options.keyBinds;
  1160. }
  1161. this._options.keyBinds = _keyBinds;
  1162. };
  1163. DateTimePicker.prototype.debug = function debug(_debug) {
  1164. if (typeof _debug !== 'boolean') {
  1165. throw new TypeError('debug() expects a boolean parameter');
  1166. }
  1167. this._options.debug = _debug;
  1168. };
  1169. DateTimePicker.prototype.allowInputToggle = function allowInputToggle(_allowInputToggle) {
  1170. if (arguments.length === 0) {
  1171. return this._options.allowInputToggle;
  1172. }
  1173. if (typeof _allowInputToggle !== 'boolean') {
  1174. throw new TypeError('allowInputToggle() expects a boolean parameter');
  1175. }
  1176. this._options.allowInputToggle = _allowInputToggle;
  1177. };
  1178. DateTimePicker.prototype.keepInvalid = function keepInvalid(_keepInvalid) {
  1179. if (arguments.length === 0) {
  1180. return this._options.keepInvalid;
  1181. }
  1182. if (typeof _keepInvalid !== 'boolean') {
  1183. throw new TypeError('keepInvalid() expects a boolean parameter');
  1184. }
  1185. this._options.keepInvalid = _keepInvalid;
  1186. };
  1187. DateTimePicker.prototype.datepickerInput = function datepickerInput(_datepickerInput) {
  1188. if (arguments.length === 0) {
  1189. return this._options.datepickerInput;
  1190. }
  1191. if (typeof _datepickerInput !== 'string') {
  1192. throw new TypeError('datepickerInput() expects a string parameter');
  1193. }
  1194. this._options.datepickerInput = _datepickerInput;
  1195. };
  1196. DateTimePicker.prototype.parseInputDate = function parseInputDate(_parseInputDate2) {
  1197. if (arguments.length === 0) {
  1198. return this._options.parseInputDate;
  1199. }
  1200. if (typeof _parseInputDate2 !== 'function') {
  1201. throw new TypeError('parseInputDate() should be as function');
  1202. }
  1203. this._options.parseInputDate = _parseInputDate2;
  1204. };
  1205. DateTimePicker.prototype.disabledTimeIntervals = function disabledTimeIntervals(_disabledTimeIntervals) {
  1206. if (arguments.length === 0) {
  1207. return this._options.disabledTimeIntervals ? $.extend({}, this._options.disabledTimeIntervals) : this._options.disabledTimeIntervals;
  1208. }
  1209. if (!_disabledTimeIntervals) {
  1210. this._options.disabledTimeIntervals = false;
  1211. this._update();
  1212. return true;
  1213. }
  1214. if (!(_disabledTimeIntervals instanceof Array)) {
  1215. throw new TypeError('disabledTimeIntervals() expects an array parameter');
  1216. }
  1217. this._options.disabledTimeIntervals = _disabledTimeIntervals;
  1218. this._update();
  1219. };
  1220. DateTimePicker.prototype.disabledHours = function disabledHours(hours) {
  1221. if (arguments.length === 0) {
  1222. return this._options.disabledHours ? $.extend({}, this._options.disabledHours) : this._options.disabledHours;
  1223. }
  1224. if (!hours) {
  1225. this._options.disabledHours = false;
  1226. this._update();
  1227. return true;
  1228. }
  1229. if (!(hours instanceof Array)) {
  1230. throw new TypeError('disabledHours() expects an array parameter');
  1231. }
  1232. this._options.disabledHours = this._indexGivenHours(hours);
  1233. this._options.enabledHours = false;
  1234. if (this._options.useCurrent && !this._options.keepInvalid) {
  1235. for (var i = 0; i < this._dates.length; i++) {
  1236. var tries = 0;
  1237. while (!this._isValid(this._dates[i], 'h')) {
  1238. this._dates[i].add(1, 'h');
  1239. if (tries === 24) {
  1240. throw 'Tried 24 times to find a valid date';
  1241. }
  1242. tries++;
  1243. }
  1244. this._setValue(this._dates[i], i);
  1245. }
  1246. }
  1247. this._update();
  1248. };
  1249. DateTimePicker.prototype.enabledHours = function enabledHours(hours) {
  1250. if (arguments.length === 0) {
  1251. return this._options.enabledHours ? $.extend({}, this._options.enabledHours) : this._options.enabledHours;
  1252. }
  1253. if (!hours) {
  1254. this._options.enabledHours = false;
  1255. this._update();
  1256. return true;
  1257. }
  1258. if (!(hours instanceof Array)) {
  1259. throw new TypeError('enabledHours() expects an array parameter');
  1260. }
  1261. this._options.enabledHours = this._indexGivenHours(hours);
  1262. this._options.disabledHours = false;
  1263. if (this._options.useCurrent && !this._options.keepInvalid) {
  1264. for (var i = 0; i < this._dates.length; i++) {
  1265. var tries = 0;
  1266. while (!this._isValid(this._dates[i], 'h')) {
  1267. this._dates[i].add(1, 'h');
  1268. if (tries === 24) {
  1269. throw 'Tried 24 times to find a valid date';
  1270. }
  1271. tries++;
  1272. }
  1273. this._setValue(this._dates[i], i);
  1274. }
  1275. }
  1276. this._update();
  1277. };
  1278. DateTimePicker.prototype.viewDate = function viewDate(newDate) {
  1279. if (arguments.length === 0) {
  1280. return this._viewDate.clone();
  1281. }
  1282. if (!newDate) {
  1283. this._viewDate = (this._dates[0] || this.getMoment()).clone();
  1284. return true;
  1285. }
  1286. if (typeof newDate !== 'string' && !moment.isMoment(newDate) && !(newDate instanceof Date)) {
  1287. throw new TypeError('viewDate() parameter must be one of [string, moment or Date]');
  1288. }
  1289. this._viewDate = this._parseInputDate(newDate);
  1290. this._viewUpdate();
  1291. };
  1292. DateTimePicker.prototype.allowMultidate = function allowMultidate(_allowMultidate) {
  1293. if (typeof _allowMultidate !== 'boolean') {
  1294. throw new TypeError('allowMultidate() expects a boolean parameter');
  1295. }
  1296. this._options.allowMultidate = _allowMultidate;
  1297. };
  1298. DateTimePicker.prototype.multidateSeparator = function multidateSeparator(_multidateSeparator) {
  1299. if (arguments.length === 0) {
  1300. return this._options.multidateSeparator;
  1301. }
  1302. if (typeof _multidateSeparator !== 'string' || _multidateSeparator.length > 1) {
  1303. throw new TypeError('multidateSeparator expects a single character string parameter');
  1304. }
  1305. this._options.multidateSeparator = _multidateSeparator;
  1306. };
  1307. _createClass(DateTimePicker, null, [{
  1308. key: 'NAME',
  1309. get: function get() {
  1310. return NAME;
  1311. }
  1312. /**
  1313. * @return {string}
  1314. */
  1315. }, {
  1316. key: 'DATA_KEY',
  1317. get: function get() {
  1318. return DATA_KEY;
  1319. }
  1320. /**
  1321. * @return {string}
  1322. */
  1323. }, {
  1324. key: 'EVENT_KEY',
  1325. get: function get() {
  1326. return EVENT_KEY;
  1327. }
  1328. /**
  1329. * @return {string}
  1330. */
  1331. }, {
  1332. key: 'DATA_API_KEY',
  1333. get: function get() {
  1334. return DATA_API_KEY;
  1335. }
  1336. }, {
  1337. key: 'DatePickerModes',
  1338. get: function get() {
  1339. return DatePickerModes;
  1340. }
  1341. }, {
  1342. key: 'ViewModes',
  1343. get: function get() {
  1344. return ViewModes;
  1345. }
  1346. }, {
  1347. key: 'Event',
  1348. get: function get() {
  1349. return Event;
  1350. }
  1351. }, {
  1352. key: 'Selector',
  1353. get: function get() {
  1354. return Selector;
  1355. }
  1356. }, {
  1357. key: 'Default',
  1358. get: function get() {
  1359. return Default;
  1360. },
  1361. set: function set(value) {
  1362. Default = value;
  1363. }
  1364. }, {
  1365. key: 'ClassName',
  1366. get: function get() {
  1367. return ClassName;
  1368. }
  1369. }]);
  1370. return DateTimePicker;
  1371. }();
  1372. return DateTimePicker;
  1373. }(jQuery, moment);
  1374. //noinspection JSUnusedGlobalSymbols
  1375. /* global DateTimePicker */
  1376. var TempusDominusBootstrap4 = function ($) {
  1377. // eslint-disable-line no-unused-vars
  1378. // ReSharper disable once InconsistentNaming
  1379. var JQUERY_NO_CONFLICT = $.fn[DateTimePicker.NAME],
  1380. verticalModes = ['top', 'bottom', 'auto'],
  1381. horizontalModes = ['left', 'right', 'auto'],
  1382. toolbarPlacements = ['default', 'top', 'bottom'],
  1383. getSelectorFromElement = function getSelectorFromElement($element) {
  1384. var selector = $element.data('target'),
  1385. $selector = void 0;
  1386. if (!selector) {
  1387. selector = $element.attr('href') || '';
  1388. selector = /^#[a-z]/i.test(selector) ? selector : null;
  1389. }
  1390. $selector = $(selector);
  1391. if ($selector.length === 0) {
  1392. return $selector;
  1393. }
  1394. if (!$selector.data(DateTimePicker.DATA_KEY)) {
  1395. $.extend({}, $selector.data(), $(this).data());
  1396. }
  1397. return $selector;
  1398. };
  1399. // ReSharper disable once InconsistentNaming
  1400. var TempusDominusBootstrap4 = function (_DateTimePicker) {
  1401. _inherits(TempusDominusBootstrap4, _DateTimePicker);
  1402. function TempusDominusBootstrap4(element, options) {
  1403. _classCallCheck(this, TempusDominusBootstrap4);
  1404. var _this = _possibleConstructorReturn(this, _DateTimePicker.call(this, element, options));
  1405. _this._init();
  1406. return _this;
  1407. }
  1408. TempusDominusBootstrap4.prototype._init = function _init() {
  1409. if (this._element.hasClass('input-group')) {
  1410. var datepickerButton = this._element.find('.datepickerbutton');
  1411. if (datepickerButton.length === 0) {
  1412. this.component = this._element.find('[data-toggle="datetimepicker"]');
  1413. } else {
  1414. this.component = datepickerButton;
  1415. }
  1416. }
  1417. };
  1418. TempusDominusBootstrap4.prototype._getDatePickerTemplate = function _getDatePickerTemplate() {
  1419. var headTemplate = $('<thead>').append($('<tr>').append($('<th>').addClass('prev').attr('data-action', 'previous').append($('<span>').addClass(this._options.icons.previous))).append($('<th>').addClass('picker-switch').attr('data-action', 'pickerSwitch').attr('colspan', '' + (this._options.calendarWeeks ? '6' : '5'))).append($('<th>').addClass('next').attr('data-action', 'next').append($('<span>').addClass(this._options.icons.next)))),
  1420. contTemplate = $('<tbody>').append($('<tr>').append($('<td>').attr('colspan', '' + (this._options.calendarWeeks ? '8' : '7'))));
  1421. return [$('<div>').addClass('datepicker-days').append($('<table>').addClass('table table-sm').append(headTemplate).append($('<tbody>'))), $('<div>').addClass('datepicker-months').append($('<table>').addClass('table-condensed').append(headTemplate.clone()).append(contTemplate.clone())), $('<div>').addClass('datepicker-years').append($('<table>').addClass('table-condensed').append(headTemplate.clone()).append(contTemplate.clone())), $('<div>').addClass('datepicker-decades').append($('<table>').addClass('table-condensed').append(headTemplate.clone()).append(contTemplate.clone()))];
  1422. };
  1423. TempusDominusBootstrap4.prototype._getTimePickerMainTemplate = function _getTimePickerMainTemplate() {
  1424. var topRow = $('<tr>'),
  1425. middleRow = $('<tr>'),
  1426. bottomRow = $('<tr>');
  1427. if (this._isEnabled('h')) {
  1428. topRow.append($('<td>').append($('<a>').attr({
  1429. href: '#',
  1430. tabindex: '-1',
  1431. 'title': this._options.tooltips.incrementHour
  1432. }).addClass('btn').attr('data-action', 'incrementHours').append($('<span>').addClass(this._options.icons.up))));
  1433. middleRow.append($('<td>').append($('<span>').addClass('timepicker-hour').attr({
  1434. 'data-time-component': 'hours',
  1435. 'title': this._options.tooltips.pickHour
  1436. }).attr('data-action', 'showHours')));
  1437. bottomRow.append($('<td>').append($('<a>').attr({
  1438. href: '#',
  1439. tabindex: '-1',
  1440. 'title': this._options.tooltips.decrementHour
  1441. }).addClass('btn').attr('data-action', 'decrementHours').append($('<span>').addClass(this._options.icons.down))));
  1442. }
  1443. if (this._isEnabled('m')) {
  1444. if (this._isEnabled('h')) {
  1445. topRow.append($('<td>').addClass('separator'));
  1446. middleRow.append($('<td>').addClass('separator').html(':'));
  1447. bottomRow.append($('<td>').addClass('separator'));
  1448. }
  1449. topRow.append($('<td>').append($('<a>').attr({
  1450. href: '#',
  1451. tabindex: '-1',
  1452. 'title': this._options.tooltips.incrementMinute
  1453. }).addClass('btn').attr('data-action', 'incrementMinutes').append($('<span>').addClass(this._options.icons.up))));
  1454. middleRow.append($('<td>').append($('<span>').addClass('timepicker-minute').attr({
  1455. 'data-time-component': 'minutes',
  1456. 'title': this._options.tooltips.pickMinute
  1457. }).attr('data-action', 'showMinutes')));
  1458. bottomRow.append($('<td>').append($('<a>').attr({
  1459. href: '#',
  1460. tabindex: '-1',
  1461. 'title': this._options.tooltips.decrementMinute
  1462. }).addClass('btn').attr('data-action', 'decrementMinutes').append($('<span>').addClass(this._options.icons.down))));
  1463. }
  1464. if (this._isEnabled('s')) {
  1465. if (this._isEnabled('m')) {
  1466. topRow.append($('<td>').addClass('separator'));
  1467. middleRow.append($('<td>').addClass('separator').html(':'));
  1468. bottomRow.append($('<td>').addClass('separator'));
  1469. }
  1470. topRow.append($('<td>').append($('<a>').attr({
  1471. href: '#',
  1472. tabindex: '-1',
  1473. 'title': this._options.tooltips.incrementSecond
  1474. }).addClass('btn').attr('data-action', 'incrementSeconds').append($('<span>').addClass(this._options.icons.up))));
  1475. middleRow.append($('<td>').append($('<span>').addClass('timepicker-second').attr({
  1476. 'data-time-component': 'seconds',
  1477. 'title': this._options.tooltips.pickSecond
  1478. }).attr('data-action', 'showSeconds')));
  1479. bottomRow.append($('<td>').append($('<a>').attr({
  1480. href: '#',
  1481. tabindex: '-1',
  1482. 'title': this._options.tooltips.decrementSecond
  1483. }).addClass('btn').attr('data-action', 'decrementSeconds').append($('<span>').addClass(this._options.icons.down))));
  1484. }
  1485. if (!this.use24Hours) {
  1486. topRow.append($('<td>').addClass('separator'));
  1487. middleRow.append($('<td>').append($('<button>').addClass('btn btn-primary').attr({
  1488. 'data-action': 'togglePeriod',
  1489. tabindex: '-1',
  1490. 'title': this._options.tooltips.togglePeriod
  1491. })));
  1492. bottomRow.append($('<td>').addClass('separator'));
  1493. }
  1494. return $('<div>').addClass('timepicker-picker').append($('<table>').addClass('table-condensed').append([topRow, middleRow, bottomRow]));
  1495. };
  1496. TempusDominusBootstrap4.prototype._getTimePickerTemplate = function _getTimePickerTemplate() {
  1497. var hoursView = $('<div>').addClass('timepicker-hours').append($('<table>').addClass('table-condensed')),
  1498. minutesView = $('<div>').addClass('timepicker-minutes').append($('<table>').addClass('table-condensed')),
  1499. secondsView = $('<div>').addClass('timepicker-seconds').append($('<table>').addClass('table-condensed')),
  1500. ret = [this._getTimePickerMainTemplate()];
  1501. if (this._isEnabled('h')) {
  1502. ret.push(hoursView);
  1503. }
  1504. if (this._isEnabled('m')) {
  1505. ret.push(minutesView);
  1506. }
  1507. if (this._isEnabled('s')) {
  1508. ret.push(secondsView);
  1509. }
  1510. return ret;
  1511. };
  1512. TempusDominusBootstrap4.prototype._getToolbar = function _getToolbar() {
  1513. var row = [];
  1514. if (this._options.buttons.showToday) {
  1515. row.push($('<td>').append($('<a>').attr({
  1516. href: '#',
  1517. tabindex: '-1',
  1518. 'data-action': 'today',
  1519. 'title': this._options.tooltips.today
  1520. }).append($('<span>').addClass(this._options.icons.today))));
  1521. }
  1522. if (!this._options.sideBySide && this._hasDate() && this._hasTime()) {
  1523. var title = void 0,
  1524. icon = void 0;
  1525. if (this._options.viewMode === 'times') {
  1526. title = this._options.tooltips.selectDate;
  1527. icon = this._options.icons.date;
  1528. } else {
  1529. title = this._options.tooltips.selectTime;
  1530. icon = this._options.icons.time;
  1531. }
  1532. row.push($('<td>').append($('<a>').attr({
  1533. href: '#',
  1534. tabindex: '-1',
  1535. 'data-action': 'togglePicker',
  1536. 'title': title
  1537. }).append($('<span>').addClass(icon))));
  1538. }
  1539. if (this._options.buttons.showClear) {
  1540. row.push($('<td>').append($('<a>').attr({
  1541. href: '#',
  1542. tabindex: '-1',
  1543. 'data-action': 'clear',
  1544. 'title': this._options.tooltips.clear
  1545. }).append($('<span>').addClass(this._options.icons.clear))));
  1546. }
  1547. if (this._options.buttons.showClose) {
  1548. row.push($('<td>').append($('<a>').attr({
  1549. href: '#',
  1550. tabindex: '-1',
  1551. 'data-action': 'close',
  1552. 'title': this._options.tooltips.close
  1553. }).append($('<span>').addClass(this._options.icons.close))));
  1554. }
  1555. return row.length === 0 ? '' : $('<table>').addClass('table-condensed').append($('<tbody>').append($('<tr>').append(row)));
  1556. };
  1557. TempusDominusBootstrap4.prototype._getTemplate = function _getTemplate() {
  1558. var template = $('<div>').addClass('bootstrap-datetimepicker-widget dropdown-menu'),
  1559. dateView = $('<div>').addClass('datepicker').append(this._getDatePickerTemplate()),
  1560. timeView = $('<div>').addClass('timepicker').append(this._getTimePickerTemplate()),
  1561. content = $('<ul>').addClass('list-unstyled'),
  1562. toolbar = $('<li>').addClass('picker-switch' + (this._options.collapse ? ' accordion-toggle' : '')).append(this._getToolbar());
  1563. if (this._options.inline) {
  1564. template.removeClass('dropdown-menu');
  1565. }
  1566. if (this.use24Hours) {
  1567. template.addClass('usetwentyfour');
  1568. }
  1569. if (this._isEnabled('s') && !this.use24Hours) {
  1570. template.addClass('wider');
  1571. }
  1572. if (this._options.sideBySide && this._hasDate() && this._hasTime()) {
  1573. template.addClass('timepicker-sbs');
  1574. if (this._options.toolbarPlacement === 'top') {
  1575. template.append(toolbar);
  1576. }
  1577. template.append($('<div>').addClass('row').append(dateView.addClass('col-md-6')).append(timeView.addClass('col-md-6')));
  1578. if (this._options.toolbarPlacement === 'bottom' || this._options.toolbarPlacement === 'default') {
  1579. template.append(toolbar);
  1580. }
  1581. return template;
  1582. }
  1583. if (this._options.toolbarPlacement === 'top') {
  1584. content.append(toolbar);
  1585. }
  1586. if (this._hasDate()) {
  1587. content.append($('<li>').addClass(this._options.collapse && this._hasTime() ? 'collapse' : '').addClass(this._options.collapse && this._hasTime() && this._options.viewMode === 'times' ? '' : 'show').append(dateView));
  1588. }
  1589. if (this._options.toolbarPlacement === 'default') {
  1590. content.append(toolbar);
  1591. }
  1592. if (this._hasTime()) {
  1593. content.append($('<li>').addClass(this._options.collapse && this._hasDate() ? 'collapse' : '').addClass(this._options.collapse && this._hasDate() && this._options.viewMode === 'times' ? 'show' : '').append(timeView));
  1594. }
  1595. if (this._options.toolbarPlacement === 'bottom') {
  1596. content.append(toolbar);
  1597. }
  1598. return template.append(content);
  1599. };
  1600. TempusDominusBootstrap4.prototype._place = function _place(e) {
  1601. var self = e && e.data && e.data.picker || this,
  1602. vertical = self._options.widgetPositioning.vertical,
  1603. horizontal = self._options.widgetPositioning.horizontal,
  1604. parent = void 0;
  1605. var position = (self.component && self.component.length ? self.component : self._element).position(),
  1606. offset = (self.component && self.component.length ? self.component : self._element).offset();
  1607. if (self._options.widgetParent) {
  1608. parent = self._options.widgetParent.append(self.widget);
  1609. } else if (self._element.is('input')) {
  1610. parent = self._element.after(self.widget).parent();
  1611. } else if (self._options.inline) {
  1612. parent = self._element.append(self.widget);
  1613. return;
  1614. } else {
  1615. parent = self._element;
  1616. self._element.children().first().after(self.widget);
  1617. }
  1618. // Top and bottom logic
  1619. if (vertical === 'auto') {
  1620. //noinspection JSValidateTypes
  1621. if (offset.top + self.widget.height() * 1.5 >= $(window).height() + $(window).scrollTop() && self.widget.height() + self._element.outerHeight() < offset.top) {
  1622. vertical = 'top';
  1623. } else {
  1624. vertical = 'bottom';
  1625. }
  1626. }
  1627. // Left and right logic
  1628. if (horizontal === 'auto') {
  1629. if (parent.width() < offset.left + self.widget.outerWidth() / 2 && offset.left + self.widget.outerWidth() > $(window).width()) {
  1630. horizontal = 'right';
  1631. } else {
  1632. horizontal = 'left';
  1633. }
  1634. }
  1635. if (vertical === 'top') {
  1636. self.widget.addClass('top').removeClass('bottom');
  1637. } else {
  1638. self.widget.addClass('bottom').removeClass('top');
  1639. }
  1640. if (horizontal === 'right') {
  1641. self.widget.addClass('float-right');
  1642. } else {
  1643. self.widget.removeClass('float-right');
  1644. }
  1645. // find the first parent element that has a relative css positioning
  1646. if (parent.css('position') !== 'relative') {
  1647. parent = parent.parents().filter(function () {
  1648. return $(this).css('position') === 'relative';
  1649. }).first();
  1650. }
  1651. if (parent.length === 0) {
  1652. throw new Error('datetimepicker component should be placed within a relative positioned container');
  1653. }
  1654. self.widget.css({
  1655. top: vertical === 'top' ? 'auto' : position.top + self._element.outerHeight() + 'px',
  1656. bottom: vertical === 'top' ? parent.outerHeight() - (parent === self._element ? 0 : position.top) + 'px' : 'auto',
  1657. left: horizontal === 'left' ? (parent === self._element ? 0 : position.left) + 'px' : 'auto',
  1658. right: horizontal === 'left' ? 'auto' : parent.outerWidth() - self._element.outerWidth() - (parent === self._element ? 0 : position.left) + 'px'
  1659. });
  1660. };
  1661. TempusDominusBootstrap4.prototype._fillDow = function _fillDow() {
  1662. var row = $('<tr>'),
  1663. currentDate = this._viewDate.clone().startOf('w').startOf('d');
  1664. if (this._options.calendarWeeks === true) {
  1665. row.append($('<th>').addClass('cw').text('#'));
  1666. }
  1667. while (currentDate.isBefore(this._viewDate.clone().endOf('w'))) {
  1668. row.append($('<th>').addClass('dow').text(currentDate.format('dd')));
  1669. currentDate.add(1, 'd');
  1670. }
  1671. this.widget.find('.datepicker-days thead').append(row);
  1672. };
  1673. TempusDominusBootstrap4.prototype._fillMonths = function _fillMonths() {
  1674. var spans = [],
  1675. monthsShort = this._viewDate.clone().startOf('y').startOf('d');
  1676. while (monthsShort.isSame(this._viewDate, 'y')) {
  1677. spans.push($('<span>').attr('data-action', 'selectMonth').addClass('month').text(monthsShort.format('MMM')));
  1678. monthsShort.add(1, 'M');
  1679. }
  1680. this.widget.find('.datepicker-months td').empty().append(spans);
  1681. };
  1682. TempusDominusBootstrap4.prototype._updateMonths = function _updateMonths() {
  1683. var monthsView = this.widget.find('.datepicker-months'),
  1684. monthsViewHeader = monthsView.find('th'),
  1685. months = monthsView.find('tbody').find('span'),
  1686. self = this;
  1687. monthsViewHeader.eq(0).find('span').attr('title', this._options.tooltips.prevYear);
  1688. monthsViewHeader.eq(1).attr('title', this._options.tooltips.selectYear);
  1689. monthsViewHeader.eq(2).find('span').attr('title', this._options.tooltips.nextYear);
  1690. monthsView.find('.disabled').removeClass('disabled');
  1691. if (!this._isValid(this._viewDate.clone().subtract(1, 'y'), 'y')) {
  1692. monthsViewHeader.eq(0).addClass('disabled');
  1693. }
  1694. monthsViewHeader.eq(1).text(this._viewDate.year());
  1695. if (!this._isValid(this._viewDate.clone().add(1, 'y'), 'y')) {
  1696. monthsViewHeader.eq(2).addClass('disabled');
  1697. }
  1698. months.removeClass('active');
  1699. if (this._getLastPickedDate().isSame(this._viewDate, 'y') && !this.unset) {
  1700. months.eq(this._getLastPickedDate().month()).addClass('active');
  1701. }
  1702. months.each(function (index) {
  1703. if (!self._isValid(self._viewDate.clone().month(index), 'M')) {
  1704. $(this).addClass('disabled');
  1705. }
  1706. });
  1707. };
  1708. TempusDominusBootstrap4.prototype._getStartEndYear = function _getStartEndYear(factor, year) {
  1709. var step = factor / 10,
  1710. startYear = Math.floor(year / factor) * factor,
  1711. endYear = startYear + step * 9,
  1712. focusValue = Math.floor(year / step) * step;
  1713. return [startYear, endYear, focusValue];
  1714. };
  1715. TempusDominusBootstrap4.prototype._updateYears = function _updateYears() {
  1716. var yearsView = this.widget.find('.datepicker-years'),
  1717. yearsViewHeader = yearsView.find('th'),
  1718. yearCaps = this._getStartEndYear(10, this._viewDate.year()),
  1719. startYear = this._viewDate.clone().year(yearCaps[0]),
  1720. endYear = this._viewDate.clone().year(yearCaps[1]);
  1721. var html = '';
  1722. yearsViewHeader.eq(0).find('span').attr('title', this._options.tooltips.prevDecade);
  1723. yearsViewHeader.eq(1).attr('title', this._options.tooltips.selectDecade);
  1724. yearsViewHeader.eq(2).find('span').attr('title', this._options.tooltips.nextDecade);
  1725. yearsView.find('.disabled').removeClass('disabled');
  1726. if (this._options.minDate && this._options.minDate.isAfter(startYear, 'y')) {
  1727. yearsViewHeader.eq(0).addClass('disabled');
  1728. }
  1729. yearsViewHeader.eq(1).text(startYear.year() + '-' + endYear.year());
  1730. if (this._options.maxDate && this._options.maxDate.isBefore(endYear, 'y')) {
  1731. yearsViewHeader.eq(2).addClass('disabled');
  1732. }
  1733. html += '<span data-action="selectYear" class="year old' + (!this._isValid(startYear, 'y') ? ' disabled' : '') + '">' + (startYear.year() - 1) + '</span>';
  1734. while (!startYear.isAfter(endYear, 'y')) {
  1735. html += '<span data-action="selectYear" class="year' + (startYear.isSame(this._getLastPickedDate(), 'y') && !this.unset ? ' active' : '') + (!this._isValid(startYear, 'y') ? ' disabled' : '') + '">' + startYear.year() + '</span>';
  1736. startYear.add(1, 'y');
  1737. }
  1738. html += '<span data-action="selectYear" class="year old' + (!this._isValid(startYear, 'y') ? ' disabled' : '') + '">' + startYear.year() + '</span>';
  1739. yearsView.find('td').html(html);
  1740. };
  1741. TempusDominusBootstrap4.prototype._updateDecades = function _updateDecades() {
  1742. var decadesView = this.widget.find('.datepicker-decades'),
  1743. decadesViewHeader = decadesView.find('th'),
  1744. yearCaps = this._getStartEndYear(100, this._viewDate.year()),
  1745. startDecade = this._viewDate.clone().year(yearCaps[0]),
  1746. endDecade = this._viewDate.clone().year(yearCaps[1]);
  1747. var minDateDecade = false,
  1748. maxDateDecade = false,
  1749. endDecadeYear = void 0,
  1750. html = '';
  1751. decadesViewHeader.eq(0).find('span').attr('title', this._options.tooltips.prevCentury);
  1752. decadesViewHeader.eq(2).find('span').attr('title', this._options.tooltips.nextCentury);
  1753. decadesView.find('.disabled').removeClass('disabled');
  1754. if (startDecade.year() === 0 || this._options.minDate && this._options.minDate.isAfter(startDecade, 'y')) {
  1755. decadesViewHeader.eq(0).addClass('disabled');
  1756. }
  1757. decadesViewHeader.eq(1).text(startDecade.year() + '-' + endDecade.year());
  1758. if (this._options.maxDate && this._options.maxDate.isBefore(endDecade, 'y')) {
  1759. decadesViewHeader.eq(2).addClass('disabled');
  1760. }
  1761. if (startDecade.year() - 10 < 0) {
  1762. html += '<span>&nbsp;</span>';
  1763. } else {
  1764. html += '<span data-action="selectDecade" class="decade old" data-selection="' + (startDecade.year() + 6) + '">' + (startDecade.year() - 10) + '</span>';
  1765. }
  1766. while (!startDecade.isAfter(endDecade, 'y')) {
  1767. endDecadeYear = startDecade.year() + 11;
  1768. minDateDecade = this._options.minDate && this._options.minDate.isAfter(startDecade, 'y') && this._options.minDate.year() <= endDecadeYear;
  1769. maxDateDecade = this._options.maxDate && this._options.maxDate.isAfter(startDecade, 'y') && this._options.maxDate.year() <= endDecadeYear;
  1770. html += '<span data-action="selectDecade" class="decade' + (this._getLastPickedDate().isAfter(startDecade) && this._getLastPickedDate().year() <= endDecadeYear ? ' active' : '') + (!this._isValid(startDecade, 'y') && !minDateDecade && !maxDateDecade ? ' disabled' : '') + '" data-selection="' + (startDecade.year() + 6) + '">' + startDecade.year() + '</span>';
  1771. startDecade.add(10, 'y');
  1772. }
  1773. html += '<span data-action="selectDecade" class="decade old" data-selection="' + (startDecade.year() + 6) + '">' + startDecade.year() + '</span>';
  1774. decadesView.find('td').html(html);
  1775. };
  1776. TempusDominusBootstrap4.prototype._fillDate = function _fillDate() {
  1777. var daysView = this.widget.find('.datepicker-days'),
  1778. daysViewHeader = daysView.find('th'),
  1779. html = [];
  1780. var currentDate = void 0,
  1781. row = void 0,
  1782. clsName = void 0,
  1783. i = void 0;
  1784. if (!this._hasDate()) {
  1785. return;
  1786. }
  1787. daysViewHeader.eq(0).find('span').attr('title', this._options.tooltips.prevMonth);
  1788. daysViewHeader.eq(1).attr('title', this._options.tooltips.selectMonth);
  1789. daysViewHeader.eq(2).find('span').attr('title', this._options.tooltips.nextMonth);
  1790. daysView.find('.disabled').removeClass('disabled');
  1791. daysViewHeader.eq(1).text(this._viewDate.format(this._options.dayViewHeaderFormat));
  1792. if (!this._isValid(this._viewDate.clone().subtract(1, 'M'), 'M')) {
  1793. daysViewHeader.eq(0).addClass('disabled');
  1794. }
  1795. if (!this._isValid(this._viewDate.clone().add(1, 'M'), 'M')) {
  1796. daysViewHeader.eq(2).addClass('disabled');
  1797. }
  1798. currentDate = this._viewDate.clone().startOf('M').startOf('w').startOf('d');
  1799. for (i = 0; i < 42; i++) {
  1800. //always display 42 days (should show 6 weeks)
  1801. if (currentDate.weekday() === 0) {
  1802. row = $('<tr>');
  1803. if (this._options.calendarWeeks) {
  1804. row.append('<td class="cw">' + currentDate.week() + '</td>');
  1805. }
  1806. html.push(row);
  1807. }
  1808. clsName = '';
  1809. if (currentDate.isBefore(this._viewDate, 'M')) {
  1810. clsName += ' old';
  1811. }
  1812. if (currentDate.isAfter(this._viewDate, 'M')) {
  1813. clsName += ' new';
  1814. }
  1815. if (this._options.allowMultidate) {
  1816. var index = this._datesFormatted.indexOf(currentDate.format('YYYY-MM-DD'));
  1817. if (index !== -1) {
  1818. if (currentDate.isSame(this._datesFormatted[index], 'd') && !this.unset) {
  1819. clsName += ' active';
  1820. }
  1821. }
  1822. } else {
  1823. if (currentDate.isSame(this._getLastPickedDate(), 'd') && !this.unset) {
  1824. clsName += ' active';
  1825. }
  1826. }
  1827. if (!this._isValid(currentDate, 'd')) {
  1828. clsName += ' disabled';
  1829. }
  1830. if (currentDate.isSame(this.getMoment(), 'd')) {
  1831. clsName += ' today';
  1832. }
  1833. if (currentDate.day() === 0 || currentDate.day() === 6) {
  1834. clsName += ' weekend';
  1835. }
  1836. row.append('<td data-action="selectDay" data-day="' + currentDate.format('L') + '" class="day' + clsName + '">' + currentDate.date() + '</td>');
  1837. currentDate.add(1, 'd');
  1838. }
  1839. daysView.find('tbody').empty().append(html);
  1840. this._updateMonths();
  1841. this._updateYears();
  1842. this._updateDecades();
  1843. };
  1844. TempusDominusBootstrap4.prototype._fillHours = function _fillHours() {
  1845. var table = this.widget.find('.timepicker-hours table'),
  1846. currentHour = this._viewDate.clone().startOf('d'),
  1847. html = [];
  1848. var row = $('<tr>');
  1849. if (this._viewDate.hour() > 11 && !this.use24Hours) {
  1850. currentHour.hour(12);
  1851. }
  1852. while (currentHour.isSame(this._viewDate, 'd') && (this.use24Hours || this._viewDate.hour() < 12 && currentHour.hour() < 12 || this._viewDate.hour() > 11)) {
  1853. if (currentHour.hour() % 4 === 0) {
  1854. row = $('<tr>');
  1855. html.push(row);
  1856. }
  1857. row.append('<td data-action="selectHour" class="hour' + (!this._isValid(currentHour, 'h') ? ' disabled' : '') + '">' + currentHour.format(this.use24Hours ? 'HH' : 'hh') + '</td>');
  1858. currentHour.add(1, 'h');
  1859. }
  1860. table.empty().append(html);
  1861. };
  1862. TempusDominusBootstrap4.prototype._fillMinutes = function _fillMinutes() {
  1863. var table = this.widget.find('.timepicker-minutes table'),
  1864. currentMinute = this._viewDate.clone().startOf('h'),
  1865. html = [],
  1866. step = this._options.stepping === 1 ? 5 : this._options.stepping;
  1867. var row = $('<tr>');
  1868. while (this._viewDate.isSame(currentMinute, 'h')) {
  1869. if (currentMinute.minute() % (step * 4) === 0) {
  1870. row = $('<tr>');
  1871. html.push(row);
  1872. }
  1873. row.append('<td data-action="selectMinute" class="minute' + (!this._isValid(currentMinute, 'm') ? ' disabled' : '') + '">' + currentMinute.format('mm') + '</td>');
  1874. currentMinute.add(step, 'm');
  1875. }
  1876. table.empty().append(html);
  1877. };
  1878. TempusDominusBootstrap4.prototype._fillSeconds = function _fillSeconds() {
  1879. var table = this.widget.find('.timepicker-seconds table'),
  1880. currentSecond = this._viewDate.clone().startOf('m'),
  1881. html = [];
  1882. var row = $('<tr>');
  1883. while (this._viewDate.isSame(currentSecond, 'm')) {
  1884. if (currentSecond.second() % 20 === 0) {
  1885. row = $('<tr>');
  1886. html.push(row);
  1887. }
  1888. row.append('<td data-action="selectSecond" class="second' + (!this._isValid(currentSecond, 's') ? ' disabled' : '') + '">' + currentSecond.format('ss') + '</td>');
  1889. currentSecond.add(5, 's');
  1890. }
  1891. table.empty().append(html);
  1892. };
  1893. TempusDominusBootstrap4.prototype._fillTime = function _fillTime() {
  1894. var toggle = void 0,
  1895. newDate = void 0;
  1896. var timeComponents = this.widget.find('.timepicker span[data-time-component]');
  1897. if (!this.use24Hours) {
  1898. toggle = this.widget.find('.timepicker [data-action=togglePeriod]');
  1899. newDate = this._getLastPickedDate().clone().add(this._getLastPickedDate().hours() >= 12 ? -12 : 12, 'h');
  1900. toggle.text(this._getLastPickedDate().format('A'));
  1901. if (this._isValid(newDate, 'h')) {
  1902. toggle.removeClass('disabled');
  1903. } else {
  1904. toggle.addClass('disabled');
  1905. }
  1906. }
  1907. timeComponents.filter('[data-time-component=hours]').text(this._getLastPickedDate().format('' + (this.use24Hours ? 'HH' : 'hh')));
  1908. timeComponents.filter('[data-time-component=minutes]').text(this._getLastPickedDate().format('mm'));
  1909. timeComponents.filter('[data-time-component=seconds]').text(this._getLastPickedDate().format('ss'));
  1910. this._fillHours();
  1911. this._fillMinutes();
  1912. this._fillSeconds();
  1913. };
  1914. TempusDominusBootstrap4.prototype._doAction = function _doAction(e, action) {
  1915. var lastPicked = this._getLastPickedDate();
  1916. if ($(e.currentTarget).is('.disabled')) {
  1917. return false;
  1918. }
  1919. action = action || $(e.currentTarget).data('action');
  1920. switch (action) {
  1921. case 'next':
  1922. {
  1923. var navFnc = DateTimePicker.DatePickerModes[this.currentViewMode].NAV_FUNCTION;
  1924. this._viewDate.add(DateTimePicker.DatePickerModes[this.currentViewMode].NAV_STEP, navFnc);
  1925. this._fillDate();
  1926. this._viewUpdate(navFnc);
  1927. break;
  1928. }
  1929. case 'previous':
  1930. {
  1931. var _navFnc = DateTimePicker.DatePickerModes[this.currentViewMode].NAV_FUNCTION;
  1932. this._viewDate.subtract(DateTimePicker.DatePickerModes[this.currentViewMode].NAV_STEP, _navFnc);
  1933. this._fillDate();
  1934. this._viewUpdate(_navFnc);
  1935. break;
  1936. }
  1937. case 'pickerSwitch':
  1938. this._showMode(1);
  1939. break;
  1940. case 'selectMonth':
  1941. {
  1942. var month = $(e.target).closest('tbody').find('span').index($(e.target));
  1943. this._viewDate.month(month);
  1944. if (this.currentViewMode === this.MinViewModeNumber) {
  1945. this._setValue(lastPicked.clone().year(this._viewDate.year()).month(this._viewDate.month()), this._getLastPickedDateIndex());
  1946. if (!this._options.inline) {
  1947. this.hide();
  1948. }
  1949. } else {
  1950. this._showMode(-1);
  1951. this._fillDate();
  1952. }
  1953. this._viewUpdate('M');
  1954. break;
  1955. }
  1956. case 'selectYear':
  1957. {
  1958. var year = parseInt($(e.target).text(), 10) || 0;
  1959. this._viewDate.year(year);
  1960. if (this.currentViewMode === this.MinViewModeNumber) {
  1961. this._setValue(lastPicked.clone().year(this._viewDate.year()), this._getLastPickedDateIndex());
  1962. if (!this._options.inline) {
  1963. this.hide();
  1964. }
  1965. } else {
  1966. this._showMode(-1);
  1967. this._fillDate();
  1968. }
  1969. this._viewUpdate('YYYY');
  1970. break;
  1971. }
  1972. case 'selectDecade':
  1973. {
  1974. var _year = parseInt($(e.target).data('selection'), 10) || 0;
  1975. this._viewDate.year(_year);
  1976. if (this.currentViewMode === this.MinViewModeNumber) {
  1977. this._setValue(lastPicked.clone().year(this._viewDate.year()), this._getLastPickedDateIndex());
  1978. if (!this._options.inline) {
  1979. this.hide();
  1980. }
  1981. } else {
  1982. this._showMode(-1);
  1983. this._fillDate();
  1984. }
  1985. this._viewUpdate('YYYY');
  1986. break;
  1987. }
  1988. case 'selectDay':
  1989. {
  1990. var day = this._viewDate.clone();
  1991. if ($(e.target).is('.old')) {
  1992. day.subtract(1, 'M');
  1993. }
  1994. if ($(e.target).is('.new')) {
  1995. day.add(1, 'M');
  1996. }
  1997. var selectDate = day.date(parseInt($(e.target).text(), 10)),
  1998. index = 0;
  1999. if (this._options.allowMultidate) {
  2000. index = this._datesFormatted.indexOf(selectDate.format('YYYY-MM-DD'));
  2001. if (index !== -1) {
  2002. this._setValue(null, index); //deselect multidate
  2003. } else {
  2004. this._setValue(selectDate, this._getLastPickedDateIndex() + 1);
  2005. }
  2006. } else {
  2007. this._setValue(selectDate, this._getLastPickedDateIndex());
  2008. }
  2009. if (!this._hasTime() && !this._options.keepOpen && !this._options.inline && !this._options.allowMultidate) {
  2010. this.hide();
  2011. }
  2012. break;
  2013. }
  2014. case 'incrementHours':
  2015. {
  2016. var newDate = lastPicked.clone().add(1, 'h');
  2017. if (this._isValid(newDate, 'h')) {
  2018. this._setValue(newDate, this._getLastPickedDateIndex());
  2019. }
  2020. break;
  2021. }
  2022. case 'incrementMinutes':
  2023. {
  2024. var _newDate = lastPicked.clone().add(this._options.stepping, 'm');
  2025. if (this._isValid(_newDate, 'm')) {
  2026. this._setValue(_newDate, this._getLastPickedDateIndex());
  2027. }
  2028. break;
  2029. }
  2030. case 'incrementSeconds':
  2031. {
  2032. var _newDate2 = lastPicked.clone().add(1, 's');
  2033. if (this._isValid(_newDate2, 's')) {
  2034. this._setValue(_newDate2, this._getLastPickedDateIndex());
  2035. }
  2036. break;
  2037. }
  2038. case 'decrementHours':
  2039. {
  2040. var _newDate3 = lastPicked.clone().subtract(1, 'h');
  2041. if (this._isValid(_newDate3, 'h')) {
  2042. this._setValue(_newDate3, this._getLastPickedDateIndex());
  2043. }
  2044. break;
  2045. }
  2046. case 'decrementMinutes':
  2047. {
  2048. var _newDate4 = lastPicked.clone().subtract(this._options.stepping, 'm');
  2049. if (this._isValid(_newDate4, 'm')) {
  2050. this._setValue(_newDate4, this._getLastPickedDateIndex());
  2051. }
  2052. break;
  2053. }
  2054. case 'decrementSeconds':
  2055. {
  2056. var _newDate5 = lastPicked.clone().subtract(1, 's');
  2057. if (this._isValid(_newDate5, 's')) {
  2058. this._setValue(_newDate5, this._getLastPickedDateIndex());
  2059. }
  2060. break;
  2061. }
  2062. case 'togglePeriod':
  2063. {
  2064. this._setValue(lastPicked.clone().add(lastPicked.hours() >= 12 ? -12 : 12, 'h'), this._getLastPickedDateIndex());
  2065. break;
  2066. }
  2067. case 'togglePicker':
  2068. {
  2069. var $this = $(e.target),
  2070. $link = $this.closest('a'),
  2071. $parent = $this.closest('ul'),
  2072. expanded = $parent.find('.show'),
  2073. closed = $parent.find('.collapse:not(.show)'),
  2074. $span = $this.is('span') ? $this : $this.find('span');
  2075. var collapseData = void 0;
  2076. if (expanded && expanded.length) {
  2077. collapseData = expanded.data('collapse');
  2078. if (collapseData && collapseData.transitioning) {
  2079. return true;
  2080. }
  2081. if (expanded.collapse) {
  2082. // if collapse plugin is available through bootstrap.js then use it
  2083. expanded.collapse('hide');
  2084. closed.collapse('show');
  2085. } else {
  2086. // otherwise just toggle in class on the two views
  2087. expanded.removeClass('show');
  2088. closed.addClass('show');
  2089. }
  2090. $span.toggleClass(this._options.icons.time + ' ' + this._options.icons.date);
  2091. if ($span.hasClass(this._options.icons.date)) {
  2092. $link.attr('title', this._options.tooltips.selectDate);
  2093. } else {
  2094. $link.attr('title', this._options.tooltips.selectTime);
  2095. }
  2096. }
  2097. }
  2098. break;
  2099. case 'showPicker':
  2100. this.widget.find('.timepicker > div:not(.timepicker-picker)').hide();
  2101. this.widget.find('.timepicker .timepicker-picker').show();
  2102. break;
  2103. case 'showHours':
  2104. this.widget.find('.timepicker .timepicker-picker').hide();
  2105. this.widget.find('.timepicker .timepicker-hours').show();
  2106. break;
  2107. case 'showMinutes':
  2108. this.widget.find('.timepicker .timepicker-picker').hide();
  2109. this.widget.find('.timepicker .timepicker-minutes').show();
  2110. break;
  2111. case 'showSeconds':
  2112. this.widget.find('.timepicker .timepicker-picker').hide();
  2113. this.widget.find('.timepicker .timepicker-seconds').show();
  2114. break;
  2115. case 'selectHour':
  2116. {
  2117. var hour = parseInt($(e.target).text(), 10);
  2118. if (!this.use24Hours) {
  2119. if (lastPicked.hours() >= 12) {
  2120. if (hour !== 12) {
  2121. hour += 12;
  2122. }
  2123. } else {
  2124. if (hour === 12) {
  2125. hour = 0;
  2126. }
  2127. }
  2128. }
  2129. this._setValue(lastPicked.clone().hours(hour), this._getLastPickedDateIndex());
  2130. if (!this._isEnabled('a') && !this._isEnabled('m') && !this._options.keepOpen && !this._options.inline) {
  2131. this.hide();
  2132. } else {
  2133. this._doAction(e, 'showPicker');
  2134. }
  2135. break;
  2136. }
  2137. case 'selectMinute':
  2138. this._setValue(lastPicked.clone().minutes(parseInt($(e.target).text(), 10)), this._getLastPickedDateIndex());
  2139. if (!this._isEnabled('a') && !this._isEnabled('s') && !this._options.keepOpen && !this._options.inline) {
  2140. this.hide();
  2141. } else {
  2142. this._doAction(e, 'showPicker');
  2143. }
  2144. break;
  2145. case 'selectSecond':
  2146. this._setValue(lastPicked.clone().seconds(parseInt($(e.target).text(), 10)), this._getLastPickedDateIndex());
  2147. if (!this._isEnabled('a') && !this._options.keepOpen && !this._options.inline) {
  2148. this.hide();
  2149. } else {
  2150. this._doAction(e, 'showPicker');
  2151. }
  2152. break;
  2153. case 'clear':
  2154. this.clear();
  2155. break;
  2156. case 'close':
  2157. this.hide();
  2158. break;
  2159. case 'today':
  2160. {
  2161. var todaysDate = this.getMoment();
  2162. if (this._isValid(todaysDate, 'd')) {
  2163. this._setValue(todaysDate, this._getLastPickedDateIndex());
  2164. }
  2165. break;
  2166. }
  2167. }
  2168. return false;
  2169. };
  2170. //public
  2171. TempusDominusBootstrap4.prototype.hide = function hide() {
  2172. var transitioning = false;
  2173. if (!this.widget) {
  2174. return;
  2175. }
  2176. // Ignore event if in the middle of a picker transition
  2177. this.widget.find('.collapse').each(function () {
  2178. var collapseData = $(this).data('collapse');
  2179. if (collapseData && collapseData.transitioning) {
  2180. transitioning = true;
  2181. return false;
  2182. }
  2183. return true;
  2184. });
  2185. if (transitioning) {
  2186. return;
  2187. }
  2188. if (this.component && this.component.hasClass('btn')) {
  2189. this.component.toggleClass('active');
  2190. }
  2191. this.widget.hide();
  2192. $(window).off('resize', this._place());
  2193. this.widget.off('click', '[data-action]');
  2194. this.widget.off('mousedown', false);
  2195. this.widget.remove();
  2196. this.widget = false;
  2197. this._notifyEvent({
  2198. type: DateTimePicker.Event.HIDE,
  2199. date: this._getLastPickedDate().clone()
  2200. });
  2201. if (this.input !== undefined) {
  2202. this.input.blur();
  2203. }
  2204. this._viewDate = this._getLastPickedDate().clone();
  2205. };
  2206. TempusDominusBootstrap4.prototype.show = function show() {
  2207. var currentMoment = void 0;
  2208. var useCurrentGranularity = {
  2209. 'year': function year(m) {
  2210. return m.month(0).date(1).hours(0).seconds(0).minutes(0);
  2211. },
  2212. 'month': function month(m) {
  2213. return m.date(1).hours(0).seconds(0).minutes(0);
  2214. },
  2215. 'day': function day(m) {
  2216. return m.hours(0).seconds(0).minutes(0);
  2217. },
  2218. 'hour': function hour(m) {
  2219. return m.seconds(0).minutes(0);
  2220. },
  2221. 'minute': function minute(m) {
  2222. return m.seconds(0);
  2223. }
  2224. };
  2225. if (this.input !== undefined) {
  2226. if (this.input.prop('disabled') || !this._options.ignoreReadonly && this.input.prop('readonly') || this.widget) {
  2227. return;
  2228. }
  2229. if (this.input.val() !== undefined && this.input.val().trim().length !== 0) {
  2230. this._setValue(this._parseInputDate(this.input.val().trim()), 0);
  2231. } else if (this.unset && this._options.useCurrent) {
  2232. currentMoment = this.getMoment();
  2233. if (typeof this._options.useCurrent === 'string') {
  2234. currentMoment = useCurrentGranularity[this._options.useCurrent](currentMoment);
  2235. }
  2236. this._setValue(currentMoment, 0);
  2237. }
  2238. } else if (this.unset && this._options.useCurrent) {
  2239. currentMoment = this.getMoment();
  2240. if (typeof this._options.useCurrent === 'string') {
  2241. currentMoment = useCurrentGranularity[this._options.useCurrent](currentMoment);
  2242. }
  2243. this._setValue(currentMoment, 0);
  2244. }
  2245. this.widget = this._getTemplate();
  2246. this._fillDow();
  2247. this._fillMonths();
  2248. this.widget.find('.timepicker-hours').hide();
  2249. this.widget.find('.timepicker-minutes').hide();
  2250. this.widget.find('.timepicker-seconds').hide();
  2251. this._update();
  2252. this._showMode();
  2253. $(window).on('resize', { picker: this }, this._place);
  2254. this.widget.on('click', '[data-action]', $.proxy(this._doAction, this)); // this handles clicks on the widget
  2255. this.widget.on('mousedown', false);
  2256. if (this.component && this.component.hasClass('btn')) {
  2257. this.component.toggleClass('active');
  2258. }
  2259. this._place();
  2260. this.widget.show();
  2261. if (this.input !== undefined && this._options.focusOnShow && !this.input.is(':focus')) {
  2262. this.input.focus();
  2263. }
  2264. this._notifyEvent({
  2265. type: DateTimePicker.Event.SHOW
  2266. });
  2267. };
  2268. TempusDominusBootstrap4.prototype.destroy = function destroy() {
  2269. this.hide();
  2270. //todo doc off?
  2271. this._element.removeData(DateTimePicker.DATA_KEY);
  2272. this._element.removeData('date');
  2273. };
  2274. TempusDominusBootstrap4.prototype.disable = function disable() {
  2275. this.hide();
  2276. if (this.component && this.component.hasClass('btn')) {
  2277. this.component.addClass('disabled');
  2278. }
  2279. if (this.input !== undefined) {
  2280. this.input.prop('disabled', true); //todo disable this/comp if input is null
  2281. }
  2282. };
  2283. TempusDominusBootstrap4.prototype.enable = function enable() {
  2284. if (this.component && this.component.hasClass('btn')) {
  2285. this.component.removeClass('disabled');
  2286. }
  2287. if (this.input !== undefined) {
  2288. this.input.prop('disabled', false); //todo enable comp/this if input is null
  2289. }
  2290. };
  2291. TempusDominusBootstrap4.prototype.toolbarPlacement = function toolbarPlacement(_toolbarPlacement) {
  2292. if (arguments.length === 0) {
  2293. return this._options.toolbarPlacement;
  2294. }
  2295. if (typeof _toolbarPlacement !== 'string') {
  2296. throw new TypeError('toolbarPlacement() expects a string parameter');
  2297. }
  2298. if (toolbarPlacements.indexOf(_toolbarPlacement) === -1) {
  2299. throw new TypeError('toolbarPlacement() parameter must be one of (' + toolbarPlacements.join(', ') + ') value');
  2300. }
  2301. this._options.toolbarPlacement = _toolbarPlacement;
  2302. if (this.widget) {
  2303. this.hide();
  2304. this.show();
  2305. }
  2306. };
  2307. TempusDominusBootstrap4.prototype.widgetPositioning = function widgetPositioning(_widgetPositioning) {
  2308. if (arguments.length === 0) {
  2309. return $.extend({}, this._options.widgetPositioning);
  2310. }
  2311. if ({}.toString.call(_widgetPositioning) !== '[object Object]') {
  2312. throw new TypeError('widgetPositioning() expects an object variable');
  2313. }
  2314. if (_widgetPositioning.horizontal) {
  2315. if (typeof _widgetPositioning.horizontal !== 'string') {
  2316. throw new TypeError('widgetPositioning() horizontal variable must be a string');
  2317. }
  2318. _widgetPositioning.horizontal = _widgetPositioning.horizontal.toLowerCase();
  2319. if (horizontalModes.indexOf(_widgetPositioning.horizontal) === -1) {
  2320. throw new TypeError('widgetPositioning() expects horizontal parameter to be one of (' + horizontalModes.join(', ') + ')');
  2321. }
  2322. this._options.widgetPositioning.horizontal = _widgetPositioning.horizontal;
  2323. }
  2324. if (_widgetPositioning.vertical) {
  2325. if (typeof _widgetPositioning.vertical !== 'string') {
  2326. throw new TypeError('widgetPositioning() vertical variable must be a string');
  2327. }
  2328. _widgetPositioning.vertical = _widgetPositioning.vertical.toLowerCase();
  2329. if (verticalModes.indexOf(_widgetPositioning.vertical) === -1) {
  2330. throw new TypeError('widgetPositioning() expects vertical parameter to be one of (' + verticalModes.join(', ') + ')');
  2331. }
  2332. this._options.widgetPositioning.vertical = _widgetPositioning.vertical;
  2333. }
  2334. this._update();
  2335. };
  2336. TempusDominusBootstrap4.prototype.widgetParent = function widgetParent(_widgetParent) {
  2337. if (arguments.length === 0) {
  2338. return this._options.widgetParent;
  2339. }
  2340. if (typeof _widgetParent === 'string') {
  2341. _widgetParent = $(_widgetParent);
  2342. }
  2343. if (_widgetParent !== null && typeof _widgetParent !== 'string' && !(_widgetParent instanceof $)) {
  2344. throw new TypeError('widgetParent() expects a string or a jQuery object parameter');
  2345. }
  2346. this._options.widgetParent = _widgetParent;
  2347. if (this.widget) {
  2348. this.hide();
  2349. this.show();
  2350. }
  2351. };
  2352. //static
  2353. TempusDominusBootstrap4._jQueryHandleThis = function _jQueryHandleThis(me, option, argument) {
  2354. var data = $(me).data(DateTimePicker.DATA_KEY);
  2355. if ((typeof option === 'undefined' ? 'undefined' : _typeof(option)) === 'object') {
  2356. $.extend({}, DateTimePicker.Default, option);
  2357. }
  2358. if (!data) {
  2359. data = new TempusDominusBootstrap4($(me), option);
  2360. $(me).data(DateTimePicker.DATA_KEY, data);
  2361. }
  2362. if (typeof option === 'string') {
  2363. if (data[option] === undefined) {
  2364. throw new Error('No method named "' + option + '"');
  2365. }
  2366. if (argument === undefined) {
  2367. return data[option]();
  2368. } else {
  2369. return data[option](argument);
  2370. }
  2371. }
  2372. };
  2373. TempusDominusBootstrap4._jQueryInterface = function _jQueryInterface(option, argument) {
  2374. if (this.length === 1) {
  2375. return TempusDominusBootstrap4._jQueryHandleThis(this[0], option, argument);
  2376. }
  2377. return this.each(function () {
  2378. TempusDominusBootstrap4._jQueryHandleThis(this, option, argument);
  2379. });
  2380. };
  2381. return TempusDominusBootstrap4;
  2382. }(DateTimePicker);
  2383. /**
  2384. * ------------------------------------------------------------------------
  2385. * jQuery
  2386. * ------------------------------------------------------------------------
  2387. */
  2388. $(document).on(DateTimePicker.Event.CLICK_DATA_API, DateTimePicker.Selector.DATA_TOGGLE, function () {
  2389. var $target = getSelectorFromElement($(this));
  2390. if ($target.length === 0) {
  2391. return;
  2392. }
  2393. TempusDominusBootstrap4._jQueryInterface.call($target, 'toggle');
  2394. }).on(DateTimePicker.Event.CHANGE, '.' + DateTimePicker.ClassName.INPUT, function (event) {
  2395. var $target = getSelectorFromElement($(this));
  2396. if ($target.length === 0) {
  2397. return;
  2398. }
  2399. TempusDominusBootstrap4._jQueryInterface.call($target, '_change', event);
  2400. }).on(DateTimePicker.Event.BLUR, '.' + DateTimePicker.ClassName.INPUT, function (event) {
  2401. var $target = getSelectorFromElement($(this)),
  2402. config = $target.data(DateTimePicker.DATA_KEY);
  2403. if ($target.length === 0) {
  2404. return;
  2405. }
  2406. if (config._options.debug || window.debug) {
  2407. return;
  2408. }
  2409. TempusDominusBootstrap4._jQueryInterface.call($target, 'hide', event);
  2410. }).on(DateTimePicker.Event.KEYDOWN, '.' + DateTimePicker.ClassName.INPUT, function (event) {
  2411. var $target = getSelectorFromElement($(this));
  2412. if ($target.length === 0) {
  2413. return;
  2414. }
  2415. TempusDominusBootstrap4._jQueryInterface.call($target, '_keydown', event);
  2416. }).on(DateTimePicker.Event.KEYUP, '.' + DateTimePicker.ClassName.INPUT, function (event) {
  2417. var $target = getSelectorFromElement($(this));
  2418. if ($target.length === 0) {
  2419. return;
  2420. }
  2421. TempusDominusBootstrap4._jQueryInterface.call($target, '_keyup', event);
  2422. }).on(DateTimePicker.Event.FOCUS, '.' + DateTimePicker.ClassName.INPUT, function (event) {
  2423. var $target = getSelectorFromElement($(this)),
  2424. config = $target.data(DateTimePicker.DATA_KEY);
  2425. if ($target.length === 0) {
  2426. return;
  2427. }
  2428. if (!config._options.allowInputToggle) {
  2429. return;
  2430. }
  2431. TempusDominusBootstrap4._jQueryInterface.call($target, 'show', event);
  2432. });
  2433. $.fn[DateTimePicker.NAME] = TempusDominusBootstrap4._jQueryInterface;
  2434. $.fn[DateTimePicker.NAME].Constructor = TempusDominusBootstrap4;
  2435. $.fn[DateTimePicker.NAME].noConflict = function () {
  2436. $.fn[DateTimePicker.NAME] = JQUERY_NO_CONFLICT;
  2437. return TempusDominusBootstrap4._jQueryInterface;
  2438. };
  2439. return TempusDominusBootstrap4;
  2440. }(jQuery);
  2441. }();