storytime 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (359) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +17 -0
  7. data/Gemfile.lock +448 -0
  8. data/Guardfile +24 -0
  9. data/MIT-LICENSE +1 -1
  10. data/README.md +160 -0
  11. data/app/assets/{javascripts/storytime/subscriptions.js → images/storytime/.keep} +0 -0
  12. data/app/assets/images/storytime/storytime-logo-nav-light.png +0 -0
  13. data/app/assets/images/storytime/storytime-logo-nav.png +0 -0
  14. data/app/assets/images/storytime/storytime-logo.png +0 -0
  15. data/app/assets/javascripts/storytime/application.js +11 -3
  16. data/app/assets/javascripts/storytime/base.js.coffee +44 -6
  17. data/app/assets/javascripts/storytime/blog_posts.js.coffee +16 -0
  18. data/app/assets/javascripts/storytime/blogs.js.coffee +18 -0
  19. data/app/assets/javascripts/storytime/character_counter.js.coffee +26 -0
  20. data/app/assets/javascripts/storytime/contenteditable.js.coffee +15 -0
  21. data/app/assets/javascripts/storytime/custom_posts.js.coffee +16 -0
  22. data/app/assets/javascripts/storytime/editor.js.coffee +50 -134
  23. data/app/assets/javascripts/storytime/media.js.coffee +91 -22
  24. data/app/assets/javascripts/storytime/pages.js.coffee +16 -0
  25. data/app/assets/javascripts/storytime/posts.js.coffee +28 -1
  26. data/app/assets/javascripts/storytime/sites.js.coffee +1 -16
  27. data/app/assets/javascripts/storytime/snippets.js.coffee +6 -3
  28. data/app/assets/javascripts/storytime/tags.js.coffee +17 -0
  29. data/app/assets/javascripts/storytime/users.js.coffee +10 -0
  30. data/app/assets/javascripts/storytime/wysiwyg.js.coffee +183 -0
  31. data/app/assets/stylesheets/storytime/_buttons.scss +70 -0
  32. data/app/assets/stylesheets/storytime/_dropdowns.scss +5 -0
  33. data/app/assets/stylesheets/storytime/_forms.scss +3 -0
  34. data/app/assets/stylesheets/storytime/_list-group.scss +13 -0
  35. data/app/assets/stylesheets/storytime/_pagination.scss +14 -0
  36. data/app/assets/stylesheets/storytime/_panels.scss +8 -0
  37. data/app/assets/stylesheets/storytime/_tabs.scss +38 -0
  38. data/app/assets/stylesheets/storytime/_type.scss +13 -0
  39. data/app/assets/stylesheets/storytime/_wells.scss +14 -0
  40. data/app/assets/stylesheets/storytime/admin.scss +42 -0
  41. data/app/assets/stylesheets/storytime/application.scss +75 -0
  42. data/app/assets/stylesheets/storytime/{comments.css.scss → comments.scss} +0 -0
  43. data/app/assets/stylesheets/storytime/icons.scss +79 -0
  44. data/app/assets/stylesheets/storytime/layout.scss +21 -0
  45. data/app/assets/stylesheets/storytime/media.scss +65 -0
  46. data/app/assets/stylesheets/storytime/modals.scss +46 -0
  47. data/app/assets/stylesheets/storytime/navigation.scss +137 -0
  48. data/app/assets/stylesheets/storytime/posts.scss +76 -0
  49. data/app/assets/stylesheets/storytime/scroll-panels.scss +19 -0
  50. data/app/assets/stylesheets/storytime/snippets.scss +11 -0
  51. data/app/assets/stylesheets/storytime/{sites.css.scss → subscriptions.scss} +0 -0
  52. data/app/assets/stylesheets/storytime/versions.scss +21 -0
  53. data/app/controllers/storytime/application_controller.rb +36 -16
  54. data/app/controllers/storytime/blog_homepage_controller.rb +10 -0
  55. data/app/controllers/storytime/blogs_controller.rb +56 -0
  56. data/app/controllers/storytime/comments_controller.rb +5 -1
  57. data/app/controllers/storytime/dashboard/autosaves_controller.rb +7 -3
  58. data/app/controllers/storytime/dashboard/blog_posts_controller.rb +60 -0
  59. data/app/controllers/storytime/dashboard/blogs_controller.rb +66 -0
  60. data/app/controllers/storytime/dashboard/custom_posts_controller.rb +51 -0
  61. data/app/controllers/storytime/dashboard/media_controller.rb +9 -7
  62. data/app/controllers/storytime/dashboard/memberships_controller.rb +49 -0
  63. data/app/controllers/storytime/dashboard/pages_controller.rb +24 -0
  64. data/app/controllers/storytime/dashboard/posts_controller.rb +29 -38
  65. data/app/controllers/storytime/dashboard/roles_controller.rb +16 -2
  66. data/app/controllers/storytime/dashboard/sites_controller.rb +25 -11
  67. data/app/controllers/storytime/dashboard/snippets_controller.rb +19 -14
  68. data/app/controllers/storytime/dashboard/subscriptions_controller.rb +9 -5
  69. data/app/controllers/storytime/dashboard/users_controller.rb +24 -22
  70. data/app/controllers/storytime/dashboard_controller.rb +9 -3
  71. data/app/controllers/storytime/homepage_controller.rb +10 -0
  72. data/app/controllers/storytime/pages_controller.rb +30 -13
  73. data/app/controllers/storytime/posts_controller.rb +22 -53
  74. data/app/controllers/storytime/subscriptions_controller.rb +5 -4
  75. data/app/helpers/storytime/application_helper.rb +28 -7
  76. data/app/helpers/storytime/dashboard/sites_helper.rb +2 -5
  77. data/app/helpers/storytime/subscriptions_helper.rb +0 -7
  78. data/app/inputs/date_time_picker_input.rb +1 -1
  79. data/app/mailers/storytime/subscription_mailer.rb +1 -3
  80. data/app/models/concerns/storytime/post_comments.rb +17 -0
  81. data/app/models/concerns/storytime/post_excerpt.rb +14 -0
  82. data/app/models/concerns/storytime/post_featured_images.rb +8 -0
  83. data/app/models/concerns/storytime/post_partial_inheritance.rb +29 -0
  84. data/app/models/concerns/storytime/post_tags.rb +41 -0
  85. data/app/models/concerns/storytime/scoped_to_site.rb +11 -0
  86. data/app/models/storytime/action.rb +1 -0
  87. data/app/models/storytime/autosave.rb +7 -1
  88. data/app/models/storytime/blog.rb +16 -0
  89. data/app/models/storytime/blog_post.rb +12 -1
  90. data/app/models/storytime/comment.rb +4 -1
  91. data/app/models/storytime/media.rb +2 -0
  92. data/app/models/storytime/membership.rb +17 -0
  93. data/app/models/storytime/page.rb +0 -5
  94. data/app/models/storytime/permission.rb +26 -20
  95. data/app/models/storytime/post.rb +29 -82
  96. data/app/models/storytime/role.rb +12 -0
  97. data/app/models/storytime/site.rb +42 -12
  98. data/app/models/storytime/snippet.rb +3 -0
  99. data/app/models/storytime/subscription.rb +2 -1
  100. data/app/models/storytime/tag.rb +5 -1
  101. data/app/models/storytime/tagging.rb +1 -0
  102. data/app/models/storytime/version.rb +1 -0
  103. data/app/policies/admin_policy.rb +30 -0
  104. data/app/policies/storytime/comment_policy.rb +5 -1
  105. data/app/policies/storytime/membership_policy.rb +32 -0
  106. data/app/policies/storytime/post_policy.rb +6 -4
  107. data/app/policies/storytime/site_policy.rb +7 -2
  108. data/app/policies/storytime/snippet_policy.rb +3 -2
  109. data/app/policies/storytime/subscription_policy.rb +3 -2
  110. data/app/policies/user_policy.rb +2 -5
  111. data/app/views/kaminari/_first_page.html.erb +13 -0
  112. data/app/views/kaminari/_gap.html.erb +8 -0
  113. data/app/views/kaminari/_last_page.html.erb +13 -0
  114. data/app/views/kaminari/_next_page.html.erb +13 -0
  115. data/app/views/kaminari/_page.html.erb +12 -0
  116. data/app/views/kaminari/_paginator.html.erb +24 -0
  117. data/app/views/kaminari/_prev_page.html.erb +13 -0
  118. data/app/views/layouts/storytime/application.html.erb +1 -1
  119. data/app/views/layouts/storytime/dashboard.html.erb +22 -6
  120. data/app/views/storytime/application/storytime/_disqus_comment_counts.html.erb +14 -0
  121. data/app/views/storytime/application/storytime/_header.html.erb +3 -4
  122. data/app/views/storytime/application/storytime/_navigation.html.erb +14 -1
  123. data/app/views/storytime/blogs/_tags.html.erb +3 -0
  124. data/app/views/storytime/{posts/index.atom.builder → blogs/show.atom.builder} +1 -1
  125. data/app/views/storytime/{posts/index.html.erb → blogs/show.html.erb} +1 -1
  126. data/app/views/storytime/comments/_discourse.html.erb +18 -0
  127. data/app/views/storytime/comments/_disqus.html.erb +2 -2
  128. data/app/views/storytime/comments/_form.html.erb +2 -2
  129. data/app/views/storytime/dashboard/_navigation.html.erb +109 -41
  130. data/app/views/storytime/dashboard/_settings_tabs.html.erb +32 -0
  131. data/app/views/storytime/dashboard/autosaves/_autosave_info.html.erb +7 -4
  132. data/app/views/storytime/dashboard/blog_posts/_form.html.erb +157 -0
  133. data/app/views/storytime/dashboard/blog_posts/edit.html.erb +55 -0
  134. data/app/views/storytime/dashboard/blog_posts/new.html.erb +31 -0
  135. data/app/views/storytime/dashboard/blogs/_blog.html.erb +3 -0
  136. data/app/views/storytime/dashboard/blogs/_form.html.erb +25 -0
  137. data/app/views/storytime/dashboard/blogs/edit.json.jbuilder +1 -0
  138. data/app/views/storytime/dashboard/blogs/index.json.jbuilder +1 -0
  139. data/app/views/storytime/dashboard/blogs/new.json.jbuilder +1 -0
  140. data/app/views/storytime/dashboard/media/_form.html.erb +3 -3
  141. data/app/views/storytime/dashboard/media/{_gallery.html → _gallery.html.erb} +7 -4
  142. data/app/views/storytime/dashboard/media/_media.html.erb +6 -13
  143. data/app/views/storytime/dashboard/media/_modal.html.erb +3 -3
  144. data/app/views/storytime/dashboard/media/index.html.erb +15 -5
  145. data/app/views/storytime/dashboard/memberships/_form.html.erb +12 -0
  146. data/app/views/storytime/dashboard/memberships/_index.html.erb +39 -0
  147. data/app/views/storytime/dashboard/memberships/_membership.html.erb +12 -0
  148. data/app/views/storytime/dashboard/memberships/index.json.jbuilder +2 -0
  149. data/app/views/storytime/dashboard/memberships/save.json.jbuilder +1 -0
  150. data/app/views/storytime/dashboard/pages/_form.html.erb +88 -0
  151. data/app/views/storytime/dashboard/pages/_index_title.html.erb +1 -0
  152. data/app/views/storytime/dashboard/pages/_new_button.html.erb +1 -0
  153. data/app/views/storytime/dashboard/pages/edit.html.erb +49 -0
  154. data/app/views/storytime/dashboard/pages/new.html.erb +28 -0
  155. data/app/views/storytime/dashboard/posts/_form.html.erb +128 -122
  156. data/app/views/storytime/dashboard/posts/_image_toolbar.html.erb +32 -0
  157. data/app/views/storytime/dashboard/posts/_index_title.html.erb +1 -0
  158. data/app/views/storytime/dashboard/posts/_list.html.erb +23 -24
  159. data/app/views/storytime/dashboard/posts/_new_button.html.erb +10 -0
  160. data/app/views/storytime/dashboard/posts/edit.html.erb +56 -13
  161. data/app/views/storytime/dashboard/posts/index.html.erb +56 -7
  162. data/app/views/storytime/dashboard/posts/new.html.erb +29 -8
  163. data/app/views/storytime/dashboard/roles/_form.html.erb +41 -0
  164. data/app/views/storytime/dashboard/roles/edit.json.jbuilder +1 -0
  165. data/app/views/storytime/dashboard/sites/_form.html.erb +31 -15
  166. data/app/views/storytime/dashboard/sites/new.html.erb +21 -8
  167. data/app/views/storytime/dashboard/sites/site.json.jbuilder +2 -0
  168. data/app/views/storytime/dashboard/snippets/_form.html.erb +26 -12
  169. data/app/views/storytime/dashboard/snippets/_index.html.erb +17 -0
  170. data/app/views/storytime/dashboard/snippets/_snippet.html.erb +12 -0
  171. data/app/views/storytime/dashboard/snippets/edit.json.jbuilder +1 -0
  172. data/app/views/storytime/dashboard/snippets/index.json.jbuilder +4 -0
  173. data/app/views/storytime/dashboard/snippets/new.json.jbuilder +1 -0
  174. data/app/views/storytime/dashboard/subscriptions/_form.html.erb +19 -0
  175. data/app/views/storytime/dashboard/subscriptions/_index.html.erb +19 -0
  176. data/app/views/storytime/dashboard/subscriptions/_subscription.html.erb +9 -10
  177. data/app/views/storytime/dashboard/subscriptions/form.json.jbuilder +1 -0
  178. data/app/views/storytime/dashboard/subscriptions/index.json.jbuilder +1 -0
  179. data/app/views/storytime/dashboard/users/_edit.html.erb +26 -0
  180. data/app/views/storytime/dashboard/users/_new.html.erb +25 -0
  181. data/app/views/storytime/dashboard/users/edit.json.jbuilder +2 -0
  182. data/app/views/storytime/dashboard/users/new.json.jbuilder +2 -0
  183. data/app/views/storytime/dashboard/versions/_version.html.erb +14 -0
  184. data/app/views/storytime/dashboard/versions/_versions_info.html.erb +1 -16
  185. data/app/views/storytime/pages/show.html.erb +1 -1
  186. data/app/views/storytime/posts/_post.html.erb +8 -0
  187. data/app/views/storytime/posts/_tags.html.erb +1 -1
  188. data/app/views/storytime/posts/show.html.erb +1 -1
  189. data/app/views/storytime/sites/_google_analytics_code.html.erb +2 -2
  190. data/app/views/storytime/snippets/_snippet.html.erb +9 -0
  191. data/app/views/storytime/subscription_mailer/new_post_email.html.erb +2 -2
  192. data/app/views/storytime/subscription_mailer/new_post_email.text.erb +2 -2
  193. data/app/views/storytime/subscriptions/_form.html.erb +0 -1
  194. data/app/views/storytime/subscriptions/_modal.html.erb +18 -10
  195. data/bin/rails +12 -0
  196. data/bin/storytime +4 -0
  197. data/circle.yml +3 -0
  198. data/config/initializers/storytime_admin.rb +3 -0
  199. data/config/initializers/url_for_patch.rb +2 -37
  200. data/config/locales/en.yml +33 -13
  201. data/config/routes.rb +47 -19
  202. data/db/migrate/20150128185746_seed_new_actions_and_permissions.rb +9 -0
  203. data/db/migrate/20150206201847_add_site_id_to_storytime_post.rb +7 -0
  204. data/db/migrate/20150206201919_add_site_id_to_storytime_snippet.rb +7 -0
  205. data/db/migrate/20150206201931_add_site_id_to_storytime_tag.rb +7 -0
  206. data/db/migrate/20150206205256_add_notification_fields_to_storytime_post.rb +6 -0
  207. data/db/migrate/20150216211257_add_subdomain_to_storytime_sites.rb +5 -0
  208. data/db/migrate/20150216225045_add_site_to_storytime_media.rb +6 -0
  209. data/db/migrate/20150219210528_remove_root_page_content_from_storytime_sites.rb +12 -0
  210. data/db/migrate/20150220184902_add_blog_id_to_posts.rb +6 -0
  211. data/db/migrate/20150224192138_add_homepage_path_to_storytime_sites.rb +5 -0
  212. data/db/migrate/20150224193151_add_subscription_email_from_to_storytime_sites.rb +5 -0
  213. data/db/migrate/20150224193551_add_layout_to_storytime_sites.rb +5 -0
  214. data/db/migrate/20150224194559_add_disqus_forum_shortname_to_storytime_sites.rb +5 -0
  215. data/db/migrate/20150224212453_remove_homepage_path_from_storytime_sites.rb +5 -0
  216. data/db/migrate/20150225143516_add_site_id_to_storytime_autosaves.rb +6 -0
  217. data/db/migrate/20150225143826_add_site_id_to_storytime_comments.rb +6 -0
  218. data/db/migrate/20150225145119_add_site_id_to_storytime_versions.rb +6 -0
  219. data/db/migrate/20150225145316_add_site_id_to_storytime_taggings.rb +6 -0
  220. data/db/migrate/20150225145608_update_storytime_site_id_columns.rb +11 -0
  221. data/db/migrate/20150225164232_add_site_id_to_storytime_permissions.rb +6 -0
  222. data/db/migrate/20150225212917_create_storytime_memberships.rb +11 -0
  223. data/db/migrate/20150225213535_create_memberships_for_storytime_users.rb +8 -0
  224. data/db/migrate/20150226201739_add_custom_domain_to_storytime_sites.rb +5 -0
  225. data/db/migrate/20150302171500_add_site_id_to_storytime_media.rb +8 -0
  226. data/db/migrate/20150302171722_set_site_layout.rb +8 -0
  227. data/db/migrate/20150302185138_remove_storytime_role_id_from_users.rb +5 -0
  228. data/db/migrate/20150302192525_transfer_posts_to_blogs.rb +8 -0
  229. data/db/migrate/20150302192759_seed_permissions.rb +9 -0
  230. data/db/migrate/20150331162329_add_discourse_name_to_storytime_sites.rb +5 -0
  231. data/db/migrate/20150402161427_remove_subdomain_from_storytime_site.rb +5 -0
  232. data/lib/generators/storytime/install_generator.rb +17 -0
  233. data/lib/generators/storytime/views_generator.rb +21 -9
  234. data/lib/generators/templates/storytime.rb +70 -27
  235. data/lib/storytime/cli/install.rb +274 -0
  236. data/lib/storytime/cli.rb +28 -0
  237. data/lib/storytime/concerns/current_site.rb +10 -0
  238. data/lib/storytime/concerns/has_versions.rb +22 -3
  239. data/lib/storytime/concerns/storytime_user.rb +31 -7
  240. data/lib/storytime/constraints/blog_constraint.rb +11 -0
  241. data/lib/storytime/constraints/blog_homepage_constraint.rb +11 -0
  242. data/lib/storytime/constraints/page_constraint.rb +13 -0
  243. data/lib/storytime/constraints/page_homepage_constraint.rb +11 -0
  244. data/lib/storytime/engine.rb +43 -14
  245. data/lib/storytime/generators/initializer.rb +45 -0
  246. data/lib/storytime/migrators/v1.rb +122 -0
  247. data/lib/storytime/post_notifier.rb +19 -0
  248. data/lib/storytime/post_url_handler.rb +47 -0
  249. data/lib/storytime/storytime_helpers.rb +12 -0
  250. data/lib/storytime/version.rb +1 -1
  251. data/lib/storytime.rb +57 -56
  252. data/screenshots/admin.png +0 -0
  253. data/screenshots/media.png +0 -0
  254. data/screenshots/page-list.png +0 -0
  255. data/screenshots/post-editor.png +0 -0
  256. data/screenshots/site-settings.png +0 -0
  257. data/screenshots/text-snippets.png +0 -0
  258. data/screenshots/user-management.png +0 -0
  259. data/spec/controllers/dashboard_controller_spec.rb +3 -1
  260. data/{app/assets/stylesheets/storytime/subscriptions.css.scss → spec/dummy/app/assets/images/.keep} +0 -0
  261. data/spec/dummy/app/assets/javascripts/application.js +3 -0
  262. data/spec/dummy/app/controllers/application_controller.rb +5 -1
  263. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  264. data/spec/dummy/app/controllers/storytime_admin/widgets_controller.rb +5 -0
  265. data/spec/dummy/app/mailers/.keep +0 -0
  266. data/spec/dummy/app/models/.keep +0 -0
  267. data/spec/dummy/app/models/concerns/.keep +0 -0
  268. data/spec/dummy/app/models/user.rb +5 -1
  269. data/spec/dummy/app/models/video_post.rb +2 -0
  270. data/spec/dummy/app/models/widget.rb +3 -0
  271. data/spec/dummy/app/views/layouts/application.html.erb +1 -1
  272. data/spec/dummy/app/views/storytime/dashboard/posts/_video_post_fields.html.erb +1 -0
  273. data/spec/dummy/app/views/widgets/storytime/dashboard/admin/_headers.html.erb +1 -0
  274. data/spec/dummy/app/views/widgets/storytime/dashboard/admin/_row.html.erb +1 -0
  275. data/spec/dummy/config/database.yml +9 -5
  276. data/spec/dummy/config/environments/test.rb +1 -0
  277. data/spec/dummy/config/initializers/devise.rb +1 -1
  278. data/spec/dummy/config/initializers/session_store.rb +1 -1
  279. data/spec/dummy/config/initializers/storytime.rb +7 -14
  280. data/spec/dummy/db/development.sqlite3 +0 -0
  281. data/spec/dummy/db/migrate/20150127172846_create_widgets.rb +9 -0
  282. data/spec/dummy/db/migrate/20150206203824_add_video_url_to_storytime_posts.rb +5 -0
  283. data/spec/dummy/db/schema.rb +76 -21
  284. data/spec/dummy/db/test.sqlite3 +0 -0
  285. data/spec/dummy/lib/assets/.keep +0 -0
  286. data/spec/dummy/log/.keep +0 -0
  287. data/spec/factories/comment_factories.rb +1 -0
  288. data/spec/factories/membership_factories.rb +7 -0
  289. data/spec/factories/site_factories.rb +3 -2
  290. data/spec/factories/user_factories.rb +3 -3
  291. data/spec/factories/widget_factories.rb +5 -0
  292. data/spec/features/blogs_spec.rb +28 -0
  293. data/spec/features/comments_spec.rb +8 -9
  294. data/spec/features/dashboard/media_spec.rb +14 -30
  295. data/spec/features/dashboard/memberships_spec.rb +58 -0
  296. data/spec/features/dashboard/pages_spec.rb +67 -44
  297. data/spec/features/dashboard/posts_spec.rb +84 -62
  298. data/spec/features/dashboard/sites_spec.rb +28 -23
  299. data/spec/features/dashboard/snippets_spec.rb +44 -44
  300. data/spec/features/dashboard/subscription_spec.rb +36 -28
  301. data/spec/features/dashboard/users_spec.rb +48 -29
  302. data/spec/features/pages_spec.rb +2 -2
  303. data/spec/features/posts_spec.rb +2 -20
  304. data/spec/features/subscription_spec.rb +4 -4
  305. data/spec/models/post_spec.rb +26 -17
  306. data/spec/policies/comment_policy_spec.rb +22 -6
  307. data/spec/policies/post_policy_spec.rb +21 -3
  308. data/spec/requests/routings_spec.rb +27 -17
  309. data/spec/spec_helper.rb +12 -1
  310. data/spec/support/database_cleaner.rb +5 -5
  311. data/spec/support/domains.rb +18 -0
  312. data/spec/support/feature_macros.rb +18 -9
  313. data/storytime.gemspec +59 -0
  314. data/vendor/assets/javascripts/.DS_Store +0 -0
  315. data/vendor/assets/javascripts/codemirror/modes/css.js +717 -0
  316. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +120 -0
  317. data/vendor/assets/javascripts/codemirror/modes/javascript.js +686 -0
  318. data/vendor/assets/javascripts/codemirror/modes/liquid.js +40 -0
  319. data/vendor/assets/javascripts/codemirror/modes/overlay.js +85 -0
  320. data/vendor/assets/javascripts/codemirror/{xml.js → modes/xml.js} +2 -2
  321. data/vendor/assets/javascripts/medium-editor.min.js +2450 -0
  322. data/vendor/assets/javascripts/phantom_js_bind_polyfill.js +24 -0
  323. data/vendor/assets/javascripts/tidy.js +30 -0
  324. data/vendor/assets/stylesheets/.DS_Store +0 -0
  325. data/vendor/assets/stylesheets/chosen-bootstrap-3.css +148 -0
  326. data/vendor/assets/stylesheets/{chosen.css.scss → chosen.scss} +1 -1
  327. data/vendor/assets/stylesheets/disable-transitions-for-test-env.css +7 -0
  328. data/vendor/assets/stylesheets/medium-editor-default.min.css +1 -0
  329. data/vendor/assets/stylesheets/medium-editor.min.css +1 -0
  330. metadata +297 -47
  331. data/app/assets/stylesheets/storytime/admin.css.scss +0 -121
  332. data/app/assets/stylesheets/storytime/application.css.scss +0 -22
  333. data/app/assets/stylesheets/storytime/layout.css.scss +0 -17
  334. data/app/assets/stylesheets/storytime/media.css.scss +0 -68
  335. data/app/assets/stylesheets/storytime/pagination.css.scss +0 -4
  336. data/app/assets/stylesheets/storytime/posts.css.scss +0 -30
  337. data/app/assets/stylesheets/storytime/versions.css.scss +0 -21
  338. data/app/helpers/storytime/dashboard/posts_helper.rb +0 -21
  339. data/app/views/storytime/blog_posts/_blog_post.html.erb +0 -8
  340. data/app/views/storytime/dashboard/posts/_basic_new_post_button.html.erb +0 -3
  341. data/app/views/storytime/dashboard/posts/_new_post_dropdown_button.html.erb +0 -10
  342. data/app/views/storytime/dashboard/sites/edit.html.erb +0 -25
  343. data/app/views/storytime/dashboard/snippets/_list.html.erb +0 -21
  344. data/app/views/storytime/dashboard/snippets/edit.html.erb +0 -13
  345. data/app/views/storytime/dashboard/snippets/index.html.erb +0 -13
  346. data/app/views/storytime/dashboard/snippets/new.html.erb +0 -12
  347. data/app/views/storytime/dashboard/subscriptions/edit.html.erb +0 -10
  348. data/app/views/storytime/dashboard/subscriptions/index.html.erb +0 -19
  349. data/app/views/storytime/dashboard/subscriptions/new.html.erb +0 -9
  350. data/app/views/storytime/dashboard/users/_user.html.erb +0 -11
  351. data/app/views/storytime/dashboard/users/edit.html.erb +0 -10
  352. data/app/views/storytime/dashboard/users/index.html.erb +0 -22
  353. data/app/views/storytime/dashboard/users/new.html.erb +0 -11
  354. data/spec/lib/storytime_spec.rb +0 -23
  355. data/vendor/assets/javascripts/codemirror/codemirror.js +0 -7831
  356. data/vendor/assets/javascripts/summernote.js +0 -5338
  357. data/vendor/assets/stylesheets/codemirror/codemirror.css +0 -309
  358. data/vendor/assets/stylesheets/codemirror/monokai.css +0 -31
  359. data/vendor/assets/stylesheets/summernote.css +0 -1
