<commit_before>/**
 * Provides interface elements to display and review likes.
 * 
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @module	WoltLabSuite/Core/Ui/Like/Handler
 * @deprecated  3.2 use ReactionHandler instead 
 */
define(
	[
		'Ajax',      'Core',                     'Dictionary',         'Language',
		'ObjectMap', 'StringUtil',               'Dom/ChangeListener', 'Dom/Util',
		'Ui/Dialog', 'WoltLabSuite/Core/Ui/User/List', 'User',         'WoltLabSuite/Core/Ui/Reaction/Handler'
	],
	function(
		Ajax,        Core,                        Dictionary,           Language,
		ObjectMap,   StringUtil,                  DomChangeListener,    DomUtil,
		UiDialog,    UiUserList,                  User,                 UiReactionHandler
	)
{
	"use strict";
	
	/**
	 * @constructor
	 */
	function UiLikeHandler(objectType, options) { this.init(objectType, options); }
	UiLikeHandler.prototype = {
		/**
		 * Initializes the like handler.
		 * 
		 * @param	{string}	objectType	object type
		 * @param	{object}	options		initialization options
		 */
		init: function(objectType, options) {
			if (options.containerSelector === '') {
				throw new Error("[WoltLabSuite/Core/Ui/Like/Handler] Expected a non-empty string for option 'containerSelector'.");
			}
			
			this._containers = new ObjectMap();
			this._details = new ObjectMap();
			this._objectType = objectType;
			this._options = Core.extend({
				// settings
				badgeClassNames: '',
				isSingleItem: false,
				markListItemAsActive: false,
				renderAsButton: true,
				summaryPrepend: true,
				summaryUseIcon: true,
				
				// permissions
				canDislike: false,
				canLike: false,
				canLikeOwnContent: false,
				canViewSummary: false,
				
				// selectors
				badgeContainerSelector: '.messageHeader .messageStatus',
				buttonAppendToSelector: '.messageFooter .messageFooterButtons',
				buttonBeforeSelector: '',
				containerSelector: '',
				summarySelector: '.messageFooterGroup'
			}, options);
			
			this.initContainers(options, objectType);
			
			DomChangeListener.add('WoltLabSuite/Core/Ui/Like/Handler-' + objectType, this.initContainers.bind(this));
			
			new UiReactionHandler(this._objectType, {
				containerSelector: this._options.containerSelector,
				summaryListSelector: '.reactionSummaryList'
			});
		},
		
		/**
		 * Initializes all applicable containers.
		 */
		initContainers: function() {
			var element, elements = elBySelAll(this._options.containerSelector), elementData, triggerChange = false;
			for (var i = 0, length = elements.length; i < length; i++) {
				element = elements[i];
				if (this._containers.has(element)) {
					continue;
				}
				
				elementData = {
					badge: null,
					dislikeButton: null,
					likeButton: null,
					summary: null,
					
					dislikes: ~~elData(element, 'like-dislikes'),
					liked: ~~elData(element, 'like-liked'),
					likes: ~~elData(element, 'like-likes'),
					objectId: ~~elData(element, 'object-id'),
					users: JSON.parse(elData(element, 'like-users'))
				};
				
				this._containers.set(element, elementData);
				this._buildWidget(element, elementData);
				
				triggerChange = true;
			}
			
			if (triggerChange) {
				DomChangeListener.trigger();
			}
		},
		
		/**
		 * Creates the interface elements.
		 * 
		 * @param	{Element}	element		container element
		 * @param	{object}	elementData	like data
		 */
		_buildWidget: function(element, elementData) {
			// build reaction summary list
			var summaryList, listItem, badgeContainer, isSummaryPosition = true;
			badgeContainer = (this._options.isSingleItem) ? elBySel(this._options.summarySelector) : elBySel(this._options.summarySelector, element);
			if (badgeContainer === null) {
				badgeContainer = (this._options.isSingleItem) ? elBySel(this._options.badgeContainerSelector) : elBySel(this._options.badgeContainerSelector, element);
				isSummaryPosition = false;
			}
			
			if (badgeContainer !== null) {
				summaryList = elCreate('ul');
				summaryList.classList.add('reactionSummaryList');
				if (isSummaryPosition) {
					summaryList.classList.add('likesSummary');
				}
				else {
					summaryList.classList.add('reactionSummaryListTiny');
				}
				
				for (var key in elementData.users) {
					if (key === "reactionTypeID") continue;
					if (!REACTION_TYPES.hasOwnProperty(key)) continue;
					
					// create element 
					var createdElement = elCreate('li');
					createdElement.className = 'reactCountButton';
					createdElement.innerHTML = REACTION_TYPES[key].renderedIcon +' ';
					elData(createdElement, 'reaction-type-id', key);
					
					var countSpan = elCreate('span');
					countSpan.className = 'reactionCount';
					countSpan.innerHTML = StringUtil.shortUnit(elementData.users[key]);
					createdElement.appendChild(countSpan);
					
					summaryList.appendChild(createdElement);
					
				}
				
				if (isSummaryPosition) {
					if (this._options.summaryPrepend) {
						DomUtil.prepend(summaryList, badgeContainer);
					}
					else {
						badgeContainer.appendChild(summaryList);
					}<commit_msg>Fix legacy code for reactions See #2508<commit_after>/**
 * Provides interface elements to display and review likes.
 * 
 * @author	<NAME>
 * @copyright	2001-2018 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @module	WoltLabSuite/Core/Ui/Like/Handler
 * @deprecated  3.2 use ReactionHandler instead 
 */
define(
	[
		'Ajax',      'Core',                     'Dictionary',         'Language',
		'ObjectMap', 'StringUtil',               'Dom/ChangeListener', 'Dom/Util',
		'Ui/Dialog', 'WoltLabSuite/Core/Ui/User/List', 'User',         'WoltLabSuite/Core/Ui/Reaction/Handler'
	],
	function(
		Ajax,        Core,                        Dictionary,           Language,
		ObjectMap,   StringUtil,                  DomChangeListener,    DomUtil,
		UiDialog,    UiUserList,                  User,                 UiReactionHandler
	)
{
	"use strict";
	
	/**
	 * @constructor
	 */
	function UiLikeHandler(objectType, options) { this.init(objectType, options); }
	UiLikeHandler.prototype = {
		/**
		 * Initializes the like handler.
		 * 
		 * @param	{string}	objectType	object type
		 * @param	{object}	options		initialization options
		 */
		init: function(objectType, options) {
			if (options.containerSelector === '') {
				throw new Error("[WoltLabSuite/Core/Ui/Like/Handler] Expected a non-empty string for option 'containerSelector'.");
			}
			
			this._containers = new ObjectMap();
			this._details = new ObjectMap();
			this._objectType = objectType;
			this._options = Core.extend({
				// settings
				badgeClassNames: '',
				isSingleItem: false,
				markListItemAsActive: false,
				renderAsButton: true,
				summaryPrepend: true,
				summaryUseIcon: true,
				
				// permissions
				canDislike: false,
				canLike: false,
				canLikeOwnContent: false,
				canViewSummary: false,
				
				// selectors
				badgeContainerSelector: '.messageHeader .messageStatus',
				buttonAppendToSelector: '.messageFooter .messageFooterButtons',
				buttonBeforeSelector: '',
				containerSelector: '',
				summarySelector: '.messageFooterGroup'
			}, options);
			
			this.initContainers(options, objectType);
			
			DomChangeListener.add('WoltLabSuite/Core/Ui/Like/Handler-' + objectType, this.initContainers.bind(this));
			
			new UiReactionHandler(this._objectType, {
				containerSelector: this._options.containerSelector,
				summaryListSelector: '.reactionSummaryList'
			});
		},
		
		/**
		 * Initializes all applicable containers.
		 */
		initContainers: function() {
			var element, elements = elBySelAll(this._options.containerSelector), elementData, triggerChange = false;
			for (var i = 0, length = elements.length; i < length; i++) {
				element = elements[i];
				if (this._containers.has(element)) {
					continue;
				}
				
				elementData = {
					badge: null,
					dislikeButton: null,
					likeButton: null,
					summary: null,
					
					dislikes: ~~elData(element, 'like-dislikes'),
					liked: ~~elData(element, 'like-liked'),
					likes: ~~elData(element, 'like-likes'),
					objectId: ~~elData(element, 'object-id'),
					users: JSON.parse(elData(element, 'like-users'))
				};
				
				this._containers.set(element, elementData);
				this._buildWidget(element, elementData);
				
				triggerChange = true;
			}
			
			if (triggerChange) {
				DomChangeListener.trigger();
			}
		},
		
		/**
		 * Creates the interface elements.
		 * 
		 * @param	{Element}	element		container element
		 * @param	{object}	elementData	like data
		 */
		_buildWidget: function(element, elementData) {
			// build reaction summary list
			var summaryList, listItem, badgeContainer, isSummaryPosition = true;
			badgeContainer = (this._options.isSingleItem) ? elBySel(this._options.summarySelector) : elBySel(this._options.summarySelector, element);
			if (badgeContainer === null) {
				badgeContainer = (this._options.isSingleItem) ? elBySel(this._options.badgeContainerSelector) : elBySel(this._options.badgeContainerSelector, element);
				isSummaryPosition = false;
			}
			
			if (badgeContainer !== null) {
				summaryList = elCreate('ul');
				summaryList.classList.add('reactionSummaryList');
				if (isSummaryPosition) {
					summaryList.classList.add('likesSummary');
				}
				else {
					summaryList.classList.add('reactionSummaryListTiny');
				}
				
				for (var key in elementData.users) {
					if (key === "reactionTypeID") continue;
					if (!REACTION_TYPES.hasOwnProperty(key)) continue;
					
					// create element 
					var createdElement = elCreate('li');
					createdElement.className = 'reactCountButton';
					elData(createdElement, 'reaction-type-id', key);
					
					var countSpan = elCreate('span');
					countSpan.className = 'reactionCount';
					countSpan.innerHTML = StringUtil.shortUnit(elementData.users[key]);
					createdElement.appendChild(countSpan);
					
					createdElement.innerHTML = createdElement.innerHTML + REACTION_TYPES[key].renderedIcon;
					
					summaryList.appendChild(createdElement);
					
				}
				
				if (isSummaryPosition) {
					if (this._options.summaryPrepend) {
						DomUtil.prepend(summaryList, badgeContainer);
					}
					else {
						badgeContainer.appendChild(summaryList);
					}
{'fraction_non_alphanumeric': 0.12052368117058145, 'fraction_numerical': 0.0025028879476318828, 'mean_word_length': 3.0901574803149607, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '1462151', 'n_tokens_mistral': 3899, 'n_tokens_neox': 3016, 'n_words': 609}