jquery-ui-timepicker-addon.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245
  1. /*! jQuery Timepicker Addon - v1.5.5 - 2015-05-24
  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.5.5"
  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) + '"></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');
  486. if (this.inst !== null) {
  487. var timeDefined = this.timeDefined;
  488. this._onTimeChange();
  489. this.timeDefined = timeDefined;
  490. }
  491. // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
  492. if (this._defaults.addSliderAccess) {
  493. var sliderAccessArgs = this._defaults.sliderAccessArgs,
  494. rtl = this._defaults.isRTL;
  495. sliderAccessArgs.isRTL = rtl;
  496. setTimeout(function () { // fix for inline mode
  497. if ($tp.find('.ui-slider-access').length === 0) {
  498. $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
  499. // fix any grids since sliders are shorter
  500. var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true);
  501. if (sliderAccessWidth) {
  502. $tp.find('table:visible').each(function () {
  503. var $g = $(this),
  504. oldWidth = $g.outerWidth(),
  505. oldMarginLeft = $g.css(rtl ? 'marginRight' : 'marginLeft').toString().replace('%', ''),
  506. newWidth = oldWidth - sliderAccessWidth,
  507. newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%',
  508. css = { width: newWidth, marginRight: 0, marginLeft: 0 };
  509. css[rtl ? 'marginRight' : 'marginLeft'] = newMarginLeft;
  510. $g.css(css);
  511. });
  512. }
  513. }
  514. }, 10);
  515. }
  516. // end slideAccess integration
  517. tp_inst._limitMinMaxDateTime(this.inst, true);
  518. }
  519. },
  520. /*
  521. * This function tries to limit the ability to go outside the
  522. * min/max date range
  523. */
  524. _limitMinMaxDateTime: function (dp_inst, adjustSliders) {
  525. var o = this._defaults,
  526. dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
  527. if (!this._defaults.showTimepicker) {
  528. return;
  529. } // No time so nothing to check here
  530. if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) {
  531. var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
  532. minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
  533. if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null || this.microsecMinOriginal === null) {
  534. this.hourMinOriginal = o.hourMin;
  535. this.minuteMinOriginal = o.minuteMin;
  536. this.secondMinOriginal = o.secondMin;
  537. this.millisecMinOriginal = o.millisecMin;
  538. this.microsecMinOriginal = o.microsecMin;
  539. }
  540. if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() === dp_date.getTime()) {
  541. this._defaults.hourMin = minDateTime.getHours();
  542. if (this.hour <= this._defaults.hourMin) {
  543. this.hour = this._defaults.hourMin;
  544. this._defaults.minuteMin = minDateTime.getMinutes();
  545. if (this.minute <= this._defaults.minuteMin) {
  546. this.minute = this._defaults.minuteMin;
  547. this._defaults.secondMin = minDateTime.getSeconds();
  548. if (this.second <= this._defaults.secondMin) {
  549. this.second = this._defaults.secondMin;
  550. this._defaults.millisecMin = minDateTime.getMilliseconds();
  551. if (this.millisec <= this._defaults.millisecMin) {
  552. this.millisec = this._defaults.millisecMin;
  553. this._defaults.microsecMin = minDateTime.getMicroseconds();
  554. } else {
  555. if (this.microsec < this._defaults.microsecMin) {
  556. this.microsec = this._defaults.microsecMin;
  557. }
  558. this._defaults.microsecMin = this.microsecMinOriginal;
  559. }
  560. } else {
  561. this._defaults.millisecMin = this.millisecMinOriginal;
  562. this._defaults.microsecMin = this.microsecMinOriginal;
  563. }
  564. } else {
  565. this._defaults.secondMin = this.secondMinOriginal;
  566. this._defaults.millisecMin = this.millisecMinOriginal;
  567. this._defaults.microsecMin = this.microsecMinOriginal;
  568. }
  569. } else {
  570. this._defaults.minuteMin = this.minuteMinOriginal;
  571. this._defaults.secondMin = this.secondMinOriginal;
  572. this._defaults.millisecMin = this.millisecMinOriginal;
  573. this._defaults.microsecMin = this.microsecMinOriginal;
  574. }
  575. } else {
  576. this._defaults.hourMin = this.hourMinOriginal;
  577. this._defaults.minuteMin = this.minuteMinOriginal;
  578. this._defaults.secondMin = this.secondMinOriginal;
  579. this._defaults.millisecMin = this.millisecMinOriginal;
  580. this._defaults.microsecMin = this.microsecMinOriginal;
  581. }
  582. }
  583. if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) {
  584. var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
  585. maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
  586. if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null || this.millisecMaxOriginal === null) {
  587. this.hourMaxOriginal = o.hourMax;
  588. this.minuteMaxOriginal = o.minuteMax;
  589. this.secondMaxOriginal = o.secondMax;
  590. this.millisecMaxOriginal = o.millisecMax;
  591. this.microsecMaxOriginal = o.microsecMax;
  592. }
  593. if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() === dp_date.getTime()) {
  594. this._defaults.hourMax = maxDateTime.getHours();
  595. if (this.hour >= this._defaults.hourMax) {
  596. this.hour = this._defaults.hourMax;
  597. this._defaults.minuteMax = maxDateTime.getMinutes();
  598. if (this.minute >= this._defaults.minuteMax) {
  599. this.minute = this._defaults.minuteMax;
  600. this._defaults.secondMax = maxDateTime.getSeconds();
  601. if (this.second >= this._defaults.secondMax) {
  602. this.second = this._defaults.secondMax;
  603. this._defaults.millisecMax = maxDateTime.getMilliseconds();
  604. if (this.millisec >= this._defaults.millisecMax) {
  605. this.millisec = this._defaults.millisecMax;
  606. this._defaults.microsecMax = maxDateTime.getMicroseconds();
  607. } else {
  608. if (this.microsec > this._defaults.microsecMax) {
  609. this.microsec = this._defaults.microsecMax;
  610. }
  611. this._defaults.microsecMax = this.microsecMaxOriginal;
  612. }
  613. } else {
  614. this._defaults.millisecMax = this.millisecMaxOriginal;
  615. this._defaults.microsecMax = this.microsecMaxOriginal;
  616. }
  617. } else {
  618. this._defaults.secondMax = this.secondMaxOriginal;
  619. this._defaults.millisecMax = this.millisecMaxOriginal;
  620. this._defaults.microsecMax = this.microsecMaxOriginal;
  621. }
  622. } else {
  623. this._defaults.minuteMax = this.minuteMaxOriginal;
  624. this._defaults.secondMax = this.secondMaxOriginal;
  625. this._defaults.millisecMax = this.millisecMaxOriginal;
  626. this._defaults.microsecMax = this.microsecMaxOriginal;
  627. }
  628. } else {
  629. this._defaults.hourMax = this.hourMaxOriginal;
  630. this._defaults.minuteMax = this.minuteMaxOriginal;
  631. this._defaults.secondMax = this.secondMaxOriginal;
  632. this._defaults.millisecMax = this.millisecMaxOriginal;
  633. this._defaults.microsecMax = this.microsecMaxOriginal;
  634. }
  635. }
  636. if (dp_inst.settings.minTime!==null) {
  637. var tempMinTime=new Date("01/01/1970 " + dp_inst.settings.minTime);
  638. if (this.hour<tempMinTime.getHours()) {
  639. this.hour=this._defaults.hourMin=tempMinTime.getHours();
  640. this.minute=this._defaults.minuteMin=tempMinTime.getMinutes();
  641. } else if (this.hour===tempMinTime.getHours() && this.minute<tempMinTime.getMinutes()) {
  642. this.minute=this._defaults.minuteMin=tempMinTime.getMinutes();
  643. } else {
  644. if (this._defaults.hourMin<tempMinTime.getHours()) {
  645. this._defaults.hourMin=tempMinTime.getHours();
  646. this._defaults.minuteMin=tempMinTime.getMinutes();
  647. } else if (this._defaults.hourMin===tempMinTime.getHours()===this.hour && this._defaults.minuteMin<tempMinTime.getMinutes()) {
  648. this._defaults.minuteMin=tempMinTime.getMinutes();
  649. } else {
  650. this._defaults.minuteMin=0;
  651. }
  652. }
  653. }
  654. if (dp_inst.settings.maxTime!==null) {
  655. var tempMaxTime=new Date("01/01/1970 " + dp_inst.settings.maxTime);
  656. if (this.hour>tempMaxTime.getHours()) {
  657. this.hour=this._defaults.hourMax=tempMaxTime.getHours();
  658. this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
  659. } else if (this.hour===tempMaxTime.getHours() && this.minute>tempMaxTime.getMinutes()) {
  660. this.minute=this._defaults.minuteMax=tempMaxTime.getMinutes();
  661. } else {
  662. if (this._defaults.hourMax>tempMaxTime.getHours()) {
  663. this._defaults.hourMax=tempMaxTime.getHours();
  664. this._defaults.minuteMax=tempMaxTime.getMinutes();
  665. } else if (this._defaults.hourMax===tempMaxTime.getHours()===this.hour && this._defaults.minuteMax>tempMaxTime.getMinutes()) {
  666. this._defaults.minuteMax=tempMaxTime.getMinutes();
  667. } else {
  668. this._defaults.minuteMax=59;
  669. }
  670. }
  671. }
  672. if (adjustSliders !== undefined && adjustSliders === true) {
  673. var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10),
  674. minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10),
  675. secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10),
  676. millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10),
  677. microsecMax = parseInt((this._defaults.microsecMax - ((this._defaults.microsecMax - this._defaults.microsecMin) % this._defaults.stepMicrosec)), 10);
  678. if (this.hour_slider) {
  679. this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax, step: this._defaults.stepHour });
  680. this.control.value(this, this.hour_slider, 'hour', this.hour - (this.hour % this._defaults.stepHour));
  681. }
  682. if (this.minute_slider) {
  683. this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax, step: this._defaults.stepMinute });
  684. this.control.value(this, this.minute_slider, 'minute', this.minute - (this.minute % this._defaults.stepMinute));
  685. }
  686. if (this.second_slider) {
  687. this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax, step: this._defaults.stepSecond });
  688. this.control.value(this, this.second_slider, 'second', this.second - (this.second % this._defaults.stepSecond));
  689. }
  690. if (this.millisec_slider) {
  691. this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax, step: this._defaults.stepMillisec });
  692. this.control.value(this, this.millisec_slider, 'millisec', this.millisec - (this.millisec % this._defaults.stepMillisec));
  693. }
  694. if (this.microsec_slider) {
  695. this.control.options(this, this.microsec_slider, 'microsec', { min: this._defaults.microsecMin, max: microsecMax, step: this._defaults.stepMicrosec });
  696. this.control.value(this, this.microsec_slider, 'microsec', this.microsec - (this.microsec % this._defaults.stepMicrosec));
  697. }
  698. }
  699. },
  700. /*
  701. * when a slider moves, set the internal time...
  702. * on time change is also called when the time is updated in the text field
  703. */
  704. _onTimeChange: function () {
  705. if (!this._defaults.showTimepicker) {
  706. return;
  707. }
  708. var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false,
  709. minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false,
  710. second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false,
  711. millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false,
  712. microsec = (this.microsec_slider) ? this.control.value(this, this.microsec_slider, 'microsec') : false,
  713. timezone = (this.timezone_select) ? this.timezone_select.val() : false,
  714. o = this._defaults,
  715. pickerTimeFormat = o.pickerTimeFormat || o.timeFormat,
  716. pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix;
  717. if (typeof(hour) === 'object') {
  718. hour = false;
  719. }
  720. if (typeof(minute) === 'object') {
  721. minute = false;
  722. }
  723. if (typeof(second) === 'object') {
  724. second = false;
  725. }
  726. if (typeof(millisec) === 'object') {
  727. millisec = false;
  728. }
  729. if (typeof(microsec) === 'object') {
  730. microsec = false;
  731. }
  732. if (typeof(timezone) === 'object') {
  733. timezone = false;
  734. }
  735. if (hour !== false) {
  736. hour = parseInt(hour, 10);
  737. }
  738. if (minute !== false) {
  739. minute = parseInt(minute, 10);
  740. }
  741. if (second !== false) {
  742. second = parseInt(second, 10);
  743. }
  744. if (millisec !== false) {
  745. millisec = parseInt(millisec, 10);
  746. }
  747. if (microsec !== false) {
  748. microsec = parseInt(microsec, 10);
  749. }
  750. if (timezone !== false) {
  751. timezone = timezone.toString();
  752. }
  753. var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
  754. // If the update was done in the input field, the input field should not be updated.
  755. // If the update was done using the sliders, update the input field.
  756. var hasChanged = (
  757. hour !== parseInt(this.hour,10) || // sliders should all be numeric
  758. minute !== parseInt(this.minute,10) ||
  759. second !== parseInt(this.second,10) ||
  760. millisec !== parseInt(this.millisec,10) ||
  761. microsec !== parseInt(this.microsec,10) ||
  762. (this.ampm.length > 0 && (hour < 12) !== ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) ||
  763. (this.timezone !== null && timezone !== this.timezone.toString()) // could be numeric or "EST" format, so use toString()
  764. );
  765. if (hasChanged) {
  766. if (hour !== false) {
  767. this.hour = hour;
  768. }
  769. if (minute !== false) {
  770. this.minute = minute;
  771. }
  772. if (second !== false) {
  773. this.second = second;
  774. }
  775. if (millisec !== false) {
  776. this.millisec = millisec;
  777. }
  778. if (microsec !== false) {
  779. this.microsec = microsec;
  780. }
  781. if (timezone !== false) {
  782. this.timezone = timezone;
  783. }
  784. if (!this.inst) {
  785. this.inst = $.datepicker._getInst(this.$input[0]);
  786. }
  787. this._limitMinMaxDateTime(this.inst, true);
  788. }
  789. if (this.support.ampm) {
  790. this.ampm = ampm;
  791. }
  792. // Updates the time within the timepicker
  793. this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o);
  794. if (this.$timeObj) {
  795. if (pickerTimeFormat === o.timeFormat) {
  796. this.$timeObj.text(this.formattedTime + pickerTimeSuffix);
  797. }
  798. else {
  799. this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
  800. }
  801. }
  802. this.timeDefined = true;
  803. if (hasChanged) {
  804. this._updateDateTime();
  805. //this.$input.focus(); // may automatically open the picker on setDate
  806. }
  807. },
  808. /*
  809. * call custom onSelect.
  810. * bind to sliders slidestop, and grid click.
  811. */
  812. _onSelectHandler: function () {
  813. var onSelect = this._defaults.onSelect || this.inst.settings.onSelect;
  814. var inputEl = this.$input ? this.$input[0] : null;
  815. if (onSelect && inputEl) {
  816. onSelect.apply(inputEl, [this.formattedDateTime, this]);
  817. }
  818. },
  819. /*
  820. * update our input with the new date time..
  821. */
  822. _updateDateTime: function (dp_inst) {
  823. dp_inst = this.inst || dp_inst;
  824. var dtTmp = (dp_inst.currentYear > 0?
  825. new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay) :
  826. new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
  827. dt = $.datepicker._daylightSavingAdjust(dtTmp),
  828. //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
  829. //dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.currentYear, dp_inst.currentMonth, dp_inst.currentDay)),
  830. dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
  831. formatCfg = $.datepicker._getFormatConfig(dp_inst),
  832. timeAvailable = dt !== null && this.timeDefined;
  833. this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
  834. var formattedDateTime = this.formattedDate;
  835. // if a slider was changed but datepicker doesn't have a value yet, set it
  836. if (dp_inst.lastVal === "") {
  837. dp_inst.currentYear = dp_inst.selectedYear;
  838. dp_inst.currentMonth = dp_inst.selectedMonth;
  839. dp_inst.currentDay = dp_inst.selectedDay;
  840. }
  841. /*
  842. * remove following lines to force every changes in date picker to change the input value
  843. * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker.
  844. * If the user manually empty the value in the input field, the date picker will never change selected value.
  845. */
  846. //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) {
  847. // return;
  848. //}
  849. if (this._defaults.timeOnly === true && this._defaults.timeOnlyShowDate === false) {
  850. formattedDateTime = this.formattedTime;
  851. } else if ((this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) || (this._defaults.timeOnly === true && this._defaults.timeOnlyShowDate === true)) {
  852. formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
  853. }
  854. this.formattedDateTime = formattedDateTime;
  855. if (!this._defaults.showTimepicker) {
  856. this.$input.val(this.formattedDate);
  857. } else if (this.$altInput && this._defaults.timeOnly === false && this._defaults.altFieldTimeOnly === true) {
  858. this.$altInput.val(this.formattedTime);
  859. this.$input.val(this.formattedDate);
  860. } else if (this.$altInput) {
  861. this.$input.val(formattedDateTime);
  862. var altFormattedDateTime = '',
  863. altSeparator = this._defaults.altSeparator !== null ? this._defaults.altSeparator : this._defaults.separator,
  864. altTimeSuffix = this._defaults.altTimeSuffix !== null ? this._defaults.altTimeSuffix : this._defaults.timeSuffix;
  865. if (!this._defaults.timeOnly) {
  866. if (this._defaults.altFormat) {
  867. altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg);
  868. }
  869. else {
  870. altFormattedDateTime = this.formattedDate;
  871. }
  872. if (altFormattedDateTime) {
  873. altFormattedDateTime += altSeparator;
  874. }
  875. }
  876. if (this._defaults.altTimeFormat !== null) {
  877. altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix;
  878. }
  879. else {
  880. altFormattedDateTime += this.formattedTime + altTimeSuffix;
  881. }
  882. this.$altInput.val(altFormattedDateTime);
  883. } else {
  884. this.$input.val(formattedDateTime);
  885. }
  886. this.$input.trigger("change");
  887. },
  888. _onFocus: function () {
  889. if (!this.$input.val() && this._defaults.defaultValue) {
  890. this.$input.val(this._defaults.defaultValue);
  891. var inst = $.datepicker._getInst(this.$input.get(0)),
  892. tp_inst = $.datepicker._get(inst, 'timepicker');
  893. if (tp_inst) {
  894. if (tp_inst._defaults.timeOnly && (inst.input.val() !== inst.lastVal)) {
  895. try {
  896. $.datepicker._updateDatepicker(inst);
  897. } catch (err) {
  898. $.timepicker.log(err);
  899. }
  900. }
  901. }
  902. }
  903. },
  904. /*
  905. * Small abstraction to control types
  906. * We can add more, just be sure to follow the pattern: create, options, value
  907. */
  908. _controls: {
  909. // slider methods
  910. slider: {
  911. create: function (tp_inst, obj, unit, val, min, max, step) {
  912. var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60
  913. return obj.prop('slide', null).slider({
  914. orientation: "horizontal",
  915. value: rtl ? val * -1 : val,
  916. min: rtl ? max * -1 : min,
  917. max: rtl ? min * -1 : max,
  918. step: step,
  919. slide: function (event, ui) {
  920. tp_inst.control.value(tp_inst, $(this), unit, rtl ? ui.value * -1 : ui.value);
  921. tp_inst._onTimeChange();
  922. },
  923. stop: function (event, ui) {
  924. tp_inst._onSelectHandler();
  925. }
  926. });
  927. },
  928. options: function (tp_inst, obj, unit, opts, val) {
  929. if (tp_inst._defaults.isRTL) {
  930. if (typeof(opts) === 'string') {
  931. if (opts === 'min' || opts === 'max') {
  932. if (val !== undefined) {
  933. return obj.slider(opts, val * -1);
  934. }
  935. return Math.abs(obj.slider(opts));
  936. }
  937. return obj.slider(opts);
  938. }
  939. var min = opts.min,
  940. max = opts.max;
  941. opts.min = opts.max = null;
  942. if (min !== undefined) {
  943. opts.max = min * -1;
  944. }
  945. if (max !== undefined) {
  946. opts.min = max * -1;
  947. }
  948. return obj.slider(opts);
  949. }
  950. if (typeof(opts) === 'string' && val !== undefined) {
  951. return obj.slider(opts, val);
  952. }
  953. return obj.slider(opts);
  954. },
  955. value: function (tp_inst, obj, unit, val) {
  956. if (tp_inst._defaults.isRTL) {
  957. if (val !== undefined) {
  958. return obj.slider('value', val * -1);
  959. }
  960. return Math.abs(obj.slider('value'));
  961. }
  962. if (val !== undefined) {
  963. return obj.slider('value', val);
  964. }
  965. return obj.slider('value');
  966. }
  967. },
  968. // select methods
  969. select: {
  970. create: function (tp_inst, obj, unit, val, min, max, step) {
  971. 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 + '">',
  972. format = tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat;
  973. for (var i = min; i <= max; i += step) {
  974. sel += '<option value="' + i + '"' + (i === val ? ' selected' : '') + '>';
  975. if (unit === 'hour') {
  976. sel += $.datepicker.formatTime($.trim(format.replace(/[^ht ]/ig, '')), {hour: i}, tp_inst._defaults);
  977. }
  978. else if (unit === 'millisec' || unit === 'microsec' || i >= 10) { sel += i; }
  979. else {sel += '0' + i.toString(); }
  980. sel += '</option>';
  981. }
  982. sel += '</select>';
  983. obj.children('select').remove();
  984. $(sel).appendTo(obj).change(function (e) {
  985. tp_inst._onTimeChange();
  986. tp_inst._onSelectHandler();
  987. tp_inst._afterInject();
  988. });
  989. return obj;
  990. },
  991. options: function (tp_inst, obj, unit, opts, val) {
  992. var o = {},
  993. $t = obj.children('select');
  994. if (typeof(opts) === 'string') {
  995. if (val === undefined) {
  996. return $t.data(opts);
  997. }
  998. o[opts] = val;
  999. }
  1000. else { o = opts; }
  1001. 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'));
  1002. },
  1003. value: function (tp_inst, obj, unit, val) {
  1004. var $t = obj.children('select');
  1005. if (val !== undefined) {
  1006. return $t.val(val);
  1007. }
  1008. return $t.val();
  1009. }
  1010. }
  1011. } // end _controls
  1012. });
  1013. $.fn.extend({
  1014. /*
  1015. * shorthand just to use timepicker.
  1016. */
  1017. timepicker: function (o) {
  1018. o = o || {};
  1019. var tmp_args = Array.prototype.slice.call(arguments);
  1020. if (typeof o === 'object') {
  1021. tmp_args[0] = $.extend(o, {
  1022. timeOnly: true
  1023. });
  1024. }
  1025. return $(this).each(function () {
  1026. $.fn.datetimepicker.apply($(this), tmp_args);
  1027. });
  1028. },
  1029. /*
  1030. * extend timepicker to datepicker
  1031. */
  1032. datetimepicker: function (o) {
  1033. o = o || {};
  1034. var tmp_args = arguments;
  1035. if (typeof(o) === 'string') {
  1036. if (o === 'getDate' || (o === 'option' && tmp_args.length === 2 && typeof (tmp_args[1]) === 'string')) {
  1037. return $.fn.datepicker.apply($(this[0]), tmp_args);
  1038. } else {
  1039. return this.each(function () {
  1040. var $t = $(this);
  1041. $t.datepicker.apply($t, tmp_args);
  1042. });
  1043. }
  1044. } else {
  1045. return this.each(function () {
  1046. var $t = $(this);
  1047. $t.datepicker($.timepicker._newInst($t, o)._defaults);
  1048. });
  1049. }
  1050. }
  1051. });
  1052. /*
  1053. * Public Utility to parse date and time
  1054. */
  1055. $.datepicker.parseDateTime = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
  1056. var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings);
  1057. if (parseRes.timeObj) {
  1058. var t = parseRes.timeObj;
  1059. parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec);
  1060. parseRes.date.setMicroseconds(t.microsec);
  1061. }
  1062. return parseRes.date;
  1063. };
  1064. /*
  1065. * Public utility to parse time
  1066. */
  1067. $.datepicker.parseTime = function (timeFormat, timeString, options) {
  1068. var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {}),
  1069. iso8601 = (timeFormat.replace(/\'.*?\'/g, '').indexOf('Z') !== -1);
  1070. // Strict parse requires the timeString to match the timeFormat exactly
  1071. var strictParse = function (f, s, o) {
  1072. // pattern for standard and localized AM/PM markers
  1073. var getPatternAmpm = function (amNames, pmNames) {
  1074. var markers = [];
  1075. if (amNames) {
  1076. $.merge(markers, amNames);
  1077. }
  1078. if (pmNames) {
  1079. $.merge(markers, pmNames);
  1080. }
  1081. markers = $.map(markers, function (val) {
  1082. return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
  1083. });
  1084. return '(' + markers.join('|') + ')?';
  1085. };
  1086. // figure out position of time elements.. cause js cant do named captures
  1087. var getFormatPositions = function (timeFormat) {
  1088. var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g),
  1089. orders = {
  1090. h: -1,
  1091. m: -1,
  1092. s: -1,
  1093. l: -1,
  1094. c: -1,
  1095. t: -1,
  1096. z: -1
  1097. };
  1098. if (finds) {
  1099. for (var i = 0; i < finds.length; i++) {
  1100. if (orders[finds[i].toString().charAt(0)] === -1) {
  1101. orders[finds[i].toString().charAt(0)] = i + 1;
  1102. }
  1103. }
  1104. }
  1105. return orders;
  1106. };
  1107. var regstr = '^' + f.toString()
  1108. .replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
  1109. var ml = match.length;
  1110. switch (match.charAt(0).toLowerCase()) {
  1111. case 'h':
  1112. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1113. case 'm':
  1114. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1115. case 's':
  1116. return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
  1117. case 'l':
  1118. return '(\\d?\\d?\\d)';
  1119. case 'c':
  1120. return '(\\d?\\d?\\d)';
  1121. case 'z':
  1122. return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
  1123. case 't':
  1124. return getPatternAmpm(o.amNames, o.pmNames);
  1125. default: // literal escaped in quotes
  1126. return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
  1127. }
  1128. })
  1129. .replace(/\s/g, '\\s?') +
  1130. o.timeSuffix + '$',
  1131. order = getFormatPositions(f),
  1132. ampm = '',
  1133. treg;
  1134. treg = s.match(new RegExp(regstr, 'i'));
  1135. var resTime = {
  1136. hour: 0,
  1137. minute: 0,
  1138. second: 0,
  1139. millisec: 0,
  1140. microsec: 0
  1141. };
  1142. if (treg) {
  1143. if (order.t !== -1) {
  1144. if (treg[order.t] === undefined || treg[order.t].length === 0) {
  1145. ampm = '';
  1146. resTime.ampm = '';
  1147. } else {
  1148. ampm = $.inArray(treg[order.t].toUpperCase(), $.map(o.amNames, function (x,i) { return x.toUpperCase(); })) !== -1 ? 'AM' : 'PM';
  1149. resTime.ampm = o[ampm === 'AM' ? 'amNames' : 'pmNames'][0];
  1150. }
  1151. }
  1152. if (order.h !== -1) {
  1153. if (ampm === 'AM' && treg[order.h] === '12') {
  1154. resTime.hour = 0; // 12am = 0 hour
  1155. } else {
  1156. if (ampm === 'PM' && treg[order.h] !== '12') {
  1157. resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12
  1158. } else {
  1159. resTime.hour = Number(treg[order.h]);
  1160. }
  1161. }
  1162. }
  1163. if (order.m !== -1) {
  1164. resTime.minute = Number(treg[order.m]);
  1165. }
  1166. if (order.s !== -1) {
  1167. resTime.second = Number(treg[order.s]);
  1168. }
  1169. if (order.l !== -1) {
  1170. resTime.millisec = Number(treg[order.l]);
  1171. }
  1172. if (order.c !== -1) {
  1173. resTime.microsec = Number(treg[order.c]);
  1174. }
  1175. if (order.z !== -1 && treg[order.z] !== undefined) {
  1176. resTime.timezone = $.timepicker.timezoneOffsetNumber(treg[order.z]);
  1177. }
  1178. return resTime;
  1179. }
  1180. return false;
  1181. };// end strictParse
  1182. // First try JS Date, if that fails, use strictParse
  1183. var looseParse = function (f, s, o) {
  1184. try {
  1185. var d = new Date('2012-01-01 ' + s);
  1186. if (isNaN(d.getTime())) {
  1187. d = new Date('2012-01-01T' + s);
  1188. if (isNaN(d.getTime())) {
  1189. d = new Date('01/01/2012 ' + s);
  1190. if (isNaN(d.getTime())) {
  1191. throw "Unable to parse time with native Date: " + s;
  1192. }
  1193. }
  1194. }
  1195. return {
  1196. hour: d.getHours(),
  1197. minute: d.getMinutes(),
  1198. second: d.getSeconds(),
  1199. millisec: d.getMilliseconds(),
  1200. microsec: d.getMicroseconds(),
  1201. timezone: d.getTimezoneOffset() * -1
  1202. };
  1203. }
  1204. catch (err) {
  1205. try {
  1206. return strictParse(f, s, o);
  1207. }
  1208. catch (err2) {
  1209. $.timepicker.log("Unable to parse \ntimeString: " + s + "\ntimeFormat: " + f);
  1210. }
  1211. }
  1212. return false;
  1213. }; // end looseParse
  1214. if (typeof o.parse === "function") {
  1215. return o.parse(timeFormat, timeString, o);
  1216. }
  1217. if (o.parse === 'loose') {
  1218. return looseParse(timeFormat, timeString, o);
  1219. }
  1220. return strictParse(timeFormat, timeString, o);
  1221. };
  1222. /**
  1223. * Public utility to format the time
  1224. * @param {string} format format of the time
  1225. * @param {Object} time Object not a Date for timezones
  1226. * @param {Object} [options] essentially the regional[].. amNames, pmNames, ampm
  1227. * @returns {string} the formatted time
  1228. */
  1229. $.datepicker.formatTime = function (format, time, options) {
  1230. options = options || {};
  1231. options = $.extend({}, $.timepicker._defaults, options);
  1232. time = $.extend({
  1233. hour: 0,
  1234. minute: 0,
  1235. second: 0,
  1236. millisec: 0,
  1237. microsec: 0,
  1238. timezone: null
  1239. }, time);
  1240. var tmptime = format,
  1241. ampmName = options.amNames[0],
  1242. hour = parseInt(time.hour, 10);
  1243. if (hour > 11) {
  1244. ampmName = options.pmNames[0];
  1245. }
  1246. tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
  1247. switch (match) {
  1248. case 'HH':
  1249. return ('0' + hour).slice(-2);
  1250. case 'H':
  1251. return hour;
  1252. case 'hh':
  1253. return ('0' + convert24to12(hour)).slice(-2);
  1254. case 'h':
  1255. return convert24to12(hour);
  1256. case 'mm':
  1257. return ('0' + time.minute).slice(-2);
  1258. case 'm':
  1259. return time.minute;
  1260. case 'ss':
  1261. return ('0' + time.second).slice(-2);
  1262. case 's':
  1263. return time.second;
  1264. case 'l':
  1265. return ('00' + time.millisec).slice(-3);
  1266. case 'c':
  1267. return ('00' + time.microsec).slice(-3);
  1268. case 'z':
  1269. return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, false);
  1270. case 'Z':
  1271. return $.timepicker.timezoneOffsetString(time.timezone === null ? options.timezone : time.timezone, true);
  1272. case 'T':
  1273. return ampmName.charAt(0).toUpperCase();
  1274. case 'TT':
  1275. return ampmName.toUpperCase();
  1276. case 't':
  1277. return ampmName.charAt(0).toLowerCase();
  1278. case 'tt':
  1279. return ampmName.toLowerCase();
  1280. default:
  1281. return match.replace(/'/g, "");
  1282. }
  1283. });
  1284. return tmptime;
  1285. };
  1286. /*
  1287. * the bad hack :/ override datepicker so it doesn't close on select
  1288. // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
  1289. */
  1290. $.datepicker._base_selectDate = $.datepicker._selectDate;
  1291. $.datepicker._selectDate = function (id, dateStr) {
  1292. var inst = this._getInst($(id)[0]),
  1293. tp_inst = this._get(inst, 'timepicker'),
  1294. was_inline;
  1295. if (tp_inst && inst.settings.showTimepicker) {
  1296. tp_inst._limitMinMaxDateTime(inst, true);
  1297. was_inline = inst.inline;
  1298. inst.inline = inst.stay_open = true;
  1299. //This way the onSelect handler called from calendarpicker get the full dateTime
  1300. this._base_selectDate(id, dateStr);
  1301. inst.inline = was_inline;
  1302. inst.stay_open = false;
  1303. this._notifyChange(inst);
  1304. this._updateDatepicker(inst);
  1305. } else {
  1306. this._base_selectDate(id, dateStr);
  1307. }
  1308. };
  1309. /*
  1310. * second bad hack :/ override datepicker so it triggers an event when changing the input field
  1311. * and does not redraw the datepicker on every selectDate event
  1312. */
  1313. $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
  1314. $.datepicker._updateDatepicker = function (inst) {
  1315. // don't popup the datepicker if there is another instance already opened
  1316. var input = inst.input[0];
  1317. if ($.datepicker._curInst && $.datepicker._curInst !== inst && $.datepicker._datepickerShowing && $.datepicker._lastInput !== input) {
  1318. return;
  1319. }
  1320. if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
  1321. this._base_updateDatepicker(inst);
  1322. // Reload the time control when changing something in the input text field.
  1323. var tp_inst = this._get(inst, 'timepicker');
  1324. if (tp_inst) {
  1325. tp_inst._addTimePicker(inst);
  1326. }
  1327. }
  1328. };
  1329. /*
  1330. * third bad hack :/ override datepicker so it allows spaces and colon in the input field
  1331. */
  1332. $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
  1333. $.datepicker._doKeyPress = function (event) {
  1334. var inst = $.datepicker._getInst(event.target),
  1335. tp_inst = $.datepicker._get(inst, 'timepicker');
  1336. if (tp_inst) {
  1337. if ($.datepicker._get(inst, 'constrainInput')) {
  1338. var ampm = tp_inst.support.ampm,
  1339. tz = tp_inst._defaults.showTimezone !== null ? tp_inst._defaults.showTimezone : tp_inst.support.timezone,
  1340. dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
  1341. datetimeChars = tp_inst._defaults.timeFormat.toString()
  1342. .replace(/[hms]/g, '')
  1343. .replace(/TT/g, ampm ? 'APM' : '')
  1344. .replace(/Tt/g, ampm ? 'AaPpMm' : '')
  1345. .replace(/tT/g, ampm ? 'AaPpMm' : '')
  1346. .replace(/T/g, ampm ? 'AP' : '')
  1347. .replace(/tt/g, ampm ? 'apm' : '')
  1348. .replace(/t/g, ampm ? 'ap' : '') +
  1349. " " + tp_inst._defaults.separator +
  1350. tp_inst._defaults.timeSuffix +
  1351. (tz ? tp_inst._defaults.timezoneList.join('') : '') +
  1352. (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) +
  1353. dateChars,
  1354. chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
  1355. return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
  1356. }
  1357. }
  1358. return $.datepicker._base_doKeyPress(event);
  1359. };
  1360. /*
  1361. * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField
  1362. * Update any alternate field to synchronise with the main field.
  1363. */
  1364. $.datepicker._base_updateAlternate = $.datepicker._updateAlternate;
  1365. $.datepicker._updateAlternate = function (inst) {
  1366. var tp_inst = this._get(inst, 'timepicker');
  1367. if (tp_inst) {
  1368. var altField = tp_inst._defaults.altField;
  1369. if (altField) { // update alternate field too
  1370. var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat,
  1371. date = this._getDate(inst),
  1372. formatCfg = $.datepicker._getFormatConfig(inst),
  1373. altFormattedDateTime = '',
  1374. altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator,
  1375. altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix,
  1376. altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat;
  1377. altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix;
  1378. if (!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null) {
  1379. if (tp_inst._defaults.altFormat) {
  1380. altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime;
  1381. }
  1382. else {
  1383. altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime;
  1384. }
  1385. }
  1386. $(altField).val( inst.input.val() ? altFormattedDateTime : "");
  1387. }
  1388. }
  1389. else {
  1390. $.datepicker._base_updateAlternate(inst);
  1391. }
  1392. };
  1393. /*
  1394. * Override key up event to sync manual input changes.
  1395. */
  1396. $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
  1397. $.datepicker._doKeyUp = function (event) {
  1398. var inst = $.datepicker._getInst(event.target),
  1399. tp_inst = $.datepicker._get(inst, 'timepicker');
  1400. if (tp_inst) {
  1401. if (tp_inst._defaults.timeOnly && (inst.input.val() !== inst.lastVal)) {
  1402. try {
  1403. $.datepicker._updateDatepicker(inst);
  1404. } catch (err) {
  1405. $.timepicker.log(err);
  1406. }
  1407. }
  1408. }
  1409. return $.datepicker._base_doKeyUp(event);
  1410. };
  1411. /*
  1412. * override "Today" button to also grab the time.
  1413. */
  1414. $.datepicker._base_gotoToday = $.datepicker._gotoToday;
  1415. $.datepicker._gotoToday = function (id) {
  1416. var inst = this._getInst($(id)[0]),
  1417. $dp = inst.dpDiv;
  1418. var tp_inst = this._get(inst, 'timepicker');
  1419. selectLocalTimezone(tp_inst);
  1420. var now = new Date();
  1421. this._setTime(inst, now);
  1422. this._setDate(inst, now);
  1423. this._base_gotoToday(id);
  1424. };
  1425. /*
  1426. * Disable & enable the Time in the datetimepicker
  1427. */
  1428. $.datepicker._disableTimepickerDatepicker = function (target) {
  1429. var inst = this._getInst(target);
  1430. if (!inst) {
  1431. return;
  1432. }
  1433. var tp_inst = this._get(inst, 'timepicker');
  1434. $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
  1435. if (tp_inst) {
  1436. inst.settings.showTimepicker = false;
  1437. tp_inst._defaults.showTimepicker = false;
  1438. tp_inst._updateDateTime(inst);
  1439. }
  1440. };
  1441. $.datepicker._enableTimepickerDatepicker = function (target) {
  1442. var inst = this._getInst(target);
  1443. if (!inst) {
  1444. return;
  1445. }
  1446. var tp_inst = this._get(inst, 'timepicker');
  1447. $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
  1448. if (tp_inst) {
  1449. inst.settings.showTimepicker = true;
  1450. tp_inst._defaults.showTimepicker = true;
  1451. tp_inst._addTimePicker(inst); // Could be disabled on page load
  1452. tp_inst._updateDateTime(inst);
  1453. }
  1454. };
  1455. /*
  1456. * Create our own set time function
  1457. */
  1458. $.datepicker._setTime = function (inst, date) {
  1459. var tp_inst = this._get(inst, 'timepicker');
  1460. if (tp_inst) {
  1461. var defaults = tp_inst._defaults;
  1462. // calling _setTime with no date sets time to defaults
  1463. tp_inst.hour = date ? date.getHours() : defaults.hour;
  1464. tp_inst.minute = date ? date.getMinutes() : defaults.minute;
  1465. tp_inst.second = date ? date.getSeconds() : defaults.second;
  1466. tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec;
  1467. tp_inst.microsec = date ? date.getMicroseconds() : defaults.microsec;
  1468. //check if within min/max times..
  1469. tp_inst._limitMinMaxDateTime(inst, true);
  1470. tp_inst._onTimeChange();
  1471. tp_inst._updateDateTime(inst);
  1472. }
  1473. };
  1474. /*
  1475. * Create new public method to set only time, callable as $().datepicker('setTime', date)
  1476. */
  1477. $.datepicker._setTimeDatepicker = function (target, date, withDate) {
  1478. var inst = this._getInst(target);
  1479. if (!inst) {
  1480. return;
  1481. }
  1482. var tp_inst = this._get(inst, 'timepicker');
  1483. if (tp_inst) {
  1484. this._setDateFromField(inst);
  1485. var tp_date;
  1486. if (date) {
  1487. if (typeof date === "string") {
  1488. tp_inst._parseTime(date, withDate);
  1489. tp_date = new Date();
  1490. tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
  1491. tp_date.setMicroseconds(tp_inst.microsec);
  1492. } else {
  1493. tp_date = new Date(date.getTime());
  1494. tp_date.setMicroseconds(date.getMicroseconds());
  1495. }
  1496. if (tp_date.toString() === 'Invalid Date') {
  1497. tp_date = undefined;
  1498. }
  1499. this._setTime(inst, tp_date);
  1500. }
  1501. }
  1502. };
  1503. /*
  1504. * override setDate() to allow setting time too within Date object
  1505. */
  1506. $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
  1507. $.datepicker._setDateDatepicker = function (target, _date) {
  1508. var inst = this._getInst(target);
  1509. var date = _date;
  1510. if (!inst) {
  1511. return;
  1512. }
  1513. if (typeof(_date) === 'string') {
  1514. date = new Date(_date);
  1515. if (!date.getTime()) {
  1516. this._base_setDateDatepicker.apply(this, arguments);
  1517. date = $(target).datepicker('getDate');
  1518. }
  1519. }
  1520. var tp_inst = this._get(inst, 'timepicker');
  1521. var tp_date;
  1522. if (date instanceof Date) {
  1523. tp_date = new Date(date.getTime());
  1524. tp_date.setMicroseconds(date.getMicroseconds());
  1525. } else {
  1526. tp_date = date;
  1527. }
  1528. // This is important if you are using the timezone option, javascript's Date
  1529. // object will only return the timezone offset for the current locale, so we
  1530. // adjust it accordingly. If not using timezone option this won't matter..
  1531. // If a timezone is different in tp, keep the timezone as is
  1532. if (tp_inst && tp_date) {
  1533. // look out for DST if tz wasn't specified
  1534. if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
  1535. tp_inst.timezone = tp_date.getTimezoneOffset() * -1;
  1536. }
  1537. date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
  1538. tp_date = $.timepicker.timezoneAdjust(tp_date, tp_inst.timezone);
  1539. }
  1540. this._updateDatepicker(inst);
  1541. this._base_setDateDatepicker.apply(this, arguments);
  1542. this._setTimeDatepicker(target, tp_date, true);
  1543. };
  1544. /*
  1545. * override getDate() to allow getting time too within Date object
  1546. */
  1547. $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
  1548. $.datepicker._getDateDatepicker = function (target, noDefault) {
  1549. var inst = this._getInst(target);
  1550. if (!inst) {
  1551. return;
  1552. }
  1553. var tp_inst = this._get(inst, 'timepicker');
  1554. if (tp_inst) {
  1555. // if it hasn't yet been defined, grab from field
  1556. if (inst.lastVal === undefined) {
  1557. this._setDateFromField(inst, noDefault);
  1558. }
  1559. var date = this._getDate(inst);
  1560. var currDT = $.trim((tp_inst.$altInput && tp_inst._defaults.altFieldTimeOnly) ? tp_inst.$input.val() + ' ' + tp_inst.$altInput.val() : tp_inst.$input.val());
  1561. if (date && tp_inst._parseTime(currDT, !inst.settings.timeOnly)) {
  1562. date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
  1563. date.setMicroseconds(tp_inst.microsec);
  1564. // This is important if you are using the timezone option, javascript's Date
  1565. // object will only return the timezone offset for the current locale, so we
  1566. // adjust it accordingly. If not using timezone option this won't matter..
  1567. if (tp_inst.timezone != null) {
  1568. // look out for DST if tz wasn't specified
  1569. if (!tp_inst.support.timezone && tp_inst._defaults.timezone === null) {
  1570. tp_inst.timezone = date.getTimezoneOffset() * -1;
  1571. }
  1572. date = $.timepicker.timezoneAdjust(date, tp_inst.timezone);
  1573. }
  1574. }
  1575. return date;
  1576. }
  1577. return this._base_getDateDatepicker(target, noDefault);
  1578. };
  1579. /*
  1580. * override parseDate() because UI 1.8.14 throws an error about "Extra characters"
  1581. * An option in datapicker to ignore extra format characters would be nicer.
  1582. */
  1583. $.datepicker._base_parseDate = $.datepicker.parseDate;
  1584. $.datepicker.parseDate = function (format, value, settings) {
  1585. var date;
  1586. try {
  1587. date = this._base_parseDate(format, value, settings);
  1588. } catch (err) {
  1589. // Hack! The error message ends with a colon, a space, and
  1590. // the "extra" characters. We rely on that instead of
  1591. // attempting to perfectly reproduce the parsing algorithm.
  1592. if (err.indexOf(":") >= 0) {
  1593. date = this._base_parseDate(format, value.substring(0, value.length - (err.length - err.indexOf(':') - 2)), settings);
  1594. $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format);
  1595. } else {
  1596. throw err;
  1597. }
  1598. }
  1599. return date;
  1600. };
  1601. /*
  1602. * override formatDate to set date with time to the input
  1603. */
  1604. $.datepicker._base_formatDate = $.datepicker._formatDate;
  1605. $.datepicker._formatDate = function (inst, day, month, year) {
  1606. var tp_inst = this._get(inst, 'timepicker');
  1607. if (tp_inst) {
  1608. tp_inst._updateDateTime(inst);
  1609. return tp_inst.$input.val();
  1610. }
  1611. return this._base_formatDate(inst);
  1612. };
  1613. /*
  1614. * override options setter to add time to maxDate(Time) and minDate(Time). MaxDate
  1615. */
  1616. $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
  1617. $.datepicker._optionDatepicker = function (target, name, value) {
  1618. var inst = this._getInst(target),
  1619. name_clone;
  1620. if (!inst) {
  1621. return null;
  1622. }
  1623. var tp_inst = this._get(inst, 'timepicker');
  1624. if (tp_inst) {
  1625. var min = null,
  1626. max = null,
  1627. onselect = null,
  1628. overrides = tp_inst._defaults.evnts,
  1629. fns = {},
  1630. prop,
  1631. ret,
  1632. oldVal,
  1633. $target;
  1634. if (typeof name === 'string') { // if min/max was set with the string
  1635. if (name === 'minDate' || name === 'minDateTime') {
  1636. min = value;
  1637. } else if (name === 'maxDate' || name === 'maxDateTime') {
  1638. max = value;
  1639. } else if (name === 'onSelect') {
  1640. onselect = value;
  1641. } else if (overrides.hasOwnProperty(name)) {
  1642. if (typeof (value) === 'undefined') {
  1643. return overrides[name];
  1644. }
  1645. fns[name] = value;
  1646. name_clone = {}; //empty results in exiting function after overrides updated
  1647. }
  1648. } else if (typeof name === 'object') { //if min/max was set with the JSON
  1649. if (name.minDate) {
  1650. min = name.minDate;
  1651. } else if (name.minDateTime) {
  1652. min = name.minDateTime;
  1653. } else if (name.maxDate) {
  1654. max = name.maxDate;
  1655. } else if (name.maxDateTime) {
  1656. max = name.maxDateTime;
  1657. }
  1658. for (prop in overrides) {
  1659. if (overrides.hasOwnProperty(prop) && name[prop]) {
  1660. fns[prop] = name[prop];
  1661. }
  1662. }
  1663. }
  1664. for (prop in fns) {
  1665. if (fns.hasOwnProperty(prop)) {
  1666. overrides[prop] = fns[prop];
  1667. if (!name_clone) { name_clone = $.extend({}, name); }
  1668. delete name_clone[prop];
  1669. }
  1670. }
  1671. if (name_clone && isEmptyObject(name_clone)) { return; }
  1672. if (min) { //if min was set
  1673. if (min === 0) {
  1674. min = new Date();
  1675. } else {
  1676. min = new Date(min);
  1677. }
  1678. tp_inst._defaults.minDate = min;
  1679. tp_inst._defaults.minDateTime = min;
  1680. } else if (max) { //if max was set
  1681. if (max === 0) {
  1682. max = new Date();
  1683. } else {
  1684. max = new Date(max);
  1685. }
  1686. tp_inst._defaults.maxDate = max;
  1687. tp_inst._defaults.maxDateTime = max;
  1688. } else if (onselect) {
  1689. tp_inst._defaults.onSelect = onselect;
  1690. }
  1691. // Datepicker will override our date when we call _base_optionDatepicker when
  1692. // calling minDate/maxDate, so we will first grab the value, call
  1693. // _base_optionDatepicker, then set our value back.
  1694. if(min || max){
  1695. $target = $(target);
  1696. oldVal = $target.datetimepicker('getDate');
  1697. ret = this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
  1698. $target.datetimepicker('setDate', oldVal);
  1699. return ret;
  1700. }
  1701. }
  1702. if (value === undefined) {
  1703. return this._base_optionDatepicker.call($.datepicker, target, name);
  1704. }
  1705. return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
  1706. };
  1707. /*
  1708. * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype,
  1709. * it will return false for all objects
  1710. */
  1711. var isEmptyObject = function (obj) {
  1712. var prop;
  1713. for (prop in obj) {
  1714. if (obj.hasOwnProperty(prop)) {
  1715. return false;
  1716. }
  1717. }
  1718. return true;
  1719. };
  1720. /*
  1721. * jQuery extend now ignores nulls!
  1722. */
  1723. var extendRemove = function (target, props) {
  1724. $.extend(target, props);
  1725. for (var name in props) {
  1726. if (props[name] === null || props[name] === undefined) {
  1727. target[name] = props[name];
  1728. }
  1729. }
  1730. return target;
  1731. };
  1732. /*
  1733. * Determine by the time format which units are supported
  1734. * Returns an object of booleans for each unit
  1735. */
  1736. var detectSupport = function (timeFormat) {
  1737. var tf = timeFormat.replace(/'.*?'/g, '').toLowerCase(), // removes literals
  1738. isIn = function (f, t) { // does the format contain the token?
  1739. return f.indexOf(t) !== -1 ? true : false;
  1740. };
  1741. return {
  1742. hour: isIn(tf, 'h'),
  1743. minute: isIn(tf, 'm'),
  1744. second: isIn(tf, 's'),
  1745. millisec: isIn(tf, 'l'),
  1746. microsec: isIn(tf, 'c'),
  1747. timezone: isIn(tf, 'z'),
  1748. ampm: isIn(tf, 't') && isIn(timeFormat, 'h'),
  1749. iso8601: isIn(timeFormat, 'Z')
  1750. };
  1751. };
  1752. /*
  1753. * Converts 24 hour format into 12 hour
  1754. * Returns 12 hour without leading 0
  1755. */
  1756. var convert24to12 = function (hour) {
  1757. hour %= 12;
  1758. if (hour === 0) {
  1759. hour = 12;
  1760. }
  1761. return String(hour);
  1762. };
  1763. var computeEffectiveSetting = function (settings, property) {
  1764. return settings && settings[property] ? settings[property] : $.timepicker._defaults[property];
  1765. };
  1766. /*
  1767. * Splits datetime string into date and time substrings.
  1768. * Throws exception when date can't be parsed
  1769. * Returns {dateString: dateString, timeString: timeString}
  1770. */
  1771. var splitDateTime = function (dateTimeString, timeSettings) {
  1772. // The idea is to get the number separator occurrences in datetime and the time format requested (since time has
  1773. // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split.
  1774. var separator = computeEffectiveSetting(timeSettings, 'separator'),
  1775. format = computeEffectiveSetting(timeSettings, 'timeFormat'),
  1776. timeParts = format.split(separator), // how many occurrences of separator may be in our format?
  1777. timePartsLen = timeParts.length,
  1778. allParts = dateTimeString.split(separator),
  1779. allPartsLen = allParts.length;
  1780. if (allPartsLen > 1) {
  1781. return {
  1782. dateString: allParts.splice(0, allPartsLen - timePartsLen).join(separator),
  1783. timeString: allParts.splice(0, timePartsLen).join(separator)
  1784. };
  1785. }
  1786. return {
  1787. dateString: dateTimeString,
  1788. timeString: ''
  1789. };
  1790. };
  1791. /*
  1792. * Internal function to parse datetime interval
  1793. * Returns: {date: Date, timeObj: Object}, where
  1794. * date - parsed date without time (type Date)
  1795. * timeObj = {hour: , minute: , second: , millisec: , microsec: } - parsed time. Optional
  1796. */
  1797. var parseDateTimeInternal = function (dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) {
  1798. var date,
  1799. parts,
  1800. parsedTime;
  1801. parts = splitDateTime(dateTimeString, timeSettings);
  1802. date = $.datepicker._base_parseDate(dateFormat, parts.dateString, dateSettings);
  1803. if (parts.timeString === '') {
  1804. return {
  1805. date: date
  1806. };
  1807. }
  1808. parsedTime = $.datepicker.parseTime(timeFormat, parts.timeString, timeSettings);
  1809. if (!parsedTime) {
  1810. throw 'Wrong time format';
  1811. }
  1812. return {
  1813. date: date,
  1814. timeObj: parsedTime
  1815. };
  1816. };
  1817. /*
  1818. * Internal function to set timezone_select to the local timezone
  1819. */
  1820. var selectLocalTimezone = function (tp_inst, date) {
  1821. if (tp_inst && tp_inst.timezone_select) {
  1822. var now = date || new Date();
  1823. tp_inst.timezone_select.val(-now.getTimezoneOffset());
  1824. }
  1825. };
  1826. /*
  1827. * Create a Singleton Instance
  1828. */
  1829. $.timepicker = new Timepicker();
  1830. /**
  1831. * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5)
  1832. * @param {number} tzMinutes if not a number, less than -720 (-1200), or greater than 840 (+1400) this value is returned
  1833. * @param {boolean} iso8601 if true formats in accordance to iso8601 "+12:45"
  1834. * @return {string}
  1835. */
  1836. $.timepicker.timezoneOffsetString = function (tzMinutes, iso8601) {
  1837. if (isNaN(tzMinutes) || tzMinutes > 840 || tzMinutes < -720) {
  1838. return tzMinutes;
  1839. }
  1840. var off = tzMinutes,
  1841. minutes = off % 60,
  1842. hours = (off - minutes) / 60,
  1843. iso = iso8601 ? ':' : '',
  1844. tz = (off >= 0 ? '+' : '-') + ('0' + Math.abs(hours)).slice(-2) + iso + ('0' + Math.abs(minutes)).slice(-2);
  1845. if (tz === '+00:00') {
  1846. return 'Z';
  1847. }
  1848. return tz;
  1849. };
  1850. /**
  1851. * Get the number in minutes that represents a timezone string
  1852. * @param {string} tzString formatted like "+0500", "-1245", "Z"
  1853. * @return {number} the offset minutes or the original string if it doesn't match expectations
  1854. */
  1855. $.timepicker.timezoneOffsetNumber = function (tzString) {
  1856. var normalized = tzString.toString().replace(':', ''); // excuse any iso8601, end up with "+1245"
  1857. if (normalized.toUpperCase() === 'Z') { // if iso8601 with Z, its 0 minute offset
  1858. return 0;
  1859. }
  1860. if (!/^(\-|\+)\d{4}$/.test(normalized)) { // possibly a user defined tz, so just give it back
  1861. return tzString;
  1862. }
  1863. return ((normalized.substr(0, 1) === '-' ? -1 : 1) * // plus or minus
  1864. ((parseInt(normalized.substr(1, 2), 10) * 60) + // hours (converted to minutes)
  1865. parseInt(normalized.substr(3, 2), 10))); // minutes
  1866. };
  1867. /**
  1868. * No way to set timezone in js Date, so we must adjust the minutes to compensate. (think setDate, getDate)
  1869. * @param {Date} date
  1870. * @param {string} toTimezone formatted like "+0500", "-1245"
  1871. * @return {Date}
  1872. */
  1873. $.timepicker.timezoneAdjust = function (date, toTimezone) {
  1874. var toTz = $.timepicker.timezoneOffsetNumber(toTimezone);
  1875. if (!isNaN(toTz)) {
  1876. date.setMinutes(date.getMinutes() + -date.getTimezoneOffset() - toTz);
  1877. }
  1878. return date;
  1879. };
  1880. /**
  1881. * Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to
  1882. * enforce date range limits.
  1883. * n.b. The input value must be correctly formatted (reformatting is not supported)
  1884. * @param {Element} startTime
  1885. * @param {Element} endTime
  1886. * @param {Object} options Options for the timepicker() call
  1887. * @return {jQuery}
  1888. */
  1889. $.timepicker.timeRange = function (startTime, endTime, options) {
  1890. return $.timepicker.handleRange('timepicker', startTime, endTime, options);
  1891. };
  1892. /**
  1893. * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to
  1894. * enforce date range limits.
  1895. * @param {Element} startTime
  1896. * @param {Element} endTime
  1897. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1898. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1899. * @param {string} method Can be used to specify the type of picker to be added
  1900. * @return {jQuery}
  1901. */
  1902. $.timepicker.datetimeRange = function (startTime, endTime, options) {
  1903. $.timepicker.handleRange('datetimepicker', startTime, endTime, options);
  1904. };
  1905. /**
  1906. * Calls `datepicker` on the `startTime` and `endTime` elements, and configures them to
  1907. * enforce date range limits.
  1908. * @param {Element} startTime
  1909. * @param {Element} endTime
  1910. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1911. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1912. * @return {jQuery}
  1913. */
  1914. $.timepicker.dateRange = function (startTime, endTime, options) {
  1915. $.timepicker.handleRange('datepicker', startTime, endTime, options);
  1916. };
  1917. /**
  1918. * Calls `method` on the `startTime` and `endTime` elements, and configures them to
  1919. * enforce date range limits.
  1920. * @param {string} method Can be used to specify the type of picker to be added
  1921. * @param {Element} startTime
  1922. * @param {Element} endTime
  1923. * @param {Object} options Options for the `timepicker()` call. Also supports `reformat`,
  1924. * a boolean value that can be used to reformat the input values to the `dateFormat`.
  1925. * @return {jQuery}
  1926. */
  1927. $.timepicker.handleRange = function (method, startTime, endTime, options) {
  1928. options = $.extend({}, {
  1929. minInterval: 0, // min allowed interval in milliseconds
  1930. maxInterval: 0, // max allowed interval in milliseconds
  1931. start: {}, // options for start picker
  1932. end: {} // options for end picker
  1933. }, options);
  1934. // for the mean time this fixes an issue with calling getDate with timepicker()
  1935. var timeOnly = false;
  1936. if(method === 'timepicker'){
  1937. timeOnly = true;
  1938. method = 'datetimepicker';
  1939. }
  1940. function checkDates(changed, other) {
  1941. var startdt = startTime[method]('getDate'),
  1942. enddt = endTime[method]('getDate'),
  1943. changeddt = changed[method]('getDate');
  1944. if (startdt !== null) {
  1945. var minDate = new Date(startdt.getTime()),
  1946. maxDate = new Date(startdt.getTime());
  1947. minDate.setMilliseconds(minDate.getMilliseconds() + options.minInterval);
  1948. maxDate.setMilliseconds(maxDate.getMilliseconds() + options.maxInterval);
  1949. if (options.minInterval > 0 && minDate > enddt) { // minInterval check
  1950. endTime[method]('setDate', minDate);
  1951. }
  1952. else if (options.maxInterval > 0 && maxDate < enddt) { // max interval check
  1953. endTime[method]('setDate', maxDate);
  1954. }
  1955. else if (startdt > enddt) {
  1956. other[method]('setDate', changeddt);
  1957. }
  1958. }
  1959. }
  1960. function selected(changed, other, option) {
  1961. if (!changed.val()) {
  1962. return;
  1963. }
  1964. var date = changed[method].call(changed, 'getDate');
  1965. if (date !== null && options.minInterval > 0) {
  1966. if (option === 'minDate') {
  1967. date.setMilliseconds(date.getMilliseconds() + options.minInterval);
  1968. }
  1969. if (option === 'maxDate') {
  1970. date.setMilliseconds(date.getMilliseconds() - options.minInterval);
  1971. }
  1972. }
  1973. if (date.getTime) {
  1974. other[method].call(other, 'option', option, date);
  1975. }
  1976. }
  1977. $.fn[method].call(startTime, $.extend({
  1978. timeOnly: timeOnly,
  1979. onClose: function (dateText, inst) {
  1980. checkDates($(this), endTime);
  1981. },
  1982. onSelect: function (selectedDateTime) {
  1983. selected($(this), endTime, 'minDate');
  1984. }
  1985. }, options, options.start));
  1986. $.fn[method].call(endTime, $.extend({
  1987. timeOnly: timeOnly,
  1988. onClose: function (dateText, inst) {
  1989. checkDates($(this), startTime);
  1990. },
  1991. onSelect: function (selectedDateTime) {
  1992. selected($(this), startTime, 'maxDate');
  1993. }
  1994. }, options, options.end));
  1995. checkDates(startTime, endTime);
  1996. selected(startTime, endTime, 'minDate');
  1997. selected(endTime, startTime, 'maxDate');
  1998. return $([startTime.get(0), endTime.get(0)]);
  1999. };
  2000. /**
  2001. * Log error or data to the console during error or debugging
  2002. * @param {Object} err pass any type object to log to the console during error or debugging
  2003. * @return {void}
  2004. */
  2005. $.timepicker.log = function () {
  2006. if (window.console) {
  2007. window.console.log.apply(window.console, Array.prototype.slice.call(arguments));
  2008. }
  2009. };
  2010. /*
  2011. * Add util object to allow access to private methods for testability.
  2012. */
  2013. $.timepicker._util = {
  2014. _extendRemove: extendRemove,
  2015. _isEmptyObject: isEmptyObject,
  2016. _convert24to12: convert24to12,
  2017. _detectSupport: detectSupport,
  2018. _selectLocalTimezone: selectLocalTimezone,
  2019. _computeEffectiveSetting: computeEffectiveSetting,
  2020. _splitDateTime: splitDateTime,
  2021. _parseDateTimeInternal: parseDateTimeInternal
  2022. };
  2023. /*
  2024. * Microsecond support
  2025. */
  2026. if (!Date.prototype.getMicroseconds) {
  2027. Date.prototype.microseconds = 0;
  2028. Date.prototype.getMicroseconds = function () { return this.microseconds; };
  2029. Date.prototype.setMicroseconds = function (m) {
  2030. this.setMilliseconds(this.getMilliseconds() + Math.floor(m / 1000));
  2031. this.microseconds = m % 1000;
  2032. return this;
  2033. };
  2034. }
  2035. /*
  2036. * Keep up with the version
  2037. */
  2038. $.timepicker.version = "1.5.5";
  2039. }));