catarse_full 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (865) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +19 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +45 -0
  5. data/app/assets/fonts/icomoon.eot +0 -0
  6. data/app/assets/fonts/icomoon.json +1 -0
  7. data/app/assets/fonts/icomoon.svg +30 -0
  8. data/app/assets/fonts/icomoon.ttf +0 -0
  9. data/app/assets/fonts/icomoon.woff +0 -0
  10. data/app/assets/images/.gitkeep +0 -0
  11. data/app/assets/images/auth/facebook_64.png +0 -0
  12. data/app/assets/images/auth/twitter_64.png +0 -0
  13. data/app/assets/images/catarse/ProjectUpdate.jpg +0 -0
  14. data/app/assets/images/catarse/back_icons.png +0 -0
  15. data/app/assets/images/catarse/back_statistics.gif +0 -0
  16. data/app/assets/images/catarse/backed_icon.png +0 -0
  17. data/app/assets/images/catarse/backer_city.png +0 -0
  18. data/app/assets/images/catarse/backer_info.gif +0 -0
  19. data/app/assets/images/catarse/backer_info.png +0 -0
  20. data/app/assets/images/catarse/background.png +0 -0
  21. data/app/assets/images/catarse/background_full.jpg +0 -0
  22. data/app/assets/images/catarse/banner-10-milhoes.png +0 -0
  23. data/app/assets/images/catarse/bg64x64_s3.png +0 -0
  24. data/app/assets/images/catarse/bg_air.jpg +0 -0
  25. data/app/assets/images/catarse/bg_explore.jpg +0 -0
  26. data/app/assets/images/catarse/bg_finish.jpg +0 -0
  27. data/app/assets/images/catarse/bg_guardian.jpg +0 -0
  28. data/app/assets/images/catarse/bg_heartbacker.jpg +0 -0
  29. data/app/assets/images/catarse/bg_money.jpg +0 -0
  30. data/app/assets/images/catarse/bg_moneytag.jpg +0 -0
  31. data/app/assets/images/catarse/bg_requirements.png +0 -0
  32. data/app/assets/images/catarse/bg_rewards.jpg +0 -0
  33. data/app/assets/images/catarse/bg_s3.png +0 -0
  34. data/app/assets/images/catarse/bg_send.png +0 -0
  35. data/app/assets/images/catarse/bg_steps.png +0 -0
  36. data/app/assets/images/catarse/bg_tips.png +0 -0
  37. data/app/assets/images/catarse/bg_tips1.png +0 -0
  38. data/app/assets/images/catarse/bg_tips2.png +0 -0
  39. data/app/assets/images/catarse/bg_tips3.png +0 -0
  40. data/app/assets/images/catarse/bg_tips4.png +0 -0
  41. data/app/assets/images/catarse/bg_tips5.png +0 -0
  42. data/app/assets/images/catarse/bg_tips6.png +0 -0
  43. data/app/assets/images/catarse/bg_tips7.png +0 -0
  44. data/app/assets/images/catarse/bg_tips8.png +0 -0
  45. data/app/assets/images/catarse/blog_icon17x14.png +0 -0
  46. data/app/assets/images/catarse/boleto_icon.png +0 -0
  47. data/app/assets/images/catarse/bot_guidelines.gif +0 -0
  48. data/app/assets/images/catarse/bot_profileUser.png +0 -0
  49. data/app/assets/images/catarse/box_alert.png +0 -0
  50. data/app/assets/images/catarse/box_download.png +0 -0
  51. data/app/assets/images/catarse/box_en.jpg +0 -0
  52. data/app/assets/images/catarse/box_pt.jpg +0 -0
  53. data/app/assets/images/catarse/bullet-green.png +0 -0
  54. data/app/assets/images/catarse/button_explore.png +0 -0
  55. data/app/assets/images/catarse/button_send.png +0 -0
  56. data/app/assets/images/catarse/category_icon14x14.png +0 -0
  57. data/app/assets/images/catarse/cc_icon.png +0 -0
  58. data/app/assets/images/catarse/comments_icon28x18.png +0 -0
  59. data/app/assets/images/catarse/comum_logo127x27.png +0 -0
  60. data/app/assets/images/catarse/confirmed_icon.png +0 -0
  61. data/app/assets/images/catarse/delete_16.png +0 -0
  62. data/app/assets/images/catarse/embed_icon19x9.png +0 -0
  63. data/app/assets/images/catarse/expiring_icon20x22.png +0 -0
  64. data/app/assets/images/catarse/explore_icon21x14.png +0 -0
  65. data/app/assets/images/catarse/explore_icon23x15.png +0 -0
  66. data/app/assets/images/catarse/facebook_black_icon.png +0 -0
  67. data/app/assets/images/catarse/facebook_icon13x26.png +0 -0
  68. data/app/assets/images/catarse/faq_icon18x18.png +0 -0
  69. data/app/assets/images/catarse/faq_video.png +0 -0
  70. data/app/assets/images/catarse/flagCity.png +0 -0
  71. data/app/assets/images/catarse/flagCityMg.png +0 -0
  72. data/app/assets/images/catarse/flagCityPoa.png +0 -0
  73. data/app/assets/images/catarse/flagCityRJ.png +0 -0
  74. data/app/assets/images/catarse/flagName.png +0 -0
  75. data/app/assets/images/catarse/flagNameMg.png +0 -0
  76. data/app/assets/images/catarse/flagNamePoa.png +0 -0
  77. data/app/assets/images/catarse/flagNameRJ.png +0 -0
  78. data/app/assets/images/catarse/flagNameSP.png +0 -0
  79. data/app/assets/images/catarse/gift-reward.png +0 -0
  80. data/app/assets/images/catarse/gift.png +0 -0
  81. data/app/assets/images/catarse/glyphicons-halflings-white.png +0 -0
  82. data/app/assets/images/catarse/glyphicons-halflings.png +0 -0
  83. data/app/assets/images/catarse/goal_icon36x17.png +0 -0
  84. data/app/assets/images/catarse/grey.png +0 -0
  85. data/app/assets/images/catarse/heart_icon17x14.png +0 -0
  86. data/app/assets/images/catarse/icon-fb.png +0 -0
  87. data/app/assets/images/catarse/icon-moip.png +0 -0
  88. data/app/assets/images/catarse/icon-paypal.png +0 -0
  89. data/app/assets/images/catarse/icon-tw.png +0 -0
  90. data/app/assets/images/catarse/icon_about.png +0 -0
  91. data/app/assets/images/catarse/icon_backerstep1.png +0 -0
  92. data/app/assets/images/catarse/icon_backerstep2.png +0 -0
  93. data/app/assets/images/catarse/icon_backerstep3.png +0 -0
  94. data/app/assets/images/catarse/icon_backerstep4.png +0 -0
  95. data/app/assets/images/catarse/icon_backerstep5.png +0 -0
  96. data/app/assets/images/catarse/icon_backersucessfull.png +0 -0
  97. data/app/assets/images/catarse/icon_backproject.png +0 -0
  98. data/app/assets/images/catarse/icon_bold.png +0 -0
  99. data/app/assets/images/catarse/icon_calc.png +0 -0
  100. data/app/assets/images/catarse/icon_colective.png +0 -0
  101. data/app/assets/images/catarse/icon_creative.png +0 -0
  102. data/app/assets/images/catarse/icon_credits.png +0 -0
  103. data/app/assets/images/catarse/icon_creditsmoney.png +0 -0
  104. data/app/assets/images/catarse/icon_datestart.png +0 -0
  105. data/app/assets/images/catarse/icon_donation.png +0 -0
  106. data/app/assets/images/catarse/icon_faq.png +0 -0
  107. data/app/assets/images/catarse/icon_gift.png +0 -0
  108. data/app/assets/images/catarse/icon_guidebacker.png +0 -0
  109. data/app/assets/images/catarse/icon_guidelinesstart.png +0 -0
  110. data/app/assets/images/catarse/icon_heart.png +0 -0
  111. data/app/assets/images/catarse/icon_italic.png +0 -0
  112. data/app/assets/images/catarse/icon_licosts.png +0 -0
  113. data/app/assets/images/catarse/icon_limagic.png +0 -0
  114. data/app/assets/images/catarse/icon_limoney.png +0 -0
  115. data/app/assets/images/catarse/icon_link.png +0 -0
  116. data/app/assets/images/catarse/icon_linktext.png +0 -0
  117. data/app/assets/images/catarse/icon_liwork.png +0 -0
  118. data/app/assets/images/catarse/icon_logo.png +0 -0
  119. data/app/assets/images/catarse/icon_media.png +0 -0
  120. data/app/assets/images/catarse/icon_new.png +0 -0
  121. data/app/assets/images/catarse/icon_nonprofit.png +0 -0
  122. data/app/assets/images/catarse/icon_projectnotfunded.png +0 -0
  123. data/app/assets/images/catarse/icon_projectsuccess.png +0 -0
  124. data/app/assets/images/catarse/icon_refreshproject.png +0 -0
  125. data/app/assets/images/catarse/icon_rewards.png +0 -0
  126. data/app/assets/images/catarse/icon_social.png +0 -0
  127. data/app/assets/images/catarse/icon_soldout.png +0 -0
  128. data/app/assets/images/catarse/icon_step1.png +0 -0
  129. data/app/assets/images/catarse/icon_step2.png +0 -0
  130. data/app/assets/images/catarse/icon_step3.png +0 -0
  131. data/app/assets/images/catarse/icon_step4.png +0 -0
  132. data/app/assets/images/catarse/icon_submitbacker.png +0 -0
  133. data/app/assets/images/catarse/icon_tag.png +0 -0
  134. data/app/assets/images/catarse/icon_time.png +0 -0
  135. data/app/assets/images/catarse/icon_url.png +0 -0
  136. data/app/assets/images/catarse/icon_video.png +0 -0
  137. data/app/assets/images/catarse/icon_vimeo.png +0 -0
  138. data/app/assets/images/catarse/institutional_video_icon16x16.png +0 -0
  139. data/app/assets/images/catarse/label_green.png +0 -0
  140. data/app/assets/images/catarse/label_green_list.png +0 -0
  141. data/app/assets/images/catarse/label_orange.png +0 -0
  142. data/app/assets/images/catarse/label_orange_list.png +0 -0
  143. data/app/assets/images/catarse/link_icon14x14.png +0 -0
  144. data/app/assets/images/catarse/logo-fb.jpg +0 -0
  145. data/app/assets/images/catarse/logo.png +0 -0
  146. data/app/assets/images/catarse/min_star12x11.png +0 -0
  147. data/app/assets/images/catarse/moip-choice.png +0 -0
  148. data/app/assets/images/catarse/multide_logo55x36.png +0 -0
  149. data/app/assets/images/catarse/newsletter_icon18x15.png +0 -0
  150. data/app/assets/images/catarse/opendata_icon26x26.png +0 -0
  151. data/app/assets/images/catarse/partners_icon26x26.png +0 -0
  152. data/app/assets/images/catarse/payment_account.jpg +0 -0
  153. data/app/assets/images/catarse/payment_boleto.jpg +0 -0
  154. data/app/assets/images/catarse/payment_cards.jpg +0 -0
  155. data/app/assets/images/catarse/paypal-choice.png +0 -0
  156. data/app/assets/images/catarse/pencil_16.png +0 -0
  157. data/app/assets/images/catarse/play89x89.png +0 -0
  158. data/app/assets/images/catarse/post_title_image.png +0 -0
  159. data/app/assets/images/catarse/power_logo200x43.png +0 -0
  160. data/app/assets/images/catarse/profile_icon19x14.png +0 -0
  161. data/app/assets/images/catarse/project_about.png +0 -0
  162. data/app/assets/images/catarse/recents_icon18x23.png +0 -0
  163. data/app/assets/images/catarse/recents_icon31x17.png +0 -0
  164. data/app/assets/images/catarse/recompensa24x20.png +0 -0
  165. data/app/assets/images/catarse/reward_box.png +0 -0
  166. data/app/assets/images/catarse/reward_count_icon18x17.png +0 -0
  167. data/app/assets/images/catarse/reward_icon.png +0 -0
  168. data/app/assets/images/catarse/schedule_icon19x22.png +0 -0
  169. data/app/assets/images/catarse/search_submit15x15.png +0 -0
  170. data/app/assets/images/catarse/sidebar_backers_icon26x19.png +0 -0
  171. data/app/assets/images/catarse/social_big_icons.png +0 -0
  172. data/app/assets/images/catarse/social_icons.png +0 -0
  173. data/app/assets/images/catarse/submit_back_icon25x22.png +0 -0
  174. data/app/assets/images/catarse/submit_project_icon25x13.png +0 -0
  175. data/app/assets/images/catarse/team_adriano.jpg +0 -0
  176. data/app/assets/images/catarse/team_diego.jpg +0 -0
  177. data/app/assets/images/catarse/team_diogo.jpg +0 -0
  178. data/app/assets/images/catarse/team_evelise.jpg +0 -0
  179. data/app/assets/images/catarse/team_luciana.jpg +0 -0
  180. data/app/assets/images/catarse/team_luis.jpg +0 -0
  181. data/app/assets/images/catarse/team_renato.jpg +0 -0
  182. data/app/assets/images/catarse/team_rodrigo.jpg +0 -0
  183. data/app/assets/images/catarse/team_ton.jpg +0 -0
  184. data/app/assets/images/catarse/thumb_step.jpg +0 -0
  185. data/app/assets/images/catarse/thumbs_up_icon16x16.png +0 -0
  186. data/app/assets/images/catarse/tick_16.png +0 -0
  187. data/app/assets/images/catarse/time_icon19x30.png +0 -0
  188. data/app/assets/images/catarse/title_component149x40.png +0 -0
  189. data/app/assets/images/catarse/title_component241x40.png +0 -0
  190. data/app/assets/images/catarse/twitter_black_icon.png +0 -0
  191. data/app/assets/images/catarse/twitter_icon28x24.png +0 -0
  192. data/app/assets/images/catarse/video_sample_cover477x330.jpg +0 -0
  193. data/app/assets/images/catarse_bootstrap/botao_bemvindo_EN_big.png +0 -0
  194. data/app/assets/images/catarse_bootstrap/botao_bemvindo_PT_big.png +0 -0
  195. data/app/assets/images/catarse_bootstrap/catarse-assets.png +0 -0
  196. data/app/assets/images/catarse_bootstrap/feedback-close.png +0 -0
  197. data/app/assets/images/catarse_bootstrap/feedback-key.png +0 -0
  198. data/app/assets/images/catarse_bootstrap/feedback-open.png +0 -0
  199. data/app/assets/images/catarse_bootstrap/logo_icon_catarse.png +0 -0
  200. data/app/assets/images/catarse_full/.gitkeep +0 -0
  201. data/app/assets/images/channels/avatar.png +0 -0
  202. data/app/assets/images/channels/banner.png +0 -0
  203. data/app/assets/images/channels/banner_tile.jpg +0 -0
  204. data/app/assets/images/channels/capa_asas.jpg +0 -0
  205. data/app/assets/images/channels/header_system.png +0 -0
  206. data/app/assets/images/channels/logo_asas_notificacao.png +0 -0
  207. data/app/assets/images/channels/successful.png +0 -0
  208. data/app/assets/images/delete_16.png +0 -0
  209. data/app/assets/images/dropdown.png +0 -0
  210. data/app/assets/images/facebook_share.png +0 -0
  211. data/app/assets/images/favicon.ico +0 -0
  212. data/app/assets/images/gravatar.png +0 -0
  213. data/app/assets/images/icon_alertheader.png +0 -0
  214. data/app/assets/images/jquery-ui/ui-bg_diagonals-small_0_aaaaaa_40x40.png +0 -0
  215. data/app/assets/images/jquery-ui/ui-bg_diagonals-thick_15_444444_40x40.png +0 -0
  216. data/app/assets/images/jquery-ui/ui-bg_diagonals-thick_95_ffdc2e_40x40.png +0 -0
  217. data/app/assets/images/jquery-ui/ui-bg_glass_55_fbf5d0_1x400.png +0 -0
  218. data/app/assets/images/jquery-ui/ui-bg_highlight-hard_30_285c00_1x100.png +0 -0
  219. data/app/assets/images/jquery-ui/ui-bg_highlight-soft_33_3a8104_1x100.png +0 -0
  220. data/app/assets/images/jquery-ui/ui-bg_highlight-soft_50_4eb305_1x100.png +0 -0
  221. data/app/assets/images/jquery-ui/ui-bg_highlight-soft_60_4ca20b_1x100.png +0 -0
  222. data/app/assets/images/jquery-ui/ui-bg_inset-soft_10_285c00_1x100.png +0 -0
  223. data/app/assets/images/jquery-ui/ui-icons_4eb305_256x240.png +0 -0
  224. data/app/assets/images/jquery-ui/ui-icons_72b42d_256x240.png +0 -0
  225. data/app/assets/images/jquery-ui/ui-icons_cd0a0a_256x240.png +0 -0
  226. data/app/assets/images/jquery-ui/ui-icons_ffffff_256x240.png +0 -0
  227. data/app/assets/images/list_cards.jpg +0 -0
  228. data/app/assets/images/loading.gif +0 -0
  229. data/app/assets/images/locales/en.png +0 -0
  230. data/app/assets/images/locales/es.png +0 -0
  231. data/app/assets/images/locales/list.txt +278 -0
  232. data/app/assets/images/locales/pt.png +0 -0
  233. data/app/assets/images/login_with_facebook_button310x60.png +0 -0
  234. data/app/assets/images/login_with_facebook_button356x60.png +0 -0
  235. data/app/assets/images/logo.png +0 -0
  236. data/app/assets/images/not_successful.en.png +0 -0
  237. data/app/assets/images/not_successful.es.png +0 -0
  238. data/app/assets/images/not_successful.pt.png +0 -0
  239. data/app/assets/images/pencil_16.png +0 -0
  240. data/app/assets/images/project_about.png +0 -0
  241. data/app/assets/images/project_menu_selected.png +0 -0
  242. data/app/assets/images/rewards_left_border.png +0 -0
  243. data/app/assets/images/rewards_right_border.png +0 -0
  244. data/app/assets/images/successful.en.png +0 -0
  245. data/app/assets/images/successful.es.png +0 -0
  246. data/app/assets/images/successful.pt.png +0 -0
  247. data/app/assets/images/tick_16.png +0 -0
  248. data/app/assets/images/tick_32.png +0 -0
  249. data/app/assets/images/twitter_share.png +0 -0
  250. data/app/assets/images/user.png +0 -0
  251. data/app/assets/images/waiting_confirmation.en.png +0 -0
  252. data/app/assets/images/waiting_confirmation.es.png +0 -0
  253. data/app/assets/images/waiting_confirmation.pt.png +0 -0
  254. data/app/assets/javascripts/.gitkeep +0 -0
  255. data/app/assets/javascripts/app/.gitkeep +1 -0
  256. data/app/assets/javascripts/app/adm/users.js +50 -0
  257. data/app/assets/javascripts/app/app.js +50 -0
  258. data/app/assets/javascripts/app/backer.js +60 -0
  259. data/app/assets/javascripts/app/devise/feedback_support.js +23 -0
  260. data/app/assets/javascripts/app/explore.js +65 -0
  261. data/app/assets/javascripts/app/mix_panel.js +76 -0
  262. data/app/assets/javascripts/app/payment.js +23 -0
  263. data/app/assets/javascripts/app/project.js +47 -0
  264. data/app/assets/javascripts/app/project/project_backers.js +27 -0
  265. data/app/assets/javascripts/app/project/project_comments.js +14 -0
  266. data/app/assets/javascripts/app/project/project_sidebar.js +74 -0
  267. data/app/assets/javascripts/app/project/updates.js +44 -0
  268. data/app/assets/javascripts/app/project_form.js +60 -0
  269. data/app/assets/javascripts/app/registration.js +23 -0
  270. data/app/assets/javascripts/app/review_form.js +48 -0
  271. data/app/assets/javascripts/app/user.js +21 -0
  272. data/app/assets/javascripts/app/user/user_backers.js +15 -0
  273. data/app/assets/javascripts/app/user/user_projects.js +20 -0
  274. data/app/assets/javascripts/application.js +23 -0
  275. data/app/assets/javascripts/catarse_full/.gitkeep +0 -0
  276. data/app/assets/javascripts/lib/backbone.js +1571 -0
  277. data/app/assets/javascripts/lib/bootstrap.min.js +7 -0
  278. data/app/assets/javascripts/lib/form.js +24 -0
  279. data/app/assets/javascripts/lib/infinite_scroll.js +43 -0
  280. data/app/assets/javascripts/lib/jquery-ui.js +2252 -0
  281. data/app/assets/javascripts/lib/jquery.js +8842 -0
  282. data/app/assets/javascripts/lib/jquery.maskedinput.js +338 -0
  283. data/app/assets/javascripts/lib/modal.js +43 -0
  284. data/app/assets/javascripts/lib/skull.js +78 -0
  285. data/app/assets/javascripts/lib/tabs.js +27 -0
  286. data/app/assets/javascripts/lib/timed_input.js +18 -0
  287. data/app/assets/javascripts/lib/twitter.js +1 -0
  288. data/app/assets/javascripts/lib/underscore.js +1227 -0
  289. data/app/assets/stylesheets/.gitkeep +0 -0
  290. data/app/assets/stylesheets/animate.min.css +1 -0
  291. data/app/assets/stylesheets/application.css.sass +47 -0
  292. data/app/assets/stylesheets/catarse.css.sass +26 -0
  293. data/app/assets/stylesheets/catarse.sass +26 -0
  294. data/app/assets/stylesheets/catarse_bootstrap/_alerts.sass +16 -0
  295. data/app/assets/stylesheets/catarse_bootstrap/_buttons.sass +35 -0
  296. data/app/assets/stylesheets/catarse_bootstrap/_colors.sass +39 -0
  297. data/app/assets/stylesheets/catarse_bootstrap/_dropdown.sass +29 -0
  298. data/app/assets/stylesheets/catarse_bootstrap/_elements.sass +43 -0
  299. data/app/assets/stylesheets/catarse_bootstrap/_fonts.sass +46 -0
  300. data/app/assets/stylesheets/catarse_bootstrap/_header.sass +101 -0
  301. data/app/assets/stylesheets/catarse_bootstrap/_main_sidebar.sass +91 -0
  302. data/app/assets/stylesheets/catarse_bootstrap/_notices.sass +27 -0
  303. data/app/assets/stylesheets/catarse_bootstrap/_project_box.sass +104 -0
  304. data/app/assets/stylesheets/catarse_bootstrap/_settings.sass +72 -0
  305. data/app/assets/stylesheets/catarse_bootstrap/grid/foundation.sass +667 -0
  306. data/app/assets/stylesheets/catarse_bootstrap/grid/normalize.sass +327 -0
  307. data/app/assets/stylesheets/catarse_bootstrap/pages/devise.sass +102 -0
  308. data/app/assets/stylesheets/catarse_bootstrap/pages/passwords/new.sass +3 -0
  309. data/app/assets/stylesheets/catarse_full/.gitkeep +0 -0
  310. data/app/assets/stylesheets/content/_body.sass +82 -0
  311. data/app/assets/stylesheets/content/_explore.sass +68 -0
  312. data/app/assets/stylesheets/content/_footer.sass +88 -0
  313. data/app/assets/stylesheets/content/_header.sass +102 -0
  314. data/app/assets/stylesheets/content/_recommended_header.sass +174 -0
  315. data/app/assets/stylesheets/content/_sessions.sass +111 -0
  316. data/app/assets/stylesheets/content/_sidebar.sass +179 -0
  317. data/app/assets/stylesheets/jquery-ui.css.scss +572 -0
  318. data/app/assets/stylesheets/miv/_alert.scss +57 -0
  319. data/app/assets/stylesheets/miv/_bootstrap.scss +4652 -0
  320. data/app/assets/stylesheets/miv/_buttons.sass +41 -0
  321. data/app/assets/stylesheets/miv/_colors.sass +75 -0
  322. data/app/assets/stylesheets/miv/_dropdown.sass +28 -0
  323. data/app/assets/stylesheets/miv/_embed.sass +112 -0
  324. data/app/assets/stylesheets/miv/_flash.sass +18 -0
  325. data/app/assets/stylesheets/miv/_form.scss +626 -0
  326. data/app/assets/stylesheets/miv/_index.sass +151 -0
  327. data/app/assets/stylesheets/miv/_locales.sass +34 -0
  328. data/app/assets/stylesheets/miv/_modal.sass +38 -0
  329. data/app/assets/stylesheets/miv/_overlay.sass +10 -0
  330. data/app/assets/stylesheets/miv/_projects.sass +159 -0
  331. data/app/assets/stylesheets/miv/_projects_land.sass +177 -0
  332. data/app/assets/stylesheets/miv/_table.scss +134 -0
  333. data/app/assets/stylesheets/miv/_tabs.sass +31 -0
  334. data/app/assets/stylesheets/resources/adm/adm.sass +109 -0
  335. data/app/assets/stylesheets/resources/backers/_create.sass +432 -0
  336. data/app/assets/stylesheets/resources/backers/_new.sass +237 -0
  337. data/app/assets/stylesheets/resources/backers/_thank_you.sass +83 -0
  338. data/app/assets/stylesheets/resources/channels/_about.sass +67 -0
  339. data/app/assets/stylesheets/resources/channels/_general.sass +60 -0
  340. data/app/assets/stylesheets/resources/channels/_icomoon.sass +47 -0
  341. data/app/assets/stylesheets/resources/channels/_profile.sass +120 -0
  342. data/app/assets/stylesheets/resources/projects/_index.sass +43 -0
  343. data/app/assets/stylesheets/resources/projects/_new.sass +117 -0
  344. data/app/assets/stylesheets/resources/projects/_pending_backers.sass +80 -0
  345. data/app/assets/stylesheets/resources/projects/_rewards.sass +22 -0
  346. data/app/assets/stylesheets/resources/projects/_show.sass +749 -0
  347. data/app/assets/stylesheets/resources/projects/_start.sass +191 -0
  348. data/app/assets/stylesheets/resources/static/_about.sass +125 -0
  349. data/app/assets/stylesheets/resources/static/_default.sass +576 -0
  350. data/app/assets/stylesheets/resources/users/_show.sass +284 -0
  351. data/app/controllers/.gitkeep +0 -0
  352. data/app/controllers/adm/backers_controller.rb +40 -0
  353. data/app/controllers/adm/base_controller.rb +37 -0
  354. data/app/controllers/adm/financials_controller.rb +49 -0
  355. data/app/controllers/adm/projects_controller.rb +32 -0
  356. data/app/controllers/adm/reports/backer_reports_controller.rb +6 -0
  357. data/app/controllers/adm/reports/base_controller.rb +6 -0
  358. data/app/controllers/adm/statistics_controller.rb +6 -0
  359. data/app/controllers/adm/users_controller.rb +26 -0
  360. data/app/controllers/application_controller.rb +118 -0
  361. data/app/controllers/channels/adm/projects_controller.rb +36 -0
  362. data/app/controllers/channels/adm/reports/subscriber_reports_controller.rb +7 -0
  363. data/app/controllers/channels/adm/statistics_controller.rb +13 -0
  364. data/app/controllers/channels/base_controller.rb +6 -0
  365. data/app/controllers/channels/channels_subscribers_controller.rb +35 -0
  366. data/app/controllers/channels/profiles_controller.rb +11 -0
  367. data/app/controllers/channels/projects_controller.rb +22 -0
  368. data/app/controllers/explore_controller.rb +6 -0
  369. data/app/controllers/omniauth_callbacks_controller.rb +28 -0
  370. data/app/controllers/passwords_controller.rb +21 -0
  371. data/app/controllers/projects/backers_controller.rb +85 -0
  372. data/app/controllers/projects/updates_controller.rb +28 -0
  373. data/app/controllers/projects_controller.rb +84 -0
  374. data/app/controllers/reports/backer_reports_for_project_owners_controller.rb +36 -0
  375. data/app/controllers/reports/base_controller.rb +6 -0
  376. data/app/controllers/rewards_controller.rb +36 -0
  377. data/app/controllers/static_controller.rb +28 -0
  378. data/app/controllers/unsubscribes_controller.rb +18 -0
  379. data/app/controllers/users/backers_controller.rb +29 -0
  380. data/app/controllers/users/projects_controller.rb +13 -0
  381. data/app/controllers/users_controller.rb +63 -0
  382. data/app/decorators/channel_decorator.rb +7 -0
  383. data/app/decorators/project_decorator.rb +69 -0
  384. data/app/decorators/user_decorator.rb +34 -0
  385. data/app/helpers/.gitkeep +0 -0
  386. data/app/helpers/channels/base_helper.rb +2 -0
  387. data/app/mailers/.gitkeep +0 -0
  388. data/app/mailers/credits_mailer.rb +9 -0
  389. data/app/mailers/notifications_mailer.rb +21 -0
  390. data/app/models/.gitkeep +0 -0
  391. data/app/models/ability.rb +129 -0
  392. data/app/models/authorization.rb +4 -0
  393. data/app/models/backer.rb +242 -0
  394. data/app/models/backer_report.rb +3 -0
  395. data/app/models/backer_reports_for_project_owner.rb +2 -0
  396. data/app/models/backers_by_period.rb +9 -0
  397. data/app/models/category.rb +17 -0
  398. data/app/models/channel.rb +22 -0
  399. data/app/models/channels_subscriber.rb +5 -0
  400. data/app/models/configuration.rb +36 -0
  401. data/app/models/notification.rb +35 -0
  402. data/app/models/notification_type.rb +4 -0
  403. data/app/models/oauth_provider.rb +6 -0
  404. data/app/models/payment_notification.rb +4 -0
  405. data/app/models/project.rb +335 -0
  406. data/app/models/project_total.rb +2 -0
  407. data/app/models/projects_by_period.rb +9 -0
  408. data/app/models/projects_for_home.rb +11 -0
  409. data/app/models/reward.rb +70 -0
  410. data/app/models/state.rb +13 -0
  411. data/app/models/statistics.rb +2 -0
  412. data/app/models/subscriber_report.rb +3 -0
  413. data/app/models/unsubscribe.rb +10 -0
  414. data/app/models/update.rb +57 -0
  415. data/app/models/user.rb +250 -0
  416. data/app/models/user_total.rb +3 -0
  417. data/app/observers/backer_observer.rb +61 -0
  418. data/app/observers/notification_observer.rb +7 -0
  419. data/app/observers/payment_notification_observer.rb +16 -0
  420. data/app/observers/project_observer.rb +113 -0
  421. data/app/observers/update_observer.rb +7 -0
  422. data/app/observers/user_observer.rb +16 -0
  423. data/app/uploaders/image_uploader.rb +24 -0
  424. data/app/uploaders/project_uploader.rb +29 -0
  425. data/app/uploaders/user_uploader.rb +12 -0
  426. data/app/views/.gitkeep +0 -0
  427. data/app/views/adm/backers/index.html.slim +170 -0
  428. data/app/views/adm/financials/index.html.slim +99 -0
  429. data/app/views/adm/projects/index.html.slim +128 -0
  430. data/app/views/adm/statistics/index.html.slim +40 -0
  431. data/app/views/adm/users/index.html.slim +74 -0
  432. data/app/views/catarse_bootstrap/devise/mailer/reset_password_instructions.en.html.slim +15 -0
  433. data/app/views/catarse_bootstrap/devise/mailer/reset_password_instructions.pt.html.slim +16 -0
  434. data/app/views/catarse_bootstrap/devise/mailer/unlock_instructions.html.erb +7 -0
  435. data/app/views/catarse_bootstrap/devise/passwords/edit.html.slim +26 -0
  436. data/app/views/catarse_bootstrap/devise/passwords/new.html.slim +21 -0
  437. data/app/views/catarse_bootstrap/devise/registrations/new.html.slim +48 -0
  438. data/app/views/catarse_bootstrap/devise/sessions/new.html.slim +40 -0
  439. data/app/views/catarse_bootstrap/devise/shared/_alert.html.slim +11 -0
  440. data/app/views/catarse_bootstrap/devise/shared/_header.html.slim +5 -0
  441. data/app/views/catarse_bootstrap/layouts/_login_feedback_support.html.slim +16 -0
  442. data/app/views/catarse_bootstrap/layouts/_mailer_styles.html.erb +22 -0
  443. data/app/views/catarse_bootstrap/layouts/_uservoice.html.slim +2 -0
  444. data/app/views/catarse_bootstrap/layouts/catarse_bootstrap.html.slim +21 -0
  445. data/app/views/catarse_bootstrap/layouts/email.html.slim +39 -0
  446. data/app/views/catarse_bootstrap/notifications_mailer/new_user_registration.en.html.slim +44 -0
  447. data/app/views/catarse_bootstrap/notifications_mailer/new_user_registration.pt.html.slim +45 -0
  448. data/app/views/catarse_bootstrap/notifications_mailer/updates.en.html.slim +4 -0
  449. data/app/views/catarse_bootstrap/notifications_mailer/updates.pt.html.slim +4 -0
  450. data/app/views/channels/adm/projects/index.html.slim +121 -0
  451. data/app/views/channels/adm/statistics/index.html.slim +21 -0
  452. data/app/views/channels/base/index.html.slim +2 -0
  453. data/app/views/channels/profiles/_footer.html.slim +13 -0
  454. data/app/views/channels/profiles/how_it_works.html.slim +67 -0
  455. data/app/views/channels/profiles/show.html.slim +47 -0
  456. data/app/views/channels/projects/_banner.html.slim +8 -0
  457. data/app/views/channels/projects/_project.html.slim +12 -0
  458. data/app/views/channels/projects/new.html.slim +128 -0
  459. data/app/views/credits_mailer/request_refund_from.text.erb +11 -0
  460. data/app/views/custom/.gitkeep +0 -0
  461. data/app/views/explore/index.html.slim +47 -0
  462. data/app/views/layouts/_analytics.html.slim +9 -0
  463. data/app/views/layouts/_announcement.html.slim +4 -0
  464. data/app/views/layouts/_catarse_bootstrap_notices.html.slim +4 -0
  465. data/app/views/layouts/_classic_uservoice.html.slim +31 -0
  466. data/app/views/layouts/_facebook_like.html.slim +2 -0
  467. data/app/views/layouts/_facebook_sdk.html.slim +20 -0
  468. data/app/views/layouts/_flash.html.slim +6 -0
  469. data/app/views/layouts/_header.html.slim +49 -0
  470. data/app/views/layouts/_locales.html.slim +7 -0
  471. data/app/views/layouts/_new_uservoice.html.slim +20 -0
  472. data/app/views/layouts/_twitter.html.erb +1 -0
  473. data/app/views/layouts/application.html.slim +71 -0
  474. data/app/views/layouts/channel_email.html.slim +23 -0
  475. data/app/views/layouts/email.html.slim +26 -0
  476. data/app/views/layouts/embed.html.slim +13 -0
  477. data/app/views/notifications_mailer/adm_project_deadline.en.html.slim +3 -0
  478. data/app/views/notifications_mailer/adm_project_deadline.pt.html.slim +3 -0
  479. data/app/views/notifications_mailer/backer_canceled_after_confirmed.html.slim +12 -0
  480. data/app/views/notifications_mailer/backer_confirmed_after_project_was_closed.en.html.slim +8 -0
  481. data/app/views/notifications_mailer/backer_confirmed_after_project_was_closed.pt.html.slim +8 -0
  482. data/app/views/notifications_mailer/backer_project_successful.en.html.slim +48 -0
  483. data/app/views/notifications_mailer/backer_project_successful.pt.html.slim +50 -0
  484. data/app/views/notifications_mailer/backer_project_unsuccessful.en.html.slim +39 -0
  485. data/app/views/notifications_mailer/backer_project_unsuccessful.pt.html.slim +41 -0
  486. data/app/views/notifications_mailer/confirm_backer.en.html.slim +43 -0
  487. data/app/views/notifications_mailer/confirm_backer.pt.html.slim +45 -0
  488. data/app/views/notifications_mailer/credits_warning.en.html.slim +41 -0
  489. data/app/views/notifications_mailer/credits_warning.pt.html.slim +40 -0
  490. data/app/views/notifications_mailer/new_draft_project.en.html.slim +34 -0
  491. data/app/views/notifications_mailer/new_draft_project.pt.html.slim +34 -0
  492. data/app/views/notifications_mailer/new_draft_project_channel.en.html.slim +34 -0
  493. data/app/views/notifications_mailer/new_draft_project_channel.pt.html.slim +34 -0
  494. data/app/views/notifications_mailer/new_features.en.html.slim +30 -0
  495. data/app/views/notifications_mailer/new_features.pt.html.slim +30 -0
  496. data/app/views/notifications_mailer/payment_slip.en.html.slim +19 -0
  497. data/app/views/notifications_mailer/payment_slip.pt.html.slim +24 -0
  498. data/app/views/notifications_mailer/pending_backer_project_unsuccessful.en.html.slim +44 -0
  499. data/app/views/notifications_mailer/pending_backer_project_unsuccessful.pt.html.slim +44 -0
  500. data/app/views/notifications_mailer/processing_payment.en.html.slim +24 -0
  501. data/app/views/notifications_mailer/processing_payment.pt.html.slim +29 -0
  502. data/app/views/notifications_mailer/project_in_wainting_funds.en.html.slim +35 -0
  503. data/app/views/notifications_mailer/project_in_wainting_funds.pt.html.slim +35 -0
  504. data/app/views/notifications_mailer/project_owner_backer_confirmed.en.html.slim +33 -0
  505. data/app/views/notifications_mailer/project_owner_backer_confirmed.pt.html.slim +34 -0
  506. data/app/views/notifications_mailer/project_received.en.html.slim +38 -0
  507. data/app/views/notifications_mailer/project_received.pt.html.slim +50 -0
  508. data/app/views/notifications_mailer/project_received_channel.en.html.slim +52 -0
  509. data/app/views/notifications_mailer/project_received_channel.pt.html.slim +52 -0
  510. data/app/views/notifications_mailer/project_rejected.en.html.slim +33 -0
  511. data/app/views/notifications_mailer/project_rejected.pt.html.slim +33 -0
  512. data/app/views/notifications_mailer/project_success.en.html.slim +30 -0
  513. data/app/views/notifications_mailer/project_success.pt.html.slim +30 -0
  514. data/app/views/notifications_mailer/project_unsuccessful.en.html.slim +42 -0
  515. data/app/views/notifications_mailer/project_unsuccessful.pt.html.slim +42 -0
  516. data/app/views/notifications_mailer/project_visible.en.html.slim +65 -0
  517. data/app/views/notifications_mailer/project_visible.pt.html.slim +65 -0
  518. data/app/views/projects/_admin_fields.html.slim +15 -0
  519. data/app/views/projects/_draft_warning.html.slim +23 -0
  520. data/app/views/projects/_failed_warning.html.slim +21 -0
  521. data/app/views/projects/_formatting_tips.en.html.slim +19 -0
  522. data/app/views/projects/_formatting_tips.pt.html.slim +20 -0
  523. data/app/views/projects/_online_warning.html.slim +33 -0
  524. data/app/views/projects/_project.html.slim +23 -0
  525. data/app/views/projects/_project_about.html.slim +20 -0
  526. data/app/views/projects/_project_edit.html.slim +32 -0
  527. data/app/views/projects/_project_header.html.slim +34 -0
  528. data/app/views/projects/_project_reports.html.slim +22 -0
  529. data/app/views/projects/_project_templates.html.slim +3 -0
  530. data/app/views/projects/_recommended_header.html.slim +19 -0
  531. data/app/views/projects/_rejected_warning.html.slim +10 -0
  532. data/app/views/projects/_successful_warning.html.slim +29 -0
  533. data/app/views/projects/_twitter_timeline.html.slim +2 -0
  534. data/app/views/projects/_waiting_funds_warning.html.slim +34 -0
  535. data/app/views/projects/backers/_anonymous_warning.en.html.slim +5 -0
  536. data/app/views/projects/backers/_anonymous_warning.pt.html.slim +5 -0
  537. data/app/views/projects/backers/_back_text.en.html.slim +11 -0
  538. data/app/views/projects/backers/_back_text.pt.html.slim +11 -0
  539. data/app/views/projects/backers/_backer.html.slim +42 -0
  540. data/app/views/projects/backers/create.html.slim +75 -0
  541. data/app/views/projects/backers/new.html.slim +40 -0
  542. data/app/views/projects/backers/show.html.slim +26 -0
  543. data/app/views/projects/embed.html.slim +2 -0
  544. data/app/views/projects/embed_panel.html.slim +11 -0
  545. data/app/views/projects/index.html.slim +70 -0
  546. data/app/views/projects/new.html.slim +134 -0
  547. data/app/views/projects/show.html.slim +169 -0
  548. data/app/views/projects/start.html.slim +121 -0
  549. data/app/views/projects/updates/_update.html.slim +17 -0
  550. data/app/views/projects/updates/new.html.slim +22 -0
  551. data/app/views/projects/video_embed.html.slim +8 -0
  552. data/app/views/projects_mailer/start_project_email.html.slim +29 -0
  553. data/app/views/rewards/_form.html.slim +19 -0
  554. data/app/views/rewards/edit.html.slim +1 -0
  555. data/app/views/rewards/index.html.slim +55 -0
  556. data/app/views/rewards/new.html.slim +1 -0
  557. data/app/views/static/_guidelines_text.pt.html.slim +17 -0
  558. data/app/views/static/_how_it_works.en.html.slim +11 -0
  559. data/app/views/static/_how_it_works.pt.html.slim +11 -0
  560. data/app/views/static/_more_tips.pt.html.slim +20 -0
  561. data/app/views/static/about.html.slim +79 -0
  562. data/app/views/static/guidelines.html.slim +22 -0
  563. data/app/views/static/guidelines_backers.html.slim +94 -0
  564. data/app/views/static/guidelines_start.html.slim +90 -0
  565. data/app/views/static/guidelines_tips.html.slim +68 -0
  566. data/app/views/static/sitemap.builder +61 -0
  567. data/app/views/users/_credits.html.slim +44 -0
  568. data/app/views/users/_current_user_fields.html.slim +76 -0
  569. data/app/views/users/_project.html.slim +60 -0
  570. data/app/views/users/_unsubscribes.html.slim +23 -0
  571. data/app/views/users/backers/index.html.slim +2 -0
  572. data/app/views/users/projects/index.html.slim +3 -0
  573. data/app/views/users/set_email.html.slim +16 -0
  574. data/app/views/users/show.html.slim +72 -0
  575. data/app/views/users/uservoice_gadget.html.slim +45 -0
  576. data/app/workers/notify_update_worker.rb +9 -0
  577. data/config/boot.rb +13 -0
  578. data/config/compass.rb +5 -0
  579. data/config/environment.rb +5 -0
  580. data/config/environments/development.rb +46 -0
  581. data/config/environments/production.rb +70 -0
  582. data/config/environments/test.rb +44 -0
  583. data/config/initializers/backtrace_silencers.rb +7 -0
  584. data/config/initializers/capybara.rb +5 -0
  585. data/config/initializers/carrierwave.rb +13 -0
  586. data/config/initializers/default_url_options.rb +6 -0
  587. data/config/initializers/devise.rb +252 -0
  588. data/config/initializers/formtastic.rb +9 -0
  589. data/config/initializers/google_analytics.rb +3 -0
  590. data/config/initializers/http_accept_language.rb +7 -0
  591. data/config/initializers/inflections.rb +13 -0
  592. data/config/initializers/locale.rb +9 -0
  593. data/config/initializers/mailchimp.rb +1 -0
  594. data/config/initializers/mime_types.rb +5 -0
  595. data/config/initializers/pluralize.rb +5 -0
  596. data/config/initializers/schema_associations.rb +3 -0
  597. data/config/initializers/secret_token.rb +16 -0
  598. data/config/initializers/sendgrid.rb +15 -0
  599. data/config/initializers/session_store.rb +15 -0
  600. data/config/initializers/statistics_loader_development.rb +4 -0
  601. data/config/initializers/timeout.rb +1 -0
  602. data/config/initializers/wrap_parameters.rb +14 -0
  603. data/config/locales/.wti.sample +14 -0
  604. data/config/locales/adm.en.yml +107 -0
  605. data/config/locales/adm.pt.yml +150 -0
  606. data/config/locales/catarse_bootstrap/models/user.en.yml +13 -0
  607. data/config/locales/catarse_bootstrap/models/user.pt.yml +13 -0
  608. data/config/locales/catarse_bootstrap/pages/forgot_password.en.yml +14 -0
  609. data/config/locales/catarse_bootstrap/pages/forgot_password.pt.yml +14 -0
  610. data/config/locales/catarse_bootstrap/pages/login.en.yml +16 -0
  611. data/config/locales/catarse_bootstrap/pages/login.pt.yml +16 -0
  612. data/config/locales/catarse_bootstrap/pages/reset_password.en.yml +14 -0
  613. data/config/locales/catarse_bootstrap/pages/reset_password.pt.yml +14 -0
  614. data/config/locales/catarse_bootstrap/pages/sign_up.en.yml +18 -0
  615. data/config/locales/catarse_bootstrap/pages/sign_up.pt.yml +17 -0
  616. data/config/locales/channels.pt.yml +100 -0
  617. data/config/locales/devise.en.yml +99 -0
  618. data/config/locales/devise.pt.yml +98 -0
  619. data/config/locales/en.yml +872 -0
  620. data/config/locales/notifications.en.yml +74 -0
  621. data/config/locales/notifications.pt.yml +74 -0
  622. data/config/locales/pt.yml +896 -0
  623. data/config/locales/rails.en.yml +209 -0
  624. data/config/locales/rails.pt.yml +211 -0
  625. data/config/locales/will_paginate.en.yml +5 -0
  626. data/config/locales/will_paginate.pt.yml +5 -0
  627. data/config/newrelic.yml +227 -0
  628. data/config/routes.rb +150 -0
  629. data/config/sidekiq.yml +1 -0
  630. data/config/unicorn.rb +38 -0
  631. data/db/migrate/20121226120921_initial_schema.rb +1836 -0
  632. data/db/migrate/20121227012003_user_totals_back_to_state_machine.rb +53 -0
  633. data/db/migrate/20121227012324_statistics_back_to_state_machine.rb +47 -0
  634. data/db/migrate/20121230111351_add_online_date_to_projects.rb +5 -0
  635. data/db/migrate/20130102180139_update_projects_to_state_machine_again.rb +25 -0
  636. data/db/migrate/20130104005632_add_moip_login_to_users.rb +5 -0
  637. data/db/migrate/20130104104501_add_how_know_and_more_links_to_projects.rb +6 -0
  638. data/db/migrate/20130105123546_add_first_backers_to_projects.rb +5 -0
  639. data/db/migrate/20130110191750_add_uploaded_image_to_projects.rb +5 -0
  640. data/db/migrate/20130117205659_alter_projects_drop_video_url_constraint.rb +15 -0
  641. data/db/migrate/20130118193907_fix_statistics_view.rb +45 -0
  642. data/db/migrate/20130121162447_create_backer_reports.rb +41 -0
  643. data/db/migrate/20130121204224_fix_projects_states.rb +11 -0
  644. data/db/migrate/20130121212325_fix_statistcs_again.rb +45 -0
  645. data/db/migrate/20130131121553_add_cpf_to_backer_report.rb +75 -0
  646. data/db/migrate/20130201200604_remove_curated_pages.rb +9 -0
  647. data/db/migrate/20130201202648_remove_projects_managers.rb +9 -0
  648. data/db/migrate/20130201202829_remove_active_admin_comments.rb +9 -0
  649. data/db/migrate/20130201205659_remove_institutional_videos.rb +9 -0
  650. data/db/migrate/20130204192704_create_backer_reports_for_project_owner.rb +33 -0
  651. data/db/migrate/20130205143533_remove_credits_from_users.rb +9 -0
  652. data/db/migrate/20130206121758_fix_view_backer_reports_for_project_owner.rb +34 -0
  653. data/db/migrate/20130211174609_add_name_en_to_categories.rb +5 -0
  654. data/db/migrate/20130212145115_rename_name_to_name_pt.rb +5 -0
  655. data/db/migrate/20130213184141_change_permalink_to_not_null.rb +17 -0
  656. data/db/migrate/20130218201312_create_users_oauth_providers.rb +10 -0
  657. data/db/migrate/20130218201751_migrate_user_data_to_users_oath_providers.rb +12 -0
  658. data/db/migrate/20130221171018_rename_users_oath_providers.rb +21 -0
  659. data/db/migrate/20130221172840_populate_authorizations.rb +12 -0
  660. data/db/migrate/20130221175717_remove_static_contents.rb +13 -0
  661. data/db/migrate/20130221184144_update_oauth_provider_name_to_lower.rb +8 -0
  662. data/db/migrate/20130221185532_recreate_statistics_with_new_users.rb +62 -0
  663. data/db/migrate/20130221201732_remove_secondary_users.rb +82 -0
  664. data/db/migrate/20130222163633_add_state_inscription_to_user.rb +5 -0
  665. data/db/migrate/20130225135512_update_user_emails_from_backers.rb +15 -0
  666. data/db/migrate/20130225141802_alter_user_drop_provider_uid_constraints.rb +15 -0
  667. data/db/migrate/20130228141234_add_unique_index_to_configuration.rb +5 -0
  668. data/db/migrate/20130304193806_create_channel_profiles.rb +12 -0
  669. data/db/migrate/20130307074614_create_versions.rb +24 -0
  670. data/db/migrate/20130307090153_add_reindex_versions_to_rewards.rb +5 -0
  671. data/db/migrate/20130308200907_add_user_name_on_backer_report_for_project_owner.rb +62 -0
  672. data/db/migrate/20130311191444_drop_uid_and_provider_constraint_on_users.rb +13 -0
  673. data/db/migrate/20130311192846_remove_unnecessary_user_indexes.rb +14 -0
  674. data/db/migrate/20130312001021_fix_duplicate_emails.rb +26 -0
  675. data/db/migrate/20130313032607_rename_channels_profiles_to_channels.rb +9 -0
  676. data/db/migrate/20130313034356_create_channels_projects.rb +8 -0
  677. data/db/migrate/20130319131919_create_channels_trustees.rb +12 -0
  678. data/db/migrate/20130410181958_add_twitter_and_facebook_and_email_to_channels.rb +7 -0
  679. data/db/migrate/20130410190247_add_image_to_channels.rb +5 -0
  680. data/db/migrate/20130410191240_add_website_to_channels.rb +5 -0
  681. data/db/migrate/20130411193016_create_channels_subscribers.rb +13 -0
  682. data/db/migrate/20130419184530_add_state_to_backers.rb +5 -0
  683. data/db/migrate/20130422071805_add_notification_type_draft_channel.rb +13 -0
  684. data/db/migrate/20130422072051_add_notification_type_project_received_channel.rb +13 -0
  685. data/db/migrate/20130423162359_update_user_total_to_backer_state_machine.rb +59 -0
  686. data/db/migrate/20130424173128_add_backer_state_machine_into_statistics.rb +61 -0
  687. data/db/migrate/20130426204503_add_row_order_to_rewards.rb +7 -0
  688. data/db/migrate/20130429142823_rename_categories.rb +12 -0
  689. data/db/migrate/20130429144749_add_new_categories.rb +27 -0
  690. data/db/migrate/20130429153115_move_projects_to_art_and_remove_old_categories.rb +15 -0
  691. data/db/migrate/20130430203333_add_layout_to_notification_type.rb +5 -0
  692. data/db/migrate/20130502175814_add_anonymous_to_reports_to_project_owner.rb +37 -0
  693. data/db/migrate/20130505013655_update_backers_state_machine.rb +35 -0
  694. data/db/migrate/20130506191243_update_backer_reports_to_project_owner_view_to_backer_state_machine.rb +65 -0
  695. data/db/migrate/20130506191508_update_backer_reports_to_backer_state_machine.rb +74 -0
  696. data/db/migrate/20130514132519_add_waiting_confirmation_on_statistics_view.rb +63 -0
  697. data/db/migrate/20130514185010_drop_views.rb +35 -0
  698. data/db/migrate/20130514185116_fix_project_owner_view.rb +66 -0
  699. data/db/migrate/20130514185926_remove_boolean_fields_from_projects.rb +18 -0
  700. data/db/migrate/20130515192404_remove_boolean_fields_from_backers.rb +14 -0
  701. data/db/migrate/20130523144013_fix_project_total_to_use_refunded_and_requested_refund_too.rb +15 -0
  702. data/db/migrate/20130523173609_fix_project_total_again_some_regex_error.rb +15 -0
  703. data/db/migrate/20130527204639_add_video_embed_url_to_projects.rb +5 -0
  704. data/db/migrate/20130529171845_update_backers_that_are_in_refunded_when_project_is_online.rb +17 -0
  705. data/db/migrate/20130604171730_add_index_to_payment_notification_on_backer_id.rb +5 -0
  706. data/db/migrate/20130604172253_update_online_date_for_legacy_projects.rb +10 -0
  707. data/db/migrate/20130604175953_remove_expires_at_from_views.rb +11 -0
  708. data/db/migrate/20130604180503_remove_expires_at_from_projects.rb +11 -0
  709. data/db/migrate/20130607222330_remove_image_url_from_projects.rb +9 -0
  710. data/db/migrate/20130617175402_create_projects_chart_view.rb +51 -0
  711. data/db/migrate/20130618175432_create_backers_by_period_view.rb +57 -0
  712. data/db/migrate/20130626122439_add_expires_at_function.rb +12 -0
  713. data/db/migrate/20130626124055_drop_payment_logs.rb +8 -0
  714. data/db/migrate/20130702192659_update_backers_by_period_view_with_deleted_backer_state.rb +107 -0
  715. data/db/migrate/20130703171547_add_exclusive_to_updates.rb +5 -0
  716. data/db/migrate/20130705131825_replace_expires_at_to_include_timezone.rb +18 -0
  717. data/db/migrate/20130705184845_alter_statistics_view_add_deleted_backer_state.rb +61 -0
  718. data/db/migrate/20130710122804_add_days_to_delivery_into_rewards.rb +5 -0
  719. data/db/migrate/20130722222945_remove_legacy_columns_from_users.rb +10 -0
  720. data/db/migrate/20130730232043_add_total_payments_service_fee_into_project_totals.rb +27 -0
  721. data/db/migrate/20130805230126_add_total_backed_projects_to_user_total.rb +60 -0
  722. data/db/migrate/20130812191450_show_refunded_on_backers_report.rb +74 -0
  723. data/db/migrate/20130814174329_alter_timestamp_to_include_timezone.rb +17 -0
  724. data/db/migrate/20130815161926_create_recommendations_view.rb +64 -0
  725. data/db/migrate/20130818015857_add_projects_home_view.rb +37 -0
  726. data/db/migrate/20130822215532_fix_credits_into_user_totals_view.rb +67 -0
  727. data/db/migrate/20130827210414_revert_expires_at.rb +12 -0
  728. data/db/migrate/20130828160026_use_expires_at_in_view.rb +11 -0
  729. data/db/migrate/20130829180232_use_timezone_instead_of_hardcoded_3.rb +12 -0
  730. data/db/migrate/20130905153553_add_sessions_table.rb +12 -0
  731. data/db/migrate/20130911180657_create_subscriber_reports.rb +8 -0
  732. data/db/seeds.rb +122 -0
  733. data/db/seeds/add-users.rb +40 -0
  734. data/db/seeds/my-seeds-local.example.rb +85 -0
  735. data/lib/blog.rb +14 -0
  736. data/lib/calendar.rb +19 -0
  737. data/lib/catarse_auto_html.rb +23 -0
  738. data/lib/catarse_full.rb +4 -0
  739. data/lib/catarse_full/engine.rb +77 -0
  740. data/lib/catarse_full/version.rb +3 -0
  741. data/lib/payment_engines.rb +26 -0
  742. data/lib/tasks/.gitkeep +0 -0
  743. data/lib/tasks/catarse_full_tasks.rake +4 -0
  744. data/lib/tasks/config.rake +56 -0
  745. data/lib/tasks/cron.rake +76 -0
  746. data/lib/tasks/db_seed.rake +15 -0
  747. data/lib/tasks/jasmine.rake +8 -0
  748. data/lib/tasks/send_old_posts_to_tumblr.rake +14 -0
  749. data/lib/tasks/users.rake +82 -0
  750. data/lib/uservoice_sso.rb +20 -0
  751. data/spec/abilities/trustee_ability_spec.rb +53 -0
  752. data/spec/config/initializers/secret_token_spec.rb +19 -0
  753. data/spec/controllers/adm/backers_controller_spec.rb +119 -0
  754. data/spec/controllers/adm/statistics_controller.rb +17 -0
  755. data/spec/controllers/adm/users_controller_spec.rb +29 -0
  756. data/spec/controllers/channels/adm/reports/subscriber_reports_controller_spec.rb +24 -0
  757. data/spec/controllers/channels/base_controller_spec.rb +5 -0
  758. data/spec/controllers/channels/channels_subscribers_controller_spec.rb +59 -0
  759. data/spec/controllers/channels/profiles_controller_spec.rb +16 -0
  760. data/spec/controllers/omniauth_callbacks_controller_spec.rb +113 -0
  761. data/spec/controllers/projects/backers_controller_spec.rb +198 -0
  762. data/spec/controllers/projects/updates_controller_spec.rb +57 -0
  763. data/spec/controllers/projects_controller_spec.rb +178 -0
  764. data/spec/controllers/rewards_controller_spec.rb +107 -0
  765. data/spec/controllers/static_controller_spec.rb +37 -0
  766. data/spec/controllers/unsubscribes_controller_spec.rb +31 -0
  767. data/spec/controllers/users/backers_controller_spec.rb +86 -0
  768. data/spec/controllers/users/projects_controller_spec.rb +19 -0
  769. data/spec/controllers/users_controller_spec.rb +92 -0
  770. data/spec/decorators/project_decorator_spec.rb +146 -0
  771. data/spec/decorators/user_decorator_spec.rb +87 -0
  772. data/spec/dummy/README.rdoc +261 -0
  773. data/spec/dummy/Rakefile +7 -0
  774. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  775. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  776. data/spec/dummy/app/mailers/.gitkeep +0 -0
  777. data/spec/dummy/app/models/.gitkeep +0 -0
  778. data/spec/dummy/config.ru +4 -0
  779. data/spec/dummy/config/application.rb +69 -0
  780. data/spec/dummy/config/boot.rb +10 -0
  781. data/spec/dummy/config/database.sample.yml +50 -0
  782. data/spec/dummy/config/environment.rb +5 -0
  783. data/spec/dummy/config/environments/development.rb +37 -0
  784. data/spec/dummy/config/environments/production.rb +67 -0
  785. data/spec/dummy/config/environments/test.rb +37 -0
  786. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  787. data/spec/dummy/config/initializers/devise_secret_key.rb +3 -0
  788. data/spec/dummy/config/initializers/inflections.rb +15 -0
  789. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  790. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  791. data/spec/dummy/config/initializers/session_store.rb +8 -0
  792. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  793. data/spec/dummy/config/locales/en.yml +5 -0
  794. data/spec/dummy/config/routes.rb +58 -0
  795. data/spec/dummy/db/structure.sql +2434 -0
  796. data/spec/dummy/lib/assets/.gitkeep +0 -0
  797. data/spec/dummy/log/.gitkeep +0 -0
  798. data/spec/dummy/public/404.html +26 -0
  799. data/spec/dummy/public/422.html +26 -0
  800. data/spec/dummy/public/500.html +25 -0
  801. data/spec/dummy/public/favicon.ico +0 -0
  802. data/spec/dummy/script/rails +6 -0
  803. data/spec/factories.rb +125 -0
  804. data/spec/factories/users_oauth_providers.rb +9 -0
  805. data/spec/features/channel_moderation_spec.rb +27 -0
  806. data/spec/features/projects_spec.rb +95 -0
  807. data/spec/features/users_spec.rb +43 -0
  808. data/spec/fixtures/image.png +0 -0
  809. data/spec/helpers/channels/base_helper_spec.rb +15 -0
  810. data/spec/javascripts/app_spec.js +85 -0
  811. data/spec/javascripts/backer_spec.js +74 -0
  812. data/spec/javascripts/explore_spec.js +211 -0
  813. data/spec/javascripts/feedback_support_spec.js +41 -0
  814. data/spec/javascripts/helpers/.gitkeep +0 -0
  815. data/spec/javascripts/mix_panel_spec.js +101 -0
  816. data/spec/javascripts/permalink_spec.js +50 -0
  817. data/spec/javascripts/project_comments_spec.js +66 -0
  818. data/spec/javascripts/project_sidebar_spec.js +105 -0
  819. data/spec/javascripts/project_spec.js +175 -0
  820. data/spec/javascripts/registration_spec.js +38 -0
  821. data/spec/javascripts/review_form_spec.js +140 -0
  822. data/spec/javascripts/skull_spec.js +103 -0
  823. data/spec/javascripts/support/jasmine.yml +93 -0
  824. data/spec/javascripts/timed_input_spec.js +64 -0
  825. data/spec/javascripts/updates_spec.js +49 -0
  826. data/spec/javascripts/video_url_spec.js +42 -0
  827. data/spec/lib/blog_spec.rb +12 -0
  828. data/spec/lib/payment_engines_spec.rb +61 -0
  829. data/spec/mailers/notifications_mailer_spec.rb +20 -0
  830. data/spec/models/ability_spec.rb +123 -0
  831. data/spec/models/authorizations_spec.rb +6 -0
  832. data/spec/models/backer_report_spec.rb +5 -0
  833. data/spec/models/backer_spec.rb +459 -0
  834. data/spec/models/category_spec.rb +13 -0
  835. data/spec/models/channel_spec.rb +47 -0
  836. data/spec/models/channels_subscriber_spec.rb +13 -0
  837. data/spec/models/configuration_spec.rb +31 -0
  838. data/spec/models/notification_spec.rb +105 -0
  839. data/spec/models/oauth_provider_spec.rb +7 -0
  840. data/spec/models/payment_notification_spec.rb +17 -0
  841. data/spec/models/project_spec.rb +771 -0
  842. data/spec/models/project_total_spec.rb +26 -0
  843. data/spec/models/projects_for_home_spec.rb +44 -0
  844. data/spec/models/reward_spec.rb +141 -0
  845. data/spec/models/statistics_spec.rb +46 -0
  846. data/spec/models/subscriber_report_spec.rb +42 -0
  847. data/spec/models/unsubscribe_spec.rb +27 -0
  848. data/spec/models/update_spec.rb +95 -0
  849. data/spec/models/user_spec.rb +357 -0
  850. data/spec/models/user_total_spec.rb +5 -0
  851. data/spec/observers/backer_observer_spec.rb +119 -0
  852. data/spec/observers/notification_observer_spec.rb +13 -0
  853. data/spec/observers/payment_notification_observer_spec.rb +34 -0
  854. data/spec/observers/project_observer_spec.rb +224 -0
  855. data/spec/observers/update_observer_spec.rb +17 -0
  856. data/spec/observers/user_observer_spec.rb +23 -0
  857. data/spec/spec_helper.rb +82 -0
  858. data/spec/support/devise.rb +3 -0
  859. data/spec/support/factory_girl.rb +2 -0
  860. data/spec/support/feature_helpers.rb +19 -0
  861. data/spec/uploaders/image_uploader_spec.rb +58 -0
  862. data/spec/uploaders/project_uploader_spec.rb +37 -0
  863. data/spec/uploaders/user_uploader_spec.rb +23 -0
  864. data/spec/views/channels/base/index.html.slim_spec.rb +5 -0
  865. metadata +1915 -0
