undercase 0.2.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (407) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +70 -0
  3. data/Rakefile +21 -0
  4. data/app/assets/fonts/FontAwesome/FontAwesome.otf +0 -0
  5. data/app/assets/fonts/FontAwesome/fontawesome-webfont.eot +0 -0
  6. data/app/assets/fonts/FontAwesome/fontawesome-webfont.svg +414 -0
  7. data/app/assets/fonts/FontAwesome/fontawesome-webfont.ttf +0 -0
  8. data/app/assets/fonts/FontAwesome/fontawesome-webfont.woff +0 -0
  9. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-black-webfont.eot +0 -0
  10. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-black-webfont.svg +914 -0
  11. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-black-webfont.ttf +0 -0
  12. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-black-webfont.woff +0 -0
  13. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-blackit-webfont.eot +0 -0
  14. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-blackit-webfont.svg +812 -0
  15. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-blackit-webfont.ttf +0 -0
  16. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-blackit-webfont.woff +0 -0
  17. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-bold-webfont.eot +0 -0
  18. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-bold-webfont.svg +955 -0
  19. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-bold-webfont.ttf +0 -0
  20. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-bold-webfont.woff +0 -0
  21. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-boldit-webfont.eot +0 -0
  22. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-boldit-webfont.svg +831 -0
  23. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-boldit-webfont.ttf +0 -0
  24. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-boldit-webfont.woff +0 -0
  25. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-extralight-webfont.eot +0 -0
  26. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-extralight-webfont.svg +905 -0
  27. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-extralight-webfont.ttf +0 -0
  28. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-extralight-webfont.woff +0 -0
  29. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-extralightit-webfont.eot +0 -0
  30. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-extralightit-webfont.svg +828 -0
  31. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-extralightit-webfont.ttf +0 -0
  32. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-extralightit-webfont.woff +0 -0
  33. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-it-webfont.eot +0 -0
  34. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-it-webfont.svg +843 -0
  35. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-it-webfont.ttf +0 -0
  36. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-it-webfont.woff +0 -0
  37. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  38. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +904 -0
  39. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  40. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  41. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-lightit-webfont.eot +0 -0
  42. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-lightit-webfont.svg +830 -0
  43. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-lightit-webfont.ttf +0 -0
  44. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-lightit-webfont.woff +0 -0
  45. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  46. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +978 -0
  47. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  48. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  49. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-semibold-webfont.eot +0 -0
  50. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-semibold-webfont.svg +968 -0
  51. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-semibold-webfont.ttf +0 -0
  52. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-semibold-webfont.woff +0 -0
  53. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-semiboldit-webfont.eot +0 -0
  54. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-semiboldit-webfont.svg +838 -0
  55. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-semiboldit-webfont.ttf +0 -0
  56. data/app/assets/fonts/Source-Sans-Pro/sourcesanspro-semiboldit-webfont.woff +0 -0
  57. data/app/assets/fonts/Undercase-Icons/Undercase-Icons.eot +0 -0
  58. data/app/assets/fonts/Undercase-Icons/Undercase-Icons.svg +72 -0
  59. data/app/assets/fonts/Undercase-Icons/Undercase-Icons.ttf +0 -0
  60. data/app/assets/fonts/Undercase-Icons/Undercase-Icons.woff +0 -0
  61. data/app/assets/images/avatar_male_small.png +0 -0
  62. data/app/assets/images/backgrounds/checkerboard_tile.png +0 -0
  63. data/app/assets/images/icons/calendar_datepicker.svg +18 -0
  64. data/app/assets/images/icons/checkbox-selected.svg +17 -0
  65. data/app/assets/images/icons/checkbox-unselected.svg +12 -0
  66. data/app/assets/images/icons/double-arrow-left.svg +13 -0
  67. data/app/assets/images/icons/double-arrow-right.svg +13 -0
  68. data/app/assets/images/icons/focus-child.svg +14 -0
  69. data/app/assets/images/icons/master-profile.svg +11 -0
  70. data/app/assets/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  71. data/app/assets/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  72. data/app/assets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  73. data/app/assets/images/ui-bg_flat_100_b8b8b8_40x100.png +0 -0
  74. data/app/assets/images/ui-bg_flat_10_000000_40x100.png +0 -0
  75. data/app/assets/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  76. data/app/assets/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  77. data/app/assets/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  78. data/app/assets/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  79. data/app/assets/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  80. data/app/assets/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  81. data/app/assets/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  82. data/app/assets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  83. data/app/assets/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  84. data/app/assets/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  85. data/app/assets/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  86. data/app/assets/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  87. data/app/assets/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  88. data/app/assets/images/ui-icons_222222_256x240.png +0 -0
  89. data/app/assets/images/ui-icons_228ef1_256x240.png +0 -0
  90. data/app/assets/images/ui-icons_2e83ff_256x240.png +0 -0
  91. data/app/assets/images/ui-icons_454545_256x240.png +0 -0
  92. data/app/assets/images/ui-icons_888888_256x240.png +0 -0
  93. data/app/assets/images/ui-icons_cd0a0a_256x240.png +0 -0
  94. data/app/assets/images/ui-icons_ef8c08_256x240.png +0 -0
  95. data/app/assets/images/ui-icons_ffd27a_256x240.png +0 -0
  96. data/app/assets/images/ui-icons_ffffff_256x240.png +0 -0
  97. data/app/assets/images/undercase/undercase_gem_logo.png +0 -0
  98. data/app/assets/javascripts/undercase/index.js +19 -0
  99. data/app/assets/javascripts/undercase/lib/BreakpointTell.js +9 -0
  100. data/app/assets/javascripts/undercase/lib/timezone.js +28 -0
  101. data/app/assets/javascripts/undercase/patterns/Filter.js +75 -0
  102. data/app/assets/javascripts/undercase/patterns/FlexibleSearchMenu.js +64 -0
  103. data/app/assets/javascripts/undercase/patterns/ToggleNavigationSearch.js +60 -0
  104. data/app/assets/javascripts/undercase/patterns/datepicker.js +36 -0
  105. data/app/assets/javascripts/undercase/patterns/expando.js +39 -0
  106. data/app/assets/javascripts/undercase/patterns/modal.js +60 -0
  107. data/app/assets/javascripts/undercase/patterns/tabs.js +26 -0
  108. data/app/assets/javascripts/undercase/patterns/timepicker.js +5 -0
  109. data/app/assets/javascripts/undercase/popover.js +26 -0
  110. data/app/assets/javascripts/undercase/presenter.js +55 -0
  111. data/app/assets/javascripts/undercase/show_code.js +35 -0
  112. data/app/assets/javascripts/undercase/vendor/date.js +879 -0
  113. data/app/assets/javascripts/undercase/vendor/jquery-extensions/jquery.calendrical.js +517 -0
  114. data/app/assets/javascripts/undercase/vendor/jquery-ui-1.10.3.js +14972 -0
  115. data/app/assets/javascripts/undercase/vendor/modernizr.custom.14960.js +764 -0
  116. data/app/assets/javascripts/undercase/vendor/underscore.js +1189 -0
  117. data/app/assets/stylesheets/undercase/libraries/_all.scss +38 -0
  118. data/app/assets/stylesheets/undercase/libraries/_borders.scss +20 -0
  119. data/app/assets/stylesheets/undercase/libraries/_colors.scss +41 -0
  120. data/app/assets/stylesheets/undercase/libraries/_constants.scss +76 -0
  121. data/app/assets/stylesheets/undercase/libraries/_groundwork_settings.scss +351 -0
  122. data/app/assets/stylesheets/undercase/libraries/_icon_codes.scss +369 -0
  123. data/app/assets/stylesheets/undercase/libraries/_mixins.scss +49 -0
  124. data/app/assets/stylesheets/undercase/libraries/mixins/_button.scss +124 -0
  125. data/app/assets/stylesheets/undercase/libraries/mixins/_forms.scss +33 -0
  126. data/app/assets/stylesheets/undercase/libraries/mixins/_layout.scss +23 -0
  127. data/app/assets/stylesheets/undercase/libraries/mixins/_typography.scss +99 -0
  128. data/app/assets/stylesheets/undercase/patterns/_all.scss +32 -0
  129. data/app/assets/stylesheets/undercase/patterns/_borders.scss +89 -0
  130. data/app/assets/stylesheets/undercase/patterns/_box_helpers.scss +39 -0
  131. data/app/assets/stylesheets/undercase/patterns/_buttons.scss +110 -0
  132. data/app/assets/stylesheets/undercase/patterns/_cards.scss +36 -0
  133. data/app/assets/stylesheets/undercase/patterns/_chevrons.scss +98 -0
  134. data/app/assets/stylesheets/undercase/patterns/_colors.scss +34 -0
  135. data/app/assets/stylesheets/undercase/patterns/_content_with_toolbar.scss +23 -0
  136. data/app/assets/stylesheets/undercase/patterns/_dropdowns.scss +49 -0
  137. data/app/assets/stylesheets/undercase/patterns/_filters.scss +121 -0
  138. data/app/assets/stylesheets/undercase/patterns/_font_faces.scss +32 -0
  139. data/app/assets/stylesheets/undercase/patterns/_forms.scss +617 -0
  140. data/app/assets/stylesheets/undercase/patterns/_horizontal_rules.scss +5 -0
  141. data/app/assets/stylesheets/undercase/patterns/_icons.scss +4 -0
  142. data/app/assets/stylesheets/undercase/patterns/_inline_message.scss +36 -0
  143. data/app/assets/stylesheets/undercase/patterns/_layout.scss +57 -0
  144. data/app/assets/stylesheets/undercase/patterns/_length_of_time.scss +10 -0
  145. data/app/assets/stylesheets/undercase/patterns/_links.scss +96 -0
  146. data/app/assets/stylesheets/undercase/patterns/_lists.scss +84 -0
  147. data/app/assets/stylesheets/undercase/patterns/_media.scss +15 -0
  148. data/app/assets/stylesheets/undercase/patterns/_modals.scss +114 -0
  149. data/app/assets/stylesheets/undercase/patterns/_navigation.scss +224 -0
  150. data/app/assets/stylesheets/undercase/patterns/_pagination.scss +33 -0
  151. data/app/assets/stylesheets/undercase/patterns/_person_placard.scss +52 -0
  152. data/app/assets/stylesheets/undercase/patterns/_popovers.scss +12 -0
  153. data/app/assets/stylesheets/undercase/patterns/_quiz.scss +67 -0
  154. data/app/assets/stylesheets/undercase/patterns/_site.scss +95 -0
  155. data/app/assets/stylesheets/undercase/patterns/_spinners.scss +23 -0
  156. data/app/assets/stylesheets/undercase/patterns/_tables.scss +111 -0
  157. data/app/assets/stylesheets/undercase/patterns/_tabs.scss +56 -0
  158. data/app/assets/stylesheets/undercase/patterns/_typography.scss +231 -0
  159. data/app/assets/stylesheets/undercase/patterns/undercase_icons/glyphs.scss +28 -0
  160. data/app/assets/stylesheets/undercase/patterns_new_front_end/_all.scss +6 -0
  161. data/app/assets/stylesheets/undercase/patterns_new_front_end/_cards.scss +248 -0
  162. data/app/assets/stylesheets/undercase/patterns_new_front_end/_links.scss +10 -0
  163. data/app/assets/stylesheets/undercase/patterns_new_front_end/_warnings.scss +32 -0
  164. data/app/assets/stylesheets/undercase/vendor_static/_all.scss +12 -0
  165. data/app/assets/stylesheets/undercase/vendor_static/_calendrical.scss +105 -0
  166. data/app/assets/stylesheets/undercase/vendor_static/_icons.scss +422 -0
  167. data/app/assets/stylesheets/undercase/vendor_static/_jquery-ui-1.8.13.custom.scss +615 -0
  168. data/app/assets/stylesheets/undercase_frame/_dummy_site.scss +307 -0
  169. data/app/assets/stylesheets/undercase_frame/vendor/coderay.css +118 -0
  170. data/app/assets/stylesheets/undercase_frame_application.css.scss +18 -0
  171. data/app/assets/stylesheets/undercase_frame_vendor_static.scss +4 -0
  172. data/app/controllers/undercase/application_controller.rb +4 -0
  173. data/app/controllers/undercase/patterns_controller.rb +13 -0
  174. data/app/helpers/undercase/application_helper.rb +86 -0
  175. data/app/helpers/undercase/pattern_helper.rb +7 -0
  176. data/app/inputs/currency_input.rb +20 -0
  177. data/app/inputs/date_picker_input.rb +77 -0
  178. data/app/inputs/date_time_picker_input.rb +141 -0
  179. data/app/inputs/radio_as_accessible_input.rb +33 -0
  180. data/app/inputs/radio_with_clear_input.rb +41 -0
  181. data/app/models/dummy_form_object.rb +24 -0
  182. data/app/views/layouts/undercase/application.html.haml +49 -0
  183. data/app/views/undercase/patterns/_blue_dotted_link_caps.html.haml +2 -0
  184. data/app/views/undercase/patterns/_blue_link.html.haml +2 -0
  185. data/app/views/undercase/patterns/_blue_link_clean.html.haml +2 -0
  186. data/app/views/undercase/patterns/_cc_button_auto.html.haml +8 -0
  187. data/app/views/undercase/patterns/_cc_button_flat_blue.html.haml +2 -0
  188. data/app/views/undercase/patterns/_cc_button_flat_gray.html.haml +7 -0
  189. data/app/views/undercase/patterns/_cc_button_flat_gray_split.html.haml +4 -0
  190. data/app/views/undercase/patterns/_cc_button_flat_green.html.haml +2 -0
  191. data/app/views/undercase/patterns/_cc_button_gray.html.haml +1 -0
  192. data/app/views/undercase/patterns/_cc_button_icon.html.haml +2 -0
  193. data/app/views/undercase/patterns/_cc_button_wire_auto.html.haml +8 -0
  194. data/app/views/undercase/patterns/_cc_link_smartbar.html.haml +2 -0
  195. data/app/views/undercase/patterns/_chevrons.html.haml +38 -0
  196. data/app/views/undercase/patterns/_colors.html.haml +12 -0
  197. data/app/views/undercase/patterns/_content_with_toolbar.html.haml +6 -0
  198. data/app/views/undercase/patterns/_dropdown.html.haml +21 -0
  199. data/app/views/undercase/patterns/_filters.html.haml +210 -0
  200. data/app/views/undercase/patterns/_filters_show_only.html.haml +77 -0
  201. data/app/views/undercase/patterns/_gray_link.html.haml +2 -0
  202. data/app/views/undercase/patterns/_grid.html.haml +0 -0
  203. data/app/views/undercase/patterns/_icon_classes.html.haml +8 -0
  204. data/app/views/undercase/patterns/_icon_custom.html.haml +12 -0
  205. data/app/views/undercase/patterns/_inline_message.html.haml +5 -0
  206. data/app/views/undercase/patterns/_length_of_time.html.haml +12 -0
  207. data/app/views/undercase/patterns/_list_circle.html.haml +4 -0
  208. data/app/views/undercase/patterns/_list_disc.html.haml +4 -0
  209. data/app/views/undercase/patterns/_navigation.html.haml +40 -0
  210. data/app/views/undercase/patterns/_pagination.html.haml +17 -0
  211. data/app/views/undercase/patterns/_pattern.html.haml +27 -0
  212. data/app/views/undercase/patterns/_person_placard.html.haml +103 -0
  213. data/app/views/undercase/patterns/_popover.html.haml +9 -0
  214. data/app/views/undercase/patterns/_tables_mobile.html.haml +23 -0
  215. data/app/views/undercase/patterns/_tables_not_desktop.html.haml +21 -0
  216. data/app/views/undercase/patterns/_tables_small_mobile.html.haml +23 -0
  217. data/app/views/undercase/patterns/_tables_small_tablet.html.haml +25 -0
  218. data/app/views/undercase/patterns/_typography.html.haml +16 -0
  219. data/app/views/undercase/patterns/_typography_body_em.html.haml +1 -0
  220. data/app/views/undercase/patterns/_typography_body_p.html.haml +1 -0
  221. data/app/views/undercase/patterns/_typography_body_strong.html.haml +1 -0
  222. data/app/views/undercase/patterns/_typography_body_thin.html.haml +1 -0
  223. data/app/views/undercase/patterns/_typography_body_underline.html.haml +1 -0
  224. data/app/views/undercase/patterns/_typography_body_uppercase.html.haml +1 -0
  225. data/app/views/undercase/patterns/_typography_heading_1.html.haml +1 -0
  226. data/app/views/undercase/patterns/_typography_heading_2.html.haml +1 -0
  227. data/app/views/undercase/patterns/_typography_heading_3.html.haml +1 -0
  228. data/app/views/undercase/patterns/_typography_heading_4.html.haml +1 -0
  229. data/app/views/undercase/patterns/_typography_heading_thin.html.haml +1 -0
  230. data/app/views/undercase/patterns/_typography_links_general.html.haml +2 -0
  231. data/app/views/undercase/patterns/_typography_links_navigation.html.haml +2 -0
  232. data/app/views/undercase/patterns/_typography_links_page_banner.html.haml +2 -0
  233. data/app/views/undercase/patterns/_uc_borders_blue.html.haml +2 -0
  234. data/app/views/undercase/patterns/_uc_borders_gray.html.haml +2 -0
  235. data/app/views/undercase/patterns/_uc_borders_hover_blue.html.haml +3 -0
  236. data/app/views/undercase/patterns/_uc_borders_left.html.haml +4 -0
  237. data/app/views/undercase/patterns/_uc_borders_lighter_gray.html.haml +3 -0
  238. data/app/views/undercase/patterns/_uc_borders_middle_blue_2.html.haml +1 -0
  239. data/app/views/undercase/patterns/_uc_borders_middle_gray.html.haml +2 -0
  240. data/app/views/undercase/patterns/_uc_borders_yellow.html.haml +1 -0
  241. data/app/views/undercase/patterns/_uc_card.html.haml +40 -0
  242. data/app/views/undercase/patterns/_uc_dialog_loading.html.haml +2 -0
  243. data/app/views/undercase/patterns/_uc_errors.html.haml +1 -0
  244. data/app/views/undercase/patterns/_uc_forms_check_boxes.html.haml +7 -0
  245. data/app/views/undercase/patterns/_uc_forms_check_boxes_boolean.html.haml +20 -0
  246. data/app/views/undercase/patterns/_uc_forms_checkbutton.html.haml +14 -0
  247. data/app/views/undercase/patterns/_uc_forms_conditionally_required.html.haml +19 -0
  248. data/app/views/undercase/patterns/_uc_forms_currency_input.html.haml +7 -0
  249. data/app/views/undercase/patterns/_uc_forms_date_picker.html.haml +9 -0
  250. data/app/views/undercase/patterns/_uc_forms_date_time_picker.html.haml +9 -0
  251. data/app/views/undercase/patterns/_uc_forms_disabled_field.html.haml +8 -0
  252. data/app/views/undercase/patterns/_uc_forms_dropdown.html.haml +10 -0
  253. data/app/views/undercase/patterns/_uc_forms_dropdown_with_optgroups.html.haml +10 -0
  254. data/app/views/undercase/patterns/_uc_forms_full_name.html.haml +32 -0
  255. data/app/views/undercase/patterns/_uc_forms_grouped_inputs.html.haml +17 -0
  256. data/app/views/undercase/patterns/_uc_forms_large_field.html.haml +8 -0
  257. data/app/views/undercase/patterns/_uc_forms_medium_field.html.haml +8 -0
  258. data/app/views/undercase/patterns/_uc_forms_phone.html.haml +26 -0
  259. data/app/views/undercase/patterns/_uc_forms_radio_button_clear_link.html.haml +7 -0
  260. data/app/views/undercase/patterns/_uc_forms_radio_buttons.html.haml +7 -0
  261. data/app/views/undercase/patterns/_uc_forms_radio_buttons_breathe.html.haml +11 -0
  262. data/app/views/undercase/patterns/_uc_forms_radio_buttons_horizontal.html.haml +11 -0
  263. data/app/views/undercase/patterns/_uc_forms_search.html.haml +23 -0
  264. data/app/views/undercase/patterns/_uc_forms_short_name.html.haml +20 -0
  265. data/app/views/undercase/patterns/_uc_forms_small_field.html.haml +8 -0
  266. data/app/views/undercase/patterns/_uc_forms_textarea.html.haml +9 -0
  267. data/app/views/undercase/patterns/_uc_forms_tiny_field.html.haml +8 -0
  268. data/app/views/undercase/patterns/_uc_list_comma.html.haml +4 -0
  269. data/app/views/undercase/patterns/_uc_list_ordered_alpha.html.haml +12 -0
  270. data/app/views/undercase/patterns/_uc_list_ordered_decimal.html.haml +12 -0
  271. data/app/views/undercase/patterns/_uc_list_pipe.html.haml +4 -0
  272. data/app/views/undercase/patterns/_uc_media.html.haml +6 -0
  273. data/app/views/undercase/patterns/_uc_modal_basic.html.haml +28 -0
  274. data/app/views/undercase/patterns/_uc_modal_exception.html.haml +34 -0
  275. data/app/views/undercase/patterns/_uc_modal_with_linked.html.haml +37 -0
  276. data/app/views/undercase/patterns/_uc_quiz_questions.html.haml +12 -0
  277. data/app/views/undercase/patterns/_uc_tabs.html.haml +16 -0
  278. data/app/views/undercase/patterns/index.html.haml +48 -0
  279. data/app/views/undercase/patterns/show.html.haml +7 -0
  280. data/app/views/undercase/popups/_dropdown.html.haml +5 -0
  281. data/config/initializers/dotiw.rb +1 -0
  282. data/config/initializers/simple_form.rb +147 -0
  283. data/config/routes.rb +4 -0
  284. data/config/tddium.yml +17 -0
  285. data/config/undercase-icons-regular.yml +41 -0
  286. data/lib/tasks/undercase.rake +51 -0
  287. data/lib/undercase.rb +15 -0
  288. data/lib/undercase/categories.yml +12 -0
  289. data/lib/undercase/category.rb +20 -0
  290. data/lib/undercase/engine.rb +13 -0
  291. data/lib/undercase/pattern.rb +68 -0
  292. data/lib/undercase/patterns/blue_dotted_link_caps.yml +4 -0
  293. data/lib/undercase/patterns/blue_link.yml +4 -0
  294. data/lib/undercase/patterns/blue_link_clean.yml +4 -0
  295. data/lib/undercase/patterns/cc_button_auto.yml +4 -0
  296. data/lib/undercase/patterns/cc_button_flat_blue.yml +4 -0
  297. data/lib/undercase/patterns/cc_button_flat_gray.yml +4 -0
  298. data/lib/undercase/patterns/cc_button_flat_gray_split.yml +9 -0
  299. data/lib/undercase/patterns/cc_button_flat_green.yml +27 -0
  300. data/lib/undercase/patterns/cc_button_gray.yml +4 -0
  301. data/lib/undercase/patterns/cc_button_icon.yml +4 -0
  302. data/lib/undercase/patterns/cc_button_wire_auto.yml +5 -0
  303. data/lib/undercase/patterns/cc_link_smartbar.yml +4 -0
  304. data/lib/undercase/patterns/chevrons.yml +4 -0
  305. data/lib/undercase/patterns/colors.yml +5 -0
  306. data/lib/undercase/patterns/content_with_toolbar.yml +4 -0
  307. data/lib/undercase/patterns/dropdown.yml +4 -0
  308. data/lib/undercase/patterns/filters.yml +5 -0
  309. data/lib/undercase/patterns/filters_show_only.yml +5 -0
  310. data/lib/undercase/patterns/gray_link.yml +4 -0
  311. data/lib/undercase/patterns/grid.yml +4 -0
  312. data/lib/undercase/patterns/icon_classes.yml +5 -0
  313. data/lib/undercase/patterns/icon_custom.yml +4 -0
  314. data/lib/undercase/patterns/inline_message.yml +4 -0
  315. data/lib/undercase/patterns/length_of_time.yml +4 -0
  316. data/lib/undercase/patterns/list_circle.yml +4 -0
  317. data/lib/undercase/patterns/list_disc.yml +4 -0
  318. data/lib/undercase/patterns/navigation.yml +4 -0
  319. data/lib/undercase/patterns/pagination.yml +4 -0
  320. data/lib/undercase/patterns/person_placard.yml +4 -0
  321. data/lib/undercase/patterns/popover.yml +4 -0
  322. data/lib/undercase/patterns/tables_mobile.yml +4 -0
  323. data/lib/undercase/patterns/tables_not_desktop.yml +4 -0
  324. data/lib/undercase/patterns/tables_small_tablet.yml +4 -0
  325. data/lib/undercase/patterns/typography.yml +4 -0
  326. data/lib/undercase/patterns/typography_body_em.yml +4 -0
  327. data/lib/undercase/patterns/typography_body_p.yml +4 -0
  328. data/lib/undercase/patterns/typography_body_strong.yml +4 -0
  329. data/lib/undercase/patterns/typography_body_thin.yml +4 -0
  330. data/lib/undercase/patterns/typography_body_underline.yml +4 -0
  331. data/lib/undercase/patterns/typography_body_uppercase.yml +4 -0
  332. data/lib/undercase/patterns/typography_heading_1.yml +4 -0
  333. data/lib/undercase/patterns/typography_heading_2.yml +4 -0
  334. data/lib/undercase/patterns/typography_heading_3.yml +4 -0
  335. data/lib/undercase/patterns/typography_heading_4.yml +4 -0
  336. data/lib/undercase/patterns/typography_heading_thin.yml +4 -0
  337. data/lib/undercase/patterns/typography_links_general.yml +4 -0
  338. data/lib/undercase/patterns/typography_links_navigation.yml +4 -0
  339. data/lib/undercase/patterns/typography_links_page_banner.yml +4 -0
  340. data/lib/undercase/patterns/uc_borders_blue.yml +4 -0
  341. data/lib/undercase/patterns/uc_borders_gray.yml +4 -0
  342. data/lib/undercase/patterns/uc_borders_hover_blue.yml +4 -0
  343. data/lib/undercase/patterns/uc_borders_left.yml +4 -0
  344. data/lib/undercase/patterns/uc_borders_lighter_gray.yml +4 -0
  345. data/lib/undercase/patterns/uc_borders_middle_blue_2.yml +4 -0
  346. data/lib/undercase/patterns/uc_borders_middle_gray.yml +4 -0
  347. data/lib/undercase/patterns/uc_borders_yellow.yml +4 -0
  348. data/lib/undercase/patterns/uc_card.yml +5 -0
  349. data/lib/undercase/patterns/uc_dialog_loading.yml +4 -0
  350. data/lib/undercase/patterns/uc_errors.yml +5 -0
  351. data/lib/undercase/patterns/uc_forms_check_boxes.yml +4 -0
  352. data/lib/undercase/patterns/uc_forms_check_boxes_boolean.yml +4 -0
  353. data/lib/undercase/patterns/uc_forms_checkbutton.yml +4 -0
  354. data/lib/undercase/patterns/uc_forms_conditionally_required.yml +4 -0
  355. data/lib/undercase/patterns/uc_forms_currency_input.yml +4 -0
  356. data/lib/undercase/patterns/uc_forms_date_picker.yml +4 -0
  357. data/lib/undercase/patterns/uc_forms_date_time_picker.yml +4 -0
  358. data/lib/undercase/patterns/uc_forms_disabled_field.yml +4 -0
  359. data/lib/undercase/patterns/uc_forms_dropdown.yml +4 -0
  360. data/lib/undercase/patterns/uc_forms_dropdown_with_optgroups.yml +4 -0
  361. data/lib/undercase/patterns/uc_forms_full_name.yml +4 -0
  362. data/lib/undercase/patterns/uc_forms_grouped_inputs.yml +4 -0
  363. data/lib/undercase/patterns/uc_forms_large_field.yml +4 -0
  364. data/lib/undercase/patterns/uc_forms_medium_field.yml +4 -0
  365. data/lib/undercase/patterns/uc_forms_phone.yml +4 -0
  366. data/lib/undercase/patterns/uc_forms_radio_button_clear_link.yml +4 -0
  367. data/lib/undercase/patterns/uc_forms_radio_buttons.yml +4 -0
  368. data/lib/undercase/patterns/uc_forms_radio_buttons_breathe.yml +4 -0
  369. data/lib/undercase/patterns/uc_forms_radio_buttons_horizontal.yml +4 -0
  370. data/lib/undercase/patterns/uc_forms_search.yml +4 -0
  371. data/lib/undercase/patterns/uc_forms_short_name.yml +4 -0
  372. data/lib/undercase/patterns/uc_forms_small_field.yml +4 -0
  373. data/lib/undercase/patterns/uc_forms_textarea.yml +4 -0
  374. data/lib/undercase/patterns/uc_forms_tiny_field.yml +4 -0
  375. data/lib/undercase/patterns/uc_list_comma.yml +4 -0
  376. data/lib/undercase/patterns/uc_list_ordered_alpha.yml +4 -0
  377. data/lib/undercase/patterns/uc_list_ordered_decimal.yml +4 -0
  378. data/lib/undercase/patterns/uc_list_pipe.yml +4 -0
  379. data/lib/undercase/patterns/uc_media.yml +4 -0
  380. data/lib/undercase/patterns/uc_modal_basic.yml +4 -0
  381. data/lib/undercase/patterns/uc_modal_exception.yml +4 -0
  382. data/lib/undercase/patterns/uc_modal_with_linked.yml +4 -0
  383. data/lib/undercase/patterns/uc_quiz_questions.yml +4 -0
  384. data/lib/undercase/patterns/uc_tabs.yml +4 -0
  385. data/lib/undercase/templates/fontcustom/glyphs.scss +6 -0
  386. data/lib/undercase/version.rb +3 -0
  387. data/public/timezones/Makefile +523 -0
  388. data/public/timezones/africa +1194 -0
  389. data/public/timezones/antarctica +411 -0
  390. data/public/timezones/asia +2751 -0
  391. data/public/timezones/australasia +1726 -0
  392. data/public/timezones/backward +117 -0
  393. data/public/timezones/etcetera +81 -0
  394. data/public/timezones/europe +2973 -0
  395. data/public/timezones/factory +10 -0
  396. data/public/timezones/iso3166.tab +276 -0
  397. data/public/timezones/leapseconds +100 -0
  398. data/public/timezones/northamerica +3254 -0
  399. data/public/timezones/pacificnew +28 -0
  400. data/public/timezones/solar87 +390 -0
  401. data/public/timezones/solar88 +390 -0
  402. data/public/timezones/solar89 +395 -0
  403. data/public/timezones/southamerica +1718 -0
  404. data/public/timezones/systemv +38 -0
  405. data/public/timezones/yearistype.sh +38 -0
  406. data/public/timezones/zone.tab +444 -0
  407. metadata +789 -0
