active_scaffold 3.7.12 → 4.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +9 -23
  3. data/README.md +3 -2
  4. data/app/assets/config/active_scaffold_manifest.js +3 -0
  5. data/app/assets/javascripts/active_scaffold.js.erb +24 -34
  6. data/app/assets/javascripts/jquery/active_scaffold.js +41 -58
  7. data/app/assets/javascripts/jquery/date_picker_bridge.js.erb +1 -1
  8. data/app/assets/stylesheets/active_scaffold_colors.scss +0 -7
  9. data/app/assets/stylesheets/active_scaffold_extensions.css.erb +2 -2
  10. data/app/assets/stylesheets/active_scaffold_jquery_ui.css.erb +7 -7
  11. data/app/assets/stylesheets/active_scaffold_layout.css +57 -30
  12. data/app/views/active_scaffold_overrides/_add_existing_form.html.erb +10 -10
  13. data/app/views/active_scaffold_overrides/_base_form.html.erb +21 -21
  14. data/app/views/active_scaffold_overrides/_create_form.html.erb +10 -7
  15. data/app/views/active_scaffold_overrides/_create_form_on_list.html.erb +5 -5
  16. data/app/views/active_scaffold_overrides/_field_search.html.erb +6 -6
  17. data/app/views/active_scaffold_overrides/_form.html.erb +11 -14
  18. data/app/views/active_scaffold_overrides/_form_association.html.erb +21 -12
  19. data/app/views/active_scaffold_overrides/_form_association_footer.html.erb +19 -10
  20. data/app/views/active_scaffold_overrides/_form_association_record.html.erb +15 -21
  21. data/app/views/active_scaffold_overrides/_form_messages.html.erb +2 -2
  22. data/app/views/active_scaffold_overrides/_horizontal_subform.html.erb +7 -6
  23. data/app/views/active_scaffold_overrides/_human_conditions.html.erb +2 -2
  24. data/app/views/active_scaffold_overrides/_list.html.erb +15 -8
  25. data/app/views/active_scaffold_overrides/_list_calculations.html.erb +2 -3
  26. data/app/views/active_scaffold_overrides/_list_header.html.erb +2 -2
  27. data/app/views/active_scaffold_overrides/_list_inline_adapter.html.erb +5 -5
  28. data/app/views/active_scaffold_overrides/_list_messages.html.erb +12 -3
  29. data/app/views/active_scaffold_overrides/_list_pagination.html.erb +3 -3
  30. data/app/views/active_scaffold_overrides/_list_pagination_links.html.erb +4 -4
  31. data/app/views/active_scaffold_overrides/_list_record.html.erb +6 -6
  32. data/app/views/active_scaffold_overrides/_list_with_header.html.erb +4 -4
  33. data/app/views/active_scaffold_overrides/_messages.html.erb +1 -1
  34. data/app/views/active_scaffold_overrides/_refresh_list.js.erb +2 -2
  35. data/app/views/active_scaffold_overrides/_render_field.js.erb +4 -4
  36. data/app/views/active_scaffold_overrides/_row.html.erb +1 -1
  37. data/app/views/active_scaffold_overrides/_search.html.erb +6 -5
  38. data/app/views/active_scaffold_overrides/_show.html.erb +3 -3
  39. data/app/views/active_scaffold_overrides/_show_actions.html.erb +1 -1
  40. data/app/views/active_scaffold_overrides/_show_association.html.erb +1 -1
  41. data/app/views/active_scaffold_overrides/_show_association_horizontal.html.erb +1 -1
  42. data/app/views/active_scaffold_overrides/_show_association_vertical.html.erb +1 -1
  43. data/app/views/active_scaffold_overrides/_show_columns.html.erb +1 -1
  44. data/app/views/active_scaffold_overrides/_show_horizontal_record.html.erb +1 -1
  45. data/app/views/active_scaffold_overrides/_update_actions.html.erb +1 -1
  46. data/app/views/active_scaffold_overrides/_update_calculations.js.erb +2 -2
  47. data/app/views/active_scaffold_overrides/_update_column.js.erb +8 -7
  48. data/app/views/active_scaffold_overrides/_update_form.html.erb +5 -5
  49. data/app/views/active_scaffold_overrides/_update_messages.js.erb +1 -1
  50. data/app/views/active_scaffold_overrides/_vertical_subform.html.erb +4 -3
  51. data/app/views/active_scaffold_overrides/action_confirmation.html.erb +3 -3
  52. data/app/views/active_scaffold_overrides/add_existing.js.erb +6 -6
  53. data/app/views/active_scaffold_overrides/add_existing_form.html.erb +1 -1
  54. data/app/views/active_scaffold_overrides/add_tab.js.erb +15 -0
  55. data/app/views/active_scaffold_overrides/create.html.erb +1 -1
  56. data/app/views/active_scaffold_overrides/delete.html.erb +4 -4
  57. data/app/views/active_scaffold_overrides/destroy.js.erb +15 -13
  58. data/app/views/active_scaffold_overrides/edit_associated.js.erb +3 -3
  59. data/app/views/active_scaffold_overrides/field_search.html.erb +1 -1
  60. data/app/views/active_scaffold_overrides/form_messages.js.erb +1 -1
  61. data/app/views/active_scaffold_overrides/list.html.erb +1 -1
  62. data/app/views/active_scaffold_overrides/on_action_update.js.erb +13 -8
  63. data/app/views/active_scaffold_overrides/on_create.js.erb +34 -6
  64. data/app/views/active_scaffold_overrides/on_mark.js.erb +3 -3
  65. data/app/views/active_scaffold_overrides/on_update.js.erb +9 -9
  66. data/app/views/active_scaffold_overrides/render_field.js.erb +1 -1
  67. data/app/views/active_scaffold_overrides/render_field_inplace.html.erb +1 -1
  68. data/app/views/active_scaffold_overrides/row.js.erb +2 -2
  69. data/app/views/active_scaffold_overrides/search.html.erb +1 -1
  70. data/app/views/active_scaffold_overrides/show.html.erb +3 -3
  71. data/app/views/active_scaffold_overrides/update.html.erb +2 -2
  72. data/app/views/active_scaffold_overrides/update_column.js.erb +4 -4
  73. data/app/views/active_scaffold_overrides/update_row.js.erb +1 -1
  74. data/lib/active_scaffold/actions/common_search.rb +5 -3
  75. data/lib/active_scaffold/actions/core.rb +57 -32
  76. data/lib/active_scaffold/actions/create.rb +19 -17
  77. data/lib/active_scaffold/actions/delete.rb +10 -12
  78. data/lib/active_scaffold/actions/field_search.rb +28 -13
  79. data/lib/active_scaffold/actions/list.rb +34 -34
  80. data/lib/active_scaffold/actions/mark.rb +5 -5
  81. data/lib/active_scaffold/actions/nested.rb +64 -56
  82. data/lib/active_scaffold/actions/search.rb +2 -2
  83. data/lib/active_scaffold/actions/show.rb +5 -5
  84. data/lib/active_scaffold/actions/subform.rb +15 -4
  85. data/lib/active_scaffold/actions/update.rb +20 -20
  86. data/lib/active_scaffold/active_record_permissions.rb +4 -3
  87. data/lib/active_scaffold/attribute_params.rb +51 -50
  88. data/lib/active_scaffold/bridges/active_storage/active_storage_bridge.rb +4 -4
  89. data/lib/active_scaffold/bridges/active_storage/active_storage_helpers.rb +6 -2
  90. data/lib/active_scaffold/bridges/active_storage.rb +1 -1
  91. data/lib/active_scaffold/bridges/ancestry/ancestry_bridge.rb +3 -3
  92. data/lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb +4 -1
  93. data/lib/active_scaffold/bridges/bitfields.rb +1 -1
  94. data/lib/active_scaffold/bridges/cancan/cancan_bridge.rb +9 -8
  95. data/lib/active_scaffold/bridges/cancan.rb +8 -8
  96. data/lib/active_scaffold/bridges/carrierwave/form_ui.rb +1 -1
  97. data/lib/active_scaffold/bridges/carrierwave/list_ui.rb +4 -3
  98. data/lib/active_scaffold/bridges/carrierwave.rb +2 -2
  99. data/lib/active_scaffold/bridges/chosen.rb +1 -5
  100. data/lib/active_scaffold/bridges/country_select/country_select_bridge_helper.rb +4 -2
  101. data/lib/active_scaffold/bridges/date_picker/ext.rb +20 -12
  102. data/lib/active_scaffold/bridges/date_picker/helper.rb +37 -33
  103. data/lib/active_scaffold/bridges/date_picker.rb +1 -4
  104. data/lib/active_scaffold/bridges/dragonfly/dragonfly_bridge.rb +1 -1
  105. data/lib/active_scaffold/bridges/dragonfly/list_ui.rb +3 -2
  106. data/lib/active_scaffold/bridges/dragonfly.rb +1 -1
  107. data/lib/active_scaffold/bridges/file_column/as_file_column_bridge.rb +3 -2
  108. data/lib/active_scaffold/bridges/file_column/file_column_helpers.rb +2 -1
  109. data/lib/active_scaffold/bridges/file_column/form_ui.rb +4 -9
  110. data/lib/active_scaffold/bridges/file_column/list_ui.rb +6 -3
  111. data/lib/active_scaffold/bridges/file_column/test/functional/file_column_keep_test.rb +3 -3
  112. data/lib/active_scaffold/bridges/file_column/test/mock_model.rb +1 -4
  113. data/lib/active_scaffold/bridges/file_column.rb +1 -0
  114. data/lib/active_scaffold/bridges/paper_trail/actions.rb +4 -2
  115. data/lib/active_scaffold/bridges/paper_trail/config.rb +1 -1
  116. data/lib/active_scaffold/bridges/paper_trail/helper.rb +1 -1
  117. data/lib/active_scaffold/bridges/paper_trail/paper_trail_bridge.rb +2 -1
  118. data/lib/active_scaffold/bridges/paperclip/list_ui.rb +3 -2
  119. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge.rb +1 -1
  120. data/lib/active_scaffold/bridges/paperclip/paperclip_bridge_helpers.rb +10 -9
  121. data/lib/active_scaffold/bridges/paperclip.rb +2 -1
  122. data/lib/active_scaffold/bridges/record_select/helpers.rb +10 -11
  123. data/lib/active_scaffold/bridges/semantic_attributes/column.rb +3 -1
  124. data/lib/active_scaffold/bridges/tiny_mce/helpers.rb +3 -7
  125. data/lib/active_scaffold/bridges/tiny_mce.rb +2 -7
  126. data/lib/active_scaffold/bridges/usa_state_select/usa_state_select_helper.rb +7 -7
  127. data/lib/active_scaffold/bridges.rb +7 -5
  128. data/lib/active_scaffold/config/base.rb +20 -24
  129. data/lib/active_scaffold/config/core.rb +27 -39
  130. data/lib/active_scaffold/config/create.rb +1 -1
  131. data/lib/active_scaffold/config/delete.rb +9 -9
  132. data/lib/active_scaffold/config/field_search.rb +4 -9
  133. data/lib/active_scaffold/config/form.rb +3 -1
  134. data/lib/active_scaffold/config/list.rb +19 -15
  135. data/lib/active_scaffold/config/nested.rb +2 -2
  136. data/lib/active_scaffold/config/search.rb +5 -5
  137. data/lib/active_scaffold/config/show.rb +1 -1
  138. data/lib/active_scaffold/config/subform.rb +1 -1
  139. data/lib/active_scaffold/config/update.rb +4 -5
  140. data/lib/active_scaffold/configurable.rb +2 -1
  141. data/lib/active_scaffold/constraints.rb +16 -11
  142. data/lib/active_scaffold/core.rb +25 -27
  143. data/lib/active_scaffold/data_structures/action_columns.rb +10 -3
  144. data/lib/active_scaffold/data_structures/action_link.rb +19 -9
  145. data/lib/active_scaffold/data_structures/action_links.rb +20 -26
  146. data/lib/active_scaffold/data_structures/actions.rb +3 -3
  147. data/lib/active_scaffold/data_structures/association/abstract.rb +8 -4
  148. data/lib/active_scaffold/data_structures/association/active_mongoid.rb +1 -0
  149. data/lib/active_scaffold/data_structures/association/active_record.rb +1 -4
  150. data/lib/active_scaffold/data_structures/column.rb +368 -327
  151. data/lib/active_scaffold/data_structures/columns.rb +3 -2
  152. data/lib/active_scaffold/data_structures/nested_info.rb +6 -5
  153. data/lib/active_scaffold/data_structures/proxy_column.rb +68 -0
  154. data/lib/active_scaffold/data_structures/set.rb +7 -4
  155. data/lib/active_scaffold/data_structures/sorting.rb +21 -12
  156. data/lib/active_scaffold/engine.rb +12 -12
  157. data/lib/active_scaffold/extensions/action_controller_rendering.rb +5 -5
  158. data/lib/active_scaffold/extensions/action_controller_rescueing.rb +1 -1
  159. data/lib/active_scaffold/extensions/action_view_rendering.rb +29 -31
  160. data/lib/active_scaffold/extensions/ice_nine.rb +2 -1
  161. data/lib/active_scaffold/extensions/localize.rb +2 -2
  162. data/lib/active_scaffold/extensions/name_option_for_datetime.rb +1 -1
  163. data/lib/active_scaffold/extensions/routing_mapper.rb +5 -4
  164. data/lib/active_scaffold/extensions/unsaved_associated.rb +3 -2
  165. data/lib/active_scaffold/finder.rb +71 -78
  166. data/lib/active_scaffold/helpers/action_link_helpers.rb +37 -49
  167. data/lib/active_scaffold/helpers/association_helpers.rb +3 -2
  168. data/lib/active_scaffold/helpers/controller_helpers.rb +18 -16
  169. data/lib/active_scaffold/helpers/form_column_helpers.rb +69 -53
  170. data/lib/active_scaffold/helpers/human_condition_helpers.rb +17 -15
  171. data/lib/active_scaffold/helpers/id_helpers.rb +5 -5
  172. data/lib/active_scaffold/helpers/list_column_helpers.rb +35 -38
  173. data/lib/active_scaffold/helpers/pagination_helpers.rb +4 -4
  174. data/lib/active_scaffold/helpers/search_column_helpers.rb +25 -34
  175. data/lib/active_scaffold/helpers/show_column_helpers.rb +7 -4
  176. data/lib/active_scaffold/helpers/tabs_helpers.rb +88 -0
  177. data/lib/active_scaffold/helpers/view_helpers.rb +15 -13
  178. data/lib/active_scaffold/marked_model.rb +1 -2
  179. data/lib/active_scaffold/orm_checks.rb +6 -4
  180. data/lib/active_scaffold/paginator.rb +3 -2
  181. data/lib/active_scaffold/registry.rb +5 -0
  182. data/lib/active_scaffold/tableless.rb +24 -14
  183. data/lib/active_scaffold/version.rb +4 -4
  184. data/lib/active_scaffold.rb +8 -34
  185. data/lib/generators/active_scaffold/controller_generator.rb +20 -20
  186. data/lib/generators/active_scaffold/install_generator.rb +4 -8
  187. data/lib/generators/active_scaffold/resource_generator.rb +31 -31
  188. data/lib/tasks/brakeman.rake +1 -1
  189. data/shoulda_macros/macros.rb +14 -14
  190. metadata +11 -232
  191. data/app/assets/javascripts/prototype/active_scaffold.js +0 -1249
  192. data/app/assets/javascripts/prototype/active_scaffold_chosen.js +0 -0
  193. data/app/assets/javascripts/prototype/dhtml_history.js +0 -870
  194. data/app/assets/javascripts/prototype/form_enhancements.js +0 -117
  195. data/app/assets/javascripts/prototype/tiny_mce_bridge.js +0 -17
  196. data/app/views/active_scaffold_overrides/_list_messages_content.html.erb +0 -8
  197. data/app/views/active_scaffold_overrides/_new_record.js.erb +0 -15
  198. data/app/views/active_scaffold_overrides/_popup_adapter.html.erb +0 -20
  199. data/app/views/active_scaffold_overrides/_refresh_create_form.js.erb +0 -12
  200. data/lib/active_scaffold/bridges/calendar_date_select/as_cds_bridge.rb +0 -58
  201. data/lib/active_scaffold/bridges/calendar_date_select.rb +0 -17
  202. data/lib/active_scaffold/data_structures/action_link_separator.rb +0 -13
  203. data/lib/active_scaffold/extensions/cow_proxy.rb +0 -102
  204. data/test/active_scaffold_config_mock.rb +0 -33
  205. data/test/bridges/bridge_test.rb +0 -88
  206. data/test/bridges/date_picker_test.rb +0 -31
  207. data/test/bridges/paper_trail_test.rb +0 -16
  208. data/test/bridges/paperclip_test.rb +0 -85
  209. data/test/bridges/tiny_mce_test.rb +0 -61
  210. data/test/class_with_finder.rb +0 -42
  211. data/test/company.rb +0 -97
  212. data/test/config/base_test.rb +0 -17
  213. data/test/config/core_test.rb +0 -66
  214. data/test/config/create_test.rb +0 -72
  215. data/test/config/delete_test.rb +0 -35
  216. data/test/config/field_search_test.rb +0 -49
  217. data/test/config/list_test.rb +0 -134
  218. data/test/config/nested_test.rb +0 -55
  219. data/test/config/search_test.rb +0 -62
  220. data/test/config/show_test.rb +0 -45
  221. data/test/config/subform_test.rb +0 -19
  222. data/test/config/update_test.rb +0 -52
  223. data/test/const_mocker.rb +0 -32
  224. data/test/data_structures/action_columns_test.rb +0 -112
  225. data/test/data_structures/action_link_test.rb +0 -79
  226. data/test/data_structures/action_links_test.rb +0 -78
  227. data/test/data_structures/actions_test.rb +0 -25
  228. data/test/data_structures/association_column_test.rb +0 -41
  229. data/test/data_structures/column_test.rb +0 -186
  230. data/test/data_structures/columns_test.rb +0 -68
  231. data/test/data_structures/set_test.rb +0 -84
  232. data/test/data_structures/sorting_test.rb +0 -148
  233. data/test/data_structures/standard_column_test.rb +0 -23
  234. data/test/data_structures/validation_reflection_test.rb +0 -69
  235. data/test/data_structures/virtual_column_test.rb +0 -23
  236. data/test/extensions/action_view_rendering_test.rb +0 -20
  237. data/test/extensions/active_record_test.rb +0 -44
  238. data/test/extensions/routing_mapper_test.rb +0 -73
  239. data/test/helpers/form_column_helpers_test.rb +0 -34
  240. data/test/helpers/list_column_helpers_test.rb +0 -53
  241. data/test/helpers/pagination_helpers_test.rb +0 -65
  242. data/test/helpers/search_column_helpers_test.rb +0 -15
  243. data/test/misc/active_record_permissions_test.rb +0 -193
  244. data/test/misc/attribute_params_test.rb +0 -460
  245. data/test/misc/calculation_test.rb +0 -39
  246. data/test/misc/configurable_test.rb +0 -97
  247. data/test/misc/constraints_test.rb +0 -209
  248. data/test/misc/convert_numbers_format_test.rb +0 -171
  249. data/test/misc/finder_test.rb +0 -124
  250. data/test/misc/lang_test.rb +0 -10
  251. data/test/misc/parse_datetime_test.rb +0 -159
  252. data/test/misc/render_test.rb +0 -9
  253. data/test/misc/tableless_test.rb +0 -56
  254. data/test/mock_app/.gitignore +0 -2
  255. data/test/mock_app/Rakefile +0 -7
  256. data/test/mock_app/app/assets/config/manifest.js +0 -0
  257. data/test/mock_app/app/controllers/addresses_controller.rb +0 -4
  258. data/test/mock_app/app/controllers/application_controller.rb +0 -10
  259. data/test/mock_app/app/controllers/buildings_controller.rb +0 -4
  260. data/test/mock_app/app/controllers/cars_controller.rb +0 -5
  261. data/test/mock_app/app/controllers/contacts_controller.rb +0 -4
  262. data/test/mock_app/app/controllers/floors_controller.rb +0 -6
  263. data/test/mock_app/app/controllers/people_controller.rb +0 -8
  264. data/test/mock_app/app/controllers/roles_controller.rb +0 -4
  265. data/test/mock_app/app/helpers/application_helper.rb +0 -3
  266. data/test/mock_app/app/models/address.rb +0 -3
  267. data/test/mock_app/app/models/building.rb +0 -9
  268. data/test/mock_app/app/models/car.rb +0 -3
  269. data/test/mock_app/app/models/contact.rb +0 -3
  270. data/test/mock_app/app/models/file_model.rb +0 -31
  271. data/test/mock_app/app/models/floor.rb +0 -8
  272. data/test/mock_app/app/models/person.rb +0 -12
  273. data/test/mock_app/app/models/role.rb +0 -3
  274. data/test/mock_app/app/views/active_scaffold_overrides/_form.html.erb +0 -2
  275. data/test/mock_app/app/views/active_scaffold_overrides/list.html.erb +0 -2
  276. data/test/mock_app/app/views/people/_first_name_form_column.html.erb +0 -2
  277. data/test/mock_app/app/views/people/_form.html.erb +0 -2
  278. data/test/mock_app/app/views/people/list.html.erb +0 -2
  279. data/test/mock_app/config/application.rb +0 -14
  280. data/test/mock_app/config/boot.rb +0 -7
  281. data/test/mock_app/config/database.yml +0 -16
  282. data/test/mock_app/config/environment.rb +0 -6
  283. data/test/mock_app/config/environments/development.rb +0 -24
  284. data/test/mock_app/config/environments/production.rb +0 -49
  285. data/test/mock_app/config/environments/test.rb +0 -34
  286. data/test/mock_app/config/initializers/backtrace_silencers.rb +0 -7
  287. data/test/mock_app/config/initializers/inflections.rb +0 -10
  288. data/test/mock_app/config/initializers/mime_types.rb +0 -5
  289. data/test/mock_app/config/initializers/secret_token.rb +0 -11
  290. data/test/mock_app/config/initializers/session_store.rb +0 -8
  291. data/test/mock_app/config/initializers/wrap_parameters.rb +0 -14
  292. data/test/mock_app/config/locales/en.yml +0 -5
  293. data/test/mock_app/config/routes.rb +0 -17
  294. data/test/mock_app/config.ru +0 -4
  295. data/test/mock_app/db/schema.rb +0 -68
  296. data/test/mock_app/db/test.sqlite3 +0 -1
  297. data/test/model_stub.rb +0 -64
  298. data/test/performance/list_cars_performance_test.rb +0 -34
  299. data/test/performance/list_people_performance_test.rb +0 -31
  300. data/test/performance_test_help.rb +0 -3
  301. data/test/run_all.rb +0 -6
  302. data/test/test_helper.rb +0 -71
  303. data/vendor/assets/javascripts/getprototypeof.js +0 -12
