<commit_before>
// Debug retina/non-retina by changing to 1/2
// window.devicePixelRatio = 1;

window.requestAnimationFrame = 
    typeof window === 'undefined' ? 
    function(){} : 
    ( window.requestAnimationFrame || 
      window.mozRequestAnimationFrame ||
      window.webkitRequestAnimationFrame ||
      window.msRequestAnimationFrame || function(callback) { setTimeout(callback, 1000/60); } );

require([
    'jquery', 
    'jqueryui',
    'bootstrap',
    'es5shim',
    'es5sham',

    'flight/lib/compose',
    'flight/lib/registry',
    'flight/lib/advice',
    'flight/lib/logger',
    'flight/lib/debug',
    
     // Make underscore available everywhere
    'underscore',

    'util/visibility',
    'service/user',

    'easing',
    'scrollStop',
    'bootstrap-datepicker',
    'util/jquery.flight',
    'util/jquery.removePrefixedClasses'
],
function(jQuery, jQueryui, bootstrap, es5shim, es5sham, compose, registry, advice, withLogging, debug, _, Visibility, UserService) {
    'use strict';

    configureApplication();

    function configureApplication() {
        // Flight Logging
        debug.enable(true);
        DEBUG.events.logNone();

        // Default datepicker options
        $.fn.datepicker.defaults.format = "yyyy-mm-dd";
        $.fn.datepicker.defaults.autoclose = true;

        Visibility.attachTo(document);
        $(window).on('hashchange', loadApplicationTypeBasedOnUrlHash);

        loadApplicationTypeBasedOnUrlHash();
    }

    /**
     * Switch between lumify and lumify-fullscreen-details based on url hash
     */
    function loadApplicationTypeBasedOnUrlHash(e) {
        var ids = graphVertexIdsToOpen(),

            // Is this the popoout details app? ids passed to hash?
            popoutDetails = !!(ids && ids.length),

            // If this is a hash change
            event = e && e.originalEvent,

            // Is this the default lumify application?
            mainApp = !popoutDetails;

        // Ignore hash change if not in popout and not going to popout
        if (event && !isPopoutUrl(event.newURL) && !isPopoutUrl(event.oldURL)) {
            return;
        }

        new UserService().isLoginRequired()
            .done(function() {
                attachApplication(false);
            })
            .fail(function() {
                attachApplication(true);
            });


        function attachApplication(loginRequired) {
            $('html')
                .toggleClass('fullscreenApp', mainApp)
                .toggleClass('fullscreenDetails', popoutDetails)
            window.isFullscreenDetails = popoutDetails;
            

            if (loginRequired) {
                require(['login'], function(Login) {
                    Login.teardownAll();
                    Login.attachTo('#login');
                });
            } else if (popoutDetails) {
                $('#login').remove();
                require(['appFullscreenDetails'], function(PopoutDetailsApp) {
                    PopoutDetailsApp.teardownAll();
                    PopoutDetailsApp.attachTo('#app', {
                        graphVertexIds: ids
                    });
                });
            } else {
                $('#login').remove();
                require(['app'], function(App) {
                    if (event) {
                        location.replace(location.href);
                    } else {
                        App.teardownAll();
                        App.attachTo('#app');
                    }

                    _.defer(function() {
                        // Cache login in case server goes down
                        require(['login'], function(Login) {
                        });
                    });
                });
            }
        }
    }

    function isPopoutUrl(url) {
        var ids = graphVertexIdsToOpen(url)

        return !!(ids && ids.length);
    }

    function graphVertexIdsToOpen(url) {
        // http://...#v=1,2,3

        var h = location.hash;

        if (url) {
            var urlMatch = url.match(/.*?(#.*)$/);
            if (urlMatch) {
                h = urlMatch[1];
            } else h = '';
        }

        if (!h || h.length === 0) return;

        var m = h.match(/^#?v=(.+)$/);

        if (m && m.length === 2 && m[1].length) {
            return m[1].split(',');
        }
    }
});


<commit_msg>Catch flight excemption that prevents app startup.<commit_after>
// Debug retina/non-retina by changing to 1/2
// window.devicePixelRatio = 1;

window.requestAnimationFrame = 
    typeof window === 'undefined' ? 
    function(){} : 
    ( window.requestAnimationFrame || 
      window.mozRequestAnimationFrame ||
      window.webkitRequestAnimationFrame ||
      window.msRequestAnimationFrame || function(callback) { setTimeout(callback, 1000/60); } );

require([
    'jquery', 
    'jqueryui',
    'bootstrap',
    'es5shim',
    'es5sham',

    'flight/lib/compose',
    'flight/lib/registry',
    'flight/lib/advice',
    'flight/lib/logger',
    'flight/lib/debug',
    
     // Make underscore available everywhere
    'underscore',

    'util/visibility',
    'service/user',

    'easing',
    'scrollStop',
    'bootstrap-datepicker',
    'util/jquery.flight',
    'util/jquery.removePrefixedClasses'
],
function(jQuery, jQueryui, bootstrap, es5shim, es5sham, compose, registry, advice, withLogging, debug, _, Visibility, UserService) {
    'use strict';

    configureApplication();

    function configureApplication() {
        // Flight Logging
        try {
            debug.enable(true);
            DEBUG.events.logNone();
        } catch(e) {
            console.warn('Error enabling DEBUG mode for flight, probably because Safari Private Browsing enabled', e);
        }

        // Default datepicker options
        $.fn.datepicker.defaults.format = "yyyy-mm-dd";
        $.fn.datepicker.defaults.autoclose = true;

        Visibility.attachTo(document);
        $(window).on('hashchange', loadApplicationTypeBasedOnUrlHash);

        loadApplicationTypeBasedOnUrlHash();
    }

    /**
     * Switch between lumify and lumify-fullscreen-details based on url hash
     */
    function loadApplicationTypeBasedOnUrlHash(e) {
        var ids = graphVertexIdsToOpen(),

            // Is this the popoout details app? ids passed to hash?
            popoutDetails = !!(ids && ids.length),

            // If this is a hash change
            event = e && e.originalEvent,

            // Is this the default lumify application?
            mainApp = !popoutDetails;

        // Ignore hash change if not in popout and not going to popout
        if (event && !isPopoutUrl(event.newURL) && !isPopoutUrl(event.oldURL)) {
            return;
        }

        new UserService().isLoginRequired()
            .done(function() {
                attachApplication(false);
            })
            .fail(function() {
                attachApplication(true);
            });


        function attachApplication(loginRequired) {
            $('html')
                .toggleClass('fullscreenApp', mainApp)
                .toggleClass('fullscreenDetails', popoutDetails)
            window.isFullscreenDetails = popoutDetails;
            

            if (loginRequired) {
                require(['login'], function(Login) {
                    Login.teardownAll();
                    Login.attachTo('#login');
                });
            } else if (popoutDetails) {
                $('#login').remove();
                require(['appFullscreenDetails'], function(PopoutDetailsApp) {
                    PopoutDetailsApp.teardownAll();
                    PopoutDetailsApp.attachTo('#app', {
                        graphVertexIds: ids
                    });
                });
            } else {
                $('#login').remove();
                require(['app'], function(App) {
                    if (event) {
                        location.replace(location.href);
                    } else {
                        App.teardownAll();
                        App.attachTo('#app');
                    }

                    _.defer(function() {
                        // Cache login in case server goes down
                        require(['login'], function(Login) {
                        });
                    });
                });
            }
        }
    }

    function isPopoutUrl(url) {
        var ids = graphVertexIdsToOpen(url)

        return !!(ids && ids.length);
    }

    function graphVertexIdsToOpen(url) {
        // http://...#v=1,2,3

        var h = location.hash;

        if (url) {
            var urlMatch = url.match(/.*?(#.*)$/);
            if (urlMatch) {
                h = urlMatch[1];
            } else h = '';
        }

        if (!h || h.length === 0) return;

        var m = h.match(/^#?v=(.+)$/);

        if (m && m.length === 2 && m[1].length) {
            return m[1].split(',');
        }
    }
});



{'fraction_non_alphanumeric': 0.12751976834836842, 'fraction_numerical': 0.004677581022385567, 'mean_word_length': 1.6074332171893146, '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': '5512089', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2307, 'n_words': 477}