<commit_before>"use strict";

/**
 * Enhanced image viewer for WCF.
 * 
 * @author	<NAME>
 * @copyright	2001-2015 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 */
WCF.ImageViewer = Class.extend({
	/**
	 * trigger element to mimic a slideshow button
	 * @var	jQuery
	 */
	_triggerElement: null,
	
	/**
	 * Initializes the WCF.ImageViewer class.
	 */
	init: function() {
		this._triggerElement = $('<span class="wcfImageViewerTriggerElement" />').data('disableSlideshow', true).hide().appendTo(document.body);
		this._triggerElement.wcfImageViewer({
			enableSlideshow: 0,
			imageSelector: '.jsImageViewerEnabled',
			staticViewer: true
		});
		
		WCF.DOMNodeInsertedHandler.addCallback('WCF.ImageViewer', $.proxy(this._domNodeInserted, this));
		WCF.DOMNodeInsertedHandler.execute();
	},
	
	/**
	 * Executes actions upon DOMNodeInserted events.
	 */
	_domNodeInserted: function() {
		this._initImageSizeCheck();
		this._rebuildImageViewer();
	},
	
	/**
	 * Rebuilds the image viewer.
	 */
	_rebuildImageViewer: function() {
		var $links = $('a.jsImageViewer');
		if ($links.length) {
			$links.removeClass('jsImageViewer').addClass('jsImageViewerEnabled').click($.proxy(this._click, this));
		}
	},
	
	/**
	 * Handles click on an image with image viewer support.
	 * 
	 * @param	object		event
	 */
	_click: function(event) {
		event.preventDefault();
		event.stopPropagation();
		
		this._triggerElement.wcfImageViewer('open', null, $(event.currentTarget).wcfIdentify());
	},
	
	/**
	 * Initializes the image size check.
	 */
	_initImageSizeCheck: function() {
		$('.jsResizeImage').each($.proxy(function(index, image) {
			if (image.complete) this._checkImageSize({ currentTarget: image });
		}, this));
		
		$('.jsResizeImage').on('load', $.proxy(this._checkImageSize, this));
	},
	
	/**
	 * Checks the image size.
	 */
	_checkImageSize: function(event) {
		var $image = $(event.currentTarget);
		if (!$image.is(':visible')) {
			$image.off('load');
			
			return;
		}
		
		$image.removeClass('jsResizeImage');
		
		// check if image falls within the signature, in that case ignore it
		if ($image.closest('.messageSignature').length) {
			return;
		}
		
		// setting img { max-width: 100% } causes the image to fit within boundaries, but does not reveal the original dimenions
		var $imageObject = new Image();
		$imageObject.src = $image.attr('src');
		
		var $maxWidth = $image.closest('div.messageText, div.messageTextPreview').width();
		if ($maxWidth < $imageObject.width) {
			if (!$image.parents('a').length) {
				$image.wrap('<a href="' + $image.attr('src') + '" class="jsImageViewerEnabled embeddedImageLink" />');
				$image.parent().click($.proxy(this._click, this));
				
				if ($image.css('float') == 'right') {
					$image.parent().addClass('messageFloatObjectRight');
				}
				else if ($image.css('float') == 'left') {
					$image.parent().addClass('messageFloatObjectLeft');
				}
				$image[0].style.removeProperty('float');
				$image[0].style.removeProperty('margin');
			}
		}
	}
});

/**<commit_msg>Fixed resizing of small embedded attachments<commit_after>"use strict";

/**
 * Enhanced image viewer for WCF.
 * 
 * @author	<NAME>
 * @copyright	2001-2015 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 */
WCF.ImageViewer = Class.extend({
	/**
	 * trigger element to mimic a slideshow button
	 * @var	jQuery
	 */
	_triggerElement: null,
	
	/**
	 * Initializes the WCF.ImageViewer class.
	 */
	init: function() {
		this._triggerElement = $('<span class="wcfImageViewerTriggerElement" />').data('disableSlideshow', true).hide().appendTo(document.body);
		this._triggerElement.wcfImageViewer({
			enableSlideshow: 0,
			imageSelector: '.jsImageViewerEnabled',
			staticViewer: true
		});
		
		WCF.DOMNodeInsertedHandler.addCallback('WCF.ImageViewer', $.proxy(this._domNodeInserted, this));
		WCF.DOMNodeInsertedHandler.execute();
	},
	
	/**
	 * Executes actions upon DOMNodeInserted events.
	 */
	_domNodeInserted: function() {
		this._initImageSizeCheck();
		this._rebuildImageViewer();
	},
	
	/**
	 * Rebuilds the image viewer.
	 */
	_rebuildImageViewer: function() {
		var $links = $('a.jsImageViewer');
		if ($links.length) {
			$links.removeClass('jsImageViewer').addClass('jsImageViewerEnabled').click($.proxy(this._click, this));
		}
	},
	
	/**
	 * Handles click on an image with image viewer support.
	 * 
	 * @param	object		event
	 */
	_click: function(event) {
		event.preventDefault();
		event.stopPropagation();
		
		this._triggerElement.wcfImageViewer('open', null, $(event.currentTarget).wcfIdentify());
	},
	
	/**
	 * Initializes the image size check.
	 */
	_initImageSizeCheck: function() {
		$('.jsResizeImage').each($.proxy(function(index, image) {
			if (image.complete) this._checkImageSize({ currentTarget: image });
		}, this));
		
		$('.jsResizeImage').on('load', $.proxy(this._checkImageSize, this));
	},
	
	/**
	 * Checks the image size.
	 */
	_checkImageSize: function(event) {
		var $image = $(event.currentTarget);
		if (!$image.is(':visible')) {
			$image.off('load');
			
			return;
		}
		
		$image.removeClass('jsResizeImage');
		
		// check if image falls within the signature, in that case ignore it
		if ($image.closest('.messageSignature').length) {
			return;
		}
		
		// setting img { max-width: 100% } causes the image to fit within boundaries, but does not reveal the original dimenions
		var $imageObject = new Image();
		$imageObject.src = $image.attr('src');
		
		var $maxWidth = $image.closest('div.messageText, div.messageTextPreview').width();
		if ($maxWidth < $imageObject.width) {
			if (!$image.parents('a').length) {
				$image.wrap('<a href="' + $image.attr('src') + '" class="jsImageViewerEnabled embeddedImageLink" />');
				$image.parent().click($.proxy(this._click, this));
				
				if ($image.css('float') == 'right') {
					$image.parent().addClass('messageFloatObjectRight');
				}
				else if ($image.css('float') == 'left') {
					$image.parent().addClass('messageFloatObjectLeft');
				}
				$image[0].style.removeProperty('float');
				$image[0].style.removeProperty('margin');
			}
		}
		else {
			$image.removeClass('embeddedAttachmentLink');
		}
	}
});

/**
{'fraction_non_alphanumeric': 0.17041288059939422, 'fraction_numerical': 0.004463574047505181, 'mean_word_length': 3.955766192733017, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '5441618', 'n_tokens_mistral': 2295, 'n_tokens_neox': 1960, 'n_words': 395}