card 0.0.1 → 1.15.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (514) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +4 -0
  3. data/GPL +331 -0
  4. data/LICENSE +16 -0
  5. data/VERSION +1 -0
  6. data/card.gemspec +48 -19
  7. data/config/initializers/01_init_ruby_extensions.rb +7 -0
  8. data/config/initializers/inflections.rb +13 -0
  9. data/config/initializers/mime_types.rb +13 -0
  10. data/config/initializers/notification.rb +4 -0
  11. data/config/initializers/recaptcha.rb +6 -0
  12. data/config/initializers/uuid_state_file.rb +3 -0
  13. data/db/bootstrap/card_actions.yml +3872 -0
  14. data/db/bootstrap/card_acts.yml +7 -0
  15. data/db/bootstrap/card_changes.yml +11909 -0
  16. data/db/bootstrap/card_references.yml +3970 -0
  17. data/db/bootstrap/cards.yml +10805 -0
  18. data/db/migrate/20110511221913_require_earlier_migrations.rb +19 -0
  19. data/db/migrate/20120105203350_require_1_8_migrations.rb +15 -0
  20. data/db/migrate/20121111025347_require_1_10_migrations.rb +15 -0
  21. data/db/migrate/20121118114000_split_link_type.rb +16 -0
  22. data/db/migrate/20121118115000_update_link_type.rb +19 -0
  23. data/db/migrate/20130106052640_table_cleanup.rb +25 -0
  24. data/db/migrate/20130109015336_trunk_left.rb +14 -0
  25. data/db/migrate/20130411210957_update_codenames.rb +14 -0
  26. data/db/migrate/20140822073704_create_new_revision_tables.rb +43 -0
  27. data/db/migrate/20141001105348_move_revisions_to_actions.rb +62 -0
  28. data/db/migrate/20141121172918_rename_card_migration_table.rb +15 -0
  29. data/db/migrate/20141208132159_remove_present_from_reference_table.rb +9 -0
  30. data/db/migrate/20141216053032_better_index_names.rb +24 -0
  31. data/db/migrate_core_cards/20130411191151_renaming_for_menu.rb +49 -0
  32. data/db/migrate_core_cards/20130411211600_delete_old_related_tab_cards.rb +18 -0
  33. data/db/migrate_core_cards/20130419215612_import_help_text.rb +13 -0
  34. data/db/migrate_core_cards/20130823192433_add_style_cards.rb +87 -0
  35. data/db/migrate_core_cards/20130910183318_move_styles_to_content.rb +11 -0
  36. data/db/migrate_core_cards/20130920214038_jsonize_tinymce.rb +15 -0
  37. data/db/migrate_core_cards/20130920291703_update_stylesheets.rb +18 -0
  38. data/db/migrate_core_cards/20130927191728_account_events.rb +21 -0
  39. data/db/migrate_core_cards/20131016172445_common_css_patch.rb +12 -0
  40. data/db/migrate_core_cards/20140110193325_reset_account_request_type.rb +11 -0
  41. data/db/migrate_core_cards/20140307231621_user_data_to_cards.rb +73 -0
  42. data/db/migrate_core_cards/20140317035504_account_requests_to_signups.rb +51 -0
  43. data/db/migrate_core_cards/20140512155840_add_script_cards.rb +83 -0
  44. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +134 -0
  45. data/db/migrate_core_cards/20140725180118_config_card_updates.rb +9 -0
  46. data/db/migrate_core_cards/20141111083921_delete_machine_output.rb +9 -0
  47. data/db/migrate_core_cards/20141115034214_config_descriptions_etc.rb +14 -0
  48. data/db/migrate_core_cards/20141119001955_make_symlinks_relative.rb +15 -0
  49. data/db/migrate_core_cards/20141120120605_fix_notification_html_message.rb +10 -0
  50. data/db/migrate_core_cards/20141204061304_watchers_to_following.rb +38 -0
  51. data/db/migrate_core_cards/20141208132416_partial_reference_type.rb +7 -0
  52. data/db/migrate_core_cards/20141208162106_add_ace_script.rb +12 -0
  53. data/db/migrate_core_cards/20141216155251_add_more_following_cards.rb +24 -0
  54. data/db/migrate_core_cards/20141230204340_uri_codename.rb +13 -0
  55. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +17 -0
  56. data/db/migrate_core_cards/20150220134731_following_to_follow_rule.rb +18 -0
  57. data/db/migrate_core_cards/data/1.11_help_text.json +410 -0
  58. data/db/migrate_core_cards/data/1.12_stylesheets/classic_cards.scss +100 -0
  59. data/db/migrate_core_cards/data/1.12_stylesheets/common.scss +226 -0
  60. data/db/migrate_core_cards/data/1.12_stylesheets/right_sidebar.scss +27 -0
  61. data/db/migrate_core_cards/data/1.12_stylesheets/traditional.scss +152 -0
  62. data/db/migrate_core_cards/data/1.13_config_text.json +32 -0
  63. data/db/migrate_core_cards/data/1.14_config_descriptions_etc.json +77 -0
  64. data/db/migrate_core_cards/data/bootstrap_layout.json +81 -0
  65. data/db/migrate_core_cards/data/mailer/follower_notification_email.html +9 -0
  66. data/db/migrate_core_cards/data/mailer/follower_notification_email.txt +11 -0
  67. data/db/migrate_core_cards/data/mailer/mail_config.json +22 -0
  68. data/db/migrate_core_cards/data/mailer/password_reset_email.html +10 -0
  69. data/db/migrate_core_cards/data/mailer/password_reset_email.txt +11 -0
  70. data/db/migrate_core_cards/data/mailer/signup_alert_email.html +7 -0
  71. data/db/migrate_core_cards/data/mailer/signup_alert_email.txt +5 -0
  72. data/db/migrate_core_cards/data/mailer/verification_email.html +9 -0
  73. data/db/migrate_core_cards/data/mailer/verification_email.txt +8 -0
  74. data/db/schema.rb +128 -0
  75. data/db/seeds.rb +8 -0
  76. data/db/version.txt +1 -0
  77. data/db/version_core_cards.txt +1 -0
  78. data/lib/card.rb +46 -3
  79. data/lib/card/active_record_ext.rb +77 -0
  80. data/lib/card/auth.rb +181 -0
  81. data/lib/card/cache.rb +199 -0
  82. data/lib/card/chunk.rb +104 -0
  83. data/lib/card/codename.rb +72 -0
  84. data/lib/card/content.rb +211 -0
  85. data/lib/card/core_ext.rb +105 -0
  86. data/lib/card/core_migration.rb +6 -0
  87. data/lib/card/diff.rb +430 -0
  88. data/lib/card/env.rb +52 -0
  89. data/lib/card/exceptions.rb +44 -0
  90. data/lib/card/format.rb +563 -0
  91. data/lib/card/loader.rb +165 -0
  92. data/lib/card/log.rb +450 -0
  93. data/lib/card/mailer.rb +37 -0
  94. data/lib/card/migration.rb +145 -0
  95. data/lib/card/name.rb +45 -0
  96. data/lib/card/query.rb +81 -0
  97. data/lib/card/query/card_clause.rb +527 -0
  98. data/lib/card/query/clause.rb +21 -0
  99. data/lib/card/query/ref_clause.rb +47 -0
  100. data/lib/card/query/value_clause.rb +65 -0
  101. data/lib/card/reference.rb +63 -0
  102. data/lib/card/set.rb +369 -0
  103. data/lib/card/set_pattern.rb +168 -0
  104. data/lib/card/simplecov_helper.rb +61 -0
  105. data/lib/card/spec_helper.rb +68 -0
  106. data/lib/card/version.rb +9 -2
  107. data/lib/cardio.rb +145 -0
  108. data/lib/generators/card.rb +32 -0
  109. data/lib/generators/card/format/USAGE +9 -0
  110. data/lib/generators/card/format/format_generator.rb +27 -0
  111. data/lib/generators/card/format/templates/format_spec_template.erb +5 -0
  112. data/lib/generators/card/format/templates/format_template.erb +3 -0
  113. data/lib/generators/card/migration/USAGE +24 -0
  114. data/lib/generators/card/migration/migration_generator.rb +38 -0
  115. data/lib/generators/card/migration/templates/card_migration.erb +10 -0
  116. data/lib/generators/card/set/USAGE +15 -0
  117. data/lib/generators/card/set/set_generator.rb +29 -0
  118. data/lib/generators/card/set/templates/set_spec_template.erb +5 -0
  119. data/lib/generators/card/set/templates/set_template.erb +1 -0
  120. data/mod/01_core/chunk/include.rb +85 -0
  121. data/mod/01_core/chunk/link.rb +87 -0
  122. data/mod/01_core/chunk/literal.rb +24 -0
  123. data/mod/01_core/chunk/reference.rb +53 -0
  124. data/mod/01_core/chunk/uri.rb +135 -0
  125. data/mod/01_core/format/data_format.rb +2 -0
  126. data/mod/01_core/format/html_format.rb +129 -0
  127. data/mod/01_core/format/text_format.rb +10 -0
  128. data/mod/01_core/layout/blank.html +5 -0
  129. data/mod/01_core/layout/default.html +20 -0
  130. data/mod/01_core/layout/noside.html +16 -0
  131. data/mod/01_core/layout/pre.html +2 -0
  132. data/mod/01_core/layout/simple.html +5 -0
  133. data/mod/01_core/set/all/active_card.rb +35 -0
  134. data/mod/01_core/set/all/collection.rb +142 -0
  135. data/mod/01_core/set/all/content.rb +64 -0
  136. data/mod/01_core/set/all/erb.rb +11 -0
  137. data/mod/01_core/set/all/fetch.rb +228 -0
  138. data/mod/01_core/set/all/haml.rb +7 -0
  139. data/mod/01_core/set/all/initialize.rb +49 -0
  140. data/mod/01_core/set/all/name.rb +275 -0
  141. data/mod/01_core/set/all/pattern.rb +56 -0
  142. data/mod/01_core/set/all/permissions.rb +284 -0
  143. data/mod/01_core/set/all/phases.rb +185 -0
  144. data/mod/01_core/set/all/references.rb +118 -0
  145. data/mod/01_core/set/all/rules.rb +315 -0
  146. data/mod/01_core/set/all/states.rb +16 -0
  147. data/mod/01_core/set/all/templating.rb +120 -0
  148. data/mod/01_core/set/all/tracked_attributes.rb +114 -0
  149. data/mod/01_core/set/all/trash.rb +50 -0
  150. data/mod/01_core/set/all/type.rb +85 -0
  151. data/mod/01_core/set/all/utils.rb +85 -0
  152. data/mod/01_core/set_pattern/01_all.rb +11 -0
  153. data/mod/01_core/set_pattern/02_all_plus.rb +13 -0
  154. data/mod/01_core/set_pattern/03_type.rb +23 -0
  155. data/mod/01_core/set_pattern/04_star.rb +15 -0
  156. data/mod/01_core/set_pattern/05_rstar.rb +17 -0
  157. data/mod/01_core/set_pattern/06_right.rb +20 -0
  158. data/mod/01_core/set_pattern/07_type_plus_right.rb +23 -0
  159. data/mod/01_core/set_pattern/08_self.rb +19 -0
  160. data/mod/01_core/spec/chunk/literal_spec.rb +14 -0
  161. data/mod/01_core/spec/chunk/uri_spec.rb +292 -0
  162. data/mod/01_core/spec/format/data_format_spec.rb +5 -0
  163. data/mod/01_core/spec/format/html_format_spec.rb +140 -0
  164. data/mod/01_core/spec/format/text_format_spec.rb +5 -0
  165. data/mod/01_core/spec/set/all/active_card_spec.rb +5 -0
  166. data/mod/01_core/spec/set/all/attribute_tracking_spec.rb +21 -0
  167. data/mod/01_core/spec/set/all/collection_spec.rb +65 -0
  168. data/mod/01_core/spec/set/all/content_spec.rb +15 -0
  169. data/mod/01_core/spec/set/all/fetch_spec.rb +204 -0
  170. data/mod/01_core/spec/set/all/initialize_spec.rb +58 -0
  171. data/mod/01_core/spec/set/all/name_spec.rb +61 -0
  172. data/mod/01_core/spec/set/all/pattern_spec.rb +81 -0
  173. data/mod/01_core/spec/set/all/permissions_spec.rb +505 -0
  174. data/mod/01_core/spec/set/all/phases_spec.rb +6 -0
  175. data/mod/01_core/spec/set/all/references_spec.rb +8 -0
  176. data/mod/01_core/spec/set/all/rules2_spec.rb +250 -0
  177. data/mod/01_core/spec/set/all/rules_spec.rb +130 -0
  178. data/mod/01_core/spec/set/all/states_spec.rb +5 -0
  179. data/mod/01_core/spec/set/all/templating_spec.rb +111 -0
  180. data/mod/01_core/spec/set/all/tracked_attributes_spec.rb +328 -0
  181. data/mod/01_core/spec/set/all/trash_spec.rb +34 -0
  182. data/mod/01_core/spec/set/all/type_spec.rb +71 -0
  183. data/mod/01_core/spec/set/all/utils_spec.rb +5 -0
  184. data/mod/01_history/lib/card/act.rb +60 -0
  185. data/mod/01_history/lib/card/action.rb +176 -0
  186. data/mod/01_history/lib/card/change.rb +29 -0
  187. data/mod/01_history/set/all/actions.rb +47 -0
  188. data/mod/01_history/set/all/content_history.rb +131 -0
  189. data/mod/01_history/set/all/history.rb +296 -0
  190. data/mod/02_basic_types/format/css_format.rb +6 -0
  191. data/mod/02_basic_types/format/csv_format.rb +6 -0
  192. data/mod/02_basic_types/format/file_format.rb +3 -0
  193. data/mod/02_basic_types/format/js_format.rb +6 -0
  194. data/mod/02_basic_types/format/json_format.rb +6 -0
  195. data/mod/02_basic_types/format/rss_format.rb +11 -0
  196. data/mod/02_basic_types/format/xml_format.rb +6 -0
  197. data/mod/02_basic_types/set/all/all_css.rb +42 -0
  198. data/mod/02_basic_types/set/all/all_csv.rb +52 -0
  199. data/mod/02_basic_types/set/all/all_js.rb +7 -0
  200. data/mod/02_basic_types/set/all/base.rb +122 -0
  201. data/mod/02_basic_types/set/all/file.rb +13 -0
  202. data/mod/02_basic_types/set/all/json.rb +66 -0
  203. data/mod/02_basic_types/set/all/rss.rb +72 -0
  204. data/mod/02_basic_types/set/all/text.rb +8 -0
  205. data/mod/02_basic_types/set/type/plain_text.rb +10 -0
  206. data/mod/02_basic_types/set/type/pointer.rb +323 -0
  207. data/mod/02_basic_types/spec/set/all/all_css_spec.rb +10 -0
  208. data/mod/02_basic_types/spec/set/all/all_csv_spec.rb +9 -0
  209. data/mod/02_basic_types/spec/set/all/base_spec.rb +57 -0
  210. data/mod/02_basic_types/spec/set/all/file_spec.rb +5 -0
  211. data/mod/02_basic_types/spec/set/all/json_spec.rb +26 -0
  212. data/mod/02_basic_types/spec/set/all/rss_spec.rb +8 -0
  213. data/mod/02_basic_types/spec/set/all/text_spec.rb +5 -0
  214. data/mod/02_basic_types/spec/set/type/plain_text_spec.rb +11 -0
  215. data/mod/02_basic_types/spec/set/type/pointer_spec.rb +103 -0
  216. data/mod/03_machines/lib/card/machine.rb +185 -0
  217. data/mod/03_machines/lib/card/machine_input.rb +40 -0
  218. data/mod/03_machines/lib/javascript/ace.js +18204 -0
  219. data/mod/03_machines/lib/javascript/html5shiv-printshiv.js +1 -0
  220. data/mod/03_machines/lib/javascript/jquery-ui.js +14913 -0
  221. data/mod/03_machines/lib/javascript/jquery.autosize.js +274 -0
  222. data/mod/03_machines/lib/javascript/jquery.fileupload.js +1114 -0
  223. data/mod/03_machines/lib/javascript/jquery.iframe-transport.js +185 -0
  224. data/mod/03_machines/lib/javascript/jquery.js +4 -0
  225. data/mod/03_machines/lib/javascript/jquery.ui.autocomplete.html.js +41 -0
  226. data/mod/03_machines/lib/javascript/jquery_ujs.js +469 -0
  227. data/mod/03_machines/lib/javascript/jquerymobile.js +15454 -0
  228. data/mod/03_machines/lib/javascript/theme-textmate.js +130 -0
  229. data/mod/03_machines/lib/javascript/tinymce.js +13 -0
  230. data/mod/03_machines/lib/javascript/wagn.js.coffee +336 -0
  231. data/mod/03_machines/lib/javascript/wagn_menu.js +72 -0
  232. data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +446 -0
  233. data/mod/03_machines/lib/stylesheets/functional.scss +184 -0
  234. data/mod/03_machines/lib/stylesheets/jquery-ui-smoothness.css +1178 -0
  235. data/mod/03_machines/lib/stylesheets/standard.scss +760 -0
  236. data/mod/03_machines/set/right/machine_output.rb +20 -0
  237. data/mod/03_machines/set/self/script_ace.rb +8 -0
  238. data/mod/03_machines/set/self/script_card_menu.rb +8 -0
  239. data/mod/03_machines/set/self/script_html5shiv_printshiv.rb +7 -0
  240. data/mod/03_machines/set/self/script_jquery.rb +8 -0
  241. data/mod/03_machines/set/self/script_jquery_helper.rb +14 -0
  242. data/mod/03_machines/set/self/script_slot.rb +9 -0
  243. data/mod/03_machines/set/self/script_tinymce.rb +8 -0
  244. data/mod/03_machines/set/self/style_functional.rb +8 -0
  245. data/mod/03_machines/set/self/style_jquery_ui_smoothness.rb +8 -0
  246. data/mod/03_machines/set/self/style_standard.rb +8 -0
  247. data/mod/03_machines/set/type/coffee_script.rb +61 -0
  248. data/mod/03_machines/set/type/css.rb +45 -0
  249. data/mod/03_machines/set/type/java_script.rb +38 -0
  250. data/mod/03_machines/set/type/scss.rb +23 -0
  251. data/mod/03_machines/set/type/skin.rb +12 -0
  252. data/mod/03_machines/spec/lib/shared_machine_examples.rb +175 -0
  253. data/mod/03_machines/spec/lib/shared_machine_input_examples.rb +65 -0
  254. data/mod/03_machines/spec/set/right/machine_output_spec.rb +5 -0
  255. data/mod/03_machines/spec/set/self/style_functional_spec.rb +5 -0
  256. data/mod/03_machines/spec/set/self/style_jquery_ui_smoothness_spec.rb +5 -0
  257. data/mod/03_machines/spec/set/self/style_standard_spec.rb +5 -0
  258. data/mod/03_machines/spec/set/type/coffeescript_spec.rb +29 -0
  259. data/mod/03_machines/spec/set/type/css_spec.rb +34 -0
  260. data/mod/03_machines/spec/set/type/javascript_spec.rb +28 -0
  261. data/mod/03_machines/spec/set/type/scss_spec.rb +56 -0
  262. data/mod/03_machines/spec/set/type/skin_spec.rb +70 -0
  263. data/mod/04_settings/lib/card/setting.rb +65 -0
  264. data/mod/04_settings/set/right/add_help.rb +11 -0
  265. data/mod/04_settings/set/right/comment.rb +91 -0
  266. data/mod/04_settings/set/right/create.rb +3 -0
  267. data/mod/04_settings/set/right/default.rb +3 -0
  268. data/mod/04_settings/set/right/delete.rb +4 -0
  269. data/mod/04_settings/set/right/help.rb +3 -0
  270. data/mod/04_settings/set/right/read.rb +2 -0
  271. data/mod/04_settings/set/right/script.rb +10 -0
  272. data/mod/04_settings/set/right/structure.rb +4 -0
  273. data/mod/04_settings/set/right/style.rb +10 -0
  274. data/mod/04_settings/set/right/update.rb +2 -0
  275. data/mod/04_settings/set/self/accountable.rb +3 -0
  276. data/mod/04_settings/set/self/add_help.rb +2 -0
  277. data/mod/04_settings/set/self/autoname.rb +2 -0
  278. data/mod/04_settings/set/self/captcha.rb +2 -0
  279. data/mod/04_settings/set/self/comment.rb +2 -0
  280. data/mod/04_settings/set/self/create.rb +2 -0
  281. data/mod/04_settings/set/self/default.rb +2 -0
  282. data/mod/04_settings/set/self/delete.rb +2 -0
  283. data/mod/04_settings/set/self/help.rb +2 -0
  284. data/mod/04_settings/set/self/input.rb +2 -0
  285. data/mod/04_settings/set/self/layout.rb +2 -0
  286. data/mod/04_settings/set/self/on_create.rb +2 -0
  287. data/mod/04_settings/set/self/on_delete.rb +2 -0
  288. data/mod/04_settings/set/self/on_update.rb +2 -0
  289. data/mod/04_settings/set/self/options.rb +2 -0
  290. data/mod/04_settings/set/self/options_label.rb +2 -0
  291. data/mod/04_settings/set/self/read.rb +2 -0
  292. data/mod/04_settings/set/self/script.rb +2 -0
  293. data/mod/04_settings/set/self/structure.rb +2 -0
  294. data/mod/04_settings/set/self/style.rb +2 -0
  295. data/mod/04_settings/set/self/table_of_contents.rb +2 -0
  296. data/mod/04_settings/set/self/thanks.rb +2 -0
  297. data/mod/04_settings/set/self/update.rb +2 -0
  298. data/mod/04_settings/set/type/setting.rb +82 -0
  299. data/mod/04_settings/spec/set/right/add_help_spec.rb +5 -0
  300. data/mod/04_settings/spec/set/right/comment_spec.rb +41 -0
  301. data/mod/04_settings/spec/set/right/create_spec.rb +10 -0
  302. data/mod/04_settings/spec/set/right/default_spec.rb +5 -0
  303. data/mod/04_settings/spec/set/right/delete_spec.rb +5 -0
  304. data/mod/04_settings/spec/set/right/help_spec.rb +5 -0
  305. data/mod/04_settings/spec/set/right/read_spec.rb +5 -0
  306. data/mod/04_settings/spec/set/right/script_spec.rb +24 -0
  307. data/mod/04_settings/spec/set/right/structure_spec.rb +17 -0
  308. data/mod/04_settings/spec/set/right/style_spec.rb +29 -0
  309. data/mod/04_settings/spec/set/right/update_spec.rb +5 -0
  310. data/mod/04_settings/spec/set/type/setting_spec.rb +10 -0
  311. data/mod/05_email/format/email_html_format.rb +9 -0
  312. data/mod/05_email/format/email_text_format.rb +11 -0
  313. data/mod/05_email/lib/card/follow_option.rb +90 -0
  314. data/mod/05_email/set/all/email_html.rb +5 -0
  315. data/mod/05_email/set/all/email_text.rb +5 -0
  316. data/mod/05_email/set/all/follow.rb +256 -0
  317. data/mod/05_email/set/all/notify.rb +223 -0
  318. data/mod/05_email/set/all/observer.rb +27 -0
  319. data/mod/05_email/set/right/bcc.rb +45 -0
  320. data/mod/05_email/set/right/cc.rb +3 -0
  321. data/mod/05_email/set/right/follow.rb +9 -0
  322. data/mod/05_email/set/right/follow_fields.rb +3 -0
  323. data/mod/05_email/set/right/followers.rb +30 -0
  324. data/mod/05_email/set/right/following.rb +52 -0
  325. data/mod/05_email/set/right/from.rb +3 -0
  326. data/mod/05_email/set/right/html_message.rb +3 -0
  327. data/mod/05_email/set/right/to.rb +3 -0
  328. data/mod/05_email/set/self/always.rb +14 -0
  329. data/mod/05_email/set/self/created.rb +21 -0
  330. data/mod/05_email/set/self/edited.rb +24 -0
  331. data/mod/05_email/set/self/follow.rb +2 -0
  332. data/mod/05_email/set/self/follow_defaults.rb +66 -0
  333. data/mod/05_email/set/self/never.rb +15 -0
  334. data/mod/05_email/set/type/email_template.rb +113 -0
  335. data/mod/05_email/set/type_plus_right/user/follow.rb +176 -0
  336. data/mod/05_email/spec/set/all/follow_spec.rb +133 -0
  337. data/mod/05_email/spec/set/all/notify_spec.rb +364 -0
  338. data/mod/05_email/spec/set/all/observer_spec.rb +76 -0
  339. data/mod/05_email/spec/set/right/followers_spec.rb +126 -0
  340. data/mod/05_email/spec/set/right/following_spec.rb +4 -0
  341. data/mod/05_email/spec/set/self/follow_defaults_spec.rb +18 -0
  342. data/mod/05_standard/file/103/icon-6566.ico +0 -0
  343. data/mod/05_standard/file/103/large-6566.ico +0 -0
  344. data/mod/05_standard/file/103/medium-6566.ico +0 -0
  345. data/mod/05_standard/file/103/original-6566.ico +0 -0
  346. data/mod/05_standard/file/103/small-6566.ico +0 -0
  347. data/mod/05_standard/file/79/icon-6556.png +0 -0
  348. data/mod/05_standard/file/79/large-6556.png +0 -0
  349. data/mod/05_standard/file/79/medium-6556.png +0 -0
  350. data/mod/05_standard/file/79/original-6556.png +0 -0
  351. data/mod/05_standard/file/79/small-6556.png +0 -0
  352. data/mod/05_standard/file/790/icon-6419.png +0 -0
  353. data/mod/05_standard/file/790/large-6419.png +0 -0
  354. data/mod/05_standard/file/790/medium-6419.png +0 -0
  355. data/mod/05_standard/file/790/original-6419.png +0 -0
  356. data/mod/05_standard/file/790/small-6419.png +0 -0
  357. data/mod/05_standard/set/all/account.rb +67 -0
  358. data/mod/05_standard/set/all/attach.rb +152 -0
  359. data/mod/05_standard/set/all/comment.rb +39 -0
  360. data/mod/05_standard/set/all/error.rb +214 -0
  361. data/mod/05_standard/set/all/event_viz.rb +62 -0
  362. data/mod/05_standard/set/all/links.rb +110 -0
  363. data/mod/05_standard/set/all/rich_html/content.rb +173 -0
  364. data/mod/05_standard/set/all/rich_html/editing.rb +145 -0
  365. data/mod/05_standard/set/all/rich_html/form.rb +234 -0
  366. data/mod/05_standard/set/all/rich_html/header.rb +64 -0
  367. data/mod/05_standard/set/all/rich_html/wrapper.rb +105 -0
  368. data/mod/05_standard/set/right/account.rb +180 -0
  369. data/mod/05_standard/set/right/email.rb +52 -0
  370. data/mod/05_standard/set/right/password.rb +39 -0
  371. data/mod/05_standard/set/right/salt.rb +5 -0
  372. data/mod/05_standard/set/right/stats.rb +35 -0
  373. data/mod/05_standard/set/right/status.rb +9 -0
  374. data/mod/05_standard/set/right/token.rb +5 -0
  375. data/mod/05_standard/set/right/when_created.rb +5 -0
  376. data/mod/05_standard/set/right/when_last_edited.rb +5 -0
  377. data/mod/05_standard/set/rstar/rules.rb +407 -0
  378. data/mod/05_standard/set/self/account_links.rb +61 -0
  379. data/mod/05_standard/set/self/alerts.rb +5 -0
  380. data/mod/05_standard/set/self/all.rb +21 -0
  381. data/mod/05_standard/set/self/foot.rb +8 -0
  382. data/mod/05_standard/set/self/head.rb +121 -0
  383. data/mod/05_standard/set/self/navbox.rb +20 -0
  384. data/mod/05_standard/set/self/now.rb +6 -0
  385. data/mod/05_standard/set/self/recent.rb +48 -0
  386. data/mod/05_standard/set/self/search.rb +43 -0
  387. data/mod/05_standard/set/self/signin.rb +121 -0
  388. data/mod/05_standard/set/self/stats.rb +91 -0
  389. data/mod/05_standard/set/self/version.rb +9 -0
  390. data/mod/05_standard/set/type/basic.rb +46 -0
  391. data/mod/05_standard/set/type/cardtype.rb +43 -0
  392. data/mod/05_standard/set/type/date.rb +8 -0
  393. data/mod/05_standard/set/type/file.rb +85 -0
  394. data/mod/05_standard/set/type/html.rb +22 -0
  395. data/mod/05_standard/set/type/image.rb +67 -0
  396. data/mod/05_standard/set/type/layout_type.rb +14 -0
  397. data/mod/05_standard/set/type/number.rb +19 -0
  398. data/mod/05_standard/set/type/phrase.rb +3 -0
  399. data/mod/05_standard/set/type/search_type.rb +243 -0
  400. data/mod/05_standard/set/type/set.rb +198 -0
  401. data/mod/05_standard/set/type/signup.rb +144 -0
  402. data/mod/05_standard/set/type/toggle.rb +12 -0
  403. data/mod/05_standard/set/type/uri.rb +11 -0
  404. data/mod/05_standard/set/type/user.rb +72 -0
  405. data/mod/05_standard/spec/chunk/include_spec.rb +186 -0
  406. data/mod/05_standard/spec/chunk/link_spec.rb +61 -0
  407. data/mod/05_standard/spec/format/css_format_spec.rb +5 -0
  408. data/mod/05_standard/spec/format/csv_format_spec.rb +5 -0
  409. data/mod/05_standard/spec/format/email_html_format_spec.rb +5 -0
  410. data/mod/05_standard/spec/format/file_format_spec.rb +5 -0
  411. data/mod/05_standard/spec/format/js_format_spec.rb +5 -0
  412. data/mod/05_standard/spec/format/json_format_spec.rb +5 -0
  413. data/mod/05_standard/spec/format/rss_format_spec.rb +5 -0
  414. data/mod/05_standard/spec/format/xml_format_spec.rb +5 -0
  415. data/mod/05_standard/spec/set/all/account_spec.rb +137 -0
  416. data/mod/05_standard/spec/set/all/attach_spec.rb +9 -0
  417. data/mod/05_standard/spec/set/all/comment_spec.rb +5 -0
  418. data/mod/05_standard/spec/set/all/email_html_spec.rb +15 -0
  419. data/mod/05_standard/spec/set/all/error_spec.rb +9 -0
  420. data/mod/05_standard/spec/set/all/event_viz_spec.rb +9 -0
  421. data/mod/05_standard/spec/set/all/history_spec.rb +173 -0
  422. data/mod/05_standard/spec/set/all/rich_html/form_spec.rb +43 -0
  423. data/mod/05_standard/spec/set/all/rich_html/wrapper_spec.rb +28 -0
  424. data/mod/05_standard/spec/set/right/account_spec.rb +162 -0
  425. data/mod/05_standard/spec/set/right/email_spec.rb +55 -0
  426. data/mod/05_standard/spec/set/right/password_spec.rb +45 -0
  427. data/mod/05_standard/spec/set/right/salt_spec.rb +5 -0
  428. data/mod/05_standard/spec/set/right/stats_spec.rb +13 -0
  429. data/mod/05_standard/spec/set/right/status_spec.rb +5 -0
  430. data/mod/05_standard/spec/set/right/token_spec.rb +5 -0
  431. data/mod/05_standard/spec/set/right/when_created_spec.rb +7 -0
  432. data/mod/05_standard/spec/set/right/when_last_edited_spec.rb +7 -0
  433. data/mod/05_standard/spec/set/rstar/rules_spec.rb +25 -0
  434. data/mod/05_standard/spec/set/self/account_links_spec.rb +9 -0
  435. data/mod/05_standard/spec/set/self/alerts_spec.rb +5 -0
  436. data/mod/05_standard/spec/set/self/all_spec.rb +48 -0
  437. data/mod/05_standard/spec/set/self/foot_spec.rb +5 -0
  438. data/mod/05_standard/spec/set/self/head_spec.rb +17 -0
  439. data/mod/05_standard/spec/set/self/navbox_spec.rb +7 -0
  440. data/mod/05_standard/spec/set/self/now_spec.rb +7 -0
  441. data/mod/05_standard/spec/set/self/recent_spec.rb +5 -0
  442. data/mod/05_standard/spec/set/self/search_spec.rb +5 -0
  443. data/mod/05_standard/spec/set/self/signin_spec.rb +73 -0
  444. data/mod/05_standard/spec/set/self/stats_spec.rb +12 -0
  445. data/mod/05_standard/spec/set/self/version_spec.rb +7 -0
  446. data/mod/05_standard/spec/set/type/basic_spec.rb +5 -0
  447. data/mod/05_standard/spec/set/type/cardtype_spec.rb +5 -0
  448. data/mod/05_standard/spec/set/type/date_spec.rb +7 -0
  449. data/mod/05_standard/spec/set/type/email_template_spec.rb +208 -0
  450. data/mod/05_standard/spec/set/type/file_spec.rb +5 -0
  451. data/mod/05_standard/spec/set/type/html_spec.rb +23 -0
  452. data/mod/05_standard/spec/set/type/image_spec.rb +16 -0
  453. data/mod/05_standard/spec/set/type/layout_type_spec.rb +7 -0
  454. data/mod/05_standard/spec/set/type/number_spec.rb +7 -0
  455. data/mod/05_standard/spec/set/type/phrase_spec.rb +7 -0
  456. data/mod/05_standard/spec/set/type/search_type_spec.rb +27 -0
  457. data/mod/05_standard/spec/set/type/set_spec.rb +26 -0
  458. data/mod/05_standard/spec/set/type/signup_spec.rb +228 -0
  459. data/mod/05_standard/spec/set/type/toggle_spec.rb +12 -0
  460. data/mod/05_standard/spec/set/type/uri_spec.rb +41 -0
  461. data/mod/05_standard/spec/set/type/user_spec.rb +5 -0
  462. data/mod/06_bootstrap/lib/javascript/bootstrap.js +2306 -0
  463. data/mod/06_bootstrap/lib/javascript/bootstrap.min.js +7 -0
  464. data/mod/06_bootstrap/lib/stylesheets/bootstrap-theme.css +476 -0
  465. data/mod/06_bootstrap/lib/stylesheets/bootstrap.css +6565 -0
  466. data/mod/06_bootstrap/lib/stylesheets/darkly.css +6583 -0
  467. data/mod/06_bootstrap/set/all/bootstrap/form.rb +37 -0
  468. data/mod/06_bootstrap/set/all/bootstrap/header.rb +29 -0
  469. data/mod/06_bootstrap/set/all/bootstrap/wrapper.rb +12 -0
  470. data/mod/06_bootstrap/set/all/rich_bootstrap.rb +28 -0
  471. data/mod/06_bootstrap/set/self/bootstrap_css.rb +7 -0
  472. data/mod/06_bootstrap/set/self/bootstrap_js.rb +7 -0
  473. data/mod/06_bootstrap/set/self/bootstrap_theme_css.rb +7 -0
  474. data/mod/06_bootstrap/set/self/navbox.rb +32 -0
  475. data/mod/06_bootstrap/set/type/search_type.rb +79 -0
  476. data/mod/06_bootstrap/spec/set/all/bootstrap/form_spec.rb +13 -0
  477. data/spec/lib/card/action_spec.rb +14 -0
  478. data/spec/lib/card/auth_spec.rb +17 -0
  479. data/spec/lib/card/cache_spec.rb +122 -0
  480. data/spec/lib/card/chunk_spec.rb +17 -0
  481. data/spec/lib/card/codename_spec.rb +25 -0
  482. data/spec/lib/card/content_spec.rb +314 -0
  483. data/spec/lib/card/diff_spec.rb +210 -0
  484. data/spec/lib/card/format_spec.rb +82 -0
  485. data/spec/lib/card/loader_spec.rb +39 -0
  486. data/spec/lib/card/log_spec.rb +270 -0
  487. data/spec/lib/card/name_spec.rb +279 -0
  488. data/spec/lib/card/query_spec.rb +456 -0
  489. data/spec/lib/card/reference_spec.rb +213 -0
  490. data/spec/lib/card/set_pattern_spec.rb +56 -0
  491. data/spec/lib/card/set_spec.rb +88 -0
  492. data/spec/mailers/mailer_spec.rb +64 -0
  493. data/spec/models/card/cardtype_spec.rb +216 -0
  494. data/spec/models/card/create_spec.rb +82 -0
  495. data/spec/models/card/trash_spec.rb +260 -0
  496. data/spec/models/card/type_transition_spec.rb +161 -0
  497. data/spec/models/card/validation_spec.rb +36 -0
  498. data/spec/models/card_spec.rb +177 -0
  499. data/spec/spec_helper.rb +130 -0
  500. data/test/fixtures/.gitkeep +0 -0
  501. data/test/fixtures/card_actions.yml +5706 -0
  502. data/test/fixtures/card_acts.yml +835 -0
  503. data/test/fixtures/card_changes.yml +17182 -0
  504. data/test/fixtures/card_references.yml +5405 -0
  505. data/test/fixtures/cards.yml +15533 -0
  506. data/test/fixtures/mao2.jpg +0 -0
  507. data/test/fixtures/rails.gif +0 -0
  508. data/test/seed.rb +201 -0
  509. metadata +762 -38
  510. data/.gitignore +0 -17
  511. data/Gemfile +0 -4
  512. data/LICENSE.txt +0 -22
  513. data/README.md +0 -29
  514. data/Rakefile +0 -1
