<commit_before>module.exports = {
	template: [],

	handler: function() {},

	init: function() {
		this.observe(this.observers);

		var updatePath = this.updatePath.bind(this);
		window.addEventListener("popstate", updatePath, false);
		this.on('teardown', function() {
			window.removeEventListener("popstate", updatePath);
		});
	},

	observers: {
		page: function(newPage, oldPage) {
			if (oldPage) oldPage.teardown();
			if (newPage) newPage.insert(this.el);
		},
		path: function(path) {
			var page;
			try {
				page = this.handler(path);
			} catch(e) {
				console.error(e.stack || e);
			}
			this.set('page', page);
		}
	},

	updatePath: function() {
		this.set('path', location.pathname);
	},

	navigate: function(path) {
		this.set('path', path);
		var page = this.get('page');
		var state = true;
		var title = page ? page.title || page.get('title') : window.title;
		window.history.pushState(state, title, path);
	},

	setHandler: function(handler) {
		this.handler = handler;
		this.updatePath();
	}
};<commit_msg>Intercept click events for navigation router<commit_after>module.exports = {
	template: [],

	handler: function() {},

	init: function() {
		this.observe(this.observers);

		var updatePath = this.updatePath.bind(this);
		var onClick = this.onClick.bind(this);
		window.addEventListener('popstate', updatePath, false);
		window.addEventListener('click', onClick, false);
		this.on('teardown', function() {
			window.removeEventListener('popstate', updatePath, false);
			window.removeEventListener('click', onClick, false);
		});
	},

	observers: {
		page: function(newPage, oldPage) {
			if (oldPage) oldPage.teardown();
			if (newPage) newPage.insert(this.el);
		},
		path: function(path) {
			var page;
			try {
				page = this.handler(path);
			} catch(e) {
				console.error(e.stack || e);
			}
			this.set('page', page);
		}
	},

	updatePath: function() {
		this.set('path', location.pathname);
	},

	onClick: function(e) {
		if (e.target.nodeName == 'A' && !e.ctrlKey && e.target.href &&
			e.target.href.indexOf(location.origin) === 0) {
			// intercept the click
			e.preventDefault();
			this.navigate(e.target.href.substr(location.origin.length));
		}
	},

	navigate: function(path) {
		if (!path) path = '/';
		this.set('path', path);
		var page = this.get('page');
		var state = true;
		var title = page ? page.title || page.get('title') : window.title;
		window.history.pushState(state, title, path);
	},

	setHandler: function(handler) {
		this.handler = handler;
		this.updatePath();
	}
};
{'fraction_non_alphanumeric': 0.17797947908445147, 'fraction_numerical': 0.0003946329913180742, 'mean_word_length': 3.8656429942418424, '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': '4072299', 'n_tokens_mistral': 974, 'n_tokens_neox': 868, 'n_words': 166}