@@ -14,17 +14,25 @@
14
14
  //= require jquery
15
15
  //= require jquery_ujs
16
16
  //= require bootstrap
17
+ //= require leather
17
18
  //= require jquery-ui/core
18
19
  //= require jquery-ui/datepicker
19
20
  //= require jquery-ui/position
20
21
  //= require jquery-ui/widget
22
+ //= require jquery-ui/resizable
21
23
  //= require jquery.ui.timepicker
22
24
  //= require jquery.iframe-transport.js
23
25
  //= require jquery.fileupload.js
24
- //= require codemirror/codemirror
25
- //= require codemirror/xml
26
+ //= require codemirror
27
+ //= require codemirror/modes/xml
28
+ //= require codemirror/modes/htmlmixed
29
+ //= require codemirror/modes/overlay
30
+ //= require codemirror/addons/fold/xml-fold
31
+ //= require codemirror/addons/edit/closetag
32
+ //= require codemirror/addons/edit/closebrackets
33
+ //= require tidy
26
34
  //= require chosen.jquery
27
- //= require summernote
35
+ //= require medium-editor.min
28
36
  //= require_tree .
29
37
 
30
38
  window.Storytime || (window.Storytime = {})
@@ -1,16 +1,15 @@
1
- $ ()->
2
- controller = $("body").data("controller")
3
- action = $("body").data("action")
4
-
1
+ initJS = (controller, action) ->
5
2
  controllerObj = Storytime.Utilities.controllerFromString(controller)
