<commit_before>window.addEventListener("DOMContentLoaded", function() {
	/**
	 * Base URL
	 */
	var BASEURL = window.location.hostname.indexOf("herokuapp") > 0 
										? "https://vertx-realtime-chat.herokuapp.com"
										: "http://localhost:7070";

	/**
	 * Get UI Elements from Document
	 */
	// Combobox - Chat ID
	var fiContainerId = document.querySelector("#fiContainerId");
	var cboChatId = document.querySelector("#cboChatId");
	var ulChatIds = document.querySelector("#ulChatIds");
	// Open Show Dialog
	var btnAddChatId = document.querySelector("#btnAddChatId");
	// Clear Chat
	var btnClearCombobox = document.querySelector("#btnClearCombobox");
	// Chat Name
	var txtChatName = document.querySelector("#txtChatName");
	// Chat Message
	var fiContainerMessage = document.querySelector("#fiContainerMessage");
	var txtChatMessage = document.querySelector("#txtChatMessage");
	// Send Chat Message
	var btnSend = document.querySelector("#btnSend");
	// Chat History
	var ulChatHistory = document.querySelector("#ulChatHistory");
	// Error Toast
	var errorToast = document.querySelector("#errorToast");
	// Dialog
	var addDialog = document.querySelector("#addDialog");
	var fiContainerNewId = document.querySelector("#fiContainerNewId");
	var txtDialogChatId = document.querySelector("#txtDialogChatId");
	var fiContainerNewDesc = document.querySelector("#fiContainerNewDesc");
	var txtDialogChatDescription = document.querySelector("#txtDialogChatDescription");
	var btnDialogSave = document.querySelector("#btnDialogSave");
	var btnDialogCancel = document.querySelector("#btnDialogCancel");

	var eventBus;
	
	/**
	 * Show Toast
	 * @param msg Error Message
	 * @returns
	 */
	function _showErrorToast(msg) {
		errorToast.MaterialSnackbar.showSnackbar({message: msg});
	};

	/**
	 * Create List Item for Chat History
	 * @param name Chat Name
	 * @param msg Chat Message
	 * @param timestamp Chat Message created time
	 * @returns
	 */
	function _createListItem(name, msg, timestamp) {
		// wrapper element
		var wrapper = document.createElement("div");
		wrapper.classList.add("message__card");
		// heading element
		var header = document.createElement("div");
		var heading = document.createElement("p");
		heading.innerHTML = "<b><em>" + name + " says:</em></b>";
		// content message element
		var content = document.createElement("div");
		content.classList.add("message__card--content");
		content.innerHTML = msg;
		// content timestamp element
		var createdAt = document.createElement("p");
		createdAt.classList.add("message__card--created", "mdl-typography--text-right");
		// convert timestamp into readable time
		var timeStampOpts = {
				year:"numeric", month:"numeric", day:"numeric",
				hour:"numeric", minute:"numeric", second: "numeric"
		}
		createdAt.innerHTML = new Intl.DateTimeFormat("en-US", timeStampOpts)
															.format(new Date().setTime(timestamp));
		// add elements to the parents
		header.appendChild(heading);
		wrapper.appendChild(header);
		content.appendChild(createdAt);
		wrapper.appendChild(content);
		// add list item to the list view
		ulChatHistory.appendChild(wrapper);
	};

	/**
	 * Scroll to last Chat Message
	 * @returns
	 */
	function _scrollToBottom() {
		// get all message cards
		var items = document.querySelectorAll(".message__card");
		// scroll into last card
		items[items.length - 1].scrollIntoView(true);
	};

	/**
	 * Requester Data from Server
	 * @param {String} route
	 * @param {Object} body
	 * @returns Promise
	 */
	function _dataRequester(route, body) {
		return new Promise(function(resolve, reject) {
			// create xhr object
			var xhr = new XMLHttpRequest();
			// init listener
			xhr.onreadystatechange = function() {
				if (xhr.readyState === 4) {
					// check xhr status
					if (xhr.status === 200 || xhr.status === 201) {
						if (xhr.responseText) {<commit_msg>add comment for xhr,readyState<commit_after>window.addEventListener("DOMContentLoaded", function() {
	/**
	 * Base URL
	 */
	var BASEURL = window.location.hostname.indexOf("herokuapp") > 0 
										? "https://vertx-realtime-chat.herokuapp.com"
										: "http://localhost:7070";

	/**
	 * Get UI Elements from Document
	 */
	// Combobox - Chat ID
	var fiContainerId = document.querySelector("#fiContainerId");
	var cboChatId = document.querySelector("#cboChatId");
	var ulChatIds = document.querySelector("#ulChatIds");
	// Open Show Dialog
	var btnAddChatId = document.querySelector("#btnAddChatId");
	// Clear Chat
	var btnClearCombobox = document.querySelector("#btnClearCombobox");
	// Chat Name
	var txtChatName = document.querySelector("#txtChatName");
	// Chat Message
	var fiContainerMessage = document.querySelector("#fiContainerMessage");
	var txtChatMessage = document.querySelector("#txtChatMessage");
	// Send Chat Message
	var btnSend = document.querySelector("#btnSend");
	// Chat History
	var ulChatHistory = document.querySelector("#ulChatHistory");
	// Error Toast
	var errorToast = document.querySelector("#errorToast");
	// Dialog
	var addDialog = document.querySelector("#addDialog");
	var fiContainerNewId = document.querySelector("#fiContainerNewId");
	var txtDialogChatId = document.querySelector("#txtDialogChatId");
	var fiContainerNewDesc = document.querySelector("#fiContainerNewDesc");
	var txtDialogChatDescription = document.querySelector("#txtDialogChatDescription");
	var btnDialogSave = document.querySelector("#btnDialogSave");
	var btnDialogCancel = document.querySelector("#btnDialogCancel");

	var eventBus;
	
	/**
	 * Show Toast
	 * @param msg Error Message
	 * @returns
	 */
	function _showErrorToast(msg) {
		errorToast.MaterialSnackbar.showSnackbar({message: msg});
	};

	/**
	 * Create List Item for Chat History
	 * @param name Chat Name
	 * @param msg Chat Message
	 * @param timestamp Chat Message created time
	 * @returns
	 */
	function _createListItem(name, msg, timestamp) {
		// wrapper element
		var wrapper = document.createElement("div");
		wrapper.classList.add("message__card");
		// heading element
		var header = document.createElement("div");
		var heading = document.createElement("p");
		heading.innerHTML = "<b><em>" + name + " says:</em></b>";
		// content message element
		var content = document.createElement("div");
		content.classList.add("message__card--content");
		content.innerHTML = msg;
		// content timestamp element
		var createdAt = document.createElement("p");
		createdAt.classList.add("message__card--created", "mdl-typography--text-right");
		// convert timestamp into readable time
		var timeStampOpts = {
				year:"numeric", month:"numeric", day:"numeric",
				hour:"numeric", minute:"numeric", second: "numeric"
		}
		createdAt.innerHTML = new Intl.DateTimeFormat("en-US", timeStampOpts)
															.format(new Date().setTime(timestamp));
		// add elements to the parents
		header.appendChild(heading);
		wrapper.appendChild(header);
		content.appendChild(createdAt);
		wrapper.appendChild(content);
		// add list item to the list view
		ulChatHistory.appendChild(wrapper);
	};

	/**
	 * Scroll to last Chat Message
	 * @returns
	 */
	function _scrollToBottom() {
		// get all message cards
		var items = document.querySelectorAll(".message__card");
		// scroll into last card
		items[items.length - 1].scrollIntoView(true);
	};

	/**
	 * Requester Data from Server
	 * @param {String} route
	 * @param {Object} body
	 * @returns Promise
	 */
	function _dataRequester(route, body) {
		return new Promise(function(resolve, reject) {
			// create xhr object
			var xhr = new XMLHttpRequest();
			// init listener
			xhr.onreadystatechange = function() {
				// 4 == DONE --> operation is complete
				if (xhr.readyState === 4) {
					// check xhr status
					if (xhr.status === 200 || xhr.status === 201) {
						if (xhr.responseText) {
{'fraction_non_alphanumeric': 0.1352669404517454, 'fraction_numerical': 0.003465092402464066, 'mean_word_length': 4.265540540540541, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 2, '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': '3800909', 'n_tokens_mistral': 2433, 'n_tokens_neox': 2200, 'n_words': 534}