{"size": 1399, "ext": "js", "max_stars_repo_path": "explainer/static/js/explainer.js", "max_stars_repo_name": "commonsearch/cosr-back", "max_stars_repo_stars_event_min_datetime": "2016-02-17T14:27:57.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-27T02:56:48.000Z", "max_issues_repo_path": "explainer/static/js/explainer.js", "max_issues_repo_name": "commonsearch/cosr-back", "max_issues_repo_issues_event_min_datetime": "2016-02-20T02:06:59.000Z", "max_issues_repo_issues_event_max_datetime": "2017-01-29T22:23:46.000Z", "max_forks_repo_path": "explainer/static/js/explainer.js", "max_forks_repo_name": "commonsearch/cosr-back", "max_forks_repo_forks_event_min_datetime": "2016-02-25T04:40:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-06-11T07:22:44.000Z"}
{"max_stars_count": 141, "max_issues_count": 69, "max_forks_count": 38, "avg_line_length": 19.9857142857, "max_line_length": 87, "alphanum_fraction": 0.5568263045}
$(function() {

	/*
		Quick script to manage the Explainer frontend. Could be improved in many ways!
	*/

	$.urlParam = function(name){
	    var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href);
	    if (results==null){
	       return null;
	    }
	    else{
	       return decodeURIComponent(results[1]).replace(/\+/g, " ") || 0;
	    }
	}

	var urldebug = function(url) {
		$("#url").val(url);

		$.get("/api/urldebug", {"url": url}, function(data) {
			data = JSON.parse(data);
			console.log(data);

			var tpl = $("#tpl_urldebug").html();

			var html = _.template(tpl)({"data": data});

			$("#urldebug_content").html(html);

		});

	};

	var searchdebug = function(query, lang) {
		$("#q").val(query);
		$("#g").val(lang);

		$.get("/api/searchdebug", {"q": query, "g": lang}, function(data) {
			data = JSON.parse(data);
			console.log(data);

			var tpl = $("#tpl_searchdebug").html();

			var html = _.template(tpl)({"data": data});

			$("#searchdebug_content").html(html);

		});

	};

	// TODO HTML5 history to avoid the submit request
	// $("#urlform").on("submit", function(evt) {
	// 	var url = $("#url").val();
	// 	urldebug(url);
	// 	return false;
	// });

	var initUrl = $.urlParam("url");
	if (initUrl) {
		urldebug(initUrl);
	}

	var initSearch = $.urlParam("q");
	if (initSearch) {
		searchdebug($.urlParam("q"), $.urlParam("g") || "en");
	}


});