bootstrap-datetimepicker.js 64 KB

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