Sha256: 025896a0d20f712142faa1d4aeb89c03c7e1b3b123501381426ad365cc80d2ce

Contents?: true

Size: 1.54 KB

Versions: 14

Compression:

Stored size: 1.54 KB

Contents

/**
 * This directive adds the css position fixed if the tabs fit on screen
 */

app.directive('fixedIfFits', function($timeout, $rootScope) {
  return {
    restrict: 'C',
    link: function(scope, element) {
      function recalculateLayout() {
        $timeout(function() {
          var height = _(element.find('.tab-content .tab-pane').get()).map(function(el) {
            return angular.element(el).height();
          }).concat([element[0].scrollHeight]).max() + element.offset().top + element.find('.row:first-of-type').height();
          var mq = window.matchMedia('(min-width: 768px)');
          if (height < $(window).height() && mq.matches) {
            var padding = 20;
            element[0].style.width = (element.width() + padding) + 'px';
            element[0].style.paddingRight = padding + 'px';
            var navbarHeight = '' + ($('.navbar').height() || 60) + 'px';
            element[0].style.height = 'calc(100vh - ' + navbarHeight + ')';
            element[0].style.paddingBottom = '30px';
            element[0].style['overflow-y'] = 'auto';
            element[0].style.position = 'fixed';
          } else {
            element[0].style.width = null;
            element[0].style.paddingRight = null;
            element[0].style.height = null;
            element[0].style.paddingBottom = null;
            element[0].style['overflow-y'] = null;
            element[0].style.position = 'static';
          }
        }, 100);
      }
      recalculateLayout();
      $rootScope.$on('$stateChangeSuccess', recalculateLayout);
    }
  };
});

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
praxis-2.0.pre.9 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-2.0.pre.8 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-2.0.pre.7 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-2.0.pre.6 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-2.0.pre.5 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-2.0.pre.4 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-2.0.pre.3 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-2.0.pre.2 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-2.0.pre.1 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-0.22.pre.2 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-0.22.pre.1 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-0.21 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-0.20.1 lib/api_browser/app/js/directives/fixed_if_fits.js
praxis-0.20.0 lib/api_browser/app/js/directives/fixed_if_fits.js