bootstrap-datetimepicker.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  1. /* =========================================================
  2. * bootstrap-datetimepicker.js
  3. * =========================================================
  4. * Copyright 2012 Stefan Petre
  5. * Improvements by Andrew Rowls
  6. * Improvements by Sébastien Malot
  7. * Improvements by Yun Lai
  8. * Improvements by Kenneth Henderick
  9. * Project URL : http://www.malot.fr/bootstrap-datetimepicker
  10. *
  11. * Licensed under the Apache License, Version 2.0 (the "License");
  12. * you may not use this file except in compliance with the License.
  13. * You may obtain a copy of the License at
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  17. * Unless required by applicable law or agreed to in writing, software
  18. * distributed under the License is distributed on an "AS IS" BASIS,
  19. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  20. * See the License for the specific language governing permissions and
  21. * limitations under the License.
  22. * ========================================================= */
  23. /*
  24. * Improvement by CuGBabyBeaR @ 2013-09-12
  25. *
  26. * Make it work in bootstrap v3
  27. */
  28. !function ($) {
  29. function UTCDate() {
  30. return new Date(Date.UTC.apply(Date, arguments));
  31. }
  32. function UTCToday() {
  33. var today = new Date();
  34. return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), today.getUTCHours(), today.getUTCMinutes(), today.getUTCSeconds(), 0);
  35. }
  36. // Picker object
  37. var Datetimepicker = function (element, options) {
  38. var that = this;
  39. this.element = $(element);
  40. // add container for single page application
  41. // when page switch the datetimepicker div will be removed also.
  42. this.container = options.container || 'body';
  43. this.language = options.language || this.element.data('date-language') || "en";
  44. this.language = this.language in dates ? this.language : "en";
  45. this.isRTL = dates[this.language].rtl || false;
  46. this.formatType = options.formatType || this.element.data('format-type') || 'standard';
  47. this.format = DPGlobal.parseFormat(options.format || this.element.data('date-format') || dates[this.language].format || DPGlobal.getDefaultFormat(this.formatType, 'input'), this.formatType);
  48. this.isInline = false;
  49. this.isVisible = false;
  50. this.isInput = this.element.is('input');
  51. this.fontAwesome = options.fontAwesome || this.element.data('font-awesome') || false;
  52. this.bootcssVer = options.bootcssVer || (this.isInput ? (this.element.is('.form-control') ? 3 : 2) : ( this.bootcssVer = this.element.is('.input-group') ? 3 : 2 ));
  53. this.component = this.element.is('.date') ? ( this.bootcssVer == 3 ? this.element.find('.input-group-addon .glyphicon-th, .input-group-addon .glyphicon-time, .input-group-addon .glyphicon-calendar, .input-group-addon .glyphicon-calendar, .input-group-addon .fa-calendar, .input-group-addon .fa-clock-o').parent() : this.element.find('.add-on .icon-th, .add-on .icon-time, .add-on .icon-calendar .fa-calendar .fa-clock-o').parent()) : false;
  54. this.componentReset = this.element.is('.date') ? ( this.bootcssVer == 3 ? this.element.find(".input-group-addon .glyphicon-remove, .input-group-addon .fa-times").parent():this.element.find(".add-on .icon-remove, .add-on .fa-times").parent()) : false;
  55. this.hasInput = this.component && this.element.find('input').length;
  56. if (this.component && this.component.length === 0) {
  57. this.component = false;
  58. }
  59. this.linkField = options.linkField || this.element.data('link-field') || false;
  60. this.linkFormat = DPGlobal.parseFormat(options.linkFormat || this.element.data('link-format') || DPGlobal.getDefaultFormat(this.formatType, 'link'), this.formatType);
  61. this.minuteStep = options.minuteStep || this.element.data('minute-step') || 5;
  62. this.pickerPosition = options.pickerPosition || this.element.data('picker-position') || 'bottom-right';
  63. this.showMeridian = options.showMeridian || this.element.data('show-meridian') || false;
  64. this.initialDate = options.initialDate || new Date();
  65. this.zIndex = options.zIndex || this.element.data('z-index') || undefined;
  66. this.icons = {
  67. leftArrow: this.fontAwesome ? 'fa-arrow-left' : (this.bootcssVer === 3 ? 'glyphicon-arrow-left' : 'icon-arrow-left'),
  68. rightArrow: this.fontAwesome ? 'fa-arrow-right' : (this.bootcssVer === 3 ? 'glyphicon-arrow-right' : 'icon-arrow-right')
  69. };
  70. this.icontype = this.fontAwesome ? 'fa' : 'glyphicon';
  71. this._attachEvents();
  72. this.formatViewType = "datetime";
  73. if ('formatViewType' in options) {
  74. this.formatViewType = options.formatViewType;
  75. } else if ('formatViewType' in this.element.data()) {
  76. this.formatViewType = this.element.data('formatViewType');
  77. }
  78. this.minView = 0;
  79. if ('minView' in options) {
  80. this.minView = options.minView;
  81. } else if ('minView' in this.element.data()) {
  82. this.minView = this.element.data('min-view');
  83. }
  84. this.minView = DPGlobal.convertViewMode(this.minView);
  85. this.maxView = DPGlobal.modes.length - 1;
  86. if ('maxView' in options) {
  87. this.maxView = options.maxView;
  88. } else if ('maxView' in this.element.data()) {
  89. this.maxView = this.element.data('max-view');
  90. }
  91. this.maxView = DPGlobal.convertViewMode(this.maxView);
  92. this.wheelViewModeNavigation = false;
  93. if ('wheelViewModeNavigation' in options) {
  94. this.wheelViewModeNavigation = options.wheelViewModeNavigation;
  95. } else if ('wheelViewModeNavigation' in this.element.data()) {
  96. this.wheelViewModeNavigation = this.element.data('view-mode-wheel-navigation');
  97. }
  98. this.wheelViewModeNavigationInverseDirection = false;
  99. if ('wheelViewModeNavigationInverseDirection' in options) {
  100. this.wheelViewModeNavigationInverseDirection = options.wheelViewModeNavigationInverseDirection;
  101. } else if ('wheelViewModeNavigationInverseDirection' in this.element.data()) {
  102. this.wheelViewModeNavigationInverseDirection = this.element.data('view-mode-wheel-navigation-inverse-dir');
  103. }
  104. this.wheelViewModeNavigationDelay = 100;
  105. if ('wheelViewModeNavigationDelay' in options) {
  106. this.wheelViewModeNavigationDelay = options.wheelViewModeNavigationDelay;
  107. } else if ('wheelViewModeNavigationDelay' in this.element.data()) {
  108. this.wheelViewModeNavigationDelay = this.element.data('view-mode-wheel-navigation-delay');
  109. }
  110. this.startViewMode = 2;
  111. if ('startView' in options) {
  112. this.startViewMode = options.startView;
  113. } else if ('startView' in this.element.data()) {
  114. this.startViewMode = this.element.data('start-view');
  115. }
  116. this.startViewMode = DPGlobal.convertViewMode(this.startViewMode);
  117. this.viewMode = this.startViewMode;
  118. this.viewSelect = this.minView;
  119. if ('viewSelect' in options) {
  120. this.viewSelect = options.viewSelect;
  121. } else if ('viewSelect' in this.element.data()) {
  122. this.viewSelect = this.element.data('view-select');
  123. }
  124. this.viewSelect = DPGlobal.convertViewMode(this.viewSelect);
  125. this.forceParse = true;
  126. if ('forceParse' in options) {
  127. this.forceParse = options.forceParse;
  128. } else if ('dateForceParse' in this.element.data()) {
  129. this.forceParse = this.element.data('date-force-parse');
  130. }
  131. var template = this.bootcssVer === 3 ? DPGlobal.templateV3 : DPGlobal.template;
  132. while (template.indexOf('{iconType}') !== -1) {
  133. template = template.replace('{iconType}', this.icontype);
  134. }
  135. while (template.indexOf('{leftArrow}') !== -1) {
  136. template = template.replace('{leftArrow}', this.icons.leftArrow);
  137. }
  138. while (template.indexOf('{rightArrow}') !== -1) {
  139. template = template.replace('{rightArrow}', this.icons.rightArrow);
  140. }
  141. this.picker = $(template)
  142. .appendTo(this.isInline ? this.element : this.container) // 'body')
  143. .on({
  144. click: $.proxy(this.click, this),
  145. mousedown: $.proxy(this.mousedown, this)
  146. });
  147. if (this.wheelViewModeNavigation) {
  148. if ($.fn.mousewheel) {
  149. this.picker.on({mousewheel: $.proxy(this.mousewheel, this)});
  150. } else {
  151. console.log("Mouse Wheel event is not supported. Please include the jQuery Mouse Wheel plugin before enabling this option");
  152. }
  153. }
  154. if (this.isInline) {
  155. this.picker.addClass('datetimepicker-inline');
  156. } else {
  157. this.picker.addClass('datetimepicker-dropdown-' + this.pickerPosition + ' dropdown-menu');
  158. }
  159. if (this.isRTL) {
  160. this.picker.addClass('datetimepicker-rtl');
  161. var selector = this.bootcssVer === 3 ? '.prev span, .next span' : '.prev i, .next i';
  162. this.picker.find(selector).toggleClass(this.icons.leftArrow + ' ' + this.icons.rightArrow);
  163. }
  164. $(document).on('mousedown', function (e) {
  165. // Clicked outside the datetimepicker, hide it
  166. if ($(e.target).closest('.datetimepicker').length === 0) {
  167. that.hide();
  168. }
  169. });
  170. this.autoclose = false;
  171. if ('autoclose' in options) {
  172. this.autoclose = options.autoclose;
  173. } else if ('dateAutoclose' in this.element.data()) {
  174. this.autoclose = this.element.data('date-autoclose');
  175. }
  176. this.keyboardNavigation = true;
  177. if ('keyboardNavigation' in options) {
  178. this.keyboardNavigation = options.keyboardNavigation;
  179. } else if ('dateKeyboardNavigation' in this.element.data()) {
  180. this.keyboardNavigation = this.element.data('date-keyboard-navigation');
  181. }
  182. this.todayBtn = (options.todayBtn || this.element.data('date-today-btn') || false);
  183. this.todayHighlight = (options.todayHighlight || this.element.data('date-today-highlight') || false);
  184. this.weekStart = ((options.weekStart || this.element.data('date-weekstart') || dates[this.language].weekStart || 0) % 7);
  185. this.weekEnd = ((this.weekStart + 6) % 7);
  186. this.startDate = -Infinity;
  187. this.endDate = Infinity;
  188. this.daysOfWeekDisabled = [];
  189. this.setStartDate(options.startDate || this.element.data('date-startdate'));
  190. this.setEndDate(options.endDate || this.element.data('date-enddate'));
  191. this.setDaysOfWeekDisabled(options.daysOfWeekDisabled || this.element.data('date-days-of-week-disabled'));
  192. this.setMinutesDisabled(options.minutesDisabled || this.element.data('date-minute-disabled'));
  193. this.setHoursDisabled(options.hoursDisabled || this.element.data('date-hour-disabled'));
  194. this.fillDow();
  195. this.fillMonths();
  196. this.update();
  197. this.showMode();
  198. if (this.isInline) {
  199. this.show();
  200. }
  201. };
  202. Datetimepicker.prototype = {
  203. constructor: Datetimepicker,
  204. _events: [],
  205. _attachEvents: function () {
  206. this._detachEvents();
  207. if (this.isInput) { // single input
  208. this._events = [
  209. [this.element, {
  210. focus: $.proxy(this.show, this),
  211. keyup: $.proxy(this.update, this),
  212. keydown: $.proxy(this.keydown, this)
  213. }]
  214. ];
  215. }
  216. else if (this.component && this.hasInput) { // component: input + button
  217. this._events = [
  218. // For components that are not readonly, allow keyboard nav
  219. [this.element.find('input'), {
  220. focus: $.proxy(this.show, this),
  221. keyup: $.proxy(this.update, this),
  222. keydown: $.proxy(this.keydown, this)
  223. }],
  224. [this.component, {
  225. click: $.proxy(this.show, this)
  226. }]
  227. ];
  228. if (this.componentReset) {
  229. this._events.push([
  230. this.componentReset,
  231. {click: $.proxy(this.reset, this)}
  232. ]);
  233. }
  234. }
  235. else if (this.element.is('div')) { // inline datetimepicker
  236. this.isInline = true;
  237. }
  238. else {
  239. this._events = [
  240. [this.element, {
  241. click: $.proxy(this.show, this)
  242. }]
  243. ];
  244. }
  245. for (var i = 0, el, ev; i < this._events.length; i++) {
  246. el = this._events[i][0];
  247. ev = this._events[i][1];
  248. el.on(ev);
  249. }
  250. },
  251. _detachEvents: function () {
  252. for (var i = 0, el, ev; i < this._events.length; i++) {
  253. el = this._events[i][0];
  254. ev = this._events[i][1];
  255. el.off(ev);
  256. }
  257. this._events = [];
  258. },
  259. show: function (e) {
  260. this.picker.show();
  261. this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
  262. if (this.forceParse) {
  263. this.update();
  264. }
  265. this.place();
  266. $(window).on('resize', $.proxy(this.place, this));
  267. if (e) {
  268. e.stopPropagation();
  269. e.preventDefault();
  270. }
  271. this.isVisible = true;
  272. this.element.trigger({
  273. type: 'show',
  274. date: this.date
  275. });
  276. },
  277. hide: function (e) {
  278. if (!this.isVisible) return;
  279. if (this.isInline) return;
  280. this.picker.hide();
  281. $(window).off('resize', this.place);
  282. this.viewMode = this.startViewMode;
  283. this.showMode();
  284. if (!this.isInput) {
  285. $(document).off('mousedown', this.hide);
  286. }
  287. if (
  288. this.forceParse &&
  289. (
  290. this.isInput && this.element.val() ||
  291. this.hasInput && this.element.find('input').val()
  292. )
  293. )
  294. this.setValue();
  295. this.isVisible = false;
  296. this.element.trigger({
  297. type: 'hide',
  298. date: this.date
  299. });
  300. },
  301. remove: function () {
  302. this._detachEvents();
  303. this.picker.remove();
  304. delete this.picker;
  305. delete this.element.data().datetimepicker;
  306. },
  307. getDate: function () {
  308. var d = this.getUTCDate();
  309. return new Date(d.getTime() + (d.getTimezoneOffset() * 60000));
  310. },
  311. getUTCDate: function () {
  312. return this.date;
  313. },
  314. setDate: function (d) {
  315. this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset() * 60000)));
  316. },
  317. setUTCDate: function (d) {
  318. if (d >= this.startDate && d <= this.endDate) {
  319. this.date = d;
  320. this.setValue();
  321. this.viewDate = this.date;
  322. this.fill();
  323. } else {
  324. this.element.trigger({
  325. type: 'outOfRange',
  326. date: d,
  327. startDate: this.startDate,
  328. endDate: this.endDate
  329. });
  330. }
  331. },
  332. setFormat: function (format) {
  333. this.format = DPGlobal.parseFormat(format, this.formatType);
  334. var element;
  335. if (this.isInput) {
  336. element = this.element;
  337. } else if (this.component) {
  338. element = this.element.find('input');
  339. }
  340. if (element && element.val()) {
  341. this.setValue();
  342. }
  343. },
  344. setValue: function () {
  345. var formatted = this.getFormattedDate();
  346. if (!this.isInput) {
  347. if (this.component) {
  348. this.element.find('input').val(formatted);
  349. }
  350. this.element.data('date', formatted);
  351. } else {
  352. this.element.val(formatted);
  353. }
  354. if (this.linkField) {
  355. $('#' + this.linkField).val(this.getFormattedDate(this.linkFormat));
  356. }
  357. },
  358. getFormattedDate: function (format) {
  359. if (format == undefined) format = this.format;
  360. return DPGlobal.formatDate(this.date, format, this.language, this.formatType);
  361. },
  362. setStartDate: function (startDate) {
  363. this.startDate = startDate || -Infinity;
  364. if (this.startDate !== -Infinity) {
  365. this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language, this.formatType);
  366. }
  367. this.update();
  368. this.updateNavArrows();
  369. },
  370. setEndDate: function (endDate) {
  371. this.endDate = endDate || Infinity;
  372. if (this.endDate !== Infinity) {
  373. this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language, this.formatType);
  374. }
  375. this.update();
  376. this.updateNavArrows();
  377. },
  378. setDaysOfWeekDisabled: function (daysOfWeekDisabled) {
  379. this.daysOfWeekDisabled = daysOfWeekDisabled || [];
  380. if (!$.isArray(this.daysOfWeekDisabled)) {
  381. this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
  382. }
  383. this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function (d) {
  384. return parseInt(d, 10);
  385. });
  386. this.update();
  387. this.updateNavArrows();
  388. },
  389. setMinutesDisabled: function (minutesDisabled) {
  390. this.minutesDisabled = minutesDisabled || [];
  391. if (!$.isArray(this.minutesDisabled)) {
  392. this.minutesDisabled = this.minutesDisabled.split(/,\s*/);
  393. }
  394. this.minutesDisabled = $.map(this.minutesDisabled, function (d) {
  395. return parseInt(d, 10);
  396. });
  397. this.update();
  398. this.updateNavArrows();
  399. },
  400. setHoursDisabled: function (hoursDisabled) {
  401. this.hoursDisabled = hoursDisabled || [];
  402. if (!$.isArray(this.hoursDisabled)) {
  403. this.hoursDisabled = this.hoursDisabled.split(/,\s*/);
  404. }
  405. this.hoursDisabled = $.map(this.hoursDisabled, function (d) {
  406. return parseInt(d, 10);
  407. });
  408. this.update();
  409. this.updateNavArrows();
  410. },
  411. place: function () {
  412. if (this.isInline) return;
  413. if (!this.zIndex) {
  414. var index_highest = 0;
  415. $('div').each(function () {
  416. var index_current = parseInt($(this).css("zIndex"), 10);
  417. if (index_current > index_highest) {
  418. index_highest = index_current;
  419. }
  420. });
  421. this.zIndex = index_highest + 10;
  422. }
  423. var offset, top, left, containerOffset;
  424. if (this.container instanceof $) {
  425. containerOffset = this.container.offset();
  426. } else {
  427. containerOffset = $(this.container).offset();
  428. }
  429. if (this.component) {
  430. offset = this.component.offset();
  431. left = offset.left;
  432. if (this.pickerPosition == 'bottom-left' || this.pickerPosition == 'top-left') {
  433. left += this.component.outerWidth() - this.picker.outerWidth();
  434. }
  435. } else {
  436. offset = this.element.offset();
  437. left = offset.left;
  438. }
  439. if(left+220 > document.body.clientWidth){
  440. left = document.body.clientWidth-220;
  441. }
  442. if (this.pickerPosition == 'top-left' || this.pickerPosition == 'top-right') {
  443. top = offset.top - this.picker.outerHeight();
  444. } else {
  445. top = offset.top + this.height;
  446. }
  447. top = top - containerOffset.top;
  448. left = left - containerOffset.left;
  449. if(this.container != 'body') top = top + document.body.scrollTop
  450. this.picker.css({
  451. top: top,
  452. left: left,
  453. zIndex: this.zIndex
  454. });
  455. },
  456. update: function () {
  457. var date, fromArgs = false;
  458. if (arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
  459. date = arguments[0];
  460. fromArgs = true;
  461. } else {
  462. date = (this.isInput ? this.element.val() : this.element.find('input').val()) || this.element.data('date') || this.initialDate;
  463. if (typeof date == 'string' || date instanceof String) {
  464. date = date.replace(/^\s+|\s+$/g,'');
  465. }
  466. }
  467. if (!date) {
  468. date = new Date();
  469. fromArgs = false;
  470. }
  471. this.date = DPGlobal.parseDate(date, this.format, this.language, this.formatType);
  472. if (fromArgs) this.setValue();
  473. if (this.date < this.startDate) {
  474. this.viewDate = new Date(this.startDate);
  475. } else if (this.date > this.endDate) {
  476. this.viewDate = new Date(this.endDate);
  477. } else {
  478. this.viewDate = new Date(this.date);
  479. }
  480. this.fill();
  481. },
  482. fillDow: function () {
  483. var dowCnt = this.weekStart,
  484. html = '<tr>';
  485. while (dowCnt < this.weekStart + 7) {
  486. html += '<th class="dow">' + dates[this.language].daysMin[(dowCnt++) % 7] + '</th>';
  487. }
  488. html += '</tr>';
  489. this.picker.find('.datetimepicker-days thead').append(html);
  490. },
  491. fillMonths: function () {
  492. var html = '',
  493. i = 0;
  494. while (i < 12) {
  495. html += '<span class="month">' + dates[this.language].monthsShort[i++] + '</span>';
  496. }
  497. this.picker.find('.datetimepicker-months td').html(html);
  498. },
  499. fill: function () {
  500. if (this.date == null || this.viewDate == null) {
  501. return;
  502. }
  503. var d = new Date(this.viewDate),
  504. year = d.getUTCFullYear(),
  505. month = d.getUTCMonth(),
  506. dayMonth = d.getUTCDate(),
  507. hours = d.getUTCHours(),
  508. minutes = d.getUTCMinutes(),
  509. startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
  510. startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() + 1 : -Infinity,
  511. endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
  512. endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() + 1 : Infinity,
  513. currentDate = (new UTCDate(this.date.getUTCFullYear(), this.date.getUTCMonth(), this.date.getUTCDate())).valueOf(),
  514. today = new Date();
  515. this.picker.find('.datetimepicker-days thead th:eq(1)')
  516. .text(dates[this.language].months[month] + ' ' + year);
  517. if (this.formatViewType == "time") {
  518. var formatted = this.getFormattedDate();
  519. this.picker.find('.datetimepicker-hours thead th:eq(1)').text(formatted);
  520. this.picker.find('.datetimepicker-minutes thead th:eq(1)').text(formatted);
  521. } else {
  522. this.picker.find('.datetimepicker-hours thead th:eq(1)')
  523. .text(dayMonth + ' ' + dates[this.language].months[month] + ' ' + year);
  524. this.picker.find('.datetimepicker-minutes thead th:eq(1)')
  525. .text(dayMonth + ' ' + dates[this.language].months[month] + ' ' + year);
  526. }
  527. this.picker.find('tfoot th.today')
  528. .text(dates[this.language].today)
  529. .toggle(this.todayBtn !== false);
  530. this.updateNavArrows();
  531. this.fillMonths();
  532. /*var prevMonth = UTCDate(year, month, 0,0,0,0,0);
  533. prevMonth.setUTCDate(prevMonth.getDate() - (prevMonth.getUTCDay() - this.weekStart + 7)%7);*/
  534. var prevMonth = UTCDate(year, month - 1, 28, 0, 0, 0, 0),
  535. day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
  536. prevMonth.setUTCDate(day);
  537. prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7) % 7);
  538. var nextMonth = new Date(prevMonth);
  539. nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
  540. nextMonth = nextMonth.valueOf();
  541. var html = [];
  542. var clsName;
  543. while (prevMonth.valueOf() < nextMonth) {
  544. if (prevMonth.getUTCDay() == this.weekStart) {
  545. html.push('<tr>');
  546. }
  547. clsName = '';
  548. if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
  549. clsName += ' old';
  550. } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
  551. clsName += ' new';
  552. }
  553. // Compare internal UTC date with local today, not UTC today
  554. if (this.todayHighlight &&
  555. prevMonth.getUTCFullYear() == today.getFullYear() &&
  556. prevMonth.getUTCMonth() == today.getMonth() &&
  557. prevMonth.getUTCDate() == today.getDate()) {
  558. clsName += ' today';
  559. }
  560. if (prevMonth.valueOf() == currentDate) {
  561. clsName += ' active';
  562. }
  563. if ((prevMonth.valueOf() + 86400000) <= this.startDate || prevMonth.valueOf() > this.endDate ||
  564. $.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) !== -1) {
  565. clsName += ' disabled';
  566. }
  567. html.push('<td class="day' + clsName + '">' + prevMonth.getUTCDate() + '</td>');
  568. if (prevMonth.getUTCDay() == this.weekEnd) {
  569. html.push('</tr>');
  570. }
  571. prevMonth.setUTCDate(prevMonth.getUTCDate() + 1);
  572. }
  573. this.picker.find('.datetimepicker-days tbody').empty().append(html.join(''));
  574. html = [];
  575. var txt = '', meridian = '', meridianOld = '';
  576. var hoursDisabled = this.hoursDisabled || [];
  577. for (var i = 0; i < 24; i++) {
  578. if (hoursDisabled.indexOf(i) !== -1) continue;
  579. var actual = UTCDate(year, month, dayMonth, i);
  580. clsName = '';
  581. // We want the previous hour for the startDate
  582. if ((actual.valueOf() + 3600000) <= this.startDate || actual.valueOf() > this.endDate) {
  583. clsName += ' disabled';
  584. } else if (hours == i) {
  585. clsName += ' active';
  586. }
  587. if (this.showMeridian && dates[this.language].meridiem.length == 2) {
  588. meridian = (i < 12 ? dates[this.language].meridiem[0] : dates[this.language].meridiem[1]);
  589. if (meridian != meridianOld) {
  590. if (meridianOld != '') {
  591. html.push('</fieldset>');
  592. }
  593. html.push('<fieldset class="hour"><legend>' + meridian.toUpperCase() + '</legend>');
  594. }
  595. meridianOld = meridian;
  596. txt = (i % 12 ? i % 12 : 12);
  597. html.push('<span class="hour' + clsName + ' hour_' + (i < 12 ? 'am' : 'pm') + '">' + txt + '</span>');
  598. if (i == 23) {
  599. html.push('</fieldset>');
  600. }
  601. } else {
  602. txt = i + ':00';
  603. html.push('<span class="hour' + clsName + '">' + txt + '</span>');
  604. }
  605. }
  606. this.picker.find('.datetimepicker-hours td').html(html.join(''));
  607. html = [];
  608. txt = '', meridian = '', meridianOld = '';
  609. var minutesDisabled = this.minutesDisabled || [];
  610. for (var i = 0; i < 60; i += this.minuteStep) {
  611. if (minutesDisabled.indexOf(i) !== -1) continue;
  612. var actual = UTCDate(year, month, dayMonth, hours, i, 0);
  613. clsName = '';
  614. if (actual.valueOf() < this.startDate || actual.valueOf() > this.endDate) {
  615. clsName += ' disabled';
  616. } else if (Math.floor(minutes / this.minuteStep) == Math.floor(i / this.minuteStep)) {
  617. clsName += ' active';
  618. }
  619. if (this.showMeridian && dates[this.language].meridiem.length == 2) {
  620. meridian = (hours < 12 ? dates[this.language].meridiem[0] : dates[this.language].meridiem[1]);
  621. if (meridian != meridianOld) {
  622. if (meridianOld != '') {
  623. html.push('</fieldset>');
  624. }
  625. html.push('<fieldset class="minute"><legend>' + meridian.toUpperCase() + '</legend>');
  626. }
  627. meridianOld = meridian;
  628. txt = (hours % 12 ? hours % 12 : 12);
  629. //html.push('<span class="minute'+clsName+' minute_'+(hours<12?'am':'pm')+'">'+txt+'</span>');
  630. html.push('<span class="minute' + clsName + '">' + txt + ':' + (i < 10 ? '0' + i : i) + '</span>');
  631. if (i == 59) {
  632. html.push('</fieldset>');
  633. }
  634. } else {
  635. txt = i + ':00';
  636. //html.push('<span class="hour'+clsName+'">'+txt+'</span>');
  637. html.push('<span class="minute' + clsName + '">' + hours + ':' + (i < 10 ? '0' + i : i) + '</span>');
  638. }
  639. }
  640. this.picker.find('.datetimepicker-minutes td').html(html.join(''));
  641. var currentYear = this.date.getUTCFullYear();
  642. var months = this.picker.find('.datetimepicker-months')
  643. .find('th:eq(1)')
  644. .text(year)
  645. .end()
  646. .find('span').removeClass('active');
  647. if (currentYear == year) {
  648. // getUTCMonths() returns 0 based, and we need to select the next one
  649. months.eq(this.date.getUTCMonth() + 2).addClass('active');
  650. }
  651. if (year < startYear || year > endYear) {
  652. months.addClass('disabled');
  653. }
  654. if (year == startYear) {
  655. months.slice(0, startMonth + 1).addClass('disabled');
  656. }
  657. if (year == endYear) {
  658. months.slice(endMonth).addClass('disabled');
  659. }
  660. html = '';
  661. year = parseInt(year / 10, 10) * 10;
  662. var yearCont = this.picker.find('.datetimepicker-years')
  663. .find('th:eq(1)')
  664. .text(year + '-' + (year + 9))
  665. .end()
  666. .find('td');
  667. year -= 1;
  668. for (var i = -1; i < 11; i++) {
  669. html += '<span class="year' + (i == -1 || i == 10 ? ' old' : '') + (currentYear == year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : '') + '">' + year + '</span>';
  670. year += 1;
  671. }
  672. yearCont.html(html);
  673. this.place();
  674. },
  675. updateNavArrows: function () {
  676. var d = new Date(this.viewDate),
  677. year = d.getUTCFullYear(),
  678. month = d.getUTCMonth(),
  679. day = d.getUTCDate(),
  680. hour = d.getUTCHours();
  681. switch (this.viewMode) {
  682. case 0:
  683. if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()
  684. && month <= this.startDate.getUTCMonth()
  685. && day <= this.startDate.getUTCDate()
  686. && hour <= this.startDate.getUTCHours()) {
  687. this.picker.find('.prev').css({visibility: 'hidden'});
  688. } else {
  689. this.picker.find('.prev').css({visibility: 'visible'});
  690. }
  691. if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()
  692. && month >= this.endDate.getUTCMonth()
  693. && day >= this.endDate.getUTCDate()
  694. && hour >= this.endDate.getUTCHours()) {
  695. this.picker.find('.next').css({visibility: 'hidden'});
  696. } else {
  697. this.picker.find('.next').css({visibility: 'visible'});
  698. }
  699. break;
  700. case 1:
  701. if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()
  702. && month <= this.startDate.getUTCMonth()
  703. && day <= this.startDate.getUTCDate()) {
  704. this.picker.find('.prev').css({visibility: 'hidden'});
  705. } else {
  706. this.picker.find('.prev').css({visibility: 'visible'});
  707. }
  708. if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()
  709. && month >= this.endDate.getUTCMonth()
  710. && day >= this.endDate.getUTCDate()) {
  711. this.picker.find('.next').css({visibility: 'hidden'});
  712. } else {
  713. this.picker.find('.next').css({visibility: 'visible'});
  714. }
  715. break;
  716. case 2:
  717. if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()
  718. && month <= this.startDate.getUTCMonth()) {
  719. this.picker.find('.prev').css({visibility: 'hidden'});
  720. } else {
  721. this.picker.find('.prev').css({visibility: 'visible'});
  722. }
  723. if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()
  724. && month >= this.endDate.getUTCMonth()) {
  725. this.picker.find('.next').css({visibility: 'hidden'});
  726. } else {
  727. this.picker.find('.next').css({visibility: 'visible'});
  728. }
  729. break;
  730. case 3:
  731. case 4:
  732. if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
  733. this.picker.find('.prev').css({visibility: 'hidden'});
  734. } else {
  735. this.picker.find('.prev').css({visibility: 'visible'});
  736. }
  737. if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
  738. this.picker.find('.next').css({visibility: 'hidden'});
  739. } else {
  740. this.picker.find('.next').css({visibility: 'visible'});
  741. }
  742. break;
  743. }
  744. },
  745. mousewheel: function (e) {
  746. e.preventDefault();
  747. e.stopPropagation();
  748. if (this.wheelPause) {
  749. return;
  750. }
  751. this.wheelPause = true;
  752. var originalEvent = e.originalEvent;
  753. var delta = originalEvent.wheelDelta;
  754. var mode = delta > 0 ? 1 : (delta === 0) ? 0 : -1;
  755. if (this.wheelViewModeNavigationInverseDirection) {
  756. mode = -mode;
  757. }
  758. this.showMode(mode);
  759. setTimeout($.proxy(function () {
  760. this.wheelPause = false
  761. }, this), this.wheelViewModeNavigationDelay);
  762. },
  763. click: function (e) {
  764. e.stopPropagation();
  765. e.preventDefault();
  766. var target = $(e.target).closest('span, td, th, legend');
  767. if (target.is('.' + this.icontype)) {
  768. target = $(target).parent().closest('span, td, th, legend');
  769. }
  770. if (target.length == 1) {
  771. if (target.is('.disabled')) {
  772. this.element.trigger({
  773. type: 'outOfRange',
  774. date: this.viewDate,
  775. startDate: this.startDate,
  776. endDate: this.endDate
  777. });
  778. return;
  779. }
  780. switch (target[0].nodeName.toLowerCase()) {
  781. case 'th':
  782. switch (target[0].className) {
  783. case 'switch':
  784. this.showMode(1);
  785. break;
  786. case 'prev':
  787. case 'next':
  788. var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
  789. switch (this.viewMode) {
  790. case 0:
  791. this.viewDate = this.moveHour(this.viewDate, dir);
  792. break;
  793. case 1:
  794. this.viewDate = this.moveDate(this.viewDate, dir);
  795. break;
  796. case 2:
  797. this.viewDate = this.moveMonth(this.viewDate, dir);
  798. break;
  799. case 3:
  800. case 4:
  801. this.viewDate = this.moveYear(this.viewDate, dir);
  802. break;
  803. }
  804. this.fill();
  805. this.element.trigger({
  806. type: target[0].className + ':' + this.convertViewModeText(this.viewMode),
  807. date: this.viewDate,
  808. startDate: this.startDate,
  809. endDate: this.endDate
  810. });
  811. break;
  812. case 'today':
  813. var date = new Date();
  814. date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
  815. // Respect startDate and endDate.
  816. if (date < this.startDate) date = this.startDate;
  817. else if (date > this.endDate) date = this.endDate;
  818. this.viewMode = this.startViewMode;
  819. this.showMode(0);
  820. this._setDate(date);
  821. this.fill();
  822. if (this.autoclose) {
  823. this.hide();
  824. }
  825. break;
  826. }
  827. break;
  828. case 'span':
  829. if (!target.is('.disabled')) {
  830. var year = this.viewDate.getUTCFullYear(),
  831. month = this.viewDate.getUTCMonth(),
  832. day = this.viewDate.getUTCDate(),
  833. hours = this.viewDate.getUTCHours(),
  834. minutes = this.viewDate.getUTCMinutes(),
  835. seconds = this.viewDate.getUTCSeconds();
  836. if (target.is('.month')) {
  837. this.viewDate.setUTCDate(1);
  838. month = target.parent().find('span').index(target);
  839. day = this.viewDate.getUTCDate();
  840. this.viewDate.setUTCMonth(month);
  841. this.element.trigger({
  842. type: 'changeMonth',
  843. date: this.viewDate
  844. });
  845. if (this.viewSelect >= 3) {
  846. this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
  847. }
  848. } else if (target.is('.year')) {
  849. this.viewDate.setUTCDate(1);
  850. year = parseInt(target.text(), 10) || 0;
  851. this.viewDate.setUTCFullYear(year);
  852. this.element.trigger({
  853. type: 'changeYear',
  854. date: this.viewDate
  855. });
  856. if (this.viewSelect >= 4) {
  857. this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
  858. }
  859. } else if (target.is('.hour')) {
  860. hours = parseInt(target.text(), 10) || 0;
  861. if (target.hasClass('hour_am') || target.hasClass('hour_pm')) {
  862. if (hours == 12 && target.hasClass('hour_am')) {
  863. hours = 0;
  864. } else if (hours != 12 && target.hasClass('hour_pm')) {
  865. hours += 12;
  866. }
  867. }
  868. this.viewDate.setUTCHours(hours);
  869. this.element.trigger({
  870. type: 'changeHour',
  871. date: this.viewDate
  872. });
  873. if (this.viewSelect >= 1) {
  874. this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
  875. }
  876. } else if (target.is('.minute')) {
  877. minutes = parseInt(target.text().substr(target.text().indexOf(':') + 1), 10) || 0;
  878. this.viewDate.setUTCMinutes(minutes);
  879. this.element.trigger({
  880. type: 'changeMinute',
  881. date: this.viewDate
  882. });
  883. if (this.viewSelect >= 0) {
  884. this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
  885. }
  886. }
  887. if (this.viewMode != 0) {
  888. var oldViewMode = this.viewMode;
  889. this.showMode(-1);
  890. this.fill();
  891. if (oldViewMode == this.viewMode && this.autoclose) {
  892. this.hide();
  893. }
  894. } else {
  895. this.fill();
  896. if (this.autoclose) {
  897. this.hide();
  898. }
  899. }
  900. }
  901. break;
  902. case 'td':
  903. if (target.is('.day') && !target.is('.disabled')) {
  904. var day = parseInt(target.text(), 10) || 1;
  905. var year = this.viewDate.getUTCFullYear(),
  906. month = this.viewDate.getUTCMonth(),
  907. hours = this.viewDate.getUTCHours(),
  908. minutes = this.viewDate.getUTCMinutes(),
  909. seconds = this.viewDate.getUTCSeconds();
  910. if (target.is('.old')) {
  911. if (month === 0) {
  912. month = 11;
  913. year -= 1;
  914. } else {
  915. month -= 1;
  916. }
  917. } else if (target.is('.new')) {
  918. if (month == 11) {
  919. month = 0;
  920. year += 1;
  921. } else {
  922. month += 1;
  923. }
  924. }
  925. this.viewDate.setUTCFullYear(year);
  926. this.viewDate.setUTCMonth(month, day);
  927. this.element.trigger({
  928. type: 'changeDay',
  929. date: this.viewDate
  930. });
  931. if (this.viewSelect >= 2) {
  932. this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
  933. }
  934. }
  935. var oldViewMode = this.viewMode;
  936. this.showMode(-1);
  937. this.fill();
  938. if (oldViewMode == this.viewMode && this.autoclose) {
  939. this.hide();
  940. }
  941. break;
  942. }
  943. }
  944. },
  945. _setDate: function (date, which) {
  946. if (!which || which == 'date')
  947. this.date = date;
  948. if (!which || which == 'view')
  949. this.viewDate = date;
  950. this.fill();
  951. this.setValue();
  952. var element;
  953. if (this.isInput) {
  954. element = this.element;
  955. } else if (this.component) {
  956. element = this.element.find('input');
  957. }
  958. if (element) {
  959. element.change();
  960. if (this.autoclose && (!which || which == 'date')) {
  961. //this.hide();
  962. }
  963. }
  964. this.element.trigger({
  965. type: 'changeDate',
  966. date: this.date
  967. });
  968. },
  969. moveMinute: function (date, dir) {
  970. if (!dir) return date;
  971. var new_date = new Date(date.valueOf());
  972. //dir = dir > 0 ? 1 : -1;
  973. new_date.setUTCMinutes(new_date.getUTCMinutes() + (dir * this.minuteStep));
  974. return new_date;
  975. },
  976. moveHour: function (date, dir) {
  977. if (!dir) return date;
  978. var new_date = new Date(date.valueOf());
  979. //dir = dir > 0 ? 1 : -1;
  980. new_date.setUTCHours(new_date.getUTCHours() + dir);
  981. return new_date;
  982. },
  983. moveDate: function (date, dir) {
  984. if (!dir) return date;
  985. var new_date = new Date(date.valueOf());
  986. //dir = dir > 0 ? 1 : -1;
  987. new_date.setUTCDate(new_date.getUTCDate() + dir);
  988. return new_date;
  989. },
  990. moveMonth: function (date, dir) {
  991. if (!dir) return date;
  992. var new_date = new Date(date.valueOf()),
  993. day = new_date.getUTCDate(),
  994. month = new_date.getUTCMonth(),
  995. mag = Math.abs(dir),
  996. new_month, test;
  997. dir = dir > 0 ? 1 : -1;
  998. if (mag == 1) {
  999. test = dir == -1
  1000. // If going back one month, make sure month is not current month
  1001. // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
  1002. ? function () {
  1003. return new_date.getUTCMonth() == month;
  1004. }
  1005. // If going forward one month, make sure month is as expected
  1006. // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
  1007. : function () {
  1008. return new_date.getUTCMonth() != new_month;
  1009. };
  1010. new_month = month + dir;
  1011. new_date.setUTCMonth(new_month);
  1012. // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
  1013. if (new_month < 0 || new_month > 11)
  1014. new_month = (new_month + 12) % 12;
  1015. } else {
  1016. // For magnitudes >1, move one month at a time...
  1017. for (var i = 0; i < mag; i++)
  1018. // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
  1019. new_date = this.moveMonth(new_date, dir);
  1020. // ...then reset the day, keeping it in the new month
  1021. new_month = new_date.getUTCMonth();
  1022. new_date.setUTCDate(day);
  1023. test = function () {
  1024. return new_month != new_date.getUTCMonth();
  1025. };
  1026. }
  1027. // Common date-resetting loop -- if date is beyond end of month, make it
  1028. // end of month
  1029. while (test()) {
  1030. new_date.setUTCDate(--day);
  1031. new_date.setUTCMonth(new_month);
  1032. }
  1033. return new_date;
  1034. },
  1035. moveYear: function (date, dir) {
  1036. return this.moveMonth(date, dir * 12);
  1037. },
  1038. dateWithinRange: function (date) {
  1039. return date >= this.startDate && date <= this.endDate;
  1040. },
  1041. keydown: function (e) {
  1042. if (this.picker.is(':not(:visible)')) {
  1043. if (e.keyCode == 27) // allow escape to hide and re-show picker
  1044. this.show();
  1045. return;
  1046. }
  1047. var dateChanged = false,
  1048. dir, day, month,
  1049. newDate, newViewDate;
  1050. switch (e.keyCode) {
  1051. case 27: // escape
  1052. this.hide();
  1053. e.preventDefault();
  1054. break;
  1055. case 37: // left
  1056. case 39: // right
  1057. if (!this.keyboardNavigation) break;
  1058. dir = e.keyCode == 37 ? -1 : 1;
  1059. viewMode = this.viewMode;
  1060. if (e.ctrlKey) {
  1061. viewMode += 2;
  1062. } else if (e.shiftKey) {
  1063. viewMode += 1;
  1064. }
  1065. if (viewMode == 4) {
  1066. newDate = this.moveYear(this.date, dir);
  1067. newViewDate = this.moveYear(this.viewDate, dir);
  1068. } else if (viewMode == 3) {
  1069. newDate = this.moveMonth(this.date, dir);
  1070. newViewDate = this.moveMonth(this.viewDate, dir);
  1071. } else if (viewMode == 2) {
  1072. newDate = this.moveDate(this.date, dir);
  1073. newViewDate = this.moveDate(this.viewDate, dir);
  1074. } else if (viewMode == 1) {
  1075. newDate = this.moveHour(this.date, dir);
  1076. newViewDate = this.moveHour(this.viewDate, dir);
  1077. } else if (viewMode == 0) {
  1078. newDate = this.moveMinute(this.date, dir);
  1079. newViewDate = this.moveMinute(this.viewDate, dir);
  1080. }
  1081. if (this.dateWithinRange(newDate)) {
  1082. this.date = newDate;
  1083. this.viewDate = newViewDate;
  1084. this.setValue();
  1085. this.update();
  1086. e.preventDefault();
  1087. dateChanged = true;
  1088. }
  1089. break;
  1090. case 38: // up
  1091. case 40: // down
  1092. if (!this.keyboardNavigation) break;
  1093. dir = e.keyCode == 38 ? -1 : 1;
  1094. viewMode = this.viewMode;
  1095. if (e.ctrlKey) {
  1096. viewMode += 2;
  1097. } else if (e.shiftKey) {
  1098. viewMode += 1;
  1099. }
  1100. if (viewMode == 4) {
  1101. newDate = this.moveYear(this.date, dir);
  1102. newViewDate = this.moveYear(this.viewDate, dir);
  1103. } else if (viewMode == 3) {
  1104. newDate = this.moveMonth(this.date, dir);
  1105. newViewDate = this.moveMonth(this.viewDate, dir);
  1106. } else if (viewMode == 2) {
  1107. newDate = this.moveDate(this.date, dir * 7);
  1108. newViewDate = this.moveDate(this.viewDate, dir * 7);
  1109. } else if (viewMode == 1) {
  1110. if (this.showMeridian) {
  1111. newDate = this.moveHour(this.date, dir * 6);
  1112. newViewDate = this.moveHour(this.viewDate, dir * 6);
  1113. } else {
  1114. newDate = this.moveHour(this.date, dir * 4);
  1115. newViewDate = this.moveHour(this.viewDate, dir * 4);
  1116. }
  1117. } else if (viewMode == 0) {
  1118. newDate = this.moveMinute(this.date, dir * 4);
  1119. newViewDate = this.moveMinute(this.viewDate, dir * 4);
  1120. }
  1121. if (this.dateWithinRange(newDate)) {
  1122. this.date = newDate;
  1123. this.viewDate = newViewDate;
  1124. this.setValue();
  1125. this.update();
  1126. e.preventDefault();
  1127. dateChanged = true;
  1128. }
  1129. break;
  1130. case 13: // enter
  1131. if (this.viewMode != 0) {
  1132. var oldViewMode = this.viewMode;
  1133. this.showMode(-1);
  1134. this.fill();
  1135. if (oldViewMode == this.viewMode && this.autoclose) {
  1136. this.hide();
  1137. }
  1138. } else {
  1139. this.fill();
  1140. if (this.autoclose) {
  1141. this.hide();
  1142. }
  1143. }
  1144. e.preventDefault();
  1145. break;
  1146. case 9: // tab
  1147. this.hide();
  1148. break;
  1149. }
  1150. if (dateChanged) {
  1151. var element;
  1152. if (this.isInput) {
  1153. element = this.element;
  1154. } else if (this.component) {
  1155. element = this.element.find('input');
  1156. }
  1157. if (element) {
  1158. element.change();
  1159. }
  1160. this.element.trigger({
  1161. type: 'changeDate',
  1162. date: this.date
  1163. });
  1164. }
  1165. },
  1166. showMode: function (dir) {
  1167. if (dir) {
  1168. var newViewMode = Math.max(0, Math.min(DPGlobal.modes.length - 1, this.viewMode + dir));
  1169. if (newViewMode >= this.minView && newViewMode <= this.maxView) {
  1170. this.element.trigger({
  1171. type: 'changeMode',
  1172. date: this.viewDate,
  1173. oldViewMode: this.viewMode,
  1174. newViewMode: newViewMode
  1175. });
  1176. this.viewMode = newViewMode;
  1177. }
  1178. }
  1179. /*
  1180. vitalets: fixing bug of very special conditions:
  1181. jquery 1.7.1 + webkit + show inline datetimepicker in bootstrap popover.
  1182. Method show() does not set display css correctly and datetimepicker is not shown.
  1183. Changed to .css('display', 'block') solve the problem.
  1184. See https://github.com/vitalets/x-editable/issues/37
  1185. In jquery 1.7.2+ everything works fine.
  1186. */
  1187. //this.picker.find('>div').hide().filter('.datetimepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
  1188. this.picker.find('>div').hide().filter('.datetimepicker-' + DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
  1189. this.updateNavArrows();
  1190. },
  1191. reset: function (e) {
  1192. this._setDate(null, 'date');
  1193. },
  1194. convertViewModeText: function (viewMode) {
  1195. switch (viewMode) {
  1196. case 4:
  1197. return 'decade';
  1198. case 3:
  1199. return 'year';
  1200. case 2:
  1201. return 'month';
  1202. case 1:
  1203. return 'day';
  1204. case 0:
  1205. return 'hour';
  1206. }
  1207. }
  1208. };
  1209. var old = $.fn.datetimepicker;
  1210. $.fn.datetimepicker = function (option) {
  1211. var args = Array.apply(null, arguments);
  1212. args.shift();
  1213. var internal_return;
  1214. this.each(function () {
  1215. var $this = $(this),
  1216. data = $this.data('datetimepicker'),
  1217. options = typeof option == 'object' && option;
  1218. if (!data) {
  1219. $this.data('datetimepicker', (data = new Datetimepicker(this, $.extend({}, $.fn.datetimepicker.defaults, options))));
  1220. }
  1221. if (typeof option == 'string' && typeof data[option] == 'function') {
  1222. internal_return = data[option].apply(data, args);
  1223. if (internal_return !== undefined) {
  1224. return false;
  1225. }
  1226. }
  1227. });
  1228. if (internal_return !== undefined)
  1229. return internal_return;
  1230. else
  1231. return this;
  1232. };
  1233. $.fn.datetimepicker.defaults = {
  1234. };
  1235. $.fn.datetimepicker.Constructor = Datetimepicker;
  1236. var dates = $.fn.datetimepicker.dates = {
  1237. en: {
  1238. days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
  1239. daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
  1240. daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
  1241. months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
  1242. monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
  1243. meridiem: ["am", "pm"],
  1244. suffix: ["st", "nd", "rd", "th"],
  1245. today: "Today"
  1246. }
  1247. };
  1248. var DPGlobal = {
  1249. modes: [
  1250. {
  1251. clsName: 'minutes',
  1252. navFnc: 'Hours',
  1253. navStep: 1
  1254. },
  1255. {
  1256. clsName: 'hours',
  1257. navFnc: 'Date',
  1258. navStep: 1
  1259. },
  1260. {
  1261. clsName: 'days',
  1262. navFnc: 'Month',
  1263. navStep: 1
  1264. },
  1265. {
  1266. clsName: 'months',
  1267. navFnc: 'FullYear',
  1268. navStep: 1
  1269. },
  1270. {
  1271. clsName: 'years',
  1272. navFnc: 'FullYear',
  1273. navStep: 10
  1274. }
  1275. ],
  1276. isLeapYear: function (year) {
  1277. return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
  1278. },
  1279. getDaysInMonth: function (year, month) {
  1280. return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
  1281. },
  1282. getDefaultFormat: function (type, field) {
  1283. if (type == "standard") {
  1284. if (field == 'input')
  1285. return 'yyyy-mm-dd hh:ii';
  1286. else
  1287. return 'yyyy-mm-dd hh:ii:ss';
  1288. } else if (type == "php") {
  1289. if (field == 'input')
  1290. return 'Y-m-d H:i';
  1291. else
  1292. return 'Y-m-d H:i:s';
  1293. } else {
  1294. throw new Error("Invalid format type.");
  1295. }
  1296. },
  1297. validParts: function (type) {
  1298. if (type == "standard") {
  1299. return /hh?|HH?|p|P|ii?|ss?|dd?|DD?|mm?|MM?|yy(?:yy)?/g;
  1300. } else if (type == "php") {
  1301. return /[dDjlNwzFmMnStyYaABgGhHis]/g;
  1302. } else {
  1303. throw new Error("Invalid format type.");
  1304. }
  1305. },
  1306. nonpunctuation: /[^ -\/:-@\[-`{-~\t\n\rTZ]+/g,
  1307. parseFormat: function (format, type) {
  1308. // IE treats \0 as a string end in inputs (truncating the value),
  1309. // so it's a bad format delimiter, anyway
  1310. var separators = format.replace(this.validParts(type), '\0').split('\0'),
  1311. parts = format.match(this.validParts(type));
  1312. if (!separators || !separators.length || !parts || parts.length == 0) {
  1313. throw new Error("Invalid date format.");
  1314. }
  1315. return {separators: separators, parts: parts};
  1316. },
  1317. parseDate: function (date, format, language, type) {
  1318. if (date instanceof Date) {
  1319. var dateUTC = new Date(date.valueOf() - date.getTimezoneOffset() * 60000);
  1320. dateUTC.setMilliseconds(0);
  1321. return dateUTC;
  1322. }
  1323. if (/^\d{4}\-\d{1,2}\-\d{1,2}$/.test(date)) {
  1324. format = this.parseFormat('yyyy-mm-dd', type);
  1325. }
  1326. if (/^\d{4}\-\d{1,2}\-\d{1,2}[T ]\d{1,2}\:\d{1,2}$/.test(date)) {
  1327. format = this.parseFormat('yyyy-mm-dd hh:ii', type);
  1328. }
  1329. if (/^\d{4}\-\d{1,2}\-\d{1,2}[T ]\d{1,2}\:\d{1,2}\:\d{1,2}[Z]{0,1}$/.test(date)) {
  1330. format = this.parseFormat('yyyy-mm-dd hh:ii:ss', type);
  1331. }
  1332. if (/^[-+]\d+[dmwy]([\s,]+[-+]\d+[dmwy])*$/.test(date)) {
  1333. var part_re = /([-+]\d+)([dmwy])/,
  1334. parts = date.match(/([-+]\d+)([dmwy])/g),
  1335. part, dir;
  1336. date = new Date();
  1337. for (var i = 0; i < parts.length; i++) {
  1338. part = part_re.exec(parts[i]);
  1339. dir = parseInt(part[1]);
  1340. switch (part[2]) {
  1341. case 'd':
  1342. date.setUTCDate(date.getUTCDate() + dir);
  1343. break;
  1344. case 'm':
  1345. date = Datetimepicker.prototype.moveMonth.call(Datetimepicker.prototype, date, dir);
  1346. break;
  1347. case 'w':
  1348. date.setUTCDate(date.getUTCDate() + dir * 7);
  1349. break;
  1350. case 'y':
  1351. date = Datetimepicker.prototype.moveYear.call(Datetimepicker.prototype, date, dir);
  1352. break;
  1353. }
  1354. }
  1355. return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), 0);
  1356. }
  1357. var parts = date && date.toString().match(this.nonpunctuation) || [],
  1358. date = new Date(0, 0, 0, 0, 0, 0, 0),
  1359. parsed = {},
  1360. setters_order = ['hh', 'h', 'ii', 'i', 'ss', 's', 'yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'D', 'DD', 'd', 'dd', 'H', 'HH', 'p', 'P'],
  1361. setters_map = {
  1362. hh: function (d, v) {
  1363. return d.setUTCHours(v);
  1364. },
  1365. h: function (d, v) {
  1366. return d.setUTCHours(v);
  1367. },
  1368. HH: function (d, v) {
  1369. return d.setUTCHours(v == 12 ? 0 : v);
  1370. },
  1371. H: function (d, v) {
  1372. return d.setUTCHours(v == 12 ? 0 : v);
  1373. },
  1374. ii: function (d, v) {
  1375. return d.setUTCMinutes(v);
  1376. },
  1377. i: function (d, v) {
  1378. return d.setUTCMinutes(v);
  1379. },
  1380. ss: function (d, v) {
  1381. return d.setUTCSeconds(v);
  1382. },
  1383. s: function (d, v) {
  1384. return d.setUTCSeconds(v);
  1385. },
  1386. yyyy: function (d, v) {
  1387. return d.setUTCFullYear(v);
  1388. },
  1389. yy: function (d, v) {
  1390. return d.setUTCFullYear(2000 + v);
  1391. },
  1392. m: function (d, v) {
  1393. v -= 1;
  1394. while (v < 0) v += 12;
  1395. v %= 12;
  1396. d.setUTCMonth(v);
  1397. while (d.getUTCMonth() != v)
  1398. if (isNaN(d.getUTCMonth()))
  1399. return d;
  1400. else
  1401. d.setUTCDate(d.getUTCDate() - 1);
  1402. return d;
  1403. },
  1404. d: function (d, v) {
  1405. return d.setUTCDate(v);
  1406. },
  1407. p: function (d, v) {
  1408. return d.setUTCHours(v == 1 ? d.getUTCHours() + 12 : d.getUTCHours());
  1409. }
  1410. },
  1411. val, filtered, part;
  1412. setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
  1413. setters_map['dd'] = setters_map['d'];
  1414. setters_map['P'] = setters_map['p'];
  1415. date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
  1416. if (parts.length == format.parts.length) {
  1417. for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
  1418. val = parseInt(parts[i], 10);
  1419. part = format.parts[i];
  1420. if (isNaN(val)) {
  1421. switch (part) {
  1422. case 'MM':
  1423. filtered = $(dates[language].months).filter(function () {
  1424. var m = this.slice(0, parts[i].length),
  1425. p = parts[i].slice(0, m.length);
  1426. return m == p;
  1427. });
  1428. val = $.inArray(filtered[0], dates[language].months) + 1;
  1429. break;
  1430. case 'M':
  1431. filtered = $(dates[language].monthsShort).filter(function () {
  1432. var m = this.slice(0, parts[i].length),
  1433. p = parts[i].slice(0, m.length);
  1434. return m.toLowerCase() == p.toLowerCase();
  1435. });
  1436. val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
  1437. break;
  1438. case 'p':
  1439. case 'P':
  1440. val = $.inArray(parts[i].toLowerCase(), dates[language].meridiem);
  1441. break;
  1442. }
  1443. }
  1444. parsed[part] = val;
  1445. }
  1446. for (var i = 0, s; i < setters_order.length; i++) {
  1447. s = setters_order[i];
  1448. if (s in parsed && !isNaN(parsed[s]))
  1449. setters_map[s](date, parsed[s])
  1450. }
  1451. }
  1452. return date;
  1453. },
  1454. formatDate: function (date, format, language, type) {
  1455. if (date == null) {
  1456. return '';
  1457. }
  1458. var val;
  1459. if (type == 'standard') {
  1460. val = {
  1461. // year
  1462. yy: date.getUTCFullYear().toString().substring(2),
  1463. yyyy: date.getUTCFullYear(),
  1464. // month
  1465. m: date.getUTCMonth() + 1,
  1466. M: dates[language].monthsShort[date.getUTCMonth()],
  1467. MM: dates[language].months[date.getUTCMonth()],
  1468. // day
  1469. d: date.getUTCDate(),
  1470. D: dates[language].daysShort[date.getUTCDay()],
  1471. DD: dates[language].days[date.getUTCDay()],
  1472. p: (dates[language].meridiem.length == 2 ? dates[language].meridiem[date.getUTCHours() < 12 ? 0 : 1] : ''),
  1473. // hour
  1474. h: date.getUTCHours(),
  1475. // minute
  1476. i: date.getUTCMinutes(),
  1477. // second
  1478. s: date.getUTCSeconds()
  1479. };
  1480. if (dates[language].meridiem.length == 2) {
  1481. val.H = (val.h % 12 == 0 ? 12 : val.h % 12);
  1482. }
  1483. else {
  1484. val.H = val.h;
  1485. }
  1486. val.HH = (val.H < 10 ? '0' : '') + val.H;
  1487. val.P = val.p.toUpperCase();
  1488. val.hh = (val.h < 10 ? '0' : '') + val.h;
  1489. val.ii = (val.i < 10 ? '0' : '') + val.i;
  1490. val.ss = (val.s < 10 ? '0' : '') + val.s;
  1491. val.dd = (val.d < 10 ? '0' : '') + val.d;
  1492. val.mm = (val.m < 10 ? '0' : '') + val.m;
  1493. } else if (type == 'php') {
  1494. // php format
  1495. val = {
  1496. // year
  1497. y: date.getUTCFullYear().toString().substring(2),
  1498. Y: date.getUTCFullYear(),
  1499. // month
  1500. F: dates[language].months[date.getUTCMonth()],
  1501. M: dates[language].monthsShort[date.getUTCMonth()],
  1502. n: date.getUTCMonth() + 1,
  1503. t: DPGlobal.getDaysInMonth(date.getUTCFullYear(), date.getUTCMonth()),
  1504. // day
  1505. j: date.getUTCDate(),
  1506. l: dates[language].days[date.getUTCDay()],
  1507. D: dates[language].daysShort[date.getUTCDay()],
  1508. w: date.getUTCDay(), // 0 -> 6
  1509. N: (date.getUTCDay() == 0 ? 7 : date.getUTCDay()), // 1 -> 7
  1510. S: (date.getUTCDate() % 10 <= dates[language].suffix.length ? dates[language].suffix[date.getUTCDate() % 10 - 1] : ''),
  1511. // hour
  1512. a: (dates[language].meridiem.length == 2 ? dates[language].meridiem[date.getUTCHours() < 12 ? 0 : 1] : ''),
  1513. g: (date.getUTCHours() % 12 == 0 ? 12 : date.getUTCHours() % 12),
  1514. G: date.getUTCHours(),
  1515. // minute
  1516. i: date.getUTCMinutes(),
  1517. // second
  1518. s: date.getUTCSeconds()
  1519. };
  1520. val.m = (val.n < 10 ? '0' : '') + val.n;
  1521. val.d = (val.j < 10 ? '0' : '') + val.j;
  1522. val.A = val.a.toString().toUpperCase();
  1523. val.h = (val.g < 10 ? '0' : '') + val.g;
  1524. val.H = (val.G < 10 ? '0' : '') + val.G;
  1525. val.i = (val.i < 10 ? '0' : '') + val.i;
  1526. val.s = (val.s < 10 ? '0' : '') + val.s;
  1527. } else {
  1528. throw new Error("Invalid format type.");
  1529. }
  1530. var date = [],
  1531. seps = $.extend([], format.separators);
  1532. for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
  1533. if (seps.length) {
  1534. date.push(seps.shift());
  1535. }
  1536. date.push(val[format.parts[i]]);
  1537. }
  1538. if (seps.length) {
  1539. date.push(seps.shift());
  1540. }
  1541. return date.join('');
  1542. },
  1543. convertViewMode: function (viewMode) {
  1544. switch (viewMode) {
  1545. case 4:
  1546. case 'decade':
  1547. viewMode = 4;
  1548. break;
  1549. case 3:
  1550. case 'year':
  1551. viewMode = 3;
  1552. break;
  1553. case 2:
  1554. case 'month':
  1555. viewMode = 2;
  1556. break;
  1557. case 1:
  1558. case 'day':
  1559. viewMode = 1;
  1560. break;
  1561. case 0:
  1562. case 'hour':
  1563. viewMode = 0;
  1564. break;
  1565. }
  1566. return viewMode;
  1567. },
  1568. headTemplate: '<thead>' +
  1569. '<tr>' +
  1570. '<th class="prev"><i class="{leftArrow}"/></th>' +
  1571. '<th colspan="5" class="switch"></th>' +
  1572. '<th class="next"><i class="{rightArrow}"/></th>' +
  1573. '</tr>' +
  1574. '</thead>',
  1575. headTemplateV3: '<thead>' +
  1576. '<tr>' +
  1577. '<th class="prev"><span class="{iconType} {leftArrow}"></span> </th>' +
  1578. '<th colspan="5" class="switch"></th>' +
  1579. '<th class="next"><span class="{iconType} {rightArrow}"></span> </th>' +
  1580. '</tr>' +
  1581. '</thead>',
  1582. contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
  1583. footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr></tfoot>'
  1584. };
  1585. DPGlobal.template = '<div class="datetimepicker">' +
  1586. '<div class="datetimepicker-minutes">' +
  1587. '<table class=" table-condensed">' +
  1588. DPGlobal.headTemplate +
  1589. DPGlobal.contTemplate +
  1590. DPGlobal.footTemplate +
  1591. '</table>' +
  1592. '</div>' +
  1593. '<div class="datetimepicker-hours">' +
  1594. '<table class=" table-condensed">' +
  1595. DPGlobal.headTemplate +
  1596. DPGlobal.contTemplate +
  1597. DPGlobal.footTemplate +
  1598. '</table>' +
  1599. '</div>' +
  1600. '<div class="datetimepicker-days">' +
  1601. '<table class=" table-condensed">' +
  1602. DPGlobal.headTemplate +
  1603. '<tbody></tbody>' +
  1604. DPGlobal.footTemplate +
  1605. '</table>' +
  1606. '</div>' +
  1607. '<div class="datetimepicker-months">' +
  1608. '<table class="table-condensed">' +
  1609. DPGlobal.headTemplate +
  1610. DPGlobal.contTemplate +
  1611. DPGlobal.footTemplate +
  1612. '</table>' +
  1613. '</div>' +
  1614. '<div class="datetimepicker-years">' +
  1615. '<table class="table-condensed">' +
  1616. DPGlobal.headTemplate +
  1617. DPGlobal.contTemplate +
  1618. DPGlobal.footTemplate +
  1619. '</table>' +
  1620. '</div>' +
  1621. '</div>';
  1622. DPGlobal.templateV3 = '<div class="datetimepicker">' +
  1623. '<div class="datetimepicker-minutes">' +
  1624. '<table class=" table-condensed">' +
  1625. DPGlobal.headTemplateV3 +
  1626. DPGlobal.contTemplate +
  1627. DPGlobal.footTemplate +
  1628. '</table>' +
  1629. '</div>' +
  1630. '<div class="datetimepicker-hours">' +
  1631. '<table class=" table-condensed">' +
  1632. DPGlobal.headTemplateV3 +
  1633. DPGlobal.contTemplate +
  1634. DPGlobal.footTemplate +
  1635. '</table>' +
  1636. '</div>' +
  1637. '<div class="datetimepicker-days">' +
  1638. '<table class=" table-condensed">' +
  1639. DPGlobal.headTemplateV3 +
  1640. '<tbody></tbody>' +
  1641. DPGlobal.footTemplate +
  1642. '</table>' +
  1643. '</div>' +
  1644. '<div class="datetimepicker-months">' +
  1645. '<table class="table-condensed">' +
  1646. DPGlobal.headTemplateV3 +
  1647. DPGlobal.contTemplate +
  1648. DPGlobal.footTemplate +
  1649. '</table>' +
  1650. '</div>' +
  1651. '<div class="datetimepicker-years">' +
  1652. '<table class="table-condensed">' +
  1653. DPGlobal.headTemplateV3 +
  1654. DPGlobal.contTemplate +
  1655. DPGlobal.footTemplate +
  1656. '</table>' +
  1657. '</div>' +
  1658. '</div>';
  1659. $.fn.datetimepicker.DPGlobal = DPGlobal;
  1660. /* DATETIMEPICKER NO CONFLICT
  1661. * =================== */
  1662. $.fn.datetimepicker.noConflict = function () {
  1663. $.fn.datetimepicker = old;
  1664. return this;
  1665. };
  1666. /* DATETIMEPICKER DATA-API
  1667. * ================== */
  1668. $(document).on(
  1669. 'focus.datetimepicker.data-api click.datetimepicker.data-api',
  1670. '[data-provide="datetimepicker"]',
  1671. function (e) {
  1672. var $this = $(this);
  1673. if ($this.data('datetimepicker')) return;
  1674. e.preventDefault();
  1675. // component click requires us to explicitly show it
  1676. $this.datetimepicker('show');
  1677. }
  1678. );
  1679. $(function () {
  1680. $('[data-provide="datetimepicker-inline"]').datetimepicker();
  1681. });
  1682. }(window.jQuery);