| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | /* assets/wpuf/js/frontend-form.js */ |
| 2 | 2 | ;(function($, window) { |
| 3 | 3 | |
| 4 | 4 | $.fn.listautowidth = function() { |
| @@ -2689,1927 +2689,1927 @@ | ||
| 2689 | 2689 | }))); |
| 2690 | 2690 | if (window.Sweetalert2) window.sweetAlert = window.swal = window.Sweetalert2; |
| 2691 | 2691 | |
| 2692 | 2692 | /* assets/wpuf/js/jquery-ui-timepicker-addon.js */ |
| 2693 | -/* | |
| 2694 | - * jQuery timepicker addon | |
| 2695 | - * By: Trent Richardson [http://trentrichardson.com] | |
| 2696 | - * Version 1.2 | |
| 2697 | - * Last Modified: 02/02/2013 | |
| 2698 | - * | |
| 2699 | - * Copyright 2013 Trent Richardson | |
| 2700 | - * You may use this project under MIT or GPL licenses. | |
| 2701 | - * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt | |
| 2702 | - * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt | |
| 2703 | - */ | |
| 2704 | - | |
| 2705 | -/*jslint evil: true, white: false, undef: false, nomen: false */ | |
| 2706 | - | |
| 2707 | -(function($) { | |
| 2708 | - | |
| 2709 | - /* | |
| 2710 | - * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded" | |
| 2711 | - */ | |
| 2712 | - $.ui.timepicker = $.ui.timepicker || {}; | |
| 2713 | - if ($.ui.timepicker.version) { | |
| 2714 | - return; | |
| 2715 | - } | |
| 2716 | - | |
| 2717 | - /* | |
| 2718 | - * Extend jQueryUI, get it started with our version number | |
| 2719 | - */ | |
| 2720 | - $.extend($.ui, { | |
| 2721 | - timepicker: { | |
| 2722 | - version: "1.2" | |
| 2723 | - } | |
| 2724 | - }); | |
| 2725 | - | |
| 2726 | - /* | |
| 2727 | - * Timepicker manager. | |
| 2728 | - * Use the singleton instance of this class, $.timepicker, to interact with the time picker. | |
| 2729 | - * Settings for (groups of) time pickers are maintained in an instance object, | |
| 2730 | - * allowing multiple different settings on the same page. | |
| 2731 | - */ | |
| 2732 | - var Timepicker = function() { | |
| 2733 | - this.regional = []; // Available regional settings, indexed by language code | |
| 2734 | - this.regional[''] = { // Default regional settings | |
| 2735 | - currentText: 'Now', | |
| 2736 | - closeText: 'Done', | |
| 2737 | - amNames: ['AM', 'A'], | |
| 2738 | - pmNames: ['PM', 'P'], | |
| 2739 | - timeFormat: 'HH:mm', | |
| 2740 | - timeSuffix: '', | |
| 2741 | - timeOnlyTitle: 'Choose Time', | |
| 2742 | - timeText: 'Time', | |
| 2743 | - hourText: 'Hour', | |
| 2744 | - minuteText: 'Minute', | |
| 2745 | - secondText: 'Second', | |
| 2746 | - millisecText: 'Millisecond', | |
| 2747 | - timezoneText: 'Time Zone', | |
| 2748 | - isRTL: false | |
| 2749 | - }; | |
| 2750 | - this._defaults = { // Global defaults for all the datetime picker instances | |
| 2751 | - showButtonPanel: true, | |
| 2752 | - timeOnly: false, | |
| 2753 | - showHour: true, | |
| 2754 | - showMinute: true, | |
| 2755 | - showSecond: false, | |
| 2756 | - showMillisec: false, | |
| 2757 | - showTimezone: false, | |
| 2758 | - showTime: true, | |
| 2759 | - stepHour: 1, | |
| 2760 | - stepMinute: 1, | |
| 2761 | - stepSecond: 1, | |
| 2762 | - stepMillisec: 1, | |
| 2763 | - hour: 0, | |
| 2764 | - minute: 0, | |
| 2765 | - second: 0, | |
| 2766 | - millisec: 0, | |
| 2767 | - timezone: null, | |
| 2768 | - useLocalTimezone: false, | |
| 2769 | - defaultTimezone: "+0000", | |
| 2770 | - hourMin: 0, | |
| 2771 | - minuteMin: 0, | |
| 2772 | - secondMin: 0, | |
| 2773 | - millisecMin: 0, | |
| 2774 | - hourMax: 23, | |
| 2775 | - minuteMax: 59, | |
| 2776 | - secondMax: 59, | |
| 2777 | - millisecMax: 999, | |
| 2778 | - minDateTime: null, | |
| 2779 | - maxDateTime: null, | |
| 2780 | - onSelect: null, | |
| 2781 | - hourGrid: 0, | |
| 2782 | - minuteGrid: 0, | |
| 2783 | - secondGrid: 0, | |
| 2784 | - millisecGrid: 0, | |
| 2785 | - alwaysSetTime: true, | |
| 2786 | - separator: ' ', | |
| 2787 | - altFieldTimeOnly: true, | |
| 2788 | - altTimeFormat: null, | |
| 2789 | - altSeparator: null, | |
| 2790 | - altTimeSuffix: null, | |
| 2791 | - pickerTimeFormat: null, | |
| 2792 | - pickerTimeSuffix: null, | |
| 2793 | - showTimepicker: true, | |
| 2794 | - timezoneIso8601: false, | |
| 2795 | - timezoneList: null, | |
| 2796 | - addSliderAccess: false, | |
| 2797 | - sliderAccessArgs: null, | |
| 2798 | - controlType: 'slider', | |
| 2799 | - defaultValue: null, | |
| 2800 | - parse: 'strict' | |
| 2801 | - }; | |
| 2802 | - $.extend(this._defaults, this.regional['']); | |
| 2803 | - }; | |
| 2804 | - | |
| 2805 | - $.extend(Timepicker.prototype, { | |
| 2806 | - $input: null, | |
| 2807 | - $altInput: null, | |
| 2808 | - $timeObj: null, | |
| 2809 | - inst: null, | |
| 2810 | - hour_slider: null, | |
| 2811 | - minute_slider: null, | |
| 2812 | - second_slider: null, | |
| 2813 | - millisec_slider: null, | |
| 2814 | - timezone_select: null, | |
| 2815 | - hour: 0, | |
| 2816 | - minute: 0, | |
| 2817 | - second: 0, | |
| 2818 | - millisec: 0, | |
| 2819 | - timezone: null, | |
| 2820 | - defaultTimezone: "+0000", | |
| 2821 | - hourMinOriginal: null, | |
| 2822 | - minuteMinOriginal: null, | |
| 2823 | - secondMinOriginal: null, | |
| 2824 | - millisecMinOriginal: null, | |
| 2825 | - hourMaxOriginal: null, | |
| 2826 | - minuteMaxOriginal: null, | |
| 2827 | - secondMaxOriginal: null, | |
| 2828 | - millisecMaxOriginal: null, | |
| 2829 | - ampm: '', | |
| 2830 | - formattedDate: '', | |
| 2831 | - formattedTime: '', | |
| 2832 | - formattedDateTime: '', | |
| 2833 | - timezoneList: null, | |
| 2834 | - units: ['hour','minute','second','millisec'], | |
| 2835 | - control: null, | |
| 2836 | - | |
| 2837 | - /* | |
| 2838 | - * Override the default settings for all instances of the time picker. | |
| 2839 | - * @param settings object - the new settings to use as defaults (anonymous object) | |
| 2840 | - * @return the manager object | |
| 2841 | - */ | |
| 2842 | - setDefaults: function(settings) { | |
| 2843 | - extendRemove(this._defaults, settings || {}); | |
| 2844 | - return this; | |
| 2845 | - }, | |
| 2846 | - | |
| 2847 | - /* | |
| 2848 | - * Create a new Timepicker instance | |
| 2849 | - */ | |
| 2850 | - _newInst: function($input, o) { | |
| 2851 | - var tp_inst = new Timepicker(), | |
| 2852 | - inlineSettings = {}, | |
| 2853 | - fns = {}, | |
| 2854 | - overrides, i; | |
| 2855 | - | |
| 2856 | - for (var attrName in this._defaults) { | |
| 2857 | - if(this._defaults.hasOwnProperty(attrName)){ | |
| 2858 | - var attrValue = $input.attr('time:' + attrName); | |
| 2859 | - if (attrValue) { | |
| 2860 | - try { | |
| 2861 | - inlineSettings[attrName] = eval(attrValue); | |
| 2862 | - } catch (err) { | |
| 2863 | - inlineSettings[attrName] = attrValue; | |
| 2864 | - } | |
| 2865 | - } | |
| 2866 | - } | |
| 2867 | - } | |
| 2868 | - overrides = { | |
| 2869 | - beforeShow: function (input, dp_inst) { | |
| 2870 | - if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) { | |
| 2871 | - return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst); | |
| 2872 | - } | |
| 2873 | - }, | |
| 2874 | - onChangeMonthYear: function (year, month, dp_inst) { | |
| 2875 | - // Update the time as well : this prevents the time from disappearing from the $input field. | |
| 2876 | - tp_inst._updateDateTime(dp_inst); | |
| 2877 | - if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) { | |
| 2878 | - tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); | |
| 2879 | - } | |
| 2880 | - }, | |
| 2881 | - onClose: function (dateText, dp_inst) { | |
| 2882 | - if (tp_inst.timeDefined === true && $input.val() !== '') { | |
| 2883 | - tp_inst._updateDateTime(dp_inst); | |
| 2884 | - } | |
| 2885 | - if ($.isFunction(tp_inst._defaults.evnts.onClose)) { | |
| 2886 | - tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst); | |
| 2887 | - } | |
| 2888 | - } | |
| 2889 | - }; | |
| 2890 | - for (i in overrides) { | |
| 2891 | - if (overrides.hasOwnProperty(i)) { | |
| 2892 | - fns[i] = o[i] || null; | |
| 2893 | - } | |
| 2894 | - } | |
| 2895 | - tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, { | |
| 2896 | - evnts:fns, | |
| 2897 | - timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); | |
| 2898 | - }); | |
| 2899 | - tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { | |
| 2900 | - return val.toUpperCase(); | |
| 2901 | - }); | |
| 2902 | - tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { | |
| 2903 | - return val.toUpperCase(); | |
| 2904 | - }); | |
| 2905 | - | |
| 2906 | - // controlType is string - key to our this._controls | |
| 2907 | - if(typeof(tp_inst._defaults.controlType) === 'string'){ | |
| 2908 | - if($.fn[tp_inst._defaults.controlType] === undefined){ | |
| 2909 | - tp_inst._defaults.controlType = 'select'; | |
| 2910 | - } | |
| 2911 | - tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType]; | |
| 2912 | - } | |
| 2913 | - // controlType is an object and must implement create, options, value methods | |
| 2914 | - else{ | |
| 2915 | - tp_inst.control = tp_inst._defaults.controlType; | |
| 2916 | - } | |
| 2917 | - | |
| 2918 | - if (tp_inst._defaults.timezoneList === null) { | |
| 2919 | - var timezoneList = ['-1200', '-1100', '-1000', '-0930', '-0900', '-0800', '-0700', '-0600', '-0500', '-0430', '-0400', '-0330', '-0300', '-0200', '-0100', '+0000', | |
| 2920 | - '+0100', '+0200', '+0300', '+0330', '+0400', '+0430', '+0500', '+0530', '+0545', '+0600', '+0630', '+0700', '+0800', '+0845', '+0900', '+0930', | |
| 2921 | - '+1000', '+1030', '+1100', '+1130', '+1200', '+1245', '+1300', '+1400']; | |
| 2922 | - | |
| 2923 | - if (tp_inst._defaults.timezoneIso8601) { | |
| 2924 | - timezoneList = $.map(timezoneList, function(val) { | |
| 2925 | - return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3)); | |
| 2926 | - }); | |
| 2927 | - } | |
| 2928 | - tp_inst._defaults.timezoneList = timezoneList; | |
| 2929 | - } | |
| 2930 | - | |
| 2931 | - tp_inst.timezone = tp_inst._defaults.timezone; | |
| 2932 | - tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin? tp_inst._defaults.hourMin : | |
| 2933 | - tp_inst._defaults.hour > tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour; | |
| 2934 | - tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin : | |
| 2935 | - tp_inst._defaults.minute > tp_inst._defaults.minuteMax? tp_inst._defaults.minuteMax : tp_inst._defaults.minute; | |
| 2936 | - tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin? tp_inst._defaults.secondMin : | |
| 2937 | - tp_inst._defaults.second > tp_inst._defaults.secondMax? tp_inst._defaults.secondMax : tp_inst._defaults.second; | |
| 2938 | - tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin? tp_inst._defaults.millisecMin : | |
| 2939 | - tp_inst._defaults.millisec > tp_inst._defaults.millisecMax? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec; | |
| 2940 | - tp_inst.ampm = ''; | |
| 2941 | - tp_inst.$input = $input; | |
| 2942 | - | |
| 2943 | - if (o.altField) { | |
| 2944 | - tp_inst.$altInput = $(o.altField).css({ | |
| 2945 | - cursor: 'pointer' | |
| 2946 | - }).focus(function() { | |
| 2947 | - $input.trigger("focus"); | |
| 2948 | - }); | |
| 2949 | - } | |
| 2950 | - | |
| 2951 | - if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) { | |
| 2952 | - tp_inst._defaults.minDate = new Date(); | |
| 2953 | - } | |
| 2954 | - if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) { | |
| 2955 | - tp_inst._defaults.maxDate = new Date(); | |
| 2956 | - } | |
| 2957 | - | |
| 2958 | - // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. | |
| 2959 | - if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) { | |
| 2960 | - tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); | |
| 2961 | - } | |
| 2962 | - if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) { | |
| 2963 | - tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime()); | |
| 2964 | - } | |
| 2965 | - if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) { | |
| 2966 | - tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime()); | |
| 2967 | - } | |
| 2968 | - if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) { | |
| 2969 | - tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); | |
| 2970 | - } | |
| 2971 | - tp_inst.$input.bind('focus', function() { | |
| 2972 | - tp_inst._onFocus(); | |
| 2973 | - }); | |
| 2974 | - | |
| 2975 | - return tp_inst; | |
| 2976 | - }, | |
| 2977 | - | |
| 2978 | - /* | |
| 2979 | - * add our sliders to the calendar | |
| 2980 | - */ | |
| 2981 | - _addTimePicker: function(dp_inst) { | |
| 2982 | - var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val(); | |
| 2983 | - | |
| 2984 | - this.timeDefined = this._parseTime(currDT); | |
| 2985 | - this._limitMinMaxDateTime(dp_inst, false); | |
| 2986 | - this._injectTimePicker(); | |
| 2987 | - }, | |
| 2988 | - | |
| 2989 | - /* | |
| 2990 | - * parse the time string from input value or _setTime | |
| 2991 | - */ | |
| 2992 | - _parseTime: function(timeString, withDate) { | |
| 2993 | - if (!this.inst) { | |
| 2994 | - this.inst = $.datepicker._getInst(this.$input[0]); | |
| 2995 | - } | |
| 2996 | - | |
| 2997 | - if (withDate || !this._defaults.timeOnly) { | |
| 2998 | - var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); | |
| 2999 | - try { | |
| 3000 | - var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults); | |
| 3001 | - if (!parseRes.timeObj) { | |
| 3002 | - return false; | |
| 3003 | - } | |
| 3004 | - $.extend(this, parseRes.timeObj); | |
| 3005 | - } catch (err) { | |
| 3006 | - $.timepicker.log("Error parsing the date/time string: " + err + | |
| 3007 | - "\ndate/time string = " + timeString + | |
| 3008 | - "\ntimeFormat = " + this._defaults.timeFormat + | |
| 3009 | - "\ndateFormat = " + dp_dateFormat); | |
| 3010 | - return false; | |
| 3011 | - } | |
| 3012 | - return true; | |
| 3013 | - } else { | |
| 3014 | - var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults); | |
| 3015 | - if (!timeObj) { | |
| 3016 | - return false; | |
| 3017 | - } | |
| 3018 | - $.extend(this, timeObj); | |
| 3019 | - return true; | |
| 3020 | - } | |
| 3021 | - }, | |
| 3022 | - | |
| 3023 | - /* | |
| 3024 | - * generate and inject html for timepicker into ui datepicker | |
| 3025 | - */ | |
| 3026 | - _injectTimePicker: function() { | |
| 3027 | - var $dp = this.inst.dpDiv, | |
| 3028 | - o = this.inst.settings, | |
| 3029 | - tp_inst = this, | |
| 3030 | - litem = '', | |
| 3031 | - uitem = '', | |
| 3032 | - max = {}, | |
| 3033 | - gridSize = {}, | |
| 3034 | - size = null; | |
| 3035 | - | |
| 3036 | - // Prevent displaying twice | |
| 3037 | - if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) { | |
| 3038 | - var noDisplay = ' style="display:none;"', | |
| 3039 | - html = '<div class="ui-timepicker-div'+ (o.isRTL? ' ui-timepicker-rtl' : '') +'"><dl>' + '<dt class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' + | |
| 3040 | - '<dd class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></dd>'; | |
| 3041 | - | |
| 3042 | - // Create the markup | |
| 3043 | - for(var i=0,l=this.units.length; i<l; i++){ | |
| 3044 | - litem = this.units[i]; | |
| 3045 | - uitem = litem.substr(0,1).toUpperCase() + litem.substr(1); | |
| 3046 | - // Added by Peter Medeiros: | |
| 3047 | - // - Figure out what the hour/minute/second max should be based on the step values. | |
| 3048 | - // - Example: if stepMinute is 15, then minMax is 45. | |
| 3049 | - max[litem] = parseInt((o[litem+'Max'] - ((o[litem+'Max'] - o[litem+'Min']) % o['step'+uitem])), 10); | |
| 3050 | - gridSize[litem] = 0; | |
| 3051 | - | |
| 3052 | - html += '<dt class="ui_tpicker_'+ litem +'_label"' + ((o['show'+uitem]) ? '' : noDisplay) + '>' + o[litem +'Text'] + '</dt>' + | |
| 3053 | - '<dd class="ui_tpicker_'+ litem +'"><div class="ui_tpicker_'+ litem +'_slider"' + ((o['show'+uitem]) ? '' : noDisplay) + '></div>'; | |
| 3054 | - | |
| 3055 | - if (o['show'+uitem] && o[litem+'Grid'] > 0) { | |
| 3056 | - html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>'; | |
| 3057 | - | |
| 3058 | - if(litem == 'hour'){ | |
| 3059 | - for (var h = o[litem+'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) { | |
| 3060 | - gridSize[litem]++; | |
| 3061 | - var tmph = $.datepicker.formatTime(useAmpm(o.pickerTimeFormat || o.timeFormat)? 'hht':'HH', {hour:h}, o); | |
| 3062 | - html += '<td data-for="'+litem+'">' + tmph + '</td>'; | |
| 3063 | - } | |
| 3064 | - } | |
| 3065 | - else{ | |
| 3066 | - for (var m = o[litem+'Min']; m <= max[litem]; m += parseInt(o[litem+'Grid'], 10)) { | |
| 3067 | - gridSize[litem]++; | |
| 3068 | - html += '<td data-for="'+litem+'">' + ((m < 10) ? '0' : '') + m + '</td>'; | |
| 3069 | - } | |
| 3070 | - } | |
| 3071 | - | |
| 3072 | - html += '</tr></table></div>'; | |
| 3073 | - } | |
| 3074 | - html += '</dd>'; | |
| 3075 | - } | |
| 3076 | - | |
| 3077 | - // Timezone | |
| 3078 | - html += '<dt class="ui_tpicker_timezone_label"' + ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>'; | |
| 3079 | - html += '<dd class="ui_tpicker_timezone" ' + ((o.showTimezone) ? '' : noDisplay) + '></dd>'; | |
| 3080 | - | |
| 3081 | - // Create the elements from string | |
| 3082 | - html += '</dl></div>'; | |
| 3083 | - var $tp = $(html); | |
| 3084 | - | |
| 3085 | - // if we only want time picker... | |
| 3086 | - if (o.timeOnly === true) { | |
| 3087 | - $tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>'); | |
| 3088 | - $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); | |
| 3089 | - } | |
| 3090 | - | |
| 3091 | - // add sliders, adjust grids, add events | |
| 3092 | - for(var i=0,l=tp_inst.units.length; i<l; i++){ | |
| 3093 | - litem = tp_inst.units[i]; | |
| 3094 | - uitem = litem.substr(0,1).toUpperCase() + litem.substr(1); | |
| 3095 | - | |
| 3096 | - // add the slider | |
| 3097 | - 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]); | |
| 3098 | - | |
| 3099 | - // adjust the grid and add click event | |
| 3100 | - if (o['show'+uitem] && o[litem+'Grid'] > 0) { | |
| 3101 | - size = 100 * gridSize[litem] * o[litem+'Grid'] / (max[litem] - o[litem+'Min']); | |
| 3102 | - $tp.find('.ui_tpicker_'+litem+' table').css({ | |
| 3103 | - width: size + "%", | |
| 3104 | - marginLeft: o.isRTL? '0' : ((size / (-2 * gridSize[litem])) + "%"), | |
| 3105 | - marginRight: o.isRTL? ((size / (-2 * gridSize[litem])) + "%") : '0', | |
| 3106 | - borderCollapse: 'collapse' | |
| 3107 | - }).find("td").click(function(e){ | |
| 3108 | - var $t = $(this), | |
| 3109 | - h = $t.html(), | |
| 3110 | - n = parseInt(h.replace(/[^0-9]/g),10), | |
| 3111 | - ap = h.replace(/[^apm]/ig), | |
| 3112 | - f = $t.data('for'); // loses scope, so we use data-for | |
| 3113 | - | |
| 3114 | - if(f == 'hour'){ | |
| 3115 | - if(ap.indexOf('p') !== -1 && n < 12){ | |
| 3116 | - n += 12; | |
| 3117 | - } | |
| 3118 | - else{ | |
| 3119 | - if(ap.indexOf('a') !== -1 && n === 12){ | |
| 3120 | - n = 0; | |
| 3121 | - } | |
| 3122 | - } | |
| 3123 | - } | |
| 3124 | - | |
| 3125 | - tp_inst.control.value(tp_inst, tp_inst[f+'_slider'], litem, n); | |
| 3126 | - | |
| 3127 | - tp_inst._onTimeChange(); | |
| 3128 | - tp_inst._onSelectHandler(); | |
| 3129 | - }) | |
| 3130 | - .css({ | |
| 3131 | - cursor: 'pointer', | |
| 3132 | - width: (100 / gridSize[litem]) + '%', | |
| 3133 | - textAlign: 'center', | |
| 3134 | - overflow: 'hidden' | |
| 3135 | - }); | |
| 3136 | - } // end if grid > 0 | |
| 3137 | - } // end for loop | |
| 3138 | - | |
| 3139 | - // Add timezone options | |
| 3140 | - this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select"); | |
| 3141 | - $.fn.append.apply(this.timezone_select, | |
| 3142 | - $.map(o.timezoneList, function(val, idx) { | |
| 3143 | - return $("<option />").val(typeof val == "object" ? val.value : val).text(typeof val == "object" ? val.label : val); | |
| 3144 | - })); | |
| 3145 | - if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") { | |
| 3146 | - var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12); | |
| 3147 | - var local_timezone = $.timepicker.timeZoneOffsetString(local_date); | |
| 3148 | - if (local_timezone == this.timezone) { | |
| 3149 | - selectLocalTimeZone(tp_inst); | |
| 3150 | - } else { | |
| 3151 | - this.timezone_select.val(this.timezone); | |
| 3152 | - } | |
| 3153 | - } else { | |
| 3154 | - if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") { | |
| 3155 | - this.timezone_select.val(o.defaultTimezone); | |
| 3156 | - } else { | |
| 3157 | - selectLocalTimeZone(tp_inst); | |
| 3158 | - } | |
| 3159 | - } | |
| 3160 | - this.timezone_select.change(function() { | |
| 3161 | - tp_inst._defaults.useLocalTimezone = false; | |
| 3162 | - tp_inst._onTimeChange(); | |
| 3163 | - tp_inst._onSelectHandler(); | |
| 3164 | - }); | |
| 3165 | - // End timezone options | |
| 3166 | - | |
| 3167 | - // inject timepicker into datepicker | |
| 3168 | - var $buttonPanel = $dp.find('.ui-datepicker-buttonpane'); | |
| 3169 | - if ($buttonPanel.length) { | |
| 3170 | - $buttonPanel.before($tp); | |
| 3171 | - } else { | |
| 3172 | - $dp.append($tp); | |
| 3173 | - } | |
| 3174 | - | |
| 3175 | - this.$timeObj = $tp.find('.ui_tpicker_time'); | |
| 3176 | - | |
| 3177 | - if (this.inst !== null) { | |
| 3178 | - var timeDefined = this.timeDefined; | |
| 3179 | - this._onTimeChange(); | |
| 3180 | - this.timeDefined = timeDefined; | |
| 3181 | - } | |
| 3182 | - | |
| 3183 | - // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/ | |
| 3184 | - if (this._defaults.addSliderAccess) { | |
| 3185 | - var sliderAccessArgs = this._defaults.sliderAccessArgs, | |
| 3186 | - rtl = this._defaults.isRTL; | |
| 3187 | - sliderAccessArgs.isRTL = rtl; | |
| 3188 | - | |
| 3189 | - setTimeout(function() { // fix for inline mode | |
| 3190 | - if ($tp.find('.ui-slider-access').length === 0) { | |
| 3191 | - $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs); | |
| 3192 | - | |
| 3193 | - // fix any grids since sliders are shorter | |
| 3194 | - var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true); | |
| 3195 | - if (sliderAccessWidth) { | |
| 3196 | - $tp.find('table:visible').each(function() { | |
| 3197 | - var $g = $(this), | |
| 3198 | - oldWidth = $g.outerWidth(), | |
| 3199 | - oldMarginLeft = $g.css(rtl? 'marginRight':'marginLeft').toString().replace('%', ''), | |
| 3200 | - newWidth = oldWidth - sliderAccessWidth, | |
| 3201 | - newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%', | |
| 3202 | - css = { width: newWidth, marginRight: 0, marginLeft: 0 }; | |
| 3203 | - css[rtl? 'marginRight':'marginLeft'] = newMarginLeft; | |
| 3204 | - $g.css(css); | |
| 3205 | - }); | |
| 3206 | - } | |
| 3207 | - } | |
| 3208 | - }, 10); | |
| 3209 | - } | |
| 3210 | - // end slideAccess integration | |
| 3211 | - | |
| 3212 | - } | |
| 3213 | - }, | |
| 3214 | - | |
| 3215 | - /* | |
| 3216 | - * This function tries to limit the ability to go outside the | |
| 3217 | - * min/max date range | |
| 3218 | - */ | |
| 3219 | - _limitMinMaxDateTime: function(dp_inst, adjustSliders) { | |
| 3220 | - var o = this._defaults, | |
| 3221 | - dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay); | |
| 3222 | - | |
| 3223 | - if (!this._defaults.showTimepicker) { | |
| 3224 | - return; | |
| 3225 | - } // No time so nothing to check here | |
| 3226 | - | |
| 3227 | - if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) { | |
| 3228 | - var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'), | |
| 3229 | - minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0); | |
| 3230 | - | |
| 3231 | - if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null) { | |
| 3232 | - this.hourMinOriginal = o.hourMin; | |
| 3233 | - this.minuteMinOriginal = o.minuteMin; | |
| 3234 | - this.secondMinOriginal = o.secondMin; | |
| 3235 | - this.millisecMinOriginal = o.millisecMin; | |
| 3236 | - } | |
| 3237 | - | |
| 3238 | - if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) { | |
| 3239 | - this._defaults.hourMin = minDateTime.getHours(); | |
| 3240 | - if (this.hour <= this._defaults.hourMin) { | |
| 3241 | - this.hour = this._defaults.hourMin; | |
| 3242 | - this._defaults.minuteMin = minDateTime.getMinutes(); | |
| 3243 | - if (this.minute <= this._defaults.minuteMin) { | |
| 3244 | - this.minute = this._defaults.minuteMin; | |
| 3245 | - this._defaults.secondMin = minDateTime.getSeconds(); | |
| 3246 | - if (this.second <= this._defaults.secondMin) { | |
| 3247 | - this.second = this._defaults.secondMin; | |
| 3248 | - this._defaults.millisecMin = minDateTime.getMilliseconds(); | |
| 3249 | - } else { | |
| 3250 | - if (this.millisec < this._defaults.millisecMin) { | |
| 3251 | - this.millisec = this._defaults.millisecMin; | |
| 3252 | - } | |
| 3253 | - this._defaults.millisecMin = this.millisecMinOriginal; | |
| 3254 | - } | |
| 3255 | - } else { | |
| 3256 | - this._defaults.secondMin = this.secondMinOriginal; | |
| 3257 | - this._defaults.millisecMin = this.millisecMinOriginal; | |
| 3258 | - } | |
| 3259 | - } else { | |
| 3260 | - this._defaults.minuteMin = this.minuteMinOriginal; | |
| 3261 | - this._defaults.secondMin = this.secondMinOriginal; | |
| 3262 | - this._defaults.millisecMin = this.millisecMinOriginal; | |
| 3263 | - } | |
| 3264 | - } else { | |
| 3265 | - this._defaults.hourMin = this.hourMinOriginal; | |
| 3266 | - this._defaults.minuteMin = this.minuteMinOriginal; | |
| 3267 | - this._defaults.secondMin = this.secondMinOriginal; | |
| 3268 | - this._defaults.millisecMin = this.millisecMinOriginal; | |
| 3269 | - } | |
| 3270 | - } | |
| 3271 | - | |
| 3272 | - if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) { | |
| 3273 | - var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'), | |
| 3274 | - maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0); | |
| 3275 | - | |
| 3276 | - if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null) { | |
| 3277 | - this.hourMaxOriginal = o.hourMax; | |
| 3278 | - this.minuteMaxOriginal = o.minuteMax; | |
| 3279 | - this.secondMaxOriginal = o.secondMax; | |
| 3280 | - this.millisecMaxOriginal = o.millisecMax; | |
| 3281 | - } | |
| 3282 | - | |
| 3283 | - if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()) { | |
| 3284 | - this._defaults.hourMax = maxDateTime.getHours(); | |
| 3285 | - if (this.hour >= this._defaults.hourMax) { | |
| 3286 | - this.hour = this._defaults.hourMax; | |
| 3287 | - this._defaults.minuteMax = maxDateTime.getMinutes(); | |
| 3288 | - if (this.minute >= this._defaults.minuteMax) { | |
| 3289 | - this.minute = this._defaults.minuteMax; | |
| 3290 | - this._defaults.secondMax = maxDateTime.getSeconds(); | |
| 3291 | - if (this.second >= this._defaults.secondMax) { | |
| 3292 | - this.second = this._defaults.secondMax; | |
| 3293 | - this._defaults.millisecMax = maxDateTime.getMilliseconds(); | |
| 3294 | - } else { | |
| 3295 | - if (this.millisec > this._defaults.millisecMax) { | |
| 3296 | - this.millisec = this._defaults.millisecMax; | |
| 3297 | - } | |
| 3298 | - this._defaults.millisecMax = this.millisecMaxOriginal; | |
| 3299 | - } | |
| 3300 | - } else { | |
| 3301 | - this._defaults.secondMax = this.secondMaxOriginal; | |
| 3302 | - this._defaults.millisecMax = this.millisecMaxOriginal; | |
| 3303 | - } | |
| 3304 | - } else { | |
| 3305 | - this._defaults.minuteMax = this.minuteMaxOriginal; | |
| 3306 | - this._defaults.secondMax = this.secondMaxOriginal; | |
| 3307 | - this._defaults.millisecMax = this.millisecMaxOriginal; | |
| 3308 | - } | |
| 3309 | - } else { | |
| 3310 | - this._defaults.hourMax = this.hourMaxOriginal; | |
| 3311 | - this._defaults.minuteMax = this.minuteMaxOriginal; | |
| 3312 | - this._defaults.secondMax = this.secondMaxOriginal; | |
| 3313 | - this._defaults.millisecMax = this.millisecMaxOriginal; | |
| 3314 | - } | |
| 3315 | - } | |
| 3316 | - | |
| 3317 | - if (adjustSliders !== undefined && adjustSliders === true) { | |
| 3318 | - var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10), | |
| 3319 | - minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10), | |
| 3320 | - secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10), | |
| 3321 | - millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10); | |
| 3322 | - | |
| 3323 | - if (this.hour_slider) { | |
| 3324 | - this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax }); | |
| 3325 | - this.control.value(this, this.hour_slider, 'hour', this.hour - (this.hour % this._defaults.stepHour)); | |
| 3326 | - } | |
| 3327 | - if (this.minute_slider) { | |
| 3328 | - this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax }); | |
| 3329 | - this.control.value(this, this.minute_slider, 'minute', this.minute - (this.minute % this._defaults.stepMinute)); | |
| 3330 | - } | |
| 3331 | - if (this.second_slider) { | |
| 3332 | - this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax }); | |
| 3333 | - this.control.value(this, this.second_slider, 'second', this.second - (this.second % this._defaults.stepSecond)); | |
| 3334 | - } | |
| 3335 | - if (this.millisec_slider) { | |
| 3336 | - this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax }); | |
| 3337 | - this.control.value(this, this.millisec_slider, 'millisec', this.millisec - (this.millisec % this._defaults.stepMillisec)); | |
| 3338 | - } | |
| 3339 | - } | |
| 3340 | - | |
| 3341 | - }, | |
| 3342 | - | |
| 3343 | - /* | |
| 3344 | - * when a slider moves, set the internal time... | |
| 3345 | - * on time change is also called when the time is updated in the text field | |
| 3346 | - */ | |
| 3347 | - _onTimeChange: function() { | |
| 3348 | - var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false, | |
| 3349 | - minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false, | |
| 3350 | - second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false, | |
| 3351 | - millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false, | |
| 3352 | - timezone = (this.timezone_select) ? this.timezone_select.val() : false, | |
| 3353 | - o = this._defaults, | |
| 3354 | - pickerTimeFormat = o.pickerTimeFormat || o.timeFormat, | |
| 3355 | - pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix; | |
| 3356 | - | |
| 3357 | - if (typeof(hour) == 'object') { | |
| 3358 | - hour = false; | |
| 3359 | - } | |
| 3360 | - if (typeof(minute) == 'object') { | |
| 3361 | - minute = false; | |
| 3362 | - } | |
| 3363 | - if (typeof(second) == 'object') { | |
| 3364 | - second = false; | |
| 3365 | - } | |
| 3366 | - if (typeof(millisec) == 'object') { | |
| 3367 | - millisec = false; | |
| 3368 | - } | |
| 3369 | - if (typeof(timezone) == 'object') { | |
| 3370 | - timezone = false; | |
| 3371 | - } | |
| 3372 | - | |
| 3373 | - if (hour !== false) { | |
| 3374 | - hour = parseInt(hour, 10); | |
| 3375 | - } | |
| 3376 | - if (minute !== false) { | |
| 3377 | - minute = parseInt(minute, 10); | |
| 3378 | - } | |
| 3379 | - if (second !== false) { | |
| 3380 | - second = parseInt(second, 10); | |
| 3381 | - } | |
| 3382 | - if (millisec !== false) { | |
| 3383 | - millisec = parseInt(millisec, 10); | |
| 3384 | - } | |
| 3385 | - | |
| 3386 | - var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0]; | |
| 3387 | - | |
| 3388 | - // If the update was done in the input field, the input field should not be updated. | |
| 3389 | - // If the update was done using the sliders, update the input field. | |
| 3390 | - var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec | |
| 3391 | - || (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) | |
| 3392 | - || ((this.timezone === null && timezone != this.defaultTimezone) || (this.timezone !== null && timezone != this.timezone))); | |
| 3393 | - | |
| 3394 | - if (hasChanged) { | |
| 3395 | - | |
| 3396 | - if (hour !== false) { | |
| 3397 | - this.hour = hour; | |
| 3398 | - } | |
| 3399 | - if (minute !== false) { | |
| 3400 | - this.minute = minute; | |
| 3401 | - } | |
| 3402 | - if (second !== false) { | |
| 3403 | - this.second = second; | |
| 3404 | - } | |
| 3405 | - if (millisec !== false) { | |
| 3406 | - this.millisec = millisec; | |
| 3407 | - } | |
| 3408 | - if (timezone !== false) { | |
| 3409 | - this.timezone = timezone; | |
| 3410 | - } | |
| 3411 | - | |
| 3412 | - if (!this.inst) { | |
| 3413 | - this.inst = $.datepicker._getInst(this.$input[0]); | |
| 3414 | - } | |
| 3415 | - | |
| 3416 | - this._limitMinMaxDateTime(this.inst, true); | |
| 3417 | - } | |
| 3418 | - if (useAmpm(o.timeFormat)) { | |
| 3419 | - this.ampm = ampm; | |
| 3420 | - } | |
| 3421 | - | |
| 3422 | - // Updates the time within the timepicker | |
| 3423 | - this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o); | |
| 3424 | - if (this.$timeObj) { | |
| 3425 | - if(pickerTimeFormat === o.timeFormat){ | |
| 3426 | - this.$timeObj.text(this.formattedTime + pickerTimeSuffix); | |
| 3427 | - } | |
| 3428 | - else{ | |
| 3429 | - this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix); | |
| 3430 | - } | |
| 3431 | - } | |
| 3432 | - | |
| 3433 | - this.timeDefined = true; | |
| 3434 | - if (hasChanged) { | |
| 3435 | - this._updateDateTime(); | |
| 3436 | - } | |
| 3437 | - }, | |
| 3438 | - | |
| 3439 | - /* | |
| 3440 | - * call custom onSelect. | |
| 3441 | - * bind to sliders slidestop, and grid click. | |
| 3442 | - */ | |
| 3443 | - _onSelectHandler: function() { | |
| 3444 | - var onSelect = this._defaults.onSelect || this.inst.settings.onSelect; | |
| 3445 | - var inputEl = this.$input ? this.$input[0] : null; | |
| 3446 | - if (onSelect && inputEl) { | |
| 3447 | - onSelect.apply(inputEl, [this.formattedDateTime, this]); | |
| 3448 | - } | |
| 3449 | - }, | |
| 3450 | - | |
| 3451 | - /* | |
| 3452 | - * update our input with the new date time.. | |
| 3453 | - */ | |
| 3454 | - _updateDateTime: function(dp_inst) { | |
| 3455 | - dp_inst = this.inst || dp_inst; | |
| 3456 | - var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), | |
| 3457 | - dateFmt = $.datepicker._get(dp_inst, 'dateFormat'), | |
| 3458 | - formatCfg = $.datepicker._getFormatConfig(dp_inst), | |
| 3459 | - timeAvailable = dt !== null && this.timeDefined; | |
| 3460 | - this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg); | |
| 3461 | - var formattedDateTime = this.formattedDate; | |
| 3462 | - | |
| 3463 | - // if a slider was changed but datepicker doesn't have a value yet, set it | |
| 3464 | - if(dp_inst.lastVal==""){ | |
| 3465 | - dp_inst.currentYear=dp_inst.selectedYear; | |
| 3466 | - dp_inst.currentMonth=dp_inst.selectedMonth; | |
| 3467 | - dp_inst.currentDay=dp_inst.selectedDay; | |
| 3468 | - } | |
| 3469 | - | |
| 3470 | - /* | |
| 3471 | - * remove following lines to force every changes in date picker to change the input value | |
| 3472 | - * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker. | |
| 3473 | - * If the user manually empty the value in the input field, the date picker will never change selected value. | |
| 3474 | - */ | |
| 3475 | - //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) { | |
| 3476 | - // return; | |
| 3477 | - //} | |
| 3478 | - | |
| 3479 | - if (this._defaults.timeOnly === true) { | |
| 3480 | - formattedDateTime = this.formattedTime; | |
| 3481 | - } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) { | |
| 3482 | - formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix; | |
| 3483 | - } | |
| 3484 | - | |
| 3485 | - this.formattedDateTime = formattedDateTime; | |
| 3486 | - | |
| 3487 | - if (!this._defaults.showTimepicker) { | |
| 3488 | - this.$input.val(this.formattedDate); | |
| 3489 | - } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) { | |
| 3490 | - this.$altInput.val(this.formattedTime); | |
| 3491 | - this.$input.val(this.formattedDate); | |
| 3492 | - } else if (this.$altInput) { | |
| 3493 | - this.$input.val(formattedDateTime); | |
| 3494 | - var altFormattedDateTime = '', | |
| 3495 | - altSeparator = this._defaults.altSeparator ? this._defaults.altSeparator : this._defaults.separator, | |
| 3496 | - altTimeSuffix = this._defaults.altTimeSuffix ? this._defaults.altTimeSuffix : this._defaults.timeSuffix; | |
| 3497 | - | |
| 3498 | - if (this._defaults.altFormat) altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg); | |
| 3499 | - else altFormattedDateTime = this.formattedDate; | |
| 3500 | - if (altFormattedDateTime) altFormattedDateTime += altSeparator; | |
| 3501 | - if (this._defaults.altTimeFormat) altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix; | |
| 3502 | - else altFormattedDateTime += this.formattedTime + altTimeSuffix; | |
| 3503 | - this.$altInput.val(altFormattedDateTime); | |
| 3504 | - } else { | |
| 3505 | - this.$input.val(formattedDateTime); | |
| 3506 | - } | |
| 3507 | - | |
| 3508 | - this.$input.trigger("change"); | |
| 3509 | - }, | |
| 3510 | - | |
| 3511 | - _onFocus: function() { | |
| 3512 | - if (!this.$input.val() && this._defaults.defaultValue) { | |
| 3513 | - this.$input.val(this._defaults.defaultValue); | |
| 3514 | - var inst = $.datepicker._getInst(this.$input.get(0)), | |
| 3515 | - tp_inst = $.datepicker._get(inst, 'timepicker'); | |
| 3516 | - if (tp_inst) { | |
| 3517 | - if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) { | |
| 3518 | - try { | |
| 3519 | - $.datepicker._updateDatepicker(inst); | |
| 3520 | - } catch (err) { | |
| 3521 | - $.timepicker.log(err); | |
| 3522 | - } | |
| 3523 | - } | |
| 3524 | - } | |
| 3525 | - } | |
| 3526 | - }, | |
| 3527 | - | |
| 3528 | - /* | |
| 3529 | - * Small abstraction to control types | |
| 3530 | - * We can add more, just be sure to follow the pattern: create, options, value | |
| 3531 | - */ | |
| 3532 | - _controls: { | |
| 3533 | - // slider methods | |
| 3534 | - slider: { | |
| 3535 | - create: function(tp_inst, obj, unit, val, min, max, step){ | |
| 3536 | - var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60 | |
| 3537 | - return obj.prop('slide', null).slider({ | |
| 3538 | - orientation: "horizontal", | |
| 3539 | - value: rtl? val*-1 : val, | |
| 3540 | - min: rtl? max*-1 : min, | |
| 3541 | - max: rtl? min*-1 : max, | |
| 3542 | - step: step, | |
| 3543 | - slide: function(event, ui) { | |
| 3544 | - tp_inst.control.value(tp_inst, $(this), unit, rtl? ui.value*-1:ui.value); | |
| 3545 | - tp_inst._onTimeChange(); | |
| 3546 | - }, | |
| 3547 | - stop: function(event, ui) { | |
| 3548 | - tp_inst._onSelectHandler(); | |
| 3549 | - } | |
| 3550 | - }); | |
| 3551 | - }, | |
| 3552 | - options: function(tp_inst, obj, unit, opts, val){ | |
| 3553 | - if(tp_inst._defaults.isRTL){ | |
| 3554 | - if(typeof(opts) == 'string'){ | |
| 3555 | - if(opts == 'min' || opts == 'max'){ | |
| 3556 | - if(val !== undefined) | |
| 3557 | - return obj.slider(opts, val*-1); | |
| 3558 | - return Math.abs(obj.slider(opts)); | |
| 3559 | - } | |
| 3560 | - return obj.slider(opts); | |
| 3561 | - } | |
| 3562 | - var min = opts.min, | |
| 3563 | - max = opts.max; | |
| 3564 | - opts.min = opts.max = null; | |
| 3565 | - if(min !== undefined) | |
| 3566 | - opts.max = min * -1; | |
| 3567 | - if(max !== undefined) | |
| 3568 | - opts.min = max * -1; | |
| 3569 | - return obj.slider(opts); | |
| 3570 | - } | |
| 3571 | - if(typeof(opts) == 'string' && val !== undefined) | |
| 3572 | - return obj.slider(opts, val); | |
| 3573 | - return obj.slider(opts); | |
| 3574 | - }, | |
| 3575 | - value: function(tp_inst, obj, unit, val){ | |
| 3576 | - if(tp_inst._defaults.isRTL){ | |
| 3577 | - if(val !== undefined) | |
| 3578 | - return obj.slider('value', val*-1); | |
| 3579 | - return Math.abs(obj.slider('value')); | |
| 3580 | - } | |
| 3581 | - if(val !== undefined) | |
| 3582 | - return obj.slider('value', val); | |
| 3583 | - return obj.slider('value'); | |
| 3584 | - } | |
| 3585 | - }, | |
| 3586 | - // select methods | |
| 3587 | - select: { | |
| 3588 | - create: function(tp_inst, obj, unit, val, min, max, step){ | |
| 3589 | - var sel = '<select class="ui-timepicker-select" data-unit="'+ unit +'" data-min="'+ min +'" data-max="'+ max +'" data-step="'+ step +'">', | |
| 3590 | - ul = tp_inst._defaults.timeFormat.indexOf('t') !== -1? 'toLowerCase':'toUpperCase', | |
| 3591 | - m = 0; | |
| 3592 | - | |
| 3593 | - for(var i=min; i<=max; i+=step){ | |
| 3594 | - sel += '<option value="'+ i +'"'+ (i==val? ' selected':'') +'>'; | |
| 3595 | - if(unit == 'hour' && useAmpm(tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat)) | |
| 3596 | - sel += $.datepicker.formatTime("hh TT", {hour:i}, tp_inst._defaults); | |
| 3597 | - else if(unit == 'millisec' || i >= 10) sel += i; | |
| 3598 | - else sel += '0'+ i.toString(); | |
| 3599 | - sel += '</option>'; | |
| 3600 | - } | |
| 3601 | - sel += '</select>'; | |
| 3602 | - | |
| 3603 | - obj.children('select').remove(); | |
| 3604 | - | |
| 3605 | - $(sel).appendTo(obj).change(function(e){ | |
| 3606 | - tp_inst._onTimeChange(); | |
| 3607 | - tp_inst._onSelectHandler(); | |
| 3608 | - }); | |
| 3609 | - | |
| 3610 | - return obj; | |
| 3611 | - }, | |
| 3612 | - options: function(tp_inst, obj, unit, opts, val){ | |
| 3613 | - var o = {}, | |
| 3614 | - $t = obj.children('select'); | |
| 3615 | - if(typeof(opts) == 'string'){ | |
| 3616 | - if(val === undefined) | |
| 3617 | - return $t.data(opts); | |
| 3618 | - o[opts] = val; | |
| 3619 | - } | |
| 3620 | - else o = opts; | |
| 3621 | - 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')); | |
| 3622 | - }, | |
| 3623 | - value: function(tp_inst, obj, unit, val){ | |
| 3624 | - var $t = obj.children('select'); | |
| 3625 | - if(val !== undefined) | |
| 3626 | - return $t.val(val); | |
| 3627 | - return $t.val(); | |
| 3628 | - } | |
| 3629 | - } | |
| 3630 | - } // end _controls | |
| 3631 | - | |
| 3632 | - }); | |
| 3633 | - | |
| 3634 | - $.fn.extend({ | |
| 3635 | - /* | |
| 3636 | - * shorthand just to use timepicker.. | |
| 3637 | - */ | |
| 3638 | - timepicker: function(o) { | |
| 3639 | - o = o || {}; | |
| 3640 | - var tmp_args = Array.prototype.slice.call(arguments); | |
| 3641 | - | |
| 3642 | - if (typeof o == 'object') { | |
| 3643 | - tmp_args[0] = $.extend(o, { | |
| 3644 | - timeOnly: true | |
| 3645 | - }); | |
| 3646 | - } | |
| 3647 | - | |
| 3648 | - return $(this).each(function() { | |
| 3649 | - $.fn.datetimepicker.apply($(this), tmp_args); | |
| 3650 | - }); | |
| 3651 | - }, | |
| 3652 | - | |
| 3653 | - /* | |
| 3654 | - * extend timepicker to datepicker | |
| 3655 | - */ | |
| 3656 | - datetimepicker: function(o) { | |
| 3657 | - o = o || {}; | |
| 3658 | - var tmp_args = arguments; | |
| 3659 | - | |
| 3660 | - if (typeof(o) == 'string') { | |
| 3661 | - if (o == 'getDate') { | |
| 3662 | - return $.fn.datepicker.apply($(this[0]), tmp_args); | |
| 3663 | - } else { | |
| 3664 | - return this.each(function() { | |
| 3665 | - var $t = $(this); | |
| 3666 | - $t.datepicker.apply($t, tmp_args); | |
| 3667 | - }); | |
| 3668 | - } | |
| 3669 | - } else { | |
| 3670 | - return this.each(function() { | |
| 3671 | - var $t = $(this); | |
| 3672 | - $t.datepicker($.timepicker._newInst($t, o)._defaults); | |
| 3673 | - }); | |
| 3674 | - } | |
| 3675 | - } | |
| 3676 | - }); | |
| 3677 | - | |
| 3678 | - /* | |
| 3679 | - * Public Utility to parse date and time | |
| 3680 | - */ | |
| 3681 | - $.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { | |
| 3682 | - var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings); | |
| 3683 | - if (parseRes.timeObj) { | |
| 3684 | - var t = parseRes.timeObj; | |
| 3685 | - parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec); | |
| 3686 | - } | |
| 3687 | - | |
| 3688 | - return parseRes.date; | |
| 3689 | - }; | |
| 3690 | - | |
| 3691 | - /* | |
| 3692 | - * Public utility to parse time | |
| 3693 | - */ | |
| 3694 | - $.datepicker.parseTime = function(timeFormat, timeString, options) { | |
| 3695 | - var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {}); | |
| 3696 | - | |
| 3697 | - // Strict parse requires the timeString to match the timeFormat exactly | |
| 3698 | - var strictParse = function(f, s, o){ | |
| 3699 | - | |
| 3700 | - // pattern for standard and localized AM/PM markers | |
| 3701 | - var getPatternAmpm = function(amNames, pmNames) { | |
| 3702 | - var markers = []; | |
| 3703 | - if (amNames) { | |
| 3704 | - $.merge(markers, amNames); | |
| 3705 | - } | |
| 3706 | - if (pmNames) { | |
| 3707 | - $.merge(markers, pmNames); | |
| 3708 | - } | |
| 3709 | - markers = $.map(markers, function(val) { | |
| 3710 | - return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); | |
| 3711 | - }); | |
| 3712 | - return '(' + markers.join('|') + ')?'; | |
| 3713 | - }; | |
| 3714 | - | |
| 3715 | - // figure out position of time elements.. cause js cant do named captures | |
| 3716 | - var getFormatPositions = function(timeFormat) { | |
| 3717 | - var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g), | |
| 3718 | - orders = { | |
| 3719 | - h: -1, | |
| 3720 | - m: -1, | |
| 3721 | - s: -1, | |
| 3722 | - l: -1, | |
| 3723 | - t: -1, | |
| 3724 | - z: -1 | |
| 3725 | - }; | |
| 3726 | - | |
| 3727 | - if (finds) { | |
| 3728 | - for (var i = 0; i < finds.length; i++) { | |
| 3729 | - if (orders[finds[i].toString().charAt(0)] == -1) { | |
| 3730 | - orders[finds[i].toString().charAt(0)] = i + 1; | |
| 3731 | - } | |
| 3732 | - } | |
| 3733 | - } | |
| 3734 | - return orders; | |
| 3735 | - }; | |
| 3736 | - | |
| 3737 | - var regstr = '^' + f.toString() | |
| 3738 | - .replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function (match) { | |
| 3739 | - var ml = match.length; | |
| 3740 | - switch (match.charAt(0).toLowerCase()) { | |
| 3741 | - case 'h': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; | |
| 3742 | - case 'm': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; | |
| 3743 | - case 's': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; | |
| 3744 | - case 'l': return '(\\d?\\d?\\d)'; | |
| 3745 | - case 'z': return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?'; | |
| 3746 | - case 't': return getPatternAmpm(o.amNames, o.pmNames); | |
| 3747 | - default: // literal escaped in quotes | |
| 3748 | - return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?'; | |
| 3749 | - } | |
| 3750 | - }) | |
| 3751 | - .replace(/\s/g, '\\s?') + | |
| 3752 | - o.timeSuffix + '$', | |
| 3753 | - order = getFormatPositions(f), | |
| 3754 | - ampm = '', | |
| 3755 | - treg; | |
| 3756 | - | |
| 3757 | - treg = s.match(new RegExp(regstr, 'i')); | |
| 3758 | - | |
| 3759 | - var resTime = { | |
| 3760 | - hour: 0, | |
| 3761 | - minute: 0, | |
| 3762 | - second: 0, | |
| 3763 | - millisec: 0 | |
| 3764 | - }; | |
| 3765 | - | |
| 3766 | - if (treg) { | |
| 3767 | - if (order.t !== -1) { | |
| 3768 | - if (treg[order.t] === undefined || treg[order.t].length === 0) { | |
| 3769 | - ampm = ''; | |
| 3770 | - resTime.ampm = ''; | |
| 3771 | - } else { | |
| 3772 | - ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM'; | |
| 3773 | - resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0]; | |
| 3774 | - } | |
| 3775 | - } | |
| 3776 | - | |
| 3777 | - if (order.h !== -1) { | |
| 3778 | - if (ampm == 'AM' && treg[order.h] == '12') { | |
| 3779 | - resTime.hour = 0; // 12am = 0 hour | |
| 3780 | - } else { | |
| 3781 | - if (ampm == 'PM' && treg[order.h] != '12') { | |
| 3782 | - resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12 | |
| 3783 | - } else { | |
| 3784 | - resTime.hour = Number(treg[order.h]); | |
| 3785 | - } | |
| 3786 | - } | |
| 3787 | - } | |
| 3788 | - | |
| 3789 | - if (order.m !== -1) { | |
| 3790 | - resTime.minute = Number(treg[order.m]); | |
| 3791 | - } | |
| 3792 | - if (order.s !== -1) { | |
| 3793 | - resTime.second = Number(treg[order.s]); | |
| 3794 | - } | |
| 3795 | - if (order.l !== -1) { | |
| 3796 | - resTime.millisec = Number(treg[order.l]); | |
| 3797 | - } | |
| 3798 | - if (order.z !== -1 && treg[order.z] !== undefined) { | |
| 3799 | - var tz = treg[order.z].toUpperCase(); | |
| 3800 | - switch (tz.length) { | |
| 3801 | - case 1: | |
| 3802 | - // Z | |
| 3803 | - tz = o.timezoneIso8601 ? 'Z' : '+0000'; | |
| 3804 | - break; | |
| 3805 | - case 5: | |
| 3806 | - // +hhmm | |
| 3807 | - if (o.timezoneIso8601) { | |
| 3808 | - tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3); | |
| 3809 | - } | |
| 3810 | - break; | |
| 3811 | - case 6: | |
| 3812 | - // +hh:mm | |
| 3813 | - if (!o.timezoneIso8601) { | |
| 3814 | - tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, ''); | |
| 3815 | - } else { | |
| 3816 | - if (tz.substring(1) == '00:00') { | |
| 3817 | - tz = 'Z'; | |
| 3818 | - } | |
| 3819 | - } | |
| 3820 | - break; | |
| 3821 | - } | |
| 3822 | - resTime.timezone = tz; | |
| 3823 | - } | |
| 3824 | - | |
| 3825 | - | |
| 3826 | - return resTime; | |
| 3827 | - } | |
| 3828 | - return false; | |
| 3829 | - };// end strictParse | |
| 3830 | - | |
| 3831 | - // First try JS Date, if that fails, use strictParse | |
| 3832 | - var looseParse = function(f,s,o){ | |
| 3833 | - try{ | |
| 3834 | - var d = new Date('2012-01-01 '+ s); | |
| 3835 | - if(isNaN(d.getTime())){ | |
| 3836 | - d = new Date('2012-01-01T'+ s); | |
| 3837 | - if(isNaN(d.getTime())){ | |
| 3838 | - d = new Date('01/01/2012 '+ s); | |
| 3839 | - if(isNaN(d.getTime())){ | |
| 3840 | - throw "Unable to parse time with native Date: "+ s; | |
| 3841 | - } | |
| 3842 | - } | |
| 3843 | - } | |
| 3844 | - | |
| 3845 | - return { | |
| 3846 | - hour: d.getHours(), | |
| 3847 | - minute: d.getMinutes(), | |
| 3848 | - second: d.getSeconds(), | |
| 3849 | - millisec: d.getMilliseconds(), | |
| 3850 | - timezone: $.timepicker.timeZoneOffsetString(d) | |
| 3851 | - }; | |
| 3852 | - } | |
| 3853 | - catch(err){ | |
| 3854 | - try{ | |
| 3855 | - return strictParse(f,s,o); | |
| 3856 | - } | |
| 3857 | - catch(err2){ | |
| 3858 | - $.timepicker.log("Unable to parse \ntimeString: "+ s +"\ntimeFormat: "+ f); | |
| 3859 | - } | |
| 3860 | - } | |
| 3861 | - return false; | |
| 3862 | - }; // end looseParse | |
| 3863 | - | |
| 3864 | - if(typeof o.parse === "function"){ | |
| 3865 | - return o.parse(timeFormat, timeString, o) | |
| 3866 | - } | |
| 3867 | - if(o.parse === 'loose'){ | |
| 3868 | - return looseParse(timeFormat, timeString, o); | |
| 3869 | - } | |
| 3870 | - return strictParse(timeFormat, timeString, o); | |
| 3871 | - }; | |
| 3872 | - | |
| 3873 | - /* | |
| 3874 | - * Public utility to format the time | |
| 3875 | - * format = string format of the time | |
| 3876 | - * time = a {}, not a Date() for timezones | |
| 3877 | - * options = essentially the regional[].. amNames, pmNames, ampm | |
| 3878 | - */ | |
| 3879 | - $.datepicker.formatTime = function(format, time, options) { | |
| 3880 | - options = options || {}; | |
| 3881 | - options = $.extend({}, $.timepicker._defaults, options); | |
| 3882 | - time = $.extend({ | |
| 3883 | - hour: 0, | |
| 3884 | - minute: 0, | |
| 3885 | - second: 0, | |
| 3886 | - millisec: 0, | |
| 3887 | - timezone: '+0000' | |
| 3888 | - }, time); | |
| 3889 | - | |
| 3890 | - var tmptime = format, | |
| 3891 | - ampmName = options.amNames[0], | |
| 3892 | - hour = parseInt(time.hour, 10); | |
| 3893 | - | |
| 3894 | - if (hour > 11) { | |
| 3895 | - ampmName = options.pmNames[0]; | |
| 3896 | - } | |
| 3897 | - | |
| 3898 | - tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) { | |
| 3899 | - switch (match) { | |
| 3900 | - case 'HH': | |
| 3901 | - return ('0' + hour).slice(-2); | |
| 3902 | - case 'H': | |
| 3903 | - return hour; | |
| 3904 | - case 'hh': | |
| 3905 | - return ('0' + convert24to12(hour)).slice(-2); | |
| 3906 | - case 'h': | |
| 3907 | - return convert24to12(hour); | |
| 3908 | - case 'mm': | |
| 3909 | - return ('0' + time.minute).slice(-2); | |
| 3910 | - case 'm': | |
| 3911 | - return time.minute; | |
| 3912 | - case 'ss': | |
| 3913 | - return ('0' + time.second).slice(-2); | |
| 3914 | - case 's': | |
| 3915 | - return time.second; | |
| 3916 | - case 'l': | |
| 3917 | - return ('00' + time.millisec).slice(-3); | |
| 3918 | - case 'z': | |
| 3919 | - return time.timezone === null? options.defaultTimezone : time.timezone; | |
| 3920 | - case 'T': | |
| 3921 | - return ampmName.charAt(0).toUpperCase(); | |
| 3922 | - case 'TT': | |
| 3923 | - return ampmName.toUpperCase(); | |
| 3924 | - case 't': | |
| 3925 | - return ampmName.charAt(0).toLowerCase(); | |
| 3926 | - case 'tt': | |
| 3927 | - return ampmName.toLowerCase(); | |
| 3928 | - default: | |
| 3929 | - return match.replace(/\'/g, "") || "'"; | |
| 3930 | - } | |
| 3931 | - }); | |
| 3932 | - | |
| 3933 | - tmptime = $.trim(tmptime); | |
| 3934 | - return tmptime; | |
| 3935 | - }; | |
| 3936 | - | |
| 3937 | - /* | |
| 3938 | - * the bad hack :/ override datepicker so it doesnt close on select | |
| 3939 | - // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378 | |
| 3940 | - */ | |
| 3941 | - $.datepicker._base_selectDate = $.datepicker._selectDate; | |
| 3942 | - $.datepicker._selectDate = function(id, dateStr) { | |
| 3943 | - var inst = this._getInst($(id)[0]), | |
| 3944 | - tp_inst = this._get(inst, 'timepicker'); | |
| 3945 | - | |
| 3946 | - if (tp_inst) { | |
| 3947 | - tp_inst._limitMinMaxDateTime(inst, true); | |
| 3948 | - inst.inline = inst.stay_open = true; | |
| 3949 | - //This way the onSelect handler called from calendarpicker get the full dateTime | |
| 3950 | - this._base_selectDate(id, dateStr); | |
| 3951 | - inst.inline = inst.stay_open = false; | |
| 3952 | - this._notifyChange(inst); | |
| 3953 | - this._updateDatepicker(inst); | |
| 3954 | - } else { | |
| 3955 | - this._base_selectDate(id, dateStr); | |
| 3956 | - } | |
| 3957 | - }; | |
| 3958 | - | |
| 3959 | - /* | |
| 3960 | - * second bad hack :/ override datepicker so it triggers an event when changing the input field | |
| 3961 | - * and does not redraw the datepicker on every selectDate event | |
| 3962 | - */ | |
| 3963 | - $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker; | |
| 3964 | - $.datepicker._updateDatepicker = function(inst) { | |
| 3965 | - | |
| 3966 | - // don't popup the datepicker if there is another instance already opened | |
| 3967 | - var input = inst.input[0]; | |
| 3968 | - if ($.datepicker._curInst && $.datepicker._curInst != inst && $.datepicker._datepickerShowing && $.datepicker._lastInput != input) { | |
| 3969 | - return; | |
| 3970 | - } | |
| 3971 | - | |
| 3972 | - if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) { | |
| 3973 | - | |
| 3974 | - this._base_updateDatepicker(inst); | |
| 3975 | - | |
| 3976 | - // Reload the time control when changing something in the input text field. | |
| 3977 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 3978 | - if (tp_inst) { | |
| 3979 | - tp_inst._addTimePicker(inst); | |
| 3980 | - | |
| 3981 | -// if (tp_inst._defaults.useLocalTimezone) { //checks daylight saving with the new date. | |
| 3982 | -// var date = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay, 12); | |
| 3983 | -// selectLocalTimeZone(tp_inst, date); | |
| 3984 | -// tp_inst._onTimeChange(); | |
| 3985 | -// } | |
| 3986 | - } | |
| 3987 | - } | |
| 3988 | - }; | |
| 3989 | - | |
| 3990 | - /* | |
| 3991 | - * third bad hack :/ override datepicker so it allows spaces and colon in the input field | |
| 3992 | - */ | |
| 3993 | - $.datepicker._base_doKeyPress = $.datepicker._doKeyPress; | |
| 3994 | - $.datepicker._doKeyPress = function(event) { | |
| 3995 | - var inst = $.datepicker._getInst(event.target), | |
| 3996 | - tp_inst = $.datepicker._get(inst, 'timepicker'); | |
| 3997 | - | |
| 3998 | - if (tp_inst) { | |
| 3999 | - if ($.datepicker._get(inst, 'constrainInput')) { | |
| 4000 | - var ampm = useAmpm(tp_inst._defaults.timeFormat), | |
| 4001 | - dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')), | |
| 4002 | - datetimeChars = tp_inst._defaults.timeFormat.toString() | |
| 4003 | - .replace(/[hms]/g, '') | |
| 4004 | - .replace(/TT/g, ampm ? 'APM' : '') | |
| 4005 | - .replace(/Tt/g, ampm ? 'AaPpMm' : '') | |
| 4006 | - .replace(/tT/g, ampm ? 'AaPpMm' : '') | |
| 4007 | - .replace(/T/g, ampm ? 'AP' : '') | |
| 4008 | - .replace(/tt/g, ampm ? 'apm' : '') | |
| 4009 | - .replace(/t/g, ampm ? 'ap' : '') + | |
| 4010 | - " " + tp_inst._defaults.separator + | |
| 4011 | - tp_inst._defaults.timeSuffix + | |
| 4012 | - (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') + | |
| 4013 | - (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) + | |
| 4014 | - dateChars, | |
| 4015 | - chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode); | |
| 4016 | - return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1); | |
| 4017 | - } | |
| 4018 | - } | |
| 4019 | - | |
| 4020 | - return $.datepicker._base_doKeyPress(event); | |
| 4021 | - }; | |
| 4022 | - | |
| 4023 | - /* | |
| 4024 | - * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField | |
| 4025 | - */ | |
| 4026 | - $.datepicker._base_updateAlternate = $.datepicker._updateAlternate; | |
| 4027 | - /* Update any alternate field to synchronise with the main field. */ | |
| 4028 | - $.datepicker._updateAlternate = function(inst) { | |
| 4029 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4030 | - if(tp_inst){ | |
| 4031 | - var altField = tp_inst._defaults.altField; | |
| 4032 | - if (altField) { // update alternate field too | |
| 4033 | - var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat, | |
| 4034 | - date = this._getDate(inst), | |
| 4035 | - formatCfg = $.datepicker._getFormatConfig(inst), | |
| 4036 | - altFormattedDateTime = '', | |
| 4037 | - altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator, | |
| 4038 | - altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix, | |
| 4039 | - altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat; | |
| 4040 | - | |
| 4041 | - altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix; | |
| 4042 | - if(!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null){ | |
| 4043 | - if(tp_inst._defaults.altFormat) | |
| 4044 | - altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime; | |
| 4045 | - else altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime; | |
| 4046 | - } | |
| 4047 | - $(altField).val(altFormattedDateTime); | |
| 4048 | - } | |
| 4049 | - } | |
| 4050 | - else{ | |
| 4051 | - $.datepicker._base_updateAlternate(inst); | |
| 4052 | - } | |
| 4053 | - }; | |
| 4054 | - | |
| 4055 | - /* | |
| 4056 | - * Override key up event to sync manual input changes. | |
| 4057 | - */ | |
| 4058 | - $.datepicker._base_doKeyUp = $.datepicker._doKeyUp; | |
| 4059 | - $.datepicker._doKeyUp = function(event) { | |
| 4060 | - var inst = $.datepicker._getInst(event.target), | |
| 4061 | - tp_inst = $.datepicker._get(inst, 'timepicker'); | |
| 4062 | - | |
| 4063 | - if (tp_inst) { | |
| 4064 | - if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) { | |
| 4065 | - try { | |
| 4066 | - $.datepicker._updateDatepicker(inst); | |
| 4067 | - } catch (err) { | |
| 4068 | - $.timepicker.log(err); | |
| 4069 | - } | |
| 4070 | - } | |
| 4071 | - } | |
| 4072 | - | |
| 4073 | - return $.datepicker._base_doKeyUp(event); | |
| 4074 | - }; | |
| 4075 | - | |
| 4076 | - /* | |
| 4077 | - * override "Today" button to also grab the time. | |
| 4078 | - */ | |
| 4079 | - $.datepicker._base_gotoToday = $.datepicker._gotoToday; | |
| 4080 | - $.datepicker._gotoToday = function(id) { | |
| 4081 | - var inst = this._getInst($(id)[0]), | |
| 4082 | - $dp = inst.dpDiv; | |
| 4083 | - this._base_gotoToday(id); | |
| 4084 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4085 | - selectLocalTimeZone(tp_inst); | |
| 4086 | - var now = new Date(); | |
| 4087 | - this._setTime(inst, now); | |
| 4088 | - $('.ui-datepicker-today', $dp).click(); | |
| 4089 | - }; | |
| 4090 | - | |
| 4091 | - /* | |
| 4092 | - * Disable & enable the Time in the datetimepicker | |
| 4093 | - */ | |
| 4094 | - $.datepicker._disableTimepickerDatepicker = function(target) { | |
| 4095 | - var inst = this._getInst(target); | |
| 4096 | - if (!inst) { | |
| 4097 | - return; | |
| 4098 | - } | |
| 4099 | - | |
| 4100 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4101 | - $(target).datepicker('getDate'); // Init selected[Year|Month|Day] | |
| 4102 | - if (tp_inst) { | |
| 4103 | - tp_inst._defaults.showTimepicker = false; | |
| 4104 | - tp_inst._updateDateTime(inst); | |
| 4105 | - } | |
| 4106 | - }; | |
| 4107 | - | |
| 4108 | - $.datepicker._enableTimepickerDatepicker = function(target) { | |
| 4109 | - var inst = this._getInst(target); | |
| 4110 | - if (!inst) { | |
| 4111 | - return; | |
| 4112 | - } | |
| 4113 | - | |
| 4114 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4115 | - $(target).datepicker('getDate'); // Init selected[Year|Month|Day] | |
| 4116 | - if (tp_inst) { | |
| 4117 | - tp_inst._defaults.showTimepicker = true; | |
| 4118 | - tp_inst._addTimePicker(inst); // Could be disabled on page load | |
| 4119 | - tp_inst._updateDateTime(inst); | |
| 4120 | - } | |
| 4121 | - }; | |
| 4122 | - | |
| 4123 | - /* | |
| 4124 | - * Create our own set time function | |
| 4125 | - */ | |
| 4126 | - $.datepicker._setTime = function(inst, date) { | |
| 4127 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4128 | - if (tp_inst) { | |
| 4129 | - var defaults = tp_inst._defaults; | |
| 4130 | - | |
| 4131 | - // calling _setTime with no date sets time to defaults | |
| 4132 | - tp_inst.hour = date ? date.getHours() : defaults.hour; | |
| 4133 | - tp_inst.minute = date ? date.getMinutes() : defaults.minute; | |
| 4134 | - tp_inst.second = date ? date.getSeconds() : defaults.second; | |
| 4135 | - tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec; | |
| 4136 | - | |
| 4137 | - //check if within min/max times.. | |
| 4138 | - tp_inst._limitMinMaxDateTime(inst, true); | |
| 4139 | - | |
| 4140 | - tp_inst._onTimeChange(); | |
| 4141 | - tp_inst._updateDateTime(inst); | |
| 4142 | - } | |
| 4143 | - }; | |
| 4144 | - | |
| 4145 | - /* | |
| 4146 | - * Create new public method to set only time, callable as $().datepicker('setTime', date) | |
| 4147 | - */ | |
| 4148 | - $.datepicker._setTimeDatepicker = function(target, date, withDate) { | |
| 4149 | - var inst = this._getInst(target); | |
| 4150 | - if (!inst) { | |
| 4151 | - return; | |
| 4152 | - } | |
| 4153 | - | |
| 4154 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4155 | - | |
| 4156 | - if (tp_inst) { | |
| 4157 | - this._setDateFromField(inst); | |
| 4158 | - var tp_date; | |
| 4159 | - if (date) { | |
| 4160 | - if (typeof date == "string") { | |
| 4161 | - tp_inst._parseTime(date, withDate); | |
| 4162 | - tp_date = new Date(); | |
| 4163 | - tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); | |
| 4164 | - } else { | |
| 4165 | - tp_date = new Date(date.getTime()); | |
| 4166 | - } | |
| 4167 | - if (tp_date.toString() == 'Invalid Date') { | |
| 4168 | - tp_date = undefined; | |
| 4169 | - } | |
| 4170 | - this._setTime(inst, tp_date); | |
| 4171 | - } | |
| 4172 | - } | |
| 4173 | - | |
| 4174 | - }; | |
| 4175 | - | |
| 4176 | - /* | |
| 4177 | - * override setDate() to allow setting time too within Date object | |
| 4178 | - */ | |
| 4179 | - $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker; | |
| 4180 | - $.datepicker._setDateDatepicker = function(target, date) { | |
| 4181 | - var inst = this._getInst(target); | |
| 4182 | - if (!inst) { | |
| 4183 | - return; | |
| 4184 | - } | |
| 4185 | - | |
| 4186 | - var tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; | |
| 4187 | - | |
| 4188 | - this._updateDatepicker(inst); | |
| 4189 | - this._base_setDateDatepicker.apply(this, arguments); | |
| 4190 | - this._setTimeDatepicker(target, tp_date, true); | |
| 4191 | - }; | |
| 4192 | - | |
| 4193 | - /* | |
| 4194 | - * override getDate() to allow getting time too within Date object | |
| 4195 | - */ | |
| 4196 | - $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker; | |
| 4197 | - $.datepicker._getDateDatepicker = function(target, noDefault) { | |
| 4198 | - var inst = this._getInst(target); | |
| 4199 | - if (!inst) { | |
| 4200 | - return; | |
| 4201 | - } | |
| 4202 | - | |
| 4203 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4204 | - | |
| 4205 | - if (tp_inst) { | |
| 4206 | - // if it hasn't yet been defined, grab from field | |
| 4207 | - if(inst.lastVal === undefined){ | |
| 4208 | - this._setDateFromField(inst, noDefault); | |
| 4209 | - } | |
| 4210 | - | |
| 4211 | - var date = this._getDate(inst); | |
| 4212 | - if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) { | |
| 4213 | - date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); | |
| 4214 | - } | |
| 4215 | - return date; | |
| 4216 | - } | |
| 4217 | - return this._base_getDateDatepicker(target, noDefault); | |
| 4218 | - }; | |
| 4219 | - | |
| 4220 | - /* | |
| 4221 | - * override parseDate() because UI 1.8.14 throws an error about "Extra characters" | |
| 4222 | - * An option in datapicker to ignore extra format characters would be nicer. | |
| 4223 | - */ | |
| 4224 | - $.datepicker._base_parseDate = $.datepicker.parseDate; | |
| 4225 | - $.datepicker.parseDate = function(format, value, settings) { | |
| 4226 | - var date; | |
| 4227 | - try { | |
| 4228 | - date = this._base_parseDate(format, value, settings); | |
| 4229 | - } catch (err) { | |
| 4230 | - // Hack! The error message ends with a colon, a space, and | |
| 4231 | - // the "extra" characters. We rely on that instead of | |
| 4232 | - // attempting to perfectly reproduce the parsing algorithm. | |
| 4233 | - date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings); | |
| 4234 | - $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format); | |
| 4235 | - } | |
| 4236 | - return date; | |
| 4237 | - }; | |
| 4238 | - | |
| 4239 | - /* | |
| 4240 | - * override formatDate to set date with time to the input | |
| 4241 | - */ | |
| 4242 | - $.datepicker._base_formatDate = $.datepicker._formatDate; | |
| 4243 | - $.datepicker._formatDate = function(inst, day, month, year) { | |
| 4244 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4245 | - if (tp_inst) { | |
| 4246 | - tp_inst._updateDateTime(inst); | |
| 4247 | - return tp_inst.$input.val(); | |
| 4248 | - } | |
| 4249 | - return this._base_formatDate(inst); | |
| 4250 | - }; | |
| 4251 | - | |
| 4252 | - /* | |
| 4253 | - * override options setter to add time to maxDate(Time) and minDate(Time). MaxDate | |
| 4254 | - */ | |
| 4255 | - $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker; | |
| 4256 | - $.datepicker._optionDatepicker = function(target, name, value) { | |
| 4257 | - var inst = this._getInst(target), | |
| 4258 | - name_clone; | |
| 4259 | - if (!inst) { | |
| 4260 | - return null; | |
| 4261 | - } | |
| 4262 | - | |
| 4263 | - var tp_inst = this._get(inst, 'timepicker'); | |
| 4264 | - if (tp_inst) { | |
| 4265 | - var min = null, | |
| 4266 | - max = null, | |
| 4267 | - onselect = null, | |
| 4268 | - overrides = tp_inst._defaults.evnts, | |
| 4269 | - fns = {}, | |
| 4270 | - prop; | |
| 4271 | - if (typeof name == 'string') { // if min/max was set with the string | |
| 4272 | - if (name === 'minDate' || name === 'minDateTime') { | |
| 4273 | - min = value; | |
| 4274 | - } else if (name === 'maxDate' || name === 'maxDateTime') { | |
| 4275 | - max = value; | |
| 4276 | - } else if (name === 'onSelect') { | |
| 4277 | - onselect = value; | |
| 4278 | - } else if (overrides.hasOwnProperty(name)) { | |
| 4279 | - if (typeof (value) === 'undefined') { | |
| 4280 | - return overrides[name]; | |
| 4281 | - } | |
| 4282 | - fns[name] = value; | |
| 4283 | - name_clone = {}; //empty results in exiting function after overrides updated | |
| 4284 | - } | |
| 4285 | - } else if (typeof name == 'object') { //if min/max was set with the JSON | |
| 4286 | - if (name.minDate) { | |
| 4287 | - min = name.minDate; | |
| 4288 | - } else if (name.minDateTime) { | |
| 4289 | - min = name.minDateTime; | |
| 4290 | - } else if (name.maxDate) { | |
| 4291 | - max = name.maxDate; | |
| 4292 | - } else if (name.maxDateTime) { | |
| 4293 | - max = name.maxDateTime; | |
| 4294 | - } | |
| 4295 | - for (prop in overrides) { | |
| 4296 | - if (overrides.hasOwnProperty(prop) && name[prop]) { | |
| 4297 | - fns[prop] = name[prop]; | |
| 4298 | - } | |
| 4299 | - } | |
| 4300 | - } | |
| 4301 | - for (prop in fns) { | |
| 4302 | - if (fns.hasOwnProperty(prop)) { | |
| 4303 | - overrides[prop] = fns[prop]; | |
| 4304 | - if (!name_clone) { name_clone = $.extend({}, name);} | |
| 4305 | - delete name_clone[prop]; | |
| 4306 | - } | |
| 4307 | - } | |
| 4308 | - if (name_clone && isEmptyObject(name_clone)) { return; } | |
| 4309 | - if (min) { //if min was set | |
| 4310 | - if (min === 0) { | |
| 4311 | - min = new Date(); | |
| 4312 | - } else { | |
| 4313 | - min = new Date(min); | |
| 4314 | - } | |
| 4315 | - tp_inst._defaults.minDate = min; | |
| 4316 | - tp_inst._defaults.minDateTime = min; | |
| 4317 | - } else if (max) { //if max was set | |
| 4318 | - if (max === 0) { | |
| 4319 | - max = new Date(); | |
| 4320 | - } else { | |
| 4321 | - max = new Date(max); | |
| 4322 | - } | |
| 4323 | - tp_inst._defaults.maxDate = max; | |
| 4324 | - tp_inst._defaults.maxDateTime = max; | |
| 4325 | - } else if (onselect) { | |
| 4326 | - tp_inst._defaults.onSelect = onselect; | |
| 4327 | - } | |
| 4328 | - } | |
| 4329 | - if (value === undefined) { | |
| 4330 | - return this._base_optionDatepicker.call($.datepicker, target, name); | |
| 4331 | - } | |
| 4332 | - return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value); | |
| 4333 | - }; | |
| 4334 | - /* | |
| 4335 | - * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype, | |
| 4336 | - * it will return false for all objects | |
| 4337 | - */ | |
| 4338 | - var isEmptyObject = function(obj) { | |
| 4339 | - var prop; | |
| 4340 | - for (prop in obj) { | |
| 4341 | - if (obj.hasOwnProperty(obj)) { | |
| 4342 | - return false; | |
| 4343 | - } | |
| 4344 | - } | |
| 4345 | - return true; | |
| 4346 | - }; | |
| 4347 | - | |
| 4348 | - /* | |
| 4349 | - * jQuery extend now ignores nulls! | |
| 4350 | - */ | |
| 4351 | - var extendRemove = function(target, props) { | |
| 4352 | - $.extend(target, props); | |
| 4353 | - for (var name in props) { | |
| 4354 | - if (props[name] === null || props[name] === undefined) { | |
| 4355 | - target[name] = props[name]; | |
| 4356 | - } | |
| 4357 | - } | |
| 4358 | - return target; | |
| 4359 | - }; | |
| 4360 | - | |
| 4361 | - /* | |
| 4362 | - * Determine by the time format if should use ampm | |
| 4363 | - * Returns true if should use ampm, false if not | |
| 4364 | - */ | |
| 4365 | - var useAmpm = function(timeFormat){ | |
| 4366 | - return (timeFormat.indexOf('t') !== -1 && timeFormat.indexOf('h') !== -1); | |
| 4367 | - }; | |
| 4368 | - | |
| 4369 | - /* | |
| 4370 | - * Converts 24 hour format into 12 hour | |
| 4371 | - * Returns 12 hour without leading 0 | |
| 4372 | - */ | |
| 4373 | - var convert24to12 = function(hour) { | |
| 4374 | - if (hour > 12) { | |
| 4375 | - hour = hour - 12; | |
| 4376 | - } | |
| 4377 | - | |
| 4378 | - if (hour == 0) { | |
| 4379 | - hour = 12; | |
| 4380 | - } | |
| 4381 | - | |
| 4382 | - return String(hour); | |
| 4383 | - }; | |
| 4384 | - | |
| 4385 | - /* | |
| 4386 | - * Splits datetime string into date ans time substrings. | |
| 4387 | - * Throws exception when date can't be parsed | |
| 4388 | - * Returns [dateString, timeString] | |
| 4389 | - */ | |
| 4390 | - var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) { | |
| 4391 | - try { | |
| 4392 | - // The idea is to get the number separator occurances in datetime and the time format requested (since time has | |
| 4393 | - // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split. | |
| 4394 | - var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator, | |
| 4395 | - format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat, | |
| 4396 | - timeParts = format.split(separator), // how many occurances of separator may be in our format? | |
| 4397 | - timePartsLen = timeParts.length, | |
| 4398 | - allParts = dateTimeString.split(separator), | |
| 4399 | - allPartsLen = allParts.length; | |
| 4400 | - | |
| 4401 | - if (allPartsLen > 1) { | |
| 4402 | - return [ | |
| 4403 | - allParts.splice(0,allPartsLen-timePartsLen).join(separator), | |
| 4404 | - allParts.splice(0,timePartsLen).join(separator) | |
| 4405 | - ]; | |
| 4406 | - } | |
| 4407 | - | |
| 4408 | - } catch (err) { | |
| 4409 | - $.timepicker.log('Could not split the date from the time. Please check the following datetimepicker options' + | |
| 4410 | - "\nthrown error: " + err + | |
| 4411 | - "\ndateTimeString" + dateTimeString + | |
| 4412 | - "\ndateFormat = " + dateFormat + | |
| 4413 | - "\nseparator = " + timeSettings.separator + | |
| 4414 | - "\ntimeFormat = " + timeSettings.timeFormat); | |
| 4415 | - | |
| 4416 | - if (err.indexOf(":") >= 0) { | |
| 4417 | - // Hack! The error message ends with a colon, a space, and | |
| 4418 | - // the "extra" characters. We rely on that instead of | |
| 4419 | - // attempting to perfectly reproduce the parsing algorithm. | |
| 4420 | - var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2), | |
| 4421 | - timeString = dateTimeString.substring(dateStringLength); | |
| 4422 | - | |
| 4423 | - return [$.trim(dateTimeString.substring(0, dateStringLength)), $.trim(dateTimeString.substring(dateStringLength))]; | |
| 4424 | - | |
| 4425 | - } else { | |
| 4426 | - throw err; | |
| 4427 | - } | |
| 4428 | - } | |
| 4429 | - return [dateTimeString, '']; | |
| 4430 | - }; | |
| 4431 | - | |
| 4432 | - /* | |
| 4433 | - * Internal function to parse datetime interval | |
| 4434 | - * Returns: {date: Date, timeObj: Object}, where | |
| 4435 | - * date - parsed date without time (type Date) | |
| 4436 | - * timeObj = {hour: , minute: , second: , millisec: } - parsed time. Optional | |
| 4437 | - */ | |
| 4438 | - var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { | |
| 4439 | - var date; | |
| 4440 | - var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings, timeSettings); | |
| 4441 | - date = $.datepicker._base_parseDate(dateFormat, splitRes[0], dateSettings); | |
| 4442 | - if (splitRes[1] !== '') { | |
| 4443 | - var timeString = splitRes[1], | |
| 4444 | - parsedTime = $.datepicker.parseTime(timeFormat, timeString, timeSettings); | |
| 4445 | - | |
| 4446 | - if (parsedTime === null) { | |
| 4447 | - throw 'Wrong time format'; | |
| 4448 | - } | |
| 4449 | - return { | |
| 4450 | - date: date, | |
| 4451 | - timeObj: parsedTime | |
| 4452 | - }; | |
| 4453 | - } else { | |
| 4454 | - return { | |
| 4455 | - date: date | |
| 4456 | - }; | |
| 4457 | - } | |
| 4458 | - }; | |
| 4459 | - | |
| 4460 | - /* | |
| 4461 | - * Internal function to set timezone_select to the local timezone | |
| 4462 | - */ | |
| 4463 | - var selectLocalTimeZone = function(tp_inst, date) { | |
| 4464 | - if (tp_inst && tp_inst.timezone_select) { | |
| 4465 | - tp_inst._defaults.useLocalTimezone = true; | |
| 4466 | - var now = typeof date !== 'undefined' ? date : new Date(); | |
| 4467 | - var tzoffset = $.timepicker.timeZoneOffsetString(now); | |
| 4468 | - if (tp_inst._defaults.timezoneIso8601) { | |
| 4469 | - tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3); | |
| 4470 | - } | |
| 4471 | - tp_inst.timezone_select.val(tzoffset); | |
| 4472 | - } | |
| 4473 | - }; | |
| 4474 | - | |
| 4475 | - /* | |
| 4476 | - * Create a Singleton Insance | |
| 4477 | - */ | |
| 4478 | - $.timepicker = new Timepicker(); | |
| 4479 | - | |
| 4480 | - /** | |
| 4481 | - * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5) | |
| 4482 | - * @param date | |
| 4483 | - * @return string | |
| 4484 | - */ | |
| 4485 | - $.timepicker.timeZoneOffsetString = function(date) { | |
| 4486 | - var off = date.getTimezoneOffset() * -1, | |
| 4487 | - minutes = off % 60, | |
| 4488 | - hours = (off - minutes) / 60; | |
| 4489 | - return (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + ('0' + (minutes * 101).toString()).slice(-2); | |
| 4490 | - }; | |
| 4491 | - | |
| 4492 | - /** | |
| 4493 | - * Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to | |
| 4494 | - * enforce date range limits. | |
| 4495 | - * n.b. The input value must be correctly formatted (reformatting is not supported) | |
| 4496 | - * @param Element startTime | |
| 4497 | - * @param Element endTime | |
| 4498 | - * @param obj options Options for the timepicker() call | |
| 4499 | - * @return jQuery | |
| 4500 | - */ | |
| 4501 | - $.timepicker.timeRange = function(startTime, endTime, options) { | |
| 4502 | - return $.timepicker.handleRange('timepicker', startTime, endTime, options); | |
| 4503 | - }; | |
| 4504 | - | |
| 4505 | - /** | |
| 4506 | - * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to | |
| 4507 | - * enforce date range limits. | |
| 4508 | - * @param Element startTime | |
| 4509 | - * @param Element endTime | |
| 4510 | - * @param obj options Options for the `timepicker()` call. Also supports `reformat`, | |
| 4511 | - * a boolean value that can be used to reformat the input values to the `dateFormat`. | |
| 4512 | - * @param string method Can be used to specify the type of picker to be added | |
| 4513 | - * @return jQuery | |
| 4514 | - */ | |
| 4515 | - $.timepicker.dateTimeRange = function(startTime, endTime, options) { | |
| 4516 | - $.timepicker.dateRange(startTime, endTime, options, 'datetimepicker'); | |
| 4517 | - }; | |
| 4518 | - | |
| 4519 | - /** | |
| 4520 | - * Calls `method` on the `startTime` and `endTime` elements, and configures them to | |
| 4521 | - * enforce date range limits. | |
| 4522 | - * @param Element startTime | |
| 4523 | - * @param Element endTime | |
| 4524 | - * @param obj options Options for the `timepicker()` call. Also supports `reformat`, | |
| 4525 | - * a boolean value that can be used to reformat the input values to the `dateFormat`. | |
| 4526 | - * @param string method Can be used to specify the type of picker to be added | |
| 4527 | - * @return jQuery | |
| 4528 | - */ | |
| 4529 | - $.timepicker.dateRange = function(startTime, endTime, options, method) { | |
| 4530 | - method = method || 'datepicker'; | |
| 4531 | - $.timepicker.handleRange(method, startTime, endTime, options); | |
| 4532 | - }; | |
| 4533 | - | |
| 4534 | - /** | |
| 4535 | - * Calls `method` on the `startTime` and `endTime` elements, and configures them to | |
| 4536 | - * enforce date range limits. | |
| 4537 | - * @param string method Can be used to specify the type of picker to be added | |
| 4538 | - * @param Element startTime | |
| 4539 | - * @param Element endTime | |
| 4540 | - * @param obj options Options for the `timepicker()` call. Also supports `reformat`, | |
| 4541 | - * a boolean value that can be used to reformat the input values to the `dateFormat`. | |
| 4542 | - * @return jQuery | |
| 4543 | - */ | |
| 4544 | - $.timepicker.handleRange = function(method, startTime, endTime, options) { | |
| 4545 | - $.fn[method].call(startTime, $.extend({ | |
| 4546 | - onClose: function(dateText, inst) { | |
| 4547 | - checkDates(this, endTime, dateText); | |
| 4548 | - }, | |
| 4549 | - onSelect: function(selectedDateTime) { | |
| 4550 | - selected(this, endTime, 'minDate'); | |
| 4551 | - } | |
| 4552 | - }, options, options.start)); | |
| 4553 | - $.fn[method].call(endTime, $.extend({ | |
| 4554 | - onClose: function(dateText, inst) { | |
| 4555 | - checkDates(this, startTime, dateText); | |
| 4556 | - }, | |
| 4557 | - onSelect: function(selectedDateTime) { | |
| 4558 | - selected(this, startTime, 'maxDate'); | |
| 4559 | - } | |
| 4560 | - }, options, options.end)); | |
| 4561 | - // timepicker doesn't provide access to its 'timeFormat' option, | |
| 4562 | - // nor could I get datepicker.formatTime() to behave with times, so I | |
| 4563 | - // have disabled reformatting for timepicker | |
| 4564 | - if (method != 'timepicker' && options.reformat) { | |
| 4565 | - $([startTime, endTime]).each(function() { | |
| 4566 | - var format = $(this)[method].call($(this), 'option', 'dateFormat'), | |
| 4567 | - date = new Date($(this).val()); | |
| 4568 | - if ($(this).val() && date) { | |
| 4569 | - $(this).val($.datepicker.formatDate(format, date)); | |
| 4570 | - } | |
| 4571 | - }); | |
| 4572 | - } | |
| 4573 | - checkDates(startTime, endTime, startTime.val()); | |
| 4574 | - | |
| 4575 | - function checkDates(changed, other, dateText) { | |
| 4576 | - if (other.val() && (new Date(startTime.val()) > new Date(endTime.val()))) { | |
| 4577 | - other.val(dateText); | |
| 4578 | - } | |
| 4579 | - } | |
| 4580 | - selected(startTime, endTime, 'minDate'); | |
| 4581 | - selected(endTime, startTime, 'maxDate'); | |
| 4582 | - | |
| 4583 | - function selected(changed, other, option) { | |
| 4584 | - if (!$(changed).val()) { | |
| 4585 | - return; | |
| 4586 | - } | |
| 4587 | - var date = $(changed)[method].call($(changed), 'getDate'); | |
| 4588 | - // timepicker doesn't implement 'getDate' and returns a jQuery | |
| 4589 | - if (date.getTime) { | |
| 4590 | - $(other)[method].call($(other), 'option', option, date); | |
| 4591 | - } | |
| 4592 | - } | |
| 4593 | - return $([startTime.get(0), endTime.get(0)]); | |
| 4594 | - }; | |
| 4595 | - | |
| 4596 | - /** | |
| 4597 | - * Log error or data to the console during error or debugging | |
| 4598 | - * @param Object err pass any type object to log to the console during error or debugging | |
| 4599 | - * @return void | |
| 4600 | - */ | |
| 4601 | - $.timepicker.log = function(err){ | |
| 4602 | - if(window.console) | |
| 4603 | - console.log(err); | |
| 4604 | - }; | |
| 4605 | - | |
| 4606 | - /* | |
| 4607 | - * Keep up with the version | |
| 4608 | - */ | |
| 4609 | - $.timepicker.version = "1.2"; | |
| 4610 | - | |
| 4611 | -})(jQuery); | |
| 2693 | +/* | |
| 2694 | + * jQuery timepicker addon | |
| 2695 | + * By: Trent Richardson [http://trentrichardson.com] | |
| 2696 | + * Version 1.2 | |
| 2697 | + * Last Modified: 02/02/2013 | |
| 2698 | + * | |
| 2699 | + * Copyright 2013 Trent Richardson | |
| 2700 | + * You may use this project under MIT or GPL licenses. | |
| 2701 | + * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt | |
| 2702 | + * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt | |
| 2703 | + */ | |
| 2704 | + | |
| 2705 | +/*jslint evil: true, white: false, undef: false, nomen: false */ | |
| 2706 | + | |
| 2707 | +(function($) { | |
| 2708 | + | |
| 2709 | + /* | |
| 2710 | + * Lets not redefine timepicker, Prevent "Uncaught RangeError: Maximum call stack size exceeded" | |
| 2711 | + */ | |
| 2712 | + $.ui.timepicker = $.ui.timepicker || {}; | |
| 2713 | + if ($.ui.timepicker.version) { | |
| 2714 | + return; | |
| 2715 | + } | |
| 2716 | + | |
| 2717 | + /* | |
| 2718 | + * Extend jQueryUI, get it started with our version number | |
| 2719 | + */ | |
| 2720 | + $.extend($.ui, { | |
| 2721 | + timepicker: { | |
| 2722 | + version: "1.2" | |
| 2723 | + } | |
| 2724 | + }); | |
| 2725 | + | |
| 2726 | + /* | |
| 2727 | + * Timepicker manager. | |
| 2728 | + * Use the singleton instance of this class, $.timepicker, to interact with the time picker. | |
| 2729 | + * Settings for (groups of) time pickers are maintained in an instance object, | |
| 2730 | + * allowing multiple different settings on the same page. | |
| 2731 | + */ | |
| 2732 | + var Timepicker = function() { | |
| 2733 | + this.regional = []; // Available regional settings, indexed by language code | |
| 2734 | + this.regional[''] = { // Default regional settings | |
| 2735 | + currentText: 'Now', | |
| 2736 | + closeText: 'Done', | |
| 2737 | + amNames: ['AM', 'A'], | |
| 2738 | + pmNames: ['PM', 'P'], | |
| 2739 | + timeFormat: 'HH:mm', | |
| 2740 | + timeSuffix: '', | |
| 2741 | + timeOnlyTitle: 'Choose Time', | |
| 2742 | + timeText: 'Time', | |
| 2743 | + hourText: 'Hour', | |
| 2744 | + minuteText: 'Minute', | |
| 2745 | + secondText: 'Second', | |
| 2746 | + millisecText: 'Millisecond', | |
| 2747 | + timezoneText: 'Time Zone', | |
| 2748 | + isRTL: false | |
| 2749 | + }; | |
| 2750 | + this._defaults = { // Global defaults for all the datetime picker instances | |
| 2751 | + showButtonPanel: true, | |
| 2752 | + timeOnly: false, | |
| 2753 | + showHour: true, | |
| 2754 | + showMinute: true, | |
| 2755 | + showSecond: false, | |
| 2756 | + showMillisec: false, | |
| 2757 | + showTimezone: false, | |
| 2758 | + showTime: true, | |
| 2759 | + stepHour: 1, | |
| 2760 | + stepMinute: 1, | |
| 2761 | + stepSecond: 1, | |
| 2762 | + stepMillisec: 1, | |
| 2763 | + hour: 0, | |
| 2764 | + minute: 0, | |
| 2765 | + second: 0, | |
| 2766 | + millisec: 0, | |
| 2767 | + timezone: null, | |
| 2768 | + useLocalTimezone: false, | |
| 2769 | + defaultTimezone: "+0000", | |
| 2770 | + hourMin: 0, | |
| 2771 | + minuteMin: 0, | |
| 2772 | + secondMin: 0, | |
| 2773 | + millisecMin: 0, | |
| 2774 | + hourMax: 23, | |
| 2775 | + minuteMax: 59, | |
| 2776 | + secondMax: 59, | |
| 2777 | + millisecMax: 999, | |
| 2778 | + minDateTime: null, | |
| 2779 | + maxDateTime: null, | |
| 2780 | + onSelect: null, | |
| 2781 | + hourGrid: 0, | |
| 2782 | + minuteGrid: 0, | |
| 2783 | + secondGrid: 0, | |
| 2784 | + millisecGrid: 0, | |
| 2785 | + alwaysSetTime: true, | |
| 2786 | + separator: ' ', | |
| 2787 | + altFieldTimeOnly: true, | |
| 2788 | + altTimeFormat: null, | |
| 2789 | + altSeparator: null, | |
| 2790 | + altTimeSuffix: null, | |
| 2791 | + pickerTimeFormat: null, | |
| 2792 | + pickerTimeSuffix: null, | |
| 2793 | + showTimepicker: true, | |
| 2794 | + timezoneIso8601: false, | |
| 2795 | + timezoneList: null, | |
| 2796 | + addSliderAccess: false, | |
| 2797 | + sliderAccessArgs: null, | |
| 2798 | + controlType: 'slider', | |
| 2799 | + defaultValue: null, | |
| 2800 | + parse: 'strict' | |
| 2801 | + }; | |
| 2802 | + $.extend(this._defaults, this.regional['']); | |
| 2803 | + }; | |
| 2804 | + | |
| 2805 | + $.extend(Timepicker.prototype, { | |
| 2806 | + $input: null, | |
| 2807 | + $altInput: null, | |
| 2808 | + $timeObj: null, | |
| 2809 | + inst: null, | |
| 2810 | + hour_slider: null, | |
| 2811 | + minute_slider: null, | |
| 2812 | + second_slider: null, | |
| 2813 | + millisec_slider: null, | |
| 2814 | + timezone_select: null, | |
| 2815 | + hour: 0, | |
| 2816 | + minute: 0, | |
| 2817 | + second: 0, | |
| 2818 | + millisec: 0, | |
| 2819 | + timezone: null, | |
| 2820 | + defaultTimezone: "+0000", | |
| 2821 | + hourMinOriginal: null, | |
| 2822 | + minuteMinOriginal: null, | |
| 2823 | + secondMinOriginal: null, | |
| 2824 | + millisecMinOriginal: null, | |
| 2825 | + hourMaxOriginal: null, | |
| 2826 | + minuteMaxOriginal: null, | |
| 2827 | + secondMaxOriginal: null, | |
| 2828 | + millisecMaxOriginal: null, | |
| 2829 | + ampm: '', | |
| 2830 | + formattedDate: '', | |
| 2831 | + formattedTime: '', | |
| 2832 | + formattedDateTime: '', | |
| 2833 | + timezoneList: null, | |
| 2834 | + units: ['hour','minute','second','millisec'], | |
| 2835 | + control: null, | |
| 2836 | + | |
| 2837 | + /* | |
| 2838 | + * Override the default settings for all instances of the time picker. | |
| 2839 | + * @param settings object - the new settings to use as defaults (anonymous object) | |
| 2840 | + * @return the manager object | |
| 2841 | + */ | |
| 2842 | + setDefaults: function(settings) { | |
| 2843 | + extendRemove(this._defaults, settings || {}); | |
| 2844 | + return this; | |
| 2845 | + }, | |
| 2846 | + | |
| 2847 | + /* | |
| 2848 | + * Create a new Timepicker instance | |
| 2849 | + */ | |
| 2850 | + _newInst: function($input, o) { | |
| 2851 | + var tp_inst = new Timepicker(), | |
| 2852 | + inlineSettings = {}, | |
| 2853 | + fns = {}, | |
| 2854 | + overrides, i; | |
| 2855 | + | |
| 2856 | + for (var attrName in this._defaults) { | |
| 2857 | + if(this._defaults.hasOwnProperty(attrName)){ | |
| 2858 | + var attrValue = $input.attr('time:' + attrName); | |
| 2859 | + if (attrValue) { | |
| 2860 | + try { | |
| 2861 | + inlineSettings[attrName] = eval(attrValue); | |
| 2862 | + } catch (err) { | |
| 2863 | + inlineSettings[attrName] = attrValue; | |
| 2864 | + } | |
| 2865 | + } | |
| 2866 | + } | |
| 2867 | + } | |
| 2868 | + overrides = { | |
| 2869 | + beforeShow: function (input, dp_inst) { | |
| 2870 | + if ($.isFunction(tp_inst._defaults.evnts.beforeShow)) { | |
| 2871 | + return tp_inst._defaults.evnts.beforeShow.call($input[0], input, dp_inst, tp_inst); | |
| 2872 | + } | |
| 2873 | + }, | |
| 2874 | + onChangeMonthYear: function (year, month, dp_inst) { | |
| 2875 | + // Update the time as well : this prevents the time from disappearing from the $input field. | |
| 2876 | + tp_inst._updateDateTime(dp_inst); | |
| 2877 | + if ($.isFunction(tp_inst._defaults.evnts.onChangeMonthYear)) { | |
| 2878 | + tp_inst._defaults.evnts.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst); | |
| 2879 | + } | |
| 2880 | + }, | |
| 2881 | + onClose: function (dateText, dp_inst) { | |
| 2882 | + if (tp_inst.timeDefined === true && $input.val() !== '') { | |
| 2883 | + tp_inst._updateDateTime(dp_inst); | |
| 2884 | + } | |
| 2885 | + if ($.isFunction(tp_inst._defaults.evnts.onClose)) { | |
| 2886 | + tp_inst._defaults.evnts.onClose.call($input[0], dateText, dp_inst, tp_inst); | |
| 2887 | + } | |
| 2888 | + } | |
| 2889 | + }; | |
| 2890 | + for (i in overrides) { | |
| 2891 | + if (overrides.hasOwnProperty(i)) { | |
| 2892 | + fns[i] = o[i] || null; | |
| 2893 | + } | |
| 2894 | + } | |
| 2895 | + tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, overrides, { | |
| 2896 | + evnts:fns, | |
| 2897 | + timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker'); | |
| 2898 | + }); | |
| 2899 | + tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { | |
| 2900 | + return val.toUpperCase(); | |
| 2901 | + }); | |
| 2902 | + tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { | |
| 2903 | + return val.toUpperCase(); | |
| 2904 | + }); | |
| 2905 | + | |
| 2906 | + // controlType is string - key to our this._controls | |
| 2907 | + if(typeof(tp_inst._defaults.controlType) === 'string'){ | |
| 2908 | + if($.fn[tp_inst._defaults.controlType] === undefined){ | |
| 2909 | + tp_inst._defaults.controlType = 'select'; | |
| 2910 | + } | |
| 2911 | + tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType]; | |
| 2912 | + } | |
| 2913 | + // controlType is an object and must implement create, options, value methods | |
| 2914 | + else{ | |
| 2915 | + tp_inst.control = tp_inst._defaults.controlType; | |
| 2916 | + } | |
| 2917 | + | |
| 2918 | + if (tp_inst._defaults.timezoneList === null) { | |
| 2919 | + var timezoneList = ['-1200', '-1100', '-1000', '-0930', '-0900', '-0800', '-0700', '-0600', '-0500', '-0430', '-0400', '-0330', '-0300', '-0200', '-0100', '+0000', | |
| 2920 | + '+0100', '+0200', '+0300', '+0330', '+0400', '+0430', '+0500', '+0530', '+0545', '+0600', '+0630', '+0700', '+0800', '+0845', '+0900', '+0930', | |
| 2921 | + '+1000', '+1030', '+1100', '+1130', '+1200', '+1245', '+1300', '+1400']; | |
| 2922 | + | |
| 2923 | + if (tp_inst._defaults.timezoneIso8601) { | |
| 2924 | + timezoneList = $.map(timezoneList, function(val) { | |
| 2925 | + return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3)); | |
| 2926 | + }); | |
| 2927 | + } | |
| 2928 | + tp_inst._defaults.timezoneList = timezoneList; | |
| 2929 | + } | |
| 2930 | + | |
| 2931 | + tp_inst.timezone = tp_inst._defaults.timezone; | |
| 2932 | + tp_inst.hour = tp_inst._defaults.hour < tp_inst._defaults.hourMin? tp_inst._defaults.hourMin : | |
| 2933 | + tp_inst._defaults.hour > tp_inst._defaults.hourMax? tp_inst._defaults.hourMax : tp_inst._defaults.hour; | |
| 2934 | + tp_inst.minute = tp_inst._defaults.minute < tp_inst._defaults.minuteMin? tp_inst._defaults.minuteMin : | |
| 2935 | + tp_inst._defaults.minute > tp_inst._defaults.minuteMax? tp_inst._defaults.minuteMax : tp_inst._defaults.minute; | |
| 2936 | + tp_inst.second = tp_inst._defaults.second < tp_inst._defaults.secondMin? tp_inst._defaults.secondMin : | |
| 2937 | + tp_inst._defaults.second > tp_inst._defaults.secondMax? tp_inst._defaults.secondMax : tp_inst._defaults.second; | |
| 2938 | + tp_inst.millisec = tp_inst._defaults.millisec < tp_inst._defaults.millisecMin? tp_inst._defaults.millisecMin : | |
| 2939 | + tp_inst._defaults.millisec > tp_inst._defaults.millisecMax? tp_inst._defaults.millisecMax : tp_inst._defaults.millisec; | |
| 2940 | + tp_inst.ampm = ''; | |
| 2941 | + tp_inst.$input = $input; | |
| 2942 | + | |
| 2943 | + if (o.altField) { | |
| 2944 | + tp_inst.$altInput = $(o.altField).css({ | |
| 2945 | + cursor: 'pointer' | |
| 2946 | + }).focus(function() { | |
| 2947 | + $input.trigger("focus"); | |
| 2948 | + }); | |
| 2949 | + } | |
| 2950 | + | |
| 2951 | + if (tp_inst._defaults.minDate === 0 || tp_inst._defaults.minDateTime === 0) { | |
| 2952 | + tp_inst._defaults.minDate = new Date(); | |
| 2953 | + } | |
| 2954 | + if (tp_inst._defaults.maxDate === 0 || tp_inst._defaults.maxDateTime === 0) { | |
| 2955 | + tp_inst._defaults.maxDate = new Date(); | |
| 2956 | + } | |
| 2957 | + | |
| 2958 | + // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime.. | |
| 2959 | + if (tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date) { | |
| 2960 | + tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime()); | |
| 2961 | + } | |
| 2962 | + if (tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date) { | |
| 2963 | + tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime()); | |
| 2964 | + } | |
| 2965 | + if (tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date) { | |
| 2966 | + tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime()); | |
| 2967 | + } | |
| 2968 | + if (tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date) { | |
| 2969 | + tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime()); | |
| 2970 | + } | |
| 2971 | + tp_inst.$input.bind('focus', function() { | |
| 2972 | + tp_inst._onFocus(); | |
| 2973 | + }); | |
| 2974 | + | |
| 2975 | + return tp_inst; | |
| 2976 | + }, | |
| 2977 | + | |
| 2978 | + /* | |
| 2979 | + * add our sliders to the calendar | |
| 2980 | + */ | |
| 2981 | + _addTimePicker: function(dp_inst) { | |
| 2982 | + var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ? this.$input.val() + ' ' + this.$altInput.val() : this.$input.val(); | |
| 2983 | + | |
| 2984 | + this.timeDefined = this._parseTime(currDT); | |
| 2985 | + this._limitMinMaxDateTime(dp_inst, false); | |
| 2986 | + this._injectTimePicker(); | |
| 2987 | + }, | |
| 2988 | + | |
| 2989 | + /* | |
| 2990 | + * parse the time string from input value or _setTime | |
| 2991 | + */ | |
| 2992 | + _parseTime: function(timeString, withDate) { | |
| 2993 | + if (!this.inst) { | |
| 2994 | + this.inst = $.datepicker._getInst(this.$input[0]); | |
| 2995 | + } | |
| 2996 | + | |
| 2997 | + if (withDate || !this._defaults.timeOnly) { | |
| 2998 | + var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat'); | |
| 2999 | + try { | |
| 3000 | + var parseRes = parseDateTimeInternal(dp_dateFormat, this._defaults.timeFormat, timeString, $.datepicker._getFormatConfig(this.inst), this._defaults); | |
| 3001 | + if (!parseRes.timeObj) { | |
| 3002 | + return false; | |
| 3003 | + } | |
| 3004 | + $.extend(this, parseRes.timeObj); | |
| 3005 | + } catch (err) { | |
| 3006 | + $.timepicker.log("Error parsing the date/time string: " + err + | |
| 3007 | + "\ndate/time string = " + timeString + | |
| 3008 | + "\ntimeFormat = " + this._defaults.timeFormat + | |
| 3009 | + "\ndateFormat = " + dp_dateFormat); | |
| 3010 | + return false; | |
| 3011 | + } | |
| 3012 | + return true; | |
| 3013 | + } else { | |
| 3014 | + var timeObj = $.datepicker.parseTime(this._defaults.timeFormat, timeString, this._defaults); | |
| 3015 | + if (!timeObj) { | |
| 3016 | + return false; | |
| 3017 | + } | |
| 3018 | + $.extend(this, timeObj); | |
| 3019 | + return true; | |
| 3020 | + } | |
| 3021 | + }, | |
| 3022 | + | |
| 3023 | + /* | |
| 3024 | + * generate and inject html for timepicker into ui datepicker | |
| 3025 | + */ | |
| 3026 | + _injectTimePicker: function() { | |
| 3027 | + var $dp = this.inst.dpDiv, | |
| 3028 | + o = this.inst.settings, | |
| 3029 | + tp_inst = this, | |
| 3030 | + litem = '', | |
| 3031 | + uitem = '', | |
| 3032 | + max = {}, | |
| 3033 | + gridSize = {}, | |
| 3034 | + size = null; | |
| 3035 | + | |
| 3036 | + // Prevent displaying twice | |
| 3037 | + if ($dp.find("div.ui-timepicker-div").length === 0 && o.showTimepicker) { | |
| 3038 | + var noDisplay = ' style="display:none;"', | |
| 3039 | + html = '<div class="ui-timepicker-div'+ (o.isRTL? ' ui-timepicker-rtl' : '') +'"><dl>' + '<dt class="ui_tpicker_time_label"' + ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' + | |
| 3040 | + '<dd class="ui_tpicker_time"' + ((o.showTime) ? '' : noDisplay) + '></dd>'; | |
| 3041 | + | |
| 3042 | + // Create the markup | |
| 3043 | + for(var i=0,l=this.units.length; i<l; i++){ | |
| 3044 | + litem = this.units[i]; | |
| 3045 | + uitem = litem.substr(0,1).toUpperCase() + litem.substr(1); | |
| 3046 | + // Added by Peter Medeiros: | |
| 3047 | + // - Figure out what the hour/minute/second max should be based on the step values. | |
| 3048 | + // - Example: if stepMinute is 15, then minMax is 45. | |
| 3049 | + max[litem] = parseInt((o[litem+'Max'] - ((o[litem+'Max'] - o[litem+'Min']) % o['step'+uitem])), 10); | |
| 3050 | + gridSize[litem] = 0; | |
| 3051 | + | |
| 3052 | + html += '<dt class="ui_tpicker_'+ litem +'_label"' + ((o['show'+uitem]) ? '' : noDisplay) + '>' + o[litem +'Text'] + '</dt>' + | |
| 3053 | + '<dd class="ui_tpicker_'+ litem +'"><div class="ui_tpicker_'+ litem +'_slider"' + ((o['show'+uitem]) ? '' : noDisplay) + '></div>'; | |
| 3054 | + | |
| 3055 | + if (o['show'+uitem] && o[litem+'Grid'] > 0) { | |
| 3056 | + html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>'; | |
| 3057 | + | |
| 3058 | + if(litem == 'hour'){ | |
| 3059 | + for (var h = o[litem+'Min']; h <= max[litem]; h += parseInt(o[litem+'Grid'], 10)) { | |
| 3060 | + gridSize[litem]++; | |
| 3061 | + var tmph = $.datepicker.formatTime(useAmpm(o.pickerTimeFormat || o.timeFormat)? 'hht':'HH', {hour:h}, o); | |
| 3062 | + html += '<td data-for="'+litem+'">' + tmph + '</td>'; | |
| 3063 | + } | |
| 3064 | + } | |
| 3065 | + else{ | |
| 3066 | + for (var m = o[litem+'Min']; m <= max[litem]; m += parseInt(o[litem+'Grid'], 10)) { | |
| 3067 | + gridSize[litem]++; | |
| 3068 | + html += '<td data-for="'+litem+'">' + ((m < 10) ? '0' : '') + m + '</td>'; | |
| 3069 | + } | |
| 3070 | + } | |
| 3071 | + | |
| 3072 | + html += '</tr></table></div>'; | |
| 3073 | + } | |
| 3074 | + html += '</dd>'; | |
| 3075 | + } | |
| 3076 | + | |
| 3077 | + // Timezone | |
| 3078 | + html += '<dt class="ui_tpicker_timezone_label"' + ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>'; | |
| 3079 | + html += '<dd class="ui_tpicker_timezone" ' + ((o.showTimezone) ? '' : noDisplay) + '></dd>'; | |
| 3080 | + | |
| 3081 | + // Create the elements from string | |
| 3082 | + html += '</dl></div>'; | |
| 3083 | + var $tp = $(html); | |
| 3084 | + | |
| 3085 | + // if we only want time picker... | |
| 3086 | + if (o.timeOnly === true) { | |
| 3087 | + $tp.prepend('<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' + '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' + '</div>'); | |
| 3088 | + $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide(); | |
| 3089 | + } | |
| 3090 | + | |
| 3091 | + // add sliders, adjust grids, add events | |
| 3092 | + for(var i=0,l=tp_inst.units.length; i<l; i++){ | |
| 3093 | + litem = tp_inst.units[i]; | |
| 3094 | + uitem = litem.substr(0,1).toUpperCase() + litem.substr(1); | |
| 3095 | + | |
| 3096 | + // add the slider | |
| 3097 | + 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]); | |
| 3098 | + | |
| 3099 | + // adjust the grid and add click event | |
| 3100 | + if (o['show'+uitem] && o[litem+'Grid'] > 0) { | |
| 3101 | + size = 100 * gridSize[litem] * o[litem+'Grid'] / (max[litem] - o[litem+'Min']); | |
| 3102 | + $tp.find('.ui_tpicker_'+litem+' table').css({ | |
| 3103 | + width: size + "%", | |
| 3104 | + marginLeft: o.isRTL? '0' : ((size / (-2 * gridSize[litem])) + "%"), | |
| 3105 | + marginRight: o.isRTL? ((size / (-2 * gridSize[litem])) + "%") : '0', | |
| 3106 | + borderCollapse: 'collapse' | |
| 3107 | + }).find("td").click(function(e){ | |
| 3108 | + var $t = $(this), | |
| 3109 | + h = $t.html(), | |
| 3110 | + n = parseInt(h.replace(/[^0-9]/g),10), | |
| 3111 | + ap = h.replace(/[^apm]/ig), | |
| 3112 | + f = $t.data('for'); // loses scope, so we use data-for | |
| 3113 | + | |
| 3114 | + if(f == 'hour'){ | |
| 3115 | + if(ap.indexOf('p') !== -1 && n < 12){ | |
| 3116 | + n += 12; | |
| 3117 | + } | |
| 3118 | + else{ | |
| 3119 | + if(ap.indexOf('a') !== -1 && n === 12){ | |
| 3120 | + n = 0; | |
| 3121 | + } | |
| 3122 | + } | |
| 3123 | + } | |
| 3124 | + | |
| 3125 | + tp_inst.control.value(tp_inst, tp_inst[f+'_slider'], litem, n); | |
| 3126 | + | |
| 3127 | + tp_inst._onTimeChange(); | |
| 3128 | + tp_inst._onSelectHandler(); | |
| 3129 | + }) | |
| 3130 | + .css({ | |
| 3131 | + cursor: 'pointer', | |
| 3132 | + width: (100 / gridSize[litem]) + '%', | |
| 3133 | + textAlign: 'center', | |
| 3134 | + overflow: 'hidden' | |
| 3135 | + }); | |
| 3136 | + } // end if grid > 0 | |
| 3137 | + } // end for loop | |
| 3138 | + | |
| 3139 | + // Add timezone options | |
| 3140 | + this.timezone_select = $tp.find('.ui_tpicker_timezone').append('<select></select>').find("select"); | |
| 3141 | + $.fn.append.apply(this.timezone_select, | |
| 3142 | + $.map(o.timezoneList, function(val, idx) { | |
| 3143 | + return $("<option />").val(typeof val == "object" ? val.value : val).text(typeof val == "object" ? val.label : val); | |
| 3144 | + })); | |
| 3145 | + if (typeof(this.timezone) != "undefined" && this.timezone !== null && this.timezone !== "") { | |
| 3146 | + var local_date = new Date(this.inst.selectedYear, this.inst.selectedMonth, this.inst.selectedDay, 12); | |
| 3147 | + var local_timezone = $.timepicker.timeZoneOffsetString(local_date); | |
| 3148 | + if (local_timezone == this.timezone) { | |
| 3149 | + selectLocalTimeZone(tp_inst); | |
| 3150 | + } else { | |
| 3151 | + this.timezone_select.val(this.timezone); | |
| 3152 | + } | |
| 3153 | + } else { | |
| 3154 | + if (typeof(this.hour) != "undefined" && this.hour !== null && this.hour !== "") { | |
| 3155 | + this.timezone_select.val(o.defaultTimezone); | |
| 3156 | + } else { | |
| 3157 | + selectLocalTimeZone(tp_inst); | |
| 3158 | + } | |
| 3159 | + } | |
| 3160 | + this.timezone_select.change(function() { | |
| 3161 | + tp_inst._defaults.useLocalTimezone = false; | |
| 3162 | + tp_inst._onTimeChange(); | |
| 3163 | + tp_inst._onSelectHandler(); | |
| 3164 | + }); | |
| 3165 | + // End timezone options | |
| 3166 | + | |
| 3167 | + // inject timepicker into datepicker | |
| 3168 | + var $buttonPanel = $dp.find('.ui-datepicker-buttonpane'); | |
| 3169 | + if ($buttonPanel.length) { | |
| 3170 | + $buttonPanel.before($tp); | |
| 3171 | + } else { | |
| 3172 | + $dp.append($tp); | |
| 3173 | + } | |
| 3174 | + | |
| 3175 | + this.$timeObj = $tp.find('.ui_tpicker_time'); | |
| 3176 | + | |
| 3177 | + if (this.inst !== null) { | |
| 3178 | + var timeDefined = this.timeDefined; | |
| 3179 | + this._onTimeChange(); | |
| 3180 | + this.timeDefined = timeDefined; | |
| 3181 | + } | |
| 3182 | + | |
| 3183 | + // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/ | |
| 3184 | + if (this._defaults.addSliderAccess) { | |
| 3185 | + var sliderAccessArgs = this._defaults.sliderAccessArgs, | |
| 3186 | + rtl = this._defaults.isRTL; | |
| 3187 | + sliderAccessArgs.isRTL = rtl; | |
| 3188 | + | |
| 3189 | + setTimeout(function() { // fix for inline mode | |
| 3190 | + if ($tp.find('.ui-slider-access').length === 0) { | |
| 3191 | + $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs); | |
| 3192 | + | |
| 3193 | + // fix any grids since sliders are shorter | |
| 3194 | + var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true); | |
| 3195 | + if (sliderAccessWidth) { | |
| 3196 | + $tp.find('table:visible').each(function() { | |
| 3197 | + var $g = $(this), | |
| 3198 | + oldWidth = $g.outerWidth(), | |
| 3199 | + oldMarginLeft = $g.css(rtl? 'marginRight':'marginLeft').toString().replace('%', ''), | |
| 3200 | + newWidth = oldWidth - sliderAccessWidth, | |
| 3201 | + newMarginLeft = ((oldMarginLeft * newWidth) / oldWidth) + '%', | |
| 3202 | + css = { width: newWidth, marginRight: 0, marginLeft: 0 }; | |
| 3203 | + css[rtl? 'marginRight':'marginLeft'] = newMarginLeft; | |
| 3204 | + $g.css(css); | |
| 3205 | + }); | |
| 3206 | + } | |
| 3207 | + } | |
| 3208 | + }, 10); | |
| 3209 | + } | |
| 3210 | + // end slideAccess integration | |
| 3211 | + | |
| 3212 | + } | |
| 3213 | + }, | |
| 3214 | + | |
| 3215 | + /* | |
| 3216 | + * This function tries to limit the ability to go outside the | |
| 3217 | + * min/max date range | |
| 3218 | + */ | |
| 3219 | + _limitMinMaxDateTime: function(dp_inst, adjustSliders) { | |
| 3220 | + var o = this._defaults, | |
| 3221 | + dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay); | |
| 3222 | + | |
| 3223 | + if (!this._defaults.showTimepicker) { | |
| 3224 | + return; | |
| 3225 | + } // No time so nothing to check here | |
| 3226 | + | |
| 3227 | + if ($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date) { | |
| 3228 | + var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'), | |
| 3229 | + minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0); | |
| 3230 | + | |
| 3231 | + if (this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null) { | |
| 3232 | + this.hourMinOriginal = o.hourMin; | |
| 3233 | + this.minuteMinOriginal = o.minuteMin; | |
| 3234 | + this.secondMinOriginal = o.secondMin; | |
| 3235 | + this.millisecMinOriginal = o.millisecMin; | |
| 3236 | + } | |
| 3237 | + | |
| 3238 | + if (dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) { | |
| 3239 | + this._defaults.hourMin = minDateTime.getHours(); | |
| 3240 | + if (this.hour <= this._defaults.hourMin) { | |
| 3241 | + this.hour = this._defaults.hourMin; | |
| 3242 | + this._defaults.minuteMin = minDateTime.getMinutes(); | |
| 3243 | + if (this.minute <= this._defaults.minuteMin) { | |
| 3244 | + this.minute = this._defaults.minuteMin; | |
| 3245 | + this._defaults.secondMin = minDateTime.getSeconds(); | |
| 3246 | + if (this.second <= this._defaults.secondMin) { | |
| 3247 | + this.second = this._defaults.secondMin; | |
| 3248 | + this._defaults.millisecMin = minDateTime.getMilliseconds(); | |
| 3249 | + } else { | |
| 3250 | + if (this.millisec < this._defaults.millisecMin) { | |
| 3251 | + this.millisec = this._defaults.millisecMin; | |
| 3252 | + } | |
| 3253 | + this._defaults.millisecMin = this.millisecMinOriginal; | |
| 3254 | + } | |
| 3255 | + } else { | |
| 3256 | + this._defaults.secondMin = this.secondMinOriginal; | |
| 3257 | + this._defaults.millisecMin = this.millisecMinOriginal; | |
| 3258 | + } | |
| 3259 | + } else { | |
| 3260 | + this._defaults.minuteMin = this.minuteMinOriginal; | |
| 3261 | + this._defaults.secondMin = this.secondMinOriginal; | |
| 3262 | + this._defaults.millisecMin = this.millisecMinOriginal; | |
| 3263 | + } | |
| 3264 | + } else { | |
| 3265 | + this._defaults.hourMin = this.hourMinOriginal; | |
| 3266 | + this._defaults.minuteMin = this.minuteMinOriginal; | |
| 3267 | + this._defaults.secondMin = this.secondMinOriginal; | |
| 3268 | + this._defaults.millisecMin = this.millisecMinOriginal; | |
| 3269 | + } | |
| 3270 | + } | |
| 3271 | + | |
| 3272 | + if ($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date) { | |
| 3273 | + var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'), | |
| 3274 | + maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0); | |
| 3275 | + | |
| 3276 | + if (this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null) { | |
| 3277 | + this.hourMaxOriginal = o.hourMax; | |
| 3278 | + this.minuteMaxOriginal = o.minuteMax; | |
| 3279 | + this.secondMaxOriginal = o.secondMax; | |
| 3280 | + this.millisecMaxOriginal = o.millisecMax; | |
| 3281 | + } | |
| 3282 | + | |
| 3283 | + if (dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()) { | |
| 3284 | + this._defaults.hourMax = maxDateTime.getHours(); | |
| 3285 | + if (this.hour >= this._defaults.hourMax) { | |
| 3286 | + this.hour = this._defaults.hourMax; | |
| 3287 | + this._defaults.minuteMax = maxDateTime.getMinutes(); | |
| 3288 | + if (this.minute >= this._defaults.minuteMax) { | |
| 3289 | + this.minute = this._defaults.minuteMax; | |
| 3290 | + this._defaults.secondMax = maxDateTime.getSeconds(); | |
| 3291 | + if (this.second >= this._defaults.secondMax) { | |
| 3292 | + this.second = this._defaults.secondMax; | |
| 3293 | + this._defaults.millisecMax = maxDateTime.getMilliseconds(); | |
| 3294 | + } else { | |
| 3295 | + if (this.millisec > this._defaults.millisecMax) { | |
| 3296 | + this.millisec = this._defaults.millisecMax; | |
| 3297 | + } | |
| 3298 | + this._defaults.millisecMax = this.millisecMaxOriginal; | |
| 3299 | + } | |
| 3300 | + } else { | |
| 3301 | + this._defaults.secondMax = this.secondMaxOriginal; | |
| 3302 | + this._defaults.millisecMax = this.millisecMaxOriginal; | |
| 3303 | + } | |
| 3304 | + } else { | |
| 3305 | + this._defaults.minuteMax = this.minuteMaxOriginal; | |
| 3306 | + this._defaults.secondMax = this.secondMaxOriginal; | |
| 3307 | + this._defaults.millisecMax = this.millisecMaxOriginal; | |
| 3308 | + } | |
| 3309 | + } else { | |
| 3310 | + this._defaults.hourMax = this.hourMaxOriginal; | |
| 3311 | + this._defaults.minuteMax = this.minuteMaxOriginal; | |
| 3312 | + this._defaults.secondMax = this.secondMaxOriginal; | |
| 3313 | + this._defaults.millisecMax = this.millisecMaxOriginal; | |
| 3314 | + } | |
| 3315 | + } | |
| 3316 | + | |
| 3317 | + if (adjustSliders !== undefined && adjustSliders === true) { | |
| 3318 | + var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)), 10), | |
| 3319 | + minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)), 10), | |
| 3320 | + secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)), 10), | |
| 3321 | + millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10); | |
| 3322 | + | |
| 3323 | + if (this.hour_slider) { | |
| 3324 | + this.control.options(this, this.hour_slider, 'hour', { min: this._defaults.hourMin, max: hourMax }); | |
| 3325 | + this.control.value(this, this.hour_slider, 'hour', this.hour - (this.hour % this._defaults.stepHour)); | |
| 3326 | + } | |
| 3327 | + if (this.minute_slider) { | |
| 3328 | + this.control.options(this, this.minute_slider, 'minute', { min: this._defaults.minuteMin, max: minMax }); | |
| 3329 | + this.control.value(this, this.minute_slider, 'minute', this.minute - (this.minute % this._defaults.stepMinute)); | |
| 3330 | + } | |
| 3331 | + if (this.second_slider) { | |
| 3332 | + this.control.options(this, this.second_slider, 'second', { min: this._defaults.secondMin, max: secMax }); | |
| 3333 | + this.control.value(this, this.second_slider, 'second', this.second - (this.second % this._defaults.stepSecond)); | |
| 3334 | + } | |
| 3335 | + if (this.millisec_slider) { | |
| 3336 | + this.control.options(this, this.millisec_slider, 'millisec', { min: this._defaults.millisecMin, max: millisecMax }); | |
| 3337 | + this.control.value(this, this.millisec_slider, 'millisec', this.millisec - (this.millisec % this._defaults.stepMillisec)); | |
| 3338 | + } | |
| 3339 | + } | |
| 3340 | + | |
| 3341 | + }, | |
| 3342 | + | |
| 3343 | + /* | |
| 3344 | + * when a slider moves, set the internal time... | |
| 3345 | + * on time change is also called when the time is updated in the text field | |
| 3346 | + */ | |
| 3347 | + _onTimeChange: function() { | |
| 3348 | + var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider, 'hour') : false, | |
| 3349 | + minute = (this.minute_slider) ? this.control.value(this, this.minute_slider, 'minute') : false, | |
| 3350 | + second = (this.second_slider) ? this.control.value(this, this.second_slider, 'second') : false, | |
| 3351 | + millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider, 'millisec') : false, | |
| 3352 | + timezone = (this.timezone_select) ? this.timezone_select.val() : false, | |
| 3353 | + o = this._defaults, | |
| 3354 | + pickerTimeFormat = o.pickerTimeFormat || o.timeFormat, | |
| 3355 | + pickerTimeSuffix = o.pickerTimeSuffix || o.timeSuffix; | |
| 3356 | + | |
| 3357 | + if (typeof(hour) == 'object') { | |
| 3358 | + hour = false; | |
| 3359 | + } | |
| 3360 | + if (typeof(minute) == 'object') { | |
| 3361 | + minute = false; | |
| 3362 | + } | |
| 3363 | + if (typeof(second) == 'object') { | |
| 3364 | + second = false; | |
| 3365 | + } | |
| 3366 | + if (typeof(millisec) == 'object') { | |
| 3367 | + millisec = false; | |
| 3368 | + } | |
| 3369 | + if (typeof(timezone) == 'object') { | |
| 3370 | + timezone = false; | |
| 3371 | + } | |
| 3372 | + | |
| 3373 | + if (hour !== false) { | |
| 3374 | + hour = parseInt(hour, 10); | |
| 3375 | + } | |
| 3376 | + if (minute !== false) { | |
| 3377 | + minute = parseInt(minute, 10); | |
| 3378 | + } | |
| 3379 | + if (second !== false) { | |
| 3380 | + second = parseInt(second, 10); | |
| 3381 | + } | |
| 3382 | + if (millisec !== false) { | |
| 3383 | + millisec = parseInt(millisec, 10); | |
| 3384 | + } | |
| 3385 | + | |
| 3386 | + var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0]; | |
| 3387 | + | |
| 3388 | + // If the update was done in the input field, the input field should not be updated. | |
| 3389 | + // If the update was done using the sliders, update the input field. | |
| 3390 | + var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || millisec != this.millisec | |
| 3391 | + || (this.ampm.length > 0 && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1)) | |
| 3392 | + || ((this.timezone === null && timezone != this.defaultTimezone) || (this.timezone !== null && timezone != this.timezone))); | |
| 3393 | + | |
| 3394 | + if (hasChanged) { | |
| 3395 | + | |
| 3396 | + if (hour !== false) { | |
| 3397 | + this.hour = hour; | |
| 3398 | + } | |
| 3399 | + if (minute !== false) { | |
| 3400 | + this.minute = minute; | |
| 3401 | + } | |
| 3402 | + if (second !== false) { | |
| 3403 | + this.second = second; | |
| 3404 | + } | |
| 3405 | + if (millisec !== false) { | |
| 3406 | + this.millisec = millisec; | |
| 3407 | + } | |
| 3408 | + if (timezone !== false) { | |
| 3409 | + this.timezone = timezone; | |
| 3410 | + } | |
| 3411 | + | |
| 3412 | + if (!this.inst) { | |
| 3413 | + this.inst = $.datepicker._getInst(this.$input[0]); | |
| 3414 | + } | |
| 3415 | + | |
| 3416 | + this._limitMinMaxDateTime(this.inst, true); | |
| 3417 | + } | |
| 3418 | + if (useAmpm(o.timeFormat)) { | |
| 3419 | + this.ampm = ampm; | |
| 3420 | + } | |
| 3421 | + | |
| 3422 | + // Updates the time within the timepicker | |
| 3423 | + this.formattedTime = $.datepicker.formatTime(o.timeFormat, this, o); | |
| 3424 | + if (this.$timeObj) { | |
| 3425 | + if(pickerTimeFormat === o.timeFormat){ | |
| 3426 | + this.$timeObj.text(this.formattedTime + pickerTimeSuffix); | |
| 3427 | + } | |
| 3428 | + else{ | |
| 3429 | + this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix); | |
| 3430 | + } | |
| 3431 | + } | |
| 3432 | + | |
| 3433 | + this.timeDefined = true; | |
| 3434 | + if (hasChanged) { | |
| 3435 | + this._updateDateTime(); | |
| 3436 | + } | |
| 3437 | + }, | |
| 3438 | + | |
| 3439 | + /* | |
| 3440 | + * call custom onSelect. | |
| 3441 | + * bind to sliders slidestop, and grid click. | |
| 3442 | + */ | |
| 3443 | + _onSelectHandler: function() { | |
| 3444 | + var onSelect = this._defaults.onSelect || this.inst.settings.onSelect; | |
| 3445 | + var inputEl = this.$input ? this.$input[0] : null; | |
| 3446 | + if (onSelect && inputEl) { | |
| 3447 | + onSelect.apply(inputEl, [this.formattedDateTime, this]); | |
| 3448 | + } | |
| 3449 | + }, | |
| 3450 | + | |
| 3451 | + /* | |
| 3452 | + * update our input with the new date time.. | |
| 3453 | + */ | |
| 3454 | + _updateDateTime: function(dp_inst) { | |
| 3455 | + dp_inst = this.inst || dp_inst; | |
| 3456 | + var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)), | |
| 3457 | + dateFmt = $.datepicker._get(dp_inst, 'dateFormat'), | |
| 3458 | + formatCfg = $.datepicker._getFormatConfig(dp_inst), | |
| 3459 | + timeAvailable = dt !== null && this.timeDefined; | |
| 3460 | + this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg); | |
| 3461 | + var formattedDateTime = this.formattedDate; | |
| 3462 | + | |
| 3463 | + // if a slider was changed but datepicker doesn't have a value yet, set it | |
| 3464 | + if(dp_inst.lastVal==""){ | |
| 3465 | + dp_inst.currentYear=dp_inst.selectedYear; | |
| 3466 | + dp_inst.currentMonth=dp_inst.selectedMonth; | |
| 3467 | + dp_inst.currentDay=dp_inst.selectedDay; | |
| 3468 | + } | |
| 3469 | + | |
| 3470 | + /* | |
| 3471 | + * remove following lines to force every changes in date picker to change the input value | |
| 3472 | + * Bug descriptions: when an input field has a default value, and click on the field to pop up the date picker. | |
| 3473 | + * If the user manually empty the value in the input field, the date picker will never change selected value. | |
| 3474 | + */ | |
| 3475 | + //if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0)) { | |
| 3476 | + // return; | |
| 3477 | + //} | |
| 3478 | + | |
| 3479 | + if (this._defaults.timeOnly === true) { | |
| 3480 | + formattedDateTime = this.formattedTime; | |
| 3481 | + } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) { | |
| 3482 | + formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix; | |
| 3483 | + } | |
| 3484 | + | |
| 3485 | + this.formattedDateTime = formattedDateTime; | |
| 3486 | + | |
| 3487 | + if (!this._defaults.showTimepicker) { | |
| 3488 | + this.$input.val(this.formattedDate); | |
| 3489 | + } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) { | |
| 3490 | + this.$altInput.val(this.formattedTime); | |
| 3491 | + this.$input.val(this.formattedDate); | |
| 3492 | + } else if (this.$altInput) { | |
| 3493 | + this.$input.val(formattedDateTime); | |
| 3494 | + var altFormattedDateTime = '', | |
| 3495 | + altSeparator = this._defaults.altSeparator ? this._defaults.altSeparator : this._defaults.separator, | |
| 3496 | + altTimeSuffix = this._defaults.altTimeSuffix ? this._defaults.altTimeSuffix : this._defaults.timeSuffix; | |
| 3497 | + | |
| 3498 | + if (this._defaults.altFormat) altFormattedDateTime = $.datepicker.formatDate(this._defaults.altFormat, (dt === null ? new Date() : dt), formatCfg); | |
| 3499 | + else altFormattedDateTime = this.formattedDate; | |
| 3500 | + if (altFormattedDateTime) altFormattedDateTime += altSeparator; | |
| 3501 | + if (this._defaults.altTimeFormat) altFormattedDateTime += $.datepicker.formatTime(this._defaults.altTimeFormat, this, this._defaults) + altTimeSuffix; | |
| 3502 | + else altFormattedDateTime += this.formattedTime + altTimeSuffix; | |
| 3503 | + this.$altInput.val(altFormattedDateTime); | |
| 3504 | + } else { | |
| 3505 | + this.$input.val(formattedDateTime); | |
| 3506 | + } | |
| 3507 | + | |
| 3508 | + this.$input.trigger("change"); | |
| 3509 | + }, | |
| 3510 | + | |
| 3511 | + _onFocus: function() { | |
| 3512 | + if (!this.$input.val() && this._defaults.defaultValue) { | |
| 3513 | + this.$input.val(this._defaults.defaultValue); | |
| 3514 | + var inst = $.datepicker._getInst(this.$input.get(0)), | |
| 3515 | + tp_inst = $.datepicker._get(inst, 'timepicker'); | |
| 3516 | + if (tp_inst) { | |
| 3517 | + if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) { | |
| 3518 | + try { | |
| 3519 | + $.datepicker._updateDatepicker(inst); | |
| 3520 | + } catch (err) { | |
| 3521 | + $.timepicker.log(err); | |
| 3522 | + } | |
| 3523 | + } | |
| 3524 | + } | |
| 3525 | + } | |
| 3526 | + }, | |
| 3527 | + | |
| 3528 | + /* | |
| 3529 | + * Small abstraction to control types | |
| 3530 | + * We can add more, just be sure to follow the pattern: create, options, value | |
| 3531 | + */ | |
| 3532 | + _controls: { | |
| 3533 | + // slider methods | |
| 3534 | + slider: { | |
| 3535 | + create: function(tp_inst, obj, unit, val, min, max, step){ | |
| 3536 | + var rtl = tp_inst._defaults.isRTL; // if rtl go -60->0 instead of 0->60 | |
| 3537 | + return obj.prop('slide', null).slider({ | |
| 3538 | + orientation: "horizontal", | |
| 3539 | + value: rtl? val*-1 : val, | |
| 3540 | + min: rtl? max*-1 : min, | |
| 3541 | + max: rtl? min*-1 : max, | |
| 3542 | + step: step, | |
| 3543 | + slide: function(event, ui) { | |
| 3544 | + tp_inst.control.value(tp_inst, $(this), unit, rtl? ui.value*-1:ui.value); | |
| 3545 | + tp_inst._onTimeChange(); | |
| 3546 | + }, | |
| 3547 | + stop: function(event, ui) { | |
| 3548 | + tp_inst._onSelectHandler(); | |
| 3549 | + } | |
| 3550 | + }); | |
| 3551 | + }, | |
| 3552 | + options: function(tp_inst, obj, unit, opts, val){ | |
| 3553 | + if(tp_inst._defaults.isRTL){ | |
| 3554 | + if(typeof(opts) == 'string'){ | |
| 3555 | + if(opts == 'min' || opts == 'max'){ | |
| 3556 | + if(val !== undefined) | |
| 3557 | + return obj.slider(opts, val*-1); | |
| 3558 | + return Math.abs(obj.slider(opts)); | |
| 3559 | + } | |
| 3560 | + return obj.slider(opts); | |
| 3561 | + } | |
| 3562 | + var min = opts.min, | |
| 3563 | + max = opts.max; | |
| 3564 | + opts.min = opts.max = null; | |
| 3565 | + if(min !== undefined) | |
| 3566 | + opts.max = min * -1; | |
| 3567 | + if(max !== undefined) | |
| 3568 | + opts.min = max * -1; | |
| 3569 | + return obj.slider(opts); | |
| 3570 | + } | |
| 3571 | + if(typeof(opts) == 'string' && val !== undefined) | |
| 3572 | + return obj.slider(opts, val); | |
| 3573 | + return obj.slider(opts); | |
| 3574 | + }, | |
| 3575 | + value: function(tp_inst, obj, unit, val){ | |
| 3576 | + if(tp_inst._defaults.isRTL){ | |
| 3577 | + if(val !== undefined) | |
| 3578 | + return obj.slider('value', val*-1); | |
| 3579 | + return Math.abs(obj.slider('value')); | |
| 3580 | + } | |
| 3581 | + if(val !== undefined) | |
| 3582 | + return obj.slider('value', val); | |
| 3583 | + return obj.slider('value'); | |
| 3584 | + } | |
| 3585 | + }, | |
| 3586 | + // select methods | |
| 3587 | + select: { | |
| 3588 | + create: function(tp_inst, obj, unit, val, min, max, step){ | |
| 3589 | + var sel = '<select class="ui-timepicker-select" data-unit="'+ unit +'" data-min="'+ min +'" data-max="'+ max +'" data-step="'+ step +'">', | |
| 3590 | + ul = tp_inst._defaults.timeFormat.indexOf('t') !== -1? 'toLowerCase':'toUpperCase', | |
| 3591 | + m = 0; | |
| 3592 | + | |
| 3593 | + for(var i=min; i<=max; i+=step){ | |
| 3594 | + sel += '<option value="'+ i +'"'+ (i==val? ' selected':'') +'>'; | |
| 3595 | + if(unit == 'hour' && useAmpm(tp_inst._defaults.pickerTimeFormat || tp_inst._defaults.timeFormat)) | |
| 3596 | + sel += $.datepicker.formatTime("hh TT", {hour:i}, tp_inst._defaults); | |
| 3597 | + else if(unit == 'millisec' || i >= 10) sel += i; | |
| 3598 | + else sel += '0'+ i.toString(); | |
| 3599 | + sel += '</option>'; | |
| 3600 | + } | |
| 3601 | + sel += '</select>'; | |
| 3602 | + | |
| 3603 | + obj.children('select').remove(); | |
| 3604 | + | |
| 3605 | + $(sel).appendTo(obj).change(function(e){ | |
| 3606 | + tp_inst._onTimeChange(); | |
| 3607 | + tp_inst._onSelectHandler(); | |
| 3608 | + }); | |
| 3609 | + | |
| 3610 | + return obj; | |
| 3611 | + }, | |
| 3612 | + options: function(tp_inst, obj, unit, opts, val){ | |
| 3613 | + var o = {}, | |
| 3614 | + $t = obj.children('select'); | |
| 3615 | + if(typeof(opts) == 'string'){ | |
| 3616 | + if(val === undefined) | |
| 3617 | + return $t.data(opts); | |
| 3618 | + o[opts] = val; | |
| 3619 | + } | |
| 3620 | + else o = opts; | |
| 3621 | + 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')); | |
| 3622 | + }, | |
| 3623 | + value: function(tp_inst, obj, unit, val){ | |
| 3624 | + var $t = obj.children('select'); | |
| 3625 | + if(val !== undefined) | |
| 3626 | + return $t.val(val); | |
| 3627 | + return $t.val(); | |
| 3628 | + } | |
| 3629 | + } | |
| 3630 | + } // end _controls | |
| 3631 | + | |
| 3632 | + }); | |
| 3633 | + | |
| 3634 | + $.fn.extend({ | |
| 3635 | + /* | |
| 3636 | + * shorthand just to use timepicker.. | |
| 3637 | + */ | |
| 3638 | + timepicker: function(o) { | |
| 3639 | + o = o || {}; | |
| 3640 | + var tmp_args = Array.prototype.slice.call(arguments); | |
| 3641 | + | |
| 3642 | + if (typeof o == 'object') { | |
| 3643 | + tmp_args[0] = $.extend(o, { | |
| 3644 | + timeOnly: true | |
| 3645 | + }); | |
| 3646 | + } | |
| 3647 | + | |
| 3648 | + return $(this).each(function() { | |
| 3649 | + $.fn.datetimepicker.apply($(this), tmp_args); | |
| 3650 | + }); | |
| 3651 | + }, | |
| 3652 | + | |
| 3653 | + /* | |
| 3654 | + * extend timepicker to datepicker | |
| 3655 | + */ | |
| 3656 | + datetimepicker: function(o) { | |
| 3657 | + o = o || {}; | |
| 3658 | + var tmp_args = arguments; | |
| 3659 | + | |
| 3660 | + if (typeof(o) == 'string') { | |
| 3661 | + if (o == 'getDate') { | |
| 3662 | + return $.fn.datepicker.apply($(this[0]), tmp_args); | |
| 3663 | + } else { | |
| 3664 | + return this.each(function() { | |
| 3665 | + var $t = $(this); | |
| 3666 | + $t.datepicker.apply($t, tmp_args); | |
| 3667 | + }); | |
| 3668 | + } | |
| 3669 | + } else { | |
| 3670 | + return this.each(function() { | |
| 3671 | + var $t = $(this); | |
| 3672 | + $t.datepicker($.timepicker._newInst($t, o)._defaults); | |
| 3673 | + }); | |
| 3674 | + } | |
| 3675 | + } | |
| 3676 | + }); | |
| 3677 | + | |
| 3678 | + /* | |
| 3679 | + * Public Utility to parse date and time | |
| 3680 | + */ | |
| 3681 | + $.datepicker.parseDateTime = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { | |
| 3682 | + var parseRes = parseDateTimeInternal(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings); | |
| 3683 | + if (parseRes.timeObj) { | |
| 3684 | + var t = parseRes.timeObj; | |
| 3685 | + parseRes.date.setHours(t.hour, t.minute, t.second, t.millisec); | |
| 3686 | + } | |
| 3687 | + | |
| 3688 | + return parseRes.date; | |
| 3689 | + }; | |
| 3690 | + | |
| 3691 | + /* | |
| 3692 | + * Public utility to parse time | |
| 3693 | + */ | |
| 3694 | + $.datepicker.parseTime = function(timeFormat, timeString, options) { | |
| 3695 | + var o = extendRemove(extendRemove({}, $.timepicker._defaults), options || {}); | |
| 3696 | + | |
| 3697 | + // Strict parse requires the timeString to match the timeFormat exactly | |
| 3698 | + var strictParse = function(f, s, o){ | |
| 3699 | + | |
| 3700 | + // pattern for standard and localized AM/PM markers | |
| 3701 | + var getPatternAmpm = function(amNames, pmNames) { | |
| 3702 | + var markers = []; | |
| 3703 | + if (amNames) { | |
| 3704 | + $.merge(markers, amNames); | |
| 3705 | + } | |
| 3706 | + if (pmNames) { | |
| 3707 | + $.merge(markers, pmNames); | |
| 3708 | + } | |
| 3709 | + markers = $.map(markers, function(val) { | |
| 3710 | + return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); | |
| 3711 | + }); | |
| 3712 | + return '(' + markers.join('|') + ')?'; | |
| 3713 | + }; | |
| 3714 | + | |
| 3715 | + // figure out position of time elements.. cause js cant do named captures | |
| 3716 | + var getFormatPositions = function(timeFormat) { | |
| 3717 | + var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z|'.*?')/g), | |
| 3718 | + orders = { | |
| 3719 | + h: -1, | |
| 3720 | + m: -1, | |
| 3721 | + s: -1, | |
| 3722 | + l: -1, | |
| 3723 | + t: -1, | |
| 3724 | + z: -1 | |
| 3725 | + }; | |
| 3726 | + | |
| 3727 | + if (finds) { | |
| 3728 | + for (var i = 0; i < finds.length; i++) { | |
| 3729 | + if (orders[finds[i].toString().charAt(0)] == -1) { | |
| 3730 | + orders[finds[i].toString().charAt(0)] = i + 1; | |
| 3731 | + } | |
| 3732 | + } | |
| 3733 | + } | |
| 3734 | + return orders; | |
| 3735 | + }; | |
| 3736 | + | |
| 3737 | + var regstr = '^' + f.toString() | |
| 3738 | + .replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[lz]|'.*?')/g, function (match) { | |
| 3739 | + var ml = match.length; | |
| 3740 | + switch (match.charAt(0).toLowerCase()) { | |
| 3741 | + case 'h': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; | |
| 3742 | + case 'm': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; | |
| 3743 | + case 's': return ml === 1? '(\\d?\\d)':'(\\d{'+ml+'})'; | |
| 3744 | + case 'l': return '(\\d?\\d?\\d)'; | |
| 3745 | + case 'z': return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?'; | |
| 3746 | + case 't': return getPatternAmpm(o.amNames, o.pmNames); | |
| 3747 | + default: // literal escaped in quotes | |
| 3748 | + return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?'; | |
| 3749 | + } | |
| 3750 | + }) | |
| 3751 | + .replace(/\s/g, '\\s?') + | |
| 3752 | + o.timeSuffix + '$', | |
| 3753 | + order = getFormatPositions(f), | |
| 3754 | + ampm = '', | |
| 3755 | + treg; | |
| 3756 | + | |
| 3757 | + treg = s.match(new RegExp(regstr, 'i')); | |
| 3758 | + | |
| 3759 | + var resTime = { | |
| 3760 | + hour: 0, | |
| 3761 | + minute: 0, | |
| 3762 | + second: 0, | |
| 3763 | + millisec: 0 | |
| 3764 | + }; | |
| 3765 | + | |
| 3766 | + if (treg) { | |
| 3767 | + if (order.t !== -1) { | |
| 3768 | + if (treg[order.t] === undefined || treg[order.t].length === 0) { | |
| 3769 | + ampm = ''; | |
| 3770 | + resTime.ampm = ''; | |
| 3771 | + } else { | |
| 3772 | + ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM'; | |
| 3773 | + resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0]; | |
| 3774 | + } | |
| 3775 | + } | |
| 3776 | + | |
| 3777 | + if (order.h !== -1) { | |
| 3778 | + if (ampm == 'AM' && treg[order.h] == '12') { | |
| 3779 | + resTime.hour = 0; // 12am = 0 hour | |
| 3780 | + } else { | |
| 3781 | + if (ampm == 'PM' && treg[order.h] != '12') { | |
| 3782 | + resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12 | |
| 3783 | + } else { | |
| 3784 | + resTime.hour = Number(treg[order.h]); | |
| 3785 | + } | |
| 3786 | + } | |
| 3787 | + } | |
| 3788 | + | |
| 3789 | + if (order.m !== -1) { | |
| 3790 | + resTime.minute = Number(treg[order.m]); | |
| 3791 | + } | |
| 3792 | + if (order.s !== -1) { | |
| 3793 | + resTime.second = Number(treg[order.s]); | |
| 3794 | + } | |
| 3795 | + if (order.l !== -1) { | |
| 3796 | + resTime.millisec = Number(treg[order.l]); | |
| 3797 | + } | |
| 3798 | + if (order.z !== -1 && treg[order.z] !== undefined) { | |
| 3799 | + var tz = treg[order.z].toUpperCase(); | |
| 3800 | + switch (tz.length) { | |
| 3801 | + case 1: | |
| 3802 | + // Z | |
| 3803 | + tz = o.timezoneIso8601 ? 'Z' : '+0000'; | |
| 3804 | + break; | |
| 3805 | + case 5: | |
| 3806 | + // +hhmm | |
| 3807 | + if (o.timezoneIso8601) { | |
| 3808 | + tz = tz.substring(1) == '0000' ? 'Z' : tz.substring(0, 3) + ':' + tz.substring(3); | |
| 3809 | + } | |
| 3810 | + break; | |
| 3811 | + case 6: | |
| 3812 | + // +hh:mm | |
| 3813 | + if (!o.timezoneIso8601) { | |
| 3814 | + tz = tz == 'Z' || tz.substring(1) == '00:00' ? '+0000' : tz.replace(/:/, ''); | |
| 3815 | + } else { | |
| 3816 | + if (tz.substring(1) == '00:00') { | |
| 3817 | + tz = 'Z'; | |
| 3818 | + } | |
| 3819 | + } | |
| 3820 | + break; | |
| 3821 | + } | |
| 3822 | + resTime.timezone = tz; | |
| 3823 | + } | |
| 3824 | + | |
| 3825 | + | |
| 3826 | + return resTime; | |
| 3827 | + } | |
| 3828 | + return false; | |
| 3829 | + };// end strictParse | |
| 3830 | + | |
| 3831 | + // First try JS Date, if that fails, use strictParse | |
| 3832 | + var looseParse = function(f,s,o){ | |
| 3833 | + try{ | |
| 3834 | + var d = new Date('2012-01-01 '+ s); | |
| 3835 | + if(isNaN(d.getTime())){ | |
| 3836 | + d = new Date('2012-01-01T'+ s); | |
| 3837 | + if(isNaN(d.getTime())){ | |
| 3838 | + d = new Date('01/01/2012 '+ s); | |
| 3839 | + if(isNaN(d.getTime())){ | |
| 3840 | + throw "Unable to parse time with native Date: "+ s; | |
| 3841 | + } | |
| 3842 | + } | |
| 3843 | + } | |
| 3844 | + | |
| 3845 | + return { | |
| 3846 | + hour: d.getHours(), | |
| 3847 | + minute: d.getMinutes(), | |
| 3848 | + second: d.getSeconds(), | |
| 3849 | + millisec: d.getMilliseconds(), | |
| 3850 | + timezone: $.timepicker.timeZoneOffsetString(d) | |
| 3851 | + }; | |
| 3852 | + } | |
| 3853 | + catch(err){ | |
| 3854 | + try{ | |
| 3855 | + return strictParse(f,s,o); | |
| 3856 | + } | |
| 3857 | + catch(err2){ | |
| 3858 | + $.timepicker.log("Unable to parse \ntimeString: "+ s +"\ntimeFormat: "+ f); | |
| 3859 | + } | |
| 3860 | + } | |
| 3861 | + return false; | |
| 3862 | + }; // end looseParse | |
| 3863 | + | |
| 3864 | + if(typeof o.parse === "function"){ | |
| 3865 | + return o.parse(timeFormat, timeString, o) | |
| 3866 | + } | |
| 3867 | + if(o.parse === 'loose'){ | |
| 3868 | + return looseParse(timeFormat, timeString, o); | |
| 3869 | + } | |
| 3870 | + return strictParse(timeFormat, timeString, o); | |
| 3871 | + }; | |
| 3872 | + | |
| 3873 | + /* | |
| 3874 | + * Public utility to format the time | |
| 3875 | + * format = string format of the time | |
| 3876 | + * time = a {}, not a Date() for timezones | |
| 3877 | + * options = essentially the regional[].. amNames, pmNames, ampm | |
| 3878 | + */ | |
| 3879 | + $.datepicker.formatTime = function(format, time, options) { | |
| 3880 | + options = options || {}; | |
| 3881 | + options = $.extend({}, $.timepicker._defaults, options); | |
| 3882 | + time = $.extend({ | |
| 3883 | + hour: 0, | |
| 3884 | + minute: 0, | |
| 3885 | + second: 0, | |
| 3886 | + millisec: 0, | |
| 3887 | + timezone: '+0000' | |
| 3888 | + }, time); | |
| 3889 | + | |
| 3890 | + var tmptime = format, | |
| 3891 | + ampmName = options.amNames[0], | |
| 3892 | + hour = parseInt(time.hour, 10); | |
| 3893 | + | |
| 3894 | + if (hour > 11) { | |
| 3895 | + ampmName = options.pmNames[0]; | |
| 3896 | + } | |
| 3897 | + | |
| 3898 | + tmptime = tmptime.replace(/(?:HH?|hh?|mm?|ss?|[tT]{1,2}|[lz]|('.*?'|".*?"))/g, function(match) { | |
| 3899 | + switch (match) { | |
| 3900 | + case 'HH': | |
| 3901 | + return ('0' + hour).slice(-2); | |
| 3902 | + case 'H': | |
| 3903 | + return hour; | |
| 3904 | + case 'hh': | |
| 3905 | + return ('0' + convert24to12(hour)).slice(-2); | |
| 3906 | + case 'h': | |
| 3907 | + return convert24to12(hour); | |
| 3908 | + case 'mm': | |
| 3909 | + return ('0' + time.minute).slice(-2); | |
| 3910 | + case 'm': | |
| 3911 | + return time.minute; | |
| 3912 | + case 'ss': | |
| 3913 | + return ('0' + time.second).slice(-2); | |
| 3914 | + case 's': | |
| 3915 | + return time.second; | |
| 3916 | + case 'l': | |
| 3917 | + return ('00' + time.millisec).slice(-3); | |
| 3918 | + case 'z': | |
| 3919 | + return time.timezone === null? options.defaultTimezone : time.timezone; | |
| 3920 | + case 'T': | |
| 3921 | + return ampmName.charAt(0).toUpperCase(); | |
| 3922 | + case 'TT': | |
| 3923 | + return ampmName.toUpperCase(); | |
| 3924 | + case 't': | |
| 3925 | + return ampmName.charAt(0).toLowerCase(); | |
| 3926 | + case 'tt': | |
| 3927 | + return ampmName.toLowerCase(); | |
| 3928 | + default: | |
| 3929 | + return match.replace(/\'/g, "") || "'"; | |
| 3930 | + } | |
| 3931 | + }); | |
| 3932 | + | |
| 3933 | + tmptime = $.trim(tmptime); | |
| 3934 | + return tmptime; | |
| 3935 | + }; | |
| 3936 | + | |
| 3937 | + /* | |
| 3938 | + * the bad hack :/ override datepicker so it doesnt close on select | |
| 3939 | + // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378 | |
| 3940 | + */ | |
| 3941 | + $.datepicker._base_selectDate = $.datepicker._selectDate; | |
| 3942 | + $.datepicker._selectDate = function(id, dateStr) { | |
| 3943 | + var inst = this._getInst($(id)[0]), | |
| 3944 | + tp_inst = this._get(inst, 'timepicker'); | |
| 3945 | + | |
| 3946 | + if (tp_inst) { | |
| 3947 | + tp_inst._limitMinMaxDateTime(inst, true); | |
| 3948 | + inst.inline = inst.stay_open = true; | |
| 3949 | + //This way the onSelect handler called from calendarpicker get the full dateTime | |
| 3950 | + this._base_selectDate(id, dateStr); | |
| 3951 | + inst.inline = inst.stay_open = false; | |
| 3952 | + this._notifyChange(inst); | |
| 3953 | + this._updateDatepicker(inst); | |
| 3954 | + } else { | |
| 3955 | + this._base_selectDate(id, dateStr); | |
| 3956 | + } | |
| 3957 | + }; | |
| 3958 | + | |
| 3959 | + /* | |
| 3960 | + * second bad hack :/ override datepicker so it triggers an event when changing the input field | |
| 3961 | + * and does not redraw the datepicker on every selectDate event | |
| 3962 | + */ | |
| 3963 | + $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker; | |
| 3964 | + $.datepicker._updateDatepicker = function(inst) { | |
| 3965 | + | |
| 3966 | + // don't popup the datepicker if there is another instance already opened | |
| 3967 | + var input = inst.input[0]; | |
| 3968 | + if ($.datepicker._curInst && $.datepicker._curInst != inst && $.datepicker._datepickerShowing && $.datepicker._lastInput != input) { | |
| 3969 | + return; | |
| 3970 | + } | |
| 3971 | + | |
| 3972 | + if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) { | |
| 3973 | + | |
| 3974 | + this._base_updateDatepicker(inst); | |
| 3975 | + | |
| 3976 | + // Reload the time control when changing something in the input text field. | |
| 3977 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 3978 | + if (tp_inst) { | |
| 3979 | + tp_inst._addTimePicker(inst); | |
| 3980 | + | |
| 3981 | +// if (tp_inst._defaults.useLocalTimezone) { //checks daylight saving with the new date. | |
| 3982 | +// var date = new Date(inst.selectedYear, inst.selectedMonth, inst.selectedDay, 12); | |
| 3983 | +// selectLocalTimeZone(tp_inst, date); | |
| 3984 | +// tp_inst._onTimeChange(); | |
| 3985 | +// } | |
| 3986 | + } | |
| 3987 | + } | |
| 3988 | + }; | |
| 3989 | + | |
| 3990 | + /* | |
| 3991 | + * third bad hack :/ override datepicker so it allows spaces and colon in the input field | |
| 3992 | + */ | |
| 3993 | + $.datepicker._base_doKeyPress = $.datepicker._doKeyPress; | |
| 3994 | + $.datepicker._doKeyPress = function(event) { | |
| 3995 | + var inst = $.datepicker._getInst(event.target), | |
| 3996 | + tp_inst = $.datepicker._get(inst, 'timepicker'); | |
| 3997 | + | |
| 3998 | + if (tp_inst) { | |
| 3999 | + if ($.datepicker._get(inst, 'constrainInput')) { | |
| 4000 | + var ampm = useAmpm(tp_inst._defaults.timeFormat), | |
| 4001 | + dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')), | |
| 4002 | + datetimeChars = tp_inst._defaults.timeFormat.toString() | |
| 4003 | + .replace(/[hms]/g, '') | |
| 4004 | + .replace(/TT/g, ampm ? 'APM' : '') | |
| 4005 | + .replace(/Tt/g, ampm ? 'AaPpMm' : '') | |
| 4006 | + .replace(/tT/g, ampm ? 'AaPpMm' : '') | |
| 4007 | + .replace(/T/g, ampm ? 'AP' : '') | |
| 4008 | + .replace(/tt/g, ampm ? 'apm' : '') | |
| 4009 | + .replace(/t/g, ampm ? 'ap' : '') + | |
| 4010 | + " " + tp_inst._defaults.separator + | |
| 4011 | + tp_inst._defaults.timeSuffix + | |
| 4012 | + (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') + | |
| 4013 | + (tp_inst._defaults.amNames.join('')) + (tp_inst._defaults.pmNames.join('')) + | |
| 4014 | + dateChars, | |
| 4015 | + chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode); | |
| 4016 | + return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1); | |
| 4017 | + } | |
| 4018 | + } | |
| 4019 | + | |
| 4020 | + return $.datepicker._base_doKeyPress(event); | |
| 4021 | + }; | |
| 4022 | + | |
| 4023 | + /* | |
| 4024 | + * Fourth bad hack :/ override _updateAlternate function used in inline mode to init altField | |
| 4025 | + */ | |
| 4026 | + $.datepicker._base_updateAlternate = $.datepicker._updateAlternate; | |
| 4027 | + /* Update any alternate field to synchronise with the main field. */ | |
| 4028 | + $.datepicker._updateAlternate = function(inst) { | |
| 4029 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4030 | + if(tp_inst){ | |
| 4031 | + var altField = tp_inst._defaults.altField; | |
| 4032 | + if (altField) { // update alternate field too | |
| 4033 | + var altFormat = tp_inst._defaults.altFormat || tp_inst._defaults.dateFormat, | |
| 4034 | + date = this._getDate(inst), | |
| 4035 | + formatCfg = $.datepicker._getFormatConfig(inst), | |
| 4036 | + altFormattedDateTime = '', | |
| 4037 | + altSeparator = tp_inst._defaults.altSeparator ? tp_inst._defaults.altSeparator : tp_inst._defaults.separator, | |
| 4038 | + altTimeSuffix = tp_inst._defaults.altTimeSuffix ? tp_inst._defaults.altTimeSuffix : tp_inst._defaults.timeSuffix, | |
| 4039 | + altTimeFormat = tp_inst._defaults.altTimeFormat !== null ? tp_inst._defaults.altTimeFormat : tp_inst._defaults.timeFormat; | |
| 4040 | + | |
| 4041 | + altFormattedDateTime += $.datepicker.formatTime(altTimeFormat, tp_inst, tp_inst._defaults) + altTimeSuffix; | |
| 4042 | + if(!tp_inst._defaults.timeOnly && !tp_inst._defaults.altFieldTimeOnly && date !== null){ | |
| 4043 | + if(tp_inst._defaults.altFormat) | |
| 4044 | + altFormattedDateTime = $.datepicker.formatDate(tp_inst._defaults.altFormat, date, formatCfg) + altSeparator + altFormattedDateTime; | |
| 4045 | + else altFormattedDateTime = tp_inst.formattedDate + altSeparator + altFormattedDateTime; | |
| 4046 | + } | |
| 4047 | + $(altField).val(altFormattedDateTime); | |
| 4048 | + } | |
| 4049 | + } | |
| 4050 | + else{ | |
| 4051 | + $.datepicker._base_updateAlternate(inst); | |
| 4052 | + } | |
| 4053 | + }; | |
| 4054 | + | |
| 4055 | + /* | |
| 4056 | + * Override key up event to sync manual input changes. | |
| 4057 | + */ | |
| 4058 | + $.datepicker._base_doKeyUp = $.datepicker._doKeyUp; | |
| 4059 | + $.datepicker._doKeyUp = function(event) { | |
| 4060 | + var inst = $.datepicker._getInst(event.target), | |
| 4061 | + tp_inst = $.datepicker._get(inst, 'timepicker'); | |
| 4062 | + | |
| 4063 | + if (tp_inst) { | |
| 4064 | + if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) { | |
| 4065 | + try { | |
| 4066 | + $.datepicker._updateDatepicker(inst); | |
| 4067 | + } catch (err) { | |
| 4068 | + $.timepicker.log(err); | |
| 4069 | + } | |
| 4070 | + } | |
| 4071 | + } | |
| 4072 | + | |
| 4073 | + return $.datepicker._base_doKeyUp(event); | |
| 4074 | + }; | |
| 4075 | + | |
| 4076 | + /* | |
| 4077 | + * override "Today" button to also grab the time. | |
| 4078 | + */ | |
| 4079 | + $.datepicker._base_gotoToday = $.datepicker._gotoToday; | |
| 4080 | + $.datepicker._gotoToday = function(id) { | |
| 4081 | + var inst = this._getInst($(id)[0]), | |
| 4082 | + $dp = inst.dpDiv; | |
| 4083 | + this._base_gotoToday(id); | |
| 4084 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4085 | + selectLocalTimeZone(tp_inst); | |
| 4086 | + var now = new Date(); | |
| 4087 | + this._setTime(inst, now); | |
| 4088 | + $('.ui-datepicker-today', $dp).click(); | |
| 4089 | + }; | |
| 4090 | + | |
| 4091 | + /* | |
| 4092 | + * Disable & enable the Time in the datetimepicker | |
| 4093 | + */ | |
| 4094 | + $.datepicker._disableTimepickerDatepicker = function(target) { | |
| 4095 | + var inst = this._getInst(target); | |
| 4096 | + if (!inst) { | |
| 4097 | + return; | |
| 4098 | + } | |
| 4099 | + | |
| 4100 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4101 | + $(target).datepicker('getDate'); // Init selected[Year|Month|Day] | |
| 4102 | + if (tp_inst) { | |
| 4103 | + tp_inst._defaults.showTimepicker = false; | |
| 4104 | + tp_inst._updateDateTime(inst); | |
| 4105 | + } | |
| 4106 | + }; | |
| 4107 | + | |
| 4108 | + $.datepicker._enableTimepickerDatepicker = function(target) { | |
| 4109 | + var inst = this._getInst(target); | |
| 4110 | + if (!inst) { | |
| 4111 | + return; | |
| 4112 | + } | |
| 4113 | + | |
| 4114 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4115 | + $(target).datepicker('getDate'); // Init selected[Year|Month|Day] | |
| 4116 | + if (tp_inst) { | |
| 4117 | + tp_inst._defaults.showTimepicker = true; | |
| 4118 | + tp_inst._addTimePicker(inst); // Could be disabled on page load | |
| 4119 | + tp_inst._updateDateTime(inst); | |
| 4120 | + } | |
| 4121 | + }; | |
| 4122 | + | |
| 4123 | + /* | |
| 4124 | + * Create our own set time function | |
| 4125 | + */ | |
| 4126 | + $.datepicker._setTime = function(inst, date) { | |
| 4127 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4128 | + if (tp_inst) { | |
| 4129 | + var defaults = tp_inst._defaults; | |
| 4130 | + | |
| 4131 | + // calling _setTime with no date sets time to defaults | |
| 4132 | + tp_inst.hour = date ? date.getHours() : defaults.hour; | |
| 4133 | + tp_inst.minute = date ? date.getMinutes() : defaults.minute; | |
| 4134 | + tp_inst.second = date ? date.getSeconds() : defaults.second; | |
| 4135 | + tp_inst.millisec = date ? date.getMilliseconds() : defaults.millisec; | |
| 4136 | + | |
| 4137 | + //check if within min/max times.. | |
| 4138 | + tp_inst._limitMinMaxDateTime(inst, true); | |
| 4139 | + | |
| 4140 | + tp_inst._onTimeChange(); | |
| 4141 | + tp_inst._updateDateTime(inst); | |
| 4142 | + } | |
| 4143 | + }; | |
| 4144 | + | |
| 4145 | + /* | |
| 4146 | + * Create new public method to set only time, callable as $().datepicker('setTime', date) | |
| 4147 | + */ | |
| 4148 | + $.datepicker._setTimeDatepicker = function(target, date, withDate) { | |
| 4149 | + var inst = this._getInst(target); | |
| 4150 | + if (!inst) { | |
| 4151 | + return; | |
| 4152 | + } | |
| 4153 | + | |
| 4154 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4155 | + | |
| 4156 | + if (tp_inst) { | |
| 4157 | + this._setDateFromField(inst); | |
| 4158 | + var tp_date; | |
| 4159 | + if (date) { | |
| 4160 | + if (typeof date == "string") { | |
| 4161 | + tp_inst._parseTime(date, withDate); | |
| 4162 | + tp_date = new Date(); | |
| 4163 | + tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); | |
| 4164 | + } else { | |
| 4165 | + tp_date = new Date(date.getTime()); | |
| 4166 | + } | |
| 4167 | + if (tp_date.toString() == 'Invalid Date') { | |
| 4168 | + tp_date = undefined; | |
| 4169 | + } | |
| 4170 | + this._setTime(inst, tp_date); | |
| 4171 | + } | |
| 4172 | + } | |
| 4173 | + | |
| 4174 | + }; | |
| 4175 | + | |
| 4176 | + /* | |
| 4177 | + * override setDate() to allow setting time too within Date object | |
| 4178 | + */ | |
| 4179 | + $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker; | |
| 4180 | + $.datepicker._setDateDatepicker = function(target, date) { | |
| 4181 | + var inst = this._getInst(target); | |
| 4182 | + if (!inst) { | |
| 4183 | + return; | |
| 4184 | + } | |
| 4185 | + | |
| 4186 | + var tp_date = (date instanceof Date) ? new Date(date.getTime()) : date; | |
| 4187 | + | |
| 4188 | + this._updateDatepicker(inst); | |
| 4189 | + this._base_setDateDatepicker.apply(this, arguments); | |
| 4190 | + this._setTimeDatepicker(target, tp_date, true); | |
| 4191 | + }; | |
| 4192 | + | |
| 4193 | + /* | |
| 4194 | + * override getDate() to allow getting time too within Date object | |
| 4195 | + */ | |
| 4196 | + $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker; | |
| 4197 | + $.datepicker._getDateDatepicker = function(target, noDefault) { | |
| 4198 | + var inst = this._getInst(target); | |
| 4199 | + if (!inst) { | |
| 4200 | + return; | |
| 4201 | + } | |
| 4202 | + | |
| 4203 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4204 | + | |
| 4205 | + if (tp_inst) { | |
| 4206 | + // if it hasn't yet been defined, grab from field | |
| 4207 | + if(inst.lastVal === undefined){ | |
| 4208 | + this._setDateFromField(inst, noDefault); | |
| 4209 | + } | |
| 4210 | + | |
| 4211 | + var date = this._getDate(inst); | |
| 4212 | + if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) { | |
| 4213 | + date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec); | |
| 4214 | + } | |
| 4215 | + return date; | |
| 4216 | + } | |
| 4217 | + return this._base_getDateDatepicker(target, noDefault); | |
| 4218 | + }; | |
| 4219 | + | |
| 4220 | + /* | |
| 4221 | + * override parseDate() because UI 1.8.14 throws an error about "Extra characters" | |
| 4222 | + * An option in datapicker to ignore extra format characters would be nicer. | |
| 4223 | + */ | |
| 4224 | + $.datepicker._base_parseDate = $.datepicker.parseDate; | |
| 4225 | + $.datepicker.parseDate = function(format, value, settings) { | |
| 4226 | + var date; | |
| 4227 | + try { | |
| 4228 | + date = this._base_parseDate(format, value, settings); | |
| 4229 | + } catch (err) { | |
| 4230 | + // Hack! The error message ends with a colon, a space, and | |
| 4231 | + // the "extra" characters. We rely on that instead of | |
| 4232 | + // attempting to perfectly reproduce the parsing algorithm. | |
| 4233 | + date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings); | |
| 4234 | + $.timepicker.log("Error parsing the date string: " + err + "\ndate string = " + value + "\ndate format = " + format); | |
| 4235 | + } | |
| 4236 | + return date; | |
| 4237 | + }; | |
| 4238 | + | |
| 4239 | + /* | |
| 4240 | + * override formatDate to set date with time to the input | |
| 4241 | + */ | |
| 4242 | + $.datepicker._base_formatDate = $.datepicker._formatDate; | |
| 4243 | + $.datepicker._formatDate = function(inst, day, month, year) { | |
| 4244 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4245 | + if (tp_inst) { | |
| 4246 | + tp_inst._updateDateTime(inst); | |
| 4247 | + return tp_inst.$input.val(); | |
| 4248 | + } | |
| 4249 | + return this._base_formatDate(inst); | |
| 4250 | + }; | |
| 4251 | + | |
| 4252 | + /* | |
| 4253 | + * override options setter to add time to maxDate(Time) and minDate(Time). MaxDate | |
| 4254 | + */ | |
| 4255 | + $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker; | |
| 4256 | + $.datepicker._optionDatepicker = function(target, name, value) { | |
| 4257 | + var inst = this._getInst(target), | |
| 4258 | + name_clone; | |
| 4259 | + if (!inst) { | |
| 4260 | + return null; | |
| 4261 | + } | |
| 4262 | + | |
| 4263 | + var tp_inst = this._get(inst, 'timepicker'); | |
| 4264 | + if (tp_inst) { | |
| 4265 | + var min = null, | |
| 4266 | + max = null, | |
| 4267 | + onselect = null, | |
| 4268 | + overrides = tp_inst._defaults.evnts, | |
| 4269 | + fns = {}, | |
| 4270 | + prop; | |
| 4271 | + if (typeof name == 'string') { // if min/max was set with the string | |
| 4272 | + if (name === 'minDate' || name === 'minDateTime') { | |
| 4273 | + min = value; | |
| 4274 | + } else if (name === 'maxDate' || name === 'maxDateTime') { | |
| 4275 | + max = value; | |
| 4276 | + } else if (name === 'onSelect') { | |
| 4277 | + onselect = value; | |
| 4278 | + } else if (overrides.hasOwnProperty(name)) { | |
| 4279 | + if (typeof (value) === 'undefined') { | |
| 4280 | + return overrides[name]; | |
| 4281 | + } | |
| 4282 | + fns[name] = value; | |
| 4283 | + name_clone = {}; //empty results in exiting function after overrides updated | |
| 4284 | + } | |
| 4285 | + } else if (typeof name == 'object') { //if min/max was set with the JSON | |
| 4286 | + if (name.minDate) { | |
| 4287 | + min = name.minDate; | |
| 4288 | + } else if (name.minDateTime) { | |
| 4289 | + min = name.minDateTime; | |
| 4290 | + } else if (name.maxDate) { | |
| 4291 | + max = name.maxDate; | |
| 4292 | + } else if (name.maxDateTime) { | |
| 4293 | + max = name.maxDateTime; | |
| 4294 | + } | |
| 4295 | + for (prop in overrides) { | |
| 4296 | + if (overrides.hasOwnProperty(prop) && name[prop]) { | |
| 4297 | + fns[prop] = name[prop]; | |
| 4298 | + } | |
| 4299 | + } | |
| 4300 | + } | |
| 4301 | + for (prop in fns) { | |
| 4302 | + if (fns.hasOwnProperty(prop)) { | |
| 4303 | + overrides[prop] = fns[prop]; | |
| 4304 | + if (!name_clone) { name_clone = $.extend({}, name);} | |
| 4305 | + delete name_clone[prop]; | |
| 4306 | + } | |
| 4307 | + } | |
| 4308 | + if (name_clone && isEmptyObject(name_clone)) { return; } | |
| 4309 | + if (min) { //if min was set | |
| 4310 | + if (min === 0) { | |
| 4311 | + min = new Date(); | |
| 4312 | + } else { | |
| 4313 | + min = new Date(min); | |
| 4314 | + } | |
| 4315 | + tp_inst._defaults.minDate = min; | |
| 4316 | + tp_inst._defaults.minDateTime = min; | |
| 4317 | + } else if (max) { //if max was set | |
| 4318 | + if (max === 0) { | |
| 4319 | + max = new Date(); | |
| 4320 | + } else { | |
| 4321 | + max = new Date(max); | |
| 4322 | + } | |
| 4323 | + tp_inst._defaults.maxDate = max; | |
| 4324 | + tp_inst._defaults.maxDateTime = max; | |
| 4325 | + } else if (onselect) { | |
| 4326 | + tp_inst._defaults.onSelect = onselect; | |
| 4327 | + } | |
| 4328 | + } | |
| 4329 | + if (value === undefined) { | |
| 4330 | + return this._base_optionDatepicker.call($.datepicker, target, name); | |
| 4331 | + } | |
| 4332 | + return this._base_optionDatepicker.call($.datepicker, target, name_clone || name, value); | |
| 4333 | + }; | |
| 4334 | + /* | |
| 4335 | + * jQuery isEmptyObject does not check hasOwnProperty - if someone has added to the object prototype, | |
| 4336 | + * it will return false for all objects | |
| 4337 | + */ | |
| 4338 | + var isEmptyObject = function(obj) { | |
| 4339 | + var prop; | |
| 4340 | + for (prop in obj) { | |
| 4341 | + if (obj.hasOwnProperty(obj)) { | |
| 4342 | + return false; | |
| 4343 | + } | |
| 4344 | + } | |
| 4345 | + return true; | |
| 4346 | + }; | |
| 4347 | + | |
| 4348 | + /* | |
| 4349 | + * jQuery extend now ignores nulls! | |
| 4350 | + */ | |
| 4351 | + var extendRemove = function(target, props) { | |
| 4352 | + $.extend(target, props); | |
| 4353 | + for (var name in props) { | |
| 4354 | + if (props[name] === null || props[name] === undefined) { | |
| 4355 | + target[name] = props[name]; | |
| 4356 | + } | |
| 4357 | + } | |
| 4358 | + return target; | |
| 4359 | + }; | |
| 4360 | + | |
| 4361 | + /* | |
| 4362 | + * Determine by the time format if should use ampm | |
| 4363 | + * Returns true if should use ampm, false if not | |
| 4364 | + */ | |
| 4365 | + var useAmpm = function(timeFormat){ | |
| 4366 | + return (timeFormat.indexOf('t') !== -1 && timeFormat.indexOf('h') !== -1); | |
| 4367 | + }; | |
| 4368 | + | |
| 4369 | + /* | |
| 4370 | + * Converts 24 hour format into 12 hour | |
| 4371 | + * Returns 12 hour without leading 0 | |
| 4372 | + */ | |
| 4373 | + var convert24to12 = function(hour) { | |
| 4374 | + if (hour > 12) { | |
| 4375 | + hour = hour - 12; | |
| 4376 | + } | |
| 4377 | + | |
| 4378 | + if (hour == 0) { | |
| 4379 | + hour = 12; | |
| 4380 | + } | |
| 4381 | + | |
| 4382 | + return String(hour); | |
| 4383 | + }; | |
| 4384 | + | |
| 4385 | + /* | |
| 4386 | + * Splits datetime string into date ans time substrings. | |
| 4387 | + * Throws exception when date can't be parsed | |
| 4388 | + * Returns [dateString, timeString] | |
| 4389 | + */ | |
| 4390 | + var splitDateTime = function(dateFormat, dateTimeString, dateSettings, timeSettings) { | |
| 4391 | + try { | |
| 4392 | + // The idea is to get the number separator occurances in datetime and the time format requested (since time has | |
| 4393 | + // fewer unknowns, mostly numbers and am/pm). We will use the time pattern to split. | |
| 4394 | + var separator = timeSettings && timeSettings.separator ? timeSettings.separator : $.timepicker._defaults.separator, | |
| 4395 | + format = timeSettings && timeSettings.timeFormat ? timeSettings.timeFormat : $.timepicker._defaults.timeFormat, | |
| 4396 | + timeParts = format.split(separator), // how many occurances of separator may be in our format? | |
| 4397 | + timePartsLen = timeParts.length, | |
| 4398 | + allParts = dateTimeString.split(separator), | |
| 4399 | + allPartsLen = allParts.length; | |
| 4400 | + | |
| 4401 | + if (allPartsLen > 1) { | |
| 4402 | + return [ | |
| 4403 | + allParts.splice(0,allPartsLen-timePartsLen).join(separator), | |
| 4404 | + allParts.splice(0,timePartsLen).join(separator) | |
| 4405 | + ]; | |
| 4406 | + } | |
| 4407 | + | |
| 4408 | + } catch (err) { | |
| 4409 | + $.timepicker.log('Could not split the date from the time. Please check the following datetimepicker options' + | |
| 4410 | + "\nthrown error: " + err + | |
| 4411 | + "\ndateTimeString" + dateTimeString + | |
| 4412 | + "\ndateFormat = " + dateFormat + | |
| 4413 | + "\nseparator = " + timeSettings.separator + | |
| 4414 | + "\ntimeFormat = " + timeSettings.timeFormat); | |
| 4415 | + | |
| 4416 | + if (err.indexOf(":") >= 0) { | |
| 4417 | + // Hack! The error message ends with a colon, a space, and | |
| 4418 | + // the "extra" characters. We rely on that instead of | |
| 4419 | + // attempting to perfectly reproduce the parsing algorithm. | |
| 4420 | + var dateStringLength = dateTimeString.length - (err.length - err.indexOf(':') - 2), | |
| 4421 | + timeString = dateTimeString.substring(dateStringLength); | |
| 4422 | + | |
| 4423 | + return [$.trim(dateTimeString.substring(0, dateStringLength)), $.trim(dateTimeString.substring(dateStringLength))]; | |
| 4424 | + | |
| 4425 | + } else { | |
| 4426 | + throw err; | |
| 4427 | + } | |
| 4428 | + } | |
| 4429 | + return [dateTimeString, '']; | |
| 4430 | + }; | |
| 4431 | + | |
| 4432 | + /* | |
| 4433 | + * Internal function to parse datetime interval | |
| 4434 | + * Returns: {date: Date, timeObj: Object}, where | |
| 4435 | + * date - parsed date without time (type Date) | |
| 4436 | + * timeObj = {hour: , minute: , second: , millisec: } - parsed time. Optional | |
| 4437 | + */ | |
| 4438 | + var parseDateTimeInternal = function(dateFormat, timeFormat, dateTimeString, dateSettings, timeSettings) { | |
| 4439 | + var date; | |
| 4440 | + var splitRes = splitDateTime(dateFormat, dateTimeString, dateSettings, timeSettings); | |
| 4441 | + date = $.datepicker._base_parseDate(dateFormat, splitRes[0], dateSettings); | |
| 4442 | + if (splitRes[1] !== '') { | |
| 4443 | + var timeString = splitRes[1], | |
| 4444 | + parsedTime = $.datepicker.parseTime(timeFormat, timeString, timeSettings); | |
| 4445 | + | |
| 4446 | + if (parsedTime === null) { | |
| 4447 | + throw 'Wrong time format'; | |
| 4448 | + } | |
| 4449 | + return { | |
| 4450 | + date: date, | |
| 4451 | + timeObj: parsedTime | |
| 4452 | + }; | |
| 4453 | + } else { | |
| 4454 | + return { | |
| 4455 | + date: date | |
| 4456 | + }; | |
| 4457 | + } | |
| 4458 | + }; | |
| 4459 | + | |
| 4460 | + /* | |
| 4461 | + * Internal function to set timezone_select to the local timezone | |
| 4462 | + */ | |
| 4463 | + var selectLocalTimeZone = function(tp_inst, date) { | |
| 4464 | + if (tp_inst && tp_inst.timezone_select) { | |
| 4465 | + tp_inst._defaults.useLocalTimezone = true; | |
| 4466 | + var now = typeof date !== 'undefined' ? date : new Date(); | |
| 4467 | + var tzoffset = $.timepicker.timeZoneOffsetString(now); | |
| 4468 | + if (tp_inst._defaults.timezoneIso8601) { | |
| 4469 | + tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3); | |
| 4470 | + } | |
| 4471 | + tp_inst.timezone_select.val(tzoffset); | |
| 4472 | + } | |
| 4473 | + }; | |
| 4474 | + | |
| 4475 | + /* | |
| 4476 | + * Create a Singleton Insance | |
| 4477 | + */ | |
| 4478 | + $.timepicker = new Timepicker(); | |
| 4479 | + | |
| 4480 | + /** | |
| 4481 | + * Get the timezone offset as string from a date object (eg '+0530' for UTC+5.5) | |
| 4482 | + * @param date | |
| 4483 | + * @return string | |
| 4484 | + */ | |
| 4485 | + $.timepicker.timeZoneOffsetString = function(date) { | |
| 4486 | + var off = date.getTimezoneOffset() * -1, | |
| 4487 | + minutes = off % 60, | |
| 4488 | + hours = (off - minutes) / 60; | |
| 4489 | + return (off >= 0 ? '+' : '-') + ('0' + (hours * 101).toString()).slice(-2) + ('0' + (minutes * 101).toString()).slice(-2); | |
| 4490 | + }; | |
| 4491 | + | |
| 4492 | + /** | |
| 4493 | + * Calls `timepicker()` on the `startTime` and `endTime` elements, and configures them to | |
| 4494 | + * enforce date range limits. | |
| 4495 | + * n.b. The input value must be correctly formatted (reformatting is not supported) | |
| 4496 | + * @param Element startTime | |
| 4497 | + * @param Element endTime | |
| 4498 | + * @param obj options Options for the timepicker() call | |
| 4499 | + * @return jQuery | |
| 4500 | + */ | |
| 4501 | + $.timepicker.timeRange = function(startTime, endTime, options) { | |
| 4502 | + return $.timepicker.handleRange('timepicker', startTime, endTime, options); | |
| 4503 | + }; | |
| 4504 | + | |
| 4505 | + /** | |
| 4506 | + * Calls `datetimepicker` on the `startTime` and `endTime` elements, and configures them to | |
| 4507 | + * enforce date range limits. | |
| 4508 | + * @param Element startTime | |
| 4509 | + * @param Element endTime | |
| 4510 | + * @param obj options Options for the `timepicker()` call. Also supports `reformat`, | |
| 4511 | + * a boolean value that can be used to reformat the input values to the `dateFormat`. | |
| 4512 | + * @param string method Can be used to specify the type of picker to be added | |
| 4513 | + * @return jQuery | |
| 4514 | + */ | |
| 4515 | + $.timepicker.dateTimeRange = function(startTime, endTime, options) { | |
| 4516 | + $.timepicker.dateRange(startTime, endTime, options, 'datetimepicker'); | |
| 4517 | + }; | |
| 4518 | + | |
| 4519 | + /** | |
| 4520 | + * Calls `method` on the `startTime` and `endTime` elements, and configures them to | |
| 4521 | + * enforce date range limits. | |
| 4522 | + * @param Element startTime | |
| 4523 | + * @param Element endTime | |
| 4524 | + * @param obj options Options for the `timepicker()` call. Also supports `reformat`, | |
| 4525 | + * a boolean value that can be used to reformat the input values to the `dateFormat`. | |
| 4526 | + * @param string method Can be used to specify the type of picker to be added | |
| 4527 | + * @return jQuery | |
| 4528 | + */ | |
| 4529 | + $.timepicker.dateRange = function(startTime, endTime, options, method) { | |
| 4530 | + method = method || 'datepicker'; | |
| 4531 | + $.timepicker.handleRange(method, startTime, endTime, options); | |
| 4532 | + }; | |
| 4533 | + | |
| 4534 | + /** | |
| 4535 | + * Calls `method` on the `startTime` and `endTime` elements, and configures them to | |
| 4536 | + * enforce date range limits. | |
| 4537 | + * @param string method Can be used to specify the type of picker to be added | |
| 4538 | + * @param Element startTime | |
| 4539 | + * @param Element endTime | |
| 4540 | + * @param obj options Options for the `timepicker()` call. Also supports `reformat`, | |
| 4541 | + * a boolean value that can be used to reformat the input values to the `dateFormat`. | |
| 4542 | + * @return jQuery | |
| 4543 | + */ | |
| 4544 | + $.timepicker.handleRange = function(method, startTime, endTime, options) { | |
| 4545 | + $.fn[method].call(startTime, $.extend({ | |
| 4546 | + onClose: function(dateText, inst) { | |
| 4547 | + checkDates(this, endTime, dateText); | |
| 4548 | + }, | |
| 4549 | + onSelect: function(selectedDateTime) { | |
| 4550 | + selected(this, endTime, 'minDate'); | |
| 4551 | + } | |
| 4552 | + }, options, options.start)); | |
| 4553 | + $.fn[method].call(endTime, $.extend({ | |
| 4554 | + onClose: function(dateText, inst) { | |
| 4555 | + checkDates(this, startTime, dateText); | |
| 4556 | + }, | |
| 4557 | + onSelect: function(selectedDateTime) { | |
| 4558 | + selected(this, startTime, 'maxDate'); | |
| 4559 | + } | |
| 4560 | + }, options, options.end)); | |
| 4561 | + // timepicker doesn't provide access to its 'timeFormat' option, | |
| 4562 | + // nor could I get datepicker.formatTime() to behave with times, so I | |
| 4563 | + // have disabled reformatting for timepicker | |
| 4564 | + if (method != 'timepicker' && options.reformat) { | |
| 4565 | + $([startTime, endTime]).each(function() { | |
| 4566 | + var format = $(this)[method].call($(this), 'option', 'dateFormat'), | |
| 4567 | + date = new Date($(this).val()); | |
| 4568 | + if ($(this).val() && date) { | |
| 4569 | + $(this).val($.datepicker.formatDate(format, date)); | |
| 4570 | + } | |
| 4571 | + }); | |
| 4572 | + } | |
| 4573 | + checkDates(startTime, endTime, startTime.val()); | |
| 4574 | + | |
| 4575 | + function checkDates(changed, other, dateText) { | |
| 4576 | + if (other.val() && (new Date(startTime.val()) > new Date(endTime.val()))) { | |
| 4577 | + other.val(dateText); | |
| 4578 | + } | |
| 4579 | + } | |
| 4580 | + selected(startTime, endTime, 'minDate'); | |
| 4581 | + selected(endTime, startTime, 'maxDate'); | |
| 4582 | + | |
| 4583 | + function selected(changed, other, option) { | |
| 4584 | + if (!$(changed).val()) { | |
| 4585 | + return; | |
| 4586 | + } | |
| 4587 | + var date = $(changed)[method].call($(changed), 'getDate'); | |
| 4588 | + // timepicker doesn't implement 'getDate' and returns a jQuery | |
| 4589 | + if (date.getTime) { | |
| 4590 | + $(other)[method].call($(other), 'option', option, date); | |
| 4591 | + } | |
| 4592 | + } | |
| 4593 | + return $([startTime.get(0), endTime.get(0)]); | |
| 4594 | + }; | |
| 4595 | + | |
| 4596 | + /** | |
| 4597 | + * Log error or data to the console during error or debugging | |
| 4598 | + * @param Object err pass any type object to log to the console during error or debugging | |
| 4599 | + * @return void | |
| 4600 | + */ | |
| 4601 | + $.timepicker.log = function(err){ | |
| 4602 | + if(window.console) | |
| 4603 | + console.log(err); | |
| 4604 | + }; | |
| 4605 | + | |
| 4606 | + /* | |
| 4607 | + * Keep up with the version | |
| 4608 | + */ | |
| 4609 | + $.timepicker.version = "1.2"; | |
| 4610 | + | |
| 4611 | +})(jQuery); | |
| 4612 | 4612 | |
| 4613 | 4613 | /* assets/wpuf/js/upload.js */ |
| 4614 | 4614 | ;(function($) { |
| 4615 | 4615 | |