6
-
7
3
  if controllerObj?
8
4
  instance = new controllerObj()
9
5
  instance["init"]() if typeof(instance["init"]) == "function"
10
6
  instance["init#{action}"]() if typeof(instance["init#{action}"]) == "function"
11
7
  Storytime.instance = instance
12
8
 
13
- $(".flash").delay(2000).fadeOut()
9
+ $ ()->
10
+ initJS($("body").data("controller"), $("body").data("action"))
11
+
12
+ $(".flash").delay(4000).fadeOut() unless window.Storytime.test_env
14
13
 
15
14
  $(".chosen").chosen()
16
15
 
@@ -21,4 +20,43 @@ $ ()->
21
20
  ).on('ajax:error', '.btn-delete-resource', (e, data, d1, d2)->
22
21
  $(@).attr("disabled", false)
23
22
  alert("There was an error deleting your #{$(@).data('resource-type')}")
23
+ )
24
+
25
+ $(".table-row-link").click ->
26
+ url = $(this).data('url')
27
+ document.location.href = url
28
+
29
+ $(document).on "click", ".storytime-menu-toggle", (e) ->
30
+ e.preventDefault()
31
+ $("#storytime-main-menu").toggle()
32
+ $("#storytime-sites-menu").toggle()
33
+
34
+ $(document).on('ajax:success', '.storytime-modal-trigger, #storytime-modal .pagination a', (e, data, status, xhr)->
35
+ $("#storytime-modal .modal-content").html(data.html)
36
+ $("#storytime-modal").removeClass("modal-wide")
37
+ initJS($("#storytime-modal-controller").val(), $("#storytime-modal-action").val())
38
+ $("#storytime-modal").modal("show")
39
+ )
40
+
41
+ $(document).on('ajax:success', '.storytime-modal-form', (e, data, status, xhr)->
42
+ unless $(e.target).hasClass("storytime-modal-trigger")
43
+ if $(this).data("redirect") == "index"
44
+ $("#storytime-modal").removeClass("modal-wide")
45
+ $("#storytime-modal .modal-content").html(data.html)
46
+ if $("#storytime-modal-controller").length && $("#storytime-modal-action").length
47
+ initJS($("#storytime-modal-controller").val(), $("#storytime-modal-action").val())
48
+
49
+ $('body').append("<div class='flash js-flash'><div class='flash-success'>Your changes were saved successfully</div></div>")
50
+
51
+ $('.chosen').chosen
52
+ width: '100%'
53
+
54
+ $(".js-flash").show().delay(4000).fadeOut '300', ->
55
+ $(this).remove()
56
+
57
+ ).on("ajax:error", ".storytime-modal-form", (e, xhr, status, error)->
58
+ unless $(e.target).hasClass("storytime-modal-trigger")
59
+ data = JSON.parse(xhr.responseText)
60
+ $("#storytime-modal .modal-content").html(data.html)
61
+ initJS($("#storytime-modal-controller").val(), $("#storytime-modal-action").val())
24
62
  )
