portal html css js resource

bootstrap-datetimepicker.js 69KB

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