venus 0.7.11 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +28 -0
  3. data/README.md +43 -2
  4. data/lib/generators/venus/asset_sync/asset_sync_generator.rb +5 -2
  5. data/lib/generators/venus/asset_sync/templates/asset_sync.rb.erb +8 -1
  6. data/lib/generators/venus/better_errors/better_errors_generator.rb +27 -0
  7. data/lib/generators/venus/better_errors/templates/better_errors.erb +1 -0
  8. data/lib/generators/venus/bootstrap/templates/simple_form_config.erb +3 -2
  9. data/lib/generators/venus/carrierwave/carrierwave_generator.rb +1 -1
  10. data/lib/generators/venus/carrierwave/templates/uploader.erb +1 -1
  11. data/lib/generators/venus/chosen/chosen_generator.rb +1 -1
  12. data/lib/generators/venus/deploy/deploy_generator.rb +7 -0
  13. data/lib/generators/venus/helpers.rb +1 -1
  14. data/lib/generators/venus/hipchat/hipchat_generator.rb +35 -0
  15. data/lib/generators/venus/hipchat/templates/deploy.rb.erb +23 -0
  16. data/lib/generators/venus/init/init_generator.rb +10 -25
  17. data/lib/generators/venus/jqueryui/jqueryui_generator.rb +2 -2
  18. data/lib/generators/venus/jqueryui/templates/jquery.timepicker.css +5 -1
  19. data/lib/generators/venus/jqueryui/templates/jquery.timepicker.js +1967 -1190
  20. data/lib/generators/venus/newrelic/newrelic_generator.rb +32 -0
  21. data/lib/generators/venus/newrelic/templates/newrelic.yml.erb +226 -0
  22. data/lib/generators/venus/puma/puma_generator.rb +30 -0
  23. data/lib/generators/venus/puma/templates/config.erb +129 -0
  24. data/lib/generators/venus/puma/templates/deploy.rb.erb +2 -0
  25. data/lib/generators/venus/puma/templates/nginx.conf.erb +25 -0
  26. data/lib/generators/venus/rails_panel/rails_panel_generator.rb +18 -0
  27. data/lib/generators/venus/rails_panel/templates/better_errors.erb +1 -0
  28. data/lib/generators/venus/sentry/sentry_generator.rb +35 -0
  29. data/lib/generators/venus/sentry/templates/js.erb +4 -0
  30. data/lib/generators/venus/sentry/templates/raven.erb +7 -0
  31. data/lib/generators/venus/sidekiq/sidekiq_generator.rb +1 -1
  32. data/lib/generators/venus/unicorn/templates/deploy.rb.erb +3 -0
  33. data/lib/generators/venus/unicorn/templates/nginx.conf.erb +25 -0
  34. data/lib/generators/venus/unicorn/templates/unicorn.rb.erb +18 -0
  35. data/lib/generators/venus/unicorn/unicorn_generator.rb +37 -0
  36. data/lib/venus/version.rb +1 -1
  37. metadata +34 -24
  38. data/lib/generators/venus/init/templates/gem_developments.erb +0 -5
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dde72a4b2fc22998b65ad817f9f31ae2f43043eb
4
+ data.tar.gz: 805bf4481c2dc8482c513eb519716a9c482ece41
5
+ SHA512:
6
+ metadata.gz: 639643e9a6c1ffdaad86301dc1e22daa694cf25c0b8f59460b91a25404cca942534fa5c18e754579ab72eab8202b1a16981bb5b0e9207691fcd6f55d7829388b
7
+ data.tar.gz: 680bd55bdb50edb49fbc82d2b454a8b57bde97d42b43be7f10047bf8cb9a366e9e1c3d79afb0a19742d1a859f0e40998e54763e79cabbddcd38743c36c36c8e2
@@ -0,0 +1,28 @@
1
+ ## 0.8.6
2
+
3
+ Features:
4
+
5
+ - Add unicorn generator, `rails generate venus:unicorn`.
6
+ - Ask generate venus:puma after generate venus:deploy.
7
+ - Add puma server generator, `rails generate venus:puma`.
8
+ - Newrelic 3.6.5 generator.
9
+ - Sentry generator for cloud exceptions storage.
10
+ - Hipchat generator for deploy notification.
11
+ - better_errors generator for rendering errors clearly.
12
+ - Bind better_errors generator into init generator.
13
+ - rails_panel generator for debugging request in Chrome.
14
+ - Bind rails_panel generator into init generator.
15
+
16
+ Updates:
17
+
18
+ - Always upload files config hint in config/asset_sync.rb
19
+ - Replace rmagick to mini_magick in carrierwave generator.
20
+ - Upgrade sidekiq to 2.12.4 .
21
+ - Remove HAML in init generator.
22
+ - Upgrade timepicker to 1.3 .
23
+ - Upgrade chosen-rails to 0.9.15 .
24
+ - Upgrade jqueryui-rails to 4.0.3 .
25
+
26
+ Fixes:
27
+
28
+ - Simple form config for bootstrap.
data/README.md CHANGED
@@ -10,7 +10,7 @@ Installation
10
10
  ```ruby
11
11
  group :development do
12
12
  ...
13
- gem 'venus', '~> 0.7.11'
13
+ gem 'venus', '~> 0.8.6'
14
14
  ...
15
15
  end
16
16
  ```
@@ -30,6 +30,48 @@ end
30
30
  Usage
31
31
  =====
32
32
 
33
+ * rails_panel generator for debugging request in Chrome.
34
+
35
+ ```
36
+ rails generate venus:rails_panel
37
+ ```
38
+
39
+ * better_errors generator for rendering errors clearly.
40
+
41
+ ```
42
+ rails generate venus:better_errors
43
+ ```
44
+
45
+ * Hipchat generator for notification while deploy.
46
+
47
+ ```
48
+ rails generate venus:hipchat
49
+ ```
50
+
51
+ * getsentry.com installation for cloud exceptions storage.
52
+
53
+ ```
54
+ rails generate venus:sentry
55
+ ```
56
+
57
+ * `newrelic_rpm` gem.
58
+
59
+ ```
60
+ rails generate venus:newrelic
61
+ ```
62
+
63
+ * `puma` server
64
+
65
+ ```
66
+ rails generate venus:puma
67
+ ```
68
+
69
+ * `unicorn` for zero downtime deployment
70
+
71
+ ```
72
+ rails generate venus:unicorn
73
+ ```
74
+
33
75
  * `asset_sync` for upload assets files to AWS S3 after precompile
34
76
 
