jquery-ui-timepicker-addon.js 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269
  1. /*! jQuery Timepicker Addon - v1.6.1 - 2015-11-14
  2. * http://trentrichardson.com/examples/timepicker
  3. * Copyright (c) 2015 Trent Richardson; Licensed MIT */
  4. (function (factory) {
  5. if (typeof define === 'function' && define.amd) {
  6. define(['jquery', 'jquery-ui'], factory);
  7. } else {
  8. factory(jQuery);
  9. }
  10. }(function ($) {
  11. /*
  12. * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded"
  13. */
  14. $.ui.timepicker = $.ui.timepicker || {};
  15. if ($.ui.timepicker.version) {
  16. return;
  17. }
  18. /*
  19. * Extend jQueryUI, get it started with our version number
  20. */
  21. $.extend($.ui, {
  22. timepicker: {
  23. version: "1.6.1"
  24. }
  25. });
  26. /*
  27. * Timepicker manager.
  28. * Use the singleton instance of this class, $.timepicker, to interact with the time picker.
  29. * Settings for (groups of) time pickers are maintained in an instance object,
  30. * allowing multiple different settings on the same page.
  31. */
  32. var Timepicker = function () {
  33. this.regional = []; // Available regional settings, indexed by language code
  34. this.regional[''] = { // Default regional settings
  35. currentText: 'Now',
  36. closeText: 'Done',
  37. amNames: ['AM', 'A'],
  38. pmNames: ['PM', 'P'],
  39. timeFormat: 'HH:mm',
  40. timeSuffix: '',
  41. timeOnlyTitle: 'Choose Time',
  42. timeText: 'Time',
  43. hourText: 'Hour',
  44. minuteText: 'Minute',
  45. secondText: 'Second',
  46. millisecText: 'Millisecond',
  47. microsecText: 'Microsecond',
  48. timezoneText: 'Time Zone',
  49. isRTL: false
  50. };
  51. this._defaults = { // Global defaults for all the datetime picker instances
  52. showButtonPanel: true,
  53. timeOnly: false,
  54. timeOnlyShowDate: false,
  55. showHour: null,
  56. showMinute: null,
  57. showSecond: null,
  58. showMillisec: null,
  59. showMicrosec: null,
  60. showTimezone: null,
  61. showTime: true,
  62. stepHour: 1,
  63. stepMinute: 1,
  64. stepSecond: 1,
  65. stepMillisec: 1,
  66. stepMicrosec: 1,
  67. hour: 0,
  68. minute: 0,
  69. second: 0,
  70. millisec: 0,
  71. microsec: 0,
  72. timezone: null,
  73. hourMin: 0,
  74. minuteMin: 0,
  75. secondMin: 0,
  76. millisecMin: 0,
  77. microsecMin: 0,
  78. hourMax: 23,
  79. minuteMax: 59,
  80. secondMax: 59,
  81. millisecMax: 999,
  82. microsecMax: 999,
  83. minDateTime: null,
  84. maxDateTime: null,
  85. maxTime: null,
  86. minTime: null,
  87. onSelect: null,
  88. hourGrid: 0,
  89. minuteGrid: 0,
  90. secondGrid: 0,
  91. millisecGrid: 0,
  92. microsecGrid: 0,
  93. alwaysSetTime: true,
  94. separator: ' ',
  95. altFieldTimeOnly: true,
  96. altTimeFormat: null,
  97. altSeparator: null,
  98. altTimeSuffix: null,
  99. altRedirectFocus: true,
  100. pickerTimeFormat: null,
  101. pickerTimeSuffix: null,
  102. showTimepicker: true,
  103. timezoneList: null,
  104. addSliderAccess: false,
  105. sliderAccessArgs: null,
  106. controlType: 'slider',
  107. oneLine: false,
  108. defaultValue: null,
  109. parse: 'strict',
  110. afterInject: null
  111. };
  112. $.extend(this._defaults, this.regional['']);
  113. };
  114. $.extend(Timepicker.prototype, {
  115. $input: null,
  116. $altInput: null,
  117. $timeObj: null,
  118. inst: null,
  119. hour_slider: null,
  120. minute_slider: null,
  121. second_slider: null,
  122. millisec_slider: null,
  123. microsec_slider: null,
  124. timezone_select: null,
  125. maxTime: null,
  126. minTime: null,
  127. hour: 0,
  128. minute: 0,
  129. second: 0,
  130. millisec: 0,
  131. microsec: 0,
  132. timezone: null,
  133. hourMinOriginal: null,
  134. minuteMinOriginal: null,
  135. secondMinOriginal: null,
  136. millisecMinOriginal: null,
  137. microsecMinOriginal: null,
  138. hourMaxOriginal: null,
  139. minuteMaxOriginal: null,
  140. secondMaxOriginal: null,
  141. millisecMaxOriginal: null,
  142. microsecMaxOriginal: null,
  143. ampm: '',
  144. formattedDate: '',
  145. formattedTime: '',
  146. formattedDateTime: '',
  147. timezoneList: null,
  148. units: ['hour', 'minute', 'second', 'millisec', 'microsec'],
  149. support: {},
  150. control: null,
  151. /*
  152. * Override the default settings for all instances of the time picker.
  153. * @param {Object} settings object - the new settings to use as defaults (anonymous object)
  154. * @return {Object} the manager object
  155. */
  156. setDefaults: function (settings) {
  157. extendRemove(this._defaults, settings || {});
  158. return this;
  159. },
  160. /*
  161. * Create a new Timepicker instance
  162. */
  163. _newInst: function ($input, opts) {
  164. var tp_inst = new Timepicker(),
  165. inlineSettings = {},
  166. fns = {},
  167. overrides, i;
  168. for (var attrName in this._defaults) {
  169. if (this._defaults.hasOwnProperty(attrName)) {
  170. var attrValue = $input.attr('time:' + attrName);
  171. if (attrValue) {
  172. try {
  173. inlineSettings[attrName] = eval(attrValue);
  174. } catch (err) {
  175. inlineSettings[attrName] = attrValue;
  176. }
  177. }
  178. }
  179. }
  180. overrides = {
  181. beforeShow: function (input, dp_inst) {
  182. if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) {
  183. return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst);
  184. }
  185. },
  186. onChangeMonthYear: function (year, month, dp_inst) {
  187. // Update the time as well : this prevents the time from disappearing from the $input field.
  188. // tp_inst._updateDateTime(dp_inst);
  189. if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) {
  190. tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);
  191. }
  192. },
  193. onClose: function (dateText, dp_inst) {
  194. if (tp_inst.timeDefined === true && $input.val() !== '') {
  195. tp_inst._updateDateTime(dp_inst);
  196. }
  197. if ($.isFunction(tp_inst._defaults.evnts.onClose)) {
  198. tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst);
  199. }
  200. }
  201. };
  202. for (i in overrides) {
  203. if (overrides.hasOwnProperty(i)) {
  204. fns[i] = opts[i] || this._defaults[i] || null;
  205. }
  206. }
  207. tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, opts, overrides, {
  208. evnts: fns,
  209. timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
  210. });
  211. tp_inst.amNames = $.map(tp_inst._defaults.amNames, function (val) {
  212. return val.toUpperCase();
  213. });
  214. tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function (val) {
  215. return val.toUpperCase();
  216. });
  217. // detect which units are supported
  218. tp_inst.support = detectSupport(
  219. tp_inst._defaults.timeFormat +
  220. (tp_inst._defaults.pickerTimeFormat ? tp_inst._defaults.pickerTimeFormat : '') +
  221. (tp_inst._defaults.altTimeFormat ? tp_inst._defaults.altTimeFormat : ''));
  222. // controlType is string - key to our this._controls
  223. if (typeof(tp_inst._defaults.controlType) === 'string') {
  224. if (tp_inst._defaults.controlType === 'slider' && typeof($.ui.slider) === 'undefined') {
  225. tp_inst._defaults.controlType = 'select';
  226. }
  227. tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType];
  228. }
  229. // controlType is an object and must implement create, options, value methods
  230. else {
  231. tp_inst.control = tp_inst._defaults.controlType;
  232. }
  233. // prep the timezone options
  234. var timezoneList = [-720, -660, -600, -570, -540, -480, -420, -360, -300, -270, -240, -210, -180, -120, -60,
  235. 0, 60, 120, 180, 210, 240, 270, 300, 330, 345, 360, 390, 420, 480, 525, 540, 570, 600, 630, 660, 690, 720, 765, 780, 840];
  236. if (tp_inst._defaults.timezoneList !== null) {
  237. timezoneList = tp_inst._defaults.timezoneList;
  238. }
  239. var tzl = timezoneList.length, tzi = 0, tzv = null;
  240. if (tzl > 0 && typeof timezoneList[0] !== 'object') {
  241. for (; tzi < tzl; tzi++) {
  242. tzv = timezoneList[tzi];
  243. timezoneList[tzi] = { value: tzv, label: $.timepicker.timezoneOffsetString(tzv, tp_inst.support.iso8601) };
  244. }
  245. }
  246. tp_inst._defaults.timezoneList = timezoneList;
  247. // set the default units
  248. tp_inst.timezone = tp_inst._defaults.timezone !== null ? $.timepicker.timezoneOffsetNumber(tp_inst._defaults.timezone) :
  249. ((new Date()).getTimezoneOffset() * -1);
  250. tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin ? tp_inst._defaults.hourMin :
  251. tp_inst._defaults.hour > tp_inst._defaults.hourMax ? tp_inst._defaults.hourMax : tp_inst._defaults.hour;
  252. tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin ? tp_inst._defaults.minuteMin :
  253. tp_inst._defaults.minute > tp_inst._defaults.minuteMax ? tp_inst._defaults.minuteMax : tp_inst._defaults.minute;
  254. tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin ? tp_inst._defaults.secondMin :
  255. tp_inst._defaults.second > tp_inst._defaults.secondMax ? tp_inst._defaults.secondMax : tp_inst._defaults.second;
  256. tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin ? tp_inst._defaults.millisecMin :
  257. tp_inst._defaults.millisec > tp_inst._defaults.millisecMax ? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec;
  258. tp_inst.microsec = tp_inst._defaults.microsec < tp_inst._defaults.microsecMin ? tp_inst._defaults.microsecMin :
  259. tp_inst._defaults.microsec > tp_inst._defaults.microsecMax ? tp_inst._defaults.microsecMax : tp_inst._defaults.microsec;
  260. tp_inst.ampm = '';
  261. tp_inst.$input = $input;
  262. if (tp_inst._defaults.altField) {
  263. tp_inst.$altInput = $(tp_inst._defaults.altField);
  264. if (tp_inst._defaults.altRedirectFocus === true) {
  265. tp_inst.$altInput.css({
  266. cursor: 'pointer'
  267. }).focus(function () {
  268. $input.trigger("focus");
  269. });
  270. }
  271. }
  272. if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) {
  273. tp_inst._defaults.minDate = new Date();
  274. }
  275. if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) {
  276. tp_inst._defaults.maxDate = new Date();
  277. }
  278. // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
  279. if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) {
  280. tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
  281. }
  282. if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) {
  283. tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
  284. }
  285. if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) {
  286. tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
  287. }
  288. if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) {
  289. tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
  290. }
  291. tp_inst.$input.bind('focus', function () {
  292. tp_inst._onFocus();
  293. });
  294. return tp_inst;
  295. },
  296. /*
  297. * add our sliders to the calendar
  298. */
  299. _addTimePicker: function (dp_inst) {
  300. var currDT = $.trim((this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val());
  301. this.timeDefined = this._parseTime(currDT);
  302. this._limitMinMaxDateTime(dp_inst, false);
  303. this._injectTimePicker();
  304. this._afterInject();
  305. },
  306. /*
  307. * parse the time string from input value or _setTime
  308. */
  309. _parseTime: function (timeString, withDate) {
  310. if (!this.inst) {
  311. this.inst = $.datepicker._getInst(this.$input[0]);
  312. }
  313. if (withDate || !this._defaults.timeOnly) {
  314. var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
  315. try {
  316. var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults);
  317. if (!parseRes.timeObj) {
  318. return false;
  319. }
  320. $.extend(this, parseRes.timeObj);
  321. } catch (err) {
  322. $.timepicker.log("Error parsing the date/time string: " + err +
  323. "\ndate/time string = " + timeString +
  324. "\ntimeFormat = " + this._defaults.timeFormat +
  325. "\ndateFormat = " + dp_dateFormat);
  326. return false;
  327. }
  328. return true;
  329. } else {
  330. var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults);
  331. if (!timeObj) {
  332. return false;
  333. }
  334. $.extend(this, timeObj);
  335. return true;
  336. }
  337. },
  338. /*
  339. * Handle callback option after injecting timepicker
  340. */
  341. _afterInject: function() {
  342. var o = this.inst.settings;
  343. if ($.isFunction(o.afterInject)) {
  344. o.afterInject.call(this);
  345. }
  346. },
  347. /*
  348. * generate and inject html for timepicker into ui datepicker
  349. */
  350. _injectTimePicker: function () {
  351. var $dp = this.inst.dpDiv,
  352. o = this.inst.settings,
  353. tp_inst = this,
  354. litem = '',
  355. uitem = '',
  356. show = null,
  357. max = {},
  358. gridSize = {},
  359. size = null,
  360. i = 0,
  361. l = 0;
  362. // Prevent displaying twice
  363. if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) {
  364. var noDisplay = ' ui_tpicker_unit_hide',
  365. html = '<div class="ui-timepicker-div' + (o.isRTL ? ' ui-timepicker-rtl' : '') + (o.oneLine && o.controlType === 'select' ? ' ui-timepicker-oneLine' : '') + '"><dl>' + '<dt class="ui_tpicker_time_label' + ((o.showTime) ? '' : noDisplay) + '">' + o.timeText + '</dt>' +
  366. '<dd class="ui_tpicker_time '+ ((o.showTime) ? '' : noDisplay) + '"><input class="ui_tpicker_time_input" ' + (o.timeInput ? '' : 'disabled') + '/></dd>';
  367. // Create the markup
  368. for (i = 0, l = this.units.length; i < l; i++) {
  369. litem = this.units[i];
  370. uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1);
  371. show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem];
  372. // Added by Peter Medeiros:
  373. // - Figure out what the hour/minute/second max should be based on the step values.
  374. // - Example: if stepMinute is 15, then minMax is 45.
  375. max[litem] = parseInt((o[litem + 'Max'] - ((o[litem + 'Max'] - o[litem + 'Min']) % o['step' + uitem])), 10);
  376. gridSize[litem] = 0;
  377. html += '<dt class="ui_tpicker_' + litem + '_label' + (show ? '' : noDisplay) + '">' + o[litem + 'Text'] + '</dt>' +
  378. '<dd class="ui_tpicker_' + litem + (show ? '' : noDisplay) + '"><div class="ui_tpicker_' + litem + '_slider' + (show ? '' : noDisplay) + '"></div>';
  379. if (show && o[litem + 'Grid'] > 0) {
  380. html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
  381. if (litem === 'hour') {
  382. for (var h = o[litem + 'Min']; h <= max[litem]; h += parseInt(o[litem + 'Grid'], 10)) {
  383. gridSize[litem]++;
  384. var tmph = $.datepicker.formatTime(this.support.ampm ? 'hht' : 'HH', {hour: h}, o);
  385. html += '<td data-for="' + litem + '">' + tmph + '</td>';
  386. }
  387. }
  388. else {
  389. for (var m = o[litem + 'Min']; m <= max[litem]; m += parseInt(o[litem + 'Grid'], 10)) {
  390. gridSize[litem]++;
  391. html += '<td data-for="' + litem + '">' + ((m < 10) ? '0' : '') + m + '</td>';
  392. }
  393. }
  394. html += '</tr></table></div>';
  395. }
  396. html += '</dd>';
  397. }
  398. // Timezone
  399. var showTz = o.showTimezone !== null ? o.showTimezone : this.support.timezone;
  400. html += '<dt class="ui_tpicker_timezone_label' + (showTz ? '' : noDisplay) + '">' + o.timezoneText + '</dt>';
  401. html += '<dd class="ui_tpicker_timezone' + (showTz ? '' : noDisplay) + '"></dd>';
  402. // Create the elements from string
  403. html += '</dl></div>';
  404. var $tp = $(html);
  405. // if we only want time picker...
  406. if (o.timeOnly === true) {
  407. $tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>');
  408. $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
  409. }
  410. // add sliders, adjust grids, add events
  411. for (i = 0, l = tp_inst.units.length; i < l; i++) {
  412. litem = tp_inst.units[i];
  413. uitem = litem.substr(0, 1).toUpperCase() + litem.substr(1);
  414. show = o['show' + uitem] !== null ? o['show' + uitem] : this.support[litem];
  415. // add the slider
  416. tp_inst[litem + '_slider'] = tp_inst.control.create(tp_inst, $tp.find('.ui_tpicker_' + litem + '_slider'), litem, tp_inst[litem], o[litem + 'Min'], max[litem], o['step' + uitem]);
  417. // adjust the grid and add click event
  418. if (show && o[litem + 'Grid'] > 0) {
  419. size = 100 * gridSize[litem] * o[litem + 'Grid'] / (max[litem] - o[litem + 'Min']);
  420. $tp.find('.ui_tpicker_' + litem + ' table').css({
  421. width: size + "%",
  422. marginLeft: o.isRTL ? '0' : ((size / (-2 * gridSize[litem])) + "%"),
  423. marginRight: o.isRTL ? ((size / (-2 * gridSize[litem])) + "%") : '0',
  424. borderCollapse: 'collapse'
  425. }).find("td").click(function (e) {
  426. var $t = $(this),
  427. h = $t.html(),
  428. n = parseInt(h.replace(/[^0-9]/g), 10),
  429. ap = h.replace(/[^apm]/ig),
  430. f = $t.data('for'); // loses scope, so we use data-for
  431. if (f === 'hour') {
  432. if (ap.indexOf('p') !== -1 && n < 12) {
  433. n += 12;
  434. }
  435. else {
  436. if (ap.indexOf('a') !== -1 && n === 12) {
  437. n = 0;
  438. }
  439. }
  440. }
  441. tp_inst.control.value(tp_inst, tp_inst[f + '_slider'], litem, n);
  442. tp_inst._onTimeChange();
  443. tp_inst._onSelectHandler();
  444. }).css({
  445. cursor: 'pointer',
  446. width: (100 / gridSize[litem]) + '%',
  447. textAlign: 'center',
  448. overflow: 'hidden'
  449. });
  450. } // end if grid > 0
  451. } // end for loop
  452. // Add timezone options
  453. this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select");
  454. $.fn.append.apply(this.timezone_select,
  455. $.map(o.timezoneList, function (val, idx) {
  456. return $("<option />").val(typeof val === "object" ? val.value : val).text(typeof val === "object" ? val.label : val);
  457. }));
  458. if (typeof(this.timezone) !== "undefined" && this.timezone !== null && this.timezone !== "") {
  459. var local_timezone = (new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12)).getTimezoneOffset() * -1;
  460. if (local_timezone === this.timezone) {
  461. selectLocalTimezone(tp_inst);
  462. } else {
  463. this.timezone_select.val(this.timezone);
  464. }
  465. } else {
  466. if (typeof(this.hour) !== "undefined" && this.hour !== null && this.hour !== "") {
  467. this.timezone_select.val(o.timezone);
  468. } else {
  469. selectLocalTimezone(tp_inst);
  470. }
  471. }
  472. this.timezone_select.change(function () {
  473. tp_inst._onTimeChange();
  474. tp_inst._onSelectHandler();
  475. tp_inst._afterInject();
  476. });
  477. // End timezone options
  478. // inject timepicker into datepicker
  479. var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
  480. if ($buttonPanel.length) {
  481. $buttonPanel.before($tp);
  482. } else {
  483. $dp.append($tp);
  484. }
  485. this.$timeObj = $tp.find('.ui_tpicker_time_input');
  486. this.$timeObj.change(function () {
  487. var timeFormat = tp_inst.inst.settings.timeFormat;
  488. var parsedTime = $.datepicker.parseTime(timeFormat, this.value);
  489. var update = new Date();
  490. if (parsedTime) {
  491. update.setHours(parsedTime.hour);
  492. update.setMinutes(parsedTime.minute);
  493. update.setSeconds(parsedTime.second);
  494. $.datepicker._setTime(tp_inst.inst, update);
  495. } else {
  496. this.value = tp_inst.formattedTime;
  497. this.blur();
  498. }
  499. });
  500. if (this.inst !== null) {
  501. var timeDefined = this.timeDefined;
  502. this._onTimeChange();
  503. this.timeDefined = timeDefined;
  504. }
  505. // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
  506. if (this._defaults.addSliderAccess) {
  507. var sliderAccessArgs = this._defaults.sliderAccessArgs,
  508. rtl = this._defaults.isRTL;
  509. sliderAccessArgs.isRTL = rtl;
  510. setTimeout(function () { // fix for inline mode
  511. if ($tp.find('.ui-slider-access').length === 0) {
  512. $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
  513. // fix any grids since sliders are shorter
  514. var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true);
  515. if (sliderAccessWidth) {
  516. $tp.find('table:visible').each(function () {
  517. var $g = $(this),
  518. oldWidth = $g.outerWidth(),
  519. oldMarginLeft = $g.css(rtl ? 'marginRight' : 'marginLeft').toString().replace('%', ''),
  520. newWidth = oldWidth - sliderAccessWidth,
  521. newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%',
  522. css = { width: newWidth, marginRight: 0, marginLeft: 0 };
  523. css[rtl ? 'marginRight' : 'marginLeft'] = newMarginLeft;
  524. $g.css(css);
  525. });
  526. }
  527. }
  528. }, 10);
  529. }
  530. // end slideAccess integration
  531. tp_inst._limitMinMaxDateTime(this.inst, true);
  532. }
  533. },
  534. /*
  535. * This function tries to limit the ability to go outside the
  536. * min/max date range
  537. */
  538. _limitMinMaxDateTime: function (dp_inst, adjustSliders) {
  539. var o = this._defaults,
  540. dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
  541. if (!this._defaults.showTimepicker) {
  542. return;
  543. } // No time so nothing to check here
  544. if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) {
  545. var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
  546. minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
  547. if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null || this.microsecMinOriginal === null) {
  548. this.hourMinOriginal = o.hourMin;
  549. this.minuteMinOriginal = o.minuteMin;
  550. this.secondMinOriginal = o.secondMin;
  551. this.millisecMinOriginal = o.millisecMin;
  552. this.microsecMinOriginal = o.microsecMin;
  553. }
  554. if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() === dp_date.getTime()) {
  555. this._defaults.hourMin = minDateTime.getHours();
  556. if (this.hour <= this._defaults.hourMin) {
  557. this.hour = this._defaults.hourMin;
  558. this._defaults.minuteMin = minDateTime.getMinutes();
  559. if (this.minute <= this._defaults.minuteMin) {
  560. this.minute = this._defaults.minuteMin;
  561. this._defaults.secondMin = minDateTime.getSeconds();
  562. if (this.second <= this._defaults.secondMin) {
  563. this.second = this._defaults.secondMin;
  564. this._defaults.millisecMin = minDateTime.getMilliseconds();
  565. if (this.millisec <= this._defaults.millisecMin) {
  566. this.millisec = this._defaults.millisecMin;
  567. this._defaults.microsecMin = minDateTime.getMicroseconds();
  568. } else {
  569. if (this.microsec < this._defaults.microsecMin) {
  570. this.microsec = this._defaults.microsecMin;
  571. }
  572. this._defaults.microsecMin = this.microsecMinOriginal;
  573. }
  574. } else {
  575. this._defaults.millisecMin = this.millisecMinOriginal;
  576. this._defaults.microsecMin = this.microsecMinOriginal;
  577. }
  578. } else {
  579. this._defaults.secondMin = this.secondMinOriginal;
  580. this._defaults.millisecMin = this.millisecMinOriginal;
  581. this._defaults.microsecMin = this.microsecMinOriginal;
  582. }
  583. } else {
  584. this._defaults.minuteMin = this.minuteMinOriginal;
  585. this._defaults.secondMin = this.secondMinOriginal;
  586. this._defaults.millisecMin = this.millisecMinOriginal;
  587. this._defaults.microsecMin = this.microsecMinOriginal;
  588. }
  589. } else {
  590. this._defaults.hourMin = this.hourMinOriginal;
  591. this._defaults.minuteMin = this.minuteMinOriginal;
  592. this._defaults.secondMin = this.secondMinOriginal;
  593. this._defaults.millisecMin = this.millisecMinOriginal;
  594. this._defaults.microsecMin = this.microsecMinOriginal;
  595. }
  596. }
  597. if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) {
  598. var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
  599. maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
  600. if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null || this.millisecMaxOriginal === null) {
  601. this.hourMaxOriginal = o.hourMax;
  602. this.minuteMaxOriginal = o.minuteMax;
  603. this.secondMaxOriginal = o.secondMax;
  604. this.millisecMaxOriginal = o.millisecMax;
  605. this.microsecMaxOriginal = o.microsecMax;
  606. }
  607. if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() === dp_date.getTime()) {
  608. this._defaults.hourMax = maxDateTime.getHours();
  609. if (this.hour >= this._defaults.hourMax) {
  610. this.hour = this._defaults.hourMax;
  611. this._defaults.minuteMax = maxDateTime.getMinutes();
  612. if (this.minute >= this._defaults.minuteMax) {
  613. this.minute = this._defaults.minuteMax;
  614. this._defaults.secondMax = maxDateTime.getSeconds();
  615. if (this.second >= this._defaults.secondMax) {
  616. this.second = this._defaults.secondMax;
  617. this._defaults.millisecMax = maxDateTime.getMilliseconds();
  618. if (this.millisec >= this._defaults.millisecMax) {
  619. this.millisec = this._defaults.millisecMax;
  620. this._defaults.microsecMax = maxDateTime.getMicroseconds();
  621. } else {
  622. if (this.microsec > this._defaults.microsecMax) {
  623. this.microsec = this._defaults.microsecMax;
  624. }
  625. this._defaults.microsecMax = this.microsecMaxOriginal;
  626. }
  627. } else {
  628. this._defaults.millisecMax = this.millisecMaxOriginal;
  629. this._defaults.microsecMax = this.microsecMaxOriginal;
  630. }
  631. } else {
  632. this._defaults.secondMax = this.secondMaxOriginal;
  633. this._defaults.millisecMax = this.millisecMaxOriginal;
  634. this._defaults.microsecMax = this.microsecMaxOriginal;
  635. }
  636. } else {
  637. this._defaults.minuteMax = this.minuteMaxOriginal;
  638. this._defaults.secondMax = this.secondMaxOriginal;
  639. this._defaults.millisecMax = this.millisecMaxOriginal;
  640. this._defaults.microsecMax = this.microsecMaxOriginal;
  641. }
  642. } else {
  643. this._defaults.hourMax = this.hourMaxOriginal;
  644. this._defaults.minuteMax = this.minuteMaxOriginal;
  645. this._defaults.secondMax = this.secondMaxOriginal;
  646. this._defaults.millisecMax = this.millisecMaxOriginal;
  647. this._defaults.microsecMax = this.microsecMaxOriginal;
  648. }
  649. }
  650. if (dp_inst.settings.minTime!==null) {
  651. var tempMinTime=new Date("01/01/1970 " + dp_inst.settings.minTime);
  652. if (this.hour<tempMinTime.getHours()) {
  653. this.hour=this._defaults.hourMin=tempMinTime.getHours();
  654. this.minute=this._defaults.minuteMin=tempMinTime.getMinutes();
  655. } else if (this.hour===tempMinTime.getHours() && this.minute<tempMinTime.getMinutes()) {
  656. this.minute=this._defaults.minuteMin=tempMinTime.getMinutes();
  657. } else {
  658. if (this._defaults.hourMin<tempMinTime.getHours()) {
  659. this._defaults.hourMin=tempMinTime.getHours();
  660. this._defaults.minuteMin=tempMinTime.getMinutes();
  661. } else if (this._defaults.hourMin===tempMinTime.getHours()===this.hour && this._defaults.minuteMin<tempMinTime.getMinutes()) {
  662. this._defaults.minuteMin=tempMinTime.getMinutes();
  663. } else {
  664. this._defaults.minuteMin=0;
  665. }
  666. }
  667. }
  668. if (dp_inst.settings.maxTime!==null) {
  669. var tempMaxTime=new Date("01/01/1970 " + dp_inst.settings.maxTime);
  670. if (this.hour>tempMaxTime.getHours()) {
  671. this.hour=this._defaults.hourMax=tempMaxTime.getHours();
  672. this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
  673. } else if (this.hour===tempMaxTime.getHours() && this.minute>tempMaxTime.getMinutes()) {
  674. this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
  675. } else {
  676. if (this._defaults.hourMax>tempMaxTime.getHours()) {
  677. this._defaults.hourMax=tempMaxTime.getHours();
  678. this._defaults.minuteMax=tempMaxTime.getMinutes();
  679. } else if (this._defaults.hourMax===tempMaxTime.getHours()===this.hour && this._defaults.minuteMax>tempMaxTime.getMinutes()) {
  680. this._defaults.minuteMax=tempMaxTime.getMinutes();
  681. } else {
  682. this._defaults.minuteMax=59;
  683. }
  684. }
  685. }
  686. if (adjustSliders !== undefined && adjustSliders === true) {
  687. var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10),
  688. minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10),
  689. secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10),
  690. millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10),
  691. microsecMax = parseInt((this._defaults.microsecMax - ((this._defaults.microsecMax - this._defaults.microsecMin) % this._defaults.stepMicrosec)), 10);
  692. if (this.hour_slider) {
  693. this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax, step: this._defaults.stepHour });
  694. this.control.value(this, this.hour_slider, 'hour', this.hour - (this.hour % this._defaults.stepHour));
  695. }
  696. if (this.minute_slider) {
  697. this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax, step: this._defaults.stepMinute });
  698. this.control.value(this, this.minute_slider, 'minute', this.minute - (this.minute % this._defaults.stepMinute));
  699. }
  700. if (this.second_slider) {
  701. this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax, step: this._defaults.stepSecond });
  702. this.control.value(this, this.second_slider, 'second', this.second - (this.second % this._defaults.stepSecond));
  703. }
  704. if (this.millisec_slider) {
  705. this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax, step: this._defaults.stepMillisec });
  706. this.control.value(this, this.millisec_slider, 'millisec', this.millisec - (this.millisec % this._defaults.stepMillisec));
  707. }
  708. if (this.microsec_slider) {
  709. this.control.options(this, this.microsec_slider, 'microsec', { min: this._defaults.microsecMin, max: microsecMax, step: this._defaults.stepMicrosec });
  710. this.control.value(this, this.microsec_slider, 'microsec', this.microsec - (this.microsec % this._defaults.stepMicrosec));
  711. }
  712. }
  713. },
  714. /*
  715. * when a slider moves, set the internal time...
  716. * on time change is also called when the time is updated in the text field
  717. */
  718. _onTimeChange: function () {
  719. if (!this._defaults.showTimepicker) {
  720. return;
  721. }
  722. var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false,
  723. minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false,
  724. second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false,
  725. millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false,
  726. microsec = (this.microsec_slider) ? this.control.value(this, this.microsec_slider, 'microsec') : false,
  727. timezone = (this.timezone_select) ? this.timezone_select.val() : false,
  728. o = this._defaults,
  729. pickerTimeFormat = o.pickerTimeFormat || o.timeFormat,
  730. pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix;
  731. if (typeof(hour) === 'object') {
  732. hour = false;
  733. }
  734. if (typeof(minute) === 'object') {
  735. minute = false;
  736. }
  737. if (typeof(second) === 'object') {
  738. second = false;
  739. }
  740. if (typeof(millisec) === 'object') {
  741. millisec = false;
  742. }
  743. if (typeof(microsec) === 'object') {
  744. microsec = false;
  745. }
  746. if (typeof(timezone) === 'object') {
  747. timezone = false;
  748. }
  749. if (hour !== false) {
  750. hour = parseInt(hour, 10);
  751. }
  752. if (minute !== false) {
  753. minute = parseInt(minute, 10);
  754. }
  755. if (second !== false) {
  756. second = parseInt(second, 10);
  757. }
  758. if (millisec !== false) {
  759. millisec = parseInt(millisec, 10);
  760. }
  761. if (microsec !== false) {
  762. microsec = parseInt(microsec, 10);
  763. }
  764. if (timezone !== false) {
  765. timezone = timezone.toString();
  766. }
  767. var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
  768. // If the update was done in the input field, the input field should not be updated.
  769. // If the update was done using the sliders, update the input field.
  770. var hasChanged = (
  771. hour !== parseInt(this.hour,10) || // sliders should all be numeric
  772. minute !== parseInt(this.minute,10) ||
  773. second !== parseInt(this.second,10) ||
  774. millisec !== parseInt(this.millisec,10) ||
  775. microsec !== parseInt(this.microsec,10) ||
  776. (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) ||
  777. (this.timezone !== null && timezone !== this.timezone.toString()) // could be numeric or "EST" format, so use toString()
  778. );
  779. if (hasChanged) {
  780. if (hour !== false) {
  781. this.hour = hour;
  782. }
  783. if (minute !== false) {
  784. this.minute = minute;
  785. }
  786. if (second !== false) {
  787. this.second = second;
  788. }
  789. if (millisec !== false) {
  790. this.millisec = millisec;
  791. }
  792. if (microsec !== false) {
  793. this.microsec = microsec;
  794. }
  795. if (timezone !== false) {
  796. this.timezone = timezone;
  797. }
  798. if (!this.inst) {
  799. this.inst = $.datepicker._getInst(this.$input[0]);
  800. }
  801. this._limitMinMaxDateTime(this.inst, true);
  802. }
  803. if (this.support.ampm) {
  804. this.ampm = ampm;
  805. }
  806. // Updates the time within the timepicker
  807. this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o);
  808. if (this.$timeObj) {
  809. var sPos = this.$timeObj[0].selectionStart;
  810. var ePos = this.$timeObj[0].selectionEnd;
  811. if (pickerTimeFormat === o.timeFormat) {
  812. this.$timeObj.val(this.formattedTime + pickerTimeSuffix);
  813. }
  814. else {
  815. this.$timeObj.val($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
  816. }
  817. this.$timeObj[0].setSelectionRange(sPos, ePos);
  818. }
  819. this.timeDefined = true;
  820. if (hasChanged) {
  821. this._updateDateTime();
  822. //this.$input.focus(); // may automatically open the picker on setDate
  823. }
  824. },
  825. /*
  826. * call custom onSelect.
  827. * bind to sliders slidestop, and grid click.
  828. */
  829. _onSelectHandler: function () {
  830. var onSelect = this._defaults.onSelect || this.inst.settings.onSelect;
  831. var inputEl = this.$input ? this.$input[0] : null;
  832. if (onSelect && inputEl) {
  833. onSelect.apply(inputEl, [this.formattedDateTime, this]);
  834. }
  835. },
  836. /*
  837. * update our input with the new date time..
  838. */
  839. _updateDateTime: function (dp_inst) {
  840. dp_inst = this.inst || dp_inst;
  841. var dtTmp = (dp_inst.currentYear > 0?
  842. new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay) :
  843. new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
  844. dt = $.datepicker._daylightSavingAdjust(dtTmp),
  845. //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
  846. //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay)),
  847. dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
  848. formatCfg = $.datepicker._getFormatConfig(dp_inst),
  849. timeAvailable = dt !== null && this.timeDefined;
  850. this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
  851. var formattedDateTime = this.formattedDate;
  852. // if a slider was changed but datepicker doesn't have a value yet, set it
  853. if (dp_inst.lastVal === "") {
  854. dp_inst.currentYear = dp_inst.selectedYear;
  855. dp_inst.currentMonth = dp_inst.selectedMonth;
  856. dp_inst.currentDay = dp_inst.selectedDay;
  857. }
  858. /*
  859. * remove following lines to force every changes in date picker to change the input value
  860. * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker.
  861. * If the user manually empty the value in the input field, the date picker will never change selected value.
  862. */
  863. //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) {
  864. // return;
  865. //}
  866. if (this._defaults.timeOnly === true && this._defaults.timeOnlyShowDate === false) {
  867. formattedDateTime = this.formattedTime;
  868. } else if ((this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) || (this._defaults.timeOnly === true && this._defaults.timeOnlyShowDate === true)) {
  869. formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
  870. }
  871. this.formattedDateTime = formattedDateTime;
  872. if (!this._defaults.showTimepicker) {
  873. this.$input.val(this.formattedDate);
  874. } else if (this.$altInput && this._defaults.timeOnly === false && this._defaults.altFieldTimeOnly === true) {
  875. this.$altInput.val(this.formattedTime);
  876. this.$input.val(this.formattedDate);
  877. } else if (this.$altInput) {
  878. this.$input.val(formattedDateTime);
  879. var altFormattedDateTime = '',
  880. altSeparator = this._defaults.altSeparator !== null ? this._defaults.altSeparator : this._defaults.separator,
  881. altTimeSuffix = this._defaults.altTimeSuffix !== null ? this._defaults.altTimeSuffix : this._defaults.timeSuffix;
  882. if (!this._defaults.timeOnly) {
  883. if (this._defaults.altFormat) {
  884. altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg);
  885. }
  886. else {
  887. altFormattedDateTime = this.formattedDate;
  888. }
  889. if (altFormattedDateTime) {
  890. altFormattedDateTime += altSeparator;
  891. }
  892. }
  893. if (this._defaults.altTimeFormat !== null) {
  894. altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix;
  895. }
  896. else {
  897. altFormattedDateTime += this.formattedTime + altTimeSuffix;
  898. }
  899. this.$altInput.val(altFormattedDateTime);
  900. } else {
  901. this.$input.val(formattedDateTime);
  902. }
  903. this.$input.trigger("change");
  904. },
  905. _onFocus: function () {
  906. if (!this.$input.val() && this._defaults.defaultValue) {
  907. this.$input.val(this._defaults.defaultValue);
  908. var inst = $.datepicker._getInst(this.$input.get(0)),
  909. tp_inst = $.datepicker._get(inst, 'timepicker');
  910. if (tp_inst) {
  911. if (tp_inst._defaults.timeOnly && (inst.input.val() !== inst.lastVal)) {
  912. try {
  913. $.datepicker._updateDatepicker(inst);
  914. } catch (err) {
  915. $.timepicker.log(err);
  916. }
  917. }
  918. }
  919. }
  920. },
  921. /*
  922. * Small abstraction to control types
  923. * We can add more, just be sure to follow the pattern: create, options, value
  924. */
  925. _controls: {
  926. // slider methods
  927. slider: {
  928. create: function (tp_inst, obj, unit, val, min, max, step) {
  929. var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60
  930. return obj.prop('slide', null).slider({
  931. orientation: "horizontal",
  932. value: rtl ? val * -1 : val,
  933. min: rtl ? max * -1 : min,
  934. max: rtl ? min * -1 : max,
  935. step: step,
  936. slide: function (event, ui) {
  937. tp_inst.control.value(tp_inst, $(this), unit, rtl ? ui.value * -1 : ui.value);
  938. tp_inst._onTimeChange();
  939. },
  940. stop: function (event, ui) {
  941. tp_inst._onSelectHandler();
  942. }
  943. });
  944. },
  945. options: function (tp_inst, obj, unit, opts, val) {
  946. if (tp_inst._defaults.isRTL) {
  947. if (typeof(opts) === 'string') {
  948. if (opts === 'min' || opts === 'max') {
  949. if (val !== undefined) {
  950. return obj.slider(opts, val * -1);
  951. }
  952. return Math.abs(obj.slider(opts));
  953. }
  954. return obj.slider(opts);
  955. }
  956. var min = opts.min,
  957. max = opts.max;
  958. opts.min = opts.max = null;
  959. if (min !== undefined) {
  960. opts.max = min * -1;
  961. }
  962. if (max !== undefined) {
  963. opts.min = max * -1;
  964. }
  965. return obj.slider(opts);
  966. }
  967. if (typeof(opts) === 'string' && val !== undefined) {
  968. return obj.slider(opts, val);
  969. }
  970. return obj.slider(opts);
  971. },
  972. value: function (tp_inst, obj, unit, val) {
  973. if (tp_inst._defaults.isRTL) {
  974. if (val !== undefined) {
  975. return obj.slider('value', val * -1);
  976. }
  977. return Math.abs(obj.slider('value'));
  978. }
  979. if (val !== undefined) {
  980. return obj.slider('value', val);
  981. }
  982. return obj.slider('value');
  983. }
  984. },
  985. // select methods
  986. select: {
  987. create: function (tp_inst, obj, unit, val, min, max, step) {
  988. var sel = '<select class="ui-timepicker-select ui-state-default ui-corner-all" data-unit="' + unit + '" data-min="' + min + '" data-max="' + max + '" data-step="' + step + '">',
  989. format = tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat;
  990. for (var i = min; i <= max; i += step) {
  991. sel += '<option value="' + i + '"' + (i === val ? ' selected' : '') + '>';
  992. if (unit === 'hour') {
  993. format = format.replace(/'.'/g, '');
  994. sel += $.datepicker.formatTime($.trim(format.replace(/[^ht ]/ig, '')), {hour: i}, tp_inst._defaults);
  995. }
  996. else if (unit === 'millisec' || unit === 'microsec' || i >= 10) { sel += i; }
  997. else {sel += '0' + i.toString(); }
  998. sel += '</option>';
  999. }
  1000. sel += '</select>';
  1001. obj.children('select').remove();
  1002. $(sel).appendTo(obj).change(function (e) {
  1003. tp_inst._onTimeChange();
  1004. tp_inst._onSelectHandler();
  1005. tp_inst._afterInject();
  1006. });
  1007. return obj;
  1008. },
  1009. options: function (tp_inst, obj, unit, opts, val) {
  1010. var o = {},
  1011. $t = obj.children('select');
  1012. if (typeof(opts) === 'string') {
  1013. if (val === undefined) {
  1014. return $t.data(opts);
  1015. }
  1016. o[opts] = val;
  1017. }
  1018. else { o = opts; }
  1019. return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min>=0 ? o.min : $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step'));
  1020. },
  1021. value: function (tp_inst, obj, unit, val) {
  1022. var $t = obj.children('select');
  1023. if (val !== undefined) {
  1024. return $t.val(val);
  1025. }
  1026. return $t.val();
  1027. }
  1028. }
  1029. } // end _controls
  1030. });
  1031. $.fn.extend({
  1032. /*
  1033. * shorthand just to use timepicker.
  1034. */
  1035. timepicker: function (o) {
  1036. o = o || {};
  1037. var tmp_args = Array.prototype.slice.call(arguments);
  1038. if (typeof o === 'object') {
  1039. tmp_args[0] = $.extend(o, {
  1040. timeOnly: true
  1041. });
  1042. }
  1043. return $(this).each(function () {
  1044. $.fn.datetimepicker.apply($(this), tmp_args);
  1045. });
  1046. },
  1047. /*
  1048. * extend timepicker to datepicker
  1049. */
  1050. datetimepicker: function (o) {
  1051. o = o || {};
  1052. var tmp_args = arguments;
  1053. if (typeof(o) === 'string') {
  1054. if (o === 'getDate' || (o === 'option' && tmp_args.length === 2 && typeof (tmp_args[1]) === 'string')) {
  1055. return $.fn.datepicker.apply($(this[0]), tmp_args);
  1056. } else {
  1057. return this.each(function () {
  1058. var $t = $(this);
  1059. $t.datepicker.apply($t, tmp_args);
  1060. });
  1061. }
  1062. } else {
  1063. return this.each(function () {
  1064. var $t = $(this);
  1065. $t.datepicker($.timepicker._newInst($t, o)._defaults);
  1066. });
  1067. }
  1068. }
  1069. });
  1070. /*
  1071. * Public Utility to parse date and time
  1072. */
  1073. $.datepicker.parseDateTime = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
  1074. var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings);
  1075. if (parseRes.timeObj) {
  1076. var t = parseRes.timeObj;
  1077. parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
  1078. parseRes.date.setMicroseconds(t.microsec);
  1079. }
  1080. return parseRes.date;
  1081. };
  1082. /*
  1083. * Public utility to parse time
  1084. */
  1085. $.datepicker.parseTime = function (timeFormat, timeString, options) {
  1086. var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {}),
  1087. iso8601 = (timeFormat.replace(/\'.*?\'/g, '').indexOf('Z') !== -1);
  1088. // Strict parse requires the timeString to match the timeFormat exactly
  1089. var strictParse = function (f, s, o) {
  1090. // pattern for standard and localized AM/PM markers
  1091. var getPatternAmpm = function (amNames, pmNames) {
  1092. var markers = [];
  1093. if (amNames) {
  1094. $.merge(markers, amNames);
  1095. }
  1096. if (pmNames) {
  1097. $.merge(markers, pmNames);
  1098. }
  1099. markers = $.map(markers, function (val) {
  1100. return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
  1101. });
  1102. return '(' + markers.join('|') + ')?';
  1103. };
  1104. // figure out position of time elements.. cause js cant do named captures
  1105. var getFormatPositions = function (timeFormat) {
  1106. var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g),
  1107. orders = {
  1108. h: -1,
  1109. m: -1,
  1110. s: -1,
  1111. l: -1,
  1112. c: -1,
  1113. t: -1,
  1114. z: -1
  1115. };
  1116. if (finds) {
  1117. for (var i = 0; i < finds.length; i++) {
  1118. if (orders[finds[i].toString().charAt(0)] === -1) {
  1119. orders[finds[i].toString().charAt(0)] = i + 1;
  1120. }
  1121. }
  1122. }
  1123. return orders;
  1124. };
  1125. var regstr = '^' + f.toString()
  1126. .replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
  1127. var ml = match.length;
  1128. switch (match.charAt(0).toLowerCase()) {
  1129. case 'h':
  1130. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1131. case 'm':
  1132. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1133. case 's':
  1134. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1135. case 'l':
  1136. return '(\\d?\\d?\\d)';
  1137. case 'c':
  1138. return '(\\d?\\d?\\d)';
  1139. case 'z':
  1140. return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
  1141. case 't':
  1142. return getPatternAmpm(o.amNames, o.pmNames);
  1143. default: // literal escaped in quotes
  1144. return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
  1145. }
  1146. })
  1147. .replace(/\s/g, '\\s?') +
  1148. o.timeSuffix + '$',
  1149. order = getFormatPositions(f),
  1150. ampm = '',
  1151. treg;
  1152. treg = s.match(new RegExp(regstr, 'i'));
  1153. var resTime = {
  1154. hour: 0,
  1155. minute: 0,
  1156. second: 0,
  1157. millisec: 0,
  1158. microsec: 0
  1159. };
  1160. if (treg) {
  1161. if (order.t !== -1) {
  1162. if (treg[order.t] === undefined || treg[order.t].length === 0) {
  1163. ampm = '';
  1164. resTime.ampm = '';
  1165. } else {
  1166. ampm = $.inArray(treg[order.t].toUpperCase(), $.map(o.amNames, function (x,i) { return x.toUpperCase(); })) !== -1 ? 'AM' : 'PM';
  1167. resTime.ampm = o[ampm === 'AM' ? 'amNames' : 'pmNames'][0];
  1168. }
  1169. }
  1170. if (order.h !== -1) {
  1171. if (ampm === 'AM' && treg[order.h] === '12') {
  1172. resTime.hour = 0; // 12am = 0 hour
  1173. } else {
  1174. if (ampm === 'PM' && treg[order.h] !== '12') {
  1175. resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12
  1176. } else {
  1177. resTime.hour = Number(treg[order.h]);
  1178. }
  1179. }
  1180. }
  1181. if (order.m !== -1) {
  1182. resTime.minute = Number(treg[order.m]);
  1183. }
  1184. if (order.s !== -1) {
  1185. resTime.second = Number(treg[order.s]);
  1186. }
  1187. if (order.l !== -1) {
  1188. resTime.millisec = Number(treg[order.l]);
  1189. }
  1190. if (order.c !== -1) {
  1191. resTime.microsec = Number(treg[order.c]);
  1192. }
  1193. if (order.z !== -1 && treg[order.z] !== undefined) {
  1194. resTime.timezone = $.timepicker.timezoneOffsetNumber(treg[order.z]);
  1195. }
  1196. return resTime;
  1197. }
  1198. return false;
  1199. };// end strictParse
  1200. // First try JS Date, if that fails, use strictParse
  1201. var looseParse = function (f, s, o) {
  1202. try {
  1203. var d = new Date('2012-01-01 ' + s);
  1204. if (isNaN(d.getTime())) {
  1205. d = new Date('2012-01-01T' + s);
  1206. if (isNaN(d.getTime())) {
  1207. d = new Date('01/01/2012 ' + s);
  1208. if (isNaN(d.getTime())) {
  1209. throw "Unable to parse time with native Date: " + s;
  1210. }
  1211. }
  1212. }
  1213. return {
  1214. hour: d.getHours(),
  1215. minute: d.getMinutes(),
  1216. second: d.getSeconds(),
  1217. millisec: d.getMilliseconds(),
  1218. microsec: d.getMicroseconds(),
  1219. timezone: d.getTimezoneOffset() * -1
  1220. };
  1221. }
  1222. catch (err) {
  1223. try {
  1224. return strictParse(f, s, o);
  1225. }
  1226. catch (err2) {
  1227. $.timepicker.log("Unable to parse \ntimeString: " + s + "\ntimeFormat: " + f);
  1228. }
  1229. }
  1230. return false;
  1231. }; // end looseParse
  1232. if (typeof o.parse === "function") {
  1233. return o.parse(timeFormat, timeString, o);
  1234. }
  1235. if (o.parse === 'loose') {
  1236. return looseParse(timeFormat, timeString, o);
  1237. }
  1238. return strictParse(timeFormat, timeString, o);
  1239. };
  1240. /**
  1241. * Public utility to format the time
  1242. * @param {string} format format of the time
  1243. * @param {Object} time Object not a Date for timezones
  1244. * @param {Object} [options] essentially the regional[].. amNames, pmNames, ampm
  1245. * @returns {string} the formatted time
  1246. */
  1247. $.datepicker.formatTime = function (format, time, options) {
  1248. options = options || {};
  1249. options = $.extend({}, $.timepicker._defaults, options);
  1250. time = $.extend({
  1251. hour: 0,
  1252. minute: 0,
  1253. second: 0,
  1254. millisec: 0,
  1255. microsec: 0,
  1256. timezone: null
  1257. }, time);
  1258. var tmptime = format,
  1259. ampmName = options.amNames[0],
  1260. hour = parseInt(time.hour, 10);
  1261. if (hour > 11) {
  1262. ampmName = options.pmNames[0];
  1263. }
  1264. tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
  1265. switch (match) {
  1266. case 'HH':
  1267. return ('0' + hour).slice(-2);
  1268. case 'H':
  1269. return hour;
  1270. case 'hh':
  1271. return ('0' + convert24to12(hour)).slice(-2);
  1272. case 'h':
  1273. return convert24to12(hour);
  1274. case 'mm':
  1275. return ('0' + time.minute).slice(-2);
  1276. case 'm':
  1277. return time.minute;
  1278. case 'ss':
  1279. return ('0' + time.second).slice(-2);
  1280. case 's':
  1281. return time.second;
  1282. case 'l':
  1283. return ('00' + time.millisec).slice(-3);
  1284. case 'c':
  1285. return ('00' + time.microsec).slice(-3);
  1286. case 'z':
  1287. return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, false);
  1288. case 'Z':
  1289. return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, true);
  1290. case 'T':
  1291. return ampmName.charAt(0).toUpperCase();
  1292. case 'TT':
  1293. return ampmName.toUpperCase();
  1294. case 't':
  1295. return ampmName.charAt(0).toLowerCase();
  1296. case 'tt':
  1297. return ampmName.toLowerCase();
  1298. default:
  1299. return match.replace(/'/g, "");
  1300. }
  1301. });
  1302. return tmptime;
  1303. };
  1304. /*
  1305. * the bad hack :/ override datepicker so it doesn't close on select
  1306. // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
  1307. */
  1308. $.datepicker._base_selectDate = $.datepicker._selectDate;
  1309. $.datepicker._selectDate = function (id, dateStr) {
  1310. var inst = this._getInst($(id)[0]),
  1311. tp_inst = this._get(inst, 'timepicker'),
  1312. was_inline;
  1313. if (tp_inst && inst.settings.showTimepicker) {
  1314. tp_inst._limitMinMaxDateTime(inst, true);
  1315. was_inline = inst.inline;
  1316. inst.inline = inst.stay_open = true;
  1317. //This way the onSelect handler called from calendarpicker get the full dateTime
  1318. this._base_selectDate(id, dateStr);
  1319. inst.inline = was_inline;
  1320. inst.stay_open = false;
  1321. this._notifyChange(inst);
  1322. this._updateDatepicker(inst);
  1323. } else {
  1324. this._base_selectDate(id, dateStr);
  1325. }
  1326. };
  1327. /*
  1328. * second bad hack :/ override datepicker so it triggers an event when changing the input field
  1329. * and does not redraw the datepicker on every selectDate event
  1330. */
  1331. $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
  1332. $.datepicker._updateDatepicker = function (inst) {
  1333. // don't popup the datepicker if there is another instance already opened
  1334. var input = inst.input[0];
  1335. if ($.datepicker._curInst && $.datepicker._curInst !== inst && $.datepicker._datepickerShowing && $.datepicker._lastInput !== input) {
  1336. return;
  1337. }
  1338. if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
  1339. this._base_updateDatepicker(inst);
  1340. // Reload the time control when changing something in the input text field.
  1341. var tp_inst = this._get(inst, 'timepicker');
  1342. if (tp_inst) {
  1343. tp_inst._addTimePicker(inst);
  1344. }
  1345. }
  1346. };
  1347. /*
  1348. * third bad hack :/ override datepicker so it allows spaces and colon in the input field
  1349. */
  1350. $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
  1351. $.datepicker._doKeyPress = function (event) {
  1352. var inst = $.datepicker._getInst(event.target),
  1353. tp_inst = $.datepicker._get(inst, 'timepicker');
  1354. if (tp_inst) {
  1355. if ($.datepicker._get(inst, 'constrainInput')) {
  1356. var ampm = tp_inst.support.ampm,
  1357. tz = tp_inst._defaults.showTimezone !== null ? tp_inst._defaults.showTimezone : tp_inst.support.timezone,
  1358. dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
  1359. datetimeChars = tp_inst._defaults.timeFormat.toString()
  1360. .replace(/[hms]/g, '')
  1361. .replace(/TT/g, ampm ? 'APM' : '')
  1362. .replace(/Tt/g, ampm ? 'AaPpMm' : '')
  1363. .replace(/tT/g, ampm ? 'AaPpMm' : '')
  1364. .replace(/T/g, ampm ? 'AP' : '')
  1365. .replace(/tt/g, ampm ? 'apm' : '')
  1366. .replace(/t/g, ampm ? 'ap' : '') +
  1367. " " + tp_inst._defaults.separator +
  1368. tp_inst._defaults.timeSuffix +
  1369. (tz ? tp_inst._defaults.timezoneList.join('') : '') +
  1370. (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) +
  1371. dateChars,
  1372. chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
  1373. return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
  1374. }
  1375. }
  1376. return $.datepicker._base_doKeyPress(event);
  1377. };
  1378. /*
  1379. * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField
  1380. * Update any alternate field to synchronise with the main field.
  1381. */
  1382. $.datepicker._base_updateAlternate = $.datepicker._updateAlternate;
  1383. $.datepicker._updateAlternate = function (inst) {
  1384. var tp_inst = this._get(inst, 'timepicker');
  1385. if (tp_inst) {
  1386. var altField = tp_inst._defaults.altField;
  1387. if (altField) { // update alternate field too
  1388. var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat,
  1389. date = this._getDate(inst),
  1390. formatCfg = $.datepicker._getFormatConfig(inst),
  1391. altFormattedDateTime = '',
  1392. altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator,
  1393. altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix,
  1394. altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat;
  1395. altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix;
  1396. if (!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null) {
  1397. if (tp_inst._defaults.altFormat) {
  1398. altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime;
  1399. }
  1400. else {
  1401. altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime;
  1402. }
  1403. }
  1404. $(altField).val( inst.input.val() ? altFormattedDateTime : "");
  1405. }
  1406. }
  1407. else {
  1408. $.datepicker._base_updateAlternate(inst);
  1409. }
  1410. };
  1411. /*
  1412. * Override key up event to sync manual input changes.
  1413. */
  1414. $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
  1415. $.datepicker._doKeyUp = function (event) {
  1416. var inst = $.datepicker._getInst(event.target),
  1417. tp_inst = $.datepicker._get(inst, 'timepicker');
  1418. if (tp_inst) {
  1419. if (tp_inst._defaults.timeOnly && (inst.input.val() !== inst.lastVal)) {
  1420. try {
  1421. $.datepicker._updateDatepicker(inst);
  1422. } catch (err) {
  1423. $.timepicker.log(err);
  1424. }
  1425. }
  1426. }
  1427. return $.datepicker._base_doKeyUp(event);
  1428. };
  1429. /*
  1430. * override "Today" button to also grab the time and set it to input field.
  1431. */
  1432. $.datepicker._base_gotoToday = $.datepicker._gotoToday;
  1433. $.datepicker._gotoToday = function (id) {
  1434. var inst = this._getInst($(id)[0]);
  1435. this._base_gotoToday(id);
  1436. var tp_inst = this._get(inst, 'timepicker');
  1437. var tzoffset = $.timepicker.timezoneOffsetNumber(tp_inst.timezone);
  1438. var now = new Date();
  1439. if (typeof tzoffset == 'string')
  1440. {
  1441. tzoffset = parseInt(tzoffset, 10);
  1442. }
  1443. console.log(tzoffset, now.getTimezoneOffset(), now);
  1444. now.setMinutes(now.getMinutes() + now.getTimezoneOffset() + tzoffset);
  1445. this._setTime(inst, now);
  1446. this._setDate(inst, now);
  1447. tp_inst._onSelectHandler();
  1448. };
  1449. /*
  1450. * Disable & enable the Time in the datetimepicker
  1451. */
  1452. $.datepicker._disableTimepickerDatepicker = function (target) {
  1453. var inst = this._getInst(target);
  1454. if (!inst) {
  1455. return;
  1456. }
  1457. var tp_inst = this._get(inst, 'timepicker');
  1458. $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
  1459. if (tp_inst) {
  1460. inst.settings.showTimepicker = false;
  1461. tp_inst._defaults.showTimepicker = false;
  1462. tp_inst._updateDateTime(inst);
  1463. }
  1464. };
  1465. $.datepicker._enableTimepickerDatepicker = function (target) {
  1466. var inst = this._getInst(target);
  1467. if (!inst) {
  1468. return;
  1469. }
  1470. var tp_inst = this._get(inst, 'timepicker');
  1471. $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
  1472. if (tp_inst) {
  1473. inst.settings.showTimepicker = true;
  1474. tp_inst._defaults.showTimepicker = true;
  1475. tp_inst._addTimePicker(inst); // Could be disabled on page load
  1476. tp_inst._updateDateTime(inst);
  1477. }
  1478. };
  1479. /*
  1480. * Create our own set time function
  1481. */
  1482. $.datepicker._setTime = function (inst, date) {
  1483. var tp_inst = this._get(inst, 'timepicker');
  1484. if (tp_inst) {
  1485. var defaults = tp_inst._defaults;
  1486. // calling _setTime with no date sets time to defaults
  1487. tp_inst.hour = date ? date.getHours() : defaults.hour;
  1488. tp_inst.minute = date ? date.getMinutes() : defaults.minute;
  1489. tp_inst.second = date ? date.getSeconds() : defaults.second;
  1490. tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec;
  1491. tp_inst.microsec = date ? date.getMicroseconds() : defaults.microsec;
  1492. //check if within min/max times..
  1493. tp_inst._limitMinMaxDateTime(inst, true);
  1494. tp_inst._onTimeChange();
  1495. tp_inst._updateDateTime(inst);
  1496. }
  1497. };
  1498. /*
  1499. * Create new public method to set only time, callable as $().datepicker('setTime', date)
  1500. */
  1501. $.datepicker._setTimeDatepicker = function (target, date, withDate) {
  1502. var inst = this._getInst(target);
  1503. if (!inst) {
  1504. return;
  1505. }
  1506. var tp_inst = this._get(inst, 'timepicker');
  1507. if (tp_inst) {
  1508. this._setDateFromField(inst);
  1509. var tp_date;
  1510. if (date) {
  1511. if (typeof date === "string") {
  1512. tp_inst._parseTime(date, withDate);
  1513. tp_date = new Date();
  1514. tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
  1515. tp_date.setMicroseconds(tp_inst.microsec);
  1516. } else {
  1517. tp_date = new Date(date.getTime());
  1518. tp_date.setMicroseconds(date.getMicroseconds());
  1519. }
  1520. if (tp_date.toString() === 'Invalid Date') {
  1521. tp_date = undefined;
  1522. }
  1523. this._setTime(inst, tp_date);
  1524. }
  1525. }
  1526. };
  1527. /*
  1528. * override setDate() to allow setting time too within Date object
  1529. */
  1530. $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
  1531. $.datepicker._setDateDatepicker = function (target, _date) {
  1532. var inst = this._getInst(target);
  1533. var date = _date;
  1534. if (!inst) {
  1535. return;
  1536. }
  1537. if (typeof(_date) === 'string') {
  1538. date = new Date(_date);
  1539. if (!date.getTime()) {
  1540. this._base_setDateDatepicker.apply(this, arguments);
  1541. date = $(target).datepicker('getDate');
  1542. }
  1543. }
  1544. var tp_inst = this._get(inst, 'timepicker');
  1545. var tp_date;
  1546. if (date instanceof Date) {
  1547. tp_date = new Date(date.getTime());
  1548. tp_date.setMicroseconds(date.getMicroseconds());
  1549. } else {
  1550. tp_date = date;
  1551. }
  1552. // This is important if you are using the timezone option, javascript's Date
  1553. // object will only return the timezone offset for the current locale, so we
  1554. // adjust it accordingly. If not using timezone option this won't matter..
  1555. // If a timezone is different in tp, keep the timezone as is
  1556. if (tp_inst && tp_date) {
  1557. // look out for DST if tz wasn't specified
  1558. if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
  1559. tp_inst.timezone = tp_date.getTimezoneOffset() * -1;
  1560. }
  1561. date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
  1562. tp_date = $.timepicker.timezoneAdjust(tp_date, tp_inst.timezone);
  1563. }
  1564. this._updateDatepicker(inst);
  1565. this._base_setDateDatepicker.apply(this, arguments);
  1566. this._setTimeDatepicker(target, tp_date, true);
  1567. };
  1568. /*
  1569. * override getDate() to allow getting time too within Date object
  1570. */
  1571. $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
  1572. $.datepicker._getDateDatepicker = function (target, noDefault) {
  1573. var inst = this._getInst(target);
  1574. if (!inst) {
  1575. return;
  1576. }
  1577. var tp_inst = this._get(inst, 'timepicker');
  1578. if (tp_inst) {
  1579. // if it hasn't yet been defined, grab from field
  1580. if (inst.lastVal === undefined) {
  1581. this._setDateFromField(inst, noDefault);
  1582. }
  1583. var date = this._getDate(inst);
  1584. var currDT = $.trim((tp_inst.$altInput && tp_inst._defaults.altFieldTimeOnly) ? tp_inst.$input.val() + ' ' + tp_inst.$altInput.val() : tp_inst.$input.val());
  1585. if (date && tp_inst._parseTime(currDT, !inst.settings.timeOnly)) {
  1586. date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
  1587. date.setMicroseconds(tp_inst.microsec);
  1588. // This is important if you are using the timezone option, javascript's Date
  1589. // object will only return the timezone offset for the current locale, so we
  1590. // adjust it accordingly. If not using timezone option this won't matter..
  1591. if (tp_inst.timezone != null) {
  1592. // look out for DST if tz wasn't specified
  1593. if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
  1594. tp_inst.timezone = date.getTimezoneOffset() * -1;
  1595. }
  1596. date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
  1597. }
  1598. }
  1599. return date;
  1600. }
  1601. return this._base_getDateDatepicker(target, noDefault);
  1602. };
  1603. /*
  1604. * override parseDate() because UI 1.8.14 throws an error about "Extra characters"
  1605. * An option in datapicker to ignore extra format characters would be nicer.
  1606. */
  1607. $.datepicker._base_parseDate = $.datepicker.parseDate;
  1608. $.datepicker.parseDate = function (format, value, settings) {
  1609. var date;
  1610. try {
  1611. date = this._base_parseDate(format, value, settings);
  1612. } catch (err) {
  1613. // Hack! The error message ends with a colon, a space, and
  1614. // the "extra" characters. We rely on that instead of
  1615. // attempting to perfectly reproduce the parsing algorithm.
  1616. if (err.indexOf(":") >= 0) {
  1617. date = this._base_parseDate(format, value.substring(0, value.length - (err.length - err.indexOf(':') - 2)), settings);
  1618. $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format);
  1619. } else {
  1620. throw err;
  1621. }
  1622. }
  1623. return date;
  1624. };
  1625. /*
  1626. * override formatDate to set date with time to the input
  1627. */
  1628. $.datepicker._base_formatDate = $.datepicker._formatDate;
  1629. $.datepicker._formatDate = function (inst, day, month, year) {
  1630. var tp_inst = this._get(inst, 'timepicker');
  1631. if (tp_inst) {
  1632. tp_inst._updateDateTime(inst);
  1633. return tp_inst.$input.val();
  1634. }
  1635. return this._base_formatDate(inst);
  1636. };
  1637. /*
  1638. * override options setter to add time to maxDate(Time) and minDate(Time). MaxDate
  1639. */
  1640. $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
  1641. $.datepicker._optionDatepicker = function (target, name, value) {
  1642. var inst = this._getInst(target),
  1643. name_clone;
  1644. if (!inst) {
  1645. return null;
  1646. }
  1647. var tp_inst = this._get(inst, 'timepicker');
  1648. if (tp_inst) {
  1649. var min = null,
  1650. max = null,
  1651. onselect = null,
  1652. overrides = tp_inst._defaults.evnts,
  1653. fns = {},
  1654. prop,
  1655. ret,
  1656. oldVal,
  1657. $target;
  1658. if (typeof name === 'string') { // if min/max was set with the string
  1659. if (name === 'minDate' || name === 'minDateTime') {
  1660. min = value;
  1661. } else if (name === 'maxDate' || name === 'maxDateTime') {
  1662. max = value;
  1663. } else if (name === 'onSelect') {
  1664. onselect = value;
  1665. } else if (overrides.hasOwnProperty(name)) {
  1666. if (typeof (value) === 'undefined') {
  1667. return overrides[name];
  1668. }
  1669. fns[name] = value;
  1670. name_clone = {}; //empty results in exiting function after overrides updated
  1671. }
  1672. } else if (typeof name === 'object') { //if min/max was set with the JSON
  1673. if (name.minDate) {
  1674. min = name.minDate;
  1675. } else if (name.minDateTime) {
  1676. min = name.minDateTime;
  1677. } else if (name.maxDate) {
  1678. max = name.maxDate;
  1679. } else if (name.maxDateTime) {
  1680. max = name.maxDateTime;
  1681. }
  1682. for (prop in overrides) {
  1683. if (overrides.hasOwnProperty(prop) && name[prop]) {
  1684. fns[prop] = name[prop];
  1685. }
  1686. }
  1687. }
  1688. for (prop in fns) {
  1689. if (fns.hasOwnProperty(prop)) {
  1690. overrides[prop] = fns[prop];
  1691. if (!name_clone) { name_clone = $.extend({}, name); }
  1692. delete name_clone[prop];
  1693. }
  1694. }
  1695. if (name_clone && isEmptyObject(name_clone)) { return; }
  1696. if (min) { //if min was set
  1697. if (min === 0) {
  1698. min = new Date();
  1699. } else {
  1700. min = new Date(min);
  1701. }
  1702. tp_inst._defaults.minDate = min;
  1703. tp_inst._defaults.minDateTime = min;
  1704. } else if (max) { //if max was set
  1705. if (max === 0) {
  1706. max = new Date();
  1707. } else {
  1708. max = new Date(max);
  1709. }
  1710. tp_inst._defaults.maxDate = max;
  1711. tp_inst._defaults.maxDateTime = max;
  1712. } else if (onselect) {
  1713. tp_inst._defaults.onSelect = onselect;
  1714. }
  1715. // Datepicker will override our date when we call _base_optionDatepicker when
  1716. // calling minDate/maxDate, so we will first grab the value, call
  1717. // _base_optionDatepicker, then set our value back.
  1718. if(min || max){
  1719. $target = $(target);
  1720. oldVal = $target.datetimepicker('getDate');
  1721. ret = this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
  1722. $target.datetimepicker('setDate', oldVal);
  1723. return ret;
  1724. }
  1725. }
  1726. if (value === undefined) {
  1727. return this._base_optionDatepicker.call($.datepicker, target, name);
  1728. }
  1729. return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
  1730. };
  1731. /*
  1732. * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype,
  1733. * it will return false for all objects
  1734. */
  1735. var isEmptyObject = function (obj) {
  1736. var prop;
  1737. for (prop in obj) {
  1738. if (obj.hasOwnProperty(prop)) {
  1739. return false;
  1740. }
  1741. }
  1742. return true;
  1743. };
  1744. /*
  1745. * jQuery extend now ignores nulls!
  1746. */
  1747. var extendRemove = function (target, props) {
  1748. $.extend(target, props);
  1749. for (var name in props) {
  1750. if (props[name] === null || props[name] === undefined) {
  1751. target[name] = props[name];
  1752. }
  1753. }
  1754. return target;
  1755. };
  1756. /*
  1757. * Determine by the time format which units are supported
  1758. * Returns an object of booleans for each unit
  1759. */
  1760. var detectSupport = function (timeFormat) {
  1761. var tf = timeFormat.replace(/'.*?'/g, '').toLowerCase(), // removes literals
  1762. isIn = function (f, t) { // does the format contain the token?
  1763. return f.indexOf(t) !== -1 ? true : false;
  1764. };
  1765. return {
  1766. hour: isIn(tf, 'h'),
  1767. minute: isIn(tf, 'm'),
  1768. second: isIn(tf, 's'),
  1769. millisec: isIn(tf, 'l'),
  1770. microsec: isIn(tf, 'c'),
  1771. timezone: isIn(tf, 'z'),
  1772. ampm: isIn(tf, 't') && isIn(timeFormat, 'h'),
  1773. iso8601: isIn(timeFormat, 'Z')
  1774. };
  1775. };
  1776. /*
  1777. * Converts 24 hour format into 12 hour
  1778. * Returns 12 hour without leading 0
  1779. */
  1780. var convert24to12 = function (hour) {
  1781. hour %= 12;
  1782. if (hour === 0) {
  1783. hour = 12;
  1784. }
  1785. return String(hour);
  1786. };
  1787. var computeEffectiveSetting = function (settings, property) {
  1788. return settings && settings[property] ? settings[property] : $.timepicker._defaults[property];
  1789. };
  1790. /*
  1791. * Splits datetime string into date and time substrings.
  1792. * Throws exception when date can't be parsed
  1793. * Returns {dateString: dateString, timeString: timeString}
  1794. */
  1795. var splitDateTime = function (dateTimeString, timeSettings) {
  1796. // The idea is to get the number separator occurrences in datetime and the time format requested (since time has
  1797. // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
  1798. var separator = computeEffectiveSetting(timeSettings, 'separator'),
  1799. format = computeEffectiveSetting(timeSettings, 'timeFormat'),
  1800. timeParts = format.split(separator), // how many occurrences of separator may be in our format?
  1801. timePartsLen = timeParts.length,
  1802. allParts = dateTimeString.split(separator),
  1803. allPartsLen = allParts.length;
  1804. if (allPartsLen > 1) {
  1805. return {
  1806. dateString: allParts.splice(0, allPartsLen - timePartsLen).join(separator),
  1807. timeString: allParts.splice(0, timePartsLen).join(separator)
  1808. };
  1809. }
  1810. return {
  1811. dateString: dateTimeString,
  1812. timeString: ''
  1813. };
  1814. };
  1815. /*
  1816. * Internal function to parse datetime interval
  1817. * Returns: {date: Date, timeObj: Object}, where
  1818. * date - parsed date without time (type Date)
  1819. * timeObj = {hour: , minute: , second: , millisec: , microsec: } - parsed time. Optional
  1820. */
  1821. var parseDateTimeInternal = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
  1822. var date,
  1823. parts,
  1824. parsedTime;
  1825. parts = splitDateTime(dateTimeString, timeSettings);
  1826. date = $.datepicker._base_parseDate(dateFormat, parts.dateString, dateSettings);
  1827. if (parts.timeString === '') {
  1828. return {
  1829. date: date
  1830. };
  1831. }
  1832. parsedTime = $.datepicker.parseTime(timeFormat, parts.timeString, timeSettings);
  1833. if (!parsedTime) {
  1834. throw 'Wrong time format';
  1835. }
  1836. return {
  1837. date: date,
  1838. timeObj: parsedTime
  1839. };
  1840. };
  1841. /*
  1842. * Internal function to set timezone_select to the local timezone
  1843. */
  1844. var selectLocalTimezone = function (tp_inst, date) {
  1845. if (tp_inst && tp_inst.timezone_select) {
  1846. var now = date || new Date();
  1847. tp_inst.timezone_select.val(-now.getTimezoneOffset());
  1848. }
  1849. };
  1850. /*
  1851. * Create a Singleton Instance
  1852. */
  1853. $.timepicker = new Timepicker();
  1854. /**
  1855. * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
  1856. * @param {number} tzMinutes if not a number, less than -720 (-1200), or greater than 840 (+1400) this value is returned
  1857. * @param {boolean} iso8601 if true formats in accordance to iso8601 "+12:45"
  1858. * @return {string}
  1859. */
  1860. $.timepicker.timezoneOffsetString = function (tzMinutes, iso8601) {
  1861. if (isNaN(tzMinutes) || tzMinutes > 840 || tzMinutes < -720) {
  1862. return tzMinutes;
  1863. }
  1864. var off = tzMinutes,
  1865. minutes = off % 60,
  1866. hours = (off - minutes) / 60,
  1867. iso = iso8601 ? ':' : '',
  1868. tz = (off >= 0 ? '+' : '-') + ('0' + Math.abs(hours)).slice(-2) + iso + ('0' + Math.abs(minutes)).slice(-2);
  1869. if (tz === '+00:00') {
  1870. return 'Z';
  1871. }
  1872. return tz;
  1873. };
  1874. /**
  1875. * Get the number in minutes that represents a timezone string
  1876. * @param {string} tzString formatted like "+0500", "-1245", "Z"
  1877. * @return {number} the offset minutes or the original string if it doesn't match expectations
  1878. */
  1879. $.timepicker.timezoneOffsetNumber = function (tzString) {
  1880. var normalized = tzString.toString().replace(':', ''); // excuse any iso8601, end up with "+1245"
  1881. if (normalized.toUpperCase() === 'Z') { // if iso8601 with Z, its 0 minute offset
  1882. return 0;
  1883. }
  1884. if (!/^(\-|\+)\d{4}$/.test(normalized)) { // possibly a user defined tz, so just give it back
  1885. return tzString;
  1886. }
  1887. return ((normalized.substr(0, 1) === '-' ? -1 : 1) * // plus or minus
  1888. ((parseInt(normalized.substr(1, 2), 10) * 60) + // hours (converted to minutes)
  1889. parseInt(normalized.substr(3, 2), 10))); // minutes
  1890. };
  1891. /**
  1892. * No way to set timezone in js Date, so we must adjust the minutes to compensate. (think setDate, getDate)
  1893. * @param {Date} date
  1894. * @param {string} toTimezone formatted like "+0500", "-1245"
  1895. * @return {Date}
  1896. */
  1897. $.timepicker.timezoneAdjust = function (date, toTimezone) {
  1898. var toTz = $.timepicker.timezoneOffsetNumber(toTimezone);
  1899. if (!isNaN(toTz)) {
  1900. date.setMinutes(date.getMinutes() + -date.getTimezoneOffset() - toTz);
  1901. }
  1902. return date;
  1903. };
  1904. /**
  1905. * Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to
  1906. * enforce date range limits.
  1907. * n.b. The input value must be correctly formatted (reformatting is not supported)
  1908. * @param {Element} startTime
  1909. * @param {Element} endTime
  1910. * @param {Object} options Options for the timepicker() call
  1911. * @return {jQuery}
  1912. */
  1913. $.timepicker.timeRange = function (startTime, endTime, options) {
  1914. return $.timepicker.handleRange('timepicker', startTime, endTime, options);
  1915. };
  1916. /**
  1917. * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to
  1918. * enforce date range limits.
  1919. * @param {Element} startTime
  1920. * @param {Element} endTime
  1921. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1922. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1923. * @param {string} method Can be used to specify the type of picker to be added
  1924. * @return {jQuery}
  1925. */
  1926. $.timepicker.datetimeRange = function (startTime, endTime, options) {
  1927. $.timepicker.handleRange('datetimepicker', startTime, endTime, options);
  1928. };
  1929. /**
  1930. * Calls `datepicker` on the `startTime` and `endTime` elements, and configures them to
  1931. * enforce date range limits.
  1932. * @param {Element} startTime
  1933. * @param {Element} endTime
  1934. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1935. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1936. * @return {jQuery}
  1937. */
  1938. $.timepicker.dateRange = function (startTime, endTime, options) {
  1939. $.timepicker.handleRange('datepicker', startTime, endTime, options);
  1940. };
  1941. /**
  1942. * Calls `method` on the `startTime` and `endTime` elements, and configures them to
  1943. * enforce date range limits.
  1944. * @param {string} method Can be used to specify the type of picker to be added
  1945. * @param {Element} startTime
  1946. * @param {Element} endTime
  1947. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1948. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1949. * @return {jQuery}
  1950. */
  1951. $.timepicker.handleRange = function (method, startTime, endTime, options) {
  1952. options = $.extend({}, {
  1953. minInterval: 0, // min allowed interval in milliseconds
  1954. maxInterval: 0, // max allowed interval in milliseconds
  1955. start: {}, // options for start picker
  1956. end: {} // options for end picker
  1957. }, options);
  1958. // for the mean time this fixes an issue with calling getDate with timepicker()
  1959. var timeOnly = false;
  1960. if(method === 'timepicker'){
  1961. timeOnly = true;
  1962. method = 'datetimepicker';
  1963. }
  1964. function checkDates(changed, other) {
  1965. var startdt = startTime[method]('getDate'),
  1966. enddt = endTime[method]('getDate'),
  1967. changeddt = changed[method]('getDate');
  1968. if (startdt !== null) {
  1969. var minDate = new Date(startdt.getTime()),
  1970. maxDate = new Date(startdt.getTime());
  1971. minDate.setMilliseconds(minDate.getMilliseconds() + options.minInterval);
  1972. maxDate.setMilliseconds(maxDate.getMilliseconds() + options.maxInterval);
  1973. if (options.minInterval > 0 && minDate > enddt) { // minInterval check
  1974. endTime[method]('setDate', minDate);
  1975. }
  1976. else if (options.maxInterval > 0 && maxDate < enddt) { // max interval check
  1977. endTime[method]('setDate', maxDate);
  1978. }
  1979. else if (startdt > enddt) {
  1980. other[method]('setDate', changeddt);
  1981. }
  1982. }
  1983. }
  1984. function selected(changed, other, option) {
  1985. if (!changed.val()) {
  1986. return;
  1987. }
  1988. var date = changed[method].call(changed, 'getDate');
  1989. if (date !== null && options.minInterval > 0) {
  1990. if (option === 'minDate') {
  1991. date.setMilliseconds(date.getMilliseconds() + options.minInterval);
  1992. }
  1993. if (option === 'maxDate') {
  1994. date.setMilliseconds(date.getMilliseconds() - options.minInterval);
  1995. }
  1996. }
  1997. if (date.getTime) {
  1998. other[method].call(other, 'option', option, date);
  1999. }
  2000. }
  2001. $.fn[method].call(startTime, $.extend({
  2002. timeOnly: timeOnly,
  2003. onClose: function (dateText, inst) {
  2004. checkDates($(this), endTime);
  2005. },
  2006. onSelect: function (selectedDateTime) {
  2007. selected($(this), endTime, 'minDate');
  2008. }
  2009. }, options, options.start));
  2010. $.fn[method].call(endTime, $.extend({
  2011. timeOnly: timeOnly,
  2012. onClose: function (dateText, inst) {
  2013. checkDates($(this), startTime);
  2014. },
  2015. onSelect: function (selectedDateTime) {
  2016. selected($(this), startTime, 'maxDate');
  2017. }
  2018. }, options, options.end));
  2019. checkDates(startTime, endTime);
  2020. selected(startTime, endTime, 'minDate');
  2021. selected(endTime, startTime, 'maxDate');
  2022. return $([startTime.get(0), endTime.get(0)]);
  2023. };
  2024. /**
  2025. * Log error or data to the console during error or debugging
  2026. * @param {Object} err pass any type object to log to the console during error or debugging
  2027. * @return {void}
  2028. */
  2029. $.timepicker.log = function () {
  2030. if (window.console) {
  2031. window.console.log.apply(window.console, Array.prototype.slice.call(arguments));
  2032. }
  2033. };
  2034. /*
  2035. * Add util object to allow access to private methods for testability.
  2036. */
  2037. $.timepicker._util = {
  2038. _extendRemove: extendRemove,
  2039. _isEmptyObject: isEmptyObject,
  2040. _convert24to12: convert24to12,
  2041. _detectSupport: detectSupport,
  2042. _selectLocalTimezone: selectLocalTimezone,
  2043. _computeEffectiveSetting: computeEffectiveSetting,
  2044. _splitDateTime: splitDateTime,
  2045. _parseDateTimeInternal: parseDateTimeInternal
  2046. };
  2047. /*
  2048. * Microsecond support
  2049. */
  2050. if (!Date.prototype.getMicroseconds) {
  2051. Date.prototype.microseconds = 0;
  2052. Date.prototype.getMicroseconds = function () { return this.microseconds; };
  2053. Date.prototype.setMicroseconds = function (m) {
  2054. this.setMilliseconds(this.getMilliseconds() + Math.floor(m / 1000));
  2055. this.microseconds = m % 1000;
  2056. return this;
  2057. };
  2058. }
  2059. /*
  2060. * Keep up with the version
  2061. */
  2062. $.timepicker.version = "1.6.1";
  2063. }));