<commit_before>/*
 * jQuery Chaos Modal
 * By <NAME>
 * Based on concept work by <NAME> - http://www.queness.com/post/77/simple-jquery-modal-window-tutorial
 * Version 1.2.0
 * Recent changes:
 * - Added image prerendering in modal content (1.2.0)
 * - Updated and fixed resizeModal function to work based off of the html element's width (1.2.0)
 * - Added image in link href support (1.2.0)
 * - Reworked automatic modal binding to clone content on-the-fly (1.2.0)
 * - Added maxWidth parameter to openModal function (1.1.0)
 * - Added automatic modal binding to .chaos-modal-link elements (1.1.0)
 * - Added option to close the modal when the mask is clicked or the ESC key is pressed (1.1.0)
 * - Reworked references to optimize javascript caching (1.1.0)
 * - Clones content container and appends to body for absolute positioning relative to body
 * - Added max width variable so you can keep modal content inside your wrapper div's width
 * Things left to do:
 * -Jquery animation queue integration
 * -Function parameters for changing the default CSS styles
 * -Change namespacing of functions to work similar to $('#example').modal("open")
 * -Add position parameter to openModal function
 */

(function( $ ) {
	//Property to store the modal current being displayed
	var currentModal,
		maxWidth;
	
	//Global variable for generating modal box clones
	$.chaosModalIndex = 0;
	
	$.fn.openModal = function( options ) {
		//Default options
		var defaults = { maskClose: true, maxWidth: 960, closeLink: true, printLink: false };
		options = $.extend({}, defaults, options);
		
		//Clone modal content
		var clone = this.clone(),
			bodyElement = $('body'),
			htmlElement =  $('html'),
			documentElement = $(document),
			windowElement = $(window),
			maskClose = options['maskClose'],
			closeLink = options['closeLink'],
			printLink = options['printLink'];
			
		//Update maxWidth
		maxWidth = options['maxWidth'];
		
		//Update currentModal
		currentModal = clone;
		clone.attr({id: 'chaos-current-modal'});
		
		//Write the mask div
		var modalMask = $('<div id="chaos-modal-mask" class="chaos-modal-mask"></div>');
		modalMask.css({'position': 'absolute', 'z-index': '9000', 'background-color': '#000', 'display': 'none', 'top': '0', 'left': '0'});
		modalMask.appendTo(bodyElement);
		
		//Write print link if none exist
		if(clone.find('.print-link').length == 0 && printLink) {
			clone.prepend('<a class="print-link">Print</a>');
			clone.children('.print-link').css({'float': 'right', 'margin': '5px'});
			}
		
		//Write close link if none exist
		if(clone.find('.close-link').length == 0 && closeLink) {
			clone.prepend('<a class="close-link">Close</a>');
			clone.children('.close-link').css({'float': 'right', 'margin': '5px'});
			}
               
        //Set the popup window css
        clone.css({'display': 'block', 'position': 'absolute', 'background': '#fff', 'z-index': '9001', 'left': '-10000px', 'margin': '0', 'padding': '0'});
        clone.appendTo(bodyElement);
        
        //Show modal after all images have loaded
        clone.find('img').last().on('load', function(e){
        	//Lock popup window width
	       	if(clone.width() > maxWidth){
	       		clone.width(maxWidth);
	       	} else {
	       		clone.width(clone.width());
	       	}
	       	clone.hide();
	       	
	     	//Calculate the modal mask size and popup window position
	     	clone.resizeModal();
	     	
	     	//Scroll to top of window
	     	windowElement.scrollTop(0).scrollLeft(0);
	     	
	     	//Mask transition effect    
	        modalMask.fadeIn(1000);   
	        modalMask.fadeTo("slow",0.8);
	     	
	        //transition effect
	        clone.fadeIn(2000);
	        
	        //Bind the window resize event
	        windowElement.bind('resize', resizeCurrentModal);
	        
	        //Bind the print link events if any close links exist
	        if(clone.find('.print-link').length > 0) {
	        	clone.find('.print-link').bind('click', printCurrentModal);
	        	}
	        
	        //Bind the close link events if any close links exist
	        if(clone.find('.close-link').length > 0) {
	        	clone.find('.close-link').bind('click', closeCurrentModal);
	        	}
	        
	        //Bind close event to mask click and when the ESC key is pressed
			if(maskClose) {
				modalMask.on('click', closeCurrentModal);
				documentElement.on('keyup', closeOnESC);
			}
        });
        clone.show();
        
        return this;
	};
	
	$.fn.closeModal = function() {
		//Clear currentModal
		currentModal = null;
		
		//Unbind the window resize event
		$(window).unbind('resize', resizeCurrentModal);
		
		//Unbind the close link events if any close links exist
        if(this.find('.close-link').length > 0) {
        	this.find('.close-link').unbind('click');
        	}
		
		//Remove the popup window
		this.hide().remove();
		
		//Remove the mask div
		$('#chaos-modal-mask').hide().remove();
		
		return this;
	};
	
	$.fn.resizeModal = function() {
		var documentElement = $(document),
			windowElement = $(window),
			htmlElement = $('html'),
			maskHeight = documentElement.height(), //Get the screen height and width
			maskWidth = htmlElement.width(),
			winH = windowElement.height(), //Get the window height and width
        	winW = windowElement.width();
        	
        //Check for invalid mask dimensions
        if(maskHeight < this.height()) { maskHeight = this.height(); }
        if(maskWidth < winW) { maskWidth = winW; }
        
        //Set height and width to mask to fill up the whole screen
        $('#chaos-modal-mask').css({'width':maskWidth,'height':maskHeight});
                
        //Calculate popup window position
        var modalTop = winH/2-this.height()/2,
        	modalLeft = winW/2-this.width()/2;
        
        //Check for invalid window positions
        if (modalTop < 0) { modalTop = 0; }
        if (modalLeft < 0) { modalLeft = 0; }
        
        //Set the popup window to center
        this.css({'top': modalTop, 'left': modalLeft});
        
        return this;
	};
	
	$.fn.printModal = function() {
		window.print();
	};
	
	function resizeCurrentModal() {
		currentModal.resizeModal();
	}
	
	function closeCurrentModal() {
		currentModal.closeModal();
	}
	
	function printCurrentModal() {
		currentModal.printModal();
	}
	function closeOnESC(e) {
		if( e.which == 27 ) {
			$(this).off('keyup', closeOnESC);
			closeCurrentModal();
		}
	}
})( jQuery );

