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