<commit_before>var pageIndex = 0;

$( document ).ready(function() {
  //loadPageIntoElement("JSONP", addPage());
  //loadPageIntoElement("Copenhagen", addPage());
  //addSearchPage();
  setUpSearch();
});

function addPage() {
	var pageId = "page" + pageIndex++;

	var tempContainer = document.createElement("div");
	tempContainer.innerHtml = 
'			<div class="wikibrowser-page-host wikibrowser-page-shadow">' +
'				<div class="wikibrowser-page ps-container ps-active-y" id="' + pageId + '">'+
'					<div class="pre-content">'+
'						<h1 id="section_0"></h1>'+
'					</div>'+
'					<div id="content" class="content"></div>'+
'				</div>'+
'			</div>';

	$(".wikibrowser-host").append(tempContainer.innerHtml);

	// Scroll to reveal the new pane
	var newPageOffset = $("#" + pageId).offset().left;
	$(".wikibrowser-host").animate({scrollLeft: newPageOffset}, 400);

	return pageId;
}

function addSearchPage() {
	var pageId = "page" + pageIndex++;

	var tempContainer = document.createElement("div");
	tempContainer.innerHtml = 
'			<div class="wikibrowser-page-host">' +
'				<div class="wikibrowser-page ps-container ps-active-y" id="' + pageId + '">'+
'					<div class="pre-content">'+
'						<h1 id="section_0"></h1>'+
'					</div>'+
'					<div id="content" class="content">'+
'                        <p><strong>Search</strong><br />'+
'                        <input type="text" placeholder="Coming soon"></input></p>'+
'                        <p>Other upcoming features:<br />'+
'                            <ul>'+
'                                <li>Close and rearrange articles</li>'+
'                                <li>Set bookmarks and leave notes</li>'+
'                                <li>Save, restore and share your layout</li>'+
'                            </ul>'+
'                        </p>'+
'                        <p><strong>How do I use this?</strong><br />'+
'                        Click on links in Wikipedia articles on the left. They will open new articles side by side!</p>'+
'                   </div>'+
'				</div>'+
'			</div>';

	$(".wikibrowser-host").append(tempContainer.innerHtml);

	return pageId;	
}

function loadPageIntoElement(page, element) {
	console.log('load page ' + page);
	$.ajax({
	    url : "http://en.wikipedia.org/w/api.php?action=parse&format=json&callback=?&continue=&page=" + page,
	    data: {
	    	format: 'json'
	    },
	    dataType: 'jsonp',
	    cache: 'true' // defaults to false for jsonp.	    
	})
	.done(function(data) {
		console.log("Received: ");
		if (typeof data.error !== 'undefined') {
			// TODO: Make it user friendly.
			$( "#" + element + " > .pre-content > h1" ).append( data.error.code );
			$( "#" + element + " > .content" ).append( data.error.info );
		}
		else {
			$( "#" + element + " > .pre-content > h1" ).append( data.parse.displaytitle );
			$( "#" + element + " > .content" ).append( data.parse.text['*'] );
			$( "#" + element + " > .content a").each(fixHyperlink);
			$( "#" + element ).perfectScrollbar({
				wheelSpeed: 3
			});
		}
	});  
}

function fixHyperlink(index, element)
{
	var jElement = $(element);
	var address = jElement.attr('href');
	if (address.substring(0, 6) === '/wiki/')
	{
		jElement.attr('href', "http://en.wikipedia.org" + address);
		jElement.on('click', function() {
			loadPageIntoElement(address.substring(6), addPage());
			return false; // prevent going to href (wikipedia)
		})
	}
	if (address.substring(0, 1) !== '#')
	{
		jElement.attr('target', "_blank");
	}
}

function setUpSearch() {
	console.log("setUpSearch");
	var searchBox = $(".wikibrowser-search-content input");
	searchBox.keyup(function(event) {
		if (event.keyCode == 13) {
			console.log("enter");
			goToArticle(searchBox[0].value);
		}
	});
	var goButton = $(".wikibrowser-go-button");
	goButton.on('click', function() {
		goToArticle(searchBox[0].value);
	});	
	var searchButton = $(".wikibrowser-search-button");
	searchButton.on('click', function() {
		searchArticle(searchBox[0].value);
	});
}