@@ -0,0 +1,16 @@
1
+ class Storytime.Dashboard.BlogPosts
2
+ initNew: ()->
3
+ @editor = new Storytime.Dashboard.Posts()
4
+ @editor.initNew()
5
+
6
+ initEdit: ()->
7
+ @editor = new Storytime.Dashboard.Posts()
8
+ @editor.initEdit()
9
+
10
+ initCreate: ()->
11
+ @editor = new Storytime.Dashboard.Posts()
12
+ @editor.initCreate()
13
+
14
+ initUpdate: ()->
15
+ @editor = new Storytime.Dashboard.Posts()
16
+ @editor.initUpdate()
@@ -0,0 +1,18 @@
1
+ class Storytime.Dashboard.Blogs
2
+ initNew: ()->
3
+ $(document).on('ajax:success', '.new-blog-form', (e, data, status, xhr) ->
4
+ unless $(e.target).hasClass("storytime-modal-trigger")
5
+ $("#blogs").html(data.html)
6
+ $("#storytime-modal").modal("hide")
7
+ )
8
+
9
+ initEdit: ()->
10
+ $(document).on('ajax:success', '.edit-blog-form', (e, data, status, xhr) ->
11
+ unless $(e.target).hasClass("storytime-modal-trigger")
12
+ $("#blogs").html(data.html)
13
+ $("#storytime-modal").modal("hide")
14
+ )
15
+
16
+ initCreate: ()->
17
+
18
+ initUpdate: ()->
@@ -0,0 +1,26 @@
1
+ class Storytime.Dashboard.CharacterCounter
2
+ init: ()->
3
+ self = @
4
+ $(".character-limit").each () ->
5
+ display = $(this).find(".character-limit-display")
6
+ limit = display.data("limit")
7
+ input = $(this).find(".character-limit-input")
8
+ contenteditable = $(this).find(".character-limit-contenteditable")
9
+ self.setText(display, limit, input)
10
+
11
+ if contenteditable.length > 0
12
+ self.bind(contenteditable, input, display, limit)
13
+ else
14
+ self.bind(input, input, display, limit)
15
+
16
+ setText: (display, limit, input) ->
17
+ display.html limit - input.val().length
18
+
19
+ bind: (field, input, display, limit) ->
20
+ field.keypress((e) ->
21
+ e.preventDefault() if (e.which is 32 or e.which > 0x20) and (input.val().length > limit - 1)
22
+ return
23
+ ).keyup(->
24
+ display.html limit - input.val().length
25
+ return
26
+ )
@@ -0,0 +1,15 @@
1
+ class Storytime.Dashboard.Contenteditable
2
+ init: () ->
3
+ inst = @
4
+ $(".contenteditable").each ->
5
+ contenteditable = $(this)
6
+ inst.bindToInput(contenteditable)
7
+
8
+ $(".contenteditable")[0].focus()
9
+
10
+ bindToInput: (contenteditable) ->
11
+ input = $(contenteditable.data("input"))
12
+
13
+ contenteditable.keyup ->
14
+ text = contenteditable.text()
15
+ input.val(text)
@@ -0,0 +1,16 @@
1
+ class Storytime.Dashboard.CustomPosts
2
+ initNew: ()->
3
+ @editor = new Storytime.Dashboard.Posts()
4
+ @editor.initNew()
5
+
6
+ initEdit: ()->
7
+ @editor = new Storytime.Dashboard.Posts()
8
+ @editor.initEdit()
9
+
10
+ initCreate: ()->
11
+ @editor = new Storytime.Dashboard.Posts()
12
+ @editor.initCreate()
13
+
14
+ initUpdate: ()->
15
+ @editor = new Storytime.Dashboard.Posts()
16
+ @editor.initUpdate()
@@ -2,60 +2,38 @@ class Storytime.Dashboard.Editor
2
2
  init: () ->
