<commit_before>// Masonry is released under the MIT license: https://desandro.mit-license.org/

// global variables
var filters = new Map()
var $active_filters_ul = $('.active-filters');
var $grid = $('#grid')
var DIV = "div";

// Call these functions when page loads
$(document).ready(function() {
    // Initialize Masonry
    $grid.masonry({
        itemSelector: '.grid-item',
        percentPosition: true,
        // horizontalOrder: true,
        columnWidth: '.grid-sizer'
    });

    // get all data
    fetchAllSpeciesData("common_name");

    // hides filters on click
    deleteFilter()

    // lets users search for a species
    searchName();
});

/** 
 * Fetches sample JSON and appends each species to the gallery
 * @param sortBy: the parameter to sort by
 */
function fetchAllSpeciesData(sortBy) {
    const parameters = {'sortBy': sortBy};
    const url = createQueryString("/allData", parameters);
    clearGallery();
    
    fetch(url).then(response => response.json()).then(speciesData => {
        for (var species in speciesData) {
            // Append images to grid
            var $html = $(
                '<div class="grid-filters ' + speciesData[species].status + ' ' + speciesData[species].trend + ' ' + speciesData[species].taxonomicPath.order_t + ' ' + speciesData[species].taxonomicPath.class_t + '">' +
                    '<div class="grid-item">' +
                        '<img src="'+ speciesData[species].imageLink +'" />' +
                        '<div class="overlay">' + 
                            '<a href="/species-template.html?species=' + speciesData[species].commonName + '"> ' + speciesData[species].commonName + '</a>' +
                        '</div> ' +
                    '</div>' +
                '</div>'); 

            $grid.append($html)
                // add and lay out newly appended items<commit_msg>Add fetch() error-handling to gallery.js<commit_after>// Masonry is released under the MIT license: https://desandro.mit-license.org/

// global variables
var filters = new Map()
var $active_filters_ul = $('.active-filters');
var $grid = $('#grid')
var DIV = "div";

// Call these functions when page loads
$(document).ready(function() {
    // Initialize Masonry
    $grid.masonry({
        itemSelector: '.grid-item',
        percentPosition: true,
        // horizontalOrder: true,
        columnWidth: '.grid-sizer'
    });

    // get all data
    fetchAllSpeciesData("common_name");

    // hides filters on click
    deleteFilter()

    // lets users search for a species
    searchName();
});

// Helper function to check for errors in fetch() calls
function handleErrors(response) {
    if (!response.ok) {
        throw Error(response.statusText);
    }
    return response.json();
}

/** 
 * Fetches sample JSON and appends each species to the gallery
 * @param sortBy: the parameter to sort by
 */
function fetchAllSpeciesData(sortBy) {
    const parameters = {'sortBy': sortBy};
    const url = createQueryString("/allData", parameters);
    clearGallery();
    
    fetch(url).then(response => handleErrors(response)).then(speciesData => {
        for (var species in speciesData) {
            // Append images to grid
            var $html = $(
                '<div class="grid-filters ' + speciesData[species].status + ' ' + speciesData[species].trend + ' ' + speciesData[species].taxonomicPath.order_t + ' ' + speciesData[species].taxonomicPath.class_t + '">' +
                    '<div class="grid-item">' +
                        '<img src="'+ speciesData[species].imageLink +'" />' +
                        '<div class="overlay">' + 
                            '<a href="/species-template.html?species=' + speciesData[species].commonName + '"> ' + speciesData[species].commonName + '</a>' +
                        '</div> ' +
                    '</div>' +
                '</div>'); 

            $grid.append($html)
                // add and lay out newly appended items
{'fraction_non_alphanumeric': 0.14573370249181977, 'fraction_numerical': 0.0, 'mean_word_length': 2.2627257799671594, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '801620', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1071, 'n_words': 276}