bootstrap-datetimepicker.js 66 KB

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