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.
- checksums.yaml +4 -4
- data/.github/matrix.json +4 -4
- data/.github/workflows/build.yml +3 -0
- data/.github/workflows/lint.yml +17 -2
- data/.github/workflows/main.yml +3 -0
- data/.github/workflows/release_7_x_scheduled.yml +3 -0
- data/.github/workflows/release_8_x_scheduled.yml +3 -0
- data/.github/workflows/test.yml +3 -2
- data/.gitignore +0 -1
- data/.prettierignore +5 -0
- data/.prettierrc.json +4 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +0 -143
- data/VERSION +1 -1
- data/app/assets/builds/blacklight.css +39 -9
- data/app/assets/javascripts/blacklight/blacklight.esm.js +207 -125
- data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
- data/app/assets/javascripts/blacklight/blacklight.js +207 -125
- data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
- data/app/assets/stylesheets/blacklight/_search_results.scss +24 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +18 -3
- data/app/components/blacklight/constraints_component.rb +2 -1
- data/app/components/blacklight/facet_field_component.rb +1 -1
- data/app/components/blacklight/open_graph_metadata_component.rb +33 -0
- data/app/components/blacklight/search/sidebar_component.html.erb +2 -2
- data/app/components/blacklight/search/sidebar_component.rb +3 -2
- data/app/controllers/concerns/blacklight/catalog.rb +3 -5
- data/app/controllers/concerns/blacklight/controller.rb +2 -6
- data/app/controllers/concerns/blacklight/search_context.rb +2 -7
- data/app/controllers/concerns/blacklight/token_based_user.rb +2 -6
- data/app/helpers/blacklight/catalog_helper_behavior.rb +9 -9
- data/app/helpers/blacklight/url_helper_behavior.rb +2 -7
- data/app/javascript/blacklight-frontend/bookmark_toggle.js +10 -8
- data/app/javascript/blacklight-frontend/checkbox_submit.js +42 -33
- data/app/javascript/blacklight-frontend/color_theme_switcher.js +47 -16
- data/app/javascript/blacklight-frontend/core.js +18 -19
- data/app/javascript/blacklight-frontend/debounce.js +7 -5
- data/app/javascript/blacklight-frontend/facet_suggest.js +27 -25
- data/app/javascript/blacklight-frontend/index.js +1 -1
- data/app/javascript/blacklight-frontend/modal.js +69 -52
- data/app/javascript/blacklight-frontend/search_context.js +36 -17
- data/app/models/blacklight/facet_paginator.rb +1 -3
- data/app/presenters/blacklight/document_presenter.rb +10 -1
- data/app/presenters/blacklight/facet_grouped_item_presenter.rb +1 -3
- data/app/presenters/blacklight/facet_item_pivot_presenter.rb +0 -8
- data/app/presenters/blacklight/json_presenter.rb +1 -3
- data/app/presenters/blacklight/open_graph_presenter.rb +34 -0
- data/app/presenters/blacklight/thumbnail_presenter.rb +24 -1
- data/app/services/blacklight/field_retriever.rb +1 -3
- data/app/services/blacklight/search_service.rb +1 -1
- data/app/views/catalog/_document.atom.builder +3 -5
- data/app/views/catalog/_show_main_content.html.erb +1 -0
- data/app/views/catalog/index.atom.builder +8 -4
- data/app/views/layouts/blacklight/base.html.erb +7 -1
- data/config/i18n-tasks.yml +1 -1
- data/config/locales/blacklight.ja.yml +256 -0
- data/lib/blacklight/configuration/context.rb +1 -1
- data/lib/blacklight/configuration/fields.rb +3 -9
- data/lib/blacklight/configuration/view_config.rb +16 -0
- data/lib/blacklight/configuration.rb +6 -2
- data/lib/blacklight/engine.rb +2 -4
- data/lib/blacklight/search_builder.rb +4 -4
- data/lib/blacklight/search_state/filter_field.rb +0 -1
- data/lib/blacklight/search_state.rb +2 -6
- data/lib/blacklight/solr/facet_paginator.rb +1 -1
- data/lib/blacklight/solr/repository.rb +1 -3
- data/lib/blacklight/solr/response/facets.rb +11 -9
- data/lib/blacklight/solr/response/spelling.rb +51 -47
- data/lib/blacklight/solr/search_builder_behavior.rb +14 -15
- data/lib/blacklight.rb +3 -9
- data/lib/generators/blacklight/assets/importmap_generator.rb +3 -3
- data/lib/generators/blacklight/assets_generator.rb +1 -1
- data/lib/railties/blacklight.rake +3 -5
- data/package-lock.json +1054 -0
- data/package.json +7 -4
- data/rollup.config.js +5 -7
- data/spec/components/blacklight/constraints_component_spec.rb +23 -1
- data/spec/components/blacklight/document/page_header_component_spec.rb +4 -4
- data/spec/components/blacklight/document_component_spec.rb +16 -3
- data/spec/components/blacklight/metadata_field_component_spec.rb +2 -2
- data/spec/components/blacklight/response/spellcheck_component_spec.rb +2 -2
- data/spec/components/blacklight/search_bar_component_spec.rb +1 -1
- data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +1 -1
- data/spec/components/blacklight/system/dropdown_component_spec.rb +1 -2
- data/spec/controllers/bookmarks_controller_spec.rb +3 -9
- data/spec/controllers/catalog_controller_spec.rb +56 -26
- data/spec/features/dark_mode_spec.rb +30 -0
- data/spec/features/did_you_mean_spec.rb +1 -1
- data/spec/features/facet_missing_spec.rb +3 -3
- data/spec/features/modal_spec.rb +2 -2
- data/spec/features/open_graph_spec.rb +43 -0
- data/spec/features/search_context_spec.rb +1 -1
- data/spec/fixtures/sample_solr_documents.yml +6 -0
- data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +11 -8
- data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +1 -1
- data/spec/helpers/blacklight/url_helper_behavior_spec.rb +5 -5
- data/spec/helpers/blacklight_helper_spec.rb +6 -4
- data/spec/helpers/catalog_helper_spec.rb +34 -8
- data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +2 -2
- data/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb +2 -2
- data/spec/lib/blacklight/search_state/filter_field_spec.rb +1 -1
- data/spec/lib/blacklight/search_state/pivot_filter_field_spec.rb +1 -1
- data/spec/lib/blacklight/search_state_spec.rb +14 -19
- data/spec/lib/blacklight_spec.rb +5 -5
- data/spec/models/blacklight/configuration_spec.rb +1 -1
- data/spec/models/blacklight/document/cache_key_spec.rb +32 -12
- data/spec/models/blacklight/facet_paginator_spec.rb +5 -5
- data/spec/models/blacklight/icon_spec.rb +3 -3
- data/spec/models/blacklight/search_builder_spec.rb +21 -16
- data/spec/models/blacklight/solr/default_filter_query_builder_spec.rb +1 -1
- data/spec/models/blacklight/solr/document_spec.rb +8 -8
- data/spec/models/blacklight/solr/response/facets_spec.rb +5 -5
- data/spec/models/blacklight/solr/response/group_response_spec.rb +1 -1
- data/spec/models/blacklight/solr/response/group_spec.rb +1 -1
- data/spec/models/blacklight/solr/response_spec.rb +18 -3
- data/spec/models/blacklight/solr/search_builder_behavior_spec.rb +46 -7
- data/spec/models/blacklight/suggest_search_spec.rb +1 -1
- data/spec/models/record_mailer_spec.rb +2 -2
- data/spec/models/search_spec.rb +7 -7
- data/spec/presenters/blacklight/document_presenter_spec.rb +19 -6
- data/spec/presenters/blacklight/facet_field_presenter_spec.rb +4 -4
- data/spec/presenters/blacklight/field_presenter_spec.rb +12 -9
- data/spec/presenters/blacklight/open_graph_presenter_spec.rb +56 -0
- data/spec/presenters/blacklight/rendering/pipeline_spec.rb +3 -3
- data/spec/presenters/blacklight/thumbnail_presenter_spec.rb +129 -13
- data/spec/routing/catalog_routing_spec.rb +1 -1
- data/spec/services/blacklight/field_retriever_spec.rb +1 -1
- data/spec/services/blacklight/search_service_spec.rb +8 -8
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -3
- data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -2
- data/spec/views/catalog/index.atom.builder_spec.rb +16 -20
- data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -1
- 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')).
|
|
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(
|
|
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
|
-
|
|
25
|
+
Accept: 'application/json',
|
|
30
26
|
'X-Requested-With': 'XMLHttpRequest',
|
|
31
|
-
'X-CSRF-Token': document.querySelector('meta[name=csrf-token]')
|
|
32
|
-
|
|
33
|
-
|
|
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 (
|
|
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(
|
|
85
|
+
alert('Unable to save the bookmark at this time.')
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
updateStateFor(state) {
|
|
83
|
-
if (state) {
|
|
84
|
-
|
|
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
|
-
|
|
12
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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
|
|
53
|
-
|
|
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
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
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) {
|
|
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
|
-
|
|
30
|
-
|
|
31
|
+
const blob = await response.blob()
|
|
32
|
+
const text = await blob.text()
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
@@ -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
|
|
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 =
|
|
73
|
+
modal.preserveLinkSelector =
|
|
74
|
+
modal.modalSelector + ' a[data-blacklight-modal~=preserve]'
|
|
74
75
|
|
|
75
|
-
modal.containerSelector
|
|
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
|
-
|
|
81
|
+
console.error('Server error:', this.url, error)
|
|
81
82
|
|
|
82
|
-
|
|
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
|
-
|
|
93
|
+
modal.target().querySelector('.modal-content').innerHTML = contents
|
|
93
94
|
|
|
94
|
-
|
|
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,
|
|
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', {
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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 (
|
|
159
|
+
if (
|
|
160
|
+
e.target.closest(
|
|
161
|
+
`${modal.triggerLinkSelector}, ${modal.preserveLinkSelector}`,
|
|
162
|
+
)
|
|
163
|
+
)
|
|
156
164
|
modal.modalAjaxLinkClick(e)
|
|
157
|
-
else if (
|
|
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()
|
|
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 (
|
|
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', {
|
|
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[
|
|
185
|
-
document.body.style[
|
|
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(
|
|
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', {
|
|
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[
|
|
204
|
-
document.body.style[
|
|
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
|