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.25.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.24.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.23.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.22.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.21.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.20.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.19.2 app/assets/javascripts/blacklight/search_context.js
blacklight-6.19.1 app/assets/javascripts/blacklight/search_context.js
blacklight-6.19.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.18.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.17.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.16.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.15.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.14.1 app/assets/javascripts/blacklight/search_context.js
blacklight-6.14.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.13.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.12.0 app/assets/javascripts/blacklight/search_context.js
blacklight-6.11.2 app/assets/javascripts/blacklight/search_context.js
blacklight-6.11.1 app/assets/javascripts/blacklight/search_context.js
blacklight-6.11.0 app/assets/javascripts/blacklight/search_context.js