|
1 | 1 | /*
|
2 | 2 | * jQuery timepicker addon
|
3 | 3 | * By: Trent Richardson [http://trentrichardson.com]
|
4 |
| - * Version 1.2 |
5 |
| - * Last Modified: 02/02/2013 |
| 4 | + * Version 1.2.1 |
| 5 | + * Last Modified: 04/06/2013 |
6 | 6 | *
|
7 | 7 | * Copyright 2013 Trent Richardson
|
8 | 8 | * You may use this project under MIT or GPL licenses.
|
|
27 | 27 | */
|
28 | 28 | $.extend($.ui, {
|
29 | 29 | timepicker: {
|
30 |
| - version: "1.2" |
| 30 | + version: "1.2.1" |
31 | 31 | }
|
32 | 32 | });
|
33 | 33 |
|
|
339 | 339 | uitem = '',
|
340 | 340 | max = {},
|
341 | 341 | gridSize = {},
|
342 |
| - size = null; |
| 342 | + size = null, |
| 343 | + i=0, |
| 344 | + l=0; |
343 | 345 |
|
344 | 346 | // Prevent displaying twice
|
345 | 347 | if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) {
|
|
348 | 350 | '<dd class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></dd>';
|
349 | 351 |
|
350 | 352 | // Create the markup
|
351 |
| - for(var i=0,l=this.units.length; i<l; i++){ |
| 353 | + for(i=0,l=this.units.length; i<l; i++){ |
352 | 354 | litem = this.units[i];
|
353 | 355 | uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
|
354 | 356 | // Added by Peter Medeiros:
|
|
397 | 399 | }
|
398 | 400 |
|
399 | 401 | // add sliders, adjust grids, add events
|
400 |
| - for(var i=0,l=tp_inst.units.length; i<l; i++){ |
| 402 | + for(i=0,l=tp_inst.units.length; i<l; i++){ |
401 | 403 | litem = tp_inst.units[i];
|
402 | 404 | uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
|
403 | 405 |
|
|
434 | 436 |
|
435 | 437 | tp_inst._onTimeChange();
|
436 | 438 | tp_inst._onSelectHandler();
|
437 |
| - }) |
438 |
| - .css({ |
| 439 | + }).css({ |
439 | 440 | cursor: 'pointer',
|
440 | 441 | width: (100 / gridSize[litem]) + '%',
|
441 | 442 | textAlign: 'center',
|
|
769 | 770 | var formattedDateTime = this.formattedDate;
|
770 | 771 |
|
771 | 772 | // if a slider was changed but datepicker doesn't have a value yet, set it
|
772 |
| - if(dp_inst.lastVal==""){ |
| 773 | + if(dp_inst.lastVal===""){ |
773 | 774 | dp_inst.currentYear=dp_inst.selectedYear;
|
774 | 775 | dp_inst.currentMonth=dp_inst.selectedMonth;
|
775 | 776 | dp_inst.currentDay=dp_inst.selectedDay;
|
|
803 | 804 | altSeparator = this._defaults.altSeparator ? this._defaults.altSeparator : this._defaults.separator,
|
804 | 805 | altTimeSuffix = this._defaults.altTimeSuffix ? this._defaults.altTimeSuffix : this._defaults.timeSuffix;
|
805 | 806 |
|
806 |
| - if (this._defaults.altFormat) altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg); |
807 |
| - else altFormattedDateTime = this.formattedDate; |
808 |
| - if (altFormattedDateTime) altFormattedDateTime += altSeparator; |
809 |
| - if (this._defaults.altTimeFormat) altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix; |
810 |
| - else altFormattedDateTime += this.formattedTime + altTimeSuffix; |
| 807 | + if (this._defaults.altFormat){ |
| 808 | + altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg); |
| 809 | + } |
| 810 | + else{ |
| 811 | + altFormattedDateTime = this.formattedDate; |
| 812 | + } |
| 813 | + |
| 814 | + if (altFormattedDateTime){ |
| 815 | + altFormattedDateTime += altSeparator; |
| 816 | + } |
| 817 | + |
| 818 | + if(this._defaults.altTimeFormat){ |
| 819 | + altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix; |
| 820 | + } |
| 821 | + else{ |
| 822 | + altFormattedDateTime += this.formattedTime + altTimeSuffix; |
| 823 | + } |
811 | 824 | this.$altInput.val(altFormattedDateTime);
|
812 | 825 | } else {
|
813 | 826 | this.$input.val(formattedDateTime);
|
|
861 | 874 | if(tp_inst._defaults.isRTL){
|
862 | 875 | if(typeof(opts) == 'string'){
|
863 | 876 | if(opts == 'min' || opts == 'max'){
|
864 |
| - if(val !== undefined) |
| 877 | + if(val !== undefined){ |
865 | 878 | return obj.slider(opts, val*-1);
|
| 879 | + } |
866 | 880 | return Math.abs(obj.slider(opts));
|
867 | 881 | }
|
868 | 882 | return obj.slider(opts);
|
869 | 883 | }
|
870 | 884 | var min = opts.min,
|
871 | 885 | max = opts.max;
|
872 | 886 | opts.min = opts.max = null;
|
873 |
| - if(min !== undefined) |
| 887 | + if(min !== undefined){ |
874 | 888 | opts.max = min * -1;
|
875 |
| - if(max !== undefined) |
| 889 | + } |
| 890 | + if(max !== undefined){ |
876 | 891 | opts.min = max * -1;
|
| 892 | + } |
877 | 893 | return obj.slider(opts);
|
878 | 894 | }
|
879 |
| - if(typeof(opts) == 'string' && val !== undefined) |
| 895 | + if(typeof(opts) == 'string' && val !== undefined){ |
880 | 896 | return obj.slider(opts, val);
|
| 897 | + } |
881 | 898 | return obj.slider(opts);
|
882 | 899 | },
|
883 | 900 | value: function(tp_inst, obj, unit, val){
|
884 | 901 | if(tp_inst._defaults.isRTL){
|
885 |
| - if(val !== undefined) |
| 902 | + if(val !== undefined){ |
886 | 903 | return obj.slider('value', val*-1);
|
| 904 | + } |
887 | 905 | return Math.abs(obj.slider('value'));
|
888 | 906 | }
|
889 |
| - if(val !== undefined) |
| 907 | + if(val !== undefined){ |
890 | 908 | return obj.slider('value', val);
|
| 909 | + } |
891 | 910 | return obj.slider('value');
|
892 | 911 | }
|
893 | 912 | },
|
894 | 913 | // select methods
|
895 | 914 | select: {
|
896 | 915 | create: function(tp_inst, obj, unit, val, min, max, step){
|
897 | 916 | var sel = '<select class="ui-timepicker-select" data-unit="'+ unit +'" data-min="'+ min +'" data-max="'+ max +'" data-step="'+ step +'">',
|
898 |
| - ul = tp_inst._defaults.timeFormat.indexOf('t') !== -1? 'toLowerCase':'toUpperCase', |
899 |
| - m = 0; |
| 917 | + format = tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat; |
900 | 918 |
|
901 | 919 | for(var i=min; i<=max; i+=step){
|
902 | 920 | sel += '<option value="'+ i +'"'+ (i==val? ' selected':'') +'>';
|
903 |
| - if(unit == 'hour' && useAmpm(tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat)) |
904 |
| - sel += $.datepicker.formatTime("hh TT", {hour:i}, tp_inst._defaults); |
905 |
| - else if(unit == 'millisec' || i >= 10) sel += i; |
906 |
| - else sel += '0'+ i.toString(); |
| 921 | + if(unit == 'hour'){ |
| 922 | + sel += $.datepicker.formatTime($.trim(format.replace(/[^ht ]/ig,'')), {hour:i}, tp_inst._defaults); |
| 923 | + } |
| 924 | + else if(unit == 'millisec' || i >= 10){ sel += i; } |
| 925 | + else {sel += '0'+ i.toString(); } |
907 | 926 | sel += '</option>';
|
908 | 927 | }
|
909 | 928 | sel += '</select>';
|
|
921 | 940 | var o = {},
|
922 | 941 | $t = obj.children('select');
|
923 | 942 | if(typeof(opts) == 'string'){
|
924 |
| - if(val === undefined) |
| 943 | + if(val === undefined){ |
925 | 944 | return $t.data(opts);
|
| 945 | + } |
926 | 946 | o[opts] = val;
|
927 | 947 | }
|
928 |
| - else o = opts; |
| 948 | + else{ o = opts; } |
929 | 949 | return tp_inst.control.create(tp_inst, obj, $t.data('unit'), $t.val(), o.min || $t.data('min'), o.max || $t.data('max'), o.step || $t.data('step'));
|
930 | 950 | },
|
931 | 951 | value: function(tp_inst, obj, unit, val){
|
932 | 952 | var $t = obj.children('select');
|
933 |
| - if(val !== undefined) |
| 953 | + if(val !== undefined){ |
934 | 954 | return $t.val(val);
|
| 955 | + } |
935 | 956 | return $t.val();
|
936 | 957 | }
|
937 | 958 | }
|
|
1170 | 1191 | }; // end looseParse
|
1171 | 1192 |
|
1172 | 1193 | if(typeof o.parse === "function"){
|
1173 |
| - return o.parse(timeFormat, timeString, o) |
| 1194 | + return o.parse(timeFormat, timeString, o); |
1174 | 1195 | }
|
1175 | 1196 | if(o.parse === 'loose'){
|
1176 | 1197 | return looseParse(timeFormat, timeString, o);
|
|
1348 | 1369 |
|
1349 | 1370 | altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix;
|
1350 | 1371 | if(!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null){
|
1351 |
| - if(tp_inst._defaults.altFormat) |
| 1372 | + if(tp_inst._defaults.altFormat){ |
1352 | 1373 | altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime;
|
1353 |
| - else altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime; |
| 1374 | + } |
| 1375 | + else{ |
| 1376 | + altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime; |
| 1377 | + } |
1354 | 1378 | }
|
1355 | 1379 | $(altField).val(altFormattedDateTime);
|
1356 | 1380 | }
|
|
1538 | 1562 | // Hack! The error message ends with a colon, a space, and
|
1539 | 1563 | // the "extra" characters. We rely on that instead of
|
1540 | 1564 | // attempting to perfectly reproduce the parsing algorithm.
|
1541 |
| - date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings); |
1542 |
| - $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format); |
| 1565 | + if (err.indexOf(":") >= 0) { |
| 1566 | + date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings); |
| 1567 | + $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format); |
| 1568 | + } else { |
| 1569 | + throw err; |
| 1570 | + } |
1543 | 1571 | }
|
1544 | 1572 | return date;
|
1545 | 1573 | };
|
|
1639 | 1667 | }
|
1640 | 1668 | return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value);
|
1641 | 1669 | };
|
| 1670 | + |
1642 | 1671 | /*
|
1643 | 1672 | * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype,
|
1644 | 1673 | * it will return false for all objects
|
|
1671 | 1700 | * Returns true if should use ampm, false if not
|
1672 | 1701 | */
|
1673 | 1702 | var useAmpm = function(timeFormat){
|
1674 |
| - return (timeFormat.indexOf('t') !== -1 && timeFormat.indexOf('h') !== -1); |
| 1703 | + return ((timeFormat.indexOf('t') !== -1 || timeFormat.indexOf('T') !== -1) && timeFormat.indexOf('h') !== -1); |
1675 | 1704 | };
|
1676 | 1705 |
|
1677 | 1706 | /*
|
|
1683 | 1712 | hour = hour - 12;
|
1684 | 1713 | }
|
1685 | 1714 |
|
1686 |
| - if (hour == 0) { |
| 1715 | + if (hour === 0) { |
1687 | 1716 | hour = 12;
|
1688 | 1717 | }
|
1689 | 1718 |
|
|
1907 | 1936 | * @return void
|
1908 | 1937 | */
|
1909 | 1938 | $.timepicker.log = function(err){
|
1910 |
| - if(window.console) |
| 1939 | + if(window.console){ |
1911 | 1940 | console.log(err);
|
| 1941 | + } |
1912 | 1942 | };
|
1913 | 1943 |
|
1914 | 1944 | /*
|
1915 | 1945 | * Keep up with the version
|
1916 | 1946 | */
|
1917 |
| - $.timepicker.version = "1.2"; |
| 1947 | + $.timepicker.version = "1.2.1"; |
1918 | 1948 |
|
1919 | 1949 | })(jQuery);
|
0 commit comments