35
77
  ```
@@ -142,7 +184,6 @@ Usage
142
184
  TODO
143
185
  ====
144
186
 
145
- * Unicorn setup for capistrano.
146
187
  * MongoDB configuration.
147
188
  * RailsAdmin or ActiveAdmin.
148
189
  * Amazon Elastic Cache & cells.
@@ -16,10 +16,11 @@ module Venus
16
16
  @settings[:aws_assets_bucket] = ask?("AWS S3 bucket for assets sync", app_name) unless key_in_settingslogic?("aws_assets_bucket")
17
17
  @settings[:aws_assets_host] = ask?("AWS S3 host for assets sync", "#{app_name}.s3-website-us-east-1.amazonaws.com") unless key_in_settingslogic?("aws_assets_host")
18
18
  @settings[:aws_assets_path_prefix] = ask?("AWS S3 assets path prefix", "") unless key_in_settingslogic?("aws_assets_path_prefix")
19
+ # @has_ckeditor_rails = ask?("has ckeditor-rails?", false)
19
20
  end
20
21
 
21
22
  def set_gemfile
22
- append_gem_into_group(:assets, "asset_sync", "~> 0.5.4")
23
+ add_gem("asset_sync", "~> 0.5.4")
23
24
  bundle_install
24
25
  end
25
26
 
@@ -32,7 +33,9 @@ module Venus
32
33
 
33
34
  def production_rb
34
35
  to_file = "config/environments/production.rb"
35
- line = " config.action_controller.asset_host = #{@settinglogic_class}.aws_assets_host"
36
+ # if(@has_ckeditor_rails)
37
+ line = "# config.relative_url_root = \"http://\#{#{@settinglogic_class}.aws_assets_host}\"\n"
38
+ line += " config.action_controller.asset_host = #{@settinglogic_class}.aws_assets_host"
36
39
  unless file_has_content?(to_file, line)
37
40
  comment_lines(to_file, /config\.action_controller\.asset_host/)
38
41
  insert_line_into_file(to_file, line, :before => /\nend[\n]*$/)
@@ -8,7 +8,11 @@ AssetSync.configure do |config|
8
8
  config.fog_region = <%= @settinglogic_class %>.aws_assets_region
9
9
  #
10
10
  # Don't delete files from the store
11
- config.existing_remote_files = "delete"
11
+ # config.existing_remote_files: "keep" # Existing pre-compiled assets on S3 will be kept
12
+ # To delete existing remote files.
13
+ # config.existing_remote_files: "delete"
14
+ # To ignore existing remote files and overwrite.
15
+ # config.existing_remote_files: "ignore"
12
16
  #
13
17
  # Automatically replace files with their equivalent gzip compressed version
14
18
  # config.gzip_compression = true
@@ -19,4 +23,7 @@ AssetSync.configure do |config|
19
23
  #
20
24
  # Fail silently. Useful for environments such as Heroku
21
25
  # config.fail_silently = true
26
+ #
27
+ # For always upload files
28
+ # config.always_upload = ["application.css", "application.js"]
22
29
  end
@@ -0,0 +1,27 @@
1
+ module Venus
2
+ module Generators
3
+ class BetterErrorsGenerator < Base
4
+ desc "Setup better errors"
5
+
6
+ def name
7
+ "better_error"
8
+ end
9
+
10
+ def asks
11
+ # @sublime = ask?("Use Sublime Text")
12
+ end
13
+
14
+ def gemfile
15
+ append_gem_into_group("development", "better_errors")
16
+ # append_gem_into_group("development", "binding_of_caller") if @sublime
17
+ bundle_install
18
+ end
19
+
20
+ def sublime
21
+ # template("better_errors.erb", "config/initializers/better_errors.rb") if @sublime
22
+ # say "Download sublime-handler (https://github.com/asuth/subl-handler) to open subl:// protocol" if @sublime
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ BetterErrors.editor = :sublime if defined? BetterErrors
@@ -1,6 +1,8 @@
1
1
 
2
+ config.label_class = "control-label"
3
+ config.form_class = "form-horizontal"
4
+
2
5
  config.wrappers :bootstrap, :tag => 'div', :class => 'control-group', :error_class => 'error' do |b|
3
- config.form_class = "form-horizontal"
4
6
  b.use :placeholder
5
7
  b.use :label, :wrap_with => { :class => 'control-label' }
6
8
  b.wrapper :tag => 'div', :class => 'controls' do |ba|
@@ -12,7 +14,6 @@
12
14
 
13
15
  <% if @unicorn %>
14
16
  config.wrappers :admin, :tag => :div, :class => 'control-group' do |b|
15
- config.form_class = "form-horizontal"
16
17
  b.use :placeholder
17
18
  b.use :label, :wrap_with => { :class => 'control-label', :tag => false }
18
19
  b.wrapper :tag => :div, :class => 'controls' do |ba|
@@ -30,7 +30,7 @@ module Venus
30
30
  else
31
31
  add_gem("carrierwave", "0.7.1")
32
32
  end
33
- add_gem('rmagick') if @imagemagick
33
+ add_gem('mini_magick', "~> 3.6.0") if @imagemagick
34
34
  add_gem("carrierwave-meta", '~> 0.0.4') if @carrierwave_meta
35
35
  add_gem('fog') if @fog
36
36
  bundle_install
@@ -1,7 +1,7 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  class <%=@sample_uploader.to_s.camelize%>Uploader < CarrierWave::Uploader::Base
3
3
  <%- if @imagemagick %>
4
- include CarrierWave::RMagick<% end %>
4
+ include CarrierWave::MiniMagick<% end %>
5
5
  <%- if @carrierwave_meta %>
6
6
  include CarrierWave::Meta<% end %>
7
7
 
@@ -13,7 +13,7 @@ module Venus
13
13
  end
14
14
 
15
15
  def gem
16
- add_gem('chosen-rails', '~> 0.9.11.2')
16
+ add_gem('chosen-rails', '~> 0.9.15')
17
17
  bundle_install
18
18
  end
19
19
 
@@ -11,6 +11,7 @@ module Venus
11
11
  @use_rvm = ask?('use rvm?', true)
12
12
  @use_assets_pipline = ask?('use assets pipline?', true)
13
13
  @use_passenger = ask?('use passenger?', true)
14
+ @use_puma = ask?('use puma server?', true) unless @use_passenger
14
15
  @git_uri = ask?('your git repository url?', 'git@github.com:foo/myapp.git')
15
16
  @stage = ask_stage_infomation
16
17
  if ask?('has staging server?', true)
@@ -53,6 +54,12 @@ module Venus
53
54
  end
54
55
  end
55
56
 
57
+ def puma
58
+ if @use_puma
59
+ generate "venus:puma"
60
+ end
61
+ end
62
+
56
63
  private
57
64
 
58
65
  def ask_stage_infomation(prefix = 'production')
@@ -191,7 +191,7 @@ module Venus
191
191
  value = '' if opts[:secret] && is_example
192
192
  inserted_value = (value.index("\n") ? value : "\"#{value}\"")
193
193
  line = " #{key}: #{inserted_value}"
194
- if file_has_content?(to_file, "defaults: &defaults\n")
194
+ if file_has_content?(to_file, "defaults: &defaults")
195
195
  insert_line_into_file(to_file, line, :after => "defaults: &defaults")
196
196
  else
197
197
  insert_line_into_file(to_file, line, :after => "development:")
@@ -0,0 +1,35 @@
1
+ module Venus
2
+ module Generators
3
+ class HipchatGenerator < Base
4
+ desc "Setup hipchat"
5
+
6
+ def name
7
+ "hipchat"
8
+ end
9
+
10
+ def asks
11
+ @is_repository_private = ask?("Is project private", false)
12
+ settingslogic_dependent unless @is_repository_private
13
+ @token = ask?("HipChat API token", "")
14
+ @room = ask?("HipChat room for deploy notification", "")
15
+ end
16
+
17
+ def settings
18
+ unless @is_repository_private
19
+ insert_settingslogics("hipchat_token", @token, :secret => true) unless key_in_settingslogic?("hipchat_token")
20
+ insert_settingslogics("hipchat_room", @room) unless key_in_settingslogic?("hipchat_room")
21
+ end
22
+ end
23
+
24
+ def gemfile
25
+ add_gem("hipchat", "~> 0.10.0")
26
+ bundle_install
27
+ end
28
+
29
+ def configs
30
+ concat_template("config/deploy.rb", "deploy.rb.erb")
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+
2
+ <% if @is_repository_private %>
3
+ require 'hipchat/capistrano'
4
+ set :hipchat_token, "<%= @token %>"
5
+ set :hipchat_room_name, "<%= @room %>"
6
+ set :hipchat_announce, true
7
+ set :hipchat_color, 'purple'
8
+ set :hipchat_success_color, 'green'
9
+ set :hipchat_failed_color, 'red'
10
+ set :hipchat_message_format, 'text'
11
+ <% else %>
12
+ settings = YAML.load_file(File.dirname(__FILE__) + "/<%= @settinglogic_yml %>")[rails_env]
13
+ if settings["hipchat_token"].to_s.length > 0
14
+ require 'hipchat/capistrano'
15
+ set :hipchat_token, settings["hipchat_token"]
16
+ set :hipchat_room_name, settings["hipchat_room"]
17
+ set :hipchat_announce, true
18
+ set :hipchat_color, 'purple'
19
+ set :hipchat_success_color, 'green'
20
+ set :hipchat_failed_color, 'red'
21
+ set :hipchat_message_format, 'text'
22
+ end
23
+ <% end %>
@@ -8,21 +8,11 @@ module Venus
8
8
  end
9
9
 
10
10
  def asks
11
- @gems = {}
12
11
  @paginate = ask?('install paginate gem "kaminari"?', true) unless has_gem?('kaminari')
13
- generate 'venus:paginate' if @paginate
14
-
15
12
  @whenever = ask?('install scheduling gem "whenever"?', true) unless has_gem?('whenever')
16
- generate 'venus:cron' if @whenever
17
-
18
- [:haml].each do |gemname|
19
- @gems[gemname] = ask?("install gem '#{gemname}'?", true)
20
- end
21
-
22
13
  @simple_form = ask?('install gem "simple_form"?', true) unless has_gem?('simple_form')
23
- if @simple_form
24
- generate "venus:simple_form"
25
- end
14
+ @better_errors = ask?("install gem 'better_errors'", true)
15
+ @rails_panel = ask?("install gem 'rails_panel'", true)
26
16
 
27
17
  @remove_gems = []
28
18
  ["coffee-rails", "sass-rails"].each do |gem_name|
@@ -67,19 +57,6 @@ module Venus
67
57
  end
68
58
  end
69
59
 
70
- def gems
71
- @is_append = !file_has_content?('Gemfile','group :development do')
72
- if @is_append
73
- concat_template('Gemfile', 'gem_developments.erb')
74
- else
75
- insert_template('Gemfile', 'gem_developments.erb', :after => 'group :development do')
76
- end
77
- @gems.each do |gemname, ans|
78
- add_gem(gemname.to_s) if ans
79
- end
80
- bundle_install
81
- end
82
-
83
60
  def gitignore
84
61
  add_gitignore ".DS_Store"
85
62
  add_gitignore "/public/assets"
@@ -92,6 +69,14 @@ module Venus
92
69
  end
93
70
  end
94
71
 
72
+ def asked_gems
73
+ generate 'venus:paginate' if @paginate
74
+ generate 'venus:cron' if @whenever
75
+ generate "venus:simple_form" if @simple_form
76
+ generate "venus:better_errors" if @better_errors
77
+ generate "venus:rails_panel" if @rails_panel
78
+ end
79
+
95
80
  end
96
81
  end
97
82
  end
@@ -12,14 +12,14 @@ module Venus
12
12
  @target_css = ask?('target content append for css file?', 'application.css')
13
13
  @datepicker = ask?('setup for datepicker?', true)
14
14
  if @datepicker
15
- puts "datepicker lang list: https://github.com/joliss/jquery-ui-rails/tree/master/vendor/assets/javascripts"
15
+ puts "datepicker lang list: https://github.com/joliss/jquery-ui-rails/blob/master/app/assets/javascripts"
16
16
  @datepicker_lang = ask?('datepicker language?', '')
17
17
  @datetimepicler = ask?('setup timepicker ?', true)
18
18
  end
19
19
  end
20
20
 
21
21
  def gem
22
- add_gem('jquery-ui-rails', '~> 4.0.1')
22
+ add_gem('jquery-ui-rails', '~> 4.0.3')
23
23
  bundle_install
24
24
  end
25
25
 
@@ -3,4 +3,8 @@
3
3
  .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
4
4
  .ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
5
5
  .ui-timepicker-div td { font-size: 90%; }
6
- .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
6
+ .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
7
+
8
+ .ui-timepicker-rtl{ direction: rtl; }
9
+ .ui-timepicker-rtl dl { text-align: right; }
10
+ .ui-timepicker-rtl dl dd { margin: 0 65px 10px 10px; }
@@ -1,1326 +1,2103 @@
1
1
  /*
2
- * jQuery timepicker addon
3
- * By: Trent Richardson [http://trentrichardson.com]
4
- * Version 1.0.0
5
- * Last Modified: 02/05/2012
6
- *
7
- * Copyright 2012 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
- * HERES THE CSS:
13
- * .ui-timepicker-div .ui-widget-header { margin-bottom: 8px; }
14
- * .ui-timepicker-div dl { text-align: left; }
15
- * .ui-timepicker-div dl dt { height: 25px; margin-bottom: -25px; }
16
- * .ui-timepicker-div dl dd { margin: 0 10px 10px 65px; }
17
- * .ui-timepicker-div td { font-size: 90%; }
18
- * .ui-tpicker-grid-label { background: none; border: none; margin: 0; padding: 0; }
19
- */
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 */
20
14
 
21
15
  (function($) {
22
16
 
23
- // Prevent "Uncaught RangeError: Maximum call stack size exceeded"
24
- $.ui.timepicker = $.ui.timepicker || {};
25
- if ($.ui.timepicker.version) {
26
- return;
27
- }
28
-
29
- $.extend($.ui, { timepicker: { version: "1.0.0" } });
30
-
31
- /* Time picker manager.
32
- Use the singleton instance of this class, $.timepicker, to interact with the time picker.
33
- Settings for (groups of) time pickers are maintained in an instance object,
34
- allowing multiple different settings on the same page. */
35
-
36
- function Timepicker() {
37
- this.regional = []; // Available regional settings, indexed by language code
38
- this.regional[''] = { // Default regional settings
39
- currentText: 'Now',
40
- closeText: 'Done',
41
- ampm: false,
42
- amNames: ['AM', 'A'],
43
- pmNames: ['PM', 'P'],
44
- timeFormat: 'hh:mm tt',
45
- timeSuffix: '',
46
- timeOnlyTitle: 'Choose Time',
47
- timeText: 'Time',
48
- hourText: 'Hour',
49
- minuteText: 'Minute',
50
- secondText: 'Second',
51
- millisecText: 'Millisecond',
52
- timezoneText: 'Time Zone'
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['']);
53
115
  };
54
- this._defaults = { // Global defaults for all the datetime picker instances
55
- showButtonPanel: true,
56
- timeOnly: false,
57
- showHour: true,
58
- showMinute: true,
59
- showSecond: false,
60
- showMillisec: false,
61
- showTimezone: false,
62
- showTime: true,
63
- stepHour: 1,
64
- stepMinute: 1,
65
- stepSecond: 1,
66
- stepMillisec: 1,
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,
67
128
  hour: 0,
68
129
  minute: 0,
69
130
  second: 0,
70
131
  millisec: 0,
71
- timezone: '+0000',
72
- hourMin: 0,
73
- minuteMin: 0,
74
- secondMin: 0,
75
- millisecMin: 0,
76
- hourMax: 23,
77
- minuteMax: 59,
78
- secondMax: 59,
79
- millisecMax: 999,
80
- minDateTime: null,
81
- maxDateTime: null,
82
- onSelect: null,
83
- hourGrid: 0,
84
- minuteGrid: 0,
85
- secondGrid: 0,
86
- millisecGrid: 0,
87
- alwaysSetTime: true,
88
- separator: ' ',
89
- altFieldTimeOnly: true,
90
- showTimepicker: true,
91
- timezoneIso8609: false,
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: '',
92
148
  timezoneList: null,
93
- addSliderAccess: false,
94
- sliderAccessArgs: null
95
- };
96
- $.extend(this._defaults, this.regional['']);
97
- };
98
-
99
- $.extend(Timepicker.prototype, {
100
- $input: null,
101
- $altInput: null,
102
- $timeObj: null,
103
- inst: null,
104
- hour_slider: null,
105
- minute_slider: null,
106
- second_slider: null,
107
- millisec_slider: null,
108
- timezone_select: null,
109
- hour: 0,
110
- minute: 0,
111
- second: 0,
112
- millisec: 0,
113
- timezone: '+0000',
114
- hourMinOriginal: null,
115
- minuteMinOriginal: null,
116
- secondMinOriginal: null,
117
- millisecMinOriginal: null,
118
- hourMaxOriginal: null,
119
- minuteMaxOriginal: null,
120
- secondMaxOriginal: null,
121
- millisecMaxOriginal: null,
122
- ampm: '',
123
- formattedDate: '',
124
- formattedTime: '',
125
- formattedDateTime: '',
126
- timezoneList: null,
127
-
128
- /* Override the default settings for all instances of the time picker.
129
- @param settings object - the new settings to use as defaults (anonymous object)
130
- @return the manager object */
131
- setDefaults: function(settings) {
132
- extendRemove(this._defaults, settings || {});
133
- return this;
134
- },
135
-
136
- //########################################################################
137
- // Create a new Timepicker instance
138
- //########################################################################
139
- _newInst: function($input, o) {
140
- var tp_inst = new Timepicker(),
141
- inlineSettings = {};
142
-
143
- for (var attrName in this._defaults) {
144
- var attrValue = $input.attr('time:' + attrName);
145
- if (attrValue) {
146
- try {
147
- inlineSettings[attrName] = eval(attrValue);
148
- } catch (err) {
149
- inlineSettings[attrName] = attrValue;
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
+ }
150
182
  }
151
183
  }
152
- }
153
- tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, {
154
- beforeShow: function(input, dp_inst) {
155
- if ($.isFunction(o.beforeShow))
156
- return o.beforeShow(input, dp_inst, tp_inst);
157
- },
158
- onChangeMonthYear: function(year, month, dp_inst) {
159
- // Update the time as well : this prevents the time from disappearing from the $input field.
160
- tp_inst._updateDateTime(dp_inst);
161
- if ($.isFunction(o.onChangeMonthYear))
162
- o.onChangeMonthYear.call($input[0], year, month, dp_inst, tp_inst);
163
- },
164
- onClose: function(dateText, dp_inst) {
165
- if (tp_inst.timeDefined === true && $input.val() != '')
166
- tp_inst._updateDateTime(dp_inst);
167
- if ($.isFunction(o.onClose))
168
- o.onClose.call($input[0], dateText, dp_inst, tp_inst);
169
- },
170
- timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
171
- });
172
- tp_inst.amNames = $.map(tp_inst._defaults.amNames, function(val) { return val.toUpperCase(); });
173
- tp_inst.pmNames = $.map(tp_inst._defaults.pmNames, function(val) { return val.toUpperCase(); });
174
-
175
- if (tp_inst._defaults.timezoneList === null) {
176
- var timezoneList = [];
177
- for (var i = -11; i <= 12; i++)
178
- timezoneList.push((i >= 0 ? '+' : '-') + ('0' + Math.abs(i).toString()).slice(-2) + '00');
179
- if (tp_inst._defaults.timezoneIso8609)
180
- timezoneList = $.map(timezoneList, function(val) {
181
- return val == '+0000' ? 'Z' : (val.substring(0, 3) + ':' + val.substring(3));
182
- });
183
- tp_inst._defaults.timezoneList = timezoneList;
184
- }
185
184
 
186
- tp_inst.hour = tp_inst._defaults.hour;
187
- tp_inst.minute = tp_inst._defaults.minute;
188
- tp_inst.second = tp_inst._defaults.second;
189
- tp_inst.millisec = tp_inst._defaults.millisec;
190
- tp_inst.ampm = '';
191
- tp_inst.$input = $input;
192
-
193
- if (o.altField)
194
- tp_inst.$altInput = $(o.altField)
195
- .css({ cursor: 'pointer' })
196
- .focus(function(){ $input.trigger("focus"); });
197
-
198
- if(tp_inst._defaults.minDate==0 || tp_inst._defaults.minDateTime==0)
199
- {
200
- tp_inst._defaults.minDate=new Date();
201
- }
202
- if(tp_inst._defaults.maxDate==0 || tp_inst._defaults.maxDateTime==0)
203
- {
204
- tp_inst._defaults.maxDate=new Date();
205
- }
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
+ }
206
212
 
207
- // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
208
- if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
209
- tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
210
- if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date)
211
- tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
212
- if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date)
213
- tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
214
- if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date)
215
- tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
216
- return tp_inst;
217
- },
218
-
219
- //########################################################################
220
- // add our sliders to the calendar
221
- //########################################################################
222
- _addTimePicker: function(dp_inst) {
223
- var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ?
224
- this.$input.val() + ' ' + this.$altInput.val() :
225
- this.$input.val();
226
-
227
- this.timeDefined = this._parseTime(currDT);
228
- this._limitMinMaxDateTime(dp_inst, false);
229
- this._injectTimePicker();
230
- },
231
-
232
- //########################################################################
233
- // parse the time string from input value or _setTime
234
- //########################################################################
235
- _parseTime: function(timeString, withDate) {
236
- var regstr = this._defaults.timeFormat.toString()
237
- .replace(/h{1,2}/ig, '(\\d?\\d)')
238
- .replace(/m{1,2}/ig, '(\\d?\\d)')
239
- .replace(/s{1,2}/ig, '(\\d?\\d)')
240
- .replace(/l{1}/ig, '(\\d?\\d?\\d)')
241
- .replace(/t{1,2}/ig, this._getPatternAmpm())
242
- .replace(/z{1}/ig, '(z|[-+]\\d\\d:?\\d\\d)?')
243
- .replace(/\s/g, '\\s?') + this._defaults.timeSuffix + '$',
244
- order = this._getFormatPositions(),
245
- ampm = '',
246
- treg;
247
-
248
- if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
249
-
250
- if (withDate || !this._defaults.timeOnly) {
251
- // the time should come after x number of characters and a space.
252
- // x = at least the length of text specified by the date format
253
- var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
254
- // escape special regex characters in the seperator
255
- var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g");
256
- regstr = '^.{' + dp_dateFormat.length + ',}?' + this._defaults.separator.replace(specials, "\\$&") + regstr;
257
- }
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
+ });
258
223
 
259
- treg = timeString.match(new RegExp(regstr, 'i'));
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:''));
260
229
 
261
- if (treg) {
262
- if (order.t !== -1) {
263
- if (treg[order.t] === undefined || treg[order.t].length === 0) {
264
- ampm = '';
265
- this.ampm = '';
266
- } else {
267
- ampm = $.inArray(treg[order.t].toUpperCase(), this.amNames) !== -1 ? 'AM' : 'PM';
268
- this.ampm = this._defaults[ampm == 'AM' ? 'amNames' : 'pmNames'][0];
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';
269
234
  }
235
+ tp_inst.control = tp_inst._controls[tp_inst._defaults.controlType];
270
236
  }
271
-
272
- if (order.h !== -1) {
273
- if (ampm == 'AM' && treg[order.h] == '12')
274
- this.hour = 0; // 12am = 0 hour
275
- else if (ampm == 'PM' && treg[order.h] != '12')
276
- this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12
277
- else this.hour = Number(treg[order.h]);
237
+ // controlType is an object and must implement create, options, value methods
238
+ else{
239
+ tp_inst.control = tp_inst._defaults.controlType;
278
240
  }
279
241
 
280
- if (order.m !== -1) this.minute = Number(treg[order.m]);
281
- if (order.s !== -1) this.second = Number(treg[order.s]);
282
- if (order.l !== -1) this.millisec = Number(treg[order.l]);
283
- if (order.z !== -1 && treg[order.z] !== undefined) {
284
- var tz = treg[order.z].toUpperCase();
285
- switch (tz.length) {
286
- case 1: // Z
287
- tz = this._defaults.timezoneIso8609 ? 'Z' : '+0000';
288
- break;
289
- case 5: // +hhmm
290
- if (this._defaults.timezoneIso8609)
291
- tz = tz.substring(1) == '0000'
292
- ? 'Z'
293
- : tz.substring(0, 3) + ':' + tz.substring(3);
294
- break;
295
- case 6: // +hh:mm
296
- if (!this._defaults.timezoneIso8609)
297
- tz = tz == 'Z' || tz.substring(1) == '00:00'
298
- ? '+0000'
299
- : tz.replace(/:/, '');
300
- else if (tz.substring(1) == '00:00')
301
- tz = 'Z';
302
- break;
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) };
303
253
  }
304
- this.timezone = tz;
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
+ });
305
279
  }
306
280
 
307
- return true;
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
+ }
308
287
 
309
- }
310
- return false;
311
- },
312
-
313
- //########################################################################
314
- // pattern for standard and localized AM/PM markers
315
- //########################################################################
316
- _getPatternAmpm: function() {
317
- var markers = [],
318
- o = this._defaults;
319
- if (o.amNames)
320
- $.merge(markers, o.amNames);
321
- if (o.pmNames)
322
- $.merge(markers, o.pmNames);
323
- markers = $.map(markers, function(val) { return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&'); });
324
- return '(' + markers.join('|') + ')?';
325
- },
326
-
327
- //########################################################################
328
- // figure out position of time elements.. cause js cant do named captures
329
- //########################################################################
330
- _getFormatPositions: function() {
331
- var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g),
332
- orders = { h: -1, m: -1, s: -1, l: -1, t: -1, z: -1 };
333
-
334
- if (finds)
335
- for (var i = 0; i < finds.length; i++)
336
- if (orders[finds[i].toString().charAt(0)] == -1)
337
- orders[finds[i].toString().charAt(0)] = i + 1;
338
-
339
- return orders;
340
- },
341
-
342
- //########################################################################
343
- // generate and inject html for timepicker into ui datepicker
344
- //########################################################################
345
- _injectTimePicker: function() {
346
- var $dp = this.inst.dpDiv,
347
- o = this._defaults,
348
- tp_inst = this,
349
- // Added by Peter Medeiros:
350
- // - Figure out what the hour/minute/second max should be based on the step values.
351
- // - Example: if stepMinute is 15, then minMax is 45.
352
- hourMax = parseInt((o.hourMax - ((o.hourMax - o.hourMin) % o.stepHour)) ,10),
353
- minMax = parseInt((o.minuteMax - ((o.minuteMax - o.minuteMin) % o.stepMinute)) ,10),
354
- secMax = parseInt((o.secondMax - ((o.secondMax - o.secondMin) % o.stepSecond)) ,10),
355
- millisecMax = parseInt((o.millisecMax - ((o.millisecMax - o.millisecMin) % o.stepMillisec)) ,10),
356
- dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, '');
357
-
358
- // Prevent displaying twice
359
- //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
360
- if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) {
361
- var noDisplay = ' style="display:none;"',
362
- html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
363
- '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' +
364
- ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
365
- '<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_id + '"' +
366
- ((o.showTime) ? '' : noDisplay) + '></dd>' +
367
- '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_id + '"' +
368
- ((o.showHour) ? '' : noDisplay) + '>' + o.hourText + '</dt>',
369
- hourGridSize = 0,
370
- minuteGridSize = 0,
371
- secondGridSize = 0,
372
- millisecGridSize = 0,
373
- size = null;
374
-
375
- // Hours
376
- html += '<dd class="ui_tpicker_hour"><div id="ui_tpicker_hour_' + dp_id + '"' +
377
- ((o.showHour) ? '' : noDisplay) + '></div>';
378
- if (o.showHour && o.hourGrid > 0) {
379
- html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
380
-
381
- for (var h = o.hourMin; h <= hourMax; h += parseInt(o.hourGrid,10)) {
382
- hourGridSize++;
383
- var tmph = (o.ampm && h > 12) ? h-12 : h;
384
- if (tmph < 10) tmph = '0' + tmph;
385
- if (o.ampm) {
386
- if (h == 0) tmph = 12 +'a';
387
- else if (h < 12) tmph += 'a';
388
- else tmph += 'p';
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;
389
333
  }
390
- html += '<td>' + tmph + '</td>';
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;
391
341
  }
392
-
393
- html += '</tr></table></div>';
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;
394
350
  }
395
- html += '</dd>';
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
+ }
396
406
 
397
- // Minutes
398
- html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_id + '"' +
399
- ((o.showMinute) ? '' : noDisplay) + '>' + o.minuteText + '</dt>'+
400
- '<dd class="ui_tpicker_minute"><div id="ui_tpicker_minute_' + dp_id + '"' +
401
- ((o.showMinute) ? '' : noDisplay) + '></div>';
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>';
402
416
 
403
- if (o.showMinute && o.minuteGrid > 0) {
404
- html += '<div style="padding-left: 1px"><table class="ui-tpicker-grid-label"><tr>';
417
+ // Create the elements from string
418
+ html += '</dl></div>';
419
+ var $tp = $(html);
405
420
 
406
- for (var m = o.minuteMin; m <= minMax; m += parseInt(o.minuteGrid,10)) {
407
- minuteGridSize++;
408
- html += '<td>' + ((m < 10) ? '0' : '') + m + '</td>';
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();
409
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
410
474
 
411
- html += '</tr></table></div>';
412
- }
413
- html += '</dd>';
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
+ }
414
508
 
415
- // Seconds
416
- html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_id + '"' +
417
- ((o.showSecond) ? '' : noDisplay) + '>' + o.secondText + '</dt>'+
418
- '<dd class="ui_tpicker_second"><div id="ui_tpicker_second_' + dp_id + '"'+
419
- ((o.showSecond) ? '' : noDisplay) + '></div>';
509
+ this.$timeObj = $tp.find('.ui_tpicker_time');
420
510
 
421
- if (o.showSecond && o.secondGrid > 0) {
422
- html += '<div style="padding-left: 1px"><table><tr>';
511
+ if (this.inst !== null) {
512
+ var timeDefined = this.timeDefined;
513
+ this._onTimeChange();
514
+ this.timeDefined = timeDefined;
515
+ }
423
516
 
424
- for (var s = o.secondMin; s <= secMax; s += parseInt(o.secondGrid,10)) {
425
- secondGridSize++;
426
- html += '<td>' + ((s < 10) ? '0' : '') + s + '</td>';
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);
427
543
  }
544
+ // end slideAccess integration
428
545
 
429
- html += '</tr></table></div>';
430
546
  }
431
- html += '</dd>';
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
+ }
432
572
 
433
- // Milliseconds
434
- html += '<dt class="ui_tpicker_millisec_label" id="ui_tpicker_millisec_label_' + dp_id + '"' +
435
- ((o.showMillisec) ? '' : noDisplay) + '>' + o.millisecText + '</dt>'+
436
- '<dd class="ui_tpicker_millisec"><div id="ui_tpicker_millisec_' + dp_id + '"'+
437
- ((o.showMillisec) ? '' : noDisplay) + '></div>';
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
+ }
438
616
 
439
- if (o.showMillisec && o.millisecGrid > 0) {
440
- html += '<div style="padding-left: 1px"><table><tr>';
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);
441
620
 
442
- for (var l = o.millisecMin; l <= millisecMax; l += parseInt(o.millisecGrid,10)) {
443
- millisecGridSize++;
444
- html += '<td>' + ((l < 10) ? '0' : '') + l + '</td>';
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;
445
627
  }
446
628
 
447
- html += '</tr></table></div>';
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
+ }
448
671
  }
449
- html += '</dd>';
450
672
 
451
- // Timezone
452
- html += '<dt class="ui_tpicker_timezone_label" id="ui_tpicker_timezone_label_' + dp_id + '"' +
453
- ((o.showTimezone) ? '' : noDisplay) + '>' + o.timezoneText + '</dt>';
454
- html += '<dd class="ui_tpicker_timezone" id="ui_tpicker_timezone_' + dp_id + '"' +
455
- ((o.showTimezone) ? '' : noDisplay) + '></dd>';
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);
456
679
 
457
- html += '</dl></div>';
458
- $tp = $(html);
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
+ }
459
701
 
460
- // if we only want time picker...
461
- if (o.timeOnly === true) {
462
- $tp.prepend(
463
- '<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' +
464
- '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' +
465
- '</div>');
466
- $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
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;
467
736
  }
468
737
 
469
- this.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_id).slider({
470
- orientation: "horizontal",
471
- value: this.hour,
472
- min: o.hourMin,
473
- max: hourMax,
474
- step: o.stepHour,
475
- slide: function(event, ui) {
476
- tp_inst.hour_slider.slider( "option", "value", ui.value);
477
- tp_inst._onTimeChange();
478
- }
479
- });
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
+ }
480
753
 
754
+ var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
481
755
 
482
- // Updated by Peter Medeiros:
483
- // - Pass in Event and UI instance into slide function
484
- this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({
485
- orientation: "horizontal",
486
- value: this.minute,
487
- min: o.minuteMin,
488
- max: minMax,
489
- step: o.stepMinute,
490
- slide: function(event, ui) {
491
- tp_inst.minute_slider.slider( "option", "value", ui.value);
492
- tp_inst._onTimeChange();
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;
493
781
  }
494
- });
495
782
 
496
- this.second_slider = $tp.find('#ui_tpicker_second_'+ dp_id).slider({
497
- orientation: "horizontal",
498
- value: this.second,
499
- min: o.secondMin,
500
- max: secMax,
501
- step: o.stepSecond,
502
- slide: function(event, ui) {
503
- tp_inst.second_slider.slider( "option", "value", ui.value);
504
- tp_inst._onTimeChange();
783
+ if (!this.inst) {
784
+ this.inst = $.datepicker._getInst(this.$input[0]);
505
785
  }
506
- });
507
786
 
508
- this.millisec_slider = $tp.find('#ui_tpicker_millisec_'+ dp_id).slider({
509
- orientation: "horizontal",
510
- value: this.millisec,
511
- min: o.millisecMin,
512
- max: millisecMax,
513
- step: o.stepMillisec,
514
- slide: function(event, ui) {
515
- tp_inst.millisec_slider.slider( "option", "value", ui.value);
516
- tp_inst._onTimeChange();
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);
517
798
  }
518
- });
799
+ else{
800
+ this.$timeObj.text($.datepicker.formatTime(pickerTimeFormat, this, o) + pickerTimeSuffix);
801
+ }
802
+ }
519
803
 
520
- this.timezone_select = $tp.find('#ui_tpicker_timezone_'+ dp_id).append('<select></select>').find("select");
521
- $.fn.append.apply(this.timezone_select,
522
- $.map(o.timezoneList, function(val, idx) {
523
- return $("<option />")
524
- .val(typeof val == "object" ? val.value : val)
525
- .text(typeof val == "object" ? val.label : val);
526
- })
527
- );
528
- this.timezone_select.val((typeof this.timezone != "undefined" && this.timezone != null && this.timezone != "") ? this.timezone : o.timezone);
529
- this.timezone_select.change(function() {
530
- tp_inst._onTimeChange();
531
- });
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
+ }
532
881
 
533
- // Add grid functionality
534
- if (o.showHour && o.hourGrid > 0) {
535
- size = 100 * hourGridSize * o.hourGrid / (hourMax - o.hourMin);
536
-
537
- $tp.find(".ui_tpicker_hour table").css({
538
- width: size + "%",
539
- marginLeft: (size / (-2 * hourGridSize)) + "%",
540
- borderCollapse: 'collapse'
541
- }).find("td").each( function(index) {
542
- $(this).click(function() {
543
- var h = $(this).html();
544
- if(o.ampm) {
545
- var ap = h.substring(2).toLowerCase(),
546
- aph = parseInt(h.substring(0,2), 10);
547
- if (ap == 'a') {
548
- if (aph == 12) h = 0;
549
- else h = aph;
550
- } else if (aph == 12) h = 12;
551
- else h = aph + 12;
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);
552
907
  }
553
- tp_inst.hour_slider.slider("option", "value", h);
554
- tp_inst._onTimeChange();
555
- tp_inst._onSelectHandler();
556
- }).css({
557
- cursor: 'pointer',
558
- width: (100 / hourGridSize) + '%',
559
- textAlign: 'center',
560
- overflow: 'hidden'
561
- });
562
- });
908
+ }
909
+ }
563
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();
564
995
 
565
- if (o.showMinute && o.minuteGrid > 0) {
566
- size = 100 * minuteGridSize * o.minuteGrid / (minMax - o.minuteMin);
567
- $tp.find(".ui_tpicker_minute table").css({
568
- width: size + "%",
569
- marginLeft: (size / (-2 * minuteGridSize)) + "%",
570
- borderCollapse: 'collapse'
571
- }).find("td").each(function(index) {
572
- $(this).click(function() {
573
- tp_inst.minute_slider.slider("option", "value", $(this).html());
996
+ $(sel).appendTo(obj).change(function(e){
574
997
  tp_inst._onTimeChange();
575
998
  tp_inst._onSelectHandler();
576
- }).css({
577
- cursor: 'pointer',
578
- width: (100 / minuteGridSize) + '%',
579
- textAlign: 'center',
580
- overflow: 'hidden'
581
999
  });
582
- });
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
+ }
583
1022
  }
1023
+ } // end _controls
584
1024
 
585
- if (o.showSecond && o.secondGrid > 0) {
586
- $tp.find(".ui_tpicker_second table").css({
587
- width: size + "%",
588
- marginLeft: (size / (-2 * secondGridSize)) + "%",
589
- borderCollapse: 'collapse'
590
- }).find("td").each(function(index) {
591
- $(this).click(function() {
592
- tp_inst.second_slider.slider("option", "value", $(this).html());
593
- tp_inst._onTimeChange();
594
- tp_inst._onSelectHandler();
595
- }).css({
596
- cursor: 'pointer',
597
- width: (100 / secondGridSize) + '%',
598
- textAlign: 'center',
599
- overflow: 'hidden'
600
- });
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
601
1038
  });
602
1039
  }
603
1040
 
604
- if (o.showMillisec && o.millisecGrid > 0) {
605
- $tp.find(".ui_tpicker_millisec table").css({
606
- width: size + "%",
607
- marginLeft: (size / (-2 * millisecGridSize)) + "%",
608
- borderCollapse: 'collapse'
609
- }).find("td").each(function(index) {
610
- $(this).click(function() {
611
- tp_inst.millisec_slider.slider("option", "value", $(this).html());
612
- tp_inst._onTimeChange();
613
- tp_inst._onSelectHandler();
614
- }).css({
615
- cursor: 'pointer',
616
- width: (100 / millisecGridSize) + '%',
617
- textAlign: 'center',
618
- overflow: 'hidden'
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);
619
1060
  });
1061
+ }
1062
+ } else {
1063
+ return this.each(function() {
1064
+ var $t = $(this);
1065
+ $t.datepicker($.timepicker._newInst($t, o)._defaults);
620
1066
  });
621
1067
  }
1068
+ }
1069
+ });
622
1070
 
623
- var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
624
- if ($buttonPanel.length) $buttonPanel.before($tp);
625
- else $dp.append($tp);
626
-
627
- this.$timeObj = $tp.find('#ui_tpicker_time_'+ dp_id);
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
+ }
628
1081
 
629
- if (this.inst !== null) {
630
- var timeDefined = this.timeDefined;
631
- this._onTimeChange();
632
- this.timeDefined = timeDefined;
633
- }
1082
+ return parseRes.date;
1083
+ };
634
1084
 
635
- //Emulate datepicker onSelect behavior. Call on slidestop.
636
- var onSelectDelegate = function() {
637
- tp_inst._onSelectHandler();
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('|') + ')?';
638
1108
  };
639
- this.hour_slider.bind('slidestop',onSelectDelegate);
640
- this.minute_slider.bind('slidestop',onSelectDelegate);
641
- this.second_slider.bind('slidestop',onSelectDelegate);
642
- this.millisec_slider.bind('slidestop',onSelectDelegate);
643
-
644
- // slideAccess integration: http://trentrichardson.com/2011/11/11/jquery-ui-sliders-and-touch-accessibility/
645
- if (this._defaults.addSliderAccess){
646
- var sliderAccessArgs = this._defaults.sliderAccessArgs;
647
- setTimeout(function(){ // fix for inline mode
648
- if($tp.find('.ui-slider-access').length == 0){
649
- $tp.find('.ui-slider:visible').sliderAccess(sliderAccessArgs);
650
-
651
- // fix any grids since sliders are shorter
652
- var sliderAccessWidth = $tp.find('.ui-slider-access:eq(0)').outerWidth(true);
653
- if(sliderAccessWidth){
654
- $tp.find('table:visible').each(function(){
655
- var $g = $(this),
656
- oldWidth = $g.outerWidth(),
657
- oldMarginLeft = $g.css('marginLeft').toString().replace('%',''),
658
- newWidth = oldWidth - sliderAccessWidth,
659
- newMarginLeft = ((oldMarginLeft * newWidth)/oldWidth) + '%';
660
-
661
- $g.css({ width: newWidth, marginLeft: newMarginLeft });
662
- });
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;
663
1127
  }
664
1128
  }
665
- },0);
666
- }
667
- // end slideAccess integration
1129
+ }
1130
+ return orders;
1131
+ };
668
1132
 
669
- }
670
- },
671
-
672
- //########################################################################
673
- // This function tries to limit the ability to go outside the
674
- // min/max date range
675
- //########################################################################
676
- _limitMinMaxDateTime: function(dp_inst, adjustSliders){
677
- var o = this._defaults,
678
- dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay);
679
-
680
- if(!this._defaults.showTimepicker) return; // No time so nothing to check here
681
-
682
- if($.datepicker._get(dp_inst, 'minDateTime') !== null && $.datepicker._get(dp_inst, 'minDateTime') !== undefined && dp_date){
683
- var minDateTime = $.datepicker._get(dp_inst, 'minDateTime'),
684
- minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
685
-
686
- if(this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null || this.millisecMinOriginal === null){
687
- this.hourMinOriginal = o.hourMin;
688
- this.minuteMinOriginal = o.minuteMin;
689
- this.secondMinOriginal = o.secondMin;
690
- this.millisecMinOriginal = o.millisecMin;
691
- }
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
+ };
692
1163
 
693
- if(dp_inst.settings.timeOnly || minDateTimeDate.getTime() == dp_date.getTime()) {
694
- this._defaults.hourMin = minDateTime.getHours();
695
- if (this.hour <= this._defaults.hourMin) {
696
- this.hour = this._defaults.hourMin;
697
- this._defaults.minuteMin = minDateTime.getMinutes();
698
- if (this.minute <= this._defaults.minuteMin) {
699
- this.minute = this._defaults.minuteMin;
700
- this._defaults.secondMin = minDateTime.getSeconds();
701
- } else if (this.second <= this._defaults.secondMin){
702
- this.second = this._defaults.secondMin;
703
- this._defaults.millisecMin = minDateTime.getMilliseconds();
1164
+ if (treg) {
1165
+ if (order.t !== -1) {
1166
+ if (treg[order.t] === undefined || treg[order.t].length === 0) {
1167
+ ampm = '';
1168
+ resTime.ampm = '';
704
1169
  } else {
705
- if(this.millisec < this._defaults.millisecMin)
706
- this.millisec = this._defaults.millisecMin;
707
- this._defaults.millisecMin = this.millisecMinOriginal;
1170
+ ampm = $.inArray(treg[order.t].toUpperCase(), o.amNames) !== -1 ? 'AM' : 'PM';
1171
+ resTime.ampm = o[ampm == 'AM' ? 'amNames' : 'pmNames'][0];
708
1172
  }
709
- } else {
710
- this._defaults.minuteMin = this.minuteMinOriginal;
711
- this._defaults.secondMin = this.secondMinOriginal;
712
- this._defaults.millisecMin = this.millisecMinOriginal;
713
1173
  }
714
- }else{
715
- this._defaults.hourMin = this.hourMinOriginal;
716
- this._defaults.minuteMin = this.minuteMinOriginal;
717
- this._defaults.secondMin = this.secondMinOriginal;
718
- this._defaults.millisecMin = this.millisecMinOriginal;
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
+ }
719
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);
720
1248
  }
1249
+ return strictParse(timeFormat, timeString, o);
1250
+ };
721
1251
 
722
- if($.datepicker._get(dp_inst, 'maxDateTime') !== null && $.datepicker._get(dp_inst, 'maxDateTime') !== undefined && dp_date){
723
- var maxDateTime = $.datepicker._get(dp_inst, 'maxDateTime'),
724
- maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
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
+ }
725
1276
 
726
- if(this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null){
727
- this.hourMaxOriginal = o.hourMax;
728
- this.minuteMaxOriginal = o.minuteMax;
729
- this.secondMaxOriginal = o.secondMax;
730
- this.millisecMaxOriginal = o.millisecMax;
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, "") || "'";
731
1313
  }
1314
+ });
732
1315
 
733
- if(dp_inst.settings.timeOnly || maxDateTimeDate.getTime() == dp_date.getTime()){
734
- this._defaults.hourMax = maxDateTime.getHours();
735
- if (this.hour >= this._defaults.hourMax) {
736
- this.hour = this._defaults.hourMax;
737
- this._defaults.minuteMax = maxDateTime.getMinutes();
738
- if (this.minute >= this._defaults.minuteMax) {
739
- this.minute = this._defaults.minuteMax;
740
- this._defaults.secondMax = maxDateTime.getSeconds();
741
- } else if (this.second >= this._defaults.secondMax) {
742
- this.second = this._defaults.secondMax;
743
- this._defaults.millisecMax = maxDateTime.getMilliseconds();
744
- } else {
745
- if(this.millisec > this._defaults.millisecMax) this.millisec = this._defaults.millisecMax;
746
- this._defaults.millisecMax = this.millisecMaxOriginal;
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;
747
1426
  }
748
- } else {
749
- this._defaults.minuteMax = this.minuteMaxOriginal;
750
- this._defaults.secondMax = this.secondMaxOriginal;
751
- this._defaults.millisecMax = this.millisecMaxOriginal;
752
1427
  }
753
- }else{
754
- this._defaults.hourMax = this.hourMaxOriginal;
755
- this._defaults.minuteMax = this.minuteMaxOriginal;
756
- this._defaults.secondMax = this.secondMaxOriginal;
757
- this._defaults.millisecMax = this.millisecMaxOriginal;
1428
+ $(altField).val(altFormattedDateTime);
758
1429
  }
759
1430
  }
1431
+ else{
1432
+ $.datepicker._base_updateAlternate(inst);
1433
+ }
1434
+ };
760
1435
 
761
- if(adjustSliders !== undefined && adjustSliders === true){
762
- var hourMax = parseInt((this._defaults.hourMax - ((this._defaults.hourMax - this._defaults.hourMin) % this._defaults.stepHour)) ,10),
763
- minMax = parseInt((this._defaults.minuteMax - ((this._defaults.minuteMax - this._defaults.minuteMin) % this._defaults.stepMinute)) ,10),
764
- secMax = parseInt((this._defaults.secondMax - ((this._defaults.secondMax - this._defaults.secondMin) % this._defaults.stepSecond)) ,10),
765
- millisecMax = parseInt((this._defaults.millisecMax - ((this._defaults.millisecMax - this._defaults.millisecMin) % this._defaults.stepMillisec)) ,10);
766
-
767
- if(this.hour_slider)
768
- this.hour_slider.slider("option", { min: this._defaults.hourMin, max: hourMax }).slider('value', this.hour);
769
- if(this.minute_slider)
770
- this.minute_slider.slider("option", { min: this._defaults.minuteMin, max: minMax }).slider('value', this.minute);
771
- if(this.second_slider)
772
- this.second_slider.slider("option", { min: this._defaults.secondMin, max: secMax }).slider('value', this.second);
773
- if(this.millisec_slider)
774
- this.millisec_slider.slider("option", { min: this._defaults.millisecMin, max: millisecMax }).slider('value', this.millisec);
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
+ }
775
1452
  }
776
1453
 
777
- },
778
-
779
-
780
- //########################################################################
781
- // when a slider moves, set the internal time...
782
- // on time change is also called when the time is updated in the text field
783
- //########################################################################
784
- _onTimeChange: function() {
785
- var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false,
786
- minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
787
- second = (this.second_slider) ? this.second_slider.slider('value') : false,
788
- millisec = (this.millisec_slider) ? this.millisec_slider.slider('value') : false,
789
- timezone = (this.timezone_select) ? this.timezone_select.val() : false,
790
- o = this._defaults;
791
-
792
- if (typeof(hour) == 'object') hour = false;
793
- if (typeof(minute) == 'object') minute = false;
794
- if (typeof(second) == 'object') second = false;
795
- if (typeof(millisec) == 'object') millisec = false;
796
- if (typeof(timezone) == 'object') timezone = false;
797
-
798
- if (hour !== false) hour = parseInt(hour,10);
799
- if (minute !== false) minute = parseInt(minute,10);
800
- if (second !== false) second = parseInt(second,10);
801
- if (millisec !== false) millisec = parseInt(millisec,10);
802
-
803
- var ampm = o[hour < 12 ? 'amNames' : 'pmNames'][0];
804
-
805
- // If the update was done in the input field, the input field should not be updated.
806
- // If the update was done using the sliders, update the input field.
807
- var hasChanged = (hour != this.hour || minute != this.minute
808
- || second != this.second || millisec != this.millisec
809
- || (this.ampm.length > 0
810
- && (hour < 12) != ($.inArray(this.ampm.toUpperCase(), this.amNames) !== -1))
811
- || timezone != this.timezone);
812
-
813
- if (hasChanged) {
814
-
815
- if (hour !== false)this.hour = hour;
816
- if (minute !== false) this.minute = minute;
817
- if (second !== false) this.second = second;
818
- if (millisec !== false) this.millisec = millisec;
819
- if (timezone !== false) this.timezone = timezone;
820
-
821
- if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
822
-
823
- this._limitMinMaxDateTime(this.inst, true);
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;
824
1479
  }
825
- if (o.ampm) this.ampm = ampm;
826
-
827
- //this._formatTime();
828
- this.formattedTime = $.datepicker.formatTime(this._defaults.timeFormat, this, this._defaults);
829
- if (this.$timeObj) this.$timeObj.text(this.formattedTime + o.timeSuffix);
830
- this.timeDefined = true;
831
- if (hasChanged) this._updateDateTime();
832
- },
833
-
834
- //########################################################################
835
- // call custom onSelect.
836
- // bind to sliders slidestop, and grid click.
837
- //########################################################################
838
- _onSelectHandler: function() {
839
- var onSelect = this._defaults.onSelect;
840
- var inputEl = this.$input ? this.$input[0] : null;
841
- if (onSelect && inputEl) {
842
- onSelect.apply(inputEl, [this.formattedDateTime, this]);
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);
843
1486
  }
844
- },
845
-
846
- //########################################################################
847
- // left for any backwards compatibility
848
- //########################################################################
849
- _formatTime: function(time, format) {
850
- time = time || { hour: this.hour, minute: this.minute, second: this.second, millisec: this.millisec, ampm: this.ampm, timezone: this.timezone };
851
- var tmptime = (format || this._defaults.timeFormat).toString();
852
-
853
- tmptime = $.datepicker.formatTime(tmptime, time, this._defaults);
854
-
855
- if (arguments.length) return tmptime;
856
- else this.formattedTime = tmptime;
857
- },
858
-
859
- //########################################################################
860
- // update our input with the new date time..
861
- //########################################################################
862
- _updateDateTime: function(dp_inst) {
863
- dp_inst = this.inst || dp_inst;
864
- var dt = $.datepicker._daylightSavingAdjust(new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay)),
865
- dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
866
- formatCfg = $.datepicker._getFormatConfig(dp_inst),
867
- timeAvailable = dt !== null && this.timeDefined;
868
- this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
869
- var formattedDateTime = this.formattedDate;
870
- if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0))
1487
+ };
1488
+
1489
+ $.datepicker._enableTimepickerDatepicker = function(target) {
1490
+ var inst = this._getInst(target);
1491
+ if (!inst) {
871
1492
  return;
1493
+ }
872
1494
 
873
- if (this._defaults.timeOnly === true) {
874
- formattedDateTime = this.formattedTime;
875
- } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) {
876
- formattedDateTime += this._defaults.separator + this.formattedTime + this._defaults.timeSuffix;
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);
877
1501
  }
1502
+ };
878
1503
 
879
- this.formattedDateTime = formattedDateTime;
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;
880
1511
 
881
- if(!this._defaults.showTimepicker) {
882
- this.$input.val(this.formattedDate);
883
- } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
884
- this.$altInput.val(this.formattedTime);
885
- this.$input.val(this.formattedDate);
886
- } else if(this.$altInput) {
887
- this.$altInput.val(formattedDateTime);
888
- this.$input.val(formattedDateTime);
889
- } else {
890
- this.$input.val(formattedDateTime);
891
- }
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;
892
1518
 
893
- this.$input.trigger("change");
894
- }
1519
+ //check if within min/max times..
1520
+ tp_inst._limitMinMaxDateTime(inst, true);
895
1521
 
896
- });
1522
+ tp_inst._onTimeChange();
1523
+ tp_inst._updateDateTime(inst);
1524
+ }
1525
+ };
897
1526
 
898
- $.fn.extend({
899
- //########################################################################
900
- // shorthand just to use timepicker..
901
- //########################################################################
902
- timepicker: function(o) {
903
- o = o || {};
904
- var tmp_args = arguments;
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
+ }
905
1535
 
906
- if (typeof o == 'object') tmp_args[0] = $.extend(o, { timeOnly: true });
1536
+ var tp_inst = this._get(inst, 'timepicker');
907
1537
 
908
- return $(this).each(function() {
909
- $.fn.datetimepicker.apply($(this), tmp_args);
910
- });
911
- },
912
-
913
- //########################################################################
914
- // extend timepicker to datepicker
915
- //########################################################################
916
- datetimepicker: function(o) {
917
- o = o || {};
918
- tmp_args = arguments;
919
-
920
- if (typeof(o) == 'string'){
921
- if(o == 'getDate')
922
- return $.fn.datepicker.apply($(this[0]), tmp_args);
923
- else
924
- return this.each(function() {
925
- var $t = $(this);
926
- $t.datepicker.apply($t, tmp_args);
927
- });
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
+ }
928
1555
  }
929
- else
930
- return this.each(function() {
931
- var $t = $(this);
932
- $t.datepicker($.timepicker._newInst($t, o)._defaults);
933
- });
934
- }
935
- });
936
-
937
- //########################################################################
938
- // format the time all pretty...
939
- // format = string format of the time
940
- // time = a {}, not a Date() for timezones
941
- // options = essentially the regional[].. amNames, pmNames, ampm
942
- //########################################################################
943
- $.datepicker.formatTime = function(format, time, options) {
944
- options = options || {};
945
- options = $.extend($.timepicker._defaults, options);
946
- time = $.extend({hour:0, minute:0, second:0, millisec:0, timezone:'+0000'}, time);
947
-
948
- var tmptime = format;
949
- var ampmName = options['amNames'][0];
950
-
951
- var hour = parseInt(time.hour, 10);
952
- if (options.ampm) {
953
- if (hour > 11){
954
- ampmName = options['pmNames'][0];
955
- if(hour > 12)
956
- hour = hour % 12;
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;
957
1567
  }
958
- if (hour === 0)
959
- hour = 12;
960
- }
961
- tmptime = tmptime.replace(/(?:hh?|mm?|ss?|[tT]{1,2}|[lz])/g, function(match) {
962
- switch (match.toLowerCase()) {
963
- case 'hh': return ('0' + hour).slice(-2);
964
- case 'h': return hour;
965
- case 'mm': return ('0' + time.minute).slice(-2);
966
- case 'm': return time.minute;
967
- case 'ss': return ('0' + time.second).slice(-2);
968
- case 's': return time.second;
969
- case 'l': return ('00' + time.millisec).slice(-3);
970
- case 'z': return time.timezone;
971
- case 't': case 'tt':
972
- if (options.ampm) {
973
- if (match.length == 1)
974
- ampmName = ampmName.charAt(0);
975
- return match.charAt(0) == 'T' ? ampmName.toUpperCase() : ampmName.toLowerCase();
976
- }
977
- return '';
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);
978
1579
  }
979
- });
980
1580
 
981
- tmptime = $.trim(tmptime);
982
- return tmptime;
983
- };
984
-
985
- //########################################################################
986
- // the bad hack :/ override datepicker so it doesnt close on select
987
- // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
988
- //########################################################################
989
- $.datepicker._base_selectDate = $.datepicker._selectDate;
990
- $.datepicker._selectDate = function (id, dateStr) {
991
- var inst = this._getInst($(id)[0]),
992
- tp_inst = this._get(inst, 'timepicker');
993
-
994
- if (tp_inst) {
995
- tp_inst._limitMinMaxDateTime(inst, true);
996
- inst.inline = inst.stay_open = true;
997
- //This way the onSelect handler called from calendarpicker get the full dateTime
998
- this._base_selectDate(id, dateStr);
999
- inst.inline = inst.stay_open = false;
1000
- this._notifyChange(inst);
1001
1581
  this._updateDatepicker(inst);
1002
- }
1003
- else this._base_selectDate(id, dateStr);
1004
- };
1005
-
1006
- //#############################################################################################
1007
- // second bad hack :/ override datepicker so it triggers an event when changing the input field
1008
- // and does not redraw the datepicker on every selectDate event
1009
- //#############################################################################################
1010
- $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
1011
- $.datepicker._updateDatepicker = function(inst) {
1012
-
1013
- // don't popup the datepicker if there is another instance already opened
1014
- var input = inst.input[0];
1015
- if($.datepicker._curInst &&
1016
- $.datepicker._curInst != inst &&
1017
- $.datepicker._datepickerShowing &&
1018
- $.datepicker._lastInput != input) {
1019
- return;
1020
- }
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
+ }
1021
1595
 
1022
- if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
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
+ };
1023
1620
 
1024
- this._base_updateDatepicker(inst);
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
+ };
1025
1643
 
1026
- // Reload the time control when changing something in the input text field.
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) {
1027
1649
  var tp_inst = this._get(inst, 'timepicker');
1028
- if(tp_inst) tp_inst._addTimePicker(inst);
1029
- }
1030
- };
1031
-
1032
- //#######################################################################################
1033
- // third bad hack :/ override datepicker so it allows spaces and colon in the input field
1034
- //#######################################################################################
1035
- $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
1036
- $.datepicker._doKeyPress = function(event) {
1037
- var inst = $.datepicker._getInst(event.target),
1038
- tp_inst = $.datepicker._get(inst, 'timepicker');
1039
-
1040
- if (tp_inst) {
1041
- if ($.datepicker._get(inst, 'constrainInput')) {
1042
- var ampm = tp_inst._defaults.ampm,
1043
- dateChars = $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
1044
- datetimeChars = tp_inst._defaults.timeFormat.toString()
1045
- .replace(/[hms]/g, '')
1046
- .replace(/TT/g, ampm ? 'APM' : '')
1047
- .replace(/Tt/g, ampm ? 'AaPpMm' : '')
1048
- .replace(/tT/g, ampm ? 'AaPpMm' : '')
1049
- .replace(/T/g, ampm ? 'AP' : '')
1050
- .replace(/tt/g, ampm ? 'apm' : '')
1051
- .replace(/t/g, ampm ? 'ap' : '') +
1052
- " " +
1053
- tp_inst._defaults.separator +
1054
- tp_inst._defaults.timeSuffix +
1055
- (tp_inst._defaults.showTimezone ? tp_inst._defaults.timezoneList.join('') : '') +
1056
- (tp_inst._defaults.amNames.join('')) +
1057
- (tp_inst._defaults.pmNames.join('')) +
1058
- dateChars,
1059
- chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
1060
- return event.ctrlKey || (chr < ' ' || !dateChars || datetimeChars.indexOf(chr) > -1);
1650
+ if (tp_inst) {
1651
+ tp_inst._updateDateTime(inst);
1652
+ return tp_inst.$input.val();
1061
1653
  }
1062
- }
1654
+ return this._base_formatDate(inst);
1655
+ };
1063
1656
 
1064
- return $.datepicker._base_doKeyPress(event);
1065
- };
1066
-
1067
- //#######################################################################################
1068
- // Override key up event to sync manual input changes.
1069
- //#######################################################################################
1070
- $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
1071
- $.datepicker._doKeyUp = function (event) {
1072
- var inst = $.datepicker._getInst(event.target),
1073
- tp_inst = $.datepicker._get(inst, 'timepicker');
1074
-
1075
- if (tp_inst) {
1076
- if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
1077
- try {
1078
- $.datepicker._updateDatepicker(inst);
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;
1079
1749
  }
1080
- catch (err) {
1081
- $.datepicker.log(err);
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];
1082
1762
  }
1083
1763
  }
1084
- }
1764
+ return target;
1765
+ };
1085
1766
 
1086
- return $.datepicker._base_doKeyUp(event);
1087
- };
1088
-
1089
- //#######################################################################################
1090
- // override "Today" button to also grab the time.
1091
- //#######################################################################################
1092
- $.datepicker._base_gotoToday = $.datepicker._gotoToday;
1093
- $.datepicker._gotoToday = function(id) {
1094
- var inst = this._getInst($(id)[0]),
1095
- $dp = inst.dpDiv;
1096
- this._base_gotoToday(id);
1097
- var now = new Date();
1098
- var tp_inst = this._get(inst, 'timepicker');
1099
- if (tp_inst && tp_inst._defaults.showTimezone && tp_inst.timezone_select) {
1100
- var tzoffset = now.getTimezoneOffset(); // If +0100, returns -60
1101
- var tzsign = tzoffset > 0 ? '-' : '+';
1102
- tzoffset = Math.abs(tzoffset);
1103
- var tzmin = tzoffset % 60;
1104
- tzoffset = tzsign + ('0' + (tzoffset - tzmin) / 60).slice(-2) + ('0' + tzmin).slice(-2);
1105
- if (tp_inst._defaults.timezoneIso8609)
1106
- tzoffset = tzoffset.substring(0, 3) + ':' + tzoffset.substring(3);
1107
- tp_inst.timezone_select.val(tzoffset);
1108
- }
1109
- this._setTime(inst, now);
1110
- $( '.ui-datepicker-today', $dp).click();
1111
- };
1112
-
1113
- //#######################################################################################
1114
- // Disable & enable the Time in the datetimepicker
1115
- //#######################################################################################
1116
- $.datepicker._disableTimepickerDatepicker = function(target, date, withDate) {
1117
- var inst = this._getInst(target),
1118
- tp_inst = this._get(inst, 'timepicker');
1119
- $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
1120
- if (tp_inst) {
1121
- tp_inst._defaults.showTimepicker = false;
1122
- tp_inst._updateDateTime(inst);
1123
- }
1124
- };
1125
-
1126
- $.datepicker._enableTimepickerDatepicker = function(target, date, withDate) {
1127
- var inst = this._getInst(target),
1128
- tp_inst = this._get(inst, 'timepicker');
1129
- $(target).datepicker('getDate'); // Init selected[Year|Month|Day]
1130
- if (tp_inst) {
1131
- tp_inst._defaults.showTimepicker = true;
1132
- tp_inst._addTimePicker(inst); // Could be disabled on page load
1133
- tp_inst._updateDateTime(inst);
1134
- }
1135
- };
1136
-
1137
- //#######################################################################################
1138
- // Create our own set time function
1139
- //#######################################################################################
1140
- $.datepicker._setTime = function(inst, date) {
1141
- var tp_inst = this._get(inst, 'timepicker');
1142
- if (tp_inst) {
1143
- var defaults = tp_inst._defaults,
1144
- // calling _setTime with no date sets time to defaults
1145
- hour = date ? date.getHours() : defaults.hour,
1146
- minute = date ? date.getMinutes() : defaults.minute,
1147
- second = date ? date.getSeconds() : defaults.second,
1148
- millisec = date ? date.getMilliseconds() : defaults.millisec;
1149
-
1150
- //check if within min/max times..
1151
- if ((hour < defaults.hourMin || hour > defaults.hourMax) || (minute < defaults.minuteMin || minute > defaults.minuteMax) || (second < defaults.secondMin || second > defaults.secondMax) || (millisec < defaults.millisecMin || millisec > defaults.millisecMax)) {
1152
- hour = defaults.hourMin;
1153
- minute = defaults.minuteMin;
1154
- second = defaults.secondMin;
1155
- millisec = defaults.millisecMin;
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;
1156
1795
  }
1157
1796
 
1158
- tp_inst.hour = hour;
1159
- tp_inst.minute = minute;
1160
- tp_inst.second = second;
1161
- tp_inst.millisec = millisec;
1797
+ if (hour === 0) {
1798
+ hour = 12;
1799
+ }
1162
1800
 
1163
- if (tp_inst.hour_slider) tp_inst.hour_slider.slider('value', hour);
1164
- if (tp_inst.minute_slider) tp_inst.minute_slider.slider('value', minute);
1165
- if (tp_inst.second_slider) tp_inst.second_slider.slider('value', second);
1166
- if (tp_inst.millisec_slider) tp_inst.millisec_slider.slider('value', millisec);
1801
+ return String(hour);
1802
+ };
1167
1803
 
1168
- tp_inst._onTimeChange();
1169
- tp_inst._updateDateTime(inst);
1170
- }
1171
- };
1172
-
1173
- //#######################################################################################
1174
- // Create new public method to set only time, callable as $().datepicker('setTime', date)
1175
- //#######################################################################################
1176
- $.datepicker._setTimeDatepicker = function(target, date, withDate) {
1177
- var inst = this._getInst(target),
1178
- tp_inst = this._get(inst, 'timepicker');
1179
-
1180
- if (tp_inst) {
1181
- this._setDateFromField(inst);
1182
- var tp_date;
1183
- if (date) {
1184
- if (typeof date == "string") {
1185
- tp_inst._parseTime(date, withDate);
1186
- tp_date = new Date();
1187
- tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
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;
1188
1846
  }
1189
- else tp_date = new Date(date.getTime());
1190
- if (tp_date.toString() == 'Invalid Date') tp_date = undefined;
1191
- this._setTime(inst, tp_date);
1192
1847
  }
1193
- }
1848
+ return [dateTimeString, ''];
1849
+ };
1194
1850
 
1195
- };
1196
-
1197
- //#######################################################################################
1198
- // override setDate() to allow setting time too within Date object
1199
- //#######################################################################################
1200
- $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
1201
- $.datepicker._setDateDatepicker = function(target, date) {
1202
- var inst = this._getInst(target),
1203
- tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
1204
-
1205
- this._updateDatepicker(inst);
1206
- this._base_setDateDatepicker.apply(this, arguments);
1207
- this._setTimeDatepicker(target, tp_date, true);
1208
- };
1209
-
1210
- //#######################################################################################
1211
- // override getDate() to allow getting time too within Date object
1212
- //#######################################################################################
1213
- $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
1214
- $.datepicker._getDateDatepicker = function(target, noDefault) {
1215
- var inst = this._getInst(target),
1216
- tp_inst = this._get(inst, 'timepicker');
1217
-
1218
- if (tp_inst) {
1219
- this._setDateFromField(inst, noDefault);
1220
- var date = this._getDate(inst);
1221
- if (date && tp_inst._parseTime($(target).val(), tp_inst.timeOnly)) date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second, tp_inst.millisec);
1222
- return date;
1223
- }
1224
- return this._base_getDateDatepicker(target, noDefault);
1225
- };
1226
-
1227
- //#######################################################################################
1228
- // override parseDate() because UI 1.8.14 throws an error about "Extra characters"
1229
- // An option in datapicker to ignore extra format characters would be nicer.
1230
- //#######################################################################################
1231
- $.datepicker._base_parseDate = $.datepicker.parseDate;
1232
- $.datepicker.parseDate = function(format, value, settings) {
1233
- var date;
1234
- try {
1235
- date = this._base_parseDate(format, value, settings);
1236
- } catch (err) {
1237
- if (err.indexOf(":") >= 0) {
1238
- // Hack! The error message ends with a colon, a space, and
1239
- // the "extra" characters. We rely on that instead of
1240
- // attempting to perfectly reproduce the parsing algorithm.
1241
- date = this._base_parseDate(format, value.substring(0,value.length-(err.length-err.indexOf(':')-2)), settings);
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
+ };
1242
1872
  } else {
1243
- // The underlying error was not related to the time
1244
- throw err;
1873
+ return {
1874
+ date: date
1875
+ };
1245
1876
  }
1246
- }
1247
- return date;
1248
- };
1249
-
1250
- //#######################################################################################
1251
- // override formatDate to set date with time to the input
1252
- //#######################################################################################
1253
- $.datepicker._base_formatDate = $.datepicker._formatDate;
1254
- $.datepicker._formatDate = function(inst, day, month, year){
1255
- var tp_inst = this._get(inst, 'timepicker');
1256
- if(tp_inst) {
1257
- tp_inst._updateDateTime(inst);
1258
- return tp_inst.$input.val();
1259
- }
1260
- return this._base_formatDate(inst);
1261
- };
1262
-
1263
- //#######################################################################################
1264
- // override options setter to add time to maxDate(Time) and minDate(Time). MaxDate
1265
- //#######################################################################################
1266
- $.datepicker._base_optionDatepicker = $.datepicker._optionDatepicker;
1267
- $.datepicker._optionDatepicker = function(target, name, value) {
1268
- var inst = this._getInst(target),
1269
- tp_inst = this._get(inst, 'timepicker');
1270
- if (tp_inst) {
1271
- var min = null, max = null, onselect = null;
1272
- if (typeof name == 'string') { // if min/max was set with the string
1273
- if (name === 'minDate' || name === 'minDateTime' )
1274
- min = value;
1275
- else if (name === 'maxDate' || name === 'maxDateTime')
1276
- max = value;
1277
- else if (name === 'onSelect')
1278
- onselect = value;
1279
- } else if (typeof name == 'object') { //if min/max was set with the JSON
1280
- if (name.minDate)
1281
- min = name.minDate;
1282
- else if (name.minDateTime)
1283
- min = name.minDateTime;
1284
- else if (name.maxDate)
1285
- max = name.maxDate;
1286
- else if (name.maxDateTime)
1287
- max = name.maxDateTime;
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
+ }
1288
2056
  }
1289
- if(min) { //if min was set
1290
- if (min == 0)
1291
- min = new Date();
1292
- else
1293
- min = new Date(min);
1294
-
1295
- tp_inst._defaults.minDate = min;
1296
- tp_inst._defaults.minDateTime = min;
1297
- } else if (max) { //if max was set
1298
- if(max==0)
1299
- max=new Date();
1300
- else
1301
- max= new Date(max);
1302
- tp_inst._defaults.maxDate = max;
1303
- tp_inst._defaults.maxDateTime = max;
1304
- } else if (onselect)
1305
- tp_inst._defaults.onSelect = onselect;
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; };
1306
2096
  }
1307
- if (value === undefined)
1308
- return this._base_optionDatepicker(target, name);
1309
- return this._base_optionDatepicker(target, name, value);
1310
- };
1311
-
1312
- //#######################################################################################
1313
- // jQuery extend now ignores nulls!
1314
- //#######################################################################################
1315
- function extendRemove(target, props) {
1316
- $.extend(target, props);
1317
- for (var name in props)
1318
- if (props[name] === null || props[name] === undefined)
1319
- target[name] = props[name];
1320
- return target;
1321
- };
1322
-
1323
- $.timepicker = new Timepicker(); // singleton instance
1324
- $.timepicker.version = "1.0.0";
2097
+
2098
+ /*
2099
+ * Keep up with the version
2100
+ */
2101
+ $.timepicker.version = "1.3";
1325
2102
 
1326
2103
  })(jQuery);