<commit_before>var hash = window.location.hash;

hide = function(element) {
    $(element).hide();
};

$(hash).appendTo('#selected');

ChangeUrl = function(title, url) {
    if (typeof (history.pushState) != "undefined") {
        var obj = { Title: title, Url: url };
        history.pushState(obj, obj.Title, obj.Url);
    } else {
        alert("Browser does not support HTML5.");
    }
}

getPosition = function(el) {
    return {
        top: $(el).offset().top,
        left: $(el).offset().left,
        width: $(el).width()
    }
}

var duration = 500;
var thumbs = {};

$('.collage-link').each(function(index) {
    thumbs[$(this).attr('id')] = $(this).find('img').attr('src');

    $(this).click(function(e) {
        small = this;
        id = $(small).attr('id');

        if (window.location.hash === '#'+id) {
            return;
        }

        e.preventDefault();

        next_id = $(small).next().attr('id');

        large = '#'+$('#selected').children().attr('id');
        a = getPosition(large);
        b = getPosition(small);
        [a.iw, a.ih] = $(large).data("size").split('x');
        [b.iw, b.ih] = $(small).data("size").split('x');

        $(large).animate({
            top: b.top - a.top,
            left: b.left - a.left,
            width: b.width
        }, duration , function() {
            if (next_id === undefined) {
                $(large).appendTo('#list').css({
                    top: 'auto',
                    left: 'auto'
                });
            }
            else {
                $(large).insertBefore('#'+next_id).css({
                    top: 'auto',
                    left: 'auto'
                });
            }
        }).find('.card-image').animate({
            height : a.ih/a.iw*b.width
        }, duration, function() {
            $(large).find('img').attr('src', thumbs[$(large).attr('id')]);
        }).find('.overlay').animate({
            opacity: 0
        }, duration, function() {
        });

        $(small).animate({
          top: a.top - b.top,
          left: a.left - b.left,
          width: a.width
        }, duration, function() {
            $(small).appendTo('#selected').css({
               top: 'auto',
               left: 'auto'
            });
        }).find('.card-image').animate({
            height: b.ih/b.iw*a.width
        }, duration, function() {
            $(small).find('img').attr('src', $(small).data("full"))
                .load(function() {
                    $('#'+id).find('.overlay').animate({
                        opacity: 0
                    }, duration);
                });
        }).find('.overlay').animate({
            opacity: 1
        }, duration, function(){
        });

        ChangeUrl(document.title, '#'+id);

    })
})<commit_msg>Prettify collage.js<commit_after>var duration = 500;
var thumbs = {};

changeUrl = function(title, url) {
    if (typeof (history.pushState) != "undefined") {
        var obj = { Title: title, Url: url };
        history.pushState(obj, obj.Title, obj.Url);
    } else {
        alert("Browser does not support HTML5.");
    }
}

id_hash = function(id) {
    return ("#" + id)
}

getData = function(el) {
    el = $(el);
    var id = el.attr('id');
    var next_id = el.next().attr('id');
    var [iw, ih] = el.data('size').split('x');
    return {
        id: id,
        iw: iw,
        ih: ih,
        id_hash: id_hash(id),
        next_id: next_id,
        next_id_hash: id_hash(next_id),
        width: el.width(),
        top: el.offset().top,
        left: el.offset().left,
        full: el.data('full'),
        thumb: thumbs[id]
    }
}

saveThumb = function(el) {
    thumbs[$(el).attr('id')] = $(el).find('img').attr('src')
}

finalPosition = function(i, f) {
    return {
        top: f.top - i.top,
        left: f.left - i.left,
        width: f.width,
        img_height: i.ih/i.iw*f.width
    }
}

topLeftAuto = {
    top: 'auto',
    left: 'auto'
}

opacity = function(o) {
    return {
        opacity: o
    }
}

largeToSmall = function(el, a, b, c, d, duration) {
    el.animate(c, duration, function() {
        if (b.next_id === undefined) {
            el.appendTo('#list').css(topLeftAuto);
        }
        else {
            el.insertBefore(b.next_id_hash).css(topLeftAuto);
        }
    }).find('.card-image').animate({
        height : c.img_height
    }, duration, function() {
        el.find('img').attr('src', a.thumb);
    }).find('.overlay').animate(opacity(0), duration);
}

smallToLarge = function(el, a, b, c, d, duration) {
    el.animate(d, duration, function() {
        el.appendTo('#selected').css(topLeftAuto);
    }).find('.card-image').animate({
        height: d.img_height
    }, duration, function() {
        el.find('img').attr('src', b.full)
            .load(function() {
                $(b.id_hash).find('.overlay').animate(opacity(0), duration);
            });
    }).find('.overlay').animate(opacity(1), duration);
}

$('.collage-link').each(function(index) {
    saveThumb(this);

    $(this).click(function(e) {
        small = $(this);

        large = $(id_hash($('#selected').children().attr('id')));
        a = getData(large);
        b = getData(small);
        c = finalPosition(a,b); //final position of large
        d = finalPosition(b,a); //final position of small

        if (window.location.hash === '#'+b.id) {
            return;
        }

        largeToSmall(large, a, b, c, d, duration);
        smallToLarge(small, a, b, c, d, duration);

        changeUrl(document.title, b.id_hash);
        e.preventDefault();
    })
})

hash = window.location.hash;
if (!$(hash).length) {
    $($('#list').children()[0]).appendTo('#selected').css(topLeftAuto);
}
else {
    $(hash).appendTo('#selected').css(topLeftAuto);
}
{'fraction_non_alphanumeric': 0.1986858032163237, 'fraction_numerical': 0.002593809441466367, 'mean_word_length': 1.8862275449101797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5471220', 'n_tokens_mistral': 1863, 'n_tokens_neox': 1811, 'n_words': 336}