<commit_before>"use strict";

var monthNames=[ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

// USER DATA
var user_language=window.navigator.userLanguage || window.navigator.language;
var is_iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
function is_cordova(){
	if( navigator.userAgent.match(/(i(os|phone|pod|pad|emobile)|android|blackberry)/i)
		&& /^file:\/{3}[^\/]/i.test(window.location.href) ){
		return true;
	}
	return false;
}

// Audio types. Best choice: m4a (mp4)
var html5_audiotypes={"mp3": "audio/mpeg","mp4": "audio/mp4","m4a": "audio/mp4",
					  "ogg": "audio/ogg","wav": "audio/wav" };

var JsonLazy={
    data: {},
    load: function(json_url, name, callback){
        if(typeof(json_url)=='undefined' || typeof(name)=='undefined'
            || typeof(callback)=='undefined')
            throw new Error('json_url, name or callback are not defined');
        ajax_request_json(json_url,function(json){
            JsonLazy.data[name]=json; //console.log(json)
            callback();
        });
    }
}

/*
* Load media
* lazy audio means that if some browsers do not load it inmediatly we let the load process finish when images are loaded
*
*/
var ResourceLoader={
	MEDIA_LOAD_TIMEOUT:15000, 		// 15 sec + (initial-interval, aprox 1 sec)
	media_load_time:0,			// load time counter
	media_load_check_status_interval:250, 	// check status every 0.25 sec
	media_load_check_status_initial_min_splash:1500,
	load_progressbar: undefined,
	load_interval: undefined,
	modal_load_window: undefined,
	modal_dialog: undefined,
	modal_dialog_msg: undefined,
	callback_on_load_end: undefined,
	num_images:0,
	num_sounds:0,
	not_loaded:{},
	ret_media:{},
	lazy_audio:false,
	download_lazy_audio_active : false,
	debug: false,
	
	load_image: function (resource_url){
		//var image_object = new Image();
		ResourceLoader.ret_media.images[get_resource_name(resource_url)]=new Image();
		// event for "error" (onerror), useless will be logged anyway in browser console...
        // "load" (onload) -> only means some data is got, to really know if it is loaded check .width property
		ResourceLoader.ret_media.images[get_resource_name(resource_url)].addEventListener("load", ResourceLoader.log_and_remove_from_not_loaded('load','images',resource_url));
		ResourceLoader.ret_media.images[get_resource_name(resource_url)].src = resource_url; // after? load begins as soon as src is set..
		//return image_object; // not good for async stuff
	},
	
	load_sound: function (resource_url){
		//var audio_object=new Audio() ;
		ResourceLoader.ret_media.sounds[get_resource_name(resource_url)]=new Audio();
		if (!ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].canPlayType 
			|| ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].canPlayType("audio/mp4")==""){ 
			return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio or mp4/m4a");}}
		}
		ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].src=resource_url;
		ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].addEventListener('canplaythrough', 
			ResourceLoader.log_and_remove_from_not_loaded('canplaythrough','sounds',resource_url)); // canplaythrough is 
			//sometimes clever and checks for connection instead of readyState, so we need further checking
		ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].playclip=function(){
			try{
				console.log(ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].error
				+  " - "+ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].readyState
				+ " - "+ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].networkState);
				ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].pause();
				ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].currentTime=0;
				ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].play();
			}catch(exception){alert("error playing audio")}
		}
		//return audio_object; // not good for async stuff
	},
	log_and_remove_from_not_loaded: function(event_name,res_type,res_url){
		if(ResourceLoader.debug) console.log(event_name+" ("+res_type+": "+res_url+") "+get_resource_name(res_url));
		if(res_type=='sounds'){
			if (ResourceLoader.ret_media.sounds[get_resource_name(res_url)]===undefined || ResourceLoader.ret_media.sounds[get_resource_name(res_url)].readyState==0){
				if(ResourceLoader.debug) console.log("INFO: "+res_url+" fired canplaythrough but it is not loaded (res="+ResourceLoader.ret_media.sounds[get_resource_name(res_url)]+" or readyState="+ResourceLoader.ret_media.sounds[get_resource_name(res_url)].readyState+")");
				return; // break so this is still in "not_loaded"
			}
			ResourceLoader.ret_media.sounds[get_resource_name(res_url)].removeEventListener(event_name, ResourceLoader.log_and_remove_from_not_loaded);
		}
		if(res_type=='images'){
            // nonexistent appear as complete (doesn't work), so we use "width"
			if (ResourceLoader.ret_media.images[get_resource_name(res_url)]===undefined ||
                !ResourceLoader.ret_media.images[get_resource_name(res_url)].complete ||     
                ResourceLoader.ret_media.images[get_resource_name(res_url)].width==0){
				if(ResourceLoader.debug)
                    console.log("INFO: "+res_url+" fired loaded but it is not loaded (res="+ResourceLoader.ret_media.images[get_resource_name(res_url)]+", complete="+ResourceLoader.ret_media.images[get_resource_name(res_url)].complete+" or width="+ResourceLoader.ret_media.images[get_resource_name(res_url)].width+").");
				return; // break so this is still in "not loaded"
			}
			ResourceLoader.ret_media.images[get_resource_name(res_url)].removeEventListener(event_name, ResourceLoader.log_and_remove_from_not_loaded);
		}
		ResourceLoader.load_progressbar.value+=1;
		ResourceLoader.not_loaded[res_type].splice(ResourceLoader.not_loaded[res_type].indexOf(res_url),1);
	},
	download_audio_ios: function(){
		ResourceLoader.modal_load_window.removeChild(document.getElementById('confirm_div'))
		// ResourceLoader.load_interval = , better with timeout + return
		setTimeout(function() {ResourceLoader.check_load_status()},
			ResourceLoader.media_load_check_status_interval);
		for(var i=0;i<ResourceLoader.not_loaded['sounds'].length;i++){
			ResourceLoader.ret_media.sounds[get_resource_name(ResourceLoader.not_loaded['sounds'][i])].load(); // play()-pause() with 1ms timeout extreme alternative
		}	
	},
	check_for_audios_readyState4: function(){
		for(var i=0;i<ResourceLoader.not_loaded.sounds.length;i++){
			var res_url=ResourceLoader.not_loaded.sounds[i];
			if (ResourceLoader.ret_media.sounds[get_resource_name(res_url)]!==undefined && ResourceLoader.ret_media.sounds[get_resource_name(res_url)].readyState==4){
				if(ResourceLoader.debug) console.log(res_url+" readyState==4 removing from not loaded.");
				ResourceLoader.log_and_remove_from_not_loaded('readyState4','sounds',res_url);
			}
		}
	},
	check_for_images_complete: function(){
		for(var i=0;i<ResourceLoader.not_loaded.images.length;i++){
			var res_url=ResourceLoader.not_loaded.images[i];
			if (ResourceLoader.ret_media.images[get_resource_name(res_url)]!==undefined && <commit_msg>minor clean<commit_after>"use strict";

var monthNames=[ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

// USER DATA
var user_language=window.navigator.userLanguage || window.navigator.language;
var is_iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
function is_cordova(){
	if( navigator.userAgent.match(/(i(os|phone|pod|pad|emobile)|android|blackberry)/i)
		&& /^file:\/{3}[^\/]/i.test(window.location.href) ){
		return true;
	}
	return false;
}

// Audio types. Best choice: m4a (mp4)
var html5_audiotypes={"mp3": "audio/mpeg","mp4": "audio/mp4","m4a": "audio/mp4",
					  "ogg": "audio/ogg","wav": "audio/wav" };

var JsonLazy={
    data: {},
    load: function(json_url, name, callback){
        if(typeof(json_url)=='undefined' || typeof(name)=='undefined'
            || typeof(callback)=='undefined')
            throw new Error('json_url, name or callback are not defined');
        ajax_request_json(json_url,function(json){
            JsonLazy.data[name]=json; //console.log(json)
            callback();
        });
    }
}

/*
* Load media
* lazy audio means that if some browsers do not load it inmediatly we let the load process finish when images are loaded
*
*/
var ResourceLoader={
	MEDIA_LOAD_TIMEOUT:15000, 		// 15 sec + (initial-interval, aprox 1 sec)
	media_load_time:0,			// load time counter
	media_load_check_status_interval:250, 	// check status every 0.25 sec
	media_load_check_status_initial_min_splash:1500,
	load_progressbar: undefined,
	load_interval: undefined,
	modal_load_window: undefined,
	modal_dialog: undefined,
	modal_dialog_msg: undefined,
	callback_on_load_end: undefined,
	num_images:0,
	num_sounds:0,
	not_loaded:{},
	ret_media:{},
	lazy_audio:false,
	download_lazy_audio_active : false,
	debug: false,
	
	load_image: function (resource_url){
		ResourceLoader.ret_media.images[get_resource_name(resource_url)]=new Image();
		ResourceLoader.ret_media.images[get_resource_name(resource_url)].addEventListener("load", ResourceLoader.log_and_remove_from_not_loaded('load','images',resource_url));
		ResourceLoader.ret_media.images[get_resource_name(resource_url)].src = resource_url; // after? load begins as soon as src is set..
		//return image_object; // not good for async stuff
	},
	
	load_sound: function (resource_url){
		//var audio_object=new Audio() ;
		ResourceLoader.ret_media.sounds[get_resource_name(resource_url)]=new Audio();
		if (!ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].canPlayType 
			|| ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].canPlayType("audio/mp4")==""){ 
			return {playclip:function(){throw new Error("Your browser doesn't support HTML5 audio or mp4/m4a");}}
		}
		ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].src=resource_url;
		ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].addEventListener('canplaythrough', 
			ResourceLoader.log_and_remove_from_not_loaded('canplaythrough','sounds',resource_url)); // canplaythrough is 
			//sometimes clever and checks for connection instead of readyState, so we need further checking
		ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].playclip=function(){
			try{
				console.log(ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].error
				+  " - "+ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].readyState
				+ " - "+ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].networkState);
				ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].pause();
				ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].currentTime=0;
				ResourceLoader.ret_media.sounds[get_resource_name(resource_url)].play();
			}catch(exception){alert("error playing audio")}
		}
		//return audio_object; // not good for async stuff
	},
	log_and_remove_from_not_loaded: function(event_name,res_type,res_url){
		if(ResourceLoader.debug) console.log(event_name+" ("+res_type+": "+res_url+") "+get_resource_name(res_url));
		if(res_type=='sounds'){
			if (ResourceLoader.ret_media.sounds[get_resource_name(res_url)]===undefined || ResourceLoader.ret_media.sounds[get_resource_name(res_url)].readyState==0){
				if(ResourceLoader.debug) console.log("INFO: "+res_url+" fired canplaythrough but it is not loaded (res="+ResourceLoader.ret_media.sounds[get_resource_name(res_url)]+" or readyState="+ResourceLoader.ret_media.sounds[get_resource_name(res_url)].readyState+")");
				return; // break so this is still in "not_loaded"
			}
			ResourceLoader.ret_media.sounds[get_resource_name(res_url)].removeEventListener(event_name, ResourceLoader.log_and_remove_from_not_loaded);
		}
		if(res_type=='images'){
            // nonexistent appear as complete (doesn't work), so we use "width"
			if (ResourceLoader.ret_media.images[get_resource_name(res_url)]===undefined ||
                !ResourceLoader.ret_media.images[get_resource_name(res_url)].complete ||     
                ResourceLoader.ret_media.images[get_resource_name(res_url)].width==0
				){
				if(ResourceLoader.debug)
                    console.log("INFO: "+res_url+" fired loaded but it is not loaded (res="+ResourceLoader.ret_media.images[get_resource_name(res_url)]+", complete="+ResourceLoader.ret_media.images[get_resource_name(res_url)].complete+" or width="+ResourceLoader.ret_media.images[get_resource_name(res_url)].width+").");
				return; // break so this is still in "not loaded"
			}
			ResourceLoader.ret_media.images[get_resource_name(res_url)].removeEventListener(event_name, ResourceLoader.log_and_remove_from_not_loaded);
		}
		ResourceLoader.load_progressbar.value+=1;
		ResourceLoader.not_loaded[res_type].splice(ResourceLoader.not_loaded[res_type].indexOf(res_url),1);
	},
	download_audio_ios: function(){
		ResourceLoader.modal_load_window.removeChild(document.getElementById('confirm_div'))
		// ResourceLoader.load_interval = , better with timeout + return
		setTimeout(function() {ResourceLoader.check_load_status()},
			ResourceLoader.media_load_check_status_interval);
		for(var i=0;i<ResourceLoader.not_loaded['sounds'].length;i++){
			ResourceLoader.ret_media.sounds[get_resource_name(ResourceLoader.not_loaded['sounds'][i])].load(); // play()-pause() with 1ms timeout extreme alternative
		}	
	},
	check_for_audios_readyState4: function(){
		for(var i=0;i<ResourceLoader.not_loaded.sounds.length;i++){
			var res_url=ResourceLoader.not_loaded.sounds[i];
			if (ResourceLoader.ret_media.sounds[get_resource_name(res_url)]!==undefined && ResourceLoader.ret_media.sounds[get_resource_name(res_url)].readyState==4){
				if(ResourceLoader.debug) console.log(res_url+" readyState==4 removing from not loaded.");
				ResourceLoader.log_and_remove_from_not_loaded('readyState4','sounds',res_url);
			}
		}
	},
	check_for_images_complete: function(){
		for(var i=0;i<ResourceLoader.not_loaded.images.length;i++){
			var res_url=ResourceLoader.not_loaded.images[i];
			if (ResourceLoader.ret_media.images[get_resource_name(res_url)]!==undefined && 
{'fraction_non_alphanumeric': 0.13758459499058118, 'fraction_numerical': 0.006558292053303565, 'mean_word_length': 5.9921951219512195, 'pattern_counts': {'":': 12, '<': 9, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6172747', 'n_tokens_mistral': 4964, 'n_tokens_neox': 4623, 'n_words': 719}