|
101 | 101 | timezoneList: null,
|
102 | 102 | addSliderAccess: false,
|
103 | 103 | sliderAccessArgs: null,
|
| 104 | + controlType: 'slider', |
104 | 105 | defaultValue: null
|
105 | 106 | };
|
106 | 107 | $.extend(this._defaults, this.regional['']);
|
|
136 | 137 | formattedDateTime: '',
|
137 | 138 | timezoneList: null,
|
138 | 139 | units: ['hour','minute','second','millisec'],
|
| 140 | + control: null, |
139 | 141 |
|
140 | 142 | /*
|
141 | 143 | * Override the default settings for all instances of the time picker.
|
|
206 | 208 | return val.toUpperCase();
|
207 | 209 | });
|
208 | 210 |
|
| 211 | + // select control type will always be available |
| 212 | + if(tp_inst._defaults.controlType == 'slider' && $.fn.slider === undefined){ |
| 213 | + tp_inst._defaults.controlType = 'select'; |
| 214 | + } |
| 215 | + |
209 | 216 | if (tp_inst._defaults.timezoneList === null) {
|
210 | 217 | var timezoneList = ['-1200', '-1100', '-1000', '-0930', '-0900', '-0800', '-0700', '-0600', '-0500', '-0430', '-0400', '-0330', '-0300', '-0200', '-0100', '+0000',
|
211 | 218 | '+0100', '+0200', '+0300', '+0330', '+0400', '+0430', '+0500', '+0530', '+0545', '+0600', '+0630', '+0700', '+0800', '+0845', '+0900', '+0930',
|
|
219 | 226 | tp_inst._defaults.timezoneList = timezoneList;
|
220 | 227 | }
|
221 | 228 |
|
| 229 | + tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType]; |
222 | 230 | tp_inst.timezone = tp_inst._defaults.timezone;
|
223 | 231 | tp_inst.hour = tp_inst._defaults.hour;
|
224 | 232 | tp_inst.minute = tp_inst._defaults.minute;
|
|
391 | 399 | uitem = litem.substr(0,1).toUpperCase() + litem.substr(1);
|
392 | 400 |
|
393 | 401 | // add the slider
|
394 |
| - tp_inst[litem+'_slider'] = $tp.find('.ui_tpicker_'+litem+'_slider').prop('slide', null).slider({ |
395 |
| - orientation: "horizontal", |
396 |
| - value: tp_inst[litem], |
397 |
| - min: o[litem+'Min'], |
398 |
| - max: max[litem], |
399 |
| - step: o['step'+uitem], |
400 |
| - slide: function(event, ui) { |
401 |
| - $(this).slider("option", "value", ui.value); |
402 |
| - tp_inst._onTimeChange(); |
403 |
| - }, |
404 |
| - stop: function(event, ui) { |
405 |
| - //Emulate datepicker onSelect behavior. Call on slidestop. |
406 |
| - tp_inst._onSelectHandler(); |
407 |
| - } |
408 |
| - }); |
| 402 | + 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]); |
409 | 403 |
|
410 | 404 | // adjust the grid and add click event
|
411 | 405 | if (o['show'+uitem] && o[litem+'Grid'] > 0) {
|
|
434 | 428 | h = aph + 12;
|
435 | 429 | }
|
436 | 430 | }
|
437 |
| - tp_inst[f+'_slider'].slider("option", "value", parseInt(h,10)); |
| 431 | + tp_inst.control.value(tp_inst, tp_inst[f+'_slider'], parseInt(h,10)); |
| 432 | + |
438 | 433 | tp_inst._onTimeChange();
|
439 | 434 | tp_inst._onSelectHandler();
|
440 | 435 | })
|
|
626 | 621 | millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)), 10);
|
627 | 622 |
|
628 | 623 | if (this.hour_slider) {
|
629 |
| - this.hour_slider.slider("option", { |
630 |
| - min: this._defaults.hourMin, |
631 |
| - max: hourMax |
632 |
| - }).slider('value', this.hour); |
| 624 | + this.control.options(this, this.hour_slider, { min: this._defaults.hourMin, max: hourMax }); |
| 625 | + this.control.value(this, this.hour_slider, this.hour); |
633 | 626 | }
|
634 | 627 | if (this.minute_slider) {
|
635 |
| - this.minute_slider.slider("option", { |
636 |
| - min: this._defaults.minuteMin, |
637 |
| - max: minMax |
638 |
| - }).slider('value', this.minute); |
| 628 | + this.control.options(this, this.minute_slider, { min: this._defaults.minuteMin, max: minMax }); |
| 629 | + this.control.value(this, this.minute_slider, this.minute); |
639 | 630 | }
|
640 | 631 | if (this.second_slider) {
|
641 |
| - this.second_slider.slider("option", { |
642 |
| - min: this._defaults.secondMin, |
643 |
| - max: secMax |
644 |
| - }).slider('value', this.second); |
| 632 | + this.control.options(this, this.second_slider, { min: this._defaults.secondMin, max: secMax }); |
| 633 | + this.control.value(this, this.second_slider, this.second); |
645 | 634 | }
|
646 | 635 | if (this.millisec_slider) {
|
647 |
| - this.millisec_slider.slider("option", { |
648 |
| - min: this._defaults.millisecMin, |
649 |
| - max: millisecMax |
650 |
| - }).slider('value', this.millisec); |
| 636 | + this.control.options(this, this.millisec_slider, { min: this._defaults.millisecMin, max: millisecMax }); |
| 637 | + this.control.value(this, this.millisec_slider, this.millisec); |
651 | 638 | }
|
652 | 639 | }
|
653 | 640 |
|
|
658 | 645 | * on time change is also called when the time is updated in the text field
|
659 | 646 | */
|
660 | 647 | _onTimeChange: function() {
|
661 |
| - var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false, |
662 |
| - minute = (this.minute_slider) ? this.minute_slider.slider('value') : false, |
663 |
| - second = (this.second_slider) ? this.second_slider.slider('value') : false, |
664 |
| - millisec = (this.millisec_slider) ? this.millisec_slider.slider('value') : false, |
| 648 | + var hour = (this.hour_slider) ? this.control.value(this, this.hour_slider) : false, |
| 649 | + minute = (this.minute_slider) ? this.control.value(this, this.minute_slider) : false, |
| 650 | + second = (this.second_slider) ? this.control.value(this, this.second_slider) : false, |
| 651 | + millisec = (this.millisec_slider) ? this.control.value(this, this.millisec_slider) : false, |
665 | 652 | timezone = (this.timezone_select) ? this.timezone_select.val() : false,
|
666 | 653 | o = this._defaults;
|
667 | 654 |
|
|
843 | 830 | }
|
844 | 831 | }
|
845 | 832 | }
|
| 833 | + }, |
| 834 | + |
| 835 | + /* |
| 836 | + * Small abstraction to control types |
| 837 | + */ |
| 838 | + _controls: { |
| 839 | + slider: { |
| 840 | + create: function(tp_inst, obj, unit, val, min, max, step){ |
| 841 | + return obj.prop('slide', null).slider({ |
| 842 | + orientation: "horizontal", |
| 843 | + value: val, |
| 844 | + min: min, |
| 845 | + max: max, |
| 846 | + step: step, |
| 847 | + slide: function(event, ui) { |
| 848 | + tp_inst.control.value(tp_inst, $(this), ui.value); |
| 849 | + tp_inst._onTimeChange(); |
| 850 | + }, |
| 851 | + stop: function(event, ui) { |
| 852 | + tp_inst._onSelectHandler(); |
| 853 | + } |
| 854 | + }); |
| 855 | + }, |
| 856 | + options: function(tp_inst, obj, opts, val){ |
| 857 | + if(typeof(opts) == 'string' && val !== undefined) |
| 858 | + return obj.slider(opts, val); |
| 859 | + return obj.slider(opts); |
| 860 | + }, |
| 861 | + value: function(tp_inst, obj, val){ |
| 862 | + if(val !== undefined) |
| 863 | + return obj.slider('value', val); |
| 864 | + return obj.slider('value'); |
| 865 | + } |
| 866 | + }, |
| 867 | + select: { |
| 868 | + create: function(tp_inst, obj, unit, val, min, max, step){ |
| 869 | + var sel = '<select class="ui-timepicker-select" data-unit="'+ unit +'" data-min="'+ min +'" data-max="'+ max +'" data-step="'+ step +'">', |
| 870 | + ul = tp_inst._defaults.timeFormat.indexOf('t') !== -1? 'toLowerCase':'toUpperCase'; |
| 871 | + |
| 872 | + for(var i=min; i<=max; i+=step){ |
| 873 | + sel += '<option value="'+ i +'"'+ (i==val? ' selected':'') +'>'; |
| 874 | + if(unit == 'hour' && tp_inst._defaults.ampm){ |
| 875 | + if(i === 0 || i === 12) |
| 876 | + sel += '12'; |
| 877 | + else sel += ('0'+ (i%12).toString()).substr(-2); |
| 878 | + sel += ' '+ ((i<12)? tp_inst._defaults.amNames[0] : tp_inst._defaults.pmNames[0])[ul](); |
| 879 | + } |
| 880 | + else if(unit == 'millisec') sel += i; |
| 881 | + else sel += ('0'+ i.toString()).substr(-2) |
| 882 | + sel += '</option>'; |
| 883 | + } |
| 884 | + sel += '</select>'; |
| 885 | + |
| 886 | + obj.children('select').remove(); |
| 887 | + |
| 888 | + $(sel).appendTo(obj).change(function(e){ |
| 889 | + tp_inst._onTimeChange(); |
| 890 | + tp_inst._onSelectHandler(); |
| 891 | + }); |
| 892 | + |
| 893 | + return obj; |
| 894 | + }, |
| 895 | + options: function(tp_inst, obj, opts, val){ |
| 896 | + var o = {}, |
| 897 | + $t = obj.find('select'); |
| 898 | + |
| 899 | + if(typeof(opts) == 'string'){ |
| 900 | + if(val == undefined) |
| 901 | + return $t.data(opts); |
| 902 | + o[opts] = val; |
| 903 | + } |
| 904 | + |
| 905 | + 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')); |
| 906 | + }, |
| 907 | + value: function(tp_inst, obj, val){ |
| 908 | + var $t = obj.children('select'); |
| 909 | + if(val !== undefined) |
| 910 | + return $t.val(val); |
| 911 | + return $t.val(); |
| 912 | + } |
| 913 | + } |
846 | 914 | }
|
847 | 915 |
|
848 | 916 | });
|
|
0 commit comments