/* Create modal box clones and click events */
jQuery(document).ready(function($){
	$('.chaos-modal-link').one('click', processModalLink);<commit_msg>Added alwaysAtTop parameter to openModal and resizeModal function. Implemented vertical positioning from current scroll position. Fixed browser following the href of print and close links.<commit_after>/*
 * jQuery Chaos Modal
 * By <NAME>
 * Based on concept work by <NAME> - http://www.queness.com/post/77/simple-jquery-modal-window-tutorial
 * Version 1.3.0
 * Recent changes:
 * - Added alwaysAtTop parameter to openModal and resizeModal function (1.3.0)
 * - Implemented vertical positioning from current scroll position (1.3.0)
 * - Fixed browser following the href of print and close links (1.3.0)
 * - Added image prerendering in modal content (1.2.0)
 * - Updated and fixed resizeModal function to work based off of the html element's width (1.2.0)
 * - Added image in link href support (1.2.0)
 * - Reworked automatic modal binding to clone content on-the-fly (1.2.0)
 * - Added maxWidth parameter to openModal function (1.1.0)
 * - Added automatic modal binding to .chaos-modal-link elements (1.1.0)
 * - Added option to close the modal when the mask is clicked or the ESC key is pressed (1.1.0)
 * - Reworked references to optimize javascript caching (1.1.0)
 * - Clones content container and appends to body for absolute positioning relative to body
 * - Added max width variable so you can keep modal content inside your wrapper div's width
 * Things left to do:
 * -Jquery animation queue integration
 * -Function parameters for changing the default CSS styles
 * -Change namespacing of functions to work similar to $('#example').modal("open")
 * -Add position parameter to openModal function
 */

(function( $ ) {
	//Property to store the modal current being displayed
	var currentModal,
		maxWidth;
	
	//Global variable for generating modal box clones
	$.chaosModalIndex = 0;
	
	$.fn.openModal = function( options ) {
		//Default options
		var defaults = { maskClose: true, maxWidth: 960, closeLink: true, printLink: false, alwaysAtTop: false };
		options = $.extend({}, defaults, options);
		
		//Clone modal content
		var clone = this.clone(),
			bodyElement = $('body'),
			htmlElement =  $('html'),
			documentElement = $(document),
			windowElement = $(window),
			maskClose = options['maskClose'],
			closeLink = options['closeLink'],
			printLink = options['printLink'],
			alwaysAtTop = options['alwaysAtTop'];
			
		//Update maxWidth
		maxWidth = options['maxWidth'];
		
		//Update currentModal
		currentModal = clone;
		clone.attr({id: 'chaos-current-modal'});
		
		//Write the mask div
		var modalMask = $('<div id="chaos-modal-mask" class="chaos-modal-mask"></div>');
		modalMask.css({'position': 'absolute', 'z-index': '9000', 'background-color': '#000', 'display': 'none', 'top': '0', 'left': '0'});
		modalMask.appendTo(bodyElement);
		
		//Write print link if none exist
		if(clone.find('.print-link').length == 0 && printLink) {
			clone.prepend('<a class="print-link">Print</a>');
			clone.children('.print-link').css({'float': 'right', 'margin': '5px'});
			}
		
		//Write close link if none exist
		if(clone.find('.close-link').length == 0 && closeLink) {
			clone.prepend('<a class="close-link">Close</a>');
			clone.children('.close-link').css({'float': 'right', 'margin': '5px'});
			}
               
        //Set the popup window css
        clone.css({'display': 'block', 'position': 'absolute', 'background': '#fff', 'z-index': '9001', 'left': '-10000px', 'margin': '0', 'padding': '0'});
        clone.appendTo(bodyElement);
        
        //Show modal after all images have loaded
        clone.find('img').last().on('load', function(e){
        	//Lock popup window width
	       	if(clone.width() > maxWidth){
	       		clone.width(maxWidth);
	       	} else {
	       		clone.width(clone.width());
	       	}
	       	clone.hide();
	       	
	     	//Calculate the modal mask size and popup window position
	     	clone.resizeModal( alwaysAtTop );
	     	
	     	//Mask transition effect    
	        modalMask.fadeIn(1000);   
	        modalMask.fadeTo("slow",0.8);
	     	
	        //transition effect
	        clone.fadeIn(2000);
	        
	        //Bind the window resize event
	        windowElement.bind('resize', {'alwaysAtTop': alwaysAtTop}, resizeCurrentModal);
	        
	        //Bind the print link events if any close links exist
	        if(clone.find('.print-link').length > 0) {
	        	clone.find('.print-link').bind('click', printCurrentModal);
	        	}
	        
	        //Bind the close link events if any close links exist
	        if(clone.find('.close-link').length > 0) {
	        	clone.find('.close-link').bind('click', closeCurrentModal);
	        	}
	        
	        //Bind close event to mask click and when the ESC key is pressed
			if(maskClose) {
				modalMask.on('click', closeCurrentModal);
				documentElement.on('keyup', closeOnESC);
			}
        });
        clone.show();
        
        return this;
	};
	
	$.fn.closeModal = function() {
		//Clear currentModal
		currentModal = null;
		
		//Unbind the window resize event
		$(window).unbind('resize', resizeCurrentModal);
		
		//Unbind the close link events if any close links exist
        if(this.find('.close-link').length > 0) {
        	this.find('.close-link').unbind('click');
        	}
		
		//Remove the popup window
		this.hide().remove();
		
		//Remove the mask div
		$('#chaos-modal-mask').hide().remove();
		
		return this;
	};
	
	$.fn.resizeModal = function( alwaysAtTop ) {
		var documentElement = $(document),
			windowElement = $(window),
			htmlElement = $('html'),
			maskHeight = documentElement.height(), //Get the screen height and width
			maskWidth = htmlElement.width(),
			winH = windowElement.height(), //Get the window height and width
        	winW = windowElement.width();
        	
        //Check for invalid mask dimensions
        if(maskHeight < this.height()) { maskHeight = this.height(); }
        if(maskWidth < winW) { maskWidth = winW; }
        
        //Set height and width to mask to fill up the whole screen
        $('#chaos-modal-mask').css({'width':maskWidth,'height':maskHeight});
                
        //Calculate popup window position
        var modalTop = winH/2-this.height()/2,
        	modalLeft = winW/2-this.width()/2;
        
        //Check for invalid window positions
        if (modalTop < 0) { modalTop = 0; }
        if (modalLeft < 0) { modalLeft = 0; }
        
        if( alwaysAtTop ) { 
        	windowElement.scrollTop(0); //Scroll to top of window
        } else {
        	modalTop += windowElement.scrollTop(); 
        	console.log(htmlElement.height());
        	var spaceFromBottom = documentElement.height() - (modalTop + this.height());
        	if( spaceFromBottom < 0 && modalTop + spaceFromBottom >= 0)
        		modalTop += spaceFromBottom;
        }
        windowElement.scrollLeft(0);
        
        //Set the popup window to center
        this.css({'top': modalTop, 'left': modalLeft});
        
        return this;
	};
	
	$.fn.printModal = function() {
		window.print();
	};
	
	function resizeCurrentModal(e) {
		var alwaysAtTop = false;
		if( e.data.alwaysAtTop ) { alwaysAtTop = e.data.alwaysAtTop; }
		currentModal.resizeModal( alwaysAtTop );
	}
	
	function closeCurrentModal(e) {
		e.preventDefault(); //Prevents browser from following links
		currentModal.closeModal();
	}
	
	function printCurrentModal(e) {
		e.preventDefault(); //Prevents browser from following links
		currentModal.printModal();
	}
	function closeOnESC(e) {
		if( e.which == 27 ) {
			$(this).off('keyup', closeOnESC);
			closeCurrentModal();
		}
	}
})( jQuery );

/* Create modal box clones and click events */
jQuery(document).ready(function($){
	$('.chaos-modal-link').one('click', processModalLink);
{'fraction_non_alphanumeric': 0.1417915650052283, 'fraction_numerical': 0.012199372603694667, 'mean_word_length': 2.7281704781704783, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5647576', 'n_tokens_mistral': 4623, 'n_tokens_neox': 4126, 'n_words': 1209}