surveillance 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (276) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +42 -0
  4. data/Rakefile +23 -0
  5. data/app/assets/javascripts/surveillance.js +6 -0
  6. data/app/assets/javascripts/surveillance/admin.coffee +4 -0
  7. data/app/assets/javascripts/surveillance/admin/matrix-questions.coffee +18 -0
  8. data/app/assets/javascripts/surveillance/application.js +17 -0
  9. data/app/assets/javascripts/surveillance/collections/branch_rule_collection.coffee +2 -0
  10. data/app/assets/javascripts/surveillance/form.coffee +7 -0
  11. data/app/assets/javascripts/surveillance/manifest.coffee +7 -0
  12. data/app/assets/javascripts/surveillance/models/branch_rule.coffee +21 -0
  13. data/app/assets/javascripts/surveillance/models/question.coffee +19 -0
  14. data/app/assets/javascripts/surveillance/models/questions/choosable_question.coffee +15 -0
  15. data/app/assets/javascripts/surveillance/models/questions/matrix.coffee +19 -0
  16. data/app/assets/javascripts/surveillance/models/questions/matrix_question.coffee +7 -0
  17. data/app/assets/javascripts/surveillance/models/questions/number.coffee +17 -0
  18. data/app/assets/javascripts/surveillance/vendor/backbone.min.js +1 -0
  19. data/app/assets/javascripts/surveillance/vendor/bootstrap.js +2118 -0
  20. data/app/assets/javascripts/surveillance/vendor/jquery-ui-sortable.js +2256 -0
  21. data/app/assets/javascripts/surveillance/vendor/jquery.scrollto.js +210 -0
  22. data/app/assets/javascripts/surveillance/vendor/underscore.min.js +5 -0
  23. data/app/assets/javascripts/surveillance/views/attempt_view.coffee +74 -0
  24. data/app/assets/javascripts/surveillance/views/question_view.coffee +53 -0
  25. data/app/assets/javascripts/surveillance/views/questions/choice_view.coffee +52 -0
  26. data/app/assets/javascripts/surveillance/views/questions/matrix_question_view.coffee +26 -0
  27. data/app/assets/javascripts/surveillance/views/questions/matrix_view.coffee +21 -0
  28. data/app/assets/javascripts/surveillance/views/questions/number_view.coffee +19 -0
  29. data/app/assets/javascripts/surveillance/views/questions/order.coffee +9 -0
  30. data/app/assets/javascripts/surveillance/views/questions/select_matrix_view.coffee +31 -0
  31. data/app/assets/javascripts/surveillance/views/section_view.coffee +54 -0
  32. data/app/assets/stylesheets/surveillance/admin.sass +1 -0
  33. data/app/assets/stylesheets/surveillance/application.css +14 -0
  34. data/app/assets/stylesheets/surveillance/fonts/glyphicons-halflings-regular.eot +0 -0
  35. data/app/assets/stylesheets/surveillance/fonts/glyphicons-halflings-regular.svg +229 -0
  36. data/app/assets/stylesheets/surveillance/fonts/glyphicons-halflings-regular.ttf +0 -0
  37. data/app/assets/stylesheets/surveillance/fonts/glyphicons-halflings-regular.woff +0 -0
  38. data/app/assets/stylesheets/surveillance/overrides.sass +2 -0
  39. data/app/assets/stylesheets/surveillance/vendor/bootstrap.css +6175 -0
  40. data/app/controllers/concerns/surveillance/attempts_management_concern.rb +51 -0
  41. data/app/controllers/concerns/surveillance/base_controller_concern.rb +37 -0
  42. data/app/controllers/surveillance/admin/attempts_controller.rb +38 -0
  43. data/app/controllers/surveillance/admin/base_controller.rb +15 -0
  44. data/app/controllers/surveillance/admin/exports_controller.rb +24 -0
  45. data/app/controllers/surveillance/admin/options_controller.rb +44 -0
  46. data/app/controllers/surveillance/admin/questions_controller.rb +59 -0
  47. data/app/controllers/surveillance/admin/sections_controller.rb +46 -0
  48. data/app/controllers/surveillance/admin/surveys_controller.rb +43 -0
  49. data/app/controllers/surveillance/application_controller.rb +7 -0
  50. data/app/controllers/surveillance/response/attempts_controller.rb +50 -0
  51. data/app/controllers/surveillance/response/base_controller.rb +38 -0
  52. data/app/controllers/surveillance/response/partial_attempts_controller.rb +15 -0
  53. data/app/controllers/surveillance/surveys_controller.rb +6 -0
  54. data/app/helpers/surveillance/admin/exports_helper.rb +37 -0
  55. data/app/helpers/surveillance/application_helper.rb +84 -0
  56. data/app/models/surveillance/answer.rb +56 -0
  57. data/app/models/surveillance/answer_content.rb +7 -0
  58. data/app/models/surveillance/attempt.rb +146 -0
  59. data/app/models/surveillance/branch_rule.rb +52 -0
  60. data/app/models/surveillance/field_setting.rb +6 -0
  61. data/app/models/surveillance/option.rb +18 -0
  62. data/app/models/surveillance/question.rb +50 -0
  63. data/app/models/surveillance/section.rb +16 -0
  64. data/app/models/surveillance/survey.rb +38 -0
  65. data/app/views/layouts/surveillance/application.html.haml +11 -0
  66. data/app/views/surveillance/admin/attempts/index.html.haml +47 -0
  67. data/app/views/surveillance/admin/attempts/list.html.haml +11 -0
  68. data/app/views/surveillance/admin/attempts/overview.html.haml +6 -0
  69. data/app/views/surveillance/admin/attempts/show.html.haml +62 -0
  70. data/app/views/surveillance/admin/exports/show.rxls +39 -0
  71. data/app/views/surveillance/admin/options/_field.html.haml +11 -0
  72. data/app/views/surveillance/admin/options/_form.html.haml +8 -0
  73. data/app/views/surveillance/admin/options/_list.html.haml +10 -0
  74. data/app/views/surveillance/admin/options/_option.html.haml +13 -0
  75. data/app/views/surveillance/admin/options/edit.html.haml +7 -0
  76. data/app/views/surveillance/admin/options/new.html.haml +7 -0
  77. data/app/views/surveillance/admin/questions/_form.html.haml +35 -0
  78. data/app/views/surveillance/admin/questions/_list.html.haml +17 -0
  79. data/app/views/surveillance/admin/questions/_question.html.haml +27 -0
  80. data/app/views/surveillance/admin/questions/edit.html.haml +7 -0
  81. data/app/views/surveillance/admin/questions/new.html.haml +4 -0
  82. data/app/views/surveillance/admin/sections/_form.html.haml +16 -0
  83. data/app/views/surveillance/admin/sections/_list.html.haml +13 -0
  84. data/app/views/surveillance/admin/sections/_section.html.haml +16 -0
  85. data/app/views/surveillance/admin/sections/edit.html.haml +7 -0
  86. data/app/views/surveillance/admin/sections/new.html.haml +4 -0
  87. data/app/views/surveillance/admin/surveys/_form.html.haml +22 -0
  88. data/app/views/surveillance/admin/surveys/_list.html.haml +13 -0
  89. data/app/views/surveillance/admin/surveys/_survey.html.haml +32 -0
  90. data/app/views/surveillance/admin/surveys/edit.html.haml +7 -0
  91. data/app/views/surveillance/admin/surveys/index.html.haml +1 -0
  92. data/app/views/surveillance/admin/surveys/new.html.haml +4 -0
  93. data/app/views/surveillance/field/date/_form.html.haml +5 -0
  94. data/app/views/surveillance/field/date/_overview.html.haml +2 -0
  95. data/app/views/surveillance/field/date/_show.html.haml +10 -0
  96. data/app/views/surveillance/field/matrix/_form.html.haml +40 -0
  97. data/app/views/surveillance/field/matrix/_overview.html.haml +19 -0
  98. data/app/views/surveillance/field/matrix/_questions_fields.html.haml +11 -0
  99. data/app/views/surveillance/field/matrix/_settings.html.haml +18 -0
  100. data/app/views/surveillance/field/matrix/_show.html.haml +22 -0
  101. data/app/views/surveillance/field/multiple_choices/_form.html.haml +18 -0
  102. data/app/views/surveillance/field/multiple_choices/_settings.html.haml +21 -0
  103. data/app/views/surveillance/field/multiple_choices/_show.html.haml +21 -0
  104. data/app/views/surveillance/field/multiple_choices_matrix/_form.html.haml +33 -0
  105. data/app/views/surveillance/field/multiple_choices_matrix/_show.html.haml +1 -0
  106. data/app/views/surveillance/field/number/_form.html.haml +5 -0
  107. data/app/views/surveillance/field/number/_overview.html.haml +2 -0
  108. data/app/views/surveillance/field/number/_settings.html.haml +2 -0
  109. data/app/views/surveillance/field/number/_show.html.haml +10 -0
  110. data/app/views/surveillance/field/order/_form.html.haml +17 -0
  111. data/app/views/surveillance/field/order/_overview.html.haml +22 -0
  112. data/app/views/surveillance/field/order/_settings.html.haml +11 -0
  113. data/app/views/surveillance/field/order/_show.html.haml +8 -0
  114. data/app/views/surveillance/field/select_matrix/_form.html.haml +17 -0
  115. data/app/views/surveillance/field/shared/_rules_form.html.haml +30 -0
  116. data/app/views/surveillance/field/shared/settings/_boolean.html.haml +9 -0
  117. data/app/views/surveillance/field/shared/settings/_number.html.haml +5 -0
  118. data/app/views/surveillance/field/single_choice/_form.html.haml +16 -0
  119. data/app/views/surveillance/field/single_choice/_overview.html.haml +14 -0
  120. data/app/views/surveillance/field/single_choice/_settings.html.haml +2 -0
  121. data/app/views/surveillance/field/single_choice/_show.html.haml +21 -0
  122. data/app/views/surveillance/field/single_select/_form.html.haml +4 -0
  123. data/app/views/surveillance/field/single_select/_overview.html.haml +14 -0
  124. data/app/views/surveillance/field/single_select/_show.html.haml +13 -0
  125. data/app/views/surveillance/field/text/_form.html.haml +5 -0
  126. data/app/views/surveillance/field/text/_overview.html.haml +2 -0
  127. data/app/views/surveillance/field/text/_show.html.haml +10 -0
  128. data/app/views/surveillance/field/text_area/_form.html.haml +5 -0
  129. data/app/views/surveillance/field/text_area/_overview.html.haml +1 -0
  130. data/app/views/surveillance/field/text_area/_show.html.haml +10 -0
  131. data/app/views/surveillance/response/attempts/complete.html.haml +11 -0
  132. data/app/views/surveillance/response/attempts/edit.html.haml +15 -0
  133. data/app/views/surveillance/sections/_section.html.haml +24 -0
  134. data/app/views/surveillance/surveys/_survey.html.haml +4 -0
  135. data/app/views/surveillance/surveys/index.html.haml +8 -0
  136. data/app/views/surveillance/surveys/show.html.haml +15 -0
  137. data/config/locales/surveillance.fr.yml +165 -0
  138. data/config/routes.rb +30 -0
  139. data/db/migrate/20130626115136_create_surveillance_surveys.rb +13 -0
  140. data/db/migrate/20130626115805_create_surveillance_sections.rb +12 -0
  141. data/db/migrate/20130626130351_create_surveillance_questions.rb +14 -0
  142. data/db/migrate/20130702111125_create_surveillance_options.rb +11 -0
  143. data/db/migrate/20130703113456_create_surveillance_attempts.rb +11 -0
  144. data/db/migrate/20130703115649_create_surveillance_answers.rb +11 -0
  145. data/db/migrate/20130703115723_create_surveillance_answer_contents.rb +10 -0
  146. data/db/migrate/20130710151627_create_surveillance_field_settings.rb +11 -0
  147. data/db/migrate/20130711100032_create_surveillance_answers_options_join_table.rb +7 -0
  148. data/db/migrate/20130729143002_create_surveillance_branch_rules.rb +14 -0
  149. data/db/migrate/20140212153506_add_state_to_surveillance_attempts.rb +6 -0
  150. data/db/migrate/20140213101147_add_access_token_to_surveillance_attempts.rb +5 -0
  151. data/db/migrate/20140213133036_add_partial_to_surveillance_questions.rb +5 -0
  152. data/lib/generators/surveillance/install/install_generator.rb +34 -0
  153. data/lib/generators/surveillance/install/templates/initializer.rb +51 -0
  154. data/lib/surveillance.rb +61 -0
  155. data/lib/surveillance/branch_action.rb +5 -0
  156. data/lib/surveillance/branch_condition.rb +5 -0
  157. data/lib/surveillance/engine.rb +13 -0
  158. data/lib/surveillance/field.rb +58 -0
  159. data/lib/surveillance/field/base.rb +149 -0
  160. data/lib/surveillance/field/date.rb +17 -0
  161. data/lib/surveillance/field/matrix.rb +66 -0
  162. data/lib/surveillance/field/matrix_question.rb +13 -0
  163. data/lib/surveillance/field/multiple_choices.rb +29 -0
  164. data/lib/surveillance/field/multiple_choices_matrix.rb +13 -0
  165. data/lib/surveillance/field/number.rb +34 -0
  166. data/lib/surveillance/field/order.rb +40 -0
  167. data/lib/surveillance/field/order_question.rb +22 -0
  168. data/lib/surveillance/field/other_choice.rb +28 -0
  169. data/lib/surveillance/field/select_matrix.rb +13 -0
  170. data/lib/surveillance/field/single_choice.rb +36 -0
  171. data/lib/surveillance/field/single_select.rb +31 -0
  172. data/lib/surveillance/field/text.rb +13 -0
  173. data/lib/surveillance/field/text_area.rb +6 -0
  174. data/lib/surveillance/partials_collection.rb +7 -0
  175. data/lib/surveillance/setting.rb +24 -0
  176. data/lib/surveillance/settings_collection.rb +17 -0
  177. data/lib/surveillance/validators.rb +7 -0
  178. data/lib/surveillance/validators/answer_validator.rb +9 -0
  179. data/lib/surveillance/version.rb +3 -0
  180. data/lib/tasks/surveillance_tasks.rake +4 -0
  181. data/spec/dummy/README.rdoc +28 -0
  182. data/spec/dummy/Rakefile +6 -0
  183. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  184. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  185. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  186. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  187. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  188. data/spec/dummy/bin/bundle +3 -0
  189. data/spec/dummy/bin/rails +4 -0
  190. data/spec/dummy/bin/rake +4 -0
  191. data/spec/dummy/config.ru +4 -0
  192. data/spec/dummy/config/application.rb +28 -0
  193. data/spec/dummy/config/boot.rb +5 -0
  194. data/spec/dummy/config/database.yml +25 -0
  195. data/spec/dummy/config/environment.rb +5 -0
  196. data/spec/dummy/config/environments/development.rb +29 -0
  197. data/spec/dummy/config/environments/production.rb +80 -0
  198. data/spec/dummy/config/environments/test.rb +36 -0
  199. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  200. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  201. data/spec/dummy/config/initializers/inflections.rb +16 -0
  202. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  203. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  204. data/spec/dummy/config/initializers/session_store.rb +3 -0
  205. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  206. data/spec/dummy/config/locales/en.yml +23 -0
  207. data/spec/dummy/config/locales/rails.fr.yml +226 -0
  208. data/spec/dummy/config/routes.rb +3 -0
  209. data/spec/dummy/db/development.sqlite3 +0 -0
  210. data/spec/dummy/db/migrate/20140113224541_create_surveillance_surveys.surveillance.rb +14 -0
  211. data/spec/dummy/db/migrate/20140113224542_create_surveillance_sections.surveillance.rb +13 -0
  212. data/spec/dummy/db/migrate/20140113224543_create_surveillance_questions.surveillance.rb +15 -0
  213. data/spec/dummy/db/migrate/20140113224544_create_surveillance_options.surveillance.rb +12 -0
  214. data/spec/dummy/db/migrate/20140113224545_create_surveillance_attempts.surveillance.rb +12 -0
  215. data/spec/dummy/db/migrate/20140113224546_create_surveillance_answers.surveillance.rb +12 -0
  216. data/spec/dummy/db/migrate/20140113224547_create_surveillance_answer_contents.surveillance.rb +11 -0
  217. data/spec/dummy/db/migrate/20140113224548_create_surveillance_field_settings.surveillance.rb +12 -0
  218. data/spec/dummy/db/migrate/20140113224549_create_surveillance_answers_options_join_table.surveillance.rb +8 -0
  219. data/spec/dummy/db/migrate/20140113224550_create_surveillance_branch_rules.surveillance.rb +15 -0
  220. data/spec/dummy/db/schema.rb +103 -0
  221. data/spec/dummy/log/development.log +38066 -0
  222. data/spec/dummy/public/404.html +58 -0
  223. data/spec/dummy/public/422.html +58 -0
  224. data/spec/dummy/public/500.html +57 -0
  225. data/spec/dummy/public/favicon.ico +0 -0
  226. data/spec/dummy/spec +1 -0
  227. data/spec/dummy/tmp/cache/assets/development/sprockets/0018421aaf29044fbd13363bbdfd8f44 +0 -0
  228. data/spec/dummy/tmp/cache/assets/development/sprockets/017d7a30ec05c0fb0265fb5167c73ee9 +0 -0
  229. data/spec/dummy/tmp/cache/assets/development/sprockets/034b76adeb89d6ca63cd9eea649331f5 +0 -0
  230. data/spec/dummy/tmp/cache/assets/development/sprockets/05de8fbfacab66a0efe4f9790b2ac723 +0 -0
  231. data/spec/dummy/tmp/cache/assets/development/sprockets/0811effcff3b9107d49398bdba7488e5 +0 -0
  232. data/spec/dummy/tmp/cache/assets/development/sprockets/0d45beae32861dc508fc2db09b9d95b3 +0 -0
  233. data/spec/dummy/tmp/cache/assets/development/sprockets/0d4961f3da5a0d5234736a6abbf42226 +0 -0
  234. data/spec/dummy/tmp/cache/assets/development/sprockets/0f491ed240e1a27bbc05e5213afd48bb +0 -0
  235. data/spec/dummy/tmp/cache/assets/development/sprockets/10e2a0dbdbb68c055e8b7ccd6f2906d8 +0 -0
  236. data/spec/dummy/tmp/cache/assets/development/sprockets/1173cdef6c662a55ef590489fe26e8fe +0 -0
  237. data/spec/dummy/tmp/cache/assets/development/sprockets/1b3e93127523ec0f3c93bcd91d4390dc +0 -0
  238. data/spec/dummy/tmp/cache/assets/development/sprockets/1bb56fbf17ccbb14dcbaa4d6d639e620 +0 -0
  239. data/spec/dummy/tmp/cache/assets/development/sprockets/2bd0ba6a1598c9fa67081d8f906db6f8 +0 -0
  240. data/spec/dummy/tmp/cache/assets/development/sprockets/3fbe053f103de46cc1b320f059b99c1f +0 -0
  241. data/spec/dummy/tmp/cache/assets/development/sprockets/4144b095447efb810a548b99e41df9eb +0 -0
  242. data/spec/dummy/tmp/cache/assets/development/sprockets/421d097cb8d88f975d8ccf75c9e5e306 +0 -0
  243. data/spec/dummy/tmp/cache/assets/development/sprockets/474bc1c9055df6cc1cdff58817a6cb41 +0 -0
  244. data/spec/dummy/tmp/cache/assets/development/sprockets/4829d251eeb22cdbd05b27b6ba809538 +0 -0
  245. data/spec/dummy/tmp/cache/assets/development/sprockets/4f584ca3f0c8ec62906e6f03bc5963c2 +0 -0
  246. data/spec/dummy/tmp/cache/assets/development/sprockets/55d647d88e01b91b2a146e7db0481c09 +0 -0
  247. data/spec/dummy/tmp/cache/assets/development/sprockets/62db8b5885b79c5dc0667fab0fbf46bb +0 -0
  248. data/spec/dummy/tmp/cache/assets/development/sprockets/7080a4d265fe784c9704db71f81da832 +0 -0
  249. data/spec/dummy/tmp/cache/assets/development/sprockets/7220af243fd39e3dffd233252e4a8c17 +0 -0
  250. data/spec/dummy/tmp/cache/assets/development/sprockets/7cd0e5bfe12b86ed494d02e8e5b62bbf +0 -0
  251. data/spec/dummy/tmp/cache/assets/development/sprockets/7e37a8ae2a50653b388d57c573d12548 +0 -0
  252. data/spec/dummy/tmp/cache/assets/development/sprockets/8113790dad1da8858c82cfc3eb14ef87 +0 -0
  253. data/spec/dummy/tmp/cache/assets/development/sprockets/83997102fc04f275cd6cd8c1ddb55835 +0 -0
  254. data/spec/dummy/tmp/cache/assets/development/sprockets/8a7b047a16adbc640e03eaabe4a4fe93 +0 -0
  255. data/spec/dummy/tmp/cache/assets/development/sprockets/90b48fb4bfa22ddcd063734065d27086 +0 -0
  256. data/spec/dummy/tmp/cache/assets/development/sprockets/935886b24c90d344752d2a80e3657801 +0 -0
  257. data/spec/dummy/tmp/cache/assets/development/sprockets/9606a6d70af63ce3fea26ded0a69d5c2 +0 -0
  258. data/spec/dummy/tmp/cache/assets/development/sprockets/97db73fdf0bbab24fb92892c61ec7a9b +0 -0
  259. data/spec/dummy/tmp/cache/assets/development/sprockets/a23bb60554e715c228ae3cdfb5d81807 +0 -0
  260. data/spec/dummy/tmp/cache/assets/development/sprockets/ad17e102b9f9288a9e919b0b0a2ab05b +0 -0
  261. data/spec/dummy/tmp/cache/assets/development/sprockets/c26ae1f6640b52c232bd392a6e2f7110 +0 -0
  262. data/spec/dummy/tmp/cache/assets/development/sprockets/c6cb3deca0f08bd9569d00fca09272da +0 -0
  263. data/spec/dummy/tmp/cache/assets/development/sprockets/d39b4eebbd0042342e10497a34fd6378 +0 -0
  264. data/spec/dummy/tmp/cache/assets/development/sprockets/d5ee573b2abdcdc245a830bde2dd76f3 +0 -0
  265. data/spec/dummy/tmp/cache/assets/development/sprockets/d6487e59842ff206d84f6de5e3a7400c +0 -0
  266. data/spec/dummy/tmp/cache/assets/development/sprockets/dafa124ddd0e828d7c5c0a5c4db455ba +0 -0
  267. data/spec/dummy/tmp/cache/assets/development/sprockets/e5bbd03518f9abc3e9bc1373c74fd3f1 +0 -0
  268. data/spec/dummy/tmp/cache/assets/development/sprockets/ed5aa255edff522c2e36e6f0151ff747 +0 -0
  269. data/spec/dummy/tmp/cache/assets/development/sprockets/ee263a426f6530013f86aa860448fa91 +0 -0
  270. data/spec/dummy/tmp/cache/assets/development/sprockets/efa0c4d855d425fdf4b63ab26c45e94c +0 -0
  271. data/spec/dummy/tmp/cache/assets/development/sprockets/f2881259fd5bad1c0a5b1ab5dff97c47 +0 -0
  272. data/spec/dummy/tmp/cache/assets/development/sprockets/f34108e540cff2fbc32036da452ca6ae +0 -0
  273. data/spec/dummy/tmp/cache/assets/development/sprockets/f7e7e00ef8efc13c6a2628e453344440 +0 -0
  274. data/spec/dummy/tmp/cache/assets/development/sprockets/f9a44009076e46b0f35af5e7031a1871 +0 -0
  275. data/spec/spec_helper.rb +87 -0
  276. metadata +598 -0
