blacklight-frontend 7.20.1 → 7.22.1

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/README.md CHANGED
@@ -39,7 +39,7 @@ rails generate blacklight:install
39
39
 
40
40
  ## Contributing Code
41
41
 
42
- Code contributions are always welcome, instructions for contributing can be found at [CONTRIBUTING.md](https://github.com/projectblacklight/blacklight/blob/master/CONTRIBUTING.md).
42
+ Code contributions are always welcome, instructions for contributing can be found at [CONTRIBUTING.md](https://github.com/projectblacklight/blacklight/blob/main/CONTRIBUTING.md).
43
43
 
44
44
  ## Configuring Apache Solr
45
45
  You'll also want some information about how Blacklight expects [Apache Solr](http://lucene.apache.org/solr ) to run, which you can find in [README_SOLR](https://github.com/projectblacklight/blacklight/wiki/README_SOLR)
@@ -1,18 +1,22 @@
1
- Blacklight = function () {
1
+ "use strict";
2
+
3
+ var Blacklight = function () {
2
4
  var buffer = new Array();
3
5
  return {
4
- onLoad: function (func) {
6
+ onLoad: function onLoad(func) {
5
7
  buffer.push(func);
6
8
  },
7
- activate: function () {
9
+ activate: function activate() {
8
10
  for (var i = 0; i < buffer.length; i++) {
9
11
  buffer[i].call();
10
12
  }
11
13
  },
12
- listeners: function () {
14
+ listeners: function listeners() {
13
15
  var listeners = [];
14
16
 
15
- if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
17
+ if (typeof Turbo !== 'undefined') {
18
+ listeners.push('turbo:load');
19
+ } else if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
16
20
  // Turbolinks 5
17
21
  if (Turbolinks.BrowserAdapter) {
18
22
  listeners.push('turbolinks:load');
@@ -37,11 +41,14 @@ Blacklight.listeners().forEach(function (listener) {
37
41
  });
38
42
  });
39
43
  Blacklight.onLoad(function () {
40
- const elem = document.querySelector('.no-js');
44
+ var elem = document.querySelector('.no-js'); // The "no-js" class may already have been removed because this function is
45
+ // run on every turbo:load event, in that case, it won't find an element.
46
+
41
47
  if (!elem) return;
42
48
  elem.classList.remove('no-js');
43
49
  elem.classList.add('js');
44
50
  });
51
+ window.Blacklight = Blacklight;
45
52
  /*global Bloodhound */
46
53
 
47
54
  Blacklight.onLoad(function () {
@@ -87,7 +94,7 @@ Blacklight.onLoad(function () {
87
94
  $(Blacklight.doBookmarkToggleBehavior.selector).blCheckboxSubmit({
88
95
  // cssClass is added to elements added, plus used for id base
89
96
  cssClass: 'toggle-bookmark',
90
- success: function (checked, response) {
97
+ success: function success(checked, response) {
91
98
  if (response.bookmarks) {
92
99
  $('[data-role=bookmark-counter]').text(response.bookmarks.count);
93
100
  }
@@ -105,8 +112,8 @@ Blacklight.onLoad(function () {
105
112
  // Button clicks should change focus. As of 10/3/19, Firefox for Mac and
106
113
  // Safari both do not set focus to a button on button click.
107
114
  // See https://zellwk.com/blog/inconsistent-button-behavior/ for background information
108
- document.querySelectorAll('button.collapse-toggle').forEach(button => {
109
- button.addEventListener('click', () => {
115
+ document.querySelectorAll('button.collapse-toggle').forEach(function (button) {
116
+ button.addEventListener('click', function () {
110
117
  event.target.focus();
111
118
  });
112
119
  });
@@ -193,12 +200,12 @@ Blacklight.onLoad(function () {
193
200
  dataType: 'json',
194
201
  type: form.attr('method').toUpperCase(),
195
202
  data: form.serialize(),
196
- error: function () {
203
+ error: function error() {
197
204
  label.removeAttr('disabled');
198
205
  checkbox.removeAttr('disabled');
199
206
  options.error.call();
200
207
  },
201
- success: function (data, status, xhr) {
208
+ success: function success(data, status, xhr) {
202
209
  //if app isn't running at all, xhr annoyingly
203
210
  //reports success with status 0.
204
211
  if (xhr.status != 0) {
@@ -224,10 +231,10 @@ Blacklight.onLoad(function () {
224
231
  $.fn.blCheckboxSubmit.defaults = {
225
232
  //cssClass is added to elements added, plus used for id base
226
233
  cssClass: 'blCheckboxSubmit',
227
- error: function () {
234
+ error: function error() {
228
235
  alert("Error");
229
236
  },
230
- success: function () {} //callback
237
+ success: function success() {} //callback
231
238
 
232
239
  };
233
240
  })(jQuery);
@@ -243,12 +250,12 @@ Blacklight.doResizeFacetLabelsAndCounts = function () {
243
250
  }
244
251
 
245
252
  document.querySelectorAll('.facet-values, .pivot-facet').forEach(function (elem) {
246
- const nodes = elem.querySelectorAll('.facet-count'); // TODO: when we drop ie11 support, this can become the spread operator:
253
+ var nodes = elem.querySelectorAll('.facet-count'); // TODO: when we drop ie11 support, this can become the spread operator:
247
254
 
248
- const longest = Array.from(nodes).sort(longer)[0];
255
+ var longest = Array.from(nodes).sort(longer)[0];
249
256
 
250
257
  if (longest && longest.textContent) {
251
- const width = longest.textContent.length + 1 + 'ch';
258
+ var width = longest.textContent.length + 1 + 'ch';
252
259
  elem.querySelector('.facet-count').style.width = width;
253
260
  }
254
261
  });
@@ -359,13 +366,13 @@ Blacklight.modal.onFailure = function (jqXHR, textStatus, errorThrown) {
359
366
  console.error('Server error:', this.url, jqXHR.status, errorThrown);
360
367
  var contents = '<div class="modal-header">' + '<div class="modal-title">There was a problem with your request.</div>' + '<button type="button" class="blacklight-modal-close btn-close close" data-dismiss="modal" aria-label="Close">' + ' <span aria-hidden="true">&times;</span>' + '</button></div>' + ' <div class="modal-body"><p>Expected a successful response from the server, but got an error</p>' + '<pre>' + this.type + ' ' + this.url + "\n" + jqXHR.status + ': ' + errorThrown + '</pre></div>';
361
368
  $(Blacklight.modal.modalSelector).find('.modal-content').html(contents);
362
- $(Blacklight.modal.modalSelector).modal('show');
369
+ Blacklight.modal.show();
363
370
  };
364
371
 
365
372
  Blacklight.modal.receiveAjax = function (contents) {
366
373
  // does it have a data- selector for container?
367
374
  // important we don't execute script tags, we shouldn't.
368
- // code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/master/src/ajax/load.js?source=c#L62
375
+ // code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/main/src/ajax/load.js?source=c#L62
369
376
  var container = $('<div>').append(jQuery.parseHTML(contents)).find(Blacklight.modal.containerSelector).first();
370
377
 
371
378
  if (container.length !== 0) {
@@ -378,7 +385,7 @@ Blacklight.modal.receiveAjax = function (contents) {
378
385
  $(Blacklight.modal.modalSelector).trigger(e); // if they did preventDefault, don't show the dialog
379
386
 
380
387
  if (e.isDefaultPrevented()) return;
381
- $(Blacklight.modal.modalSelector).modal('show');
388
+ Blacklight.modal.show();
382
389
  };
383
390
 
384
391
  Blacklight.modal.modalAjaxLinkClick = function (e) {
@@ -425,7 +432,7 @@ Blacklight.modal.setupModal = function () {
425
432
  Blacklight.modal.checkCloseModal = function (event) {
426
433
  if ($(event.target).find(Blacklight.modal.modalCloseSelector).length) {
427
434
  var modalFlashes = $(this).find('.flash_messages');
428
- $(event.target).modal('hide');
435
+ Blacklight.modal.hide(event.target);
429
436
  event.preventDefault();
430
437
  var mainFlashes = $('#main-flashes');
431
438
  mainFlashes.append(modalFlashes);
@@ -433,6 +440,22 @@ Blacklight.modal.checkCloseModal = function (event) {
433
440
  }
434
441
  };
435
442
 
443
+ Blacklight.modal.hide = function (el) {
444
+ if (bootstrap.Modal.VERSION >= "5") {
445
+ bootstrap.Modal.getOrCreateInstance(el || document.querySelector(Blacklight.modal.modalSelector)).hide();
446
+ } else {
447
+ $(el || Blacklight.modal.modalSelector).modal('hide');
448
+ }
449
+ };
450
+
451
+ Blacklight.modal.show = function (el) {
452
+ if (bootstrap.Modal.VERSION >= "5") {
453
+ bootstrap.Modal.getOrCreateInstance(el || document.querySelector(Blacklight.modal.modalSelector)).show();
454
+ } else {
455
+ $(el || Blacklight.modal.modalSelector).modal('show');
456
+ }
457
+ };
458
+
436
459
  Blacklight.onLoad(function () {
437
460
  Blacklight.modal.setupModal();
438
461
  });
@@ -443,9 +466,9 @@ Blacklight.doSearchContextBehavior = function () {
443
466
  return Blacklight.do_search_context_behavior();
444
467
  }
445
468
 
446
- const elements = document.querySelectorAll('a[data-context-href]'); // Equivalent to Array.from(), but supports ie11
469
+ var elements = document.querySelectorAll('a[data-context-href]'); // Equivalent to Array.from(), but supports ie11
447
470
 
448
- const nodes = Array.prototype.slice.call(elements);
471
+ var nodes = Array.prototype.slice.call(elements);
449
472
  nodes.forEach(function (element) {
450
473
  element.addEventListener('click', function (e) {
451
474
  Blacklight.handleSearchContextMethod.call(e.currentTarget, e);
@@ -453,9 +476,17 @@ Blacklight.doSearchContextBehavior = function () {
453
476
  });
454
477
  };
455
478
 
456
- Blacklight.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content;
479
+ Blacklight.csrfToken = function () {
480
+ var _document$querySelect;
481
+
482
+ return (_document$querySelect = document.querySelector('meta[name=csrf-token]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.content;
483
+ };
484
+
485
+ Blacklight.csrfParam = function () {
486
+ var _document$querySelect2;
457
487
 
458
- Blacklight.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content; // this is the Rails.handleMethod with a couple adjustments, described inline:
488
+ return (_document$querySelect2 = document.querySelector('meta[name=csrf-param]')) === null || _document$querySelect2 === void 0 ? void 0 : _document$querySelect2.content;
489
+ }; // this is the Rails.handleMethod with a couple adjustments, described inline:
459
490
  // first, we're attaching this directly to the event handler, so we can check for meta-keys
460
491
 
461
492
 
@@ -467,22 +498,21 @@ Blacklight.handleSearchContextMethod = function (event) {
467
498
 
468
499
  var link = this; // instead of using the normal href, we need to use the context href instead
469
500
 
470
- let href = link.getAttribute('data-context-href');
471
- let target = link.getAttribute('target');
472
- let csrfToken = Blacklight.csrfToken();
473
- let csrfParam = Blacklight.csrfParam();
474
- let form = document.createElement('form');
501
+ var href = link.getAttribute('data-context-href');
502
+ var target = link.getAttribute('target');
503
+ var csrfToken = Blacklight.csrfToken();
504
+ var csrfParam = Blacklight.csrfParam();
505
+ var form = document.createElement('form');
475
506
  form.method = 'post';
476
507
  form.action = href;
477
- let formContent = `<input name="_method" value="post" type="hidden" />
478
- <input name="redirect" value="${link.getAttribute('href')}" type="hidden" />`; // check for meta keys.. if set, we should open in a new tab
508
+ var formContent = "<input name=\"_method\" value=\"post\" type=\"hidden\" />\n <input name=\"redirect\" value=\"".concat(link.getAttribute('href'), "\" type=\"hidden\" />"); // check for meta keys.. if set, we should open in a new tab
479
509
 
480
510
  if (event.metaKey || event.ctrlKey) {
481
511
  target = '_blank';
482
512
  }
483
513
 
484
514
  if (csrfParam !== undefined && csrfToken !== undefined) {
485
- formContent += `<input name="${csrfParam}" value="${csrfToken}" type="hidden" />`;
515
+ formContent += "<input name=\"".concat(csrfParam, "\" value=\"").concat(csrfToken, "\" type=\"hidden\" />");
486
516
  } // Must trigger submit by click on a button, else "submit" event handler won't work!
487
517
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
488
518
 
@@ -1,6 +1,8 @@
1
1
  .constraints-container {
2
2
  @extend .mb-2;
3
- @extend .d-flex;
3
+ display: flex;
4
+ flex-wrap: wrap;
5
+ gap: 0.5rem 0.25rem;
4
6
  }
5
7
 
6
8
  .applied-filter {
@@ -1,5 +1,6 @@
1
1
  .search-widgets {
2
- @extend .d-flex;
2
+ display: flex;
3
+
3
4
  > * {
4
5
  @extend .mx-1;
5
6
  }
@@ -1,4 +1,4 @@
1
- Blacklight = function() {
1
+ const Blacklight = function() {
2
2
  var buffer = new Array;
3
3
  return {
4
4
  onLoad: function(func) {
@@ -13,7 +13,9 @@ Blacklight = function() {
13
13
 
14
14
  listeners: function () {
15
15
  var listeners = [];
16
- if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
16
+ if (typeof Turbo !== 'undefined') {
17
+ listeners.push('turbo:load');
18
+ } else if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
17
19
  // Turbolinks 5
18
20
  if (Turbolinks.BrowserAdapter) {
19
21
  listeners.push('turbolinks:load');
@@ -41,8 +43,12 @@ Blacklight.listeners().forEach(function(listener) {
41
43
  Blacklight.onLoad(function () {
42
44
  const elem = document.querySelector('.no-js');
43
45
 
46
+ // The "no-js" class may already have been removed because this function is
47
+ // run on every turbo:load event, in that case, it won't find an element.
44
48
  if (!elem) return;
45
49
 
46
50
  elem.classList.remove('no-js')
47
51
  elem.classList.add('js')
48
52
  })
53
+
54
+ window.Blacklight = Blacklight
@@ -114,13 +114,13 @@ Blacklight.modal.onFailure = function(jqXHR, textStatus, errorThrown) {
114
114
  this.type + ' ' + this.url + "\n" + jqXHR.status + ': ' + errorThrown +
115
115
  '</pre></div>';
116
116
  $(Blacklight.modal.modalSelector).find('.modal-content').html(contents);
117
- $(Blacklight.modal.modalSelector).modal('show');
117
+ Blacklight.modal.show();
118
118
  }
119
119
 
120
120
  Blacklight.modal.receiveAjax = function (contents) {
121
121
  // does it have a data- selector for container?
122
122
  // important we don't execute script tags, we shouldn't.
123
- // code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/master/src/ajax/load.js?source=c#L62
123
+ // code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/main/src/ajax/load.js?source=c#L62
124
124
  var container = $('<div>').
125
125
  append( jQuery.parseHTML(contents) ).find( Blacklight.modal.containerSelector ).first();
126
126
  if (container.length !== 0) {
@@ -135,7 +135,7 @@ Blacklight.modal.receiveAjax = function (contents) {
135
135
  // if they did preventDefault, don't show the dialog
136
136
  if (e.isDefaultPrevented()) return;
137
137
 
138
- $(Blacklight.modal.modalSelector).modal('show');
138
+ Blacklight.modal.show();
139
139
  };
140
140
 
141
141
 
@@ -196,7 +196,7 @@ Blacklight.modal.checkCloseModal = function(event) {
196
196
  if ($(event.target).find(Blacklight.modal.modalCloseSelector).length) {
197
197
  var modalFlashes = $(this).find('.flash_messages');
198
198
 
199
- $(event.target).modal('hide');
199
+ Blacklight.modal.hide(event.target);
200
200
  event.preventDefault();
201
201
 
202
202
  var mainFlashes = $('#main-flashes');
@@ -205,6 +205,22 @@ Blacklight.modal.checkCloseModal = function(event) {
205
205
  }
206
206
  }
207
207
 
208
+ Blacklight.modal.hide = function(el) {
209
+ if (bootstrap.Modal.VERSION >= "5") {
210
+ bootstrap.Modal.getOrCreateInstance(el || document.querySelector(Blacklight.modal.modalSelector)).hide();
211
+ } else {
212
+ $(el || Blacklight.modal.modalSelector).modal('hide');
213
+ }
214
+ }
215
+
216
+ Blacklight.modal.show = function(el) {
217
+ if (bootstrap.Modal.VERSION >= "5") {
218
+ bootstrap.Modal.getOrCreateInstance(el || document.querySelector(Blacklight.modal.modalSelector)).show();
219
+ } else {
220
+ $(el || Blacklight.modal.modalSelector).modal('show');
221
+ }
222
+ }
223
+
208
224
  Blacklight.onLoad(function() {
209
225
  Blacklight.modal.setupModal();
210
226
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "blacklight-frontend",
3
- "version": "7.20.1",
4
- "description": "[![Build Status](https://travis-ci.com/projectblacklight/blacklight.png?branch=master)](https://travis-ci.com/projectblacklight/blacklight) [![Gem Version](https://badge.fury.io/rb/blacklight.png)](http://badge.fury.io/rb/blacklight) [![Coverage Status](https://coveralls.io/repos/github/projectblacklight/blacklight/badge.svg?branch=master)](https://coveralls.io/github/projectblacklight/blacklight?branch=master)",
3
+ "version": "7.22.1",
4
+ "description": "[![Build Status](https://travis-ci.com/projectblacklight/blacklight.png?branch=main)](https://travis-ci.com/projectblacklight/blacklight) [![Gem Version](https://badge.fury.io/rb/blacklight.png)](http://badge.fury.io/rb/blacklight) [![Coverage Status](https://coveralls.io/repos/github/projectblacklight/blacklight/badge.svg?branch=main)](https://coveralls.io/github/projectblacklight/blacklight?branch=main)",
5
5
  "main": "app/assets/javascripts/blacklight",
6
6
  "scripts": {
7
7
  "js-compile-bundle": "shx cat app/javascript/blacklight/core.js app/javascript/blacklight/autocomplete.js app/javascript/blacklight/bookmark_toggle.js app/javascript/blacklight/button_focus.js app/javascript/blacklight/checkbox_submit.js app/javascript/blacklight/facet_load.js app/javascript/blacklight/modal.js app/javascript/blacklight/search_context.js | shx sed \"s/^(import|export).*//\" | babel --filename app/javascript/blacklight/blacklight.js > app/assets/javascripts/blacklight/blacklight.js"
@@ -23,8 +23,10 @@
23
23
  "devDependencies": {
24
24
  "@babel/cli": "^7.2.3",
25
25
  "@babel/core": "^7.2.3",
26
+ "@babel/preset-env": "^7.16.0",
26
27
  "shx": "^0.3.2"
27
28
  },
29
+ "browserslist": "> 0.25%, not dead",
28
30
  "dependencies": {
29
31
  "bloodhound-js": "^1.2.3",
30
32
  "bootstrap": ">=4.3.1 <6.0.0",