@@ -1,870 +0,0 @@
1
- /*
2
- Copyright (c) 2007 Brian Dillard and Brad Neuberg:
3
- Brian Dillard | Project Lead | bdillard@pathf.com | http://blogs.pathf.com/agileajax/
4
- Brad Neuberg | Original Project Creator | http://codinginparadise.org
5
-
6
- SVN r113 from http://code.google.com/p/reallysimplehistory
7
- + Changes by Ed Wildgoose - MailASail
8
- + Changed EncodeURIComponent -> EncodeURI
9
- + Changed DecodeURIComponent -> DecodeURI
10
- + Changed 'blank.html?' -> '/blank.html?'
11
-
12
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
13
- (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
14
- publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do
15
- so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
21
- FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
- */
24
-
25
- /*
26
- dhtmlHistory: An object that provides history, history data, and bookmarking for DHTML and Ajax applications.
27
-
28
- dependencies:
29
- * the historyStorage object included in this file.
30
-
31
- */
32
- window.dhtmlHistory = {
33
-
34
- /*Public: User-agent booleans*/
35
- isIE: false,
36
- isOpera: false,
37
- isSafari: false,
38
- isKonquerer: false,
39
- isGecko: false,
40
- isSupported: false,
41
-
42
- /*Public: Create the DHTML history infrastructure*/
43
- create: function(options) {
44
-
45
- /*
46
- options - object to store initialization parameters
47
- options.blankURL - string to override the default location of blank.html. Must end in "?"
48
- options.debugMode - boolean that causes hidden form fields to be shown for development purposes.
49
- options.toJSON - function to override default JSON stringifier
50
- options.fromJSON - function to override default JSON parser
51
- options.baseTitle - pattern for title changes; example: "Armchair DJ [@@@]" - @@@ will be replaced
52
- */
53
-
54
- var that = this;
55
-
56
- /*set user-agent flags*/
57
- var UA = navigator.userAgent.toLowerCase();
58
- var platform = navigator.platform.toLowerCase();
59
- var vendor = navigator.vendor || "";
60
- if (vendor === "KDE") {
61
- this.isKonqueror = true;
62
- this.isSupported = false;
63
- } else if (typeof window.opera !== "undefined") {
64
- this.isOpera = true;
65
- this.isSupported = true;
66
- } else if (typeof document.all !== "undefined") {
67
- this.isIE = true;
68
- this.isSupported = true;
69
- } else if (vendor.indexOf("Apple Computer, Inc.") > -1) {
70
- this.isSafari = true;
71
- //this.isSupported = (platform.indexOf("mac") > -1);
72
- this.isSupported = false;
73
- } else if (UA.indexOf("gecko") != -1) {
74
- this.isGecko = true;
75
- this.isSupported = true;
76
- }
77
-
78
- if (this.isSupported) {
79
- /*Set up the historyStorage object; pass in options bundle*/
80
- window.historyStorage.setup(options);
81
-
82
- /*Set up our base title if one is passed in*/
83
- if (options && options.baseTitle) {
84
- if (options.baseTitle.indexOf("@@@") < 0 && historyStorage.debugMode) {
85
- throw new Error("Programmer error: options.baseTitle must contain the replacement parameter"
86
- + " '@@@' to be useful.");
87
- }
88
- this.baseTitle = options.baseTitle;
89
- }
90
-
91
- /*Create Safari/Opera-specific code*/
92
- if (this.isSafari && this.isSupported) {
93
- this.createSafari();
94
- } else if (this.isOpera) {
95
- this.createOpera();
96
- }
97
-
98
- /*Get our initial location*/
99
- var initialHash = this.getCurrentLocation();
100
-
101
- /*Save it as our current location*/
102
- this.currentLocation = initialHash;
103
-
104
- /*Now that we have a hash, create IE-specific code*/
105
- if (this.isIE) {
106
- /*Optionally override the URL of IE's blank HTML file*/
107
- if (options && options.blankURL) {
108
- var u = options.blankURL;
109
- /*assign the value, adding the trailing ? if it's not passed in*/
110
- this.blankURL = (u.indexOf("?") != u.length - 1
111
- ? u + "?"
112
- : u
113
- );
114
- }
115
- this.createIE(initialHash);
116
- }
117
-
118
- /*Add an unload listener for the page; this is needed for FF 1.5+ because this browser caches all dynamic updates to the
119
- page, which can break some of our logic related to testing whether this is the first instance a page has loaded or whether
120
- it is being pulled from the cache*/
121
-
122
- var unloadHandler = function() {
123
- that.firstLoad = null;
124
- };
125
-
126
- this.addEventListener(window,'unload',unloadHandler);
127
-
128
- /*Determine if this is our first page load; for IE, we do this in this.iframeLoaded(), which is fired on pageload. We do it
129
- there because we have no historyStorage at this point, which only exists after the page is finished loading in IE*/
130
- if (this.isIE) {
131
- /*The iframe will get loaded on page load, and we want to ignore this fact*/
132
- this.ignoreLocationChange = true;
133
- } else if (this.isSupported) {
134
- if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) {
135
- /*This is our first page load, so ignore the location change and add our special history entry*/
136
- this.ignoreLocationChange = true;
137
- this.firstLoad = true;
138
- historyStorage.put(this.PAGELOADEDSTRING, true);
139
- } else {
140
- /*This isn't our first page load, so indicate that we want to pay attention to this location change*/
141
- this.ignoreLocationChange = false;
142
- this.firstLoad = false;
143
- /*For browsers other than IE, fire a history change event; on IE, the event will be thrown automatically when its
144
- hidden iframe reloads on page load. Unfortunately, we don't have any listeners yet; indicate that we want to fire
145
- an event when a listener is added.*/
146
- this.fireOnNewListener = true;
147
- }
148
- }
149
-
150
- /*Other browsers can use a location handler that checks at regular intervals as their primary mechanism; we use it for IE as
151
- well to handle an important edge case; see checkLocation() for details*/
152
- var locationHandler = function() {
153
- that.checkLocation();
154
- };
155
- setInterval(locationHandler, 100);
156
- }
157
- },
158
-
159
- /*Public: Initialize our DHTML history. You must call this after the page is finished loading. Optionally, you can pass your listener in
160
- here so you don't need to make a separate call to addListener*/
161
- initialize: function(listener) {
162
-
163
- /*save original document title to plug in when we hit a null-key history point*/
164
- this.originalTitle = document.title;
165
-
166
- /*IE needs to be explicitly initialized. IE doesn't autofill form data until the page is finished loading, so we have to wait*/
167
- if (this.isIE) {
168
- /*If this is the first time this page has loaded*/
169
- if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) {
170
- /*For IE, we do this in initialize(); for other browsers, we do it in create()*/
171
- this.fireOnNewListener = false;
172
- this.firstLoad = true;
173
- historyStorage.put(this.PAGELOADEDSTRING, true);
174
- }
175
- /*Else if this is a fake onload event*/
176
- else {
177
- this.fireOnNewListener = true;
178
- this.firstLoad = false;
179
- }
180
- }
181
- /*optional convenience to save a separate call to addListener*/
182
- if (listener) {
183
- this.addListener(listener);
184
- }
185
- },
186
-
187
- /*Public: Adds a history change listener. Only one listener is supported at this time.*/
188
- addListener: function(listener) {
189
- this.listener = listener;
190
- /*If the page was just loaded and we should not ignore it, fire an event to our new listener now*/
191
- if (this.fireOnNewListener) {
192
- this.fireHistoryEvent(this.currentLocation);
193
- this.fireOnNewListener = false;
194
- }
195
- },
196
-
197
- /*Public: Change the current HTML title*/
198
- changeTitle: function(historyData) {
199
- var winTitle = (historyData && historyData.newTitle
200
- /*Plug the new title into the pattern*/
201
- ? this.baseTitle.replace('@@@', historyData.newTitle)
202
- /*Otherwise, if there is no new title, use the original document title. This is useful when some
203
- history changes have title changes and some don't; we can automatically return to the original
204
- title rather than leaving a misleading title in the title bar. The same goes for our "virgin"
205
- (hashless) page state.*/
206
- : this.originalTitle
207
- );
208
- /*No need to do anything if the title isn't changing*/
209
- if (document.title == winTitle) {
210
- return;
211
- }
212
-
213
-
214
- /*Now change the DOM*/
215
- document.title = winTitle;
216
- /*Change it in the iframe, too, for IE*/
217
- if (this.isIE) {
218
- this.iframe.contentWindow.document.title = winTitle;
219
- }
220
-
221
- /*If non-IE, reload the hash so the new title "sticks" in the browser history object*/
222
- if (!this.isIE && !this.isOpera) {
223
- var hash = decodeURI(document.location.hash);
224
- if (hash != "") {
225
- var encodedHash = encodeURI(this.removeHash(hash));
226
- document.location.hash = encodedHash;
227
- } else {
228
- //document.location.hash = "#";
229
- }
230
- }
231
- },
232
-
233
- /*Public: Add a history point. Parameters available:
234
- * newLocation (required):
235
- This will be the #hash value in the URL. Users can bookmark it. It will persist across sessions, so
236
- your application should be able to restore itself to a specific state based on just this value. It
237
- should be either a simple keyword for a viewstate or else a pseudo-querystring.
238
- * historyData (optional):
239
- This is for complex data that is relevant only to the current browsing session. It will be available
240
- to your application until the browser is closed. If the user comes back to a bookmarked history point
241
- during a later session, this data will no longer be available. Don't rely on it for application
242
- re-initialization from a bookmark.
243
- * historyData.newTitle (optional):
244
- This will swap out the html <title> attribute with a new value. If you have set a baseTitle using the
245
- options bundle, the value will be plugged into the baseTitle by swapping out the @@@ replacement param.
246
- */
247
- add: function(newLocation, historyData) {
248
-
249
- var that = this;
250
-
251
- /*Escape the location and remove any leading hash symbols*/
252
- var encodedLocation = encodeURI(this.removeHash(newLocation));
253
-
254
- if (this.isSafari) {
255
-
256
- /*Store the history data into history storage - pass in unencoded newLocation since
257
- historyStorage does its own encoding*/
258
- historyStorage.put(newLocation, historyData);
259
-
260
- /*Save this as our current location*/
261
- this.currentLocation = encodedLocation;
262
-
263
- /*Change the browser location*/
264
- window.location.hash = encodedLocation;
265
-
266
- /*Save this to the Safari form field*/
267
- this.putSafariState(encodedLocation);
268
-
269
- this.changeTitle(historyData);
270
-
271
- } else {
272
-
273
- /*Most browsers require that we wait a certain amount of time before changing the location, such
274
- as 200 MS; rather than forcing external callers to use window.setTimeout to account for this,
275
- we internally handle it by putting requests in a queue.*/
276
- var addImpl = function() {
277
-
278
- /*Indicate that the current wait time is now less*/
279
- if (that.currentWaitTime > 0) {
280
- that.currentWaitTime = that.currentWaitTime - that.waitTime;
281
- }
282
-
283
- /*IE has a strange bug; if the encodedLocation is the same as _any_ preexisting id in the
284
- document, then the history action gets recorded twice; throw a programmer exception if
285
- there is an element with this ID*/
286
- if (document.getElementById(encodedLocation) && that.debugMode) {
287
- var e = "Exception: History locations can not have the same value as _any_ IDs that might be in the document,"
288
- + " due to a bug in IE; please ask the developer to choose a history location that does not match any HTML"
289
- + " IDs in this document. The following ID is already taken and cannot be a location: " + newLocation;
290
- throw new Error(e);
291
- }
292
-
293
- /*Store the history data into history storage - pass in unencoded newLocation since
294
- historyStorage does its own encoding*/
295
- historyStorage.put(newLocation, historyData);
296
-
297
- /*Indicate to the browser to ignore this upcomming location change since we're making it programmatically*/
298
- that.ignoreLocationChange = true;
299
-
300
- /*Indicate to IE that this is an atomic location change block*/
301
- that.ieAtomicLocationChange = true;
302
-
303
- /*Save this as our current location*/
304
- that.currentLocation = encodedLocation;
305
-
306
- /*Change the browser location*/
307
- window.location.hash = encodedLocation;
308
-
309
- /*Change the hidden iframe's location if on IE*/
310
- if (that.isIE) {
311
- that.iframe.src = that.blankURL + encodedLocation;
312
- }
313
-
314
- /*End of atomic location change block for IE*/
315
- that.ieAtomicLocationChange = false;
316
-
317
- that.changeTitle(historyData);
318
-
319
- };
320
-
321
- /*Now queue up this add request*/
322
- window.setTimeout(addImpl, this.currentWaitTime);
323
-
324
- /*Indicate that the next request will have to wait for awhile*/
325
- this.currentWaitTime = this.currentWaitTime + this.waitTime;
326
- }
327
- },
328
-
329
- /*Public*/
330
- isFirstLoad: function() {
331
- return this.firstLoad;
332
- },
333
-
334
- /*Public*/
335
- getVersion: function() {
336
- return this.VERSIONNUMBER;
337
- },
338
-
339
- /*- - - - - - - - - - - -*/
340
-
341
- /*Private: Constant for our own internal history event called when the page is loaded*/
342
- PAGELOADEDSTRING: "DhtmlHistory_pageLoaded",
343
-
344
- VERSIONNUMBER: "0.8",
345
-
346
- /*
347
- Private: Pattern for title changes. Example: "Armchair DJ [@@@]" where @@@ will be relaced by values passed to add();
348
- Default is just the title itself, hence "@@@"
349
- */
350
- baseTitle: "@@@",
351
-
352
- /*Private: Placeholder variable for the original document title; will be set in ititialize()*/
353
- originalTitle: null,
354
-
355
- /*Private: URL for the blank html file we use for IE; can be overridden via the options bundle. Otherwise it must be served
356
- in same directory as this library*/
357
- blankURL: "/blank.html?",
358
-
359
- /*Private: Our history change listener.*/
360
- listener: null,
361
-
362
- /*Private: MS to wait between add requests - will be reset for certain browsers*/
363
- waitTime: 200,
364
-
365
- /*Private: MS before an add request can execute*/
366
- currentWaitTime: 0,
367
-
368
- /*Private: Our current hash location, without the "#" symbol.*/
369
- currentLocation: null,
370
-
371
- /*Private: Hidden iframe used to IE to detect history changes*/
372
- iframe: null,
373
-
374
- /*Private: Flags and DOM references used only by Safari*/
375
- safariHistoryStartPoint: null,
376
- safariStack: null,
377
- safariLength: null,
378
-
379
- /*Private: Flag used to keep checkLocation() from doing anything when it discovers location changes we've made ourselves
380
- programmatically with the add() method. Basically, add() sets this to true. When checkLocation() discovers it's true,
381
- it refrains from firing our listener, then resets the flag to false for next cycle. That way, our listener only gets fired on
382
- history change events triggered by the user via back/forward buttons and manual hash changes. This flag also helps us set up
383
- IE's special iframe-based method of handling history changes.*/
384
- ignoreLocationChange: null,
385
-
386
- /*Private: A flag that indicates that we should fire a history change event when we are ready, i.e. after we are initialized and
387
- we have a history change listener. This is needed due to an edge case in browsers other than IE; if you leave a page entirely
388
- then return, we must fire this as a history change event. Unfortunately, we have lost all references to listeners from earlier,
389
- because JavaScript clears out.*/
390
- fireOnNewListener: null,
391
-
392
- /*Private: A variable that indicates whether this is the first time this page has been loaded. If you go to a web page, leave it
393
- for another one, and then return, the page's onload listener fires again. We need a way to differentiate between the first page
394
- load and subsequent ones. This variable works hand in hand with the pageLoaded variable we store into historyStorage.*/
395
- firstLoad: null,
396
-
397
- /*Private: A variable to handle an important edge case in IE. In IE, if a user manually types an address into their browser's
398
- location bar, we must intercept this by calling checkLocation() at regular intervals. However, if we are programmatically
399
- changing the location bar ourselves using the add() method, we need to ignore these changes in checkLocation(). Unfortunately,
400
- these changes take several lines of code to complete, so for the duration of those lines of code, we set this variable to true.
401
- That signals to checkLocation() to ignore the change-in-progress. Once we're done with our chunk of location-change code in
402
- add(), we set this back to false. We'll do the same thing when capturing user-entered address changes in checkLocation itself.*/
403
- ieAtomicLocationChange: null,
404
-
405
- /*Private: Generic utility function for attaching events*/
406
- addEventListener: function(o,e,l) {
407
- if (o.addEventListener) {
408
- o.addEventListener(e,l,false);
409
- } else if (o.attachEvent) {
410
- o.attachEvent('on'+e,function() {
411
- l(window.event);
412
- });
413
- }
414
- },
415
-
416
-
417
- /*Private: Create IE-specific DOM nodes and overrides*/
418
- createIE: function(initialHash) {
419
- /*write out a hidden iframe for IE and set the amount of time to wait between add() requests*/
420
- this.waitTime = 400;/*IE needs longer between history updates*/
421
- var styles = (historyStorage.debugMode
422
- ? 'width: 800px;height:80px;border:1px solid black;'
423
- : historyStorage.hideStyles
424
- );
425
- var iframeID = "rshHistoryFrame";
426
- var iframeHTML = '<iframe frameborder="0" id="' + iframeID + '" style="' + styles + '" src="' + this.blankURL + initialHash + '"></iframe>';
427
- document.write(iframeHTML);
428
- this.iframe = document.getElementById(iframeID);
429
- },
430
-
431
- /*Private: Create Opera-specific DOM nodes and overrides*/
432
- createOpera: function() {
433
- this.waitTime = 400;/*Opera needs longer between history updates*/
434
- var imgHTML = '<img src="javascript:location.href=\'javascript:dhtmlHistory.checkLocation();\';" style="' + historyStorage.hideStyles + '" />';
435
- document.write(imgHTML);
436
- },
437
-
438
- /*Private: Create Safari-specific DOM nodes and overrides*/
439
- createSafari: function() {
440
- var formID = "rshSafariForm";
441
- var stackID = "rshSafariStack";
442
- var lengthID = "rshSafariLength";
443
- var formStyles = historyStorage.debugMode ? historyStorage.showStyles : historyStorage.hideStyles;
444
- var stackStyles = (historyStorage.debugMode
445
- ? 'width: 800px;height:80px;border:1px solid black;'
446
- : historyStorage.hideStyles
447
- );
448
- var lengthStyles = (historyStorage.debugMode
449
- ? 'width:800px;height:20px;border:1px solid black;margin:0;padding:0;'
450
- : historyStorage.hideStyles
451
- );
452
- var safariHTML = '<form id="' + formID + '" style="' + formStyles + '">'
453
- + '<textarea style="' + stackStyles + '" id="' + stackID + '">[]</textarea>'
454
- + '<input type="text" style="' + lengthStyles + '" id="' + lengthID + '" value=""/>'
455
- + '</form>';
456
- document.write(safariHTML);
457
- this.safariStack = document.getElementById(stackID);
458
- this.safariLength = document.getElementById(lengthID);
459
- if (!historyStorage.hasKey(this.PAGELOADEDSTRING)) {
460
- this.safariHistoryStartPoint = history.length;
461
- this.safariLength.value = this.safariHistoryStartPoint;
462
- } else {
463
- this.safariHistoryStartPoint = this.safariLength.value;
464
- }
465
- },
466
-
467
- /*TODO: make this public again?*/
468
- /*Private: Get browser's current hash location; for Safari, read value from a hidden form field*/
469
- getCurrentLocation: function() {
470
- var r = (this.isSafari
471
- ? this.getSafariState()
472
- : this.getCurrentHash()
473
- );
474
- return r;
475
- },
476
-
477
- /*TODO: make this public again?*/
478
- /*Private: Manually parse the current url for a hash; tip of the hat to YUI*/
479
- getCurrentHash: function() {
480
- var r = window.location.href;
481
- var i = r.indexOf("#");
482
- return (i >= 0
483
- ? r.substr(i+1)
484
- : ""
485
- );
486
- },
487
-
488
- /*Private: Safari method to read the history stack from a hidden form field*/
489
- getSafariStack: function() {
490
- var r = this.safariStack.value;
491
- return historyStorage.fromJSON(r);
492
- },
493
- /*Private: Safari method to read from the history stack*/
494
- getSafariState: function() {
495
- var stack = this.getSafariStack();
496
- var state = stack[history.length - this.safariHistoryStartPoint - 1];
497
- return state;
498
- },
499
- /*Private: Safari method to write the history stack to a hidden form field*/
500
- putSafariState: function(newLocation) {
501
- var stack = this.getSafariStack();
502
- stack[history.length - this.safariHistoryStartPoint] = newLocation;
503
- this.safariStack.value = historyStorage.toJSON(stack);
504
- },
505
-
506
- /*Private: Notify the listener of new history changes.*/
507
- fireHistoryEvent: function(newHash) {
508
- var decodedHash = decodeURI(newHash)
509
- /*extract the value from our history storage for this hash*/
510
- var historyData = historyStorage.get(decodedHash);
511
- this.changeTitle(historyData);
512
- /*call our listener*/
513
- this.listener.call(null, decodedHash, historyData);
514
- },
515
-
516
- /*Private: See if the browser has changed location. This is the primary history mechanism for Firefox. For IE, we use this to
517
- handle an important edge case: if a user manually types in a new hash value into their IE location bar and press enter, we want to
518
- to intercept this and notify any history listener.*/
519
- checkLocation: function() {
520
-
521
- /*Ignore any location changes that we made ourselves for browsers other than IE*/
522
- if (!this.isIE && this.ignoreLocationChange) {
523
- this.ignoreLocationChange = false;
524
- return;
525
- }
526
-
527
- /*If we are dealing with IE and we are in the middle of making a location change from an iframe, ignore it*/
528
- if (!this.isIE && this.ieAtomicLocationChange) {
529
- return;
530
- }
531
-
532
- /*Get hash location*/
533
- var hash = this.getCurrentLocation();
534
-
535
- /*Do nothing if there's been no change*/
536
- if (hash == this.currentLocation) {
537
- return;
538
- }
539
-
540
- /*In IE, users manually entering locations into the browser; we do this by comparing the browser's location against the
541
- iframe's location; if they differ, we are dealing with a manual event and need to place it inside our history, otherwise
542
- we can return*/
543
- this.ieAtomicLocationChange = true;
544
-
545
- if (this.isIE && this.getIframeHash() != hash) {
546
- this.iframe.src = this.blankURL + hash;
547
- }
548
- else if (this.isIE) {
549
- /*the iframe is unchanged*/
550
- return;
551
- }
552
-
553
- /*Save this new location*/
554
- this.currentLocation = hash;
555
-
556
- this.ieAtomicLocationChange = false;
557
-
558
- /*Notify listeners of the change*/
559
- this.fireHistoryEvent(hash);
560
- },
561
-
562
- /*Private: Get the current location of IE's hidden iframe.*/
563
- getIframeHash: function() {
564
- var doc = this.iframe.contentWindow.document;
565
- var hash = String(doc.location.search);
566
- if (hash.length == 1 && hash.charAt(0) == "?") {
567
- hash = "";
568
- }
569
- else if (hash.length >= 2 && hash.charAt(0) == "?") {
570
- hash = hash.substring(1);
571
- }
572
- return hash;
573
- },
574
-
575
- /*Private: Remove any leading hash that might be on a location.*/
576
- removeHash: function(hashValue) {
577
- var r;
578
- if (hashValue === null || hashValue === undefined) {
579
- r = null;
580
- }
581
- else if (hashValue === "") {
582
- r = "";
583
- }
584
- else if (hashValue.length == 1 && hashValue.charAt(0) == "#") {
585
- r = "";
586
- }
587
- else if (hashValue.length > 1 && hashValue.charAt(0) == "#") {
588
- r = hashValue.substring(1);
589
- }
590
- else {
591
- r = hashValue;
592
- }
593
- return r;
594
- },
595
-
596
- /*Private: For IE, tell when the hidden iframe has finished loading.*/
597
- iframeLoaded: function(newLocation) {
598
- /*ignore any location changes that we made ourselves*/
599
- if (this.ignoreLocationChange) {
600
- this.ignoreLocationChange = false;
601
- return;
602
- }
603
-
604
- /*Get the new location*/
605
- var hash = String(newLocation.search);
606
- if (hash.length == 1 && hash.charAt(0) == "?") {
607
- hash = "";
608
- }
609
- else if (hash.length >= 2 && hash.charAt(0) == "?") {
610
- hash = hash.substring(1);
611
- }
612
- /*Keep the browser location bar in sync with the iframe hash*/
613
- window.location.hash = hash;
614
-
615
- /*Notify listeners of the change*/
616
- this.fireHistoryEvent(hash);
617
- }
618
-
619
-
620
- };
621
-
622
- /*
623
- historyStorage: An object that uses a hidden form to store history state across page loads. The mechanism for doing so relies on
624
- the fact that browsers save the text in form data for the life of the browser session, which means the text is still there when
625
- the user navigates back to the page. This object can be used independently of the dhtmlHistory object for caching of Ajax
626
- session information.
627
-
628
- dependencies:
629
- * json2007.js (included in a separate file) or alternate JSON methods passed in through an options bundle.
630
- */
631
- window.historyStorage = {
632
-
633
- /*Public: Set up our historyStorage object for use by dhtmlHistory or other objects*/
634
- setup: function(options) {
635
-
636
- /*
637
- options - object to store initialization parameters - passed in from dhtmlHistory or directly into historyStorage
638
- options.debugMode - boolean that causes hidden form fields to be shown for development purposes.
639
- options.toJSON - function to override default JSON stringifier
640
- options.fromJSON - function to override default JSON parser
641
- */
642
-
643
- /*process init parameters*/
644
- if (typeof options !== "undefined") {
645
- if (options.debugMode) {
646
- this.debugMode = options.debugMode;
647
- }
648
- if (options.toJSON) {
649
- this.toJSON = options.toJSON;
650
- }
651
- if (options.fromJSON) {
652
- this.fromJSON = options.fromJSON;
653
- }
654
- }
655
-
656
- /*write a hidden form and textarea into the page; we'll stow our history stack here*/
657
- var formID = "rshStorageForm";
658
- var textareaID = "rshStorageField";
659
- var formStyles = this.debugMode ? historyStorage.showStyles : historyStorage.hideStyles;
660
- var textareaStyles = (historyStorage.debugMode
661
- ? 'width: 800px;height:80px;border:1px solid black;'
662
- : historyStorage.hideStyles
663
- );
664
- var textareaHTML = '<form id="' + formID + '" style="' + formStyles + '">'
665
- + '<textarea id="' + textareaID + '" style="' + textareaStyles + '"></textarea>'
666
- + '</form>';
667
- document.write(textareaHTML);
668
- this.storageField = document.getElementById(textareaID);
669
- if (typeof window.opera !== "undefined") {
670
- this.storageField.focus();/*Opera needs to focus this element before persisting values in it*/
671
- }
672
- },
673
-
674
- /*Public*/
675
- put: function(key, value) {
676
-
677
- var encodedKey = encodeURI(key);
678
-
679
- this.assertValidKey(encodedKey);
680
- /*if we already have a value for this, remove the value before adding the new one*/
681
- if (this.hasKey(key)) {
682
- this.remove(key);
683
- }
684
- /*store this new key*/
685
- this.storageHash[encodedKey] = value;
686
- /*save and serialize the hashtable into the form*/
687
- this.saveHashTable();
688
- },
689
-
690
- /*Public*/
691
- get: function(key) {
692
-
693
- var encodedKey = encodeURI(key);
694
-
695
- this.assertValidKey(encodedKey);
696
- /*make sure the hash table has been loaded from the form*/
697
- this.loadHashTable();
698
- var value = this.storageHash[encodedKey];
699
- if (value === undefined) {
700
- value = null;
701
- }
702
- return value;
703
- },
704
-
705
- /*Public*/
706
- remove: function(key) {
707
-
708
- var encodedKey = encodeURI(key);
709
-
710
- this.assertValidKey(encodedKey);
711
- /*make sure the hash table has been loaded from the form*/
712
- this.loadHashTable();
713
- /*delete the value*/
714
- delete this.storageHash[encodedKey];
715
- /*serialize and save the hash table into the form*/
716
- this.saveHashTable();
717
- },
718
-
719
- /*Public: Clears out all saved data.*/
720
- reset: function() {
721
- this.storageField.value = "";
722
- this.storageHash = {};
723
- },
724
-
725
- /*Public*/
726
- hasKey: function(key) {
727
-
728
- var encodedKey = encodeURI(key);
729
-
730
- this.assertValidKey(encodedKey);
731
- /*make sure the hash table has been loaded from the form*/
732
- this.loadHashTable();
733
- return (typeof this.storageHash[encodedKey] !== "undefined");
734
- },
735
-
736
- /*Public*/
737
- isValidKey: function(key) {
738
- return (typeof key === "string");
739
- //TODO - should we ban hash signs and other special characters?
740
- },
741
-
742
- /*- - - - - - - - - - - -*/
743
-
744
- /*Private - CSS strings utilized by both objects to hide or show behind-the-scenes DOM elements*/
745
- showStyles: 'border:0;margin:0;padding:0;',
746
- hideStyles: 'left:-1000px;top:-1000px;width:1px;height:1px;border:0;position:absolute;',
747
-
748
- /*Private - debug mode flag*/
749
- debugMode: false,
750
-
751
- /*Private: Our hash of key name/values.*/
752
- storageHash: {},
753
-
754
- /*Private: If true, we have loaded our hash table out of the storage form.*/
755
- hashLoaded: false,
756
-
757
- /*Private: DOM reference to our history field*/
758
- storageField: null,
759
-
760
- /*Private: Assert that a key is valid; throw an exception if it not.*/
761
- assertValidKey: function(key) {
762
- var isValid = this.isValidKey(key);
763
- if (!isValid && this.debugMode) {
764
- throw new Error("Please provide a valid key for window.historyStorage. Invalid key = " + key + ".");
765
- }
766
- },
767
-
768
- /*Private: Load the hash table up from the form.*/
769
- loadHashTable: function() {
770
- if (!this.hashLoaded) {
771
- var serializedHashTable = this.storageField.value;
772
- if (serializedHashTable !== "" && serializedHashTable !== null) {
773
- this.storageHash = this.fromJSON(serializedHashTable);
774
- this.hashLoaded = true;
775
- }
776
- }
777
- },
778
- /*Private: Save the hash table into the form.*/
779
- saveHashTable: function() {
780
- this.loadHashTable();
781
- var serializedHashTable = this.toJSON(this.storageHash);
782
- this.storageField.value = serializedHashTable;
783
- },
784
- /*Private: Bridges for our JSON implementations - both rely on 2007 JSON.org library - can be overridden by options bundle*/
785
- toJSON: function(o) {
786
- return o.toJSONString();
787
- },
788
- fromJSON: function(s) {
789
- return s.parseJSON();
790
- }
791
- };
792
-
793
-
794
- /*******************************************************************/
795
- /** QueryString Object from http://adamv.com/dev/javascript/querystring */
796
- /* Client-side access to querystring name=value pairs
797
- Version 1.3
798
- 28 May 2008
799
-
800
- License (Simplified BSD):
801
- http://adamv.com/dev/javascript/qslicense.txt
802
- */
803
- function Querystring(qs) { // optionally pass a querystring to parse
804
- this.params = {};
805
-
806
- if (qs == null) qs = location.search.substring(1, location.search.length);
807
- if (qs.length == 0) return;
808
-
809
- // Turn <plus> back to <space>
810
- // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
811
- qs = qs.replace(/\+/g, ' ');
812
- var args = qs.split('&'); // parse out name/value pairs separated via &
813
-
814
- // split out each name=value pair
815
- for (var i = 0; i < args.length; i++) {
816
- var pair = args[i].split('=');
817
- var name = decodeURI(pair[0]);
818
-
819
- var value = (pair.length==2)
820
- ? decodeURI(pair[1])
821
- : name;
822
-
823
- this.params[name] = value;
824
- }
825
- }
826
-
827
- Querystring.prototype.get = function(key, default_) {
828
- var value = this.params[key];
829
- return (value != null) ? value : default_;
830
- }
831
-
832
- Querystring.prototype.contains = function(key) {
833
- var value = this.params[key];
834
- return (value != null);
835
- }
836
-
837
- /*******************************************************************/
838
- /* Added by Ed Wildgoose - MailASail */
839
- /* Initialise the library and add our history callback */
840
- /*******************************************************************/
841
- window.dhtmlHistory.create({
842
- toJSON: function(o) {
843
- return Object.toJSON(o);
844
- }
845
- , fromJSON: function(s) {
846
- return s.evalJSON();
847
- }
848
-
849
- // Enable this to assist with debugging
850
- // , debugMode: true
851
-
852
- // dhtmlHistory has been modified not to need the next line
853
- // But left in for robustness when updating dhtmlHistory
854
- , blankURL: '/blank.html?'
855
- });
856
-
857
- /** Our callback to receive history
858
- change events. */
859
- var handleHistoryChange = function(pageId, pageData) {
860
- if (!pageData) return;
861
- var info = pageId.split(':');
862
- var id = info[0];
863
- pageData += '&_method=get';
864
- new Ajax.Request(pageData, {asynchronous:true, evalScripts:true, method: 'get', onLoading:function(request){Element.show(id+'-pagination-loading-indicator');}});
865
- }
866
-
867
- window.onload = function() {
868
- dhtmlHistory.initialize(handleHistoryChange);
869
- };
870
-