<commit_before>/*======================================================
************   Image Lazy Loading   ************
************   Based on solution by <NAME>, https://github.com/MarcGodard   ************
======================================================*/
app.initImagesLazyLoad = function (pageContainer) {
    pageContainer = $(pageContainer);

    // Lazy images
    var lazyLoadImages;
    if (pageContainer.hasClass('lazy')) {
        lazyLoadImages = pageContainer;
        pageContainer = lazyLoadImages.parents('.page');
    }
    else {
        lazyLoadImages = pageContainer.find('.lazy');
    }
    if (lazyLoadImages.length === 0) return;

    // Scrollable page content
    var pageContent;
    if (pageContainer.hasClass('page-content'))  {
        pageContent = pageContainer;
        pageContainer = pageContainer.parents('.page');
    }
    else  {
        pageContent = pageContainer.find('.page-content');
    }
    if (pageContent.length === 0) return;

    // Placeholder
    var placeholderSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEXCwsK592mkAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==';
    if (typeof app.params.imagesLazyLoadPlaceholder === 'string') {
        placeholderSrc = app.params.imagesLazyLoadPlaceholder;
    }
    if (app.params.imagesLazyLoadPlaceholder !== false) lazyLoadImages.each(function(){
        if ($(this).attr('data-src') && !$(this).attr('src')) $(this).attr('src', placeholderSrc);
    });

    // load image
    var imagesSequence = [];
    var imageIsLoading = false;
    function loadImage(el) {
        el = $(el);

        var bg = el.attr('data-background');
        var src = bg ? bg : el.attr('data-src');
        if (!src) return;

        function onLoad() {
            el.removeClass('lazy').addClass('lazy-loaded');
            if (bg) {
                el.css('background-image', 'url(' + src + ')');
            }
            else {
                el.attr('src', src);
            }

            if (app.params.imagesLazyLoadSequential) {
                imageIsLoading = false;
                if (imagesSequence.length > 0) {
                    loadImage(imagesSequence.shift());
                }
            }
        }

        function onError() {
            el.removeClass('lazy').addClass('lazy-loaded');
            if (bg) {
                el.css('background-image', 'url(' + placeholderSrc + ')');
            }
            else {
                el.attr('src', placeholderSrc);
            }

            if (app.params.imagesLazyLoadSequential) {
                imageIsLoading = false;
                if (imagesSequence.length > 0) {
                    loadImage(imagesSequence.shift());
                }
            }
        }

        if (app.params.imagesLazyLoadSequential) {
            if (imageIsLoading) {
                if (imagesSequence.indexOf(el[0]) < 0) imagesSequence.push(el[0]);
                return;
            }
        }

        // Loading flag
        imageIsLoading = true;

        var image = new Image();
        image.onload = onLoad;
        image.onerror = onError;
        image.src =src;
		
		// Add loaded callback
		if (app.params.onLazyLoad && !el.hasClass('lazy-loaded')) app.params.onLazyLoad(el);
    }
    function lazyHandler() {
        lazyLoadImages = pageContainer.find('.lazy');
        lazyLoadImages.each(function(index, el) {
            el = $(el);
            if (el.parents('.tab:not(.active)').length > 0) {
                return;
            }
            if (isElementInViewport(el[0])) {
                loadImage(el);
            }
        });
    }

    function isElementInViewport (el) {
        var rect = el.getBoundingClientRect();
        var threshold = app.params.imagesLazyLoadThreshold || 0;
        return (
            rect.top >= (0 - threshold) &&
            rect.left >= (0 - threshold) &&
            rect.top <= (app.height + threshold) &&
            rect.left <= (app.width + threshold)
        );<commit_msg>lazy callbacks and events<commit_after>/*======================================================
************   Image Lazy Loading   ************
************   Based on solution by <NAME>, https://github.com/MarcGodard   ************
======================================================*/
app.initImagesLazyLoad = function (pageContainer) {
    pageContainer = $(pageContainer);

    // Lazy images
    var lazyLoadImages;
    if (pageContainer.hasClass('lazy')) {
        lazyLoadImages = pageContainer;
        pageContainer = lazyLoadImages.parents('.page');
    }
    else {
        lazyLoadImages = pageContainer.find('.lazy');
    }
    if (lazyLoadImages.length === 0) return;

    // Scrollable page content
    var pageContent;
    if (pageContainer.hasClass('page-content'))  {
        pageContent = pageContainer;
        pageContainer = pageContainer.parents('.page');
    }
    else  {
        pageContent = pageContainer.find('.page-content');
    }
    if (pageContent.length === 0) return;

    // Placeholder
    var placeholderSrc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEXCwsK592mkAAAACklEQVQI12NgAAAAAgAB4iG8MwAAAABJRU5ErkJggg==';
    if (typeof app.params.imagesLazyLoadPlaceholder === 'string') {
        placeholderSrc = app.params.imagesLazyLoadPlaceholder;
    }
    if (app.params.imagesLazyLoadPlaceholder !== false) lazyLoadImages.each(function(){
        if ($(this).attr('data-src') && !$(this).attr('src')) $(this).attr('src', placeholderSrc);
    });

    // load image
    var imagesSequence = [];
    var imageIsLoading = false;
    function loadImage(el) {
        el = $(el);

        var bg = el.attr('data-background');
        var src = bg ? bg : el.attr('data-src');
        if (!src) return;

        function onLoad() {
            el.removeClass('lazy').addClass('lazy-loaded');
            if (bg) {
                el.css('background-image', 'url(' + src + ')');
            }
            else {
                el.attr('src', src);
            }

            if (app.params.imagesLazyLoadSequential) {
                imageIsLoading = false;
                if (imagesSequence.length > 0) {
                    loadImage(imagesSequence.shift());
                }
            }
            el.trigger('lazy-loaded');
            if (app.params.onLazyLoaded) app.params.onLazyLoaded(el);
        }

        function onError() {
            el.removeClass('lazy').addClass('lazy-loaded');
            if (bg) {
                el.css('background-image', 'url(' + placeholderSrc + ')');
            }
            else {
                el.attr('src', placeholderSrc);
            }

            if (app.params.imagesLazyLoadSequential) {
                imageIsLoading = false;
                if (imagesSequence.length > 0) {
                    loadImage(imagesSequence.shift());
                }
            }
            el.trigger('lazy-error');
            if (app.params.onLazyError) app.params.onLazyError(el);
        }

        if (app.params.imagesLazyLoadSequential) {
            if (imageIsLoading) {
                if (imagesSequence.indexOf(el[0]) < 0) imagesSequence.push(el[0]);
                return;
            }
        }

        // Loading flag
        imageIsLoading = true;

        var image = new Image();
        image.onload = onLoad;
        image.onerror = onError;
        image.src =src;

        // Add loaded callback and events
        el.trigger('lazy-load');
        if (app.params.onLazyLoad && !el.hasClass('lazy-loaded')) app.params.onLazyLoad(el);
    }
    function lazyHandler() {
        lazyLoadImages = pageContainer.find('.lazy');
        lazyLoadImages.each(function(index, el) {
            el = $(el);
            if (el.parents('.tab:not(.active)').length > 0) {
                return;
            }
            if (isElementInViewport(el[0])) {
                loadImage(el);
            }
        });
    }

    function isElementInViewport (el) {
        var rect = el.getBoundingClientRect();
        var threshold = app.params.imagesLazyLoadThreshold || 0;
        return (
            rect.top >= (0 - threshold) &&
            rect.left >= (0 - threshold) &&
            rect.top <= (app.height + threshold) &&
            rect.left <= (app.width + threshold)
        );
{'fraction_non_alphanumeric': 0.16485095175386089, 'fraction_numerical': 0.006225308272476955, 'mean_word_length': 1.94673721340388, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '3493147', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2318, 'n_words': 408}