georgia 0.7.8 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (315) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +60 -16
  4. data/Rakefile +17 -10
  5. data/app/assets/images/georgia/arrow.png +0 -0
  6. data/app/assets/images/georgia/close.png +0 -0
  7. data/app/assets/javascripts/georgia/application.js +3 -6
  8. data/app/assets/javascripts/georgia/bootstrap-vendor.js.coffee +1 -1
  9. data/app/assets/javascripts/georgia/ckeditor/config.js +1 -1
  10. data/app/assets/javascripts/georgia/components/flash.js.coffee +1 -1
  11. data/app/assets/javascripts/georgia/components/media-library.js.coffee +1 -1
  12. data/app/assets/javascripts/georgia/components/tables.js.coffee +30 -0
  13. data/app/assets/javascripts/georgia/components/tables/{checkbox.js.coffee → checkboxable.js.coffee} +10 -39
  14. data/app/assets/javascripts/georgia/components/tables/media.js.coffee +17 -29
  15. data/app/assets/javascripts/georgia/components/tables/pages.js.coffee +26 -44
  16. data/app/assets/javascripts/georgia/components/tags.js.coffee +13 -24
  17. data/app/assets/javascripts/georgia/vendor/ekko-lightbox.min.js +7 -0
  18. data/app/assets/javascripts/georgia/vendor/textext.core.js +1618 -0
  19. data/app/assets/javascripts/georgia/vendor/textext.plugin.ajax.js +354 -0
  20. data/app/assets/javascripts/georgia/vendor/textext.plugin.arrow.js +106 -0
  21. data/app/assets/javascripts/georgia/vendor/textext.plugin.autocomplete.js +1110 -0
  22. data/app/assets/javascripts/georgia/vendor/textext.plugin.clear.js +116 -0
  23. data/app/assets/javascripts/georgia/vendor/textext.plugin.filter.js +242 -0
  24. data/app/assets/javascripts/georgia/vendor/textext.plugin.focus.js +174 -0
  25. data/app/assets/javascripts/georgia/vendor/textext.plugin.prompt.js +309 -0
  26. data/app/assets/javascripts/georgia/vendor/textext.plugin.suggestions.js +175 -0
  27. data/app/assets/javascripts/georgia/vendor/textext.plugin.tags.js +698 -0
  28. data/app/assets/stylesheets/georgia/application.css.scss +71 -12
  29. data/app/assets/stylesheets/georgia/components/_button.scss +3 -20
  30. data/app/assets/stylesheets/georgia/components/_label.scss +36 -1
  31. data/app/assets/stylesheets/georgia/components/_portlet.scss +4 -1
  32. data/app/assets/stylesheets/georgia/components/_status.scss +9 -0
  33. data/app/assets/stylesheets/georgia/components/_table.scss +7 -0
  34. data/app/assets/stylesheets/georgia/layout/_base.scss +22 -5
  35. data/app/assets/stylesheets/georgia/layout/_print.scss +8 -0
  36. data/app/assets/stylesheets/georgia/modules/_activities.scss +3 -0
  37. data/app/assets/stylesheets/georgia/modules/_footer.scss +3 -1
  38. data/app/assets/stylesheets/georgia/modules/_form_with_helpers.scss +2 -2
  39. data/app/assets/stylesheets/georgia/modules/_header.scss +4 -13
  40. data/app/assets/stylesheets/georgia/modules/_link.scss +6 -1
  41. data/app/assets/stylesheets/georgia/modules/_login.scss +7 -0
  42. data/app/assets/stylesheets/georgia/modules/_media.scss +10 -0
  43. data/app/assets/stylesheets/georgia/modules/_navigation.scss +5 -0
  44. data/app/assets/stylesheets/georgia/modules/_pages.scss +3 -0
  45. data/app/assets/stylesheets/georgia/modules/_results.scss +11 -4
  46. data/app/assets/stylesheets/georgia/modules/_sidebar.scss +6 -21
  47. data/app/assets/stylesheets/georgia/modules/_users.scss +3 -0
  48. data/app/assets/stylesheets/georgia/overrides/_flatly.scss +16 -0
  49. data/app/assets/stylesheets/georgia/overrides/_textext.scss +54 -0
  50. data/app/assets/stylesheets/georgia/settings/_base.scss +1 -1
  51. data/app/assets/stylesheets/georgia/settings/_colors.scss +31 -1
  52. data/app/assets/stylesheets/georgia/settings/_z-index.scss +2 -2
  53. data/app/assets/stylesheets/georgia/vendor/_bootswatch-flatly-theme.scss +7 -0
  54. data/app/assets/stylesheets/georgia/vendor/_ekko-lightbox.min.scss +6 -0
  55. data/app/assets/stylesheets/georgia/vendor/_select2_bootstrap.scss +497 -0
  56. data/app/assets/stylesheets/georgia/vendor/_textext.core.scss +29 -0
  57. data/app/assets/stylesheets/georgia/vendor/_textext.plugin.arrow.scss +13 -0
  58. data/app/assets/stylesheets/georgia/vendor/_textext.plugin.autocomplete.scss +35 -0
  59. data/app/assets/stylesheets/georgia/vendor/_textext.plugin.clear.scss +13 -0
  60. data/app/assets/stylesheets/georgia/vendor/_textext.plugin.focus.scss +12 -0
  61. data/app/assets/stylesheets/georgia/vendor/_textext.plugin.prompt.scss +16 -0
  62. data/app/assets/stylesheets/georgia/vendor/_textext.plugin.tags.scss +49 -0
  63. data/app/controllers/georgia/api/media_controller.rb +4 -2
  64. data/app/controllers/georgia/api/tags_controller.rb +10 -7
  65. data/app/controllers/georgia/application_controller.rb +17 -2
  66. data/app/controllers/georgia/concerns/frontendable.rb +2 -3
  67. data/app/controllers/georgia/dashboard_controller.rb +5 -7
  68. data/app/controllers/georgia/links_controller.rb +1 -0
  69. data/app/controllers/georgia/media_controller.rb +50 -41
  70. data/app/controllers/georgia/menus_controller.rb +16 -6
  71. data/app/controllers/georgia/pages_controller.rb +98 -58
  72. data/app/controllers/georgia/revisions_controller.rb +120 -24
  73. data/app/controllers/georgia/ui_associations_controller.rb +1 -0
  74. data/app/controllers/georgia/users_controller.rb +31 -11
  75. data/app/controllers/georgia/widgets_controller.rb +13 -4
  76. data/app/helpers/georgia/application_helper.rb +4 -0
  77. data/app/helpers/georgia/forms_helper.rb +2 -2
  78. data/app/helpers/georgia/ui_helper.rb +78 -12
  79. data/app/helpers/georgia/users_helper.rb +21 -0
  80. data/app/mailers/georgia/notifier.rb +4 -4
  81. data/app/models/ckeditor/asset.rb +16 -4
  82. data/app/models/ckeditor/asset_search.rb +15 -0
  83. data/app/models/ckeditor/attachment_file.rb +7 -0
  84. data/app/models/ckeditor/picture.rb +10 -0
  85. data/app/models/georgia/clone.rb +3 -1
  86. data/app/models/georgia/concerns/contentable.rb +2 -3
  87. data/app/models/georgia/concerns/searchable.rb +32 -0
  88. data/app/models/georgia/concerns/taggable.rb +2 -2
  89. data/app/models/georgia/concerns/treeable.rb +0 -1
  90. data/app/models/georgia/content.rb +1 -3
  91. data/app/models/georgia/dashboard.rb +7 -0
  92. data/app/models/georgia/link.rb +10 -3
  93. data/app/models/georgia/menu.rb +4 -4
  94. data/app/models/georgia/page.rb +75 -10
  95. data/app/models/georgia/revision.rb +10 -5
  96. data/app/models/georgia/role.rb +5 -5
  97. data/app/models/georgia/role_assignment.rb +8 -0
  98. data/app/models/georgia/slide.rb +4 -4
  99. data/app/models/georgia/status.rb +3 -5
  100. data/app/models/georgia/ui_association.rb +3 -5
  101. data/app/models/georgia/ui_section.rb +1 -1
  102. data/app/models/georgia/user.rb +5 -14
  103. data/app/models/georgia/widget.rb +3 -3
  104. data/app/policies/georgia/api_policy.rb +13 -0
  105. data/app/policies/georgia/application_policy.rb +30 -0
  106. data/app/policies/georgia/concerns/content_policy.rb +56 -0
  107. data/app/policies/georgia/concerns/publishing_policy.rb +52 -0
  108. data/app/policies/georgia/dashboard_policy.rb +19 -0
  109. data/app/policies/georgia/media_policy.rb +56 -0
  110. data/app/policies/georgia/navigation_policy.rb +42 -0
  111. data/app/policies/georgia/page_policy.rb +26 -0
  112. data/app/policies/georgia/revision_policy.rb +7 -44
  113. data/app/policies/georgia/ui_association_policy.rb +4 -0
  114. data/app/policies/georgia/user_policy.rb +46 -0
  115. data/app/policies/georgia/widget_policy.rb +42 -0
  116. data/app/presenters/georgia/active_facet_presenter.rb +2 -1
  117. data/app/presenters/georgia/link_portlet.rb +2 -2
  118. data/app/presenters/georgia/pagination_presenter.rb +45 -7
  119. data/app/presenters/georgia/permission_table_presenter.rb +80 -0
  120. data/app/presenters/georgia/revision_status_message.rb +73 -0
  121. data/app/presenters/georgia/sidebar_link_presenter.rb +1 -1
  122. data/app/presenters/georgia/slide_portlet.rb +5 -1
  123. data/app/routes/georgia/pageable_route_concern.rb +35 -0
  124. data/app/searches/georgia/media_search.rb +39 -0
  125. data/app/searches/georgia/page_search.rb +47 -0
  126. data/app/searches/georgia/search_definition.rb +72 -0
  127. data/app/searches/georgia/tag_search.rb +32 -0
  128. data/app/services/georgia/clone_revision.rb +71 -0
  129. data/app/services/georgia/compress_files.rb +49 -0
  130. data/app/services/georgia/copy_page.rb +100 -0
  131. data/app/services/georgia/create_activity.rb +16 -0
  132. data/app/services/georgia/create_media_asset.rb +53 -0
  133. data/app/services/georgia/parse_json_tags.rb +21 -0
  134. data/app/services/georgia/update_revision.rb +52 -0
  135. data/app/views/georgia/api/media/pictures.html.erb +1 -1
  136. data/app/views/georgia/ckeditor/assets/_asset.html.erb +2 -4
  137. data/app/views/georgia/ckeditor/pictures/_picture.html.erb +1 -6
  138. data/app/views/georgia/dashboard/panels/_messages.html.erb +26 -28
  139. data/app/views/georgia/dashboard/panels/_reviews.html.erb +23 -22
  140. data/app/views/georgia/dashboard/show.html.erb +9 -3
  141. data/app/views/georgia/header/_media.html.erb +2 -2
  142. data/app/views/georgia/header/_navigation.html.erb +3 -3
  143. data/app/views/georgia/header/_pages.html.erb +3 -3
  144. data/app/views/georgia/header/_users.html.erb +2 -2
  145. data/app/views/georgia/header/_widgets.html.erb +1 -1
  146. data/app/views/georgia/media/_header.html.erb +4 -2
  147. data/app/views/georgia/media/create.js.erb +1 -0
  148. data/app/views/georgia/media/destroy.js.erb +3 -0
  149. data/app/views/georgia/media/edit.html.erb +35 -30
  150. data/app/views/georgia/media/search.html.erb +2 -2
  151. data/app/views/georgia/menus/index.html.erb +1 -1
  152. data/app/views/georgia/pages/_header.html.erb +4 -4
  153. data/app/views/georgia/pages/_page.html.erb +1 -1
  154. data/app/views/georgia/pages/search.html.erb +4 -5
  155. data/app/views/georgia/pages/settings.html.erb +72 -61
  156. data/app/views/georgia/revisions/_revision.html.erb +12 -7
  157. data/app/views/georgia/revisions/edit.html.erb +17 -11
  158. data/app/views/georgia/revisions/fields/_content.html.erb +1 -2
  159. data/app/views/georgia/revisions/fields/_message.html.erb +11 -0
  160. data/app/views/georgia/revisions/fields/_ui_section.html.erb +1 -1
  161. data/app/views/georgia/revisions/fields/_widgets.html.erb +1 -1
  162. data/app/views/georgia/revisions/index.html.erb +2 -2
  163. data/app/views/georgia/revisions/messages/_awaiting_review.html.erb +15 -0
  164. data/app/views/georgia/revisions/messages/_continue_draft.html.erb +8 -0
  165. data/app/views/georgia/revisions/messages/_edit_current_revision.html.erb +12 -0
  166. data/app/views/georgia/revisions/messages/_insufficient_rights.html.erb +6 -0
  167. data/app/views/georgia/revisions/messages/_request_review.html.erb +7 -0
  168. data/app/views/georgia/revisions/messages/_review.html.erb +7 -0
  169. data/app/views/georgia/revisions/messages/_start_draft.html.erb +4 -0
  170. data/app/views/georgia/revisions/panels/_actions.html.erb +7 -0
  171. data/app/views/georgia/revisions/panels/_activities.html.erb +6 -0
  172. data/app/views/georgia/revisions/panels/_drafts.html.erb +28 -0
  173. data/app/views/georgia/revisions/panels/_info.html.erb +39 -0
  174. data/app/views/georgia/shared/modals/_media_library.html.erb +3 -1
  175. data/app/views/georgia/shared/search/_messages.html.erb +1 -1
  176. data/app/views/georgia/users/_form.html.erb +17 -2
  177. data/app/views/georgia/users/_user.html.erb +1 -1
  178. data/app/views/georgia/users/edit.html.erb +0 -1
  179. data/app/views/georgia/users/index.html.erb +1 -1
  180. data/app/views/georgia/users/permissions.html.erb +15 -0
  181. data/app/views/georgia/users/sessions/new.html.erb +3 -3
  182. data/app/views/layouts/georgia/_footer.html.erb +1 -3
  183. data/app/views/layouts/georgia/_head.html.erb +3 -4
  184. data/app/views/layouts/georgia/_header.html.erb +8 -10
  185. data/app/views/public_activity/_default.html.erb +15 -0
  186. data/app/views/public_activity/georgia_page/_copy.html.erb +15 -0
  187. data/app/views/public_activity/georgia_page/_create.html.erb +15 -0
  188. data/app/views/public_activity/georgia_page/_decline.html.erb +15 -0
  189. data/app/views/public_activity/georgia_page/_publish.html.erb +15 -0
  190. data/app/views/public_activity/georgia_page/_unpublish.html.erb +15 -0
  191. data/app/views/public_activity/georgia_page/_update.html.erb +15 -0
  192. data/app/views/public_activity/georgia_revision/_approve.html.erb +15 -0
  193. data/app/views/public_activity/georgia_revision/_decline.html.erb +15 -0
  194. data/app/views/public_activity/georgia_revision/_draft.html.erb +15 -0
  195. data/app/views/public_activity/georgia_revision/_restore.html.erb +15 -0
  196. data/app/views/public_activity/georgia_revision/_review.html.erb +15 -0
  197. data/app/views/public_activity/georgia_revision/_update.html.erb +15 -0
  198. data/config/initializers/acts_as_taggable_on.rb +13 -12
  199. data/config/initializers/ckeditor.rb +36 -16
  200. data/config/initializers/devise.rb +17 -15
  201. data/config/initializers/elasticsearch.rb +44 -0
  202. data/config/initializers/inflections.rb +1 -1
  203. data/config/routes.rb +13 -36
  204. data/db/migrate/001_create_ckeditor_assets.rb +6 -5
  205. data/db/migrate/002_create_georgia_contents.rb +2 -4
  206. data/db/migrate/008_create_georgia_roles.rb +0 -2
  207. data/db/migrate/015_add_receives_notifications_to_users.rb +7 -0
  208. data/db/migrate/016_add_role_id_to_users.rb +7 -0
  209. data/db/migrate/017_add_status_to_revisions.rb +7 -0
  210. data/db/migrate/018_create_georgia_role_assignments.rb +11 -0
  211. data/db/migrate/019_create_activities.rb +23 -0
  212. data/db/migrate/020_remove_georgia_revisions_state.rb +11 -0
  213. data/db/migrate/021_add_revised_by_id_to_georgia_revisions.rb +13 -0
  214. data/lib/generators/georgia/install/install_generator.rb +3 -29
  215. data/lib/generators/georgia/install/templates/app/controllers/pages_controller.rb +1 -1
  216. data/lib/generators/georgia/install/templates/config/initializers/georgia.rb +3 -7
  217. data/lib/generators/georgia/setup/setup_generator.rb +29 -0
  218. data/lib/georgia.rb +26 -9
  219. data/lib/georgia/engine.rb +6 -25
  220. data/lib/georgia/permissions.rb +57 -0
  221. data/lib/georgia/uploader/adapter.rb +4 -1
  222. data/lib/georgia/uploader/storage/file.rb +23 -0
  223. data/lib/georgia/version.rb +1 -1
  224. data/lib/tasks/georgia_tasks.rake +99 -0
  225. metadata +463 -461
  226. data/app/assets/fonts/georgia/signika-bold-webfont.eot +0 -0
  227. data/app/assets/fonts/georgia/signika-bold-webfont.svg +0 -1711
  228. data/app/assets/fonts/georgia/signika-bold-webfont.ttf +0 -0
  229. data/app/assets/fonts/georgia/signika-bold-webfont.woff +0 -0
  230. data/app/assets/fonts/georgia/signika-light-webfont.eot +0 -0
  231. data/app/assets/fonts/georgia/signika-light-webfont.svg +0 -1680
  232. data/app/assets/fonts/georgia/signika-light-webfont.ttf +0 -0
  233. data/app/assets/fonts/georgia/signika-light-webfont.woff +0 -0
  234. data/app/assets/fonts/georgia/signika-regular-webfont.eot +0 -0
  235. data/app/assets/fonts/georgia/signika-regular-webfont.svg +0 -1746
  236. data/app/assets/fonts/georgia/signika-regular-webfont.ttf +0 -0
  237. data/app/assets/fonts/georgia/signika-regular-webfont.woff +0 -0
  238. data/app/assets/images/georgia/bg-body-bar.jpg +0 -0
  239. data/app/assets/images/georgia/content-types/avi.jpg +0 -0
  240. data/app/assets/images/georgia/content-types/css.jpg +0 -0
  241. data/app/assets/images/georgia/content-types/csv.jpg +0 -0
  242. data/app/assets/images/georgia/content-types/doc.jpg +0 -0
  243. data/app/assets/images/georgia/content-types/docx.jpg +0 -0
  244. data/app/assets/images/georgia/content-types/eps.jpg +0 -0
  245. data/app/assets/images/georgia/content-types/gif.jpg +0 -0
  246. data/app/assets/images/georgia/content-types/gz.jpg +0 -0
  247. data/app/assets/images/georgia/content-types/html.jpg +0 -0
  248. data/app/assets/images/georgia/content-types/jpeg.jpg +0 -0
  249. data/app/assets/images/georgia/content-types/jpg.jpg +0 -0
  250. data/app/assets/images/georgia/content-types/mp3.jpg +0 -0
  251. data/app/assets/images/georgia/content-types/ods.jpg +0 -0
  252. data/app/assets/images/georgia/content-types/odt.jpg +0 -0
  253. data/app/assets/images/georgia/content-types/pdf.jpg +0 -0
  254. data/app/assets/images/georgia/content-types/png.jpg +0 -0
  255. data/app/assets/images/georgia/content-types/ppt.jpg +0 -0
  256. data/app/assets/images/georgia/content-types/pptx.jpg +0 -0
  257. data/app/assets/images/georgia/content-types/rar.jpg +0 -0
  258. data/app/assets/images/georgia/content-types/tar.jpg +0 -0
  259. data/app/assets/images/georgia/content-types/txt.jpg +0 -0
  260. data/app/assets/images/georgia/content-types/wav.jpg +0 -0
  261. data/app/assets/images/georgia/content-types/xls.jpg +0 -0
  262. data/app/assets/images/georgia/content-types/zip.jpg +0 -0
  263. data/app/assets/images/georgia/down_arrow.gif +0 -0
  264. data/app/assets/images/georgia/grippy_large.png +0 -0
  265. data/app/assets/images/georgia/logo.png +0 -0
  266. data/app/assets/images/georgia/up_arrow.gif +0 -0
  267. data/app/assets/javascripts/georgia/keybindings.js.coffee +0 -42
  268. data/app/assets/stylesheets/georgia/components/_state.scss +0 -17
  269. data/app/assets/stylesheets/georgia/settings/_fonts.scss +0 -3
  270. data/app/decorators/georgia/link_decorator.rb +0 -9
  271. data/app/decorators/georgia/links_decorator.rb +0 -4
  272. data/app/helpers/georgia/internationalization_helper.rb +0 -45
  273. data/app/helpers/georgia/menus_helper.rb +0 -20
  274. data/app/helpers/georgia/meta_tags_helper.rb +0 -22
  275. data/app/helpers/georgia/pages_helper.rb +0 -30
  276. data/app/helpers/georgia/routes_helper.rb +0 -25
  277. data/app/helpers/georgia/twitter_helper.rb +0 -24
  278. data/app/models/ability.rb +0 -19
  279. data/app/models/acts_as_taggable_on/tag.rb +0 -5
  280. data/app/models/georgia/concerns/cacheable.rb +0 -18
  281. data/app/models/georgia/concerns/orderable.rb +0 -21
  282. data/app/models/georgia/concerns/publishable.rb +0 -35
  283. data/app/models/georgia/concerns/revisionable.rb +0 -38
  284. data/app/models/georgia/concerns/slugable.rb +0 -48
  285. data/app/models/georgia/concerns/statable.rb +0 -64
  286. data/app/models/georgia/concerns/templatable.rb +0 -20
  287. data/app/policies/georgia/policy.rb +0 -17
  288. data/app/presenters/georgia/page_actions_presenter.rb +0 -92
  289. data/app/presenters/georgia/warning_message.rb +0 -55
  290. data/app/services/create_media_asset.rb +0 -51
  291. data/app/sweepers/navigation_sweeper.rb +0 -12
  292. data/app/views/georgia/media/sidebar/_facets.html.erb +0 -12
  293. data/app/views/menus/_dropdown_group.html.erb +0 -10
  294. data/app/views/menus/_dropdown_link.html.erb +0 -3
  295. data/app/views/menus/_dropdown_menu.html.erb +0 -11
  296. data/app/views/menus/_link.html.erb +0 -1
  297. data/app/views/menus/_menu.html.erb +0 -7
  298. data/config/initializers/simple_form.rb +0 -79
  299. data/config/locales/georgia.en.yml +0 -4
  300. data/lib/georgia/indexer.rb +0 -33
  301. data/lib/georgia/indexer/adapter.rb +0 -44
  302. data/lib/georgia/indexer/extensions/solr_adapter/acts_as_taggable_on/tag.rb +0 -30
  303. data/lib/georgia/indexer/extensions/solr_adapter/ckeditor/asset.rb +0 -46
  304. data/lib/georgia/indexer/extensions/solr_adapter/georgia/page.rb +0 -75
  305. data/lib/georgia/indexer/extensions/tire_adapter/acts_as_taggable_on/tag.rb +0 -34
  306. data/lib/georgia/indexer/extensions/tire_adapter/ckeditor/asset.rb +0 -57
  307. data/lib/georgia/indexer/extensions/tire_adapter/georgia/page.rb +0 -55
  308. data/lib/georgia/indexer/solr_adapter.rb +0 -20
  309. data/lib/georgia/indexer/tire_adapter.rb +0 -18
  310. data/lib/tasks/assets.rake +0 -20
  311. data/lib/tasks/georgia.rake +0 -65
  312. data/lib/tasks/sidekiq.rake +0 -8
  313. data/lib/tasks/solr.rake +0 -21
  314. data/lib/tasks/upgrade.rake +0 -39
  315. data/lib/templates/erb/scaffold/_form.html.erb +0 -13
