<commit_before>/**
 * State.js
 * @param  {[type]} root    [description]
 * @param  {[type]} factory [description]
 * @return {[type]}         [description]
 */
( function ( window, factory ) {

    'use strict';

    if ( typeof define === 'function' && define.amd ) {

        define( [
            'jquery',
            './Util'
        ], function ( $, Util ) {
            return factory( window, $, Util );
        } );

    } else if ( typeof exports === 'object' ) {

        module.exports = factory(
            window,
            require( 'jquery' ),
            require( './Util' )
        );

    } else {

        window.StateManager = window.StateManager || {};

        window.StateManager.State = factory(
            window,
            window.jQuery,
            window.StateManager.Util
        );

    }

} ( window, function ( window, $, Util ) {

    'use strict';

    var name = 'State',
        debugEnabled = true,
        debug = debugEnabled ? Util.debug : function () {},
        $window = $( window )
    ;

    //////////////////////////////////////////////////////////////////////////////////////

    function init() {

        $window.on( 'StateManager.AfterInitState', newState );

    }

    /**
     * Decide where to focus the page after push state
     */
    function newState() {

        var state = window.history.state,
            scrollTarget = 0
        ;

        if ( state !== null && typeof state.scrollTarget !== 'undefined' && $( state.scrollTarget ).length > 0 )  {
            scrollTarget = $( state.scrollTarget ).first().offset().top;
        }

        if ( ! $( 'html' ).hasClass( 'initial-load' ) ) {

            $( 'html, body' )
                .stop()
                .animate({
                    'scrollTop' : scrollTarget
                }, 200 )
            ;

        } else {

            $( 'html' ).removeClass( 'initial-load' );

        }

        $window.trigger( 'OnDemandImages.Init' );

        // @todo: Break this out to its own module
        // $( '.scroll-to-anchor' ).each( function () {
        //     var $this = $( this );

        //     if ( ! $this.hasClass( 'initialized' ) ) {
        //         return;
        //     }

        //     $this
        //         .off( 'click.Manager' )
        //         .on( 'click.' + name, function ( event ) {

        //         var scroll_target_selector = $(this).data('scroll-target'),
        //             scroll_target_focus = $(this).data('scroll-focus'),
        //             $focus_target = null,
        //             $target = null,
        //             scroll_destination = 0
        //         ;

        //         if ( !_.isUndefined(scroll_target_selector) ) {

        //             $target = $( scroll_target_selector ).first();

        //             if ($target.length > 0) {

        //                 // Continue as normal for cmd clicks etc
        //                 if ( event.which == 2 || event.metaKey ) { return true; }

        //                 // Determine scroll_destination
        //                 scroll_destination = $target.offset().top - Header.get_scroll_offset() - 60;

        //                 $target.addClass('highlight-sequence-init');

        //                 // scroll to top
        //                 // @todo: Abstract window scrolling
        //                 $('html,body').stop().animate(
        //                     {
        //                         'scrollTop' : scroll_destination
        //                     },
        //                     {
        //                         'duration' : 400,
        //                         'easing' : 'easeInOutCubic',
        //                         'complete' : function(){

        //                             // Is there a focus target included?
        //                             if ( !_.isUndefined(scroll_target_focus) ) {
        //                                 $focus_target = $( scroll_target_focus );
        //                                 if ($focus_target.length > 0) {
        //                                     $focus_target.focus();
        //                                 }
        //                             }

        //                             $target.addClass('highlight-sequence');
        //                             setTimeout(function() {
        //                                 $target
        //                                     .removeClass('highlight-sequence-init')
        //                                     .removeClass('highlight-sequence')
        //                                 ;
        //                             }, 1500);
        //                         }
        //                     }
        //                 );

        //                 event.preventDefault();
        //                 return false;
        //             }
        //         }
        //     });

        //     $this.addClass('initialized');
        // });

        // trigger a scroll for good measure
        $window.trigger( 'WindowEvents.Scroll' );

    }

    /**
     * Handle how the page updates depending on the browser's use of history
     *
     * @param  {String} title   page title for the upcoming page
     * @param  {String} url     uri for upcoming page
     * @param  {Object} options passed into the history state object
     */
    function pushState( title, url, options ) {

        if ( Util.getMode() === 'traditional' ) {

            window.location = url;

        } else {

            window.history.pushState(
                options,
                title,
                url
            );

            $window.trigger( 'StateManager.NewState' );

        }

    }

    //////////////////////////////////////////////////////////////////////////////////////

    return {
        init: init,
        pushState: pushState
    };<commit_msg>Shift pushstate to be triggered from gotoUrl.<commit_after>/**
 * State.js
 * @param  {[type]} root    [description]
 * @param  {[type]} factory [description]
 * @return {[type]}         [description]
 */
( function ( window, factory ) {

    'use strict';

    if ( typeof define === 'function' && define.amd ) {

        define( [
            'jquery',
            './Util'
        ], function ( $, Util ) {
            return factory( window, $, Util );
        } );

    } else if ( typeof exports === 'object' ) {

        module.exports = factory(
            window,
            require( 'jquery' ),
            require( './Util' )
        );

    } else {

        window.StateManager = window.StateManager || {};

        window.StateManager.State = factory(
            window,
            window.jQuery,
            window.StateManager.Util
        );

    }

} ( window, function ( window, $, Util ) {

    'use strict';

    var name = 'State',
        debugEnabled = true,
        debug = debugEnabled ? Util.debug : function () {},
        $window = $( window )
    ;

    //////////////////////////////////////////////////////////////////////////////////////

    function init() {

        $window.on( 'StateManager.AfterInitState', newState );

        $window.on( 'StateManager.PushState', pushState );

    }

    /**
     * Decide where to focus the page after push state
     */
    function newState() {

        var state = window.history.state,
            scrollTarget = 0
        ;

        if ( state !== null && typeof state.scrollTarget !== 'undefined' && $( state.scrollTarget ).length > 0 )  {
            scrollTarget = $( state.scrollTarget ).first().offset().top;
        }

        if ( ! $( 'html' ).hasClass( 'initial-load' ) ) {

            $( 'html, body' )
                .stop()
                .animate({
                    'scrollTop' : scrollTarget
                }, 200 )
            ;

        } else {

            $( 'html' ).removeClass( 'initial-load' );

        }

        $window.trigger( 'OnDemandImages.Init' );

        // @todo: Break this out to its own module
        // $( '.scroll-to-anchor' ).each( function () {
        //     var $this = $( this );

        //     if ( ! $this.hasClass( 'initialized' ) ) {
        //         return;
        //     }

        //     $this
        //         .off( 'click.Manager' )
        //         .on( 'click.' + name, function ( event ) {

        //         var scroll_target_selector = $(this).data('scroll-target'),
        //             scroll_target_focus = $(this).data('scroll-focus'),
        //             $focus_target = null,
        //             $target = null,
        //             scroll_destination = 0
        //         ;

        //         if ( !_.isUndefined(scroll_target_selector) ) {

        //             $target = $( scroll_target_selector ).first();

        //             if ($target.length > 0) {

        //                 // Continue as normal for cmd clicks etc
        //                 if ( event.which == 2 || event.metaKey ) { return true; }

        //                 // Determine scroll_destination
        //                 scroll_destination = $target.offset().top - Header.get_scroll_offset() - 60;

        //                 $target.addClass('highlight-sequence-init');

        //                 // scroll to top
        //                 // @todo: Abstract window scrolling
        //                 $('html,body').stop().animate(
        //                     {
        //                         'scrollTop' : scroll_destination
        //                     },
        //                     {
        //                         'duration' : 400,
        //                         'easing' : 'easeInOutCubic',
        //                         'complete' : function(){

        //                             // Is there a focus target included?
        //                             if ( !_.isUndefined(scroll_target_focus) ) {
        //                                 $focus_target = $( scroll_target_focus );
        //                                 if ($focus_target.length > 0) {
        //                                     $focus_target.focus();
        //                                 }
        //                             }

        //                             $target.addClass('highlight-sequence');
        //                             setTimeout(function() {
        //                                 $target
        //                                     .removeClass('highlight-sequence-init')
        //                                     .removeClass('highlight-sequence')
        //                                 ;
        //                             }, 1500);
        //                         }
        //                     }
        //                 );

        //                 event.preventDefault();
        //                 return false;
        //             }
        //         }
        //     });

        //     $this.addClass('initialized');
        // });

        // trigger a scroll for good measure
        $window.trigger( 'WindowEvents.Scroll' );

    }

    /**
     * Handle how the page updates depending on the browser's use of history
     */
    function pushState( event, object ) {

        object = $.extend( {
            options: {
                url: object.url
            },
            title: ''
        }, object );

        if ( Util.getMode() === 'traditional' ) {

            window.location = object.url;

        } else {

            window.history.pushState(
                object.options,
                object.title,
                object.url
            );

            $window.trigger( 'StateManager.NewState' );

        }

    }

    //////////////////////////////////////////////////////////////////////////////////////

    return {
        init: init,
        pushState: pushState
    };
{'fraction_non_alphanumeric': 0.1535095101834708, 'fraction_numerical': 0.0030297929641474497, 'mean_word_length': 0.8949130920108436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5120440', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2721, 'n_words': 572}