bootstrap-datetimepicker.js 68 KB

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