function goToArticle(query) {
	console.log("goToArticle " + query);
	results = getSearchResults(query, function(results) {
		if (typeof results.query.search === 'undefined' || results.query.searchinfo.totalhits === 0)
		{<commit_msg>Adds scrollbar to the temp test page<commit_after>var pageIndex = 0;

$( document ).ready(function() {
  //loadPageIntoElement("JSONP", addPage());
  //loadPageIntoElement("Copenhagen", addPage());
  //addSearchPage();
  setUpSearch();
});

function addPage() {
	var pageId = "page" + pageIndex++;

	var tempContainer = document.createElement("div");
	tempContainer.innerHtml = 
'			<div class="wikibrowser-page-host wikibrowser-page-shadow">' +
'				<div class="wikibrowser-page ps-container ps-active-y" id="' + pageId + '">'+
'					<div class="pre-content">'+
'						<h1 id="section_0"></h1>'+
'					</div>'+
'					<div id="content" class="content"></div>'+
'				</div>'+
'			</div>';

	$(".wikibrowser-host").append(tempContainer.innerHtml);

	// Scroll to reveal the new pane
	var newPageOffset = $("#" + pageId).offset().left;
	$(".wikibrowser-host").animate({scrollLeft: newPageOffset}, 400);

	return pageId;
}

function addSearchPage() {
	var pageId = "page" + pageIndex++;

	var tempContainer = document.createElement("div");
	tempContainer.innerHtml = 
'			<div class="wikibrowser-page-host">' +
'				<div class="wikibrowser-page ps-container ps-active-y" id="' + pageId + '">'+
'					<div class="pre-content">'+
'						<h1 id="section_0"></h1>'+
'					</div>'+
'					<div id="content" class="content">'+
'                        <p><strong>Search</strong><br />'+
'                        <input type="text" placeholder="Coming soon"></input></p>'+
'                        <p>Other upcoming features:<br />'+
'                            <ul>'+
'                                <li>Close and rearrange articles</li>'+
'                                <li>Set bookmarks and leave notes</li>'+
'                                <li>Save, restore and share your layout</li>'+
'                            </ul>'+
'                        </p>'+
'                        <p><strong>How do I use this?</strong><br />'+
'                        Click on links in Wikipedia articles on the left. They will open new articles side by side!</p>'+
'                   </div>'+
'				</div>'+
'			</div>';

	$(".wikibrowser-host").append(tempContainer.innerHtml);

	return pageId;	
}

function loadPageIntoElement(page, element) {
	console.log('load page ' + page);
	$.ajax({
	    url : "http://en.wikipedia.org/w/api.php?action=parse&format=json&callback=?&continue=&page=" + page,
	    data: {
	    	format: 'json'
	    },
	    dataType: 'jsonp',
	    cache: 'true' // defaults to false for jsonp.	    
	})
	.done(function(data) {
		console.log("Received: ");
		if (typeof data.error !== 'undefined') {
			// TODO: Make it user friendly.
			$( "#" + element + " > .pre-content > h1" ).append( data.error.code );
			$( "#" + element + " > .content" ).append( data.error.info );
		}
		else {
			$( "#" + element + " > .pre-content > h1" ).append( data.parse.displaytitle );
			$( "#" + element + " > .content" ).append( data.parse.text['*'] );
			$( "#" + element + " > .content a").each(fixHyperlink);
			$( "#" + element ).perfectScrollbar({
				wheelSpeed: 3
			});
		}
	});  
}

function fixHyperlink(index, element)
{
	var jElement = $(element);
	var address = jElement.attr('href');
	if (address.substring(0, 6) === '/wiki/')
	{
		jElement.attr('href', "http://en.wikipedia.org" + address);
		jElement.on('click', function() {
			loadPageIntoElement(address.substring(6), addPage());
			return false; // prevent going to href (wikipedia)
		})
	}
	if (address.substring(0, 1) !== '#')
	{
		jElement.attr('target', "_blank");
	}
}

function setUpSearch() {
	console.log("setUpSearch");
	var searchBox = $(".wikibrowser-search-content input");
	searchBox.keyup(function(event) {
		if (event.keyCode == 13) {
			console.log("enter");
			goToArticle(searchBox[0].value);
		}
	});
	var goButton = $(".wikibrowser-go-button");
	goButton.on('click', function() {
		goToArticle(searchBox[0].value);
	});	
	var searchButton = $(".wikibrowser-search-button");
	searchButton.on('click', function() {
		searchArticle(searchBox[0].value);
	});
	$( ".wikibrowser-search-content" ).parent().perfectScrollbar({
		wheelSpeed: 3
	});
}

function goToArticle(query) {
	console.log("goToArticle " + query);
	results = getSearchResults(query, function(results) {
		if (typeof results.query.search === 'undefined' || results.query.searchinfo.totalhits === 0)
		{
{'fraction_non_alphanumeric': 0.1979020979020979, 'fraction_numerical': 0.005710955710955711, 'mean_word_length': 2.8898458748866727, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 103, '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': '312411', 'n_tokens_mistral': 3074, 'n_tokens_neox': 2808, 'n_words': 538}