<commit_before>/**
 * Provides enhanced tooltips.
 * 
 * @author	<NAME>
 * @copyright	2001-2015 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @module	WoltLab/WCF/UI/Tooltip
 */
define(['jquery', 'UI/Alignment'], function($, UIAlignment) {
	"use strict";
	
	var _elements = null;
	var _pointer = null;
	var _text = null;
	var _tooltip = null;
	
	/**
	 * @constructor
	 */
	function UITooltip() {};
	UITooltip.prototype = {
		/**
		 * Initializes the tooltip element and binds event listener.
		 */
		setup: function() {
			if ($.browser.mobile) return;
			
			_tooltip = document.createElement('div');
			_tooltip.setAttribute('id', 'balloonTooltip');
			_tooltip.classList.add('balloonTooltip');
			
			_text = document.createElement('span');
			_text.setAttribute('id', 'balloonTooltipText');
			_tooltip.appendChild(_text);
			
			_pointer = document.createElement('span');
			_pointer.classList.add('elementPointer');
			_pointer.appendChild(document.createElement('span'));
			_tooltip.appendChild(_pointer);
			
			document.body.appendChild(_tooltip);
			
			_elements = document.getElementsByClassName('jsTooltip');
			
			this.init();
			
			WCF.DOMNodeInsertedHandler.addCallback('WoltLab/WCF/UI/Tooltip', this.init.bind(this));
		},
		
		/**
		 * Initializes tooltip elements.
		 */
		init: function() {
			while (_elements.length) {
				var element = _elements[0];
				element.classList.remove('jsTooltip');
				
				var title = element.getAttribute('title');
				title = (typeof title === 'string') ? title.trim() : '';
				
				if (title.length) {
					element.setAttribute('data-tooltip', title);
					element.removeAttribute('title');
					
					element.addEventListener('mouseenter', this._mouseEnter.bind(this));
					element.addEventListener('mouseleave', this._mouseLeave.bind(this));
					element.addEventListener('click', this._mouseLeave.bind(this));
				}
			}
		},
		
		/**
		 * Displays the tooltip on mouse enter.
		 * 
		 * @param	{object}	event	event object
		 */
		_mouseEnter: function(event) {
			var element = event.currentTarget;
			var title = element.getAttribute('title');
			title = (typeof title === 'string') ? title.trim() : '';
			
			if (title !== '') {
				element.setAttribute('data-tooltip', title);
				element.removeAttribute('title');
			}
			
			title = element.getAttribute('data-tooltip');
			
			// reset tooltip position
			_tooltip.style.removeProperty('top');
			_tooltip.style.removeProperty('left');
			
			// ignore empty tooltip
			if (!title.length) {
				_tooltip.classList.remove('active');
				return;
			}
			else {
				_tooltip.classList.add('active');
			}
			
			_text.textContent = title;
			
			UIAlignment.set(_tooltip, element, {
				horizontal: 'center',
				pointer: true,
				pointerClassNames: ['inverse']
			});<commit_msg>Changed tooltip default vertical orientation to top<commit_after>/**
 * Provides enhanced tooltips.
 * 
 * @author	<NAME>
 * @copyright	2001-2015 WoltLab GmbH
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @module	WoltLab/WCF/UI/Tooltip
 */
define(['jquery', 'UI/Alignment'], function($, UIAlignment) {
	"use strict";
	
	var _elements = null;
	var _pointer = null;
	var _text = null;
	var _tooltip = null;
	
	/**
	 * @constructor
	 */
	function UITooltip() {};
	UITooltip.prototype = {
		/**
		 * Initializes the tooltip element and binds event listener.
		 */
		setup: function() {
			if ($.browser.mobile) return;
			
			_tooltip = document.createElement('div');
			_tooltip.setAttribute('id', 'balloonTooltip');
			_tooltip.classList.add('balloonTooltip');
			
			_text = document.createElement('span');
			_text.setAttribute('id', 'balloonTooltipText');
			_tooltip.appendChild(_text);
			
			_pointer = document.createElement('span');
			_pointer.classList.add('elementPointer');
			_pointer.appendChild(document.createElement('span'));
			_tooltip.appendChild(_pointer);
			
			document.body.appendChild(_tooltip);
			
			_elements = document.getElementsByClassName('jsTooltip');
			
			this.init();
			
			WCF.DOMNodeInsertedHandler.addCallback('WoltLab/WCF/UI/Tooltip', this.init.bind(this));
		},
		
		/**
		 * Initializes tooltip elements.
		 */
		init: function() {
			while (_elements.length) {
				var element = _elements[0];
				element.classList.remove('jsTooltip');
				
				var title = element.getAttribute('title');
				title = (typeof title === 'string') ? title.trim() : '';
				
				if (title.length) {
					element.setAttribute('data-tooltip', title);
					element.removeAttribute('title');
					
					element.addEventListener('mouseenter', this._mouseEnter.bind(this));
					element.addEventListener('mouseleave', this._mouseLeave.bind(this));
					element.addEventListener('click', this._mouseLeave.bind(this));
				}
			}
		},
		
		/**
		 * Displays the tooltip on mouse enter.
		 * 
		 * @param	{object}	event	event object
		 */
		_mouseEnter: function(event) {
			var element = event.currentTarget;
			var title = element.getAttribute('title');
			title = (typeof title === 'string') ? title.trim() : '';
			
			if (title !== '') {
				element.setAttribute('data-tooltip', title);
				element.removeAttribute('title');
			}
			
			title = element.getAttribute('data-tooltip');
			
			// reset tooltip position
			_tooltip.style.removeProperty('top');
			_tooltip.style.removeProperty('left');
			
			// ignore empty tooltip
			if (!title.length) {
				_tooltip.classList.remove('active');
				return;
			}
			else {
				_tooltip.classList.add('active');
			}
			
			_text.textContent = title;
			
			UIAlignment.set(_tooltip, element, {
				horizontal: 'center',
				pointer: true,
				pointerClassNames: ['inverse'],
				vertical: 'top'
			});
{'fraction_non_alphanumeric': 0.15137376879212028, 'fraction_numerical': 0.003110419906687403, 'mean_word_length': 3.442056792018419, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2646615', 'n_tokens_mistral': 2148, 'n_tokens_neox': 1710, 'n_words': 328}