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
@@ -2,35 +2,24 @@ class @Tags
|
|
2
2
|
|
3
3
|
constructor: (element, options={}) ->
|
4
4
|
@el = $(element)
|
5
|
-
@
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
tags: () =>
|
12
|
-
query = @el.select2('container').find('input.select2-input').val()
|
13
|
-
@search(query)
|
14
|
-
@options = $.extend {}, @options, options
|
15
|
-
|
16
|
-
@el.select2(@options)
|
17
|
-
|
18
|
-
search: (query='') ->
|
19
|
-
if query?
|
20
|
-
$.ajax(
|
5
|
+
@el.textext(
|
6
|
+
plugins: 'autocomplete ajax tags arrow'
|
7
|
+
tags:
|
8
|
+
items: @initTags()
|
9
|
+
ajax:
|
10
|
+
url: '/admin/api/tags/'
|
21
11
|
type: 'GET'
|
22
|
-
|
23
|
-
|
24
|
-
async: false
|
25
|
-
success: (data) =>
|
26
|
-
@tags = $.map(data.results, (e) => e.text)
|
27
|
-
)
|
28
|
-
@tags
|
12
|
+
cacheResults: true
|
13
|
+
)
|
29
14
|
|
15
|
+
initTags: () =>
|
16
|
+
tags = @el.text().split(', ')
|
17
|
+
@el.text('')
|
18
|
+
tags
|
30
19
|
|
31
20
|
$.fn.taggable = ->
|
32
21
|
@each ->
|
33
22
|
new Tags(this)
|
34
23
|
|
35
24
|
jQuery ->
|
36
|
-
$('
|
25
|
+
$('textarea.js-taggable').taggable()
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*!
|
2
|
+
* Lightbox for Bootstrap 3 by @ashleydw
|
3
|
+
* https://github.com/ashleydw/lightbox
|
4
|
+
*
|
5
|
+
* License: https://github.com/ashleydw/lightbox/blob/master/LICENSE
|
6
|
+
*/
|
7
|
+
(function(){"use strict";var a,b;a=jQuery,b=function(b,c){var d,e,f,g=this;return this.options=a.extend({title:null,footer:null,remote:null},a.fn.ekkoLightbox.defaults,c||{}),this.$element=a(b),d="",this.modal_id=this.options.modal_id?this.options.modal_id:"ekkoLightbox-"+Math.floor(1e3*Math.random()+1),f='<div class="modal-header"'+(this.options.title||this.options.always_show_close?"":' style="display:none"')+'><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h4 class="modal-title">'+(this.options.title||" ")+"</h4></div>",e='<div class="modal-footer"'+(this.options.footer?"":' style="display:none"')+">"+this.options.footer+"</div>",a(document.body).append('<div id="'+this.modal_id+'" class="ekko-lightbox modal fade" tabindex="-1"><div class="modal-dialog"><div class="modal-content">'+f+'<div class="modal-body"><div class="ekko-lightbox-container"><div></div></div></div>'+e+"</div></div></div>"),this.modal=a("#"+this.modal_id),this.modal_dialog=this.modal.find(".modal-dialog").first(),this.modal_content=this.modal.find(".modal-content").first(),this.modal_body=this.modal.find(".modal-body").first(),this.lightbox_container=this.modal_body.find(".ekko-lightbox-container").first(),this.lightbox_body=this.lightbox_container.find("> div:first-child").first(),this.showLoading(),this.modal_arrows=null,this.border={top:parseFloat(this.modal_dialog.css("border-top-width"))+parseFloat(this.modal_content.css("border-top-width"))+parseFloat(this.modal_body.css("border-top-width")),right:parseFloat(this.modal_dialog.css("border-right-width"))+parseFloat(this.modal_content.css("border-right-width"))+parseFloat(this.modal_body.css("border-right-width")),bottom:parseFloat(this.modal_dialog.css("border-bottom-width"))+parseFloat(this.modal_content.css("border-bottom-width"))+parseFloat(this.modal_body.css("border-bottom-width")),left:parseFloat(this.modal_dialog.css("border-left-width"))+parseFloat(this.modal_content.css("border-left-width"))+parseFloat(this.modal_body.css("border-left-width"))},this.padding={top:parseFloat(this.modal_dialog.css("padding-top"))+parseFloat(this.modal_content.css("padding-top"))+parseFloat(this.modal_body.css("padding-top")),right:parseFloat(this.modal_dialog.css("padding-right"))+parseFloat(this.modal_content.css("padding-right"))+parseFloat(this.modal_body.css("padding-right")),bottom:parseFloat(this.modal_dialog.css("padding-bottom"))+parseFloat(this.modal_content.css("padding-bottom"))+parseFloat(this.modal_body.css("padding-bottom")),left:parseFloat(this.modal_dialog.css("padding-left"))+parseFloat(this.modal_content.css("padding-left"))+parseFloat(this.modal_body.css("padding-left"))},this.modal.on("show.bs.modal",this.options.onShow.bind(this)).on("shown.bs.modal",function(){return g.modal_shown(),g.options.onShown.call(g)}).on("hide.bs.modal",this.options.onHide.bind(this)).on("hidden.bs.modal",function(){return g.gallery&&a(document).off("keydown.ekkoLightbox"),g.modal.remove(),g.options.onHidden.call(g)}).modal("show",c),this.modal},b.prototype={modal_shown:function(){var b,c=this;return this.options.remote?(this.gallery=this.$element.data("gallery"),this.gallery&&(this.gallery_items="document.body"===this.options.gallery_parent_selector||""===this.options.gallery_parent_selector?a(document.body).find('*[data-toggle="lightbox"][data-gallery="'+this.gallery+'"]'):this.$element.parents(this.options.gallery_parent_selector).first().find('*[data-toggle="lightbox"][data-gallery="'+this.gallery+'"]'),this.gallery_index=this.gallery_items.index(this.$element),a(document).on("keydown.ekkoLightbox",this.navigate.bind(this)),this.options.directional_arrows&&this.gallery_items.length>1&&(this.lightbox_container.prepend('<div class="ekko-lightbox-nav-overlay"><a href="#" class="'+this.strip_stops(this.options.left_arrow_class)+'"></a><a href="#" class="'+this.strip_stops(this.options.right_arrow_class)+'"></a></div>'),this.modal_arrows=this.lightbox_container.find("div.ekko-lightbox-nav-overlay").first(),this.lightbox_container.find("a"+this.strip_spaces(this.options.left_arrow_class)).on("click",function(a){return a.preventDefault(),c.navigate_left()}),this.lightbox_container.find("a"+this.strip_spaces(this.options.right_arrow_class)).on("click",function(a){return a.preventDefault(),c.navigate_right()}))),this.options.type?"image"===this.options.type?this.preloadImage(this.options.remote,!0):"youtube"===this.options.type&&(b=this.getYoutubeId(this.options.remote))?this.showYoutubeVideo(b):"vimeo"===this.options.type?this.showVimeoVideo(this.options.remote):"instagram"===this.options.type?this.showInstagramVideo(this.options.remote):"url"===this.options.type?this.showInstagramVideo(this.options.remote):this.error('Could not detect remote target type. Force the type using data-type="image|youtube|vimeo|url"'):this.detectRemoteType(this.options.remote)):this.error("No remote target given")},strip_stops:function(a){return a.replace(/\./g,"")},strip_spaces:function(a){return a.replace(/\s/g,"")},isImage:function(a){return a.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i)},isSwf:function(a){return a.match(/\.(swf)((\?|#).*)?$/i)},getYoutubeId:function(a){var b;return b=a.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/),b&&11===b[2].length?b[2]:!1},getVimeoId:function(a){return a.indexOf("vimeo")>0?a:!1},getInstagramId:function(a){return a.indexOf("instagram")>0?a:!1},navigate:function(a){if(a=a||window.event,39===a.keyCode||37===a.keyCode){if(39===a.keyCode)return this.navigate_right();if(37===a.keyCode)return this.navigate_left()}},navigate_left:function(){var b;if(1!==this.gallery_items.length)return this.showLoading(),0===this.gallery_index?this.gallery_index=this.gallery_items.length-1:this.gallery_index--,this.options.onNavigate("left",this.gallery_index),this.$element=a(this.gallery_items.get(this.gallery_index)),this.updateTitleAndFooter(),b=this.$element.attr("data-remote")||this.$element.attr("href"),this.detectRemoteType(b,this.$element.attr("data-type"))},navigate_right:function(){var b,c;if(1!==this.gallery_items.length)return this.showLoading(),this.gallery_index===this.gallery_items.length-1?this.gallery_index=0:this.gallery_index++,this.options.onNavigate("right",this.gallery_index),this.$element=a(this.gallery_items.get(this.gallery_index)),c=this.$element.attr("data-remote")||this.$element.attr("href"),this.updateTitleAndFooter(),this.detectRemoteType(c,this.$element.attr("data-type")),this.gallery_index+1<this.gallery_items.length&&(b=a(this.gallery_items.get(this.gallery_index+1),!1),c=b.attr("data-remote")||b.attr("href"),"image"===b.attr("data-type")||this.isImage(c))?this.preloadImage(c,!1):void 0},detectRemoteType:function(a,b){var c;return"image"===b||this.isImage(a)?(this.options.type="image",this.preloadImage(a,!0)):"youtube"===b||(c=this.getYoutubeId(a))?(this.options.type="youtube",this.showYoutubeVideo(c)):"vimeo"===b||(c=this.getVimeoId(a))?(this.options.type="vimeo",this.showVimeoVideo(c)):"instagram"===b||(c=this.getInstagramId(a))?(this.options.type="instagram",this.showInstagramVideo(c)):"url"===b||(c=this.getInstagramId(a))?(this.options.type="instagram",this.showInstagramVideo(c)):(this.options.type="url",this.loadRemoteContent(a))},updateTitleAndFooter:function(){var a,b,c,d;return c=this.modal_content.find(".modal-header"),b=this.modal_content.find(".modal-footer"),d=this.$element.data("title")||"",a=this.$element.data("footer")||"",d||this.options.always_show_close?c.css("display","").find(".modal-title").html(d||" "):c.css("display","none"),a?b.css("display","").html(a):b.css("display","none"),this},showLoading:function(){return this.lightbox_body.html('<div class="modal-loading">Loading..</div>'),this},showYoutubeVideo:function(a){var b,c,d;return b=560/315,d=this.$element.data("width")||560,d=this.checkDimensions(d),c=d/b,this.resize(d),this.lightbox_body.html('<iframe width="'+d+'" height="'+c+'" src="//www.youtube.com/embed/'+a+'?badge=0&autoplay=1&html5=1" frameborder="0" allowfullscreen></iframe>'),this.modal_arrows?this.modal_arrows.css("display","none"):void 0},showVimeoVideo:function(a){var b,c,d;return b=500/281,d=this.$element.data("width")||560,d=this.checkDimensions(d),c=d/b,this.resize(d),this.lightbox_body.html('<iframe width="'+d+'" height="'+c+'" src="'+a+'?autoplay=1" frameborder="0" allowfullscreen></iframe>'),this.modal_arrows?this.modal_arrows.css("display","none"):void 0},showInstagramVideo:function(a){var b;return b=this.$element.data("width")||612,b=this.checkDimensions(b),this.resize(b),this.lightbox_body.html('<iframe width="'+b+'" height="'+b+'" src="'+this.addTrailingSlash(a)+'embed/" frameborder="0" allowfullscreen></iframe>'),this.modal_arrows?this.modal_arrows.css("display","none"):void 0},loadRemoteContent:function(b){var c,d,e=this;return d=this.$element.data("width")||560,this.resize(d),c=this.$element.data("disableExternalCheck")||!1,console.log(c,this.isExternal(b)),c||this.isExternal(b)?this.lightbox_body.html('<iframe width="'+d+'" height="'+d+'" src="'+b+'" frameborder="0" allowfullscreen></iframe>'):this.lightbox_body.load(b,a.proxy(function(){return e.$element.trigger("loaded.bs.modal")})),this.modal_arrows?this.modal_arrows.css("display","block"):void 0},isExternal:function(a){var b;return b=a.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/),"string"==typeof b[1]&&b[1].length>0&&b[1].toLowerCase()!==location.protocol?!0:"string"==typeof b[2]&&b[2].length>0&&b[2].replace(new RegExp(":("+{"http:":80,"https:":443}[location.protocol]+")?$"),"")!==location.host?!0:!1},error:function(a){return this.lightbox_body.html(a),this},preloadImage:function(b,c){var d,e=this;return d=new Image,(null==c||c===!0)&&(d.onload=function(){var b;return b=a("<img />"),b.attr("src",d.src),b.addClass("img-responsive"),e.lightbox_body.html(b),e.modal_arrows&&e.modal_arrows.css("display","block"),e.resize(d.width)},d.onerror=function(){return e.error("Failed to load image: "+b)}),d.src=b,d},resize:function(b){var c;return c=b+this.border.left+this.padding.left+this.padding.right+this.border.right,this.modal_dialog.css("width","auto").css("max-width",c),this.lightbox_container.find("a").css("padding-top",function(){return a(this).parent().height()/2}),this},checkDimensions:function(a){var b,c;return c=a+this.border.left+this.padding.left+this.padding.right+this.border.right,b=document.body.clientWidth,c>b&&(a=this.modal_body.width()),a},close:function(){return this.modal.modal("hide")},addTrailingSlash:function(a){return"/"!==a.substr(-1)&&(a+="/"),a}},a.fn.ekkoLightbox=function(c){return this.each(function(){var d;return d=a(this),c=a.extend({remote:d.attr("data-remote")||d.attr("href"),gallery_parent_selector:d.attr("data-parent"),type:d.attr("data-type")},c,d.data()),new b(this,c),this})},a.fn.ekkoLightbox.defaults={gallery_parent_selector:"*:not(.row)",left_arrow_class:".glyphicon .glyphicon-chevron-left",right_arrow_class:".glyphicon .glyphicon-chevron-right",directional_arrows:!0,type:null,always_show_close:!0,onShow:function(){},onShown:function(){},onHide:function(){},onHidden:function(){},onNavigate:function(){}}}).call(this);
|
@@ -0,0 +1,1618 @@
|
|
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($, undefined)
|
10
|
+
{
|
11
|
+
/**
|
12
|
+
* TextExt is the main core class which by itself doesn't provide any functionality
|
13
|
+
* that is user facing, however it has the underlying mechanics to bring all the
|
14
|
+
* plugins together under one roof and make them work with each other or on their
|
15
|
+
* own.
|
16
|
+
*
|
17
|
+
* @author agorbatchev
|
18
|
+
* @date 2011/08/19
|
19
|
+
* @id TextExt
|
20
|
+
*/
|
21
|
+
function TextExt() {};
|
22
|
+
|
23
|
+
/**
|
24
|
+
* ItemManager is used to seamlessly convert between string that come from the user input to whatever
|
25
|
+
* the format the item data is being passed around in. It's used by all plugins that in one way or
|
26
|
+
* another operate with items, such as Tags, Filter, Autocomplete and Suggestions. Default implementation
|
27
|
+
* works with `String` type.
|
28
|
+
*
|
29
|
+
* Each instance of `TextExt` creates a new instance of default implementation of `ItemManager`
|
30
|
+
* unless `itemManager` option was set to another implementation.
|
31
|
+
*
|
32
|
+
* To satisfy requirements of managing items of type other than a `String`, different implementation
|
33
|
+
* if `ItemManager` should be supplied.
|
34
|
+
*
|
35
|
+
* If you wish to bring your own implementation, you need to create a new class and implement all the
|
36
|
+
* methods that `ItemManager` has. After, you need to supply your pass via the `itemManager` option during
|
37
|
+
* initialization like so:
|
38
|
+
*
|
39
|
+
* $('#input').textext({
|
40
|
+
* itemManager : CustomItemManager
|
41
|
+
* })
|
42
|
+
*
|
43
|
+
* @author agorbatchev
|
44
|
+
* @date 2011/08/19
|
45
|
+
* @id ItemManager
|
46
|
+
*/
|
47
|
+
function ItemManager() {};
|
48
|
+
|
49
|
+
/**
|
50
|
+
* TextExtPlugin is a base class for all plugins. It provides common methods which are reused
|
51
|
+
* by majority of plugins.
|
52
|
+
*
|
53
|
+
* All plugins must register themselves by calling the `$.fn.textext.addPlugin(name, constructor)`
|
54
|
+
* function while providing plugin name and constructor. The plugin name is the same name that user
|
55
|
+
* will identify the plugin in the `plugins` option when initializing TextExt component and constructor
|
56
|
+
* function will create a new instance of the plugin. *Without registering, the core won't
|
57
|
+
* be able to see the plugin.*
|
58
|
+
*
|
59
|
+
* <span class="new label version">new in 1.2.0</span> You can get instance of each plugin from the core
|
60
|
+
* via associated function with the same name as the plugin. For example:
|
61
|
+
*
|
62
|
+
* $('#input').textext()[0].tags()
|
63
|
+
* $('#input').textext()[0].autocomplete()
|
64
|
+
* ...
|
65
|
+
*
|
66
|
+
* @author agorbatchev
|
67
|
+
* @date 2011/08/19
|
68
|
+
* @id TextExtPlugin
|
69
|
+
*/
|
70
|
+
function TextExtPlugin() {};
|
71
|
+
|
72
|
+
var stringify = (JSON || {}).stringify,
|
73
|
+
slice = Array.prototype.slice,
|
74
|
+
p,
|
75
|
+
UNDEFINED = 'undefined',
|
76
|
+
|
77
|
+
/**
|
78
|
+
* TextExt provides a way to pass in the options to configure the core as well as
|
79
|
+
* each plugin that is being currently used. The jQuery exposed plugin `$().textext()`
|
80
|
+
* function takes a hash object with key/value set of options. For example:
|
81
|
+
*
|
82
|
+
* $('textarea').textext({
|
83
|
+
* enabled: true
|
84
|
+
* })
|
85
|
+
*
|
86
|
+
* There are multiple ways of passing in the options:
|
87
|
+
*
|
88
|
+
* 1. Options could be nested multiple levels deep and accessed using all lowercased, dot
|
89
|
+
* separated style, eg `foo.bar.world`. The manual is using this style for clarity and
|
90
|
+
* consistency. For example:
|
91
|
+
*
|
92
|
+
* {
|
93
|
+
* item: {
|
94
|
+
* manager: ...
|
95
|
+
* },
|
96
|
+
*
|
97
|
+
* html: {
|
98
|
+
* wrap: ...
|
99
|
+
* },
|
100
|
+
*
|
101
|
+
* autocomplete: {
|
102
|
+
* enabled: ...,
|
103
|
+
* dropdown: {
|
104
|
+
* position: ...
|
105
|
+
* }
|
106
|
+
* }
|
107
|
+
* }
|
108
|
+
*
|
109
|
+
* 2. Options could be specified using camel cased names in a flat key/value fashion like so:
|
110
|
+
*
|
111
|
+
* {
|
112
|
+
* itemManager: ...,
|
113
|
+
* htmlWrap: ...,
|
114
|
+
* autocompleteEnabled: ...,
|
115
|
+
* autocompleteDropdownPosition: ...
|
116
|
+
* }
|
117
|
+
*
|
118
|
+
* 3. Finally, options could be specified in mixed style. It's important to understand that
|
119
|
+
* for each dot separated name, its alternative in camel case is also checked for, eg for
|
120
|
+
* `foo.bar.world` it's alternatives could be `fooBarWorld`, `foo.barWorld` or `fooBar.world`,
|
121
|
+
* which translates to `{ foo: { bar: { world: ... } } }`, `{ fooBarWorld: ... }`,
|
122
|
+
* `{ foo : { barWorld : ... } }` or `{ fooBar: { world: ... } }` respectively. For example:
|
123
|
+
*
|
124
|
+
* {
|
125
|
+
* itemManager : ...,
|
126
|
+
* htmlWrap: ...,
|
127
|
+
* autocomplete: {
|
128
|
+
* enabled: ...,
|
129
|
+
* dropdownPosition: ...
|
130
|
+
* }
|
131
|
+
* }
|
132
|
+
*
|
133
|
+
* Mixed case is used through out the code, wherever it seems appropriate. However in the code, all option
|
134
|
+
* names are specified in the dot notation because it works both ways where as camel case is not
|
135
|
+
* being converted to its alternative dot notation.
|
136
|
+
*
|
137
|
+
* @author agorbatchev
|
138
|
+
* @date 2011/08/17
|
139
|
+
* @id TextExt.options
|
140
|
+
*/
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Default instance of `ItemManager` which takes `String` type as default for tags.
|
144
|
+
*
|
145
|
+
* @name item.manager
|
146
|
+
* @default ItemManager
|
147
|
+
* @author agorbatchev
|
148
|
+
* @date 2011/08/19
|
149
|
+
* @id TextExt.options.item.manager
|
150
|
+
*/
|
151
|
+
OPT_ITEM_MANAGER = 'item.manager',
|
152
|
+
|
153
|
+
/**
|
154
|
+
* List of plugins that should be used with the current instance of TextExt. The list could be
|
155
|
+
* specified as array of strings or as comma or space separated string.
|
156
|
+
*
|
157
|
+
* @name plugins
|
158
|
+
* @default []
|
159
|
+
* @author agorbatchev
|
160
|
+
* @date 2011/08/19
|
161
|
+
* @id TextExt.options.plugins
|
162
|
+
*/
|
163
|
+
OPT_PLUGINS = 'plugins',
|
164
|
+
|
165
|
+
/**
|
166
|
+
* TextExt allows for overriding of virtually any method that the core or any of its plugins
|
167
|
+
* use. This could be accomplished through the use of the `ext` option.
|
168
|
+
*
|
169
|
+
* It's possible to specifically target the core or any plugin, as well as overwrite all the
|
170
|
+
* desired methods everywhere.
|
171
|
+
*
|
172
|
+
* 1. Targeting the core:
|
173
|
+
*
|
174
|
+
* ext: {
|
175
|
+
* core: {
|
176
|
+
* trigger: function()
|
177
|
+
* {
|
178
|
+
* console.log('TextExt.trigger', arguments);
|
179
|
+
* $.fn.textext.TextExt.prototype.trigger.apply(this, arguments);
|
180
|
+
* }
|
181
|
+
* }
|
182
|
+
* }
|
183
|
+
*
|
184
|
+
* 2. Targeting individual plugins:
|
185
|
+
*
|
186
|
+
* ext: {
|
187
|
+
* tags: {
|
188
|
+
* addTags: function(tags)
|
189
|
+
* {
|
190
|
+
* console.log('TextExtTags.addTags', tags);
|
191
|
+
* $.fn.textext.TextExtTags.prototype.addTags.apply(this, arguments);
|
192
|
+
* }
|
193
|
+
* }
|
194
|
+
* }
|
195
|
+
*
|
196
|
+
* 3. Targeting `ItemManager` instance:
|
197
|
+
*
|
198
|
+
* ext: {
|
199
|
+
* itemManager: {
|
200
|
+
* stringToItem: function(str)
|
201
|
+
* {
|
202
|
+
* console.log('ItemManager.stringToItem', str);
|
203
|
+
* return $.fn.textext.ItemManager.prototype.stringToItem.apply(this, arguments);
|
204
|
+
* }
|
205
|
+
* }
|
206
|
+
* }
|
207
|
+
*
|
208
|
+
* 4. And finally, in edge cases you can extend everything at once:
|
209
|
+
*
|
210
|
+
* ext: {
|
211
|
+
* '*': {
|
212
|
+
* fooBar: function() {}
|
213
|
+
* }
|
214
|
+
* }
|
215
|
+
*
|
216
|
+
* @name ext
|
217
|
+
* @default {}
|
218
|
+
* @author agorbatchev
|
219
|
+
* @date 2011/08/19
|
220
|
+
* @id TextExt.options.ext
|
221
|
+
*/
|
222
|
+
OPT_EXT = 'ext',
|
223
|
+
|
224
|
+
/**
|
225
|
+
* HTML source that is used to generate elements necessary for the core and all other
|
226
|
+
* plugins to function.
|
227
|
+
*
|
228
|
+
* @name html.wrap
|
229
|
+
* @default '<div class="text-core"><div class="text-wrap"/></div>'
|
230
|
+
* @author agorbatchev
|
231
|
+
* @date 2011/08/19
|
232
|
+
* @id TextExt.options.html.wrap
|
233
|
+
*/
|
234
|
+
OPT_HTML_WRAP = 'html.wrap',
|
235
|
+
|
236
|
+
/**
|
237
|
+
* HTML source that is used to generate hidden input value of which will be submitted
|
238
|
+
* with the HTML form.
|
239
|
+
*
|
240
|
+
* @name html.hidden
|
241
|
+
* @default '<input type="hidden" />'
|
242
|
+
* @author agorbatchev
|
243
|
+
* @date 2011/08/20
|
244
|
+
* @id TextExt.options.html.hidden
|
245
|
+
*/
|
246
|
+
OPT_HTML_HIDDEN = 'html.hidden',
|
247
|
+
|
248
|
+
/**
|
249
|
+
* Hash table of key codes and key names for which special events will be created
|
250
|
+
* by the core. For each entry a `[name]KeyDown`, `[name]KeyUp` and `[name]KeyPress` events
|
251
|
+
* will be triggered along side with `anyKeyUp` and `anyKeyDown` events for every
|
252
|
+
* key stroke.
|
253
|
+
*
|
254
|
+
* Here's a list of default keys:
|
255
|
+
*
|
256
|
+
* {
|
257
|
+
* 8 : 'backspace',
|
258
|
+
* 9 : 'tab',
|
259
|
+
* 13 : 'enter!',
|
260
|
+
* 27 : 'escape!',
|
261
|
+
* 37 : 'left',
|
262
|
+
* 38 : 'up!',
|
263
|
+
* 39 : 'right',
|
264
|
+
* 40 : 'down!',
|
265
|
+
* 46 : 'delete',
|
266
|
+
* 108 : 'numpadEnter'
|
267
|
+
* }
|
268
|
+
*
|
269
|
+
* Please note the `!` at the end of some keys. This tells the core that by default
|
270
|
+
* this keypress will be trapped and not passed on to the text input.
|
271
|
+
*
|
272
|
+
* @name keys
|
273
|
+
* @default { ... }
|
274
|
+
* @author agorbatchev
|
275
|
+
* @date 2011/08/19
|
276
|
+
* @id TextExt.options.keys
|
277
|
+
*/
|
278
|
+
OPT_KEYS = 'keys',
|
279
|
+
|
280
|
+
/**
|
281
|
+
* The core triggers or reacts to the following events.
|
282
|
+
*
|
283
|
+
* @author agorbatchev
|
284
|
+
* @date 2011/08/17
|
285
|
+
* @id TextExt.events
|
286
|
+
*/
|
287
|
+
|
288
|
+
/**
|
289
|
+
* Core triggers `preInvalidate` event before the dimensions of padding on the text input
|
290
|
+
* are set.
|
291
|
+
*
|
292
|
+
* @name preInvalidate
|
293
|
+
* @author agorbatchev
|
294
|
+
* @date 2011/08/19
|
295
|
+
* @id TextExt.events.preInvalidate
|
296
|
+
*/
|
297
|
+
EVENT_PRE_INVALIDATE = 'preInvalidate',
|
298
|
+
|
299
|
+
/**
|
300
|
+
* Core triggers `postInvalidate` event after the dimensions of padding on the text input
|
301
|
+
* are set.
|
302
|
+
*
|
303
|
+
* @name postInvalidate
|
304
|
+
* @author agorbatchev
|
305
|
+
* @date 2011/08/19
|
306
|
+
* @id TextExt.events.postInvalidate
|
307
|
+
*/
|
308
|
+
EVENT_POST_INVALIDATE = 'postInvalidate',
|
309
|
+
|
310
|
+
/**
|
311
|
+
* Core triggers `getFormData` on every key press to collect data that will be populated
|
312
|
+
* into the hidden input that will be submitted with the HTML form and data that will
|
313
|
+
* be displayed in the input field that user is currently interacting with.
|
314
|
+
*
|
315
|
+
* All plugins that wish to affect how the data is presented or sent must react to
|
316
|
+
* `getFormData` and populate the data in the following format:
|
317
|
+
*
|
318
|
+
* {
|
319
|
+
* input : {String},
|
320
|
+
* form : {Object}
|
321
|
+
* }
|
322
|
+
*
|
323
|
+
* The data key must be a numeric weight which will be used to determine which data
|
324
|
+
* ends up being used. Data with the highest numerical weight gets the priority. This
|
325
|
+
* allows plugins to set the final data regardless of their initialization order, which
|
326
|
+
* otherwise would be impossible.
|
327
|
+
*
|
328
|
+
* For example, the Tags and Autocomplete plugins have to work side by side and Tags
|
329
|
+
* plugin must get priority on setting the data. Therefore the Tags plugin sets data
|
330
|
+
* with the weight 200 where as the Autocomplete plugin sets data with the weight 100.
|
331
|
+
*
|
332
|
+
* Here's an example of a typical `getFormData` handler:
|
333
|
+
*
|
334
|
+
* TextExtPlugin.prototype.onGetFormData = function(e, data, keyCode)
|
335
|
+
* {
|
336
|
+
* data[100] = self.formDataObject('input value', 'form value');
|
337
|
+
* };
|
338
|
+
*
|
339
|
+
* Core also reacts to the `getFormData` and updates hidden input with data which will be
|
340
|
+
* submitted with the HTML form.
|
341
|
+
*
|
342
|
+
* @name getFormData
|
343
|
+
* @author agorbatchev
|
344
|
+
* @date 2011/08/19
|
345
|
+
* @id TextExt.events.getFormData
|
346
|
+
*/
|
347
|
+
EVENT_GET_FORM_DATA = 'getFormData',
|
348
|
+
|
349
|
+
/**
|
350
|
+
* Core triggers and reacts to the `setFormData` event to update the actual value in the
|
351
|
+
* hidden input that will be submitted with the HTML form. Second argument can be value
|
352
|
+
* of any type and by default it will be JSON serialized with `TextExt.serializeData()`
|
353
|
+
* function.
|
354
|
+
*
|
355
|
+
* @name setFormData
|
356
|
+
* @author agorbatchev
|
357
|
+
* @date 2011/08/22
|
358
|
+
* @id TextExt.events.setFormData
|
359
|
+
*/
|
360
|
+
EVENT_SET_FORM_DATA = 'setFormData',
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Core triggers and reacts to the `setInputData` event to update the actual value in the
|
364
|
+
* text input that user is interacting with. Second argument must be of a `String` type
|
365
|
+
* the value of which will be set into the text input.
|
366
|
+
*
|
367
|
+
* @name setInputData
|
368
|
+
* @author agorbatchev
|
369
|
+
* @date 2011/08/22
|
370
|
+
* @id TextExt.events.setInputData
|
371
|
+
*/
|
372
|
+
EVENT_SET_INPUT_DATA = 'setInputData',
|
373
|
+
|
374
|
+
/**
|
375
|
+
* Core triggers `postInit` event to let plugins run code after all plugins have been
|
376
|
+
* created and initialized. This is a good place to set some kind of global values before
|
377
|
+
* somebody gets to use them. This is not the right place to expect all plugins to finish
|
378
|
+
* their initialization.
|
379
|
+
*
|
380
|
+
* @name postInit
|
381
|
+
* @author agorbatchev
|
382
|
+
* @date 2011/08/19
|
383
|
+
* @id TextExt.events.postInit
|
384
|
+
*/
|
385
|
+
EVENT_POST_INIT = 'postInit',
|
386
|
+
|
387
|
+
/**
|
388
|
+
* Core triggers `ready` event after all global configuration and prepearation has been
|
389
|
+
* done and the TextExt component is ready for use. Event handlers should expect all
|
390
|
+
* values to be set and the plugins to be in the final state.
|
391
|
+
*
|
392
|
+
* @name ready
|
393
|
+
* @author agorbatchev
|
394
|
+
* @date 2011/08/19
|
395
|
+
* @id TextExt.events.ready
|
396
|
+
*/
|
397
|
+
EVENT_READY = 'ready',
|
398
|
+
|
399
|
+
/**
|
400
|
+
* Core triggers `anyKeyUp` event for every key up event triggered within the component.
|
401
|
+
*
|
402
|
+
* @name anyKeyUp
|
403
|
+
* @author agorbatchev
|
404
|
+
* @date 2011/08/19
|
405
|
+
* @id TextExt.events.anyKeyUp
|
406
|
+
*/
|
407
|
+
|
408
|
+
/**
|
409
|
+
* Core triggers `anyKeyDown` event for every key down event triggered within the component.
|
410
|
+
*
|
411
|
+
* @name anyKeyDown
|
412
|
+
* @author agorbatchev
|
413
|
+
* @date 2011/08/19
|
414
|
+
* @id TextExt.events.anyKeyDown
|
415
|
+
*/
|
416
|
+
|
417
|
+
/**
|
418
|
+
* Core triggers `[name]KeyUp` event for every key specifid in the `keys` option that is
|
419
|
+
* triggered within the component.
|
420
|
+
*
|
421
|
+
* @name [name]KeyUp
|
422
|
+
* @author agorbatchev
|
423
|
+
* @date 2011/08/19
|
424
|
+
* @id TextExt.events.[name]KeyUp
|
425
|
+
*/
|
426
|
+
|
427
|
+
/**
|
428
|
+
* Core triggers `[name]KeyDown` event for every key specified in the `keys` option that is
|
429
|
+
* triggered within the component.
|
430
|
+
*
|
431
|
+
* @name [name]KeyDown
|
432
|
+
* @author agorbatchev
|
433
|
+
* @date 2011/08/19
|
434
|
+
* @id TextExt.events.[name]KeyDown
|
435
|
+
*/
|
436
|
+
|
437
|
+
/**
|
438
|
+
* Core triggers `[name]KeyPress` event for every key specified in the `keys` option that is
|
439
|
+
* triggered within the component.
|
440
|
+
*
|
441
|
+
* @name [name]KeyPress
|
442
|
+
* @author agorbatchev
|
443
|
+
* @date 2011/08/19
|
444
|
+
* @id TextExt.events.[name]KeyPress
|
445
|
+
*/
|
446
|
+
|
447
|
+
DEFAULT_OPTS = {
|
448
|
+
itemManager : ItemManager,
|
449
|
+
|
450
|
+
plugins : [],
|
451
|
+
ext : {},
|
452
|
+
|
453
|
+
html : {
|
454
|
+
wrap : '<div class="text-core"><div class="text-wrap"/></div>',
|
455
|
+
hidden : '<input type="hidden" />'
|
456
|
+
},
|
457
|
+
|
458
|
+
keys : {
|
459
|
+
8 : 'backspace',
|
460
|
+
9 : 'tab',
|
461
|
+
13 : 'enter!',
|
462
|
+
27 : 'escape!',
|
463
|
+
37 : 'left',
|
464
|
+
38 : 'up!',
|
465
|
+
39 : 'right',
|
466
|
+
40 : 'down!',
|
467
|
+
46 : 'delete',
|
468
|
+
108 : 'numpadEnter'
|
469
|
+
}
|
470
|
+
}
|
471
|
+
;
|
472
|
+
|
473
|
+
// Freak out if there's no JSON.stringify function found
|
474
|
+
if(!stringify)
|
475
|
+
throw new Error('JSON.stringify() not found');
|
476
|
+
|
477
|
+
/**
|
478
|
+
* Returns object property by name where name is dot-separated and object is multiple levels deep.
|
479
|
+
* @param target Object Source object.
|
480
|
+
* @param name String Dot separated property name, ie `foo.bar.world`
|
481
|
+
* @id core.getProperty
|
482
|
+
*/
|
483
|
+
function getProperty(source, name)
|
484
|
+
{
|
485
|
+
if(typeof(name) === 'string')
|
486
|
+
name = name.split('.');
|
487
|
+
|
488
|
+
var fullCamelCaseName = name.join('.').replace(/\.(\w)/g, function(match, letter) { return letter.toUpperCase() }),
|
489
|
+
nestedName = name.shift(),
|
490
|
+
result
|
491
|
+
;
|
492
|
+
|
493
|
+
if(typeof(result = source[fullCamelCaseName]) != UNDEFINED)
|
494
|
+
result = result;
|
495
|
+
|
496
|
+
else if(typeof(result = source[nestedName]) != UNDEFINED && name.length > 0)
|
497
|
+
result = getProperty(result, name);
|
498
|
+
|
499
|
+
// name.length here should be zero
|
500
|
+
return result;
|
501
|
+
};
|
502
|
+
|
503
|
+
/**
|
504
|
+
* Hooks up specified events in the scope of the current object.
|
505
|
+
* @author agorbatchev
|
506
|
+
* @date 2011/08/09
|
507
|
+
*/
|
508
|
+
function hookupEvents()
|
509
|
+
{
|
510
|
+
var args = slice.apply(arguments),
|
511
|
+
self = this,
|
512
|
+
target = args.length === 1 ? self : args.shift(),
|
513
|
+
event
|
514
|
+
;
|
515
|
+
|
516
|
+
args = args[0] || {};
|
517
|
+
|
518
|
+
function bind(event, handler)
|
519
|
+
{
|
520
|
+
target.bind(event, function()
|
521
|
+
{
|
522
|
+
// apply handler to our PLUGIN object, not the target
|
523
|
+
return handler.apply(self, arguments);
|
524
|
+
});
|
525
|
+
}
|
526
|
+
|
527
|
+
for(event in args)
|
528
|
+
bind(event, args[event]);
|
529
|
+
};
|
530
|
+
|
531
|
+
function formDataObject(input, form)
|
532
|
+
{
|
533
|
+
return { 'input' : input, 'form' : form };
|
534
|
+
};
|
535
|
+
|
536
|
+
//--------------------------------------------------------------------------------
|
537
|
+
// ItemManager core component
|
538
|
+
|
539
|
+
p = ItemManager.prototype;
|
540
|
+
|
541
|
+
/**
|
542
|
+
* Initialization method called by the core during instantiation.
|
543
|
+
*
|
544
|
+
* @signature ItemManager.init(core)
|
545
|
+
*
|
546
|
+
* @param core {TextExt} Instance of the TextExt core class.
|
547
|
+
*
|
548
|
+
* @author agorbatchev
|
549
|
+
* @date 2011/08/19
|
550
|
+
* @id ItemManager.init
|
551
|
+
*/
|
552
|
+
p.init = function(core)
|
553
|
+
{
|
554
|
+
};
|
555
|
+
|
556
|
+
/**
|
557
|
+
* Filters out items from the list that don't match the query and returns remaining items. Default
|
558
|
+
* implementation checks if the item starts with the query.
|
559
|
+
*
|
560
|
+
* @signature ItemManager.filter(list, query)
|
561
|
+
*
|
562
|
+
* @param list {Array} List of items. Default implementation works with strings.
|
563
|
+
* @param query {String} Query string.
|
564
|
+
*
|
565
|
+
* @author agorbatchev
|
566
|
+
* @date 2011/08/19
|
567
|
+
* @id ItemManager.filter
|
568
|
+
*/
|
569
|
+
p.filter = function(list, query)
|
570
|
+
{
|
571
|
+
var result = [],
|
572
|
+
i, item
|
573
|
+
;
|
574
|
+
|
575
|
+
for(i = 0; i < list.length; i++)
|
576
|
+
{
|
577
|
+
item = list[i];
|
578
|
+
if(this.itemContains(item, query))
|
579
|
+
result.push(item);
|
580
|
+
}
|
581
|
+
|
582
|
+
return result;
|
583
|
+
};
|
584
|
+
|
585
|
+
/**
|
586
|
+
* Returns `true` if specified item contains another string, `false` otherwise. In the default implementation
|
587
|
+
* `String.indexOf()` is used to check if item string begins with the needle string.
|
588
|
+
*
|
589
|
+
* @signature ItemManager.itemContains(item, needle)
|
590
|
+
*
|
591
|
+
* @param item {Object} Item to check. Default implementation works with strings.
|
592
|
+
* @param needle {String} Search string to be found within the item.
|
593
|
+
*
|
594
|
+
* @author agorbatchev
|
595
|
+
* @date 2011/08/19
|
596
|
+
* @id ItemManager.itemContains
|
597
|
+
*/
|
598
|
+
p.itemContains = function(item, needle)
|
599
|
+
{
|
600
|
+
return this.itemToString(item).toLowerCase().indexOf(needle.toLowerCase()) == 0;
|
601
|
+
};
|
602
|
+
|
603
|
+
/**
|
604
|
+
* Converts specified string to item. Because default implemenation works with string, input string
|
605
|
+
* is simply returned back. To use custom objects, different implementation of this method could
|
606
|
+
* return something like `{ name : {String} }`.
|
607
|
+
*
|
608
|
+
* @signature ItemManager.stringToItem(str)
|
609
|
+
*
|
610
|
+
* @param str {String} Input string.
|
611
|
+
*
|
612
|
+
* @author agorbatchev
|
613
|
+
* @date 2011/08/19
|
614
|
+
* @id ItemManager.stringToItem
|
615
|
+
*/
|
616
|
+
p.stringToItem = function(str)
|
617
|
+
{
|
618
|
+
return str;
|
619
|
+
};
|
620
|
+
|
621
|
+
/**
|
622
|
+
* Converts specified item to string. Because default implemenation works with string, input string
|
623
|
+
* is simply returned back. To use custom objects, different implementation of this method could
|
624
|
+
* for example return `name` field of `{ name : {String} }`.
|
625
|
+
*
|
626
|
+
* @signature ItemManager.itemToString(item)
|
627
|
+
*
|
628
|
+
* @param item {Object} Input item to be converted to string.
|
629
|
+
*
|
630
|
+
* @author agorbatchev
|
631
|
+
* @date 2011/08/19
|
632
|
+
* @id ItemManager.itemToString
|
633
|
+
*/
|
634
|
+
p.itemToString = function(item)
|
635
|
+
{
|
636
|
+
return item;
|
637
|
+
};
|
638
|
+
|
639
|
+
/**
|
640
|
+
* Returns `true` if both items are equal, `false` otherwise. Because default implemenation works with
|
641
|
+
* string, input items are compared as strings. To use custom objects, different implementation of this
|
642
|
+
* method could for example compare `name` fields of `{ name : {String} }` type object.
|
643
|
+
*
|
644
|
+
* @signature ItemManager.compareItems(item1, item2)
|
645
|
+
*
|
646
|
+
* @param item1 {Object} First item.
|
647
|
+
* @param item2 {Object} Second item.
|
648
|
+
*
|
649
|
+
* @author agorbatchev
|
650
|
+
* @date 2011/08/19
|
651
|
+
* @id ItemManager.compareItems
|
652
|
+
*/
|
653
|
+
p.compareItems = function(item1, item2)
|
654
|
+
{
|
655
|
+
return item1 == item2;
|
656
|
+
};
|
657
|
+
|
658
|
+
//--------------------------------------------------------------------------------
|
659
|
+
// TextExt core component
|
660
|
+
|
661
|
+
p = TextExt.prototype;
|
662
|
+
|
663
|
+
/**
|
664
|
+
* Initializes current component instance with work with the supplied text input and options.
|
665
|
+
*
|
666
|
+
* @signature TextExt.init(input, opts)
|
667
|
+
*
|
668
|
+
* @param input {HTMLElement} Text input.
|
669
|
+
* @param opts {Object} Options.
|
670
|
+
*
|
671
|
+
* @author agorbatchev
|
672
|
+
* @date 2011/08/19
|
673
|
+
* @id TextExt.init
|
674
|
+
*/
|
675
|
+
p.init = function(input, opts)
|
676
|
+
{
|
677
|
+
var self = this,
|
678
|
+
hiddenInput,
|
679
|
+
itemManager,
|
680
|
+
container
|
681
|
+
;
|
682
|
+
|
683
|
+
self._defaults = $.extend({}, DEFAULT_OPTS);
|
684
|
+
self._opts = opts || {};
|
685
|
+
self._plugins = {};
|
686
|
+
self._itemManager = itemManager = new (self.opts(OPT_ITEM_MANAGER))();
|
687
|
+
input = $(input);
|
688
|
+
container = $(self.opts(OPT_HTML_WRAP));
|
689
|
+
hiddenInput = $(self.opts(OPT_HTML_HIDDEN));
|
690
|
+
|
691
|
+
input
|
692
|
+
.wrap(container)
|
693
|
+
.keydown(function(e) { return self.onKeyDown(e) })
|
694
|
+
.keyup(function(e) { return self.onKeyUp(e) })
|
695
|
+
.data('textext', self)
|
696
|
+
;
|
697
|
+
|
698
|
+
// keep references to html elements using jQuery.data() to avoid circular references
|
699
|
+
$(self).data({
|
700
|
+
'hiddenInput' : hiddenInput,
|
701
|
+
'wrapElement' : input.parents('.text-wrap').first(),
|
702
|
+
'input' : input
|
703
|
+
});
|
704
|
+
|
705
|
+
// set the name of the hidden input to the text input's name
|
706
|
+
hiddenInput.attr('name', input.attr('name'));
|
707
|
+
// remove name attribute from the text input
|
708
|
+
input.attr('name', null);
|
709
|
+
// add hidden input to the DOM
|
710
|
+
hiddenInput.insertAfter(input);
|
711
|
+
|
712
|
+
$.extend(true, itemManager, self.opts(OPT_EXT + '.item.manager'));
|
713
|
+
$.extend(true, self, self.opts(OPT_EXT + '.*'), self.opts(OPT_EXT + '.core'));
|
714
|
+
|
715
|
+
self.originalWidth = input.outerWidth();
|
716
|
+
|
717
|
+
self.invalidateBounds();
|
718
|
+
|
719
|
+
itemManager.init(self);
|
720
|
+
|
721
|
+
self.initPatches();
|
722
|
+
self.initPlugins(self.opts(OPT_PLUGINS), $.fn.textext.plugins);
|
723
|
+
|
724
|
+
self.on({
|
725
|
+
setFormData : self.onSetFormData,
|
726
|
+
getFormData : self.onGetFormData,
|
727
|
+
setInputData : self.onSetInputData,
|
728
|
+
anyKeyUp : self.onAnyKeyUp
|
729
|
+
});
|
730
|
+
|
731
|
+
self.trigger(EVENT_POST_INIT);
|
732
|
+
self.trigger(EVENT_READY);
|
733
|
+
|
734
|
+
self.getFormData(0);
|
735
|
+
};
|
736
|
+
|
737
|
+
/**
|
738
|
+
* Initialized all installed patches against current instance. The patches are initialized based on their
|
739
|
+
* initialization priority which is returned by each patch's `initPriority()` method. Priority
|
740
|
+
* is a `Number` where patches with higher value gets their `init()` method called before patches
|
741
|
+
* with lower priority value.
|
742
|
+
*
|
743
|
+
* This facilitates initializing of patches in certain order to insure proper dependencies
|
744
|
+
* regardless of which order they are loaded.
|
745
|
+
*
|
746
|
+
* By default all patches have the same priority - zero, which means they will be initialized
|
747
|
+
* in rorder they are loaded, that is unless `initPriority()` is overriden.
|
748
|
+
*
|
749
|
+
* @signature TextExt.initPatches()
|
750
|
+
*
|
751
|
+
* @author agorbatchev
|
752
|
+
* @date 2011/10/11
|
753
|
+
* @id TextExt.initPatches
|
754
|
+
*/
|
755
|
+
p.initPatches = function()
|
756
|
+
{
|
757
|
+
var list = [],
|
758
|
+
source = $.fn.textext.patches,
|
759
|
+
name
|
760
|
+
;
|
761
|
+
|
762
|
+
for(name in source)
|
763
|
+
list.push(name);
|
764
|
+
|
765
|
+
this.initPlugins(list, source);
|
766
|
+
};
|
767
|
+
|
768
|
+
/**
|
769
|
+
* Creates and initializes all specified plugins. The plugins are initialized based on their
|
770
|
+
* initialization priority which is returned by each plugin's `initPriority()` method. Priority
|
771
|
+
* is a `Number` where plugins with higher value gets their `init()` method called before plugins
|
772
|
+
* with lower priority value.
|
773
|
+
*
|
774
|
+
* This facilitates initializing of plugins in certain order to insure proper dependencies
|
775
|
+
* regardless of which order user enters them in the `plugins` option field.
|
776
|
+
*
|
777
|
+
* By default all plugins have the same priority - zero, which means they will be initialized
|
778
|
+
* in the same order as entered by the user.
|
779
|
+
*
|
780
|
+
* @signature TextExt.initPlugins(plugins)
|
781
|
+
*
|
782
|
+
* @param plugins {Array} List of plugin names to initialize.
|
783
|
+
*
|
784
|
+
* @author agorbatchev
|
785
|
+
* @date 2011/08/19
|
786
|
+
* @id TextExt.initPlugins
|
787
|
+
*/
|
788
|
+
p.initPlugins = function(plugins, source)
|
789
|
+
{
|
790
|
+
var self = this,
|
791
|
+
ext, name, plugin, initList = [], i
|
792
|
+
;
|
793
|
+
|
794
|
+
if(typeof(plugins) == 'string')
|
795
|
+
plugins = plugins.split(/\s*,\s*|\s+/g);
|
796
|
+
|
797
|
+
for(i = 0; i < plugins.length; i++)
|
798
|
+
{
|
799
|
+
name = plugins[i];
|
800
|
+
plugin = source[name];
|
801
|
+
|
802
|
+
if(plugin)
|
803
|
+
{
|
804
|
+
self._plugins[name] = plugin = new plugin();
|
805
|
+
self[name] = (function(plugin) {
|
806
|
+
return function(){ return plugin; }
|
807
|
+
})(plugin);
|
808
|
+
initList.push(plugin);
|
809
|
+
$.extend(true, plugin, self.opts(OPT_EXT + '.*'), self.opts(OPT_EXT + '.' + name));
|
810
|
+
}
|
811
|
+
}
|
812
|
+
|
813
|
+
// sort plugins based on their priority values
|
814
|
+
initList.sort(function(p1, p2)
|
815
|
+
{
|
816
|
+
p1 = p1.initPriority();
|
817
|
+
p2 = p2.initPriority();
|
818
|
+
|
819
|
+
return p1 === p2
|
820
|
+
? 0
|
821
|
+
: p1 < p2 ? 1 : -1
|
822
|
+
;
|
823
|
+
});
|
824
|
+
|
825
|
+
for(i = 0; i < initList.length; i++)
|
826
|
+
initList[i].init(self);
|
827
|
+
};
|
828
|
+
|
829
|
+
/**
|
830
|
+
* Returns true if specified plugin is was instantiated for the current instance of core.
|
831
|
+
*
|
832
|
+
* @signature TextExt.hasPlugin(name)
|
833
|
+
*
|
834
|
+
* @param name {String} Name of the plugin to check.
|
835
|
+
*
|
836
|
+
* @author agorbatchev
|
837
|
+
* @date 2011/12/28
|
838
|
+
* @id TextExt.hasPlugin
|
839
|
+
* @version 1.1
|
840
|
+
*/
|
841
|
+
p.hasPlugin = function(name)
|
842
|
+
{
|
843
|
+
return !!this._plugins[name];
|
844
|
+
};
|
845
|
+
|
846
|
+
/**
|
847
|
+
* Allows to add multiple event handlers which will be execued in the scope of the current object.
|
848
|
+
*
|
849
|
+
* @signature TextExt.on([target], handlers)
|
850
|
+
*
|
851
|
+
* @param target {Object} **Optional**. Target object which has traditional `bind(event, handler)` method.
|
852
|
+
* Handler function will still be executed in the current object's scope.
|
853
|
+
* @param handlers {Object} Key/value pairs of event names and handlers, eg `{ event: handler }`.
|
854
|
+
*
|
855
|
+
* @author agorbatchev
|
856
|
+
* @date 2011/08/19
|
857
|
+
* @id TextExt.on
|
858
|
+
*/
|
859
|
+
p.on = hookupEvents;
|
860
|
+
|
861
|
+
/**
|
862
|
+
* Binds an event handler to the input box that user interacts with.
|
863
|
+
*
|
864
|
+
* @signature TextExt.bind(event, handler)
|
865
|
+
*
|
866
|
+
* @param event {String} Event name.
|
867
|
+
* @param handler {Function} Event handler.
|
868
|
+
*
|
869
|
+
* @author agorbatchev
|
870
|
+
* @date 2011/08/19
|
871
|
+
* @id TextExt.bind
|
872
|
+
*/
|
873
|
+
p.bind = function(event, handler)
|
874
|
+
{
|
875
|
+
this.input().bind(event, handler);
|
876
|
+
};
|
877
|
+
|
878
|
+
/**
|
879
|
+
* Triggers an event on the input box that user interacts with. All core events are originated here.
|
880
|
+
*
|
881
|
+
* @signature TextExt.trigger(event, ...args)
|
882
|
+
*
|
883
|
+
* @param event {String} Name of the event to trigger.
|
884
|
+
* @param ...args All remaining arguments will be passed to the event handler.
|
885
|
+
*
|
886
|
+
* @author agorbatchev
|
887
|
+
* @date 2011/08/19
|
888
|
+
* @id TextExt.trigger
|
889
|
+
*/
|
890
|
+
p.trigger = function()
|
891
|
+
{
|
892
|
+
var args = arguments;
|
893
|
+
this.input().trigger(args[0], slice.call(args, 1));
|
894
|
+
};
|
895
|
+
|
896
|
+
/**
|
897
|
+
* Returns instance of `itemManager` that is used by the component.
|
898
|
+
*
|
899
|
+
* @signature TextExt.itemManager()
|
900
|
+
*
|
901
|
+
* @author agorbatchev
|
902
|
+
* @date 2011/08/19
|
903
|
+
* @id TextExt.itemManager
|
904
|
+
*/
|
905
|
+
p.itemManager = function()
|
906
|
+
{
|
907
|
+
return this._itemManager;
|
908
|
+
};
|
909
|
+
|
910
|
+
/**
|
911
|
+
* Returns jQuery input element with which user is interacting with.
|
912
|
+
*
|
913
|
+
* @signature TextExt.input()
|
914
|
+
*
|
915
|
+
* @author agorbatchev
|
916
|
+
* @date 2011/08/10
|
917
|
+
* @id TextExt.input
|
918
|
+
*/
|
919
|
+
p.input = function()
|
920
|
+
{
|
921
|
+
return $(this).data('input');
|
922
|
+
};
|
923
|
+
|
924
|
+
/**
|
925
|
+
* Returns option value for the specified option by name. If the value isn't found in the user
|
926
|
+
* provided options, it will try looking for default value.
|
927
|
+
*
|
928
|
+
* @signature TextExt.opts(name)
|
929
|
+
*
|
930
|
+
* @param name {String} Option name as described in the options.
|
931
|
+
*
|
932
|
+
* @author agorbatchev
|
933
|
+
* @date 2011/08/19
|
934
|
+
* @id TextExt.opts
|
935
|
+
*/
|
936
|
+
p.opts = function(name)
|
937
|
+
{
|
938
|
+
var result = getProperty(this._opts, name);
|
939
|
+
return typeof(result) == 'undefined' ? getProperty(this._defaults, name) : result;
|
940
|
+
};
|
941
|
+
|
942
|
+
/**
|
943
|
+
* Returns HTML element that was created from the `html.wrap` option. This is the top level HTML
|
944
|
+
* container for the text input with which user is interacting with.
|
945
|
+
*
|
946
|
+
* @signature TextExt.wrapElement()
|
947
|
+
*
|
948
|
+
* @author agorbatchev
|
949
|
+
* @date 2011/08/19
|
950
|
+
* @id TextExt.wrapElement
|
951
|
+
*/
|
952
|
+
p.wrapElement = function()
|
953
|
+
{
|
954
|
+
return $(this).data('wrapElement');
|
955
|
+
};
|
956
|
+
|
957
|
+
/**
|
958
|
+
* Updates container to match dimensions of the text input. Triggers `preInvalidate` and `postInvalidate`
|
959
|
+
* events.
|
960
|
+
*
|
961
|
+
* @signature TextExt.invalidateBounds()
|
962
|
+
*
|
963
|
+
* @author agorbatchev
|
964
|
+
* @date 2011/08/19
|
965
|
+
* @id TextExt.invalidateBounds
|
966
|
+
*/
|
967
|
+
p.invalidateBounds = function()
|
968
|
+
{
|
969
|
+
var self = this,
|
970
|
+
input = self.input(),
|
971
|
+
wrap = self.wrapElement(),
|
972
|
+
container = wrap.parent(),
|
973
|
+
// width = self.originalWidth + 'px',
|
974
|
+
width = '100%',
|
975
|
+
height
|
976
|
+
;
|
977
|
+
|
978
|
+
self.trigger(EVENT_PRE_INVALIDATE);
|
979
|
+
|
980
|
+
height = input.outerHeight() + 'px';
|
981
|
+
|
982
|
+
// using css() method instead of width() and height() here because they don't seem to do the right thing in jQuery 1.8.x
|
983
|
+
// https://github.com/alexgorbatchev/jquery-textext/issues/74
|
984
|
+
input.css({ 'width' : width });
|
985
|
+
wrap.css({ 'width' : width, 'height' : height });
|
986
|
+
container.css({ 'height' : height });
|
987
|
+
|
988
|
+
self.trigger(EVENT_POST_INVALIDATE);
|
989
|
+
};
|
990
|
+
|
991
|
+
/**
|
992
|
+
* Focuses user input on the text box.
|
993
|
+
*
|
994
|
+
* @signature TextExt.focusInput()
|
995
|
+
*
|
996
|
+
* @author agorbatchev
|
997
|
+
* @date 2011/08/19
|
998
|
+
* @id TextExt.focusInput
|
999
|
+
*/
|
1000
|
+
p.focusInput = function()
|
1001
|
+
{
|
1002
|
+
this.input()[0].focus();
|
1003
|
+
};
|
1004
|
+
|
1005
|
+
/**
|
1006
|
+
* Serializes data for to be set into the hidden input field and which will be submitted
|
1007
|
+
* with the HTML form.
|
1008
|
+
*
|
1009
|
+
* By default simple JSON serialization is used. It's expected that `JSON.stringify`
|
1010
|
+
* method would be available either through built in class in most modern browsers
|
1011
|
+
* or through JSON2 library.
|
1012
|
+
*
|
1013
|
+
* @signature TextExt.serializeData(data)
|
1014
|
+
*
|
1015
|
+
* @param data {Object} Data to serialize.
|
1016
|
+
*
|
1017
|
+
* @author agorbatchev
|
1018
|
+
* @date 2011/08/09
|
1019
|
+
* @id TextExt.serializeData
|
1020
|
+
*/
|
1021
|
+
p.serializeData = stringify;
|
1022
|
+
|
1023
|
+
/**
|
1024
|
+
* Returns the hidden input HTML element which will be submitted with the HTML form.
|
1025
|
+
*
|
1026
|
+
* @signature TextExt.hiddenInput()
|
1027
|
+
*
|
1028
|
+
* @author agorbatchev
|
1029
|
+
* @date 2011/08/09
|
1030
|
+
* @id TextExt.hiddenInput
|
1031
|
+
*/
|
1032
|
+
p.hiddenInput = function(value)
|
1033
|
+
{
|
1034
|
+
return $(this).data('hiddenInput');
|
1035
|
+
};
|
1036
|
+
|
1037
|
+
/**
|
1038
|
+
* Abstracted functionality to trigger an event and get the data with maximum weight set by all
|
1039
|
+
* the event handlers. This functionality is used for the `getFormData` event.
|
1040
|
+
*
|
1041
|
+
* @signature TextExt.getWeightedEventResponse(event, args)
|
1042
|
+
*
|
1043
|
+
* @param event {String} Event name.
|
1044
|
+
* @param args {Object} Argument to be passed with the event.
|
1045
|
+
*
|
1046
|
+
* @author agorbatchev
|
1047
|
+
* @date 2011/08/22
|
1048
|
+
* @id TextExt.getWeightedEventResponse
|
1049
|
+
*/
|
1050
|
+
p.getWeightedEventResponse = function(event, args)
|
1051
|
+
{
|
1052
|
+
var self = this,
|
1053
|
+
data = {},
|
1054
|
+
maxWeight = 0
|
1055
|
+
;
|
1056
|
+
|
1057
|
+
self.trigger(event, data, args);
|
1058
|
+
|
1059
|
+
for(var weight in data)
|
1060
|
+
maxWeight = Math.max(maxWeight, weight);
|
1061
|
+
|
1062
|
+
return data[maxWeight];
|
1063
|
+
};
|
1064
|
+
|
1065
|
+
/**
|
1066
|
+
* Triggers the `getFormData` event to get all the plugins to return their data.
|
1067
|
+
*
|
1068
|
+
* After the data is returned, triggers `setFormData` and `setInputData` to update appopriate values.
|
1069
|
+
*
|
1070
|
+
* @signature TextExt.getFormData(keyCode)
|
1071
|
+
*
|
1072
|
+
* @param keyCode {Number} Key code number which has triggered this update. It's impotant to pass
|
1073
|
+
* this value to the plugins because they might return different values based on the key that was
|
1074
|
+
* pressed. For example, the Tags plugin returns an empty string for the `input` value if the enter
|
1075
|
+
* key was pressed, otherwise it returns whatever is currently in the text input.
|
1076
|
+
*
|
1077
|
+
* @author agorbatchev
|
1078
|
+
* @date 2011/08/22
|
1079
|
+
* @id TextExt.getFormData
|
1080
|
+
*/
|
1081
|
+
p.getFormData = function(keyCode)
|
1082
|
+
{
|
1083
|
+
var self = this,
|
1084
|
+
data = self.getWeightedEventResponse(EVENT_GET_FORM_DATA, keyCode || 0)
|
1085
|
+
;
|
1086
|
+
|
1087
|
+
self.trigger(EVENT_SET_FORM_DATA , data['form']);
|
1088
|
+
self.trigger(EVENT_SET_INPUT_DATA , data['input']);
|
1089
|
+
};
|
1090
|
+
|
1091
|
+
//--------------------------------------------------------------------------------
|
1092
|
+
// Event handlers
|
1093
|
+
|
1094
|
+
/**
|
1095
|
+
* Reacts to the `anyKeyUp` event and triggers the `getFormData` to change data that will be submitted
|
1096
|
+
* with the form. Default behaviour is that everything that is typed in will be JSON serialized, so
|
1097
|
+
* the end result will be a JSON string.
|
1098
|
+
*
|
1099
|
+
* @signature TextExt.onAnyKeyUp(e)
|
1100
|
+
*
|
1101
|
+
* @param e {Object} jQuery event.
|
1102
|
+
*
|
1103
|
+
* @author agorbatchev
|
1104
|
+
* @date 2011/08/19
|
1105
|
+
* @id TextExt.onAnyKeyUp
|
1106
|
+
*/
|
1107
|
+
p.onAnyKeyUp = function(e, keyCode)
|
1108
|
+
{
|
1109
|
+
this.getFormData(keyCode);
|
1110
|
+
};
|
1111
|
+
|
1112
|
+
/**
|
1113
|
+
* Reacts to the `setInputData` event and populates the input text field that user is currently
|
1114
|
+
* interacting with.
|
1115
|
+
*
|
1116
|
+
* @signature TextExt.onSetInputData(e, data)
|
1117
|
+
*
|
1118
|
+
* @param e {Event} jQuery event.
|
1119
|
+
* @param data {String} Value to be set.
|
1120
|
+
*
|
1121
|
+
* @author agorbatchev
|
1122
|
+
* @date 2011/08/22
|
1123
|
+
* @id TextExt.onSetInputData
|
1124
|
+
*/
|
1125
|
+
p.onSetInputData = function(e, data)
|
1126
|
+
{
|
1127
|
+
this.input().val(data);
|
1128
|
+
};
|
1129
|
+
|
1130
|
+
/**
|
1131
|
+
* Reacts to the `setFormData` event and populates the hidden input with will be submitted with
|
1132
|
+
* the HTML form. The value will be serialized with `serializeData()` method.
|
1133
|
+
*
|
1134
|
+
* @signature TextExt.onSetFormData(e, data)
|
1135
|
+
*
|
1136
|
+
* @param e {Event} jQuery event.
|
1137
|
+
* @param data {Object} Data that will be set.
|
1138
|
+
*
|
1139
|
+
* @author agorbatchev
|
1140
|
+
* @date 2011/08/22
|
1141
|
+
* @id TextExt.onSetFormData
|
1142
|
+
*/
|
1143
|
+
p.onSetFormData = function(e, data)
|
1144
|
+
{
|
1145
|
+
var self = this;
|
1146
|
+
self.hiddenInput().val(self.serializeData(data));
|
1147
|
+
};
|
1148
|
+
|
1149
|
+
/**
|
1150
|
+
* Reacts to `getFormData` event triggered by the core. At the bare minimum the core will tell
|
1151
|
+
* itself to use the current value in the text input as the data to be submitted with the HTML
|
1152
|
+
* form.
|
1153
|
+
*
|
1154
|
+
* @signature TextExt.onGetFormData(e, data)
|
1155
|
+
*
|
1156
|
+
* @param e {Event} jQuery event.
|
1157
|
+
*
|
1158
|
+
* @author agorbatchev
|
1159
|
+
* @date 2011/08/09
|
1160
|
+
* @id TextExt.onGetFormData
|
1161
|
+
*/
|
1162
|
+
p.onGetFormData = function(e, data)
|
1163
|
+
{
|
1164
|
+
var val = this.input().val();
|
1165
|
+
data[0] = formDataObject(val, val);
|
1166
|
+
};
|
1167
|
+
|
1168
|
+
//--------------------------------------------------------------------------------
|
1169
|
+
// User mouse/keyboard input
|
1170
|
+
|
1171
|
+
/**
|
1172
|
+
* Triggers `[name]KeyUp` and `[name]KeyPress` for every keystroke as described in the events.
|
1173
|
+
*
|
1174
|
+
* @signature TextExt.onKeyUp(e)
|
1175
|
+
*
|
1176
|
+
* @param e {Object} jQuery event.
|
1177
|
+
* @author agorbatchev
|
1178
|
+
* @date 2011/08/19
|
1179
|
+
* @id TextExt.onKeyUp
|
1180
|
+
*/
|
1181
|
+
|
1182
|
+
/**
|
1183
|
+
* Triggers `[name]KeyDown` for every keystroke as described in the events.
|
1184
|
+
*
|
1185
|
+
* @signature TextExt.onKeyDown(e)
|
1186
|
+
*
|
1187
|
+
* @param e {Object} jQuery event.
|
1188
|
+
* @author agorbatchev
|
1189
|
+
* @date 2011/08/19
|
1190
|
+
* @id TextExt.onKeyDown
|
1191
|
+
*/
|
1192
|
+
|
1193
|
+
$(['Down', 'Up']).each(function()
|
1194
|
+
{
|
1195
|
+
var type = this.toString();
|
1196
|
+
|
1197
|
+
p['onKey' + type] = function(e)
|
1198
|
+
{
|
1199
|
+
var self = this,
|
1200
|
+
keyName = self.opts(OPT_KEYS)[e.keyCode],
|
1201
|
+
defaultResult = true
|
1202
|
+
;
|
1203
|
+
|
1204
|
+
if(keyName)
|
1205
|
+
{
|
1206
|
+
defaultResult = keyName.substr(-1) != '!';
|
1207
|
+
keyName = keyName.replace('!', '');
|
1208
|
+
|
1209
|
+
self.trigger(keyName + 'Key' + type);
|
1210
|
+
|
1211
|
+
// manual *KeyPress event fimplementation for the function keys like Enter, Backspace, etc.
|
1212
|
+
if(type == 'Up' && self._lastKeyDown == e.keyCode)
|
1213
|
+
{
|
1214
|
+
self._lastKeyDown = null;
|
1215
|
+
self.trigger(keyName + 'KeyPress');
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
if(type == 'Down')
|
1219
|
+
self._lastKeyDown = e.keyCode;
|
1220
|
+
}
|
1221
|
+
|
1222
|
+
self.trigger('anyKey' + type, e.keyCode);
|
1223
|
+
|
1224
|
+
return defaultResult;
|
1225
|
+
};
|
1226
|
+
});
|
1227
|
+
|
1228
|
+
//--------------------------------------------------------------------------------
|
1229
|
+
// Plugin Base
|
1230
|
+
|
1231
|
+
p = TextExtPlugin.prototype;
|
1232
|
+
|
1233
|
+
/**
|
1234
|
+
* Allows to add multiple event handlers which will be execued in the scope of the current object.
|
1235
|
+
*
|
1236
|
+
* @signature TextExt.on([target], handlers)
|
1237
|
+
*
|
1238
|
+
* @param target {Object} **Optional**. Target object which has traditional `bind(event, handler)` method.
|
1239
|
+
* Handler function will still be executed in the current object's scope.
|
1240
|
+
* @param handlers {Object} Key/value pairs of event names and handlers, eg `{ event: handler }`.
|
1241
|
+
*
|
1242
|
+
* @author agorbatchev
|
1243
|
+
* @date 2011/08/19
|
1244
|
+
* @id TextExtPlugin.on
|
1245
|
+
*/
|
1246
|
+
p.on = hookupEvents;
|
1247
|
+
|
1248
|
+
/**
|
1249
|
+
* Returns the hash object that `getFormData` triggered by the core expects.
|
1250
|
+
*
|
1251
|
+
* @signature TextExtPlugin.formDataObject(input, form)
|
1252
|
+
*
|
1253
|
+
* @param input {String} Value that will go into the text input that user is interacting with.
|
1254
|
+
* @param form {Object} Value that will be serialized and put into the hidden that will be submitted
|
1255
|
+
* with the HTML form.
|
1256
|
+
*
|
1257
|
+
* @author agorbatchev
|
1258
|
+
* @date 2011/08/22
|
1259
|
+
* @id TextExtPlugin.formDataObject
|
1260
|
+
*/
|
1261
|
+
p.formDataObject = formDataObject;
|
1262
|
+
|
1263
|
+
/**
|
1264
|
+
* Initialization method called by the core during plugin instantiation. This method must be implemented
|
1265
|
+
* by each plugin individually.
|
1266
|
+
*
|
1267
|
+
* @signature TextExtPlugin.init(core)
|
1268
|
+
*
|
1269
|
+
* @param core {TextExt} Instance of the TextExt core class.
|
1270
|
+
*
|
1271
|
+
* @author agorbatchev
|
1272
|
+
* @date 2011/08/19
|
1273
|
+
* @id TextExtPlugin.init
|
1274
|
+
*/
|
1275
|
+
p.init = function(core) { throw new Error('Not implemented') };
|
1276
|
+
|
1277
|
+
/**
|
1278
|
+
* Initialization method wich should be called by the plugin during the `init()` call.
|
1279
|
+
*
|
1280
|
+
* @signature TextExtPlugin.baseInit(core, defaults)
|
1281
|
+
*
|
1282
|
+
* @param core {TextExt} Instance of the TextExt core class.
|
1283
|
+
* @param defaults {Object} Default plugin options. These will be checked if desired value wasn't
|
1284
|
+
* found in the options supplied by the user.
|
1285
|
+
*
|
1286
|
+
* @author agorbatchev
|
1287
|
+
* @date 2011/08/19
|
1288
|
+
* @id TextExtPlugin.baseInit
|
1289
|
+
*/
|
1290
|
+
p.baseInit = function(core, defaults)
|
1291
|
+
{
|
1292
|
+
var self = this;
|
1293
|
+
|
1294
|
+
core._defaults = $.extend(true, core._defaults, defaults);
|
1295
|
+
self._core = core;
|
1296
|
+
self._timers = {};
|
1297
|
+
};
|
1298
|
+
|
1299
|
+
/**
|
1300
|
+
* Allows starting of multiple timeout calls. Each time this method is called with the same
|
1301
|
+
* timer name, the timer is reset. This functionality is useful in cases where an action needs
|
1302
|
+
* to occur only after a certain period of inactivity. For example, making an AJAX call after
|
1303
|
+
* user stoped typing for 1 second.
|
1304
|
+
*
|
1305
|
+
* @signature TextExtPlugin.startTimer(name, delay, callback)
|
1306
|
+
*
|
1307
|
+
* @param name {String} Timer name.
|
1308
|
+
* @param delay {Number} Delay in seconds.
|
1309
|
+
* @param callback {Function} Callback function.
|
1310
|
+
*
|
1311
|
+
* @author agorbatchev
|
1312
|
+
* @date 2011/08/25
|
1313
|
+
* @id TextExtPlugin.startTimer
|
1314
|
+
*/
|
1315
|
+
p.startTimer = function(name, delay, callback)
|
1316
|
+
{
|
1317
|
+
var self = this;
|
1318
|
+
|
1319
|
+
self.stopTimer(name);
|
1320
|
+
|
1321
|
+
self._timers[name] = setTimeout(
|
1322
|
+
function()
|
1323
|
+
{
|
1324
|
+
delete self._timers[name];
|
1325
|
+
callback.apply(self);
|
1326
|
+
},
|
1327
|
+
delay * 1000
|
1328
|
+
);
|
1329
|
+
};
|
1330
|
+
|
1331
|
+
/**
|
1332
|
+
* Stops the timer by name without resetting it.
|
1333
|
+
*
|
1334
|
+
* @signature TextExtPlugin.stopTimer(name)
|
1335
|
+
*
|
1336
|
+
* @param name {String} Timer name.
|
1337
|
+
*
|
1338
|
+
* @author agorbatchev
|
1339
|
+
* @date 2011/08/25
|
1340
|
+
* @id TextExtPlugin.stopTimer
|
1341
|
+
*/
|
1342
|
+
p.stopTimer = function(name)
|
1343
|
+
{
|
1344
|
+
clearTimeout(this._timers[name]);
|
1345
|
+
};
|
1346
|
+
|
1347
|
+
/**
|
1348
|
+
* Returns instance of the `TextExt` to which current instance of the plugin is attached to.
|
1349
|
+
*
|
1350
|
+
* @signature TextExtPlugin.core()
|
1351
|
+
*
|
1352
|
+
* @author agorbatchev
|
1353
|
+
* @date 2011/08/19
|
1354
|
+
* @id TextExtPlugin.core
|
1355
|
+
*/
|
1356
|
+
p.core = function()
|
1357
|
+
{
|
1358
|
+
return this._core;
|
1359
|
+
};
|
1360
|
+
|
1361
|
+
/**
|
1362
|
+
* Shortcut to the core's `opts()` method. Returns option value.
|
1363
|
+
*
|
1364
|
+
* @signature TextExtPlugin.opts(name)
|
1365
|
+
*
|
1366
|
+
* @param name {String} Option name as described in the options.
|
1367
|
+
*
|
1368
|
+
* @author agorbatchev
|
1369
|
+
* @date 2011/08/19
|
1370
|
+
* @id TextExtPlugin.opts
|
1371
|
+
*/
|
1372
|
+
p.opts = function(name)
|
1373
|
+
{
|
1374
|
+
return this.core().opts(name);
|
1375
|
+
};
|
1376
|
+
|
1377
|
+
/**
|
1378
|
+
* Shortcut to the core's `itemManager()` method. Returns instance of the `ItemManger` that is
|
1379
|
+
* currently in use.
|
1380
|
+
*
|
1381
|
+
* @signature TextExtPlugin.itemManager()
|
1382
|
+
*
|
1383
|
+
* @author agorbatchev
|
1384
|
+
* @date 2011/08/19
|
1385
|
+
* @id TextExtPlugin.itemManager
|
1386
|
+
*/
|
1387
|
+
p.itemManager = function()
|
1388
|
+
{
|
1389
|
+
return this.core().itemManager();
|
1390
|
+
};
|
1391
|
+
|
1392
|
+
/**
|
1393
|
+
* Shortcut to the core's `input()` method. Returns instance of the HTML element that represents
|
1394
|
+
* current text input.
|
1395
|
+
*
|
1396
|
+
* @signature TextExtPlugin.input()
|
1397
|
+
*
|
1398
|
+
* @author agorbatchev
|
1399
|
+
* @date 2011/08/19
|
1400
|
+
* @id TextExtPlugin.input
|
1401
|
+
*/
|
1402
|
+
p.input = function()
|
1403
|
+
{
|
1404
|
+
return this.core().input();
|
1405
|
+
};
|
1406
|
+
|
1407
|
+
/**
|
1408
|
+
* Shortcut to the commonly used `this.input().val()` call to get or set value of the text input.
|
1409
|
+
*
|
1410
|
+
* @signature TextExtPlugin.val(value)
|
1411
|
+
*
|
1412
|
+
* @param value {String} Optional value. If specified, the value will be set, otherwise it will be
|
1413
|
+
* returned.
|
1414
|
+
*
|
1415
|
+
* @author agorbatchev
|
1416
|
+
* @date 2011/08/20
|
1417
|
+
* @id TextExtPlugin.val
|
1418
|
+
*/
|
1419
|
+
p.val = function(value)
|
1420
|
+
{
|
1421
|
+
var input = this.input();
|
1422
|
+
|
1423
|
+
if(typeof(value) === UNDEFINED)
|
1424
|
+
return input.val();
|
1425
|
+
else
|
1426
|
+
input.val(value);
|
1427
|
+
};
|
1428
|
+
|
1429
|
+
/**
|
1430
|
+
* Shortcut to the core's `trigger()` method. Triggers specified event with arguments on the
|
1431
|
+
* component core.
|
1432
|
+
*
|
1433
|
+
* @signature TextExtPlugin.trigger(event, ...args)
|
1434
|
+
*
|
1435
|
+
* @param event {String} Name of the event to trigger.
|
1436
|
+
* @param ...args All remaining arguments will be passed to the event handler.
|
1437
|
+
*
|
1438
|
+
* @author agorbatchev
|
1439
|
+
* @date 2011/08/19
|
1440
|
+
* @id TextExtPlugin.trigger
|
1441
|
+
*/
|
1442
|
+
p.trigger = function()
|
1443
|
+
{
|
1444
|
+
var core = this.core();
|
1445
|
+
core.trigger.apply(core, arguments);
|
1446
|
+
};
|
1447
|
+
|
1448
|
+
/**
|
1449
|
+
* Shortcut to the core's `bind()` method. Binds specified handler to the event.
|
1450
|
+
*
|
1451
|
+
* @signature TextExtPlugin.bind(event, handler)
|
1452
|
+
*
|
1453
|
+
* @param event {String} Event name.
|
1454
|
+
* @param handler {Function} Event handler.
|
1455
|
+
*
|
1456
|
+
* @author agorbatchev
|
1457
|
+
* @date 2011/08/20
|
1458
|
+
* @id TextExtPlugin.bind
|
1459
|
+
*/
|
1460
|
+
p.bind = function(event, handler)
|
1461
|
+
{
|
1462
|
+
this.core().bind(event, handler);
|
1463
|
+
};
|
1464
|
+
|
1465
|
+
/**
|
1466
|
+
* Returns initialization priority for this plugin. If current plugin depends upon some other plugin
|
1467
|
+
* to be initialized before or after, priority needs to be adjusted accordingly. Plugins with higher
|
1468
|
+
* priority initialize before plugins with lower priority.
|
1469
|
+
*
|
1470
|
+
* Default initialization priority is `0`.
|
1471
|
+
*
|
1472
|
+
* @signature TextExtPlugin.initPriority()
|
1473
|
+
*
|
1474
|
+
* @author agorbatchev
|
1475
|
+
* @date 2011/08/22
|
1476
|
+
* @id TextExtPlugin.initPriority
|
1477
|
+
*/
|
1478
|
+
p.initPriority = function()
|
1479
|
+
{
|
1480
|
+
return 0;
|
1481
|
+
};
|
1482
|
+
|
1483
|
+
//--------------------------------------------------------------------------------
|
1484
|
+
// jQuery Integration
|
1485
|
+
|
1486
|
+
/**
|
1487
|
+
* TextExt integrates as a jQuery plugin available through the `$(selector).textext(opts)` call. If
|
1488
|
+
* `opts` argument is passed, then a new instance of `TextExt` will be created for all the inputs
|
1489
|
+
* that match the `selector`. If `opts` wasn't passed and TextExt was already intantiated for
|
1490
|
+
* inputs that match the `selector`, array of `TextExt` instances will be returned instead.
|
1491
|
+
*
|
1492
|
+
* // will create a new instance of `TextExt` for all elements that match `.sample`
|
1493
|
+
* $('.sample').textext({ ... });
|
1494
|
+
*
|
1495
|
+
* // will return array of all `TextExt` instances
|
1496
|
+
* var list = $('.sample').textext();
|
1497
|
+
*
|
1498
|
+
* The following properties are also exposed through the jQuery `$.fn.textext`:
|
1499
|
+
*
|
1500
|
+
* * `TextExt` -- `TextExt` class.
|
1501
|
+
* * `TextExtPlugin` -- `TextExtPlugin` class.
|
1502
|
+
* * `ItemManager` -- `ItemManager` class.
|
1503
|
+
* * `plugins` -- Key/value table of all registered plugins.
|
1504
|
+
* * `addPlugin(name, constructor)` -- All plugins should register themselves using this function.
|
1505
|
+
*
|
1506
|
+
* @author agorbatchev
|
1507
|
+
* @date 2011/08/19
|
1508
|
+
* @id TextExt.jquery
|
1509
|
+
*/
|
1510
|
+
|
1511
|
+
var cssInjected = false;
|
1512
|
+
|
1513
|
+
var textext = $.fn.textext = function(opts)
|
1514
|
+
{
|
1515
|
+
var css;
|
1516
|
+
|
1517
|
+
if(!cssInjected && (css = $.fn.textext.css) != null)
|
1518
|
+
{
|
1519
|
+
$('head').append('<style>' + css + '</style>');
|
1520
|
+
cssInjected = true;
|
1521
|
+
}
|
1522
|
+
|
1523
|
+
return this.map(function()
|
1524
|
+
{
|
1525
|
+
var self = $(this);
|
1526
|
+
|
1527
|
+
if(opts == null)
|
1528
|
+
return self.data('textext');
|
1529
|
+
|
1530
|
+
var instance = new TextExt();
|
1531
|
+
|
1532
|
+
instance.init(self, opts);
|
1533
|
+
self.data('textext', instance);
|
1534
|
+
|
1535
|
+
return instance.input()[0];
|
1536
|
+
});
|
1537
|
+
};
|
1538
|
+
|
1539
|
+
/**
|
1540
|
+
* This static function registers a new plugin which makes it available through the `plugins` option
|
1541
|
+
* to the end user. The name specified here is the name the end user would put in the `plugins` option
|
1542
|
+
* to add this plugin to a new instance of TextExt.
|
1543
|
+
*
|
1544
|
+
* @signature $.fn.textext.addPlugin(name, constructor)
|
1545
|
+
*
|
1546
|
+
* @param name {String} Name of the plugin.
|
1547
|
+
* @param constructor {Function} Plugin constructor.
|
1548
|
+
*
|
1549
|
+
* @author agorbatchev
|
1550
|
+
* @date 2011/10/11
|
1551
|
+
* @id TextExt.addPlugin
|
1552
|
+
*/
|
1553
|
+
textext.addPlugin = function(name, constructor)
|
1554
|
+
{
|
1555
|
+
textext.plugins[name] = constructor;
|
1556
|
+
constructor.prototype = new textext.TextExtPlugin();
|
1557
|
+
};
|
1558
|
+
|
1559
|
+
/**
|
1560
|
+
* This static function registers a new patch which is added to each instance of TextExt. If you are
|
1561
|
+
* adding a new patch, make sure to call this method.
|
1562
|
+
*
|
1563
|
+
* @signature $.fn.textext.addPatch(name, constructor)
|
1564
|
+
*
|
1565
|
+
* @param name {String} Name of the patch.
|
1566
|
+
* @param constructor {Function} Patch constructor.
|
1567
|
+
*
|
1568
|
+
* @author agorbatchev
|
1569
|
+
* @date 2011/10/11
|
1570
|
+
* @id TextExt.addPatch
|
1571
|
+
*/
|
1572
|
+
textext.addPatch = function(name, constructor)
|
1573
|
+
{
|
1574
|
+
textext.patches[name] = constructor;
|
1575
|
+
constructor.prototype = new textext.TextExtPlugin();
|
1576
|
+
};
|
1577
|
+
|
1578
|
+
textext.TextExt = TextExt;
|
1579
|
+
textext.TextExtPlugin = TextExtPlugin;
|
1580
|
+
textext.ItemManager = ItemManager;
|
1581
|
+
textext.plugins = {};
|
1582
|
+
textext.patches = {};
|
1583
|
+
})(jQuery);
|
1584
|
+
|
1585
|
+
(function($)
|
1586
|
+
{
|
1587
|
+
function TextExtIE9Patches() {};
|
1588
|
+
|
1589
|
+
$.fn.textext.TextExtIE9Patches = TextExtIE9Patches;
|
1590
|
+
$.fn.textext.addPatch('ie9',TextExtIE9Patches);
|
1591
|
+
|
1592
|
+
var p = TextExtIE9Patches.prototype;
|
1593
|
+
|
1594
|
+
p.init = function(core)
|
1595
|
+
{
|
1596
|
+
if(navigator.userAgent.indexOf('MSIE 9') == -1)
|
1597
|
+
return;
|
1598
|
+
|
1599
|
+
var self = this;
|
1600
|
+
|
1601
|
+
core.on({ postInvalidate : self.onPostInvalidate });
|
1602
|
+
};
|
1603
|
+
|
1604
|
+
p.onPostInvalidate = function()
|
1605
|
+
{
|
1606
|
+
var self = this,
|
1607
|
+
input = self.input(),
|
1608
|
+
val = input.val()
|
1609
|
+
;
|
1610
|
+
|
1611
|
+
// agorbatchev :: IE9 doesn't seem to update the padding if box-sizing is on until the
|
1612
|
+
// text box value changes, so forcing this change seems to do the trick of updating
|
1613
|
+
// IE's padding visually.
|
1614
|
+
input.val(Math.random());
|
1615
|
+
input.val(val);
|
1616
|
+
};
|
1617
|
+
})(jQuery);
|
1618
|
+
|