<commit_before>
// ---------------------------------------------
// BZZ

// ---> Site

if (!site) { var site = {}; }

// ---------------------------------------------
// UI

site.ui = {};

// ---> init

site.ui.init = function() {
	
	loggr.log("site.ui.init()");
	
	if (!site.session.ui_pause_callbacks) { site.session.ui_pause_callbacks = []; }
	if (!site.session.ui_resume_callbacks) { site.session.ui_resume_callbacks = []; }
	
	// Add some events to ui || TODO: move this to site.ui ?
	$(".actionbar .icon_app").on("click", function() {
		site.lifecycle.onBackButton
	});
	
	/*
	$("#canvas_doodle").on("touchstart", function(e){ doo.touchBegin(e); });
	$("#canvas_doodle").on("touchmove",  function(e){ doo.touchMove(e); });
	$("#canvas_doodle").on("touchend",  function(e){ doo.touchEnd(e); });
	*/
	
	site.ui.hackActiveCssRule();
	
}

// ---> Sections

site.ui.gotosection = function(selector) {
	
	loggr.log("site.ui.gotosection(): "+ selector);
	
	site.vars.previousSection = site.vars.currentSection;
	
	site.vars.currentSection = selector;
	site.lifecycle.add_section_history(selector);
	
	// When leaving home: dismiss overflow menu
	if (selector!="#home" && site.home.overflowMenuIsVisible) {
		site.home.dismissOverflowMenu();
	}
	
	// Call close function
	if (!site.session.ui_pause_callbacks) { site.session.ui_pause_callbacks = []; }
	while (site.session.ui_pause_callbacks.length>0) {
		var func = site.session.ui_pause_callbacks.shift(); // same order as incoming..
		try { func(); } catch(e) { }
	}
	
	// Clean up ui_resume_callbacks
	if (!site.session.ui_resume_callbacks) { site.session.ui_resume_callbacks = []; }
	while (site.session.ui_resume_callbacks.length>0) {
		site.session.ui_resume_callbacks.shift(); // same order as incoming..
	}
	
	// TODO: nice animations?
	// TODO: Settimeout is a workaround so that :active elements lose their active state..
	if (site.timeouts.gotosection) { clearTimeout(site.timeouts.gotosection); }
		
	$(".activatablel_active").removeClass("activatablel_active");
	$(".activatabled_active").removeClass("activatabled_active");
	
	// Hide home when needed (because it is shown by default so body.onload does load it)
	if (selector!="#home") {
		$("#home").css("display","none");
	}
		
	if (site.vars.previousSection=="#splash") {
		// Resize .main
		$(site.vars.currentSection+" .main").css("height",$(window).height()-56);
		// Show..
		$(selector).css("display","block");
		// Translate splash
		var translate = "translate3d(0px,"+ (-($(window).height()-$(".actionbar").height())) +"px,0px)";
		$("#splash").css({"transform":translate,"-webkit-transform":translate});
		setTimeout(function(){
			$("#splash").fadeOut(250);
		},750);
	} else {
		$("section").css("display","none");
		$(selector).css("display","block");
	}
	
	loggr.log(" > "+ selector +" display: "+$(selector).css("display"));
	setTimeout(site.lifecycle.onResize,10);
	
	site.ui.setLongclickHelp();
	
}

// ---> Loading

site.ui.showloading = function(message,submsg) {
	loggr.log("site.ui.showloading()");
	if (!message) { message = site.helpers.getRandomListEntry(site.data.strings.loading); }
	if (submsg) { message += "<br><span class='overlay_submsg'>"+submsg+"</span>"; }
	site.vars.isLoading = true;
	$("#loading.overlay_wrap .message").html(message);
	$("#loading.overlay_wrap").fadeIn(500); // TODO: animation gpu powered..
	
}


site.ui.hideloading = function() {
	loggr.log("site.ui.hideloading()");
	site.vars.isLoading = false;
	$("#loading.overlay_wrap .message").html("");
	$("#loading.overlay_wrap").fadeOut(500); // TODO: animation gpu powered..
}

// ---> Loadbar

site.ui.showLoadbar = function() {
	
	loggr.log("site.ui.showLoadbar()");
	
	if (site.timeouts.fadeOutLoadbar) { clearTimeout(site.timeouts.fadeOutLoadbar); }
	$(".loadbar").css("display","block");
	
}

