<commit_before>/**
 * Created by PAVEI on 30/09/2014.
 */

angular.module('ionic-img-lazy-load', []);

angular.module('ionic-img-lazy-load').directive(
    'scroller', function ($document, $rootScope, $timeout) {
        return {
            restrict: 'A',
            link: function ($scope, $element, $attributes) {

                var id = 0,
                    scrollTimeoutId,
                    resizeTimeoutId;

                $scope.invoke = function () {
                    $rootScope.$broadcast('scrollEvent');
                }

                $element.bind('scroll', function (e) {

                    $timeout.cancel(scrollTimeoutId);

                    // wait for 200ms and then invoke listeners (simulates stop event)
                    scrollTimeoutId = $timeout($scope.invoke, 50);

                });


            }
        }
    });

angular.module('ionic-img-lazy-load').directive(
    'imageLazySrc', function ($document) {
        return {
            restrict: 'A',
            link: function ($scope, $element, $attributes) {
                var listenerRemover;

                var deregistration = $scope.$on('scrollEvent', function () {
                        console.log('scroll');
                        if (isInView()) {
                            $element[0].src = $attributes.imageLazySrc; // set src attribute on element (it will load image)
                            deregistration();
                        }
                    }
                );

                function isInView() {

                    var clientHeight = $document[0].documentElement.clientHeight;
                    var clientWidth = $document[0].documentElement.clientWidth;
                    var imageRect = $element[0].getBoundingClientRect();
                    return  (imageRect.top >= 0 && imageRect.bottom <= clientHeight) && (imageRect.left >= 0 && imageRect.right <= clientWidth);
                }

                // bind listener
                // listenerRemover = scrollAndResizeListener.bindListener(isInView);

                // unbind event listeners if element was destroyed
                // it happens when you change view, etc
                $element.on('$destroy', function () {
                    deregistration();
                });

                // explicitly call scroll listener (because, some images are in viewport already and we haven't scrolled yet)
                if (isInView()) {
                    $element[0].src = $attributes.imageLazySrc; // set src attribute on element (it will load image)
                    deregistration();
                }
            }
        }
    }
);<commit_msg>Adjust for codepen<commit_after>/**
 * Created by PAVEI on 30/09/2014.
 */

angular.module('ionic-img-lazy-load', []);

angular.module('ionic-img-lazy-load').directive(
    'scroller', function ($rootScope, $timeout) {
        return {
            restrict: 'A',
            link: function ($scope, $element) {

                var scrollTimeoutId = 0;

                $scope.invoke = function () {
                    $rootScope.$broadcast('scrollEvent');
                };

                $element.bind('scroll', function () {

                    $timeout.cancel(scrollTimeoutId);

                    // wait for 200ms and then invoke listeners (simulates stop event)
                    scrollTimeoutId = $timeout($scope.invoke, 50);

                });


            }
        };
    });

angular.module('ionic-img-lazy-load').directive(
    'imageLazySrc', function ($document) {
        return {
            restrict: 'A',
            link: function ($scope, $element, $attributes) {

                var deregistration = $scope.$on('scrollEvent', function () {
                        console.log('scroll');
                        if (isInView()) {
                            $element[0].src = $attributes.imageLazySrc; // set src attribute on element (it will load image)
                            deregistration();
                        }
                    }
                );

                function isInView() {

                    var clientHeight = $document[0].documentElement.clientHeight;
                    var clientWidth = $document[0].documentElement.clientWidth;
                    var imageRect = $element[0].getBoundingClientRect();
                    return  (imageRect.top >= 0 && imageRect.bottom <= clientHeight) && (imageRect.left >= 0 && imageRect.right <= clientWidth);
                }

                // bind listener
                // listenerRemover = scrollAndResizeListener.bindListener(isInView);

                // unbind event listeners if element was destroyed
                // it happens when you change view, etc
                $element.on('$destroy', function () {
                    deregistration();
                });

                // explicitly call scroll listener (because, some images are in viewport already and we haven't scrolled yet)
                if (isInView()) {
                    $element[0].src = $attributes.imageLazySrc; // set src attribute on element (it will load image)
                    deregistration();
                }
            }
        };
    }
);
{'fraction_non_alphanumeric': 0.1122780217681879, 'fraction_numerical': 0.008019858697727707, 'mean_word_length': 1.4082758620689655, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2231959', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1201, 'n_words': 295}