<commit_before>///<module="events"/>
///<lib="jquery"/>
module ghost.browser.navigation
{
 //   export var Navigation:Navigation;
    /**
     * Global navigation system. Manages navigation history
     * @type {Navigation}
     */
    export class Navigation extends ghost.events.EventDispatcher
    {
        /**
         * Events triggered when a page change
         * @type {string}
         */
        public static EVENT_PAGE_CHANGED:string = ghost.events.Eventer.PAGE_CHANGED;
        /**
         * Type of page change : Push
         * @type {string}
         */
        public static PUSH:string = "page_pushed";
        /**
         * Type of page change : Pop
         * @type {string}
         */
        public static POP:string = "page_popped";
        /**
         * Type of page change : Replace
         * @type {string}
         */
        public static REPLACE:string = "page_replaced";
        /**
         * Events triggered when a page change
         * @type {string}
         */
        public EVENT_PAGE_CHANGED:string = Navigation.EVENT_PAGE_CHANGED;
        /**
         * Type of page change : Push
         * @type {string}
         */
        public PUSH:string = Navigation.PUSH;
        /**
         * Type of page change : Pop
         * @type {string}
         */
        public POP:string = Navigation.POP;
        /**
         * Type of page change : Replace
         * @type {string}
         */
        public REPLACE:string = Navigation.REPLACE;
        /**
         * Default scope name
         * @type {string}
         * @private
         */
        private _DEFAULT_SCOPE:string = null;//"default_scope";
        /**
         * @private
         */
        private _scopes:any;
        /**
         * Key/value object for default page scope<=>page
         */
        private _defaultsPages:any;
        /**
         * Application's navigation instance
         */
        public static instance:Navigation;
        /**
         * Listening
         * @type {boolean}
         */
        private _listening:boolean = false;
        /**
         * Constructor
         * @param ready If true, will be active as soon as possible otherwise will wait for #listen() to be call
         */
        constructor(ready:boolean = true)
        {
            super();
            if(Navigation.instance)
            {
                //TODO:allow this ?
                throw new Error("There is already an instance of navigation");
            }
            Navigation.instance = this;
            this._scopes = {};
            ghost.events.Eventer.on(ghost.events.Eventer.HASH_CHANGE, this._onHashChange, this);
            //TODO:not sure
            var _this:Navigation = this;
            if(ready)
            {
                this.listen();
            }
        }
        public listen():void
        {
            ghost.$ready(()=>
            {
                if(!this._listening)
                {
                    this._listening = true;
                    this._detectScope();
                    this._onHashChange(true);
                }
            });
        }
        private _detectScope():void
        {
            var _this:Navigation = this;
            var hash:any = _this.parseHash();
            $("[data-scope]").each(function()
            {
                var $child = $(this).children("[data-name]");
                var page:string;
                var scope:string = $(this).attr("data-scope");
                
                if(hash[scope])
                {
                    page = hash[scope];
                }
                if(!page)
                {

                    if($child.length == 0)
                    {
                        page = _this.getDefaultPage(scope);
                    }else
                    {
                        page = $child.eq(0).attr("data-name");
                    }
                }
                if(page)
                {
                    _this.pushPage($(this).attr("data-scope"), page);
                }else
                {
                    console.warn("No child with data-name inside a data-scope element and no default page for scope["+scope+"]", this);
                }
            });
        }
        private parseHash():any
        {
            var hash:any = window.location.hash.substring(1);
            var hashSplit:string[] = hash.split("+");
            var hashes:any = hashSplit.reduce((previous:any, big_hash:string)=>
            {
                var split:string[] = big_hash.split("_");
                if(split.length == 0 || split[0] == "")
                {
                    return previous;
                }
                var scope:string, page:string;
                if(split.length == 1)
                {
                    //no _ :
                    if(!this._DEFAULT_SCOPE)
                    {
                        console.warn("Uncaught Error: Navigation._DEFAULT_SCOPE not set!");
                        return previous;
                    }
                    scope = this._DEFAULT_SCOPE;
                }else
                {
                    scope = split[0];
                }
                page = split.slice(1).join("_");
                previous[scope] = page;
                return previous;
            }, {});
            return hashes;
        }
         private _onHashChange(first:boolean = false):void
        {
            var hashes:any = this.parseHash();
            var scope:string, page:string;
            for(var p in hashes)
            {
                scope = p;
                page = hashes[scope];
                if(first === true)
                {
                    $("#"+scope).attr("first",page);
                    this.pushPage(scope, page);
                }else
                {
                    if(page == "back")
                    {
        
                        this.popPage(scope);
                    }else
                    {
                        this.pushPage(scope, page);
                    }

                }

            }   
        }
        /**
         * Called when hash page changed
         * @private
         */
        private _onHashChange2(first:boolean = false):void
        {

            var index;
            var hash:any = window.location.hash;
            if((index = hash.indexOf("#"))!=-1)
            {
                hash = hash.substring(index+1);<commit_msg>New hash parser<commit_after>///<module="events"/>
///<lib="jquery"/>
module ghost.browser.navigation
{
 //   export var Navigation:Navigation;
    /**
     * Global navigation system. Manages navigation history
     * @type {Navigation}
     */
    export class Navigation extends ghost.events.EventDispatcher
    {
        /**
         * Events triggered when a page change
         * @type {string}
         */
        public static EVENT_PAGE_CHANGED:string = ghost.events.Eventer.PAGE_CHANGED;
        /**
         * Type of page change : Push
         * @type {string}
         */
        public static PUSH:string = "page_pushed";
        /**
         * Type of page change : Pop
         * @type {string}
         */
        public static POP:string = "page_popped";
        /**
         * Type of page change : Replace
         * @type {string}
         */
        public static REPLACE:string = "page_replaced";
        /**
         * Events triggered when a page change
         * @type {string}
         */
        public EVENT_PAGE_CHANGED:string = Navigation.EVENT_PAGE_CHANGED;
        /**
         * Type of page change : Push
         * @type {string}
         */
        public PUSH:string = Navigation.PUSH;
        /**
         * Type of page change : Pop
         * @type {string}
         */
        public POP:string = Navigation.POP;
        /**
         * Type of page change : Replace
         * @type {string}
         */
        public REPLACE:string = Navigation.REPLACE;
        /**
         * Default scope name
         * @type {string}
         * @private
         */
        private _DEFAULT_SCOPE:string = null;//"default_scope";
        /**
         * @private
         */
        private _scopes:any;
        /**
         * Key/value object for default page scope<=>page
         */
        private _defaultsPages:any;
        /**
         * Application's navigation instance
         */
        public static instance:Navigation;
        /**
         * Listening
         * @type {boolean}
         */
        private _listening:boolean = false;
        /**
         * Constructor
         * @param ready If true, will be active as soon as possible otherwise will wait for #listen() to be call
         */
        constructor(ready:boolean = true)
        {
            super();
            if(Navigation.instance)
            {
                //TODO:allow this ?
                throw new Error("There is already an instance of navigation");
            }
            Navigation.instance = this;
            this._scopes = {};
            ghost.events.Eventer.on(ghost.events.Eventer.HASH_CHANGE, this._onHashChange, this);
            //TODO:not sure
            var _this:Navigation = this;
            if(ready)
            {
                this.listen();
            }
        }
        public listen():void
        {
            ghost.$ready(()=>
            {
                if(!this._listening)
                {
                    this._listening = true;
                    this._detectScope();
                    this._onHashChange(true);
                }
            });
        }
        private _detectScope():void
        {
            var _this:Navigation = this;
            var hash:any = _this.parseHash();
            $("[data-scope]").each(function()
            {
                var $child = $(this).children("[data-name]");
                var page:string;
                var scope:string = $(this).attr("data-scope");
                
                if(hash[scope])
                {
                    page = hash[scope].page;
                }
                if(!page)
                {

                    if($child.length == 0)
                    {
                        page = _this.getDefaultPage(scope);
                    }else
                    {
                        page = $child.eq(0).attr("data-name");
                    }
                }
                if(page)
                {
                    _this.pushPage($(this).attr("data-scope"), page);
                }else
                {
                    console.warn("No child with data-name inside a data-scope element and no default page for scope["+scope+"]", this);
                }
            });
        }
        private parseHash():any
        {
            var hash:any = window.location.hash.substring(1);
            var hashSplit:string[] = hash.split("+");
            var hashes:any = hashSplit.reduce((previous:any, big_hash:string)=>
            {
                var split:string[] = big_hash.split("/");
                var canHaveParam:boolean = true;
                if(split.length == 1)
                {
                    canHaveParam = false;
                    split = big_hash.split("_");
                }
                if(split.length == 0 || split[0] == "")
                {
                    return previous;
                }
                var scope:string, page:string;
                if(split.length == 1)
                {
                    //no _ :
                    if(!this._DEFAULT_SCOPE)
                    {
                        console.log(hash);
                        console.log(hashSplit);
                        console.warn("Uncaught Error: Navigation._DEFAULT_SCOPE not set!");
                        //debugger;
                        return previous;
                    }
                    scope = this._DEFAULT_SCOPE;
                }else
                {
                    scope = split[0];
                }
                var params:any = null;
                if(canHaveParam)
                {
                    page = split[1];
                    params = split.slice(2);   
                }else
                {
                    page = split.slice(1).join("_");
                }
                previous[scope] = {page:page, params:params};
                return previous;
            }, {});
            return hashes;
        }
         private _onHashChange(first:boolean = false):void
        {
            var hashes:any = this.parseHash();
            var scope:string, page:string;
            for(var p in hashes)
            {
                scope = p;
                page = hashes[scope].page;
                if(first === true)
                {
                    $("#"+scope).attr("first",page);
                    this.pushPage(scope, page);
                }else
                {
                    if(page == "back")
                    {
        
                        this.popPage(scope);
                    }else
                    {
                        this.pushPage(scope, page);
                    }

                }

            }   
        }
        /**
         * Called when hash page changed
         * @private
         */
        private _onHashChange2(first:boolean = false):void
        {

            var index;
            var hash:any = window.location.hash;
            if((index = hash.indexOf("#"))!=-1)
            {
                hash = hash.substring(index+1);
{'fraction_non_alphanumeric': 0.10792853979034402, 'fraction_numerical': 0.0018455632659087555, 'mean_word_length': 1.027994011976048, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3808115', 'n_tokens_mistral': 3442, 'n_tokens_neox': 3235, 'n_words': 693}