3
3
  self = @
4
4
 
5
- mediaInstance = @initMedia()
6
- @initWysiwyg()
7
-
8
- # Title character limit
9
- title_character_limit = $("#title_character_limit").data("limit")
10
- $("#title_character_limit").html title_character_limit - $("#post_title").val().length
11
-
12
- $("#post_title").keypress((e) ->
13
- e.preventDefault() if (e.which is 32 or e.which > 0x20) and ($("#post_title").val().length > title_character_limit - 1)
14
- return
15
- ).keyup(->
16
- $("#title_character_limit").html title_character_limit - $("#post_title").val().length
17
- return
18
- )
19
-
20
- # Excerpt character limit
21
- excerpt_character_limit = $("#excerpt_character_limit").data("limit")
22
- $("#excerpt_character_limit").html excerpt_character_limit - $("#post_excerpt").val().length
5
+ (new Storytime.Dashboard.Contenteditable()).init()
6
+ (new Storytime.Dashboard.CharacterCounter()).init()
7
+ @initChosen()
8
+ (new Storytime.Dashboard.Tags()).init()
23
9
 
24
- $("#post_excerpt").keypress((e) ->
25
- e.preventDefault() if (e.which is 32 or e.which > 0x20) and ($("#post_excerpt").val().length > excerpt_character_limit - 1)
26
- return
27
- ).keyup(->
28
- $("#excerpt_character_limit").html excerpt_character_limit - $("#post_excerpt").val().length
29
- return
30
- )
31
-
32
- if $(".edit_post").length
33
- form = $(".edit_post").last()
10
+ mediaInstance = @initMedia()
11
+ (new Storytime.Dashboard.Wysiwyg()).init()
12
+
13
+ form = $(".post-form")
14
+
15
+ $("#medium-editor-post").keyup ->
16
+ form.data "unsaved-changes", true
34
17
 
