sunrise-locales 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. data/Gemfile +36 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +15 -0
  4. data/Rakefile +27 -0
  5. data/app/controllers/manage/locales_controller.rb +43 -0
  6. data/app/views/manage/locales/_locale.html.erb +21 -0
  7. data/app/views/manage/locales/edit.html.erb +101 -0
  8. data/app/views/manage/locales/index.html.erb +24 -0
  9. data/config/locales/ru.yml +20 -0
  10. data/config/locales/uk.yml +20 -0
  11. data/config/routes.rb +5 -0
  12. data/lib/generators/sunrise/locales/USAGE +6 -0
  13. data/lib/generators/sunrise/locales/install_generator.rb +20 -0
  14. data/lib/generators/sunrise/locales/templates/codemirror.css +107 -0
  15. data/lib/generators/sunrise/locales/templates/codemirror.js +2157 -0
  16. data/lib/generators/sunrise/locales/templates/yaml.js +95 -0
  17. data/lib/sunrise-locales.rb +1 -0
  18. data/lib/sunrise/locales.rb +13 -0
  19. data/lib/sunrise/locales/engine.rb +19 -0
  20. data/lib/sunrise/locales/version.rb +5 -0
  21. data/lib/sunrise/locales/yml_locale.rb +43 -0
  22. data/spec/controllers/manage/locales_controller_spec.rb +59 -0
  23. data/spec/dummy/Rakefile +7 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  26. data/spec/dummy/app/helpers/manage/assets_helper.rb +2 -0
  27. data/spec/dummy/app/helpers/manage/base_helper.rb +81 -0
  28. data/spec/dummy/app/helpers/manage/pages_helper.rb +2 -0
  29. data/spec/dummy/app/helpers/manage/settings_helper.rb +2 -0
  30. data/spec/dummy/app/helpers/manage/structures_helper.rb +12 -0
  31. data/spec/dummy/app/helpers/manage/users_helper.rb +6 -0
  32. data/spec/dummy/app/models/defaults/ability.rb +39 -0
  33. data/spec/dummy/app/models/defaults/asset.rb +9 -0
  34. data/spec/dummy/app/models/defaults/attachment_file.rb +31 -0
  35. data/spec/dummy/app/models/defaults/avatar.rb +33 -0
  36. data/spec/dummy/app/models/defaults/header.rb +5 -0
  37. data/spec/dummy/app/models/defaults/page.rb +5 -0
  38. data/spec/dummy/app/models/defaults/picture.rb +31 -0
  39. data/spec/dummy/app/models/defaults/position_type.rb +7 -0
  40. data/spec/dummy/app/models/defaults/role.rb +20 -0
  41. data/spec/dummy/app/models/defaults/role_type.rb +8 -0
  42. data/spec/dummy/app/models/defaults/structure.rb +16 -0
  43. data/spec/dummy/app/models/defaults/structure_type.rb +9 -0
  44. data/spec/dummy/app/models/defaults/user.rb +47 -0
  45. data/spec/dummy/app/uploaders/attachment_file_uploader.rb +5 -0
  46. data/spec/dummy/app/uploaders/avatar_uploader.rb +17 -0
  47. data/spec/dummy/app/uploaders/picture_uploader.rb +17 -0
  48. data/spec/dummy/app/views/layouts/application.html.erb +37 -0
  49. data/spec/dummy/app/views/pages/show.html.erb +2 -0
  50. data/spec/dummy/app/views/shared/_notice.html.erb +17 -0
  51. data/spec/dummy/config.ru +4 -0
  52. data/spec/dummy/config/application.rb +46 -0
  53. data/spec/dummy/config/application.yml.sample +4 -0
  54. data/spec/dummy/config/boot.rb +10 -0
  55. data/spec/dummy/config/database.yml +22 -0
  56. data/spec/dummy/config/database.yml.sample +34 -0
  57. data/spec/dummy/config/environment.rb +5 -0
  58. data/spec/dummy/config/environments/development.rb +26 -0
  59. data/spec/dummy/config/environments/production.rb +49 -0
  60. data/spec/dummy/config/environments/test.rb +35 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/devise.rb +204 -0
  63. data/spec/dummy/config/initializers/inflections.rb +10 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  65. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  66. data/spec/dummy/config/initializers/session_store.rb +8 -0
  67. data/spec/dummy/config/initializers/simple_form.rb +93 -0
  68. data/spec/dummy/config/initializers/sunrise.rb +9 -0
  69. data/spec/dummy/config/locales/devise.en.yml +53 -0
  70. data/spec/dummy/config/locales/en.yml +3 -0
  71. data/spec/dummy/config/locales/ru.yml +3 -0
  72. data/spec/dummy/config/locales/simple_form.en.yml +24 -0
  73. data/spec/dummy/config/locales/uk.yml +2 -0
  74. data/spec/dummy/config/logrotate-config.sample +9 -0
  75. data/spec/dummy/config/nginx-config-passenger.sample +51 -0
  76. data/spec/dummy/config/routes.rb +64 -0
  77. data/spec/dummy/db/migrate/20110801124809_sunrise_create_users.rb +29 -0
  78. data/spec/dummy/db/migrate/20110801124909_sunrise_create_roles.rb +16 -0
  79. data/spec/dummy/db/migrate/20110801125009_sunrise_create_structures.rb +27 -0
  80. data/spec/dummy/db/migrate/20110801125109_sunrise_create_pages.rb +17 -0
  81. data/spec/dummy/db/migrate/20110801125209_sunrise_create_assets.rb +28 -0
  82. data/spec/dummy/db/migrate/20110801125309_sunrise_create_headers.rb +20 -0
  83. data/spec/dummy/db/seeds.rb +25 -0
  84. data/spec/dummy/db/test.sqlite3 +0 -0
  85. data/spec/dummy/lib/templates/erb/scaffold/_form.html.erb +13 -0
  86. data/spec/dummy/log/test.log +1678 -0
  87. data/spec/dummy/public/404.html +26 -0
  88. data/spec/dummy/public/422.html +26 -0
  89. data/spec/dummy/public/500.html +26 -0
  90. data/spec/dummy/public/favicon.ico +0 -0
  91. data/spec/dummy/public/images/manage/add_post_bot.gif +0 -0
  92. data/spec/dummy/public/images/manage/add_post_top.gif +0 -0
  93. data/spec/dummy/public/images/manage/add_white_bot.gif +0 -0
  94. data/spec/dummy/public/images/manage/add_white_top.gif +0 -0
  95. data/spec/dummy/public/images/manage/arrow.png +0 -0
  96. data/spec/dummy/public/images/manage/back_but_lc.gif +0 -0
  97. data/spec/dummy/public/images/manage/back_but_rc.gif +0 -0
  98. data/spec/dummy/public/images/manage/bot_corn.gif +0 -0
  99. data/spec/dummy/public/images/manage/bot_duo_corn.gif +0 -0
  100. data/spec/dummy/public/images/manage/but_bg.png +0 -0
  101. data/spec/dummy/public/images/manage/but_block_lc.gif +0 -0
  102. data/spec/dummy/public/images/manage/but_block_rc.gif +0 -0
  103. data/spec/dummy/public/images/manage/but_freze_lc.gif +0 -0
  104. data/spec/dummy/public/images/manage/but_freze_rc.gif +0 -0
  105. data/spec/dummy/public/images/manage/but_gr.gif +0 -0
  106. data/spec/dummy/public/images/manage/but_gr_l.gif +0 -0
  107. data/spec/dummy/public/images/manage/but_gr_r.gif +0 -0
  108. data/spec/dummy/public/images/manage/but_search.gif +0 -0
  109. data/spec/dummy/public/images/manage/but_unfreze_lc.gif +0 -0
  110. data/spec/dummy/public/images/manage/but_unfreze_rc.gif +0 -0
  111. data/spec/dummy/public/images/manage/button_add_foto.gif +0 -0
  112. data/spec/dummy/public/images/manage/button_add_foto_ru.gif +0 -0
  113. data/spec/dummy/public/images/manage/button_add_foto_ua.gif +0 -0
  114. data/spec/dummy/public/images/manage/button_add_foto_uk.gif +0 -0
  115. data/spec/dummy/public/images/manage/cancelbutton.gif +0 -0
  116. data/spec/dummy/public/images/manage/dark_arr.gif +0 -0
  117. data/spec/dummy/public/images/manage/dark_arr_left.gif +0 -0
  118. data/spec/dummy/public/images/manage/dark_cross_ico.gif +0 -0
  119. data/spec/dummy/public/images/manage/dot.gif +0 -0
  120. data/spec/dummy/public/images/manage/duo_bg.gif +0 -0
  121. data/spec/dummy/public/images/manage/duo_bg_small.gif +0 -0
  122. data/spec/dummy/public/images/manage/duo_bg_small_blocked.gif +0 -0
  123. data/spec/dummy/public/images/manage/duo_bg_small_frozed.gif +0 -0
  124. data/spec/dummy/public/images/manage/duo_bg_small_notact.gif +0 -0
  125. data/spec/dummy/public/images/manage/duo_bot_small.gif +0 -0
  126. data/spec/dummy/public/images/manage/duo_bot_small_blocked.gif +0 -0
  127. data/spec/dummy/public/images/manage/duo_bot_small_frozed.gif +0 -0
  128. data/spec/dummy/public/images/manage/duo_bot_small_notact.gif +0 -0
  129. data/spec/dummy/public/images/manage/duo_top_small.gif +0 -0
  130. data/spec/dummy/public/images/manage/duo_top_small_blocked.gif +0 -0
  131. data/spec/dummy/public/images/manage/duo_top_small_frozed.gif +0 -0
  132. data/spec/dummy/public/images/manage/duo_top_small_notact.gif +0 -0
  133. data/spec/dummy/public/images/manage/edit_white_top.gif +0 -0
  134. data/spec/dummy/public/images/manage/empty.gif +0 -0
  135. data/spec/dummy/public/images/manage/filter_bot_bg.gif +0 -0
  136. data/spec/dummy/public/images/manage/filter_top_bg.gif +0 -0
  137. data/spec/dummy/public/images/manage/flag_en.gif +0 -0
  138. data/spec/dummy/public/images/manage/flag_en_nonact.gif +0 -0
  139. data/spec/dummy/public/images/manage/flag_ru.gif +0 -0
  140. data/spec/dummy/public/images/manage/flag_ru_nonact.gif +0 -0
  141. data/spec/dummy/public/images/manage/flag_ua.gif +0 -0
  142. data/spec/dummy/public/images/manage/flag_ua_nonact.gif +0 -0
  143. data/spec/dummy/public/images/manage/foto.jpg +0 -0
  144. data/spec/dummy/public/images/manage/ico_add.gif +0 -0
  145. data/spec/dummy/public/images/manage/ico_del.gif +0 -0
  146. data/spec/dummy/public/images/manage/ico_down.gif +0 -0
  147. data/spec/dummy/public/images/manage/ico_edit.gif +0 -0
  148. data/spec/dummy/public/images/manage/ico_settings.gif +0 -0
  149. data/spec/dummy/public/images/manage/ico_up.gif +0 -0
  150. data/spec/dummy/public/images/manage/input_bg.gif +0 -0
  151. data/spec/dummy/public/images/manage/l_but_corn.gif +0 -0
  152. data/spec/dummy/public/images/manage/minimise_but.gif +0 -0
  153. data/spec/dummy/public/images/manage/mp3.png +0 -0
  154. data/spec/dummy/public/images/manage/page_arr_hover.png +0 -0
  155. data/spec/dummy/public/images/manage/page_next_arr.gif +0 -0
  156. data/spec/dummy/public/images/manage/page_num_hover.gif +0 -0
  157. data/spec/dummy/public/images/manage/page_prev_arr.gif +0 -0
  158. data/spec/dummy/public/images/manage/panel/l_but_corn.gif +0 -0
  159. data/spec/dummy/public/images/manage/panel/maximise_but.gif +0 -0
  160. data/spec/dummy/public/images/manage/panel/r_but_corn.gif +0 -0
  161. data/spec/dummy/public/images/manage/panel/top_menu_arr.gif +0 -0
  162. data/spec/dummy/public/images/manage/panel/user_pic.gif +0 -0
  163. data/spec/dummy/public/images/manage/preloader.gif +0 -0
  164. data/spec/dummy/public/images/manage/r_but_corn.gif +0 -0
  165. data/spec/dummy/public/images/manage/select_bg.gif +0 -0
  166. data/spec/dummy/public/images/manage/select_corn.gif +0 -0
  167. data/spec/dummy/public/images/manage/struct_corn_lg.gif +0 -0
  168. data/spec/dummy/public/images/manage/struct_corn_llg.gif +0 -0
  169. data/spec/dummy/public/images/manage/struct_corn_lw.gif +0 -0
  170. data/spec/dummy/public/images/manage/struct_corn_rg.gif +0 -0
  171. data/spec/dummy/public/images/manage/struct_corn_rlg.gif +0 -0
  172. data/spec/dummy/public/images/manage/struct_corn_rw.gif +0 -0
  173. data/spec/dummy/public/images/manage/tab_gl.gif +0 -0
  174. data/spec/dummy/public/images/manage/tab_gr.gif +0 -0
  175. data/spec/dummy/public/images/manage/tab_wl.gif +0 -0
  176. data/spec/dummy/public/images/manage/tab_wr.gif +0 -0
  177. data/spec/dummy/public/images/manage/top_corn.gif +0 -0
  178. data/spec/dummy/public/images/manage/top_duo_corn.gif +0 -0
  179. data/spec/dummy/public/images/manage/top_menu_arr.gif +0 -0
  180. data/spec/dummy/public/images/manage/transp_cross.png +0 -0
  181. data/spec/dummy/public/images/manage/upload_progress.gif +0 -0
  182. data/spec/dummy/public/images/manage/user_act_lc.gif +0 -0
  183. data/spec/dummy/public/images/manage/user_act_rc.gif +0 -0
  184. data/spec/dummy/public/images/manage/user_ico.gif +0 -0
  185. data/spec/dummy/public/images/manage/user_pic.gif +0 -0
  186. data/spec/dummy/public/images/manage/user_pic_small.gif +0 -0
  187. data/spec/dummy/public/images/manage/user_pic_thumb.gif +0 -0
  188. data/spec/dummy/public/javascripts/application.js +2 -0
  189. data/spec/dummy/public/javascripts/controls.js +965 -0
  190. data/spec/dummy/public/javascripts/datepicker/jquery-ui-i18n.js +1176 -0
  191. data/spec/dummy/public/javascripts/datepicker/jquery.ui.datepicker-ru.js +37 -0
  192. data/spec/dummy/public/javascripts/datepicker/jquery.ui.datepicker-uk.js +37 -0
  193. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  194. data/spec/dummy/public/javascripts/effects.js +1123 -0
  195. data/spec/dummy/public/javascripts/fileupload/fileuploader-input.js +217 -0
  196. data/spec/dummy/public/javascripts/fileupload/fileuploader.css +31 -0
  197. data/spec/dummy/public/javascripts/fileupload/fileuploader.js +1288 -0
  198. data/spec/dummy/public/javascripts/jquery-ui-timepicker-addon.js +911 -0
  199. data/spec/dummy/public/javascripts/jquery.cookie.js +97 -0
  200. data/spec/dummy/public/javascripts/jquery.fancybox-1.3.4.pack.js +46 -0
  201. data/spec/dummy/public/javascripts/jquery.tmpl.min.js +10 -0
  202. data/spec/dummy/public/javascripts/manage-fileuploader.js +182 -0
  203. data/spec/dummy/public/javascripts/manage.js +294 -0
  204. data/spec/dummy/public/javascripts/preloader.js +47 -0
  205. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  206. data/spec/dummy/public/javascripts/rails.js +331 -0
  207. data/spec/dummy/public/stylesheets/application.css +1 -0
  208. data/spec/dummy/public/stylesheets/fancybox/images/blank.gif +0 -0
  209. data/spec/dummy/public/stylesheets/fancybox/images/fancy_close.png +0 -0
  210. data/spec/dummy/public/stylesheets/fancybox/images/fancy_loading.png +0 -0
  211. data/spec/dummy/public/stylesheets/fancybox/images/fancy_nav_left.png +0 -0
  212. data/spec/dummy/public/stylesheets/fancybox/images/fancy_nav_right.png +0 -0
  213. data/spec/dummy/public/stylesheets/fancybox/images/fancy_shadow_e.png +0 -0
  214. data/spec/dummy/public/stylesheets/fancybox/images/fancy_shadow_n.png +0 -0
  215. data/spec/dummy/public/stylesheets/fancybox/images/fancy_shadow_ne.png +0 -0
  216. data/spec/dummy/public/stylesheets/fancybox/images/fancy_shadow_nw.png +0 -0
  217. data/spec/dummy/public/stylesheets/fancybox/images/fancy_shadow_s.png +0 -0
  218. data/spec/dummy/public/stylesheets/fancybox/images/fancy_shadow_se.png +0 -0
  219. data/spec/dummy/public/stylesheets/fancybox/images/fancy_shadow_sw.png +0 -0
  220. data/spec/dummy/public/stylesheets/fancybox/images/fancy_shadow_w.png +0 -0
  221. data/spec/dummy/public/stylesheets/fancybox/images/fancy_title_left.png +0 -0
  222. data/spec/dummy/public/stylesheets/fancybox/images/fancy_title_main.png +0 -0
  223. data/spec/dummy/public/stylesheets/fancybox/images/fancy_title_over.png +0 -0
  224. data/spec/dummy/public/stylesheets/fancybox/images/fancy_title_right.png +0 -0
  225. data/spec/dummy/public/stylesheets/fancybox/images/fancybox-x.png +0 -0
  226. data/spec/dummy/public/stylesheets/fancybox/images/fancybox-y.png +0 -0
  227. data/spec/dummy/public/stylesheets/fancybox/images/fancybox.png +0 -0
  228. data/spec/dummy/public/stylesheets/fancybox/jquery.fancybox-1.3.4.css +359 -0
  229. data/spec/dummy/public/stylesheets/manage/buttons.css +42 -0
  230. data/spec/dummy/public/stylesheets/manage/ie.css +16 -0
  231. data/spec/dummy/public/stylesheets/manage/main.css +1108 -0
  232. data/spec/dummy/public/stylesheets/manage/panel.css +126 -0
  233. data/spec/dummy/public/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  234. data/spec/dummy/public/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  235. data/spec/dummy/public/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  236. data/spec/dummy/public/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  237. data/spec/dummy/public/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  238. data/spec/dummy/public/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  239. data/spec/dummy/public/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  240. data/spec/dummy/public/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  241. data/spec/dummy/public/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
  242. data/spec/dummy/public/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  243. data/spec/dummy/public/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
  244. data/spec/dummy/public/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
  245. data/spec/dummy/public/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  246. data/spec/dummy/public/stylesheets/smoothness/jquery-ui-1.8.13.custom.css +578 -0
  247. data/spec/dummy/script/rails +6 -0
  248. data/spec/factories/structure_factory.rb +22 -0
  249. data/spec/factories/user_factory.rb +48 -0
  250. data/spec/generators/install_generator_spec.rb +18 -0
  251. data/spec/integration/navigation_spec.rb +9 -0
  252. data/spec/spec.opts +2 -0
  253. data/spec/spec_helper.rb +57 -0
  254. data/spec/sunrise_locales_spec.rb +7 -0
  255. data/spec/support/helpers/controller_macros.rb +40 -0
  256. data/spec/tmp/public/javascripts/codemirror.js +2157 -0
  257. data/spec/tmp/public/javascripts/yaml.js +95 -0
  258. data/spec/tmp/public/stylesheets/codemirror.css +107 -0
  259. metadata +575 -0
