<commit_before>var iterating = false; // decide if iterating the slideshow or just jumping into fullscreen

// function to test if fullscreen
var Fullscreen = function(){
	if(window.innerHeight == screen.height && window.innerWidth == screen.width){
		return true;
	}
	else{
		return false;
	}
}

// removes video and img elements in the fullscreenView parent element, so as to retain the #fullscreenNotifications
var removeFullScreenChildren = function(){
	$('#FullScreenView').css({backgroundImage:'none'});
	$('#FullScreenView video').remove();
	$('#FullScreenView img').remove();
};

var goFullscreen = function(){
	var element = document.getElementById('FullScreenView');
	if(element.requestFullscreen) {
		element.requestFullscreen();
	  } else if(element.mozRequestFullScreen) {
		element.mozRequestFullScreen();
	  } else if(element.webkitRequestFullscreen) {
		element.webkitRequestFullscreen();
	  } else if(element.msRequestFullscreen) {
		element.msRequestFullscreen();
	  }
	  
	
};
	
var fullscreenImage = function(img){
	currentFSElement = img; // this is for other functions to know on the first time using currentFSElement
	removeFullScreenChildren();
	var element = document.getElementById("FullScreenView");
	//element.style.visibility="visible";
	element.style.backgroundImage='url('+img.getAttribute("src")+')';
	$(element).css("background-color","rgba(100,100,100,0.4");
	if (!window.screenTop && !window.screenY) { // not already fullscreen, right?
	
		goFullscreen();
		
		if(getSetting('fullscreenCaptions') === true){
			notify(imageDB[selected_index].caption);
		}
		
	}
};

var fullscreenVideo = function(vid){
	currentFSElement = vid; // this is just to initiate the currentFSElement
	muteAll(); // mute any videos playing outside of fullscreen
	var fsParent = $('#FullScreenView');
	var vidClone = $(vid).clone(true,false);
	vidClone.off()
	.prop('currentTime',0)
	.attr('id','') // remove the duplicate id'
	.prop('muted',false)
	.prop('volume',global_volume)
	removeFullScreenChildren(); // resets FullscreenView
	vidClone.appendTo(fsParent).get(0).play(); // appends and begins playing the new Fullscreen video

	if(!iterating){ // if just jumping into fullscreen, match the playhead with the smaller version of the video
		matchVideoCurrentTimes(true);
	}

	if (!window.screenTop && !window.screenY) {			  
		
		goFullscreen();
		if(getSetting('fullscreenCaptions').value){
			notify(imageDB[selected_index].caption);
		}
	}
	
	checkMuted();
};


var IterateSlideshow = function(direction){
		removeFullScreenChildren(); // get rid of whatever videos/images are already in the fsview
		var nextElemId = parseInt(currentFSElement.getAttribute("id"))-direction; // the id of the element to switch to
		var element = null;
		iterating = true;
		
		if (direction>0){
			if(nextElemId > -1){ // if not reached the end of the collection, proceed (direction increment correlates with id decrement)
				element = document.getElementById((parseInt(currentFSElement.getAttribute("id"))-1).toString());
			}
			else{ // we've reached the end of the collection:
				element = document.getElementById((imageDB.length-1).toString()); // go back to the beginning of the collection
			}
		}else{
			if(nextElemId<=imageDB.length-1){ // does not exceed the collection length
				element = document.getElementById((parseInt(currentFSElement.getAttribute("id"))+1).toString());
			}
			else{ // go back to the end of collection
				element = document.getElementById("0");
			}
		}
		// Decide what to do whether image is an IMG or a VIDEO
		currentFSElement = element;
		if($(element).is('img')){
			fullscreenImage(currentFSElement);
		}
		else if($(element).is('video')){ // video 
			fullscreenVideo(currentFSElement);
			
		}
		
		var newid = parseInt(currentFSElement.getAttribute('id'));
		if(getSetting('fullscreenCaptions')){
			notify(imageDB[newid].caption ? imageDB[newid].caption : imageDB[newid]);
		}
		
};

var currentFSfalse = function(){
		//alert("got fullscreen request")
		currentFSElement = false;
		$("#FullScreenView").css("visibility","hidden");
};
	
// jumps to an element on the page purely by scrolling to its position
var jumpToElementByScrollPosition = function(element_to_jump_to){
	// make the documents scroll position (scrollTop) equal to an elements position
	$(document).scrollTop($(element_to_jump_to).offset().top - 100);
};

var exitFullScreen = function()
{
    if (document.exitFullscreen)
        document.exitFullscreen();
    else if (document.msExitFullscreen)
        document.msExitFullscreen();
    else if (document.mozCancelFullScreen)
        document.mozCancelFullScreen();
    else if (document.webkitExitFullscreen)
        document.webkitExitFullscreen();
};

