georgia 0.7.8 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +60 -16
- data/Rakefile +17 -10
- data/app/assets/images/georgia/arrow.png +0 -0
- data/app/assets/images/georgia/close.png +0 -0
- data/app/assets/javascripts/georgia/application.js +3 -6
- data/app/assets/javascripts/georgia/bootstrap-vendor.js.coffee +1 -1
- data/app/assets/javascripts/georgia/ckeditor/config.js +1 -1
- data/app/assets/javascripts/georgia/components/flash.js.coffee +1 -1
- data/app/assets/javascripts/georgia/components/media-library.js.coffee +1 -1
- data/app/assets/javascripts/georgia/components/tables.js.coffee +30 -0
- data/app/assets/javascripts/georgia/components/tables/{checkbox.js.coffee → checkboxable.js.coffee} +10 -39
- data/app/assets/javascripts/georgia/components/tables/media.js.coffee +17 -29
- data/app/assets/javascripts/georgia/components/tables/pages.js.coffee +26 -44
- data/app/assets/javascripts/georgia/components/tags.js.coffee +13 -24
- data/app/assets/javascripts/georgia/vendor/ekko-lightbox.min.js +7 -0
- data/app/assets/javascripts/georgia/vendor/textext.core.js +1618 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.ajax.js +354 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.arrow.js +106 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.autocomplete.js +1110 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.clear.js +116 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.filter.js +242 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.focus.js +174 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.prompt.js +309 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.suggestions.js +175 -0
- data/app/assets/javascripts/georgia/vendor/textext.plugin.tags.js +698 -0
- data/app/assets/stylesheets/georgia/application.css.scss +71 -12
- data/app/assets/stylesheets/georgia/components/_button.scss +3 -20
- data/app/assets/stylesheets/georgia/components/_label.scss +36 -1
- data/app/assets/stylesheets/georgia/components/_portlet.scss +4 -1
- data/app/assets/stylesheets/georgia/components/_status.scss +9 -0
- data/app/assets/stylesheets/georgia/components/_table.scss +7 -0
- data/app/assets/stylesheets/georgia/layout/_base.scss +22 -5
- data/app/assets/stylesheets/georgia/layout/_print.scss +8 -0
- data/app/assets/stylesheets/georgia/modules/_activities.scss +3 -0
- data/app/assets/stylesheets/georgia/modules/_footer.scss +3 -1
- data/app/assets/stylesheets/georgia/modules/_form_with_helpers.scss +2 -2
- data/app/assets/stylesheets/georgia/modules/_header.scss +4 -13
- data/app/assets/stylesheets/georgia/modules/_link.scss +6 -1
- data/app/assets/stylesheets/georgia/modules/_login.scss +7 -0
- data/app/assets/stylesheets/georgia/modules/_media.scss +10 -0
- data/app/assets/stylesheets/georgia/modules/_navigation.scss +5 -0
- data/app/assets/stylesheets/georgia/modules/_pages.scss +3 -0
- data/app/assets/stylesheets/georgia/modules/_results.scss +11 -4
- data/app/assets/stylesheets/georgia/modules/_sidebar.scss +6 -21
- data/app/assets/stylesheets/georgia/modules/_users.scss +3 -0
- data/app/assets/stylesheets/georgia/overrides/_flatly.scss +16 -0
- data/app/assets/stylesheets/georgia/overrides/_textext.scss +54 -0
- data/app/assets/stylesheets/georgia/settings/_base.scss +1 -1
- data/app/assets/stylesheets/georgia/settings/_colors.scss +31 -1
- data/app/assets/stylesheets/georgia/settings/_z-index.scss +2 -2
- data/app/assets/stylesheets/georgia/vendor/_bootswatch-flatly-theme.scss +7 -0
- data/app/assets/stylesheets/georgia/vendor/_ekko-lightbox.min.scss +6 -0
- data/app/assets/stylesheets/georgia/vendor/_select2_bootstrap.scss +497 -0
- data/app/assets/stylesheets/georgia/vendor/_textext.core.scss +29 -0
- data/app/assets/stylesheets/georgia/vendor/_textext.plugin.arrow.scss +13 -0
- data/app/assets/stylesheets/georgia/vendor/_textext.plugin.autocomplete.scss +35 -0
- data/app/assets/stylesheets/georgia/vendor/_textext.plugin.clear.scss +13 -0
- data/app/assets/stylesheets/georgia/vendor/_textext.plugin.focus.scss +12 -0
- data/app/assets/stylesheets/georgia/vendor/_textext.plugin.prompt.scss +16 -0
- data/app/assets/stylesheets/georgia/vendor/_textext.plugin.tags.scss +49 -0
- data/app/controllers/georgia/api/media_controller.rb +4 -2
- data/app/controllers/georgia/api/tags_controller.rb +10 -7
- data/app/controllers/georgia/application_controller.rb +17 -2
- data/app/controllers/georgia/concerns/frontendable.rb +2 -3
- data/app/controllers/georgia/dashboard_controller.rb +5 -7
- data/app/controllers/georgia/links_controller.rb +1 -0
- data/app/controllers/georgia/media_controller.rb +50 -41
- data/app/controllers/georgia/menus_controller.rb +16 -6
- data/app/controllers/georgia/pages_controller.rb +98 -58
- data/app/controllers/georgia/revisions_controller.rb +120 -24
- data/app/controllers/georgia/ui_associations_controller.rb +1 -0
- data/app/controllers/georgia/users_controller.rb +31 -11
- data/app/controllers/georgia/widgets_controller.rb +13 -4
- data/app/helpers/georgia/application_helper.rb +4 -0
- data/app/helpers/georgia/forms_helper.rb +2 -2
- data/app/helpers/georgia/ui_helper.rb +78 -12
- data/app/helpers/georgia/users_helper.rb +21 -0
- data/app/mailers/georgia/notifier.rb +4 -4
- data/app/models/ckeditor/asset.rb +16 -4
- data/app/models/ckeditor/asset_search.rb +15 -0
- data/app/models/ckeditor/attachment_file.rb +7 -0
- data/app/models/ckeditor/picture.rb +10 -0
- data/app/models/georgia/clone.rb +3 -1
- data/app/models/georgia/concerns/contentable.rb +2 -3
- data/app/models/georgia/concerns/searchable.rb +32 -0
- data/app/models/georgia/concerns/taggable.rb +2 -2
- data/app/models/georgia/concerns/treeable.rb +0 -1
- data/app/models/georgia/content.rb +1 -3
- data/app/models/georgia/dashboard.rb +7 -0
- data/app/models/georgia/link.rb +10 -3
- data/app/models/georgia/menu.rb +4 -4
- data/app/models/georgia/page.rb +75 -10
- data/app/models/georgia/revision.rb +10 -5
- data/app/models/georgia/role.rb +5 -5
- data/app/models/georgia/role_assignment.rb +8 -0
- data/app/models/georgia/slide.rb +4 -4
- data/app/models/georgia/status.rb +3 -5
- data/app/models/georgia/ui_association.rb +3 -5
- data/app/models/georgia/ui_section.rb +1 -1
- data/app/models/georgia/user.rb +5 -14
- data/app/models/georgia/widget.rb +3 -3
- data/app/policies/georgia/api_policy.rb +13 -0
- data/app/policies/georgia/application_policy.rb +30 -0
- data/app/policies/georgia/concerns/content_policy.rb +56 -0
- data/app/policies/georgia/concerns/publishing_policy.rb +52 -0
- data/app/policies/georgia/dashboard_policy.rb +19 -0
- data/app/policies/georgia/media_policy.rb +56 -0
- data/app/policies/georgia/navigation_policy.rb +42 -0
- data/app/policies/georgia/page_policy.rb +26 -0
- data/app/policies/georgia/revision_policy.rb +7 -44
- data/app/policies/georgia/ui_association_policy.rb +4 -0
- data/app/policies/georgia/user_policy.rb +46 -0
- data/app/policies/georgia/widget_policy.rb +42 -0
- data/app/presenters/georgia/active_facet_presenter.rb +2 -1
- data/app/presenters/georgia/link_portlet.rb +2 -2
- data/app/presenters/georgia/pagination_presenter.rb +45 -7
- data/app/presenters/georgia/permission_table_presenter.rb +80 -0
- data/app/presenters/georgia/revision_status_message.rb +73 -0
- data/app/presenters/georgia/sidebar_link_presenter.rb +1 -1
- data/app/presenters/georgia/slide_portlet.rb +5 -1
- data/app/routes/georgia/pageable_route_concern.rb +35 -0
- data/app/searches/georgia/media_search.rb +39 -0
- data/app/searches/georgia/page_search.rb +47 -0
- data/app/searches/georgia/search_definition.rb +72 -0
- data/app/searches/georgia/tag_search.rb +32 -0
- data/app/services/georgia/clone_revision.rb +71 -0
- data/app/services/georgia/compress_files.rb +49 -0
- data/app/services/georgia/copy_page.rb +100 -0
- data/app/services/georgia/create_activity.rb +16 -0
- data/app/services/georgia/create_media_asset.rb +53 -0
- data/app/services/georgia/parse_json_tags.rb +21 -0
- data/app/services/georgia/update_revision.rb +52 -0
- data/app/views/georgia/api/media/pictures.html.erb +1 -1
- data/app/views/georgia/ckeditor/assets/_asset.html.erb +2 -4
- data/app/views/georgia/ckeditor/pictures/_picture.html.erb +1 -6
- data/app/views/georgia/dashboard/panels/_messages.html.erb +26 -28
- data/app/views/georgia/dashboard/panels/_reviews.html.erb +23 -22
- data/app/views/georgia/dashboard/show.html.erb +9 -3
- data/app/views/georgia/header/_media.html.erb +2 -2
- data/app/views/georgia/header/_navigation.html.erb +3 -3
- data/app/views/georgia/header/_pages.html.erb +3 -3
- data/app/views/georgia/header/_users.html.erb +2 -2
- data/app/views/georgia/header/_widgets.html.erb +1 -1
- data/app/views/georgia/media/_header.html.erb +4 -2
- data/app/views/georgia/media/create.js.erb +1 -0
- data/app/views/georgia/media/destroy.js.erb +3 -0
- data/app/views/georgia/media/edit.html.erb +35 -30
- data/app/views/georgia/media/search.html.erb +2 -2
- data/app/views/georgia/menus/index.html.erb +1 -1
- data/app/views/georgia/pages/_header.html.erb +4 -4
- data/app/views/georgia/pages/_page.html.erb +1 -1
- data/app/views/georgia/pages/search.html.erb +4 -5
- data/app/views/georgia/pages/settings.html.erb +72 -61
- data/app/views/georgia/revisions/_revision.html.erb +12 -7
- data/app/views/georgia/revisions/edit.html.erb +17 -11
- data/app/views/georgia/revisions/fields/_content.html.erb +1 -2
- data/app/views/georgia/revisions/fields/_message.html.erb +11 -0
- data/app/views/georgia/revisions/fields/_ui_section.html.erb +1 -1
- data/app/views/georgia/revisions/fields/_widgets.html.erb +1 -1
- data/app/views/georgia/revisions/index.html.erb +2 -2
- data/app/views/georgia/revisions/messages/_awaiting_review.html.erb +15 -0
- data/app/views/georgia/revisions/messages/_continue_draft.html.erb +8 -0
- data/app/views/georgia/revisions/messages/_edit_current_revision.html.erb +12 -0
- data/app/views/georgia/revisions/messages/_insufficient_rights.html.erb +6 -0
- data/app/views/georgia/revisions/messages/_request_review.html.erb +7 -0
- data/app/views/georgia/revisions/messages/_review.html.erb +7 -0
- data/app/views/georgia/revisions/messages/_start_draft.html.erb +4 -0
- data/app/views/georgia/revisions/panels/_actions.html.erb +7 -0
- data/app/views/georgia/revisions/panels/_activities.html.erb +6 -0
- data/app/views/georgia/revisions/panels/_drafts.html.erb +28 -0
- data/app/views/georgia/revisions/panels/_info.html.erb +39 -0
- data/app/views/georgia/shared/modals/_media_library.html.erb +3 -1
- data/app/views/georgia/shared/search/_messages.html.erb +1 -1
- data/app/views/georgia/users/_form.html.erb +17 -2
- data/app/views/georgia/users/_user.html.erb +1 -1
- data/app/views/georgia/users/edit.html.erb +0 -1
- data/app/views/georgia/users/index.html.erb +1 -1
- data/app/views/georgia/users/permissions.html.erb +15 -0
- data/app/views/georgia/users/sessions/new.html.erb +3 -3
- data/app/views/layouts/georgia/_footer.html.erb +1 -3
- data/app/views/layouts/georgia/_head.html.erb +3 -4
- data/app/views/layouts/georgia/_header.html.erb +8 -10
- data/app/views/public_activity/_default.html.erb +15 -0
- data/app/views/public_activity/georgia_page/_copy.html.erb +15 -0
- data/app/views/public_activity/georgia_page/_create.html.erb +15 -0
- data/app/views/public_activity/georgia_page/_decline.html.erb +15 -0
- data/app/views/public_activity/georgia_page/_publish.html.erb +15 -0
- data/app/views/public_activity/georgia_page/_unpublish.html.erb +15 -0
- data/app/views/public_activity/georgia_page/_update.html.erb +15 -0
- data/app/views/public_activity/georgia_revision/_approve.html.erb +15 -0
- data/app/views/public_activity/georgia_revision/_decline.html.erb +15 -0
- data/app/views/public_activity/georgia_revision/_draft.html.erb +15 -0
- data/app/views/public_activity/georgia_revision/_restore.html.erb +15 -0
- data/app/views/public_activity/georgia_revision/_review.html.erb +15 -0
- data/app/views/public_activity/georgia_revision/_update.html.erb +15 -0
- data/config/initializers/acts_as_taggable_on.rb +13 -12
- data/config/initializers/ckeditor.rb +36 -16
- data/config/initializers/devise.rb +17 -15
- data/config/initializers/elasticsearch.rb +44 -0
- data/config/initializers/inflections.rb +1 -1
- data/config/routes.rb +13 -36
- data/db/migrate/001_create_ckeditor_assets.rb +6 -5
- data/db/migrate/002_create_georgia_contents.rb +2 -4
- data/db/migrate/008_create_georgia_roles.rb +0 -2
- data/db/migrate/015_add_receives_notifications_to_users.rb +7 -0
- data/db/migrate/016_add_role_id_to_users.rb +7 -0
- data/db/migrate/017_add_status_to_revisions.rb +7 -0
- data/db/migrate/018_create_georgia_role_assignments.rb +11 -0
- data/db/migrate/019_create_activities.rb +23 -0
- data/db/migrate/020_remove_georgia_revisions_state.rb +11 -0
- data/db/migrate/021_add_revised_by_id_to_georgia_revisions.rb +13 -0
- data/lib/generators/georgia/install/install_generator.rb +3 -29
- data/lib/generators/georgia/install/templates/app/controllers/pages_controller.rb +1 -1
- data/lib/generators/georgia/install/templates/config/initializers/georgia.rb +3 -7
- data/lib/generators/georgia/setup/setup_generator.rb +29 -0
- data/lib/georgia.rb +26 -9
- data/lib/georgia/engine.rb +6 -25
- data/lib/georgia/permissions.rb +57 -0
- data/lib/georgia/uploader/adapter.rb +4 -1
- data/lib/georgia/uploader/storage/file.rb +23 -0
- data/lib/georgia/version.rb +1 -1
- data/lib/tasks/georgia_tasks.rake +99 -0
- metadata +463 -461
- data/app/assets/fonts/georgia/signika-bold-webfont.eot +0 -0
- data/app/assets/fonts/georgia/signika-bold-webfont.svg +0 -1711
- data/app/assets/fonts/georgia/signika-bold-webfont.ttf +0 -0
- data/app/assets/fonts/georgia/signika-bold-webfont.woff +0 -0
- data/app/assets/fonts/georgia/signika-light-webfont.eot +0 -0
- data/app/assets/fonts/georgia/signika-light-webfont.svg +0 -1680
- data/app/assets/fonts/georgia/signika-light-webfont.ttf +0 -0
- data/app/assets/fonts/georgia/signika-light-webfont.woff +0 -0
- data/app/assets/fonts/georgia/signika-regular-webfont.eot +0 -0
- data/app/assets/fonts/georgia/signika-regular-webfont.svg +0 -1746
- data/app/assets/fonts/georgia/signika-regular-webfont.ttf +0 -0
- data/app/assets/fonts/georgia/signika-regular-webfont.woff +0 -0
- data/app/assets/images/georgia/bg-body-bar.jpg +0 -0
- data/app/assets/images/georgia/content-types/avi.jpg +0 -0
- data/app/assets/images/georgia/content-types/css.jpg +0 -0
- data/app/assets/images/georgia/content-types/csv.jpg +0 -0
- data/app/assets/images/georgia/content-types/doc.jpg +0 -0
- data/app/assets/images/georgia/content-types/docx.jpg +0 -0
- data/app/assets/images/georgia/content-types/eps.jpg +0 -0
- data/app/assets/images/georgia/content-types/gif.jpg +0 -0
- data/app/assets/images/georgia/content-types/gz.jpg +0 -0
- data/app/assets/images/georgia/content-types/html.jpg +0 -0
- data/app/assets/images/georgia/content-types/jpeg.jpg +0 -0
- data/app/assets/images/georgia/content-types/jpg.jpg +0 -0
- data/app/assets/images/georgia/content-types/mp3.jpg +0 -0
- data/app/assets/images/georgia/content-types/ods.jpg +0 -0
- data/app/assets/images/georgia/content-types/odt.jpg +0 -0
- data/app/assets/images/georgia/content-types/pdf.jpg +0 -0
- data/app/assets/images/georgia/content-types/png.jpg +0 -0
- data/app/assets/images/georgia/content-types/ppt.jpg +0 -0
- data/app/assets/images/georgia/content-types/pptx.jpg +0 -0
- data/app/assets/images/georgia/content-types/rar.jpg +0 -0
- data/app/assets/images/georgia/content-types/tar.jpg +0 -0
- data/app/assets/images/georgia/content-types/txt.jpg +0 -0
- data/app/assets/images/georgia/content-types/wav.jpg +0 -0
- data/app/assets/images/georgia/content-types/xls.jpg +0 -0
- data/app/assets/images/georgia/content-types/zip.jpg +0 -0
- data/app/assets/images/georgia/down_arrow.gif +0 -0
- data/app/assets/images/georgia/grippy_large.png +0 -0
- data/app/assets/images/georgia/logo.png +0 -0
- data/app/assets/images/georgia/up_arrow.gif +0 -0
- data/app/assets/javascripts/georgia/keybindings.js.coffee +0 -42
- data/app/assets/stylesheets/georgia/components/_state.scss +0 -17
- data/app/assets/stylesheets/georgia/settings/_fonts.scss +0 -3
- data/app/decorators/georgia/link_decorator.rb +0 -9
- data/app/decorators/georgia/links_decorator.rb +0 -4
- data/app/helpers/georgia/internationalization_helper.rb +0 -45
- data/app/helpers/georgia/menus_helper.rb +0 -20
- data/app/helpers/georgia/meta_tags_helper.rb +0 -22
- data/app/helpers/georgia/pages_helper.rb +0 -30
- data/app/helpers/georgia/routes_helper.rb +0 -25
- data/app/helpers/georgia/twitter_helper.rb +0 -24
- data/app/models/ability.rb +0 -19
- data/app/models/acts_as_taggable_on/tag.rb +0 -5
- data/app/models/georgia/concerns/cacheable.rb +0 -18
- data/app/models/georgia/concerns/orderable.rb +0 -21
- data/app/models/georgia/concerns/publishable.rb +0 -35
- data/app/models/georgia/concerns/revisionable.rb +0 -38
- data/app/models/georgia/concerns/slugable.rb +0 -48
- data/app/models/georgia/concerns/statable.rb +0 -64
- data/app/models/georgia/concerns/templatable.rb +0 -20
- data/app/policies/georgia/policy.rb +0 -17
- data/app/presenters/georgia/page_actions_presenter.rb +0 -92
- data/app/presenters/georgia/warning_message.rb +0 -55
- data/app/services/create_media_asset.rb +0 -51
- data/app/sweepers/navigation_sweeper.rb +0 -12
- data/app/views/georgia/media/sidebar/_facets.html.erb +0 -12
- data/app/views/menus/_dropdown_group.html.erb +0 -10
- data/app/views/menus/_dropdown_link.html.erb +0 -3
- data/app/views/menus/_dropdown_menu.html.erb +0 -11
- data/app/views/menus/_link.html.erb +0 -1
- data/app/views/menus/_menu.html.erb +0 -7
- data/config/initializers/simple_form.rb +0 -79
- data/config/locales/georgia.en.yml +0 -4
- data/lib/georgia/indexer.rb +0 -33
- data/lib/georgia/indexer/adapter.rb +0 -44
- data/lib/georgia/indexer/extensions/solr_adapter/acts_as_taggable_on/tag.rb +0 -30
- data/lib/georgia/indexer/extensions/solr_adapter/ckeditor/asset.rb +0 -46
- data/lib/georgia/indexer/extensions/solr_adapter/georgia/page.rb +0 -75
- data/lib/georgia/indexer/extensions/tire_adapter/acts_as_taggable_on/tag.rb +0 -34
- data/lib/georgia/indexer/extensions/tire_adapter/ckeditor/asset.rb +0 -57
- data/lib/georgia/indexer/extensions/tire_adapter/georgia/page.rb +0 -55
- data/lib/georgia/indexer/solr_adapter.rb +0 -20
- data/lib/georgia/indexer/tire_adapter.rb +0 -18
- data/lib/tasks/assets.rake +0 -20
- data/lib/tasks/georgia.rake +0 -65
- data/lib/tasks/sidekiq.rake +0 -8
- data/lib/tasks/solr.rake +0 -21
- data/lib/tasks/upgrade.rake +0 -39
- data/lib/templates/erb/scaffold/_form.html.erb +0 -13
@@ -0,0 +1,1110 @@
|
|
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
|
+
* Autocomplete plugin brings the classic autocomplete functionality to the TextExt ecosystem.
|
13
|
+
* The gist of functionality is when user starts typing in, for example a term or a tag, a
|
14
|
+
* dropdown would be presented with possible suggestions to complete the input quicker.
|
15
|
+
*
|
16
|
+
* @author agorbatchev
|
17
|
+
* @date 2011/08/17
|
18
|
+
* @id TextExtAutocomplete
|
19
|
+
*/
|
20
|
+
function TextExtAutocomplete() {};
|
21
|
+
|
22
|
+
$.fn.textext.TextExtAutocomplete = TextExtAutocomplete;
|
23
|
+
$.fn.textext.addPlugin('autocomplete', TextExtAutocomplete);
|
24
|
+
|
25
|
+
var p = TextExtAutocomplete.prototype,
|
26
|
+
|
27
|
+
CSS_DOT = '.',
|
28
|
+
CSS_SELECTED = 'text-selected',
|
29
|
+
CSS_DOT_SELECTED = CSS_DOT + CSS_SELECTED,
|
30
|
+
CSS_SUGGESTION = 'text-suggestion',
|
31
|
+
CSS_DOT_SUGGESTION = CSS_DOT + CSS_SUGGESTION,
|
32
|
+
CSS_LABEL = 'text-label',
|
33
|
+
CSS_DOT_LABEL = CSS_DOT + CSS_LABEL,
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Autocomplete plugin options are grouped under `autocomplete` when passed to the
|
37
|
+
* `$().textext()` function. For example:
|
38
|
+
*
|
39
|
+
* $('textarea').textext({
|
40
|
+
* plugins: 'autocomplete',
|
41
|
+
* autocomplete: {
|
42
|
+
* dropdownPosition: 'above'
|
43
|
+
* }
|
44
|
+
* })
|
45
|
+
*
|
46
|
+
* @author agorbatchev
|
47
|
+
* @date 2011/08/17
|
48
|
+
* @id TextExtAutocomplete.options
|
49
|
+
*/
|
50
|
+
|
51
|
+
/**
|
52
|
+
* This is a toggle switch to enable or disable the Autucomplete plugin. The value is checked
|
53
|
+
* each time at the top level which allows you to toggle this setting on the fly.
|
54
|
+
*
|
55
|
+
* @name autocomplete.enabled
|
56
|
+
* @default true
|
57
|
+
* @author agorbatchev
|
58
|
+
* @date 2011/08/17
|
59
|
+
* @id TextExtAutocomplete.options.autocomplete.enabled
|
60
|
+
*/
|
61
|
+
OPT_ENABLED = 'autocomplete.enabled',
|
62
|
+
|
63
|
+
/**
|
64
|
+
* This option allows to specify position of the dropdown. The two possible values
|
65
|
+
* are `above` and `below`.
|
66
|
+
*
|
67
|
+
* @name autocomplete.dropdown.position
|
68
|
+
* @default "below"
|
69
|
+
* @author agorbatchev
|
70
|
+
* @date 2011/08/17
|
71
|
+
* @id TextExtAutocomplete.options.autocomplete.dropdown.position
|
72
|
+
*/
|
73
|
+
OPT_POSITION = 'autocomplete.dropdown.position',
|
74
|
+
|
75
|
+
/**
|
76
|
+
* This option allows to specify maximum height of the dropdown. Value is taken directly, so
|
77
|
+
* if desired height is 200 pixels, value must be `200px`.
|
78
|
+
*
|
79
|
+
* @name autocomplete.dropdown.maxHeight
|
80
|
+
* @default "100px"
|
81
|
+
* @author agorbatchev
|
82
|
+
* @date 2011/12/29
|
83
|
+
* @id TextExtAutocomplete.options.autocomplete.dropdown.maxHeight
|
84
|
+
* @version 1.1
|
85
|
+
*/
|
86
|
+
OPT_MAX_HEIGHT = 'autocomplete.dropdown.maxHeight',
|
87
|
+
|
88
|
+
/**
|
89
|
+
* This option allows to override how a suggestion item is rendered. The value should be
|
90
|
+
* a function, the first argument of which is suggestion to be rendered and `this` context
|
91
|
+
* is the current instance of `TextExtAutocomplete`.
|
92
|
+
*
|
93
|
+
* [Click here](/manual/examples/autocomplete-with-custom-render.html) to see a demo.
|
94
|
+
*
|
95
|
+
* For example:
|
96
|
+
*
|
97
|
+
* $('textarea').textext({
|
98
|
+
* plugins: 'autocomplete',
|
99
|
+
* autocomplete: {
|
100
|
+
* render: function(suggestion)
|
101
|
+
* {
|
102
|
+
* return '<b>' + suggestion + '</b>';
|
103
|
+
* }
|
104
|
+
* }
|
105
|
+
* })
|
106
|
+
*
|
107
|
+
* @name autocomplete.render
|
108
|
+
* @default null
|
109
|
+
* @author agorbatchev
|
110
|
+
* @date 2011/12/23
|
111
|
+
* @id TextExtAutocomplete.options.autocomplete.render
|
112
|
+
* @version 1.1
|
113
|
+
*/
|
114
|
+
OPT_RENDER = 'autocomplete.render',
|
115
|
+
|
116
|
+
/**
|
117
|
+
* HTML source that is used to generate the dropdown.
|
118
|
+
*
|
119
|
+
* @name html.dropdown
|
120
|
+
* @default '<div class="text-dropdown"><div class="text-list"/></div>'
|
121
|
+
* @author agorbatchev
|
122
|
+
* @date 2011/08/17
|
123
|
+
* @id TextExtAutocomplete.options.html.dropdown
|
124
|
+
*/
|
125
|
+
OPT_HTML_DROPDOWN = 'html.dropdown',
|
126
|
+
|
127
|
+
/**
|
128
|
+
* HTML source that is used to generate each suggestion.
|
129
|
+
*
|
130
|
+
* @name html.suggestion
|
131
|
+
* @default '<div class="text-suggestion"><span class="text-label"/></div>'
|
132
|
+
* @author agorbatchev
|
133
|
+
* @date 2011/08/17
|
134
|
+
* @id TextExtAutocomplete.options.html.suggestion
|
135
|
+
*/
|
136
|
+
OPT_HTML_SUGGESTION = 'html.suggestion',
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Autocomplete plugin triggers or reacts to the following events.
|
140
|
+
*
|
141
|
+
* @author agorbatchev
|
142
|
+
* @date 2011/08/17
|
143
|
+
* @id TextExtAutocomplete.events
|
144
|
+
*/
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Autocomplete plugin triggers and reacts to the `hideDropdown` to hide the dropdown if it's
|
148
|
+
* already visible.
|
149
|
+
*
|
150
|
+
* @name hideDropdown
|
151
|
+
* @author agorbatchev
|
152
|
+
* @date 2011/08/17
|
153
|
+
* @id TextExtAutocomplete.events.hideDropdown
|
154
|
+
*/
|
155
|
+
EVENT_HIDE_DROPDOWN = 'hideDropdown',
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Autocomplete plugin triggers and reacts to the `showDropdown` to show the dropdown if it's
|
159
|
+
* not already visible.
|
160
|
+
*
|
161
|
+
* It's possible to pass a render callback function which will be called instead of the
|
162
|
+
* default `TextExtAutocomplete.renderSuggestions()`.
|
163
|
+
*
|
164
|
+
* Here's how another plugin should trigger this event with the optional render callback:
|
165
|
+
*
|
166
|
+
* this.trigger('showDropdown', function(autocomplete)
|
167
|
+
* {
|
168
|
+
* autocomplete.clearItems();
|
169
|
+
* var node = autocomplete.addDropdownItem('<b>Item</b>');
|
170
|
+
* node.addClass('new-look');
|
171
|
+
* });
|
172
|
+
*
|
173
|
+
* @name showDropdown
|
174
|
+
* @author agorbatchev
|
175
|
+
* @date 2011/08/17
|
176
|
+
* @id TextExtAutocomplete.events.showDropdown
|
177
|
+
*/
|
178
|
+
EVENT_SHOW_DROPDOWN = 'showDropdown',
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Autocomplete plugin reacts to the `setSuggestions` event triggered by other plugins which
|
182
|
+
* wish to populate the suggestion items. Suggestions should be passed as event argument in the
|
183
|
+
* following format: `{ data : [ ... ] }`.
|
184
|
+
*
|
185
|
+
* Here's how another plugin should trigger this event:
|
186
|
+
*
|
187
|
+
* this.trigger('setSuggestions', { data : [ "item1", "item2" ] });
|
188
|
+
*
|
189
|
+
* @name setSuggestions
|
190
|
+
* @author agorbatchev
|
191
|
+
* @date 2011/08/17
|
192
|
+
* @id TextExtAutocomplete.events.setSuggestions
|
193
|
+
*/
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Autocomplete plugin triggers the `getSuggestions` event and expects to get results by listening for
|
197
|
+
* the `setSuggestions` event.
|
198
|
+
*
|
199
|
+
* @name getSuggestions
|
200
|
+
* @author agorbatchev
|
201
|
+
* @date 2011/08/17
|
202
|
+
* @id TextExtAutocomplete.events.getSuggestions
|
203
|
+
*/
|
204
|
+
EVENT_GET_SUGGESTIONS = 'getSuggestions',
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Autocomplete plugin triggers `getFormData` event with the current suggestion so that the the core
|
208
|
+
* will be updated with serialized data to be submitted with the HTML form.
|
209
|
+
*
|
210
|
+
* @name getFormData
|
211
|
+
* @author agorbatchev
|
212
|
+
* @date 2011/08/18
|
213
|
+
* @id TextExtAutocomplete.events.getFormData
|
214
|
+
*/
|
215
|
+
EVENT_GET_FORM_DATA = 'getFormData',
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Autocomplete plugin reacts to `toggleDropdown` event and either shows or hides the dropdown
|
219
|
+
* depending if it's currently hidden or visible.
|
220
|
+
*
|
221
|
+
* @name toggleDropdown
|
222
|
+
* @author agorbatchev
|
223
|
+
* @date 2011/12/27
|
224
|
+
* @id TextExtAutocomplete.events.toggleDropdown
|
225
|
+
* @version 1.1
|
226
|
+
*/
|
227
|
+
EVENT_TOGGLE_DROPDOWN = 'toggleDropdown',
|
228
|
+
|
229
|
+
POSITION_ABOVE = 'above',
|
230
|
+
POSITION_BELOW = 'below',
|
231
|
+
|
232
|
+
DATA_MOUSEDOWN_ON_AUTOCOMPLETE = 'mousedownOnAutocomplete',
|
233
|
+
|
234
|
+
DEFAULT_OPTS = {
|
235
|
+
autocomplete : {
|
236
|
+
enabled : true,
|
237
|
+
dropdown : {
|
238
|
+
position : POSITION_BELOW,
|
239
|
+
maxHeight : '100px'
|
240
|
+
}
|
241
|
+
},
|
242
|
+
|
243
|
+
html : {
|
244
|
+
dropdown : '<div class="text-dropdown"><div class="text-list"/></div>',
|
245
|
+
suggestion : '<div class="text-suggestion"><span class="text-label"/></div>'
|
246
|
+
}
|
247
|
+
}
|
248
|
+
;
|
249
|
+
|
250
|
+
/**
|
251
|
+
* Initialization method called by the core during plugin instantiation.
|
252
|
+
*
|
253
|
+
* @signature TextExtAutocomplete.init(core)
|
254
|
+
*
|
255
|
+
* @param core {TextExt} Instance of the TextExt core class.
|
256
|
+
*
|
257
|
+
* @author agorbatchev
|
258
|
+
* @date 2011/08/17
|
259
|
+
* @id TextExtAutocomplete.init
|
260
|
+
*/
|
261
|
+
p.init = function(core)
|
262
|
+
{
|
263
|
+
var self = this;
|
264
|
+
|
265
|
+
self.baseInit(core, DEFAULT_OPTS);
|
266
|
+
|
267
|
+
var input = self.input(),
|
268
|
+
container
|
269
|
+
;
|
270
|
+
|
271
|
+
if(self.opts(OPT_ENABLED) === true)
|
272
|
+
{
|
273
|
+
self.on({
|
274
|
+
blur : self.onBlur,
|
275
|
+
anyKeyUp : self.onAnyKeyUp,
|
276
|
+
deleteKeyUp : self.onAnyKeyUp,
|
277
|
+
backspaceKeyPress : self.onBackspaceKeyPress,
|
278
|
+
enterKeyPress : self.onEnterKeyPress,
|
279
|
+
escapeKeyPress : self.onEscapeKeyPress,
|
280
|
+
setSuggestions : self.onSetSuggestions,
|
281
|
+
showDropdown : self.onShowDropdown,
|
282
|
+
hideDropdown : self.onHideDropdown,
|
283
|
+
toggleDropdown : self.onToggleDropdown,
|
284
|
+
postInvalidate : self.positionDropdown,
|
285
|
+
getFormData : self.onGetFormData,
|
286
|
+
|
287
|
+
// using keyDown for up/down keys so that repeat events are
|
288
|
+
// captured and user can scroll up/down by holding the keys
|
289
|
+
downKeyDown : self.onDownKeyDown,
|
290
|
+
upKeyDown : self.onUpKeyDown
|
291
|
+
});
|
292
|
+
|
293
|
+
container = $(self.opts(OPT_HTML_DROPDOWN));
|
294
|
+
container.insertAfter(input);
|
295
|
+
|
296
|
+
self.on(container, {
|
297
|
+
mouseover : self.onMouseOver,
|
298
|
+
mousedown : self.onMouseDown,
|
299
|
+
click : self.onClick
|
300
|
+
});
|
301
|
+
|
302
|
+
container
|
303
|
+
.css('maxHeight', self.opts(OPT_MAX_HEIGHT))
|
304
|
+
.addClass('text-position-' + self.opts(OPT_POSITION))
|
305
|
+
;
|
306
|
+
|
307
|
+
$(self).data('container', container);
|
308
|
+
|
309
|
+
$(document.body).click(function(e)
|
310
|
+
{
|
311
|
+
if (self.isDropdownVisible() && !self.withinWrapElement(e.target))
|
312
|
+
self.trigger(EVENT_HIDE_DROPDOWN);
|
313
|
+
});
|
314
|
+
|
315
|
+
self.positionDropdown();
|
316
|
+
}
|
317
|
+
};
|
318
|
+
|
319
|
+
/**
|
320
|
+
* Returns top level dropdown container HTML element.
|
321
|
+
*
|
322
|
+
* @signature TextExtAutocomplete.containerElement()
|
323
|
+
*
|
324
|
+
* @author agorbatchev
|
325
|
+
* @date 2011/08/15
|
326
|
+
* @id TextExtAutocomplete.containerElement
|
327
|
+
*/
|
328
|
+
p.containerElement = function()
|
329
|
+
{
|
330
|
+
return $(this).data('container');
|
331
|
+
};
|
332
|
+
|
333
|
+
//--------------------------------------------------------------------------------
|
334
|
+
// User mouse/keyboard input
|
335
|
+
|
336
|
+
/**
|
337
|
+
* Reacts to the `mouseOver` event triggered by the TextExt core.
|
338
|
+
*
|
339
|
+
* @signature TextExtAutocomplete.onMouseOver(e)
|
340
|
+
*
|
341
|
+
* @param e {Object} jQuery event.
|
342
|
+
*
|
343
|
+
* @author agorbatchev
|
344
|
+
* @date 2011/08/17
|
345
|
+
* @id TextExtAutocomplete.onMouseOver
|
346
|
+
*/
|
347
|
+
p.onMouseOver = function(e)
|
348
|
+
{
|
349
|
+
var self = this,
|
350
|
+
target = $(e.target)
|
351
|
+
;
|
352
|
+
|
353
|
+
if(target.is(CSS_DOT_SUGGESTION))
|
354
|
+
{
|
355
|
+
self.clearSelected();
|
356
|
+
target.addClass(CSS_SELECTED);
|
357
|
+
}
|
358
|
+
};
|
359
|
+
|
360
|
+
/**
|
361
|
+
* Reacts to the `mouseDown` event triggered by the TextExt core.
|
362
|
+
*
|
363
|
+
* @signature TextExtAutocomplete.onMouseDown(e)
|
364
|
+
*
|
365
|
+
* @param e {Object} jQuery event.
|
366
|
+
*
|
367
|
+
* @author adamayres
|
368
|
+
* @date 2012/01/13
|
369
|
+
* @id TextExtAutocomplete.onMouseDown
|
370
|
+
*/
|
371
|
+
p.onMouseDown = function(e)
|
372
|
+
{
|
373
|
+
this.containerElement().data(DATA_MOUSEDOWN_ON_AUTOCOMPLETE, true);
|
374
|
+
};
|
375
|
+
|
376
|
+
/**
|
377
|
+
* Reacts to the `click` event triggered by the TextExt core.
|
378
|
+
*
|
379
|
+
* @signature TextExtAutocomplete.onClick(e)
|
380
|
+
*
|
381
|
+
* @param e {Object} jQuery event.
|
382
|
+
*
|
383
|
+
* @author agorbatchev
|
384
|
+
* @date 2011/08/17
|
385
|
+
* @id TextExtAutocomplete.onClick
|
386
|
+
*/
|
387
|
+
p.onClick = function(e)
|
388
|
+
{
|
389
|
+
var self = this,
|
390
|
+
target = $(e.target)
|
391
|
+
;
|
392
|
+
|
393
|
+
if(target.is(CSS_DOT_SUGGESTION) || target.is(CSS_DOT_LABEL))
|
394
|
+
self.trigger('enterKeyPress');
|
395
|
+
|
396
|
+
if (self.core().hasPlugin('tags'))
|
397
|
+
self.val('');
|
398
|
+
};
|
399
|
+
|
400
|
+
/**
|
401
|
+
* Reacts to the `blur` event triggered by the TextExt core.
|
402
|
+
*
|
403
|
+
* @signature TextExtAutocomplete.onBlur(e)
|
404
|
+
*
|
405
|
+
* @param e {Object} jQuery event.
|
406
|
+
*
|
407
|
+
* @author agorbatchev
|
408
|
+
* @date 2011/08/17
|
409
|
+
* @id TextExtAutocomplete.onBlur
|
410
|
+
*/
|
411
|
+
p.onBlur = function(e)
|
412
|
+
{
|
413
|
+
var self = this,
|
414
|
+
container = self.containerElement(),
|
415
|
+
isBlurByMousedown = container.data(DATA_MOUSEDOWN_ON_AUTOCOMPLETE) === true
|
416
|
+
;
|
417
|
+
|
418
|
+
// only trigger a close event if the blur event was
|
419
|
+
// not triggered by a mousedown event on the autocomplete
|
420
|
+
// otherwise set focus back back on the input
|
421
|
+
if(self.isDropdownVisible())
|
422
|
+
isBlurByMousedown ? self.core().focusInput() : self.trigger(EVENT_HIDE_DROPDOWN);
|
423
|
+
|
424
|
+
container.removeData(DATA_MOUSEDOWN_ON_AUTOCOMPLETE);
|
425
|
+
};
|
426
|
+
|
427
|
+
/**
|
428
|
+
* Reacts to the `backspaceKeyPress` event triggered by the TextExt core.
|
429
|
+
*
|
430
|
+
* @signature TextExtAutocomplete.onBackspaceKeyPress(e)
|
431
|
+
*
|
432
|
+
* @param e {Object} jQuery event.
|
433
|
+
*
|
434
|
+
* @author agorbatchev
|
435
|
+
* @date 2011/08/17
|
436
|
+
* @id TextExtAutocomplete.onBackspaceKeyPress
|
437
|
+
*/
|
438
|
+
p.onBackspaceKeyPress = function(e)
|
439
|
+
{
|
440
|
+
var self = this,
|
441
|
+
isEmpty = self.val().length > 0
|
442
|
+
;
|
443
|
+
|
444
|
+
if(isEmpty || self.isDropdownVisible())
|
445
|
+
self.getSuggestions();
|
446
|
+
};
|
447
|
+
|
448
|
+
/**
|
449
|
+
* Reacts to the `anyKeyUp` event triggered by the TextExt core.
|
450
|
+
*
|
451
|
+
* @signature TextExtAutocomplete.onAnyKeyUp(e)
|
452
|
+
*
|
453
|
+
* @param e {Object} jQuery event.
|
454
|
+
*
|
455
|
+
* @author agorbatchev
|
456
|
+
* @date 2011/08/17
|
457
|
+
* @id TextExtAutocomplete.onAnyKeyUp
|
458
|
+
*/
|
459
|
+
p.onAnyKeyUp = function(e, keyCode)
|
460
|
+
{
|
461
|
+
var self = this,
|
462
|
+
isFunctionKey = self.opts('keys.' + keyCode) != null
|
463
|
+
;
|
464
|
+
|
465
|
+
if(self.val().length > 0 && !isFunctionKey)
|
466
|
+
self.getSuggestions();
|
467
|
+
};
|
468
|
+
|
469
|
+
/**
|
470
|
+
* Reacts to the `downKeyDown` event triggered by the TextExt core.
|
471
|
+
*
|
472
|
+
* @signature TextExtAutocomplete.onDownKeyDown(e)
|
473
|
+
*
|
474
|
+
* @param e {Object} jQuery event.
|
475
|
+
*
|
476
|
+
* @author agorbatchev
|
477
|
+
* @date 2011/08/17
|
478
|
+
* @id TextExtAutocomplete.onDownKeyDown
|
479
|
+
*/
|
480
|
+
p.onDownKeyDown = function(e)
|
481
|
+
{
|
482
|
+
var self = this;
|
483
|
+
|
484
|
+
self.isDropdownVisible()
|
485
|
+
? self.toggleNextSuggestion()
|
486
|
+
: self.getSuggestions()
|
487
|
+
;
|
488
|
+
};
|
489
|
+
|
490
|
+
/**
|
491
|
+
* Reacts to the `upKeyDown` event triggered by the TextExt core.
|
492
|
+
*
|
493
|
+
* @signature TextExtAutocomplete.onUpKeyDown(e)
|
494
|
+
*
|
495
|
+
* @param e {Object} jQuery event.
|
496
|
+
*
|
497
|
+
* @author agorbatchev
|
498
|
+
* @date 2011/08/17
|
499
|
+
* @id TextExtAutocomplete.onUpKeyDown
|
500
|
+
*/
|
501
|
+
p.onUpKeyDown = function(e)
|
502
|
+
{
|
503
|
+
this.togglePreviousSuggestion();
|
504
|
+
};
|
505
|
+
|
506
|
+
/**
|
507
|
+
* Reacts to the `enterKeyPress` event triggered by the TextExt core.
|
508
|
+
*
|
509
|
+
* @signature TextExtAutocomplete.onEnterKeyPress(e)
|
510
|
+
*
|
511
|
+
* @param e {Object} jQuery event.
|
512
|
+
*
|
513
|
+
* @author agorbatchev
|
514
|
+
* @date 2011/08/17
|
515
|
+
* @id TextExtAutocomplete.onEnterKeyPress
|
516
|
+
*/
|
517
|
+
p.onEnterKeyPress = function(e)
|
518
|
+
{
|
519
|
+
var self = this;
|
520
|
+
|
521
|
+
if(self.isDropdownVisible())
|
522
|
+
self.selectFromDropdown();
|
523
|
+
};
|
524
|
+
|
525
|
+
/**
|
526
|
+
* Reacts to the `escapeKeyPress` event triggered by the TextExt core. Hides the dropdown
|
527
|
+
* if it's currently visible.
|
528
|
+
*
|
529
|
+
* @signature TextExtAutocomplete.onEscapeKeyPress(e)
|
530
|
+
*
|
531
|
+
* @param e {Object} jQuery event.
|
532
|
+
*
|
533
|
+
* @author agorbatchev
|
534
|
+
* @date 2011/08/17
|
535
|
+
* @id TextExtAutocomplete.onEscapeKeyPress
|
536
|
+
*/
|
537
|
+
p.onEscapeKeyPress = function(e)
|
538
|
+
{
|
539
|
+
var self = this;
|
540
|
+
|
541
|
+
if(self.isDropdownVisible())
|
542
|
+
self.trigger(EVENT_HIDE_DROPDOWN);
|
543
|
+
};
|
544
|
+
|
545
|
+
//--------------------------------------------------------------------------------
|
546
|
+
// Core functionality
|
547
|
+
|
548
|
+
/**
|
549
|
+
* Positions dropdown either below or above the input based on the `autocomplete.dropdown.position`
|
550
|
+
* option specified, which could be either `above` or `below`.
|
551
|
+
*
|
552
|
+
* @signature TextExtAutocomplete.positionDropdown()
|
553
|
+
*
|
554
|
+
* @author agorbatchev
|
555
|
+
* @date 2011/08/15
|
556
|
+
* @id TextExtAutocomplete.positionDropdown
|
557
|
+
*/
|
558
|
+
p.positionDropdown = function()
|
559
|
+
{
|
560
|
+
var self = this,
|
561
|
+
container = self.containerElement(),
|
562
|
+
direction = self.opts(OPT_POSITION),
|
563
|
+
height = self.core().wrapElement().outerHeight(),
|
564
|
+
css = {}
|
565
|
+
;
|
566
|
+
|
567
|
+
css[direction === POSITION_ABOVE ? 'bottom' : 'top'] = height + 'px';
|
568
|
+
container.css(css);
|
569
|
+
};
|
570
|
+
|
571
|
+
/**
|
572
|
+
* Returns list of all the suggestion HTML elements in the dropdown.
|
573
|
+
*
|
574
|
+
* @signature TextExtAutocomplete.suggestionElements()
|
575
|
+
*
|
576
|
+
* @author agorbatchev
|
577
|
+
* @date 2011/08/17
|
578
|
+
* @id TextExtAutocomplete.suggestionElements
|
579
|
+
*/
|
580
|
+
p.suggestionElements = function()
|
581
|
+
{
|
582
|
+
return this.containerElement().find(CSS_DOT_SUGGESTION);
|
583
|
+
};
|
584
|
+
|
585
|
+
|
586
|
+
/**
|
587
|
+
* Highlights specified suggestion as selected in the dropdown.
|
588
|
+
*
|
589
|
+
* @signature TextExtAutocomplete.setSelectedSuggestion(suggestion)
|
590
|
+
*
|
591
|
+
* @param suggestion {Object} Suggestion object. With the default `ItemManager` this
|
592
|
+
* is expected to be a string, anything else with custom implementations.
|
593
|
+
*
|
594
|
+
* @author agorbatchev
|
595
|
+
* @date 2011/08/17
|
596
|
+
* @id TextExtAutocomplete.setSelectedSuggestion
|
597
|
+
*/
|
598
|
+
p.setSelectedSuggestion = function(suggestion)
|
599
|
+
{
|
600
|
+
if(!suggestion)
|
601
|
+
return;
|
602
|
+
|
603
|
+
var self = this,
|
604
|
+
all = self.suggestionElements(),
|
605
|
+
target = all.first(),
|
606
|
+
item, i
|
607
|
+
;
|
608
|
+
|
609
|
+
self.clearSelected();
|
610
|
+
|
611
|
+
for(i = 0; i < all.length; i++)
|
612
|
+
{
|
613
|
+
item = $(all[i]);
|
614
|
+
|
615
|
+
if(self.itemManager().compareItems(item.data(CSS_SUGGESTION), suggestion))
|
616
|
+
{
|
617
|
+
target = item.addClass(CSS_SELECTED);
|
618
|
+
break;
|
619
|
+
}
|
620
|
+
}
|
621
|
+
|
622
|
+
target.addClass(CSS_SELECTED);
|
623
|
+
self.scrollSuggestionIntoView(target);
|
624
|
+
};
|
625
|
+
|
626
|
+
/**
|
627
|
+
* Returns the first suggestion HTML element from the dropdown that is highlighted as selected.
|
628
|
+
*
|
629
|
+
* @signature TextExtAutocomplete.selectedSuggestionElement()
|
630
|
+
*
|
631
|
+
* @author agorbatchev
|
632
|
+
* @date 2011/08/17
|
633
|
+
* @id TextExtAutocomplete.selectedSuggestionElement
|
634
|
+
*/
|
635
|
+
p.selectedSuggestionElement = function()
|
636
|
+
{
|
637
|
+
return this.suggestionElements().filter(CSS_DOT_SELECTED).first();
|
638
|
+
};
|
639
|
+
|
640
|
+
/**
|
641
|
+
* Returns `true` if dropdown is currently visible, `false` otherwise.
|
642
|
+
*
|
643
|
+
* @signature TextExtAutocomplete.isDropdownVisible()
|
644
|
+
*
|
645
|
+
* @author agorbatchev
|
646
|
+
* @date 2011/08/17
|
647
|
+
* @id TextExtAutocomplete.isDropdownVisible
|
648
|
+
*/
|
649
|
+
p.isDropdownVisible = function()
|
650
|
+
{
|
651
|
+
return this.containerElement().is(':visible') === true;
|
652
|
+
};
|
653
|
+
|
654
|
+
/**
|
655
|
+
* Reacts to the `getFormData` event triggered by the core. Returns data with the
|
656
|
+
* weight of 100 to be *less than the Tags plugin* data weight. The weights system is
|
657
|
+
* covered in greater detail in the [`getFormData`][1] event documentation.
|
658
|
+
*
|
659
|
+
* [1]: /manual/textext.html#getformdata
|
660
|
+
*
|
661
|
+
* @signature TextExtAutocomplete.onGetFormData(e, data, keyCode)
|
662
|
+
*
|
663
|
+
* @param e {Object} jQuery event.
|
664
|
+
* @param data {Object} Data object to be populated.
|
665
|
+
* @param keyCode {Number} Key code that triggered the original update request.
|
666
|
+
*
|
667
|
+
* @author agorbatchev
|
668
|
+
* @date 2011/08/22
|
669
|
+
* @id TextExtAutocomplete.onGetFormData
|
670
|
+
*/
|
671
|
+
p.onGetFormData = function(e, data, keyCode)
|
672
|
+
{
|
673
|
+
var self = this,
|
674
|
+
val = self.val(),
|
675
|
+
inputValue = val,
|
676
|
+
formValue = val
|
677
|
+
;
|
678
|
+
data[100] = self.formDataObject(inputValue, formValue);
|
679
|
+
};
|
680
|
+
|
681
|
+
/**
|
682
|
+
* Returns initialization priority of the Autocomplete plugin which is expected to be
|
683
|
+
* *greater than the Tags plugin* because of the dependencies. The value is 200.
|
684
|
+
*
|
685
|
+
* @signature TextExtAutocomplete.initPriority()
|
686
|
+
*
|
687
|
+
* @author agorbatchev
|
688
|
+
* @date 2011/08/22
|
689
|
+
* @id TextExtAutocomplete.initPriority
|
690
|
+
*/
|
691
|
+
p.initPriority = function()
|
692
|
+
{
|
693
|
+
return 200;
|
694
|
+
};
|
695
|
+
|
696
|
+
/**
|
697
|
+
* Reacts to the `hideDropdown` event and hides the dropdown if it's already visible.
|
698
|
+
*
|
699
|
+
* @signature TextExtAutocomplete.onHideDropdown(e)
|
700
|
+
*
|
701
|
+
* @param e {Object} jQuery event.
|
702
|
+
*
|
703
|
+
* @author agorbatchev
|
704
|
+
* @date 2011/08/17
|
705
|
+
* @id TextExtAutocomplete.onHideDropdown
|
706
|
+
*/
|
707
|
+
p.onHideDropdown = function(e)
|
708
|
+
{
|
709
|
+
this.hideDropdown();
|
710
|
+
};
|
711
|
+
|
712
|
+
/**
|
713
|
+
* Reacts to the 'toggleDropdown` event and shows or hides the dropdown depending if
|
714
|
+
* it's currently hidden or visible.
|
715
|
+
*
|
716
|
+
* @signature TextExtAutocomplete.onToggleDropdown(e)
|
717
|
+
*
|
718
|
+
* @param e {Object} jQuery event.
|
719
|
+
*
|
720
|
+
* @author agorbatchev
|
721
|
+
* @date 2011/12/27
|
722
|
+
* @id TextExtAutocomplete.onToggleDropdown
|
723
|
+
* @version 1.1.0
|
724
|
+
*/
|
725
|
+
p.onToggleDropdown = function(e)
|
726
|
+
{
|
727
|
+
var self = this;
|
728
|
+
self.trigger(self.containerElement().is(':visible') ? EVENT_HIDE_DROPDOWN : EVENT_SHOW_DROPDOWN);
|
729
|
+
};
|
730
|
+
|
731
|
+
/**
|
732
|
+
* Reacts to the `showDropdown` event and shows the dropdown if it's not already visible.
|
733
|
+
* It's possible to pass a render callback function which will be called instead of the
|
734
|
+
* default `TextExtAutocomplete.renderSuggestions()`.
|
735
|
+
*
|
736
|
+
* If no suggestion were previously loaded, it will fire `getSuggestions` event and exit.
|
737
|
+
*
|
738
|
+
* Here's how another plugin should trigger this event with the optional render callback:
|
739
|
+
*
|
740
|
+
* this.trigger('showDropdown', function(autocomplete)
|
741
|
+
* {
|
742
|
+
* autocomplete.clearItems();
|
743
|
+
* var node = autocomplete.addDropdownItem('<b>Item</b>');
|
744
|
+
* node.addClass('new-look');
|
745
|
+
* });
|
746
|
+
*
|
747
|
+
* @signature TextExtAutocomplete.onShowDropdown(e, renderCallback)
|
748
|
+
*
|
749
|
+
* @param e {Object} jQuery event.
|
750
|
+
* @param renderCallback {Function} Optional callback function which would be used to
|
751
|
+
* render dropdown items. As a first argument, reference to the current instance of
|
752
|
+
* Autocomplete plugin will be supplied. It's assumed, that if this callback is provided
|
753
|
+
* rendering will be handled completely manually.
|
754
|
+
*
|
755
|
+
* @author agorbatchev
|
756
|
+
* @date 2011/08/17
|
757
|
+
* @id TextExtAutocomplete.onShowDropdown
|
758
|
+
*/
|
759
|
+
p.onShowDropdown = function(e, renderCallback)
|
760
|
+
{
|
761
|
+
var self = this,
|
762
|
+
current = self.selectedSuggestionElement().data(CSS_SUGGESTION),
|
763
|
+
suggestions = self._suggestions
|
764
|
+
;
|
765
|
+
|
766
|
+
if(!suggestions)
|
767
|
+
return self.trigger(EVENT_GET_SUGGESTIONS);
|
768
|
+
|
769
|
+
if($.isFunction(renderCallback))
|
770
|
+
{
|
771
|
+
renderCallback(self);
|
772
|
+
}
|
773
|
+
else
|
774
|
+
{
|
775
|
+
self.renderSuggestions(self._suggestions);
|
776
|
+
self.toggleNextSuggestion();
|
777
|
+
}
|
778
|
+
|
779
|
+
self.showDropdown(self.containerElement());
|
780
|
+
self.setSelectedSuggestion(current);
|
781
|
+
};
|
782
|
+
|
783
|
+
/**
|
784
|
+
* Reacts to the `setSuggestions` event. Expects to recieve the payload as the second argument
|
785
|
+
* in the following structure:
|
786
|
+
*
|
787
|
+
* {
|
788
|
+
* result : [ "item1", "item2" ],
|
789
|
+
* showHideDropdown : false
|
790
|
+
* }
|
791
|
+
*
|
792
|
+
* Notice the optional `showHideDropdown` option. By default, ie without the `showHideDropdown`
|
793
|
+
* value the method will trigger either `showDropdown` or `hideDropdown` depending if there are
|
794
|
+
* suggestions. If set to `false`, no event is triggered.
|
795
|
+
*
|
796
|
+
* @signature TextExtAutocomplete.onSetSuggestions(e, data)
|
797
|
+
*
|
798
|
+
* @param data {Object} Data payload.
|
799
|
+
*
|
800
|
+
* @author agorbatchev
|
801
|
+
* @date 2011/08/17
|
802
|
+
* @id TextExtAutocomplete.onSetSuggestions
|
803
|
+
*/
|
804
|
+
p.onSetSuggestions = function(e, data)
|
805
|
+
{
|
806
|
+
var self = this,
|
807
|
+
suggestions = self._suggestions = data.result
|
808
|
+
;
|
809
|
+
|
810
|
+
if(data.showHideDropdown !== false)
|
811
|
+
self.trigger(suggestions === null || suggestions.length === 0 ? EVENT_HIDE_DROPDOWN : EVENT_SHOW_DROPDOWN);
|
812
|
+
};
|
813
|
+
|
814
|
+
/**
|
815
|
+
* Prepears for and triggers the `getSuggestions` event with the `{ query : {String} }` as second
|
816
|
+
* argument.
|
817
|
+
*
|
818
|
+
* @signature TextExtAutocomplete.getSuggestions()
|
819
|
+
*
|
820
|
+
* @author agorbatchev
|
821
|
+
* @date 2011/08/17
|
822
|
+
* @id TextExtAutocomplete.getSuggestions
|
823
|
+
*/
|
824
|
+
p.getSuggestions = function()
|
825
|
+
{
|
826
|
+
var self = this,
|
827
|
+
val = self.val()
|
828
|
+
;
|
829
|
+
|
830
|
+
if(self._previousInputValue == val)
|
831
|
+
return;
|
832
|
+
|
833
|
+
// if user clears input, then we want to select first suggestion
|
834
|
+
// instead of the last one
|
835
|
+
if(val == '')
|
836
|
+
current = null;
|
837
|
+
|
838
|
+
self._previousInputValue = val;
|
839
|
+
self.trigger(EVENT_GET_SUGGESTIONS, { query : val });
|
840
|
+
};
|
841
|
+
|
842
|
+
/**
|
843
|
+
* Removes all HTML suggestion items from the dropdown.
|
844
|
+
*
|
845
|
+
* @signature TextExtAutocomplete.clearItems()
|
846
|
+
*
|
847
|
+
* @author agorbatchev
|
848
|
+
* @date 2011/08/17
|
849
|
+
* @id TextExtAutocomplete.clearItems
|
850
|
+
*/
|
851
|
+
p.clearItems = function()
|
852
|
+
{
|
853
|
+
this.containerElement().find('.text-list').children().remove();
|
854
|
+
};
|
855
|
+
|
856
|
+
/**
|
857
|
+
* Clears all and renders passed suggestions.
|
858
|
+
*
|
859
|
+
* @signature TextExtAutocomplete.renderSuggestions(suggestions)
|
860
|
+
*
|
861
|
+
* @param suggestions {Array} List of suggestions to render.
|
862
|
+
*
|
863
|
+
* @author agorbatchev
|
864
|
+
* @date 2011/08/17
|
865
|
+
* @id TextExtAutocomplete.renderSuggestions
|
866
|
+
*/
|
867
|
+
p.renderSuggestions = function(suggestions)
|
868
|
+
{
|
869
|
+
var self = this;
|
870
|
+
|
871
|
+
self.clearItems();
|
872
|
+
|
873
|
+
$.each(suggestions || [], function(index, item)
|
874
|
+
{
|
875
|
+
self.addSuggestion(item);
|
876
|
+
});
|
877
|
+
};
|
878
|
+
|
879
|
+
/**
|
880
|
+
* Shows the dropdown.
|
881
|
+
*
|
882
|
+
* @signature TextExtAutocomplete.showDropdown()
|
883
|
+
*
|
884
|
+
* @author agorbatchev
|
885
|
+
* @date 2011/08/17
|
886
|
+
* @id TextExtAutocomplete.showDropdown
|
887
|
+
*/
|
888
|
+
p.showDropdown = function()
|
889
|
+
{
|
890
|
+
this.containerElement().show();
|
891
|
+
};
|
892
|
+
|
893
|
+
/**
|
894
|
+
* Hides the dropdown.
|
895
|
+
*
|
896
|
+
* @signature TextExtAutocomplete.hideDropdown()
|
897
|
+
*
|
898
|
+
* @author agorbatchev
|
899
|
+
* @date 2011/08/17
|
900
|
+
* @id TextExtAutocomplete.hideDropdown
|
901
|
+
*/
|
902
|
+
p.hideDropdown = function()
|
903
|
+
{
|
904
|
+
var self = this,
|
905
|
+
dropdown = self.containerElement()
|
906
|
+
;
|
907
|
+
|
908
|
+
self._previousInputValue = null;
|
909
|
+
dropdown.hide();
|
910
|
+
};
|
911
|
+
|
912
|
+
/**
|
913
|
+
* Adds single suggestion to the bottom of the dropdown. Uses `ItemManager.itemToString()` to
|
914
|
+
* serialize provided suggestion to string.
|
915
|
+
*
|
916
|
+
* @signature TextExtAutocomplete.addSuggestion(suggestion)
|
917
|
+
*
|
918
|
+
* @param suggestion {Object} Suggestion item. By default expected to be a string.
|
919
|
+
*
|
920
|
+
* @author agorbatchev
|
921
|
+
* @date 2011/08/17
|
922
|
+
* @id TextExtAutocomplete.addSuggestion
|
923
|
+
*/
|
924
|
+
p.addSuggestion = function(suggestion)
|
925
|
+
{
|
926
|
+
var self = this,
|
927
|
+
renderer = self.opts(OPT_RENDER),
|
928
|
+
node = self.addDropdownItem(renderer ? renderer.call(self, suggestion) : self.itemManager().itemToString(suggestion))
|
929
|
+
;
|
930
|
+
|
931
|
+
node.data(CSS_SUGGESTION, suggestion);
|
932
|
+
};
|
933
|
+
|
934
|
+
/**
|
935
|
+
* Adds and returns HTML node to the bottom of the dropdown.
|
936
|
+
*
|
937
|
+
* @signature TextExtAutocomplete.addDropdownItem(html)
|
938
|
+
*
|
939
|
+
* @param html {String} HTML to be inserted into the item.
|
940
|
+
*
|
941
|
+
* @author agorbatchev
|
942
|
+
* @date 2011/08/17
|
943
|
+
* @id TextExtAutocomplete.addDropdownItem
|
944
|
+
*/
|
945
|
+
p.addDropdownItem = function(html)
|
946
|
+
{
|
947
|
+
var self = this,
|
948
|
+
container = self.containerElement().find('.text-list'),
|
949
|
+
node = $(self.opts(OPT_HTML_SUGGESTION))
|
950
|
+
;
|
951
|
+
|
952
|
+
node.find('.text-label').html(html);
|
953
|
+
container.append(node);
|
954
|
+
return node;
|
955
|
+
};
|
956
|
+
|
957
|
+
/**
|
958
|
+
* Removes selection highlight from all suggestion elements.
|
959
|
+
*
|
960
|
+
* @signature TextExtAutocomplete.clearSelected()
|
961
|
+
*
|
962
|
+
* @author agorbatchev
|
963
|
+
* @date 2011/08/02
|
964
|
+
* @id TextExtAutocomplete.clearSelected
|
965
|
+
*/
|
966
|
+
p.clearSelected = function()
|
967
|
+
{
|
968
|
+
this.suggestionElements().removeClass(CSS_SELECTED);
|
969
|
+
};
|
970
|
+
|
971
|
+
/**
|
972
|
+
* Selects next suggestion relative to the current one. If there's no
|
973
|
+
* currently selected suggestion, it will select the first one. Selected
|
974
|
+
* suggestion will always be scrolled into view.
|
975
|
+
*
|
976
|
+
* @signature TextExtAutocomplete.toggleNextSuggestion()
|
977
|
+
*
|
978
|
+
* @author agorbatchev
|
979
|
+
* @date 2011/08/02
|
980
|
+
* @id TextExtAutocomplete.toggleNextSuggestion
|
981
|
+
*/
|
982
|
+
p.toggleNextSuggestion = function()
|
983
|
+
{
|
984
|
+
var self = this,
|
985
|
+
selected = self.selectedSuggestionElement(),
|
986
|
+
next
|
987
|
+
;
|
988
|
+
|
989
|
+
if(selected.length > 0)
|
990
|
+
{
|
991
|
+
next = selected.next();
|
992
|
+
|
993
|
+
if(next.length > 0)
|
994
|
+
selected.removeClass(CSS_SELECTED);
|
995
|
+
}
|
996
|
+
else
|
997
|
+
{
|
998
|
+
next = self.suggestionElements().first();
|
999
|
+
}
|
1000
|
+
|
1001
|
+
next.addClass(CSS_SELECTED);
|
1002
|
+
self.scrollSuggestionIntoView(next);
|
1003
|
+
};
|
1004
|
+
|
1005
|
+
/**
|
1006
|
+
* Selects previous suggestion relative to the current one. Selected
|
1007
|
+
* suggestion will always be scrolled into view.
|
1008
|
+
*
|
1009
|
+
* @signature TextExtAutocomplete.togglePreviousSuggestion()
|
1010
|
+
*
|
1011
|
+
* @author agorbatchev
|
1012
|
+
* @date 2011/08/02
|
1013
|
+
* @id TextExtAutocomplete.togglePreviousSuggestion
|
1014
|
+
*/
|
1015
|
+
p.togglePreviousSuggestion = function()
|
1016
|
+
{
|
1017
|
+
var self = this,
|
1018
|
+
selected = self.selectedSuggestionElement(),
|
1019
|
+
prev = selected.prev()
|
1020
|
+
;
|
1021
|
+
|
1022
|
+
if(prev.length == 0)
|
1023
|
+
return;
|
1024
|
+
|
1025
|
+
self.clearSelected();
|
1026
|
+
prev.addClass(CSS_SELECTED);
|
1027
|
+
self.scrollSuggestionIntoView(prev);
|
1028
|
+
};
|
1029
|
+
|
1030
|
+
/**
|
1031
|
+
* Scrolls specified HTML suggestion element into the view.
|
1032
|
+
*
|
1033
|
+
* @signature TextExtAutocomplete.scrollSuggestionIntoView(item)
|
1034
|
+
*
|
1035
|
+
* @param item {HTMLElement} jQuery HTML suggestion element which needs to
|
1036
|
+
* scrolled into view.
|
1037
|
+
*
|
1038
|
+
* @author agorbatchev
|
1039
|
+
* @date 2011/08/17
|
1040
|
+
* @id TextExtAutocomplete.scrollSuggestionIntoView
|
1041
|
+
*/
|
1042
|
+
p.scrollSuggestionIntoView = function(item)
|
1043
|
+
{
|
1044
|
+
var itemHeight = item.outerHeight(),
|
1045
|
+
dropdown = this.containerElement(),
|
1046
|
+
dropdownHeight = dropdown.innerHeight(),
|
1047
|
+
scrollPos = dropdown.scrollTop(),
|
1048
|
+
itemTop = (item.position() || {}).top,
|
1049
|
+
scrollTo = null,
|
1050
|
+
paddingTop = parseInt(dropdown.css('paddingTop'))
|
1051
|
+
;
|
1052
|
+
|
1053
|
+
if(itemTop == null)
|
1054
|
+
return;
|
1055
|
+
|
1056
|
+
// if scrolling down and item is below the bottom fold
|
1057
|
+
if(itemTop + itemHeight > dropdownHeight)
|
1058
|
+
scrollTo = itemTop + scrollPos + itemHeight - dropdownHeight + paddingTop;
|
1059
|
+
|
1060
|
+
// if scrolling up and item is above the top fold
|
1061
|
+
if(itemTop < 0)
|
1062
|
+
scrollTo = itemTop + scrollPos - paddingTop;
|
1063
|
+
|
1064
|
+
if(scrollTo != null)
|
1065
|
+
dropdown.scrollTop(scrollTo);
|
1066
|
+
};
|
1067
|
+
|
1068
|
+
/**
|
1069
|
+
* Uses the value from the text input to finish autocomplete action. Currently selected
|
1070
|
+
* suggestion from the dropdown will be used to complete the action. Triggers `hideDropdown`
|
1071
|
+
* event.
|
1072
|
+
*
|
1073
|
+
* @signature TextExtAutocomplete.selectFromDropdown()
|
1074
|
+
*
|
1075
|
+
* @author agorbatchev
|
1076
|
+
* @date 2011/08/17
|
1077
|
+
* @id TextExtAutocomplete.selectFromDropdown
|
1078
|
+
*/
|
1079
|
+
p.selectFromDropdown = function()
|
1080
|
+
{
|
1081
|
+
var self = this,
|
1082
|
+
suggestion = self.selectedSuggestionElement().data(CSS_SUGGESTION)
|
1083
|
+
;
|
1084
|
+
|
1085
|
+
if(suggestion)
|
1086
|
+
{
|
1087
|
+
self.val(self.itemManager().itemToString(suggestion));
|
1088
|
+
self.core().getFormData();
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
self.trigger(EVENT_HIDE_DROPDOWN);
|
1092
|
+
};
|
1093
|
+
|
1094
|
+
/**
|
1095
|
+
* Determines if the specified HTML element is within the TextExt core wrap HTML element.
|
1096
|
+
*
|
1097
|
+
* @signature TextExtAutocomplete.withinWrapElement(element)
|
1098
|
+
*
|
1099
|
+
* @param element {HTMLElement} element to check if contained by wrap element
|
1100
|
+
*
|
1101
|
+
* @author adamayres
|
1102
|
+
* @version 1.3.0
|
1103
|
+
* @date 2012/01/15
|
1104
|
+
* @id TextExtAutocomplete.withinWrapElement
|
1105
|
+
*/
|
1106
|
+
p.withinWrapElement = function(element)
|
1107
|
+
{
|
1108
|
+
return this.core().wrapElement().find(element).size() > 0;
|
1109
|
+
}
|
1110
|
+
})(jQuery);
|