blacklight-frontend 7.33.1 → 7.37.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.
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const Blacklight = function () {
|
|
4
4
|
var buffer = new Array();
|
|
5
5
|
return {
|
|
6
|
-
onLoad: function
|
|
6
|
+
onLoad: function (func) {
|
|
7
7
|
buffer.push(func);
|
|
8
8
|
},
|
|
9
|
-
activate: function
|
|
9
|
+
activate: function () {
|
|
10
10
|
for (var i = 0; i < buffer.length; i++) {
|
|
11
11
|
buffer[i].call();
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
listeners: function
|
|
14
|
+
listeners: function () {
|
|
15
15
|
var listeners = [];
|
|
16
16
|
if (typeof Turbo !== 'undefined') {
|
|
17
17
|
listeners.push('turbo:load');
|
|
@@ -39,7 +39,7 @@ Blacklight.listeners().forEach(function (listener) {
|
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
41
|
Blacklight.onLoad(function () {
|
|
42
|
-
|
|
42
|
+
const elem = document.querySelector('.no-js');
|
|
43
43
|
|
|
44
44
|
// The "no-js" class may already have been removed because this function is
|
|
45
45
|
// run on every turbo:load event, in that case, it won't find an element.
|
|
@@ -47,6 +47,14 @@ Blacklight.onLoad(function () {
|
|
|
47
47
|
elem.classList.remove('no-js');
|
|
48
48
|
elem.classList.add('js');
|
|
49
49
|
});
|
|
50
|
+
Blacklight.csrfToken = () => {
|
|
51
|
+
var _document$querySelect;
|
|
52
|
+
return (_document$querySelect = document.querySelector('meta[name=csrf-token]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.content;
|
|
53
|
+
};
|
|
54
|
+
Blacklight.csrfParam = () => {
|
|
55
|
+
var _document$querySelect2;
|
|
56
|
+
return (_document$querySelect2 = document.querySelector('meta[name=csrf-param]')) === null || _document$querySelect2 === void 0 ? void 0 : _document$querySelect2.content;
|
|
57
|
+
};
|
|
50
58
|
window.Blacklight = Blacklight;
|
|
51
59
|
/*global Bloodhound */
|
|
52
60
|
|
|
@@ -89,7 +97,7 @@ Blacklight.onLoad(function () {
|
|
|
89
97
|
$(Blacklight.doBookmarkToggleBehavior.selector).blCheckboxSubmit({
|
|
90
98
|
// cssClass is added to elements added, plus used for id base
|
|
91
99
|
cssClass: 'toggle-bookmark',
|
|
92
|
-
success: function
|
|
100
|
+
success: function (checked, response) {
|
|
93
101
|
if (response.bookmarks) {
|
|
94
102
|
$('[data-role=bookmark-counter]').text(response.bookmarks.count);
|
|
95
103
|
}
|
|
@@ -105,8 +113,8 @@ Blacklight.onLoad(function () {
|
|
|
105
113
|
// Button clicks should change focus. As of 10/3/19, Firefox for Mac and
|
|
106
114
|
// Safari both do not set focus to a button on button click.
|
|
107
115
|
// See https://zellwk.com/blog/inconsistent-button-behavior/ for background information
|
|
108
|
-
document.querySelectorAll('button.collapse-toggle').forEach(
|
|
109
|
-
button.addEventListener('click',
|
|
116
|
+
document.querySelectorAll('button.collapse-toggle').forEach(button => {
|
|
117
|
+
button.addEventListener('click', () => {
|
|
110
118
|
event.target.focus();
|
|
111
119
|
});
|
|
112
120
|
});
|
|
@@ -187,15 +195,18 @@ Blacklight.onLoad(function () {
|
|
|
187
195
|
checkbox.attr('disabled', 'disabled');
|
|
188
196
|
$.ajax({
|
|
189
197
|
url: form.attr('action'),
|
|
198
|
+
beforeSend: function (xhr) {
|
|
199
|
+
xhr.setRequestHeader('X-CSRF-Token', Blacklight.csrfToken());
|
|
200
|
+
},
|
|
190
201
|
dataType: 'json',
|
|
191
202
|
type: form.attr('method').toUpperCase(),
|
|
192
203
|
data: form.serialize(),
|
|
193
|
-
error: function
|
|
204
|
+
error: function () {
|
|
194
205
|
label.removeAttr('disabled');
|
|
195
206
|
checkbox.removeAttr('disabled');
|
|
196
207
|
options.error.call();
|
|
197
208
|
},
|
|
198
|
-
success: function
|
|
209
|
+
success: function (data, status, xhr) {
|
|
199
210
|
//if app isn't running at all, xhr annoyingly
|
|
200
211
|
//reports success with status 0.
|
|
201
212
|
if (xhr.status != 0) {
|
|
@@ -219,10 +230,10 @@ Blacklight.onLoad(function () {
|
|
|
219
230
|
$.fn.blCheckboxSubmit.defaults = {
|
|
220
231
|
//cssClass is added to elements added, plus used for id base
|
|
221
232
|
cssClass: 'blCheckboxSubmit',
|
|
222
|
-
error: function
|
|
233
|
+
error: function () {
|
|
223
234
|
alert("Error");
|
|
224
235
|
},
|
|
225
|
-
success: function
|
|
236
|
+
success: function () {} //callback
|
|
226
237
|
};
|
|
227
238
|
})(jQuery);
|
|
228
239
|
/*global Blacklight */
|
|
@@ -234,11 +245,11 @@ Blacklight.doResizeFacetLabelsAndCounts = function () {
|
|
|
234
245
|
return b.textContent.length - a.textContent.length;
|
|
235
246
|
}
|
|
236
247
|
document.querySelectorAll('.facet-values, .pivot-facet').forEach(function (elem) {
|
|
237
|
-
|
|
248
|
+
const nodes = elem.querySelectorAll('.facet-count');
|
|
238
249
|
// TODO: when we drop ie11 support, this can become the spread operator:
|
|
239
|
-
|
|
250
|
+
const longest = Array.from(nodes).sort(longer)[0];
|
|
240
251
|
if (longest && longest.textContent) {
|
|
241
|
-
|
|
252
|
+
const width = longest.textContent.length + 1 + 'ch';
|
|
242
253
|
elem.querySelector('.facet-count').style.width = width;
|
|
243
254
|
}
|
|
244
255
|
});
|
|
@@ -443,23 +454,15 @@ Blacklight.doSearchContextBehavior = function () {
|
|
|
443
454
|
console.warn("do_search_context_behavior is deprecated. Use doSearchContextBehavior instead.");
|
|
444
455
|
return Blacklight.do_search_context_behavior();
|
|
445
456
|
}
|
|
446
|
-
|
|
457
|
+
const elements = document.querySelectorAll('a[data-context-href]');
|
|
447
458
|
// Equivalent to Array.from(), but supports ie11
|
|
448
|
-
|
|
459
|
+
const nodes = Array.prototype.slice.call(elements);
|
|
449
460
|
nodes.forEach(function (element) {
|
|
450
461
|
element.addEventListener('click', function (e) {
|
|
451
462
|
Blacklight.handleSearchContextMethod.call(e.currentTarget, e);
|
|
452
463
|
});
|
|
453
464
|
});
|
|
454
465
|
};
|
|
455
|
-
Blacklight.csrfToken = function () {
|
|
456
|
-
var _document$querySelect;
|
|
457
|
-
return (_document$querySelect = document.querySelector('meta[name=csrf-token]')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.content;
|
|
458
|
-
};
|
|
459
|
-
Blacklight.csrfParam = function () {
|
|
460
|
-
var _document$querySelect2;
|
|
461
|
-
return (_document$querySelect2 = document.querySelector('meta[name=csrf-param]')) === null || _document$querySelect2 === void 0 ? void 0 : _document$querySelect2.content;
|
|
462
|
-
};
|
|
463
466
|
|
|
464
467
|
// this is the Rails.handleMethod with a couple adjustments, described inline:
|
|
465
468
|
// first, we're attaching this directly to the event handler, so we can check for meta-keys
|
|
@@ -471,17 +474,18 @@ Blacklight.handleSearchContextMethod = function (event) {
|
|
|
471
474
|
var link = this;
|
|
472
475
|
|
|
473
476
|
// instead of using the normal href, we need to use the context href instead
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
477
|
+
let href = link.getAttribute('data-context-href');
|
|
478
|
+
let target = link.getAttribute('target');
|
|
479
|
+
let csrfToken = Blacklight.csrfToken();
|
|
480
|
+
let csrfParam = Blacklight.csrfParam();
|
|
481
|
+
let form = document.createElement('form');
|
|
479
482
|
form.method = 'post';
|
|
480
483
|
form.action = href;
|
|
481
|
-
|
|
484
|
+
let formContent = "<input name=\"_method\" value=\"post\" type=\"hidden\" />\n <input name=\"redirect\" value=\"".concat(link.getAttribute('href'), "\" type=\"hidden\" />");
|
|
482
485
|
|
|
483
486
|
// check for meta keys.. if set, we should open in a new tab
|
|
484
487
|
if (event.metaKey || event.ctrlKey) {
|
|
488
|
+
form.dataset.turbo = "false";
|
|
485
489
|
target = '_blank';
|
|
486
490
|
}
|
|
487
491
|
if (csrfParam !== undefined && csrfToken !== undefined) {
|
|
@@ -51,4 +51,7 @@ Blacklight.onLoad(function () {
|
|
|
51
51
|
elem.classList.add('js')
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
+
Blacklight.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content
|
|
55
|
+
Blacklight.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content
|
|
56
|
+
|
|
54
57
|
window.Blacklight = Blacklight
|
|
@@ -15,9 +15,6 @@ Blacklight.doSearchContextBehavior = function() {
|
|
|
15
15
|
})
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
Blacklight.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content
|
|
19
|
-
Blacklight.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content
|
|
20
|
-
|
|
21
18
|
// this is the Rails.handleMethod with a couple adjustments, described inline:
|
|
22
19
|
// first, we're attaching this directly to the event handler, so we can check for meta-keys
|
|
23
20
|
Blacklight.handleSearchContextMethod = function(event) {
|
|
@@ -42,6 +39,7 @@ Blacklight.handleSearchContextMethod = function(event) {
|
|
|
42
39
|
|
|
43
40
|
// check for meta keys.. if set, we should open in a new tab
|
|
44
41
|
if(event.metaKey || event.ctrlKey) {
|
|
42
|
+
form.dataset.turbo = "false";
|
|
45
43
|
target = '_blank';
|
|
46
44
|
}
|
|
47
45
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blacklight-frontend",
|
|
3
|
-
"version": "7.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.37.0",
|
|
4
|
+
"description": "The frontend code and styles for Blacklight",
|
|
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"
|