var matchVideoCurrentTimes = function(goingFullscreen){
	if(goingFullscreen){ // from fullscreen video to smaller one
		$('#FullScreenView video').prop('currentTime',currentFSElement.currentTime);
	}
	else{ // transfer current time from fullscreen one to small one
		currentFSElement.currentTime = $('#FullScreenView video').prop('currentTime');
	}
};


$(document).ready(function(){
	$(document).bind("exitFullscreen msExitFullscreen mozCancelFullScreen webkitExitFullscreen",currentFSfalse());
	$(document).on("fullscreenchange mozfullscreenchange msfullscreenchange webkitfullscreenchange",function(){
			if($("#FullScreenView").css("visibility")=="visible"){
				$("#FullScreenView").css("visibility","hidden");
			 // clears everything inside the fullScreenView object
				// jumps to the last slideshow-ed image outside of full screen view:
				// jumpToElementById(currentFSElement); NO LONGER RELEVANT
				
				notifs.hide();
				iterating = false; // reset this variable
				if('#FullScreenView video'){
					matchVideoCurrentTimes(false);
					Unmute(currentFSElement);
				}
				removeFullScreenChildren(); // clear the fullscreen parent
				
				if(currentFSElement){
					jumpToElementByScrollPosition(currentFSElement);
				}
			}
			else{
				$("#FullScreenView").css("visibility","visible");
			}

	});

	//Fullscreen click events
	$('#FullScreenView')
		.on('click',function(e){
			if(e.which===1){
				IterateSlideshow(1);
			}
			else if(e.which===3){
				IterateSlideshow(-1);
			}
			else if(e.which===2){
				
				alert("middle button!");
				if(document.webkitExitFullscreen){
					e.preventDefault();
					document.webkitExitFullscreen();
				}
			}
		})
		.on('contextmenu',function(e){ // 'contextmenu' is just right click basically<commit_msg>Highlight the last-viewed fullscreen img/vid<commit_after>var iterating = false; // decide if iterating the slideshow or just jumping into fullscreen

// function to test if fullscreen
var Fullscreen = function(){
	if(window.innerHeight == screen.height && window.innerWidth == screen.width){
		return true;
	}
	else{
		return false;
	}
}

// removes video and img elements in the fullscreenView parent element, so as to retain the #fullscreenNotifications
var removeFullScreenChildren = function(){
	$('#FullScreenView').css({backgroundImage:'none'});
	$('#FullScreenView video').remove();
	$('#FullScreenView img').remove();
};

var goFullscreen = function(){
	var element = document.getElementById('FullScreenView');
	if(element.requestFullscreen) {
		element.requestFullscreen();
	  } else if(element.mozRequestFullScreen) {
		element.mozRequestFullScreen();
	  } else if(element.webkitRequestFullscreen) {
		element.webkitRequestFullscreen();
	  } else if(element.msRequestFullscreen) {
		element.msRequestFullscreen();
	  }
	  
	
};
	
var fullscreenImage = function(img){
	currentFSElement = img; // this is for other functions to know on the first time using currentFSElement
	removeFullScreenChildren();
	var element = document.getElementById("FullScreenView");
	//element.style.visibility="visible";
	element.style.backgroundImage='url('+img.getAttribute("src")+')';
	$(element).css("background-color","rgba(100,100,100,0.4");
	if (!window.screenTop && !window.screenY) { // not already fullscreen, right?
	
		goFullscreen();
		
		if(getSetting('fullscreenCaptions') === true){
			notify(imageDB[selected_index].caption);
		}
		
	}
};

var fullscreenVideo = function(vid){
	currentFSElement = vid; // this is just to initiate the currentFSElement
	muteAll(); // mute any videos playing outside of fullscreen
	var fsParent = $('#FullScreenView');
	var vidClone = $(vid).clone(true,false);
	vidClone.off()
	.prop('currentTime',0)
	.attr('id','') // remove the duplicate id'
	.prop('muted',false)
	.prop('volume',global_volume)
	removeFullScreenChildren(); // resets FullscreenView
	vidClone.appendTo(fsParent).get(0).play(); // appends and begins playing the new Fullscreen video

	if(!iterating){ // if just jumping into fullscreen, match the playhead with the smaller version of the video
		matchVideoCurrentTimes(true);
	}

	if (!window.screenTop && !window.screenY) {			  
		
		goFullscreen();
		if(getSetting('fullscreenCaptions').value){
			notify(imageDB[selected_index].caption);
		}
	}
	
	checkMuted();
};


var IterateSlideshow = function(direction){
		removeFullScreenChildren(); // get rid of whatever videos/images are already in the fsview
		var nextElemId = parseInt(currentFSElement.getAttribute("id"))-direction; // the id of the element to switch to
		var element = null;
		iterating = true;
		
		if (direction>0){
			if(nextElemId > -1){ // if not reached the end of the collection, proceed (direction increment correlates with id decrement)
				element = document.getElementById((parseInt(currentFSElement.getAttribute("id"))-1).toString());
			}
			else{ // we've reached the end of the collection:
				element = document.getElementById((imageDB.length-1).toString()); // go back to the beginning of the collection
			}
		}else{
			if(nextElemId<=imageDB.length-1){ // does not exceed the collection length
				element = document.getElementById((parseInt(currentFSElement.getAttribute("id"))+1).toString());
			}
			else{ // go back to the end of collection
				element = document.getElementById("0");
			}
		}
		// Decide what to do whether image is an IMG or a VIDEO
		currentFSElement = element;
		if($(element).is('img')){
			fullscreenImage(currentFSElement);
		}
		else if($(element).is('video')){ // video 
			fullscreenVideo(currentFSElement);
			
		}
		
		var newid = parseInt(currentFSElement.getAttribute('id'));
		if(getSetting('fullscreenCaptions')){
			notify(imageDB[newid].caption ? imageDB[newid].caption : imageDB[newid]);
		}
		
};

var currentFSfalse = function(){
		//alert("got fullscreen request")
		currentFSElement = false;
		$("#FullScreenView").css("visibility","hidden");
};
	
// jumps to an element on the page purely by scrolling to its position
var jumpToElementByScrollPosition = function(element_to_jump_to){
	// make the documents scroll position (scrollTop) equal to an elements position
	$(document).scrollTop($(element_to_jump_to).offset().top - 100);
};

var exitFullScreen = function()
{
    if (document.exitFullscreen)
        document.exitFullscreen();
    else if (document.msExitFullscreen)
        document.msExitFullscreen();
    else if (document.mozCancelFullScreen)
        document.mozCancelFullScreen();
    else if (document.webkitExitFullscreen)
        document.webkitExitFullscreen();
};

var matchVideoCurrentTimes = function(goingFullscreen){
	if(goingFullscreen){ // from fullscreen video to smaller one
		$('#FullScreenView video').prop('currentTime',currentFSElement.currentTime);
	}
	else{ // transfer current time from fullscreen one to small one
		currentFSElement.currentTime = $('#FullScreenView video').prop('currentTime');
	}
};

var tmHideHighlight = 0;
var highlightElement = function(element){
	clearTimeout(tmHideHighlight);
	
	var highlight = $('<div/>');
	highlight.css({
		display:'none',
		position:'absolute',
		top:$(element).offset().top,
		left:$(element).offset().left,
		width:$(element).parent().width(),
		height:$(element).parent().height(),
		backgroundColor:'rgba(100,255,0,0.5)',
		zIndex:100
	}).appendTo('body').fadeIn('slow');
	
	// Wait, and then fadeOut and remove() the highlight element
	tmHideHighlight = setTimeout(function(){highlight.fadeOut('slow',function(){highlight.remove()})},100); 
};


$(document).ready(function(){
	$(document).bind("exitFullscreen msExitFullscreen mozCancelFullScreen webkitExitFullscreen",currentFSfalse());
	$(document).on("fullscreenchange mozfullscreenchange msfullscreenchange webkitfullscreenchange",function(){
			if($("#FullScreenView").css("visibility")=="visible"){
				$("#FullScreenView").css("visibility","hidden");
			 // clears everything inside the fullScreenView object
				// jumps to the last slideshow-ed image outside of full screen view:
				// jumpToElementById(currentFSElement); NO LONGER RELEVANT
				
				notifs.hide();
				iterating = false; // reset this variable
				if('#FullScreenView video'){
					matchVideoCurrentTimes(false);
					Unmute(currentFSElement);
				}
				removeFullScreenChildren(); // clear the fullscreen parent
				jumpToElementByScrollPosition(currentFSElement);
				highlightElement(currentFSElement);
			}
			else{
				$("#FullScreenView").css("visibility","visible");
			}

	});

	//Fullscreen click events
	$('#FullScreenView')
		.on('click',function(e){
			if(e.which===1){
				IterateSlideshow(1);
			}
			else if(e.which===3){
				IterateSlideshow(-1);
			}
			else if(e.which===2){
				
				alert("middle button!");
				if(document.webkitExitFullscreen){
					e.preventDefault();
					document.webkitExitFullscreen();
				}
			}
		})
		.on('contextmenu',function(e){ // 'contextmenu' is just right click basically
{'fraction_non_alphanumeric': 0.1379816513761468, 'fraction_numerical': 0.0052844036697247704, 'mean_word_length': 4.69172932330827, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '3545260', 'n_tokens_mistral': 4438, 'n_tokens_neox': 3954, 'n_words': 934}