Sha256: 1f0f5e5a159af4c36cf38a1dbd921e0169b630cca9df083968e34b44da4f70ce

Contents?: true

Size: 1.71 KB

Versions: 18

Compression:

Stored size: 1.71 KB

Contents

/**
 * @ngdoc directive
 * @name Bastion.components.directive:bstContainerScroll
 * @restrict A
 *
 * @requires $window
 * @requires $timeout
 *
 * @description
 *   The container scroll directive should be applied to a wrapping div around an element that
 *   you wish to have scrolling capabilities that is outside the standard browser flow.
 *
 * @example
 *   <pre>
       <div bst-container-scroll></div>
     </pre>
 */
angular.module('Bastion.components').directive('bstContainerScroll', ['$window', '$timeout', function ($window, $timeout) {
    return {
        restrict: 'A',
        compile: function (tElement) {
            tElement.addClass("container-scroll-wrapper");

            return function (scope, element) {
                var windowElement = angular.element($window),
                    bottomPadding = parseInt(element.css('padding-bottom').replace('px', ''), 10),
                    newElementHeight, addScroll;

                addScroll = function () {
                    var windowHeight = windowElement.height(),
                        offset = element.offset().top;

                    if (bottomPadding) {
                        offset = offset + bottomPadding;
                    }

                    newElementHeight = windowHeight - offset;

                    if (newElementHeight <= 100) {
                        newElementHeight = 300;
                    }

                    element.outerHeight(newElementHeight);
                    element.height(newElementHeight);
                };

                windowElement.bind('resize', addScroll);
                $timeout(function () {
                    windowElement.trigger('resize');
                }, 0);
            };
        }
    };
}]);

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
bastion-4.2.2 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-4.2.1 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-4.2.0 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-4.1.0 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-4.0.0 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.4.4 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.4.3 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.4.2 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.4.1 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.4.0 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.3.6 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.3.5 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.3.4 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.3.3 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.3.2 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.3.1 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.3.0 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js
bastion-3.2.2 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js