site.ui.hideLoadbar = function() {
	
	loggr.log("site.ui.hideLoadbar()");
	
	if (site.timeouts.fadeOutLoadbar) { clearTimeout(site.timeouts.fadeOutLoadbar); }
	site.timeouts.fadeOutLoadbar = setTimeout(function(){$(".loadbar").fadeOut(250,function(){$(".loadbar").css("display","none");})},1000);
	
}

// ---> Hoverbox (toasts!)

site.ui.showtoast = function(msg, timeInSec, topMode) {
	loggr.log("site.ui.showtoast()");
	if (site.ui.ui_showtoast_hide) { clearTimeout(site.ui.ui_showtoast_hide); }
	if (!timeInSec) { timeInSec = 1.5; }
	var timeInMsec = timeInSec * 1000;
	if (topMode && !$("#overlay_toast").hasClass("top")) {
		$("#overlay_toast").addClass("top");
	} 
	if (!topMode) {
		$(".fab").css("bottom",$("#overlay_toast").outerHeight()+16);
	}
	$("#overlay_toast").html(msg);
	$("#overlay_toast").fadeIn(250);
	site.ui.ui_showtoast_hide = setTimeout(function(){site.ui.hidetoast();},timeInMsec);
}

site.ui.hidetoast = function() {
	loggr.log("site.ui.hidetoast()");
	if (site.timeouts.ui_showtoast_hide) { clearTimeout(site.ui.ui_showtoast_hide); }
	$("#overlay_toast").fadeOut(250, function(){
		if ($("#overlay_toast").hasClass("top")) {
			$("#overlay_toast").removeClass("top");
	}
	});
	$(".fab").css("bottom",16);
	
}

site.ui.createtoast = function() {
	loggr.log("site.ui.createtoast()");
	var snip = document.createElement("div");
	snip.id = "overlay_toast";
	$("body").append(snip);
}

// ---> Longclick help