@@ -0,0 +1,74 @@
1
+ App.views.Project.addChild('ProjectSidebar', {
2
+ el: '.sidebar',
3
+
4
+ events:{
5
+ "click .show_reward_form": "showRewardForm",
6
+ "click #rewards .box.clickable" : "selectReward"
7
+ },
8
+
9
+ selectReward: function(event){
10
+ var url = this.$(event.currentTarget).data('new_backer_url');
11
+ this.navigate(url);
12
+ return false;
13
+ },
14
+
15
+ activate: function() {
16
+ this.$rewards = this.$('#rewards');
17
+ this.sortableRewards();
18
+ this.reloadRewards();
19
+ },
20
+
21
+ reloadRewards: function() {
22
+ var that = this;
23
+ $.get(that.$rewards.data('index_path')).success(function(data){
24
+ that.$rewards.html(data);
25
+ });
26
+ },
27
+
28
+ sortableRewards: function() {
29
+ if(this.$rewards.data("can_update") == true){
30
+ this.$rewards.sortable({
31
+ axis: 'y',
32
+ placeholder: "ui-state-highlight",
33
+ start: function(e, ui) {
34
+ return ui.placeholder.height(ui.item.height());
35
+ },
36
+ stop: function(e, ui) {
37
+ return ui.item.effect('highlight', {}, 1000);
38
+ },
39
+ update: function(e, ui) {
40
+ var csrfToken, position;
41
+ position = $('#rewards .sortable').index(ui.item);
42
+ csrfToken = $("meta[name='csrf-token']").attr("content");
43
+ return $.ajax({
44
+ type: 'POST',
45
+ url: ui.item.data('update_url'),
46
+ dataType: 'json',
47
+ headers: {
48
+ 'X-CSRF-Token': csrfToken
49
+ },
50
+ data: {
51
+ reward: {
52
+ row_order_position: position
53
+ }
54
+ }
55
+ });
56
+ }
57
+ })
58
+ }
59
+ },
60
+
61
+
62
+ showRewardForm: function(event) {
63
+ event.preventDefault();
64
+ var $target = this.$(event.currentTarget);
65
+ $target.fadeOut('fast');
66
+
67
+ $.get($target.data('path')).success(function(data){
68
+ $($target.data('target')).html(data);
69
+ });
70
+
71
+ this.$($target.data('target')).fadeIn('fast');
72
+ }
73
+ });
74
+
@@ -0,0 +1,44 @@
1
+ App.views.Project.addChild('Updates', _.extend({
2
+ el: '#project_updates',
3
+
4
+ events: {
5
+ 'ajax:success .results .update' : 'onUpdateDestroy',
6
+ 'ajax:success form#new_update' : 'onUpdateCreate'
7
+ },
8
+
9
+ onUpdateCreate: function(e, data){
10
+ $('.ghost-flash').addClass('flash').removeClass('hide', 'ghost-flash');
11
+ app.flash();
12
+ this.$results.prepend(data);
13
+ },
14
+
15
+ activate: function(){
16
+ this.$loader = this.$("#updates-loading img");
17
+ this.$loaderDiv = this.$("#updates-loading");
18
+ this.$results = this.$(".results");
19
+ this.path = this.$el.data('path');
20
+ this.filter = {};
21
+ this.setupScroll();
22
+ this.parent.on('selectTab', this.fetchPage);
23
+ this.on('scroll:success', this.parseXFBML);
24
+ },
25
+
26
+ parseXFBML: function(){
27
+ if(this.$el.is(':visible')){
28
+ FB.XFBML.parse();
29
+ }
30
+ },
31
+
32
+ updates: function(){
33
+ return this.$('.results .update');
34
+ },
35
+
36
+ onUpdateDestroy: function(e){
37
+ var $target = $(e.currentTarget);
38
+ $target.remove();
39
+ this.parent.$('a#updates_link .count').html(' (' + this.updates().length + ')');
40
+ }
41
+
42
+ }, Skull.InfiniteScroll));
43
+
44
+
@@ -0,0 +1,60 @@
1
+ App.addChild('ProjectForm', _.extend({
2
+ el: 'form#project_form',
3
+
4
+ events: {
5
+ 'blur input' : 'checkInput',
6
+ },
7
+
8
+ activate: function(){
9
+ this.setupForm();
10
+ }
11
+
12
+ }, Skull.Form));
13
+
14
+ // Put subview here to avoid dependency issues
15
+
16
+ App.views.ProjectForm.addChild('VideoUrl', _.extend({
17
+ el: 'input#project_video_url',
18
+
19
+ events: {
20
+ 'timedKeyup' : 'checkVideoUrl'
21
+ },
22
+
23
+ checkVideoUrl: function(){
24
+ var that = this;
25
+ $.get(this.$el.data('path') + '?url=' + encodeURIComponent(this.$el.val())).success(function(data){
26
+ if(!data || !data.video_id){
27
+ that.$el.trigger('invalid');
28
+ }
29
+ });
30
+ },
31
+
32
+ activate: function(){
33
+ this.setupTimedInput();
34
+ }
35
+ }, Skull.TimedInput));
36
+
37
+ App.views.ProjectForm.addChild('Permalink', _.extend({
38
+ el: 'input#project_permalink',
39
+
40
+ events: {
41
+ 'timedKeyup' : 'checkPermalink'
42
+ },
43
+
44
+ checkPermalink: function(){
45
+ var that = this;
46
+ if(this.re.test(this.$el.val())){
47
+ $.get('/pt/' + this.$el.val()).complete(function(data){
48
+ if(data.status != 404){
49
+ that.$el.trigger('invalid');
50
+ }
51
+ });
52
+ }
53
+ },
54
+
55
+ activate: function(){
56
+ this.re = new RegExp(this.$el.prop('pattern'));
57
+ this.setupTimedInput();
58
+ }
59
+ }, Skull.TimedInput));
60
+
@@ -0,0 +1,23 @@
1
+ App.addChild("Registration", {
2
+ el: '#catarse_bootstrap[data-controller-name="registrations"]',
3
+
4
+ events: {
5
+ 'change input#show_password': 'showPassword'
6
+ },
7
+
8
+ activate: function() {
9
+ this.$password_input = this.$('input#user_password');
10
+ },
11
+
12
+ showPassword: function(event) {
13
+ var $show_password = this.$(event.target);
14
+
15
+ if($show_password.prop('checked')) {
16
+ this.$password_input.prop('type', 'text');
17
+ } else {
18
+ this.$password_input.prop('type', 'password');
19
+ }
20
+
21
+ return false;
22
+ }
23
+ });
@@ -0,0 +1,48 @@
1
+ App.addChild('ReviewForm', _.extend({
2
+ el: 'form#review_form',
3
+
4
+ events: {
5
+ 'blur input' : 'checkInput',
6
+ 'click #accept' : 'acceptTerms',
7
+ 'click #live_in_brazil' : 'toggleAddressFields'
8
+ },
9
+
10
+ toggleAddressFields: function(){
11
+ this.$('fieldset.address_data').fadeToggle();
12
+ },
13
+
14
+ acceptTerms: function(){
15
+ if(this.validate()){
16
+ $('#payment').show();
17
+ this.updateBacker();
18
+ } else {
19
+ return false;
20
+ }
21
+ },
22
+
23
+ activate: function(){
24
+ this.setupForm();
25
+ if(this.$('#live_in_brazil:checked').length == 0){
26
+ this.$('fieldset.address_data').hide();
27
+ }
28
+ },
29
+
30
+ updateBacker: function(){
31
+ var backer_data = {
32
+ payer_name: this.$('#user_full_name').val(),
33
+ payer_email: this.$('#user_email').val(),
34
+ address_street: this.$('#user_address_street').val(),
35
+ address_number: this.$('#user_address_number').val(),
36
+ address_complement: this.$('#user_address_complement').val(),
37
+ address_neighbourhood: this.$('#user_address_neighbourhood').val(),
38
+ address_zip_code: this.$('#user_address_zip_code').val(),
39
+ address_city: this.$('#user_address_city').val(),
40
+ address_state: this.$('#user_address_state').val(),
41
+ address_phone_number: this.$('#user_phone_number').val()
42
+ }
43
+ $.post(this.$el.data('update-info-path'), {
44
+ backer: backer_data
45
+ });
46
+ }
47
+ }, Skull.Form));
48
+
@@ -0,0 +1,21 @@
1
+ App.addChild('User', _.extend({
2
+ el: '#main_content[data-action="show"][data-controller-name="users"]',
3
+
4
+ //@TODO: Refactor this ugly code into a generic routing generation inside the Skull.Tabs extension
5
+ activate: function(){
6
+ this.route('backs');
7
+ this.route('projects');
8
+ this.route('credits');
9
+ this.route('settings');
10
+ this.route('unsubscribes');
11
+ },
12
+
13
+ followRoute: function(){
14
+ var $tab = this.$('nav#user_profile_menu a[href="' + window.location.hash + '"]');
15
+ if($tab.length > 0){
16
+ this.onTabClick({ target: $tab });
17
+ }
18
+ },
19
+
20
+ }, Skull.Tabs));
21
+
@@ -0,0 +1,15 @@
1
+ App.views.User.addChild('UserBackers', _.extend({
2
+ el: '#user_backed_projects',
3
+
4
+ activate: function(){
5
+ this.$loader = this.$(".loading img");
6
+ this.$loaderDiv = this.$(".loading");
7
+ this.$results = this.$(".results");
8
+ this.path = this.$el.data('path');
9
+ this.filter = {};
10
+ this.setupScroll();
11
+ this.fetchPage();
12
+ }
13
+
14
+ }, Skull.InfiniteScroll));
15
+
@@ -0,0 +1,20 @@
1
+ App.views.User.addChild('UserProjects', _.extend({
2
+ el: '#user_created_projects',
3
+
4
+ activate: function(){
5
+ var that = this;
6
+ this.$loader = this.$(".loading img");
7
+ this.$loaderDiv = this.$(".loading");
8
+ this.$results = this.$(".results");
9
+ this.path = this.$el.data('path');
10
+ this.filter = {};
11
+ this.setupScroll();
12
+ this.parent.on('selectTab', function(){
13
+ if(that.$el.is(':visible')){
14
+ that.fetchPage();
15
+ }
16
+ });
17
+ }
18
+
19
+ }, Skull.InfiniteScroll));
20
+
@@ -0,0 +1,23 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require ./lib/jquery.js
14
+ //= require jquery_ujs
15
+ //= require ./lib/jquery-ui.js
16
+ //= require best_in_place
17
+ //= require ./lib/underscore.js
18
+ //= require ./lib/backbone.js
19
+ //= require ./lib/skull.js
20
+ //= require ./app/app.js
21
+ //= require_tree ./lib
22
+ //= require_tree ./app
23
+
@@ -0,0 +1,1571 @@
1
+ // Backbone.js 1.0.0
2
+
3
+ // (c) 2010-2013 Jeremy Ashkenas, DocumentCloud Inc.
4
+ // Backbone may be freely distributed under the MIT license.
5
+ // For all details and documentation:
6
+ // http://backbonejs.org
7
+
8
+ (function(){
9
+
10
+ // Initial Setup
11
+ // -------------
12
+
13
+ // Save a reference to the global object (`window` in the browser, `exports`
14
+ // on the server).
15
+ var root = this;
16
+
17
+ // Save the previous value of the `Backbone` variable, so that it can be
18
+ // restored later on, if `noConflict` is used.
19
+ var previousBackbone = root.Backbone;
20
+
21
+ // Create local references to array methods we'll want to use later.
22
+ var array = [];
23
+ var push = array.push;
24
+ var slice = array.slice;
25
+ var splice = array.splice;
26
+
27
+ // The top-level namespace. All public Backbone classes and modules will
28
+ // be attached to this. Exported for both the browser and the server.
29
+ var Backbone;
30
+ if (typeof exports !== 'undefined') {
31
+ Backbone = exports;
32
+ } else {
33
+ Backbone = root.Backbone = {};
34
+ }
35
+
36
+ // Current version of the library. Keep in sync with `package.json`.
37
+ Backbone.VERSION = '1.0.0';
38
+
39
+ // Require Underscore, if we're on the server, and it's not already present.
40
+ var _ = root._;
41
+ if (!_ && (typeof require !== 'undefined')) _ = require('underscore');
42
+
43
+ // For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
44
+ // the `$` variable.
45
+ Backbone.$ = root.jQuery || root.Zepto || root.ender || root.$;
46
+
47
+ // Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
48
+ // to its previous owner. Returns a reference to this Backbone object.
49
+ Backbone.noConflict = function() {
50
+ root.Backbone = previousBackbone;
51
+ return this;
52
+ };
53
+
54
+ // Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option
55
+ // will fake `"PUT"` and `"DELETE"` requests via the `_method` parameter and
56
+ // set a `X-Http-Method-Override` header.
57
+ Backbone.emulateHTTP = false;
58
+
59
+ // Turn on `emulateJSON` to support legacy servers that can't deal with direct
60
+ // `application/json` requests ... will encode the body as
61
+ // `application/x-www-form-urlencoded` instead and will send the model in a
62
+ // form param named `model`.
63
+ Backbone.emulateJSON = false;
64
+
65
+ // Backbone.Events
66
+ // ---------------
67
+
68
+ // A module that can be mixed in to *any object* in order to provide it with
69
+ // custom events. You may bind with `on` or remove with `off` callback
70
+ // functions to an event; `trigger`-ing an event fires all callbacks in
71
+ // succession.
72
+ //
73
+ // var object = {};
74
+ // _.extend(object, Backbone.Events);
75
+ // object.on('expand', function(){ alert('expanded'); });
76
+ // object.trigger('expand');
77
+ //
78
+ var Events = Backbone.Events = {
79
+
80
+ // Bind an event to a `callback` function. Passing `"all"` will bind
81
+ // the callback to all events fired.
82
+ on: function(name, callback, context) {
83
+ if (!eventsApi(this, 'on', name, [callback, context]) || !callback) return this;
84
+ this._events || (this._events = {});
85
+ var events = this._events[name] || (this._events[name] = []);
86
+ events.push({callback: callback, context: context, ctx: context || this});
87
+ return this;
88
+ },
89
+
90
+ // Bind an event to only be triggered a single time. After the first time
91
+ // the callback is invoked, it will be removed.
92
+ once: function(name, callback, context) {
93
+ if (!eventsApi(this, 'once', name, [callback, context]) || !callback) return this;
94
+ var self = this;
95
+ var once = _.once(function() {
96
+ self.off(name, once);
97
+ callback.apply(this, arguments);
98
+ });
99
+ once._callback = callback;
100
+ return this.on(name, once, context);
101
+ },
102
+
103
+ // Remove one or many callbacks. If `context` is null, removes all
104
+ // callbacks with that function. If `callback` is null, removes all
105
+ // callbacks for the event. If `name` is null, removes all bound
106
+ // callbacks for all events.
107
+ off: function(name, callback, context) {
108
+ var retain, ev, events, names, i, l, j, k;
109
+ if (!this._events || !eventsApi(this, 'off', name, [callback, context])) return this;
110
+ if (!name && !callback && !context) {
111
+ this._events = {};
112
+ return this;
113
+ }
114
+
115
+ names = name ? [name] : _.keys(this._events);
116
+ for (i = 0, l = names.length; i < l; i++) {
117
+ name = names[i];
118
+ if (events = this._events[name]) {
119
+ this._events[name] = retain = [];
120
+ if (callback || context) {
121
+ for (j = 0, k = events.length; j < k; j++) {
122
+ ev = events[j];
123
+ if ((callback && callback !== ev.callback && callback !== ev.callback._callback) ||
124
+ (context && context !== ev.context)) {
125
+ retain.push(ev);
126
+ }
127
+ }
128
+ }
129
+ if (!retain.length) delete this._events[name];
130
+ }
131
+ }
132
+
133
+ return this;
134
+ },
135
+
136
+ // Trigger one or many events, firing all bound callbacks. Callbacks are
137
+ // passed the same arguments as `trigger` is, apart from the event name
138
+ // (unless you're listening on `"all"`, which will cause your callback to
139
+ // receive the true name of the event as the first argument).
140
+ trigger: function(name) {
141
+ if (!this._events) return this;
142
+ var args = slice.call(arguments, 1);
143
+ if (!eventsApi(this, 'trigger', name, args)) return this;
144
+ var events = this._events[name];
145
+ var allEvents = this._events.all;
146
+ if (events) triggerEvents(events, args);
147
+ if (allEvents) triggerEvents(allEvents, arguments);
148
+ return this;
149
+ },
150
+
151
+ // Tell this object to stop listening to either specific events ... or
152
+ // to every object it's currently listening to.
153
+ stopListening: function(obj, name, callback) {
154
+ var listeners = this._listeners;
155
+ if (!listeners) return this;
156
+ var deleteListener = !name && !callback;
157
+ if (typeof name === 'object') callback = this;
158
+ if (obj) (listeners = {})[obj._listenerId] = obj;
159
+ for (var id in listeners) {
160
+ listeners[id].off(name, callback, this);
161
+ if (deleteListener) delete this._listeners[id];
162
+ }
163
+ return this;
164
+ }
165
+
166
+ };
167
+
168
+ // Regular expression used to split event strings.
169
+ var eventSplitter = /\s+/;
170
+
171
+ // Implement fancy features of the Events API such as multiple event
172
+ // names `"change blur"` and jQuery-style event maps `{change: action}`
173
+ // in terms of the existing API.
174
+ var eventsApi = function(obj, action, name, rest) {
175
+ if (!name) return true;
176
+
177
+ // Handle event maps.
178
+ if (typeof name === 'object') {
179
+ for (var key in name) {
180
+ obj[action].apply(obj, [key, name[key]].concat(rest));
181
+ }
182
+ return false;
183
+ }
184
+
185
+ // Handle space separated event names.
186
+ if (eventSplitter.test(name)) {
187
+ var names = name.split(eventSplitter);
188
+ for (var i = 0, l = names.length; i < l; i++) {
189
+ obj[action].apply(obj, [names[i]].concat(rest));
190
+ }
191
+ return false;
192
+ }
193
+
194
+ return true;
195
+ };
196
+
197
+ // A difficult-to-believe, but optimized internal dispatch function for
198
+ // triggering events. Tries to keep the usual cases speedy (most internal
199
+ // Backbone events have 3 arguments).
200
+ var triggerEvents = function(events, args) {
201
+ var ev, i = -1, l = events.length, a1 = args[0], a2 = args[1], a3 = args[2];
202
+ switch (args.length) {
203
+ case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); return;
204
+ case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1); return;
205
+ case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2); return;
206
+ case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return;
207
+ default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args);
208
+ }
209
+ };
210
+
211
+ var listenMethods = {listenTo: 'on', listenToOnce: 'once'};
212
+
213
+ // Inversion-of-control versions of `on` and `once`. Tell *this* object to
214
+ // listen to an event in another object ... keeping track of what it's
215
+ // listening to.
216
+ _.each(listenMethods, function(implementation, method) {
217
+ Events[method] = function(obj, name, callback) {
218
+ var listeners = this._listeners || (this._listeners = {});
219
+ var id = obj._listenerId || (obj._listenerId = _.uniqueId('l'));
220
+ listeners[id] = obj;
221
+ if (typeof name === 'object') callback = this;
222
+ obj[implementation](name, callback, this);
223
+ return this;
224
+ };
225
+ });
226
+
227
+ // Aliases for backwards compatibility.
228
+ Events.bind = Events.on;
229
+ Events.unbind = Events.off;
230
+
231
+ // Allow the `Backbone` object to serve as a global event bus, for folks who
232
+ // want global "pubsub" in a convenient place.
233
+ _.extend(Backbone, Events);
234
+
235
+ // Backbone.Model
236
+ // --------------
237
+
238
+ // Backbone **Models** are the basic data object in the framework --
239
+ // frequently representing a row in a table in a database on your server.
240
+ // A discrete chunk of data and a bunch of useful, related methods for
241
+ // performing computations and transformations on that data.
242
+
243
+ // Create a new model with the specified attributes. A client id (`cid`)
244
+ // is automatically generated and assigned for you.
245
+ var Model = Backbone.Model = function(attributes, options) {
246
+ var defaults;
247
+ var attrs = attributes || {};
248
+ options || (options = {});
249
+ this.cid = _.uniqueId('c');
250
+ this.attributes = {};
251
+ _.extend(this, _.pick(options, modelOptions));
252
+ if (options.parse) attrs = this.parse(attrs, options) || {};
253
+ if (defaults = _.result(this, 'defaults')) {
254
+ attrs = _.defaults({}, attrs, defaults);
255
+ }
256
+ this.set(attrs, options);
257
+ this.changed = {};
258
+ this.initialize.apply(this, arguments);
259
+ };
260
+
261
+ // A list of options to be attached directly to the model, if provided.
262
+ var modelOptions = ['url', 'urlRoot', 'collection'];
263
+
264
+ // Attach all inheritable methods to the Model prototype.
265
+ _.extend(Model.prototype, Events, {
266
+
267
+ // A hash of attributes whose current and previous value differ.
268
+ changed: null,
269
+
270
+ // The value returned during the last failed validation.
271
+ validationError: null,
272
+
273
+ // The default name for the JSON `id` attribute is `"id"`. MongoDB and
274
+ // CouchDB users may want to set this to `"_id"`.
275
+ idAttribute: 'id',
276
+
277
+ // Initialize is an empty function by default. Override it with your own
278
+ // initialization logic.
279
+ initialize: function(){},
280
+
281
+ // Return a copy of the model's `attributes` object.
282
+ toJSON: function(options) {
283
+ return _.clone(this.attributes);
284
+ },
285
+
286
+ // Proxy `Backbone.sync` by default -- but override this if you need
287
+ // custom syncing semantics for *this* particular model.
288
+ sync: function() {
289
+ return Backbone.sync.apply(this, arguments);
290
+ },
291
+
292
+ // Get the value of an attribute.
293
+ get: function(attr) {
294
+ return this.attributes[attr];
295
+ },
296
+
297
+ // Get the HTML-escaped value of an attribute.
298
+ escape: function(attr) {
299
+ return _.escape(this.get(attr));
300
+ },
301
+
302
+ // Returns `true` if the attribute contains a value that is not null
303
+ // or undefined.
304
+ has: function(attr) {
305
+ return this.get(attr) != null;
306
+ },
307
+
308
+ // Set a hash of model attributes on the object, firing `"change"`. This is
309
+ // the core primitive operation of a model, updating the data and notifying
310
+ // anyone who needs to know about the change in state. The heart of the beast.
311
+ set: function(key, val, options) {
312
+ var attr, attrs, unset, changes, silent, changing, prev, current;
313
+ if (key == null) return this;
314
+
315
+ // Handle both `"key", value` and `{key: value}` -style arguments.
316
+ if (typeof key === 'object') {
317
+ attrs = key;
318
+ options = val;
319
+ } else {
320
+ (attrs = {})[key] = val;
321
+ }
322
+
323
+ options || (options = {});
324
+
325
+ // Run validation.
326
+ if (!this._validate(attrs, options)) return false;
327
+
328
+ // Extract attributes and options.
329
+ unset = options.unset;
330
+ silent = options.silent;
331
+ changes = [];
332
+ changing = this._changing;
333
+ this._changing = true;
334
+
335
+ if (!changing) {
336
+ this._previousAttributes = _.clone(this.attributes);
337
+ this.changed = {};
338
+ }
339
+ current = this.attributes, prev = this._previousAttributes;
340
+
341
+ // Check for changes of `id`.
342
+ if (this.idAttribute in attrs) this.id = attrs[this.idAttribute];
343
+
344
+ // For each `set` attribute, update or delete the current value.
345
+ for (attr in attrs) {
346
+ val = attrs[attr];
347
+ if (!_.isEqual(current[attr], val)) changes.push(attr);
348
+ if (!_.isEqual(prev[attr], val)) {
349
+ this.changed[attr] = val;
350
+ } else {
351
+ delete this.changed[attr];
352
+ }
353
+ unset ? delete current[attr] : current[attr] = val;
354
+ }
355
+
356
+ // Trigger all relevant attribute changes.
357
+ if (!silent) {
358
+ if (changes.length) this._pending = true;
359
+ for (var i = 0, l = changes.length; i < l; i++) {
360
+ this.trigger('change:' + changes[i], this, current[changes[i]], options);
361
+ }
362
+ }
363
+
364
+ // You might be wondering why there's a `while` loop here. Changes can
365
+ // be recursively nested within `"change"` events.
366
+ if (changing) return this;
367
+ if (!silent) {
368
+ while (this._pending) {
369
+ this._pending = false;
370
+ this.trigger('change', this, options);
371
+ }
372
+ }
373
+ this._pending = false;
374
+ this._changing = false;
375
+ return this;
376
+ },
377
+
378
+ // Remove an attribute from the model, firing `"change"`. `unset` is a noop
379
+ // if the attribute doesn't exist.
380
+ unset: function(attr, options) {
381
+ return this.set(attr, void 0, _.extend({}, options, {unset: true}));
382
+ },
383
+
384
+ // Clear all attributes on the model, firing `"change"`.
385
+ clear: function(options) {
386
+ var attrs = {};
387
+ for (var key in this.attributes) attrs[key] = void 0;
388
+ return this.set(attrs, _.extend({}, options, {unset: true}));
389
+ },
390
+
391
+ // Determine if the model has changed since the last `"change"` event.
392
+ // If you specify an attribute name, determine if that attribute has changed.
393
+ hasChanged: function(attr) {
394
+ if (attr == null) return !_.isEmpty(this.changed);
395
+ return _.has(this.changed, attr);
396
+ },
397
+
398
+ // Return an object containing all the attributes that have changed, or
399
+ // false if there are no changed attributes. Useful for determining what
400
+ // parts of a view need to be updated and/or what attributes need to be
401
+ // persisted to the server. Unset attributes will be set to undefined.
402
+ // You can also pass an attributes object to diff against the model,
403
+ // determining if there *would be* a change.
404
+ changedAttributes: function(diff) {
405
+ if (!diff) return this.hasChanged() ? _.clone(this.changed) : false;
406
+ var val, changed = false;
407
+ var old = this._changing ? this._previousAttributes : this.attributes;
408
+ for (var attr in diff) {
409
+ if (_.isEqual(old[attr], (val = diff[attr]))) continue;
410
+ (changed || (changed = {}))[attr] = val;
411
+ }
412
+ return changed;
413
+ },
414
+
415
+ // Get the previous value of an attribute, recorded at the time the last
416
+ // `"change"` event was fired.
417
+ previous: function(attr) {
418
+ if (attr == null || !this._previousAttributes) return null;
419
+ return this._previousAttributes[attr];
420
+ },
421
+
422
+ // Get all of the attributes of the model at the time of the previous
423
+ // `"change"` event.
424
+ previousAttributes: function() {
425
+ return _.clone(this._previousAttributes);
426
+ },
427
+
428
+ // Fetch the model from the server. If the server's representation of the
429
+ // model differs from its current attributes, they will be overridden,
430
+ // triggering a `"change"` event.
431
+ fetch: function(options) {
432
+ options = options ? _.clone(options) : {};
433
+ if (options.parse === void 0) options.parse = true;
434
+ var model = this;
435
+ var success = options.success;
436
+ options.success = function(resp) {
437
+ if (!model.set(model.parse(resp, options), options)) return false;
438
+ if (success) success(model, resp, options);
439
+ model.trigger('sync', model, resp, options);
440
+ };
441
+ wrapError(this, options);
442
+ return this.sync('read', this, options);
443
+ },
444
+
445
+ // Set a hash of model attributes, and sync the model to the server.
446
+ // If the server returns an attributes hash that differs, the model's
447
+ // state will be `set` again.
448
+ save: function(key, val, options) {
449
+ var attrs, method, xhr, attributes = this.attributes;
450
+
451
+ // Handle both `"key", value` and `{key: value}` -style arguments.
452
+ if (key == null || typeof key === 'object') {
453
+ attrs = key;
454
+ options = val;
455
+ } else {
456
+ (attrs = {})[key] = val;
457
+ }
458
+
459
+ // If we're not waiting and attributes exist, save acts as `set(attr).save(null, opts)`.
460
+ if (attrs && (!options || !options.wait) && !this.set(attrs, options)) return false;
461
+
462
+ options = _.extend({validate: true}, options);
463
+
464
+ // Do not persist invalid models.
465
+ if (!this._validate(attrs, options)) return false;
466
+
467
+ // Set temporary attributes if `{wait: true}`.
468
+ if (attrs && options.wait) {
469
+ this.attributes = _.extend({}, attributes, attrs);
470
+ }
471
+
472
+ // After a successful server-side save, the client is (optionally)
473
+ // updated with the server-side state.
474
+ if (options.parse === void 0) options.parse = true;
475
+ var model = this;
476
+ var success = options.success;
477
+ options.success = function(resp) {
478
+ // Ensure attributes are restored during synchronous saves.
479
+ model.attributes = attributes;
480
+ var serverAttrs = model.parse(resp, options);
481
+ if (options.wait) serverAttrs = _.extend(attrs || {}, serverAttrs);
482
+ if (_.isObject(serverAttrs) && !model.set(serverAttrs, options)) {
483
+ return false;
484
+ }
485
+ if (success) success(model, resp, options);
486
+ model.trigger('sync', model, resp, options);
487
+ };
488
+ wrapError(this, options);
489
+
490
+ method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
491
+ if (method === 'patch') options.attrs = attrs;
492
+ xhr = this.sync(method, this, options);
493
+
494
+ // Restore attributes.
495
+ if (attrs && options.wait) this.attributes = attributes;
496
+
497
+ return xhr;
498
+ },
499
+
500
+ // Destroy this model on the server if it was already persisted.
501
+ // Optimistically removes the model from its collection, if it has one.
502
+ // If `wait: true` is passed, waits for the server to respond before removal.
503
+ destroy: function(options) {
504
+ options = options ? _.clone(options) : {};
505
+ var model = this;
506
+ var success = options.success;
507
+
508
+ var destroy = function() {
509
+ model.trigger('destroy', model, model.collection, options);
510
+ };
511
+
512
+ options.success = function(resp) {
513
+ if (options.wait || model.isNew()) destroy();
514
+ if (success) success(model, resp, options);
515
+ if (!model.isNew()) model.trigger('sync', model, resp, options);
516
+ };
517
+
518
+ if (this.isNew()) {
519
+ options.success();
520
+ return false;
521
+ }
522
+ wrapError(this, options);
523
+
524
+ var xhr = this.sync('delete', this, options);
525
+ if (!options.wait) destroy();
526
+ return xhr;
527
+ },
528
+
529
+ // Default URL for the model's representation on the server -- if you're
530
+ // using Backbone's restful methods, override this to change the endpoint
531
+ // that will be called.
532
+ url: function() {
533
+ var base = _.result(this, 'urlRoot') || _.result(this.collection, 'url') || urlError();
534
+ if (this.isNew()) return base;
535
+ return base + (base.charAt(base.length - 1) === '/' ? '' : '/') + encodeURIComponent(this.id);
536
+ },
537
+
538
+ // **parse** converts a response into the hash of attributes to be `set` on
539
+ // the model. The default implementation is just to pass the response along.
540
+ parse: function(resp, options) {
541
+ return resp;
542
+ },
543
+
544
+ // Create a new model with identical attributes to this one.
545
+ clone: function() {
546
+ return new this.constructor(this.attributes);
547
+ },
548
+
549
+ // A model is new if it has never been saved to the server, and lacks an id.
550
+ isNew: function() {
551
+ return this.id == null;
552
+ },
553
+
554
+ // Check if the model is currently in a valid state.
555
+ isValid: function(options) {
556
+ return this._validate({}, _.extend(options || {}, { validate: true }));
557
+ },
558
+
559
+ // Run validation against the next complete set of model attributes,
560
+ // returning `true` if all is well. Otherwise, fire an `"invalid"` event.
561
+ _validate: function(attrs, options) {
562
+ if (!options.validate || !this.validate) return true;
563
+ attrs = _.extend({}, this.attributes, attrs);
564
+ var error = this.validationError = this.validate(attrs, options) || null;
565
+ if (!error) return true;
566
+ this.trigger('invalid', this, error, _.extend(options || {}, {validationError: error}));
567
+ return false;
568
+ }
569
+
570
+ });
571
+
572
+ // Underscore methods that we want to implement on the Model.
573
+ var modelMethods = ['keys', 'values', 'pairs', 'invert', 'pick', 'omit'];
574
+
575
+ // Mix in each Underscore method as a proxy to `Model#attributes`.
576
+ _.each(modelMethods, function(method) {
577
+ Model.prototype[method] = function() {
578
+ var args = slice.call(arguments);
579
+ args.unshift(this.attributes);
580
+ return _[method].apply(_, args);
581
+ };
582
+ });
583
+
584
+ // Backbone.Collection
585
+ // -------------------
586
+
587
+ // If models tend to represent a single row of data, a Backbone Collection is
588
+ // more analagous to a table full of data ... or a small slice or page of that
589
+ // table, or a collection of rows that belong together for a particular reason
590
+ // -- all of the messages in this particular folder, all of the documents
591
+ // belonging to this particular author, and so on. Collections maintain
592
+ // indexes of their models, both in order, and for lookup by `id`.
593
+
594
+ // Create a new **Collection**, perhaps to contain a specific type of `model`.
595
+ // If a `comparator` is specified, the Collection will maintain
596
+ // its models in sort order, as they're added and removed.
597
+ var Collection = Backbone.Collection = function(models, options) {
598
+ options || (options = {});
599
+ if (options.url) this.url = options.url;
600
+ if (options.model) this.model = options.model;
601
+ if (options.comparator !== void 0) this.comparator = options.comparator;
602
+ this._reset();
603
+ this.initialize.apply(this, arguments);
604
+ if (models) this.reset(models, _.extend({silent: true}, options));
605
+ };
606
+
607
+ // Default options for `Collection#set`.
608
+ var setOptions = {add: true, remove: true, merge: true};
609
+ var addOptions = {add: true, merge: false, remove: false};
610
+
611
+ // Define the Collection's inheritable methods.
612
+ _.extend(Collection.prototype, Events, {
613
+
614
+ // The default model for a collection is just a **Backbone.Model**.
615
+ // This should be overridden in most cases.
616
+ model: Model,
617
+
618
+ // Initialize is an empty function by default. Override it with your own
619
+ // initialization logic.
620
+ initialize: function(){},
621
+
622
+ // The JSON representation of a Collection is an array of the
623
+ // models' attributes.
624
+ toJSON: function(options) {
625
+ return this.map(function(model){ return model.toJSON(options); });
626
+ },
627
+
628
+ // Proxy `Backbone.sync` by default.
629
+ sync: function() {
630
+ return Backbone.sync.apply(this, arguments);
631
+ },
632
+
633
+ // Add a model, or list of models to the set.
634
+ add: function(models, options) {
635
+ return this.set(models, _.defaults(options || {}, addOptions));
636
+ },
637
+
638
+ // Remove a model, or a list of models from the set.
639
+ remove: function(models, options) {
640
+ models = _.isArray(models) ? models.slice() : [models];
641
+ options || (options = {});
642
+ var i, l, index, model;
643
+ for (i = 0, l = models.length; i < l; i++) {
644
+ model = this.get(models[i]);
645
+ if (!model) continue;
646
+ delete this._byId[model.id];
647
+ delete this._byId[model.cid];
648
+ index = this.indexOf(model);
649
+ this.models.splice(index, 1);
650
+ this.length--;
651
+ if (!options.silent) {
652
+ options.index = index;
653
+ model.trigger('remove', model, this, options);
654
+ }
655
+ this._removeReference(model);
656
+ }
657
+ return this;
658
+ },
659
+
660
+ // Update a collection by `set`-ing a new list of models, adding new ones,
661
+ // removing models that are no longer present, and merging models that
662
+ // already exist in the collection, as necessary. Similar to **Model#set**,
663
+ // the core operation for updating the data contained by the collection.
664
+ set: function(models, options) {
665
+ options = _.defaults(options || {}, setOptions);
666
+ if (options.parse) models = this.parse(models, options);
667
+ if (!_.isArray(models)) models = models ? [models] : [];
668
+ var i, l, model, attrs, existing, sort;
669
+ var at = options.at;
670
+ var sortable = this.comparator && (at == null) && options.sort !== false;
671
+ var sortAttr = _.isString(this.comparator) ? this.comparator : null;
672
+ var toAdd = [], toRemove = [], modelMap = {};
673
+
674
+ // Turn bare objects into model references, and prevent invalid models
675
+ // from being added.
676
+ for (i = 0, l = models.length; i < l; i++) {
677
+ if (!(model = this._prepareModel(models[i], options))) continue;
678
+
679
+ // If a duplicate is found, prevent it from being added and
680
+ // optionally merge it into the existing model.
681
+ if (existing = this.get(model)) {
682
+ if (options.remove) modelMap[existing.cid] = true;
683
+ if (options.merge) {
684
+ existing.set(model.attributes, options);
685
+ if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true;
686
+ }
687
+
688
+ // This is a new model, push it to the `toAdd` list.
689
+ } else if (options.add) {
690
+ toAdd.push(model);
691
+
692
+ // Listen to added models' events, and index models for lookup by
693
+ // `id` and by `cid`.
694
+ model.on('all', this._onModelEvent, this);
695
+ this._byId[model.cid] = model;
696
+ if (model.id != null) this._byId[model.id] = model;
697
+ }
698
+ }
699
+
700
+ // Remove nonexistent models if appropriate.
701
+ if (options.remove) {
702
+ for (i = 0, l = this.length; i < l; ++i) {
703
+ if (!modelMap[(model = this.models[i]).cid]) toRemove.push(model);
704
+ }
705
+ if (toRemove.length) this.remove(toRemove, options);
706
+ }
707
+
708
+ // See if sorting is needed, update `length` and splice in new models.
709
+ if (toAdd.length) {
710
+ if (sortable) sort = true;
711
+ this.length += toAdd.length;
712
+ if (at != null) {
713
+ splice.apply(this.models, [at, 0].concat(toAdd));
714
+ } else {
715
+ push.apply(this.models, toAdd);
716
+ }
717
+ }
718
+
719
+ // Silently sort the collection if appropriate.
720
+ if (sort) this.sort({silent: true});
721
+
722
+ if (options.silent) return this;
723
+
724
+ // Trigger `add` events.
725
+ for (i = 0, l = toAdd.length; i < l; i++) {
726
+ (model = toAdd[i]).trigger('add', model, this, options);
727
+ }
728
+
729
+ // Trigger `sort` if the collection was sorted.
730
+ if (sort) this.trigger('sort', this, options);
731
+ return this;
732
+ },
733
+
734
+ // When you have more items than you want to add or remove individually,
735
+ // you can reset the entire set with a new list of models, without firing
736
+ // any granular `add` or `remove` events. Fires `reset` when finished.
737
+ // Useful for bulk operations and optimizations.
738
+ reset: function(models, options) {
739
+ options || (options = {});
740
+ for (var i = 0, l = this.models.length; i < l; i++) {
741
+ this._removeReference(this.models[i]);
742
+ }
743
+ options.previousModels = this.models;
744
+ this._reset();
745
+ this.add(models, _.extend({silent: true}, options));
746
+ if (!options.silent) this.trigger('reset', this, options);
747
+ return this;
748
+ },
749
+
750
+ // Add a model to the end of the collection.
751
+ push: function(model, options) {
752
+ model = this._prepareModel(model, options);
753
+ this.add(model, _.extend({at: this.length}, options));
754
+ return model;
755
+ },
756
+
757
+ // Remove a model from the end of the collection.
758
+ pop: function(options) {
759
+ var model = this.at(this.length - 1);
760
+ this.remove(model, options);
761
+ return model;
762
+ },
763
+
764
+ // Add a model to the beginning of the collection.
765
+ unshift: function(model, options) {
766
+ model = this._prepareModel(model, options);
767
+ this.add(model, _.extend({at: 0}, options));
768
+ return model;
769
+ },
770
+
771
+ // Remove a model from the beginning of the collection.
772
+ shift: function(options) {
773
+ var model = this.at(0);
774
+ this.remove(model, options);
775
+ return model;
776
+ },
777
+
778
+ // Slice out a sub-array of models from the collection.
779
+ slice: function(begin, end) {
780
+ return this.models.slice(begin, end);
781
+ },
782
+
783
+ // Get a model from the set by id.
784
+ get: function(obj) {
785
+ if (obj == null) return void 0;
786
+ return this._byId[obj.id != null ? obj.id : obj.cid || obj];
787
+ },
788
+
789
+ // Get the model at the given index.
790
+ at: function(index) {
791
+ return this.models[index];
792
+ },
793
+
794
+ // Return models with matching attributes. Useful for simple cases of
795
+ // `filter`.
796
+ where: function(attrs, first) {
797
+ if (_.isEmpty(attrs)) return first ? void 0 : [];
798
+ return this[first ? 'find' : 'filter'](function(model) {
799
+ for (var key in attrs) {
800
+ if (attrs[key] !== model.get(key)) return false;
801
+ }
802
+ return true;
803
+ });
804
+ },
805
+
806
+ // Return the first model with matching attributes. Useful for simple cases
807
+ // of `find`.
808
+ findWhere: function(attrs) {
809
+ return this.where(attrs, true);
810
+ },
811
+
812
+ // Force the collection to re-sort itself. You don't need to call this under
813
+ // normal circumstances, as the set will maintain sort order as each item
814
+ // is added.
815
+ sort: function(options) {
816
+ if (!this.comparator) throw new Error('Cannot sort a set without a comparator');
817
+ options || (options = {});
818
+
819
+ // Run sort based on type of `comparator`.
820
+ if (_.isString(this.comparator) || this.comparator.length === 1) {
821
+ this.models = this.sortBy(this.comparator, this);
822
+ } else {
823
+ this.models.sort(_.bind(this.comparator, this));
824
+ }
825
+
826
+ if (!options.silent) this.trigger('sort', this, options);
827
+ return this;
828
+ },
829
+
830
+ // Figure out the smallest index at which a model should be inserted so as
831
+ // to maintain order.
832
+ sortedIndex: function(model, value, context) {
833
+ value || (value = this.comparator);
834
+ var iterator = _.isFunction(value) ? value : function(model) {
835
+ return model.get(value);
836
+ };
837
+ return _.sortedIndex(this.models, model, iterator, context);
838
+ },
839
+
840
+ // Pluck an attribute from each model in the collection.
841
+ pluck: function(attr) {
842
+ return _.invoke(this.models, 'get', attr);
843
+ },
844
+
845
+ // Fetch the default set of models for this collection, resetting the
846
+ // collection when they arrive. If `reset: true` is passed, the response
847
+ // data will be passed through the `reset` method instead of `set`.
848
+ fetch: function(options) {
849
+ options = options ? _.clone(options) : {};
850
+ if (options.parse === void 0) options.parse = true;
851
+ var success = options.success;
852
+ var collection = this;
853
+ options.success = function(resp) {
854
+ var method = options.reset ? 'reset' : 'set';
855
+ collection[method](resp, options);
856
+ if (success) success(collection, resp, options);
857
+ collection.trigger('sync', collection, resp, options);
858
+ };
859
+ wrapError(this, options);
860
+ return this.sync('read', this, options);
861
+ },
862
+
863
+ // Create a new instance of a model in this collection. Add the model to the
864
+ // collection immediately, unless `wait: true` is passed, in which case we
865
+ // wait for the server to agree.
866
+ create: function(model, options) {
867
+ options = options ? _.clone(options) : {};
868
+ if (!(model = this._prepareModel(model, options))) return false;
869
+ if (!options.wait) this.add(model, options);
870
+ var collection = this;
871
+ var success = options.success;
872
+ options.success = function(resp) {
873
+ if (options.wait) collection.add(model, options);
874
+ if (success) success(model, resp, options);
875
+ };
876
+ model.save(null, options);
877
+ return model;
878
+ },
879
+
880
+ // **parse** converts a response into a list of models to be added to the
881
+ // collection. The default implementation is just to pass it through.
882
+ parse: function(resp, options) {
883
+ return resp;
884
+ },
885
+
886
+ // Create a new collection with an identical list of models as this one.
887
+ clone: function() {
888
+ return new this.constructor(this.models);
889
+ },
890
+
891
+ // Private method to reset all internal state. Called when the collection
892
+ // is first initialized or reset.
893
+ _reset: function() {
894
+ this.length = 0;
895
+ this.models = [];
896
+ this._byId = {};
897
+ },
898
+
899
+ // Prepare a hash of attributes (or other model) to be added to this
900
+ // collection.
901
+ _prepareModel: function(attrs, options) {
902
+ if (attrs instanceof Model) {
903
+ if (!attrs.collection) attrs.collection = this;
904
+ return attrs;
905
+ }
906
+ options || (options = {});
907
+ options.collection = this;
908
+ var model = new this.model(attrs, options);
909
+ if (!model._validate(attrs, options)) {
910
+ this.trigger('invalid', this, attrs, options);
911
+ return false;
912
+ }
913
+ return model;
914
+ },
915
+
916
+ // Internal method to sever a model's ties to a collection.
917
+ _removeReference: function(model) {
918
+ if (this === model.collection) delete model.collection;
919
+ model.off('all', this._onModelEvent, this);
920
+ },
921
+
922
+ // Internal method called every time a model in the set fires an event.
923
+ // Sets need to update their indexes when models change ids. All other
924
+ // events simply proxy through. "add" and "remove" events that originate
925
+ // in other collections are ignored.
926
+ _onModelEvent: function(event, model, collection, options) {
927
+ if ((event === 'add' || event === 'remove') && collection !== this) return;
928
+ if (event === 'destroy') this.remove(model, options);
929
+ if (model && event === 'change:' + model.idAttribute) {
930
+ delete this._byId[model.previous(model.idAttribute)];
931
+ if (model.id != null) this._byId[model.id] = model;
932
+ }
933
+ this.trigger.apply(this, arguments);
934
+ }
935
+
936
+ });
937
+
938
+ // Underscore methods that we want to implement on the Collection.
939
+ // 90% of the core usefulness of Backbone Collections is actually implemented
940
+ // right here:
941
+ var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
942
+ 'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
943
+ 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
944
+ 'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
945
+ 'tail', 'drop', 'last', 'without', 'indexOf', 'shuffle', 'lastIndexOf',
946
+ 'isEmpty', 'chain'];
947
+
948
+ // Mix in each Underscore method as a proxy to `Collection#models`.
949
+ _.each(methods, function(method) {
950
+ Collection.prototype[method] = function() {
951
+ var args = slice.call(arguments);
952
+ args.unshift(this.models);
953
+ return _[method].apply(_, args);
954
+ };
955
+ });
956
+
957
+ // Underscore methods that take a property name as an argument.
958
+ var attributeMethods = ['groupBy', 'countBy', 'sortBy'];
959
+
960
+ // Use attributes instead of properties.
961
+ _.each(attributeMethods, function(method) {
962
+ Collection.prototype[method] = function(value, context) {
963
+ var iterator = _.isFunction(value) ? value : function(model) {
964
+ return model.get(value);
965
+ };
966
+ return _[method](this.models, iterator, context);
967
+ };
968
+ });
969
+
970
+ // Backbone.View
971
+ // -------------
972
+
973
+ // Backbone Views are almost more convention than they are actual code. A View
974
+ // is simply a JavaScript object that represents a logical chunk of UI in the
975
+ // DOM. This might be a single item, an entire list, a sidebar or panel, or
976
+ // even the surrounding frame which wraps your whole app. Defining a chunk of
977
+ // UI as a **View** allows you to define your DOM events declaratively, without
978
+ // having to worry about render order ... and makes it easy for the view to
979
+ // react to specific changes in the state of your models.
980
+
981
+ // Creating a Backbone.View creates its initial element outside of the DOM,
982
+ // if an existing element is not provided...
983
+ var View = Backbone.View = function(options) {
984
+ this.cid = _.uniqueId('view');
985
+ this._configure(options || {});
986
+ this._ensureElement();
987
+ this.initialize.apply(this, arguments);
988
+ this.delegateEvents();
989
+ };
990
+
991
+ // Cached regex to split keys for `delegate`.
992
+ var delegateEventSplitter = /^(\S+)\s*(.*)$/;
993
+
994
+ // List of view options to be merged as properties.
995
+ var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
996
+
997
+ // Set up all inheritable **Backbone.View** properties and methods.
998
+ _.extend(View.prototype, Events, {
999
+
1000
+ // The default `tagName` of a View's element is `"div"`.
1001
+ tagName: 'div',
1002
+
1003
+ // jQuery delegate for element lookup, scoped to DOM elements within the
1004
+ // current view. This should be prefered to global lookups where possible.
1005
+ $: function(selector) {
1006
+ return this.$el.find(selector);
1007
+ },
1008
+
1009
+ // Initialize is an empty function by default. Override it with your own
1010
+ // initialization logic.
1011
+ initialize: function(){},
1012
+
1013
+ // **render** is the core function that your view should override, in order
1014
+ // to populate its element (`this.el`), with the appropriate HTML. The
1015
+ // convention is for **render** to always return `this`.
1016
+ render: function() {
1017
+ return this;
1018
+ },
1019
+
1020
+ // Remove this view by taking the element out of the DOM, and removing any
1021
+ // applicable Backbone.Events listeners.
1022
+ remove: function() {
1023
+ this.$el.remove();
1024
+ this.stopListening();
1025
+ return this;
1026
+ },
1027
+
1028
+ // Change the view's element (`this.el` property), including event
1029
+ // re-delegation.
1030
+ setElement: function(element, delegate) {
1031
+ if (this.$el) this.undelegateEvents();
1032
+ this.$el = element instanceof Backbone.$ ? element : Backbone.$(element);
1033
+ this.el = this.$el[0];
1034
+ if (delegate !== false) this.delegateEvents();
1035
+ return this;
1036
+ },
1037
+
1038
+ // Set callbacks, where `this.events` is a hash of
1039
+ //
1040
+ // *{"event selector": "callback"}*
1041
+ //
1042
+ // {
1043
+ // 'mousedown .title': 'edit',
1044
+ // 'click .button': 'save'
1045
+ // 'click .open': function(e) { ... }
1046
+ // }
1047
+ //
1048
+ // pairs. Callbacks will be bound to the view, with `this` set properly.
1049
+ // Uses event delegation for efficiency.
1050
+ // Omitting the selector binds the event to `this.el`.
1051
+ // This only works for delegate-able events: not `focus`, `blur`, and
1052
+ // not `change`, `submit`, and `reset` in Internet Explorer.
1053
+ delegateEvents: function(events) {
1054
+ if (!(events || (events = _.result(this, 'events')))) return this;
1055
+ this.undelegateEvents();
1056
+ for (var key in events) {
1057
+ var method = events[key];
1058
+ if (!_.isFunction(method)) method = this[events[key]];
1059
+ if (!method) continue;
1060
+
1061
+ var match = key.match(delegateEventSplitter);
1062
+ var eventName = match[1], selector = match[2];
1063
+ method = _.bind(method, this);
1064
+ eventName += '.delegateEvents' + this.cid;
1065
+ if (selector === '') {
1066
+ this.$el.on(eventName, method);
1067
+ } else {
1068
+ this.$el.on(eventName, selector, method);
1069
+ }
1070
+ }
1071
+ return this;
1072
+ },
1073
+
1074
+ // Clears all callbacks previously bound to the view with `delegateEvents`.
1075
+ // You usually don't need to use this, but may wish to if you have multiple
1076
+ // Backbone views attached to the same DOM element.
1077
+ undelegateEvents: function() {
1078
+ this.$el.off('.delegateEvents' + this.cid);
1079
+ return this;
1080
+ },
1081
+
1082
+ // Performs the initial configuration of a View with a set of options.
1083
+ // Keys with special meaning *(e.g. model, collection, id, className)* are
1084
+ // attached directly to the view. See `viewOptions` for an exhaustive
1085
+ // list.
1086
+ _configure: function(options) {
1087
+ if (this.options) options = _.extend({}, _.result(this, 'options'), options);
1088
+ _.extend(this, _.pick(options, viewOptions));
1089
+ this.options = options;
1090
+ },
1091
+
1092
+ // Ensure that the View has a DOM element to render into.
1093
+ // If `this.el` is a string, pass it through `$()`, take the first
1094
+ // matching element, and re-assign it to `el`. Otherwise, create
1095
+ // an element from the `id`, `className` and `tagName` properties.
1096
+ _ensureElement: function() {
1097
+ if (!this.el) {
1098
+ var attrs = _.extend({}, _.result(this, 'attributes'));
1099
+ if (this.id) attrs.id = _.result(this, 'id');
1100
+ if (this.className) attrs['class'] = _.result(this, 'className');
1101
+ var $el = Backbone.$('<' + _.result(this, 'tagName') + '>').attr(attrs);
1102
+ this.setElement($el, false);
1103
+ } else {
1104
+ this.setElement(_.result(this, 'el'), false);
1105
+ }
1106
+ }
1107
+
1108
+ });
1109
+
1110
+ // Backbone.sync
1111
+ // -------------
1112
+
1113
+ // Override this function to change the manner in which Backbone persists
1114
+ // models to the server. You will be passed the type of request, and the
1115
+ // model in question. By default, makes a RESTful Ajax request
1116
+ // to the model's `url()`. Some possible customizations could be:
1117
+ //
1118
+ // * Use `setTimeout` to batch rapid-fire updates into a single request.
1119
+ // * Send up the models as XML instead of JSON.
1120
+ // * Persist models via WebSockets instead of Ajax.
1121
+ //
1122
+ // Turn on `Backbone.emulateHTTP` in order to send `PUT` and `DELETE` requests
1123
+ // as `POST`, with a `_method` parameter containing the true HTTP method,
1124
+ // as well as all requests with the body as `application/x-www-form-urlencoded`
1125
+ // instead of `application/json` with the model in a param named `model`.
1126
+ // Useful when interfacing with server-side languages like **PHP** that make
1127
+ // it difficult to read the body of `PUT` requests.
1128
+ Backbone.sync = function(method, model, options) {
1129
+ var type = methodMap[method];
1130
+
1131
+ // Default options, unless specified.
1132
+ _.defaults(options || (options = {}), {
1133
+ emulateHTTP: Backbone.emulateHTTP,
1134
+ emulateJSON: Backbone.emulateJSON
1135
+ });
1136
+
1137
+ // Default JSON-request options.
1138
+ var params = {type: type, dataType: 'json'};
1139
+
1140
+ // Ensure that we have a URL.
1141
+ if (!options.url) {
1142
+ params.url = _.result(model, 'url') || urlError();
1143
+ }
1144
+
1145
+ // Ensure that we have the appropriate request data.
1146
+ if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
1147
+ params.contentType = 'application/json';
1148
+ params.data = JSON.stringify(options.attrs || model.toJSON(options));
1149
+ }
1150
+
1151
+ // For older servers, emulate JSON by encoding the request into an HTML-form.
1152
+ if (options.emulateJSON) {
1153
+ params.contentType = 'application/x-www-form-urlencoded';
1154
+ params.data = params.data ? {model: params.data} : {};
1155
+ }
1156
+
1157
+ // For older servers, emulate HTTP by mimicking the HTTP method with `_method`
1158
+ // And an `X-HTTP-Method-Override` header.
1159
+ if (options.emulateHTTP && (type === 'PUT' || type === 'DELETE' || type === 'PATCH')) {
1160
+ params.type = 'POST';
1161
+ if (options.emulateJSON) params.data._method = type;
1162
+ var beforeSend = options.beforeSend;
1163
+ options.beforeSend = function(xhr) {
1164
+ xhr.setRequestHeader('X-HTTP-Method-Override', type);
1165
+ if (beforeSend) return beforeSend.apply(this, arguments);
1166
+ };
1167
+ }
1168
+
1169
+ // Don't process data on a non-GET request.
1170
+ if (params.type !== 'GET' && !options.emulateJSON) {
1171
+ params.processData = false;
1172
+ }
1173
+
1174
+ // If we're sending a `PATCH` request, and we're in an old Internet Explorer
1175
+ // that still has ActiveX enabled by default, override jQuery to use that
1176
+ // for XHR instead. Remove this line when jQuery supports `PATCH` on IE8.
1177
+ if (params.type === 'PATCH' && window.ActiveXObject &&
1178
+ !(window.external && window.external.msActiveXFilteringEnabled)) {
1179
+ params.xhr = function() {
1180
+ return new ActiveXObject("Microsoft.XMLHTTP");
1181
+ };
1182
+ }
1183
+
1184
+ // Make the request, allowing the user to override any Ajax options.
1185
+ var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
1186
+ model.trigger('request', model, xhr, options);
1187
+ return xhr;
1188
+ };
1189
+
1190
+ // Map from CRUD to HTTP for our default `Backbone.sync` implementation.
1191
+ var methodMap = {
1192
+ 'create': 'POST',
1193
+ 'update': 'PUT',
1194
+ 'patch': 'PATCH',
1195
+ 'delete': 'DELETE',
1196
+ 'read': 'GET'
1197
+ };
1198
+
1199
+ // Set the default implementation of `Backbone.ajax` to proxy through to `$`.
1200
+ // Override this if you'd like to use a different library.
1201
+ Backbone.ajax = function() {
1202
+ return Backbone.$.ajax.apply(Backbone.$, arguments);
1203
+ };
1204
+
1205
+ // Backbone.Router
1206
+ // ---------------
1207
+
1208
+ // Routers map faux-URLs to actions, and fire events when routes are
1209
+ // matched. Creating a new one sets its `routes` hash, if not set statically.
1210
+ var Router = Backbone.Router = function(options) {
1211
+ options || (options = {});
1212
+ if (options.routes) this.routes = options.routes;
1213
+ this._bindRoutes();
1214
+ this.initialize.apply(this, arguments);
1215
+ };
1216
+
1217
+ // Cached regular expressions for matching named param parts and splatted
1218
+ // parts of route strings.
1219
+ var optionalParam = /\((.*?)\)/g;
1220
+ var namedParam = /(\(\?)?:\w+/g;
1221
+ var splatParam = /\*\w+/g;
1222
+ var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
1223
+
1224
+ // Set up all inheritable **Backbone.Router** properties and methods.
1225
+ _.extend(Router.prototype, Events, {
1226
+
1227
+ // Initialize is an empty function by default. Override it with your own
1228
+ // initialization logic.
1229
+ initialize: function(){},
1230
+
1231
+ // Manually bind a single named route to a callback. For example:
1232
+ //
1233
+ // this.route('search/:query/p:num', 'search', function(query, num) {
1234
+ // ...
1235
+ // });
1236
+ //
1237
+ route: function(route, name, callback) {
1238
+ if (!_.isRegExp(route)) route = this._routeToRegExp(route);
1239
+ if (_.isFunction(name)) {
1240
+ callback = name;
1241
+ name = '';
1242
+ }
1243
+ if (!callback) callback = this[name];
1244
+ var router = this;
1245
+ Backbone.history.route(route, function(fragment) {
1246
+ var args = router._extractParameters(route, fragment);
1247
+ callback && callback.apply(router, args);
1248
+ router.trigger.apply(router, ['route:' + name].concat(args));
1249
+ router.trigger('route', name, args);
1250
+ Backbone.history.trigger('route', router, name, args);
1251
+ });
1252
+ return this;
1253
+ },
1254
+
1255
+ // Simple proxy to `Backbone.history` to save a fragment into the history.
1256
+ navigate: function(fragment, options) {
1257
+ Backbone.history.navigate(fragment, options);
1258
+ return this;
1259
+ },
1260
+
1261
+ // Bind all defined routes to `Backbone.history`. We have to reverse the
1262
+ // order of the routes here to support behavior where the most general
1263
+ // routes can be defined at the bottom of the route map.
1264
+ _bindRoutes: function() {
1265
+ if (!this.routes) return;
1266
+ this.routes = _.result(this, 'routes');
1267
+ var route, routes = _.keys(this.routes);
1268
+ while ((route = routes.pop()) != null) {
1269
+ this.route(route, this.routes[route]);
1270
+ }
1271
+ },
1272
+
1273
+ // Convert a route string into a regular expression, suitable for matching
1274
+ // against the current location hash.
1275
+ _routeToRegExp: function(route) {
1276
+ route = route.replace(escapeRegExp, '\\$&')
1277
+ .replace(optionalParam, '(?:$1)?')
1278
+ .replace(namedParam, function(match, optional){
1279
+ return optional ? match : '([^\/]+)';
1280
+ })
1281
+ .replace(splatParam, '(.*?)');
1282
+ return new RegExp('^' + route + '$');
1283
+ },
1284
+
1285
+ // Given a route, and a URL fragment that it matches, return the array of
1286
+ // extracted decoded parameters. Empty or unmatched parameters will be
1287
+ // treated as `null` to normalize cross-browser behavior.
1288
+ _extractParameters: function(route, fragment) {
1289
+ var params = route.exec(fragment).slice(1);
1290
+ return _.map(params, function(param) {
1291
+ return param ? decodeURIComponent(param) : null;
1292
+ });
1293
+ }
1294
+
1295
+ });
1296
+
1297
+ // Backbone.History
1298
+ // ----------------
1299
+
1300
+ // Handles cross-browser history management, based on either
1301
+ // [pushState](http://diveintohtml5.info/history.html) and real URLs, or
1302
+ // [onhashchange](https://developer.mozilla.org/en-US/docs/DOM/window.onhashchange)
1303
+ // and URL fragments. If the browser supports neither (old IE, natch),
1304
+ // falls back to polling.
1305
+ var History = Backbone.History = function() {
1306
+ this.handlers = [];
1307
+ _.bindAll(this, 'checkUrl');
1308
+
1309
+ // Ensure that `History` can be used outside of the browser.
1310
+ if (typeof window !== 'undefined') {
1311
+ this.location = window.location;
1312
+ this.history = window.history;
1313
+ }
1314
+ };
1315
+
1316
+ // Cached regex for stripping a leading hash/slash and trailing space.
1317
+ var routeStripper = /^[#\/]|\s+$/g;
1318
+
1319
+ // Cached regex for stripping leading and trailing slashes.
1320
+ var rootStripper = /^\/+|\/+$/g;
1321
+
1322
+ // Cached regex for detecting MSIE.
1323
+ var isExplorer = /msie [\w.]+/;
1324
+
1325
+ // Cached regex for removing a trailing slash.
1326
+ var trailingSlash = /\/$/;
1327
+
1328
+ // Has the history handling already been started?
1329
+ History.started = false;
1330
+
1331
+ // Set up all inheritable **Backbone.History** properties and methods.
1332
+ _.extend(History.prototype, Events, {
1333
+
1334
+ // The default interval to poll for hash changes, if necessary, is
1335
+ // twenty times a second.
1336
+ interval: 50,
1337
+
1338
+ // Gets the true hash value. Cannot use location.hash directly due to bug
1339
+ // in Firefox where location.hash will always be decoded.
1340
+ getHash: function(window) {
1341
+ var match = (window || this).location.href.match(/#(.*)$/);
1342
+ return match ? match[1] : '';
1343
+ },
1344
+
1345
+ // Get the cross-browser normalized URL fragment, either from the URL,
1346
+ // the hash, or the override.
1347
+ getFragment: function(fragment, forcePushState) {
1348
+ if (fragment == null) {
1349
+ if (this._hasPushState || !this._wantsHashChange || forcePushState) {
1350
+ fragment = this.location.pathname;
1351
+ var root = this.root.replace(trailingSlash, '');
1352
+ if (!fragment.indexOf(root)) fragment = fragment.substr(root.length);
1353
+ } else {
1354
+ fragment = this.getHash();
1355
+ }
1356
+ }
1357
+ return fragment.replace(routeStripper, '');
1358
+ },
1359
+
1360
+ // Start the hash change handling, returning `true` if the current URL matches
1361
+ // an existing route, and `false` otherwise.
1362
+ start: function(options) {
1363
+ if (History.started) throw new Error("Backbone.history has already been started");
1364
+ History.started = true;
1365
+
1366
+ // Figure out the initial configuration. Do we need an iframe?
1367
+ // Is pushState desired ... is it available?
1368
+ this.options = _.extend({}, {root: '/'}, this.options, options);
1369
+ this.root = this.options.root;
1370
+ this._wantsHashChange = this.options.hashChange !== false;
1371
+ this._wantsPushState = !!this.options.pushState;
1372
+ this._hasPushState = !!(this.options.pushState && this.history && this.history.pushState);
1373
+ var fragment = this.getFragment();
1374
+ var docMode = document.documentMode;
1375
+ var oldIE = (isExplorer.exec(navigator.userAgent.toLowerCase()) && (!docMode || docMode <= 7));
1376
+
1377
+ // Normalize root to always include a leading and trailing slash.
1378
+ this.root = ('/' + this.root + '/').replace(rootStripper, '/');
1379
+
1380
+ if (oldIE && this._wantsHashChange) {
1381
+ this.iframe = Backbone.$('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo('body')[0].contentWindow;
1382
+ this.navigate(fragment);
1383
+ }
1384
+
1385
+ // Depending on whether we're using pushState or hashes, and whether
1386
+ // 'onhashchange' is supported, determine how we check the URL state.
1387
+ if (this._hasPushState) {
1388
+ Backbone.$(window).on('popstate', this.checkUrl);
1389
+ } else if (this._wantsHashChange && ('onhashchange' in window) && !oldIE) {
1390
+ Backbone.$(window).on('hashchange', this.checkUrl);
1391
+ } else if (this._wantsHashChange) {
1392
+ this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
1393
+ }
1394
+
1395
+ // Determine if we need to change the base url, for a pushState link
1396
+ // opened by a non-pushState browser.
1397
+ this.fragment = fragment;
1398
+ var loc = this.location;
1399
+ var atRoot = loc.pathname.replace(/[^\/]$/, '$&/') === this.root;
1400
+
1401
+ // If we've started off with a route from a `pushState`-enabled browser,
1402
+ // but we're currently in a browser that doesn't support it...
1403
+ if (this._wantsHashChange && this._wantsPushState && !this._hasPushState && !atRoot) {
1404
+ this.fragment = this.getFragment(null, true);
1405
+ this.location.replace(this.root + this.location.search + '#' + this.fragment);
1406
+ // Return immediately as browser will do redirect to new url
1407
+ return true;
1408
+
1409
+ // Or if we've started out with a hash-based route, but we're currently
1410
+ // in a browser where it could be `pushState`-based instead...
1411
+ } else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
1412
+ this.fragment = this.getHash().replace(routeStripper, '');
1413
+ this.history.replaceState({}, document.title, this.root + this.fragment + loc.search);
1414
+ }
1415
+
1416
+ if (!this.options.silent) return this.loadUrl();
1417
+ },
1418
+
1419
+ // Disable Backbone.history, perhaps temporarily. Not useful in a real app,
1420
+ // but possibly useful for unit testing Routers.
1421
+ stop: function() {
1422
+ Backbone.$(window).off('popstate', this.checkUrl).off('hashchange', this.checkUrl);
1423
+ clearInterval(this._checkUrlInterval);
1424
+ History.started = false;
1425
+ },
1426
+
1427
+ // Add a route to be tested when the fragment changes. Routes added later
1428
+ // may override previous routes.
1429
+ route: function(route, callback) {
1430
+ this.handlers.unshift({route: route, callback: callback});
1431
+ },
1432
+
1433
+ // Checks the current URL to see if it has changed, and if it has,
1434
+ // calls `loadUrl`, normalizing across the hidden iframe.
1435
+ checkUrl: function(e) {
1436
+ var current = this.getFragment();
1437
+ if (current === this.fragment && this.iframe) {
1438
+ current = this.getFragment(this.getHash(this.iframe));
1439
+ }
1440
+ if (current === this.fragment) return false;
1441
+ if (this.iframe) this.navigate(current);
1442
+ this.loadUrl() || this.loadUrl(this.getHash());
1443
+ },
1444
+
1445
+ // Attempt to load the current URL fragment. If a route succeeds with a
1446
+ // match, returns `true`. If no defined routes matches the fragment,
1447
+ // returns `false`.
1448
+ loadUrl: function(fragmentOverride) {
1449
+ var fragment = this.fragment = this.getFragment(fragmentOverride);
1450
+ var matched = _.any(this.handlers, function(handler) {
1451
+ if (handler.route.test(fragment)) {
1452
+ handler.callback(fragment);
1453
+ return true;
1454
+ }
1455
+ });
1456
+ return matched;
1457
+ },
1458
+
1459
+ // Save a fragment into the hash history, or replace the URL state if the
1460
+ // 'replace' option is passed. You are responsible for properly URL-encoding
1461
+ // the fragment in advance.
1462
+ //
1463
+ // The options object can contain `trigger: true` if you wish to have the
1464
+ // route callback be fired (not usually desirable), or `replace: true`, if
1465
+ // you wish to modify the current URL without adding an entry to the history.
1466
+ navigate: function(fragment, options) {
1467
+ if (!History.started) return false;
1468
+ if (!options || options === true) options = {trigger: options};
1469
+ fragment = this.getFragment(fragment || '');
1470
+ if (this.fragment === fragment) return;
1471
+ this.fragment = fragment;
1472
+ var url = this.root + fragment;
1473
+
1474
+ // If pushState is available, we use it to set the fragment as a real URL.
1475
+ if (this._hasPushState) {
1476
+ this.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, url);
1477
+
1478
+ // If hash changes haven't been explicitly disabled, update the hash
1479
+ // fragment to store history.
1480
+ } else if (this._wantsHashChange) {
1481
+ this._updateHash(this.location, fragment, options.replace);
1482
+ if (this.iframe && (fragment !== this.getFragment(this.getHash(this.iframe)))) {
1483
+ // Opening and closing the iframe tricks IE7 and earlier to push a
1484
+ // history entry on hash-tag change. When replace is true, we don't
1485
+ // want this.
1486
+ if(!options.replace) this.iframe.document.open().close();
1487
+ this._updateHash(this.iframe.location, fragment, options.replace);
1488
+ }
1489
+
1490
+ // If you've told us that you explicitly don't want fallback hashchange-
1491
+ // based history, then `navigate` becomes a page refresh.
1492
+ } else {
1493
+ return this.location.assign(url);
1494
+ }
1495
+ if (options.trigger) this.loadUrl(fragment);
1496
+ },
1497
+
1498
+ // Update the hash location, either replacing the current entry, or adding
1499
+ // a new one to the browser history.
1500
+ _updateHash: function(location, fragment, replace) {
1501
+ if (replace) {
1502
+ var href = location.href.replace(/(javascript:|#).*$/, '');
1503
+ location.replace(href + '#' + fragment);
1504
+ } else {
1505
+ // Some browsers require that `hash` contains a leading #.
1506
+ location.hash = '#' + fragment;
1507
+ }
1508
+ }
1509
+
1510
+ });
1511
+
1512
+ // Create the default Backbone.history.
1513
+ Backbone.history = new History;
1514
+
1515
+ // Helpers
1516
+ // -------
1517
+
1518
+ // Helper function to correctly set up the prototype chain, for subclasses.
1519
+ // Similar to `goog.inherits`, but uses a hash of prototype properties and
1520
+ // class properties to be extended.
1521
+ var extend = function(protoProps, staticProps) {
1522
+ var parent = this;
1523
+ var child;
1524
+
1525
+ // The constructor function for the new subclass is either defined by you
1526
+ // (the "constructor" property in your `extend` definition), or defaulted
1527
+ // by us to simply call the parent's constructor.
1528
+ if (protoProps && _.has(protoProps, 'constructor')) {
1529
+ child = protoProps.constructor;
1530
+ } else {
1531
+ child = function(){ return parent.apply(this, arguments); };
1532
+ }
1533
+
1534
+ // Add static properties to the constructor function, if supplied.
1535
+ _.extend(child, parent, staticProps);
1536
+
1537
+ // Set the prototype chain to inherit from `parent`, without calling
1538
+ // `parent`'s constructor function.
1539
+ var Surrogate = function(){ this.constructor = child; };
1540
+ Surrogate.prototype = parent.prototype;
1541
+ child.prototype = new Surrogate;
1542
+
1543
+ // Add prototype properties (instance properties) to the subclass,
1544
+ // if supplied.
1545
+ if (protoProps) _.extend(child.prototype, protoProps);
1546
+
1547
+ // Set a convenience property in case the parent's prototype is needed
1548
+ // later.
1549
+ child.__super__ = parent.prototype;
1550
+
1551
+ return child;
1552
+ };
1553
+
1554
+ // Set up inheritance for the model, collection, router, view and history.
1555
+ Model.extend = Collection.extend = Router.extend = View.extend = History.extend = extend;
1556
+
1557
+ // Throw an error when a URL is needed, and none is supplied.
1558
+ var urlError = function() {
1559
+ throw new Error('A "url" property or function must be specified');
1560
+ };
1561
+
1562
+ // Wrap an optional error callback with a fallback error event.
1563
+ var wrapError = function (model, options) {
1564
+ var error = options.error;
1565
+ options.error = function(resp) {
1566
+ if (error) error(model, resp, options);
1567
+ model.trigger('error', model, resp, options);
1568
+ };
1569
+ };
1570
+
1571
+ }).call(this);