blacklight 9.2.1 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.github/matrix.json +4 -4
  3. data/.github/workflows/build.yml +3 -0
  4. data/.github/workflows/lint.yml +17 -2
  5. data/.github/workflows/main.yml +3 -0
  6. data/.github/workflows/release_7_x_scheduled.yml +3 -0
  7. data/.github/workflows/release_8_x_scheduled.yml +3 -0
  8. data/.github/workflows/test.yml +3 -2
  9. data/.gitignore +0 -1
  10. data/.prettierignore +5 -0
  11. data/.prettierrc.json +4 -0
  12. data/.rubocop.yml +4 -0
  13. data/.rubocop_todo.yml +0 -143
  14. data/VERSION +1 -1
  15. data/app/assets/builds/blacklight.css +39 -9
  16. data/app/assets/javascripts/blacklight/blacklight.esm.js +207 -125
  17. data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
  18. data/app/assets/javascripts/blacklight/blacklight.js +207 -125
  19. data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
  20. data/app/assets/stylesheets/blacklight/_search_results.scss +24 -0
  21. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +18 -3
  22. data/app/components/blacklight/constraints_component.rb +2 -1
  23. data/app/components/blacklight/facet_field_component.rb +1 -1
  24. data/app/components/blacklight/open_graph_metadata_component.rb +33 -0
  25. data/app/components/blacklight/search/sidebar_component.html.erb +2 -2
  26. data/app/components/blacklight/search/sidebar_component.rb +3 -2
  27. data/app/controllers/concerns/blacklight/catalog.rb +3 -5
  28. data/app/controllers/concerns/blacklight/controller.rb +2 -6
  29. data/app/controllers/concerns/blacklight/search_context.rb +2 -7
  30. data/app/controllers/concerns/blacklight/token_based_user.rb +2 -6
  31. data/app/helpers/blacklight/catalog_helper_behavior.rb +9 -9
  32. data/app/helpers/blacklight/url_helper_behavior.rb +2 -7
  33. data/app/javascript/blacklight-frontend/bookmark_toggle.js +10 -8
  34. data/app/javascript/blacklight-frontend/checkbox_submit.js +42 -33
  35. data/app/javascript/blacklight-frontend/color_theme_switcher.js +47 -16
  36. data/app/javascript/blacklight-frontend/core.js +18 -19
  37. data/app/javascript/blacklight-frontend/debounce.js +7 -5
  38. data/app/javascript/blacklight-frontend/facet_suggest.js +27 -25
  39. data/app/javascript/blacklight-frontend/index.js +1 -1
  40. data/app/javascript/blacklight-frontend/modal.js +69 -52
  41. data/app/javascript/blacklight-frontend/search_context.js +36 -17
  42. data/app/models/blacklight/facet_paginator.rb +1 -3
  43. data/app/presenters/blacklight/document_presenter.rb +10 -1
  44. data/app/presenters/blacklight/facet_grouped_item_presenter.rb +1 -3
  45. data/app/presenters/blacklight/facet_item_pivot_presenter.rb +0 -8
  46. data/app/presenters/blacklight/json_presenter.rb +1 -3
  47. data/app/presenters/blacklight/open_graph_presenter.rb +34 -0
  48. data/app/presenters/blacklight/thumbnail_presenter.rb +24 -1
  49. data/app/services/blacklight/field_retriever.rb +1 -3
  50. data/app/services/blacklight/search_service.rb +1 -1
  51. data/app/views/catalog/_document.atom.builder +3 -5
  52. data/app/views/catalog/_show_main_content.html.erb +1 -0
  53. data/app/views/catalog/index.atom.builder +8 -4
  54. data/app/views/layouts/blacklight/base.html.erb +7 -1
  55. data/config/i18n-tasks.yml +1 -1
  56. data/config/locales/blacklight.ja.yml +256 -0
  57. data/lib/blacklight/configuration/context.rb +1 -1
  58. data/lib/blacklight/configuration/fields.rb +3 -9
  59. data/lib/blacklight/configuration/view_config.rb +16 -0
  60. data/lib/blacklight/configuration.rb +6 -2
  61. data/lib/blacklight/engine.rb +2 -4
  62. data/lib/blacklight/search_builder.rb +4 -4
  63. data/lib/blacklight/search_state/filter_field.rb +0 -1
  64. data/lib/blacklight/search_state.rb +2 -6
  65. data/lib/blacklight/solr/facet_paginator.rb +1 -1
  66. data/lib/blacklight/solr/repository.rb +1 -3
  67. data/lib/blacklight/solr/response/facets.rb +11 -9
  68. data/lib/blacklight/solr/response/spelling.rb +51 -47
  69. data/lib/blacklight/solr/search_builder_behavior.rb +14 -15
  70. data/lib/blacklight.rb +3 -9
  71. data/lib/generators/blacklight/assets/importmap_generator.rb +3 -3
  72. data/lib/generators/blacklight/assets_generator.rb +1 -1
  73. data/lib/railties/blacklight.rake +3 -5
  74. data/package-lock.json +1054 -0
  75. data/package.json +7 -4
  76. data/rollup.config.js +5 -7
  77. data/spec/components/blacklight/constraints_component_spec.rb +23 -1
  78. data/spec/components/blacklight/document/page_header_component_spec.rb +4 -4
  79. data/spec/components/blacklight/document_component_spec.rb +16 -3
  80. data/spec/components/blacklight/metadata_field_component_spec.rb +2 -2
  81. data/spec/components/blacklight/response/spellcheck_component_spec.rb +2 -2
  82. data/spec/components/blacklight/search_bar_component_spec.rb +1 -1
  83. data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +1 -1
  84. data/spec/components/blacklight/system/dropdown_component_spec.rb +1 -2
  85. data/spec/controllers/bookmarks_controller_spec.rb +3 -9
  86. data/spec/controllers/catalog_controller_spec.rb +56 -26
  87. data/spec/features/dark_mode_spec.rb +30 -0
  88. data/spec/features/did_you_mean_spec.rb +1 -1
  89. data/spec/features/facet_missing_spec.rb +3 -3
  90. data/spec/features/modal_spec.rb +2 -2
  91. data/spec/features/open_graph_spec.rb +43 -0
  92. data/spec/features/search_context_spec.rb +1 -1
  93. data/spec/fixtures/sample_solr_documents.yml +6 -0
  94. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +11 -8
  95. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +1 -1
  96. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +5 -5
  97. data/spec/helpers/blacklight_helper_spec.rb +6 -4
  98. data/spec/helpers/catalog_helper_spec.rb +34 -8
  99. data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +2 -2
  100. data/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb +2 -2
  101. data/spec/lib/blacklight/search_state/filter_field_spec.rb +1 -1
  102. data/spec/lib/blacklight/search_state/pivot_filter_field_spec.rb +1 -1
  103. data/spec/lib/blacklight/search_state_spec.rb +14 -19
  104. data/spec/lib/blacklight_spec.rb +5 -5
  105. data/spec/models/blacklight/configuration_spec.rb +1 -1
  106. data/spec/models/blacklight/document/cache_key_spec.rb +32 -12
  107. data/spec/models/blacklight/facet_paginator_spec.rb +5 -5
  108. data/spec/models/blacklight/icon_spec.rb +3 -3
  109. data/spec/models/blacklight/search_builder_spec.rb +21 -16
  110. data/spec/models/blacklight/solr/default_filter_query_builder_spec.rb +1 -1
  111. data/spec/models/blacklight/solr/document_spec.rb +8 -8
  112. data/spec/models/blacklight/solr/response/facets_spec.rb +5 -5
  113. data/spec/models/blacklight/solr/response/group_response_spec.rb +1 -1
  114. data/spec/models/blacklight/solr/response/group_spec.rb +1 -1
  115. data/spec/models/blacklight/solr/response_spec.rb +18 -3
  116. data/spec/models/blacklight/solr/search_builder_behavior_spec.rb +46 -7
  117. data/spec/models/blacklight/suggest_search_spec.rb +1 -1
  118. data/spec/models/record_mailer_spec.rb +2 -2
  119. data/spec/models/search_spec.rb +7 -7
  120. data/spec/presenters/blacklight/document_presenter_spec.rb +19 -6
  121. data/spec/presenters/blacklight/facet_field_presenter_spec.rb +4 -4
  122. data/spec/presenters/blacklight/field_presenter_spec.rb +12 -9
  123. data/spec/presenters/blacklight/open_graph_presenter_spec.rb +56 -0
  124. data/spec/presenters/blacklight/rendering/pipeline_spec.rb +3 -3
  125. data/spec/presenters/blacklight/thumbnail_presenter_spec.rb +129 -13
  126. data/spec/routing/catalog_routing_spec.rb +1 -1
  127. data/spec/services/blacklight/field_retriever_spec.rb +1 -1
  128. data/spec/services/blacklight/search_service_spec.rb +8 -8
  129. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -3
  130. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -2
  131. data/spec/views/catalog/index.atom.builder_spec.rb +16 -20
  132. data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -1
  133. metadata +12 -2
