<commit_before>(function(){
    
$(function(){
    new Backbone.Router({
        routes: {
            '': IndexView,
            'walkthrough': WalkthroughView, 
            'walkthrough_end': IndexView,
            'gap_sheets': GapSheetIndexView,
            ':unique_lga/lga_overview': view(LGAView, 'overview'),
            ':unique_lga/lga_health': view(LGAView, 'health'),              
            ':unique_lga/lga_education': view(LGAView, 'education'),
            ':unique_lga/lga_water': view(LGAView, 'water'),
            ':unique_lga/map_overview': view(MapView, 'overview'),
            ':unique_lga/map_health': view(MapView, 'health'),
            ':unique_lga/map_education': view(MapView, 'education'),  
            ':unique_lga/map_water': view(MapView, 'water'),  
            ':unique_lga/facilities_overview': view(FacilitiesView, 'overview'),
            ':unique_lga/facilities_health': view(FacilitiesView, 'health'),
            ':unique_lga/facilities_education': view(FacilitiesView, 'education'),
            ':unique_lga/facilities_water': view(FacilitiesView, 'water'),
            ':unique_lga/gap_sheet_education': view(GapSheetView, 'education'),
            ':unique_lga/gap_sheet_health': view(GapSheetView, 'health')
        }
    });

    MapView.init();
    FacilitiesView.init();
    render_lga_search(NMIS.sorted_lgas);
    Backbone.history.start();
});



// Helper Functions
// ===========================================

function loadLGACache(unique_lga){
    // Loads local storage cache into memory
    if (window.localStorage && localStorage.lgas){
        var lgas = $.parseJSON(localStorage.lgas);
        _.each(lgas, function(lga){
            NMIS.lgas[lga.unique_lga] = lga;
        });
    }
}

function setLGACache(lga){
    // Local storage LGA cache
    if (window.localStorage && JSON){
        var lgas = $.parseJSON(localStorage.lgas || '[]');
        lgas.push(lga);
        while (true){
            try {
                localStorage.lgas = JSON.stringify(lgas);
                break;
            } catch(e){
                // Assume quota exceeded error
                // Currently no consistent error msg across browsers
                // http://chrisberkhout.com/blog/localstorage-errors/
                // Remove the oldest LGA and try again
                lgas.shift();
            }
        }
    }
}

function view(viewObj, sector){
    // Wrapper for LGA based views. Fetches the appropriate 
    // LGA JSON data before calling the render() function of a view.

    function render_wrap(lga, sector){
        $('.map_view, .loading').hide();
        $('#content').stop().css('opacity', 1);
        $('#content .index').removeClass('index');
        $('#content .container').show();
        $(window).scrollTop(0);
        viewObj.render(lga, sector);
        Walkthrough.show();
    }

    return function(unique_lga){
        // Load LGA from in memory cache
        var lga = NMIS.lgas[unique_lga];
        if (lga){
            render_wrap(lga, sector);
        } else {
            $('.loading').show();
            $('#content').fadeTo(100, 0.5);

            // Fetch LGA data from network
            var url = NMIS.lgas_folder + unique_lga + '.json';
            $.getJSON(url, function(lga){
                    NMIS.lgas[unique_lga] = lga;
                    setLGACache(lga);
                    render_wrap(lga, sector);
                })
                .error(function ajaxError(xhr, textStatus, errorThrown){
                    // If there is a network error, load localStorage cache into memory
                    loadLGACache();
                    var lga = NMIS.lgas[unique_lga];
                    if (lga){
                        return render_wrap(lga, sector);
                    }

                    $('#explore_header, .map_view, .loading').hide();
                    $('#content .content').html(
                        '<h1 class="notfound">Sorry, this LGA\'s data is currently unavailable</h1>');
                    $('#content .container').show();
                });
        }
    }
}


function render_header(lga, active_view, sector){
    // Renders the LGA navigation bar
    var template = $('#explore_header_template').html();
    var html = _.template(template, {
        lga: lga,
        active_view: active_view,
        sector: sector<commit_msg>Cleanup<commit_after>(function(){
    
$(function(){
    new Backbone.Router({
        routes: {
            '': IndexView,
            'walkthrough': WalkthroughView, 
            'walkthrough_end': IndexView,
            'gap_sheets': GapSheetIndexView,
            ':unique_lga/lga_overview': view(LGAView, 'overview'),
            ':unique_lga/lga_health': view(LGAView, 'health'),              
            ':unique_lga/lga_education': view(LGAView, 'education'),
            ':unique_lga/lga_water': view(LGAView, 'water'),
            ':unique_lga/map_overview': view(MapView, 'overview'),
            ':unique_lga/map_health': view(MapView, 'health'),
            ':unique_lga/map_education': view(MapView, 'education'),  
            ':unique_lga/map_water': view(MapView, 'water'),  
            ':unique_lga/facilities_overview': view(FacilitiesView, 'overview'),
            ':unique_lga/facilities_health': view(FacilitiesView, 'health'),
            ':unique_lga/facilities_education': view(FacilitiesView, 'education'),
            ':unique_lga/facilities_water': view(FacilitiesView, 'water'),
            ':unique_lga/gap_sheet_education': view(GapSheetView, 'education'),
            ':unique_lga/gap_sheet_health': view(GapSheetView, 'health')
        }
    });

    MapView.init();
    FacilitiesView.init();
    render_lga_search(NMIS.sorted_lgas);
    Backbone.history.start();
});



// Helper Functions
// ===========================================

function loadLGACache(unique_lga){
    // Loads local storage cache into memory
    if (window.localStorage && localStorage.lgas){
        var lgas = $.parseJSON(localStorage.lgas);
        _.each(lgas, function(lga){
            NMIS.lgas[lga.unique_lga] = lga;
        });
    }
}

function setLGACache(lga){
    // Local storage LGA cache
    if (window.localStorage && JSON){
        var lgas = $.parseJSON(localStorage.lgas || '[]');
        lgas.push(lga);
        while (true){
            try {
                localStorage.lgas = JSON.stringify(lgas);
                break;
            } catch(e){
                // Assume quota exceeded error
                // Currently no consistent error msg across browsers
                // http://chrisberkhout.com/blog/localstorage-errors/
                // Remove the oldest LGA and try again
                lgas.shift();
            }
        }
    }
}

function view(viewObj, sector){
    // Wrapper for LGA based views. Fetches the appropriate 
    // LGA JSON data before calling the render() function of a view.

    function render_wrap(lga, sector){
        $('.map_view, .loading').hide();
        $('#content').stop().css('opacity', 1);
        $('#content .index').removeClass('index');
        $('#content .container').show();
        $(window).scrollTop(0);
        viewObj.render(lga, sector);
        Walkthrough.show();
    }

    return function(unique_lga){
        // Load LGA from in memory cache
        var lga = NMIS.lgas[unique_lga];
        if (lga){
            render_wrap(lga, sector);
        } else {
            $('.loading').show();
            $('#content').fadeTo(100, 0.5);

            // Fetch LGA data from network
            var url = NMIS.lgas_folder + unique_lga + '.json';
            $.getJSON(url, function(lga){
                    NMIS.lgas[unique_lga] = lga;
                    setLGACache(lga);
                    render_wrap(lga, sector);
                })
                .error(function(xhr){
                    // If there is a network error, load localStorage cache into memory
                    loadLGACache();
                    var lga = NMIS.lgas[unique_lga];
                    if (lga){
                        return render_wrap(lga, sector);
                    }

                    $('#explore_header, .map_view, .loading').hide();
                    $('#content .content').html(
                        '<h1 class="notfound">Sorry, this LGA\'s data is currently unavailable</h1>');
                    $('#content .container').show();
                });
        }
    }
}


function render_header(lga, active_view, sector){
    // Renders the LGA navigation bar
    var template = $('#explore_header_template').html();
    var html = _.template(template, {
        lga: lga,
        active_view: active_view,
        sector: sector
{'fraction_non_alphanumeric': 0.1433979580130779, 'fraction_numerical': 0.0020649305953883215, 'mean_word_length': 1.9314055144586415, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '761468', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2458, 'n_words': 498}