Skip to content

Commit

Permalink
Fixes multiple cascading problems with search_context.js not firing a…
Browse files Browse the repository at this point in the history
…nd generally having a bad time. (#540)

Co-authored-by: Banu Kutlu <bzk60@psu.edu>

Co-authored-by: Banu Hapeloglu Kutlu <bzk60@psu.edu>
  • Loading branch information
cdmo and Banu Hapeloglu Kutlu committed Jan 23, 2020
1 parent 94a708a commit f6c0d5c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 53 deletions.
1 change: 1 addition & 0 deletions app/javascript/packs/application.js
Expand Up @@ -28,4 +28,5 @@ document.addEventListener("turbolinks:load", function() {
availability.executeAvailability();
bookCovers.start();
Blacklight.doBookmarkToggleBehavior();
Blacklight.doSearchContextBehavior();
});
50 changes: 1 addition & 49 deletions app/javascript/psulib_blacklight/index.js
Expand Up @@ -20,52 +20,4 @@ import 'blacklight-frontend/app/javascript/blacklight/checkbox_submit'
import 'blacklight-frontend/app/javascript/blacklight/modal'
import 'blacklight-frontend/app/javascript/blacklight/button_focus'
import 'blacklight-frontend/app/javascript/blacklight/facet_load'
(function($) {
Blacklight.doSearchContextBehavior = function() {
if (typeof Blacklight.do_search_context_behavior == 'function') {
console.warn("do_search_context_behavior is deprecated. Use doSearchContextBehavior instead.");
return Blacklight.do_search_context_behavior();
}
$('a[data-context-href]').on('click.search-context', Blacklight.handleSearchContextMethod);
};

// this is the $.rails.handleMethod with a couple adjustments, described inline:
// first, we're attaching this directly to the event handler, so we can check for meta-keys
Blacklight.handleSearchContextMethod = function(event) {
if (typeof Blacklight.handle_search_context_method == 'function') {
console.warn("handle_search_context_method is deprecated. Use handleSearchContextMethod instead.");
return Blacklight.handle_search_context_method(event);
}
var link = $(this);

// instead of using the normal href, we need to use the context href instead
var href = link.data('context-href'),
method = 'post',
target = link.attr('target'),
csrfToken = $('meta[name=csrf-token]').attr('content'),
csrfParam = $('meta[name=csrf-param]').attr('content'),
form = $('<form method="post" action="' + href + '"></form>'),
metadataInput = '<input name="_method" value="' + method + '" type="hidden" />',
redirectHref = '<input name="redirect" value="' + link.attr('href') + '" type="hidden" />';

// check for meta keys.. if set, we should open in a new tab
if(event.metaKey || event.ctrlKey) {
target = '_blank';
}

if (csrfParam !== undefined && csrfToken !== undefined) {
metadataInput += '<input name="' + csrfParam + '" value="' + csrfToken + '" type="hidden" />';
}

if (target) { form.attr('target', target); }

form.hide().append(metadataInput).append(redirectHref).appendTo('body');
form.submit();

return false;
};

Blacklight.onLoad(function() {
Blacklight.doSearchContextBehavior();
});
})(jQuery);
import 'blacklight-frontend/app/javascript/blacklight/search_context'
8 changes: 4 additions & 4 deletions config/locales/blacklight.en.yml
Expand Up @@ -43,11 +43,11 @@ en:
edition: "Edition: %{value}"
views:
pagination_compact:
next: '<span class="d-none d-md-inline">Next </span><i class="fas fa-arrow-right"></i>'
previous: '<i class="fas fa-arrow-left"></i><span class="d-none d-md-inline"> Previous</span>'
next: 'Next &#10145;'
previous: '&#11013; Previous'
pagination:
previous: '<i class="fas fa-arrow-left"></i> <span class="d-none d-md-inline"> Previous</span>'
next: '<span class="d-none d-md-inline">Next </span><i class="fas fa-arrow-right"></i>'
previous: '&#11013; Previous'
next: 'Next &#10145;'
support:
array:
words_connector: "<br>"
Expand Down
1 change: 1 addition & 0 deletions config/webpack/environment.js
Expand Up @@ -17,6 +17,7 @@ environment.plugins.prepend(
jquery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default'],
Rails: 'rails-ujs'
})
)

Expand Down

0 comments on commit f6c0d5c

Please sign in to comment.