bootstrap-datetimepicker.js 69 KB

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