@@ -0,0 +1,698 @@
1
+ /**
2
+ * jQuery TextExt Plugin
3
+ * http://textextjs.com
4
+ *
5
+ * @version 1.3.1
6
+ * @copyright Copyright (C) 2011 Alex Gorbatchev. All rights reserved.
7
+ * @license MIT License
8
+ */
9
+ (function($)
10
+ {
11
+ /**
12
+ * Tags plugin brings in the traditional tag functionality where user can assemble and
13
+ * edit list of tags. Tags plugin works especially well together with Autocomplete, Filter,
14
+ * Suggestions and Ajax plugins to provide full spectrum of features. It can also work on
15
+ * its own and just do one thing -- tags.
16
+ *
17
+ * @author agorbatchev
18
+ * @date 2011/08/19
19
+ * @id TextExtTags
20
+ */
21
+ function TextExtTags() {};
22
+
23
+ $.fn.textext.TextExtTags = TextExtTags;
24
+ $.fn.textext.addPlugin('tags', TextExtTags);
25
+
26
+ var p = TextExtTags.prototype,
27
+
28
+ CSS_DOT = '.',
29
+ CSS_TAGS_ON_TOP = 'text-tags-on-top',
30
+ CSS_DOT_TAGS_ON_TOP = CSS_DOT + CSS_TAGS_ON_TOP,
31
+ CSS_TAG = 'text-tag',
32
+ CSS_DOT_TAG = CSS_DOT + CSS_TAG,
33
+ CSS_TAGS = 'text-tags',
34
+ CSS_DOT_TAGS = CSS_DOT + CSS_TAGS,
35
+ CSS_LABEL = 'text-label',
36
+ CSS_DOT_LABEL = CSS_DOT + CSS_LABEL,
37
+ CSS_REMOVE = 'text-remove',
38
+ CSS_DOT_REMOVE = CSS_DOT + CSS_REMOVE,
39
+
40
+ /**
41
+ * Tags plugin options are grouped under `tags` when passed to the
42
+ * `$().textext()` function. For example:
43
+ *
44
+ * $('textarea').textext({
45
+ * plugins: 'tags',
46
+ * tags: {
47
+ * items: [ "tag1", "tag2" ]
48
+ * }
49
+ * })
50
+ *
51
+ * @author agorbatchev
52
+ * @date 2011/08/19
53
+ * @id TextExtTags.options
54
+ */
55
+
56
+ /**
57
+ * This is a toggle switch to enable or disable the Tags plugin. The value is checked
58
+ * each time at the top level which allows you to toggle this setting on the fly.
59
+ *
60
+ * @name tags.enabled
61
+ * @default true
62
+ * @author agorbatchev
63
+ * @date 2011/08/19
64
+ * @id TextExtTags.options.tags.enabled
65
+ */
66
+ OPT_ENABLED = 'tags.enabled',
67
+
68
+ /**
69
+ * Allows to specify tags which will be added to the input by default upon initialization.
70
+ * Each item in the array must be of the type that current `ItemManager` can understand.
71
+ * Default type is `String`.
72
+ *
73
+ * @name tags.items
74
+ * @default null
75
+ * @author agorbatchev
76
+ * @date 2011/08/19
77
+ * @id TextExtTags.options.tags.items
78
+ */
79
+ OPT_ITEMS = 'tags.items',
80
+
81
+ /**
82
+ * HTML source that is used to generate a single tag.
83
+ *
84
+ * @name html.tag
85
+ * @default '<div class="text-tags"/>'
86
+ * @author agorbatchev
87
+ * @date 2011/08/19
88
+ * @id TextExtTags.options.html.tag
89
+ */
90
+ OPT_HTML_TAG = 'html.tag',
91
+
92
+ /**
93
+ * HTML source that is used to generate container for the tags.
94
+ *
95
+ * @name html.tags
96
+ * @default '<div class="text-tag"><div class="text-button"><span class="text-label"/><a class="text-remove"/></div></div>'
97
+ * @author agorbatchev
98
+ * @date 2011/08/19
99
+ * @id TextExtTags.options.html.tags
100
+ */
101
+ OPT_HTML_TAGS = 'html.tags',
102
+
103
+ /**
104
+ * Tags plugin dispatches or reacts to the following events.
105
+ *
106
+ * @author agorbatchev
107
+ * @date 2011/08/17
108
+ * @id TextExtTags.events
109
+ */
110
+
111
+ /**
112
+ * Tags plugin triggers the `isTagAllowed` event before adding each tag to the tag list. Other plugins have
113
+ * an opportunity to interrupt this by setting `result` of the second argument to `false`. For example:
114
+ *
115
+ * $('textarea').textext({...}).bind('isTagAllowed', function(e, data)
116
+ * {
117
+ * if(data.tag === 'foo')
118
+ * data.result = false;
119
+ * })
120
+ *
121
+ * The second argument `data` has the following format: `{ tag : {Object}, result : {Boolean} }`. `tag`
122
+ * property is in the format that the current `ItemManager` can understand.
123
+ *
124
+ * @name isTagAllowed
125
+ * @author agorbatchev
126
+ * @date 2011/08/19
127
+ * @id TextExtTags.events.isTagAllowed
128
+ */
129
+ EVENT_IS_TAG_ALLOWED = 'isTagAllowed',
130
+
131
+ /**
132
+ * Tags plugin triggers the `tagClick` event when user clicks on one of the tags. This allows to process
133
+ * the click and potentially change the value of the tag (for example in case of user feedback).
134
+ *
135
+ * $('textarea').textext({...}).bind('tagClick', function(e, tag, value, callback)
136
+ * {
137
+ * var newValue = window.prompt('New value', value);
138
+
139
+ * if(newValue)
140
+ * callback(newValue, true);
141
+ * })
142
+ *
143
+ * Callback argument has the following signature:
144
+ *
145
+ * function(newValue, refocus)
146
+ * {
147
+ * ...
148
+ * }
149
+ *
150
+ * Please check out [example](/manual/examples/tags-changing.html).
151
+ *
152
+ * @name tagClick
153
+ * @version 1.3.0
154
+ * @author s.stok
155
+ * @date 2011/01/23
156
+ * @id TextExtTags.events.tagClick
157
+ */
158
+ EVENT_TAG_CLICK = 'tagClick',
159
+
160
+ DEFAULT_OPTS = {
161
+ tags : {
162
+ enabled : true,
163
+ items : null
164
+ },
165
+
166
+ html : {
167
+ tags : '<div class="text-tags"/>',
168
+ tag : '<div class="text-tag"><div class="text-button"><span class="text-label"/><a class="text-remove"/></div></div>'
169
+ }
170
+ }
171
+ ;
172
+
173
+ /**
174
+ * Initialization method called by the core during plugin instantiation.
175
+ *
176
+ * @signature TextExtTags.init(core)
177
+ *
178
+ * @param core {TextExt} Instance of the TextExt core class.
179
+ *
180
+ * @author agorbatchev
181
+ * @date 2011/08/19
182
+ * @id TextExtTags.init
183
+ */
184
+ p.init = function(core)
185
+ {
186
+ this.baseInit(core, DEFAULT_OPTS);
187
+ var self = this,
188
+ input = self.input(),
189
+ container
190
+ ;
191
+
192
+ if(self.opts(OPT_ENABLED))
193
+ {
194
+ container = $(self.opts(OPT_HTML_TAGS));
195
+ input.after(container);
196
+
197
+ $(self).data('container', container);
198
+
199
+ self.on({
200
+ enterKeyPress : self.onEnterKeyPress,
201
+ backspaceKeyDown : self.onBackspaceKeyDown,
202
+ preInvalidate : self.onPreInvalidate,
203
+ postInit : self.onPostInit,
204
+ getFormData : self.onGetFormData
205
+ });
206
+
207
+ self.on(container, {
208
+ click : self.onClick,
209
+ mousemove : self.onContainerMouseMove
210
+ });
211
+
212
+ self.on(input, {
213
+ mousemove : self.onInputMouseMove
214
+ });
215
+ }
216
+
217
+ self._originalPadding = {
218
+ left : parseInt(input.css('paddingLeft') || 0),
219
+ top : parseInt(input.css('paddingTop') || 0)
220
+ };
221
+
222
+ self._paddingBox = {
223
+ left : 0,
224
+ top : 0
225
+ };
226
+
227
+ self.updateFormCache();
228
+ };
229
+
230
+ /**
231
+ * Returns HTML element in which all tag HTML elements are residing.
232
+ *
233
+ * @signature TextExtTags.containerElement()
234
+ *
235
+ * @author agorbatchev
236
+ * @date 2011/08/15
237
+ * @id TextExtTags.containerElement
238
+ */
239
+ p.containerElement = function()
240
+ {
241
+ return $(this).data('container');
242
+ };
243
+
244
+ //--------------------------------------------------------------------------------
245
+ // Event handlers
246
+
247
+ /**
248
+ * Reacts to the `postInit` event triggered by the core and sets default tags
249
+ * if any were specified.
250
+ *
251
+ * @signature TextExtTags.onPostInit(e)
252
+ *
253
+ * @param e {Object} jQuery event.
254
+ *
255
+ * @author agorbatchev
256
+ * @date 2011/08/09
257
+ * @id TextExtTags.onPostInit
258
+ */
259
+ p.onPostInit = function(e)
260
+ {
261
+ var self = this;
262
+ self.addTags(self.opts(OPT_ITEMS));
263
+ };
264
+
265
+ /**
266
+ * Reacts to the [`getFormData`][1] event triggered by the core. Returns data with the
267
+ * weight of 200 to be *greater than the Autocomplete plugin* data weight. The weights
268
+ * system is covered in greater detail in the [`getFormData`][1] event documentation.
269
+ *
270
+ * [1]: /manual/textext.html#getformdata
271
+ *
272
+ * @signature TextExtTags.onGetFormData(e, data, keyCode)
273
+ *
274
+ * @param e {Object} jQuery event.
275
+ * @param data {Object} Data object to be populated.
276
+ * @param keyCode {Number} Key code that triggered the original update request.
277
+ *
278
+ * @author agorbatchev
279
+ * @date 2011/08/22
280
+ * @id TextExtTags.onGetFormData
281
+ */
282
+ p.onGetFormData = function(e, data, keyCode)
283
+ {
284
+ var self = this,
285
+ inputValue = keyCode === 13 ? '' : self.val(),
286
+ formValue = self._formData
287
+ ;
288
+
289
+ data[200] = self.formDataObject(inputValue, formValue);
290
+ };
291
+
292
+ /**
293
+ * Returns initialization priority of the Tags plugin which is expected to be
294
+ * *less than the Autocomplete plugin* because of the dependencies. The value is
295
+ * 100.
296
+ *
297
+ * @signature TextExtTags.initPriority()
298
+ *
299
+ * @author agorbatchev
300
+ * @date 2011/08/22
301
+ * @id TextExtTags.initPriority
302
+ */
303
+ p.initPriority = function()
304
+ {
305
+ return 100;
306
+ };
307
+
308
+ /**
309
+ * Reacts to user moving mouse over the text area when cursor is over the text
310
+ * and not over the tags. Whenever mouse cursor is over the area covered by
311
+ * tags, the tags container is flipped to be on top of the text area which
312
+ * makes all tags functional with the mouse.
313
+ *
314
+ * @signature TextExtTags.onInputMouseMove(e)
315
+ *
316
+ * @param e {Object} jQuery event.
317
+ *
318
+ * @author agorbatchev
319
+ * @date 2011/08/08
320
+ * @id TextExtTags.onInputMouseMove
321
+ */
322
+ p.onInputMouseMove = function(e)
323
+ {
324
+ this.toggleZIndex(e);
325
+ };
326
+
327
+ /**
328
+ * Reacts to user moving mouse over the tags. Whenever the cursor moves out
329
+ * of the tags and back into where the text input is happening visually,
330
+ * the tags container is sent back under the text area which allows user
331
+ * to interact with the text using mouse cursor as expected.
332
+ *
333
+ * @signature TextExtTags.onContainerMouseMove(e)
334
+ *
335
+ * @param e {Object} jQuery event.
336
+ *
337
+ * @author agorbatchev
338
+ * @date 2011/08/08
339
+ * @id TextExtTags.onContainerMouseMove
340
+ */
341
+ p.onContainerMouseMove = function(e)
342
+ {
343
+ this.toggleZIndex(e);
344
+ };
345
+
346
+ /**
347
+ * Reacts to the `backspaceKeyDown` event. When backspace key is pressed in an empty text field,
348
+ * deletes last tag from the list.
349
+ *
350
+ * @signature TextExtTags.onBackspaceKeyDown(e)
351
+ *
352
+ * @param e {Object} jQuery event.
353
+ *
354
+ * @author agorbatchev
355
+ * @date 2011/08/02
356
+ * @id TextExtTags.onBackspaceKeyDown
357
+ */
358
+ p.onBackspaceKeyDown = function(e)
359
+ {
360
+ var self = this,
361
+ lastTag = self.tagElements().last()
362
+ ;
363
+
364
+ if(self.val().length == 0)
365
+ self.removeTag(lastTag);
366
+ };
367
+
368
+ /**
369
+ * Reacts to the `preInvalidate` event and updates the input box to look like the tags are
370
+ * positioned inside it.
371
+ *
372
+ * @signature TextExtTags.onPreInvalidate(e)
373
+ *
374
+ * @param e {Object} jQuery event.
375
+ *
376
+ * @author agorbatchev
377
+ * @date 2011/08/19
378
+ * @id TextExtTags.onPreInvalidate
379
+ */
380
+ p.onPreInvalidate = function(e)
381
+ {
382
+ var self = this,
383
+ lastTag = self.tagElements().last(),
384
+ pos = lastTag.position()
385
+ ;
386
+
387
+ if(lastTag.length > 0)
388
+ pos.left += lastTag.innerWidth();
389
+ else
390
+ pos = self._originalPadding;
391
+
392
+ self._paddingBox = pos;
393
+
394
+ self.input().css({
395
+ paddingLeft : pos.left,
396
+ paddingTop : pos.top
397
+ });
398
+ };
399
+
400
+ /**
401
+ * Reacts to the mouse `click` event.
402
+ *
403
+ * @signature TextExtTags.onClick(e)
404
+ *
405
+ * @param e {Object} jQuery event.
406
+ *
407
+ * @author agorbatchev
408
+ * @date 2011/08/19
409
+ * @id TextExtTags.onClick
410
+ */
411
+ p.onClick = function(e)
412
+ {
413
+ var self = this,
414
+ core = self.core(),
415
+ source = $(e.target),
416
+ focus = 0,
417
+ tag
418
+ ;
419
+
420
+ if(source.is(CSS_DOT_TAGS))
421
+ {
422
+ focus = 1;
423
+ }
424
+ else if(source.is(CSS_DOT_REMOVE))
425
+ {
426
+ self.removeTag(source.parents(CSS_DOT_TAG + ':first'));
427
+ focus = 1;
428
+ }
429
+ else if(source.is(CSS_DOT_LABEL))
430
+ {
431
+ tag = source.parents(CSS_DOT_TAG + ':first');
432
+ self.trigger(EVENT_TAG_CLICK, tag, tag.data(CSS_TAG), tagClickCallback);
433
+ }
434
+
435
+ function tagClickCallback(newValue, refocus)
436
+ {
437
+ tag.data(CSS_TAG, newValue);
438
+ tag.find(CSS_DOT_LABEL).text(self.itemManager().itemToString(newValue));
439
+
440
+ self.updateFormCache();
441
+ core.getFormData();
442
+ core.invalidateBounds();
443
+
444
+ if(refocus)
445
+ core.focusInput();
446
+ }
447
+
448
+ if(focus)
449
+ core.focusInput();
450
+ };
451
+
452
+ /**
453
+ * Reacts to the `enterKeyPress` event and adds whatever is currently in the text input
454
+ * as a new tag. Triggers `isTagAllowed` to check if the tag could be added first.
455
+ *
456
+ * @signature TextExtTags.onEnterKeyPress(e)
457
+ *
458
+ * @param e {Object} jQuery event.
459
+ *
460
+ * @author agorbatchev
461
+ * @date 2011/08/19
462
+ * @id TextExtTags.onEnterKeyPress
463
+ */
464
+ p.onEnterKeyPress = function(e)
465
+ {
466
+ var self = this,
467
+ val = self.val(),
468
+ tag = self.itemManager().stringToItem(val)
469
+ ;
470
+
471
+ if(self.isTagAllowed(tag))
472
+ {
473
+ self.addTags([ tag ]);
474
+ // refocus the textarea just in case it lost the focus
475
+ self.core().focusInput();
476
+ }
477
+ };
478
+
479
+ //--------------------------------------------------------------------------------
480
+ // Core functionality
481
+
482
+ /**
483
+ * Creates a cache object with all the tags currently added which will be returned
484
+ * in the `onGetFormData` handler.
485
+ *
486
+ * @signature TextExtTags.updateFormCache()
487
+ *
488
+ * @author agorbatchev
489
+ * @date 2011/08/09
490
+ * @id TextExtTags.updateFormCache
491
+ */
492
+ p.updateFormCache = function()
493
+ {
494
+ var self = this,
495
+ result = []
496
+ ;
497
+
498
+ self.tagElements().each(function()
499
+ {
500
+ result.push($(this).data(CSS_TAG));
501
+ });
502
+
503
+ // cache the results to be used in the onGetFormData
504
+ self._formData = result;
505
+ };
506
+
507
+ /**
508
+ * Toggles tag container to be on top of the text area or under based on where
509
+ * the mouse cursor is located. When cursor is above the text input and out of
510
+ * any of the tags, the tags container is sent under the text area. If cursor
511
+ * is over any of the tags, the tag container is brought to be over the text
512
+ * area.
513
+ *
514
+ * @signature TextExtTags.toggleZIndex(e)
515
+ *
516
+ * @param e {Object} jQuery event.
517
+ *
518
+ * @author agorbatchev
519
+ * @date 2011/08/08
520
+ * @id TextExtTags.toggleZIndex
521
+ */
522
+ p.toggleZIndex = function(e)
523
+ {
524
+ var self = this,
525
+ offset = self.input().offset(),
526
+ mouseX = e.clientX - offset.left,
527
+ mouseY = e.clientY - offset.top,
528
+ box = self._paddingBox,
529
+ container = self.containerElement(),
530
+ isOnTop = container.is(CSS_DOT_TAGS_ON_TOP),
531
+ isMouseOverText = mouseX > box.left && mouseY > box.top
532
+ ;
533
+
534
+ if(!isOnTop && !isMouseOverText || isOnTop && isMouseOverText)
535
+ container[(!isOnTop ? 'add' : 'remove') + 'Class'](CSS_TAGS_ON_TOP);
536
+ };
537
+
538
+ /**
539
+ * Returns all tag HTML elements.
540
+ *
541
+ * @signature TextExtTags.tagElements()
542
+ *
543
+ * @author agorbatchev
544
+ * @date 2011/08/19
545
+ * @id TextExtTags.tagElements
546
+ */
547
+ p.tagElements = function()
548
+ {
549
+ return this.containerElement().find(CSS_DOT_TAG);
550
+ };
551
+
552
+ /**
553
+ * Wrapper around the `isTagAllowed` event which triggers it and returns `true`
554
+ * if `result` property of the second argument remains `true`.
555
+ *
556
+ * @signature TextExtTags.isTagAllowed(tag)
557
+ *
558
+ * @param tag {Object} Tag object that the current `ItemManager` can understand.
559
+ * Default is `String`.
560
+ *
561
+ * @author agorbatchev
562
+ * @date 2011/08/19
563
+ * @id TextExtTags.isTagAllowed
564
+ */
565
+ p.isTagAllowed = function(tag)
566
+ {
567
+ var opts = { tag : tag, result : true };
568
+ this.trigger(EVENT_IS_TAG_ALLOWED, opts);
569
+ return opts.result === true;
570
+ };
571
+
572
+ /**
573
+ * Adds specified tags to the tag list. Triggers `isTagAllowed` event for each tag
574
+ * to insure that it could be added. Calls `TextExt.getFormData()` to refresh the data.
575
+ *
576
+ * @signature TextExtTags.addTags(tags)
577
+ *
578
+ * @param tags {Array} List of tags that current `ItemManager` can understand. Default
579
+ * is `String`.
580
+ *
581
+ * @author agorbatchev
582
+ * @date 2011/08/19
583
+ * @id TextExtTags.addTags
584
+ */
585
+ p.addTags = function(tags)
586
+ {
587
+ if(!tags || tags.length == 0)
588
+ return;
589
+
590
+ var self = this,
591
+ core = self.core(),
592
+ container = self.containerElement(),
593
+ i, tag
594
+ ;
595
+
596
+ for(i = 0; i < tags.length; i++)
597
+ {
598
+ tag = tags[i];
599
+
600
+ if(tag && self.isTagAllowed(tag))
601
+ container.append(self.renderTag(tag));
602
+ }
603
+
604
+ self.updateFormCache();
605
+ core.getFormData();
606
+ core.invalidateBounds();
607
+ };
608
+
609
+ /**
610
+ * Returns HTML element for the specified tag.
611
+ *
612
+ * @signature TextExtTags.getTagElement(tag)
613
+ *
614
+ * @param tag {Object} Tag object in the format that current `ItemManager` can understand.
615
+ * Default is `String`.
616
+
617
+ * @author agorbatchev
618
+ * @date 2011/08/19
619
+ * @id TextExtTags.getTagElement
620
+ */
621
+ p.getTagElement = function(tag)
622
+ {
623
+ var self = this,
624
+ list = self.tagElements(),
625
+ i, item
626
+ ;
627
+
628
+ for(i = 0; i < list.length; i++) {
629
+ item = $(list[i]);
630
+ if(self.itemManager().compareItems(item.data(CSS_TAG), tag))
631
+ return item;
632
+ }
633
+
634
+ return null;
635
+ };
636
+
637
+ /**
638
+ * Removes specified tag from the list. Calls `TextExt.getFormData()` to refresh the data.
639
+ *
640
+ * @signature TextExtTags.removeTag(tag)
641
+ *
642
+ * @param tag {Object} Tag object in the format that current `ItemManager` can understand.
643
+ * Default is `String`.
644
+ *
645
+ * @author agorbatchev
646
+ * @date 2011/08/19
647
+ * @id TextExtTags.removeTag
648
+ */
649
+ p.removeTag = function(tag)
650
+ {
651
+ var self = this,
652
+ core = self.core(),
653
+ element
654
+ ;
655
+
656
+ if(tag instanceof $)
657
+ {
658
+ element = tag;
659
+ tag = tag.data(CSS_TAG);
660
+ }
661
+ else
662
+ {
663
+ element = self.getTagElement(tag);
664
+ if (element === null) {
665
+ //Tag does not exist
666
+ return;
667
+ }
668
+ }
669
+
670
+ element.remove();
671
+ self.updateFormCache();
672
+ core.getFormData();
673
+ core.invalidateBounds();
674
+ };
675
+
676
+ /**
677
+ * Creates and returns new HTML element from the source code specified in the `html.tag` option.
678
+ *
679
+ * @signature TextExtTags.renderTag(tag)
680
+ *
681
+ * @param tag {Object} Tag object in the format that current `ItemManager` can understand.
682
+ * Default is `String`.
683
+ *
684
+ * @author agorbatchev
685
+ * @date 2011/08/19
686
+ * @id TextExtTags.renderTag
687
+ */
688
+ p.renderTag = function(tag)
689
+ {
690
+ var self = this,
691
+ node = $(self.opts(OPT_HTML_TAG))
692
+ ;
693
+
694
+ node.find('.text-label').text(self.itemManager().itemToString(tag));
695
+ node.data(CSS_TAG, tag);
696
+ return node;
697
+ };
698
+ })(jQuery);