site.ui.setLongclickHelp = function() {
	<commit_msg>Always remove .top class from toast unless topMode=true<commit_after>
// ---------------------------------------------
// BZZ

// ---> Site

if (!site) { var site = {}; }

// ---------------------------------------------
// UI

site.ui = {};

// ---> init

site.ui.init = function() {
	
	loggr.log("site.ui.init()");
	
	if (!site.session.ui_pause_callbacks) { site.session.ui_pause_callbacks = []; }
	if (!site.session.ui_resume_callbacks) { site.session.ui_resume_callbacks = []; }
	
	// Add some events to ui || TODO: move this to site.ui ?
	$(".actionbar .icon_app").on("click", function() {
		site.lifecycle.onBackButton
	});
	
	/*
	$("#canvas_doodle").on("touchstart", function(e){ doo.touchBegin(e); });
	$("#canvas_doodle").on("touchmove",  function(e){ doo.touchMove(e); });
	$("#canvas_doodle").on("touchend",  function(e){ doo.touchEnd(e); });
	*/
	
	site.ui.hackActiveCssRule();
	
}

// ---> Sections

site.ui.gotosection = function(selector) {
	
	loggr.log("site.ui.gotosection(): "+ selector);
	
	site.vars.previousSection = site.vars.currentSection;
	
	site.vars.currentSection = selector;
	site.lifecycle.add_section_history(selector);
	
	// When leaving home: dismiss overflow menu
	if (selector!="#home" && site.home.overflowMenuIsVisible) {
		site.home.dismissOverflowMenu();
	}
	
	// Call close function
	if (!site.session.ui_pause_callbacks) { site.session.ui_pause_callbacks = []; }
	while (site.session.ui_pause_callbacks.length>0) {
		var func = site.session.ui_pause_callbacks.shift(); // same order as incoming..
		try { func(); } catch(e) { }
	}
	
	// Clean up ui_resume_callbacks
	if (!site.session.ui_resume_callbacks) { site.session.ui_resume_callbacks = []; }
	while (site.session.ui_resume_callbacks.length>0) {
		site.session.ui_resume_callbacks.shift(); // same order as incoming..
	}
	
	// TODO: nice animations?
	// TODO: Settimeout is a workaround so that :active elements lose their active state..
	if (site.timeouts.gotosection) { clearTimeout(site.timeouts.gotosection); }
		
	$(".activatablel_active").removeClass("activatablel_active");
	$(".activatabled_active").removeClass("activatabled_active");
	
	// Hide home when needed (because it is shown by default so body.onload does load it)
	if (selector!="#home") {
		$("#home").css("display","none");
	}
		
	if (site.vars.previousSection=="#splash") {
		// Resize .main
		$(site.vars.currentSection+" .main").css("height",$(window).height()-56);
		// Show..
		$(selector).css("display","block");
		// Translate splash
		var translate = "translate3d(0px,"+ (-($(window).height()-$(".actionbar").height())) +"px,0px)";
		$("#splash").css({"transform":translate,"-webkit-transform":translate});
		setTimeout(function(){
			$("#splash").fadeOut(250);
		},750);
	} else {
		$("section").css("display","none");
		$(selector).css("display","block");
	}
	
	loggr.log(" > "+ selector +" display: "+$(selector).css("display"));
	setTimeout(site.lifecycle.onResize,10);
	
	site.ui.setLongclickHelp();
	
}

// ---> Loading

site.ui.showloading = function(message,submsg) {
	loggr.log("site.ui.showloading()");
	if (!message) { message = site.helpers.getRandomListEntry(site.data.strings.loading); }
	if (submsg) { message += "<br><span class='overlay_submsg'>"+submsg+"</span>"; }
	site.vars.isLoading = true;
	$("#loading.overlay_wrap .message").html(message);
	$("#loading.overlay_wrap").fadeIn(500); // TODO: animation gpu powered..
	
}


site.ui.hideloading = function() {
	loggr.log("site.ui.hideloading()");
	site.vars.isLoading = false;
	$("#loading.overlay_wrap .message").html("");
	$("#loading.overlay_wrap").fadeOut(500); // TODO: animation gpu powered..
}

// ---> Loadbar

site.ui.showLoadbar = function() {
	
	loggr.log("site.ui.showLoadbar()");
	
	if (site.timeouts.fadeOutLoadbar) { clearTimeout(site.timeouts.fadeOutLoadbar); }
	$(".loadbar").css("display","block");
	
}

site.ui.hideLoadbar = function() {
	
	loggr.log("site.ui.hideLoadbar()");
	
	if (site.timeouts.fadeOutLoadbar) { clearTimeout(site.timeouts.fadeOutLoadbar); }
	site.timeouts.fadeOutLoadbar = setTimeout(function(){$(".loadbar").fadeOut(250,function(){$(".loadbar").css("display","none");})},1000);
	
}

// ---> Hoverbox (toasts!)

site.ui.showtoast = function(msg, timeInSec, topMode) {
	loggr.log("site.ui.showtoast()");
	if (site.ui.ui_showtoast_hide) { clearTimeout(site.ui.ui_showtoast_hide); }
	if (!timeInSec) { timeInSec = 1.5; }
	var timeInMsec = timeInSec * 1000;
	if (topMode && !$("#overlay_toast").hasClass("top")) {
		$("#overlay_toast").addClass("top");
	} 
	if (!topMode) {
		$(".fab").css("bottom",$("#overlay_toast").outerHeight()+16);
		$("#overlay_toast").removeClass("top");
	}
	$("#overlay_toast").html(msg);
	$("#overlay_toast").fadeIn(250);
	site.ui.ui_showtoast_hide = setTimeout(function(){site.ui.hidetoast();},timeInMsec);
}

site.ui.hidetoast = function() {
	loggr.log("site.ui.hidetoast()");
	if (site.timeouts.ui_showtoast_hide) { clearTimeout(site.ui.ui_showtoast_hide); }
	$("#overlay_toast").fadeOut(250, function(){
		if ($("#overlay_toast").hasClass("top")) {
			$("#overlay_toast").removeClass("top");
	}
	});
	$(".fab").css("bottom",16);
	
}

site.ui.createtoast = function() {
	loggr.log("site.ui.createtoast()");
	var snip = document.createElement("div");
	snip.id = "overlay_toast";
	$("body").append(snip);
}

// ---> Longclick help

site.ui.setLongclickHelp = function() {
	
{'fraction_non_alphanumeric': 0.22692379704175247, 'fraction_numerical': 0.008238157648380453, 'mean_word_length': 4.296479920674269, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 29, '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': '11470', 'n_tokens_mistral': 3938, 'n_tokens_neox': 3766, 'n_words': 538}