Skip to content

Commit

Permalink
Move to global jQuery for importmap
Browse files Browse the repository at this point in the history
Moves jQuery to an include via the layout. Imports in entry.js are
resolved first, regardless of logical order, so the recent changes to
include things like Blacklight Gallery via importmap won't get the
global jQuery being defined in entry.js.
  • Loading branch information
taylor-steve committed Jan 16, 2025
1 parent a2f7499 commit 187b003
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ GEM
rails (>= 6.1, < 9)
view_component (>= 2.74, < 4)
zeitwerk
blacklight-gallery (4.8.1)
blacklight-gallery (4.8.3)
blacklight (>= 7.17, < 9)
rails (>= 6.1, < 9)
blacklight-hierarchy (6.4.0)
Expand Down Expand Up @@ -211,7 +211,7 @@ GEM
mini_mime (>= 0.1.3)
ssrf_filter (~> 1.0)
clipboard-rails (1.7.1)
concurrent-ruby (1.3.4)
concurrent-ruby (1.3.5)
config (5.5.2)
deep_merge (~> 1.2, >= 1.2.1)
ostruct
Expand Down Expand Up @@ -581,7 +581,7 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rdoc (6.10.0)
rdoc (6.11.0)
psych (>= 4.0.0)
recaptcha (5.18.0)
redcarpet (3.6.0)
Expand Down
4 changes: 1 addition & 3 deletions app/javascript/entry.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// This is the entrypoint for the importmap build.
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
import jQuery from 'jquery'
window.jQuery = jQuery
window.$ = jQuery

import "@hotwired/turbo-rails"

Expand All @@ -17,6 +14,7 @@ window.Blacklight = Blacklight

import { I18n } from 'i18n-js'
export const i18n = new I18n()
window.i18n = i18n

import 'transform_result'
import 'blacklight-hierarchy'
1 change: 1 addition & 0 deletions app/views/layouts/spotlight/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<%= description %>
<%= twitter_card %>
<%= opengraph %>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<%= javascript_importmap_tags 'entry' %>
<%= javascript_include_tag "application", defer: true %>
<%= javascript_tag "window.addEventListener('load', () => window.sirTrevorIcon = '#{asset_path('spotlight/blocks/sir-trevor-icons.svg')}')" %>
Expand Down
2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
pin_all_from "app/javascript/controllers", under: "controllers"
pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.6.3/dist/jquery.js"
pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.7.1/dist/jquery.js"
pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@4.6.2/dist/js/bootstrap.js"
pin "popper.js", to: "https://ga.jspm.io/npm:popper.js@1.16.1/dist/umd/popper.js"
pin "i18n-js", to: "https://ga.jspm.io/npm:i18n-js@4.2.3/dist/import/index.js"
Expand Down
3 changes: 3 additions & 0 deletions vendor/javascript/blacklight-hierarchy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 187b003

Please sign in to comment.