<commit_before>function viewImage(href)
{
    function getImageFiles()
    {
        var items = $("#filesbox .filelink");
        var images = [];
    
        for (var i = 0; i < items.length; ++i)
        {
            var item = items[i];
            var mimeType = $(item).data("mimetype");
            var url = $(item).data("url");
            console.log("mimetype: " + mimeType + ", url: " + url);
            if (mimeType.indexOf("image/") === 0)
            {
                images.push(url);
            }
        }
    
        return images;
    }
    
    function previousImage()
    {
        var img = $("#image-popup img");
        var src = img.attr("src");
        var images = getImageFiles();
    
        var idx = images.indexOf(src);
        if (idx !== -1)
        {
            if (idx > 0)
            {
                viewImage(images[idx - 1]);
            }
            else
            {
                viewImage(images[images.length - 1]);
            }
        }
    }
    
    function nextImage()
    {
        var img = $("#image-popup img");
        var src = img.attr("src");
        var images = getImageFiles();
    
        console.log("src: " + src);
        console.log(images);
        var idx = images.indexOf(src);
        if (idx !== -1)
        {
            if (idx < images.length - 1)
            {
                viewImage(images[idx + 1]);
            }
            else
            {
                viewImage(images[0]);
            }
        }
    }
    

    var popup = $("#image-popup");
    var img = popup.find("img");

    var w = popup.width() - 32;
    var h = popup.height() - 32;

    img.css("maxWidth", w + "px");
    img.css("maxHeight", h + "px");

    img.off("load").one("load", function ()
    {
        sh.popup_close("busy-popup");
        
        if (popup.is(".sh-visible"))
        {
            img.parent().animate({
                width: (img.width() + 2) + "px",
                height: (img.height() + 2) + "px"
            }, 350, function ()
            {
                img.css("visibility", "inherit");
            });
        }
        else
        {
            img.parent().width(img.width());
            img.parent().height(img.height());
            img.css("visibility", "inherit");
            sh.popup("image-popup");
            $("#image-popup").attr("tabindex", -1).focus();
        }
    });
    /*
    $("#image-popup-previous").off("click").one("click", previousImage);
    $("#image-popup-next").off("click").one("click", nextImage);
    */
    $("#image-popup").off("keydown").on("keydown", function (ev)
    {
        if (! $(this).hasClass("sh-visible"))
        {
            return;
        }

        console.log("key pressed: " + ev.which);
        switch (ev.which)
        {
        case 37:
            previousImage();
            break;

        case 39:
            nextImage();
            break;
        }
        ev.preventDefault();
    });

    img.off("touchstart").on("touchstart", function (ev)
    {
        this.swipeContext = {
            beginX: ev.originalEvent.touches[0].screenX,
            dx: 0
        };

        $("#image-popup h1").css("display", "none");
    });

    img.off("touchmove").on("touchmove", function (ev)
    {
        var dx = ev.originalEvent.touches[0].screenX - this.swipeContext.beginX;
    
        var value = Math.min(1.0, Math.abs(dx) / ($(window).width() / 3));

        $(this).css("margin-left", dx)
               .css("opacity", 1.0 - value);

        this.swipeContext.dx = dx;
    });

    img.off("touchend").on("touchend", function (ev)
    {
        var dx = this.swipeContext.dx;
        if (dx < - $(window).width() / 3)
        {<commit_msg>prevent touch scrolling while the image popup is visible<commit_after>function viewImage(href)
{
    function getImageFiles()
    {
        var items = $("#filesbox .filelink");
        var images = [];
    
        for (var i = 0; i < items.length; ++i)
        {
            var item = items[i];
            var mimeType = $(item).data("mimetype");
            var url = $(item).data("url");
            console.log("mimetype: " + mimeType + ", url: " + url);
            if (mimeType.indexOf("image/") === 0)
            {
                images.push(url);
            }
        }
    
        return images;
    }
    
    function previousImage()
    {
        var img = $("#image-popup img");
        var src = img.attr("src");
        var images = getImageFiles();
    
        var idx = images.indexOf(src);
        if (idx !== -1)
        {
            if (idx > 0)
            {
                viewImage(images[idx - 1]);
            }
            else
            {
                viewImage(images[images.length - 1]);
            }
        }
    }
    
    function nextImage()
    {
        var img = $("#image-popup img");
        var src = img.attr("src");
        var images = getImageFiles();
    
        console.log("src: " + src);
        console.log(images);
        var idx = images.indexOf(src);
        if (idx !== -1)
        {
            if (idx < images.length - 1)
            {
                viewImage(images[idx + 1]);
            }
            else
            {
                viewImage(images[0]);
            }
        }
    }
    

    var popup = $("#image-popup");
    var img = popup.find("img");

    var w = popup.width() - 32;
    var h = popup.height() - 32;

    img.css("maxWidth", w + "px");
    img.css("maxHeight", h + "px");

    img.off("load").one("load", function ()
    {
        sh.popup_close("busy-popup");
        
        if (popup.is(".sh-visible"))
        {
            img.parent().animate({
                width: (img.width() + 2) + "px",
                height: (img.height() + 2) + "px"
            }, 350, function ()
            {
                img.css("visibility", "inherit");
            });
        }
        else
        {
            img.parent().width(img.width());
            img.parent().height(img.height());
            img.css("visibility", "inherit");
            sh.popup("image-popup");
            $("#image-popup").attr("tabindex", -1).focus();
        }
    });
    /*
    $("#image-popup-previous").off("click").one("click", previousImage);
    $("#image-popup-next").off("click").one("click", nextImage);
    */
    $("#image-popup").off("keydown").on("keydown", function (ev)
    {
        if (! $(this).hasClass("sh-visible"))
        {
            return;
        }

        console.log("key pressed: " + ev.which);
        switch (ev.which)
        {
        case 37:
            previousImage();
            break;

        case 39:
            nextImage();
            break;
        }
        ev.preventDefault();
    });

    img.off("touchstart").on("touchstart", function (ev)
    {
        this.swipeContext = {
            beginX: ev.originalEvent.touches[0].screenX,
            dx: 0
        };

        $("#image-popup h1").css("display", "none");
    });

    img.off("touchmove").on("touchmove", function (ev)
    {
        var dx = ev.originalEvent.touches[0].screenX - this.swipeContext.beginX;
    
        var value = Math.min(1.0, Math.abs(dx) / ($(window).width() / 3));

        $(this).css("margin-left", dx)
               .css("opacity", 1.0 - value);

        this.swipeContext.dx = dx;

        ev.preventDefault();
    });

    img.off("touchend").on("touchend", function (ev)
    {
        var dx = this.swipeContext.dx;
        if (dx < - $(window).width() / 3)
        {
{'fraction_non_alphanumeric': 0.1738205980066445, 'fraction_numerical': 0.009036544850498339, 'mean_word_length': 1.3816455696202532, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3350834', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2235, 'n_words': 413}