Sha256: 482d71a0f9ca92c4567105501cc88220a7302df97e012139a4492afc958874c5

Contents?: true

Size: 1.24 KB

Versions: 24

Compression:

Stored size: 1.24 KB

Contents

export default class {
  connect() {
    var $container, slider;

    function init() {
      var data = $container.data();
      var sidebar = $container.data().sidebar;
      var items = data.browseGroupCategoriesCount;
      var dir = $('html').attr('dir');
      var controls = $container.parent().find('.browse-group-categories-controls')[0];

      slider = tns({
        container: $container[0],
        controlsContainer: controls,
        loop: false,
        nav: false,
        items: 1,
        slideBy: 'page',
        textDirection: dir,
        responsive: {
          576: {
            items: itemCount(items, sidebar)
          }
        }
      });
    }

    // Destroy the slider instance, as tns will change the dom elements, causing some issues with turbolinks
    function setupDestroy() {
      document.addEventListener('turbolinks:before-cache', function() {
        if (slider && slider.destroy) {
          slider.destroy();
        }
      });
    }

    function itemCount(items, sidebar) {
      if (items < 3) {
        return items;
      }
      return sidebar ? 3 : 4;
    }

    return $('[data-browse-group-categories-carousel]').each(function() {
      $container = $(this);
      init();
      setupDestroy();
    });
  }
}

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
blacklight-spotlight-4.3.6 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.3.5 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.3.4 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.3.3 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.3.2 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.3.1 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.3.0 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.2.0 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.1.2 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.1.1 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.1.0 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.0.3 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.0.2 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.0.1 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-4.0.0 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-3.6.0.beta10 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-3.6.0.beta9 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-3.6.0.beta8 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-3.6.0.beta7 app/javascript/spotlight/user/browse_group_categories.js
blacklight-spotlight-3.6.0.beta6 app/javascript/spotlight/user/browse_group_categories.js