blacklight-frontend 7.25.0 → 8.0.0-pre.2

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.
Files changed (28) hide show
  1. package/README.md +12 -4
  2. package/app/assets/javascripts/blacklight/blacklight.js +392 -489
  3. package/app/assets/javascripts/blacklight/blacklight.js.map +1 -0
  4. package/app/assets/stylesheets/blacklight/_autocomplete.scss +21 -0
  5. package/app/assets/stylesheets/blacklight/_blacklight_base.scss +1 -1
  6. package/app/assets/stylesheets/blacklight/_bootstrap_overrides.scss +8 -0
  7. package/app/assets/stylesheets/blacklight/_facets.scss +35 -31
  8. package/app/assets/stylesheets/blacklight/_group.scss +2 -2
  9. package/app/assets/stylesheets/blacklight/_header.scss +3 -15
  10. package/app/assets/stylesheets/blacklight/_icons.scss +0 -14
  11. package/app/assets/stylesheets/blacklight/_mixins.scss +20 -0
  12. package/app/assets/stylesheets/blacklight/_modal.scss +8 -2
  13. package/app/assets/stylesheets/blacklight/_search_form.scss +30 -3
  14. package/app/assets/stylesheets/blacklight/_search_history.scss +10 -1
  15. package/app/assets/stylesheets/blacklight/_search_results.scss +6 -2
  16. package/app/assets/stylesheets/blacklight/blacklight_defaults.scss +5 -1
  17. package/package.json +9 -13
  18. package/app/assets/images/blacklight/list.svg +0 -1
  19. package/app/assets/images/blacklight/search.svg +0 -1
  20. package/app/assets/stylesheets/blacklight/_twitter_typeahead.scss +0 -30
  21. package/app/javascript/blacklight/autocomplete.js +0 -36
  22. package/app/javascript/blacklight/bookmark_toggle.js +0 -25
  23. package/app/javascript/blacklight/button_focus.js +0 -10
  24. package/app/javascript/blacklight/checkbox_submit.js +0 -134
  25. package/app/javascript/blacklight/core.js +0 -54
  26. package/app/javascript/blacklight/facet_load.js +0 -22
  27. package/app/javascript/blacklight/modal.js +0 -226
  28. package/app/javascript/blacklight/search_context.js +0 -69
