<commit_before>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

// route urls to their virtual pages

// re-route map (for rename)
frappe.re_route = {"#login": ""};
frappe.route_titles = {};
frappe.route_history = [];
frappe.view_factory = {};
frappe.view_factories = [];
frappe.route_options = null;

frappe.route = function() {
	if(frappe.re_route[window.location.hash] !== undefined) {
		// after saving a doc, for example,
		// "New DocType 1" and the renamed "TestDocType", both exist in history
		// now if we try to go back,
		// it doesn't allow us to go back to the one prior to "New DocType 1"
		// Hence if this check is true, instead of changing location hash,
		// we just do a back to go to the doc previous to the "New DocType 1"
		var re_route_val = frappe.get_route_str(frappe.re_route[window.location.hash]);
		var cur_route_val = frappe.get_route_str(frappe._cur_route);
		if (decodeURIComponent(re_route_val) === decodeURIComponent(cur_route_val)) {
			window.history.back();
			return;
		} else {
			window.location.hash = frappe.re_route[window.location.hash];
		}
	}

	frappe._cur_route = window.location.hash;

	route = frappe.get_route();
	frappe.route_history.push(route);

	if(route[0] && route[1] && frappe.views[route[0] + "Factory"]) {
		// has a view generator, generate!
		if(!frappe.view_factory[route[0]]) {
			frappe.view_factory[route[0]] = new frappe.views[route[0] + "Factory"]();
		}

		frappe.view_factory[route[0]].show();
	} else {
		// show page
		frappe.views.pageview.show(route[0]);
	}

	if(frappe.route_titles[window.location.hash]) {
		frappe.utils.set_title(frappe.route_titles[window.location.hash]);
	}
}

frappe.get_route = function(route) {
	// for app
	var route = frappe.get_route_str(route).split('/')
	var parts = route[route.length - 1].split("?");
	route[route.length - 1] = parts[0];
	if (parts.length > 1) {
		var query_params = get_query_params(parts[1]);
		frappe.route_options = $.extend(frappe.route_options || {}, query_params);
	}

	return route;
}

frappe.get_prev_route = function() {
	if(frappe.route_history && frappe.route_history.length > 1) {
		return frappe.route_history[frappe.route_history.length - 2];
	} else {
		return [];
	}
}

frappe.get_route_str = function(route) {
	if(!route)
		route = window.location.hash;

	if(route.substr(0,1)=='#') route = route.substr(1);
	if(route.substr(0,1)=='!') route = route.substr(1);
<commit_msg>[fix] backward compatibilty of module view route<commit_after>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

// route urls to their virtual pages

// re-route map (for rename)
frappe.re_route = {"#login": ""};
frappe.route_titles = {};
frappe.route_history = [];
frappe.view_factory = {};
frappe.view_factories = [];
frappe.route_options = null;

frappe.route = function() {
	if(frappe.re_route[window.location.hash] !== undefined) {
		// after saving a doc, for example,
		// "New DocType 1" and the renamed "TestDocType", both exist in history
		// now if we try to go back,
		// it doesn't allow us to go back to the one prior to "New DocType 1"
		// Hence if this check is true, instead of changing location hash,
		// we just do a back to go to the doc previous to the "New DocType 1"
		var re_route_val = frappe.get_route_str(frappe.re_route[window.location.hash]);
		var cur_route_val = frappe.get_route_str(frappe._cur_route);
		if (decodeURIComponent(re_route_val) === decodeURIComponent(cur_route_val)) {
			window.history.back();
			return;
		} else {
			window.location.hash = frappe.re_route[window.location.hash];
		}
	}

	frappe._cur_route = window.location.hash;

	route = frappe.get_route();
	if (route === false) {
		return;
	}

	frappe.route_history.push(route);

	if(route[0] && route[1] && frappe.views[route[0] + "Factory"]) {
		// has a view generator, generate!
		if(!frappe.view_factory[route[0]]) {
			frappe.view_factory[route[0]] = new frappe.views[route[0] + "Factory"]();
		}

		frappe.view_factory[route[0]].show();
	} else {
		// show page
		frappe.views.pageview.show(route[0]);
	}

	if(frappe.route_titles[window.location.hash]) {
		frappe.utils.set_title(frappe.route_titles[window.location.hash]);
	}
}

frappe.get_route = function(route) {
	// for app
	var route = frappe.get_route_str(route).split('/')
	var parts = route[route.length - 1].split("?");
	route[route.length - 1] = parts[0];
	if (parts.length > 1) {
		var query_params = get_query_params(parts[1]);
		frappe.route_options = $.extend(frappe.route_options || {}, query_params);
	}

	// backward compatibility
	if (route && route[0]==='Module') {
		frappe.set_route('modules', route[1]);
		return false;
	}

	return route;
}

frappe.get_prev_route = function() {
	if(frappe.route_history && frappe.route_history.length > 1) {
		return frappe.route_history[frappe.route_history.length - 2];
	} else {
		return [];
	}
}

frappe.get_route_str = function(route) {
	if(!route)
		route = window.location.hash;

	if(route.substr(0,1)=='#') route = route.substr(1);
	if(route.substr(0,1)=='!') route = route.substr(1);

{'fraction_non_alphanumeric': 0.1571873782625633, 'fraction_numerical': 0.011297234125438255, 'mean_word_length': 4.223804679552391, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, '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': '4491809', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1913, 'n_words': 395}