@@ -0,0 +1,911 @@
1
+ /*
2
+ * jQuery timepicker addon
3
+ * By: Trent Richardson [http://trentrichardson.com]
4
+ * Version 0.9.3
5
+ * Last Modified: 02/05/2011
6
+ *
7
+ * Copyright 2010 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; }
16
+ * .ui-timepicker-div dl dd{ margin: -25px 0 10px 65px; }
17
+ * .ui-timepicker-div td { font-size: 90%; }
18
+ */
19
+
20
+ (function($) {
21
+
22
+ $.extend($.ui, { timepicker: { version: "0.9.3" } });
23
+
24
+ /* Time picker manager.
25
+ Use the singleton instance of this class, $.timepicker, to interact with the time picker.
26
+ Settings for (groups of) time pickers are maintained in an instance object,
27
+ allowing multiple different settings on the same page. */
28
+
29
+ function Timepicker() {
30
+ this.regional = []; // Available regional settings, indexed by language code
31
+ this.regional[''] = { // Default regional settings
32
+ currentText: 'Now',
33
+ closeText: 'Done',
34
+ ampm: false,
35
+ timeFormat: 'hh:mm tt',
36
+ timeOnlyTitle: 'Choose Time',
37
+ timeText: 'Time',
38
+ hourText: 'Hour',
39
+ minuteText: 'Minute',
40
+ secondText: 'Second'
41
+ };
42
+ this._defaults = { // Global defaults for all the datetime picker instances
43
+ showButtonPanel: true,
44
+ timeOnly: false,
45
+ showHour: true,
46
+ showMinute: true,
47
+ showSecond: false,
48
+ showTime: true,
49
+ stepHour: 0.05,
50
+ stepMinute: 0.05,
51
+ stepSecond: 0.05,
52
+ hour: 0,
53
+ minute: 0,
54
+ second: 0,
55
+ hourMin: 0,
56
+ minuteMin: 0,
57
+ secondMin: 0,
58
+ hourMax: 23,
59
+ minuteMax: 59,
60
+ secondMax: 59,
61
+ minDateTime: null,
62
+ maxDateTime: null,
63
+ hourGrid: 0,
64
+ minuteGrid: 0,
65
+ secondGrid: 0,
66
+ alwaysSetTime: true,
67
+ separator: ' ',
68
+ altFieldTimeOnly: true,
69
+ showTimepicker: true
70
+ };
71
+ $.extend(this._defaults, this.regional['']);
72
+ }
73
+
74
+ $.extend(Timepicker.prototype, {
75
+ $input: null,
76
+ $altInput: null,
77
+ $timeObj: null,
78
+ inst: null,
79
+ hour_slider: null,
80
+ minute_slider: null,
81
+ second_slider: null,
82
+ hour: 0,
83
+ minute: 0,
84
+ second: 0,
85
+ hourMinOriginal: null,
86
+ minuteMinOriginal: null,
87
+ secondMinOriginal: null,
88
+ hourMaxOriginal: null,
89
+ minuteMaxOriginal: null,
90
+ secondMaxOriginal: null,
91
+ ampm: '',
92
+ formattedDate: '',
93
+ formattedTime: '',
94
+ formattedDateTime: '',
95
+
96
+ /* Override the default settings for all instances of the time picker.
97
+ @param settings object - the new settings to use as defaults (anonymous object)
98
+ @return the manager object */
99
+ setDefaults: function(settings) {
100
+ extendRemove(this._defaults, settings || {});
101
+ return this;
102
+ },
103
+
104
+ //########################################################################
105
+ // Create a new Timepicker instance
106
+ //########################################################################
107
+ _newInst: function($input, o) {
108
+ var tp_inst = new Timepicker(),
109
+ inlineSettings = {};
110
+
111
+ tp_inst.hour = tp_inst._defaults.hour;
112
+ tp_inst.minute = tp_inst._defaults.minute;
113
+ tp_inst.second = tp_inst._defaults.second;
114
+ tp_inst.ampm = '';
115
+ tp_inst.$input = $input;
116
+
117
+
118
+ for (var attrName in this._defaults) {
119
+ var attrValue = $input.attr('time:' + attrName);
120
+ if (attrValue) {
121
+ try {
122
+ inlineSettings[attrName] = eval(attrValue);
123
+ } catch (err) {
124
+ inlineSettings[attrName] = attrValue;
125
+ }
126
+ }
127
+ }
128
+ tp_inst._defaults = $.extend({}, this._defaults, inlineSettings, o, {
129
+ beforeShow: function(input, dp_inst) {
130
+ if ($.isFunction(o.beforeShow))
131
+ o.beforeShow(input, dp_inst, tp_inst);
132
+ },
133
+ onChangeMonthYear: function(year, month, dp_inst) {
134
+ // Update the time as well : this prevents the time from disappearing from the $input field.
135
+ tp_inst._updateDateTime(dp_inst);
136
+ if ($.isFunction(o.onChangeMonthYear))
137
+ o.onChangeMonthYear(year, month, dp_inst, tp_inst);
138
+ },
139
+ onClose: function(dateText, dp_inst) {
140
+ if (tp_inst.timeDefined === true && $input.val() != '')
141
+ tp_inst._updateDateTime(dp_inst);
142
+ if ($.isFunction(o.onClose))
143
+ o.onClose(dateText, dp_inst, tp_inst);
144
+ },
145
+ timepicker: tp_inst // add timepicker as a property of datepicker: $.datepicker._get(dp_inst, 'timepicker');
146
+ });
147
+
148
+ if (o.altField)
149
+ tp_inst.$altInput = $(o.altField)
150
+ .css({ cursor: 'pointer' })
151
+ .focus(function(){ $input.trigger("focus"); });
152
+
153
+ // datepicker needs minDate/maxDate, timepicker needs minDateTime/maxDateTime..
154
+ if(tp_inst._defaults.minDate !== undefined && tp_inst._defaults.minDate instanceof Date)
155
+ tp_inst._defaults.minDateTime = new Date(tp_inst._defaults.minDate.getTime());
156
+ if(tp_inst._defaults.minDateTime !== undefined && tp_inst._defaults.minDateTime instanceof Date)
157
+ tp_inst._defaults.minDate = new Date(tp_inst._defaults.minDateTime.getTime());
158
+ if(tp_inst._defaults.maxDate !== undefined && tp_inst._defaults.maxDate instanceof Date)
159
+ tp_inst._defaults.maxDateTime = new Date(tp_inst._defaults.maxDate.getTime());
160
+ if(tp_inst._defaults.maxDateTime !== undefined && tp_inst._defaults.maxDateTime instanceof Date)
161
+ tp_inst._defaults.maxDate = new Date(tp_inst._defaults.maxDateTime.getTime());
162
+
163
+ return tp_inst;
164
+ },
165
+
166
+ //########################################################################
167
+ // add our sliders to the calendar
168
+ //########################################################################
169
+ _addTimePicker: function(dp_inst) {
170
+ var currDT = (this.$altInput && this._defaults.altFieldTimeOnly) ?
171
+ this.$input.val() + ' ' + this.$altInput.val() :
172
+ this.$input.val();
173
+
174
+ this.timeDefined = this._parseTime(currDT);
175
+ this._limitMinMaxDateTime(dp_inst, false);
176
+ this._injectTimePicker();
177
+ },
178
+
179
+ //########################################################################
180
+ // parse the time string from input value or _setTime
181
+ //########################################################################
182
+ _parseTime: function(timeString, withDate) {
183
+ var regstr = this._defaults.timeFormat.toString()
184
+ .replace(/h{1,2}/ig, '(\\d?\\d)')
185
+ .replace(/m{1,2}/ig, '(\\d?\\d)')
186
+ .replace(/s{1,2}/ig, '(\\d?\\d)')
187
+ .replace(/t{1,2}/ig, '(am|pm|a|p)?')
188
+ .replace(/\s/g, '\\s?') + '$',
189
+ order = this._getFormatPositions(),
190
+ treg;
191
+
192
+ if (!this.inst) this.inst = $.datepicker._getInst(this.$input[0]);
193
+
194
+ if (withDate || !this._defaults.timeOnly) {
195
+ // the time should come after x number of characters and a space.
196
+ // x = at least the length of text specified by the date format
197
+ var dp_dateFormat = $.datepicker._get(this.inst, 'dateFormat');
198
+ regstr = '.{' + dp_dateFormat.length + ',}' + this._defaults.separator + regstr;
199
+ }
200
+
201
+ treg = timeString.match(new RegExp(regstr, 'i'));
202
+
203
+ if (treg) {
204
+ if (order.t !== -1)
205
+ this.ampm = ((treg[order.t] === undefined || treg[order.t].length === 0) ?
206
+ '' :
207
+ (treg[order.t].charAt(0).toUpperCase() == 'A') ? 'AM' : 'PM').toUpperCase();
208
+
209
+ if (order.h !== -1) {
210
+ if (this.ampm == 'AM' && treg[order.h] == '12')
211
+ this.hour = 0; // 12am = 0 hour
212
+ else if (this.ampm == 'PM' && treg[order.h] != '12')
213
+ this.hour = (parseFloat(treg[order.h]) + 12).toFixed(0); // 12pm = 12 hour, any other pm = hour + 12
214
+ else this.hour = Number(treg[order.h]);
215
+ }
216
+
217
+ if (order.m !== -1) this.minute = Number(treg[order.m]);
218
+ if (order.s !== -1) this.second = Number(treg[order.s]);
219
+
220
+ return true;
221
+
222
+ }
223
+ return false;
224
+ },
225
+
226
+ //########################################################################
227
+ // figure out position of time elements.. cause js cant do named captures
228
+ //########################################################################
229
+ _getFormatPositions: function() {
230
+ var finds = this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|t{1,2})/g),
231
+ orders = { h: -1, m: -1, s: -1, t: -1 };
232
+
233
+ if (finds)
234
+ for (var i = 0; i < finds.length; i++)
235
+ if (orders[finds[i].toString().charAt(0)] == -1)
236
+ orders[finds[i].toString().charAt(0)] = i + 1;
237
+
238
+ return orders;
239
+ },
240
+
241
+ //########################################################################
242
+ // generate and inject html for timepicker into ui datepicker
243
+ //########################################################################
244
+ _injectTimePicker: function() {
245
+ var $dp = this.inst.dpDiv,
246
+ o = this._defaults,
247
+ tp_inst = this,
248
+ // Added by Peter Medeiros:
249
+ // - Figure out what the hour/minute/second max should be based on the step values.
250
+ // - Example: if stepMinute is 15, then minMax is 45.
251
+ hourMax = (o.hourMax - (o.hourMax % o.stepHour)).toFixed(0),
252
+ minMax = (o.minuteMax - (o.minuteMax % o.stepMinute)).toFixed(0),
253
+ secMax = (o.secondMax - (o.secondMax % o.stepSecond)).toFixed(0),
254
+ dp_id = this.inst.id.toString().replace(/([^A-Za-z0-9_])/g, '');
255
+
256
+ // Prevent displaying twice
257
+ //if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0) {
258
+ if ($dp.find("div#ui-timepicker-div-"+ dp_id).length === 0 && o.showTimepicker) {
259
+ var noDisplay = ' style="display:none;"',
260
+ html = '<div class="ui-timepicker-div" id="ui-timepicker-div-' + dp_id + '"><dl>' +
261
+ '<dt class="ui_tpicker_time_label" id="ui_tpicker_time_label_' + dp_id + '"' +
262
+ ((o.showTime) ? '' : noDisplay) + '>' + o.timeText + '</dt>' +
263
+ '<dd class="ui_tpicker_time" id="ui_tpicker_time_' + dp_id + '"' +
264
+ ((o.showTime) ? '' : noDisplay) + '></dd>' +
265
+ '<dt class="ui_tpicker_hour_label" id="ui_tpicker_hour_label_' + dp_id + '"' +
266
+ ((o.showHour) ? '' : noDisplay) + '>' + o.hourText + '</dt>',
267
+ hourGridSize = 0,
268
+ minuteGridSize = 0,
269
+ secondGridSize = 0,
270
+ size;
271
+
272
+ if (o.showHour && o.hourGrid > 0) {
273
+ html += '<dd class="ui_tpicker_hour">' +
274
+ '<div id="ui_tpicker_hour_' + dp_id + '"' + ((o.showHour) ? '' : noDisplay) + '></div>' +
275
+ '<div style="padding-left: 1px"><table><tr>';
276
+
277
+ for (var h = o.hourMin; h < hourMax; h += o.hourGrid) {
278
+ hourGridSize++;
279
+ var tmph = (o.ampm && h > 12) ? h-12 : h;
280
+ if (tmph < 10) tmph = '0' + tmph;
281
+ if (o.ampm) {
282
+ if (h == 0) tmph = 12 +'a';
283
+ else if (h < 12) tmph += 'a';
284
+ else tmph += 'p';
285
+ }
286
+ html += '<td>' + tmph + '</td>';
287
+ }
288
+
289
+ html += '</tr></table></div>' +
290
+ '</dd>';
291
+ } else html += '<dd class="ui_tpicker_hour" id="ui_tpicker_hour_' + dp_id + '"' +
292
+ ((o.showHour) ? '' : noDisplay) + '></dd>';
293
+
294
+ html += '<dt class="ui_tpicker_minute_label" id="ui_tpicker_minute_label_' + dp_id + '"' +
295
+ ((o.showMinute) ? '' : noDisplay) + '>' + o.minuteText + '</dt>';
296
+
297
+ if (o.showMinute && o.minuteGrid > 0) {
298
+ html += '<dd class="ui_tpicker_minute ui_tpicker_minute_' + o.minuteGrid + '">' +
299
+ '<div id="ui_tpicker_minute_' + dp_id + '"' +
300
+ ((o.showMinute) ? '' : noDisplay) + '></div>' +
301
+ '<div style="padding-left: 1px"><table><tr>';
302
+
303
+ for (var m = o.minuteMin; m < minMax; m += o.minuteGrid) {
304
+ minuteGridSize++;
305
+ html += '<td>' + ((m < 10) ? '0' : '') + m + '</td>';
306
+ }
307
+
308
+ html += '</tr></table></div>' +
309
+ '</dd>';
310
+ } else html += '<dd class="ui_tpicker_minute" id="ui_tpicker_minute_' + dp_id + '"' +
311
+ ((o.showMinute) ? '' : noDisplay) + '></dd>';
312
+
313
+ html += '<dt class="ui_tpicker_second_label" id="ui_tpicker_second_label_' + dp_id + '"' +
314
+ ((o.showSecond) ? '' : noDisplay) + '>' + o.secondText + '</dt>';
315
+
316
+ if (o.showSecond && o.secondGrid > 0) {
317
+ html += '<dd class="ui_tpicker_second ui_tpicker_second_' + o.secondGrid + '">' +
318
+ '<div id="ui_tpicker_second_' + dp_id + '"' +
319
+ ((o.showSecond) ? '' : noDisplay) + '></div>' +
320
+ '<div style="padding-left: 1px"><table><tr>';
321
+
322
+ for (var s = o.secondMin; s < secMax; s += o.secondGrid) {
323
+ secondGridSize++;
324
+ html += '<td>' + ((s < 10) ? '0' : '') + s + '</td>';
325
+ }
326
+
327
+ html += '</tr></table></div>' +
328
+ '</dd>';
329
+ } else html += '<dd class="ui_tpicker_second" id="ui_tpicker_second_' + dp_id + '"' +
330
+ ((o.showSecond) ? '' : noDisplay) + '></dd>';
331
+
332
+ html += '</dl></div>';
333
+ $tp = $(html);
334
+
335
+ // if we only want time picker...
336
+ if (o.timeOnly === true) {
337
+ $tp.prepend(
338
+ '<div class="ui-widget-header ui-helper-clearfix ui-corner-all">' +
339
+ '<div class="ui-datepicker-title">' + o.timeOnlyTitle + '</div>' +
340
+ '</div>');
341
+ $dp.find('.ui-datepicker-header, .ui-datepicker-calendar').hide();
342
+ }
343
+
344
+ this.hour_slider = $tp.find('#ui_tpicker_hour_'+ dp_id).slider({
345
+ orientation: "horizontal",
346
+ value: this.hour,
347
+ min: o.hourMin,
348
+ max: hourMax,
349
+ step: o.stepHour,
350
+ slide: function(event, ui) {
351
+ tp_inst.hour_slider.slider( "option", "value", ui.value);
352
+ tp_inst._onTimeChange();
353
+ }
354
+ });
355
+
356
+ // Updated by Peter Medeiros:
357
+ // - Pass in Event and UI instance into slide function
358
+ this.minute_slider = $tp.find('#ui_tpicker_minute_'+ dp_id).slider({
359
+ orientation: "horizontal",
360
+ value: this.minute,
361
+ min: o.minuteMin,
362
+ max: minMax,
363
+ step: o.stepMinute,
364
+ slide: function(event, ui) {
365
+ // update the global minute slider instance value with the current slider value
366
+ tp_inst.minute_slider.slider( "option", "value", ui.value);
367
+ tp_inst._onTimeChange();
368
+ }
369
+ });
370
+
371
+ this.second_slider = $tp.find('#ui_tpicker_second_'+ dp_id).slider({
372
+ orientation: "horizontal",
373
+ value: this.second,
374
+ min: o.secondMin,
375
+ max: secMax,
376
+ step: o.stepSecond,
377
+ slide: function(event, ui) {
378
+ tp_inst.second_slider.slider( "option", "value", ui.value);
379
+ tp_inst._onTimeChange();
380
+ }
381
+ });
382
+
383
+ // Add grid functionality
384
+ if (o.showHour && o.hourGrid > 0) {
385
+ size = 100 * hourGridSize * o.hourGrid / (hourMax - o.hourMin);
386
+
387
+ $tp.find(".ui_tpicker_hour table").css({
388
+ width: size + "%",
389
+ marginLeft: (size / (-2 * hourGridSize)) + "%",
390
+ borderCollapse: 'collapse'
391
+ }).find("td").each( function(index) {
392
+ $(this).click(function() {
393
+ var h = $(this).html();
394
+ if(o.ampm) {
395
+ var ap = h.substring(2).toLowerCase(),
396
+ aph = parseInt(h.substring(0,2));
397
+ if (ap == 'a') {
398
+ if (aph == 12) h = 0;
399
+ else h = aph;
400
+ } else if (aph == 12) h = 12;
401
+ else h = aph + 12;
402
+ }
403
+ tp_inst.hour_slider.slider("option", "value", h);
404
+ tp_inst._onTimeChange();
405
+ }).css({
406
+ cursor: 'pointer',
407
+ width: (100 / hourGridSize) + '%',
408
+ textAlign: 'center',
409
+ overflow: 'hidden'
410
+ });
411
+ });
412
+ }
413
+
414
+ if (o.showMinute && o.minuteGrid > 0) {
415
+ size = 100 * minuteGridSize * o.minuteGrid / (minMax - o.minuteMin);
416
+ $tp.find(".ui_tpicker_minute table").css({
417
+ width: size + "%",
418
+ marginLeft: (size / (-2 * minuteGridSize)) + "%",
419
+ borderCollapse: 'collapse'
420
+ }).find("td").each(function(index) {
421
+ $(this).click(function() {
422
+ tp_inst.minute_slider.slider("option", "value", $(this).html());
423
+ tp_inst._onTimeChange();
424
+ }).css({
425
+ cursor: 'pointer',
426
+ width: (100 / minuteGridSize) + '%',
427
+ textAlign: 'center',
428
+ overflow: 'hidden'
429
+ });
430
+ });
431
+ }
432
+
433
+ if (o.showSecond && o.secondGrid > 0) {
434
+ $tp.find(".ui_tpicker_second table").css({
435
+ width: size + "%",
436
+ marginLeft: (size / (-2 * secondGridSize)) + "%",
437
+ borderCollapse: 'collapse'
438
+ }).find("td").each(function(index) {
439
+ $(this).click(function() {
440
+ tp_inst.second_slider.slider("option", "value", $(this).html());
441
+ tp_inst._onTimeChange();
442
+ }).css({
443
+ cursor: 'pointer',
444
+ width: (100 / secondGridSize) + '%',
445
+ textAlign: 'center',
446
+ overflow: 'hidden'
447
+ });
448
+ });
449
+ }
450
+
451
+ var $buttonPanel = $dp.find('.ui-datepicker-buttonpane');
452
+ if ($buttonPanel.length) $buttonPanel.before($tp);
453
+ else $dp.append($tp);
454
+
455
+ this.$timeObj = $('#ui_tpicker_time_'+ dp_id);
456
+
457
+ if (this.inst !== null) {
458
+ var timeDefined = this.timeDefined;
459
+ this._onTimeChange();
460
+ this.timeDefined = timeDefined;
461
+ }
462
+
463
+ //Emulate datepicker onSelect behavior. Call on slidestop.
464
+ var onSelect = tp_inst._defaults['onSelect'];
465
+ if (onSelect) {
466
+ var inputEl = tp_inst.$input ? tp_inst.$input[0] : null;
467
+ var onSelectHandler = function() {
468
+ onSelect.apply(inputEl, [tp_inst.formattedDateTime, tp_inst]); // trigger custom callback*/
469
+ }
470
+ this.hour_slider.bind('slidestop',onSelectHandler);
471
+ this.minute_slider.bind('slidestop',onSelectHandler);
472
+ this.second_slider.bind('slidestop',onSelectHandler);
473
+ }
474
+ }
475
+ },
476
+
477
+ //########################################################################
478
+ // This function tries to limit the ability to go outside the
479
+ // min/max date range
480
+ //########################################################################
481
+ _limitMinMaxDateTime: function(dp_inst, adjustSliders){
482
+ var o = this._defaults,
483
+ dp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay),
484
+ tp_date = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay, this.hour, this.minute, this.second, 0);
485
+
486
+ if(this._defaults.minDateTime !== null && dp_date){
487
+ var minDateTime = this._defaults.minDateTime,
488
+ minDateTimeDate = new Date(minDateTime.getFullYear(), minDateTime.getMonth(), minDateTime.getDate(), 0, 0, 0, 0);
489
+
490
+ if(this.hourMinOriginal === null || this.minuteMinOriginal === null || this.secondMinOriginal === null){
491
+ this.hourMinOriginal = o.hourMin;
492
+ this.minuteMinOriginal = o.minuteMin;
493
+ this.secondMinOriginal = o.secondMin;
494
+ }
495
+
496
+ if(minDateTimeDate.getTime() == dp_date.getTime()){
497
+ this._defaults.hourMin = minDateTime.getHours();
498
+ this._defaults.minuteMin = minDateTime.getMinutes();
499
+ this._defaults.secondMin = minDateTime.getSeconds();
500
+
501
+ if(this.hour < this._defaults.hourMin) this.hour = this._defaults.hourMin;
502
+ if(this.minute < this._defaults.minuteMin) this.minute = this._defaults.minuteMin;
503
+ if(this.second < this._defaults.secondMin) this.second = this._defaults.secondMin;
504
+ }else{
505
+ this._defaults.hourMin = this.hourMinOriginal;
506
+ this._defaults.minuteMin = this.minuteMinOriginal;
507
+ this._defaults.secondMin = this.secondMinOriginal;
508
+ }
509
+ }
510
+
511
+ if(this._defaults.maxDateTime !== null && dp_date){
512
+ var maxDateTime = this._defaults.maxDateTime,
513
+ maxDateTimeDate = new Date(maxDateTime.getFullYear(), maxDateTime.getMonth(), maxDateTime.getDate(), 0, 0, 0, 0);
514
+
515
+ if(this.hourMaxOriginal === null || this.minuteMaxOriginal === null || this.secondMaxOriginal === null){
516
+ this.hourMaxOriginal = o.hourMax;
517
+ this.minuteMaxOriginal = o.minuteMax;
518
+ this.secondMaxOriginal = o.secondMax;
519
+ }
520
+
521
+ if(maxDateTimeDate.getTime() == dp_date.getTime()){
522
+ this._defaults.hourMax = maxDateTime.getHours();
523
+ this._defaults.minuteMax = maxDateTime.getMinutes();
524
+ this._defaults.secondMax = maxDateTime.getSeconds();
525
+
526
+ if(this.hour > this._defaults.hourMax){ this.hour = this._defaults.hourMax; }
527
+ if(this.minute > this._defaults.minuteMax) this.minute = this._defaults.minuteMax;
528
+ if(this.second > this._defaults.secondMax) this.second = this._defaults.secondMax;
529
+ }else{
530
+ this._defaults.hourMax = this.hourMaxOriginal;
531
+ this._defaults.minuteMax = this.minuteMaxOriginal;
532
+ this._defaults.secondMax = this.secondMaxOriginal;
533
+ }
534
+ }
535
+
536
+ if(adjustSliders !== undefined && adjustSliders === true){
537
+ this.hour_slider.slider("option", { min: this._defaults.hourMin, max: this._defaults.hourMax }).slider('value', this.hour);
538
+ this.minute_slider.slider("option", { min: this._defaults.minuteMin, max: this._defaults.minuteMax }).slider('value', this.minute);
539
+ this.second_slider.slider("option", { min: this._defaults.secondMin, max: this._defaults.secondMax }).slider('value', this.second);
540
+ }
541
+
542
+ },
543
+
544
+ //########################################################################
545
+ // when a slider moves, set the internal time...
546
+ // on time change is also called when the time is updated in the text field
547
+ //########################################################################
548
+ _onTimeChange: function() {
549
+ var hour = (this.hour_slider) ? this.hour_slider.slider('value') : false,
550
+ minute = (this.minute_slider) ? this.minute_slider.slider('value') : false,
551
+ second = (this.second_slider) ? this.second_slider.slider('value') : false;
552
+
553
+ if (hour !== false) hour = parseInt(hour,10);
554
+ if (minute !== false) minute = parseInt(minute,10);
555
+ if (second !== false) second = parseInt(second,10);
556
+
557
+ var ampm = (hour < 12) ? 'AM' : 'PM';
558
+
559
+ // If the update was done in the input field, the input field should not be updated.
560
+ // If the update was done using the sliders, update the input field.
561
+ var hasChanged = (hour != this.hour || minute != this.minute || second != this.second || (this.ampm.length > 0 && this.ampm != ampm));
562
+
563
+ if (hasChanged) {
564
+
565
+ if (hour !== false)this.hour = hour;
566
+ if (minute !== false) this.minute = minute;
567
+ if (second !== false) this.second = second;
568
+ }
569
+ if (this._defaults.ampm) this.ampm = ampm;
570
+
571
+ this._formatTime();
572
+ if (this.$timeObj) this.$timeObj.text(this.formattedTime);
573
+ this.timeDefined = true;
574
+ if (hasChanged) this._updateDateTime();
575
+ },
576
+
577
+ //########################################################################
578
+ // format the time all pretty...
579
+ //########################################################################
580
+ _formatTime: function(time, format, ampm) {
581
+ if (ampm == undefined) ampm = this._defaults.ampm;
582
+ time = time || { hour: this.hour, minute: this.minute, second: this.second, ampm: this.ampm };
583
+ var tmptime = format || this._defaults.timeFormat.toString();
584
+
585
+ if (ampm) {
586
+ var hour12 = ((time.ampm == 'AM') ? (time.hour) : (time.hour % 12));
587
+ hour12 = (Number(hour12) === 0) ? 12 : hour12;
588
+ tmptime = tmptime.toString()
589
+ .replace(/hh/g, ((hour12 < 10) ? '0' : '') + hour12)
590
+ .replace(/h/g, hour12)
591
+ .replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute)
592
+ .replace(/m/g, time.minute)
593
+ .replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second)
594
+ .replace(/s/g, time.second)
595
+ .replace(/TT/g, time.ampm.toUpperCase())
596
+ .replace(/tt/g, time.ampm.toLowerCase())
597
+ .replace(/T/g, time.ampm.charAt(0).toUpperCase())
598
+ .replace(/t/g, time.ampm.charAt(0).toLowerCase());
599
+ } else {
600
+ tmptime = tmptime.toString()
601
+ .replace(/hh/g, ((time.hour < 10) ? '0' : '') + time.hour)
602
+ .replace(/h/g, time.hour)
603
+ .replace(/mm/g, ((time.minute < 10) ? '0' : '') + time.minute)
604
+ .replace(/m/g, time.minute)
605
+ .replace(/ss/g, ((time.second < 10) ? '0' : '') + time.second)
606
+ .replace(/s/g, time.second);
607
+ tmptime = $.trim(tmptime.replace(/t/gi, ''));
608
+ }
609
+
610
+ if (arguments.length) return tmptime;
611
+ else this.formattedTime = tmptime;
612
+ },
613
+
614
+ //########################################################################
615
+ // update our input with the new date time..
616
+ //########################################################################
617
+ _updateDateTime: function(dp_inst) {
618
+ dp_inst = this.inst || dp_inst,
619
+ dt = new Date(dp_inst.selectedYear, dp_inst.selectedMonth, dp_inst.selectedDay),
620
+ dateFmt = $.datepicker._get(dp_inst, 'dateFormat'),
621
+ formatCfg = $.datepicker._getFormatConfig(dp_inst),
622
+ timeAvailable = dt !== null && this.timeDefined;
623
+ this.formattedDate = $.datepicker.formatDate(dateFmt, (dt === null ? new Date() : dt), formatCfg);
624
+ var formattedDateTime = this.formattedDate;
625
+ if (dp_inst.lastVal !== undefined && (dp_inst.lastVal.length > 0 && this.$input.val().length === 0))
626
+ return;
627
+
628
+ if (this._defaults.timeOnly === true) {
629
+ formattedDateTime = this.formattedTime;
630
+ } else if (this._defaults.timeOnly !== true && (this._defaults.alwaysSetTime || timeAvailable)) {
631
+ formattedDateTime += this._defaults.separator + this.formattedTime;
632
+ }
633
+
634
+ this.formattedDateTime = formattedDateTime;
635
+
636
+ if(!this._defaults.showTimepicker) {
637
+ this.$input.val(this.formattedDate);
638
+ } else if (this.$altInput && this._defaults.altFieldTimeOnly === true) {
639
+ this.$altInput.val(this.formattedTime);
640
+ this.$input.val(this.formattedDate);
641
+ } else if(this.$altInput) {
642
+ this.$altInput.val(formattedDateTime);
643
+ this.$input.val(formattedDateTime);
644
+ } else {
645
+ this.$input.val(formattedDateTime);
646
+ }
647
+
648
+ this.$input.trigger("change");
649
+ }
650
+
651
+ });
652
+
653
+ $.fn.extend({
654
+ //########################################################################
655
+ // shorthand just to use timepicker..
656
+ //########################################################################
657
+ timepicker: function(o) {
658
+ o = o || {};
659
+ var tmp_args = arguments;
660
+
661
+ if (typeof o == 'object') tmp_args[0] = $.extend(o, { timeOnly: true });
662
+
663
+ return $(this).each(function() {
664
+ $.fn.datetimepicker.apply($(this), tmp_args);
665
+ });
666
+ },
667
+
668
+ //########################################################################
669
+ // extend timepicker to datepicker
670
+ //########################################################################
671
+ datetimepicker: function(o) {
672
+ o = o || {};
673
+ var $input = this,
674
+ tmp_args = arguments;
675
+
676
+ if (typeof(o) == 'string'){
677
+ if(o == 'getDate')
678
+ return $.fn.datepicker.apply($(this[0]), tmp_args);
679
+ else
680
+ return this.each(function() {
681
+ var $t = $(this);
682
+ $t.datepicker.apply($t, tmp_args);
683
+ });
684
+ }
685
+ else
686
+ return this.each(function() {
687
+ var $t = $(this);
688
+ $t.datepicker($.timepicker._newInst($t, o)._defaults);
689
+ });
690
+ }
691
+ });
692
+
693
+ //########################################################################
694
+ // the bad hack :/ override datepicker so it doesnt close on select
695
+ // inspired: http://stackoverflow.com/questions/1252512/jquery-datepicker-prevent-closing-picker-when-clicking-a-date/1762378#1762378
696
+ //########################################################################
697
+ $.datepicker._base_selectDate = $.datepicker._selectDate;
698
+ $.datepicker._selectDate = function (id, dateStr) {
699
+ var inst = this._getInst($(id)[0]),
700
+ tp_inst = this._get(inst, 'timepicker');
701
+
702
+ if (tp_inst) {
703
+ tp_inst._limitMinMaxDateTime(inst, true);
704
+ inst.inline = inst.stay_open = true;
705
+ //This way the onSelect handler called from calendarpicker get the full dateTime
706
+ this._base_selectDate(id, dateStr + tp_inst._defaults.separator + tp_inst.formattedTime);
707
+ inst.inline = inst.stay_open = false;
708
+ this._notifyChange(inst);
709
+ this._updateDatepicker(inst);
710
+ }
711
+ else this._base_selectDate(id, dateStr);
712
+ };
713
+
714
+ //#############################################################################################
715
+ // second bad hack :/ override datepicker so it triggers an event when changing the input field
716
+ // and does not redraw the datepicker on every selectDate event
717
+ //#############################################################################################
718
+ $.datepicker._base_updateDatepicker = $.datepicker._updateDatepicker;
719
+ $.datepicker._updateDatepicker = function(inst) {
720
+ if (typeof(inst.stay_open) !== 'boolean' || inst.stay_open === false) {
721
+
722
+ this._base_updateDatepicker(inst);
723
+
724
+ // Reload the time control when changing something in the input text field.
725
+ var tp_inst = this._get(inst, 'timepicker');
726
+ if(tp_inst) tp_inst._addTimePicker(inst);
727
+ }
728
+ };
729
+
730
+ //#######################################################################################
731
+ // third bad hack :/ override datepicker so it allows spaces and colan in the input field
732
+ //#######################################################################################
733
+ $.datepicker._base_doKeyPress = $.datepicker._doKeyPress;
734
+ $.datepicker._doKeyPress = function(event) {
735
+ var inst = $.datepicker._getInst(event.target),
736
+ tp_inst = $.datepicker._get(inst, 'timepicker');
737
+
738
+ if (tp_inst) {
739
+ if ($.datepicker._get(inst, 'constrainInput')) {
740
+ var ampm = tp_inst._defaults.ampm,
741
+ datetimeChars = tp_inst._defaults.timeFormat.toString()
742
+ .replace(/[hms]/g, '')
743
+ .replace(/TT/g, ampm ? 'APM' : '')
744
+ .replace(/T/g, ampm ? 'AP' : '')
745
+ .replace(/tt/g, ampm ? 'apm' : '')
746
+ .replace(/t/g, ampm ? 'ap' : '') +
747
+ " " +
748
+ tp_inst._defaults.separator +
749
+ $.datepicker._possibleChars($.datepicker._get(inst, 'dateFormat')),
750
+ chr = String.fromCharCode(event.charCode === undefined ? event.keyCode : event.charCode);
751
+ return event.ctrlKey || (chr < ' ' || !datetimeChars || datetimeChars.indexOf(chr) > -1);
752
+ }
753
+ }
754
+
755
+ return $.datepicker._base_doKeyPress(event);
756
+ };
757
+
758
+ //#######################################################################################
759
+ // Override key up event to sync manual input changes.
760
+ //#######################################################################################
761
+ $.datepicker._base_doKeyUp = $.datepicker._doKeyUp;
762
+ $.datepicker._doKeyUp = function (event) {
763
+ var inst = $.datepicker._getInst(event.target),
764
+ tp_inst = $.datepicker._get(inst, 'timepicker');
765
+
766
+ if (tp_inst) {
767
+ if (tp_inst._defaults.timeOnly && (inst.input.val() != inst.lastVal)) {
768
+ try {
769
+ $.datepicker._updateDatepicker(inst);
770
+ }
771
+ catch (err) {
772
+ $.datepicker.log(err);
773
+ }
774
+ }
775
+ }
776
+
777
+ return $.datepicker._base_doKeyUp(event);
778
+ };
779
+
780
+ //#######################################################################################
781
+ // override "Today" button to also grab the time.
782
+ //#######################################################################################
783
+ $.datepicker._base_gotoToday = $.datepicker._gotoToday;
784
+ $.datepicker._gotoToday = function(id) {
785
+ this._base_gotoToday(id);
786
+ this._setTime(this._getInst($(id)[0]), new Date());
787
+ };
788
+
789
+ //#######################################################################################
790
+ // Disable & enable the Time in the datetimepicker
791
+ //#######################################################################################
792
+ $.datepicker._disableTimepickerDatepicker = function(target, date, withDate) {
793
+ var inst = this._getInst(target),
794
+ tp_inst = this._get(inst, 'timepicker');
795
+ if (tp_inst) {
796
+ tp_inst._defaults.showTimepicker = false;
797
+ tp_inst._onTimeChange();
798
+ tp_inst._updateDateTime(inst);
799
+ }
800
+ };
801
+
802
+ $.datepicker._enableTimepickerDatepicker = function(target, date, withDate) {
803
+ var inst = this._getInst(target),
804
+ tp_inst = this._get(inst, 'timepicker');
805
+ if (tp_inst) {
806
+ tp_inst._defaults.showTimepicker = true;
807
+ tp_inst._onTimeChange();
808
+ tp_inst._updateDateTime(inst);
809
+ }
810
+ };
811
+
812
+ //#######################################################################################
813
+ // Create our own set time function
814
+ //#######################################################################################
815
+ $.datepicker._setTime = function(inst, date) {
816
+ var tp_inst = this._get(inst, 'timepicker');
817
+ if (tp_inst) {
818
+ var defaults = tp_inst._defaults,
819
+ // calling _setTime with no date sets time to defaults
820
+ hour = date ? date.getHours() : defaults.hour,
821
+ minute = date ? date.getMinutes() : defaults.minute,
822
+ second = date ? date.getSeconds() : defaults.second;
823
+
824
+ //check if within min/max times..
825
+ if ((hour < defaults.hourMin || hour > defaults.hourMax) || (minute < defaults.minuteMin || minute > defaults.minuteMax) || (second < defaults.secondMin || second > defaults.secondMax)) {
826
+ hour = defaults.hourMin;
827
+ minute = defaults.minuteMin;
828
+ second = defaults.secondMin;
829
+ }
830
+
831
+ if (tp_inst.hour_slider) tp_inst.hour_slider.slider('value', hour);
832
+ else tp_inst.hour = hour;
833
+ if (tp_inst.minute_slider) tp_inst.minute_slider.slider('value', minute);
834
+ else tp_inst.minute = minute;
835
+ if (tp_inst.second_slider) tp_inst.second_slider.slider('value', second);
836
+ else tp_inst.second = second;
837
+
838
+ tp_inst._onTimeChange();
839
+ tp_inst._updateDateTime(inst);
840
+ }
841
+ };
842
+
843
+ //#######################################################################################
844
+ // Create new public method to set only time, callable as $().datepicker('setTime', date)
845
+ //#######################################################################################
846
+ $.datepicker._setTimeDatepicker = function(target, date, withDate) {
847
+ var inst = this._getInst(target),
848
+ tp_inst = this._get(inst, 'timepicker');
849
+
850
+ if (tp_inst) {
851
+ this._setDateFromField(inst);
852
+ var tp_date;
853
+ if (date) {
854
+ if (typeof date == "string") {
855
+ tp_inst._parseTime(date, withDate);
856
+ tp_date = new Date();
857
+ tp_date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second);
858
+ }
859
+ else tp_date = new Date(date.getTime());
860
+ if (tp_date.toString() == 'Invalid Date') tp_date = undefined;
861
+ }
862
+ this._setTime(inst, tp_date);
863
+ }
864
+
865
+ };
866
+
867
+ //#######################################################################################
868
+ // override setDate() to allow setting time too within Date object
869
+ //#######################################################################################
870
+ $.datepicker._base_setDateDatepicker = $.datepicker._setDateDatepicker;
871
+ $.datepicker._setDateDatepicker = function(target, date) {
872
+ var inst = this._getInst(target),
873
+ tp_date = (date instanceof Date) ? new Date(date.getTime()) : date;
874
+
875
+ this._updateDatepicker(inst);
876
+ this._base_setDateDatepicker.apply(this, arguments);
877
+ this._setTimeDatepicker(target, tp_date, true);
878
+ };
879
+
880
+ //#######################################################################################
881
+ // override getDate() to allow getting time too within Date object
882
+ //#######################################################################################
883
+ $.datepicker._base_getDateDatepicker = $.datepicker._getDateDatepicker;
884
+ $.datepicker._getDateDatepicker = function(target, noDefault) {
885
+ var inst = this._getInst(target),
886
+ tp_inst = this._get(inst, 'timepicker');
887
+
888
+ if (tp_inst) {
889
+ this._setDateFromField(inst, noDefault);
890
+ var date = this._getDate(inst);
891
+ if (date && tp_inst._parseTime($(target).val(), true)) date.setHours(tp_inst.hour, tp_inst.minute, tp_inst.second);
892
+ return date;
893
+ }
894
+ return this._base_getDateDatepicker(target, noDefault);
895
+ };
896
+
897
+ //#######################################################################################
898
+ // jQuery extend now ignores nulls!
899
+ //#######################################################################################
900
+ function extendRemove(target, props) {
901
+ $.extend(target, props);
902
+ for (var name in props)
903
+ if (props[name] === null || props[name] === undefined)
904
+ target[name] = props[name];
905
+ return target;
906
+ }
907
+
908
+ $.timepicker = new Timepicker(); // singleton instance
909
+ $.timepicker.version = "0.9.3";
910
+
911
+ })(jQuery);