@@ -1,134 +0,0 @@
1
- /* A JQuery plugin (should this be implemented as a widget instead? not sure)
2
- that will convert a "toggle" form, with single submit button to add/remove
3
- something, like used for Bookmarks, into an AJAXy checkbox instead.
4
-
5
- Apply to a form. Does require certain assumption about the form:
6
- 1) The same form 'action' href must be used for both ADD and REMOVE
7
- actions, with the different being the hidden input name="_method"
8
- being set to "put" or "delete" -- that's the Rails method to pretend
9
- to be doing a certain HTTP verb. So same URL, PUT to add, DELETE
10
- to remove. This plugin assumes that.
11
-
12
- Plus, the form this is applied to should provide a data-doc-id
13
- attribute (HTML5-style doc-*) that contains the id/primary key
14
- of the object in question -- used by plugin for a unique value for
15
- DOM id's.
16
-
17
- Uses HTML for a checkbox compatible with Bootstrap 3.
18
-
19
- Pass in options for your class name and labels:
20
- $("form.something").blCheckboxSubmit({
21
- //cssClass is added to elements added, plus used for id base
22
- cssClass: "toggle_my_kinda_form",
23
- error: function() {
24
- #optional callback
25
- },
26
- success: function(after_success_check_state) {
27
- #optional callback
28
- }
29
- });
30
- */
31
- (function($) {
32
- $.fn.blCheckboxSubmit = function(argOpts) {
33
- this.each(function() {
34
- var options = $.extend({}, $.fn.blCheckboxSubmit.defaults, argOpts);
35
-
36
-
37
- var form = $(this);
38
- form.children().hide();
39
- //We're going to use the existing form to actually send our add/removes
40
- //This works conveneintly because the exact same action href is used
41
- //for both bookmarks/$doc_id. But let's take out the irrelevant parts
42
- //of the form to avoid any future confusion.
43
- form.find('input[type=submit]').remove();
44
-
45
- //View needs to set data-doc-id so we know a unique value
46
- //for making DOM id
47
- var uniqueId = form.attr('data-doc-id') || Math.random();
48
- // if form is currently using method delete to change state,
49
- // then checkbox is currently checked
50
- var checked = (form.find('input[name=_method][value=delete]').length != 0);
51
-
52
- var checkbox = $('<input type="checkbox">')
53
- .addClass( options.cssClass )
54
- .attr('id', options.cssClass + '_' + uniqueId);
55
- var label = $('<label>')
56
- .addClass( options.cssClass )
57
- .attr('for', options.cssClass + '_' + uniqueId)
58
- .attr('title', form.attr('title') || '');
59
- var span = $('<span>');
60
-
61
- label.append(checkbox);
62
- label.append(' ');
63
- label.append(span);
64
-
65
- var checkboxDiv = $('<div class="checkbox" />')
66
- .addClass(options.cssClass)
67
- .append(label);
68
-
69
- function updateStateFor(state) {
70
- checkbox.prop('checked', state);
71
- label.toggleClass('checked', state);
72
- if (state) {
73
- //Set the Rails hidden field that fakes an HTTP verb
74
- //properly for current state action.
75
- form.find('input[name=_method]').val('delete');
76
- span.html(form.attr('data-present'));
77
- } else {
78
- form.find('input[name=_method]').val('put');
79
- span.html(form.attr('data-absent'));
80
- }
81
- }
82
-
83
- form.append(checkboxDiv);
84
- updateStateFor(checked);
85
-
86
- checkbox.click(function() {
87
- span.html(form.attr('data-inprogress'));
88
- label.attr('disabled', 'disabled');
89
- checkbox.attr('disabled', 'disabled');
90
-
91
- $.ajax({
92
- url: form.attr('action'),
93
- dataType: 'json',
94
- type: form.attr('method').toUpperCase(),
95
- data: form.serialize(),
96
- error: function() {
97
- label.removeAttr('disabled');
98
- checkbox.removeAttr('disabled');
99
- options.error.call();
100
- },
101
- success: function(data, status, xhr) {
102
- //if app isn't running at all, xhr annoyingly
103
- //reports success with status 0.
104
- if (xhr.status != 0) {
105
- checked = ! checked;
106
- updateStateFor(checked);
107
- label.removeAttr('disabled');
108
- checkbox.removeAttr('disabled');
109
- options.success.call(form, checked, xhr.responseJSON);
110
- } else {
111
- label.removeAttr('disabled');
112
- checkbox.removeAttr('disabled');
113
- options.error.call();
114
- }
115
- }
116
- });
117
-
118
- return false;
119
- }); //checkbox.click
120
-
121
-
122
- }); //this.each
123
- return this;
124
- };
125
-
126
- $.fn.blCheckboxSubmit.defaults = {
127
- //cssClass is added to elements added, plus used for id base
128
- cssClass: 'blCheckboxSubmit',
129
- error: function() {
130
- alert("Error");
131
- },
132
- success: function() {} //callback
133
- };
134
- })(jQuery);
@@ -1,54 +0,0 @@
1
- const Blacklight = function() {
2
- var buffer = new Array;
3
- return {
4
- onLoad: function(func) {
5
- buffer.push(func);
6
- },
7
-
8
- activate: function() {
9
- for(var i = 0; i < buffer.length; i++) {
10
- buffer[i].call();
11
- }
12
- },
13
-
14
- listeners: function () {
15
- var listeners = [];
16
- if (typeof Turbo !== 'undefined') {
17
- listeners.push('turbo:load');
18
- } else if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
19
- // Turbolinks 5
20
- if (Turbolinks.BrowserAdapter) {
21
- listeners.push('turbolinks:load');
22
- } else {
23
- // Turbolinks < 5
24
- listeners.push('page:load', 'DOMContentLoaded');
25
- }
26
- } else {
27
- listeners.push('DOMContentLoaded');
28
- }
29
-
30
- return listeners;
31
- }
32
- };
33
- }();
34
-
35
- // turbolinks triggers page:load events on page transition
36
- // If app isn't using turbolinks, this event will never be triggered, no prob.
37
- Blacklight.listeners().forEach(function(listener) {
38
- document.addEventListener(listener, function() {
39
- Blacklight.activate()
40
- })
41
- })
42
-
43
- Blacklight.onLoad(function () {
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
-
50
- elem.classList.remove('no-js')
51
- elem.classList.add('js')
52
- })
53
-
54
- window.Blacklight = Blacklight
@@ -1,22 +0,0 @@
1
- /*global Blacklight */
2
-
3
- 'use strict';
4
-
5
- Blacklight.doResizeFacetLabelsAndCounts = function() {
6
- // adjust width of facet columns to fit their contents
7
- function longer (a,b) { return b.textContent.length - a.textContent.length }
8
-
9
- document.querySelectorAll('.facet-values, .pivot-facet').forEach(function(elem){
10
- const nodes = elem.querySelectorAll('.facet-count')
11
- // TODO: when we drop ie11 support, this can become the spread operator:
12
- const longest = Array.from(nodes).sort(longer)[0]
13
- if (longest && longest.textContent) {
14
- const width = longest.textContent.length + 1 + 'ch'
15
- elem.querySelector('.facet-count').style.width = width
16
- }
17
- })
18
- }
19
-
20
- Blacklight.onLoad(function() {
21
- Blacklight.doResizeFacetLabelsAndCounts()
22
- })
@@ -1,226 +0,0 @@
1
- /*
2
- The blacklight modal plugin can display some interactions inside a Bootstrap
3
- modal window, including some multi-page interactions.
4
-
5
- It supports unobtrusive Javascript, where a link or form that would have caused
6
- a new page load is changed to display it's results inside a modal dialog,
7
- by this plugin. The plugin assumes there is a Bootstrap modal div
8
- on the page with id #blacklight-modal to use as the modal -- the standard Blacklight
9
- layout provides this.
10
-
11
- To make a link or form have their results display inside a modal, add
12
- `data-blacklight-modal="trigger"` to the link or form. (Note, form itself not submit input)
13
- With Rails link_to helper, you'd do that like:
14
-
15
- link_to something, link, data: { blacklight_modal: "trigger" }
16
-
17
- The results of the link href or form submit will be displayed inside
18
- a modal -- they should include the proper HTML markup for a bootstrap modal's
19
- contents. Also, you ordinarily won't want the Rails template with wrapping
20
- navigational elements to be used. The Rails controller could suppress
21
- the layout when a JS AJAX request is detected, OR the response
22
- can include a `<div data-blacklight-modal="container">` -- only the contents
23
- of the container will be placed inside the modal, the rest of the
24
- page will be ignored.
25
-
26
- If you'd like to have a link or button that closes the modal,
27
- you can just add a `data-dismiss="modal"` to the link,
28
- standard Bootstrap convention. But you can also have
29
- an href on this link for non-JS contexts, we'll make sure
30
- inside the modal it closes the modal and the link is NOT followed.
31
-
32
- Link or forms inside the modal will ordinarily cause page loads
33
- when they are triggered. However, if you'd like their results
34
- to stay within the modal, just add `data-blacklight-modal="preserve"`
35
- to the link or form.
36
-
37
- Here's an example of what might be returned, demonstrating most of the devices available:
38
-
39
- <div data-blacklight-modal="container">
40
- <div class="modal-header">
41
- <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
42
- <h3 class="modal-title">Request Placed</h3>
43
- </div>
44
-
45
- <div class="modal-body">
46
- <p>Some message</p>
47
- <%= link_to "This result will still be within modal", some_link, data: { blacklight_modal: "preserve" } %>
48
- </div>
49
-
50
-
51
- <div class="modal-footer">
52
- <%= link_to "Close the modal", request_done_path, class: "submit button dialog-close", data: { dismiss: "modal" } %>
53
- </div>
54
- </div>
55
-
56
-
57
- One additional feature. If the content returned from the AJAX modal load
58
- has an element with `data-blacklight-modal=close`, that will trigger the modal
59
- to be closed. And if this element includes a node with class "flash_messages",
60
- the flash-messages node will be added to the main page inside #main-flahses.
61
-
62
- == Events
63
-
64
- We'll send out an event 'loaded.blacklight.blacklight-modal' with the #blacklight-modal
65
- dialog as the target, right after content is loaded into the modal but before
66
- it is shown (if not already a shown modal). In an event handler, you can
67
- inspect loaded content by looking inside $(this). If you call event.preventDefault(),
68
- we won't 'show' the dialog (although it may already have been shown, you may want to
69
- $(this).modal("hide") if you want to ensure hidden/closed.
70
-
71
- The data-blacklight-modal=close behavior is implemented with this event, see for example.
72
- */
73
-
74
- // We keep all our data in Blacklight.modal object.
75
- // Create lazily if someone else created first.
76
- if (Blacklight.modal === undefined) {
77
- Blacklight.modal = {};
78
- }
79
-
80
- // a Bootstrap modal div that should be already on the page hidden
81
- Blacklight.modal.modalSelector = '#blacklight-modal';
82
-
83
- // Trigger selectors identify forms or hyperlinks that should open
84
- // inside a modal dialog.
85
- Blacklight.modal.triggerLinkSelector = 'a[data-blacklight-modal~=trigger]';
86
- Blacklight.modal.triggerFormSelector = 'form[data-blacklight-modal~=trigger]';
87
-
88
- // preserve selectors identify forms or hyperlinks that, if activated already
89
- // inside a modal dialog, should have destinations remain inside the modal -- but
90
- // won't trigger a modal if not already in one.
91
- //
92
- // No need to repeat selectors from trigger selectors, those will already
93
- // be preserved. MUST be manually prefixed with the modal selector,
94
- // so they only apply to things inside a modal.
95
- Blacklight.modal.preserveLinkSelector = Blacklight.modal.modalSelector + ' a[data-blacklight-modal~=preserve]';
96
-
97
- Blacklight.modal.containerSelector = '[data-blacklight-modal~=container]';
98
-
99
- Blacklight.modal.modalCloseSelector = '[data-blacklight-modal~=close]';
100
-
101
- // Called on fatal failure of ajax load, function returns content
102
- // to show to user in modal. Right now called only for extreme
103
- // network errors.
104
- Blacklight.modal.onFailure = function(jqXHR, textStatus, errorThrown) {
105
- console.error('Server error:', this.url, jqXHR.status, errorThrown);
106
-
107
- var contents = '<div class="modal-header">' +
108
- '<div class="modal-title">There was a problem with your request.</div>' +
109
- '<button type="button" class="blacklight-modal-close btn-close close" data-dismiss="modal" aria-label="Close">' +
110
- ' <span aria-hidden="true">&times;</span>' +
111
- '</button></div>' +
112
- ' <div class="modal-body"><p>Expected a successful response from the server, but got an error</p>' +
113
- '<pre>' +
114
- this.type + ' ' + this.url + "\n" + jqXHR.status + ': ' + errorThrown +
115
- '</pre></div>';
116
- $(Blacklight.modal.modalSelector).find('.modal-content').html(contents);
117
- Blacklight.modal.show();
118
- }
119
-
120
- Blacklight.modal.receiveAjax = function (contents) {
121
- // does it have a data- selector for container?
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/main/src/ajax/load.js?source=c#L62
124
- var container = $('<div>').
125
- append( jQuery.parseHTML(contents) ).find( Blacklight.modal.containerSelector ).first();
126
- if (container.length !== 0) {
127
- contents = container.html();
128
- }
129
-
130
- $(Blacklight.modal.modalSelector).find('.modal-content').html(contents);
131
-
132
- // send custom event with the modal dialog div as the target
133
- var e = $.Event('loaded.blacklight.blacklight-modal')
134
- $(Blacklight.modal.modalSelector).trigger(e);
135
- // if they did preventDefault, don't show the dialog
136
- if (e.isDefaultPrevented()) return;
137
-
138
- Blacklight.modal.show();
139
- };
140
-
141
-
142
- Blacklight.modal.modalAjaxLinkClick = function(e) {
143
- e.preventDefault();
144
-
145
- $.ajax({
146
- url: $(this).attr('href')
147
- })
148
- .fail(Blacklight.modal.onFailure)
149
- .done(Blacklight.modal.receiveAjax)
150
- };
151
-
152
- Blacklight.modal.modalAjaxFormSubmit = function(e) {
153
- e.preventDefault();
154
-
155
- $.ajax({
156
- url: $(this).attr('action'),
157
- data: $(this).serialize(),
158
- type: $(this).attr('method') // POST
159
- })
160
- .fail(Blacklight.modal.onFailure)
161
- .done(Blacklight.modal.receiveAjax)
162
- }
163
-
164
-
165
-
166
- Blacklight.modal.setupModal = function() {
167
- // Event indicating blacklight is setting up a modal link,
168
- // you can catch it and call e.preventDefault() to abort
169
- // setup.
170
- var e = $.Event('setup.blacklight.blacklight-modal');
171
- $('body').trigger(e);
172
- if (e.isDefaultPrevented()) return;
173
-
174
- // Register both trigger and preserve selectors in ONE event handler, combining
175
- // into one selector with a comma, so if something matches BOTH selectors, it
176
- // still only gets the event handler called once.
177
- $('body').on('click', Blacklight.modal.triggerLinkSelector + ', ' + Blacklight.modal.preserveLinkSelector,
178
- Blacklight.modal.modalAjaxLinkClick);
179
- $('body').on('submit', Blacklight.modal.triggerFormSelector + ', ' + Blacklight.modal.preserveFormSelector,
180
- Blacklight.modal.modalAjaxFormSubmit);
181
-
182
- // Catch our own custom loaded event to implement data-blacklight-modal=closed
183
- $('body').on('loaded.blacklight.blacklight-modal', Blacklight.modal.checkCloseModal);
184
-
185
- // we support doing data-dismiss=modal on a <a> with a href for non-ajax
186
- // use, we need to suppress following the a's href that's there for
187
- // non-JS contexts.
188
- $('body').on('click', Blacklight.modal.modalSelector + ' a[data-dismiss~=modal]', function (e) {
189
- e.preventDefault();
190
- });
191
- };
192
-
193
- // A function used as an event handler on loaded.blacklight.blacklight-modal
194
- // to catch contained data-blacklight-modal=closed directions
195
- Blacklight.modal.checkCloseModal = function(event) {
196
- if ($(event.target).find(Blacklight.modal.modalCloseSelector).length) {
197
- var modalFlashes = $(this).find('.flash_messages');
198
-
199
- Blacklight.modal.hide(event.target);
200
- event.preventDefault();
201
-
202
- var mainFlashes = $('#main-flashes');
203
- mainFlashes.append(modalFlashes);
204
- modalFlashes.fadeIn(500);
205
- }
206
- }
207
-
208
- Blacklight.modal.hide = function(el) {
209
- if (typeof bootstrap !== 'undefined' && typeof bootstrap.Modal !== 'undefined' && 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 (typeof bootstrap !== 'undefined' && typeof bootstrap.Modal !== 'undefined' && 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
-
224
- Blacklight.onLoad(function() {
225
- Blacklight.modal.setupModal();
226
- });
@@ -1,69 +0,0 @@
1
- Blacklight.doSearchContextBehavior = function() {
2
- if (typeof Blacklight.do_search_context_behavior == 'function') {
3
- console.warn("do_search_context_behavior is deprecated. Use doSearchContextBehavior instead.");
4
- return Blacklight.do_search_context_behavior();
5
- }
6
-
7
- const elements = document.querySelectorAll('a[data-context-href]')
8
- // Equivalent to Array.from(), but supports ie11
9
- const nodes = Array.prototype.slice.call(elements)
10
-
11
- nodes.forEach(function(element) {
12
- element.addEventListener('click', function(e) {
13
- Blacklight.handleSearchContextMethod.call(e.currentTarget, e)
14
- })
15
- })
16
- };
17
-
18
- Blacklight.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content
19
- Blacklight.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content
20
-
21
- // this is the Rails.handleMethod with a couple adjustments, described inline:
22
- // first, we're attaching this directly to the event handler, so we can check for meta-keys
23
- Blacklight.handleSearchContextMethod = function(event) {
24
- if (typeof Blacklight.handle_search_context_method == 'function') {
25
- console.warn("handle_search_context_method is deprecated. Use handleSearchContextMethod instead.");
26
- return Blacklight.handle_search_context_method(event);
27
- }
28
- var link = this
29
-
30
- // instead of using the normal href, we need to use the context href instead
31
- let href = link.getAttribute('data-context-href')
32
- let target = link.getAttribute('target')
33
- let csrfToken = Blacklight.csrfToken()
34
- let csrfParam = Blacklight.csrfParam()
35
- let form = document.createElement('form')
36
- form.method = 'post'
37
- form.action = href
38
-
39
-
40
- let formContent = `<input name="_method" value="post" type="hidden" />
41
- <input name="redirect" value="${link.getAttribute('href')}" type="hidden" />`
42
-
43
- // check for meta keys.. if set, we should open in a new tab
44
- if(event.metaKey || event.ctrlKey) {
45
- target = '_blank';
46
- }
47
-
48
- if (csrfParam !== undefined && csrfToken !== undefined) {
49
- formContent += `<input name="${csrfParam}" value="${csrfToken}" type="hidden" />`
50
- }
51
-
52
- // Must trigger submit by click on a button, else "submit" event handler won't work!
53
- // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
54
- formContent += '<input type="submit" />'
55
-
56
- if (target) { form.setAttribute('target', target); }
57
-
58
- form.style.display = 'none'
59
- form.innerHTML = formContent
60
- document.body.appendChild(form)
61
- form.querySelector('[type="submit"]').click()
62
-
63
- event.preventDefault()
64
- event.stopPropagation()
65
- };
66
-
67
- Blacklight.onLoad(function() {
68
- Blacklight.doSearchContextBehavior();
69
- });