Skip to content

Commit

Permalink
Load jquery via importmap
Browse files Browse the repository at this point in the history
We still need it for select2 but we want to update and install it via
node modules.

In order for this to work we need to use module script tags. Since
jQuery is loaded via importmap and a JS module (`alchemy_admin.js`)
it execution is deferred.
  • Loading branch information
tvdeyen committed Sep 23, 2024
1 parent 161ae81 commit 770a0d0
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 11 deletions.
1 change: 0 additions & 1 deletion alchemy_cms.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency "dragonfly_svg", ["~> 0.0.4"]
gem.add_runtime_dependency "gutentag", ["~> 2.2", ">= 2.2.1"]
gem.add_runtime_dependency "importmap-rails", ["~> 1.2", ">= 1.2.1"]
gem.add_runtime_dependency "jquery-rails", ["~> 4.0", ">= 4.0.4"]
gem.add_runtime_dependency "kaminari", ["~> 1.1"]
gem.add_runtime_dependency "originator", ["~> 3.1"]
gem.add_runtime_dependency "ransack", [">= 1.8", "< 5.0"]
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/alchemy/admin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Alchemy CMS Sprockets Manifest
// ------------------------------
//= require jquery3
//= require alchemy/alchemy.dialog
//= require alchemy/alchemy.image_overlay
2 changes: 2 additions & 0 deletions app/javascript/alchemy_admin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// We still use jQuery in some places (ie. select2)
import "handlebars"
import "jquery"
import "@ungap/custom-elements"
import "@hotwired/turbo-rails"
import "select2"
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/dashboard/info.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<%= Alchemy.t 'Update status unavailable' %>
</span>
</p>
<script type="text/javascript">
<script type="module">
var el = $('#update_check');
var spinner = new Alchemy.Spinner('small')
spinner.spin(el[0])
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pages/_page_layout_filter.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</label>
</div>

<script type="text/javascript">
<script type="module">
$(function() {
$("#page_layout").on("change", function(e) {
var url = "<%= alchemy.admin_pages_path(search_filter_params.except(:page_layout, :page).merge(view: "list")) %>";
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pages/_sitemap.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{{/each}}
</script>

<script type="text/javascript">
<script type="module">
$(function() {
Alchemy.currentSitemap = new Alchemy.Sitemap({
url: '<%= alchemy.tree_admin_pages_path %>',
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pages/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<% end %>


<script type="text/javascript">
<script type="module">
$(function() {
Alchemy.PagePublicationFields();
});
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pages/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<% end %>
<% content_for :javascripts do %>
<script type="text/javascript" charset="utf-8">
<script type="module">
$(document).one('turbo:load', function() {
$('#unlock_page_form, #publish_page_form').on('submit', function(event) {
var not_dirty = Alchemy.checkPageDirtyness(this);
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pictures/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
</div>

<% content_for :javascripts do %>
<script type="text/javascript" charset="utf-8">
<script type="module">
$(function() {
Alchemy.pictureSelector();
$('#picture_archive').on("click", ".thumbnail_background", function(event) {
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/resources/_filter_bar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= render partial: "filter", collection: resource_filters_for_select %>
</div>

<script type="text/javascript">
<script type="module">
$(function() {
$('select', '#filter_bar').on('change', function(e) {
var $this = $(this);
Expand Down
1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pin "cropperjs", to: "cropperjs.min.js", preload: true
pin "flatpickr", to: "flatpickr.min.js", preload: true # @4.6.13
pin "handlebars", to: "handlebars.min.js", preload: true # @4.7.8
pin "jquery", to: "jquery.min.js", preload: true
pin "keymaster", to: "keymaster.min.js", preload: true
pin "select2", to: "select2.min.js", preload: true
pin "sortablejs", to: "sortable.min.js", preload: true # @1.15.1
Expand Down
1 change: 0 additions & 1 deletion lib/alchemy_cms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
require "dragonfly"
require "gutentag"
require "importmap-rails"
require "jquery-rails"
require "kaminari"
require "non_stupid_digest_assets"
require "ransack"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"cropperjs": "^1.6.2",
"flatpickr": "^4.6.13",
"handlebars": "^4.7.8",
"jquery": "^3.7.1",
"keymaster": "^1.6.2",
"select2": "github:select2/select2#3.5.4",
"sortablejs": "^1.15.2",
Expand All @@ -35,7 +36,6 @@
"eslint": "^9.8.0",
"jest": "^29.6.4",
"jest-environment-jsdom": "^29.6.4",
"jquery": "^3.7.1",
"jsdom-testing-mocks": "^1.13.0",
"prettier": "^3.3.3",
"rollup": "^4.18.1",
Expand Down
7 changes: 7 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export default [
},
context: "window"
},
{
input: "node_modules/jquery/dist/jquery.min.js",
output: {
file: "vendor/javascript/jquery.min.js"
},
context: "window"
},
{
input: "node_modules/keymaster/keymaster.js",
output: {
Expand Down
2 changes: 2 additions & 0 deletions vendor/javascript/jquery.min.js

Large diffs are not rendered by default.

0 comments on commit 770a0d0

Please sign in to comment.