<commit_before>//http://krasimirtsonev.com/blog/article/A-modern-JavaScript-router-in-100-lines-history-api-pushState-hash-url
(function() {
	
	"use strict";
	
	function clearSlashes(path) {
		return path.toString().replace(/\/$/, '').replace(/^\//, '');
	}
	
	function Router() {
		
		this.routes = [];
		this.root = "/";
	}
	
	Router.prototype = new JSYG.StdContruct();
	
	Router.prototype.add = function(re, handler) {
		
		if (typeof re == 'function') {
			handler = re;
			re = '';
		}
		
		this.routes.push({
			re : re,
			handler : handler
		});
		
		return this;
	};
	
	Router.prototype.getFragment = function() {
		
		var fragment = '',match;
		
		if (this.mode === 'history') {
			
			fragment = clearSlashes(decodeURI(location.pathname + location.search));
			fragment = fragment.replace(/\?(.*)$/, '');
			fragment = this.root != '/' ? fragment.replace(this.root, '') : fragment;
		}
		else {
			
			match = window.location.href.match(/#(.*)$/);
			fragment = match ? match[1] : '';
		}
		
		return clearSlashes(fragment);
	};
	
	Router.prototype.remove = function(param) {
		
		var i=0,r,N=this.route.length;
		
		for (;i<N,r=this.routes[i];i++) {
			
			if (r.handler === param || r.re.toString() === param.toString()) {
				this.routes.splice(i, 1);
				return this;
			}
		}
		
		return this;
	};
	
	Router.prototype.flush = function() {
		
		while(this.routes[0]) this.routes.pop();
		
		this.mode = null;
		
		this.root = '/';
		
		return this;
	};
	
	Router.prototype._check = function(f) {
		
		var fragment = f || this.getFragment(),
			match,i=0,N=this.routes.length;
		
		for (;i<N;i++) {
			
			match = fragment.match(this.routes[i].re);
			
			if (match) {
				match.shift();
				this.routes[i].handler.apply({}, match);
				return this;
			}
		}
		
		return this;
	};
			
	Router.prototype.listen = function() {
		
		var that = this;
		
		this.stopListening();
		
		function listen() { that.check(that.getFragment()); }
		
		window.addEventListener("hashchange",listen,false);
		
		this.stopListening = function() {
			window.removeEventListener("hashchange",listen,false);
		};
		
		return this;
	};
	
	Router.prototype.stopListening = function() {
		return this;
	};
	
	Router.prototype.navigate = function(path) {
		
		path = path ? path : '';
		
		if (this.mode === 'history') {
			history.pushState(null, null, this.root + clearSlashes(path));
		}
		else {
			window.location.href.match(/#(.*)$/);
			window.location.href = window.location.href.replace(/#(.*)$/, '')+ '#' + path;
		}
		
		return this;
	};
	
	JSYG.router = new Router();
	<commit_msg>Reprise du module à la sauce JSYG.<commit_after>//http://krasimirtsonev.com/blog/article/A-modern-JavaScript-router-in-100-lines-history-api-pushState-hash-url
(function() {
	
	"use strict";
	
	function clearSlashes(path) {
		return path.toString().replace(/\/$/, '').replace(/^\//, '');
	}
	
	function Router() {
		
		this.routes = [];
	}
	
	Router.prototype = new JSYG.StdContruct();
	
	Router.prototype.root = '/';
	
	Router.prototype.mode = 'hash';
	
	Router.prototype.add = function(re, handler) {
		
		this.routes.push({
			re : re,
			handler : handler
		});
		
		return this;
	};
	
	Router.prototype.getFragment = function() {
		
		var fragment = '',match;
		
		if (this.mode === 'history') {
			
			fragment = clearSlashes(decodeURI(location.pathname + location.search));
			fragment = fragment.replace(/\?(.*)$/, '');
			fragment = this.root != '/' ? fragment.replace(this.root, '') : fragment;
		}
		else {
			
			match = window.location.href.match(/#(.*)$/);
			fragment = match ? match[1] : '';
		}
		
		return clearSlashes(fragment);
	};
	
	Router.prototype.remove = function(param) {
		
		var i=0,r,N=this.route.length;
		
		for (;i<N,r=this.routes[i];i++) {
			
			if (r.handler === param || r.re.toString() === param.toString()) {
				this.routes.splice(i, 1);
				return this;
			}
		}
		
		return this;
	};
		
	function check() {
		
		var fragment = this.getFragment(),
			match,i=0,N=this.routes.length;
		
		for (;i<N;i++) {
			
			match = fragment.match(this.routes[i].re);
			
			if (match) {
				match.shift();
				this.routes[i].handler.apply(this,match);
				return this;
			}
		}
		
		return this;
	}
			
	Router.prototype.listen = function() {
		
		var listen = check.bind(this);
		
		this.stopListening();
		
		window.addEventListener("hashchange",listen,false);
		
		this.stopListening = function() {
			window.removeEventListener("hashchange",listen,false);
		};
		
		return this;
	};
	
	Router.prototype.stopListening = function() {
		return this;
	};
	
	Router.prototype.reset = function() {
		
		JSYG.StdConstruct.prototype.reset.call(this);
		
		while (this.routes[0]) this.routes.pop();
		
		return this;
	};
	
	Router.prototype.navigate = function(path) {
		
		path = path ? path : '';
		
		if (this.mode === 'history') {
			history.pushState(null, null, this.root + clearSlashes(path));
		}
		else {
			window.location.href.match(/#(.*)$/);
			window.location.href = window.location.href.replace(/#(.*)$/, '')+ '#' + path;
		}
		
		return this;
	};
	
	JSYG.router = new Router();
	
{'fraction_non_alphanumeric': 0.1889825524406979, 'fraction_numerical': 0.003136639874534405, 'mean_word_length': 2.8710166919575113, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6459127', 'n_tokens_mistral': 2136, 'n_tokens_neox': 1734, 'n_words': 285}