Sha256: 15e46df33828f361ae18ed840445b1ee744339bb14b05a12ffaa8de0b65ffb6e

Contents?: true

Size: 1.88 KB

Versions: 39

Compression:

Stored size: 1.88 KB

Contents

/* global Tabs */

Tabs = (function() {
  function Tabs(el) {
    _.bindAll(this, 'overflowTabs');

    this.el = el;
    this.tabs = this.el.querySelectorAll("li:not(.tabs-dropdown)")

    /* <li class='tabs-dropdown'><a href='#'></a><ul></ul></li> */
    this.dropdown = document.createElement('li');
    this.dropdown.classList.add('tabs-dropdown');
    this.dropdown.appendChild(document.createElement('a'));
    this.dropdownList = document.createElement('ul');
    this.dropdown.appendChild(this.dropdownList);

    this.el.appendChild(this.dropdown);

    this.tabWidths = _.map(this.tabs, function(tab) {
      return tab.offsetWidth;
    });
    this.totalTabsWidth = this.tabWidths.reduce(function(previousValue, currentValue) {
      return previousValue + currentValue;
    });

    window.addEventListener("resize", this.overflowTabs);
    this.overflowTabs();
  }

  Tabs.prototype.overflowTabs = function() {
    var containerWidth = this.el.offsetWidth;
    var dropdownWidth = this.dropdown.offsetWidth;

    for (var i = 0; i < this.tabs.length; i++) {
      var tab = this.tabs[i];
      tab.parentNode.removeChild(tab);
    }

    if (this.totalTabsWidth < containerWidth) {
      this.el.classList.remove("tabs-overflowed");
    } else {
      this.el.classList.add("tabs-overflowed");
      remainingWidth -= dropdownWidth;
    }

    var remainingWidth = containerWidth;
    for (var i = 0; i < this.tabs.length; i++) {
      remainingWidth -= this.tabWidths[i];
      var tab = this.tabs[i];
      if (remainingWidth >= 0) {
        tab.classList.remove("in-dropdown");
        this.el.insertBefore(tab, this.dropdown);
      } else {
        tab.classList.add("in-dropdown");
        this.dropdownList.appendChild(tab);
      }
    }
  };

  return Tabs;
})();

window.addEventListener('load', function() {
  _.each(document.querySelectorAll('.tabs'), function(el) {
    new Tabs(el);
  });
});

Version data entries

39 entries across 39 versions & 2 rubygems

Version Path
solidus_backend_devise_token_auth-2.8.0.alpha.12 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.11 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.10 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.9 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.8 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.7 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.6 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.5 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.4 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.3 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend_devise_token_auth-2.8.0.alpha.2 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend-2.7.0 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend-2.6.1 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend-2.6.0 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend-2.6.0.rc1 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend-2.5.0 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend-2.5.0.rc1 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend-2.5.0.beta2 app/assets/javascripts/spree/backend/components/tabs.js
solidus_backend-2.5.0.beta1 app/assets/javascripts/spree/backend/components/tabs.js