blacklight-frontend 7.20.0 → 7.22.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/README.md +1 -1
- package/app/assets/javascripts/blacklight/blacklight.js +63 -32
- package/app/assets/stylesheets/blacklight/_constraints.scss +3 -1
- package/app/assets/stylesheets/blacklight/_controls.scss +2 -1
- package/app/javascript/blacklight/core.js +12 -3
- package/app/javascript/blacklight/modal.js +20 -4
- package/package.json +4 -2
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/
|
|
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
|
-
|
|
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
|
|
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,10 +41,14 @@ Blacklight.listeners().forEach(function (listener) {
|
|
|
37
41
|
});
|
|
38
42
|
});
|
|
39
43
|
Blacklight.onLoad(function () {
|
|
40
|
-
|
|
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
|
+
|
|
47
|
+
if (!elem) return;
|
|
41
48
|
elem.classList.remove('no-js');
|
|
42
49
|
elem.classList.add('js');
|
|
43
50
|
});
|
|
51
|
+
window.Blacklight = Blacklight;
|
|
44
52
|
/*global Bloodhound */
|
|
45
53
|
|
|
46
54
|
Blacklight.onLoad(function () {
|
|
@@ -86,7 +94,7 @@ Blacklight.onLoad(function () {
|
|
|
86
94
|
$(Blacklight.doBookmarkToggleBehavior.selector).blCheckboxSubmit({
|
|
87
95
|
// cssClass is added to elements added, plus used for id base
|
|
88
96
|
cssClass: 'toggle-bookmark',
|
|
89
|
-
success: function (checked, response) {
|
|
97
|
+
success: function success(checked, response) {
|
|
90
98
|
if (response.bookmarks) {
|
|
91
99
|
$('[data-role=bookmark-counter]').text(response.bookmarks.count);
|
|
92
100
|
}
|
|
@@ -104,8 +112,8 @@ Blacklight.onLoad(function () {
|
|
|
104
112
|
// Button clicks should change focus. As of 10/3/19, Firefox for Mac and
|
|
105
113
|
// Safari both do not set focus to a button on button click.
|
|
106
114
|
// See https://zellwk.com/blog/inconsistent-button-behavior/ for background information
|
|
107
|
-
document.querySelectorAll('button.collapse-toggle').forEach(button
|
|
108
|
-
button.addEventListener('click', ()
|
|
115
|
+
document.querySelectorAll('button.collapse-toggle').forEach(function (button) {
|
|
116
|
+
button.addEventListener('click', function () {
|
|
109
117
|
event.target.focus();
|
|
110
118
|
});
|
|
111
119
|
});
|
|
@@ -192,12 +200,12 @@ Blacklight.onLoad(function () {
|
|
|
192
200
|
dataType: 'json',
|
|
193
201
|
type: form.attr('method').toUpperCase(),
|
|
194
202
|
data: form.serialize(),
|
|
195
|
-
error: function () {
|
|
203
|
+
error: function error() {
|
|
196
204
|
label.removeAttr('disabled');
|
|
197
205
|
checkbox.removeAttr('disabled');
|
|
198
206
|
options.error.call();
|
|
199
207
|
},
|
|
200
|
-
success: function (data, status, xhr) {
|
|
208
|
+
success: function success(data, status, xhr) {
|
|
201
209
|
//if app isn't running at all, xhr annoyingly
|
|
202
210
|
//reports success with status 0.
|
|
203
211
|
if (xhr.status != 0) {
|
|
@@ -223,10 +231,10 @@ Blacklight.onLoad(function () {
|
|
|
223
231
|
$.fn.blCheckboxSubmit.defaults = {
|
|
224
232
|
//cssClass is added to elements added, plus used for id base
|
|
225
233
|
cssClass: 'blCheckboxSubmit',
|
|
226
|
-
error: function () {
|
|
234
|
+
error: function error() {
|
|
227
235
|
alert("Error");
|
|
228
236
|
},
|
|
229
|
-
success: function () {} //callback
|
|
237
|
+
success: function success() {} //callback
|
|
230
238
|
|
|
231
239
|
};
|
|
232
240
|
})(jQuery);
|
|
@@ -242,12 +250,12 @@ Blacklight.doResizeFacetLabelsAndCounts = function () {
|
|
|
242
250
|
}
|
|
243
251
|
|
|
244
252
|
document.querySelectorAll('.facet-values, .pivot-facet').forEach(function (elem) {
|
|
245
|
-
|
|
253
|
+
var nodes = elem.querySelectorAll('.facet-count'); // TODO: when we drop ie11 support, this can become the spread operator:
|
|
246
254
|
|
|
247
|
-
|
|
255
|
+
var longest = Array.from(nodes).sort(longer)[0];
|
|
248
256
|
|
|
249
257
|
if (longest && longest.textContent) {
|
|
250
|
-
|
|
258
|
+
var width = longest.textContent.length + 1 + 'ch';
|
|
251
259
|
elem.querySelector('.facet-count').style.width = width;
|
|
252
260
|
}
|
|
253
261
|
});
|
|
@@ -358,13 +366,13 @@ Blacklight.modal.onFailure = function (jqXHR, textStatus, errorThrown) {
|
|
|
358
366
|
console.error('Server error:', this.url, jqXHR.status, errorThrown);
|
|
359
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">×</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>';
|
|
360
368
|
$(Blacklight.modal.modalSelector).find('.modal-content').html(contents);
|
|
361
|
-
|
|
369
|
+
Blacklight.modal.show();
|
|
362
370
|
};
|
|
363
371
|
|
|
364
372
|
Blacklight.modal.receiveAjax = function (contents) {
|
|
365
373
|
// does it have a data- selector for container?
|
|
366
374
|
// important we don't execute script tags, we shouldn't.
|
|
367
|
-
// code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/
|
|
375
|
+
// code modelled off of JQuery ajax.load. https://github.com/jquery/jquery/blob/main/src/ajax/load.js?source=c#L62
|
|
368
376
|
var container = $('<div>').append(jQuery.parseHTML(contents)).find(Blacklight.modal.containerSelector).first();
|
|
369
377
|
|
|
370
378
|
if (container.length !== 0) {
|
|
@@ -377,7 +385,7 @@ Blacklight.modal.receiveAjax = function (contents) {
|
|
|
377
385
|
$(Blacklight.modal.modalSelector).trigger(e); // if they did preventDefault, don't show the dialog
|
|
378
386
|
|
|
379
387
|
if (e.isDefaultPrevented()) return;
|
|
380
|
-
|
|
388
|
+
Blacklight.modal.show();
|
|
381
389
|
};
|
|
382
390
|
|
|
383
391
|
Blacklight.modal.modalAjaxLinkClick = function (e) {
|
|
@@ -424,7 +432,7 @@ Blacklight.modal.setupModal = function () {
|
|
|
424
432
|
Blacklight.modal.checkCloseModal = function (event) {
|
|
425
433
|
if ($(event.target).find(Blacklight.modal.modalCloseSelector).length) {
|
|
426
434
|
var modalFlashes = $(this).find('.flash_messages');
|
|
427
|
-
|
|
435
|
+
Blacklight.modal.hide(event.target);
|
|
428
436
|
event.preventDefault();
|
|
429
437
|
var mainFlashes = $('#main-flashes');
|
|
430
438
|
mainFlashes.append(modalFlashes);
|
|
@@ -432,6 +440,22 @@ Blacklight.modal.checkCloseModal = function (event) {
|
|
|
432
440
|
}
|
|
433
441
|
};
|
|
434
442
|
|
|
443
|
+
Blacklight.modal.hide = function (el) {
|
|
444
|
+
if (bootstrap.Modal.VERSION >= "5") {
|
|
445
|
+
bootstrap.Modal.getOrCreateInstance(el).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).show();
|
|
454
|
+
} else {
|
|
455
|
+
$(el || Blacklight.modal.modalSelector).modal('show');
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
|
|
435
459
|
Blacklight.onLoad(function () {
|
|
436
460
|
Blacklight.modal.setupModal();
|
|
437
461
|
});
|
|
@@ -442,9 +466,9 @@ Blacklight.doSearchContextBehavior = function () {
|
|
|
442
466
|
return Blacklight.do_search_context_behavior();
|
|
443
467
|
}
|
|
444
468
|
|
|
445
|
-
|
|
469
|
+
var elements = document.querySelectorAll('a[data-context-href]'); // Equivalent to Array.from(), but supports ie11
|
|
446
470
|
|
|
447
|
-
|
|
471
|
+
var nodes = Array.prototype.slice.call(elements);
|
|
448
472
|
nodes.forEach(function (element) {
|
|
449
473
|
element.addEventListener('click', function (e) {
|
|
450
474
|
Blacklight.handleSearchContextMethod.call(e.currentTarget, e);
|
|
@@ -452,9 +476,17 @@ Blacklight.doSearchContextBehavior = function () {
|
|
|
452
476
|
});
|
|
453
477
|
};
|
|
454
478
|
|
|
455
|
-
Blacklight.csrfToken = ()
|
|
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;
|
|
456
487
|
|
|
457
|
-
|
|
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:
|
|
458
490
|
// first, we're attaching this directly to the event handler, so we can check for meta-keys
|
|
459
491
|
|
|
460
492
|
|
|
@@ -466,22 +498,21 @@ Blacklight.handleSearchContextMethod = function (event) {
|
|
|
466
498
|
|
|
467
499
|
var link = this; // instead of using the normal href, we need to use the context href instead
|
|
468
500
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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');
|
|
474
506
|
form.method = 'post';
|
|
475
507
|
form.action = href;
|
|
476
|
-
|
|
477
|
-
<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
|
|
478
509
|
|
|
479
510
|
if (event.metaKey || event.ctrlKey) {
|
|
480
511
|
target = '_blank';
|
|
481
512
|
}
|
|
482
513
|
|
|
483
514
|
if (csrfParam !== undefined && csrfToken !== undefined) {
|
|
484
|
-
formContent +=
|
|
515
|
+
formContent += "<input name=\"".concat(csrfParam, "\" value=\"").concat(csrfToken, "\" type=\"hidden\" />");
|
|
485
516
|
} // Must trigger submit by click on a button, else "submit" event handler won't work!
|
|
486
517
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
|
|
487
518
|
|
|
@@ -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
|
|
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');
|
|
@@ -39,7 +41,14 @@ Blacklight.listeners().forEach(function(listener) {
|
|
|
39
41
|
})
|
|
40
42
|
|
|
41
43
|
Blacklight.onLoad(function () {
|
|
42
|
-
const elem = document.querySelector('.no-js')
|
|
44
|
+
const elem = document.querySelector('.no-js');
|
|
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.
|
|
48
|
+
if (!elem) return;
|
|
49
|
+
|
|
43
50
|
elem.classList.remove('no-js')
|
|
44
51
|
elem.classList.add('js')
|
|
45
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
|
-
|
|
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/
|
|
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
|
-
|
|
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
|
-
|
|
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).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).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.
|
|
4
|
-
"description": "[](https://travis-ci.com/projectblacklight/blacklight) [](http://badge.fury.io/rb/blacklight) [](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",
|