Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use intersection observer to init Tinymce editors #2476

Merged
merged 7 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ namespace :alchemy do
yarn install && \
yarn link && \
cd spec/dummy && \
yarn link @alchemy_cms/admin && \
export RAILS_ENV=test && \
bin/rake db:create && \
bin/rake db:environment:set && \
bin/rake db:migrate:reset && \
bin/rails javascript:install:esbuild && \
bin/rails g alchemy:install --skip --skip-demo-files --auto-accept --skip-db-create && \
yarn link @alchemy_cms/admin && \
bin/rails javascript:build && \
cd -
BASH
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/alchemy/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
//= require alchemy/alchemy.uploader
//= require alchemy/alchemy.preview_window
//= require alchemy/alchemy.spinner
//= require alchemy/alchemy.tinymce
//= require alchemy/alchemy.tooltips
//= require alchemy/page_select
//= require alchemy/node_select
93 changes: 0 additions & 93 deletions app/assets/javascripts/alchemy/alchemy.tinymce.js.coffee

This file was deleted.

19 changes: 11 additions & 8 deletions app/models/alchemy/ingredients/richtext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,23 @@ def preview_text(max_length = 30)
stripped_body.to_s[0..max_length - 1]
end

# Returns css class names for the editor textarea.
def tinymce_class_name
"has_tinymce#{has_custom_tinymce_config? ? " #{element.name}_#{role}" : ""}"
def element_id
"tinymce_#{id}"
end

def has_tinymce?
true
end

# Returns true if there is a tinymce setting defined that contains settings.
def has_custom_tinymce_config?
custom_tinymce_config.is_a?(Hash)
end

def custom_tinymce_config
settings[:tinymce]
end

private

def strip_content
Expand All @@ -53,11 +61,6 @@ def sanitize_content
def sanitizer_settings
settings[:sanitizer] || {}
end

# Returns true if there is a tinymce setting defined that contains settings.
def has_custom_tinymce_config?
settings[:tinymce].is_a?(Hash)
end
end
end
end
10 changes: 0 additions & 10 deletions app/views/alchemy/admin/pages/_tinymce_custom_config.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/alchemy/admin/pages/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@
<% end %>

<% content_for :javascripts do %>
<% if Alchemy::Tinymce.custom_configs_present?(@page) %>
<%= render 'tinymce_custom_config' %>
<% end %>

<% content_for :javascript_includes do %>
<meta name="turbolinks-cache-control" content="no-cache">
Expand Down
13 changes: 11 additions & 2 deletions app/views/alchemy/ingredients/_richtext_editor.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
<%= ingredient_label(richtext_editor) %>
<div class="tinymce_container">
<%= f.text_area :value,
class: richtext_editor.tinymce_class_name,
id: "tinymce_#{richtext_editor.id}" %>
class: "has_tinymce",
id: richtext_editor.element_id %>
</div>
<% end %>
<% if richtext_editor.has_custom_tinymce_config? %>
<script type="text/javascript" charset="utf-8">
Alchemy.Tinymce.setCustomConfig("<%= richtext_editor.element_id %>", {
<% richtext_editor.custom_tinymce_config.each do |k, v| %>
<%= k %>: <%== v.to_json %>,
<% end %>
});
</script>
<% end %>
<% end %>
12 changes: 5 additions & 7 deletions app/views/layouts/alchemy/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
// Store regular expression for external link url matching.
Alchemy.link_url_regexp = <%= link_url_regexp.inspect %>;
// Holds the default Alchemy TinyMCE configuration
Alchemy.Tinymce = {
defaults: {
plugins: '<%= Alchemy::Tinymce.plugins.join(',') %>',
<% Alchemy::Tinymce.init.each do |k, v| %>
<%= k %>: <%== v.to_json %>,
<% end %>
}
Alchemy.TinymceDefaults = {
plugins: '<%= Alchemy::Tinymce.plugins.join(',') %>',
<% Alchemy::Tinymce.init.each do |k, v| %>
<%= k %>: <%== v.to_json %>,
<% end %>
};
</script>
<%= render 'alchemy/admin/partials/routes' %>
Expand Down
23 changes: 0 additions & 23 deletions lib/alchemy/tinymce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,6 @@ def init=(settings)
def init
@@init
end

def custom_configs_present?(page)
custom_config_ingredients(page).any?
end

def custom_config_ingredients(page)
ingredient_definitions_from_elements(page.descendent_element_definitions)
end

private

def ingredient_definitions_from_elements(definitions)
definitions.collect do |el|
next if el["ingredients"].blank?

ingredients = el["ingredients"].select do |c|
c["settings"] && c["settings"]["tinymce"].is_a?(Hash)
end
next if ingredients.blank?

ingredients.map { |c| c.merge("element" => el["name"]) }
end.flatten.compact
end
end
end
end
2 changes: 2 additions & 0 deletions package/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ImageLoader from "./src/image_loader"
import ImageCropper from "./src/image_cropper"
import Datepicker from "./src/datepicker"
import Sitemap from "./src/sitemap"
import Tinymce from "./src/tinymce"
import PagePublicationFields from "./src/page_publication_fields.js"

// Global Alchemy object
Expand All @@ -28,5 +29,6 @@ Object.assign(Alchemy, {
IngredientAnchorLink,
Datepicker,
Sitemap,
Tinymce,
PagePublicationFields
})
6 changes: 3 additions & 3 deletions package/dist/admin.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package/dist/admin.js.map

Large diffs are not rendered by default.

Loading