@@ -6,53 +6,59 @@
6
6
  being set to "put" or "delete" -- that's the Rails method to pretend
7
7
  to be doing a certain HTTP verb. So same URL, PUT to add, DELETE
8
8
  to remove. This plugin assumes that.
9
- Plus, the form this is applied to should provide a data-doc-id
10
- attribute (HTML5-style doc-*) that contains the id/primary key
11
- of the object in question -- used by plugin for a unique value for
12
- DOM id's.
13
9
  Uses HTML for a checkbox compatible with Bootstrap.
14
- new CheckboxSubmit(document.querySelector('form.something')).render()
10
+ new CheckboxSubmit(document.querySelector('form.something')).clicked()
15
11
  */
16
12
  export default class CheckboxSubmit {
17
13
  constructor(form) {
18
14
  this.form = form
19
15
  }
20
16
 
21
- clicked(evt) {
17
+ clicked() {
22
18
  this.spanTarget.innerHTML = this.form.getAttribute('data-inprogress')
23
- this.labelTarget.setAttribute('disabled', 'disabled');
24
- this.checkboxTarget.setAttribute('disabled', 'disabled');
19
+ this.labelTarget.setAttribute('disabled', 'disabled')
20
+ this.checkboxTarget.setAttribute('disabled', 'disabled')
25
21
  fetch(this.formTarget.getAttribute('action'), {
26
22
  body: new FormData(this.formTarget),
27
23
  method: this.formTarget.getAttribute('method').toUpperCase(),
28
24
  headers: {
29
- 'Accept': 'application/json',
25
+ Accept: 'application/json',
30
26
  'X-Requested-With': 'XMLHttpRequest',
31
- 'X-CSRF-Token': document.querySelector('meta[name=csrf-token]')?.content
32
- }
33
- }).then((response) => {
34
- if (response.ok) return response.json();
35
- return Promise.reject('response was not ok')
36
- }).then((json) => {
37
- this.labelTarget.removeAttribute('disabled')
38
- this.checkboxTarget.removeAttribute('disabled')
39
- // For accessibility return keyboard focus
40
- // back to the checkbox after form submission
41
- this.checkboxTarget.focus()
42
- this.updateStateFor(!this.checked)
43
- this.bookmarksCounter().forEach(counter => {
44
- counter.innerHTML = json.bookmarks.count;
45
- });
46
-
47
- var e = new CustomEvent('bookmark.blacklight', { detail: { checked: this.checked }, bubbles: true });
48
- this.formTarget.dispatchEvent(e)
49
- }).catch((error) => {
50
- this.handleError(error)
27
+ 'X-CSRF-Token': document.querySelector('meta[name=csrf-token]')
28
+ ?.content,
29
+ },
51
30
  })
31
+ .then((response) => {
32
+ if (response.ok) return response.json()
33
+ return Promise.reject('response was not ok')
34
+ })
35
+ .then((json) => {
36
+ this.labelTarget.removeAttribute('disabled')
37
+ this.checkboxTarget.removeAttribute('disabled')
38
+ // For accessibility return keyboard focus
39
+ // back to the checkbox after form submission
40
+ this.checkboxTarget.focus()
41
+ this.updateStateFor(!this.checked)
42
+ this.bookmarksCounter().forEach((counter) => {
43
+ counter.innerHTML = json.bookmarks.count
44
+ })
45
+
46
+ var e = new CustomEvent('bookmark.blacklight', {
47
+ detail: { checked: this.checked },
48
+ bubbles: true,
49
+ })
50
+ this.formTarget.dispatchEvent(e)
51
+ })
52
+ .catch((error) => {
53
+ this.handleError(error)
54
+ })
52
55
  }
53
56
 
54
57
  get checked() {
55
- return (this.form.querySelectorAll('input[name=_method][value=delete]').length != 0)
58
+ return (
59
+ this.form.querySelectorAll('input[name=_method][value=delete]').length !=
60
+ 0
61
+ )
56
62
  }
57
63
 
58
64
  get formTarget() {
@@ -76,12 +82,15 @@ export default class CheckboxSubmit {
76
82
  }
77
83
 
78
84
  handleError() {
79
- alert("Unable to save the bookmark at this time.")
85
+ alert('Unable to save the bookmark at this time.')
80
86
  }
81
87
 
82
88
  updateStateFor(state) {
83
- if (state) { this.checkboxTarget.setAttribute('checked', state) }
84
- else { this.checkboxTarget.removeAttribute('checked') }
89
+ if (state) {
90
+ this.checkboxTarget.setAttribute('checked', state)
91
+ } else {
92
+ this.checkboxTarget.removeAttribute('checked')
93
+ }
85
94
 
86
95
  if (state) {
87
96
  this.labelTarget.classList.add('checked')
@@ -8,20 +8,43 @@ import Core from 'blacklight-frontend/core'
8
8
  const ColorThemeSwitcher = (() => {
9
9
  'use strict'
10
10
 
11
- const getStoredTheme = () => localStorage.getItem('theme')
12
- const setStoredTheme = theme => localStorage.setItem('theme', theme)
11
+ // Accessing localStorage can throw (e.g. NS_ERROR_FAILURE in Firefox when the
12
+ // profile's storage is corrupt, or SecurityError when storage is disabled),
13
+ // so treat any failure as "no stored theme" rather than breaking page load.
14
+ const getStoredTheme = () => {
15
+ try {
16
+ return localStorage.getItem('theme')
17
+ } catch {
18
+ return null
19
+ }
20
+ }
21
+
22
+ const setStoredTheme = (theme) => {
23
+ try {
24
+ localStorage.setItem('theme', theme)
25
+ } catch {
26
+ // Storage is unavailable; the theme still applies for this page view.
27
+ }
28
+ }
13
29
 
14
30
  const getPreferredTheme = () => {
15
31
  const storedTheme = getStoredTheme()
16
32
  if (storedTheme) {
17
33
  return storedTheme
18
34
  }
19
- return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
35
+ return window.matchMedia('(prefers-color-scheme: dark)').matches
36
+ ? 'dark'
37
+ : 'light'
20
38
  }
21
39
 
22
- const setTheme = theme => {
40
+ const setTheme = (theme) => {
23
41
  if (theme === 'auto') {
24
- document.documentElement.setAttribute('data-bs-theme', window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
42
+ document.documentElement.setAttribute(
43
+ 'data-bs-theme',
44
+ window.matchMedia('(prefers-color-scheme: dark)').matches
45
+ ? 'dark'
46
+ : 'light',
47
+ )
25
48
  } else {
26
49
  document.documentElement.setAttribute('data-bs-theme', theme)
27
50
  }
@@ -32,7 +55,7 @@ const ColorThemeSwitcher = (() => {
32
55
  if (!themeSwitcher) return
33
56
 
34
57
  // Reset all dropdown items
35
- document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
58
+ document.querySelectorAll('[data-bs-theme-value]').forEach((element) => {
36
59
  element.classList.remove('active')
37
60
  element.setAttribute('aria-pressed', 'false')
38
61
  const check = element.querySelector('.bl-theme-check')
@@ -40,7 +63,9 @@ const ColorThemeSwitcher = (() => {
40
63
  })
41
64
 
42
65
  // Activate the selected item
43
- const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
66
+ const btnToActive = document.querySelector(
67
+ `[data-bs-theme-value="${theme}"]`,
68
+ )
44
69
  if (btnToActive) {
45
70
  btnToActive.classList.add('active')
46
71
  btnToActive.setAttribute('aria-pressed', 'true')
@@ -49,8 +74,12 @@ const ColorThemeSwitcher = (() => {
49
74
  }
50
75
 
51
76
  // Swap the toggle button icon
52
- themeSwitcher.querySelectorAll('.bl-theme-icon').forEach(icon => icon.classList.add('d-none'))
53
- const activeIcon = themeSwitcher.querySelector(`.bl-theme-icon[data-bl-theme-icon="${theme}"]`)
77
+ themeSwitcher
78
+ .querySelectorAll('.bl-theme-icon')
79
+ .forEach((icon) => icon.classList.add('d-none'))
80
+ const activeIcon = themeSwitcher.querySelector(
81
+ `.bl-theme-icon[data-bl-theme-icon="${theme}"]`,
82
+ )
54
83
  if (activeIcon) activeIcon.classList.remove('d-none')
55
84
 
56
85
  themeSwitcher.setAttribute('aria-label', `Toggle theme (${theme})`)
@@ -60,14 +89,16 @@ const ColorThemeSwitcher = (() => {
60
89
  }
61
90
  }
62
91
 
63
- window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
64
- const storedTheme = getStoredTheme()
65
- if (storedTheme !== 'light' && storedTheme !== 'dark') {
66
- setTheme(getPreferredTheme())
67
- }
68
- })
92
+ window
93
+ .matchMedia('(prefers-color-scheme: dark)')
94
+ .addEventListener('change', () => {
95
+ const storedTheme = getStoredTheme()
96
+ if (storedTheme !== 'light' && storedTheme !== 'dark') {
97
+ setTheme(getPreferredTheme())
98
+ }
99
+ })
69
100
 
70
- document.addEventListener('click', e => {
101
+ document.addEventListener('click', (e) => {
71
102
  const btn = e.target.closest('[data-bs-theme-value]')
72
103
  if (!btn) return
73
104
 
@@ -1,47 +1,46 @@
1
- const Core = function() {
2
- const buffer = new Array;
1
+ const Core = (function () {
2
+ const buffer = new Array()
3
3
  return {
4
- onLoad: function(func) {
5
- buffer.push(func);
4
+ onLoad: function (func) {
5
+ buffer.push(func)
6
6
  },
7
7
 
8
- activate: function() {
9
- for(let i = 0; i < buffer.length; i++) {
10
- buffer[i].call();
8
+ activate: function () {
9
+ for (let i = 0; i < buffer.length; i++) {
10
+ buffer[i].call()
11
11
  }
12
12
  },
13
13
 
14
14
  listeners: function () {
15
- const listeners = [];
15
+ const listeners = []
16
16
  if (typeof Turbo !== 'undefined') {
17
- listeners.push('turbo:load', 'turbo:frame-load');
17
+ listeners.push('turbo:load', 'turbo:frame-load')
18
18
  } else {
19
- listeners.push('DOMContentLoaded');
19
+ listeners.push('DOMContentLoaded')
20
20
  }
21
21
 
22
- return listeners;
23
- }
24
- };
25
- }();
22
+ return listeners
23
+ },
24
+ }
25
+ })()
26
26
 
27
27
  // turbo triggers turbo:load events on page transition
28
28
  // If app isn't using turbo, this event will never be triggered, no prob.
29
- Core.listeners().forEach(function(listener) {
30
- document.addEventListener(listener, function() {
29
+ Core.listeners().forEach(function (listener) {
30
+ document.addEventListener(listener, function () {
31
31
  Core.activate()
32
32
  })
33
33
  })
34
34
 
35
35
  Core.onLoad(function () {
36
- const elem = document.querySelector('.no-js');
36
+ const elem = document.querySelector('.no-js')
37
37
 
38
38
  // The "no-js" class may already have been removed because this function is
39
39
  // run on every turbo:load event, in that case, it won't find an element.
40
- if (!elem) return;
40
+ if (!elem) return
41
41
 
42
42
  elem.classList.remove('no-js')
43
43
  elem.classList.add('js')
44
44
  })
45
45
 
46
-
47
46
  export default Core
@@ -7,9 +7,11 @@
7
7
  // debounced // does print to the screen
8
8
  // ```
9
9
  export default function debounce(func, timeout = 200) {
10
- let timer;
11
- return (...args) => {
12
- clearTimeout(timer);
13
- timer = setTimeout(() => { func.apply(this, args); }, timeout);
14
- };
10
+ let timer
11
+ return (...args) => {
12
+ clearTimeout(timer)
13
+ timer = setTimeout(() => {
14
+ func.apply(this, args)
15
+ }, timeout)
16
+ }
15
17
  }
@@ -1,50 +1,52 @@
1
- import debounce from "blacklight-frontend/debounce";
1
+ import debounce from 'blacklight-frontend/debounce'
2
2
 
3
3
  const FacetSuggest = async (e) => {
4
4
  if (e.target.matches('.facet-suggest')) {
5
- const queryFragment = e.target.value?.trim();
6
- const facetField = e.target.dataset.facetField;
7
- const facetArea = document.querySelector('.facet-extended-list');
8
- const prevNextLinks = document.querySelectorAll('.prev_next_links');
5
+ const queryFragment = e.target.value?.trim()
6
+ const facetField = e.target.dataset.facetField
7
+ const facetArea = document.querySelector('.facet-extended-list')
8
+ const prevNextLinks = document.querySelectorAll('.prev_next_links')
9
9
 
10
- if (!facetField) { return; }
10
+ if (!facetField) {
11
+ return
12
+ }
11
13
 
12
14
  // Get the search params from the current query so the facet suggestions
13
15
  // can retain that context.
14
- const facetSearchContext = e.target.dataset.facetSearchContext;
15
- const url = new URL(facetSearchContext, window.location.origin);
16
+ const facetSearchContext = e.target.dataset.facetSearchContext
17
+ const url = new URL(facetSearchContext, window.location.origin)
16
18
 
17
19
  // Drop facet.page so a filtered suggestion list will always start on page 1
18
- url.searchParams.delete('facet.page');
20
+ url.searchParams.delete('facet.page')
19
21
  // add our queryFragment for facet filtering
20
- url.searchParams.append('query_fragment', queryFragment);
22
+ url.searchParams.append('query_fragment', queryFragment)
21
23
 
22
- const facetSearchParams = url.searchParams.toString();
23
- const basePathComponent = url.pathname.split('/')[1];
24
+ const facetSearchParams = url.searchParams.toString()
25
+ const basePathComponent = url.pathname.split('/')[1]
24
26
 
25
- const urlToFetch = `/${basePathComponent}/facet_suggest/${facetField}?${facetSearchParams}`;
27
+ const urlToFetch = `/${basePathComponent}/facet_suggest/${facetField}?${facetSearchParams}`
26
28
 
27
- const response = await fetch(urlToFetch);
29
+ const response = await fetch(urlToFetch)
28
30
  if (response.ok) {
29
- const blob = await response.blob()
30
- const text = await blob.text()
31
+ const blob = await response.blob()
32
+ const text = await blob.text()
31
33
 
32
- if (text && facetArea) {
33
- facetArea.innerHTML = text
34
- }
34
+ if (text && facetArea) {
35
+ facetArea.innerHTML = text
36
+ }
35
37
  }
36
38
 
37
39
  // Hide the prev/next links when a user enters text in the facet
38
40
  // suggestion input. They don't work with a filtered list.
39
- prevNextLinks.forEach(element => {
40
- element.classList.toggle('invisible', !!queryFragment);
41
- });
41
+ prevNextLinks.forEach((element) => {
42
+ element.classList.toggle('invisible', !!queryFragment)
43
+ })
42
44
 
43
45
  // Add a class to distinguish suggested facet values vs. regular.
44
- facetArea.classList.toggle('facet-suggestions', !!queryFragment);
46
+ facetArea.classList.toggle('facet-suggestions', !!queryFragment)
45
47
  }
46
- };
48
+ }
47
49
 
48
- document.addEventListener('input', debounce(FacetSuggest));
50
+ document.addEventListener('input', debounce(FacetSuggest))
49
51
 
50
52
  export default FacetSuggest
@@ -14,5 +14,5 @@ export default {
14
14
  Modal,
15
15
  SearchContext,
16
16
  Core,
17
- onLoad: Core.onLoad
17
+ onLoad: Core.onLoad,
18
18
  }
@@ -57,11 +57,11 @@ const Modal = (() => {
57
57
  const modal = {}
58
58
 
59
59
  // a Bootstrap modal div that should be already on the page hidden
60
- modal.modalSelector = '#blacklight-modal';
60
+ modal.modalSelector = '#blacklight-modal'
61
61
 
62
62
  // Trigger selectors identify forms or hyperlinks that should open
63
63
  // inside a modal dialog.
64
- modal.triggerLinkSelector = 'a[data-blacklight-modal~=trigger]';
64
+ modal.triggerLinkSelector = 'a[data-blacklight-modal~=trigger]'
65
65
 
66
66
  // preserve selectors identify forms or hyperlinks that, if activated already
67
67
  // inside a modal dialog, should have destinations remain inside the modal -- but
@@ -70,16 +70,17 @@ const Modal = (() => {
70
70
  // No need to repeat selectors from trigger selectors, those will already
71
71
  // be preserved. MUST be manually prefixed with the modal selector,
72
72
  // so they only apply to things inside a modal.
73
- modal.preserveLinkSelector = modal.modalSelector + ' a[data-blacklight-modal~=preserve]';
73
+ modal.preserveLinkSelector =
74
+ modal.modalSelector + ' a[data-blacklight-modal~=preserve]'
74
75
 
75
- modal.containerSelector = '[data-blacklight-modal~=container]';
76
+ modal.containerSelector = '[data-blacklight-modal~=container]'
76
77
 
77
78
  // Called on fatal failure of ajax load, function returns content
78
79
  // to show to user in modal. Right now called only for network errors.
79
80
  modal.onFailure = function (error) {
80
- console.error('Server error:', this.url, error);
81
+ console.error('Server error:', this.url, error)
81
82
 
82
- const contents = `<div class="modal-header">
83
+ const contents = `<div class="modal-header">
83
84
  <div class="modal-title">There was a problem with your request.</div>
84
85
  <button type="button" class="blacklight-modal-close btn-close" data-bl-dismiss="modal" aria-label="Close">
85
86
  </button>
@@ -89,17 +90,17 @@ const Modal = (() => {
89
90
  <pre>${this.url}\n${error}</pre>
90
91
  </div>`
91
92
 
92
- modal.target().querySelector('.modal-content').innerHTML = contents
93
+ modal.target().querySelector('.modal-content').innerHTML = contents
93
94
 
94
- modal.show();
95
+ modal.show()
95
96
  }
96
97
 
97
98
  // Add the passed in contents to the modal and display it.
98
99
  // We have specific handling so that scripts returned from the ajax call are executed.
99
100
  // This enables adding a script like recaptcha to prevent bots from sending emails.
100
101
  modal.receiveAjax = function (contents) {
101
- const domparser = new DOMParser();
102
- const dom = domparser.parseFromString(contents, "text/html")
102
+ const domparser = new DOMParser()
103
+ const dom = domparser.parseFromString(contents, 'text/html')
103
104
  // If there is a containerSelector on the document, use its children.
104
105
  let elements = dom.querySelectorAll(`${modal.containerSelector} > *`)
105
106
  const frag = document.createDocumentFragment()
@@ -113,13 +114,16 @@ const Modal = (() => {
113
114
  modal.target().querySelector('.modal-content').replaceChildren(frag)
114
115
 
115
116
  // send custom event with the modal dialog div as the target
116
- var e = new CustomEvent('loaded.blacklight.blacklight-modal', { bubbles: true, cancelable: true });
117
+ var e = new CustomEvent('loaded.blacklight.blacklight-modal', {
118
+ bubbles: true,
119
+ cancelable: true,
120
+ })
117
121
  modal.target().dispatchEvent(e)
118
122
 
119
123
  // if they did preventDefault, don't show the dialog
120
- if (e.defaultPrevented) return;
121
- modal.show();
122
- };
124
+ if (e.defaultPrevented) return
125
+ modal.show()
126
+ }
123
127
 
124
128
  // DOMParser doesn't allow scripts to be executed. This fixes that.
125
129
  modal.activateScripts = function (frag) {
@@ -131,86 +135,99 @@ const Modal = (() => {
131
135
  })
132
136
  }
133
137
 
134
- modal.modalAjaxLinkClick = function(e) {
135
- e.preventDefault();
138
+ modal.modalAjaxLinkClick = function (e) {
139
+ e.preventDefault()
136
140
  const href = e.target.closest('a').getAttribute('href')
137
- fetch(href, { headers: { 'X-Requested-With': 'XMLHttpRequest' }})
138
- .then(response => {
139
- if (!response.ok) {
140
- throw new TypeError("Request failed");
141
- }
142
- return response.text();
143
- })
144
- .then(data => modal.receiveAjax(data))
145
- .catch(error => modal.onFailure(error))
146
- };
147
-
148
- modal.setupModal = function() {
141
+ fetch(href, { headers: { 'X-Requested-With': 'XMLHttpRequest' } })
142
+ .then((response) => {
143
+ if (!response.ok) {
144
+ throw new TypeError('Request failed')
145
+ }
146
+ return response.text()
147
+ })
148
+ .then((data) => modal.receiveAjax(data))
149
+ .catch((error) => modal.onFailure(error))
150
+ }
151
+
152
+ modal.setupModal = function () {
149
153
  // Register several click handlers in ONE event handler for efficiency
150
154
  //
151
155
  // * close button OR click on backdrop (modal.modalSelector) closes modal
152
156
  // * trigger and preserve link in modal functionality -- if somethign matches both trigger and
153
157
  // preserve, still only called once.
154
158
  document.addEventListener('click', (e) => {
155
- if (e.target.closest(`${modal.triggerLinkSelector}, ${modal.preserveLinkSelector}`))
159
+ if (
160
+ e.target.closest(
161
+ `${modal.triggerLinkSelector}, ${modal.preserveLinkSelector}`,
162
+ )
163
+ )
156
164
  modal.modalAjaxLinkClick(e)
157
- else if (e.target.matches(`${modal.modalSelector}`) || e.target.closest('[data-bl-dismiss="modal"]'))
165
+ else if (
166
+ e.target.matches(`${modal.modalSelector}`) ||
167
+ e.target.closest('[data-bl-dismiss="modal"]')
168
+ )
158
169
  modal.hide()
159
170
  })
160
171
 
161
172
  // Make sure user-agent dismissal of html 'dialog', etc `esc` key, triggers
162
173
  // our hide logic, including events and scroll restoration.
163
- const modalDom = modal.target();
174
+ const modalDom = modal.target()
164
175
  if (modalDom) {
165
176
  modal.target().addEventListener('cancel', (e) => {
166
- e.preventDefault(); // 'hide' will close the modal unless cancelled
177
+ e.preventDefault() // 'hide' will close the modal unless cancelled
167
178
 
168
- modal.hide();
169
- });
179
+ modal.hide()
180
+ })
170
181
  }
171
- };
182
+ }
172
183
 
173
- modal.hide = function (el) {
174
- const dom = modal.target();
184
+ modal.hide = function () {
185
+ const dom = modal.target()
175
186
 
176
187
  if (!dom.open) return
177
188
 
178
- var e = new CustomEvent('hide.blacklight.blacklight-modal', { bubbles: true, cancelable: true });
189
+ var e = new CustomEvent('hide.blacklight.blacklight-modal', {
190
+ bubbles: true,
191
+ cancelable: true,
192
+ })
179
193
  dom.dispatchEvent(e)
180
194
 
181
195
  dom.close()
182
196
 
183
197
  // Turn body scrolling back to what it was
184
- document.body.style["overflow"] = modal.originalBodyOverflow;
185
- document.body.style["padding-right"] = modal.originalBodyPaddingRight;
186
- modal.originalBodyOverflow = undefined;
187
- modal.originalBodyPaddingRight = undefined;
198
+ document.body.style['overflow'] = modal.originalBodyOverflow
199
+ document.body.style['padding-right'] = modal.originalBodyPaddingRight
200
+ modal.originalBodyOverflow = undefined
201
+ modal.originalBodyPaddingRight = undefined
188
202
  }
189
203
 
190
- modal.show = function(el) {
191
- const dom = modal.target();
204
+ modal.show = function () {
205
+ const dom = modal.target()
192
206
 
193
207
  if (dom.open) return
194
208
 
195
- var e = new CustomEvent('show.blacklight.blacklight-modal', { bubbles: true, cancelable: true });
209
+ var e = new CustomEvent('show.blacklight.blacklight-modal', {
210
+ bubbles: true,
211
+ cancelable: true,
212
+ })
196
213
  dom.dispatchEvent(e)
197
214
 
198
215
  dom.showModal()
199
216
 
200
217
  // Turn off body scrolling
201
- modal.originalBodyOverflow = document.body.style['overflow'];
202
- modal.originalBodyPaddingRight = document.body.style['padding-right'];
203
- document.body.style["overflow"] = "hidden"
204
- document.body.style["padding-right"] = "0px"
218
+ modal.originalBodyOverflow = document.body.style['overflow']
219
+ modal.originalBodyPaddingRight = document.body.style['padding-right']
220
+ document.body.style['overflow'] = 'hidden'
221
+ document.body.style['padding-right'] = '0px'
205
222
  }
206
223
 
207
- modal.target = function() {
208
- return document.querySelector(modal.modalSelector);
224
+ modal.target = function () {
225
+ return document.querySelector(modal.modalSelector)
209
226
  }
210
227
 
211
228
  modal.setupModal()
212
229
 
213
- return modal;
230
+ return modal
214
231
  })()
215
232
 
216
233
  export default Modal