Sha256: 816221292f808202b8879b43890c3dc973813abe0046b3652791b7e1ad5c1374

Contents?: true

Size: 1.8 KB

Versions: 21

Compression:

Stored size: 1.8 KB

Contents

/* ========================================================================
 * http://styleguide.bookingsync.com/javascript/#stackable
 * ========================================================================
 * Copyright 2016 BookingSync SAS.
 * Licensed under MIT (https://github.com/BookingSync/styleguide/blob/master/LICENSE)
 * ======================================================================== */

+function ($) {
  'use strict';

  var refreshStackable = function() {
    $('ul[data-toggle="stackable"]').each(function (index, element) {
      var $element = $(element);
      var targetSelector = $element.data('target');
      var $target = $element.find(targetSelector);
      var totalWidth = $element.width();
      var $targetList = $target.children('ul');
      var targetListWidth, maxItemsWidth;
      var currentWidth = 0;
      var stackNextItems = false;

      // Get width of stacked tab
      $target.removeClass('hide');
      targetListWidth = $target.width();
      maxItemsWidth = totalWidth - targetListWidth;
      $target.addClass('hide');

      // Bring back all items to the main list
      $targetList.find('li').each(function(index, item) {
        $element.append($(item).detach());
      });

      // Move items not fitting in the single line to the stacked list
      $element.children('li:not(' + targetSelector + ')').each(function(index, item) {
        var $item = $(item);
        var itemWidth = $item.width();

        if (stackNextItems !== true && currentWidth + itemWidth < maxItemsWidth) {
          currentWidth += itemWidth;
        } else {
          stackNextItems = true;
          $target.removeClass('hide');
          $targetList.append($item.detach());
        }
      });
    });
  };

  $(document).ready(refreshStackable);
  $(window).resize(refreshStackable);
}(jQuery);

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
bootstrap-bookingsync-sass-3.0.0 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-2.0.0 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.5 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.4 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.3 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.2 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.1 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta12 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta11 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta10 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta9 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta8 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta7 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta6 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta5 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta4 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta3 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta2 assets/javascripts/bookingsync/stackable.js
bootstrap-bookingsync-sass-1.0.0.beta1 assets/javascripts/bookingsync/stackable.js