You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1967 lines
68 KiB

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