proclaim 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (265) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +6 -0
  3. data/Gemfile +14 -0
  4. data/LICENSE +674 -0
  5. data/README.md +137 -0
  6. data/Rakefile +65 -0
  7. data/VERSION +1 -0
  8. data/app/assets/images/ajax_loader.gif +0 -0
  9. data/app/assets/javascripts/proclaim.js +18 -0
  10. data/app/assets/javascripts/proclaim/comments_handler.js.coffee +192 -0
  11. data/app/assets/javascripts/proclaim/editor.js.coffee +50 -0
  12. data/app/assets/javascripts/proclaim/images.js.coffee +3 -0
  13. data/app/assets/javascripts/proclaim/subscriptions.js.coffee +3 -0
  14. data/app/assets/stylesheets/proclaim.css.scss +28 -0
  15. data/app/assets/stylesheets/proclaim/comments.css.scss +14 -0
  16. data/app/assets/stylesheets/proclaim/images.scss +3 -0
  17. data/app/assets/stylesheets/proclaim/posts.css.scss +77 -0
  18. data/app/assets/stylesheets/proclaim/subscriptions.css.scss +3 -0
  19. data/app/controllers/proclaim/application_controller.rb +44 -0
  20. data/app/controllers/proclaim/comments_controller.rb +128 -0
  21. data/app/controllers/proclaim/images_controller.rb +108 -0
  22. data/app/controllers/proclaim/posts_controller.rb +131 -0
  23. data/app/controllers/proclaim/subscriptions_controller.rb +67 -0
  24. data/app/helpers/proclaim/application_helper.rb +34 -0
  25. data/app/helpers/proclaim/comments_helper.rb +4 -0
  26. data/app/helpers/proclaim/images_helper.rb +4 -0
  27. data/app/helpers/proclaim/posts_helper.rb +4 -0
  28. data/app/helpers/proclaim/subscriptions_helper.rb +4 -0
  29. data/app/mailers/proclaim/subscription_mailer.rb +43 -0
  30. data/app/models/proclaim/comment.rb +35 -0
  31. data/app/models/proclaim/image.rb +19 -0
  32. data/app/models/proclaim/post.rb +133 -0
  33. data/app/models/proclaim/subscription.rb +63 -0
  34. data/app/policies/application_policy.rb +53 -0
  35. data/app/policies/proclaim/comment_policy.rb +27 -0
  36. data/app/policies/proclaim/image_policy.rb +29 -0
  37. data/app/policies/proclaim/post_policy.rb +38 -0
  38. data/app/policies/proclaim/subscription_policy.rb +32 -0
  39. data/app/uploaders/proclaim/image_uploader.rb +82 -0
  40. data/app/views/layouts/proclaim/subscription_mailer.html.erb +133 -0
  41. data/app/views/proclaim/comments/_comment.html.erb +33 -0
  42. data/app/views/proclaim/comments/_form.html.erb +51 -0
  43. data/app/views/proclaim/posts/_form.html.erb +67 -0
  44. data/app/views/proclaim/posts/edit.html.erb +3 -0
  45. data/app/views/proclaim/posts/index.html.erb +30 -0
  46. data/app/views/proclaim/posts/new.html.erb +3 -0
  47. data/app/views/proclaim/posts/show.html.erb +46 -0
  48. data/app/views/proclaim/subscription_mailer/new_comment_notification_email.html.erb +11 -0
  49. data/app/views/proclaim/subscription_mailer/new_post_notification_email.html.erb +15 -0
  50. data/app/views/proclaim/subscription_mailer/welcome_email.html.erb +25 -0
  51. data/app/views/proclaim/subscriptions/_form.html.erb +32 -0
  52. data/app/views/proclaim/subscriptions/new.html.erb +8 -0
  53. data/app/views/proclaim/subscriptions/subscribed.html.erb +7 -0
  54. data/app/views/proclaim/subscriptions/unsubscribe.html.erb +7 -0
  55. data/app/views/proclaim/subscriptions/unsubscribed.html.erb +3 -0
  56. data/config/routes.rb +18 -0
  57. data/db/migrate/20141108222616_create_proclaim_posts.rb +15 -0
  58. data/db/migrate/20141114235359_create_proclaim_comments.rb +15 -0
  59. data/db/migrate/20141115022230_create_proclaim_comment_hierarchies.rb +26 -0
  60. data/db/migrate/20141210234057_create_proclaim_subscriptions.rb +17 -0
  61. data/db/migrate/20141222224905_create_proclaim_images.rb +12 -0
  62. data/lib/generators/proclaim/install_generator.rb +23 -0
  63. data/lib/generators/proclaim/templates/README +27 -0
  64. data/lib/generators/proclaim/templates/initialize_proclaim.rb +22 -0
  65. data/lib/generators/proclaim/views_generator.rb +24 -0
  66. data/lib/proclaim.rb +22 -0
  67. data/lib/proclaim/engine.rb +39 -0
  68. data/lib/proclaim/version.rb +3 -0
  69. data/lib/tasks/proclaim_tasks.rake +4 -0
  70. data/proclaim.gemspec +46 -0
  71. data/test/controllers/proclaim/comments_controller_test.rb +228 -0
  72. data/test/controllers/proclaim/images_controller_test.rb +123 -0
  73. data/test/controllers/proclaim/posts_controller_test.rb +303 -0
  74. data/test/controllers/proclaim/subscriptions_controller_test.rb +93 -0
  75. data/test/dummy/README.rdoc +28 -0
  76. data/test/dummy/Rakefile +6 -0
  77. data/test/dummy/app/assets/javascripts/application.js +14 -0
  78. data/test/dummy/app/assets/stylesheets/application.css +16 -0
  79. data/test/dummy/app/controllers/application_controller.rb +15 -0
  80. data/test/dummy/app/helpers/application_helper.rb +28 -0
  81. data/test/dummy/app/models/user.rb +7 -0
  82. data/test/dummy/app/views/layouts/application.html.erb +16 -0
  83. data/test/dummy/bin/bundle +3 -0
  84. data/test/dummy/bin/rails +4 -0
  85. data/test/dummy/bin/rake +4 -0
  86. data/test/dummy/config.ru +4 -0
  87. data/test/dummy/config/application.rb +24 -0
  88. data/test/dummy/config/boot.rb +5 -0
  89. data/test/dummy/config/database.yml +25 -0
  90. data/test/dummy/config/environment.rb +5 -0
  91. data/test/dummy/config/environments/development.rb +45 -0
  92. data/test/dummy/config/environments/production.rb +80 -0
  93. data/test/dummy/config/environments/test.rb +49 -0
  94. data/test/dummy/config/initializers/assets.rb +8 -0
  95. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  96. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  97. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  98. data/test/dummy/config/initializers/inflections.rb +16 -0
  99. data/test/dummy/config/initializers/mime_types.rb +4 -0
  100. data/test/dummy/config/initializers/session_store.rb +3 -0
  101. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  102. data/test/dummy/config/locales/en.yml +23 -0
  103. data/test/dummy/config/routes.rb +5 -0
  104. data/test/dummy/config/secrets.yml +22 -0
  105. data/test/dummy/db/migrate/20141117214323_create_users.rb +10 -0
  106. data/test/dummy/db/schema.rb +75 -0
  107. data/test/dummy/log/development.log +131 -0
  108. data/test/dummy/log/test.log +25961 -0
  109. data/test/dummy/public/404.html +67 -0
  110. data/test/dummy/public/422.html +67 -0
  111. data/test/dummy/public/500.html +66 -0
  112. data/test/dummy/public/favicon.ico +0 -0
  113. data/test/dummy/tmp/cache/assets/test/sass/0b69f7cc441d56def3a51688e6a7a8474dc476d1/proclaim.css.scssc +0 -0
  114. data/test/dummy/tmp/cache/assets/test/sass/12a97df611d5fb0e395afda829edf8b9372acde7/comments.css.scssc +0 -0
  115. data/test/dummy/tmp/cache/assets/test/sass/12a97df611d5fb0e395afda829edf8b9372acde7/images.scssc +0 -0
  116. data/test/dummy/tmp/cache/assets/test/sass/12a97df611d5fb0e395afda829edf8b9372acde7/posts.css.scssc +0 -0
  117. data/test/dummy/tmp/cache/assets/test/sass/12a97df611d5fb0e395afda829edf8b9372acde7/subscriptions.css.scssc +0 -0
  118. data/test/dummy/tmp/cache/assets/test/sprockets/04adcece63bc645379e6de797e7998f8 +0 -0
  119. data/test/dummy/tmp/cache/assets/test/sprockets/06620fc450f0a9b4a482a7bc08387711 +0 -0
  120. data/test/dummy/tmp/cache/assets/test/sprockets/076dd0d567a92c34163b3b98af1d48ba +0 -0
  121. data/test/dummy/tmp/cache/assets/test/sprockets/09fc2eadf6d6062b2cc135a44e4e73db +0 -0
  122. data/test/dummy/tmp/cache/assets/test/sprockets/09fe8c62e8ae706e01058b4b4d056c8e +0 -0
  123. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  124. data/test/dummy/tmp/cache/assets/test/sprockets/142fd040033525acb73ad2ccf1406aea +0 -0
  125. data/test/dummy/tmp/cache/assets/test/sprockets/1762aeeaf38da3b8d989a5b66b088004 +0 -0
  126. data/test/dummy/tmp/cache/assets/test/sprockets/194ac1a695334e303516614579b3926d +0 -0
  127. data/test/dummy/tmp/cache/assets/test/sprockets/197ea008934db3e7ea8045302d206b92 +0 -0
  128. data/test/dummy/tmp/cache/assets/test/sprockets/19eba2635fec0895379c3e38f81ada84 +0 -0
  129. data/test/dummy/tmp/cache/assets/test/sprockets/1c2ebe72fcd7ff1379a561552ca30f85 +0 -0
  130. data/test/dummy/tmp/cache/assets/test/sprockets/1f42c80faacb651f670ec2b0998e49dc +0 -0
  131. data/test/dummy/tmp/cache/assets/test/sprockets/2243230e778a749ecbf0415a52e75be0 +0 -0
  132. data/test/dummy/tmp/cache/assets/test/sprockets/23ad87e715c70312aa61dde4fbb4bfe1 +0 -0
  133. data/test/dummy/tmp/cache/assets/test/sprockets/245b8735db4ea90bcaa91c011a1f447e +0 -0
  134. data/test/dummy/tmp/cache/assets/test/sprockets/26a42dac0cec64483f4126d2de4b0c9e +0 -0
  135. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  136. data/test/dummy/tmp/cache/assets/test/sprockets/30151c8f6d93717f06fa12774612ddf4 +0 -0
  137. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  138. data/test/dummy/tmp/cache/assets/test/sprockets/3c623d200214a5334aaf170537db087f +0 -0
  139. data/test/dummy/tmp/cache/assets/test/sprockets/3ec36650a50759fd4b75794cb253936f +0 -0
  140. data/test/dummy/tmp/cache/assets/test/sprockets/40431cdcc10c75ba1f275ecfe42623d3 +0 -0
  141. data/test/dummy/tmp/cache/assets/test/sprockets/4226218a4b06608115b21063353370ea +0 -0
  142. data/test/dummy/tmp/cache/assets/test/sprockets/437901953eb8707af6c27ca59cf65d91 +0 -0
  143. data/test/dummy/tmp/cache/assets/test/sprockets/461885b8ad31ef6a94c9a4f2e332b7eb +0 -0
  144. data/test/dummy/tmp/cache/assets/test/sprockets/4792f46317cda92ccd5b278ec61f9ac5 +0 -0
  145. data/test/dummy/tmp/cache/assets/test/sprockets/4dcb3434b91b1c62f897a1741c6d398b +0 -0
  146. data/test/dummy/tmp/cache/assets/test/sprockets/5101cda93cf70f0fc0837713be587780 +0 -0
  147. data/test/dummy/tmp/cache/assets/test/sprockets/52d8c61de0703e0d7cf97d0f7b0cca7a +0 -0
  148. data/test/dummy/tmp/cache/assets/test/sprockets/57f3d19a9bd484ac68c46f962a8684b2 +0 -0
  149. data/test/dummy/tmp/cache/assets/test/sprockets/587e7c1332c8d8b69746dd85164e2cef +0 -0
  150. data/test/dummy/tmp/cache/assets/test/sprockets/5934d5d0d1ac6657842708e85c73cf51 +0 -0
  151. data/test/dummy/tmp/cache/assets/test/sprockets/5af081799d7da2f04ead6a516c6015ad +0 -0
  152. data/test/dummy/tmp/cache/assets/test/sprockets/69ee5af8d9a655898a67bc538ca1c7e7 +0 -0
  153. data/test/dummy/tmp/cache/assets/test/sprockets/6d1c56259648b0383bc438c875a448c3 +0 -0
  154. data/test/dummy/tmp/cache/assets/test/sprockets/6e7de35055967df848aa490830043e51 +0 -0
  155. data/test/dummy/tmp/cache/assets/test/sprockets/70bc59560ee544af7bb2f727247db307 +0 -0
  156. data/test/dummy/tmp/cache/assets/test/sprockets/728cb566999910549092ff0a98e2853b +0 -0
  157. data/test/dummy/tmp/cache/assets/test/sprockets/72b5f0d35e9d69b744a156edad98f983 +0 -0
  158. data/test/dummy/tmp/cache/assets/test/sprockets/72ffa34d552e3fd02f28a6f845a5ac5b +0 -0
  159. data/test/dummy/tmp/cache/assets/test/sprockets/7369d324e84bc872c42b3e717ff4ad6c +0 -0
  160. data/test/dummy/tmp/cache/assets/test/sprockets/749a8b0e45b11df748a256dd04ceb1f7 +0 -0
  161. data/test/dummy/tmp/cache/assets/test/sprockets/77fb9f62552d9b786f9407ef11cc9a09 +0 -0
  162. data/test/dummy/tmp/cache/assets/test/sprockets/797823842565e01fc989ad8df0bd4254 +0 -0
  163. data/test/dummy/tmp/cache/assets/test/sprockets/7c139afa2296ac17483520109aecd449 +0 -0
  164. data/test/dummy/tmp/cache/assets/test/sprockets/7fb99e2b35af65c4f58bfb92dd4185b4 +0 -0
  165. data/test/dummy/tmp/cache/assets/test/sprockets/819de31c63b704f9ddf4865587a91d41 +0 -0
  166. data/test/dummy/tmp/cache/assets/test/sprockets/8604b464bf846e5223da37ef2f29b524 +0 -0
  167. data/test/dummy/tmp/cache/assets/test/sprockets/88fc815613b473e98e9307b1d423918d +0 -0
  168. data/test/dummy/tmp/cache/assets/test/sprockets/8bc4341aa4060b8646e8134722cf3b11 +0 -0
  169. data/test/dummy/tmp/cache/assets/test/sprockets/8cf8fd5ff8eae12211a88f971af30236 +0 -0
  170. data/test/dummy/tmp/cache/assets/test/sprockets/8da3b4a9f17aafff49eb263bdb758f44 +0 -0
  171. data/test/dummy/tmp/cache/assets/test/sprockets/9168e513bae02f041dbb806d6dbe94ac +0 -0
  172. data/test/dummy/tmp/cache/assets/test/sprockets/920c1322be1212a54b7c4f2751d5e7bf +0 -0
  173. data/test/dummy/tmp/cache/assets/test/sprockets/92205679a36afd387a2ba5c585a5a62c +0 -0
  174. data/test/dummy/tmp/cache/assets/test/sprockets/940566ebcae2d4e5c56a881ab66f2cf0 +0 -0
  175. data/test/dummy/tmp/cache/assets/test/sprockets/976967e07e2944a7ecc7403667f1f96b +0 -0
  176. data/test/dummy/tmp/cache/assets/test/sprockets/99bdde70cefa71745279232be575f14e +0 -0
  177. data/test/dummy/tmp/cache/assets/test/sprockets/9a8e402a7e32063e46647403b43553a5 +0 -0
  178. data/test/dummy/tmp/cache/assets/test/sprockets/9b09ad72f8cc33503878b01c713d92d0 +0 -0
  179. data/test/dummy/tmp/cache/assets/test/sprockets/a20dbdfebf37fe50e832a6273c972553 +0 -0
  180. data/test/dummy/tmp/cache/assets/test/sprockets/a3c6189fad6cb9ae955f6d5a43a61d51 +0 -0
  181. data/test/dummy/tmp/cache/assets/test/sprockets/abb54e11ff057a3e22a5a97d27cc4fa3 +0 -0
  182. data/test/dummy/tmp/cache/assets/test/sprockets/ad18e3875541d4298b1df133d494b93f +0 -0
  183. data/test/dummy/tmp/cache/assets/test/sprockets/b9b7c575c22943d49734d52381c5ee16 +0 -0
  184. data/test/dummy/tmp/cache/assets/test/sprockets/ba269a52f100d3d6cffda81e82e1ed49 +0 -0
  185. data/test/dummy/tmp/cache/assets/test/sprockets/bc7a0846b4881b0832d41de2b1724dba +0 -0
  186. data/test/dummy/tmp/cache/assets/test/sprockets/bcb2df87f9611d3cc3ef8a5575e54fb8 +0 -0
  187. data/test/dummy/tmp/cache/assets/test/sprockets/bcf33791d3286af3ba2cdf6a6756c89e +0 -0
  188. data/test/dummy/tmp/cache/assets/test/sprockets/be32d0a530ce861537d6abfa41333df9 +0 -0
  189. data/test/dummy/tmp/cache/assets/test/sprockets/c8270a6f07dccc5f00e6b2b43f10efd2 +0 -0
  190. data/test/dummy/tmp/cache/assets/test/sprockets/cd82cd410a50bffcfb6e21e3c49a85c9 +0 -0
  191. data/test/dummy/tmp/cache/assets/test/sprockets/ce4ccaa06bdee6426486224bc7e54187 +0 -0
  192. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  193. data/test/dummy/tmp/cache/assets/test/sprockets/d0bdb8592e4eed80aa2341e37f20dbc9 +0 -0
  194. data/test/dummy/tmp/cache/assets/test/sprockets/d4b784b16fa1b1dfcca6590689a8c157 +0 -0
  195. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  196. data/test/dummy/tmp/cache/assets/test/sprockets/d968bd38a69bbf5c0065e2df3d30cfd3 +0 -0
  197. data/test/dummy/tmp/cache/assets/test/sprockets/daa4d4b8a5ce46d6c4ecf031e0c61cfe +0 -0
  198. data/test/dummy/tmp/cache/assets/test/sprockets/dc2effd195334219a7e4acfdc7ec7974 +0 -0
  199. data/test/dummy/tmp/cache/assets/test/sprockets/de36ab6c3b1a9b62a586d98373dd569c +0 -0
  200. data/test/dummy/tmp/cache/assets/test/sprockets/e3aec457d5c753090d6521f2bb2d91b6 +0 -0
  201. data/test/dummy/tmp/cache/assets/test/sprockets/e8d6158b1fed2f574242b55856a3953d +0 -0
  202. data/test/dummy/tmp/cache/assets/test/sprockets/ea82f6aececcf81eef3e2e15a9225e66 +0 -0
  203. data/test/dummy/tmp/cache/assets/test/sprockets/ed9f5c17f71ec75de10b1bb029ebd7a2 +0 -0
  204. data/test/dummy/tmp/cache/assets/test/sprockets/f2984adaeaa5322e3a040705c6d40622 +0 -0
  205. data/test/dummy/tmp/cache/assets/test/sprockets/f62fd0cf9f5e7e077ec9c4daeccb06ae +0 -0
  206. data/test/dummy/tmp/cache/assets/test/sprockets/f78ea69bdbba5738c052e9eb04e6c208 +0 -0
  207. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  208. data/test/dummy/tmp/cache/assets/test/sprockets/f864e553f706456dbdf168319970ec2e +0 -0
  209. data/test/dummy/tmp/cache/assets/test/sprockets/fb0f641bfcbb0101c040da9ff736447b +0 -0
  210. data/test/dummy/tmp/cache/assets/test/sprockets/fe426a44cf23cf82032091cbffff898c +0 -0
  211. data/test/dummy/tmp/cache/assets/test/sprockets/ff732ea47a86c449582b2a81ef2930da +0 -0
  212. data/test/dummy/tmp/cache/assets/test/sprockets/ffc4980851addaacf12abeebfa63e07f +0 -0
  213. data/test/dummy/tmp/generators/config/initializers/proclaim.rb +22 -0
  214. data/test/factories/proclaim/comment.rb +11 -0
  215. data/test/factories/proclaim/image.rb +6 -0
  216. data/test/factories/proclaim/post.rb +14 -0
  217. data/test/factories/proclaim/subscription.rb +13 -0
  218. data/test/factories/user.rb +6 -0
  219. data/test/helpers/proclaim/comments_helper_test.rb +6 -0
  220. data/test/helpers/proclaim/posts_helper_test.rb +6 -0
  221. data/test/helpers/proclaim/subscriptions_helper_test.rb +6 -0
  222. data/test/integration/with_javascript/comment_test.rb +353 -0
  223. data/test/integration/with_javascript/post_form_test.rb +179 -0
  224. data/test/integration/with_javascript/post_subscription_test.rb +273 -0
  225. data/test/integration/without_javascript/blog_subscription_test.rb +87 -0
  226. data/test/integration/without_javascript/post_test.rb +140 -0
  227. data/test/integration/without_javascript/subscription_email_test.rb +95 -0
  228. data/test/integration/without_javascript/unsubscribe_test.rb +32 -0
  229. data/test/mailers/previews/proclaim/subscription_mailer_preview.rb +22 -0
  230. data/test/mailers/proclaim/subscription_mailer_test.rb +87 -0
  231. data/test/models/proclaim/comment_test.rb +41 -0
  232. data/test/models/proclaim/image_test.rb +70 -0
  233. data/test/models/proclaim/post_test.rb +127 -0
  234. data/test/models/proclaim/subscription_test.rb +66 -0
  235. data/test/policies/proclaim/comment_policy_test.rb +71 -0
  236. data/test/policies/proclaim/post_policy_test.rb +87 -0
  237. data/test/policies/proclaim/subscription_policy_test.rb +91 -0
  238. data/test/proclaim_test.rb +7 -0
  239. data/test/support/images/test.jpg +0 -0
  240. data/test/support/pages/posts/edit_page.rb +5 -0
  241. data/test/support/pages/posts/show_page.rb +47 -0
  242. data/test/support/wait_for_ajax.rb +11 -0
  243. data/test/test_helper.rb +56 -0
  244. data/vendor/assets/images/link.png +0 -0
  245. data/vendor/assets/images/remove.png +0 -0
  246. data/vendor/assets/images/resize-bigger.png +0 -0
  247. data/vendor/assets/images/resize-smaller.png +0 -0
  248. data/vendor/assets/images/unlink.png +0 -0
  249. data/vendor/assets/javascripts/addons/medium-editor-insert-embeds.js +197 -0
  250. data/vendor/assets/javascripts/addons/medium-editor-insert-embeds.min.js +10 -0
  251. data/vendor/assets/javascripts/addons/medium-editor-insert-images.js +572 -0
  252. data/vendor/assets/javascripts/addons/medium-editor-insert-images.min.js +10 -0
  253. data/vendor/assets/javascripts/addons/medium-editor-insert-maps.js +50 -0
  254. data/vendor/assets/javascripts/addons/medium-editor-insert-maps.min.js +10 -0
  255. data/vendor/assets/javascripts/addons/medium-editor-insert-plugin.js +496 -0
  256. data/vendor/assets/javascripts/addons/medium-editor-insert-plugin.min.js +10 -0
  257. data/vendor/assets/javascripts/addons/medium-editor-insert-tables.js +132 -0
  258. data/vendor/assets/javascripts/addons/medium-editor-insert-tables.min.js +10 -0
  259. data/vendor/assets/javascripts/medium-editor-insert-plugin.all.js +1415 -0
  260. data/vendor/assets/javascripts/medium-editor-insert-plugin.all.min.js +10 -0
  261. data/vendor/assets/stylesheets/medium-editor-insert-plugin-frontend.css +55 -0
  262. data/vendor/assets/stylesheets/medium-editor-insert-plugin-frontend.min.css +10 -0
  263. data/vendor/assets/stylesheets/medium-editor-insert-plugin.css +277 -0
  264. data/vendor/assets/stylesheets/medium-editor-insert-plugin.min.css +10 -0
  265. metadata +791 -0
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * medium-editor-insert-plugin v0.3.2 - jQuery insert plugin for MediumEditor
3
+ *
4
+ * https://github.com/orthes/medium-editor-insert-plugin
5
+ *
6
+ * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk)
7
+ * Released under the MIT license
8
+ */
9
+
10
+ !function(a){var b={};MediumEditor&&"function"==typeof MediumEditor&&(MediumEditor.prototype.serialize=function(){var b,c,d,e,f,g,h,i,j={};for(b=0;b<this.elements.length;b+=1){for(d=""!==this.elements[b].id?this.elements[b].id:"element-"+b,e=a(this.elements[b]).clone(),f=a(".mediumInsert",e),c=0;c<f.length;c++)g=a(f[c]),h=a(".mediumInsert-placeholder",g).children(),0===h.length?g.remove():(g.removeAttr("contenteditable"),a("img[draggable]",g).removeAttr("draggable"),g.hasClass("small")&&h.addClass("small"),a(".mediumInsert-buttons",g).remove(),h.unwrap());i=e.html().trim(),j[d]={value:i}}return j},MediumEditor.prototype.deactivate=function(){var b;if(!this.isActive)return!1;for(this.isActive=!1,void 0!==this.toolbar&&(this.toolbar.style.display="none"),document.documentElement.removeEventListener("mouseup",this.checkSelectionWrapper),b=0;b<this.elements.length;b+=1)this.elements[b].removeEventListener("keyup",this.checkSelectionWrapper),this.elements[b].removeEventListener("blur",this.checkSelectionWrapper),this.elements[b].removeAttribute("contentEditable");a.fn.mediumInsert.insert.$el&&a.fn.mediumInsert.insert.$el.mediumInsert("disable")},MediumEditor.prototype.activate=function(){var b;if(this.isActive)return!1;for(void 0!==this.toolbar&&(this.toolbar.style.display="block"),this.isActive=!0,b=0;b<this.elements.length;b+=1)this.elements[b].setAttribute("contentEditable",!0);this.bindSelect(),a.fn.mediumInsert.insert.$el&&a.fn.mediumInsert.insert.$el.mediumInsert("enable")}),a.fn.mediumInsert=function(c){return"string"==typeof c&&a.fn.mediumInsert.insert[c]?void a.fn.mediumInsert.insert[c]():(a.fn.mediumInsert.settings=a.extend(a.fn.mediumInsert.settings,c),this.each(function(){a(this).addClass("medium-editor-insert-plugin");var c="p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote";a(this).on("dragover drop",c,function(a){return a.preventDefault(),!1}),a.fn.mediumInsert.insert.init(a(this)),a.each(a.fn.mediumInsert.settings.addons,function(c){if("undefined"!=typeof b[c]){var d=a.fn.mediumInsert.settings.addons[c];d.$el=a.fn.mediumInsert.insert.$el,b[c].init(d)}})}))},a.fn.mediumInsert.settings={enabled:!0,beginning:!1,addons:{images:{},embeds:{}}},a.fn.mediumInsert.registerAddon=function(a,c){b[a]=c},a.fn.mediumInsert.getAddon=function(a){return b[a]},a.fn.mediumInsert.insert={init:function(a){this.$el=a,this.isFirefox=navigator.userAgent.match(/firefox/i),this.setPlaceholders(),this.setEvents()},deselect:function(){document.getSelection().removeAllRanges()},disable:function(){a.fn.mediumInsert.settings.enabled=!1,a.fn.mediumInsert.insert.$el.find(".mediumInsert-buttons").addClass("hide")},enable:function(){a.fn.mediumInsert.settings.enabled=!0,a.fn.mediumInsert.insert.$el.find(".mediumInsert-buttons").removeClass("hide")},getMaxId:function(){var b=-1;return a('div[id^="mediumInsert-"]').each(function(){var c=parseInt(a(this).attr("id").split("-")[1],10);c>b&&(b=c)}),b},getButtons:function(c){var d,e=a.fn.mediumInsert.settings.editor,f=e&&e.options?e.options.buttonLabels:"";return d=a.fn.mediumInsert.settings.enabled?'<div class="mediumInsert-buttons"><a class="mediumInsert-buttonsShow">+</a><ul class="mediumInsert-buttonsOptions medium-editor-toolbar medium-editor-toolbar-active">':'<div class="mediumInsert-buttons hide"><a class="mediumInsert-buttonsShow">+</a><ul class="mediumInsert-buttonsOptions medium-editor-toolbar medium-editor-toolbar-active">',0===Object.keys(a.fn.mediumInsert.settings.addons).length?!1:("undefined"==typeof c?a.each(a.fn.mediumInsert.settings.addons,function(a){"undefined"==typeof b[a]?console.log('Addon "'+a+'" is not available. Did you forgot to include the related file?'):d+="<li>"+b[a].insertButton(f)+"</li>"}):d+="<li>"+b[c].insertButton(f)+"</li>",d+="</ul></div>")},setPlaceholders:function(){var b,c=this,d=a.fn.mediumInsert.insert.$el,e=this.getButtons();return e===!1?!1:(e='<div class="mediumInsert" contenteditable="false">'+e+'<div class="mediumInsert-placeholder"></div></div>',d.is(":empty")&&d.html("<p><br></p>"),void d.keyup(function(){var f,g=d.children(":last");(""===d.html()||"<br>"===d.html())&&d.html("<p><br></p>"),g.hasClass("mediumInsert")&&g.find(".mediumInsert-placeholder").children().length>0&&d.append("<p><br></p>"),c.isFirefox&&a(".mediumInsert .mediumInsert-placeholder:empty",d).each(function(){a(this).parent().remove()}),f=c.getMaxId()+1;var h="p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote";a.fn.mediumInsert.settings.beginning&&(b=d.children(h).first(),b.prev().hasClass("mediumInsert")===!1&&(b.before(e),b.prev(".mediumInsert").attr("id","mediumInsert-"+f).addClass("mediumInsert-first"),f++)),d.children(h).each(function(){a(this).next().hasClass("mediumInsert")===!1&&(a(this).after(e),a(this).next(".mediumInsert").attr("id","mediumInsert-"+f)),f++})}).keyup())},setEvents:function(){var c=this,d=a.fn.mediumInsert.insert.$el;d.on("selectstart mousedown",".mediumInsert",function(b){a(b.target).is("img")===!1&&b.preventDefault()}),d.on("blur",function(){var b,c=a(this).clone();c.find(".mediumInsert").remove(),b=c.html().replace(/^\s+|\s+$/g,""),(""===b||"<p><br></p>"===b)&&a(this).addClass("medium-editor-placeholder")}),d.on("keypress",function(a){c.isFirefox&&13===a.keyCode&&d.contents().each(function(){return function(a,b){return"#text"===b.nodeName&&""!==b.textContent.trim()?(document.execCommand("insertHTML",!1,"<p>"+b.data+"</p>"),b.remove()):void 0}}(this))}),d.on("keydown",function(a){return navigator.userAgent.match(/chrome/i)&&(d.children().last().removeClass("hide"),(a.ctrlKey||a.metaKey)&&65===a.which)?(a.preventDefault(),0===d.find("p").text().trim().length?!1:(d.children().last().addClass("hide"),document.execCommand("selectAll",!1,null))):void 0}),d.on("click",".mediumInsert-buttons a.mediumInsert-buttonsShow",function(){var b=a(this).siblings(".mediumInsert-buttonsOptions"),d=a(this).parent().siblings(".mediumInsert-placeholder");a(this).hasClass("active")?(a(this).removeClass("active"),b.hide(),a("a",b).show()):(a(this).addClass("active"),b.show(),a("a",b).each(function(){var c=a(this).attr("class").split("action-")[1],e=c.split("-")[0];a(".mediumInsert-"+e,d).length>0&&a("a:not(.action-"+c+")",b).hide()})),c.deselect()}),d.on("mouseleave",".mediumInsert",function(){a("a.mediumInsert-buttonsShow",this).removeClass("active"),a(".mediumInsert-buttonsOptions",this).hide()}),d.on("click",".mediumInsert-buttons .mediumInsert-action",function(c){c.preventDefault();var d=a(this).data("addon"),e=a(this).data("action"),f=a(this).parents(".mediumInsert-buttons").siblings(".mediumInsert-placeholder");b[d]&&b[d][e]&&b[d][e](f),a(this).parents(".mediumInsert").mouseleave()})}}}(jQuery);
@@ -0,0 +1,132 @@
1
+ /*!
2
+ * medium-editor-insert-plugin v0.3.2 - jQuery insert plugin for MediumEditor
3
+ *
4
+ * https://github.com/orthes/medium-editor-insert-plugin
5
+ *
6
+ * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk)
7
+ * Released under the MIT license
8
+ */
9
+
10
+ (function ($) {
11
+
12
+ $.fn.mediumInsert.registerAddon('tables', {
13
+
14
+ /**
15
+ * Table default options
16
+ */
17
+
18
+ defaults: {
19
+ defaultRows: 2,
20
+ defaultCols: 2
21
+ },
22
+
23
+ /**
24
+ * Tables initial function
25
+ * @return {void}
26
+ */
27
+ init : function (options) {
28
+ this.options = $.extend(this.defaults, options);
29
+ this.$el = $.fn.mediumInsert.insert.$el;
30
+ this.setTableButtonEvents();
31
+ },
32
+
33
+ insertButton : function (buttonLabels) {
34
+ var label = 'Table';
35
+ if (buttonLabels === 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) {
36
+ label = '<i class="fa fa-table"></i>';
37
+ }
38
+
39
+ if (typeof buttonLabels === 'object' && buttonLabels.table) {
40
+ label = buttonLabels.table;
41
+ }
42
+
43
+ return '<button data-addon="tables" data-action="add" class="medium-editor-action mediumInsert-action">' + label + '</button>';
44
+ },
45
+
46
+ /**
47
+ * Add table to $placeholder
48
+ * @param {element} $placeholder $placeholder to add embed to
49
+ * @return {void}
50
+ */
51
+ add : function ($placeholder) {
52
+ $.fn.mediumInsert.insert.deselect();
53
+
54
+ var formHtml = '<div class="medium-editor-toolbar-form-anchor mediumInsert-tableDemoBox"><table><tr><td></td><td><label>cols:<input type="text" value="' + this.options.defaultCols + '" class="mediumInsert-tableCols" /></label></td></tr><tr><td><label>rows:<input type="text" value="' + this.options.defaultRows + '" class="mediumInsert-tableRows" /></label></td><td><table class="mediumInsert-demoTable"></table></td></tr><tr><td></td><td><label><button class="mediumInsert-tableReadyButton">insert</button></label></td></tr></table></</div>';
55
+ $(formHtml).appendTo($placeholder.prev());
56
+ this.updateDemoTable();
57
+
58
+ setTimeout(function () {
59
+ $placeholder.prev().find('input').focus();
60
+ }, 50);
61
+
62
+ $.fn.mediumInsert.insert.deselect();
63
+ this.currentPlaceholder = $placeholder;
64
+ },
65
+
66
+ setTableButtonEvents : function () {
67
+ var that = this;
68
+
69
+ $(document).on('keyup',
70
+ 'input.mediumInsert-tableRows, input.mediumInsert-tableCols',
71
+ function() { that.updateDemoTable(); });
72
+
73
+ $(document).on('click', function(e) {
74
+ if ($(e.target).parents('.mediumInsert-buttons').length === 0) {
75
+ that.removeToolbar();
76
+ }
77
+ });
78
+
79
+ $(document).on('click', 'button.mediumInsert-tableReadyButton', function() {
80
+ that.setEnterActionEvents();
81
+ that.removeToolbar();
82
+ });
83
+ },
84
+
85
+ getDimensions : function () {
86
+ return {
87
+ rows: parseFloat($('input.mediumInsert-tableRows').val()) || 1,
88
+ cols: parseFloat($('input.mediumInsert-tableCols').val()) || 1
89
+ };
90
+ },
91
+
92
+ buildTable : function (table) {
93
+ var i, j, $row,
94
+ dimensions = this.getDimensions(),
95
+ $table = $(table);
96
+
97
+ for (i = 0; i < dimensions.rows; i++) {
98
+ $row = $('<tr>');
99
+ for (j = 0; j < dimensions.cols; j++) {
100
+ $row.append('<td>');
101
+ }
102
+ $table.append($row);
103
+ }
104
+ },
105
+
106
+ updateDemoTable : function () {
107
+ var $demoTable = $('table.mediumInsert-demoTable');
108
+
109
+ $demoTable.empty();
110
+ this.buildTable($demoTable);
111
+ },
112
+
113
+ setEnterActionEvents : function () {
114
+ var that = this;
115
+ if ($.fn.mediumInsert.settings.enabled === false) {
116
+ return false;
117
+ }
118
+
119
+ var $table = $('<table class="mediumInsert-table">');
120
+ that.buildTable($table);
121
+
122
+ that.currentPlaceholder.append($table);
123
+ that.currentPlaceholder.closest('[data-medium-element]').trigger('keyup').trigger('input');
124
+ },
125
+
126
+ removeToolbar : function () {
127
+ $(".mediumInsert-tableDemoBox").remove();
128
+ }
129
+
130
+ });
131
+
132
+ }(jQuery));
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * medium-editor-insert-plugin v0.3.2 - jQuery insert plugin for MediumEditor
3
+ *
4
+ * https://github.com/orthes/medium-editor-insert-plugin
5
+ *
6
+ * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk)
7
+ * Released under the MIT license
8
+ */
9
+
10
+ !function(a){a.fn.mediumInsert.registerAddon("tables",{defaults:{defaultRows:2,defaultCols:2},init:function(b){this.options=a.extend(this.defaults,b),this.$el=a.fn.mediumInsert.insert.$el,this.setTableButtonEvents()},insertButton:function(a){var b="Table";return("fontawesome"===a||"object"==typeof a&&a.fontawesome)&&(b='<i class="fa fa-table"></i>'),"object"==typeof a&&a.table&&(b=a.table),'<button data-addon="tables" data-action="add" class="medium-editor-action mediumInsert-action">'+b+"</button>"},add:function(b){a.fn.mediumInsert.insert.deselect();var c='<div class="medium-editor-toolbar-form-anchor mediumInsert-tableDemoBox"><table><tr><td></td><td><label>cols:<input type="text" value="'+this.options.defaultCols+'" class="mediumInsert-tableCols" /></label></td></tr><tr><td><label>rows:<input type="text" value="'+this.options.defaultRows+'" class="mediumInsert-tableRows" /></label></td><td><table class="mediumInsert-demoTable"></table></td></tr><tr><td></td><td><label><button class="mediumInsert-tableReadyButton">insert</button></label></td></tr></table></</div>';a(c).appendTo(b.prev()),this.updateDemoTable(),setTimeout(function(){b.prev().find("input").focus()},50),a.fn.mediumInsert.insert.deselect(),this.currentPlaceholder=b},setTableButtonEvents:function(){var b=this;a(document).on("keyup","input.mediumInsert-tableRows, input.mediumInsert-tableCols",function(){b.updateDemoTable()}),a(document).on("click",function(c){0===a(c.target).parents(".mediumInsert-buttons").length&&b.removeToolbar()}),a(document).on("click","button.mediumInsert-tableReadyButton",function(){b.setEnterActionEvents(),b.removeToolbar()})},getDimensions:function(){return{rows:parseFloat(a("input.mediumInsert-tableRows").val())||1,cols:parseFloat(a("input.mediumInsert-tableCols").val())||1}},buildTable:function(b){var c,d,e,f=this.getDimensions(),g=a(b);for(c=0;c<f.rows;c++){for(e=a("<tr>"),d=0;d<f.cols;d++)e.append("<td>");g.append(e)}},updateDemoTable:function(){var b=a("table.mediumInsert-demoTable");b.empty(),this.buildTable(b)},setEnterActionEvents:function(){var b=this;if(a.fn.mediumInsert.settings.enabled===!1)return!1;var c=a('<table class="mediumInsert-table">');b.buildTable(c),b.currentPlaceholder.append(c),b.currentPlaceholder.closest("[data-medium-element]").trigger("keyup").trigger("input")},removeToolbar:function(){a(".mediumInsert-tableDemoBox").remove()}})}(jQuery);
@@ -0,0 +1,1415 @@
1
+ /*!
2
+ * medium-editor-insert-plugin v0.3.2 - jQuery insert plugin for MediumEditor
3
+ *
4
+ * https://github.com/orthes/medium-editor-insert-plugin
5
+ *
6
+ * Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk)
7
+ * Released under the MIT license
8
+ */
9
+
10
+ /* global MediumEditor */
11
+
12
+ (function ($) {
13
+ /*
14
+ * Private storage of registered addons
15
+ */
16
+ var addons = {};
17
+
18
+ /**
19
+ * Extend MediumEditor functions if the editor exists
20
+ */
21
+ if (MediumEditor && typeof(MediumEditor) === "function") {
22
+ /**
23
+ * Extend MediumEditor's serialize function to get rid of unnecesarry Medium Editor Insert Plugin stuff
24
+ *
25
+ * @return {object} content Object containing HTML content of each element
26
+ */
27
+
28
+ MediumEditor.prototype.serialize = function () {
29
+ var i, j,
30
+ elementid,
31
+ content = {},
32
+ $clone, $inserts, $insert, $insertData, html;
33
+ for (i = 0; i < this.elements.length; i += 1) {
34
+ elementid = (this.elements[i].id !== '') ? this.elements[i].id : 'element-' + i;
35
+
36
+ $clone = $(this.elements[i]).clone();
37
+ $inserts = $('.mediumInsert', $clone);
38
+ for (j = 0; j < $inserts.length; j++) {
39
+ $insert = $($inserts[j]);
40
+ $insertData = $('.mediumInsert-placeholder', $insert).children();
41
+ if ($insertData.length === 0) {
42
+ $insert.remove();
43
+ } else {
44
+ $insert.removeAttr('contenteditable');
45
+ $('img[draggable]', $insert).removeAttr('draggable');
46
+ if ($insert.hasClass('small')) {
47
+ $insertData.addClass('small');
48
+ }
49
+ $('.mediumInsert-buttons', $insert).remove();
50
+ $insertData.unwrap();
51
+ }
52
+ }
53
+
54
+ html = $clone.html().trim();
55
+ content[elementid] = {
56
+ value: html
57
+ };
58
+ }
59
+ return content;
60
+ };
61
+
62
+ /**
63
+ * Extend MediumEditor's deactivate function to call $.fn.mediumInsert.insert.disable function
64
+ *
65
+ * @return {void}
66
+ */
67
+
68
+ MediumEditor.prototype.deactivate = function () {
69
+ var i;
70
+ if (!this.isActive) {
71
+ return false;
72
+ }
73
+ this.isActive = false;
74
+
75
+ if (this.toolbar !== undefined) {
76
+ this.toolbar.style.display = 'none';
77
+ }
78
+
79
+ document.documentElement.removeEventListener('mouseup', this.checkSelectionWrapper);
80
+
81
+ for (i = 0; i < this.elements.length; i += 1) {
82
+ this.elements[i].removeEventListener('keyup', this.checkSelectionWrapper);
83
+ this.elements[i].removeEventListener('blur', this.checkSelectionWrapper);
84
+ this.elements[i].removeAttribute('contentEditable');
85
+ }
86
+
87
+ if ($.fn.mediumInsert.insert.$el)
88
+ $.fn.mediumInsert.insert.$el.mediumInsert('disable');
89
+ };
90
+
91
+ /**
92
+ * Extend MediumEditor's activate function to call $.fn.mediumInsert.insert.enable function
93
+ *
94
+ * @return {void}
95
+ */
96
+
97
+ MediumEditor.prototype.activate = function () {
98
+ var i;
99
+ if (this.isActive) {
100
+ return false;
101
+ }
102
+
103
+ if (this.toolbar !== undefined) {
104
+ this.toolbar.style.display = 'block';
105
+ }
106
+
107
+ this.isActive = true;
108
+ for (i = 0; i < this.elements.length; i += 1) {
109
+ this.elements[i].setAttribute('contentEditable', true);
110
+ }
111
+ this.bindSelect();
112
+
113
+ if ($.fn.mediumInsert.insert.$el)
114
+ $.fn.mediumInsert.insert.$el.mediumInsert('enable');
115
+ };
116
+ }
117
+
118
+ /**
119
+ * Medium Editor Insert Plugin
120
+ *
121
+ * @param {object} options Options for the plugin
122
+ * @param {void}
123
+ */
124
+
125
+ $.fn.mediumInsert = function (options) {
126
+
127
+ if (typeof options === 'string' && $.fn.mediumInsert.insert[options]) {
128
+ $.fn.mediumInsert.insert[options]();
129
+ } else {
130
+ $.fn.mediumInsert.settings = $.extend($.fn.mediumInsert.settings, options);
131
+
132
+
133
+
134
+ /**
135
+ * Initial plugin loop
136
+ */
137
+
138
+ return this.each(function () {
139
+ $(this).addClass('medium-editor-insert-plugin');
140
+
141
+ var blocks = 'p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote';
142
+ $(this).on('dragover drop', blocks, function (e) {
143
+ e.preventDefault();
144
+ return false;
145
+ });
146
+
147
+ $.fn.mediumInsert.insert.init($(this));
148
+
149
+ $.each($.fn.mediumInsert.settings.addons, function (i) {
150
+ if (typeof addons[i] !== 'undefined') {
151
+ var addonOptions = $.fn.mediumInsert.settings.addons[i];
152
+ addonOptions.$el = $.fn.mediumInsert.insert.$el;
153
+ addons[i].init(addonOptions);
154
+ }
155
+ });
156
+ });
157
+ }
158
+ };
159
+
160
+
161
+ /**
162
+ * Settings
163
+ */
164
+ $.fn.mediumInsert.settings = {
165
+ enabled: true,
166
+ beginning: false,
167
+ addons: {
168
+ images: {},
169
+ embeds: {}
170
+ }
171
+ };
172
+
173
+ /**
174
+ * Register new addon
175
+ */
176
+ $.fn.mediumInsert.registerAddon = function(name, addon){
177
+ addons[name] = addon;
178
+ };
179
+
180
+ /**
181
+ * Get registered addon
182
+ */
183
+ $.fn.mediumInsert.getAddon = function(name){
184
+ return addons[name];
185
+ };
186
+
187
+
188
+ /**
189
+ * Addon Initialization
190
+ */
191
+
192
+ $.fn.mediumInsert.insert = {
193
+
194
+ /**
195
+ * Insert initial function
196
+ *
197
+ * @param {element} el Parent container element
198
+ * @return {void}
199
+ */
200
+
201
+ init: function ($el) {
202
+ this.$el = $el;
203
+ this.isFirefox = navigator.userAgent.match(/firefox/i);
204
+ this.setPlaceholders();
205
+ this.setEvents();
206
+ },
207
+
208
+ /**
209
+ * Deselect selected text
210
+ *
211
+ * @return {void}
212
+ */
213
+
214
+ deselect: function () {
215
+ document.getSelection().removeAllRanges();
216
+ },
217
+
218
+ /**
219
+ * Disable the plugin
220
+ *
221
+ * @return {void}
222
+ */
223
+
224
+ disable: function () {
225
+ $.fn.mediumInsert.settings.enabled = false;
226
+
227
+ $.fn.mediumInsert.insert.$el.find('.mediumInsert-buttons').addClass('hide');
228
+ },
229
+
230
+ /**
231
+ * Enable the plugin
232
+ *
233
+ * @return {void}
234
+ */
235
+
236
+ enable: function () {
237
+ $.fn.mediumInsert.settings.enabled = true;
238
+
239
+ $.fn.mediumInsert.insert.$el.find('.mediumInsert-buttons').removeClass('hide');
240
+ },
241
+
242
+ /**
243
+ * Return max id in #mediumInsert-*
244
+ *
245
+ * @return {int} max (Max number, -1 if no placeholders exist)
246
+ */
247
+ getMaxId: function () {
248
+ var max = -1;
249
+
250
+ $('div[id^="mediumInsert-"]').each(function () {
251
+ var id = parseInt($(this).attr('id').split('-')[1], 10);
252
+ if (id > max) {
253
+ max = id;
254
+ }
255
+ });
256
+
257
+ return max;
258
+ },
259
+
260
+ /**
261
+ * Return insert buttons optionally filtered by addon name
262
+ *
263
+ * @param {string} addon Addon name of addon to display only
264
+ * @return {void}
265
+ */
266
+ getButtons: function (addon) {
267
+ var editor = $.fn.mediumInsert.settings.editor,
268
+ buttonLabels = (editor && editor.options) ? editor.options.buttonLabels : '';
269
+
270
+ var buttons;
271
+ if($.fn.mediumInsert.settings.enabled) {
272
+ buttons = '<div class="mediumInsert-buttons">'+
273
+ '<a class="mediumInsert-buttonsShow">+</a>'+
274
+ '<ul class="mediumInsert-buttonsOptions medium-editor-toolbar medium-editor-toolbar-active">';
275
+ } else {
276
+ buttons = '<div class="mediumInsert-buttons hide">'+
277
+ '<a class="mediumInsert-buttonsShow">+</a>'+
278
+ '<ul class="mediumInsert-buttonsOptions medium-editor-toolbar medium-editor-toolbar-active">';
279
+ }
280
+
281
+ if (Object.keys($.fn.mediumInsert.settings.addons).length === 0) {
282
+ return false;
283
+ }
284
+
285
+ if (typeof addon === 'undefined') {
286
+ $.each($.fn.mediumInsert.settings.addons, function (i) {
287
+ if (typeof addons[i] === 'undefined') {
288
+ console.log('Addon "' + i + '" is not available. Did you forgot to include the related file?');
289
+ } else {
290
+ buttons += '<li>' + addons[i].insertButton(buttonLabels) + '</li>';
291
+ }
292
+ });
293
+ } else {
294
+ buttons += '<li>' + addons[addon].insertButton(buttonLabels) + '</li>';
295
+ }
296
+
297
+ buttons += '</ul></div>';
298
+
299
+ return buttons;
300
+ },
301
+
302
+ /**
303
+ * Method setting placeholders
304
+ *
305
+ * @return {void}
306
+ */
307
+
308
+ setPlaceholders: function () {
309
+ var that = this,
310
+ $el = $.fn.mediumInsert.insert.$el,
311
+ insertBlock = this.getButtons(),
312
+ $firstEl;
313
+
314
+ if (insertBlock === false) {
315
+ return false;
316
+ }
317
+
318
+ insertBlock = '<div class="mediumInsert" contenteditable="false">'+
319
+ insertBlock +
320
+ '<div class="mediumInsert-placeholder"></div>'+
321
+ '</div>';
322
+
323
+ if ($el.is(':empty')) {
324
+ $el.html('<p><br></p>');
325
+ }
326
+
327
+ $el.keyup(function () {
328
+ var $lastChild = $el.children(':last'),
329
+ i;
330
+
331
+ // Fix #39
332
+ // After deleting all content (ctrl+A and delete) in Firefox, all content is deleted and only <br> appears
333
+ // To force placeholder to appear, set <p><br></p> as content of the $el
334
+ if ($el.html() === '' || $el.html() === '<br>') {
335
+ $el.html('<p><br></p>');
336
+ }
337
+
338
+ if ($lastChild.hasClass('mediumInsert') && $lastChild.find('.mediumInsert-placeholder').children().length > 0) {
339
+ $el.append('<p><br></p>');
340
+ }
341
+
342
+ // Fix not deleting placeholder in Firefox
343
+ // by removing all empty placeholders
344
+ if (that.isFirefox){
345
+ $('.mediumInsert .mediumInsert-placeholder:empty', $el).each(function () {
346
+ $(this).parent().remove();
347
+ });
348
+ }
349
+
350
+ i = that.getMaxId() +1;
351
+
352
+ var blocks = 'p, h1, h2, h3, h4, h5, h6, ol, ul, blockquote';
353
+
354
+ if ($.fn.mediumInsert.settings.beginning) {
355
+ $firstEl = $el.children(blocks).first();
356
+ if ($firstEl.prev().hasClass('mediumInsert') === false) {
357
+ $firstEl.before(insertBlock);
358
+ $firstEl.prev('.mediumInsert').attr('id', 'mediumInsert-'+ i).addClass('mediumInsert-first');
359
+ i++;
360
+ }
361
+ }
362
+
363
+ $el.children(blocks).each(function () {
364
+ if ($(this).next().hasClass('mediumInsert') === false) {
365
+ $(this).after(insertBlock);
366
+ $(this).next('.mediumInsert').attr('id', 'mediumInsert-'+ i);
367
+ }
368
+ i++;
369
+ });
370
+
371
+ }).keyup();
372
+ },
373
+
374
+
375
+ /**
376
+ * Set events on placeholders
377
+ *
378
+ * @return {void}
379
+ */
380
+
381
+ setEvents: function () {
382
+ var that = this,
383
+ $el = $.fn.mediumInsert.insert.$el;
384
+
385
+ $el.on('selectstart mousedown', '.mediumInsert', function (e) {
386
+ if ($(e.target).is('img') === false) {
387
+ e.preventDefault();
388
+ }
389
+ });
390
+
391
+ $el.on('blur', function () {
392
+ var $clone = $(this).clone(),
393
+ cloneHtml;
394
+
395
+ $clone.find('.mediumInsert').remove();
396
+ cloneHtml = $clone.html().replace(/^\s+|\s+$/g, '');
397
+
398
+ if (cloneHtml === '' || cloneHtml === '<p><br></p>') {
399
+ $(this).addClass('medium-editor-placeholder');
400
+ }
401
+ });
402
+
403
+
404
+ // Fix #29
405
+ // Sometimes in Firefox when you hit enter, <br type="_moz"> appears instead of <p><br></p>
406
+ // If it happens, force to wrap the <br> into a paragraph
407
+ $el.on('keypress', function (e) {
408
+ if (that.isFirefox) {
409
+ if (e.keyCode === 13) {
410
+ //wrap content text in p to avoid firefox problems
411
+ $el.contents().each((function() {
412
+ return function(index, field) {
413
+ if (field.nodeName === '#text' && field.textContent.trim() !== '') {
414
+ document.execCommand('insertHTML', false, "<p>" + field.data + "</p>");
415
+ return field.remove();
416
+ }
417
+ };
418
+ })(this));
419
+ // Removed because of #94 issue
420
+ //
421
+ // Firefox add extra br tag inside p tag
422
+ // var latestPTag = $el.find('p').last();
423
+ // if (latestPTag.text().length > 0) {
424
+ // latestPTag.find('br').remove();
425
+ // }
426
+ }
427
+ }
428
+ });
429
+
430
+ // Fix #39
431
+ // For some reason Chrome doesn't "select-all", when the last placeholder is visible.
432
+ // So it's needed to hide it when the user "selects all", and show it again when they presses any other key.
433
+ $el.on('keydown', function (e) {
434
+ // Fix Select-all using (ctrl + a) in chrome
435
+ if (navigator.userAgent.match(/chrome/i)) {
436
+ $el.children().last().removeClass('hide');
437
+ if ( (e.ctrlKey || e.metaKey) && e.which === 65) {
438
+ e.preventDefault();
439
+ if($el.find('p').text().trim().length === 0) {
440
+ return false;
441
+ }
442
+
443
+ $el.children().last().addClass('hide');
444
+ return document.execCommand('selectAll', false, null);
445
+ }
446
+ }
447
+ });
448
+
449
+ $el.on('click', '.mediumInsert-buttons a.mediumInsert-buttonsShow', function () {
450
+ var $options = $(this).siblings('.mediumInsert-buttonsOptions'),
451
+ $placeholder = $(this).parent().siblings('.mediumInsert-placeholder');
452
+
453
+ if ($(this).hasClass('active')) {
454
+ $(this).removeClass('active');
455
+ $options.hide();
456
+
457
+ $('a', $options).show();
458
+ } else {
459
+ $(this).addClass('active');
460
+ $options.show();
461
+
462
+ $('a', $options).each(function () {
463
+ var aClass = $(this).attr('class').split('action-')[1],
464
+ plugin = aClass.split('-')[0];
465
+ if ($('.mediumInsert-'+ plugin, $placeholder).length > 0) {
466
+ $('a:not(.action-'+ aClass +')', $options).hide();
467
+ }
468
+ });
469
+ }
470
+
471
+ that.deselect();
472
+ });
473
+
474
+ $el.on('mouseleave', '.mediumInsert', function () {
475
+ $('a.mediumInsert-buttonsShow', this).removeClass('active');
476
+ $('.mediumInsert-buttonsOptions', this).hide();
477
+ });
478
+
479
+ $el.on('click', '.mediumInsert-buttons .mediumInsert-action', function (e) {
480
+ e.preventDefault();
481
+
482
+ var addon = $(this).data('addon'),
483
+ action = $(this).data('action'),
484
+ $placeholder = $(this).parents('.mediumInsert-buttons').siblings('.mediumInsert-placeholder');
485
+
486
+ if (addons[addon] && addons[addon][action]) {
487
+ addons[addon][action]($placeholder);
488
+ }
489
+
490
+ $(this).parents('.mediumInsert').mouseleave();
491
+ });
492
+ }
493
+
494
+ };
495
+
496
+ }(jQuery));
497
+
498
+ (function ($) {
499
+
500
+ $.fn.mediumInsert.registerAddon('embeds', {
501
+
502
+ /**
503
+ * Embed default options
504
+ */
505
+
506
+ defaults: {
507
+ urlPlaceholder: 'Paste or type a link'
508
+ //,oembedProxy: 'http://medium.iframe.ly/api/oembed?iframe=1'
509
+ },
510
+
511
+ /**
512
+ * Embeds initial function
513
+ * @return {void}
514
+ */
515
+ init : function (options) {
516
+ this.options = $.extend(this.defaults, options);
517
+ this.$el = $.fn.mediumInsert.insert.$el;
518
+ this.setEmbedButtonEvents();
519
+ this.preparePreviousEmbeds();
520
+ },
521
+
522
+ insertButton : function (buttonLabels) {
523
+ var label = 'Embed';
524
+ if (buttonLabels === 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) {
525
+ label = '<i class="fa fa-code"></i>';
526
+ }
527
+
528
+ if (typeof buttonLabels === 'object' && buttonLabels.embed) {
529
+ label = buttonLabels.embed;
530
+ }
531
+
532
+ return '<button data-addon="embeds" data-action="add" class="medium-editor-action mediumInsert-action">' + label + '</button>';
533
+ },
534
+
535
+ /**
536
+ * Add embed to $placeholder
537
+ * @param {element} $placeholder $placeholder to add embed to
538
+ * @return {void}
539
+ */
540
+ add : function ($placeholder) {
541
+ $.fn.mediumInsert.insert.deselect();
542
+
543
+
544
+ var formHtml = '<div class="medium-editor-toolbar medium-editor-toolbar-active medium-editor-toolbar-form-anchor mediumInsert-embedsWire" style="display: block;"><input type="text" value="" placeholder="' + this.options.urlPlaceholder + '" class="mediumInsert-embedsText medium-editor-toolbar-anchor-input"></div>';
545
+ $(formHtml).appendTo($placeholder.prev());
546
+ setTimeout(function () {
547
+ $placeholder.prev().find('input').focus();
548
+ }, 50);
549
+
550
+ $.fn.mediumInsert.insert.deselect();
551
+
552
+ this.currentPlaceholder = $placeholder;
553
+ $(".mediumInsert-embedsText").focus();
554
+ },
555
+
556
+ /**
557
+ * Make existing embeds interactive
558
+ *
559
+ * @return {void}
560
+ */
561
+
562
+ preparePreviousEmbeds: function () {
563
+ this.$el.find('.mediumInsert-embeds').each(function() {
564
+ var $parent = $(this).parent();
565
+ if (!$parent.hasClass('mediumInsert-placeholder')) {
566
+ $parent.html('<div class="mediumInsert-placeholder" draggable="true">' + $parent.html() + '</div>');
567
+ }
568
+ });
569
+ },
570
+
571
+ setEmbedButtonEvents : function () {
572
+ var that = this;
573
+ $(document).on('keypress', 'input.mediumInsert-embedsText', function (e) {
574
+ if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
575
+ that.setEnterActionEvents();
576
+ that.removeToolbar();
577
+ }
578
+ });
579
+
580
+ this.$el
581
+ .on('blur', '.mediumInsert-embedsText', function () {
582
+ that.removeToolbar();
583
+ })
584
+ // Fix #72
585
+ // Workaround for CTRL+V not working in FF, when cleanPastedHTML and forcePlainText options on editor are set to true,
586
+ // because editor steals the event and doesn't pass it to the plugin
587
+ // https://github.com/orthes/medium-editor-insert-plugin/issues/72
588
+ .on('paste', '.mediumInsert-embedsText', function (e) {
589
+ if ($.fn.mediumInsert.insert.isFirefox && e.originalEvent.clipboardData) {
590
+ $(this).val(e.originalEvent.clipboardData.getData('text/plain'));
591
+ }
592
+ });
593
+
594
+ },
595
+ setEnterActionEvents : function () {
596
+ var that = this;
597
+ if ($.fn.mediumInsert.settings.enabled === false) {
598
+ return false;
599
+ }
600
+
601
+ var url = $("input.mediumInsert-embedsText").val();
602
+ if (!url) {
603
+ return false;
604
+ }
605
+
606
+ function processEmbedTag(embed_tag) {
607
+ if (!embed_tag) {
608
+ alert('Incorrect URL format specified');
609
+ return false;
610
+ } else {
611
+ var returnedTag = embed_tag;
612
+ var tagId = new Date().getTime();
613
+ embed_tag = $('<div class="mediumInsert-embeds" id="' + tagId + '"></div>').append(embed_tag);
614
+ that.currentPlaceholder.append(embed_tag);
615
+ that.currentPlaceholder.closest('[data-medium-element]').trigger('keyup').trigger('input');
616
+
617
+ if(returnedTag.indexOf("facebook") !== -1) {
618
+ if (typeof(FB) !== 'undefined') {
619
+ setTimeout(function() { FB.XFBML.parse();}, 2000);
620
+ }
621
+ }
622
+ }
623
+ }
624
+
625
+ if (this.options.oembedProxy) {
626
+ that.getOEmbedHTML(url, function(error, oebmed) {
627
+
628
+ var html = !error && oebmed && oebmed.html;
629
+
630
+ if (oebmed && !oebmed.html && oebmed.type === 'photo' && oebmed.url) {
631
+ html = '<img src="' + oebmed.url + '" />';
632
+ }
633
+
634
+ processEmbedTag(html);
635
+ });
636
+ } else {
637
+ var embed_tag = that.convertUrlToEmbedTag(url);
638
+ return processEmbedTag(embed_tag);
639
+ }
640
+
641
+ },
642
+
643
+ removeToolbar : function () {
644
+ $(".mediumInsert-embedsWire").remove();
645
+ },
646
+
647
+ getOEmbedHTML: function(url, cb) {
648
+ $.ajax({
649
+ url: this.options.oembedProxy,
650
+ dataType: "json",
651
+ data: {
652
+ url: url
653
+ },
654
+ success: function(data, textStatus, jqXHR) {
655
+ cb(null, data, jqXHR);
656
+ },
657
+ error: function(jqXHR, textStatus, errorThrown) {
658
+ var responseJSON = (function() {
659
+ try {
660
+ return JSON.parse(jqXHR.responseText);
661
+ } catch(e) {}
662
+ }());
663
+
664
+ cb((responseJSON && responseJSON.error) || jqXHR.status || errorThrown.message, responseJSON, jqXHR);
665
+ }
666
+ });
667
+ },
668
+
669
+ convertUrlToEmbedTag : function (url) {
670
+ // We didn't get something we expect so let's get out of here.
671
+ if (!(new RegExp(['youtube', 'yout.be', 'vimeo', 'facebook', 'instagram'].join("|")).test(url))) return false;
672
+
673
+ var embed_tag = url.replace(/\n?/g, '').replace(/^((http(s)?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|v\/)?)([a-zA-Z0-9\-_]+)(.*)?$/, '<div class="video"><iframe width="420" height="315" src="//www.youtube.com/embed/$7" frameborder="0" allowfullscreen></iframe></div>')
674
+ .replace(/^http:\/\/vimeo\.com(\/.+)?\/([0-9]+)$/, '<iframe src="//player.vimeo.com/video/$2" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>')
675
+ //.replace(/^https:\/\/twitter\.com\/(\w+)\/status\/(\d+)\/?$/, '<blockquote class="twitter-tweet" align="center" lang="en"><a href="https://twitter.com/$1/statuses/$2"></a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>')
676
+ .replace(/^https:\/\/www\.facebook\.com\/(video.php|photo.php)\?v=(\d+).+$/, '<div class="fb-post" data-href="https://www.facebook.com/photo.php?v=$2"><div class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/photo.php?v=$2">Post</a></div></div>')
677
+ .replace(/^http:\/\/instagram\.com\/p\/(.+)\/?$/, '<span class="instagram"><iframe src="//instagram.com/p/$1/embed/" width="612" height="710" frameborder="0" scrolling="no" allowtransparency="true"></iframe></span>');
678
+
679
+
680
+ return (/<("[^"]*"|'[^']*'|[^'">])*>/).test(embed_tag) ? embed_tag : false;
681
+ }
682
+
683
+ });
684
+
685
+ }(jQuery));
686
+
687
+ (function ($) {
688
+
689
+ $.fn.mediumInsert.registerAddon('images', {
690
+
691
+ /**
692
+ * Images default options
693
+ */
694
+
695
+ defaults: {
696
+ /**
697
+ * Active or inactive image's drag and drop
698
+ */
699
+ useDragAndDrop: true,
700
+
701
+ /**
702
+ * Relative path to a script that handles file uploads
703
+ */
704
+ imagesUploadScript: 'upload.php',
705
+
706
+ /**
707
+ * Relative path to a script that handles file deleting
708
+ */
709
+ imagesDeleteScript: 'delete.php',
710
+
711
+ /**
712
+ * Placeeholder text for inserting link
713
+ */
714
+ urlPlaceholder: 'Paste or type a link',
715
+
716
+ /**
717
+ * Format data before sending them to server while uploading an image
718
+ *
719
+ * @param {File} file File to upload
720
+ * @return {object} formData FormData instance
721
+ */
722
+ formatData: function (file) {
723
+ var formData = new FormData();
724
+ formData.append('file', file);
725
+ return formData;
726
+ },
727
+
728
+ /**
729
+ * Upload single file
730
+ *
731
+ * @param {element} $placeholder Placeholder to add image to
732
+ * @param {File} file File to upload
733
+ * @param {object} that Context
734
+ * @param {void}
735
+ */
736
+ uploadFile: function ($placeholder, file, that) {
737
+ $.ajax({
738
+ type: "post",
739
+ url: that.options.imagesUploadScript,
740
+ xhr: function () {
741
+ var xhr = new XMLHttpRequest();
742
+ xhr.upload.onprogress = that.updateProgressBar;
743
+ return xhr;
744
+ },
745
+ cache: false,
746
+ contentType: false,
747
+ complete: function (jqxhr) {
748
+ that.uploadCompleted(jqxhr, $placeholder);
749
+ },
750
+ processData: false,
751
+ data: that.options.formatData(file)
752
+ });
753
+ },
754
+
755
+ /**
756
+ * Makes ajax call for deleting a file on a server
757
+ *
758
+ * @param {string} file File name
759
+ * @param {object} that Context
760
+ * @return {void}
761
+ */
762
+ deleteFile: function (file, that) {
763
+ $.ajax({
764
+ type: "post",
765
+ url: that.options.imagesDeleteScript,
766
+ data: {
767
+ file: file
768
+ }
769
+ });
770
+ }
771
+ },
772
+
773
+
774
+ /**
775
+ * Images initial function
776
+ *
777
+ * @param {object} options Options to overide defaults
778
+ * @return {void}
779
+ */
780
+
781
+ init: function (options) {
782
+ if (options && options.$el) {
783
+ this.$el = options.$el;
784
+ }
785
+ this.options = $.extend(this.defaults, options);
786
+
787
+ this.setImageEvents();
788
+
789
+ if (this.options.useDragAndDrop === true){
790
+ this.setDragAndDropEvents();
791
+ }
792
+
793
+ this.preparePreviousImages();
794
+
795
+ },
796
+
797
+
798
+ /**
799
+ * Returns insert button
800
+ *
801
+ * @param {string} buttonLabels
802
+ * @return {string}
803
+ */
804
+
805
+ insertButton: function(buttonLabels){
806
+ var label = 'Img';
807
+ if (buttonLabels === 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) {
808
+ label = '<i class="fa fa-picture-o"></i>';
809
+ }
810
+
811
+ if (typeof buttonLabels === 'object' && buttonLabels.img) {
812
+ label = buttonLabels.img;
813
+ }
814
+
815
+ return '<button data-addon="images" data-action="add" class="medium-editor-action mediumInsert-action">'+label+'</button>';
816
+ },
817
+
818
+ /**
819
+ * Make existing images interactive
820
+ *
821
+ * @return {void}
822
+ */
823
+
824
+ preparePreviousImages: function () {
825
+ this.$el.find('.mediumInsert-images').each(function() {
826
+ var $parent = $(this).parent();
827
+ if (!$parent.hasClass('mediumInsert-placeholder')) {
828
+ $parent.html($.fn.mediumInsert.insert.getButtons('images') +
829
+ '<div class="mediumInsert-placeholder" draggable="true">' + $parent.html() + '</div>'
830
+ );
831
+ }
832
+ });
833
+ },
834
+
835
+ /**
836
+ * Add image to placeholder
837
+ *
838
+ * @param {element} $placeholder Placeholder to add image to
839
+ * @return {element} $selectFile <input type="file"> element
840
+ */
841
+
842
+ add: function ($placeholder) {
843
+ var that = this,
844
+ $selectFile, files;
845
+
846
+ $selectFile = $('<input type="file" multiple="multiple">').click();
847
+ $selectFile.change(function () {
848
+ files = this.files;
849
+ that.uploadFiles($placeholder, files, that);
850
+ });
851
+
852
+ $.fn.mediumInsert.insert.deselect();
853
+
854
+ return $selectFile;
855
+ },
856
+
857
+ /**
858
+ * Update progressbar while upload
859
+ *
860
+ * @param {event} e XMLHttpRequest.upload.onprogress event
861
+ * @return {void}
862
+ */
863
+
864
+ updateProgressBar: function (e) {
865
+ var $progress = $('.progress:first', this.$el),
866
+ complete;
867
+
868
+ if (e.lengthComputable) {
869
+ complete = e.loaded / e.total * 100;
870
+ complete = complete ? complete : 0;
871
+ $progress.attr('value', complete);
872
+ $progress.html(complete);
873
+ }
874
+ },
875
+
876
+ /**
877
+ * Show uploaded image after upload completed
878
+ *
879
+ * @param {jqXHR} jqxhr jqXHR object
880
+ * @return {void}
881
+ */
882
+
883
+ uploadCompleted: function (jqxhr, $placeholder) {
884
+ var $progress = $('.progress:first', $placeholder),
885
+ $img;
886
+
887
+ $progress.attr('value', 100);
888
+ $progress.html(100);
889
+
890
+ if (jqxhr.responseText) {
891
+ $progress.before('<figure class="mediumInsert-images"><img src="'+ jqxhr.responseText +'" draggable="true" alt=""></figure>');
892
+ $img = $progress.siblings('img');
893
+
894
+ $img.load(function () {
895
+ $img.parent().mouseleave().mouseenter();
896
+ });
897
+ } else {
898
+ $progress.before('<div class="mediumInsert-error">There was a problem uploading the file.</div>');
899
+
900
+ setTimeout(function () {
901
+ $('.mediumInsert-error:first', $placeholder).fadeOut(function () {
902
+ $(this).remove();
903
+ });
904
+ }, 3000);
905
+ }
906
+
907
+ $progress.remove();
908
+
909
+ $placeholder.closest('[data-medium-element]').trigger('keyup').trigger('input');
910
+ },
911
+
912
+ /**
913
+ * Upload single file
914
+ *
915
+ * @param {element} $placeholder Placeholder to add image to
916
+ * @param {File} file File to upload
917
+ * @param {object} that Context
918
+ * @param {void}
919
+ */
920
+
921
+ uploadFile: function ($placeholder, file, that) {
922
+ return that.options.uploadFile($placeholder, file, that);
923
+ },
924
+
925
+ /**
926
+ * Lopp though files, check file types and call uploadFile() function on each file that passes
927
+ *
928
+ * @param {element} placeholder Placeholder to add image to
929
+ * @param {FileList} files Files to upload
930
+ * @param {object} that Context
931
+ * @return {void}
932
+ */
933
+
934
+ uploadFiles: function ($placeholder, files, that) {
935
+ var acceptedTypes = {
936
+ 'image/png': true,
937
+ 'image/jpeg': true,
938
+ 'image/gif': true
939
+ };
940
+
941
+ for (var i = 0; i < files.length; i++) {
942
+ var file = files[i];
943
+
944
+ if (acceptedTypes[file.type] === true) {
945
+ $placeholder.append('<progress class="progress" min="0" max="100" value="0">0</progress>');
946
+
947
+ that.uploadFile($placeholder, file, that);
948
+ }
949
+ }
950
+ },
951
+
952
+ /**
953
+ * Makes ajax call for deleting a file on a server
954
+ *
955
+ * @param {string} file File name
956
+ * @param {object} that Context
957
+ * @return {void}
958
+ */
959
+
960
+ deleteFile: function (file, that) {
961
+ return that.options.deleteFile(file, that);
962
+ },
963
+
964
+ /**
965
+ * Set image events displaying remove and resize buttons
966
+ *
967
+ * @return {void}
968
+ */
969
+
970
+ setImageEvents: function () {
971
+ var that = this;
972
+
973
+ this.$el.on('mouseenter', '.mediumInsert-images', function () {
974
+ var $img = $('img', this),
975
+ positionTop,
976
+ positionLeft;
977
+
978
+ if ($.fn.mediumInsert.settings.enabled === false) {
979
+ return;
980
+ }
981
+
982
+ if ($img.length > 0) {
983
+ $(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageRemove"></a>');
984
+
985
+ if ($(this).prevAll().length === 0) {
986
+ if ($(this).parent().parent().hasClass('small')) {
987
+ $(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageResizeBigger"></a>');
988
+ } else {
989
+ $(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageResizeSmaller"></a>');
990
+ }
991
+ }
992
+
993
+ if ($(this).siblings().length === 0) {
994
+ if ($img.parent().is('a')) {
995
+ $(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageUnlink"></a>');
996
+ } else {
997
+ $(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageLink"></a>');
998
+ }
999
+ }
1000
+
1001
+ positionTop = $img.position().top + parseInt($img.css('margin-top'), 10);
1002
+ positionLeft = $img.position().left + $img.width() -30;
1003
+ $('.mediumInsert-imageRemove', this).css({
1004
+ 'right': 'auto',
1005
+ 'top': positionTop,
1006
+ 'left': positionLeft
1007
+ });
1008
+ $('.mediumInsert-imageResizeBigger, .mediumInsert-imageResizeSmaller', this).css({
1009
+ 'right': 'auto',
1010
+ 'top': positionTop,
1011
+ 'left': positionLeft-31
1012
+ });
1013
+ $('.mediumInsert-imageLink, .mediumInsert-imageUnlink', this).css({
1014
+ 'right': 'auto',
1015
+ 'top': positionTop,
1016
+ 'left': positionLeft-62
1017
+ });
1018
+ }
1019
+ });
1020
+
1021
+ this.$el.on('mouseleave', '.mediumInsert-images', function () {
1022
+ $('.mediumInsert-imageIcon', this).remove();
1023
+ });
1024
+
1025
+ this.$el.on('click', '.mediumInsert-imageResizeSmaller', function () {
1026
+ $(this).parent().parent().parent().addClass('small');
1027
+ $(this).parent().mouseleave().mouseleave();
1028
+
1029
+ $.fn.mediumInsert.insert.deselect();
1030
+ that.$el.trigger('keyup').trigger('input');
1031
+ });
1032
+
1033
+ this.$el.on('click', '.mediumInsert-imageResizeBigger', function () {
1034
+ $(this).parent().parent().parent().removeClass('small');
1035
+ $(this).parent().mouseleave().mouseleave();
1036
+
1037
+ $.fn.mediumInsert.insert.deselect();
1038
+ that.$el.trigger('keyup').trigger('input');
1039
+ });
1040
+
1041
+ this.$el.on('click', '.mediumInsert-imageRemove', function () {
1042
+ var img = $(this).siblings('img').attr('src');
1043
+
1044
+ if ($(this).parent().siblings().length === 0) {
1045
+ $(this).parent().parent().parent().removeClass('small');
1046
+ }
1047
+ $(this).parent().remove();
1048
+
1049
+ that.deleteFile(img, that);
1050
+
1051
+ $.fn.mediumInsert.insert.deselect();
1052
+
1053
+ that.$el.trigger('keyup').trigger('input');
1054
+ });
1055
+
1056
+ this.$el.on('click', '.mediumInsert-imageLink', function () {
1057
+ var $placeholder = $(this).closest('.mediumInsert-placeholder'),
1058
+ $formHtml = $('<div class="medium-editor-toolbar medium-editor-toolbar-active medium-editor-toolbar-form-anchor mediumInsert-imageLinkWire" style="display: block;"><input type="text" value="" placeholder="' + that.options.urlPlaceholder + '" class="mediumInsert-imageLinkText medium-editor-toolbar-anchor-input"></div>');
1059
+
1060
+ $formHtml.appendTo($placeholder);
1061
+ setTimeout(function () {
1062
+ $formHtml.find('input').focus();
1063
+ }, 50);
1064
+
1065
+ $.fn.mediumInsert.insert.deselect();
1066
+ });
1067
+
1068
+ this.$el.on('click', '.mediumInsert-imageUnlink', function () {
1069
+ var $figure = $(this).closest('.mediumInsert-images');
1070
+
1071
+ $figure.find('img').unwrap();
1072
+
1073
+ $(this).removeClass('mediumInsert-imageUnlink')
1074
+ .addClass('mediumInsert-imageLink');
1075
+
1076
+ that.$el.trigger('keyup').trigger('input');
1077
+ });
1078
+
1079
+ this.$el
1080
+ .on('keypress', '.mediumInsert-imageLinkText', function (e) {
1081
+ var $placeholder = $(this).closest('.mediumInsert-placeholder');
1082
+
1083
+ if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
1084
+ $placeholder.find('.mediumInsert-images:first').find('img').wrap('<a href="'+ $(this).val() +'" target="_blank"></a>');
1085
+ $placeholder.find('.mediumInsert-imageLink')
1086
+ .removeClass('mediumInsert-imageLink')
1087
+ .addClass('mediumInsert-imageUnlink');
1088
+
1089
+ // Workaround for "Uncaught NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is no longer a child of this node. Perhaps it was moved in a 'blur' event handler?"
1090
+ try {
1091
+ $('.mediumInsert-imageLinkWire').remove();
1092
+ } catch(err) {}
1093
+
1094
+ that.$el.trigger('keyup').trigger('input');
1095
+ }
1096
+ })
1097
+ .on('blur', '.mediumInsert-imageLinkText', function () {
1098
+ $('.mediumInsert-imageLinkWire').remove();
1099
+ })
1100
+ .on('paste', '.mediumInsert-imageLinkText', function (e) {
1101
+ if ($.fn.mediumInsert.insert.isFirefox && e.originalEvent.clipboardData) {
1102
+ $(this).val(e.originalEvent.clipboardData.getData('text/plain'));
1103
+ }
1104
+ });
1105
+ },
1106
+
1107
+ /**
1108
+ * Set drag and drop events
1109
+ *
1110
+ * @return {void}
1111
+ */
1112
+
1113
+ setDragAndDropEvents: function () {
1114
+ var that = this,
1115
+ dropSuccessful = false,
1116
+ dropSort = false,
1117
+ dropSortIndex, dropSortParent;
1118
+
1119
+ $(document).on('dragover', 'body', function () {
1120
+ if ($.fn.mediumInsert.settings.enabled === false) {
1121
+ return;
1122
+ }
1123
+
1124
+ that.$el.addClass('hover');
1125
+ });
1126
+
1127
+ $(document).on('dragend', 'body', function () {
1128
+ if ($.fn.mediumInsert.settings.enabled === false) {
1129
+ return;
1130
+ }
1131
+
1132
+ that.$el.removeClass('hover');
1133
+ });
1134
+
1135
+ this.$el.on('dragover', '.mediumInsert', function () {
1136
+ if ($.fn.mediumInsert.settings.enabled === false) {
1137
+ return;
1138
+ }
1139
+
1140
+ $(this).addClass('hover');
1141
+ $(this).attr('contenteditable', true);
1142
+ });
1143
+
1144
+ this.$el.on('dragleave', '.mediumInsert', function () {
1145
+ if ($.fn.mediumInsert.settings.enabled === false) {
1146
+ return;
1147
+ }
1148
+
1149
+ $(this).removeClass('hover');
1150
+ $(this).attr('contenteditable', false);
1151
+ });
1152
+
1153
+ this.$el.on('dragstart', '.mediumInsert .mediumInsert-images img', function () {
1154
+ if ($.fn.mediumInsert.settings.enabled === false) {
1155
+ return;
1156
+ }
1157
+
1158
+ dropSortIndex = $(this).parent().index();
1159
+ dropSortParent = $(this).parent().parent().parent().attr('id');
1160
+ });
1161
+
1162
+ this.$el.on('dragend', '.mediumInsert .mediumInsert-images img', function (e) {
1163
+ if ($.fn.mediumInsert.settings.enabled === false) {
1164
+ return;
1165
+ }
1166
+
1167
+ if (dropSuccessful === true) {
1168
+ if ($(e.originalEvent.target.parentNode).siblings().length === 0) {
1169
+ $(e.originalEvent.target.parentNode).parent().parent().removeClass('small');
1170
+ }
1171
+ $(e.originalEvent.target.parentNode).mouseleave();
1172
+ $(e.originalEvent.target.parentNode).remove();
1173
+ dropSuccessful = false;
1174
+ dropSort = false;
1175
+
1176
+ that.$el.trigger('keyup').trigger('input');
1177
+ }
1178
+ });
1179
+
1180
+ this.$el.on('dragover', '.mediumInsert .mediumInsert-images img', function (e) {
1181
+ if ($.fn.mediumInsert.settings.enabled === false) {
1182
+ return;
1183
+ }
1184
+
1185
+ e.preventDefault();
1186
+ });
1187
+
1188
+ this.$el.on('drop', '.mediumInsert .mediumInsert-images img', function () {
1189
+ var index, $dragged, finalIndex;
1190
+
1191
+ if ($.fn.mediumInsert.settings.enabled === false) {
1192
+ return;
1193
+ }
1194
+
1195
+
1196
+ if (dropSortParent !== $(this).parent().parent().parent().attr('id')) {
1197
+ dropSort = false;
1198
+ dropSortIndex = dropSortParent = null;
1199
+ return;
1200
+ }
1201
+
1202
+ index = parseInt(dropSortIndex, 10);
1203
+
1204
+ // Sort
1205
+ $dragged = $(this).parent().parent().find('.mediumInsert-images:nth-child('+ (index+1) +')');
1206
+ finalIndex = $(this).parent().index();
1207
+ if(index < finalIndex) {
1208
+ $dragged.insertAfter($(this).parent());
1209
+ } else if(index > finalIndex) {
1210
+ $dragged.insertBefore($(this).parent());
1211
+ }
1212
+
1213
+ $dragged.mouseleave();
1214
+
1215
+ dropSort = true;
1216
+ dropSortIndex = null;
1217
+
1218
+ that.$el.trigger('keyup').trigger('input');
1219
+ });
1220
+
1221
+ this.$el.on('drop', '.mediumInsert', function (e) {
1222
+ var files;
1223
+
1224
+ e.preventDefault();
1225
+
1226
+ if ($.fn.mediumInsert.settings.enabled === false) {
1227
+ return;
1228
+ }
1229
+
1230
+ $(this).removeClass('hover');
1231
+ that.$el.removeClass('hover');
1232
+ $(this).attr('contenteditable', false);
1233
+
1234
+ files = e.originalEvent.dataTransfer.files;
1235
+ if (files.length > 0) {
1236
+ // File upload
1237
+ that.uploadFiles($('.mediumInsert-placeholder', this), files, that);
1238
+ } else if (dropSort === true) {
1239
+ dropSort = false;
1240
+ } else {
1241
+ // Image move from block to block
1242
+ $('.mediumInsert-placeholder', this).append('<figure class="mediumInsert-images">'+ e.originalEvent.dataTransfer.getData('text/html') +'</figure>');
1243
+ $('meta', this).remove();
1244
+ dropSuccessful = true;
1245
+ }
1246
+ });
1247
+ }
1248
+ });
1249
+ }(jQuery));
1250
+
1251
+ (function ($) {
1252
+
1253
+ $.fn.mediumInsert.registerAddon('maps', {
1254
+
1255
+ /**
1256
+ * Maps initial function
1257
+ * @return {void}
1258
+ */
1259
+
1260
+ init: function () {
1261
+ this.$el = $.fn.mediumInsert.insert.$el;
1262
+ },
1263
+
1264
+ insertButton: function(buttonLabels){
1265
+ var label = 'Map';
1266
+ if (buttonLabels === 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) {
1267
+ label = '<i class="fa fa-map-marker"></i>';
1268
+ }
1269
+
1270
+ if (typeof buttonLabels === 'object' && buttonLabels.map) {
1271
+ label = buttonLabels.map;
1272
+ }
1273
+
1274
+ return '<button data-addon="maps" data-action="add" class="medium-editor-action mediumInsert-action">'+label+'</button>';
1275
+ },
1276
+
1277
+ /**
1278
+ * Add map to placeholder
1279
+ * @param {element} placeholder Placeholder to add map to
1280
+ * @return {void}
1281
+ */
1282
+
1283
+ add: function (placeholder) {
1284
+ $.fn.mediumInsert.insert.deselect();
1285
+
1286
+ placeholder.append('<div class="mediumInsert-maps">Map - Coming soon...</div>');
1287
+ }
1288
+
1289
+ });
1290
+
1291
+ }(jQuery));
1292
+
1293
+ (function ($) {
1294
+
1295
+ $.fn.mediumInsert.registerAddon('tables', {
1296
+
1297
+ /**
1298
+ * Table default options
1299
+ */
1300
+
1301
+ defaults: {
1302
+ defaultRows: 2,
1303
+ defaultCols: 2
1304
+ },
1305
+
1306
+ /**
1307
+ * Tables initial function
1308
+ * @return {void}
1309
+ */
1310
+ init : function (options) {
1311
+ this.options = $.extend(this.defaults, options);
1312
+ this.$el = $.fn.mediumInsert.insert.$el;
1313
+ this.setTableButtonEvents();
1314
+ },
1315
+
1316
+ insertButton : function (buttonLabels) {
1317
+ var label = 'Table';
1318
+ if (buttonLabels === 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) {
1319
+ label = '<i class="fa fa-table"></i>';
1320
+ }
1321
+
1322
+ if (typeof buttonLabels === 'object' && buttonLabels.table) {
1323
+ label = buttonLabels.table;
1324
+ }
1325
+
1326
+ return '<button data-addon="tables" data-action="add" class="medium-editor-action mediumInsert-action">' + label + '</button>';
1327
+ },
1328
+
1329
+ /**
1330
+ * Add table to $placeholder
1331
+ * @param {element} $placeholder $placeholder to add embed to
1332
+ * @return {void}
1333
+ */
1334
+ add : function ($placeholder) {
1335
+ $.fn.mediumInsert.insert.deselect();
1336
+
1337
+ var formHtml = '<div class="medium-editor-toolbar-form-anchor mediumInsert-tableDemoBox"><table><tr><td></td><td><label>cols:<input type="text" value="' + this.options.defaultCols + '" class="mediumInsert-tableCols" /></label></td></tr><tr><td><label>rows:<input type="text" value="' + this.options.defaultRows + '" class="mediumInsert-tableRows" /></label></td><td><table class="mediumInsert-demoTable"></table></td></tr><tr><td></td><td><label><button class="mediumInsert-tableReadyButton">insert</button></label></td></tr></table></</div>';
1338
+ $(formHtml).appendTo($placeholder.prev());
1339
+ this.updateDemoTable();
1340
+
1341
+ setTimeout(function () {
1342
+ $placeholder.prev().find('input').focus();
1343
+ }, 50);
1344
+
1345
+ $.fn.mediumInsert.insert.deselect();
1346
+ this.currentPlaceholder = $placeholder;
1347
+ },
1348
+
1349
+ setTableButtonEvents : function () {
1350
+ var that = this;
1351
+
1352
+ $(document).on('keyup',
1353
+ 'input.mediumInsert-tableRows, input.mediumInsert-tableCols',
1354
+ function() { that.updateDemoTable(); });
1355
+
1356
+ $(document).on('click', function(e) {
1357
+ if ($(e.target).parents('.mediumInsert-buttons').length === 0) {
1358
+ that.removeToolbar();
1359
+ }
1360
+ });
1361
+
1362
+ $(document).on('click', 'button.mediumInsert-tableReadyButton', function() {
1363
+ that.setEnterActionEvents();
1364
+ that.removeToolbar();
1365
+ });
1366
+ },
1367
+
1368
+ getDimensions : function () {
1369
+ return {
1370
+ rows: parseFloat($('input.mediumInsert-tableRows').val()) || 1,
1371
+ cols: parseFloat($('input.mediumInsert-tableCols').val()) || 1
1372
+ };
1373
+ },
1374
+
1375
+ buildTable : function (table) {
1376
+ var i, j, $row,
1377
+ dimensions = this.getDimensions(),
1378
+ $table = $(table);
1379
+
1380
+ for (i = 0; i < dimensions.rows; i++) {
1381
+ $row = $('<tr>');
1382
+ for (j = 0; j < dimensions.cols; j++) {
1383
+ $row.append('<td>');
1384
+ }
1385
+ $table.append($row);
1386
+ }
1387
+ },
1388
+
1389
+ updateDemoTable : function () {
1390
+ var $demoTable = $('table.mediumInsert-demoTable');
1391
+
1392
+ $demoTable.empty();
1393
+ this.buildTable($demoTable);
1394
+ },
1395
+
1396
+ setEnterActionEvents : function () {
1397
+ var that = this;
1398
+ if ($.fn.mediumInsert.settings.enabled === false) {
1399
+ return false;
1400
+ }
1401
+
1402
+ var $table = $('<table class="mediumInsert-table">');
1403
+ that.buildTable($table);
1404
+
1405
+ that.currentPlaceholder.append($table);
1406
+ that.currentPlaceholder.closest('[data-medium-element]').trigger('keyup').trigger('input');
1407
+ },
1408
+
1409
+ removeToolbar : function () {
1410
+ $(".mediumInsert-tableDemoBox").remove();
1411
+ }
1412
+
1413
+ });
1414
+
1415
+ }(jQuery));