$(document).ready(function() {

    /**
     * Replaces tokens in a string with values in a supplied key-value map.
     */
    if (!String.prototype.supplant) {
        String.prototype.supplant = function(o) {
            return this.replace(/\{([^{}]*)\}/g, function (a, b) {
                var r = o[b];
                return typeof r === 'string' || typeof r === 'number' ? r : a;
            });
        };
    }
    
    /**
     * Parses the GET query and returns a key-value map of the data.
     */
    if (!HTMLDocument.prototype.parseQuery) {
        HTMLDocument.prototype.parseQuery = function() {
            if (!document.location.search)
                return {};
            var params = {};
            $.each(document.location.search.substring(1).split(/&/g), function(i, token) {
                var parts = token.split(/=/, 2);
                params[parts[0]] = parts[1];
            });
            return params;
        }
    }
    
    // Convenience constants
    var WIN = $(window);
    
    // Cause <a> elems with the a-newtab class to open in a new tab.
    $('a.a-newtab').attr('target', '_BLANK');
    
    // Cause the navbar to expand when clicking the navbar-expand button.
    $('a.navbar-expand').click(function(e) {
        $('.navbar-links').toggleClass('navbar-expanded');
    });
    
    // Card grid interaction functions
    var cardsInterpolated = false;
    
    var cardInterpolate = () => {
        cardsInterpolated = true;
        $('.card-parent').each((ind, elem) => {
            var cols = $(elem).children('.card-col'), cards = [], i = 0, card;
            while (card = $(cols[i]).children('.card:eq(0)'), card.size() > 0) {
                cards.push(card.detach());
                if (++i >= cols.size())
                    i = 0;
            }
            cols.each((i, elem) => $(elem).children().detach());
            var col0 = cols.filter('.card-col:eq(0)');
            $.each(cards, (ind, card) => col0.append(card));
        });
    };
    
    var cardDeinterpolate = () => {
        cardsInterpolated = false;
        $('.card-parent').each((ind, elem) => {
            var cols = $(elem).children('.card-col'), col0 = cols.filter('.card-col:eq(0)'), cards = [];
            col0.children().each((ind, card) => cards.push($(card).detach()));
            $.each(cards, (ind, card) => $(cols[ind % cols.size()]).append(card));
        });
    };
    
    // Listens for when the browser window is resized.
    var onWindowResize = e => {
        if (WIN.width() > 768) {
            if (cardsInterpolated)
                cardDeinterpolate();
        } else {
            if (!cardsInterpolated)
                cardInterpolate();
        }
    };
    WIN.resize(onWindowResize);
    onWindowResize();

});

/**
 * Adds a card to a card grid.
 */
var addCard = (parent, card) => {
    if (parent.hasClass('card-parent') && card.hasClass('card')) {
        var cols = $(parent).children('.card-col'), size = 0, col;
        for (var i = 0;; i++) {
            if (i >= cols.size()) {
                col = cols.filter('.card-col:eq(0)');
                break;
            }
            col = $(cols[i]);
            var children = col.children().size();
            if (children < size)
                break;
            size = children;
        }
        col.append(card);
    }
    else
        throw 'Invalid call to addCard!';
};
@@ -1,8 +1,897 @@
+/**%0A * Whether the cards have been interpolated yet.%0A */%0Avar cardsInterpolated = false;%0A%0A/**%0A * Adds a card to a card grid.%0A */%0Avar addCard = (parent, card) =%3E %7B%0A    if (parent.hasClass('card-parent') && card.hasClass('card')) %7B%0A        if (cardsInterpolated)%0A            $(parent).children('.card-col:eq(0)').append(card);%0A        else %7B%0A            var cols = $(parent).children('.card-col'), size = 0, col;%0A            for (var i = 0;; i++) %7B%0A                if (i %3E= cols.size()) %7B%0A                    col = cols.filter('.card-col:eq(0)');%0A                    break;%0A                %7D%0A                col = $(cols%5Bi%5D);%0A                var children = col.children().size();%0A                if (children %3C size)%0A                    break;%0A                size = children;%0A            %7D%0A            col.append(card);%0A        %7D%0A    %7D%0A    else%0A        throw 'Invalid call to addCard!';%0A%7D;%0A%0A
 $(docume
@@ -2257,48 +2257,8 @@
 ons%0A
-    var cardsInterpolated = false;%0A    %0A
     
@@ -3624,635 +3624,7 @@
 );%0A%0A
+
 %7D);
-%0A%0A/**%0A * Adds a card to a card grid.%0A */%0Avar addCard = (parent, card) =%3E %7B%0A    if (parent.hasClass('card-parent') && card.hasClass('card')) %7B%0A        var cols = $(parent).children('.card-col'), size = 0, col;%0A        for (var i = 0;; i++) %7B%0A            if (i %3E= cols.size()) %7B%0A                col = cols.filter('.card-col:eq(0)');%0A                break;%0A            %7D%0A            col = $(cols%5Bi%5D);%0A            var children = col.children().size();%0A            if (children %3C size)%0A                break;%0A            size = children;%0A        %7D%0A        col.append(card);%0A    %7D%0A    else%0A        throw 'Invalid call to addCard!';%0A%7D;

Make addCard work on mobile environments