Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tooltip.js « templates « CoreHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fbeba46df37475a72da2649ff604d0dcc23fa587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*!
 * Piwik - Web Analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

var Piwik_Tooltip = (function() {

	var domElement = false;
	var visible = false;
	var addedClass = false;
	var topOffset = 15;

	var mouseX, mouseY;

	/** Position the tooltip next to the mouse */
	var position = function() {
		var tipWidth = domElement.outerWidth();
		var maxX = $('body').innerWidth() - tipWidth - 25;
		if (mouseX < maxX) {
			// tooltip right of mouse
			domElement.css({
				top: (mouseY - topOffset) + "px",
				left: (mouseX + 15) + "px"
			});
		}
		else {
			// tooltip left of mouse
			domElement.css({
				top: (mouseY - topOffset) + "px",
				left: (mouseX - 15 - tipWidth) + "px"
			});
		}
	};

	/** Create and initialize the tooltip */
	var initialize = function() {
		if (domElement !== false) {
			return;
		}

		domElement = $(document.createElement('div'));
		domElement.addClass('piwik-tooltip');
		$('body').prepend(domElement);
		domElement.hide();

		$(document).mousemove(function(e) {
			mouseX = e.pageX;
			mouseY = e.pageY;
			if (visible) {
				position();
			}
		});
	};

	$(document).ready(function() {
		initialize();
	});

	return {

		/** Show the tooltip with HTML content. */
		show: function(html, addClass, maxWidth) {
			initialize();
			
			if (visible && addedClass != addClass) {
				domElement.removeClass(addedClass);
			} else {
				visible = true;
				position();
				domElement.show();
			}

			if (addClass && addedClass != addClass) {
				addedClass = addClass;
				domElement.addClass(addClass);
			}

			domElement.css({width: 'auto'});
			domElement.html(html);
			if (domElement.outerWidth() > maxWidth) {
				domElement.css({width: maxWidth + 'px'});
			}

			if (domElement.outerHeight() < 25) {
				topOffset = 5;
			} else {
				topOffset = 15;
			}
			
			position();
		},

		/** Show the tooltip with title/text content. */
		showWithTitle: function(title, text, addClass) {
			var html = '<span class="tip-title">' + title + '</span><br />' + text;
			this.show(html, addClass);
		},

		/** Hide the tooltip */
		hide: function() {
			if (domElement !== false) {
				domElement.hide();
			}

			if (addedClass) {
				domElement.removeClass(addedClass);
				addedClass = false;
			}

			visible = false;
		}

	};

})();