@@ -0,0 +1,60 @@
1
+ (function($, ns) {
2
+ $(document).on('ToggleNavigationSearch:present', function(event) {
3
+ var $element = $(event.target);
4
+ var $navigationMenu = $('.js-navigation-menu', $element);
5
+ var $navigationSearch = $('.js-navigation-search', $element);
6
+ var $toggleSearchTrigger = $('.js-toggle-search-trigger', $element);
7
+ var $toggleMenuTrigger = $('.js-toggle-menu-trigger', $element);
8
+
9
+ var toggleNavigationSearch = {
10
+
11
+ init: function() {
12
+ if (window.undercase.BreakpointTell.isMobile()) {
13
+ toggleNavigationSearch.showMenu();
14
+ }
15
+ this.bind();
16
+ },
17
+
18
+ bind: function() {
19
+ $toggleSearchTrigger.on('click', function(event) {
20
+ event.preventDefault();
21
+ toggleNavigationSearch.showSearch();
22
+ });
23
+
24
+ $toggleMenuTrigger.on('click', function(event) {
25
+ event.preventDefault();
26
+ toggleNavigationSearch.showMenu();
27
+ });
28
+ $(window).on('resize', function() {
29
+ if(window.undercase.BreakpointTell.isMobile()) {
30
+ if ($navigationMenu.is(':visible')) {
31
+ toggleNavigationSearch.showMenu();
32
+ } else {
33
+ toggleNavigationSearch.showSearch();
34
+ }
35
+ } else {
36
+ toggleNavigationSearch.showSearchAndMenu();
37
+ }
38
+ });
39
+ },
40
+
41
+ showSearch: function() {
42
+ $navigationSearch.show();
43
+ $navigationMenu.hide();
44
+ },
45
+
46
+ showMenu: function() {
47
+ $navigationMenu.show();
48
+ $navigationSearch.hide();
49
+ },
50
+
51
+ showSearchAndMenu: function() {
52
+ $navigationMenu.show();
53
+ $navigationSearch.show();
54
+ }
55
+ }
56
+
57
+ toggleNavigationSearch.init();
58
+
59
+ });
60
+ })(jQuery);
@@ -0,0 +1,36 @@
1
+ (function($) {
2
+ function setLabel($input) {
3
+ timezoneJS.casebook.getTimezoneAbbreviation($input.val(), function(timezoneAbbreviation) {
4
+ $input.parent().siblings('.js-timezone').text(timezoneAbbreviation);
5
+ });
6
+ }
7
+
8
+ $(document).on('datepicker:present', function(event) {
9
+ var $target = $(event.target);
10
+ var args = {};
11
+ args.defaultDate = '0';
12
+ args.numberOfMonths = 2;
13
+ args.showCurrentAtPos = 1;
14
+ args.onSelect = function(dateText, inst) {
15
+ $target.trigger('change');
16
+ $target.focus();
17
+ };
18
+ args.minDate = $target.attr('min-date');
19
+ args.maxDate = $target.attr('max-date');
20
+ if ($target.attr('disable-future-dates') === "true") {
21
+ args.maxDate = '0';
22
+ }
23
+ $target.datepicker(args);
24
+
25
+ $target.change(function() {
26
+ setLabel($target);
27
+ });
28
+
29
+ $target.keydown(function() {
30
+ $target.datepicker("hide");
31
+ });
32
+
33
+ var dateValue = $target.val();
34
+ if(dateValue) { setLabel($target); }
35
+ });
36
+ })(jQuery);
@@ -0,0 +1,39 @@
1
+ (function($) {
2
+ $(document).on('expando:present', function(event){
3
+ var expando = $(event.target);
4
+ var expando_elem = expando.find(".js-expando-elem").first();
5
+
6
+ function toggleAriaExpanded() {
7
+ var ariaExpanded = "false";
8
+ if (expando.hasClass("open")) {
9
+ ariaExpanded = "true";
10
+ }
11
+ expando_elem.attr("aria-expanded", ariaExpanded);
12
+ }
13
+
14
+ function toggleExpando() {
15
+ expando.toggleClass("open");
16
+ toggleAriaExpanded();
17
+ return true;
18
+ }
19
+
20
+ function expandExpando(){
21
+ if(!expando.hasClass('open')) {
22
+ toggleExpando();
23
+ }
24
+ }
25
+
26
+ expando_elem.attr("tabindex",0);
27
+ toggleAriaExpanded();
28
+
29
+ expando.bind("expandFilters", expandExpando);
30
+ expando_elem.bind("click", toggleExpando);
31
+ expando_elem.keydown(function(e) {
32
+ if (e.keyCode == $.ui.keyCode.SPACE || e.keyCode == $.ui.keyCode.ENTER) {
33
+ toggleExpando();
34
+ } else {
35
+ return true;
36
+ }
37
+ });
38
+ });
39
+ })(jQuery);
@@ -0,0 +1,60 @@
1
+ (function($, ns) {
2
+ function isCancelButtonEvent(event) {
3
+ var $target = $(event.target);
4
+ var isExactlyButton = $target.hasClass('js-close-modal');
5
+ var isChildOfButton = $target.parents('.js-close-modal').size() > 0;
6
+ return isExactlyButton || isChildOfButton;
7
+ }
8
+
9
+ var Modal = function(target) {
10
+ var self = this;
11
+ this.target = $(target);
12
+
13
+ this.target.dialog({
14
+ dialogClass: "uc-modal-fixed-wrapper-frame js-uc-modal-fixed-wrapper-frame",
15
+ autoOpen: false,
16
+ show: "fade",
17
+ hide: "fade",
18
+ modal: true,
19
+ draggable: false,
20
+ resizable: false,
21
+ open: function(event, ui) {
22
+ var modalFixedWrapperFrame = $(event.target.parentElement);
23
+ modalFixedWrapperFrame.wrap("<div class='uc-modal-fixed-wrapper'></div>");
24
+ modalFixedWrapperFrame.wrap("<div class='container'></div>");
25
+ modalFixedWrapperFrame.removeAttr("style");
26
+ $(".ui-dialog-content", modalFixedWrapperFrame).removeAttr("style");
27
+ modalFixedWrapperFrame.css("background", "none");
28
+ $("body").addClass("modal-on");
29
+ $('html, body').animate({ scrollTop: 0 }, 0);
30
+ self.wasHidden = self.target.hasClass('js-hidden');
31
+ self.target.removeClass('js-hidden');
32
+
33
+ self.target.click(function(event) {
34
+ if(isCancelButtonEvent(event)) {
35
+ self.close();
36
+ event.preventDefault();
37
+ }
38
+ });
39
+ },
40
+ close: function(event, ui) {
41
+ $("body").removeClass("modal-on");
42
+ $('.uc-modal-fixed-wrapper').remove();
43
+ self.target.trigger('closed');
44
+ if(self.wasHidden) {
45
+ self.target.addClass('js-hidden');
46
+ }
47
+ }
48
+ })
49
+ };
50
+
51
+ Modal.prototype.open = function() {
52
+ this.target.dialog("open");
53
+ };
54
+
55
+ Modal.prototype.close = function() {
56
+ this.target.dialog("close");
57
+ }
58
+
59
+ ns.modal = Modal;
60
+ })(jQuery, window.undercase);
@@ -0,0 +1,26 @@
1
+ (function($, ns) {
2
+ var AutocompleterTabs = function(target){
3
+
4
+ this.root = target;
5
+ this.addRoleAttributes();
6
+
7
+ $('.js-tab-button', this.root).on('click focus', function(e){
8
+ $(this).tab('show');
9
+ e.preventDefault();
10
+ e.stopPropagation();
11
+ });
12
+ };
13
+
14
+ AutocompleterTabs.prototype.setFirstActive = function(){
15
+ $('.js-tab-button:first', this.root).tab('show');
16
+ };
17
+
18
+ AutocompleterTabs.prototype.addRoleAttributes = function(){
19
+ var root = this.root;
20
+ $('.uc-autocompleter-tabs', root).attr('role', 'tablist');
21
+ $('.uc-autocompleter-tabs .uc-autocompleter-tabs__tab', root).attr('role', 'tab');
22
+ $('.uc-autocompleter-tab-panel', root).attr('role', 'tabpanel');
23
+ };
24
+
25
+ ns.AutocompleterTabs = AutocompleterTabs;
26
+ })(jQuery, window.undercase);
@@ -0,0 +1,5 @@
1
+ (function($, ns) {
2
+ $(document).on('timepicker:present', function(event) {
3
+ $(event.target).calendricalTime({timeInterval: 15, padding: 6});
4
+ });
5
+ })(jQuery);
@@ -0,0 +1,26 @@
1
+ (function($, ns) {
2
+ $(document).on('popover:present', function(event) {
3
+ var $trigger = $(event.target);
4
+
5
+ var $popoverContent = $(".popover-content", $trigger).remove();
6
+
7
+ $trigger.popover({
8
+ html: true,
9
+ content: $popoverContent.html()
10
+ });
11
+
12
+ $('body').on('click', function (bodyClickEvent) {
13
+ var clickedElement = bodyClickEvent.target;
14
+
15
+ // Don't hide if the trigger or the popover (or any of their children) are clicked
16
+ if (
17
+ !$trigger.is(clickedElement) &&
18
+ !$trigger.has(clickedElement).length &&
19
+ !$(".popover").is(clickedElement) &&
20
+ !$(".popover").has(clickedElement).length
21
+ ) {
22
+ $trigger.popover("hide");
23
+ }
24
+ });
25
+ });
26
+ })(jQuery);
@@ -0,0 +1,55 @@
1
+ (function($, ns) {
2
+ var initializePresenters = function(target) {
3
+ var $target = $(target);
4
+ var $els = $target.find('[data-presents]').add($target.filter('[data-presents]'));
5
+
6
+ $els.each(function() {
7
+ var $el = $(this);
8
+ var presenters = $el.data('presents').split(' ');
9
+ $.each(presenters, function() {
10
+ var presenter = this;
11
+ $el.trigger(presenter + ':present');
12
+ });
13
+ });
14
+ };
15
+
16
+ var observerStrategies = {
17
+ mutationObserver: function() {
18
+ var observer = new MutationObserver(function(mutations) {
19
+ mutations.map(function(mutation) {
20
+ var nodes = $.makeArray(mutation.addedNodes);
21
+ return nodes;
22
+ }).forEach(function(node) {
23
+ initializePresenters(node);
24
+ });
25
+ });
26
+
27
+ var body = document.querySelector('body');
28
+ observer.observe(body, { childList: true, subtree: true });
29
+ },
30
+
31
+ mutationEvent: function() {
32
+ $('body').on('DOMNodeInserted', function(event) {
33
+ initializePresenters(event.target);
34
+ });
35
+ }
36
+ };
37
+
38
+ var observeNewNodes = function() {
39
+ var observerStrategy;
40
+ if (typeof MutationObserver !== 'undefined') {
41
+ observerStrategy = observerStrategies.mutationObserver;
42
+ } else {
43
+ observerStrategy = observerStrategies.mutationEvent;
44
+ }
45
+ observerStrategy();
46
+ };
47
+
48
+ var present = function(){
49
+ observeNewNodes();
50
+ initializePresenters($('body'));
51
+ };
52
+
53
+ ns.present = present;
54
+
55
+ })(jQuery, undercase);
@@ -0,0 +1,35 @@
1
+ (function($, ns) {
2
+ $(document).on('show-code:present', function(event) {
3
+ var self = $(event.target);
4
+
5
+ var codeLink = $(".js-code-link", self);
6
+ var designLink = $(".js-design-link", self);
7
+
8
+ var codeSection = $(".js-code-section", self);
9
+ var designSection = $(".js-design-section", self);
10
+
11
+ $(".js-pattern-view-modes a", self).click(function(event){
12
+ event.preventDefault();
13
+ });
14
+
15
+ $(".js-code-link", self).click(function(event){
16
+ event.preventDefault();
17
+
18
+ codeSection.show();
19
+ designSection.hide();
20
+
21
+ codeLink.addClass("uf-bc-gray");
22
+ designLink.removeClass("uf-bc-gray");
23
+ });
24
+
25
+ $(".js-design-link", self).click(function(event){
26
+ event.preventDefault();
27
+
28
+ codeSection.hide();
29
+ designSection.show();
30
+
31
+ codeLink.removeClass("uf-bc-gray");
32
+ designLink.addClass("uf-bc-gray");
33
+ });
34
+ });
35
+ })(jQuery);
@@ -0,0 +1,879 @@
1
+ // -----
2
+ // The `timezoneJS.Date` object gives you full-blown timezone support, independent from the timezone set on the end-user's machine running the browser. It uses the Olson zoneinfo files for its timezone data.
3
+ //
4
+ // The constructor function and setter methods use proxy JavaScript Date objects behind the scenes, so you can use strings like '10/22/2006' with the constructor. You also get the same sensible wraparound behavior with numeric parameters (like setting a value of 14 for the month wraps around to the next March).
5
+ //
6
+ // The other significant difference from the built-in JavaScript Date is that `timezoneJS.Date` also has named properties that store the values of year, month, date, etc., so it can be directly serialized to JSON and used for data transfer.
7
+
8
+ /*
9
+ * Copyright 2010 Matthew Eernisse (mde@fleegix.org)
10
+ * and Open Source Applications Foundation
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ *
24
+ * Credits: Ideas included from incomplete JS implementation of Olson
25
+ * parser, "XMLDAte" by Philippe Goetz (philippe.goetz@wanadoo.fr)
26
+ *
27
+ * Contributions:
28
+ * Jan Niehusmann
29
+ * Ricky Romero
30
+ * Preston Hunt (prestonhunt@gmail.com)
31
+ * Dov. B Katz (dov.katz@morganstanley.com)
32
+ * Peter Bergström (pbergstr@mac.com)
33
+ * Long Ho
34
+ */
35
+ (function () {
36
+ // Standard initialization stuff to make sure the library is
37
+ // usable on both client and server (node) side.
38
+
39
+ var root = this;
40
+
41
+ var timezoneJS;
42
+ if (typeof exports !== 'undefined') {
43
+ timezoneJS = exports;
44
+ } else {
45
+ timezoneJS = root.timezoneJS = {};
46
+ }
47
+
48
+ timezoneJS.VERSION = '1.0.0';
49
+
50
+ // Grab the ajax library from global context.
51
+ // This can be jQuery, Zepto or fleegix.
52
+ // You can also specify your own transport mechanism by declaring
53
+ // `timezoneJS.timezone.transport` to a `function`. More details will follow
54
+ var $ = root.$ || root.jQuery || root.Zepto
55
+ , fleegix = root.fleegix
56
+ // Declare constant list of days and months. Unfortunately this doesn't leave room for i18n due to the Olson data being in English itself
57
+ , DAYS = timezoneJS.Days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
58
+ , MONTHS = timezoneJS.Months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
59
+ , SHORT_MONTHS = {}
60
+ , SHORT_DAYS = {}
61
+ , PARSED_TIME_STRINGS = {}
62
+ , EXACT_DATE_TIME = {}
63
+
64
+ //`{ "Jan": 0, "Feb": 1, "Mar": 2, "Apr": 3, "May": 4, "Jun": 5, "Jul": 6, "Aug": 7, "Sep": 8, "Oct": 9, "Nov": 10, "Dec": 11 }`
65
+ for (var i = 0; i < MONTHS.length; i++) {
66
+ SHORT_MONTHS[MONTHS[i].substr(0, 3)] = i;
67
+ }
68
+
69
+ //`{ "Sun": 0, "Mon": 1, "Tue": 2, "Wed": 3, "Thu": 4, "Fri": 5, "Sat": 6 }`
70
+ for (i = 0; i < DAYS.length; i++) {
71
+ SHORT_DAYS[DAYS[i].substr(0, 3)] = i;
72
+ }
73
+
74
+ // Format a number to the length = digits. For ex:
75
+ //
76
+ // `_fixWidth(2, 2) = '02'`
77
+ //
78
+ // `_fixWidth(1998, 2) = '98'`
79
+ //
80
+ // This is used to pad numbers in converting date to string in ISO standard.
81
+ var _fixWidth = function (number, digits) {
82
+ if (typeof number !== "number") { throw "not a number: " + number; }
83
+ var s = number.toString();
84
+ if (number.length > digits) {
85
+ return number.substr(number.length - digits, number.length);
86
+ }
87
+ while (s.length < digits) {
88
+ s = '0' + s;
89
+ }
90
+ return s;
91
+ };
92
+
93
+ // Abstraction layer for different transport layers, including fleegix/jQuery/Zepto
94
+ //
95
+ // Object `opts` include
96
+ //
97
+ // - `url`: url to ajax query
98
+ //
99
+ // - `async`: true for asynchronous, false otherwise. If false, return value will be response from URL. This is true by default
100
+ //
101
+ // - `success`: success callback function
102
+ //
103
+ // - `error`: error callback function
104
+ // Returns response from URL if async is false, otherwise the AJAX request object itself
105
+ var _transport = function (opts) {
106
+ if ((!fleegix || typeof fleegix.xhr === 'undefined') && (!$ || typeof $.ajax === 'undefined')) {
107
+ throw new Error('Please use the Fleegix.js XHR module, jQuery ajax, Zepto ajax, or define your own transport mechanism for downloading zone files.');
108
+ }
109
+ if (!opts) return;
110
+ if (!opts.url) throw new Error ('URL must be specified');
111
+ if (!('async' in opts)) opts.async = true;
112
+ if (!opts.async) {
113
+ return fleegix && fleegix.xhr
114
+ ? fleegix.xhr.doReq({ url: opts.url, async: false })
115
+ : $.ajax({ url : opts.url, async : false }).responseText;
116
+ }
117
+ return fleegix && fleegix.xhr
118
+ ? fleegix.xhr.send({
119
+ url : opts.url,
120
+ method : 'get',
121
+ handleSuccess : opts.success,
122
+ handleErr : opts.error
123
+ })
124
+ : $.ajax({
125
+ url : opts.url,
126
+ method : 'GET',
127
+ error : opts.error,
128
+ success : opts.success
129
+ });
130
+ };
131
+
132
+ // Constructor, which is similar to that of the native Date object itself
133
+ timezoneJS.Date = function () {
134
+ var args = Array.prototype.slice.apply(arguments)
135
+ , dt = null
136
+ , tz = null
137
+ , arr = [];
138
+
139
+
140
+ //We support several different constructors, including all the ones from `Date` object
141
+ // with a timezone string at the end.
142
+ //
143
+ //- `[tz]`: Returns object with time in `tz` specified.
144
+ //
145
+ // - `utcMillis`, `[tz]`: Return object with UTC time = `utcMillis`, in `tz`.
146
+ //
147
+ // - `Date`, `[tz]`: Returns object with UTC time = `Date.getTime()`, in `tz`.
148
+ //
149
+ // - `year, month, [date,] [hours,] [minutes,] [seconds,] [millis,] [tz]: Same as `Date` object
150
+ // with tz.
151
+ //
152
+ // - `Array`: Can be any combo of the above.
153
+ //
154
+ //If 1st argument is an array, we can use it as a list of arguments itself
155
+ if (Object.prototype.toString.call(args[0]) === '[object Array]') {
156
+ args = args[0];
157
+ }
158
+ if (typeof args[args.length - 1] === 'string' && /^[a-zA-Z]+\//gi.test(args[args.length - 1])) {
159
+ tz = args.pop();
160
+ }
161
+ switch (args.length) {
162
+ case 0:
163
+ dt = new Date();
164
+ break;
165
+ case 1:
166
+ dt = new Date(args[0]);
167
+ break;
168
+ default:
169
+ for (var i = 0; i < 7; i++) {
170
+ arr[i] = args[i] || 0;
171
+ }
172
+ dt = new Date(arr[0], arr[1], arr[2], arr[3], arr[4], arr[5], arr[6]);
173
+ break;
174
+ }
175
+
176
+ this._extractTimeArray = function () {
177
+ return [this.year, this.month, this.date, this.hours, this.minutes, this.seconds, this.milliseconds, this.timezone];
178
+ };
179
+ this._useCache = false;
180
+ this._tzInfo = {};
181
+ this._day = 0;
182
+ this.year = 0;
183
+ this.month = 0;
184
+ this.date = 0;
185
+ this.hours= 0;
186
+ this.minutes = 0;
187
+ this.seconds = 0;
188
+ this.milliseconds = 0;
189
+ this.timezone = tz || null;
190
+ this.utc = tz === 'Etc/UTC' || tz === 'Etc/GMT';
191
+ //Tricky part:
192
+ // For the cases where there are 1/2 arguments: `timezoneJS.Date(millis, [tz])` and `timezoneJS.Date(Date, [tz])`. The
193
+ // Date `dt` created should be in UTC. Thus the way I detect such cases is to determine if `arr` is not populated & `tz`
194
+ // is specified. Because if `tz` is not specified, `dt` can be in local time.
195
+ this.setFromDateObjProxy(dt, !arr.length && tz);
196
+ };
197
+
198
+ // Implements most of the native Date object
199
+ timezoneJS.Date.prototype = {
200
+ getDate: function () { return this.date; },
201
+ getDay: function () { return this._day; },
202
+ getFullYear: function () { return this.year; },
203
+ getMonth: function () { return this.month; },
204
+ getYear: function () { return this.year; },
205
+ getHours: function () { return this.hours; },
206
+ getMilliseconds: function () { return this.milliseconds; },
207
+ getMinutes: function () { return this.minutes; },
208
+ getSeconds: function () { return this.seconds; },
209
+ // Time adjusted to user-specified timezone
210
+ getTime: function () {
211
+ var dt = Date.UTC.apply(root, this._extractTimeArray());
212
+ return dt + (this.getTimezoneOffset() * 60 * 1000);
213
+ },
214
+ getTimezone: function () { return this.timezone; },
215
+ getTimezoneOffset: function () { return this.getTimezoneInfo().tzOffset; },
216
+ getTimezoneAbbreviation: function () { return this.getTimezoneInfo().tzAbbr; },
217
+ getTimezoneInfo: function () {
218
+ // If UTC, easy!
219
+ if (this.utc) return { tzOffset: 0, tzAbbr: 'UTC' };
220
+ if (this._useCache) return this._tzInfo;
221
+ var res;
222
+ // If timezone is specified, get the correct timezone info based on the Date given
223
+ if (this.timezone) {
224
+ var dt = new Date(Date.UTC.apply(root, this._extractTimeArray()));
225
+ var tz = this.timezone;
226
+ res = timezoneJS.timezone.getTzInfo(dt, tz);
227
+ }
228
+ // If no timezone was specified, use the local browser offset
229
+ else {
230
+ res = { tzOffset: this.getLocalOffset(), tzAbbr: null };
231
+ }
232
+ this._tzInfo = res;
233
+ this._useCache = true;
234
+ return res;
235
+ },
236
+ getUTCDate: function () { return this.getUTCDateProxy().getUTCDate(); },
237
+ getUTCDay: function () { return this.getUTCDateProxy().getUTCDay(); },
238
+ getUTCFullYear: function () { return this.getUTCDateProxy().getUTCFullYear(); },
239
+ getUTCHours: function () { return this.getUTCDateProxy().getUTCHours(); },
240
+ getUTCMilliseconds: function () { return this.getUTCDateProxy().getUTCMilliseconds(); },
241
+ getUTCMinutes: function () { return this.getUTCDateProxy().getUTCMinutes(); },
242
+ getUTCMonth: function () { return this.getUTCDateProxy().getUTCMonth(); },
243
+ getUTCSeconds: function () { return this.getUTCDateProxy().getUTCSeconds(); },
244
+ setDate: function (n) { this.setAttribute('date', n); },
245
+ setFullYear: function (n) { this.setAttribute('year', n); },
246
+ setMonth: function (n) { this.setAttribute('month', n); },
247
+ setYear: function (n) { this.setUTCAttribute('year', n); },
248
+ setHours: function (n) { this.setAttribute('hours', n); },
249
+ setMilliseconds: function (n) { this.setAttribute('milliseconds', n); },
250
+ setMinutes: function (n) { this.setAttribute('minutes', n); },
251
+ setSeconds: function (n) { this.setAttribute('seconds', n); },
252
+ setTime: function (n) {
253
+ if (isNaN(n)) { throw new Error('Units must be a number.'); }
254
+ var dt = new Date(0);
255
+ dt.setUTCMilliseconds(n - (this.getTimezoneOffset() * 60 * 1000));
256
+ this.setFromDateObjProxy(dt, true);
257
+ },
258
+ setUTCDate: function (n) { this.setUTCAttribute('date', n); },
259
+ setUTCFullYear: function (n) { this.setUTCAttribute('year', n); },
260
+ setUTCHours: function (n) { this.setUTCAttribute('hours', n); },
261
+ setUTCMilliseconds: function (n) { this.setUTCAttribute('milliseconds', n); },
262
+ setUTCMinutes: function (n) { this.setUTCAttribute('minutes', n); },
263
+ setUTCMonth: function (n) { this.setUTCAttribute('month', n); },
264
+ setUTCSeconds: function (n) { this.setUTCAttribute('seconds', n); },
265
+ toGMTString: function () { return this.toString('EEE, dd MMM yyyy HH:mm:ss Z', 'Etc/GMT'); },
266
+ toLocaleString: function () {},
267
+ toLocaleDateString: function () {},
268
+ toLocaleTimeString: function () {},
269
+ toSource: function () {},
270
+ toISOString: function () { return this.toString('yyyy-MM-ddTHH:mm:ss.SSS', 'Etc/UTC') + 'Z'; },
271
+ toJSON: function () { return this.toISOString(); },
272
+ // Allows different format following ISO8601 format:
273
+ toString: function (format, tz) {
274
+ // Default format is the same as toISOString
275
+ if (!format) return this.toString('yyyy-MM-dd HH:mm:ss');
276
+ var result = format;
277
+ var tzInfo = tz ? timezoneJS.timezone.getTzInfo(new Date(this.getTime()), tz) : this.getTimezoneInfo();
278
+ var _this = this;
279
+ // If timezone is specified, get a clone of the current Date object and modify it
280
+ if (tz) {
281
+ _this = this.clone();
282
+ _this.setTimezone(tz);
283
+ }
284
+ var hours = _this.getHours();
285
+ return result
286
+ // fix the same characters in Month names
287
+ .replace(/a+/g, function () { return 'k'; })
288
+ // `y`: year
289
+ .replace(/y+/g, function (token) { return _fixWidth(_this.getFullYear(), token.length); })
290
+ // `d`: date
291
+ .replace(/d+/g, function (token) { return _fixWidth(_this.getDate(), token.length); })
292
+ // `m`: minute
293
+ .replace(/m+/g, function (token) { return _fixWidth(_this.getMinutes(), token.length); })
294
+ // `s`: second
295
+ .replace(/s+/g, function (token) { return _fixWidth(_this.getSeconds(), token.length); })
296
+ // `S`: millisecond
297
+ .replace(/S+/g, function (token) { return _fixWidth(_this.getMilliseconds(), token.length); })
298
+ // `M`: month. Note: `MM` will be the numeric representation (e.g February is 02) but `MMM` will be text representation (e.g February is Feb)
299
+ .replace(/M+/g, function (token) {
300
+ var _month = _this.getMonth(),
301
+ _len = token.length;
302
+ if (_len > 3) {
303
+ return timezoneJS.Months[_month];
304
+ } else if (_len > 2) {
305
+ return timezoneJS.Months[_month].substring(0, _len);
306
+ }
307
+ return _fixWidth(_month + 1, _len);
308
+ })
309
+ // `k`: AM/PM
310
+ .replace(/k+/g, function () {
311
+ if (hours >= 12) {
312
+ if (hours > 12) {
313
+ hours -= 12;
314
+ }
315
+ return 'PM';
316
+ }
317
+ return 'AM';
318
+ })
319
+ // `H`: hour
320
+ .replace(/H+/g, function (token) { return _fixWidth(hours, token.length); })
321
+ // `E`: day
322
+ .replace(/E+/g, function (token) { return DAYS[_this.getDay()].substring(0, token.length); })
323
+ // `Z`: timezone abbreviation
324
+ .replace(/Z+/gi, function () { return tzInfo.tzAbbr; });
325
+ },
326
+ toUTCString: function () { return this.toGMTString(); },
327
+ valueOf: function () { return this.getTime(); },
328
+ clone: function () {
329
+ return new timezoneJS.Date(this._extractTimeArray());
330
+ },
331
+ setFromDateObjProxy: function (dt, fromUTC) {
332
+ this.year = fromUTC ? dt.getUTCFullYear() : dt.getFullYear();
333
+ this.month = fromUTC ? dt.getUTCMonth() : dt.getMonth();
334
+ this.date = fromUTC ? dt.getUTCDate() : dt.getDate();
335
+ this.hours = fromUTC ? dt.getUTCHours() : dt.getHours();
336
+ this.minutes = fromUTC ? dt.getUTCMinutes() : dt.getMinutes();
337
+ this.seconds = fromUTC ? dt.getUTCSeconds() : dt.getSeconds();
338
+ this.milliseconds = fromUTC ? dt.getUTCMilliseconds() : dt.getMilliseconds();
339
+ this._day = fromUTC ? dt.getUTCDay() : dt.getDay();
340
+ this._dateProxy = dt;
341
+ this._useCache = false;
342
+ },
343
+ getUTCDateProxy: function () {
344
+ var dt = new Date(Date.UTC.apply(root, this._extractTimeArray()));
345
+ dt.setUTCMinutes(dt.getUTCMinutes() + this.getTimezoneOffset());
346
+ return dt;
347
+ },
348
+ setAttribute: function (unit, n) {
349
+ if (isNaN(n)) { throw new Error('Units must be a number.'); }
350
+ var dt = this._dateProxy;
351
+ var meth = unit === 'year' ? 'FullYear' : unit.substr(0, 1).toUpperCase() + unit.substr(1);
352
+ dt['set' + meth](n);
353
+ this.setFromDateObjProxy(dt);
354
+ },
355
+ setUTCAttribute: function (unit, n) {
356
+ if (isNaN(n)) { throw new Error('Units must be a number.'); }
357
+ var meth = unit === 'year' ? 'FullYear' : unit.substr(0, 1).toUpperCase() + unit.substr(1);
358
+ var dt = this.getUTCDateProxy();
359
+ dt['setUTC' + meth](n);
360
+ dt.setUTCMinutes(dt.getUTCMinutes() - this.getTimezoneOffset());
361
+ this.setFromDateObjProxy(dt, true);
362
+ },
363
+ setTimezone: function (tz) {
364
+ var previousOffset = this.getTimezoneInfo().tzOffset;
365
+
366
+ this.utc = tz === 'Etc/UTC' || tz === 'Etc/GMT';
367
+ this.timezone = tz;
368
+ this._useCache = false;
369
+
370
+ // Create a new time that offsets by the delta of the two timezones
371
+ var _this = this.clone();
372
+ _this.setUTCMinutes(_this.getUTCMinutes() - this.getTimezoneInfo().tzOffset + previousOffset);
373
+ this.setFromDateObjProxy(_this, this.utc);
374
+ },
375
+ removeTimezone: function () {
376
+ this.utc = false;
377
+ this.timezone = null;
378
+ this._useCache = false;
379
+ },
380
+ civilToJulianDayNumber: function (y, m, d) {
381
+ var a;
382
+ // Adjust for zero-based JS-style array
383
+ m++;
384
+ if (m > 12) {
385
+ a = parseInt(m/12, 10);
386
+ m = m % 12;
387
+ y += a;
388
+ }
389
+ if (m <= 2) {
390
+ y -= 1;
391
+ m += 12;
392
+ }
393
+ a = Math.floor(y / 100);
394
+ var b = 2 - a + Math.floor(a / 4)
395
+ , jDt = Math.floor(365.25 * (y + 4716)) + Math.floor(30.6001 * (m + 1)) + d + b - 1524;
396
+ return jDt;
397
+ },
398
+ getLocalOffset: function () {
399
+ return this._dateProxy.getTimezoneOffset();
400
+ }
401
+ };
402
+
403
+
404
+ timezoneJS.timezone = new function () {
405
+ var _this = this
406
+ , regionMap = {'Etc':'etcetera','EST':'northamerica','MST':'northamerica','HST':'northamerica','EST5EDT':'northamerica','CST6CDT':'northamerica','MST7MDT':'northamerica','PST8PDT':'northamerica','America':'northamerica','Pacific':'australasia','Atlantic':'europe','Africa':'africa','Indian':'africa','Antarctica':'antarctica','Asia':'asia','Australia':'australasia','Europe':'europe','WET':'europe','CET':'europe','MET':'europe','EET':'europe'}
407
+ , regionExceptions = {'Pacific/Honolulu':'northamerica','Atlantic/Bermuda':'northamerica','Atlantic/Cape_Verde':'africa','Atlantic/St_Helena':'africa','Indian/Kerguelen':'antarctica','Indian/Chagos':'asia','Indian/Maldives':'asia','Indian/Christmas':'australasia','Indian/Cocos':'australasia','America/Danmarkshavn':'europe','America/Scoresbysund':'europe','America/Godthab':'europe','America/Thule':'europe','Asia/Yekaterinburg':'europe','Asia/Omsk':'europe','Asia/Novosibirsk':'europe','Asia/Krasnoyarsk':'europe','Asia/Irkutsk':'europe','Asia/Yakutsk':'europe','Asia/Vladivostok':'europe','Asia/Sakhalin':'europe','Asia/Magadan':'europe','Asia/Kamchatka':'europe','Asia/Anadyr':'europe','Africa/Ceuta':'europe','America/Argentina/Buenos_Aires':'southamerica','America/Argentina/Cordoba':'southamerica','America/Argentina/Tucuman':'southamerica','America/Argentina/La_Rioja':'southamerica','America/Argentina/San_Juan':'southamerica','America/Argentina/Jujuy':'southamerica','America/Argentina/Catamarca':'southamerica','America/Argentina/Mendoza':'southamerica','America/Argentina/Rio_Gallegos':'southamerica','America/Argentina/Ushuaia':'southamerica','America/Aruba':'southamerica','America/La_Paz':'southamerica','America/Noronha':'southamerica','America/Belem':'southamerica','America/Fortaleza':'southamerica','America/Recife':'southamerica','America/Araguaina':'southamerica','America/Maceio':'southamerica','America/Bahia':'southamerica','America/Sao_Paulo':'southamerica','America/Campo_Grande':'southamerica','America/Cuiaba':'southamerica','America/Porto_Velho':'southamerica','America/Boa_Vista':'southamerica','America/Manaus':'southamerica','America/Eirunepe':'southamerica','America/Rio_Branco':'southamerica','America/Santiago':'southamerica','Pacific/Easter':'southamerica','America/Bogota':'southamerica','America/Curacao':'southamerica','America/Guayaquil':'southamerica','Pacific/Galapagos':'southamerica','Atlantic/Stanley':'southamerica','America/Cayenne':'southamerica','America/Guyana':'southamerica','America/Asuncion':'southamerica','America/Lima':'southamerica','Atlantic/South_Georgia':'southamerica','America/Paramaribo':'southamerica','America/Port_of_Spain':'southamerica','America/Montevideo':'southamerica','America/Caracas':'southamerica'};
408
+
409
+ function invalidTZError(t) { throw new Error('Timezone "' + t + '" is either incorrect, or not loaded in the timezone registry.'); }
410
+ function builtInLoadZoneFile(fileName, opts) {
411
+ var url = _this.zoneFileBasePath + '/' + fileName;
412
+ return !opts || !opts.async
413
+ ? _this.parseZones(_this.transport({ url : url, async : false }))
414
+ : _this.transport({
415
+ async: true,
416
+ url : url,
417
+ success : function (str) {
418
+ if (_this.parseZones(str) && typeof opts.callback === 'function') {
419
+ opts.callback();
420
+ }
421
+ return true;
422
+ },
423
+ error : function () {
424
+ throw new Error('Error retrieving "' + url + '" zoneinfo files');
425
+ }
426
+ });
427
+ }
428
+ function getRegionForTimezone(tz) {
429
+ var exc = regionExceptions[tz]
430
+ , reg
431
+ , ret;
432
+ if (exc) return exc;
433
+ reg = tz.split('/')[0];
434
+ ret = regionMap[reg];
435
+ // If there's nothing listed in the main regions for this TZ, check the 'backward' links
436
+ if (ret) return ret;
437
+ var link = _this.zones[tz];
438
+ if (typeof link === 'string') {
439
+ return getRegionForTimezone(link);
440
+ }
441
+ // Backward-compat file hasn't loaded yet, try looking in there
442
+ if (!_this.loadedZones.backward) {
443
+ // This is for obvious legacy zones (e.g., Iceland) that don't even have a prefix like "America/" that look like normal zones
444
+ _this.loadZoneFile('backward');
445
+ return getRegionForTimezone(tz);
446
+ }
447
+ invalidTZError(tz);
448
+ }
449
+ function parseTimeString(str) {
450
+ var pat = /(\d+)(?::0*(\d*))?(?::0*(\d*))?([wsugz])?$/;
451
+ var hms = str.match(pat);
452
+ hms[1] = parseInt(hms[1], 10);
453
+ hms[2] = hms[2] ? parseInt(hms[2], 10) : 0;
454
+ hms[3] = hms[3] ? parseInt(hms[3], 10) : 0;
455
+ PARSED_TIME_STRINGS[str] = hms;
456
+
457
+ return hms;
458
+ }
459
+ function getZone(dt, tz) {
460
+ var t = tz;
461
+ var zoneList = _this.zones[t];
462
+ // Follow links to get to an acutal zone
463
+ while (typeof zoneList === "string") {
464
+ t = zoneList;
465
+ zoneList = _this.zones[t];
466
+ }
467
+ if (!zoneList) {
468
+ // Backward-compat file hasn't loaded yet, try looking in there
469
+ if (!_this.loadedZones.backward) {
470
+ //This is for backward entries like "America/Fort_Wayne" that
471
+ // getRegionForTimezone *thinks* it has a region file and zone
472
+ // for (e.g., America => 'northamerica'), but in reality it's a
473
+ // legacy zone we need the backward file for.
474
+ _this.loadZoneFile('backward');
475
+ return getZone(dt, tz);
476
+ }
477
+ invalidTZError(t);
478
+ }
479
+ for (var i = 0; i < zoneList.length; i++) {
480
+ var z = zoneList[i];
481
+ if (!z[3]) { break; }
482
+ var yea = parseInt(z[3], 10);
483
+ var mon = 11;
484
+ var dat = 31;
485
+ if (z[4]) {
486
+ mon = SHORT_MONTHS[z[4].substr(0, 3)];
487
+ dat = parseInt(z[5], 10);
488
+ }
489
+ var string = z[6] ? z[6] : '23:59:59';
490
+ t = PARSED_TIME_STRINGS[string] || parseTimeString(string);
491
+ var d = Date.UTC(yea, mon, dat, t[1], t[2], t[3]);
492
+ if (dt.getTime() < d) { break; }
493
+ }
494
+ if (i === zoneList.length) { throw new Error('No Zone found for "' + tz + '" on ' + dt); }
495
+ return zoneList[i];
496
+
497
+ }
498
+ function getBasicOffset(z) {
499
+ var off = PARSED_TIME_STRINGS[z[0]] || parseTimeString(z[0])
500
+ , adj = z[0].indexOf('-') === 0 ? -1 : 1;
501
+ off = adj * (((off[1] * 60 + off[2]) * 60 + off[3]) * 1000);
502
+ return -off/60/1000;
503
+ }
504
+
505
+ //if isUTC is true, date is given in UTC, otherwise it's given
506
+ // in local time (ie. date.getUTC*() returns local time components)
507
+ function getRule(date, zone, isUTC) {
508
+ var ruleset = zone[1];
509
+ var basicOffset = getBasicOffset(zone);
510
+
511
+ //Convert a date to UTC. Depending on the 'type' parameter, the date
512
+ // parameter may be:
513
+ //
514
+ // - `u`, `g`, `z`: already UTC (no adjustment).
515
+ //
516
+ // - `s`: standard time (adjust for time zone offset but not for DST)
517
+ //
518
+ // - `w`: wall clock time (adjust for both time zone and DST offset).
519
+ //
520
+ // DST adjustment is done using the rule given as third argument.
521
+ var convertDateToUTC = function (date, type, rule) {
522
+ var offset = 0;
523
+
524
+ if (type === 'u' || type === 'g' || type === 'z') { // UTC
525
+ offset = 0;
526
+ } else if (type === 's') { // Standard Time
527
+ offset = basicOffset;
528
+ } else if (type === 'w' || !type) { // Wall Clock Time
529
+ offset = getAdjustedOffset(basicOffset,rule);
530
+ } else {
531
+ throw("unknown type "+type);
532
+ }
533
+ offset *= 60 * 1000; // to millis
534
+
535
+ return new Date(date.getTime() + offset);
536
+ };
537
+
538
+ //Step 1: Find applicable rules for this year.
539
+ //
540
+ //Step 2: Sort the rules by effective date.
541
+ //
542
+ //Step 3: Check requested date to see if a rule has yet taken effect this year. If not,
543
+ //
544
+ //Step 4: Get the rules for the previous year. If there isn't an applicable rule for last year, then
545
+ // there probably is no current time offset since they seem to explicitly turn off the offset
546
+ // when someone stops observing DST.
547
+ //
548
+ // FIXME if this is not the case and we'll walk all the way back (ugh).
549
+ //
550
+ //Step 5: Sort the rules by effective date.
551
+ //Step 6: Apply the most recent rule before the current time.
552
+ var convertRuleToExactDateAndTime = function (yearAndRule, prevRule) {
553
+ var year = yearAndRule[0]
554
+ , rule = yearAndRule[1];
555
+ // Assume that the rule applies to the year of the given date.
556
+
557
+ var hms = PARSED_TIME_STRINGS[rule[5]] || parseTimeString(rule[5]);
558
+ var effectiveDate;
559
+
560
+ if (!EXACT_DATE_TIME[year])
561
+ EXACT_DATE_TIME[year] = {};
562
+
563
+ // Result for given parameters is already stored
564
+ if (EXACT_DATE_TIME[year][rule])
565
+ effectiveDate = EXACT_DATE_TIME[year][rule];
566
+ else {
567
+ //If we have a specific date, use that!
568
+ if (!isNaN(rule[4])) {
569
+ effectiveDate = new Date(Date.UTC(year, SHORT_MONTHS[rule[3]], rule[4], hms[1], hms[2], hms[3], 0));
570
+ }
571
+ //Let's hunt for the date.
572
+ else {
573
+ var targetDay
574
+ , operator;
575
+ //Example: `lastThu`
576
+ if (rule[4].substr(0, 4) === "last") {
577
+ // Start at the last day of the month and work backward.
578
+ effectiveDate = new Date(Date.UTC(year, SHORT_MONTHS[rule[3]] + 1, 1, hms[1] - 24, hms[2], hms[3], 0));
579
+ targetDay = SHORT_DAYS[rule[4].substr(4, 3)];
580
+ operator = "<=";
581
+ }
582
+ //Example: `Sun>=15`
583
+ else {
584
+ //Start at the specified date.
585
+ effectiveDate = new Date(Date.UTC(year, SHORT_MONTHS[rule[3]], rule[4].substr(5), hms[1], hms[2], hms[3], 0));
586
+ targetDay = SHORT_DAYS[rule[4].substr(0, 3)];
587
+ operator = rule[4].substr(3, 2);
588
+ }
589
+ var ourDay = effectiveDate.getUTCDay();
590
+ //Go forwards.
591
+ if (operator === ">=") {
592
+ effectiveDate.setUTCDate(effectiveDate.getUTCDate() + (targetDay - ourDay + ((targetDay < ourDay) ? 7 : 0)));
593
+ }
594
+ //Go backwards. Looking for the last of a certain day, or operator is "<=" (less likely).
595
+ else {
596
+ effectiveDate.setUTCDate(effectiveDate.getUTCDate() + (targetDay - ourDay - ((targetDay > ourDay) ? 7 : 0)));
597
+ }
598
+ }
599
+ EXACT_DATE_TIME[year][rule] = effectiveDate;
600
+ }
601
+
602
+
603
+ //If previous rule is given, correct for the fact that the starting time of the current
604
+ // rule may be specified in local time.
605
+ if (prevRule) {
606
+ effectiveDate = convertDateToUTC(effectiveDate, hms[4], prevRule);
607
+ }
608
+ return effectiveDate;
609
+ };
610
+
611
+ var findApplicableRules = function (year, ruleset) {
612
+ var applicableRules = [];
613
+ for (var i = 0; ruleset && i < ruleset.length; i++) {
614
+ //Exclude future rules.
615
+ if (Number(ruleset[i][0]) <= year &&
616
+ (
617
+ // Date is in a set range.
618
+ Number(ruleset[i][1]) >= year ||
619
+ // Date is in an "only" year.
620
+ (Number(ruleset[i][0]) === year && ruleset[i][1] === "only") ||
621
+ //We're in a range from the start year to infinity.
622
+ ruleset[i][1] === "max"
623
+ )
624
+ ) {
625
+ //It's completely okay to have any number of matches here.
626
+ // Normally we should only see two, but that doesn't preclude other numbers of matches.
627
+ // These matches are applicable to this year.
628
+ applicableRules.push([year, ruleset[i]]);
629
+ }
630
+ }
631
+ return applicableRules;
632
+ };
633
+
634
+ var compareDates = function (a, b, prev) {
635
+ var year, rule;
636
+ if (a.constructor !== Date) {
637
+ year = a[0];
638
+ rule = a[1];
639
+ a = (!prev && EXACT_DATE_TIME[year] && EXACT_DATE_TIME[year][rule]) ? EXACT_DATE_TIME[year][rule]
640
+ : convertRuleToExactDateAndTime(a, prev);
641
+ } else if (prev) {
642
+ a = convertDateToUTC(a, isUTC ? 'u' : 'w', prev);
643
+ }
644
+ if (b.constructor !== Date) {
645
+ year = b[0];
646
+ rule = b[1];
647
+ b = (!prev && EXACT_DATE_TIME[year] && EXACT_DATE_TIME[year][rule]) ? EXACT_DATE_TIME[year][rule]
648
+ : convertRuleToExactDateAndTime(b, prev);
649
+ } else if (prev) {
650
+ b = convertDateToUTC(b, isUTC ? 'u' : 'w', prev);
651
+ }
652
+ a = Number(a);
653
+ b = Number(b);
654
+ return a - b;
655
+ };
656
+
657
+ var year = date.getUTCFullYear();
658
+ var applicableRules;
659
+
660
+ applicableRules = findApplicableRules(year, _this.rules[ruleset]);
661
+ applicableRules.push(date);
662
+ //While sorting, the time zone in which the rule starting time is specified
663
+ // is ignored. This is ok as long as the timespan between two DST changes is
664
+ // larger than the DST offset, which is probably always true.
665
+ // As the given date may indeed be close to a DST change, it may get sorted
666
+ // to a wrong position (off by one), which is corrected below.
667
+ applicableRules.sort(compareDates);
668
+
669
+ //If there are not enough past DST rules...
670
+ if (applicableRules.indexOf(date) < 2) {
671
+ applicableRules = applicableRules.concat(findApplicableRules(year-1, _this.rules[ruleset]));
672
+ applicableRules.sort(compareDates);
673
+ }
674
+
675
+ var pinpoint = applicableRules.indexOf(date);
676
+ if (pinpoint > 1 && compareDates(date, applicableRules[pinpoint-1], applicableRules[pinpoint-2][1]) < 0) {
677
+ //The previous rule does not really apply, take the one before that.
678
+ return applicableRules[pinpoint - 2][1];
679
+ } else if (pinpoint > 0 && pinpoint < applicableRules.length - 1 && compareDates(date, applicableRules[pinpoint+1], applicableRules[pinpoint-1][1]) > 0) {
680
+ //The next rule does already apply, take that one.
681
+ return applicableRules[pinpoint + 1][1];
682
+ } else if (pinpoint === 0) {
683
+ //No applicable rule found in this and in previous year.
684
+ return null;
685
+ }
686
+ return applicableRules[pinpoint - 1][1];
687
+ }
688
+ function getAdjustedOffset(off, rule) {
689
+ var save = rule[6];
690
+ var t = PARSED_TIME_STRINGS[save] || parseTimeString(save);
691
+ var adj = save.indexOf('-') === 0 ? -1 : 1;
692
+ var ret = (adj*(((t[1] *60 + t[2]) * 60 + t[3]) * 1000));
693
+ ret = ret/60/1000;
694
+ ret -= off;
695
+ ret = -Math.ceil(ret);
696
+ return ret;
697
+ }
698
+ function getAbbreviation(zone, rule) {
699
+ var res;
700
+ var base = zone[2];
701
+ if (base.indexOf('%s') > -1) {
702
+ var repl;
703
+ if (rule) {
704
+ repl = rule[7] === '-' ? '' : rule[7];
705
+ }
706
+ //FIXME: Right now just falling back to Standard --
707
+ // apparently ought to use the last valid rule,
708
+ // although in practice that always ought to be Standard
709
+ else {
710
+ repl = 'S';
711
+ }
712
+ res = base.replace('%s', repl);
713
+ }
714
+ else if (base.indexOf('/') > -1) {
715
+ //Chose one of two alternative strings.
716
+ var t = PARSED_TIME_STRINGS[rule[6]] || parseTimeString(rule[6]);
717
+ var isDst = t[1] || t[2] || t[3];
718
+ res = base.split("/", 2)[isDst ? 1 : 0];
719
+ } else {
720
+ res = base;
721
+ }
722
+ return res;
723
+ }
724
+
725
+ this.zoneFileBasePath;
726
+ this.zoneFiles = ['africa', 'antarctica', 'asia', 'australasia', 'backward', 'etcetera', 'europe', 'northamerica', 'pacificnew', 'southamerica'];
727
+ this.loadingSchemes = {
728
+ PRELOAD_ALL: 'preloadAll',
729
+ LAZY_LOAD: 'lazyLoad',
730
+ MANUAL_LOAD: 'manualLoad'
731
+ };
732
+ this.loadingScheme = this.loadingSchemes.LAZY_LOAD;
733
+ this.loadedZones = {};
734
+ this.zones = {};
735
+ this.rules = {};
736
+
737
+ this.init = function (o) {
738
+ var opts = { async: true }
739
+ , def = this.defaultZoneFile = this.loadingScheme === this.loadingSchemes.PRELOAD_ALL
740
+ ? this.zoneFiles
741
+ : 'northamerica'
742
+ , done = 0
743
+ , callbackFn;
744
+ //Override default with any passed-in opts
745
+ for (var p in o) {
746
+ opts[p] = o[p];
747
+ }
748
+ if (typeof def === 'string') {
749
+ return this.loadZoneFile(def, opts);
750
+ }
751
+ //Wraps callback function in another one that makes
752
+ // sure all files have been loaded.
753
+ callbackFn = opts.callback;
754
+ opts.callback = function () {
755
+ done++;
756
+ (done === def.length) && typeof callbackFn === 'function' && callbackFn();
757
+ };
758
+ for (var i = 0; i < def.length; i++) {
759
+ this.loadZoneFile(def[i], opts);
760
+ }
761
+ };
762
+
763
+ //Get the zone files via XHR -- if the sync flag
764
+ // is set to true, it's being called by the lazy-loading
765
+ // mechanism, so the result needs to be returned inline.
766
+ this.loadZoneFile = function (fileName, opts) {
767
+ if (typeof window.__karma__ !== 'undefined') {
768
+ this.zoneFileBasePath = 'base/javascripts/public/timezones';
769
+ }
770
+ if (typeof this.zoneFileBasePath === 'undefined') {
771
+ throw new Error('Please define a base path to your zone file directory -- timezoneJS.timezone.zoneFileBasePath.');
772
+ }
773
+ //Ignore already loaded zones.
774
+ if (this.loadedZones[fileName]) {
775
+ return;
776
+ }
777
+ this.loadedZones[fileName] = true;
778
+ return builtInLoadZoneFile(fileName, opts);
779
+ };
780
+ this.loadZoneJSONData = function (url, sync) {
781
+ var processData = function (data) {
782
+ data = eval('('+ data +')');
783
+ for (var z in data.zones) {
784
+ _this.zones[z] = data.zones[z];
785
+ }
786
+ for (var r in data.rules) {
787
+ _this.rules[r] = data.rules[r];
788
+ }
789
+ };
790
+ return sync
791
+ ? processData(_this.transport({ url : url, async : false }))
792
+ : _this.transport({ url : url, success : processData });
793
+ };
794
+ this.loadZoneDataFromObject = function (data) {
795
+ if (!data) { return; }
796
+ for (var z in data.zones) {
797
+ _this.zones[z] = data.zones[z];
798
+ }
799
+ for (var r in data.rules) {
800
+ _this.rules[r] = data.rules[r];
801
+ }
802
+ };
803
+ this.getAllZones = function () {
804
+ var arr = [];
805
+ for (var z in this.zones) { arr.push(z); }
806
+ return arr.sort();
807
+ };
808
+ this.parseZones = function (str) {
809
+ var lines = str.split('\n')
810
+ , arr = []
811
+ , chunk = ''
812
+ , l
813
+ , zone = null
814
+ , rule = null;
815
+ for (var i = 0; i < lines.length; i++) {
816
+ l = lines[i];
817
+ if (l.match(/^\s/)) {
818
+ l = "Zone " + zone + l;
819
+ }
820
+ l = l.split("#")[0];
821
+ if (l.length > 3) {
822
+ arr = l.split(/\s+/);
823
+ chunk = arr.shift();
824
+ //Ignore Leap.
825
+ switch (chunk) {
826
+ case 'Zone':
827
+ zone = arr.shift();
828
+ if (!_this.zones[zone]) {
829
+ _this.zones[zone] = [];
830
+ }
831
+ _this.zones[zone].push(arr);
832
+ break;
833
+ case 'Rule':
834
+ rule = arr.shift();
835
+ if (!_this.rules[rule]) {
836
+ _this.rules[rule] = [];
837
+ }
838
+ _this.rules[rule].push(arr);
839
+ break;
840
+ case 'Link':
841
+ //No zones for these should already exist.
842
+ if (_this.zones[arr[1]]) {
843
+ throw new Error('Error with Link ' + arr[1] + '. Cannot create link of a preexisted zone.');
844
+ }
845
+ //Create the link.
846
+ _this.zones[arr[1]] = arr[0];
847
+ break;
848
+ }
849
+ }
850
+ }
851
+ return true;
852
+ };
853
+ //Expose transport mechanism and allow overwrite.
854
+ this.transport = _transport;
855
+ this.getTzInfo = function (dt, tz, isUTC) {
856
+ //Lazy-load any zones not yet loaded.
857
+ if (this.loadingScheme === this.loadingSchemes.LAZY_LOAD) {
858
+ //Get the correct region for the zone.
859
+ var zoneFile = getRegionForTimezone(tz);
860
+ if (!zoneFile) {
861
+ throw new Error('Not a valid timezone ID.');
862
+ }
863
+ if (!this.loadedZones[zoneFile]) {
864
+ //Get the file and parse it -- use synchronous XHR.
865
+ this.loadZoneFile(zoneFile);
866
+ }
867
+ }
868
+ var zone = getZone(dt, tz);
869
+ var off = getBasicOffset(zone);
870
+ //See if the offset needs adjustment.
871
+ var rule = getRule(dt, zone, isUTC);
872
+ if (rule) {
873
+ off = getAdjustedOffset(off, rule);
874
+ }
875
+ var abbr = getAbbreviation(zone, rule);
876
+ return { tzOffset: off, tzAbbr: abbr };
877
+ };
878
+ };
879
+ }).call(this);