18
+ if $(".edit-post-form").length
35
19
  $("#preview_post").click(->
36
20
  self.autosavePostForm()
37
21
  return
38
22
  )
39
23
 
24
+ self.setAutosaveInterval(10000) unless window.Storytime.test_env
25
+
40
26
  if $("#main").data("preview")
41
27
  window.open $("#preview_post").attr("href")
42
28
  else
43
- form = $(".new_post").last()
44
-
45
29
  $("#preview_post").click(->
46
30
  form.data "unsaved-changes", false
47
31
 
48
- $("<input name='preview' type='hidden' value='true'>").insertAfter($(".new_post").children().first())
49
- $(".new_post").submit()
32
+ $("<input name='preview' type='hidden' value='true'>").insertAfter(form.children().first())
33
+ form.submit()
50
34
  return
51
35
  )
52
36
 
53
- # Setup Chosen select field
54
- $(".chosen-select").chosen
55
- no_results_text: "No results were found... Press 'Enter' to create a new tag named "
56
- placeholder_text_multiple: "Select or enter one or more Tags"
57
- search_contains: true
58
-
59
37
  # Setup datepicker
60
38
  $(".datepicker").datepicker
61
39
  dateFormat: "MM d, yy"
@@ -69,20 +47,8 @@ class Storytime.Dashboard.Editor
69
47
  mediaInstance.initUpload()
70
48
  return
71
49
 
72
- # Add new tags
73
- $("#post_tag_ids").next("div").find(".search-field").children("input").on 'keyup', (e) ->
74
- if e.which is 13 and $("#post_tag_ids").next("div").find(".search-field").children("input").val().length > 0
75
- searched_tag = $("#post_tag_ids").next("div").find(".search-field").children("input").val()
76
- $("#post_tag_ids").append('<option value="nv__' + searched_tag + '">' + searched_tag + '</option>')
77
-
78
- selected_tags = $("#post_tag_ids").val() || []
79
- selected_tags.push "nv__#{searched_tag}"
80
-
81
- $("#post_tag_ids").val selected_tags
82
- $("#post_tag_ids").trigger 'chosen:updated'
83
- return
84
-
85
50
  # Set published field on Publish button click
51
+ # TODO: This should not rely on javascript. Should make publish button a submit button and look for the button name in the controller to set published = true
86
52
  $(".publish").on 'click', () ->
87
53
  $("#post_published").val(1)
88
54
  form.data "unsaved-changes", false
@@ -98,6 +64,7 @@ class Storytime.Dashboard.Editor
98
64
  mediaInstance.initInsert()
99
65
  mediaInstance.initFeaturedImageSelector()
100
66
  mediaInstance.initSecondaryImageSelector()
67
+ mediaInstance.initImageSelector()
101
68
 
102
69
  $(document).on 'shown.bs.modal', ()->
103
70
  mediaInstance.initUpload()
@@ -105,108 +72,56 @@ class Storytime.Dashboard.Editor
105
72
 
106
73
  mediaInstance
107
74
 
