jquery_datetimepick 1.3.1

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