blacklight-frontend 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.
- package/app/assets/builds/blacklight.css +39 -9
- package/app/assets/javascripts/blacklight/blacklight.esm.js +207 -125
- package/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
- package/app/assets/javascripts/blacklight/blacklight.js +207 -125
- package/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
- package/app/assets/stylesheets/blacklight/_search_results.scss +24 -0
- package/app/assets/stylesheets/blacklight/blacklight_defaults.scss +18 -3
- package/app/javascript/blacklight-frontend/bookmark_toggle.js +10 -8
- package/app/javascript/blacklight-frontend/checkbox_submit.js +42 -33
- package/app/javascript/blacklight-frontend/color_theme_switcher.js +47 -16
- package/app/javascript/blacklight-frontend/core.js +18 -19
- package/app/javascript/blacklight-frontend/debounce.js +7 -5
- package/app/javascript/blacklight-frontend/facet_suggest.js +27 -25
- package/app/javascript/blacklight-frontend/index.js +1 -1
- package/app/javascript/blacklight-frontend/modal.js +69 -52
- package/app/javascript/blacklight-frontend/search_context.js +36 -17
- package/package.json +7 -4
|
@@ -12,19 +12,15 @@
|
|
|
12
12
|
being set to "put" or "delete" -- that's the Rails method to pretend
|
|
13
13
|
to be doing a certain HTTP verb. So same URL, PUT to add, DELETE
|
|
14
14
|
to remove. This plugin assumes that.
|
|
15
|
-
Plus, the form this is applied to should provide a data-doc-id
|
|
16
|
-
attribute (HTML5-style doc-*) that contains the id/primary key
|
|
17
|
-
of the object in question -- used by plugin for a unique value for
|
|
18
|
-
DOM id's.
|
|
19
15
|
Uses HTML for a checkbox compatible with Bootstrap.
|
|
20
|
-
new CheckboxSubmit(document.querySelector('form.something')).
|
|
16
|
+
new CheckboxSubmit(document.querySelector('form.something')).clicked()
|
|
21
17
|
*/
|
|
22
18
|
class CheckboxSubmit {
|
|
23
19
|
constructor(form) {
|
|
24
20
|
this.form = form;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
|
-
clicked(
|
|
23
|
+
clicked() {
|
|
28
24
|
this.spanTarget.innerHTML = this.form.getAttribute('data-inprogress');
|
|
29
25
|
this.labelTarget.setAttribute('disabled', 'disabled');
|
|
30
26
|
this.checkboxTarget.setAttribute('disabled', 'disabled');
|
|
@@ -32,33 +28,43 @@
|
|
|
32
28
|
body: new FormData(this.formTarget),
|
|
33
29
|
method: this.formTarget.getAttribute('method').toUpperCase(),
|
|
34
30
|
headers: {
|
|
35
|
-
|
|
31
|
+
Accept: 'application/json',
|
|
36
32
|
'X-Requested-With': 'XMLHttpRequest',
|
|
37
|
-
'X-CSRF-Token': document.querySelector('meta[name=csrf-token]')
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
'X-CSRF-Token': document.querySelector('meta[name=csrf-token]')
|
|
34
|
+
?.content,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
.then((response) => {
|
|
38
|
+
if (response.ok) return response.json()
|
|
39
|
+
return Promise.reject('response was not ok')
|
|
40
|
+
})
|
|
41
|
+
.then((json) => {
|
|
42
|
+
this.labelTarget.removeAttribute('disabled');
|
|
43
|
+
this.checkboxTarget.removeAttribute('disabled');
|
|
44
|
+
// For accessibility return keyboard focus
|
|
45
|
+
// back to the checkbox after form submission
|
|
46
|
+
this.checkboxTarget.focus();
|
|
47
|
+
this.updateStateFor(!this.checked);
|
|
48
|
+
this.bookmarksCounter().forEach((counter) => {
|
|
49
|
+
counter.innerHTML = json.bookmarks.count;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
var e = new CustomEvent('bookmark.blacklight', {
|
|
53
|
+
detail: { checked: this.checked },
|
|
54
|
+
bubbles: true,
|
|
55
|
+
});
|
|
56
|
+
this.formTarget.dispatchEvent(e);
|
|
57
|
+
})
|
|
58
|
+
.catch((error) => {
|
|
59
|
+
this.handleError(error);
|
|
51
60
|
});
|
|
52
|
-
|
|
53
|
-
var e = new CustomEvent('bookmark.blacklight', { detail: { checked: this.checked }, bubbles: true });
|
|
54
|
-
this.formTarget.dispatchEvent(e);
|
|
55
|
-
}).catch((error) => {
|
|
56
|
-
this.handleError(error);
|
|
57
|
-
});
|
|
58
61
|
}
|
|
59
62
|
|
|
60
63
|
get checked() {
|
|
61
|
-
return (
|
|
64
|
+
return (
|
|
65
|
+
this.form.querySelectorAll('input[name=_method][value=delete]').length !=
|
|
66
|
+
0
|
|
67
|
+
)
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
get formTarget() {
|
|
@@ -82,12 +88,15 @@
|
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
handleError() {
|
|
85
|
-
alert(
|
|
91
|
+
alert('Unable to save the bookmark at this time.');
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
updateStateFor(state) {
|
|
89
|
-
if (state) {
|
|
90
|
-
|
|
95
|
+
if (state) {
|
|
96
|
+
this.checkboxTarget.setAttribute('checked', state);
|
|
97
|
+
} else {
|
|
98
|
+
this.checkboxTarget.removeAttribute('checked');
|
|
99
|
+
}
|
|
91
100
|
|
|
92
101
|
if (state) {
|
|
93
102
|
this.labelTarget.classList.add('checked');
|
|
@@ -107,15 +116,17 @@
|
|
|
107
116
|
const elementType = e.target.getAttribute('data-checkboxsubmit-target');
|
|
108
117
|
if (elementType == 'checkbox' || elementType == 'label') {
|
|
109
118
|
const form = e.target.closest('form');
|
|
110
|
-
if (form) new CheckboxSubmit(form).clicked(
|
|
119
|
+
if (form) new CheckboxSubmit(form).clicked();
|
|
111
120
|
if (e.code == 'Space') e.preventDefault();
|
|
112
121
|
}
|
|
113
122
|
};
|
|
114
123
|
|
|
115
124
|
document.addEventListener('click', BookmarkToggle);
|
|
116
125
|
document.addEventListener('keydown', function (e) {
|
|
117
|
-
if (e.key === 'Enter' || e.code == 'Space') {
|
|
118
|
-
|
|
126
|
+
if (e.key === 'Enter' || e.code == 'Space') {
|
|
127
|
+
BookmarkToggle(e);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
119
130
|
|
|
120
131
|
const ButtonFocus = (e) => {
|
|
121
132
|
// Button clicks should change focus. As of 10/3/19, Firefox for Mac and
|
|
@@ -128,15 +139,15 @@
|
|
|
128
139
|
|
|
129
140
|
document.addEventListener('click', ButtonFocus);
|
|
130
141
|
|
|
131
|
-
const Core = function() {
|
|
132
|
-
const buffer = new Array;
|
|
142
|
+
const Core = (function () {
|
|
143
|
+
const buffer = new Array();
|
|
133
144
|
return {
|
|
134
|
-
onLoad: function(func) {
|
|
145
|
+
onLoad: function (func) {
|
|
135
146
|
buffer.push(func);
|
|
136
147
|
},
|
|
137
148
|
|
|
138
|
-
activate: function() {
|
|
139
|
-
for(let i = 0; i < buffer.length; i++) {
|
|
149
|
+
activate: function () {
|
|
150
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
140
151
|
buffer[i].call();
|
|
141
152
|
}
|
|
142
153
|
},
|
|
@@ -149,15 +160,15 @@
|
|
|
149
160
|
listeners.push('DOMContentLoaded');
|
|
150
161
|
}
|
|
151
162
|
|
|
152
|
-
return listeners
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}();
|
|
163
|
+
return listeners
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
})();
|
|
156
167
|
|
|
157
168
|
// turbo triggers turbo:load events on page transition
|
|
158
169
|
// If app isn't using turbo, this event will never be triggered, no prob.
|
|
159
|
-
Core.listeners().forEach(function(listener) {
|
|
160
|
-
document.addEventListener(listener, function() {
|
|
170
|
+
Core.listeners().forEach(function (listener) {
|
|
171
|
+
document.addEventListener(listener, function () {
|
|
161
172
|
Core.activate();
|
|
162
173
|
});
|
|
163
174
|
});
|
|
@@ -167,7 +178,7 @@
|
|
|
167
178
|
|
|
168
179
|
// The "no-js" class may already have been removed because this function is
|
|
169
180
|
// run on every turbo:load event, in that case, it won't find an element.
|
|
170
|
-
if (!elem) return
|
|
181
|
+
if (!elem) return
|
|
171
182
|
|
|
172
183
|
elem.classList.remove('no-js');
|
|
173
184
|
elem.classList.add('js');
|
|
@@ -181,20 +192,43 @@
|
|
|
181
192
|
|
|
182
193
|
const ColorThemeSwitcher = (() => {
|
|
183
194
|
|
|
184
|
-
|
|
185
|
-
|
|
195
|
+
// Accessing localStorage can throw (e.g. NS_ERROR_FAILURE in Firefox when the
|
|
196
|
+
// profile's storage is corrupt, or SecurityError when storage is disabled),
|
|
197
|
+
// so treat any failure as "no stored theme" rather than breaking page load.
|
|
198
|
+
const getStoredTheme = () => {
|
|
199
|
+
try {
|
|
200
|
+
return localStorage.getItem('theme')
|
|
201
|
+
} catch {
|
|
202
|
+
return null
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const setStoredTheme = (theme) => {
|
|
207
|
+
try {
|
|
208
|
+
localStorage.setItem('theme', theme);
|
|
209
|
+
} catch {
|
|
210
|
+
// Storage is unavailable; the theme still applies for this page view.
|
|
211
|
+
}
|
|
212
|
+
};
|
|
186
213
|
|
|
187
214
|
const getPreferredTheme = () => {
|
|
188
215
|
const storedTheme = getStoredTheme();
|
|
189
216
|
if (storedTheme) {
|
|
190
217
|
return storedTheme
|
|
191
218
|
}
|
|
192
|
-
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
219
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
220
|
+
? 'dark'
|
|
221
|
+
: 'light'
|
|
193
222
|
};
|
|
194
223
|
|
|
195
|
-
const setTheme = theme => {
|
|
224
|
+
const setTheme = (theme) => {
|
|
196
225
|
if (theme === 'auto') {
|
|
197
|
-
document.documentElement.setAttribute(
|
|
226
|
+
document.documentElement.setAttribute(
|
|
227
|
+
'data-bs-theme',
|
|
228
|
+
window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
229
|
+
? 'dark'
|
|
230
|
+
: 'light',
|
|
231
|
+
);
|
|
198
232
|
} else {
|
|
199
233
|
document.documentElement.setAttribute('data-bs-theme', theme);
|
|
200
234
|
}
|
|
@@ -205,7 +239,7 @@
|
|
|
205
239
|
if (!themeSwitcher) return
|
|
206
240
|
|
|
207
241
|
// Reset all dropdown items
|
|
208
|
-
document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
|
|
242
|
+
document.querySelectorAll('[data-bs-theme-value]').forEach((element) => {
|
|
209
243
|
element.classList.remove('active');
|
|
210
244
|
element.setAttribute('aria-pressed', 'false');
|
|
211
245
|
const check = element.querySelector('.bl-theme-check');
|
|
@@ -213,7 +247,9 @@
|
|
|
213
247
|
});
|
|
214
248
|
|
|
215
249
|
// Activate the selected item
|
|
216
|
-
const btnToActive = document.querySelector(
|
|
250
|
+
const btnToActive = document.querySelector(
|
|
251
|
+
`[data-bs-theme-value="${theme}"]`,
|
|
252
|
+
);
|
|
217
253
|
if (btnToActive) {
|
|
218
254
|
btnToActive.classList.add('active');
|
|
219
255
|
btnToActive.setAttribute('aria-pressed', 'true');
|
|
@@ -222,8 +258,12 @@
|
|
|
222
258
|
}
|
|
223
259
|
|
|
224
260
|
// Swap the toggle button icon
|
|
225
|
-
themeSwitcher
|
|
226
|
-
|
|
261
|
+
themeSwitcher
|
|
262
|
+
.querySelectorAll('.bl-theme-icon')
|
|
263
|
+
.forEach((icon) => icon.classList.add('d-none'));
|
|
264
|
+
const activeIcon = themeSwitcher.querySelector(
|
|
265
|
+
`.bl-theme-icon[data-bl-theme-icon="${theme}"]`,
|
|
266
|
+
);
|
|
227
267
|
if (activeIcon) activeIcon.classList.remove('d-none');
|
|
228
268
|
|
|
229
269
|
themeSwitcher.setAttribute('aria-label', `Toggle theme (${theme})`);
|
|
@@ -233,14 +273,16 @@
|
|
|
233
273
|
}
|
|
234
274
|
};
|
|
235
275
|
|
|
236
|
-
window
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
276
|
+
window
|
|
277
|
+
.matchMedia('(prefers-color-scheme: dark)')
|
|
278
|
+
.addEventListener('change', () => {
|
|
279
|
+
const storedTheme = getStoredTheme();
|
|
280
|
+
if (storedTheme !== 'light' && storedTheme !== 'dark') {
|
|
281
|
+
setTheme(getPreferredTheme());
|
|
282
|
+
}
|
|
283
|
+
});
|
|
242
284
|
|
|
243
|
-
document.addEventListener('click', e => {
|
|
285
|
+
document.addEventListener('click', (e) => {
|
|
244
286
|
const btn = e.target.closest('[data-bs-theme-value]');
|
|
245
287
|
if (!btn) return
|
|
246
288
|
|
|
@@ -264,11 +306,13 @@
|
|
|
264
306
|
// debounced // does print to the screen
|
|
265
307
|
// ```
|
|
266
308
|
function debounce(func, timeout = 200) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
309
|
+
let timer;
|
|
310
|
+
return (...args) => {
|
|
311
|
+
clearTimeout(timer);
|
|
312
|
+
timer = setTimeout(() => {
|
|
313
|
+
func.apply(this, args);
|
|
314
|
+
}, timeout);
|
|
315
|
+
}
|
|
272
316
|
}
|
|
273
317
|
|
|
274
318
|
const FacetSuggest = async (e) => {
|
|
@@ -278,7 +322,9 @@
|
|
|
278
322
|
const facetArea = document.querySelector('.facet-extended-list');
|
|
279
323
|
const prevNextLinks = document.querySelectorAll('.prev_next_links');
|
|
280
324
|
|
|
281
|
-
if (!facetField) {
|
|
325
|
+
if (!facetField) {
|
|
326
|
+
return
|
|
327
|
+
}
|
|
282
328
|
|
|
283
329
|
// Get the search params from the current query so the facet suggestions
|
|
284
330
|
// can retain that context.
|
|
@@ -297,17 +343,17 @@
|
|
|
297
343
|
|
|
298
344
|
const response = await fetch(urlToFetch);
|
|
299
345
|
if (response.ok) {
|
|
300
|
-
|
|
301
|
-
|
|
346
|
+
const blob = await response.blob();
|
|
347
|
+
const text = await blob.text();
|
|
302
348
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
349
|
+
if (text && facetArea) {
|
|
350
|
+
facetArea.innerHTML = text;
|
|
351
|
+
}
|
|
306
352
|
}
|
|
307
353
|
|
|
308
354
|
// Hide the prev/next links when a user enters text in the facet
|
|
309
355
|
// suggestion input. They don't work with a filtered list.
|
|
310
|
-
prevNextLinks.forEach(element => {
|
|
356
|
+
prevNextLinks.forEach((element) => {
|
|
311
357
|
element.classList.toggle('invisible', !!queryFragment);
|
|
312
358
|
});
|
|
313
359
|
|
|
@@ -381,7 +427,7 @@
|
|
|
381
427
|
|
|
382
428
|
// Trigger selectors identify forms or hyperlinks that should open
|
|
383
429
|
// inside a modal dialog.
|
|
384
|
-
modal.triggerLinkSelector
|
|
430
|
+
modal.triggerLinkSelector = 'a[data-blacklight-modal~=trigger]';
|
|
385
431
|
|
|
386
432
|
// preserve selectors identify forms or hyperlinks that, if activated already
|
|
387
433
|
// inside a modal dialog, should have destinations remain inside the modal -- but
|
|
@@ -390,16 +436,17 @@
|
|
|
390
436
|
// No need to repeat selectors from trigger selectors, those will already
|
|
391
437
|
// be preserved. MUST be manually prefixed with the modal selector,
|
|
392
438
|
// so they only apply to things inside a modal.
|
|
393
|
-
modal.preserveLinkSelector =
|
|
439
|
+
modal.preserveLinkSelector =
|
|
440
|
+
modal.modalSelector + ' a[data-blacklight-modal~=preserve]';
|
|
394
441
|
|
|
395
|
-
modal.containerSelector
|
|
442
|
+
modal.containerSelector = '[data-blacklight-modal~=container]';
|
|
396
443
|
|
|
397
444
|
// Called on fatal failure of ajax load, function returns content
|
|
398
445
|
// to show to user in modal. Right now called only for network errors.
|
|
399
446
|
modal.onFailure = function (error) {
|
|
400
|
-
|
|
447
|
+
console.error('Server error:', this.url, error);
|
|
401
448
|
|
|
402
|
-
|
|
449
|
+
const contents = `<div class="modal-header">
|
|
403
450
|
<div class="modal-title">There was a problem with your request.</div>
|
|
404
451
|
<button type="button" class="blacklight-modal-close btn-close" data-bl-dismiss="modal" aria-label="Close">
|
|
405
452
|
</button>
|
|
@@ -409,9 +456,9 @@
|
|
|
409
456
|
<pre>${this.url}\n${error}</pre>
|
|
410
457
|
</div>`;
|
|
411
458
|
|
|
412
|
-
|
|
459
|
+
modal.target().querySelector('.modal-content').innerHTML = contents;
|
|
413
460
|
|
|
414
|
-
|
|
461
|
+
modal.show();
|
|
415
462
|
};
|
|
416
463
|
|
|
417
464
|
// Add the passed in contents to the modal and display it.
|
|
@@ -419,7 +466,7 @@
|
|
|
419
466
|
// This enables adding a script like recaptcha to prevent bots from sending emails.
|
|
420
467
|
modal.receiveAjax = function (contents) {
|
|
421
468
|
const domparser = new DOMParser();
|
|
422
|
-
const dom = domparser.parseFromString(contents,
|
|
469
|
+
const dom = domparser.parseFromString(contents, 'text/html');
|
|
423
470
|
// If there is a containerSelector on the document, use its children.
|
|
424
471
|
let elements = dom.querySelectorAll(`${modal.containerSelector} > *`);
|
|
425
472
|
const frag = document.createDocumentFragment();
|
|
@@ -433,11 +480,14 @@
|
|
|
433
480
|
modal.target().querySelector('.modal-content').replaceChildren(frag);
|
|
434
481
|
|
|
435
482
|
// send custom event with the modal dialog div as the target
|
|
436
|
-
var e = new CustomEvent('loaded.blacklight.blacklight-modal', {
|
|
483
|
+
var e = new CustomEvent('loaded.blacklight.blacklight-modal', {
|
|
484
|
+
bubbles: true,
|
|
485
|
+
cancelable: true,
|
|
486
|
+
});
|
|
437
487
|
modal.target().dispatchEvent(e);
|
|
438
488
|
|
|
439
489
|
// if they did preventDefault, don't show the dialog
|
|
440
|
-
if (e.defaultPrevented) return
|
|
490
|
+
if (e.defaultPrevented) return
|
|
441
491
|
modal.show();
|
|
442
492
|
};
|
|
443
493
|
|
|
@@ -451,30 +501,37 @@
|
|
|
451
501
|
});
|
|
452
502
|
};
|
|
453
503
|
|
|
454
|
-
modal.modalAjaxLinkClick = function(e) {
|
|
504
|
+
modal.modalAjaxLinkClick = function (e) {
|
|
455
505
|
e.preventDefault();
|
|
456
506
|
const href = e.target.closest('a').getAttribute('href');
|
|
457
|
-
fetch(href, { headers: { 'X-Requested-With': 'XMLHttpRequest' }})
|
|
458
|
-
.then(response => {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
.then(data => modal.receiveAjax(data))
|
|
465
|
-
.catch(error => modal.onFailure(error));
|
|
507
|
+
fetch(href, { headers: { 'X-Requested-With': 'XMLHttpRequest' } })
|
|
508
|
+
.then((response) => {
|
|
509
|
+
if (!response.ok) {
|
|
510
|
+
throw new TypeError('Request failed')
|
|
511
|
+
}
|
|
512
|
+
return response.text()
|
|
513
|
+
})
|
|
514
|
+
.then((data) => modal.receiveAjax(data))
|
|
515
|
+
.catch((error) => modal.onFailure(error));
|
|
466
516
|
};
|
|
467
517
|
|
|
468
|
-
modal.setupModal = function() {
|
|
518
|
+
modal.setupModal = function () {
|
|
469
519
|
// Register several click handlers in ONE event handler for efficiency
|
|
470
520
|
//
|
|
471
521
|
// * close button OR click on backdrop (modal.modalSelector) closes modal
|
|
472
522
|
// * trigger and preserve link in modal functionality -- if somethign matches both trigger and
|
|
473
523
|
// preserve, still only called once.
|
|
474
524
|
document.addEventListener('click', (e) => {
|
|
475
|
-
if (
|
|
525
|
+
if (
|
|
526
|
+
e.target.closest(
|
|
527
|
+
`${modal.triggerLinkSelector}, ${modal.preserveLinkSelector}`,
|
|
528
|
+
)
|
|
529
|
+
)
|
|
476
530
|
modal.modalAjaxLinkClick(e);
|
|
477
|
-
else if (
|
|
531
|
+
else if (
|
|
532
|
+
e.target.matches(`${modal.modalSelector}`) ||
|
|
533
|
+
e.target.closest('[data-bl-dismiss="modal"]')
|
|
534
|
+
)
|
|
478
535
|
modal.hide();
|
|
479
536
|
});
|
|
480
537
|
|
|
@@ -490,29 +547,35 @@
|
|
|
490
547
|
}
|
|
491
548
|
};
|
|
492
549
|
|
|
493
|
-
modal.hide = function (
|
|
550
|
+
modal.hide = function () {
|
|
494
551
|
const dom = modal.target();
|
|
495
552
|
|
|
496
553
|
if (!dom.open) return
|
|
497
554
|
|
|
498
|
-
var e = new CustomEvent('hide.blacklight.blacklight-modal', {
|
|
555
|
+
var e = new CustomEvent('hide.blacklight.blacklight-modal', {
|
|
556
|
+
bubbles: true,
|
|
557
|
+
cancelable: true,
|
|
558
|
+
});
|
|
499
559
|
dom.dispatchEvent(e);
|
|
500
560
|
|
|
501
561
|
dom.close();
|
|
502
562
|
|
|
503
563
|
// Turn body scrolling back to what it was
|
|
504
|
-
document.body.style[
|
|
505
|
-
document.body.style[
|
|
564
|
+
document.body.style['overflow'] = modal.originalBodyOverflow;
|
|
565
|
+
document.body.style['padding-right'] = modal.originalBodyPaddingRight;
|
|
506
566
|
modal.originalBodyOverflow = undefined;
|
|
507
567
|
modal.originalBodyPaddingRight = undefined;
|
|
508
568
|
};
|
|
509
569
|
|
|
510
|
-
modal.show = function(
|
|
570
|
+
modal.show = function () {
|
|
511
571
|
const dom = modal.target();
|
|
512
572
|
|
|
513
573
|
if (dom.open) return
|
|
514
574
|
|
|
515
|
-
var e = new CustomEvent('show.blacklight.blacklight-modal', {
|
|
575
|
+
var e = new CustomEvent('show.blacklight.blacklight-modal', {
|
|
576
|
+
bubbles: true,
|
|
577
|
+
cancelable: true,
|
|
578
|
+
});
|
|
516
579
|
dom.dispatchEvent(e);
|
|
517
580
|
|
|
518
581
|
dom.showModal();
|
|
@@ -520,17 +583,17 @@
|
|
|
520
583
|
// Turn off body scrolling
|
|
521
584
|
modal.originalBodyOverflow = document.body.style['overflow'];
|
|
522
585
|
modal.originalBodyPaddingRight = document.body.style['padding-right'];
|
|
523
|
-
document.body.style[
|
|
524
|
-
document.body.style[
|
|
586
|
+
document.body.style['overflow'] = 'hidden';
|
|
587
|
+
document.body.style['padding-right'] = '0px';
|
|
525
588
|
};
|
|
526
589
|
|
|
527
|
-
modal.target = function() {
|
|
528
|
-
return document.querySelector(modal.modalSelector)
|
|
590
|
+
modal.target = function () {
|
|
591
|
+
return document.querySelector(modal.modalSelector)
|
|
529
592
|
};
|
|
530
593
|
|
|
531
594
|
modal.setupModal();
|
|
532
595
|
|
|
533
|
-
return modal
|
|
596
|
+
return modal
|
|
534
597
|
})();
|
|
535
598
|
|
|
536
599
|
const SearchContext = (e) => {
|
|
@@ -540,47 +603,66 @@
|
|
|
540
603
|
}
|
|
541
604
|
};
|
|
542
605
|
|
|
543
|
-
SearchContext.csrfToken = () =>
|
|
544
|
-
|
|
606
|
+
SearchContext.csrfToken = () =>
|
|
607
|
+
document.querySelector('meta[name=csrf-token]')?.content;
|
|
608
|
+
SearchContext.csrfParam = () =>
|
|
609
|
+
document.querySelector('meta[name=csrf-param]')?.content;
|
|
545
610
|
|
|
546
611
|
// this is the Rails.handleMethod with a couple adjustments, described inline:
|
|
547
612
|
// first, we're attaching this directly to the event handler, so we can check for meta-keys
|
|
548
|
-
SearchContext.handleSearchContextMethod = function(event) {
|
|
613
|
+
SearchContext.handleSearchContextMethod = function (event) {
|
|
549
614
|
const link = this;
|
|
550
615
|
|
|
551
|
-
// instead of using the normal href, we need to use the context href instead
|
|
552
|
-
|
|
616
|
+
// instead of using the normal href, we need to use the context href instead.
|
|
617
|
+
// Only post to same-origin URLs, which also rules out javascript: URLs;
|
|
618
|
+
// otherwise fall through to the link's default behavior.
|
|
619
|
+
const contextUrl = new URL(
|
|
620
|
+
link.getAttribute('data-context-href'),
|
|
621
|
+
window.location.href,
|
|
622
|
+
);
|
|
623
|
+
if (contextUrl.origin !== window.location.origin) return
|
|
624
|
+
|
|
553
625
|
let target = link.getAttribute('target');
|
|
554
626
|
let csrfToken = SearchContext.csrfToken();
|
|
555
627
|
let csrfParam = SearchContext.csrfParam();
|
|
556
628
|
let form = document.createElement('form');
|
|
557
629
|
form.method = 'post';
|
|
558
|
-
form.action = href;
|
|
559
|
-
|
|
630
|
+
form.action = contextUrl.href;
|
|
631
|
+
|
|
632
|
+
const appendHiddenInput = (name, value) => {
|
|
633
|
+
const input = document.createElement('input');
|
|
634
|
+
input.type = 'hidden';
|
|
635
|
+
input.name = name;
|
|
636
|
+
input.value = value;
|
|
637
|
+
form.appendChild(input);
|
|
638
|
+
};
|
|
560
639
|
|
|
561
|
-
|
|
562
|
-
|
|
640
|
+
appendHiddenInput('_method', 'post');
|
|
641
|
+
appendHiddenInput('redirect', link.getAttribute('href'));
|
|
563
642
|
|
|
564
643
|
// check for meta keys.. if set, we should open in a new tab
|
|
565
|
-
if(event.metaKey || event.ctrlKey) {
|
|
566
|
-
form.dataset.turbo =
|
|
644
|
+
if (event.metaKey || event.ctrlKey) {
|
|
645
|
+
form.dataset.turbo = 'false';
|
|
567
646
|
target = '_blank';
|
|
568
647
|
}
|
|
569
648
|
|
|
570
649
|
if (csrfParam !== undefined && csrfToken !== undefined) {
|
|
571
|
-
|
|
650
|
+
appendHiddenInput(csrfParam, csrfToken);
|
|
572
651
|
}
|
|
573
652
|
|
|
574
653
|
// Must trigger submit by click on a button, else "submit" event handler won't work!
|
|
575
654
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
|
|
576
|
-
|
|
655
|
+
const submit = document.createElement('input');
|
|
656
|
+
submit.type = 'submit';
|
|
657
|
+
form.appendChild(submit);
|
|
577
658
|
|
|
578
|
-
if (target) {
|
|
659
|
+
if (target) {
|
|
660
|
+
form.setAttribute('target', target);
|
|
661
|
+
}
|
|
579
662
|
|
|
580
663
|
form.style.display = 'none';
|
|
581
|
-
form.innerHTML = formContent;
|
|
582
664
|
document.body.appendChild(form);
|
|
583
|
-
|
|
665
|
+
submit.click();
|
|
584
666
|
|
|
585
667
|
event.preventDefault();
|
|
586
668
|
};
|
|
@@ -595,7 +677,7 @@
|
|
|
595
677
|
Modal,
|
|
596
678
|
SearchContext,
|
|
597
679
|
Core,
|
|
598
|
-
onLoad: Core.onLoad
|
|
680
|
+
onLoad: Core.onLoad,
|
|
599
681
|
};
|
|
600
682
|
|
|
601
683
|
return index;
|