datetimepicker.js 60 KB

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