Sha256: 8753d3ecb520fa22033638a47817c5301402773c6877698aa0c646d4134ba27a

Contents?: true

Size: 1.56 KB

Versions: 5

Compression:

Stored size: 1.56 KB

Contents

const Blacklight = function() {
  var buffer = new Array;
  return {
    onLoad: function(func) {
      buffer.push(func);
    },

    activate: function() {
      for(var i = 0; i < buffer.length; i++) {
        buffer[i].call();
      }
    },

    listeners: function () {
      var listeners = [];
      if (typeof Turbo !== 'undefined') {
        listeners.push('turbo:load');
      } else if (typeof Turbolinks !== 'undefined' && Turbolinks.supported) {
        // Turbolinks 5
        if (Turbolinks.BrowserAdapter) {
          listeners.push('turbolinks:load');
        } else {
          // Turbolinks < 5
          listeners.push('page:load', 'DOMContentLoaded');
        }
      } else {
        listeners.push('DOMContentLoaded');
      }

      return listeners;
    }
  };
}();

// turbolinks triggers page:load events on page transition
// If app isn't using turbolinks, this event will never be triggered, no prob.
Blacklight.listeners().forEach(function(listener) {
  document.addEventListener(listener, function() {
    Blacklight.activate()
  })
})

Blacklight.onLoad(function () {
  const elem = document.querySelector('.no-js');

  // The "no-js" class may already have been removed because this function is
  // run on every turbo:load event, in that case, it won't find an element.
  if (!elem) return;

  elem.classList.remove('no-js')
  elem.classList.add('js')
})

Blacklight.csrfToken = () => document.querySelector('meta[name=csrf-token]')?.content
Blacklight.csrfParam = () => document.querySelector('meta[name=csrf-param]')?.content

window.Blacklight = Blacklight

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
blacklight-7.40.0 app/javascript/blacklight/core.js
blacklight-7.39.0 app/javascript/blacklight/core.js
blacklight-7.38.0 app/javascript/blacklight/core.js
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-7.37.0/app/javascript/blacklight/core.js
blacklight-7.37.0 app/javascript/blacklight/core.js