@@ -0,0 +1,210 @@
1
+ /*!
2
+ * jQuery.scrollTo
3
+ * Copyright (c) 2007-2015 Ariel Flesler - aflesler ○ gmail • com | http://flesler.blogspot.com
4
+ * Licensed under MIT
5
+ * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
6
+ * @projectDescription Lightweight, cross-browser and highly customizable animated scrolling with jQuery
7
+ * @author Ariel Flesler
8
+ * @version 2.1.2
9
+ */
10
+ ;(function(factory) {
11
+ 'use strict';
12
+ if (typeof define === 'function' && define.amd) {
13
+ // AMD
14
+ define(['jquery'], factory);
15
+ } else if (typeof module !== 'undefined' && module.exports) {
16
+ // CommonJS
17
+ module.exports = factory(require('jquery'));
18
+ } else {
19
+ // Global
20
+ factory(jQuery);
21
+ }
22
+ })(function($) {
23
+ 'use strict';
24
+
25
+ var $scrollTo = $.scrollTo = function(target, duration, settings) {
26
+ return $(window).scrollTo(target, duration, settings);
27
+ };
28
+
29
+ $scrollTo.defaults = {
30
+ axis:'xy',
31
+ duration: 0,
32
+ limit:true
33
+ };
34
+
35
+ function isWin(elem) {
36
+ return !elem.nodeName ||
37
+ $.inArray(elem.nodeName.toLowerCase(), ['iframe','#document','html','body']) !== -1;
38
+ }
39
+
40
+ $.fn.scrollTo = function(target, duration, settings) {
41
+ if (typeof duration === 'object') {
42
+ settings = duration;
43
+ duration = 0;
44
+ }
45
+ if (typeof settings === 'function') {
46
+ settings = { onAfter:settings };
47
+ }
48
+ if (target === 'max') {
49
+ target = 9e9;
50
+ }
51
+
52
+ settings = $.extend({}, $scrollTo.defaults, settings);
53
+ // Speed is still recognized for backwards compatibility
54
+ duration = duration || settings.duration;
55
+ // Make sure the settings are given right
56
+ var queue = settings.queue && settings.axis.length > 1;
57
+ if (queue) {
58
+ // Let's keep the overall duration
59
+ duration /= 2;
60
+ }
61
+ settings.offset = both(settings.offset);
62
+ settings.over = both(settings.over);
63
+
64
+ return this.each(function() {
65
+ // Null target yields nothing, just like jQuery does
66
+ if (target === null) return;
67
+
68
+ var win = isWin(this),
69
+ elem = win ? this.contentWindow || window : this,
70
+ $elem = $(elem),
71
+ targ = target,
72
+ attr = {},
73
+ toff;
74
+
75
+ switch (typeof targ) {
76
+ // A number will pass the regex
77
+ case 'number':
78
+ case 'string':
79
+ if (/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(targ)) {
80
+ targ = both(targ);
81
+ // We are done
82
+ break;
83
+ }
84
+ // Relative/Absolute selector
85
+ targ = win ? $(targ) : $(targ, elem);
86
+ /* falls through */
87
+ case 'object':
88
+ if (targ.length === 0) return;
89
+ // DOMElement / jQuery
90
+ if (targ.is || targ.style) {
91
+ // Get the real position of the target
92
+ toff = (targ = $(targ)).offset();
93
+ }
94
+ }
95
+
96
+ var offset = $.isFunction(settings.offset) && settings.offset(elem, targ) || settings.offset;
97
+
98
+ $.each(settings.axis.split(''), function(i, axis) {
99
+ var Pos = axis === 'x' ? 'Left' : 'Top',
100
+ pos = Pos.toLowerCase(),
101
+ key = 'scroll' + Pos,
102
+ prev = $elem[key](),
103
+ max = $scrollTo.max(elem, axis);
104
+
105
+ if (toff) {// jQuery / DOMElement
106
+ attr[key] = toff[pos] + (win ? 0 : prev - $elem.offset()[pos]);
107
+
108
+ // If it's a dom element, reduce the margin
109
+ if (settings.margin) {
110
+ attr[key] -= parseInt(targ.css('margin'+Pos), 10) || 0;
111
+ attr[key] -= parseInt(targ.css('border'+Pos+'Width'), 10) || 0;
112
+ }
113
+
114
+ attr[key] += offset[pos] || 0;
115
+
116
+ if (settings.over[pos]) {
117
+ // Scroll to a fraction of its width/height
118
+ attr[key] += targ[axis === 'x'?'width':'height']() * settings.over[pos];
119
+ }
120
+ } else {
121
+ var val = targ[pos];
122
+ // Handle percentage values
123
+ attr[key] = val.slice && val.slice(-1) === '%' ?
124
+ parseFloat(val) / 100 * max
125
+ : val;
126
+ }
127
+
128
+ // Number or 'number'
129
+ if (settings.limit && /^\d+$/.test(attr[key])) {
130
+ // Check the limits
131
+ attr[key] = attr[key] <= 0 ? 0 : Math.min(attr[key], max);
132
+ }
133
+
134
+ // Don't waste time animating, if there's no need.
135
+ if (!i && settings.axis.length > 1) {
136
+ if (prev === attr[key]) {
137
+ // No animation needed
138
+ attr = {};
139
+ } else if (queue) {
140
+ // Intermediate animation
141
+ animate(settings.onAfterFirst);
142
+ // Don't animate this axis again in the next iteration.
143
+ attr = {};
144
+ }
145
+ }
146
+ });
147
+
148
+ animate(settings.onAfter);
149
+
150
+ function animate(callback) {
151
+ var opts = $.extend({}, settings, {
152
+ // The queue setting conflicts with animate()
153
+ // Force it to always be true
154
+ queue: true,
155
+ duration: duration,
156
+ complete: callback && function() {
157
+ callback.call(elem, targ, settings);
158
+ }
159
+ });
160
+ $elem.animate(attr, opts);
161
+ }
162
+ });
163
+ };
164
+
165
+ // Max scrolling position, works on quirks mode
166
+ // It only fails (not too badly) on IE, quirks mode.
167
+ $scrollTo.max = function(elem, axis) {
168
+ var Dim = axis === 'x' ? 'Width' : 'Height',
169
+ scroll = 'scroll'+Dim;
170
+
171
+ if (!isWin(elem))
172
+ return elem[scroll] - $(elem)[Dim.toLowerCase()]();
173
+
174
+ var size = 'client' + Dim,
175
+ doc = elem.ownerDocument || elem.document,
176
+ html = doc.documentElement,
177
+ body = doc.body;
178
+
179
+ return Math.max(html[scroll], body[scroll]) - Math.min(html[size], body[size]);
180
+ };
181
+
182
+ function both(val) {
183
+ return $.isFunction(val) || $.isPlainObject(val) ? val : { top:val, left:val };
184
+ }
185
+
186
+ // Add special hooks so that window scroll properties can be animated
187
+ $.Tween.propHooks.scrollLeft =
188
+ $.Tween.propHooks.scrollTop = {
189
+ get: function(t) {
190
+ return $(t.elem)[t.prop]();
191
+ },
192
+ set: function(t) {
193
+ var curr = this.get(t);
194
+ // If interrupt is true and user scrolled, stop animating
195
+ if (t.options.interrupt && t._last && t._last !== curr) {
196
+ return $(t.elem).stop();
197
+ }
198
+ var next = Math.round(t.now);
199
+ // Don't waste CPU
200
+ // Browsers don't render floating point scroll
201
+ if (curr !== next) {
202
+ $(t.elem)[t.prop](next);
203
+ t._last = this.get(t);
204
+ }
205
+ }
206
+ };
207
+
208
+ // AMD requirement
209
+ return $scrollTo;
210
+ });
@@ -0,0 +1,5 @@
1
+ // Underscore.js 1.5.2
2
+ // http://underscorejs.org
3
+ // (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
4
+ // Underscore may be freely distributed under the MIT license.
5
+ (function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,g=e.filter,d=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,w=Object.keys,_=i.bind,j=function(n){return n instanceof j?n:this instanceof j?(this._wrapped=n,void 0):new j(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=j),exports._=j):n._=j,j.VERSION="1.5.2";var A=j.each=j.forEach=function(n,t,e){if(null!=n)if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var u=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}else for(var a=j.keys(n),u=0,i=a.length;i>u;u++)if(t.call(e,n[a[u]],a[u],n)===r)return};j.map=j.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e.push(t.call(r,n,u,i))}),e)};var E="Reduce of empty array with no initial value";j.reduce=j.foldl=j.inject=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=j.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)throw new TypeError(E);return r},j.reduceRight=j.foldr=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=j.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);var i=n.length;if(i!==+i){var a=j.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)throw new TypeError(E);return r},j.find=j.detect=function(n,t,r){var e;return O(n,function(n,u,i){return t.call(r,n,u,i)?(e=n,!0):void 0}),e},j.filter=j.select=function(n,t,r){var e=[];return null==n?e:g&&n.filter===g?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&e.push(n)}),e)},j.reject=function(n,t,r){return j.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},j.every=j.all=function(n,t,e){t||(t=j.identity);var u=!0;return null==n?u:d&&n.every===d?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void 0:r}),!!u)};var O=j.some=j.any=function(n,t,e){t||(t=j.identity);var u=!1;return null==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){return u||(u=t.call(e,n,i,a))?r:void 0}),!!u)};j.contains=j.include=function(n,t){return null==n?!1:y&&n.indexOf===y?n.indexOf(t)!=-1:O(n,function(n){return n===t})},j.invoke=function(n,t){var r=o.call(arguments,2),e=j.isFunction(t);return j.map(n,function(n){return(e?t:n[t]).apply(n,r)})},j.pluck=function(n,t){return j.map(n,function(n){return n[t]})},j.where=function(n,t,r){return j.isEmpty(t)?r?void 0:[]:j[r?"find":"filter"](n,function(n){for(var r in t)if(t[r]!==n[r])return!1;return!0})},j.findWhere=function(n,t){return j.where(n,t,!0)},j.max=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.max.apply(Math,n);if(!t&&j.isEmpty(n))return-1/0;var e={computed:-1/0,value:-1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a>e.computed&&(e={value:n,computed:a})}),e.value},j.min=function(n,t,r){if(!t&&j.isArray(n)&&n[0]===+n[0]&&n.length<65535)return Math.min.apply(Math,n);if(!t&&j.isEmpty(n))return 1/0;var e={computed:1/0,value:1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a<e.computed&&(e={value:n,computed:a})}),e.value},j.shuffle=function(n){var t,r=0,e=[];return A(n,function(n){t=j.random(r++),e[r-1]=e[t],e[t]=n}),e},j.sample=function(n,t,r){return arguments.length<2||r?n[j.random(n.length-1)]:j.shuffle(n).slice(0,Math.max(0,t))};var k=function(n){return j.isFunction(n)?n:function(t){return t[n]}};j.sortBy=function(n,t,r){var e=k(t);return j.pluck(j.map(n,function(n,t,u){return{value:n,index:t,criteria:e.call(r,n,t,u)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.index-t.index}),"value")};var F=function(n){return function(t,r,e){var u={},i=null==r?j.identity:k(r);return A(t,function(r,a){var o=i.call(e,r,a,t);n(u,o,r)}),u}};j.groupBy=F(function(n,t,r){(j.has(n,t)?n[t]:n[t]=[]).push(r)}),j.indexBy=F(function(n,t,r){n[t]=r}),j.countBy=F(function(n,t){j.has(n,t)?n[t]++:n[t]=1}),j.sortedIndex=function(n,t,r,e){r=null==r?j.identity:k(r);for(var u=r.call(e,t),i=0,a=n.length;a>i;){var o=i+a>>>1;r.call(e,n[o])<u?i=o+1:a=o}return i},j.toArray=function(n){return n?j.isArray(n)?o.call(n):n.length===+n.length?j.map(n,j.identity):j.values(n):[]},j.size=function(n){return null==n?0:n.length===+n.length?n.length:j.keys(n).length},j.first=j.head=j.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:o.call(n,0,t)},j.initial=function(n,t,r){return o.call(n,0,n.length-(null==t||r?1:t))},j.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:o.call(n,Math.max(n.length-t,0))},j.rest=j.tail=j.drop=function(n,t,r){return o.call(n,null==t||r?1:t)},j.compact=function(n){return j.filter(n,j.identity)};var M=function(n,t,r){return t&&j.every(n,j.isArray)?c.apply(r,n):(A(n,function(n){j.isArray(n)||j.isArguments(n)?t?a.apply(r,n):M(n,t,r):r.push(n)}),r)};j.flatten=function(n,t){return M(n,t,[])},j.without=function(n){return j.difference(n,o.call(arguments,1))},j.uniq=j.unique=function(n,t,r,e){j.isFunction(t)&&(e=r,r=t,t=!1);var u=r?j.map(n,r,e):n,i=[],a=[];return A(u,function(r,e){(t?e&&a[a.length-1]===r:j.contains(a,r))||(a.push(r),i.push(n[e]))}),i},j.union=function(){return j.uniq(j.flatten(arguments,!0))},j.intersection=function(n){var t=o.call(arguments,1);return j.filter(j.uniq(n),function(n){return j.every(t,function(t){return j.indexOf(t,n)>=0})})},j.difference=function(n){var t=c.apply(e,o.call(arguments,1));return j.filter(n,function(n){return!j.contains(t,n)})},j.zip=function(){for(var n=j.max(j.pluck(arguments,"length").concat(0)),t=new Array(n),r=0;n>r;r++)t[r]=j.pluck(arguments,""+r);return t},j.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},j.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=j.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}if(y&&n.indexOf===y)return n.indexOf(t,r);for(;u>e;e++)if(n[e]===t)return e;return-1},j.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=null!=r;if(b&&n.lastIndexOf===b)return e?n.lastIndexOf(t,r):n.lastIndexOf(t);for(var u=e?r:n.length;u--;)if(n[u]===t)return u;return-1},j.range=function(n,t,r){arguments.length<=1&&(t=n||0,n=0),r=arguments[2]||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=0,i=new Array(e);e>u;)i[u++]=n,n+=r;return i};var R=function(){};j.bind=function(n,t){var r,e;if(_&&n.bind===_)return _.apply(n,o.call(arguments,1));if(!j.isFunction(n))throw new TypeError;return r=o.call(arguments,2),e=function(){if(!(this instanceof e))return n.apply(t,r.concat(o.call(arguments)));R.prototype=n.prototype;var u=new R;R.prototype=null;var i=n.apply(u,r.concat(o.call(arguments)));return Object(i)===i?i:u}},j.partial=function(n){var t=o.call(arguments,1);return function(){return n.apply(this,t.concat(o.call(arguments)))}},j.bindAll=function(n){var t=o.call(arguments,1);if(0===t.length)throw new Error("bindAll must be passed function names");return A(t,function(t){n[t]=j.bind(n[t],n)}),n},j.memoize=function(n,t){var r={};return t||(t=j.identity),function(){var e=t.apply(this,arguments);return j.has(r,e)?r[e]:r[e]=n.apply(this,arguments)}},j.delay=function(n,t){var r=o.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},j.defer=function(n){return j.delay.apply(j,[n,1].concat(o.call(arguments,1)))},j.throttle=function(n,t,r){var e,u,i,a=null,o=0;r||(r={});var c=function(){o=r.leading===!1?0:new Date,a=null,i=n.apply(e,u)};return function(){var l=new Date;o||r.leading!==!1||(o=l);var f=t-(l-o);return e=this,u=arguments,0>=f?(clearTimeout(a),a=null,o=l,i=n.apply(e,u)):a||r.trailing===!1||(a=setTimeout(c,f)),i}},j.debounce=function(n,t,r){var e,u,i,a,o;return function(){i=this,u=arguments,a=new Date;var c=function(){var l=new Date-a;t>l?e=setTimeout(c,t-l):(e=null,r||(o=n.apply(i,u)))},l=r&&!e;return e||(e=setTimeout(c,t)),l&&(o=n.apply(i,u)),o}},j.once=function(n){var t,r=!1;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},j.wrap=function(n,t){return function(){var r=[n];return a.apply(r,arguments),t.apply(this,r)}},j.compose=function(){var n=arguments;return function(){for(var t=arguments,r=n.length-1;r>=0;r--)t=[n[r].apply(this,t)];return t[0]}},j.after=function(n,t){return function(){return--n<1?t.apply(this,arguments):void 0}},j.keys=w||function(n){if(n!==Object(n))throw new TypeError("Invalid object");var t=[];for(var r in n)j.has(n,r)&&t.push(r);return t},j.values=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=n[t[u]];return e},j.pairs=function(n){for(var t=j.keys(n),r=t.length,e=new Array(r),u=0;r>u;u++)e[u]=[t[u],n[t[u]]];return e},j.invert=function(n){for(var t={},r=j.keys(n),e=0,u=r.length;u>e;e++)t[n[r[e]]]=r[e];return t},j.functions=j.methods=function(n){var t=[];for(var r in n)j.isFunction(n[r])&&t.push(r);return t.sort()},j.extend=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]=t[r]}),n},j.pick=function(n){var t={},r=c.apply(e,o.call(arguments,1));return A(r,function(r){r in n&&(t[r]=n[r])}),t},j.omit=function(n){var t={},r=c.apply(e,o.call(arguments,1));for(var u in n)j.contains(r,u)||(t[u]=n[u]);return t},j.defaults=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]===void 0&&(n[r]=t[r])}),n},j.clone=function(n){return j.isObject(n)?j.isArray(n)?n.slice():j.extend({},n):n},j.tap=function(n,t){return t(n),n};var S=function(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;n instanceof j&&(n=n._wrapped),t instanceof j&&(t=t._wrapped);var u=l.call(n);if(u!=l.call(t))return!1;switch(u){case"[object String]":return n==String(t);case"[object Number]":return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case"[object Date]":case"[object Boolean]":return+n==+t;case"[object RegExp]":return n.source==t.source&&n.global==t.global&&n.multiline==t.multiline&&n.ignoreCase==t.ignoreCase}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]==n)return e[i]==t;var a=n.constructor,o=t.constructor;if(a!==o&&!(j.isFunction(a)&&a instanceof a&&j.isFunction(o)&&o instanceof o))return!1;r.push(n),e.push(t);var c=0,f=!0;if("[object Array]"==u){if(c=n.length,f=c==t.length)for(;c--&&(f=S(n[c],t[c],r,e)););}else{for(var s in n)if(j.has(n,s)&&(c++,!(f=j.has(t,s)&&S(n[s],t[s],r,e))))break;if(f){for(s in t)if(j.has(t,s)&&!c--)break;f=!c}}return r.pop(),e.pop(),f};j.isEqual=function(n,t){return S(n,t,[],[])},j.isEmpty=function(n){if(null==n)return!0;if(j.isArray(n)||j.isString(n))return 0===n.length;for(var t in n)if(j.has(n,t))return!1;return!0},j.isElement=function(n){return!(!n||1!==n.nodeType)},j.isArray=x||function(n){return"[object Array]"==l.call(n)},j.isObject=function(n){return n===Object(n)},A(["Arguments","Function","String","Number","Date","RegExp"],function(n){j["is"+n]=function(t){return l.call(t)=="[object "+n+"]"}}),j.isArguments(arguments)||(j.isArguments=function(n){return!(!n||!j.has(n,"callee"))}),"function"!=typeof/./&&(j.isFunction=function(n){return"function"==typeof n}),j.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},j.isNaN=function(n){return j.isNumber(n)&&n!=+n},j.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"==l.call(n)},j.isNull=function(n){return null===n},j.isUndefined=function(n){return n===void 0},j.has=function(n,t){return f.call(n,t)},j.noConflict=function(){return n._=t,this},j.identity=function(n){return n},j.times=function(n,t,r){for(var e=Array(Math.max(0,n)),u=0;n>u;u++)e[u]=t.call(r,u);return e},j.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))};var I={escape:{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"}};I.unescape=j.invert(I.escape);var T={escape:new RegExp("["+j.keys(I.escape).join("")+"]","g"),unescape:new RegExp("("+j.keys(I.unescape).join("|")+")","g")};j.each(["escape","unescape"],function(n){j[n]=function(t){return null==t?"":(""+t).replace(T[n],function(t){return I[n][t]})}}),j.result=function(n,t){if(null==n)return void 0;var r=n[t];return j.isFunction(r)?r.call(n):r},j.mixin=function(n){A(j.functions(n),function(t){var r=j[t]=n[t];j.prototype[t]=function(){var n=[this._wrapped];return a.apply(n,arguments),z.call(this,r.apply(j,n))}})};var N=0;j.uniqueId=function(n){var t=++N+"";return n?n+t:t},j.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var q=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},D=/\\|'|\r|\n|\t|\u2028|\u2029/g;j.template=function(n,t,r){var e;r=j.defaults({},r,j.templateSettings);var u=new RegExp([(r.escape||q).source,(r.interpolate||q).source,(r.evaluate||q).source].join("|")+"|$","g"),i=0,a="__p+='";n.replace(u,function(t,r,e,u,o){return a+=n.slice(i,o).replace(D,function(n){return"\\"+B[n]}),r&&(a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'"),e&&(a+="'+\n((__t=("+e+"))==null?'':__t)+\n'"),u&&(a+="';\n"+u+"\n__p+='"),i=o+t.length,t}),a+="';\n",r.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{e=new Function(r.variable||"obj","_",a)}catch(o){throw o.source=a,o}if(t)return e(t,j);var c=function(n){return e.call(this,n,j)};return c.source="function("+(r.variable||"obj")+"){\n"+a+"}",c},j.chain=function(n){return j(n).chain()};var z=function(n){return this._chain?j(n).chain():n};j.mixin(j),A(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=e[n];j.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!=n&&"splice"!=n||0!==r.length||delete r[0],z.call(this,r)}}),A(["concat","join","slice"],function(n){var t=e[n];j.prototype[n]=function(){return z.call(this,t.apply(this._wrapped,arguments))}}),j.extend(j.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this);
@@ -0,0 +1,74 @@
1
+ class Surveillance.AttemptView extends Backbone.View
2
+ initialize: ->
3
+ @partialUpdateURL = @$el.data("partial-update-url")
4
+ @$lastAnsweredSectionField = @$(".last-answered-section")
5
+ @lastAnsweredSection = @$lastAnsweredSectionField.val()
6
+
7
+ # Locks submissions from "Enter" key in text fields
8
+ # If the form has a `[data-surveillance-full-form]` attribute set, it can
9
+ # be submitted at any time
10
+ @allowSubmission = !!@$el.data('surveillance-full-form')
11
+ @$el.on("submit", _.bind(@ensureSubmissionAllowed, this))
12
+
13
+ @sectionViews = _.map @$(".survey-section"), (el) =>
14
+ section = new Surveillance.SectionView(el: el)
15
+ @listenTo section, "validated", => @nextSection(section)
16
+ @listenTo section, "canceled", => @previousSection(section)
17
+ @listenTo section, "change-section", (sectionId) =>
18
+ @changeSection(section, sectionId)
19
+ @listenTo section, "submit-survey", => @submit()
20
+ @listenTo section, "section-complete", => @savePartialAttemptAt(section.index)
21
+
22
+ section
23
+
24
+ # Fill section views with their default next and previous elements
25
+ _.each @sectionViews, (view) =>
26
+ view.nextSection = @nextFor(view)
27
+ view.previousSection = @previousFor(view)
28
+
29
+ nextSection: (view) ->
30
+ @transition(view, view.nextSection)
31
+
32
+ previousSection: (view) ->
33
+ @transition(view, view.previousSection)
34
+
35
+ changeSection: (current, nextId, mode = "next") ->
36
+ view = @findSection(nextId)
37
+ view.previousSection = current
38
+ @transition(current, view)
39
+
40
+ transition: (currentView, nextSection) ->
41
+ currentView.$el.fadeOut 200, ->
42
+ nextSection.$el.fadeIn(200)
43
+ $.scrollTo(nextSection.$el, 200, offset: -60)
44
+
45
+ nextFor: (view) ->
46
+ _.reduce(@sectionViews, @nextIterator(view), null)
47
+
48
+ previousFor: (view) ->
49
+ _.reduceRight(@sectionViews, @nextIterator(view), null)
50
+
51
+ nextIterator: (view) ->
52
+ (found, section) ->
53
+ return section if found == "next"
54
+ return found if found
55
+ return "next" if section.cid == view.cid
56
+
57
+ findSection: (id) ->
58
+ _.find @sectionViews, (view) -> view.id == id
59
+
60
+ submit: ->
61
+ @updateLanstAnsweredSection(_.last(@sectionViews).index)
62
+ @allowSubmission = true
63
+ @$el.submit()
64
+ @$(".validate-survey").button("loading")
65
+
66
+ ensureSubmissionAllowed: (e) ->
67
+ @allowSubmission
68
+
69
+ savePartialAttemptAt: (index) ->
70
+ @updateLanstAnsweredSection(index)
71
+ $.post(@partialUpdateURL, @$el.serialize())
72
+
73
+ updateLanstAnsweredSection: (index) ->
74
+ @$lastAnsweredSectionField.val(index) if index > @lastAnsweredSection
@@ -0,0 +1,53 @@
1
+ class Surveillance.QuestionView extends Backbone.View
2
+ events:
3
+ "change input, select": "processAnswerValues"
4
+
5
+ initialize: ->
6
+ @$fields = @getFields()
7
+
8
+ @beforeInitialize?()
9
+
10
+ @buildModel(required: @fieldRequired(), rules: @branchRules())
11
+
12
+ @processAnswerValues()
13
+
14
+ @listenTo(@model, "invalid", @refreshErrors)
15
+
16
+ processAnswerValues: ->
17
+ fields = @fieldValues()
18
+ answers = @requiredAnswersCount()
19
+
20
+ @model.set(fields: fields, fieldsToFill: answers)
21
+ @cleanErrors()
22
+
23
+ @afterAnswerValuesProcessing?()
24
+
25
+ fieldValues: ->
26
+ _.compact(_.map(@$fields, (el) => @processFieldValue($(el))))
27
+
28
+ requiredAnswersCount: ->
29
+ _.keys(_.groupBy(@$fields, (el) -> $(el).attr("name"))).length
30
+
31
+ processFieldValue: ($el) ->
32
+ $el.val()
33
+
34
+ cleanErrors: ->
35
+ @$(".has-error").removeClass("has-error")
36
+
37
+ refreshErrors: ->
38
+ @$(".form-group").addClass("has-error")
39
+
40
+ getFields: ->
41
+ @$("input, select").not("[type=hidden]")
42
+
43
+ isValid: ->
44
+ @model.isValid()
45
+
46
+ fieldRequired: ->
47
+ @$el.data("required")
48
+
49
+ branchRules: ->
50
+ @$el.data("branch-rules")
51
+
52
+ buildModel: (options) ->
53
+ @model = new Surveillance.Question(options)
@@ -0,0 +1,52 @@
1
+ class Surveillance.ChoiceView extends Surveillance.QuestionView
2
+ events:
3
+ "change input[type=radio], input[type=checkbox]": "valueChanged"
4
+ "change .other-field input[type=text]": "otherChanged"
5
+ "change select": "selectValueChanged"
6
+
7
+ beforeInitialize: ->
8
+ _.bindAll(this, "valueFor")
9
+
10
+ choiceValues: ->
11
+ if ($select = @$("select")).length
12
+ $select.val() || null
13
+ else
14
+ _.compact(_.map(@$("input[type=radio], input[type=checkbox]"), @valueFor))
15
+
16
+ valueFor: (input) ->
17
+ if (value = ($input = $(input)).is(":checked") and $input.val())
18
+ if value.match(/^\d+$/) then parseInt(value, 10) else value
19
+
20
+ otherValue: ->
21
+ @$(".other-field input[type=text]").val() || null
22
+
23
+ valueChanged: ->
24
+ @model.set(value: @choiceValues())
25
+ @cleanErrors()
26
+
27
+ otherChanged: ->
28
+ @model.set(other: @otherValue())
29
+ @cleanErrors()
30
+
31
+ selectValueChanged: ->
32
+ @model.set(value: @$("select").val())
33
+ @cleanErrors()
34
+
35
+ cleanErrors: ->
36
+ @$el.removeClass("has-error")
37
+ @$(".has-error").removeClass("has-error")
38
+
39
+ requiredAnswersCount: ->
40
+ if _.include(@fieldValues(), "other") then 2 else 1
41
+
42
+ buildModel: (options) ->
43
+ @model = new Surveillance.ChoosableQuestion(
44
+ _.extend(options, { value: @choiceValues(), other: @otherValue() })
45
+ )
46
+
47
+ refreshErrors: ->
48
+ if @model.validationError.chooseField
49
+ @$(".form-group").addClass("has-error")
50
+
51
+ if @model.validationError.fillOtherField
52
+ @$(".other-field .form-group").addClass("has-error")
@@ -0,0 +1,26 @@
1
+ class Surveillance.MatrixQuestionView extends Backbone.View
2
+ events:
3
+ "change input[type=radio], input[type=checkbox]": "valueChanged"
4
+
5
+ initialize: (options) ->
6
+ @model.set(
7
+ id: @$el.data("sub-question-id")
8
+ value: @choiceValues()
9
+ )
10
+
11
+ _.bindAll(this, "valueFor")
12
+
13
+ @listenTo(@model, "invalid", @refreshErrors)
14
+
15
+ choiceValues: ->
16
+ _.compact(_.map(@$("input[type=radio], input[type=checkbox]"), @valueFor))
17
+
18
+ valueChanged: ->
19
+ @model.set(value: @choiceValues())
20
+ @$el.removeClass("danger")
21
+
22
+ refreshErrors: ->
23
+ @$el.addClass("danger") if @model.validationError
24
+
25
+ valueFor: (input) ->
26
+ ($input = $(input)).is(":checked") and (val = $input.val()) and parseInt(val, 10)
@@ -0,0 +1,21 @@
1
+ class Surveillance.MatrixView extends Surveillance.QuestionView
2
+ beforeInitialize: ->
3
+ _.bindAll(this, "buildSubQuestions")
4
+
5
+ processFieldValue: ($el) ->
6
+ if $el.is(":checked")
7
+ questionId = $el.closest("[data-sub-question-id]").data("sub-question-id")
8
+ "#{ questionId }:#{ $el.val() }"
9
+
10
+ getFields: ->
11
+ super.not(".string")
12
+
13
+ buildModel: (options) ->
14
+ @model = new Surveillance.Matrix(options)
15
+ @buildSubQuestions()
16
+
17
+ buildSubQuestions: (el) ->
18
+ _.each @$("[data-sub-question-id]"), (el) =>
19
+ model = new Surveillance.MatrixQuestion
20
+ new Surveillance.MatrixQuestionView(el: el, model: model)
21
+ @model.subQuestions.push(model)