@@ -0,0 +1,274 @@
1
+ /*!
2
+ Autosize 1.18.13
3
+ license: MIT
4
+ http://www.jacklmoore.com/autosize
5
+ */
6
+ (function ($) {
7
+ var
8
+ defaults = {
9
+ className: 'autosizejs',
10
+ id: 'autosizejs',
11
+ append: '\n',
12
+ callback: false,
13
+ resizeDelay: 10,
14
+ placeholder: true
15
+ },
16
+
17
+ // border:0 is unnecessary, but avoids a bug in Firefox on OSX
18
+ copy = '<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden; transition:none; -webkit-transition:none; -moz-transition:none;"/>',
19
+
20
+ // line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.
21
+ typographyStyles = [
22
+ 'fontFamily',
23
+ 'fontSize',
24
+ 'fontWeight',
25
+ 'fontStyle',
26
+ 'letterSpacing',
27
+ 'textTransform',
28
+ 'wordSpacing',
29
+ 'textIndent',
30
+ 'whiteSpace'
31
+ ],
32
+
33
+ // to keep track which textarea is being mirrored when adjust() is called.
34
+ mirrored,
35
+
36
+ // the mirror element, which is used to calculate what size the mirrored element should be.
37
+ mirror = $(copy).data('autosize', true)[0];
38
+
39
+ // test that line-height can be accurately copied.
40
+ mirror.style.lineHeight = '99px';
41
+ if ($(mirror).css('lineHeight') === '99px') {
42
+ typographyStyles.push('lineHeight');
43
+ }
44
+ mirror.style.lineHeight = '';
45
+
46
+ $.fn.autosize = function (options) {
47
+ if (!this.length) {
48
+ return this;
49
+ }
50
+
51
+ options = $.extend({}, defaults, options || {});
52
+
53
+ if (mirror.parentNode !== document.body) {
54
+ $(document.body).append(mirror);
55
+ }
56
+
57
+ return this.each(function () {
58
+ var
59
+ ta = this,
60
+ $ta = $(ta),
61
+ maxHeight,
62
+ minHeight,
63
+ boxOffset = 0,
64
+ callback = $.isFunction(options.callback),
65
+ originalStyles = {
66
+ height: ta.style.height,
67
+ overflow: ta.style.overflow,
68
+ overflowY: ta.style.overflowY,
69
+ wordWrap: ta.style.wordWrap,
70
+ resize: ta.style.resize
71
+ },
72
+ timeout,
73
+ width = $ta.width(),
74
+ taResize = $ta.css('resize');
75
+
76
+ if ($ta.data('autosize')) {
77
+ // exit if autosize has already been applied, or if the textarea is the mirror element.
78
+ return;
79
+ }
80
+ $ta.data('autosize', true);
81
+
82
+ if ($ta.css('box-sizing') === 'border-box' || $ta.css('-moz-box-sizing') === 'border-box' || $ta.css('-webkit-box-sizing') === 'border-box'){
83
+ boxOffset = $ta.outerHeight() - $ta.height();
84
+ }
85
+
86
+ // IE8 and lower return 'auto', which parses to NaN, if no min-height is set.
87
+ minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height());
88
+
89
+ $ta.css({
90
+ overflow: 'hidden',
91
+ overflowY: 'hidden',
92
+ wordWrap: 'break-word' // horizontal overflow is hidden, so break-word is necessary for handling words longer than the textarea width
93
+ });
94
+
95
+ if (taResize === 'vertical') {
96
+ $ta.css('resize','none');
97
+ } else if (taResize === 'both') {
98
+ $ta.css('resize', 'horizontal');
99
+ }
100
+
101
+ // The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.
102
+ // window.getComputedStyle, getBoundingClientRect returning a width are unsupported, but also unneeded in IE8 and lower.
103
+ function setWidth() {
104
+ var width;
105
+ var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : false;
106
+
107
+ if (style) {
108
+
109
+ width = ta.getBoundingClientRect().width;
110
+
111
+ if (width === 0 || typeof width !== 'number') {
112
+ width = parseInt(style.width,10);
113
+ }
114
+
115
+ $.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
116
+ width -= parseInt(style[val],10);
117
+ });
118
+ } else {
119
+ width = $ta.width();
120
+ }
121
+
122
+ mirror.style.width = Math.max(width,0) + 'px';
123
+ }
124
+
125
+ function initMirror() {
126
+ var styles = {};
127
+
128
+ mirrored = ta;
129
+ mirror.className = options.className;
130
+ mirror.id = options.id;
131
+ maxHeight = parseInt($ta.css('maxHeight'), 10);
132
+
133
+ // mirror is a duplicate textarea located off-screen that
134
+ // is automatically updated to contain the same text as the
135
+ // original textarea. mirror always has a height of 0.
136
+ // This gives a cross-browser supported way getting the actual
137
+ // height of the text, through the scrollTop property.
138
+ $.each(typographyStyles, function(i,val){
139
+ styles[val] = $ta.css(val);
140
+ });
141
+
142
+ $(mirror).css(styles).attr('wrap', $ta.attr('wrap'));
143
+
144
+ setWidth();
145
+
146
+ // Chrome-specific fix:
147
+ // When the textarea y-overflow is hidden, Chrome doesn't reflow the text to account for the space
148
+ // made available by removing the scrollbar. This workaround triggers the reflow for Chrome.
149
+ if (window.chrome) {
150
+ var width = ta.style.width;
151
+ ta.style.width = '0px';
152
+ var ignore = ta.offsetWidth;
153
+ ta.style.width = width;
154
+ }
155
+ }
156
+
157
+ // Using mainly bare JS in this function because it is going
158
+ // to fire very often while typing, and needs to very efficient.
159
+ function adjust() {
160
+ var height, original;
161
+
162
+ if (mirrored !== ta) {
163
+ initMirror();
164
+ } else {
165
+ setWidth();
166
+ }
167
+
168
+ if (!ta.value && options.placeholder) {
169
+ // If the textarea is empty, copy the placeholder text into
170
+ // the mirror control and use that for sizing so that we
171
+ // don't end up with placeholder getting trimmed.
172
+ mirror.value = ($ta.attr("placeholder") || '');
173
+ } else {
174
+ mirror.value = ta.value;
175
+ }
176
+
177
+ mirror.value += options.append || '';
178
+ mirror.style.overflowY = ta.style.overflowY;
179
+ original = parseInt(ta.style.height,10);
180
+
181
+ // Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied
182
+ mirror.scrollTop = 0;
183
+
184
+ mirror.scrollTop = 9e4;
185
+
186
+ // Using scrollTop rather than scrollHeight because scrollHeight is non-standard and includes padding.
187
+ height = mirror.scrollTop;
188
+
189
+ if (maxHeight && height > maxHeight) {
190
+ ta.style.overflowY = 'scroll';
191
+ height = maxHeight;
192
+ } else {
193
+ ta.style.overflowY = 'hidden';
194
+ if (height < minHeight) {
195
+ height = minHeight;
196
+ }
197
+ }
198
+
199
+ height += boxOffset;
200
+
201
+ if (original !== height) {
202
+ ta.style.height = height + 'px';
203
+ if (callback) {
204
+ options.callback.call(ta,ta);
205
+ }
206
+ $ta.trigger('autosize.resized');
207
+ }
208
+ }
209
+
210
+ function resize () {
211
+ clearTimeout(timeout);
212
+ timeout = setTimeout(function(){
213
+ var newWidth = $ta.width();
214
+
215
+ if (newWidth !== width) {
216
+ width = newWidth;
217
+ adjust();
218
+ }
219
+ }, parseInt(options.resizeDelay,10));
220
+ }
221
+
222
+ if ('onpropertychange' in ta) {
223
+ if ('oninput' in ta) {
224
+ // Detects IE9. IE9 does not fire onpropertychange or oninput for deletions,
225
+ // so binding to onkeyup to catch most of those occasions. There is no way that I
226
+ // know of to detect something like 'cut' in IE9.
227
+ $ta.on('input.autosize keyup.autosize', adjust);
228
+ } else {
229
+ // IE7 / IE8
230
+ $ta.on('propertychange.autosize', function(){
231
+ if(event.propertyName === 'value'){
232
+ adjust();
233
+ }
234
+ });
235
+ }
236
+ } else {
237
+ // Modern Browsers
238
+ $ta.on('input.autosize', adjust);
239
+ }
240
+
241
+ // Set options.resizeDelay to false if using fixed-width textarea elements.
242
+ // Uses a timeout and width check to reduce the amount of times adjust needs to be called after window resize.
243
+
244
+ if (options.resizeDelay !== false) {
245
+ $(window).on('resize.autosize', resize);
246
+ }
247
+
248
+ // Event for manual triggering if needed.
249
+ // Should only be needed when the value of the textarea is changed through JavaScript rather than user input.
250
+ $ta.on('autosize.resize', adjust);
251
+
252
+ // Event for manual triggering that also forces the styles to update as well.
253
+ // Should only be needed if one of typography styles of the textarea change, and the textarea is already the target of the adjust method.
254
+ $ta.on('autosize.resizeIncludeStyle', function() {
255
+ mirrored = null;
256
+ adjust();
257
+ });
258
+
259
+ $ta.on('autosize.destroy', function(){
260
+ mirrored = null;
261
+ clearTimeout(timeout);
262
+ $(window).off('resize', resize);
263
+ $ta
264
+ .off('autosize')
265
+ .off('.autosize')
266
+ .css(originalStyles)
267
+ .removeData('autosize');
268
+ });
269
+
270
+ // Call adjust in case the textarea already contains text.
271
+ adjust();
272
+ });
273
+ };
274
+ }(jQuery || $)); // jQuery or jQuery-like library, such as Zepto
@@ -0,0 +1,1114 @@
1
+ /*
2
+ * jQuery File Upload Plugin 5.19.8
3
+ * https://github.com/blueimp/jQuery-File-Upload
4
+ *
5
+ * Copyright 2010, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint nomen: true, unparam: true, regexp: true */
13
+ /*global define, window, document, File, Blob, FormData, location */
14
+
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'jquery.ui.widget'
22
+ ], factory);
23
+ } else {
24
+ // Browser globals:
25
+ factory(window.jQuery);
26
+ }
27
+ }(function ($) {
28
+ 'use strict';
29
+
30
+ // The FileReader API is not actually used, but works as feature detection,
31
+ // as e.g. Safari supports XHR file uploads via the FormData API,
32
+ // but not non-multipart XHR file uploads:
33
+ $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
34
+ $.support.xhrFormDataFileUpload = !!window.FormData;
35
+
36
+ // The fileupload widget listens for change events on file input fields defined
37
+ // via fileInput setting and paste or drop events of the given dropZone.
38
+ // In addition to the default jQuery Widget methods, the fileupload widget
39
+ // exposes the "add" and "send" methods, to add or directly send files using
40
+ // the fileupload API.
41
+ // By default, files added via file input selection, paste, drag & drop or
42
+ // "add" method are uploaded immediately, but it is possible to override
43
+ // the "add" callback option to queue file uploads.
44
+ $.widget('blueimp.fileupload', {
45
+
46
+ options: {
47
+ // The drop target element(s), by the default the complete document.
48
+ // Set to null to disable drag & drop support:
49
+ dropZone: $(document),
50
+ // The paste target element(s), by the default the complete document.
51
+ // Set to null to disable paste support:
52
+ pasteZone: $(document),
53
+ // The file input field(s), that are listened to for change events.
54
+ // If undefined, it is set to the file input fields inside
55
+ // of the widget element on plugin initialization.
56
+ // Set to null to disable the change listener.
57
+ fileInput: undefined,
58
+ // By default, the file input field is replaced with a clone after
59
+ // each input field change event. This is required for iframe transport
60
+ // queues and allows change events to be fired for the same file
61
+ // selection, but can be disabled by setting the following option to false:
62
+ replaceFileInput: true,
63
+ // The parameter name for the file form data (the request argument name).
64
+ // If undefined or empty, the name property of the file input field is
65
+ // used, or "files[]" if the file input name property is also empty,
66
+ // can be a string or an array of strings:
67
+ paramName: undefined,
68
+ // By default, each file of a selection is uploaded using an individual
69
+ // request for XHR type uploads. Set to false to upload file
70
+ // selections in one request each:
71
+ singleFileUploads: true,
72
+ // To limit the number of files uploaded with one XHR request,
73
+ // set the following option to an integer greater than 0:
74
+ limitMultiFileUploads: undefined,
75
+ // Set the following option to true to issue all file upload requests
76
+ // in a sequential order:
77
+ sequentialUploads: false,
78
+ // To limit the number of concurrent uploads,
79
+ // set the following option to an integer greater than 0:
80
+ limitConcurrentUploads: undefined,
81
+ // Set the following option to true to force iframe transport uploads:
82
+ forceIframeTransport: false,
83
+ // Set the following option to the location of a redirect url on the
84
+ // origin server, for cross-domain iframe transport uploads:
85
+ redirect: undefined,
86
+ // The parameter name for the redirect url, sent as part of the form
87
+ // data and set to 'redirect' if this option is empty:
88
+ redirectParamName: undefined,
89
+ // Set the following option to the location of a postMessage window,
90
+ // to enable postMessage transport uploads:
91
+ postMessage: undefined,
92
+ // By default, XHR file uploads are sent as multipart/form-data.
93
+ // The iframe transport is always using multipart/form-data.
94
+ // Set to false to enable non-multipart XHR uploads:
95
+ multipart: true,
96
+ // To upload large files in smaller chunks, set the following option
97
+ // to a preferred maximum chunk size. If set to 0, null or undefined,
98
+ // or the browser does not support the required Blob API, files will
99
+ // be uploaded as a whole.
100
+ maxChunkSize: undefined,
101
+ // When a non-multipart upload or a chunked multipart upload has been
102
+ // aborted, this option can be used to resume the upload by setting
103
+ // it to the size of the already uploaded bytes. This option is most
104
+ // useful when modifying the options object inside of the "add" or
105
+ // "send" callbacks, as the options are cloned for each file upload.
106
+ uploadedBytes: undefined,
107
+ // By default, failed (abort or error) file uploads are removed from the
108
+ // global progress calculation. Set the following option to false to
109
+ // prevent recalculating the global progress data:
110
+ recalculateProgress: true,
111
+ // Interval in milliseconds to calculate and trigger progress events:
112
+ progressInterval: 100,
113
+ // Interval in milliseconds to calculate progress bitrate:
114
+ bitrateInterval: 500,
115
+
116
+ // Additional form data to be sent along with the file uploads can be set
117
+ // using this option, which accepts an array of objects with name and
118
+ // value properties, a function returning such an array, a FormData
119
+ // object (for XHR file uploads), or a simple object.
120
+ // The form of the first fileInput is given as parameter to the function:
121
+ formData: function (form) {
122
+ return form.serializeArray();
123
+ },
124
+
125
+ // The add callback is invoked as soon as files are added to the fileupload
126
+ // widget (via file input selection, drag & drop, paste or add API call).
127
+ // If the singleFileUploads option is enabled, this callback will be
128
+ // called once for each file in the selection for XHR file uplaods, else
129
+ // once for each file selection.
130
+ // The upload starts when the submit method is invoked on the data parameter.
131
+ // The data object contains a files property holding the added files
132
+ // and allows to override plugin options as well as define ajax settings.
133
+ // Listeners for this callback can also be bound the following way:
134
+ // .bind('fileuploadadd', func);
135
+ // data.submit() returns a Promise object and allows to attach additional
136
+ // handlers using jQuery's Deferred callbacks:
137
+ // data.submit().done(func).fail(func).always(func);
138
+ add: function (e, data) {
139
+ data.submit();
140
+ },
141
+
142
+ // Other callbacks:
143
+ // Callback for the submit event of each file upload:
144
+ // submit: function (e, data) {}, // .bind('fileuploadsubmit', func);
145
+ // Callback for the start of each file upload request:
146
+ // send: function (e, data) {}, // .bind('fileuploadsend', func);
147
+ // Callback for successful uploads:
148
+ // done: function (e, data) {}, // .bind('fileuploaddone', func);
149
+ // Callback for failed (abort or error) uploads:
150
+ // fail: function (e, data) {}, // .bind('fileuploadfail', func);
151
+ // Callback for completed (success, abort or error) requests:
152
+ // always: function (e, data) {}, // .bind('fileuploadalways', func);
153
+ // Callback for upload progress events:
154
+ // progress: function (e, data) {}, // .bind('fileuploadprogress', func);
155
+ // Callback for global upload progress events:
156
+ // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func);
157
+ // Callback for uploads start, equivalent to the global ajaxStart event:
158
+ // start: function (e) {}, // .bind('fileuploadstart', func);
159
+ // Callback for uploads stop, equivalent to the global ajaxStop event:
160
+ // stop: function (e) {}, // .bind('fileuploadstop', func);
161
+ // Callback for change events of the fileInput(s):
162
+ // change: function (e, data) {}, // .bind('fileuploadchange', func);
163
+ // Callback for paste events to the pasteZone(s):
164
+ // paste: function (e, data) {}, // .bind('fileuploadpaste', func);
165
+ // Callback for drop events of the dropZone(s):
166
+ // drop: function (e, data) {}, // .bind('fileuploaddrop', func);
167
+ // Callback for dragover events of the dropZone(s):
168
+ // dragover: function (e) {}, // .bind('fileuploaddragover', func);
169
+
170
+ // The plugin options are used as settings object for the ajax calls.
171
+ // The following are jQuery ajax settings required for the file uploads:
172
+ processData: false,
173
+ contentType: false,
174
+ cache: false
175
+ },
176
+
177
+ // A list of options that require a refresh after assigning a new value:
178
+ _refreshOptionsList: [
179
+ 'fileInput',
180
+ 'dropZone',
181
+ 'pasteZone',
182
+ 'multipart',
183
+ 'forceIframeTransport'
184
+ ],
185
+
186
+ _BitrateTimer: function () {
187
+ this.timestamp = +(new Date());
188
+ this.loaded = 0;
189
+ this.bitrate = 0;
190
+ this.getBitrate = function (now, loaded, interval) {
191
+ var timeDiff = now - this.timestamp;
192
+ if (!this.bitrate || !interval || timeDiff > interval) {
193
+ this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8;
194
+ this.loaded = loaded;
195
+ this.timestamp = now;
196
+ }
197
+ return this.bitrate;
198
+ };
199
+ },
200
+
201
+ _isXHRUpload: function (options) {
202
+ return !options.forceIframeTransport &&
203
+ ((!options.multipart && $.support.xhrFileUpload) ||
204
+ $.support.xhrFormDataFileUpload);
205
+ },
206
+
207
+ _getFormData: function (options) {
208
+ var formData;
209
+ if (typeof options.formData === 'function') {
210
+ return options.formData(options.form);
211
+ }
212
+ if ($.isArray(options.formData)) {
213
+ return options.formData;
214
+ }
215
+ if (options.formData) {
216
+ formData = [];
217
+ $.each(options.formData, function (name, value) {
218
+ formData.push({name: name, value: value});
219
+ });
220
+ return formData;
221
+ }
222
+ return [];
223
+ },
224
+
225
+ _getTotal: function (files) {
226
+ var total = 0;
227
+ $.each(files, function (index, file) {
228
+ total += file.size || 1;
229
+ });
230
+ return total;
231
+ },
232
+
233
+ _onProgress: function (e, data) {
234
+ if (e.lengthComputable) {
235
+ var now = +(new Date()),
236
+ total,
237
+ loaded;
238
+ if (data._time && data.progressInterval &&
239
+ (now - data._time < data.progressInterval) &&
240
+ e.loaded !== e.total) {
241
+ return;
242
+ }
243
+ data._time = now;
244
+ total = data.total || this._getTotal(data.files);
245
+ loaded = parseInt(
246
+ e.loaded / e.total * (data.chunkSize || total),
247
+ 10
248
+ ) + (data.uploadedBytes || 0);
249
+ this._loaded += loaded - (data.loaded || data.uploadedBytes || 0);
250
+ data.lengthComputable = true;
251
+ data.loaded = loaded;
252
+ data.total = total;
253
+ data.bitrate = data._bitrateTimer.getBitrate(
254
+ now,
255
+ loaded,
256
+ data.bitrateInterval
257
+ );
258
+ // Trigger a custom progress event with a total data property set
259
+ // to the file size(s) of the current upload and a loaded data
260
+ // property calculated accordingly:
261
+ this._trigger('progress', e, data);
262
+ // Trigger a global progress event for all current file uploads,
263
+ // including ajax calls queued for sequential file uploads:
264
+ this._trigger('progressall', e, {
265
+ lengthComputable: true,
266
+ loaded: this._loaded,
267
+ total: this._total,
268
+ bitrate: this._bitrateTimer.getBitrate(
269
+ now,
270
+ this._loaded,
271
+ data.bitrateInterval
272
+ )
273
+ });
274
+ }
275
+ },
276
+
277
+ _initProgressListener: function (options) {
278
+ var that = this,
279
+ xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr();
280
+ // Accesss to the native XHR object is required to add event listeners
281
+ // for the upload progress event:
282
+ if (xhr.upload) {
283
+ $(xhr.upload).bind('progress', function (e) {
284
+ var oe = e.originalEvent;
285
+ // Make sure the progress event properties get copied over:
286
+ e.lengthComputable = oe.lengthComputable;
287
+ e.loaded = oe.loaded;
288
+ e.total = oe.total;
289
+ that._onProgress(e, options);
290
+ });
291
+ options.xhr = function () {
292
+ return xhr;
293
+ };
294
+ }
295
+ },
296
+
297
+ _initXHRData: function (options) {
298
+ var formData,
299
+ file = options.files[0],
300
+ // Ignore non-multipart setting if not supported:
301
+ multipart = options.multipart || !$.support.xhrFileUpload,
302
+ paramName = options.paramName[0];
303
+ options.headers = options.headers || {};
304
+ if (options.contentRange) {
305
+ options.headers['Content-Range'] = options.contentRange;
306
+ }
307
+ if (!multipart) {
308
+ options.headers['Content-Disposition'] = 'attachment; filename="' +
309
+ encodeURI(file.name) + '"';
310
+ options.contentType = file.type;
311
+ options.data = options.blob || file;
312
+ } else if ($.support.xhrFormDataFileUpload) {
313
+ if (options.postMessage) {
314
+ // window.postMessage does not allow sending FormData
315
+ // objects, so we just add the File/Blob objects to
316
+ // the formData array and let the postMessage window
317
+ // create the FormData object out of this array:
318
+ formData = this._getFormData(options);
319
+ if (options.blob) {
320
+ formData.push({
321
+ name: paramName,
322
+ value: options.blob
323
+ });
324
+ } else {
325
+ $.each(options.files, function (index, file) {
326
+ formData.push({
327
+ name: options.paramName[index] || paramName,
328
+ value: file
329
+ });
330
+ });
331
+ }
332
+ } else {
333
+ if (options.formData instanceof FormData) {
334
+ formData = options.formData;
335
+ } else {
336
+ formData = new FormData();
337
+ $.each(this._getFormData(options), function (index, field) {
338
+ formData.append(field.name, field.value);
339
+ });
340
+ }
341
+ if (options.blob) {
342
+ options.headers['Content-Disposition'] = 'attachment; filename="' +
343
+ encodeURI(file.name) + '"';
344
+ formData.append(paramName, options.blob, file.name);
345
+ } else {
346
+ $.each(options.files, function (index, file) {
347
+ // Files are also Blob instances, but some browsers
348
+ // (Firefox 3.6) support the File API but not Blobs.
349
+ // This check allows the tests to run with
350
+ // dummy objects:
351
+ if ((window.Blob && file instanceof Blob) ||
352
+ (window.File && file instanceof File)) {
353
+ formData.append(
354
+ options.paramName[index] || paramName,
355
+ file,
356
+ file.name
357
+ );
358
+ }
359
+ });
360
+ }
361
+ }
362
+ options.data = formData;
363
+ }
364
+ // Blob reference is not needed anymore, free memory:
365
+ options.blob = null;
366
+ },
367
+
368
+ _initIframeSettings: function (options) {
369
+ // Setting the dataType to iframe enables the iframe transport:
370
+ options.dataType = 'iframe ' + (options.dataType || '');
371
+ // The iframe transport accepts a serialized array as form data:
372
+ options.formData = this._getFormData(options);
373
+ // Add redirect url to form data on cross-domain uploads:
374
+ if (options.redirect && $('<a></a>').prop('href', options.url)
375
+ .prop('host') !== location.host) {
376
+ options.formData.push({
377
+ name: options.redirectParamName || 'redirect',
378
+ value: options.redirect
379
+ });
380
+ }
381
+ },
382
+
383
+ _initDataSettings: function (options) {
384
+ if (this._isXHRUpload(options)) {
385
+ if (!this._chunkedUpload(options, true)) {
386
+ if (!options.data) {
387
+ this._initXHRData(options);
388
+ }
389
+ this._initProgressListener(options);
390
+ }
391
+ if (options.postMessage) {
392
+ // Setting the dataType to postmessage enables the
393
+ // postMessage transport:
394
+ options.dataType = 'postmessage ' + (options.dataType || '');
395
+ }
396
+ } else {
397
+ this._initIframeSettings(options, 'iframe');
398
+ }
399
+ },
400
+
401
+ _getParamName: function (options) {
402
+ var fileInput = $(options.fileInput),
403
+ paramName = options.paramName;
404
+ if (!paramName) {
405
+ paramName = [];
406
+ fileInput.each(function () {
407
+ var input = $(this),
408
+ name = input.prop('name') || 'files[]',
409
+ i = (input.prop('files') || [1]).length;
410
+ while (i) {
411
+ paramName.push(name);
412
+ i -= 1;
413
+ }
414
+ });
415
+ if (!paramName.length) {
416
+ paramName = [fileInput.prop('name') || 'files[]'];
417
+ }
418
+ } else if (!$.isArray(paramName)) {
419
+ paramName = [paramName];
420
+ }
421
+ return paramName;
422
+ },
423
+
424
+ _initFormSettings: function (options) {
425
+ // Retrieve missing options from the input field and the
426
+ // associated form, if available:
427
+ if (!options.form || !options.form.length) {
428
+ options.form = $(options.fileInput.prop('form'));
429
+ // If the given file input doesn't have an associated form,
430
+ // use the default widget file input's form:
431
+ if (!options.form.length) {
432
+ options.form = $(this.options.fileInput.prop('form'));
433
+ }
434
+ }
435
+ options.paramName = this._getParamName(options);
436
+ if (!options.url) {
437
+ options.url = options.form.prop('action') || location.href;
438
+ }
439
+ // The HTTP request method must be "POST" or "PUT":
440
+ options.type = (options.type || options.form.prop('method') || '')
441
+ .toUpperCase();
442
+ if (options.type !== 'POST' && options.type !== 'PUT' &&
443
+ options.type !== 'PATCH') {
444
+ options.type = 'POST';
445
+ }
446
+ if (!options.formAcceptCharset) {
447
+ options.formAcceptCharset = options.form.attr('accept-charset');
448
+ }
449
+ },
450
+
451
+ _getAJAXSettings: function (data) {
452
+ var options = $.extend({}, this.options, data);
453
+ this._initFormSettings(options);
454
+ this._initDataSettings(options);
455
+ return options;
456
+ },
457
+
458
+ // Maps jqXHR callbacks to the equivalent
459
+ // methods of the given Promise object:
460
+ _enhancePromise: function (promise) {
461
+ promise.success = promise.done;
462
+ promise.error = promise.fail;
463
+ promise.complete = promise.always;
464
+ return promise;
465
+ },
466
+
467
+ // Creates and returns a Promise object enhanced with
468
+ // the jqXHR methods abort, success, error and complete:
469
+ _getXHRPromise: function (resolveOrReject, context, args) {
470
+ var dfd = $.Deferred(),
471
+ promise = dfd.promise();
472
+ context = context || this.options.context || promise;
473
+ if (resolveOrReject === true) {
474
+ dfd.resolveWith(context, args);
475
+ } else if (resolveOrReject === false) {
476
+ dfd.rejectWith(context, args);
477
+ }
478
+ promise.abort = dfd.promise;
479
+ return this._enhancePromise(promise);
480
+ },
481
+
482
+ // Parses the Range header from the server response
483
+ // and returns the uploaded bytes:
484
+ _getUploadedBytes: function (jqXHR) {
485
+ var range = jqXHR.getResponseHeader('Range'),
486
+ parts = range && range.split('-'),
487
+ upperBytesPos = parts && parts.length > 1 &&
488
+ parseInt(parts[1], 10);
489
+ return upperBytesPos && upperBytesPos + 1;
490
+ },
491
+
492
+ // Uploads a file in multiple, sequential requests
493
+ // by splitting the file up in multiple blob chunks.
494
+ // If the second parameter is true, only tests if the file
495
+ // should be uploaded in chunks, but does not invoke any
496
+ // upload requests:
497
+ _chunkedUpload: function (options, testOnly) {
498
+ var that = this,
499
+ file = options.files[0],
500
+ fs = file.size,
501
+ ub = options.uploadedBytes = options.uploadedBytes || 0,
502
+ mcs = options.maxChunkSize || fs,
503
+ slice = file.slice || file.webkitSlice || file.mozSlice,
504
+ dfd = $.Deferred(),
505
+ promise = dfd.promise(),
506
+ jqXHR,
507
+ upload;
508
+ if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) ||
509
+ options.data) {
510
+ return false;
511
+ }
512
+ if (testOnly) {
513
+ return true;
514
+ }
515
+ if (ub >= fs) {
516
+ file.error = 'Uploaded bytes exceed file size';
517
+ return this._getXHRPromise(
518
+ false,
519
+ options.context,
520
+ [null, 'error', file.error]
521
+ );
522
+ }
523
+ // The chunk upload method:
524
+ upload = function (i) {
525
+ // Clone the options object for each chunk upload:
526
+ var o = $.extend({}, options);
527
+ o.blob = slice.call(
528
+ file,
529
+ ub,
530
+ ub + mcs,
531
+ file.type
532
+ );
533
+ // Store the current chunk size, as the blob itself
534
+ // will be dereferenced after data processing:
535
+ o.chunkSize = o.blob.size;
536
+ // Expose the chunk bytes position range:
537
+ o.contentRange = 'bytes ' + ub + '-' +
538
+ (ub + o.chunkSize - 1) + '/' + fs;
539
+ // Process the upload data (the blob and potential form data):
540
+ that._initXHRData(o);
541
+ // Add progress listeners for this chunk upload:
542
+ that._initProgressListener(o);
543
+ jqXHR = ($.ajax(o) || that._getXHRPromise(false, o.context))
544
+ .done(function (result, textStatus, jqXHR) {
545
+ ub = that._getUploadedBytes(jqXHR) ||
546
+ (ub + o.chunkSize);
547
+ // Create a progress event if upload is done and
548
+ // no progress event has been invoked for this chunk:
549
+ if (!o.loaded) {
550
+ that._onProgress($.Event('progress', {
551
+ lengthComputable: true,
552
+ loaded: ub - o.uploadedBytes,
553
+ total: ub - o.uploadedBytes
554
+ }), o);
555
+ }
556
+ options.uploadedBytes = o.uploadedBytes = ub;
557
+ if (ub < fs) {
558
+ // File upload not yet complete,
559
+ // continue with the next chunk:
560
+ upload();
561
+ } else {
562
+ dfd.resolveWith(
563
+ o.context,
564
+ [result, textStatus, jqXHR]
565
+ );
566
+ }
567
+ })
568
+ .fail(function (jqXHR, textStatus, errorThrown) {
569
+ dfd.rejectWith(
570
+ o.context,
571
+ [jqXHR, textStatus, errorThrown]
572
+ );
573
+ });
574
+ };
575
+ this._enhancePromise(promise);
576
+ promise.abort = function () {
577
+ return jqXHR.abort();
578
+ };
579
+ upload();
580
+ return promise;
581
+ },
582
+
583
+ _beforeSend: function (e, data) {
584
+ if (this._active === 0) {
585
+ // the start callback is triggered when an upload starts
586
+ // and no other uploads are currently running,
587
+ // equivalent to the global ajaxStart event:
588
+ this._trigger('start');
589
+ // Set timer for global bitrate progress calculation:
590
+ this._bitrateTimer = new this._BitrateTimer();
591
+ }
592
+ this._active += 1;
593
+ // Initialize the global progress values:
594
+ this._loaded += data.uploadedBytes || 0;
595
+ this._total += this._getTotal(data.files);
596
+ },
597
+
598
+ _onDone: function (result, textStatus, jqXHR, options) {
599
+ if (!this._isXHRUpload(options)) {
600
+ // Create a progress event for each iframe load:
601
+ this._onProgress($.Event('progress', {
602
+ lengthComputable: true,
603
+ loaded: 1,
604
+ total: 1
605
+ }), options);
606
+ }
607
+ options.result = result;
608
+ options.textStatus = textStatus;
609
+ options.jqXHR = jqXHR;
610
+ this._trigger('done', null, options);
611
+ },
612
+
613
+ _onFail: function (jqXHR, textStatus, errorThrown, options) {
614
+ options.jqXHR = jqXHR;
615
+ options.textStatus = textStatus;
616
+ options.errorThrown = errorThrown;
617
+ this._trigger('fail', null, options);
618
+ if (options.recalculateProgress) {
619
+ // Remove the failed (error or abort) file upload from
620
+ // the global progress calculation:
621
+ this._loaded -= options.loaded || options.uploadedBytes || 0;
622
+ this._total -= options.total || this._getTotal(options.files);
623
+ }
624
+ },
625
+
626
+ _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) {
627
+ this._active -= 1;
628
+ options.textStatus = textStatus;
629
+ if (jqXHRorError && jqXHRorError.always) {
630
+ options.jqXHR = jqXHRorError;
631
+ options.result = jqXHRorResult;
632
+ } else {
633
+ options.jqXHR = jqXHRorResult;
634
+ options.errorThrown = jqXHRorError;
635
+ }
636
+ this._trigger('always', null, options);
637
+ if (this._active === 0) {
638
+ // The stop callback is triggered when all uploads have
639
+ // been completed, equivalent to the global ajaxStop event:
640
+ this._trigger('stop');
641
+ // Reset the global progress values:
642
+ this._loaded = this._total = 0;
643
+ this._bitrateTimer = null;
644
+ }
645
+ },
646
+
647
+ _onSend: function (e, data) {
648
+ var that = this,
649
+ jqXHR,
650
+ aborted,
651
+ slot,
652
+ pipe,
653
+ options = that._getAJAXSettings(data),
654
+ send = function () {
655
+ that._sending += 1;
656
+ // Set timer for bitrate progress calculation:
657
+ options._bitrateTimer = new that._BitrateTimer();
658
+ jqXHR = jqXHR || (
659
+ ((aborted || that._trigger('send', e, options) === false) &&
660
+ that._getXHRPromise(false, options.context, aborted)) ||
661
+ that._chunkedUpload(options) || $.ajax(options)
662
+ ).done(function (result, textStatus, jqXHR) {
663
+ that._onDone(result, textStatus, jqXHR, options);
664
+ }).fail(function (jqXHR, textStatus, errorThrown) {
665
+ that._onFail(jqXHR, textStatus, errorThrown, options);
666
+ }).always(function (jqXHRorResult, textStatus, jqXHRorError) {
667
+ that._sending -= 1;
668
+ that._onAlways(
669
+ jqXHRorResult,
670
+ textStatus,
671
+ jqXHRorError,
672
+ options
673
+ );
674
+ if (options.limitConcurrentUploads &&
675
+ options.limitConcurrentUploads > that._sending) {
676
+ // Start the next queued upload,
677
+ // that has not been aborted:
678
+ var nextSlot = that._slots.shift(),
679
+ isPending;
680
+ while (nextSlot) {
681
+ // jQuery 1.6 doesn't provide .state(),
682
+ // while jQuery 1.8+ removed .isRejected():
683
+ isPending = nextSlot.state ?
684
+ nextSlot.state() === 'pending' :
685
+ !nextSlot.isRejected();
686
+ if (isPending) {
687
+ nextSlot.resolve();
688
+ break;
689
+ }
690
+ nextSlot = that._slots.shift();
691
+ }
692
+ }
693
+ });
694
+ return jqXHR;
695
+ };
696
+ this._beforeSend(e, options);
697
+ if (this.options.sequentialUploads ||
698
+ (this.options.limitConcurrentUploads &&
699
+ this.options.limitConcurrentUploads <= this._sending)) {
700
+ if (this.options.limitConcurrentUploads > 1) {
701
+ slot = $.Deferred();
702
+ this._slots.push(slot);
703
+ pipe = slot.pipe(send);
704
+ } else {
705
+ pipe = (this._sequence = this._sequence.pipe(send, send));
706
+ }
707
+ // Return the piped Promise object, enhanced with an abort method,
708
+ // which is delegated to the jqXHR object of the current upload,
709
+ // and jqXHR callbacks mapped to the equivalent Promise methods:
710
+ pipe.abort = function () {
711
+ aborted = [undefined, 'abort', 'abort'];
712
+ if (!jqXHR) {
713
+ if (slot) {
714
+ slot.rejectWith(options.context, aborted);
715
+ }
716
+ return send();
717
+ }
718
+ return jqXHR.abort();
719
+ };
720
+ return this._enhancePromise(pipe);
721
+ }
722
+ return send();
723
+ },
724
+
725
+ _onAdd: function (e, data) {
726
+ var that = this,
727
+ result = true,
728
+ options = $.extend({}, this.options, data),
729
+ limit = options.limitMultiFileUploads,
730
+ paramName = this._getParamName(options),
731
+ paramNameSet,
732
+ paramNameSlice,
733
+ fileSet,
734
+ i;
735
+ if (!(options.singleFileUploads || limit) ||
736
+ !this._isXHRUpload(options)) {
737
+ fileSet = [data.files];
738
+ paramNameSet = [paramName];
739
+ } else if (!options.singleFileUploads && limit) {
740
+ fileSet = [];
741
+ paramNameSet = [];
742
+ for (i = 0; i < data.files.length; i += limit) {
743
+ fileSet.push(data.files.slice(i, i + limit));
744
+ paramNameSlice = paramName.slice(i, i + limit);
745
+ if (!paramNameSlice.length) {
746
+ paramNameSlice = paramName;
747
+ }
748
+ paramNameSet.push(paramNameSlice);
749
+ }
750
+ } else {
751
+ paramNameSet = paramName;
752
+ }
753
+ data.originalFiles = data.files;
754
+ $.each(fileSet || data.files, function (index, element) {
755
+ var newData = $.extend({}, data);
756
+ newData.files = fileSet ? element : [element];
757
+ newData.paramName = paramNameSet[index];
758
+ newData.submit = function () {
759
+ newData.jqXHR = this.jqXHR =
760
+ (that._trigger('submit', e, this) !== false) &&
761
+ that._onSend(e, this);
762
+ return this.jqXHR;
763
+ };
764
+ result = that._trigger('add', e, newData);
765
+ return result;
766
+ });
767
+ return result;
768
+ },
769
+
770
+ _replaceFileInput: function (input) {
771
+ var inputClone = input.clone(true);
772
+ $('<form></form>').append(inputClone)[0].reset();
773
+ // Detaching allows to insert the fileInput on another form
774
+ // without loosing the file input value:
775
+ input.after(inputClone).detach();
776
+ // Avoid memory leaks with the detached file input:
777
+ $.cleanData(input.unbind('remove'));
778
+ // Replace the original file input element in the fileInput
779
+ // elements set with the clone, which has been copied including
780
+ // event handlers:
781
+ this.options.fileInput = this.options.fileInput.map(function (i, el) {
782
+ if (el === input[0]) {
783
+ return inputClone[0];
784
+ }
785
+ return el;
786
+ });
787
+ // If the widget has been initialized on the file input itself,
788
+ // override this.element with the file input clone:
789
+ if (input[0] === this.element[0]) {
790
+ this.element = inputClone;
791
+ }
792
+ },
793
+
794
+ _handleFileTreeEntry: function (entry, path) {
795
+ var that = this,
796
+ dfd = $.Deferred(),
797
+ errorHandler = function (e) {
798
+ if (e && !e.entry) {
799
+ e.entry = entry;
800
+ }
801
+ // Since $.when returns immediately if one
802
+ // Deferred is rejected, we use resolve instead.
803
+ // This allows valid files and invalid items
804
+ // to be returned together in one set:
805
+ dfd.resolve([e]);
806
+ },
807
+ dirReader;
808
+ path = path || '';
809
+ if (entry.isFile) {
810
+ if (entry._file) {
811
+ // Workaround for Chrome bug #149735
812
+ entry._file.relativePath = path;
813
+ dfd.resolve(entry._file);
814
+ } else {
815
+ entry.file(function (file) {
816
+ file.relativePath = path;
817
+ dfd.resolve(file);
818
+ }, errorHandler);
819
+ }
820
+ } else if (entry.isDirectory) {
821
+ dirReader = entry.createReader();
822
+ dirReader.readEntries(function (entries) {
823
+ that._handleFileTreeEntries(
824
+ entries,
825
+ path + entry.name + '/'
826
+ ).done(function (files) {
827
+ dfd.resolve(files);
828
+ }).fail(errorHandler);
829
+ }, errorHandler);
830
+ } else {
831
+ // Return an empy list for file system items
832
+ // other than files or directories:
833
+ dfd.resolve([]);
834
+ }
835
+ return dfd.promise();
836
+ },
837
+
838
+ _handleFileTreeEntries: function (entries, path) {
839
+ var that = this;
840
+ return $.when.apply(
841
+ $,
842
+ $.map(entries, function (entry) {
843
+ return that._handleFileTreeEntry(entry, path);
844
+ })
845
+ ).pipe(function () {
846
+ return Array.prototype.concat.apply(
847
+ [],
848
+ arguments
849
+ );
850
+ });
851
+ },
852
+
853
+ _getDroppedFiles: function (dataTransfer) {
854
+ dataTransfer = dataTransfer || {};
855
+ var items = dataTransfer.items;
856
+ if (items && items.length && (items[0].webkitGetAsEntry ||
857
+ items[0].getAsEntry)) {
858
+ return this._handleFileTreeEntries(
859
+ $.map(items, function (item) {
860
+ var entry;
861
+ if (item.webkitGetAsEntry) {
862
+ entry = item.webkitGetAsEntry();
863
+ if (entry) {
864
+ // Workaround for Chrome bug #149735:
865
+ entry._file = item.getAsFile();
866
+ }
867
+ return entry;
868
+ }
869
+ return item.getAsEntry();
870
+ })
871
+ );
872
+ }
873
+ return $.Deferred().resolve(
874
+ $.makeArray(dataTransfer.files)
875
+ ).promise();
876
+ },
877
+
878
+ _getSingleFileInputFiles: function (fileInput) {
879
+ fileInput = $(fileInput);
880
+ var entries = fileInput.prop('webkitEntries') ||
881
+ fileInput.prop('entries'),
882
+ files,
883
+ value;
884
+ if (entries && entries.length) {
885
+ return this._handleFileTreeEntries(entries);
886
+ }
887
+ files = $.makeArray(fileInput.prop('files'));
888
+ if (!files.length) {
889
+ value = fileInput.prop('value');
890
+ if (!value) {
891
+ return $.Deferred().resolve([]).promise();
892
+ }
893
+ // If the files property is not available, the browser does not
894
+ // support the File API and we add a pseudo File object with
895
+ // the input value as name with path information removed:
896
+ files = [{name: value.replace(/^.*\\/, '')}];
897
+ } else if (files[0].name === undefined && files[0].fileName) {
898
+ // File normalization for Safari 4 and Firefox 3:
899
+ $.each(files, function (index, file) {
900
+ file.name = file.fileName;
901
+ file.size = file.fileSize;
902
+ });
903
+ }
904
+ return $.Deferred().resolve(files).promise();
905
+ },
906
+
907
+ _getFileInputFiles: function (fileInput) {
908
+ if (!(fileInput instanceof $) || fileInput.length === 1) {
909
+ return this._getSingleFileInputFiles(fileInput);
910
+ }
911
+ return $.when.apply(
912
+ $,
913
+ $.map(fileInput, this._getSingleFileInputFiles)
914
+ ).pipe(function () {
915
+ return Array.prototype.concat.apply(
916
+ [],
917
+ arguments
918
+ );
919
+ });
920
+ },
921
+
922
+ _onChange: function (e) {
923
+ var that = this,
924
+ data = {
925
+ fileInput: $(e.target),
926
+ form: $(e.target.form)
927
+ };
928
+ this._getFileInputFiles(data.fileInput).always(function (files) {
929
+ data.files = files;
930
+ if (that.options.replaceFileInput) {
931
+ that._replaceFileInput(data.fileInput);
932
+ }
933
+ if (that._trigger('change', e, data) !== false) {
934
+ that._onAdd(e, data);
935
+ }
936
+ });
937
+ },
938
+
939
+ _onPaste: function (e) {
940
+ var cbd = e.originalEvent.clipboardData,
941
+ items = (cbd && cbd.items) || [],
942
+ data = {files: []};
943
+ $.each(items, function (index, item) {
944
+ var file = item.getAsFile && item.getAsFile();
945
+ if (file) {
946
+ data.files.push(file);
947
+ }
948
+ });
949
+ if (this._trigger('paste', e, data) === false ||
950
+ this._onAdd(e, data) === false) {
951
+ return false;
952
+ }
953
+ },
954
+
955
+ _onDrop: function (e) {
956
+ var that = this,
957
+ dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer,
958
+ data = {};
959
+ if (dataTransfer && dataTransfer.files && dataTransfer.files.length) {
960
+ e.preventDefault();
961
+ }
962
+ this._getDroppedFiles(dataTransfer).always(function (files) {
963
+ data.files = files;
964
+ if (that._trigger('drop', e, data) !== false) {
965
+ that._onAdd(e, data);
966
+ }
967
+ });
968
+ },
969
+
970
+ _onDragOver: function (e) {
971
+ var dataTransfer = e.dataTransfer = e.originalEvent.dataTransfer;
972
+ if (this._trigger('dragover', e) === false) {
973
+ return false;
974
+ }
975
+ if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1) {
976
+ dataTransfer.dropEffect = 'copy';
977
+ e.preventDefault();
978
+ }
979
+ },
980
+
981
+ _initEventHandlers: function () {
982
+ if (this._isXHRUpload(this.options)) {
983
+ this._on(this.options.dropZone, {
984
+ dragover: this._onDragOver,
985
+ drop: this._onDrop
986
+ });
987
+ this._on(this.options.pasteZone, {
988
+ paste: this._onPaste
989
+ });
990
+ }
991
+ this._on(this.options.fileInput, {
992
+ change: this._onChange
993
+ });
994
+ },
995
+
996
+ _destroyEventHandlers: function () {
997
+ this._off(this.options.dropZone, 'dragover drop');
998
+ this._off(this.options.pasteZone, 'paste');
999
+ this._off(this.options.fileInput, 'change');
1000
+ },
1001
+
1002
+ _setOption: function (key, value) {
1003
+ var refresh = $.inArray(key, this._refreshOptionsList) !== -1;
1004
+ if (refresh) {
1005
+ this._destroyEventHandlers();
1006
+ }
1007
+ this._super(key, value);
1008
+ if (refresh) {
1009
+ this._initSpecialOptions();
1010
+ this._initEventHandlers();
1011
+ }
1012
+ },
1013
+
1014
+ _initSpecialOptions: function () {
1015
+ var options = this.options;
1016
+ if (options.fileInput === undefined) {
1017
+ options.fileInput = this.element.is('input[type="file"]') ?
1018
+ this.element : this.element.find('input[type="file"]');
1019
+ } else if (!(options.fileInput instanceof $)) {
1020
+ options.fileInput = $(options.fileInput);
1021
+ }
1022
+ if (!(options.dropZone instanceof $)) {
1023
+ options.dropZone = $(options.dropZone);
1024
+ }
1025
+ if (!(options.pasteZone instanceof $)) {
1026
+ options.pasteZone = $(options.pasteZone);
1027
+ }
1028
+ },
1029
+
1030
+ _create: function () {
1031
+ var options = this.options;
1032
+ // Initialize options set via HTML5 data-attributes:
1033
+ $.extend(options, $(this.element[0].cloneNode(false)).data());
1034
+ this._initSpecialOptions();
1035
+ this._slots = [];
1036
+ this._sequence = this._getXHRPromise(true);
1037
+ this._sending = this._active = this._loaded = this._total = 0;
1038
+ this._initEventHandlers();
1039
+ },
1040
+
1041
+ _destroy: function () {
1042
+ this._destroyEventHandlers();
1043
+ },
1044
+
1045
+ // This method is exposed to the widget API and allows adding files
1046
+ // using the fileupload API. The data parameter accepts an object which
1047
+ // must have a files property and can contain additional options:
1048
+ // .fileupload('add', {files: filesList});
1049
+ add: function (data) {
1050
+ var that = this;
1051
+ if (!data || this.options.disabled) {
1052
+ return;
1053
+ }
1054
+ if (data.fileInput && !data.files) {
1055
+ this._getFileInputFiles(data.fileInput).always(function (files) {
1056
+ data.files = files;
1057
+ that._onAdd(null, data);
1058
+ });
1059
+ } else {
1060
+ data.files = $.makeArray(data.files);
1061
+ this._onAdd(null, data);
1062
+ }
1063
+ },
1064
+
1065
+ // This method is exposed to the widget API and allows sending files
1066
+ // using the fileupload API. The data parameter accepts an object which
1067
+ // must have a files or fileInput property and can contain additional options:
1068
+ // .fileupload('send', {files: filesList});
1069
+ // The method returns a Promise object for the file upload call.
1070
+ send: function (data) {
1071
+ if (data && !this.options.disabled) {
1072
+ if (data.fileInput && !data.files) {
1073
+ var that = this,
1074
+ dfd = $.Deferred(),
1075
+ promise = dfd.promise(),
1076
+ jqXHR,
1077
+ aborted;
1078
+ promise.abort = function () {
1079
+ aborted = true;
1080
+ if (jqXHR) {
1081
+ return jqXHR.abort();
1082
+ }
1083
+ dfd.reject(null, 'abort', 'abort');
1084
+ return promise;
1085
+ };
1086
+ this._getFileInputFiles(data.fileInput).always(
1087
+ function (files) {
1088
+ if (aborted) {
1089
+ return;
1090
+ }
1091
+ data.files = files;
1092
+ jqXHR = that._onSend(null, data).then(
1093
+ function (result, textStatus, jqXHR) {
1094
+ dfd.resolve(result, textStatus, jqXHR);
1095
+ },
1096
+ function (jqXHR, textStatus, errorThrown) {
1097
+ dfd.reject(jqXHR, textStatus, errorThrown);
1098
+ }
1099
+ );
1100
+ }
1101
+ );
1102
+ return this._enhancePromise(promise);
1103
+ }
1104
+ data.files = $.makeArray(data.files);
1105
+ if (data.files.length) {
1106
+ return this._onSend(null, data);
1107
+ }
1108
+ }
1109
+ return this._getXHRPromise(false, data && data.context);
1110
+ }
1111
+
1112
+ });
1113
+
1114
+ }));