Sha256: 4c1ccab1408e32f8ac479137d80ee83add6961dc1aa8a0951e6822761d4bbab2

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 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),
                    addScroll;

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

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

                    element.outerHeight(windowHeight - offset);
                    element.height(windowHeight - offset);
                };

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bastion-3.2.1 app/assets/javascripts/bastion/components/bst-container-scroll.directive.js