Sha256: 9d8ccc1923b153778552c8200825e9665023a13cabc9a64ea5b0d092f7be1c5f

Contents?: true

Size: 1.41 KB

Versions: 17

Compression:

Stored size: 1.41 KB

Contents

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

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

    listeners: function () {
      const listeners = [];
      if (typeof Turbo !== 'undefined') {
        listeners.push('turbo:load', 'turbo:frame-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')
})


export default Blacklight

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
blacklight-8.4.0 app/javascript/blacklight/core.js
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/javascript/blacklight/core.js
blacklight-8.3.0 app/javascript/blacklight/core.js
blacklight-8.2.2 app/javascript/blacklight/core.js
blacklight-8.2.1 app/javascript/blacklight/core.js
blacklight-8.2.0 app/javascript/blacklight/core.js
blacklight-8.1.0 app/javascript/blacklight/core.js
blacklight-8.0.1 app/javascript/blacklight/core.js
blacklight-8.0.0 app/javascript/blacklight/core.js
blacklight-8.0.0.beta8 app/javascript/blacklight/core.js
blacklight-8.0.0.beta7 app/javascript/blacklight/core.js
blacklight-8.0.0.beta6 app/javascript/blacklight/core.js
blacklight-8.0.0.beta5 app/javascript/blacklight/core.js
blacklight-8.0.0.beta4 app/javascript/blacklight/core.js
blacklight-8.0.0.beta3 app/javascript/blacklight/core.js
blacklight-8.0.0.beta2 app/javascript/blacklight/core.js
blacklight-8.0.0.beta1 app/javascript/blacklight/core.js