Sha256: f9f468a7ed50e11cf966db34b1cb39582b5a92513fef0e5e54d8e78be0e45120

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

const Core = 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.
Core.listeners().forEach(function(listener) {
  document.addEventListener(listener, function() {
    Core.activate()
  })
})

Core.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 Core

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
blacklight-8.8.4 app/javascript/blacklight/core.js
blacklight-8.8.3 app/javascript/blacklight/core.js
blacklight-8.8.2 app/javascript/blacklight/core.js
blacklight-8.8.1 app/javascript/blacklight/core.js
blacklight-8.8.0 app/javascript/blacklight/core.js
blacklight-8.7.0 app/javascript/blacklight/core.js
blacklight-8.6.1 app/javascript/blacklight/core.js
blacklight-8.6.0 app/javascript/blacklight/core.js
blacklight-8.5.1 app/javascript/blacklight/core.js
blacklight-8.5.0 app/javascript/blacklight/core.js