Sha256: 69707c9cca108cff1553655836611e8d70a3abf9b9313e9e126544053eb86eaa

Contents?: true

Size: 1.56 KB

Versions: 95

Compression:

Stored size: 1.56 KB

Contents

//= require blacklight/core
(function($) {
  Blacklight.do_search_context_behavior = function() {
    $('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) {
    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.do_search_context_behavior();
  });
})(jQuery);

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
blacklight-6.10.1 app/assets/javascripts/blacklight/search_context.js
blacklight-6.10.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.9.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.8.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.7.3 app/assets/javascripts/blacklight/search_context.js
blacklight-6.7.2 app/assets/javascripts/blacklight/search_context.js
blacklight-5.19.2 app/assets/javascripts/blacklight/search_context.js
blacklight-5.19.1 app/assets/javascripts/blacklight/search_context.js
blacklight-6.7.1 app/assets/javascripts/blacklight/search_context.js
blacklight-6.7.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.6.2 app/assets/javascripts/blacklight/search_context.js
blacklight-6.6.1 app/assets/javascripts/blacklight/search_context.js
blacklight-6.6.0 app/assets/javascripts/blacklight/search_context.js
blacklight-5.19.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.5.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.4.2 app/assets/javascripts/blacklight/search_context.js
blacklight-6.4.1 app/assets/javascripts/blacklight/search_context.js
blacklight-6.4.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.3.3 app/assets/javascripts/blacklight/search_context.js
blacklight-6.3.1 app/assets/javascripts/blacklight/search_context.js