108
- initWysiwyg: () ->
109
- self = @
110
-
111
- # Summernote config and setup
112
- $(".summernote").summernote
113
- codemirror:
114
- htmlMode: true
115
- lineNumbers: true
116
- lineWrapping: true
117
- mode: 'text/html'
118
- theme: 'monokai'
119
- height: 200
120
- minHeight: null
121
- maxHeight: null
122
- toolbar: [
123
- ['style', ['style']]
124
- ['font', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']]
125
- # ['fontname', ['fontname']]
126
- # ['fontsize', ['fontsize']]
127
- ['color', ['color']]
128
- ['para', ['ul', 'ol', 'paragraph']]
129
- # ['height', ['height']]
130
- ['table', ['table']]
131
- ['insert', ['link', 'picture', 'video', 'hr']]
132
- ['view', ['fullscreen', 'codeview']]
133
- ['editing', ['undo', 'redo']]
134
- ['help', ['help']]
135
- ]
136
- onblur: ->
137
- $(".summernote").data("range", document.getSelection().getRangeAt(0))
138
- return
139
- onfocus: ->
140
- self.updateLater(10000) if $(".edit_post").length
141
- return
142
- onkeyup: ->
143
- form = if $(".edit_post").length then $(".edit_post").last() else $(".new_post").last()
144
- form.data "unsaved-changes", true
145
- return
146
- onImageUpload: (files, editor, $editable) ->
147
- $("#media_file").fileupload('send', {files: files})
148
- .success((result, textStatus, jqXHR) ->
149
- editor.insertImage($editable, result.file_url)
150
- return
151
- )
152
- return
153
-
154
- # Show Gallery when using Summernote insertPicture modal
155
- $(".note-image-dialog").on 'shown.bs.modal', () ->
156
- if $("#media_gallery").length > 0
157
- $(".note-image-dialog").find(".row-fluid").append(
158
- "<div id='gallery_copy'>
159
- <h5>Gallery</h5>
160
- <div id='media_gallery'>" +
161
- $("#media_gallery").html() +
162
- "</div>
163
- </div>")
164
- return
165
-
166
- # Remove Gallery when closing out Summernote insertPicture modal
167
- $(".note-image-dialog").on 'hide.bs.modal', () ->
168
- $("#gallery_copy").remove()
169
- return
170
-
75
+ initChosen: () ->
76
+ $(".chosen-select").chosen
77
+ no_results_text: "No results were found... Press 'Enter' to create a new tag named "
78
+ placeholder_text_multiple: "Select or enter one or more Tags"
79
+ search_contains: true
80
+ width: '100%'
81
+
171
82
  autosavePostForm: () ->
172
83
  self = @
173
84
  post_id = $("#main").data("post-id")
174
- dashboard_namespace = $("#main").data("dashboard-namespace")
85
+ postType = $(".post-form").data("post-type")
86
+
87
+ autosaveUrl = $(".post-form").data("autosave-url")
175
88
 
176
89
  data = []
177
- data.push {name: "post[draft_content]", value: $(".summernote").code()}
90
+ data.push {name: "#{postType}[draft_content]", value: $(".draft-content-input").val()}
178
91
 
179
- form = if $(".edit_post").length then $(".edit_post").last() else $(".new_post").last()
92
+ form = $(".post-form")
180
93
  form.data "unsaved-changes", false
181
94
 
182
- $.ajax(
95
+ deferred = $.ajax(
183
96
  type: "POST"
184
- url: "#{dashboard_namespace}/posts/#{post_id}/autosaves"
97
+ url: autosaveUrl
185
98
  data: data
186
99
  )
187
100
 
188
- updateLater: (timer) ->
189
- self = @
190
- timer = 120000 unless timer?
101
+ deferred.done ()->
102
+ time_now = new Date().toLocaleTimeString()
103
+ $("#draft_last_saved_at").html "Draft saved at #{time_now}"
104
+ return
191
105
 
192
- form = if $(".edit_post").length then $(".edit_post").last() else $(".new_post").last()
106
+ return deferred
193
107
 
194
- timeoutId = window.setTimeout((->
195
- if form.data("unsaved-changes") is true
196
- self.autosavePostForm().done(->
197
- self.updateLater timer
108
+ setAutosaveInterval: (timer) ->
109
+ self = @
110
+ timer = 120000 unless timer?
198
111
 
199
- time_now = new Date().toLocaleTimeString()
200
- $("#draft_last_saved_at").html "Draft saved at #{time_now}"
201
- return
202
- ).fail(->
203
- console.log "Something went wrong while trying to autosave..."
112
+ form = $(".post-form")
113
+
114
+ window.setTimeout((->
115
+
116
+ if form.data("unsaved-changes") is true
117
+ self.autosavePostForm().always(->
118
+ self.setAutosaveInterval timer
204
119
  return
205
120
  )
206
121
 
207
122
  return
208
123
  else
209
- self.updateLater timer
124
+ self.setAutosaveInterval timer
210
125
  return
211
126
  ), timer)
212
127
  return
@@ -223,4 +138,5 @@ class Storytime.Dashboard.Editor
223
138
  )
224
139
 
225
140
  $(window).on "beforeunload", ->
226
- return "You haven't saved your changes." if form.data "unsaved-changes"
141
+ if form.data("unsaved-changes") && !window.Storytime.test_env
142
+ return "You haven't saved your changes."
@@ -14,13 +14,14 @@ class Storytime.Dashboard.Media
14
14
  initUpload: ()->
15
15
  unless @uploadInitialized
16
16
  $('#media_file').fileupload({
17
- dataType: 'json',
18
17
  done: (e, data)->
19
- $(".media_container").prepend(data.result.html)
18
+ $("#media_gallery_container").html(data.result)
19
+ $("#progress").hide()
20
20
  return
21
21
 
22
22
  progressall: (e, data)->
23
23
  progress = parseInt(data.loaded / data.total * 100, 10)
24
+ $("#progress").show()
24
25
  $('#progress .progress-bar').css('width', progress + '%')
25
26
  return
26
27
 
@@ -43,8 +44,7 @@ class Storytime.Dashboard.Media
43
44
  else
44
45
  $("#featured_media_container").html("<img id='featured_media_image' src='#{$(@).data("thumb-url")}' />")
45
46
 
46
- featured_media.parent().parent().find(".select_featured_image").hide()
47
- featured_media.parent().parent().find(".remove_featured_image").show()
47
+ featured_media.parent().parent().addClass("has-image")
48
48
 
49
49
  $("#insertMediaModal").modal("hide")
50
50
  return
@@ -57,27 +57,24 @@ class Storytime.Dashboard.Media
57
57
  else
58
58
  $("#secondary_media_container").html("<img id='secondary_media_image' src='#{$(@).data("thumb-url")}' />")
59
59
 
60
- secondary_media.parent().parent().find(".select_featured_image").hide()
61
- secondary_media.parent().parent().find(".remove_featured_image").show()
60
+ secondary_media.parent().parent().addClass("has-image")
62
61
 
63
62
  $("#insertMediaModal").modal("hide")
64
63
  return
65
- else if self.selectingSecondary
66
- $("#secondary_media_id").val $(@).data("media-id")
67
- if $("#secondary_media_image").length > 0
68
- $("#secondary_media_image").attr("src", $(@).data("thumb-url"))
64
+ else
65
+ image_tag = "<img src='#{$(@).data("image-url")}' class='img-responsive' />"
66
+ if self.elementContainsSelection($("#medium-editor-post")[0])
67
+ self.pasteHtmlAtCaret(image_tag, false)
69
68
  else
70
- $("#secondary_media_container").html("<img id='secondary_media_image' src='#{$(@).data("thumb-url")}' />")
71
-
69
+ $("#medium-editor-post").append(image_tag)
70
+
71
+ input = $($("#medium-editor-post").data("input"))
72
+ html = $("#medium-editor-post").html()
73
+ input.val(html)
74
+ codemirror = input.siblings(".CodeMirror")[0].CodeMirror
75
+ codemirror.setValue(html)
72
76
  $("#insertMediaModal").modal("hide")
73
77
  return
74
- else
75
- image_tag = "<img src='#{$(@).data("image-url")}' />"
76
- node = $(".summernote").data("range").createContextualFragment(image_tag)
77
-
78
- $(".summernote").data("range").insertNode(node)
79
- $(".note-image-dialog").modal("hide")
80
- return
81
78
 
82
79
  $(document).on "click", "button.remove_featured_image", (e) ->
83
80
  e.preventDefault()
@@ -85,11 +82,17 @@ class Storytime.Dashboard.Media
85
82
  $(this).parent().find("input").val ""
86
83
  $(this).parent().find(".image_container").html ""
87
84
 
88
- $(this).parent().find(".select_featured_image").show()
89
- $(this).parent().find(".remove_featured_image").hide()
85
+ $(this).parent().removeClass("has-image")
90
86
  return
91
87
  return
92
88
 
89
+ initImageSelector: () ->
90
+ self = @
91
+ $(document).on "click", ".insert-media-button", (e) ->
92
+ e.preventDefault()
93
+ $("#insertMediaModal").modal("show")
94
+ return
95
+
93
96
  initFeaturedImageSelector: ()->
94
97
  self = @
95
98
  $(document).on "click", "#featured_media_button", (e)->
@@ -122,4 +125,70 @@ class Storytime.Dashboard.Media
122
125
  self.selectingSecondary = false
123
126
  return
124
127
 
125
- return
128
+ return
129
+
130
+ pasteHtmlAtCaret: (html, selectPastedContent) ->
131
+ self = @
132
+ sel = undefined
133
+ range = undefined
134
+ if window.getSelection
135
+ # IE9 and non-IE
136
+ sel = window.getSelection()
137
+ if sel.getRangeAt and sel.rangeCount
138
+ range = sel.getRangeAt(0)
139
+ range.deleteContents()
140
+ # Range.createContextualFragment() would be useful here but is
141
+ # only relatively recently standardized and is not supported in
142
+ # some browsers (IE9, for one)
143
+ el = document.createElement('div')
144
+ el.innerHTML = html
145
+ frag = document.createDocumentFragment()
146
+ node = undefined
147
+ lastNode = undefined
148
+ while node = el.firstChild
149
+ lastNode = frag.appendChild(node)
150
+ firstNode = frag.firstChild
151
+ range.insertNode frag
152
+ # Preserve the selection
153
+ if lastNode
154
+ range = range.cloneRange()
155
+ range.setStartAfter lastNode
156
+ if selectPastedContent
157
+ range.setStartBefore firstNode
158
+ else
159
+ range.collapse true
160
+ sel.removeAllRanges()
161
+ sel.addRange range
162
+ else if (sel = document.selection) and sel.type != 'Control'
163
+ # IE < 9
164
+ originalRange = sel.createRange()
165
+ originalRange.collapse true
166
+ sel.createRange().pasteHTML html
167
+ if selectPastedContent
168
+ range = sel.createRange()
169
+ range.setEndPoint 'StartToStart', originalRange
170
+ range.select()
171
+ return
172
+
173
+ isOrContains: (node, container) ->
174
+ while node
175
+ if node == container
176
+ return true
177
+ node = node.parentNode
178
+ false
179
+
180
+ elementContainsSelection: (el) ->
181
+ self = @
182
+ sel = undefined
183
+ if window.getSelection
184
+ sel = window.getSelection()
185
+ if sel.rangeCount > 0
186
+ i = 0
187
+ while i < sel.rangeCount
188
+ if !self.isOrContains(sel.getRangeAt(i).commonAncestorContainer, el)
189
+ return false
190
+ ++i
191
+ return true
192
+ else if (sel = document.selection) and sel.type != 'Control'
193
+ return self.isOrContains(sel.createRange().parentElement(), el)
194
+ false
@@ -0,0 +1,16 @@
1
+ class Storytime.Dashboard.Pages
2
+ initNew: ()->
3
+ @editor = new Storytime.Dashboard.Posts()
4
+ @editor.initNew()
5
+
6
+ initEdit: ()->
7
+ @editor = new Storytime.Dashboard.Posts()
8
+ @editor.initEdit()
9
+
10
+ initCreate: ()->
11
+ @editor = new Storytime.Dashboard.Posts()
12
+ @editor.initCreate()
13
+
14
+ initUpdate: ()->
15
+ @editor = new Storytime.Dashboard.Posts()
16
+ @editor.initUpdate()
@@ -2,15 +2,42 @@ class Storytime.Dashboard.Posts
2
2
  initNew: ()->
3
3
  @editor = new Storytime.Dashboard.Editor()
4
4
  @editor.init()
5
+ @initCollapse()
5
6
 
6
7
  initEdit: ()->
7
8
  @editor = new Storytime.Dashboard.Editor()
8
9
  @editor.init()
10
+ @initCollapse()
9
11
 
10
12
  initCreate: ()->
11
13
  @editor = new Storytime.Dashboard.Editor()
12
14
  @editor.init()
15
+ @initCollapse()
13
16
 
14
17
  initUpdate: ()->
15
18
  @editor = new Storytime.Dashboard.Editor()
16
- @editor.init()
19
+ @editor.init()
20
+ @initCollapse()
21
+
22
+ initCollapse: ()->
23
+ $('body').on 'keydown', (e) ->
24
+ if e.which == 27
25
+ $(".post-action-panel.in").collapse("hide")
26
+
27
+ $(".post-action-panel").on "show.bs.collapse", ->
28
+ $(".post-action-panel").removeClass "in"
29
+ $(".scroll-panel-header").fadeOut
30
+ duration: 'fast'
31
+ easing: 'swing'
32
+ $(".scroll-panel-body").scrollTop(0)
33
+ $(".scroll-panel-body").animate({top: "0"}, 'fast', 'swing')
34
+
35
+ $(".post-action-panel").on "shown.bs.collapse", ->
36
+ $(".chosen-select").trigger("chosen:updated")
37
+
38
+ $(".post-action-panel").on "hide.bs.collapse", ->
39
+ top = $(".scroll-panel-body").data("top")
40
+ $(".scroll-panel-header").fadeIn
41
+ duration: 'fast'
42
+ easing: 'swing'
43
+ $(".scroll-panel-body").animate({top: top}, 'fast', 'swing')