<commit_before>var sakai = sakai ||
{};

sakai._search = {};
sakai.search = function() {

	/*
	 Config variables
	 */
	var contentToSearch = 10;
	
	var meObj = false;
	var foundcontent = false;
	var hasHadFocus = false;
	var searchterm = "";
	var currentpage = 0;
	
	sakai._search.reset = function() {
		$("#search_result_title").hide();
		$(".search_results_part_footer").hide();
		$("#introduction_text").show();
		$("#display_more_content").show();
	}
	
	var doInit = function() {
	
		sdata.Ajax.request({
			url: "/rest/me?sid=" + Math.random(),
			onSuccess: function(response) {
			
				meObj = eval('(' + response + ')');
				if (meObj.preferences.uuid) {
					inituser = meObj.profile.firstName + " " + meObj.profile.lastName;
					$("#userid").text(inituser);
					placeImage();
					getMySites();
				}
				else {
					document.location = "/dev/redesign/index.html";
				}
				
			}
		});
		
	};
	
	var getMySites = function() {
		sdata.Ajax.request({
			url: "/rest/sites?sid=" + Math.random(),
			onSuccess: function(response) {
				var data = json_parse(response);
				var finaljson = {}
				finaljson.items = [];
				if (data.entry) {
					finaljson.items = data.entry;
				}
				$("#search_filter_my_sites").html(sdata.html.Template.render("search_filter_my_sites_template", finaljson));
				History.history_change();
				
			}
		});
	};
	
	var placeImage = function() {
		// Fix small arrow horizontal position
		$('.explore_nav_selected_arrow').css('right', $('.explore_nav_selected').width() / 2 + 10);
		
		// Round cornners for elements with '.rounded_corners' class
		$('.rounded_corners').corners("2px");
		
		// IE Fixes
		if (($.browser.msie) && ($.browser.version < 8)) {
			// Tab fix
			$('.fl-tabs li a').css('bottom', '-1px');
			$('.fl-tabs .fl-activeTab a').css('bottom', '-1px');
			
			//Search button fix
			$('.search_button').css('top', '4px');
			
			// Small Arrow Fix
			$('.explore_nav_selected_arrow').css('bottom', '-10px');
		}
	}
	
	sakai._search.doHSearch = function(page, searchquery) {
		if (!page) {
			page = 1;
		}
		if (!searchquery) {
			searchquery = $("#search_text").val().toLowerCase();
		}
		currentpage = page;
		History.addBEvent("" + page + "|" + searchquery);
	}
	
	sakai._search.doSearch = function(page, searchquery) {
	
		currentpage = parseInt(page);
		
		if (searchquery) {
			$("#search_text").val(searchquery);
			$("#search_text").addClass("search_bar_selected");
		}
		
		searchterm = $("#search_text").val().toLowerCase();
		
		if (searchterm) {
			// Set searching messages
			
			$("#mysearchterm").text(searchterm);
			$("#numberfound").text("0");
			
			// Set everything visible
			
			$("#introduction_text").hide();
			$("#display_more_content").hide();
			$("#content_media_header").show();
			$("#content_header").show();
			$("#courses_content_header").show();
			$("#search_result_title").show();
			$(".search_results_part_footer").show();
			
			// Set off the AJAX request
			
			// content Search
			var searchFilter = $('#search_filter option:selected"').val();
			var searchWhere = '*';
			if (searchFilter === 'entire_community') {
				searchWhere = '*';
			}
			else if (searchFilter === 'all_my_sites') {
				searchWhere = 'mysites';
			}
			else {
				//	Specific site add the location.
				searchWhere = searchFilter;
			}
			
			var contentsearchterm = "";
			var splitted = searchterm.split(" ");
			for (var i = 0; i < splitted.length; i++) {
				contentsearchterm += splitted[i] + "~" + " " + splitted[i] + "*" + " ";
			}
			
			sdata.Ajax.request({
				httpMethod: "GET",
				url: "/dev/redesign/dummyjson/searchContent.json?p=" + (currentpage - 1) + "&path=/_private&n=" + contentToSearch + "&q=" + contentsearchterm + "&sites=" + searchWhere + "&mimetype=text/plain&s=sakai:firstName&s=sakai:lastName&sid=" + Math.random(),
				onSuccess: function(data) {
					foundcontent = eval('(' + data + ')');
					rendercontent();
				},
				onFail: function(status) {
					foundcontent = {};
					rendercontent();
				}
			});
			
		}
		else {
		
			sakai._search.reset();
			
		}
		
	}
	
	
	/*<commit_msg>SAK-16233<commit_after>var sakai = sakai ||
{};

sakai._search = {};
sakai.search = function() {

	/*
	 Config variables
	 */
	var contentToSearch = 10;
	
	var meObj = false;
	var foundcontent = false;
	var hasHadFocus = false;
	var searchterm = "";
	var currentpage = 0;
	
	sakai._search.reset = function() {
		$("#search_result_title").hide();
		$(".search_results_part_footer").hide();
		$("#introduction_text").show();
		$("#display_more_content").show();
	}
	
	var doInit = function() {
	
		sdata.Ajax.request({
			url: "/rest/me?sid=" + Math.random(),
			onSuccess: function(response) {
			
				meObj = eval('(' + response + ')');
				if (meObj.preferences.uuid) {
					inituser = meObj.profile.firstName + " " + meObj.profile.lastName;
					$("#userid").text(inituser);
					placeImage();
					getMySites();
				}
				else {
					document.location = Config.URL.GATEWAY_URL;
				}
				
			}
		});
		
	};
	
	var getMySites = function() {
		sdata.Ajax.request({
			url: "/rest/sites?sid=" + Math.random(),
			onSuccess: function(response) {
				var data = json_parse(response);
				var finaljson = {}
				finaljson.items = [];
				if (data.entry) {
					finaljson.items = data.entry;
				}
				$("#search_filter_my_sites").html(sdata.html.Template.render("search_filter_my_sites_template", finaljson));
				History.history_change();
				
			}
		});
	};
	
	var placeImage = function() {
		// Fix small arrow horizontal position
		$('.explore_nav_selected_arrow').css('right', $('.explore_nav_selected').width() / 2 + 10);
		
		// Round cornners for elements with '.rounded_corners' class
		$('.rounded_corners').corners("2px");
		
		// IE Fixes
		if (($.browser.msie) && ($.browser.version < 8)) {
			// Tab fix
			$('.fl-tabs li a').css('bottom', '-1px');
			$('.fl-tabs .fl-activeTab a').css('bottom', '-1px');
			
			//Search button fix
			$('.search_button').css('top', '4px');
			
			// Small Arrow Fix
			$('.explore_nav_selected_arrow').css('bottom', '-10px');
		}
	}
	
	sakai._search.doHSearch = function(page, searchquery) {
		if (!page) {
			page = 1;
		}
		if (!searchquery) {
			searchquery = $("#search_text").val().toLowerCase();
		}
		currentpage = page;
		History.addBEvent("" + page + "|" + searchquery);
	}
	
	sakai._search.doSearch = function(page, searchquery) {
	
		currentpage = parseInt(page);
		
		if (searchquery) {
			$("#search_text").val(searchquery);
			$("#search_text").addClass("search_bar_selected");
		}
		
		searchterm = $("#search_text").val().toLowerCase();
		
		if (searchterm) {
			// Set searching messages
			
			$("#mysearchterm").text(searchterm);
			$("#numberfound").text("0");
			
			// Set everything visible
			
			$("#introduction_text").hide();
			$("#display_more_content").hide();
			$("#content_media_header").show();
			$("#content_header").show();
			$("#courses_content_header").show();
			$("#search_result_title").show();
			$(".search_results_part_footer").show();
			
			// Set off the AJAX request
			
			// content Search
			var searchFilter = $('#search_filter option:selected"').val();
			var searchWhere = '*';
			if (searchFilter === 'entire_community') {
				searchWhere = '*';
			}
			else if (searchFilter === 'all_my_sites') {
				searchWhere = 'mysites';
			}
			else {
				//	Specific site add the location.
				searchWhere = searchFilter;
			}
			
			var contentsearchterm = "";
			var splitted = searchterm.split(" ");
			for (var i = 0; i < splitted.length; i++) {
				contentsearchterm += splitted[i] + "~" + " " + splitted[i] + "*" + " ";
			}
			
			sdata.Ajax.request({
				httpMethod: "GET",
				url: "/dev/dummyjson/searchContent.json?p=" + (currentpage - 1) + "&path=/_private&n=" + contentToSearch + "&q=" + contentsearchterm + "&sites=" + searchWhere + "&mimetype=text/plain&s=sakai:firstName&s=sakai:lastName&sid=" + Math.random(),
				onSuccess: function(data) {
					foundcontent = eval('(' + data + ')');
					rendercontent();
				},
				onFail: function(status) {
					foundcontent = {};
					rendercontent();
				}
			});
			
		}
		else {
		
			sakai._search.reset();
			
		}
		
	}
	
	
	/*
{'fraction_non_alphanumeric': 0.19239701747952573, 'fraction_numerical': 0.004767143381004767, 'mean_word_length': 3.1385938290338897, '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': '4557741', 'n_tokens_mistral': 3415, 'n_tokens_neox': 2754, 'n_words': 478}