tenon 1.1.8 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +768 -69
- data/Rakefile +7 -13
- data/app/assets/javascripts/tenon/application.js +4 -0
- data/app/controllers/tenon/assets_controller.rb +22 -23
- data/app/controllers/tenon/base_controller.rb +22 -13
- data/app/controllers/tenon/index_controller.rb +0 -4
- data/app/controllers/tenon/item_versions_controller.rb +20 -8
- data/app/controllers/tenon/resources_controller.rb +100 -30
- data/app/controllers/tenon/simple_resources_controller.rb +7 -7
- data/app/controllers/tenon/styleguides_controller.rb +10 -0
- data/app/decorators/tenon/application_decorator.rb +4 -8
- data/app/decorators/tenon/asset_decorator.rb +0 -25
- data/app/filterers/tenon/generic_filterer.rb +24 -0
- data/app/form_builders/tenon/form_builder.rb +189 -19
- data/app/helpers/tenon/active_link_to_helper.rb +9 -0
- data/app/helpers/tenon/application_helper.rb +4 -23
- data/app/helpers/tenon/asset_helper.rb +2 -2
- data/app/helpers/tenon/back_to_index_path_helper.rb +13 -0
- data/app/helpers/tenon/breadcrumbs_helper.rb +33 -0
- data/app/helpers/tenon/flash_helper.rb +14 -0
- data/app/helpers/tenon/icon_helper.rb +7 -0
- data/app/helpers/tenon/input_block_helper.rb +25 -0
- data/app/helpers/tenon/item_version_helper.rb +22 -9
- data/app/helpers/tenon/nav_helper.rb +21 -17
- data/app/helpers/tenon/piece_helper.rb +2 -7
- data/app/helpers/tenon/platform_hints_helper.rb +3 -5
- data/app/helpers/tenon/styleguide_helper.rb +15 -0
- data/app/helpers/tenon/tenon_content_helper.rb +11 -6
- data/app/helpers/tenon/tenon_helper.rb +19 -9
- data/app/models/tenon/application_record.rb +5 -0
- data/app/models/tenon/asset.rb +2 -2
- data/app/models/tenon/item_asset.rb +1 -1
- data/app/models/tenon/item_version.rb +1 -1
- data/app/models/tenon/styleguide.rb +11 -0
- data/app/models/tenon/tenon_content/piece.rb +13 -13
- data/app/models/tenon/tenon_content/row.rb +1 -1
- data/app/models/tenon/tenon_content/row_types/four_column_image.rb +4 -4
- data/app/models/tenon/tenon_content/row_types/four_column_image_and_text.rb +8 -8
- data/app/models/tenon/tenon_content/row_types/four_column_text.rb +4 -4
- data/app/models/tenon/tenon_content/row_types/full_width_embedded_content.rb +1 -1
- data/app/models/tenon/tenon_content/row_types/full_width_image.rb +1 -1
- data/app/models/tenon/tenon_content/row_types/full_width_text.rb +1 -1
- data/app/models/tenon/tenon_content/row_types/left_image_right_text.rb +2 -2
- data/app/models/tenon/tenon_content/row_types/left_text_right_image.rb +2 -2
- data/app/models/tenon/tenon_content/row_types/left_wrapped_image_with_text.rb +2 -2
- data/app/models/tenon/tenon_content/row_types/right_wrapped_image_with_text.rb +2 -2
- data/app/models/tenon/tenon_content/row_types/six_column_image.rb +6 -6
- data/app/models/tenon/tenon_content/row_types/six_column_image_and_text.rb +12 -12
- data/app/models/tenon/tenon_content/row_types/three_column_image.rb +3 -3
- data/app/models/tenon/tenon_content/row_types/three_column_image_and_text.rb +6 -6
- data/app/models/tenon/tenon_content/row_types/three_column_text.rb +3 -3
- data/app/models/tenon/tenon_content/row_types/two_column_image.rb +2 -2
- data/app/models/tenon/tenon_content/row_types/two_column_image_and_text.rb +4 -4
- data/app/models/tenon/tenon_content/row_types/two_column_text.rb +2 -2
- data/app/models/tenon/tenon_content/row_types/two_column_with_background_image.rb +3 -3
- data/app/models/tenon/tenon_content/row_types.rb +17 -17
- data/app/policies/my_settings_policy.rb +2 -0
- data/app/policies/tenon/application_policy.rb +63 -0
- data/app/policies/tenon/asset_policy.rb +4 -0
- data/app/policies/tenon/item_version_policy.rb +4 -0
- data/app/serializers/item_version_serializer.rb +23 -0
- data/app/serializers/tenon/application_serializer.rb +37 -0
- data/app/serializers/tenon/asset_serializer.rb +5 -0
- data/app/serializers/tenon/paginating_serializer.rb +18 -0
- data/app/views/layouts/tenon/application.html.haml +28 -18
- data/app/views/tenon/assets/_form.html.haml +29 -12
- data/app/views/tenon/assets/crop.html.haml +13 -13
- data/app/views/tenon/assets/edit.html.haml +1 -12
- data/app/views/tenon/assets/index.html.haml +5 -19
- data/app/views/tenon/assets/new.html.haml +1 -0
- data/app/views/tenon/fields/_asset.html.haml +26 -27
- data/app/views/tenon/fields/_base.html.haml +7 -0
- data/app/views/tenon/fields/_base_inline.html.haml +4 -0
- data/app/views/tenon/fields/_check_box.html.haml +9 -0
- data/app/views/tenon/fields/_collection_select.html.haml +4 -0
- data/app/views/tenon/fields/_color_field.html.haml +3 -0
- data/app/views/tenon/fields/_date_picker.html.haml +2 -0
- data/app/views/tenon/fields/_date_time_picker.html.haml +6 -0
- data/app/views/tenon/fields/_email_field.html.haml +2 -0
- data/app/views/tenon/fields/_inline_check_box.html.haml +5 -0
- data/app/views/tenon/fields/_inline_radio_button.html.haml +5 -0
- data/app/views/tenon/fields/_number_field.html.haml +2 -0
- data/app/views/tenon/fields/_password_field.html.haml +2 -0
- data/app/views/tenon/fields/_phone_field.html.haml +2 -0
- data/app/views/tenon/fields/_radio_button.html.haml +9 -0
- data/app/views/tenon/fields/_rich_text.html.haml +3 -6
- data/app/views/tenon/fields/_select.html.haml +3 -0
- data/app/views/tenon/fields/_text_area.html.haml +2 -0
- data/app/views/tenon/fields/_text_field.html.haml +2 -0
- data/app/views/tenon/fields/_title_text_field.html.haml +2 -0
- data/app/views/tenon/fields/_url_field.html.haml +2 -0
- data/app/views/tenon/index/index.html.haml +8 -29
- data/app/views/tenon/item_assets/new.html.haml +20 -22
- data/app/views/tenon/item_versions/_item_version.json.jbuilder +4 -4
- data/app/views/tenon/item_versions/index.html.haml +14 -6
- data/app/views/tenon/item_versions/new.html.haml +8 -10
- data/app/views/tenon/settings/_contact.html.haml +14 -19
- data/app/views/tenon/settings/_general.html.haml +15 -11
- data/app/views/tenon/settings/_seo.html.haml +10 -9
- data/app/views/tenon/settings/show.html.haml +12 -31
- data/app/views/tenon/shared/_account_dropdown.html.haml +6 -0
- data/app/views/tenon/shared/_app_info.html.haml +5 -0
- data/app/views/tenon/shared/_breadcrumbs.html.haml +1 -0
- data/app/views/tenon/shared/_burger.html.haml +5 -0
- data/app/views/tenon/shared/_default_form_toolbar.html.haml +26 -0
- data/app/views/tenon/shared/_draft_controls.html.haml +18 -0
- data/app/views/tenon/shared/_i18n_language_nav.html.haml +2 -2
- data/app/views/tenon/shared/_main_nav.html.haml +3 -14
- data/app/views/tenon/shared/_platform_hints.html.haml +15 -15
- data/app/views/tenon/shared/_seo_fields.html.haml +8 -6
- data/app/views/tenon/shared/_site_title.html.haml +6 -0
- data/app/views/tenon/shared/_util_nav.html.haml +4 -27
- data/app/views/tenon/shared/_version_warning.html.haml +11 -11
- data/app/views/tenon/styleguides/_buttons.html.haml +118 -0
- data/app/views/tenon/styleguides/_colors.html.haml +59 -0
- data/app/views/tenon/styleguides/_forms.html.haml +4 -0
- data/app/views/tenon/styleguides/_icons.html.haml +21 -0
- data/app/views/tenon/styleguides/_typography.html.haml +27 -0
- data/app/views/tenon/styleguides/buttons/_colors.html.haml +43 -0
- data/app/views/tenon/styleguides/buttons/_styles.html.haml +59 -0
- data/app/views/tenon/styleguides/colors/_helpers.html.haml +48 -0
- data/app/views/tenon/styleguides/colors/_variables.html.haml +31 -0
- data/app/views/tenon/styleguides/forms/_default.html.haml +92 -0
- data/app/views/tenon/styleguides/forms/_html5.html.haml +31 -0
- data/app/views/tenon/styleguides/forms/_tenon_content.html.haml +15 -0
- data/app/views/tenon/styleguides/index.html.haml +52 -0
- data/app/views/tenon/styleguides/typography/_blockquote.html.haml +7 -0
- data/app/views/tenon/styleguides/typography/_inline.html.haml +8 -0
- data/app/views/tenon/styleguides/typography/_lists.html.haml +40 -0
- data/app/views/tenon/styleguides/typography/_paragraphs.html.haml +17 -0
- data/app/views/tenon/styleguides/typography/_small.html.haml +18 -0
- data/app/views/tenon/styleguides/typography/_styles.html.haml +14 -0
- data/app/views/tenon/styleguides/typography/_variables.html.haml +43 -0
- data/app/views/tenon/tenon_content/_display.html.haml +2 -2
- data/app/views/tenon/tenon_content/_embed_modal.html.haml +3 -3
- data/app/views/tenon/tenon_content/_fields.html.haml +21 -35
- data/app/views/tenon/tenon_content/_row.html.haml +14 -13
- data/app/views/tenon/tenon_content/{_builder.html.haml → _tenon_content.html.haml} +2 -2
- data/app/views/tenon/tenon_content/piece_types/form/_background_image.html.haml +6 -6
- data/app/views/tenon/tenon_content/piece_types/form/_embedded_content.html.haml +2 -1
- data/app/views/tenon/tenon_content/piece_types/form/_image.html.haml +37 -29
- data/app/views/tenon/tenon_content/row_types/display/_four_column_image.html.haml +4 -4
- data/app/views/tenon/tenon_content/row_types/display/_four_column_image_and_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/display/_four_column_text.html.haml +4 -4
- data/app/views/tenon/tenon_content/row_types/display/_full_width_embedded_content.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/display/_full_width_image.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/display/_full_width_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/display/_left_image_right_text.html.haml +8 -8
- data/app/views/tenon/tenon_content/row_types/display/_left_text_right_image.html.haml +7 -7
- data/app/views/tenon/tenon_content/row_types/display/_left_wrapped_image_with_text.html.haml +6 -6
- data/app/views/tenon/tenon_content/row_types/display/_right_wrapped_image_with_text.html.haml +7 -7
- data/app/views/tenon/tenon_content/row_types/display/_six_column_image.html.haml +4 -4
- data/app/views/tenon/tenon_content/row_types/display/_six_column_image_and_text.html.haml +5 -5
- data/app/views/tenon/tenon_content/row_types/display/_three_column_image.html.haml +4 -4
- data/app/views/tenon/tenon_content/row_types/display/_three_column_image_and_text.html.haml +4 -4
- data/app/views/tenon/tenon_content/row_types/display/_three_column_text.html.haml +4 -4
- data/app/views/tenon/tenon_content/row_types/display/_two_column_image.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/display/_two_column_image_and_text.html.haml +4 -4
- data/app/views/tenon/tenon_content/row_types/display/_two_column_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/display/_two_column_with_background_image.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_four_column_image.html.haml +2 -2
- data/app/views/tenon/tenon_content/row_types/form/_four_column_image_and_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_four_column_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_full_width_embedded_content.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_full_width_image.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_full_width_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_left_image_right_text.html.haml +9 -8
- data/app/views/tenon/tenon_content/row_types/form/_left_text_right_image.html.haml +6 -6
- data/app/views/tenon/tenon_content/row_types/form/_left_wrapped_image_with_text.html.haml +7 -7
- data/app/views/tenon/tenon_content/row_types/form/_right_wrapped_image_with_text.html.haml +7 -7
- data/app/views/tenon/tenon_content/row_types/form/_six_column_image.html.haml +2 -2
- data/app/views/tenon/tenon_content/row_types/form/_six_column_image_and_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_three_column_image.html.haml +2 -2
- data/app/views/tenon/tenon_content/row_types/form/_three_column_image_and_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_three_column_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_two_column_image.html.haml +2 -2
- data/app/views/tenon/tenon_content/row_types/form/_two_column_image_and_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_two_column_text.html.haml +3 -3
- data/app/views/tenon/tenon_content/row_types/form/_two_column_with_background_image.html.haml +2 -2
- data/config/initializers/class_extensions/hash.rb +1 -1
- data/config/initializers/client_side_validations.rb +27 -0
- data/config/initializers/tenon.rb +0 -14
- data/config/routes.rb +10 -46
- data/db/migrate/20151117171000_drop_default_tenon_resources.rb +15 -0
- data/db/migrate/20160119185645_remove_tenon_users.rb +7 -0
- data/db/migrate/20160126123154_remove_tenon_callouts_subscribers.rb +8 -0
- data/db/migrate/20160126194219_convert_piece_size_to_int.rb +6 -0
- data/lib/ckeditor/plugins/pastefromword/filter/default.js +1 -1
- data/lib/generators/tenon/scaffold/scaffold_generator.rb +52 -27
- data/lib/generators/tenon/scaffold/templates/controller.rb +7 -4
- data/lib/generators/tenon/scaffold/templates/policy.rb +2 -0
- data/lib/generators/tenon/scaffold/templates/serializer.rb +2 -0
- data/lib/generators/tenon/scaffold/templates/view__form.html.haml +49 -54
- data/lib/generators/tenon/scaffold/templates/view_edit.html.haml +1 -8
- data/lib/generators/tenon/scaffold/templates/view_index.html.haml +8 -24
- data/lib/generators/tenon/scaffold/templates/view_new.html.haml +1 -8
- data/lib/tasks/tenon_tasks.rake +2 -2
- data/lib/templates/active_record/model/model.rb +12 -13
- data/lib/templates/migration/templates/create_table_migration.rb +1 -1
- data/lib/tenon/can_be_foreign.rb +1 -1
- data/lib/tenon/engine.rb +26 -32
- data/lib/tenon/filterers/base_filterer.rb +64 -0
- data/lib/tenon/has_history/attr_serializer.rb +6 -6
- data/lib/tenon/proxy_attachment.rb +2 -2
- data/lib/tenon/version.rb +1 -1
- data/lib/tenon.rb +1 -3
- data/vendor/assets/javascripts/bootstrap.modal.js +1 -1
- data/vendor/assets/javascripts/date_picker/picker.date.js +1429 -0
- data/vendor/assets/javascripts/date_picker/picker.js +1122 -0
- data/vendor/assets/javascripts/number-to-words.es6 +35 -0
- data/vendor/assets/stylesheets/bootstrap.scss +1 -1
- metadata +206 -972
- data/app/assets/images/tenon/icons/delete.png +0 -0
- data/app/assets/images/tenon/icons/edit.png +0 -0
- data/app/assets/images/tenon/icons/thumbdown.png +0 -0
- data/app/assets/images/tenon/icons/thumbup.png +0 -0
- data/app/assets/images/tenon/select2-spinner.gif +0 -0
- data/app/assets/images/tenon/select2.png +0 -0
- data/app/assets/images/tenon/select2x2.png +0 -0
- data/app/assets/javascripts/tenon/controllers/assets.js.coffee +0 -3
- data/app/assets/javascripts/tenon/controllers/index.js.coffee +0 -6
- data/app/assets/javascripts/tenon/controllers/tenon.js.coffee +0 -1
- data/app/assets/javascripts/tenon/features/asset_attachment.js.coffee +0 -37
- data/app/assets/javascripts/tenon/features/asset_cropping.js.coffee +0 -49
- data/app/assets/javascripts/tenon/features/asset_detachment.js.coffee +0 -11
- data/app/assets/javascripts/tenon/features/asset_list_post_crop_handler.js.coffee +0 -15
- data/app/assets/javascripts/tenon/features/asset_uploader.js.coffee +0 -88
- data/app/assets/javascripts/tenon/features/box_toggles.js.coffee +0 -17
- data/app/assets/javascripts/tenon/features/cocoon_hooks.js.coffee +0 -12
- data/app/assets/javascripts/tenon/features/date_time_picker.js.coffee +0 -25
- data/app/assets/javascripts/tenon/features/editor.js.coffee +0 -24
- data/app/assets/javascripts/tenon/features/file_select_widget.js.erb +0 -39
- data/app/assets/javascripts/tenon/features/flash.js.coffee +0 -13
- data/app/assets/javascripts/tenon/features/focus_first_field.js.coffee +0 -8
- data/app/assets/javascripts/tenon/features/hamburger_navigation.js.coffee +0 -26
- data/app/assets/javascripts/tenon/features/header_menu.js.coffee +0 -20
- data/app/assets/javascripts/tenon/features/i18n_fields.js.coffee +0 -23
- data/app/assets/javascripts/tenon/features/infinite_loading.js.coffee +0 -12
- data/app/assets/javascripts/tenon/features/item_version_autosave.js.coffee +0 -35
- data/app/assets/javascripts/tenon/features/item_version_index_handler.js.coffee +0 -3
- data/app/assets/javascripts/tenon/features/main_menu.js.coffee +0 -11
- data/app/assets/javascripts/tenon/features/modal_forms.js.coffee +0 -44
- data/app/assets/javascripts/tenon/features/modal_windows.js.coffee +0 -104
- data/app/assets/javascripts/tenon/features/multiple_asset_attachment.js.coffee +0 -8
- data/app/assets/javascripts/tenon/features/nested_fields.js +0 -95
- data/app/assets/javascripts/tenon/features/nested_lists.js +0 -10
- data/app/assets/javascripts/tenon/features/nested_set_writer.js.coffee +0 -65
- data/app/assets/javascripts/tenon/features/new_item_version_handler.js.coffee +0 -32
- data/app/assets/javascripts/tenon/features/pagination.js.coffee +0 -21
- data/app/assets/javascripts/tenon/features/protect_changes.js.coffee +0 -25
- data/app/assets/javascripts/tenon/features/quick_search.js.coffee +0 -41
- data/app/assets/javascripts/tenon/features/record_approval.js.coffee +0 -33
- data/app/assets/javascripts/tenon/features/record_boolean_toggle.js.coffee +0 -37
- data/app/assets/javascripts/tenon/features/record_deletion.js.coffee +0 -24
- data/app/assets/javascripts/tenon/features/record_list.js.coffee +0 -86
- data/app/assets/javascripts/tenon/features/record_list_updater.js.coffee +0 -56
- data/app/assets/javascripts/tenon/features/s3_direct_upload.js.coffee +0 -43
- data/app/assets/javascripts/tenon/features/sidebar_active_links.js.coffee +0 -20
- data/app/assets/javascripts/tenon/features/sortable_nested_fields.js.coffee +0 -17
- data/app/assets/javascripts/tenon/features/tenon_content/aesthetics.js.coffee +0 -31
- data/app/assets/javascripts/tenon/features/tenon_content/asset_attachment.js.coffee +0 -15
- data/app/assets/javascripts/tenon/features/tenon_content/asset_link.js.coffee +0 -11
- data/app/assets/javascripts/tenon/features/tenon_content/base.js.coffee +0 -16
- data/app/assets/javascripts/tenon/features/tenon_content/bottombar_toggler.js.coffee +0 -15
- data/app/assets/javascripts/tenon/features/tenon_content/caption_toggler.js.coffee +0 -11
- data/app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee +0 -53
- data/app/assets/javascripts/tenon/features/tenon_content/column_swap.js.coffee +0 -44
- data/app/assets/javascripts/tenon/features/tenon_content/editor.js.coffee +0 -34
- data/app/assets/javascripts/tenon/features/tenon_content/embedded_content_modal_handler.js.coffee +0 -12
- data/app/assets/javascripts/tenon/features/tenon_content/image_asset_link.js.coffee +0 -5
- data/app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee +0 -63
- data/app/assets/javascripts/tenon/features/tenon_content/image_links.js.coffee +0 -54
- data/app/assets/javascripts/tenon/features/tenon_content/library.js.coffee +0 -39
- data/app/assets/javascripts/tenon/features/tenon_content/library_filter.js.coffee +0 -17
- data/app/assets/javascripts/tenon/features/tenon_content/pop_out.js.coffee +0 -46
- data/app/assets/javascripts/tenon/features/tenon_content/post_crop_handler.js.coffee +0 -22
- data/app/assets/javascripts/tenon/features/tenon_content/sidebar_navigation.js.coffee +0 -26
- data/app/assets/javascripts/tenon/features/tenon_content/sortable.js.coffee +0 -18
- data/app/assets/javascripts/tenon/features/tenon_content/stretch_to_fill.js.coffee +0 -50
- data/app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee +0 -48
- data/app/assets/javascripts/tenon/features/tenon_content.js.coffee +0 -1
- data/app/assets/javascripts/tenon/features/video_feeds.js.coffee +0 -4
- data/app/assets/javascripts/tenon/manifest.json +0 -44
- data/app/assets/javascripts/tenon/medium-on-tenon.js +0 -1465
- data/app/assets/javascripts/tenon/templates/assets/asset_field.jst.eco +0 -17
- data/app/assets/javascripts/tenon/templates/assets/asset_progress.jst.eco +0 -8
- data/app/assets/javascripts/tenon/templates/assets/asset_row.jst.eco +0 -21
- data/app/assets/javascripts/tenon/templates/assets/asset_select.jst.eco +0 -1
- data/app/assets/javascripts/tenon/templates/comments/comment_row.jst.eco +0 -23
- data/app/assets/javascripts/tenon/templates/contacts/contact_row.jst.eco +0 -56
- data/app/assets/javascripts/tenon/templates/errors.jst.eco +0 -13
- data/app/assets/javascripts/tenon/templates/events/event_row.jst.eco +0 -22
- data/app/assets/javascripts/tenon/templates/galleries/gallery_row.jst.eco +0 -12
- data/app/assets/javascripts/tenon/templates/item_versions/item_version_row.jst.eco +0 -22
- data/app/assets/javascripts/tenon/templates/modal.jst.eco +0 -14
- data/app/assets/javascripts/tenon/templates/pages/page_row.jst.eco +0 -21
- data/app/assets/javascripts/tenon/templates/post_categories/post_category_row.jst.eco +0 -12
- data/app/assets/javascripts/tenon/templates/posts/post_row.jst.eco +0 -30
- data/app/assets/javascripts/tenon/templates/redirects/redirect_row.jst.eco +0 -18
- data/app/assets/javascripts/tenon/templates/tenon_callouts/tenon_callout_row.jst.eco +0 -19
- data/app/assets/javascripts/tenon/templates/tenon_content/popped_out.jst.eco +0 -6
- data/app/assets/javascripts/tenon/templates/users/user_row.jst.eco +0 -21
- data/app/assets/javascripts/tenon/tenon.js +0 -68
- data/app/assets/javascripts/tenon/tenon_dispatcher.js.coffee +0 -25
- data/app/assets/javascripts/tenon/tenon_manifest.js +0 -45
- data/app/assets/stylesheets/tenon/colors-custom.scss +0 -25
- data/app/assets/stylesheets/tenon/colors-named.scss +0 -22
- data/app/assets/stylesheets/tenon/helpers.scss +0 -28
- data/app/assets/stylesheets/tenon/layout/assets.scss +0 -49
- data/app/assets/stylesheets/tenon/layout/breakpoints.scss +0 -48
- data/app/assets/stylesheets/tenon/layout/global.scss +0 -36
- data/app/assets/stylesheets/tenon/layout/grid.scss +0 -145
- data/app/assets/stylesheets/tenon/layout/main-nav.scss +0 -149
- data/app/assets/stylesheets/tenon/layout/margins.scss +0 -3
- data/app/assets/stylesheets/tenon/layout/mobile.scss +0 -5
- data/app/assets/stylesheets/tenon/layout/sidebar.scss +0 -102
- data/app/assets/stylesheets/tenon/layout/util-nav.scss +0 -51
- data/app/assets/stylesheets/tenon/mixins.scss +0 -81
- data/app/assets/stylesheets/tenon/styleguide.scss +0 -6
- data/app/assets/stylesheets/tenon/tenon.scss +0 -71
- data/app/assets/stylesheets/tenon/typography.scss +0 -65
- data/app/assets/stylesheets/tenon/ui/alerts.scss +0 -65
- data/app/assets/stylesheets/tenon/ui/asset-attachment.scss +0 -136
- data/app/assets/stylesheets/tenon/ui/asset-cropping.scss +0 -51
- data/app/assets/stylesheets/tenon/ui/asset-uploads.scss +0 -26
- data/app/assets/stylesheets/tenon/ui/buttons.scss +0 -65
- data/app/assets/stylesheets/tenon/ui/callouts.scss +0 -26
- data/app/assets/stylesheets/tenon/ui/comments.scss +0 -57
- data/app/assets/stylesheets/tenon/ui/forms.scss +0 -204
- data/app/assets/stylesheets/tenon/ui/generic-loader.scss +0 -21
- data/app/assets/stylesheets/tenon/ui/header-tools.scss +0 -116
- data/app/assets/stylesheets/tenon/ui/i18n.scss +0 -18
- data/app/assets/stylesheets/tenon/ui/list-style-toggle.scss +0 -39
- data/app/assets/stylesheets/tenon/ui/login.scss +0 -97
- data/app/assets/stylesheets/tenon/ui/medium-editor.scss +0 -114
- data/app/assets/stylesheets/tenon/ui/modals.scss +0 -179
- data/app/assets/stylesheets/tenon/ui/pagination.scss +0 -113
- data/app/assets/stylesheets/tenon/ui/progress-bars.scss +0 -131
- data/app/assets/stylesheets/tenon/ui/quick-search.scss +0 -20
- data/app/assets/stylesheets/tenon/ui/record-grids.scss +0 -95
- data/app/assets/stylesheets/tenon/ui/record-lists.scss +0 -154
- data/app/assets/stylesheets/tenon/ui/section-headers.scss +0 -30
- data/app/assets/stylesheets/tenon/ui/select2-custom.scss +0 -70
- data/app/assets/stylesheets/tenon/ui/tables.scss +0 -19
- data/app/assets/stylesheets/tenon/ui/tabs.scss +0 -7
- data/app/assets/stylesheets/tenon/ui/tenon-content-library.scss +0 -80
- data/app/assets/stylesheets/tenon/ui/tenon-content-popped-out.scss +0 -92
- data/app/assets/stylesheets/tenon/ui/tenon-content.scss +0 -318
- data/app/assets/stylesheets/tenon/ui/thinking.scss +0 -3
- data/app/assets/stylesheets/tenon/ui/toolbox.scss +0 -31
- data/app/assets/stylesheets/tenon/z-indexes.scss +0 -35
- data/app/assets/stylesheets/tenon_addons.scss +0 -1
- data/app/controllers/tenon/comments_controller.rb +0 -51
- data/app/controllers/tenon/contacts_controller.rb +0 -65
- data/app/controllers/tenon/events_controller.rb +0 -9
- data/app/controllers/tenon/galleries_controller.rb +0 -9
- data/app/controllers/tenon/pages_controller.rb +0 -51
- data/app/controllers/tenon/post_categories_controller.rb +0 -9
- data/app/controllers/tenon/posts_controller.rb +0 -28
- data/app/controllers/tenon/redirects_controller.rb +0 -25
- data/app/controllers/tenon/tenon_callouts_controller.rb +0 -7
- data/app/controllers/tenon/users_controller.rb +0 -64
- data/app/decorators/tenon/comment_decorator.rb +0 -22
- data/app/decorators/tenon/contact_decorator.rb +0 -13
- data/app/decorators/tenon/event_decorator.rb +0 -11
- data/app/decorators/tenon/gallery_decorator.rb +0 -4
- data/app/decorators/tenon/page_decorator.rb +0 -11
- data/app/decorators/tenon/post_category_decorator.rb +0 -4
- data/app/decorators/tenon/post_decorator.rb +0 -4
- data/app/decorators/tenon/redirect_decorator.rb +0 -2
- data/app/decorators/tenon/tenon_callout_decorator.rb +0 -4
- data/app/decorators/tenon/user_decorator.rb +0 -4
- data/app/mailers/tenon/comment_mailer.rb +0 -16
- data/app/mailers/tenon/contact_mailer.rb +0 -15
- data/app/models/ability.rb +0 -32
- data/app/models/tenon/comment.rb +0 -47
- data/app/models/tenon/comment_subscriber.rb +0 -7
- data/app/models/tenon/contact.rb +0 -46
- data/app/models/tenon/event.rb +0 -45
- data/app/models/tenon/gallery.rb +0 -15
- data/app/models/tenon/page.rb +0 -105
- data/app/models/tenon/photo.rb +0 -10
- data/app/models/tenon/post.rb +0 -35
- data/app/models/tenon/post_category.rb +0 -7
- data/app/models/tenon/redirect.rb +0 -17
- data/app/models/tenon/role.rb +0 -8
- data/app/models/tenon/role_assignment.rb +0 -6
- data/app/models/tenon/s3_direct_upload.rb +0 -75
- data/app/models/tenon/tenon_callout.rb +0 -16
- data/app/models/tenon/user.rb +0 -60
- data/app/views/devise/confirmations/new.html.erb +0 -12
- data/app/views/devise/confirmations/new.html.haml +0 -0
- data/app/views/devise/mailer/confirmation_instructions.html.haml +0 -7
- data/app/views/devise/mailer/reset_password_instructions.html.haml +0 -15
- data/app/views/devise/mailer/unlock_instructions.html.haml +0 -9
- data/app/views/devise/passwords/edit.html.haml +0 -22
- data/app/views/devise/passwords/new.html.haml +0 -17
- data/app/views/devise/registrations/edit.html.haml +0 -0
- data/app/views/devise/registrations/new.html.haml +0 -22
- data/app/views/devise/sessions/new.html.haml +0 -28
- data/app/views/devise/shared/_links.erb +0 -19
- data/app/views/devise/shared/_links.haml +0 -0
- data/app/views/devise/unlocks/new.html.erb +0 -12
- data/app/views/devise/unlocks/new.html.haml +0 -0
- data/app/views/layouts/tenon/login.html.haml +0 -19
- data/app/views/tenon/assets/_asset.json.jbuilder +0 -7
- data/app/views/tenon/assets/_sidebar_index.html.haml +0 -18
- data/app/views/tenon/assets/create.json.jbuilder +0 -1
- data/app/views/tenon/assets/index.json.jbuilder +0 -5
- data/app/views/tenon/assets/update.json.jbuilder +0 -1
- data/app/views/tenon/comment_mailer/comment_notification.html.haml +0 -7
- data/app/views/tenon/comments/_sidebar_index.html.haml +0 -22
- data/app/views/tenon/comments/index.html.haml +0 -19
- data/app/views/tenon/comments/index.json.jbuilder +0 -22
- data/app/views/tenon/contact_mailer/contact_notification.html.haml +0 -15
- data/app/views/tenon/contacts/_sidebar_index.html.haml +0 -32
- data/app/views/tenon/contacts/index.html.haml +0 -19
- data/app/views/tenon/contacts/index.json.jbuilder +0 -15
- data/app/views/tenon/events/_form.html.haml +0 -44
- data/app/views/tenon/events/edit.html.haml +0 -8
- data/app/views/tenon/events/index.html.haml +0 -23
- data/app/views/tenon/events/index.json.jbuilder +0 -16
- data/app/views/tenon/events/new.html.haml +0 -8
- data/app/views/tenon/galleries/_form.html.haml +0 -38
- data/app/views/tenon/galleries/_photo_fields.html.haml +0 -3
- data/app/views/tenon/galleries/edit.html.haml +0 -8
- data/app/views/tenon/galleries/index.html.haml +0 -22
- data/app/views/tenon/galleries/index.json.jbuilder +0 -15
- data/app/views/tenon/galleries/new.html.haml +0 -8
- data/app/views/tenon/pages/_form.html.haml +0 -58
- data/app/views/tenon/pages/edit.html.haml +0 -8
- data/app/views/tenon/pages/index.html.haml +0 -23
- data/app/views/tenon/pages/index.json.jbuilder +0 -22
- data/app/views/tenon/pages/new.html.haml +0 -8
- data/app/views/tenon/post_categories/_form.html.haml +0 -11
- data/app/views/tenon/post_categories/_post_category.json.jbuilder +0 -2
- data/app/views/tenon/post_categories/create.json.jbuilder +0 -1
- data/app/views/tenon/post_categories/edit.html.haml +0 -1
- data/app/views/tenon/post_categories/index.html.haml +0 -30
- data/app/views/tenon/post_categories/index.json.jbuilder +0 -5
- data/app/views/tenon/post_categories/update.json.jbuilder +0 -1
- data/app/views/tenon/posts/_form.html.haml +0 -65
- data/app/views/tenon/posts/edit.html.haml +0 -8
- data/app/views/tenon/posts/index.html.haml +0 -27
- data/app/views/tenon/posts/index.json.jbuilder +0 -20
- data/app/views/tenon/posts/new.html.haml +0 -8
- data/app/views/tenon/redirects/_form.html.haml +0 -42
- data/app/views/tenon/redirects/_redirect.json.jbuilder +0 -3
- data/app/views/tenon/redirects/edit.html.haml +0 -8
- data/app/views/tenon/redirects/index.html.haml +0 -29
- data/app/views/tenon/redirects/index.json.jbuilder +0 -5
- data/app/views/tenon/redirects/new.html.haml +0 -8
- data/app/views/tenon/shared/_posts_nav.html.haml +0 -8
- data/app/views/tenon/shared/menu_items/_assets.html.haml +0 -3
- data/app/views/tenon/shared/menu_items/_comments.html.haml +0 -2
- data/app/views/tenon/shared/menu_items/_events.html.haml +0 -6
- data/app/views/tenon/shared/menu_items/_galleries.html.haml +0 -6
- data/app/views/tenon/shared/menu_items/_pages.html.haml +0 -6
- data/app/views/tenon/shared/menu_items/_posts.html.haml +0 -7
- data/app/views/tenon/shared/menu_items/_settings.html.haml +0 -2
- data/app/views/tenon/shared/menu_items/_users.html.haml +0 -2
- data/app/views/tenon/shared/section_header/_quick_search.html.haml +0 -3
- data/app/views/tenon/shared/section_header/_sidebar_toggle.html.haml +0 -1
- data/app/views/tenon/tenon_callouts/_form.html.haml +0 -45
- data/app/views/tenon/tenon_callouts/_tenon_callout.json.jbuilder +0 -1
- data/app/views/tenon/tenon_callouts/edit.html.haml +0 -8
- data/app/views/tenon/tenon_callouts/index.html.haml +0 -24
- data/app/views/tenon/tenon_callouts/index.json.jbuilder +0 -5
- data/app/views/tenon/tenon_callouts/new.html.haml +0 -8
- data/app/views/tenon/users/_form.html.haml +0 -50
- data/app/views/tenon/users/edit.html.haml +0 -8
- data/app/views/tenon/users/index.html.haml +0 -23
- data/app/views/tenon/users/index.json.jbuilder +0 -28
- data/app/views/tenon/users/new.html.haml +0 -8
- data/config/initializers/devise.rb +0 -258
- data/config/locales/devise.en.yml +0 -60
- data/config/locales/tenon.en.yml +0 -313
- data/db/seeds.rb +0 -47
- data/lib/generators/tenon/scaffold/templates/view__item.json.jbuilder +0 -1
- data/lib/generators/tenon/scaffold/templates/view_index.json.jbuilder +0 -5
- data/lib/generators/tenon/scaffold/templates/view_item_row.jst.eco +0 -13
- data/lib/generators/tenon/scaffold_small/scaffold_small_generator.rb +0 -8
- data/lib/generators/tenon/scaffold_small/templates/controller.rb +0 -19
- data/lib/generators/tenon/scaffold_small/templates/decorator.rb +0 -2
- data/lib/generators/tenon/scaffold_small/templates/view__form.html.haml +0 -26
- data/lib/generators/tenon/scaffold_small/templates/view__item.json.jbuilder +0 -2
- data/lib/generators/tenon/scaffold_small/templates/view_create.json.jbuilder +0 -1
- data/lib/generators/tenon/scaffold_small/templates/view_index.html.haml +0 -27
- data/lib/generators/tenon/scaffold_small/templates/view_index.json.jbuilder +0 -5
- data/lib/generators/tenon/scaffold_small/templates/view_item_row.jst.eco +0 -12
- data/lib/generators/tenon/scaffold_small/templates/view_update.json.jbuilder +0 -1
- data/lib/tenon/can_have_comments.rb +0 -16
- data/lib/tenon/config/events.rb +0 -29
- data/lib/tenon/factories/comments.rb +0 -10
- data/lib/tenon/factories/contacts.rb +0 -9
- data/lib/tenon/factories/events.rb +0 -7
- data/lib/tenon/factories/galleries.rb +0 -5
- data/lib/tenon/factories/pages.rb +0 -5
- data/lib/tenon/factories/posts.rb +0 -10
- data/lib/tenon/factories/redirects.rb +0 -9
- data/lib/tenon/factories/tenon_callouts.rb +0 -9
- data/lib/tenon/factories/users.rb +0 -26
- data/lib/tenon/warning_generator.rb +0 -29
- data/spec/controllers/tenon/assets_controller_spec.rb +0 -262
- data/spec/controllers/tenon/comments_controller_spec.rb +0 -173
- data/spec/controllers/tenon/contacts_controller_spec.rb +0 -174
- data/spec/controllers/tenon/index_controller_spec.rb +0 -31
- data/spec/controllers/tenon/item_assets_controller_spec.rb +0 -29
- data/spec/controllers/tenon/pages_controller_spec.rb +0 -67
- data/spec/controllers/tenon/posts_controller_spec.rb +0 -31
- data/spec/controllers/tenon/resources_controller_spec.rb +0 -352
- data/spec/controllers/tenon/settings_controller_spec.rb +0 -65
- data/spec/controllers/tenon/simple_resources_controller_spec.rb +0 -42
- data/spec/controllers/tenon/users_controller_spec.rb +0 -112
- data/spec/decorators/tenon/application_decorator_spec.rb +0 -75
- data/spec/decorators/tenon/asset_decorator_spec.rb +0 -101
- data/spec/decorators/tenon/comment_decorator_spec.rb +0 -43
- data/spec/decorators/tenon/contact_decorator_spec.rb +0 -24
- data/spec/decorators/tenon/event_decorator_spec.rb +0 -26
- data/spec/decorators/tenon/page_decorator_spec.rb +0 -23
- data/spec/decorators/tenon/tenon_content/row_type_decorator_spec.rb +0 -20
- data/spec/features/settings_spec.rb +0 -75
- data/spec/features/tenon/assets_spec.rb +0 -88
- data/spec/features/tenon/comments_spec.rb +0 -51
- data/spec/features/tenon/contacts_spec.rb +0 -51
- data/spec/features/tenon/events_spec.rb +0 -104
- data/spec/features/tenon/galleries_spec.rb +0 -107
- data/spec/features/tenon/i18n_spec.rb +0 -106
- data/spec/features/tenon/pages_spec.rb +0 -97
- data/spec/features/tenon/post_categories_spec.rb +0 -91
- data/spec/features/tenon/posts_spec.rb +0 -93
- data/spec/features/tenon/tenon_callouts_spec.rb +0 -101
- data/spec/features/tenon/users_spec.rb +0 -98
- data/spec/fixtures/files/test.png +0 -0
- data/spec/lib/tenon/asset_style_generator_spec.rb +0 -84
- data/spec/lib/tenon/can_be_foreign_spec.rb +0 -20
- data/spec/lib/tenon/can_have_comments_spec.rb +0 -22
- data/spec/lib/tenon/has_asset_spec.rb +0 -46
- data/spec/lib/tenon/has_history/attr_serializer_spec.rb +0 -63
- data/spec/lib/tenon/i18n_lookup_spec.rb +0 -88
- data/spec/lib/tenon/proxy_attachment_spec.rb +0 -96
- data/spec/lib/tenon/reorderable_spec.rb +0 -25
- data/spec/lib/tenon/tenon_content_spec.rb +0 -22
- data/spec/lib/tenon/warning_generator_spec.rb +0 -153
- data/spec/models/tenon/asset_spec.rb +0 -98
- data/spec/models/tenon/comment_spec.rb +0 -81
- data/spec/models/tenon/contact_spec.rb +0 -62
- data/spec/models/tenon/event_spec.rb +0 -79
- data/spec/models/tenon/gallery_spec.rb +0 -12
- data/spec/models/tenon/item_asset_spec.rb +0 -19
- data/spec/models/tenon/my_settings_spec.rb +0 -27
- data/spec/models/tenon/page_spec.rb +0 -60
- data/spec/models/tenon/post_spec.rb +0 -48
- data/spec/models/tenon/redirect_spec.rb +0 -31
- data/spec/models/tenon/tenon_callout_spec.rb +0 -10
- data/spec/models/tenon/tenon_content/row_spec.rb +0 -34
- data/spec/models/tenon/user_spec.rb +0 -59
- data/spec/services/tenon/redirector_spec.rb +0 -30
- data/spec/spec_helper.rb +0 -79
- data/spec/support/integration_example_group.rb +0 -35
- data/spec/support/request_helpers.rb +0 -10
- data/vendor/assets/javascripts/backstretch.js +0 -4
- data/vendor/assets/javascripts/bootstrap.collapse.js +0 -179
- data/vendor/assets/javascripts/bootstrap.datetimepicker.js +0 -954
- data/vendor/assets/javascripts/bootstrap.tabs.js +0 -135
- data/vendor/assets/javascripts/cufon/Aller_400.font.js +0 -7
- data/vendor/assets/javascripts/cufon/Aller_700.font.js +0 -7
- data/vendor/assets/javascripts/cufon/cufon.js +0 -7
- data/vendor/assets/javascripts/jquery.corner.js +0 -249
- data/vendor/assets/javascripts/jquery.hoverIntent.js +0 -115
- data/vendor/assets/javascripts/jquery.radioSlider.js +0 -55
- data/vendor/assets/javascripts/jscrollpane.js +0 -1435
- data/vendor/assets/javascripts/select2.js +0 -3
- data/vendor/assets/javascripts/underscore.inflection.js +0 -177
- data/vendor/assets/stylesheets/bootstrap.datetimepicker.css +0 -152
- data/vendor/assets/stylesheets/bootstrap.tables.scss +0 -201
- data/vendor/assets/stylesheets/jscrollpane.scss +0 -20
- data/vendor/assets/stylesheets/select2.css +0 -1
@@ -1,1465 +0,0 @@
|
|
1
|
-
// forked from medium v. 0.9.3
|
2
|
-
function MediumEditor(elements, options) {
|
3
|
-
'use strict';
|
4
|
-
return this.init(elements, options);
|
5
|
-
}
|
6
|
-
|
7
|
-
if (typeof module === 'object') {
|
8
|
-
module.exports = MediumEditor;
|
9
|
-
}
|
10
|
-
|
11
|
-
(function (window, document) {
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
function extend(b, a) {
|
15
|
-
var prop;
|
16
|
-
if (b === undefined) {
|
17
|
-
return a;
|
18
|
-
}
|
19
|
-
for (prop in a) {
|
20
|
-
if (a.hasOwnProperty(prop) && b.hasOwnProperty(prop) === false) {
|
21
|
-
b[prop] = a[prop];
|
22
|
-
}
|
23
|
-
}
|
24
|
-
return b;
|
25
|
-
}
|
26
|
-
|
27
|
-
// http://stackoverflow.com/questions/5605401/insert-link-in-contenteditable-element
|
28
|
-
// by Tim Down
|
29
|
-
function saveSelection() {
|
30
|
-
var i,
|
31
|
-
len,
|
32
|
-
ranges,
|
33
|
-
sel = window.getSelection();
|
34
|
-
if (sel.getRangeAt && sel.rangeCount) {
|
35
|
-
ranges = [];
|
36
|
-
for (i = 0, len = sel.rangeCount; i < len; i += 1) {
|
37
|
-
ranges.push(sel.getRangeAt(i));
|
38
|
-
}
|
39
|
-
return ranges;
|
40
|
-
}
|
41
|
-
return null;
|
42
|
-
}
|
43
|
-
|
44
|
-
function restoreSelection(savedSel) {
|
45
|
-
var i,
|
46
|
-
len,
|
47
|
-
sel = window.getSelection();
|
48
|
-
|
49
|
-
if (savedSel) {
|
50
|
-
sel.removeAllRanges();
|
51
|
-
for (i = 0, len = savedSel.length; i < len; i += 1) {
|
52
|
-
sel.addRange(savedSel[i]);
|
53
|
-
}
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
// http://stackoverflow.com/questions/1197401/how-can-i-get-the-element-the-caret-is-in-with-javascript-when-using-contentedi
|
58
|
-
// by You
|
59
|
-
function getSelectionStart() {
|
60
|
-
var node = document.getSelection().anchorNode,
|
61
|
-
startNode = (node && node.nodeType === 3 ? node.parentNode : node);
|
62
|
-
return startNode;
|
63
|
-
}
|
64
|
-
|
65
|
-
// http://stackoverflow.com/questions/4176923/html-of-selected-text
|
66
|
-
// by Tim Down
|
67
|
-
function getSelectionHtml() {
|
68
|
-
var i,
|
69
|
-
html = '',
|
70
|
-
sel,
|
71
|
-
len,
|
72
|
-
container;
|
73
|
-
if (window.getSelection !== undefined) {
|
74
|
-
sel = window.getSelection();
|
75
|
-
if (sel.rangeCount) {
|
76
|
-
container = document.createElement('div');
|
77
|
-
for (i = 0, len = sel.rangeCount; i < len; i += 1) {
|
78
|
-
container.appendChild(sel.getRangeAt(i).cloneContents());
|
79
|
-
}
|
80
|
-
html = container.innerHTML;
|
81
|
-
}
|
82
|
-
} else if (document.selection !== undefined) {
|
83
|
-
if (document.selection.type === 'Text') {
|
84
|
-
html = document.selection.createRange().htmlText;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
return html;
|
88
|
-
}
|
89
|
-
|
90
|
-
// https://github.com/jashkenas/underscore
|
91
|
-
function isElement(obj) {
|
92
|
-
return !!(obj && obj.nodeType === 1);
|
93
|
-
}
|
94
|
-
|
95
|
-
MediumEditor.prototype = {
|
96
|
-
defaults: {
|
97
|
-
allowMultiParagraphSelection: true,
|
98
|
-
anchorInputPlaceholder: 'Paste or type a link',
|
99
|
-
anchorPreviewHideDelay: 500,
|
100
|
-
buttons: ['bold', 'italic', 'underline', 'anchor', 'header1', 'header2', 'header3', 'header4', 'quote'],
|
101
|
-
buttonLabels: false,
|
102
|
-
checkLinkFormat: false,
|
103
|
-
cleanPastedHTML: false,
|
104
|
-
delay: 0,
|
105
|
-
diffLeft: 0,
|
106
|
-
diffTop: -10,
|
107
|
-
disableReturn: false,
|
108
|
-
disableDoubleReturn: false,
|
109
|
-
disableToolbar: false,
|
110
|
-
disableEditing: false,
|
111
|
-
elementsContainer: false,
|
112
|
-
firstHeader: 'h3',
|
113
|
-
secondHeader: 'h4',
|
114
|
-
thirdHeader: 'h5',
|
115
|
-
fourthHeader: 'h6',
|
116
|
-
forcePlainText: true,
|
117
|
-
placeholder: 'Type your text',
|
118
|
-
targetBlank: false,
|
119
|
-
extensions: {}
|
120
|
-
},
|
121
|
-
|
122
|
-
// http://stackoverflow.com/questions/17907445/how-to-detect-ie11#comment30165888_17907562
|
123
|
-
// by rg89
|
124
|
-
isIE: ((navigator.appName === 'Microsoft Internet Explorer') || ((navigator.appName === 'Netscape') && (new RegExp('Trident/.*rv:([0-9]{1,}[.0-9]{0,})').exec(navigator.userAgent) !== null))),
|
125
|
-
|
126
|
-
init: function (elements, options) {
|
127
|
-
this.setElementSelection(elements);
|
128
|
-
if (this.elements.length === 0) {
|
129
|
-
return;
|
130
|
-
}
|
131
|
-
this.parentElements = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'pre'];
|
132
|
-
this.id = document.querySelectorAll('.medium-editor-toolbar').length + 1;
|
133
|
-
this.options = extend(options, this.defaults);
|
134
|
-
return this.setup();
|
135
|
-
},
|
136
|
-
|
137
|
-
setup: function () {
|
138
|
-
this.isActive = true;
|
139
|
-
this.initElements()
|
140
|
-
.bindSelect()
|
141
|
-
.bindPaste()
|
142
|
-
.setPlaceholders()
|
143
|
-
.bindWindowActions();
|
144
|
-
},
|
145
|
-
|
146
|
-
initElements: function () {
|
147
|
-
this.updateElementList();
|
148
|
-
var i,
|
149
|
-
addToolbar = false;
|
150
|
-
for (i = 0; i < this.elements.length; i += 1) {
|
151
|
-
if (!this.options.disableEditing && !this.elements[i].getAttribute('data-disable-editing')) {
|
152
|
-
this.elements[i].setAttribute('contentEditable', true);
|
153
|
-
}
|
154
|
-
if (!this.elements[i].getAttribute('data-placeholder')) {
|
155
|
-
this.elements[i].setAttribute('data-placeholder', this.options.placeholder);
|
156
|
-
}
|
157
|
-
this.elements[i].setAttribute('data-medium-element', true);
|
158
|
-
this.bindParagraphCreation(i).bindReturn(i).bindTab(i);
|
159
|
-
if (!this.options.disableToolbar && !this.elements[i].getAttribute('data-disable-toolbar')) {
|
160
|
-
addToolbar = true;
|
161
|
-
}
|
162
|
-
}
|
163
|
-
// Init toolbar
|
164
|
-
if (addToolbar) {
|
165
|
-
if (!this.options.elementsContainer) {
|
166
|
-
this.options.elementsContainer = document.body;
|
167
|
-
}
|
168
|
-
this.initToolbar()
|
169
|
-
.bindButtons()
|
170
|
-
.bindAnchorForm()
|
171
|
-
.bindAnchorPreview();
|
172
|
-
}
|
173
|
-
return this;
|
174
|
-
},
|
175
|
-
|
176
|
-
setElementSelection: function (selector) {
|
177
|
-
this.elementSelection = selector;
|
178
|
-
this.updateElementList();
|
179
|
-
},
|
180
|
-
|
181
|
-
updateElementList: function () {
|
182
|
-
this.elements = typeof this.elementSelection === 'string' ? document.querySelectorAll(this.elementSelection) : this.elementSelection;
|
183
|
-
if (this.elements.nodeType === 1) {
|
184
|
-
this.elements = [this.elements];
|
185
|
-
}
|
186
|
-
},
|
187
|
-
|
188
|
-
serialize: function () {
|
189
|
-
var i,
|
190
|
-
elementid,
|
191
|
-
content = {};
|
192
|
-
for (i = 0; i < this.elements.length; i += 1) {
|
193
|
-
elementid = (this.elements[i].id !== '') ? this.elements[i].id : 'element-' + i;
|
194
|
-
content[elementid] = {
|
195
|
-
value: this.elements[i].innerHTML.trim()
|
196
|
-
};
|
197
|
-
}
|
198
|
-
return content;
|
199
|
-
},
|
200
|
-
|
201
|
-
/**
|
202
|
-
* Helper function to call a method with a number of parameters on all registered extensions.
|
203
|
-
* The function assures that the function exists before calling.
|
204
|
-
*
|
205
|
-
* @param {string} funcName name of the function to call
|
206
|
-
* @param [args] arguments passed into funcName
|
207
|
-
*/
|
208
|
-
callExtensions: function (funcName) {
|
209
|
-
if (arguments.length < 1) {
|
210
|
-
return;
|
211
|
-
}
|
212
|
-
|
213
|
-
var args = Array.prototype.slice.call(arguments, 1),
|
214
|
-
ext,
|
215
|
-
name;
|
216
|
-
|
217
|
-
for (name in this.options.extensions) {
|
218
|
-
if (this.options.extensions.hasOwnProperty(name)) {
|
219
|
-
ext = this.options.extensions[name];
|
220
|
-
if (ext[funcName] !== undefined) {
|
221
|
-
ext[funcName].apply(ext, args);
|
222
|
-
}
|
223
|
-
}
|
224
|
-
}
|
225
|
-
},
|
226
|
-
|
227
|
-
bindParagraphCreation: function (index) {
|
228
|
-
var self = this;
|
229
|
-
this.elements[index].addEventListener('keypress', function (e) {
|
230
|
-
var node = getSelectionStart(),
|
231
|
-
tagName;
|
232
|
-
if (e.which === 32) {
|
233
|
-
tagName = node.tagName.toLowerCase();
|
234
|
-
if (tagName === 'a') {
|
235
|
-
document.execCommand('unlink', false, null);
|
236
|
-
}
|
237
|
-
}
|
238
|
-
self.triggerChange();
|
239
|
-
});
|
240
|
-
|
241
|
-
this.elements[index].addEventListener('keyup', function (e) {
|
242
|
-
var node = getSelectionStart(),
|
243
|
-
tagName;
|
244
|
-
if (node && node.getAttribute('data-medium-element') && node.children.length === 0 && !(self.options.disableReturn || node.getAttribute('data-disable-return'))) {
|
245
|
-
document.execCommand('formatBlock', false, 'p');
|
246
|
-
}
|
247
|
-
if (e.which === 13) {
|
248
|
-
node = getSelectionStart();
|
249
|
-
tagName = node.tagName.toLowerCase();
|
250
|
-
if (!(self.options.disableReturn || this.getAttribute('data-disable-return')) &&
|
251
|
-
tagName !== 'li' && !self.isListItemChild(node)) {
|
252
|
-
if (!e.shiftKey) {
|
253
|
-
document.execCommand('formatBlock', false, 'p');
|
254
|
-
}
|
255
|
-
if (tagName === 'a') {
|
256
|
-
document.execCommand('unlink', false, null);
|
257
|
-
}
|
258
|
-
}
|
259
|
-
}
|
260
|
-
self.triggerChange();
|
261
|
-
});
|
262
|
-
|
263
|
-
return this;
|
264
|
-
},
|
265
|
-
|
266
|
-
isListItemChild: function (node) {
|
267
|
-
var parentNode = node.parentNode,
|
268
|
-
tagName = parentNode.tagName.toLowerCase();
|
269
|
-
while (this.parentElements.indexOf(tagName) === -1 && tagName !== 'div') {
|
270
|
-
if (tagName === 'li') {
|
271
|
-
return true;
|
272
|
-
}
|
273
|
-
parentNode = parentNode.parentNode;
|
274
|
-
if (parentNode && parentNode.tagName) {
|
275
|
-
tagName = parentNode.tagName.toLowerCase();
|
276
|
-
} else {
|
277
|
-
return false;
|
278
|
-
}
|
279
|
-
}
|
280
|
-
return false;
|
281
|
-
},
|
282
|
-
|
283
|
-
bindReturn: function (index) {
|
284
|
-
var self = this;
|
285
|
-
this.elements[index].addEventListener('keypress', function (e) {
|
286
|
-
if (e.which === 13) {
|
287
|
-
if (self.options.disableReturn || this.getAttribute('data-disable-return')) {
|
288
|
-
e.preventDefault();
|
289
|
-
} else if (self.options.disableDoubleReturn || this.getAttribute('data-disable-double-return')) {
|
290
|
-
var node = getSelectionStart();
|
291
|
-
if (node && node.innerText === '\n') {
|
292
|
-
e.preventDefault();
|
293
|
-
}
|
294
|
-
}
|
295
|
-
}
|
296
|
-
});
|
297
|
-
return this;
|
298
|
-
},
|
299
|
-
|
300
|
-
bindTab: function (index) {
|
301
|
-
this.elements[index].addEventListener('keydown', function (e) {
|
302
|
-
if (e.which === 9) {
|
303
|
-
// Override tab only for pre nodes
|
304
|
-
var tag = getSelectionStart().tagName.toLowerCase();
|
305
|
-
if (tag === 'pre') {
|
306
|
-
e.preventDefault();
|
307
|
-
document.execCommand('insertHtml', null, ' ');
|
308
|
-
this.triggerChange();
|
309
|
-
}
|
310
|
-
}
|
311
|
-
});
|
312
|
-
return this;
|
313
|
-
},
|
314
|
-
|
315
|
-
buttonTemplate: function (btnType) {
|
316
|
-
var buttonLabels = this.getButtonLabels(this.options.buttonLabels),
|
317
|
-
buttonTemplates = {
|
318
|
-
'bold': '<button class="medium-editor-action medium-editor-action-bold" data-action="bold" data-element="b">' + buttonLabels.bold + '</button>',
|
319
|
-
'italic': '<button class="medium-editor-action medium-editor-action-italic" data-action="italic" data-element="i">' + buttonLabels.italic + '</button>',
|
320
|
-
'underline': '<button class="medium-editor-action medium-editor-action-underline" data-action="underline" data-element="u">' + buttonLabels.underline + '</button>',
|
321
|
-
'strikethrough': '<button class="medium-editor-action medium-editor-action-strikethrough" data-action="strikethrough" data-element="strike"><strike>A</strike></button>',
|
322
|
-
'superscript': '<button class="medium-editor-action medium-editor-action-superscript" data-action="superscript" data-element="sup">' + buttonLabels.superscript + '</button>',
|
323
|
-
'subscript': '<button class="medium-editor-action medium-editor-action-subscript" data-action="subscript" data-element="sub">' + buttonLabels.subscript + '</button>',
|
324
|
-
'anchor': '<button class="medium-editor-action medium-editor-action-anchor" data-action="anchor" data-element="a">' + buttonLabels.anchor + '</button>',
|
325
|
-
'image': '<button class="medium-editor-action medium-editor-action-image" data-action="image" data-element="img">' + buttonLabels.image + '</button>',
|
326
|
-
'header1': '<button class="medium-editor-action medium-editor-action-header1" data-action="append-' + this.options.firstHeader + '" data-element="' + this.options.firstHeader + '">' + buttonLabels.header1 + '</button>',
|
327
|
-
'header2': '<button class="medium-editor-action medium-editor-action-header2" data-action="append-' + this.options.secondHeader + '" data-element="' + this.options.secondHeader + '">' + buttonLabels.header2 + '</button>',
|
328
|
-
'header3': '<button class="medium-editor-action medium-editor-action-header3" data-action="append-' + this.options.thirdHeader + '" data-element="' + this.options.thirdHeader + '">' + buttonLabels.header3 + '</button>',
|
329
|
-
'header4': '<button class="medium-editor-action medium-editor-action-header4" data-action="append-' + this.options.fourthHeader + '" data-element="' + this.options.fourthHeader + '">' + buttonLabels.header4 + '</button>',
|
330
|
-
'quote': '<button class="medium-editor-action medium-editor-action-quote" data-action="append-blockquote" data-element="blockquote">' + buttonLabels.quote + '</button>',
|
331
|
-
'orderedlist': '<button class="medium-editor-action medium-editor-action-orderedlist" data-action="insertorderedlist" data-element="ol">' + buttonLabels.orderedlist + '</button>',
|
332
|
-
'unorderedlist': '<button class="medium-editor-action medium-editor-action-unorderedlist" data-action="insertunorderedlist" data-element="ul">' + buttonLabels.unorderedlist + '</button>',
|
333
|
-
'pre': '<button class="medium-editor-action medium-editor-action-pre" data-action="append-pre" data-element="pre">' + buttonLabels.pre + '</button>',
|
334
|
-
'indent': '<button class="medium-editor-action medium-editor-action-indent" data-action="indent" data-element="ul">' + buttonLabels.indent + '</button>',
|
335
|
-
'outdent': '<button class="medium-editor-action medium-editor-action-outdent" data-action="outdent" data-element="ul">' + buttonLabels.outdent + '</button>'
|
336
|
-
};
|
337
|
-
return buttonTemplates[btnType] || false;
|
338
|
-
},
|
339
|
-
|
340
|
-
// TODO: break method
|
341
|
-
getButtonLabels: function (buttonLabelType) {
|
342
|
-
var customButtonLabels,
|
343
|
-
attrname,
|
344
|
-
buttonLabels = {
|
345
|
-
'bold': '<b>B</b>',
|
346
|
-
'italic': '<b><i>I</i></b>',
|
347
|
-
'underline': '<b><u>U</u></b>',
|
348
|
-
'superscript': '<b>x<sup>1</sup></b>',
|
349
|
-
'subscript': '<b>x<sub>1</sub></b>',
|
350
|
-
'anchor': '<b>#</b>',
|
351
|
-
'image': '<b>image</b>',
|
352
|
-
'header1': '<b>H1</b>',
|
353
|
-
'header2': '<b>H2</b>',
|
354
|
-
'header3': '<b>H3</b>',
|
355
|
-
'header4': '<b>H4</b>',
|
356
|
-
'quote': '<b>“</b>',
|
357
|
-
'orderedlist': '<b>1.</b>',
|
358
|
-
'unorderedlist': '<b>•</b>',
|
359
|
-
'pre': '<b>0101</b>',
|
360
|
-
'indent': '<b>→</b>',
|
361
|
-
'outdent': '<b>←</b>'
|
362
|
-
};
|
363
|
-
if (buttonLabelType === 'fontawesome') {
|
364
|
-
customButtonLabels = {
|
365
|
-
'bold': '<i class="fa fa-bold"></i>',
|
366
|
-
'italic': '<i class="fa fa-italic"></i>',
|
367
|
-
'underline': '<i class="fa fa-underline"></i>',
|
368
|
-
'superscript': '<i class="fa fa-superscript"></i>',
|
369
|
-
'subscript': '<i class="fa fa-subscript"></i>',
|
370
|
-
'anchor': '<i class="fa fa-link"></i>',
|
371
|
-
'image': '<i class="fa fa-picture-o"></i>',
|
372
|
-
'quote': '<i class="fa fa-quote-right"></i>',
|
373
|
-
'orderedlist': '<i class="fa fa-list-ol"></i>',
|
374
|
-
'unorderedlist': '<i class="fa fa-list-ul"></i>',
|
375
|
-
'pre': '<i class="fa fa-code fa-lg"></i>',
|
376
|
-
'indent': '<i class="fa fa-indent"></i>',
|
377
|
-
'outdent': '<i class="fa fa-outdent"></i>'
|
378
|
-
};
|
379
|
-
} else if (typeof buttonLabelType === 'object') {
|
380
|
-
customButtonLabels = buttonLabelType;
|
381
|
-
}
|
382
|
-
if (typeof customButtonLabels === 'object') {
|
383
|
-
for (attrname in customButtonLabels) {
|
384
|
-
if (customButtonLabels.hasOwnProperty(attrname)) {
|
385
|
-
buttonLabels[attrname] = customButtonLabels[attrname];
|
386
|
-
}
|
387
|
-
}
|
388
|
-
}
|
389
|
-
return buttonLabels;
|
390
|
-
},
|
391
|
-
|
392
|
-
initToolbar: function () {
|
393
|
-
if (this.toolbar) {
|
394
|
-
return this;
|
395
|
-
}
|
396
|
-
this.toolbar = this.createToolbar();
|
397
|
-
this.keepToolbarAlive = false;
|
398
|
-
this.anchorForm = this.toolbar.querySelector('.medium-editor-toolbar-form-anchor');
|
399
|
-
this.anchorInput = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-input');
|
400
|
-
this.anchorTarget = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-target-input');
|
401
|
-
this.anchorBtn = this.anchorForm.querySelector('input.medium-editor-toolbar-anchor-btn-input');
|
402
|
-
this.toolbarActions = this.toolbar.querySelector('.medium-editor-toolbar-actions');
|
403
|
-
this.anchorPreview = this.createAnchorPreview();
|
404
|
-
|
405
|
-
return this;
|
406
|
-
},
|
407
|
-
|
408
|
-
createToolbar: function () {
|
409
|
-
var toolbar = document.createElement('div');
|
410
|
-
toolbar.id = 'medium-editor-toolbar-' + this.id;
|
411
|
-
toolbar.className = 'medium-editor-toolbar';
|
412
|
-
toolbar.appendChild(this.toolbarButtons());
|
413
|
-
toolbar.appendChild(this.toolbarFormAnchor());
|
414
|
-
this.options.elementsContainer.appendChild(toolbar);
|
415
|
-
return toolbar;
|
416
|
-
},
|
417
|
-
|
418
|
-
//TODO: actionTemplate
|
419
|
-
toolbarButtons: function () {
|
420
|
-
var btns = this.options.buttons,
|
421
|
-
ul = document.createElement('ul'),
|
422
|
-
li,
|
423
|
-
i,
|
424
|
-
btn,
|
425
|
-
ext;
|
426
|
-
|
427
|
-
ul.id = 'medium-editor-toolbar-actions';
|
428
|
-
ul.className = 'medium-editor-toolbar-actions clearfix';
|
429
|
-
|
430
|
-
for (i = 0; i < btns.length; i += 1) {
|
431
|
-
if (this.options.extensions.hasOwnProperty(btns[i])) {
|
432
|
-
ext = this.options.extensions[btns[i]];
|
433
|
-
btn = ext.getButton !== undefined ? ext.getButton() : null;
|
434
|
-
} else {
|
435
|
-
btn = this.buttonTemplate(btns[i]);
|
436
|
-
}
|
437
|
-
|
438
|
-
if (btn) {
|
439
|
-
|
440
|
-
li = document.createElement('li');
|
441
|
-
if (isElement(btn)) {
|
442
|
-
li.appendChild(btn);
|
443
|
-
} else {
|
444
|
-
li.innerHTML = btn;
|
445
|
-
}
|
446
|
-
ul.appendChild(li);
|
447
|
-
}
|
448
|
-
}
|
449
|
-
|
450
|
-
return ul;
|
451
|
-
},
|
452
|
-
|
453
|
-
toolbarFormAnchor: function () {
|
454
|
-
var anchor = document.createElement('div'),
|
455
|
-
input = document.createElement('input'),
|
456
|
-
cancel = document.createElement('a'),
|
457
|
-
asset_button = document.createElement('a'),
|
458
|
-
target_wrap = document.createElement('div'),
|
459
|
-
target_label = document.createElement('label'),
|
460
|
-
target = document.createElement('input'),
|
461
|
-
btn_wrap = document.createElement('div'),
|
462
|
-
btn_label = document.createElement('label'),
|
463
|
-
btn = document.createElement('input'),
|
464
|
-
icon = document.createElement('i');
|
465
|
-
|
466
|
-
cancel.setAttribute('href', '#');
|
467
|
-
cancel.setAttribute('title', 'Cancel');
|
468
|
-
cancel.setAttribute('data-tooltip', 'true');
|
469
|
-
cancel.className = 'medium-editor-cancel';
|
470
|
-
|
471
|
-
asset_button.className = 'medium-editor-link-to-asset';
|
472
|
-
asset_button.setAttribute('href', '/tenon/item_assets/new?hide_upload=true');
|
473
|
-
asset_button.setAttribute('title', 'Link to an Asset');
|
474
|
-
asset_button.setAttribute('data-tooltip', 'true');
|
475
|
-
asset_button.setAttribute('data-modal-remote', 'true');
|
476
|
-
asset_button.setAttribute('data-modal-title', 'Link to Asset');
|
477
|
-
asset_button.setAttribute('data-modal-handler', 'Tenon.features.tenonContent.AssetLink');
|
478
|
-
|
479
|
-
target.className = 'medium-editor-toolbar-anchor-checkbox medium-editor-toolbar-anchor-target-input';
|
480
|
-
target.setAttribute('type', 'checkbox')
|
481
|
-
target.setAttribute('title', 'Open in New Window?')
|
482
|
-
target.setAttribute('data-tooltip', 'true');
|
483
|
-
target_label.className = 'medium-editor-toolbar-anchor-checkbox-label medium-editor-toolbar-anchor-target-label';
|
484
|
-
target_wrap.className = 'medium-editor-toolbar-anchor-checkbox-wrap medium-editor-toolbar-anchor-target';
|
485
|
-
target_wrap.insertBefore(target_label, target_wrap.firstChild);
|
486
|
-
target_wrap.insertBefore(target, target_wrap.firstChild);
|
487
|
-
|
488
|
-
btn.className = 'medium-editor-toolbar-anchor-checkbox medium-editor-toolbar-anchor-btn-input';
|
489
|
-
btn.setAttribute('type', 'checkbox')
|
490
|
-
btn.setAttribute('title', 'Style as a button?')
|
491
|
-
btn.setAttribute('data-tooltip', 'true');
|
492
|
-
btn_label.className = 'medium-editor-toolbar-anchor-checkbox-label medium-editor-toolbar-anchor-btn-label';
|
493
|
-
btn_wrap.className = 'medium-editor-toolbar-anchor-checkbox-wrap medium-editor-toolbar-anchor-btn';
|
494
|
-
btn_wrap.insertBefore(btn_label, btn_wrap.firstChild);
|
495
|
-
btn_wrap.insertBefore(btn, btn_wrap.firstChild);
|
496
|
-
|
497
|
-
input.className = 'medium-editor-toolbar-anchor-input';
|
498
|
-
input.setAttribute('type', 'text');
|
499
|
-
input.setAttribute('placeholder', this.options.anchorInputPlaceholder);
|
500
|
-
|
501
|
-
anchor.className = 'medium-editor-toolbar-form-anchor';
|
502
|
-
anchor.id = 'medium-editor-toolbar-form-anchor';
|
503
|
-
if (!this.isIE) { anchor.appendChild(asset_button); }
|
504
|
-
anchor.appendChild(input);
|
505
|
-
anchor.appendChild(btn_wrap);
|
506
|
-
anchor.appendChild(target_wrap);
|
507
|
-
anchor.appendChild(cancel);
|
508
|
-
|
509
|
-
return anchor;
|
510
|
-
},
|
511
|
-
|
512
|
-
bindSelect: function () {
|
513
|
-
var self = this,
|
514
|
-
timer = '',
|
515
|
-
i;
|
516
|
-
|
517
|
-
this.checkSelectionWrapper = function (e) {
|
518
|
-
|
519
|
-
// Do not close the toolbar when bluring the editable area and clicking into the anchor form
|
520
|
-
if (e && self.clickingIntoArchorForm(e)) {
|
521
|
-
return false;
|
522
|
-
}
|
523
|
-
|
524
|
-
clearTimeout(timer);
|
525
|
-
timer = setTimeout(function () {
|
526
|
-
self.checkSelection();
|
527
|
-
}, self.options.delay);
|
528
|
-
};
|
529
|
-
|
530
|
-
document.documentElement.addEventListener('mouseup', this.checkSelectionWrapper);
|
531
|
-
|
532
|
-
for (i = 0; i < this.elements.length; i += 1) {
|
533
|
-
this.elements[i].addEventListener('keyup', this.checkSelectionWrapper);
|
534
|
-
this.elements[i].addEventListener('blur', this.checkSelectionWrapper);
|
535
|
-
}
|
536
|
-
return this;
|
537
|
-
},
|
538
|
-
|
539
|
-
checkSelection: function () {
|
540
|
-
var newSelection,
|
541
|
-
selectionElement;
|
542
|
-
|
543
|
-
if (this.keepToolbarAlive !== true && !this.options.disableToolbar) {
|
544
|
-
newSelection = window.getSelection();
|
545
|
-
if (newSelection.toString().trim() === '' ||
|
546
|
-
(this.options.allowMultiParagraphSelection === false && this.hasMultiParagraphs())) {
|
547
|
-
this.hideToolbarActions();
|
548
|
-
} else {
|
549
|
-
selectionElement = this.getSelectionElement();
|
550
|
-
if (!selectionElement || selectionElement.getAttribute('data-disable-toolbar')) {
|
551
|
-
this.hideToolbarActions();
|
552
|
-
} else {
|
553
|
-
this.checkSelectionElement(newSelection, selectionElement);
|
554
|
-
}
|
555
|
-
}
|
556
|
-
}
|
557
|
-
return this;
|
558
|
-
},
|
559
|
-
|
560
|
-
clickingIntoArchorForm: function (e) {
|
561
|
-
var self = this;
|
562
|
-
if (e.type && e.type.toLowerCase() === 'blur' && e.relatedTarget && e.relatedTarget === self.anchorInput) {
|
563
|
-
return true;
|
564
|
-
}
|
565
|
-
return false;
|
566
|
-
},
|
567
|
-
|
568
|
-
hasMultiParagraphs: function () {
|
569
|
-
var selectionHtml = getSelectionHtml().replace(/<[\S]+><\/[\S]+>/gim, ''),
|
570
|
-
hasMultiParagraphs = selectionHtml.match(/<(p|h[0-6]|blockquote)>([\s\S]*?)<\/(p|h[0-6]|blockquote)>/g);
|
571
|
-
|
572
|
-
return (hasMultiParagraphs ? hasMultiParagraphs.length : 0);
|
573
|
-
},
|
574
|
-
|
575
|
-
checkSelectionElement: function (newSelection, selectionElement) {
|
576
|
-
var i;
|
577
|
-
this.selection = newSelection;
|
578
|
-
this.selectionRange = this.selection.getRangeAt(0);
|
579
|
-
for (i = 0; i < this.elements.length; i += 1) {
|
580
|
-
if (this.elements[i] === selectionElement) {
|
581
|
-
this.setToolbarButtonStates()
|
582
|
-
.setToolbarPosition()
|
583
|
-
.showToolbarActions();
|
584
|
-
return;
|
585
|
-
}
|
586
|
-
}
|
587
|
-
this.hideToolbarActions();
|
588
|
-
},
|
589
|
-
|
590
|
-
getSelectionElement: function () {
|
591
|
-
var selection = window.getSelection(),
|
592
|
-
range, current, parent,
|
593
|
-
result,
|
594
|
-
getMediumElement = function (e) {
|
595
|
-
var localParent = e;
|
596
|
-
try {
|
597
|
-
while (!localParent.getAttribute('data-medium-element')) {
|
598
|
-
localParent = localParent.parentNode;
|
599
|
-
}
|
600
|
-
} catch (errb) {
|
601
|
-
return false;
|
602
|
-
}
|
603
|
-
return localParent;
|
604
|
-
};
|
605
|
-
// First try on current node
|
606
|
-
try {
|
607
|
-
range = selection.getRangeAt(0);
|
608
|
-
current = range.commonAncestorContainer;
|
609
|
-
parent = current.parentNode;
|
610
|
-
|
611
|
-
if (current.getAttribute('data-medium-element')) {
|
612
|
-
result = current;
|
613
|
-
} else {
|
614
|
-
result = getMediumElement(parent);
|
615
|
-
}
|
616
|
-
// If not search in the parent nodes.
|
617
|
-
} catch (err) {
|
618
|
-
result = getMediumElement(parent);
|
619
|
-
}
|
620
|
-
return result;
|
621
|
-
},
|
622
|
-
|
623
|
-
setToolbarPosition: function () {
|
624
|
-
var buttonHeight = 50,
|
625
|
-
selection = window.getSelection(),
|
626
|
-
range = selection.getRangeAt(0),
|
627
|
-
boundary = range.getBoundingClientRect(),
|
628
|
-
defaultLeft = (this.options.diffLeft) - (this.toolbar.offsetWidth / 2),
|
629
|
-
middleBoundary = (boundary.left + boundary.right) / 2,
|
630
|
-
halfOffsetWidth = this.toolbar.offsetWidth / 2;
|
631
|
-
if (boundary.top < buttonHeight) {
|
632
|
-
this.toolbar.classList.add('medium-toolbar-arrow-over');
|
633
|
-
this.toolbar.classList.remove('medium-toolbar-arrow-under');
|
634
|
-
this.toolbar.style.top = buttonHeight + boundary.bottom - this.options.diffTop + window.pageYOffset - this.toolbar.offsetHeight + 'px';
|
635
|
-
} else {
|
636
|
-
this.toolbar.classList.add('medium-toolbar-arrow-under');
|
637
|
-
this.toolbar.classList.remove('medium-toolbar-arrow-over');
|
638
|
-
this.toolbar.style.top = boundary.top + this.options.diffTop + window.pageYOffset - this.toolbar.offsetHeight + 'px';
|
639
|
-
}
|
640
|
-
if (middleBoundary < halfOffsetWidth) {
|
641
|
-
this.toolbar.style.left = defaultLeft + halfOffsetWidth + 'px';
|
642
|
-
} else if ((window.innerWidth - middleBoundary) < halfOffsetWidth) {
|
643
|
-
this.toolbar.style.left = window.innerWidth + defaultLeft - halfOffsetWidth + 'px';
|
644
|
-
} else {
|
645
|
-
this.toolbar.style.left = defaultLeft + middleBoundary + 'px';
|
646
|
-
}
|
647
|
-
|
648
|
-
this.hideAnchorPreview();
|
649
|
-
|
650
|
-
return this;
|
651
|
-
},
|
652
|
-
|
653
|
-
setToolbarButtonStates: function () {
|
654
|
-
var buttons = this.toolbarActions.querySelectorAll('button'),
|
655
|
-
i;
|
656
|
-
for (i = 0; i < buttons.length; i += 1) {
|
657
|
-
buttons[i].classList.remove('medium-editor-button-active');
|
658
|
-
}
|
659
|
-
this.checkActiveButtons();
|
660
|
-
return this;
|
661
|
-
},
|
662
|
-
|
663
|
-
checkActiveButtons: function () {
|
664
|
-
var elements = Array.prototype.slice.call(this.elements),
|
665
|
-
parentNode = this.getSelectedParentElement();
|
666
|
-
while (parentNode.tagName !== undefined && this.parentElements.indexOf(parentNode.tagName.toLowerCase) === -1) {
|
667
|
-
this.activateButton(parentNode.tagName.toLowerCase());
|
668
|
-
this.callExtensions('checkState', parentNode);
|
669
|
-
|
670
|
-
// we can abort the search upwards if we leave the contentEditable element
|
671
|
-
if (elements.indexOf(parentNode) !== -1) {
|
672
|
-
break;
|
673
|
-
}
|
674
|
-
parentNode = parentNode.parentNode;
|
675
|
-
}
|
676
|
-
},
|
677
|
-
|
678
|
-
activateButton: function (tag) {
|
679
|
-
var el = this.toolbar.querySelector('[data-element="' + tag + '"]');
|
680
|
-
if (el !== null && el.className.indexOf('medium-editor-button-active') === -1) {
|
681
|
-
el.className += ' medium-editor-button-active';
|
682
|
-
}
|
683
|
-
},
|
684
|
-
|
685
|
-
bindButtons: function () {
|
686
|
-
var buttons = this.toolbar.querySelectorAll('button'),
|
687
|
-
i,
|
688
|
-
self = this,
|
689
|
-
triggerAction = function (e) {
|
690
|
-
e.preventDefault();
|
691
|
-
e.stopPropagation();
|
692
|
-
if (self.selection === undefined) {
|
693
|
-
self.checkSelection();
|
694
|
-
}
|
695
|
-
if (this.className.indexOf('medium-editor-button-active') > -1) {
|
696
|
-
this.classList.remove('medium-editor-button-active');
|
697
|
-
} else {
|
698
|
-
this.className += ' medium-editor-button-active';
|
699
|
-
}
|
700
|
-
if (this.hasAttribute('data-action')) {
|
701
|
-
self.execAction(this.getAttribute('data-action'), e);
|
702
|
-
}
|
703
|
-
};
|
704
|
-
for (i = 0; i < buttons.length; i += 1) {
|
705
|
-
buttons[i].addEventListener('click', triggerAction);
|
706
|
-
}
|
707
|
-
this.setFirstAndLastItems(buttons);
|
708
|
-
return this;
|
709
|
-
},
|
710
|
-
|
711
|
-
setFirstAndLastItems: function (buttons) {
|
712
|
-
if (buttons.length > 0) {
|
713
|
-
buttons[0].className += ' medium-editor-button-first';
|
714
|
-
buttons[buttons.length - 1].className += ' medium-editor-button-last';
|
715
|
-
}
|
716
|
-
return this;
|
717
|
-
},
|
718
|
-
|
719
|
-
execAction: function (action, e) {
|
720
|
-
if (action.indexOf('append-') > -1) {
|
721
|
-
this.execFormatBlock(action.replace('append-', ''));
|
722
|
-
this.setToolbarPosition();
|
723
|
-
// this.setToolbarButtonStates();
|
724
|
-
} else if (action === 'anchor') {
|
725
|
-
this.triggerAnchorAction(e);
|
726
|
-
} else if (action === 'image') {
|
727
|
-
document.execCommand('insertImage', false, window.getSelection());
|
728
|
-
} else {
|
729
|
-
document.execCommand(action, false, null);
|
730
|
-
this.setToolbarPosition();
|
731
|
-
}
|
732
|
-
this.triggerChange();
|
733
|
-
},
|
734
|
-
|
735
|
-
// http://stackoverflow.com/questions/15867542/range-object-get-selection-parent-node-chrome-vs-firefox
|
736
|
-
rangeSelectsSingleNode: function (range) {
|
737
|
-
var startNode = range.startContainer;
|
738
|
-
return startNode === range.endContainer &&
|
739
|
-
startNode.hasChildNodes() &&
|
740
|
-
range.endOffset === range.startOffset + 1;
|
741
|
-
},
|
742
|
-
|
743
|
-
getSelectedParentElement: function () {
|
744
|
-
var selectedParentElement = null,
|
745
|
-
range = this.selectionRange;
|
746
|
-
if (this.rangeSelectsSingleNode(range)) {
|
747
|
-
selectedParentElement = range.startContainer.childNodes[range.startOffset];
|
748
|
-
} else if (range.startContainer.nodeType === 3) {
|
749
|
-
selectedParentElement = range.startContainer.parentNode;
|
750
|
-
} else {
|
751
|
-
selectedParentElement = range.startContainer;
|
752
|
-
}
|
753
|
-
return selectedParentElement;
|
754
|
-
},
|
755
|
-
|
756
|
-
triggerAnchorAction: function () {
|
757
|
-
var selectedParentElement = this.getSelectedParentElement();
|
758
|
-
if (selectedParentElement.tagName &&
|
759
|
-
selectedParentElement.tagName.toLowerCase() === 'a') {
|
760
|
-
document.execCommand('unlink', false, null);
|
761
|
-
this.triggerChange();
|
762
|
-
} else {
|
763
|
-
if (this.anchorForm.style.display === 'block') {
|
764
|
-
this.showToolbarActions();
|
765
|
-
} else {
|
766
|
-
this.showAnchorForm();
|
767
|
-
}
|
768
|
-
}
|
769
|
-
return this;
|
770
|
-
},
|
771
|
-
|
772
|
-
execFormatBlock: function (el) {
|
773
|
-
var selectionData = this.getSelectionData(this.selection.anchorNode);
|
774
|
-
// FF handles blockquote differently on formatBlock
|
775
|
-
// allowing nesting, we need to use outdent
|
776
|
-
// https://developer.mozilla.org/en-US/docs/Rich-Text_Editing_in_Mozilla
|
777
|
-
if (el === 'blockquote' && selectionData.el &&
|
778
|
-
selectionData.el.parentNode.tagName.toLowerCase() === 'blockquote') {
|
779
|
-
return document.execCommand('outdent', false, null);
|
780
|
-
}
|
781
|
-
if (selectionData.tagName === el) {
|
782
|
-
el = 'p';
|
783
|
-
}
|
784
|
-
// When IE we need to add <> to heading elements and
|
785
|
-
// blockquote needs to be called as indent
|
786
|
-
// http://stackoverflow.com/questions/10741831/execcommand-formatblock-headings-in-ie
|
787
|
-
// http://stackoverflow.com/questions/1816223/rich-text-editor-with-blockquote-function/1821777#1821777
|
788
|
-
if (this.isIE) {
|
789
|
-
if (el === 'blockquote') {
|
790
|
-
return document.execCommand('indent', false, el);
|
791
|
-
}
|
792
|
-
el = '<' + el + '>';
|
793
|
-
}
|
794
|
-
return document.execCommand('formatBlock', false, el);
|
795
|
-
},
|
796
|
-
|
797
|
-
getSelectionData: function (el) {
|
798
|
-
var tagName;
|
799
|
-
|
800
|
-
if (el && el.tagName) {
|
801
|
-
tagName = el.tagName.toLowerCase();
|
802
|
-
}
|
803
|
-
|
804
|
-
while (el && this.parentElements.indexOf(tagName) === -1) {
|
805
|
-
el = el.parentNode;
|
806
|
-
if (el && el.tagName) {
|
807
|
-
tagName = el.tagName.toLowerCase();
|
808
|
-
}
|
809
|
-
}
|
810
|
-
|
811
|
-
this.triggerChange();
|
812
|
-
|
813
|
-
return {
|
814
|
-
el: el,
|
815
|
-
tagName: tagName
|
816
|
-
};
|
817
|
-
},
|
818
|
-
|
819
|
-
getFirstChild: function (el) {
|
820
|
-
var firstChild = el.firstChild;
|
821
|
-
while (firstChild !== null && firstChild.nodeType !== 1) {
|
822
|
-
firstChild = firstChild.nextSibling;
|
823
|
-
}
|
824
|
-
return firstChild;
|
825
|
-
},
|
826
|
-
|
827
|
-
hideToolbarActions: function () {
|
828
|
-
this.keepToolbarAlive = false;
|
829
|
-
if (this.toolbar !== undefined) {
|
830
|
-
this.toolbar.classList.remove('medium-editor-toolbar-active');
|
831
|
-
}
|
832
|
-
},
|
833
|
-
|
834
|
-
showToolbarActions: function () {
|
835
|
-
var self = this,
|
836
|
-
timer;
|
837
|
-
this.anchorForm.style.display = 'none';
|
838
|
-
this.toolbarActions.style.display = 'block';
|
839
|
-
this.keepToolbarAlive = false;
|
840
|
-
clearTimeout(timer);
|
841
|
-
timer = setTimeout(function () {
|
842
|
-
if (self.toolbar && !self.toolbar.classList.contains('medium-editor-toolbar-active')) {
|
843
|
-
self.toolbar.classList.add('medium-editor-toolbar-active');
|
844
|
-
}
|
845
|
-
}, 100);
|
846
|
-
},
|
847
|
-
|
848
|
-
showAnchorForm: function (link_value) {
|
849
|
-
this.toolbarActions.style.display = 'none';
|
850
|
-
this.savedSelection = saveSelection();
|
851
|
-
this.anchorForm.style.display = 'block';
|
852
|
-
this.keepToolbarAlive = true;
|
853
|
-
this.anchorInput.focus();
|
854
|
-
this.anchorInput.value = link_value || '';
|
855
|
-
},
|
856
|
-
|
857
|
-
bindAnchorForm: function () {
|
858
|
-
var linkCancel = this.anchorForm.querySelector('a.medium-editor-cancel'),
|
859
|
-
self = this;
|
860
|
-
|
861
|
-
this.anchorInput.addEventListener('keyup', function (e) {
|
862
|
-
if (e.keyCode === 13) {
|
863
|
-
e.preventDefault();
|
864
|
-
|
865
|
-
// set target for link and pass to createLink()
|
866
|
-
var target = "_self";
|
867
|
-
if (self.anchorTarget.checked) {
|
868
|
-
target = "_blank";
|
869
|
-
// reset target state to false:
|
870
|
-
self.anchorTarget.checked = false;
|
871
|
-
}
|
872
|
-
|
873
|
-
// set class for link and pass to createLink()
|
874
|
-
var btn = "";
|
875
|
-
if (self.anchorBtn.checked) {
|
876
|
-
btn = "btn";
|
877
|
-
// reset target state to false:
|
878
|
-
self.anchorBtn.checked = false;
|
879
|
-
}
|
880
|
-
|
881
|
-
self.createLink(this, target, btn);
|
882
|
-
}
|
883
|
-
});
|
884
|
-
this.anchorInput.addEventListener('click', function (e) {
|
885
|
-
// make sure not to hide form when cliking into the input
|
886
|
-
e.stopPropagation();
|
887
|
-
self.keepToolbarAlive = true;
|
888
|
-
});
|
889
|
-
this.anchorInput.addEventListener('blur', function () {
|
890
|
-
// self.keepToolbarAlive = false;
|
891
|
-
self.checkSelection();
|
892
|
-
});
|
893
|
-
|
894
|
-
linkCancel.addEventListener('click', function (e) {
|
895
|
-
e.preventDefault();
|
896
|
-
self.showToolbarActions();
|
897
|
-
restoreSelection(self.savedSelection);
|
898
|
-
});
|
899
|
-
return this;
|
900
|
-
},
|
901
|
-
|
902
|
-
|
903
|
-
hideAnchorPreview: function () {
|
904
|
-
this.anchorPreview.classList.remove('medium-editor-anchor-preview-active');
|
905
|
-
},
|
906
|
-
|
907
|
-
// TODO: break method
|
908
|
-
showAnchorPreview: function (anchorEl) {
|
909
|
-
if (this.anchorPreview.classList.contains('medium-editor-anchor-preview-active')) {
|
910
|
-
return true;
|
911
|
-
}
|
912
|
-
|
913
|
-
var self = this,
|
914
|
-
buttonHeight = 40,
|
915
|
-
boundary = anchorEl.getBoundingClientRect(),
|
916
|
-
middleBoundary = (boundary.left + boundary.right) / 2,
|
917
|
-
halfOffsetWidth,
|
918
|
-
defaultLeft,
|
919
|
-
timer;
|
920
|
-
|
921
|
-
self.anchorPreview.querySelector('i').textContent = anchorEl.href;
|
922
|
-
halfOffsetWidth = self.anchorPreview.offsetWidth / 2;
|
923
|
-
defaultLeft = self.options.diffLeft - halfOffsetWidth;
|
924
|
-
|
925
|
-
clearTimeout(timer);
|
926
|
-
timer = setTimeout(function () {
|
927
|
-
if (self.anchorPreview && !self.anchorPreview.classList.contains('medium-editor-anchor-preview-active')) {
|
928
|
-
self.anchorPreview.classList.add('medium-editor-anchor-preview-active');
|
929
|
-
}
|
930
|
-
}, 100);
|
931
|
-
|
932
|
-
self.observeAnchorPreview(anchorEl);
|
933
|
-
|
934
|
-
self.anchorPreview.classList.add('medium-toolbar-arrow-over');
|
935
|
-
self.anchorPreview.classList.remove('medium-toolbar-arrow-under');
|
936
|
-
self.anchorPreview.style.top = Math.round(buttonHeight + boundary.bottom - self.options.diffTop + window.pageYOffset - self.anchorPreview.offsetHeight) + 'px';
|
937
|
-
if (middleBoundary < halfOffsetWidth) {
|
938
|
-
self.anchorPreview.style.left = defaultLeft + halfOffsetWidth + 'px';
|
939
|
-
} else if ((window.innerWidth - middleBoundary) < halfOffsetWidth) {
|
940
|
-
self.anchorPreview.style.left = window.innerWidth + defaultLeft - halfOffsetWidth + 'px';
|
941
|
-
} else {
|
942
|
-
self.anchorPreview.style.left = defaultLeft + middleBoundary + 'px';
|
943
|
-
}
|
944
|
-
|
945
|
-
return this;
|
946
|
-
},
|
947
|
-
|
948
|
-
// TODO: break method
|
949
|
-
observeAnchorPreview: function (anchorEl) {
|
950
|
-
var self = this,
|
951
|
-
lastOver = (new Date()).getTime(),
|
952
|
-
over = true,
|
953
|
-
stamp = function () {
|
954
|
-
lastOver = (new Date()).getTime();
|
955
|
-
over = true;
|
956
|
-
},
|
957
|
-
unstamp = function (e) {
|
958
|
-
if (!e.relatedTarget || !/anchor-preview/.test(e.relatedTarget.className)) {
|
959
|
-
over = false;
|
960
|
-
}
|
961
|
-
},
|
962
|
-
interval_timer = setInterval(function () {
|
963
|
-
if (over) {
|
964
|
-
return true;
|
965
|
-
}
|
966
|
-
var durr = (new Date()).getTime() - lastOver;
|
967
|
-
if (durr > self.options.anchorPreviewHideDelay) {
|
968
|
-
// hide the preview 1/2 second after mouse leaves the link
|
969
|
-
self.hideAnchorPreview();
|
970
|
-
|
971
|
-
// cleanup
|
972
|
-
clearInterval(interval_timer);
|
973
|
-
self.anchorPreview.removeEventListener('mouseover', stamp);
|
974
|
-
self.anchorPreview.removeEventListener('mouseout', unstamp);
|
975
|
-
anchorEl.removeEventListener('mouseover', stamp);
|
976
|
-
anchorEl.removeEventListener('mouseout', unstamp);
|
977
|
-
|
978
|
-
}
|
979
|
-
}, 200);
|
980
|
-
|
981
|
-
self.anchorPreview.addEventListener('mouseover', stamp);
|
982
|
-
self.anchorPreview.addEventListener('mouseout', unstamp);
|
983
|
-
anchorEl.addEventListener('mouseover', stamp);
|
984
|
-
anchorEl.addEventListener('mouseout', unstamp);
|
985
|
-
},
|
986
|
-
|
987
|
-
createAnchorPreview: function () {
|
988
|
-
var self = this,
|
989
|
-
anchorPreview = document.createElement('div');
|
990
|
-
|
991
|
-
anchorPreview.id = 'medium-editor-anchor-preview-' + this.id;
|
992
|
-
anchorPreview.className = 'medium-editor-anchor-preview';
|
993
|
-
anchorPreview.innerHTML = this.anchorPreviewTemplate();
|
994
|
-
this.options.elementsContainer.appendChild(anchorPreview);
|
995
|
-
|
996
|
-
anchorPreview.addEventListener('click', function () {
|
997
|
-
self.anchorPreviewClickHandler();
|
998
|
-
});
|
999
|
-
|
1000
|
-
return anchorPreview;
|
1001
|
-
},
|
1002
|
-
|
1003
|
-
anchorPreviewTemplate: function () {
|
1004
|
-
return '<div class="medium-editor-toolbar-anchor-preview" id="medium-editor-toolbar-anchor-preview">' +
|
1005
|
-
' <i class="medium-editor-toolbar-anchor-preview-inner"></i>' +
|
1006
|
-
'</div>';
|
1007
|
-
},
|
1008
|
-
|
1009
|
-
anchorPreviewClickHandler: function (e) {
|
1010
|
-
if (this.activeAnchor) {
|
1011
|
-
|
1012
|
-
var self = this,
|
1013
|
-
range = document.createRange(),
|
1014
|
-
sel = window.getSelection();
|
1015
|
-
|
1016
|
-
range.selectNodeContents(self.activeAnchor);
|
1017
|
-
sel.removeAllRanges();
|
1018
|
-
sel.addRange(range);
|
1019
|
-
setTimeout(function () {
|
1020
|
-
if (self.activeAnchor) {
|
1021
|
-
self.showAnchorForm(self.activeAnchor.href);
|
1022
|
-
}
|
1023
|
-
self.keepToolbarAlive = false;
|
1024
|
-
}, 100 + self.options.delay);
|
1025
|
-
|
1026
|
-
}
|
1027
|
-
|
1028
|
-
this.hideAnchorPreview();
|
1029
|
-
},
|
1030
|
-
|
1031
|
-
editorAnchorObserver: function (e) {
|
1032
|
-
var self = this,
|
1033
|
-
overAnchor = true,
|
1034
|
-
leaveAnchor = function () {
|
1035
|
-
// mark the anchor as no longer hovered, and stop listening
|
1036
|
-
overAnchor = false;
|
1037
|
-
self.activeAnchor.removeEventListener('mouseout', leaveAnchor);
|
1038
|
-
};
|
1039
|
-
|
1040
|
-
if (e.target && e.target.tagName.toLowerCase() === 'a') {
|
1041
|
-
|
1042
|
-
// Detect empty href attributes
|
1043
|
-
// The browser will make href="" or href="#top"
|
1044
|
-
// into absolute urls when accessed as e.targed.href, so check the html
|
1045
|
-
if (!/href=["']\S+["']/.test(e.target.outerHTML) || /href=["']#\S+["']/.test(e.target.outerHTML)) {
|
1046
|
-
return true;
|
1047
|
-
}
|
1048
|
-
|
1049
|
-
// only show when hovering on anchors
|
1050
|
-
if (this.toolbar.classList.contains('medium-editor-toolbar-active')) {
|
1051
|
-
// only show when toolbar is not present
|
1052
|
-
return true;
|
1053
|
-
}
|
1054
|
-
this.activeAnchor = e.target;
|
1055
|
-
this.activeAnchor.addEventListener('mouseout', leaveAnchor);
|
1056
|
-
// show the anchor preview according to the configured delay
|
1057
|
-
// if the mouse has not left the anchor tag in that time
|
1058
|
-
setTimeout(function () {
|
1059
|
-
if (overAnchor) {
|
1060
|
-
self.showAnchorPreview(e.target);
|
1061
|
-
}
|
1062
|
-
}, self.options.delay);
|
1063
|
-
|
1064
|
-
|
1065
|
-
}
|
1066
|
-
},
|
1067
|
-
|
1068
|
-
bindAnchorPreview: function (index) {
|
1069
|
-
var i, self = this;
|
1070
|
-
this.editorAnchorObserverWrapper = function (e) {
|
1071
|
-
self.editorAnchorObserver(e);
|
1072
|
-
};
|
1073
|
-
for (i = 0; i < this.elements.length; i += 1) {
|
1074
|
-
this.elements[i].addEventListener('mouseover', this.editorAnchorObserverWrapper);
|
1075
|
-
}
|
1076
|
-
return this;
|
1077
|
-
},
|
1078
|
-
|
1079
|
-
checkLinkFormat: function (value) {
|
1080
|
-
var re = /^https?:\/\//;
|
1081
|
-
if (value.match(re)) {
|
1082
|
-
return value;
|
1083
|
-
}
|
1084
|
-
return "http://" + value;
|
1085
|
-
},
|
1086
|
-
|
1087
|
-
setTargetBlank: function (href) {
|
1088
|
-
var el = getSelectionStart(),
|
1089
|
-
i;
|
1090
|
-
if (el.tagName.toLowerCase() === 'a') {
|
1091
|
-
el.target = '_blank';
|
1092
|
-
} else {
|
1093
|
-
el = el.getElementsByTagName('a');
|
1094
|
-
for (i = 0; i < el.length; i += 1) {
|
1095
|
-
if ( el[i].getAttribute('href') === href) {
|
1096
|
-
el[i].target = '_blank';
|
1097
|
-
}
|
1098
|
-
}
|
1099
|
-
}
|
1100
|
-
},
|
1101
|
-
|
1102
|
-
setBtnClass: function (href) {
|
1103
|
-
var el = getSelectionStart(),
|
1104
|
-
i;
|
1105
|
-
if (el.tagName.toLowerCase() === 'a') {
|
1106
|
-
el.className = 'btn';
|
1107
|
-
} else {
|
1108
|
-
el = el.getElementsByTagName('a');
|
1109
|
-
for (i = 0; i < el.length; i += 1) {
|
1110
|
-
if ( el[i].getAttribute('href') === href) {
|
1111
|
-
el[i].className = 'btn';
|
1112
|
-
}
|
1113
|
-
}
|
1114
|
-
}
|
1115
|
-
console.log(el);
|
1116
|
-
},
|
1117
|
-
|
1118
|
-
createLink: function (input, target, btn) {
|
1119
|
-
restoreSelection(this.savedSelection);
|
1120
|
-
if (this.options.checkLinkFormat) {
|
1121
|
-
input.value = this.checkLinkFormat(input.value);
|
1122
|
-
}
|
1123
|
-
|
1124
|
-
document.execCommand('createLink', false, input.value);
|
1125
|
-
|
1126
|
-
if (target === "_blank") {
|
1127
|
-
this.setTargetBlank(input.value);
|
1128
|
-
}
|
1129
|
-
|
1130
|
-
if (btn === "btn") {
|
1131
|
-
this.setBtnClass(input.value);
|
1132
|
-
}
|
1133
|
-
|
1134
|
-
this.triggerChange();
|
1135
|
-
|
1136
|
-
this.checkSelection();
|
1137
|
-
this.showToolbarActions();
|
1138
|
-
input.value = '';
|
1139
|
-
},
|
1140
|
-
|
1141
|
-
bindWindowActions: function () {
|
1142
|
-
var timerResize,
|
1143
|
-
self = this;
|
1144
|
-
this.windowResizeHandler = function () {
|
1145
|
-
clearTimeout(timerResize);
|
1146
|
-
timerResize = setTimeout(function () {
|
1147
|
-
if (self.toolbar && self.toolbar.classList.contains('medium-editor-toolbar-active')) {
|
1148
|
-
self.setToolbarPosition();
|
1149
|
-
}
|
1150
|
-
}, 100);
|
1151
|
-
};
|
1152
|
-
window.addEventListener('resize', this.windowResizeHandler);
|
1153
|
-
return this;
|
1154
|
-
},
|
1155
|
-
|
1156
|
-
activate: function () {
|
1157
|
-
if (this.isActive) {
|
1158
|
-
return;
|
1159
|
-
}
|
1160
|
-
|
1161
|
-
this.setup();
|
1162
|
-
},
|
1163
|
-
|
1164
|
-
// TODO: break method
|
1165
|
-
deactivate: function () {
|
1166
|
-
var i;
|
1167
|
-
if (!this.isActive) {
|
1168
|
-
return;
|
1169
|
-
}
|
1170
|
-
this.isActive = false;
|
1171
|
-
|
1172
|
-
if (this.toolbar !== undefined) {
|
1173
|
-
this.options.elementsContainer.removeChild(this.anchorPreview);
|
1174
|
-
this.options.elementsContainer.removeChild(this.toolbar);
|
1175
|
-
delete this.toolbar;
|
1176
|
-
delete this.anchorPreview;
|
1177
|
-
}
|
1178
|
-
|
1179
|
-
document.documentElement.removeEventListener('mouseup', this.checkSelectionWrapper);
|
1180
|
-
window.removeEventListener('resize', this.windowResizeHandler);
|
1181
|
-
|
1182
|
-
for (i = 0; i < this.elements.length; i += 1) {
|
1183
|
-
this.elements[i].removeEventListener('mouseover', this.editorAnchorObserverWrapper);
|
1184
|
-
this.elements[i].removeEventListener('keyup', this.checkSelectionWrapper);
|
1185
|
-
this.elements[i].removeEventListener('blur', this.checkSelectionWrapper);
|
1186
|
-
this.elements[i].removeEventListener('paste', this.pasteWrapper);
|
1187
|
-
this.elements[i].removeAttribute('contentEditable');
|
1188
|
-
this.elements[i].removeAttribute('data-medium-element');
|
1189
|
-
}
|
1190
|
-
|
1191
|
-
},
|
1192
|
-
|
1193
|
-
htmlEntities: function (str) {
|
1194
|
-
// converts special characters (like <) into their escaped/encoded values (like <).
|
1195
|
-
// This allows you to show to display the string without the browser reading it as HTML.
|
1196
|
-
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
1197
|
-
},
|
1198
|
-
|
1199
|
-
bindPaste: function () {
|
1200
|
-
var i, self = this;
|
1201
|
-
this.pasteWrapper = function (e) {
|
1202
|
-
var paragraphs,
|
1203
|
-
html = '',
|
1204
|
-
p;
|
1205
|
-
|
1206
|
-
this.classList.remove('medium-editor-placeholder');
|
1207
|
-
if (!self.options.forcePlainText && !self.options.cleanPastedHTML) {
|
1208
|
-
return this;
|
1209
|
-
}
|
1210
|
-
|
1211
|
-
if (e.clipboardData && e.clipboardData.getData && !e.defaultPrevented) {
|
1212
|
-
e.preventDefault();
|
1213
|
-
|
1214
|
-
if (self.options.cleanPastedHTML && e.clipboardData.getData('text/html')) {
|
1215
|
-
return self.cleanPaste(e.clipboardData.getData('text/html'));
|
1216
|
-
}
|
1217
|
-
if (!(self.options.disableReturn || this.getAttribute('data-disable-return'))) {
|
1218
|
-
paragraphs = e.clipboardData.getData('text/plain').split(/[\r\n]/g);
|
1219
|
-
for (p = 0; p < paragraphs.length; p += 1) {
|
1220
|
-
if (paragraphs[p] !== '') {
|
1221
|
-
if (navigator.userAgent.match(/firefox/i) && p === 0) {
|
1222
|
-
html += self.htmlEntities(paragraphs[p]);
|
1223
|
-
} else {
|
1224
|
-
html += '<p>' + self.htmlEntities(paragraphs[p]) + '</p>';
|
1225
|
-
}
|
1226
|
-
}
|
1227
|
-
}
|
1228
|
-
document.execCommand('insertHTML', false, html);
|
1229
|
-
this.triggerChange();
|
1230
|
-
} else {
|
1231
|
-
document.execCommand('insertHTML', false, e.clipboardData.getData('text/plain'));
|
1232
|
-
this.triggerChange();
|
1233
|
-
}
|
1234
|
-
}
|
1235
|
-
};
|
1236
|
-
for (i = 0; i < this.elements.length; i += 1) {
|
1237
|
-
this.elements[i].addEventListener('paste', this.pasteWrapper);
|
1238
|
-
}
|
1239
|
-
|
1240
|
-
this.triggerChange();
|
1241
|
-
|
1242
|
-
return this;
|
1243
|
-
},
|
1244
|
-
|
1245
|
-
setPlaceholders: function () {
|
1246
|
-
var i,
|
1247
|
-
activatePlaceholder = function (el) {
|
1248
|
-
if (!(el.querySelector('img')) &&
|
1249
|
-
el.textContent.replace(/^\s+|\s+$/g, '') === '') {
|
1250
|
-
el.classList.add('medium-editor-placeholder');
|
1251
|
-
}
|
1252
|
-
},
|
1253
|
-
placeholderWrapper = function (e) {
|
1254
|
-
this.classList.remove('medium-editor-placeholder');
|
1255
|
-
if (e.type !== 'keypress') {
|
1256
|
-
activatePlaceholder(this);
|
1257
|
-
}
|
1258
|
-
};
|
1259
|
-
for (i = 0; i < this.elements.length; i += 1) {
|
1260
|
-
activatePlaceholder(this.elements[i]);
|
1261
|
-
this.elements[i].addEventListener('blur', placeholderWrapper);
|
1262
|
-
this.elements[i].addEventListener('keypress', placeholderWrapper);
|
1263
|
-
}
|
1264
|
-
return this;
|
1265
|
-
},
|
1266
|
-
|
1267
|
-
cleanPaste: function (text) {
|
1268
|
-
|
1269
|
-
/*jslint regexp: true*/
|
1270
|
-
/*
|
1271
|
-
jslint does not allow character negation, because the negation
|
1272
|
-
will not match any unicode characters. In the regexes in this
|
1273
|
-
block, negation is used specifically to match the end of an html
|
1274
|
-
tag, and in fact unicode characters *should* be allowed.
|
1275
|
-
*/
|
1276
|
-
var i, elList, workEl,
|
1277
|
-
el = this.getSelectionElement(),
|
1278
|
-
multiline = /<p|<br|<div/.test(text),
|
1279
|
-
replacements = [
|
1280
|
-
|
1281
|
-
// replace two bogus tags that begin pastes from google docs
|
1282
|
-
[new RegExp(/<[^>]*docs-internal-guid[^>]*>/gi), ""],
|
1283
|
-
[new RegExp(/<\/b>(<br[^>]*>)?$/gi), ""],
|
1284
|
-
|
1285
|
-
// un-html spaces and newlines inserted by OS X
|
1286
|
-
[new RegExp(/<span class="Apple-converted-space">\s+<\/span>/g), ' '],
|
1287
|
-
[new RegExp(/<br class="Apple-interchange-newline">/g), '<br>'],
|
1288
|
-
|
1289
|
-
// replace google docs italics+bold with a span to be replaced once the html is inserted
|
1290
|
-
[new RegExp(/<span[^>]*(font-style:italic;font-weight:bold|font-weight:bold;font-style:italic)[^>]*>/gi), '<span class="replace-with italic bold">'],
|
1291
|
-
|
1292
|
-
// replace google docs italics with a span to be replaced once the html is inserted
|
1293
|
-
[new RegExp(/<span[^>]*font-style:italic[^>]*>/gi), '<span class="replace-with italic">'],
|
1294
|
-
|
1295
|
-
//[replace google docs bolds with a span to be replaced once the html is inserted
|
1296
|
-
[new RegExp(/<span[^>]*font-weight:bold[^>]*>/gi), '<span class="replace-with bold">'],
|
1297
|
-
|
1298
|
-
// replace manually entered b/i/a tags with real ones
|
1299
|
-
[new RegExp(/<(\/?)(i|b|a)>/gi), '<$1$2>'],
|
1300
|
-
|
1301
|
-
// replace manually a tags with real ones, converting smart-quotes from google docs
|
1302
|
-
[new RegExp(/<a\s+href=("|”|“|“|”)([^&]+)("|”|“|“|”)>/gi), '<a href="$2">']
|
1303
|
-
|
1304
|
-
];
|
1305
|
-
/*jslint regexp: false*/
|
1306
|
-
|
1307
|
-
for (i = 0; i < replacements.length; i += 1) {
|
1308
|
-
text = text.replace(replacements[i][0], replacements[i][1]);
|
1309
|
-
}
|
1310
|
-
|
1311
|
-
if (multiline) {
|
1312
|
-
|
1313
|
-
// double br's aren't converted to p tags, but we want paragraphs.
|
1314
|
-
elList = text.split('<br><br>');
|
1315
|
-
|
1316
|
-
this.pasteHTML('<p>' + elList.join('</p><p>') + '</p>');
|
1317
|
-
document.execCommand('insertText', false, "\n");
|
1318
|
-
this.triggerChange();
|
1319
|
-
|
1320
|
-
// block element cleanup
|
1321
|
-
elList = el.querySelectorAll('p,div,br');
|
1322
|
-
for (i = 0; i < elList.length; i += 1) {
|
1323
|
-
|
1324
|
-
workEl = elList[i];
|
1325
|
-
|
1326
|
-
switch (workEl.tagName.toLowerCase()) {
|
1327
|
-
case 'p':
|
1328
|
-
case 'div':
|
1329
|
-
this.filterCommonBlocks(workEl);
|
1330
|
-
break;
|
1331
|
-
case 'br':
|
1332
|
-
this.filterLineBreak(workEl);
|
1333
|
-
break;
|
1334
|
-
}
|
1335
|
-
|
1336
|
-
}
|
1337
|
-
|
1338
|
-
|
1339
|
-
} else {
|
1340
|
-
|
1341
|
-
this.pasteHTML(text);
|
1342
|
-
|
1343
|
-
}
|
1344
|
-
|
1345
|
-
},
|
1346
|
-
|
1347
|
-
pasteHTML: function (html) {
|
1348
|
-
var elList, workEl, i, fragmentBody, pasteBlock = document.createDocumentFragment();
|
1349
|
-
|
1350
|
-
pasteBlock.appendChild(document.createElement('body'));
|
1351
|
-
|
1352
|
-
fragmentBody = pasteBlock.querySelector('body');
|
1353
|
-
fragmentBody.innerHTML = html;
|
1354
|
-
|
1355
|
-
this.cleanupSpans(fragmentBody);
|
1356
|
-
|
1357
|
-
elList = fragmentBody.querySelectorAll('*');
|
1358
|
-
for (i = 0; i < elList.length; i += 1) {
|
1359
|
-
|
1360
|
-
workEl = elList[i];
|
1361
|
-
|
1362
|
-
// delete ugly attributes
|
1363
|
-
workEl.removeAttribute('class');
|
1364
|
-
workEl.removeAttribute('style');
|
1365
|
-
workEl.removeAttribute('dir');
|
1366
|
-
|
1367
|
-
if (workEl.tagName.toLowerCase() === 'meta') {
|
1368
|
-
workEl.parentNode.removeChild(workEl);
|
1369
|
-
}
|
1370
|
-
|
1371
|
-
}
|
1372
|
-
document.execCommand('insertHTML', false, fragmentBody.innerHTML.replace(/ /g, ' '));
|
1373
|
-
this.triggerChange();
|
1374
|
-
},
|
1375
|
-
isCommonBlock: function (el) {
|
1376
|
-
return (el && (el.tagName.toLowerCase() === 'p' || el.tagName.toLowerCase() === 'div'));
|
1377
|
-
},
|
1378
|
-
filterCommonBlocks: function (el) {
|
1379
|
-
if (/^\s*$/.test(el.innerText)) {
|
1380
|
-
el.parentNode.removeChild(el);
|
1381
|
-
}
|
1382
|
-
},
|
1383
|
-
filterLineBreak: function (el) {
|
1384
|
-
if (this.isCommonBlock(el.previousElementSibling)) {
|
1385
|
-
|
1386
|
-
// remove stray br's following common block elements
|
1387
|
-
el.parentNode.removeChild(el);
|
1388
|
-
|
1389
|
-
} else if (this.isCommonBlock(el.parentNode) && (el.parentNode.firstChild === el || el.parentNode.lastChild === el)) {
|
1390
|
-
|
1391
|
-
// remove br's just inside open or close tags of a div/p
|
1392
|
-
el.parentNode.removeChild(el);
|
1393
|
-
|
1394
|
-
} else if (el.parentNode.childElementCount === 1) {
|
1395
|
-
|
1396
|
-
// and br's that are the only child of a div/p
|
1397
|
-
this.removeWithParent(el);
|
1398
|
-
|
1399
|
-
}
|
1400
|
-
|
1401
|
-
},
|
1402
|
-
|
1403
|
-
// remove an element, including its parent, if it is the only element within its parent
|
1404
|
-
removeWithParent: function (el) {
|
1405
|
-
if (el && el.parentNode) {
|
1406
|
-
if (el.parentNode.parentNode && el.parentNode.childElementCount === 1) {
|
1407
|
-
el.parentNode.parentNode.removeChild(el.parentNode);
|
1408
|
-
} else {
|
1409
|
-
el.parentNode.removeChild(el.parentNode);
|
1410
|
-
}
|
1411
|
-
}
|
1412
|
-
},
|
1413
|
-
|
1414
|
-
cleanupSpans: function (container_el) {
|
1415
|
-
|
1416
|
-
var i,
|
1417
|
-
el,
|
1418
|
-
new_el,
|
1419
|
-
spans = container_el.querySelectorAll('.replace-with');
|
1420
|
-
|
1421
|
-
for (i = 0; i < spans.length; i += 1) {
|
1422
|
-
|
1423
|
-
el = spans[i];
|
1424
|
-
new_el = document.createElement(el.classList.contains('bold') ? 'b' : 'i');
|
1425
|
-
|
1426
|
-
if (el.classList.contains('bold') && el.classList.contains('italic')) {
|
1427
|
-
|
1428
|
-
// add an i tag as well if this has both italics and bold
|
1429
|
-
new_el.innerHTML = '<i>' + el.innerHTML + '</i>';
|
1430
|
-
|
1431
|
-
} else {
|
1432
|
-
|
1433
|
-
new_el.innerHTML = el.innerHTML;
|
1434
|
-
|
1435
|
-
}
|
1436
|
-
el.parentNode.replaceChild(new_el, el);
|
1437
|
-
|
1438
|
-
}
|
1439
|
-
|
1440
|
-
spans = container_el.querySelectorAll('span');
|
1441
|
-
for (i = 0; i < spans.length; i += 1) {
|
1442
|
-
|
1443
|
-
el = spans[i];
|
1444
|
-
|
1445
|
-
// remove empty spans, replace others with their contents
|
1446
|
-
if (/^\s*$/.test()) {
|
1447
|
-
el.parentNode.removeChild(el);
|
1448
|
-
} else {
|
1449
|
-
el.parentNode.replaceChild(document.createTextNode(el.innerText), el);
|
1450
|
-
}
|
1451
|
-
|
1452
|
-
}
|
1453
|
-
|
1454
|
-
},
|
1455
|
-
|
1456
|
-
triggerChange: function () {
|
1457
|
-
// in IE all medium changes need to be triggered manually:
|
1458
|
-
// http://stackoverflow.com/a/23930764
|
1459
|
-
// Note: this will sometimes be triggered more than once per change
|
1460
|
-
jQuery(document).find('.editable-text').trigger('change');
|
1461
|
-
}
|
1462
|
-
|
1463
|
-
};
|
1464
|
-
|
1465
|
-
}(window, document));
|