<commit_before>/**
 * ImageViewer for WCF.
 * Based upon "Slimbox 2" by <NAME> 2007-20120, http://www.digitalia.be/software/slimbox2, MIT-style license.
 * 
 * @author	<NAME>
 * @copyright	2001-2012 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 */
WCF.ImageViewer = Class.extend({
	/**
	 * Initializes the ImageViewer for every a-tag with the attribute rel = imageviewer.
	 */
	init: function() {
		WCF.DOMNodeInsertedHandler.addCallback('WCF.ImageViewer', $.proxy(this._domNodeInserted, this));
		
		WCF.DOMNodeInsertedHandler.enable();
		
		// navigation buttons
		$('<span><span class="icon icon24 icon-chevron-left jsTooltip" title="' + WCF.Language.get('wcf.imageViewer.previous') + '" /></span>').appendTo($('#lbPrevLink'));
		$('<span><span class="icon icon24 icon-chevron-right jsTooltip" title="' + WCF.Language.get('wcf.imageViewer.next') + '" /></span>').appendTo($('#lbNextLink'));
		
		// close and enlarge icons
		$('<span class="icon icon24 icon-remove jsTooltip" title="' + WCF.Language.get('wcf.imageViewer.close') + '" />').appendTo($('#lbCloseLink'));
		var $buttonEnlarge = $('<span class="icon icon24 icon-resize-full jsTooltip" title="' + WCF.Language.get('wcf.imageViewer.enlarge') + '" id="lbEnlarge" />').insertAfter($('#lbCloseLink'));
		
		WCF.DOMNodeInsertedHandler.disable();
		
		// handle enlarge button
		$buttonEnlarge.click($.proxy(this._enlarge, this));
		
		this._initImageViewer();
	},
	
	/**
	 * Executes actions upon DOMNodeInserted events.
	 */
	_domNodeInserted: function() {
		this._initImageSizeCheck();
		this._initImageViewer();
	},
	
	/**
	 * Initializes the image viewer for all links with class ".jsImageViewer"
	 */
	_initImageViewer: function() {
		WCF.DOMNodeInsertedHandler.enable();
		
		$('a.jsImageViewer').each(function(index, link) {
			var $link = $(link).removeClass('jsImageViewer');
			$link.slimbox({
				counterText: WCF.Language.get('wcf.imageViewer.counter'),
				loop: true
			});
		});
		
		WCF.DOMNodeInsertedHandler.disable();
	},
	
	/**
	 * Redirects to image for full view.
	 */
	_enlarge: function() {
		var $url = $('#lbImage').css('backgroundImage');
		if ($url) {
			$url = $url.substring(4, $url.length - 1);
			window.location = $url;
		}
	},
	
	/**
	 * Initializes the image size check.
	 */
	_initImageSizeCheck: function() {
		$('.jsResizeImage').on('load', $.proxy(this._checkImageSize, this));
	},
	
	/**
	 * Checks the image size.
	 */
	_checkImageSize: function(event) {
		var $image = $(event.currentTarget);
		$image.removeClass('jsResizeImage');
		var $dimensions = $image.getDimensions();
		var $maxWidth = $image.parents('div').innerWidth();
		
		if ($dimensions.width > $maxWidth) {
			$image.css({
				height: Math.round($dimensions.height * ($maxWidth / $dimensions.width)) + 'px',
				width: $maxWidth + 'px'
			});
			
			if (!$image.parents('a').length) {
				$image.wrap('<a href="' + $image.attr('src') + '" />');
				$image.parent().slimbox();<commit_msg>Fix enlarging in ImageViewer<commit_after>/**
 * ImageViewer for WCF.
 * Based upon "Slimbox 2" by <NAME> 2007-20120, http://www.digitalia.be/software/slimbox2, MIT-style license.
 * 
 * @author	<NAME>
 * @copyright	2001-2012 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 */
WCF.ImageViewer = Class.extend({
	/**
	 * Initializes the ImageViewer for every a-tag with the attribute rel = imageviewer.
	 */
	init: function() {
		WCF.DOMNodeInsertedHandler.addCallback('WCF.ImageViewer', $.proxy(this._domNodeInserted, this));
		
		WCF.DOMNodeInsertedHandler.enable();
		
		// navigation buttons
		$('<span><span class="icon icon24 icon-chevron-left jsTooltip" title="' + WCF.Language.get('wcf.imageViewer.previous') + '" /></span>').appendTo($('#lbPrevLink'));
		$('<span><span class="icon icon24 icon-chevron-right jsTooltip" title="' + WCF.Language.get('wcf.imageViewer.next') + '" /></span>').appendTo($('#lbNextLink'));
		
		// close and enlarge icons
		$('<span class="icon icon24 icon-remove jsTooltip" title="' + WCF.Language.get('wcf.imageViewer.close') + '" />').appendTo($('#lbCloseLink'));
		var $buttonEnlarge = $('<span class="icon icon24 icon-resize-full jsTooltip" title="' + WCF.Language.get('wcf.imageViewer.enlarge') + '" id="lbEnlarge" />').insertAfter($('#lbCloseLink'));
		
		WCF.DOMNodeInsertedHandler.disable();
		
		// handle enlarge button
		$buttonEnlarge.click($.proxy(this._enlarge, this));
		
		this._initImageViewer();
	},
	
	/**
	 * Executes actions upon DOMNodeInserted events.
	 */
	_domNodeInserted: function() {
		this._initImageSizeCheck();
		this._initImageViewer();
	},
	
	/**
	 * Initializes the image viewer for all links with class ".jsImageViewer"
	 */
	_initImageViewer: function() {
		WCF.DOMNodeInsertedHandler.enable();
		
		$('a.jsImageViewer').each(function(index, link) {
			var $link = $(link).removeClass('jsImageViewer');
			$link.slimbox({
				counterText: WCF.Language.get('wcf.imageViewer.counter'),
				loop: true
			});
		});
		
		WCF.DOMNodeInsertedHandler.disable();
	},
	
	/**
	 * Redirects to image for full view.
	 */
	_enlarge: function() {
		var $url = $('#lbImage').css('backgroundImage');
		if ($url) {
			$url = $url.replace(/^url\((["']?)(.*)\1\)$/, '$2');
			window.location = $url;
		}
	},
	
	/**
	 * Initializes the image size check.
	 */
	_initImageSizeCheck: function() {
		$('.jsResizeImage').on('load', $.proxy(this._checkImageSize, this));
	},
	
	/**
	 * Checks the image size.
	 */
	_checkImageSize: function(event) {
		var $image = $(event.currentTarget);
		$image.removeClass('jsResizeImage');
		var $dimensions = $image.getDimensions();
		var $maxWidth = $image.parents('div').innerWidth();
		
		if ($dimensions.width > $maxWidth) {
			$image.css({
				height: Math.round($dimensions.height * ($maxWidth / $dimensions.width)) + 'px',
				width: $maxWidth + 'px'
			});
			
			if (!$image.parents('a').length) {
				$image.wrap('<a href="' + $image.attr('src') + '" />');
				$image.parent().slimbox();
{'fraction_non_alphanumeric': 0.19145073444462782, 'fraction_numerical': 0.00957253672223139, 'mean_word_length': 4.075376884422111, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, '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': '5704649', 'n_tokens_mistral': 2298, 'n_tokens_neox': 1994, 'n_words': 381}